import ContractExact /-! -/ namespace FastAct /-! -/ @[inline] def midW (a b:UInt64):UInt64:= (((a&&&(0xffffffff:UInt64))*(b&&&(0xffffffff:UInt64)))>>>(32:UInt64))+ (((a&&&(0xffffffff:UInt64))*(b>>>(32:UInt64)))&&&(0xffffffff:UInt64))+ (((a>>>(32:UInt64))*(b&&&(0xffffffff:UInt64)))&&&(0xffffffff:UInt64)) @[inline] def mulHiW (a b:UInt64):UInt64:= (a>>>(32:UInt64))*(b>>>(32:UInt64))+(((a&&&(0xffffffff:UInt64))*(b>>>(32:UInt64)))>>>(32:UInt64))+ (((a>>>(32:UInt64))*(b&&&(0xffffffff:UInt64)))>>>(32:UInt64))+(midW a b>>>(32:UInt64)) @[inline] def mulLoW (a b:UInt64):UInt64:= (midW a b<<<(32:UInt64))+((a&&&(0xffffffff:UInt64))*(b&&&(0xffffffff:UInt64))&&&(0xffffffff:UInt64)) def mul128 (a b:UInt64):UInt64×UInt64:=(mulHiW a b,mulLoW a b) lemma toNat_and_mask (x:UInt64):(x&&&0xffffffff).toNat=x.toNat%2^32:=by rw[UInt64.toNat_and] exact Nat.and_two_pow_sub_one_eq_mod x.toNat 32 lemma toNat_shr32 (x:UInt64):(x>>>32).toNat=x.toNat/2^32:=by rw[UInt64.toNat_shiftRight] simp only[UInt64.reduceToNat,Nat.reduceMod,Nat.shiftRight_eq_div_pow,Nat.reducePow] lemma mul128_spec (a b:UInt64): (mul128 a b).1.toNat*2^64+(mul128 a b).2.toNat=a.toNat*b.toNat:=by have ha:=a.toNat_lt have hb:=b.toNat_lt have hk:a.toNat*b.toNat<2^128:= calc a.toNat*b.toNat<2^64*2^64:=Nat.mul_lt_mul'' ha hb _=2^128:=by norm_num simp only[mul128,mulHiW,mulLoW,midW,UInt64.toNat_add,UInt64.toNat_mul, UInt64.toNat_shiftLeft,toNat_and_mask,toNat_shr32] have h32:(32:UInt64).toNat%64=32:=by decide rw[h32,Nat.shiftLeft_eq] have hA:=(Nat.div_add_mod' a.toNat (2^32)).symm have hB:=(Nat.div_add_mod' b.toNat (2^32)).symm have hA0:a.toNat%2^32<2^32:=Nat.mod_lt _ (by norm_num) have hB0:b.toNat%2^32<2^32:=Nat.mod_lt _ (by norm_num) have hA1:a.toNat/2^32<2^32:=by omega have hB1:b.toNat/2^32<2^32:=by omega generalize a.toNat/2^32=A1 at* generalize a.toNat%2^32=A0 at* generalize b.toNat/2^32=B1 at* generalize b.toNat%2^32=B0 at* have prod_lt: ∀x y:Nat,x<2^32->y<2^32->x*y<2^64:= λx y hx hy=> calc x*y<2^32*2^32:=Nat.mul_lt_mul'' hx hy _=2^64:=by norm_num have m00:=prod_lt A0 B0 hA0 hB0 have m01:=prod_lt A0 B1 hA0 hB1 have m10:=prod_lt A1 B0 hA1 hB0 have m11:=prod_lt A1 B1 hA1 hB1 have hab:a.toNat*b.toNat=A1*B1*2^64+(A0*B1+A1*B0)*2^32+A0*B0:=by rw[hA,hB];ring simp only[Nat.mod_eq_of_lt m00,Nat.mod_eq_of_lt m01,Nat.mod_eq_of_lt m10, Nat.mod_eq_of_lt m11] rw[hab] generalize A0*B0=p00 at* generalize A0*B1=p01 at* generalize A1*B0=p10 at* generalize A1*B1=p11 at* omega /-! -/ def one:Nat:=2^62 noncomputable def V (a:Nat):ℝ:=(a:ℝ)/2^62 lemma V_nonneg (a:Nat):0<=V a:=by unfold V;positivity lemma V_one:V one=1:=by norm_num[V,one] lemma V_mono {a b:Nat} (h:a<=b):V a<=V b:=by unfold V;gcongr lemma V_add (a b:Nat):V (a+b)=V a+V b:=by unfold V;push_cast;ring lemma V_sub_ge (a b:Nat):V a-V b<=V (a-b):=by unfold V rcases le_total b a with h | h · rw[Nat.cast_sub h];ring_nf;rfl · rw[Nat.sub_eq_zero_of_le h] have:(a:ℝ)<=b:=by exact_mod_cast h simp only[Nat.cast_zero,zero_div] rw[div_sub_div_same] exact div_nonpos_of_nonpos_of_nonneg (by linarith only[this]) (by positivity) lemma V_sub_le_of_le {a b:Nat} (h:b<=a):V (a-b)=V a-V b:=by unfold V;rw[Nat.cast_sub h];ring @[inline] def mulDnW (a b:UInt64):UInt64:=(mulHiW a b<<<2)+(mulLoW a b>>>62) @[inline] def mulUpW (a b:UInt64):UInt64:= if mulLoW a b&&&0x3fffffffffffffff=0 then mulDnW a b else mulDnW a b+1 @[inline] def mulDn (a b:Nat):Nat:=(mulDnW a.toUInt64 b.toUInt64).toNat @[inline] def mulUp (a b:Nat):Nat:=(mulUpW a.toUInt64 b.toUInt64).toNat lemma toNat_toUInt64_le (a:Nat):a.toUInt64.toNat<=a:=by rw[UInt64.toNat_ofNat'];exact Nat.mod_le _ _ lemma toNat_toUInt64_of_lt {a:Nat} (h:a<2^64):a.toUInt64.toNat=a:=by rw[UInt64.toNat_ofNat'];exact Nat.mod_eq_of_lt h lemma toNat_mulDnW (a b:UInt64):(mulDnW a b).toNat= ((mulHiW a b).toNat*4%2^64+(mulLoW a b).toNat/2^62)%2^64:=by unfold mulDnW rw[UInt64.toNat_add,UInt64.toNat_shiftLeft,UInt64.toNat_shiftRight] have h2:(2:UInt64).toNat%64=2:=by decide have h62:(62:UInt64).toNat%64=62:=by decide rw[h2,h62,Nat.shiftLeft_eq,Nat.shiftRight_eq_div_pow] lemma low62_zero_iff (x:UInt64):(x&&&0x3fffffffffffffff=0)↔x.toNat%2^62=0:=by rw[<-UInt64.toNat_inj,UInt64.toNat_and] have:(0x3fffffffffffffff:UInt64).toNat=2^62-1:=by decide rw[this,Nat.and_two_pow_sub_one_eq_mod];simp only[Nat.reducePow,UInt64.toNat_zero] lemma halves {a b:Nat} (ha:a<2^64) (hb:b<2^64): (mulHiW a.toUInt64 b.toUInt64).toNat*2^64+(mulLoW a.toUInt64 b.toUInt64).toNat=a*b:=by have hs:=mul128_spec a.toUInt64 b.toUInt64 rwa[toNat_toUInt64_of_lt ha,toNat_toUInt64_of_lt hb] at hs lemma mulDn_mul_le (a b:Nat):mulDn a b*2^62<=a*b:=by have hs:=mul128_spec a.toUInt64 b.toUInt64 have hle:a.toUInt64.toNat*b.toUInt64.toNat<=a*b:= Nat.mul_le_mul (toNat_toUInt64_le a) (toNat_toUInt64_le b) simp only[mul128] at hs unfold mulDn rw[toNat_mulDnW] generalize (mulHiW a.toUInt64 b.toUInt64).toNat=h at* generalize (mulLoW a.toUInt64 b.toUInt64).toNat=l at* omega lemma mulUp_bounds {a b:Nat} (ha:a<=one) (hb:b<=one): a*b<=mulUp a b*2^62/\mulUp a b*2^62pow_nonneg h0 n have l2:V (mulDn rl rl)<=r^2:=by rw[sq];exact V_mulDn_le hl hl have l3:V (mulDn (mulDn rl rl) rl)<=r^3:=by rw[pow_succ];exact V_mulDn_le l2 hl have l4:V (mulDn (mulDn (mulDn rl rl) rl) rl)<=r^4:=by rw[pow_succ];exact V_mulDn_le l3 hl have l5:V (mulDn (mulDn (mulDn (mulDn rl rl) rl) rl) rl)<=r^5:=by rw[pow_succ];exact V_mulDn_le l4 hl have l6:V (mulDn (mulDn (mulDn (mulDn (mulDn rl rl) rl) rl) rl) rl)<=r^6:=by rw[pow_succ];exact V_mulDn_le l5 hl have u2:r^2<=V (mulUp rh rh):=by rw[sq];exact le_V_mulUp hh hh h0 hrh hrh have b2:mulUp rh rh<=one:=mulUp_le hrh hrh have u3:r^3<=V (mulUp (mulUp rh rh) rh):=by rw[pow_succ];exact le_V_mulUp u2 hh h0 b2 hrh have b3:=mulUp_le b2 hrh have u4:r^4<=V (mulUp (mulUp (mulUp rh rh) rh) rh):=by rw[pow_succ];exact le_V_mulUp u3 hh h0 b3 hrh have b4:=mulUp_le b3 hrh have u5:r^5<=V (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh):=by rw[pow_succ];exact le_V_mulUp u4 hh h0 b4 hrh have b5:=mulUp_le b4 hrh have u6:r^6<=V (mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) rh):=by rw[pow_succ];exact le_V_mulUp u5 hh h0 b5 hrh have b6:=mulUp_le b5 hrh have u7:r^7<=V (mulUp (mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) rh) rh):=by rw[pow_succ];exact le_V_mulUp u6 hh h0 b6 hrh have b7:=mulUp_le b6 hrh have fl: ∀(k:Nat) (x:Nat),x=one/k->V x<=1/k:= λk x h=>h▸V_div_le k have fh: ∀(k:Nat) (x:Nat),0x=(one+k-1)/k->1/(k:ℝ)<=V x:= λk x hk h=>h▸le_V_divUp k hk have hf2l:=fl 2 f2l rfl have hf3l:=fl 6 f3l rfl have hf4l:=fl 24 f4l rfl have hf5l:=fl 120 f5l rfl have hf6l:=fl 720 f6l rfl have hf2h:=fh 2 f2h (by norm_num) rfl have hf3h:=fh 6 f3h (by norm_num) rfl have hf4h:=fh 24 f4h (by norm_num) rfl have hf5h:=fh 120 f5h (by norm_num) rfl have hf6h:=fh 720 f6h (by norm_num) rfl have hremF:8/(35280:ℝ)<=V remF:=by have h:=fh 35280 ((one+35280-1)/35280) (by norm_num) rfl unfold remF V at* push_cast at* rw[mul_div_right_comm] linarith only[h] have bf2:=f_le_one 2 (by norm_num) (rfl:f2h=_) have bf3:=f_le_one 6 (by norm_num) (rfl:f3h=_) have bf4:=f_le_one 24 (by norm_num) (rfl:f4h=_) have bf5:=f_le_one 120 (by norm_num) (rfl:f5h=_) have bf6:=f_le_one 720 (by norm_num) (rfl:f6h=_) have brem:remF<=one:=by unfold remF one;norm_num have c2:=V_mulDn_le l2 hf2l have c3:=V_mulDn_le l3 hf3l have c4:=V_mulDn_le l4 hf4l have c5:=V_mulDn_le l5 hf5l have c6:=V_mulDn_le l6 hf6l have d2:=le_V_mulUp u2 hf2h (by norm_num) b2 bf2 have d3:=le_V_mulUp u3 hf3h (by norm_num) b3 bf3 have d4:=le_V_mulUp u4 hf4h (by norm_num) b4 bf4 have d5:=le_V_mulUp u5 hf5h (by norm_num) b5 bf5 have d6:=le_V_mulUp u6 hf6h (by norm_num) b6 bf6 have d7:=le_V_mulUp u7 hremF (by norm_num) b7 brem have hexp1:Real.exp (-r)<=1:=Real.exp_le_one_iff.mpr (by linarith only[h0]) have hab:=abs_le.mp hT refine ⟨?_,?_,min_le_left _ _⟩ · simp only[expSmall] refine le_trans (b:=max 0 (V (one+mulDn (mulDn rl rl) f2l+ mulDn (mulDn (mulDn (mulDn rl rl) rl) rl) f4l+ mulDn (mulDn (mulDn (mulDn (mulDn (mulDn rl rl) rl) rl) rl) rl) f6l)- V (rh+mulUp (mulUp (mulUp rh rh) rh) f3h+ mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) f5h+ mulUp (mulUp (mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) rh) rh) remF))) ?_ ?_ · unfold V rw[le_max_iff] rcases le_total (rh+mulUp (mulUp (mulUp rh rh) rh) f3h+ mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) f5h+ mulUp (mulUp (mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) rh) rh) remF) (one+mulDn (mulDn rl rl) f2l+ mulDn (mulDn (mulDn (mulDn rl rl) rl) rl) f4l+ mulDn (mulDn (mulDn (mulDn (mulDn (mulDn rl rl) rl) rl) rl) rl) f6l) with h | h · right;rw[Nat.cast_sub h];ring_nf;rfl · left;rw[Nat.sub_eq_zero_of_le h];simp only[CharP.cast_eq_zero,zero_div,Std.le_refl] · apply max_le (Real.exp_pos _).le simp only[V_add,V_one] at* linarith only[hh,c2,c4,c6,d3,d5,d7,hab] · simp only[expSmall] rcases le_total one (one+mulUp (mulUp rh rh) f2h+mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) f4h+ mulUp (mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) rh) f6h+ mulUp (mulUp (mulUp (mulUp (mulUp (mulUp (mulUp rh rh) rh) rh) rh) rh) rh) remF- (rl+mulDn (mulDn (mulDn rl rl) rl) f3l+ mulDn (mulDn (mulDn (mulDn (mulDn rl rl) rl) rl) rl) f5l)) with h | h · rw[min_eq_left h,V_one];exact hexp1 · rw[min_eq_right h] refine le_trans ?_ (V_sub_ge _ _) simp only[V_add,V_one] linarith only[hab.2,hl,c3,c5,d2,d4,d6,d7,hab] /-! -/ def Encl (iv:Nat×Nat) (b:ℝ):Prop:= V iv.1<=Real.exp (-b)/\Real.exp (-b)<=V iv.2/\iv.2<=one def powOf (base:Nat×Nat):Nat->Nat×Nat | 0=>(one,one) | j+1=>let p:=powOf base j;(mulDn p.1 base.1,min one (mulUp p.2 base.2)) lemma Encl.mul {x y:Nat×Nat} {a b:ℝ} (hx:Encl x a) (hy:Encl y b): Encl (mulDn x.1 y.1,min one (mulUp x.2 y.2)) (a+b):=by have he:Real.exp (-(a+b))=Real.exp (-a)*Real.exp (-b):=by rw[<-Real.exp_add];ring_nf refine ⟨?_,?_,min_le_left _ _⟩ · rw[he];exact V_mulDn_le hx.1 hy.1 · rw[he] rcases le_total one (mulUp x.2 y.2) with h | h · rw[min_eq_left h,V_one,<-he] exact Real.exp_le_one_iff.mpr (by have:=Real.exp_le_one_iff.mp (le_trans hx.2.1 (V_one▸V_mono hx.2.2)) have:=Real.exp_le_one_iff.mp (le_trans hy.2.1 (V_one▸V_mono hy.2.2)) linarith) · rw[min_eq_right h] exact le_V_mulUp hx.2.1 hy.2.1 (Real.exp_pos _).le hx.2.2 hy.2.2 lemma powOf_spec {base:Nat×Nat} {b:ℝ} (hb:Encl base b): ∀j:Nat,Encl (powOf base j) (j*b) | 0=>by refine ⟨?_,?_,le_rfl⟩<;>simp only[powOf,V_one,CharP.cast_eq_zero,zero_mul,neg_zero,Real.exp_zero,Std.le_refl] | j+1=>by have:=(powOf_spec hb j).mul hb simp only[powOf] convert this using 2;push_cast;ring def sixtyFourth:Nat:=2^56 lemma V_sixtyFourth:V sixtyFourth=1/64:=by norm_num[V,sixtyFourth] def base64:Nat×Nat:=expSmall sixtyFourth sixtyFourth lemma base64_spec:Encl base64 (1/64):=by exact expSmall_spec (rl:=sixtyFourth) (rh:=sixtyFourth) (r:=1/64) V_sixtyFourth.le V_sixtyFourth.ge (by norm_num[sixtyFourth,one]) def fracTab:Array (Nat×Nat):=Array.ofFn (n:=64) λj=>powOf base64 j.val def baseOne:Nat×Nat:=powOf base64 64 def intTab:Array (Nat×Nat):=Array.ofFn (n:=17) λn=>powOf baseOne n.val lemma getElem!_ofFn' {α:Type} [Inhabited α] {n:Nat} (f:Fin n->α) {i:Nat} (h:i>>(-(e+56)).toNat;(v,v+1) lemma scaled_spec (m:Nat) (e:Int): ((scaled m e).1:ℝ)<=m*(2:ℝ)^e*2^56/\ (m:ℝ)*(2:ℝ)^e*2^56<=(scaled m e).2/\(scaled m e).1<=(scaled m e).2:=by unfold scaled have hz:(m:ℝ)*(2:ℝ)^e*2^56=m*(2:ℝ)^(e+56):=by rw[zpow_add₀ two_ne_zero];norm_num;ring split · rename_i h have hk:((2:ℝ)^(e+56))=2^(e+56).toNat:=by rw[<-zpow_natCast,Int.toNat_of_nonneg h] simp only[Nat.shiftLeft_eq,hz,hk];push_cast;simp only[Std.le_refl,and_self] · rename_i h set k:=(-(e+56)).toNat have hk:((2:ℝ)^(e+56))=1/2^k:=by rw[show e+56=-(k:Int) by omega,zpow_neg,zpow_natCast,one_div] simp only[Nat.shiftRight_eq_div_pow,hz,hk] have hp:(0:ℝ)<2^k:=by positivity have h1:=Nat.div_mul_le_self m (2^k) have h2:=Nat.lt_succ_iff.mpr (le_refl (m/2^k)) have h3:m<(m/2^k+1)*2^k:=by have:=Nat.lt_mul_div_succ m (Nat.two_pow_pos k);linarith only[this] refine ⟨?_,?_,Nat.le_succ _⟩ · rw[mul_one_div,le_div_iff₀ hp];exact_mod_cast h1 · rw[mul_one_div,div_le_iff₀ hp];push_cast;exact_mod_cast h3.le def lim17:Nat:=17*2^56 @[inline] def expNeg (m:Nat) (e:Int):Option (Nat×Nat):= let c:=scaled m e if lim17<=c.2 then none else let q:=c.1>>>50 let rl:=(c.1-(q<<<50))<<<6 let rh:=(c.2-(q<<<50))<<<6 if one>>6]! let IF:=(mulDn I.1 F.1,min one (mulUp I.2 F.2)) some (mulDn IF.1 P.1,min one (mulUp IF.2 P.2)) lemma expNeg_spec {m:Nat} {e:Int} {iv:Nat×Nat} (h:expNeg m e=some iv): Encl iv (m*(2:ℝ)^e):=by unfold expNeg at h simp only[Nat.shiftRight_eq_div_pow,Nat.shiftLeft_eq] at h obtain ⟨hlo,hhi,hle⟩:=scaled_spec m e generalize (scaled m e).1=cl at* generalize (scaled m e).2=ch at* split at h · exact absurd h (by simp only[reduceCtorEq,not_false_eq_true]) rename_i hlim split at h · exact absurd h (by simp only[reduceCtorEq,not_false_eq_true]) rename_i hrh simp only[Option.some.injEq] at h subst h set q:=cl/2^50 have hq:q*2^50<=cl:=Nat.div_mul_le_self cl _ have hqd:q=q/2^6*64+q%64:=by have:=Nat.div_add_mod q 64;omega have hn:q/2^6<17:=by unfold lim17 at hlim;omega have hj:q%64<64:=Nat.mod_lt _ (by norm_num) set C:=(m:ℝ)*(2:ℝ)^e set r:=C-(q/2^6:Nat)-(q%64:Nat)*(1/64:ℝ) have hr:C=(q/2^6:Nat)+(q%64:Nat)*(1/64:ℝ)+r:=by ring have hqr:((q:Nat):ℝ)*2^50=((q/2^6:Nat):ℝ)*2^56+((q%64:Nat):ℝ)*2^50:=by have:((q:Nat):ℝ)=((q/2^6*64+q%64:Nat):ℝ):=by rw[<-hqd] rw[this];push_cast;ring have hrl:V ((cl-q*2^50)*2^6)<=r:=by unfold V;rw[Nat.cast_mul,Nat.cast_sub hq];push_cast rw[div_le_iff₀ (by positivity)] simp only[r];linarith only[hqr,hlo] have hrh':r<=V ((ch-q*2^50)*2^6):=by unfold V;rw[Nat.cast_mul,Nat.cast_sub (hq.trans hle)];push_cast rw[le_div_iff₀ (by positivity)] simp only[r];linarith only[hqr,hhi] have hP:=expSmall_spec hrl hrh' (by omega) have hI:=intTab_spec hn have hF:=fracTab_spec hj rw[hr] exact (hI.mul hF).mul hP /-! -/ def two62f:Float:=4611686018427387904.0 @[inline] def mulLe (q d num:Nat):Bool:= let h:=(mulHiW q.toUInt64 d.toUInt64).toNat let nh:=num>>>2 h>>2 nh>>50)+2) if q>>50)+2) if q>>50+2))*den:Nat):ℝ):=by exact_mod_cast h2 push_cast at this⊢;linarith only[this] · simp only[reduceCtorEq] at h /-! -/ open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats FloatLib.Numerics open ExactRuntime.FastRound def settleInt (lo hi:Int):Option UInt32:= let a:=finishWord lo (-62) false if lo≠0&&hi≠0&&a==finishWord hi (-62) false&&expOf a != 255&& (decodeD a).significand != 0 then some a else none @[inline] def settle (neg:Bool) (a b:Nat):Option UInt32:= let w:=roundW neg a (-62) if a≠0&&b≠0&&w==roundW neg b (-62)&&expOf w != 255&& (decodeD w).significand != 0 then some w else none lemma settle_eq (neg:Bool) (a b:Nat): settle neg a b= settleInt (if neg then-(b:Int) else a) (if neg then-(a:Int) else b):=by unfold settle settleInt by_cases ha:a=0 · subst ha;cases neg<;>simp only[ne_eq,not_true_eq_false,decide_false,decide_not,Bool.false_and,Int.reduceNeg,Bool.false_eq_true, ↓reduceIte,CharP.cast_eq_zero,Int.natCast_eq_zero,neg_eq_zero,neg_zero,Bool.and_false] by_cases hb:b=0 · subst hb;cases neg<;>simp only[ne_eq,decide_not,not_true_eq_false,decide_false,Bool.and_false,Int.reduceNeg,Bool.false_and,Bool.false_eq_true, ↓reduceIte,Int.natCast_eq_zero,CharP.cast_eq_zero,neg_zero,neg_eq_zero] rw[roundW_signed neg a _ ha,roundW_signed neg b _ hb] cases neg · simp only[ne_eq,decide_not,Bool.false_eq_true, ↓reduceIte,Int.reduceNeg,Bool.and_eq_true,Bool.not_eq_eq_eq_not,Bool.not_true,decide_eq_false_iff_not,beq_iff_eq,bne_iff_ne,Int.natCast_eq_zero] · simp only[ite_true] by_cases he:finishWord (-(a:Int)) (-62) false=finishWord (-(b:Int)) (-62) false · simp only[ne_eq,ha,not_false_eq_true,decide_true,hb,Bool.and_self,Int.reduceNeg,he,BEq.rfl,Bool.true_and,Bool.and_eq_true,bne_iff_ne,neg_eq_zero,Int.natCast_eq_zero] · have he': ¬finishWord (-(b:Int)) (-62) false=finishWord (-(a:Int)) (-62) false:= λh=>he h.symm simp only[ne_eq,ha,not_false_eq_true,decide_true,hb,Bool.and_self,Int.reduceNeg,Bool.true_and,Bool.and_eq_true,beq_iff_eq,he,bne_iff_ne,false_and, ↓reduceIte,neg_eq_zero,Int.natCast_eq_zero,he'] lemma settleInt_spec {lo hi:Int} {a:UInt32} (h:settleInt lo hi=some a) {v:ℝ} (hl:(lo:ℝ)*2^(-62:Int)<=v) (hh:v<=(hi:ℝ)*2^(-62:Int)) {z:Model Fmt} (hz:Model.toReal z=Model.roundAt Fmt v):toWord z=a:=by unfold settleInt at h dsimp only at h split at h · rename_i hc simp only[Option.some.injEq] at h subst h simp only[Bool.and_eq_true,bne_iff_ne,ne_eq,decide_eq_true_eq,beq_iff_eq] at hc obtain ⟨⟨⟨⟨hlo,hhi⟩,heq⟩,hfin⟩,hsig⟩:=hc exact bracket_spec hlo hhi rfl heq.symm hfin hsig hl hh hz · simp only[reduceCtorEq] at h lemma int_scale (n:Nat):((n:Int):ℝ)*2^(-62:Int)=V n:=by unfold V;push_cast;rw[zpow_neg,zpow_ofNat];ring lemma toReal_ofW_decode {w:UInt32} (hfin:expOf w≠255): Model.toReal (ofW w)= (if (decodeD w).negative then-1 else 1)*((decodeD w).significand*(2:ℝ)^(decodeD w).exponent):=by rw[Model.toReal_eq,ofW,toDyadic_ofUInt32 _ hfin] simp only[FloatLib.Numerics.Dyadic.toReal,FloatLib.Numerics.Dyadic.cast_signedSignificand] ring /-! -/ lemma realSigmoid_neg_eq (C:ℝ): realSigmoid (-C)=Real.exp (-C)/(1+Real.exp (-C)):=by unfold realSigmoid rw[neg_neg] have hp:=Real.exp_pos (-C) have h:Real.exp C=1/Real.exp (-C):=by rw[Real.exp_neg,one_div,inv_inv] rw[h];field_simp;ring def sigmoidFast (w:UInt32):Option UInt32:= if expOf w=255 then none else let d:=decodeD w match expNeg d.significand d.exponent with | none=>none | some t=> if d.negative then match divLo t.1 (one+t.1),divHi t.2 (one+t.2) with | some ql,some qh=>settle false ql qh | _,_=>none else match divLo one (one+t.2),divHi one (one+t.1) with | some ql,some qh=>settle false ql qh | _,_=>none lemma sigmoidFast_spec {w a:UInt32} (h:sigmoidFast w=some a):sigmoidCR w=a:=by unfold sigmoidFast at h split at h · simp only[reduceCtorEq] at h rename_i hfin dsimp only at h have hx:=toReal_ofW_decode hfin generalize decodeD w=d at h hx have hspec:=(toReal_sigmoidModel (fmt:=Fmt) (by decide) (input:=Model.ofUInt32 w) (by simp only[isFinite_ofUInt32,bne_iff_ne,ne_eq,hfin,not_false_eq_true])).2 change Model.toReal (sigmoidModel (ofW w))=Model.roundAt Fmt (realSigmoid (Model.toReal (ofW w))) at hspec rw[hx] at hspec change toWord (sigmoidModel (ofW w))=a split at h · simp only[reduceCtorEq] at h rename_i t ht have hE:=expNeg_spec ht set C:=(d.significand:ℝ)*(2:ℝ)^d.exponent set T:=Real.exp (-C) have hT:0rfl | some a=>exact (sigmoidFast_spec h).symm /-! -/ def tanhFast (w:UInt32):Option UInt32:= if expOf w=255 then none else let d:=decodeD w match expNeg d.significand (d.exponent+1) with | none=>none | some t=> if one settle d.negative ql qh | _,_=>none lemma neg_int_scale (n:Nat):((-(n:Int):Int):ℝ)*2^(-62:Int)=-V n:=by rw[Int.cast_neg,neg_mul,int_scale] lemma tanhFast_spec {w a:UInt32} (h:tanhFast w=some a):tanhCR w=a:=by unfold tanhFast at h split at h · simp only[reduceCtorEq] at h rename_i hfin dsimp only at h have hx:=toReal_ofW_decode hfin generalize decodeD w=d at h hx have hspec:=(toReal_tanhModel (fmt:=Fmt) (by decide) (input:=Model.ofUInt32 w) (by simp only[isFinite_ofUInt32,bne_iff_ne,ne_eq,hfin,not_false_eq_true])).2 change Model.toReal (tanhModel (ofW w))=Model.roundAt Fmt (Real.tanh (Model.toReal (ofW w))) at hspec rw[hx] at hspec change toWord (tanhModel (ofW w))=a split at h · simp only[reduceCtorEq] at h rename_i t ht have hE:=expNeg_spec ht set C:=(d.significand:ℝ)*(2:ℝ)^d.exponent have h2C:(d.significand:ℝ)*(2:ℝ)^(d.exponent+1)=2*C:=by rw[zpow_add₀ two_ne_zero];simp only[C];ring rw[h2C] at hE set T:=Real.exp (-(2*C)) have hT:0simp only[hneg,ite_true,Bool.false_eq_true,ite_false] at h · refine settleInt_spec h (v:=Real.tanh C) ?_ ?_ (by rw[hspec];simp only[hneg,Bool.false_eq_true, ↓reduceIte,one_mul]) · rw[int_scale];exact lo · rw[int_scale];exact hi · refine settleInt_spec h (v:=Real.tanh (-C)) ?_ ?_ (by rw[hspec,hneg];simp only[↓reduceIte,neg_mul,one_mul,Real.tanh_neg,Model.roundAt_neg,Model.IEEERoundingMode.negate_nearest]) · rw[neg_int_scale,Real.tanh_neg];linarith only[hi] · rw[neg_int_scale,Real.tanh_neg];linarith only[lo] · simp only[reduceCtorEq] at h def tanhF (w:UInt32):UInt32:=(tanhFast w).getD (tanhCR w) lemma tanhF_eq:tanhF=tanhCR:=by funext w unfold tanhF cases h:tanhFast w with | none=>rfl | some a=>exact (tanhFast_spec h).symm /-! -/ end FastAct namespace FexK open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats /-! -/ @[inline] def m64 (w:UInt32):UInt64:= if (w>>>23)&&&0xFF=0 then (w&&&0x7FFFFF).toUInt64 else (w&&&0x7FFFFF).toUInt64+0x800000 @[inline] def i32 (w:UInt32):UInt32:=if (w>>>23)&&&0xFF=0 then 0 else ((w>>>23)&&&0xFF)-1 structure FY where P:UInt64 N:UInt64 lo:UInt32 ok:Bool @[specialize] def fyLoop (fa fb:Nat->UInt32) (index:Nat):Nat->UInt64->UInt64->UInt32->FY | 0,P,N,lo=>⟨P,N,lo,true⟩ | cnt+1,P,N,lo=> let a:=fa index let b:=fb index if expOf a=255\/expOf b=255 then ⟨P,N,lo,false⟩ else let p:=m64 a*m64 b if p=0 then fyLoop fa fb (index+1) cnt P N lo else let k:=i32 a+i32 b if P=0/\N=0 then if Bool.xor (signOf a) (signOf b) then fyLoop fa fb (index+1) cnt 0 p k else fyLoop fa fb (index+1) cnt p 0 k else if lo<=k then let d:=k-lo if d<=15 then let q:=p<<UInt32):UInt32:= let r:=fyLoop fa fb 0 n 0 0 0 if r.ok&&r.P != r.N then if r.Pfa i.val) (Array.ofFn (n:=n) λi=>fb i.val) /-! -/ lemma m64_eq (w:UInt32):(m64 w).toNat=mantOf w:=by unfold m64 mantOf expOf fracOf have hf:(w&&&0x7FFFFF).toNat<2^23:=by rw[UInt32.toNat_and];exact Nat.lt_of_le_of_lt Nat.and_le_right (by decide) split · rw[UInt32.toNat_toUInt64] · rw[UInt64.toNat_add,UInt32.toNat_toUInt64] simp only[UInt64.reduceToNat];omega lemma i32_eq (w:UInt32):(i32 w).toNat=idxOf w:=by unfold i32 idxOf expOf split · rfl · rename_i h have h1:(1:UInt32)<=(w>>>23)&&&0xFF:=by rw[UInt32.le_iff_toNat_le] have:((w>>>23)&&&0xFF).toNat≠0:= λh0=>h (UInt32.toNat_inj.mp (by simpa only[UInt32.toNat_and,UInt32.toNat_shiftRight,UInt32.reduceToNat,Nat.reduceMod,UInt32.toNat_zero] using h0)) simp only[UInt32.reduceToNat];omega rw[UInt32.toNat_sub_of_le _ _ h1];rfl lemma mant_lt (w:UInt32):mantOf w<2^24:=by unfold mantOf fracOf have hf:(w&&&0x7FFFFF).toNat<2^23:=by rw[UInt32.toNat_and];exact Nat.lt_of_le_of_lt Nat.and_le_right (by decide) split<;>omega lemma p_eq (a b:UInt32):(m64 a*m64 b).toNat=mantOf a*mantOf b:=by rw[UInt64.toNat_mul,m64_eq,m64_eq] apply Nat.mod_eq_of_lt have:=mant_lt a;have:=mant_lt b calc mantOf a*mantOf b<2^24*2^24:=Nat.mul_lt_mul'' ‹_› ‹_› _<=2^64:=by decide lemma k_eq (a b:UInt32) (ha:expOf a≠255) (hb:expOf b≠255): (i32 a+i32 b).toNat=idxOf a+idxOf b:=by rw[UInt32.toNat_add,i32_eq,i32_eq] have:=idxOf_le a ha;have:=idxOf_le b hb omega lemma add_nov (x y:UInt64) (h:x<=x+y):(x+y).toNat=x.toNat+y.toNat:=by rw[UInt64.le_iff_toNat_le,UInt64.toNat_add] at h rw[UInt64.toNat_add] have:=y.toNat_lt;have:=x.toNat_lt omega lemma shl_eq (x:UInt64) (s:UInt32) (hs:s.toNat<64) (hx:x.toNat*2^s.toNat<2^64): (x<<UInt32) (A B:Array UInt32) (cnt:Nat): ∀(index:Nat) (P N:UInt64) (lo:UInt32), (∀k,index<=k->k< index+cnt->A[k]! =fa k/\B[k]! =fb k)-> (fyLoop fa fb index cnt P N lo).ok=true-> (∀k,index<=k->k< index+cnt->expOf (fa k)≠255/\expOf (fb k)≠255)/\ (((fyLoop fa fb index cnt P N lo).P.toNat:Int)-(fyLoop fa fb index cnt P N lo).N.toNat)* 2^(fyLoop fa fb index cnt P N lo).lo.toNat= ((P.toNat:Int)-N.toNat)*2^lo.toNat+dsum A B index cnt:=by induction cnt with | zero=> intro index P N lo _ _ refine ⟨λk h1 h2=>by omega,?_⟩ simp only[fyLoop,dsum,add_zero] | succ cnt ih=> intro index P N lo hAB hok obtain ⟨hA,hB⟩:=hAB index le_rfl (by omega) have hAB': ∀k,index+1<=k->k< index+1+cnt->A[k]! =fa k/\B[k]! =fb k:= λk h1 h2=>hAB k (by omega) (by omega) have hterm:dsum A B index (cnt+1)= (if Bool.xor (signOf (fa index)) (signOf (fb index)) then-((mantOf (fa index)*mantOf (fb index):Nat):Int) else ((mantOf (fa index)*mantOf (fb index):Nat):Int))* 2^(idxOf (fa index)+idxOf (fb index))+dsum A B (index+1) cnt:=by rw[dsum,hA,hB,Pinned.sv_mul] by_cases hsp:expOf (fa index)=255\/expOf (fb index)=255 · simp only[fyLoop,hsp, ↓reduceIte,Bool.false_eq_true] at hok · have hsp':=not_or.mp hsp have fin_of (h: ∀k,index+1<=k->k< index+1+cnt-> expOf (fa k)≠255/\expOf (fb k)≠255): ∀k,index<=k->k< index+(cnt+1)->expOf (fa k)≠255/\expOf (fb k)≠255:=by intro k h1 h2 rcases Nat.lt_or_ge k (index+1) with hk | hk · have:k=index:=by omega subst this;exact hsp' · exact h k hk (by omega) have hp:=p_eq (fa index) (fb index) have hk:=k_eq (fa index) (fb index) hsp'.1 hsp'.2 have hpl:mantOf (fa index)*mantOf (fb index)<2^48:=by have:=mant_lt (fa index);have:=mant_lt (fb index) calc mantOf (fa index)*mantOf (fb index)<2^24*2^24:=Nat.mul_lt_mul'' ‹_› ‹_› _=2^48:=by norm_num generalize hpv:m64 (fa index)*m64 (fb index)=p at hp generalize hkv:i32 (fa index)+i32 (fb index)=k at hk generalize hng:Bool.xor (signOf (fa index)) (signOf (fb index))=ng at hterm generalize hM:mantOf (fa index)*mantOf (fb index)=M at hp hterm hpl generalize hI:idxOf (fa index)+idxOf (fb index)=I at hk hterm have unf:fyLoop fa fb index (cnt+1) P N lo= (if p=0 then fyLoop fa fb (index+1) cnt P N lo else if P=0/\N=0 then (if ng then fyLoop fa fb (index+1) cnt 0 p k else fyLoop fa fb (index+1) cnt p 0 k) else if lo<=k then (if k-lo<=15 then (if ng then (if N<=N+p<<<(k-lo).toUInt64 then fyLoop fa fb (index+1) cnt P (N+p<<<(k-lo).toUInt64) lo else ⟨P,N,lo,false⟩) else (if P<=P+p<<<(k-lo).toUInt64 then fyLoop fa fb (index+1) cnt (P+p<<<(k-lo).toUInt64) N lo else ⟨P,N,lo,false⟩)) else ⟨P,N,lo,false⟩) else (if lo-k<=15/\P<(1:UInt64)<<<(63-(lo-k)).toUInt64/\ N<(1:UInt64)<<<(63-(lo-k)).toUInt64 then (if ng then fyLoop fa fb (index+1) cnt (P<<<(lo-k).toUInt64) ((N<<<(lo-k).toUInt64)+p) k else fyLoop fa fb (index+1) cnt ((P<<<(lo-k).toUInt64)+p) (N<<<(lo-k).toUInt64) k) else ⟨P,N,lo,false⟩)):=by rw[fyLoop];simp only[hsp,ite_false,hpv,hkv,hng] rw[unf] at hok⊢ by_cases c1:p=0 · rw[if_pos c1] at hok⊢ obtain ⟨h1,h2⟩:=ih (index+1) P N lo hAB' hok refine ⟨fin_of h1,?_⟩ have hM0:M=0:=by rw[<-hp,c1];rfl rw[h2,hterm,hM0];simp only[CharP.cast_eq_zero,neg_zero,ite_self,zero_mul,zero_add] rw[if_neg c1] at hok⊢ by_cases c2:P=0/\N=0 · rw[if_pos c2] at hok⊢ cases ng · rw[if_neg (by simp only[Bool.false_eq_true,not_false_eq_true])] at hok⊢ obtain ⟨h1,h2⟩:=ih _ _ _ _ hAB' hok refine ⟨fin_of h1,?_⟩ rw[h2,hterm,c2.1,c2.2,hp,hk];simp only[UInt64.toNat_zero,CharP.cast_eq_zero,sub_zero,sub_self,zero_mul,Bool.false_eq_true, ↓reduceIte,zero_add] · rw[if_pos rfl] at hok⊢ obtain ⟨h1,h2⟩:=ih _ _ _ _ hAB' hok refine ⟨fin_of h1,?_⟩ rw[h2,hterm,c2.1,c2.2,hp,hk];simp only[UInt64.toNat_zero,CharP.cast_eq_zero,zero_sub,neg_mul,sub_self,zero_mul, ↓reduceIte,zero_add] rw[if_neg c2] at hok⊢ by_cases c4:lo<=k · rw[if_pos c4] at hok⊢ have hle:lo.toNat<=k.toNat:=UInt32.le_iff_toNat_le.mp c4 have hdk:(k-lo).toNat=k.toNat-lo.toNat:=UInt32.toNat_sub_of_le _ _ c4 by_cases c5:k-lo<=15 · rw[if_pos c5] at hok⊢ have hd15:(k-lo).toNat<=15:=by have:=UInt32.le_iff_toNat_le.mp c5;simpa only[ge_iff_le,UInt32.reduceToNat] using this have hq:(p<<<(k-lo).toUInt64).toNat=p.toNat*2^(k-lo).toNat:=by apply shl_eq _ _ (by omega) calc p.toNat*2^(k-lo).toNat<2^48*2^15:= Nat.mul_lt_mul_of_lt_of_le (by omega) (Nat.pow_le_pow_right (by norm_num) hd15) (by positivity) _<=2^64:=by norm_num have e:(2:Int)^k.toNat=2^(k.toNat-lo.toNat)*2^lo.toNat:=by rw[<-pow_add];congr 1;omega cases ng · rw[if_neg (by simp only[Bool.false_eq_true,not_false_eq_true])] at hok⊢ by_cases c8:P<=P+p<<<(k-lo).toUInt64 · rw[if_pos c8] at hok⊢ obtain ⟨h1,h2⟩:=ih _ _ _ _ hAB' hok refine ⟨fin_of h1,?_⟩ rw[h2,hterm,add_nov _ _ c8,hq,hp,hdk,<-hk,e] simp only[Nat.cast_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,Bool.false_eq_true, ↓reduceIte];push_cast;ring · rw[if_neg c8] at hok;simp only[Bool.false_eq_true] at hok · rw[if_pos rfl] at hok⊢ by_cases c7:N<=N+p<<<(k-lo).toUInt64 · rw[if_pos c7] at hok⊢ obtain ⟨h1,h2⟩:=ih _ _ _ _ hAB' hok refine ⟨fin_of h1,?_⟩ rw[h2,hterm,add_nov _ _ c7,hq,hp,hdk,<-hk,e] simp only[Nat.cast_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat, ↓reduceIte,neg_mul];push_cast;ring · rw[if_neg c7] at hok;simp only[Bool.false_eq_true] at hok · rw[if_neg c5] at hok;simp only[Bool.false_eq_true] at hok · rw[if_neg c4] at hok⊢ by_cases c9:lo-k<=15/\P<(1:UInt64)<<<(63-(lo-k)).toUInt64/\ N<(1:UInt64)<<<(63-(lo-k)).toUInt64 · rw[if_pos c9] at hok⊢ obtain ⟨s15,bP,bN⟩:=c9 have hlt:k.toNatUInt32) (cnt:Nat): ∀(index:Nat) (pos neg:Array Nat) (nz:Bool), (∀k,index<=k->k< index+cnt->expOf (fa k)≠255/\expOf (fb k)≠255)-> pos.size=18->neg.size=18-> (Pinned.dotLoop fa fb pos neg false nz index cnt).special=false:=by induction cnt with | zero=>intro index pos neg nz _ _ _;simp only[Pinned.dotLoop] | succ cnt ih=> intro index pos neg nz hf hp hn have he:=hf index le_rfl (by omega) obtain ⟨h1,h2,h3,-,-⟩:= Pinned.Acc.add_spec ⟨pos,neg,false,nz⟩ (mantOf (fa index)*mantOf (fb index)) (idxOf (fa index)+idxOf (fb index)) (Bool.xor (signOf (fa index)) (signOf (fb index))) hp hn (ExactRuntime.mul_mant_lt _ _) (by have:=ExactRuntime.idxOf_le _ he.1;have:=ExactRuntime.idxOf_le _ he.2;omega) have hstep:Pinned.dotStep ⟨pos,neg,false,nz⟩ (fa index) (fb index)= Pinned.Acc.add ⟨pos,neg,false,nz⟩ (mantOf (fa index)*mantOf (fb index)) (idxOf (fa index)+idxOf (fb index)) (Bool.xor (signOf (fa index)) (signOf (fb index))):=by simp only[Pinned.dotStep,he.1,he.2,or_self, ↓reduceIte] rw[Pinned.dotLoop,hstep] generalize hr:Pinned.Acc.add ⟨pos,neg,false,nz⟩ (mantOf (fa index)*mantOf (fb index)) (idxOf (fa index)+idxOf (fb index)) (Bool.xor (signOf (fa index)) (signOf (fb index)))=r at h1 h2 h3 obtain ⟨p',n',s',z'⟩:=r simp only at h1 h2 h3⊢ subst h3 exact ih (index+1) p' n' z' (λk k1 k2=>hf k (by omega) (by omega)) h1 h2 lemma dotOf_fin (n:Nat) (fa fb:Nat->UInt32) (hf: ∀k,kexpOf (fa k)≠255/\expOf (fb k)≠255): ∃nz:Bool,dotOf n fa fb= finishWord (ExactRuntime.dsum (Array.ofFn (n:=n) λi=>fa i.val) (Array.ofFn (n:=n) λi=>fb i.val) 0 n) (-298) nz:=by rw[<-Pinned.dotFn_eq_dotOf] unfold Pinned.dotFn have hsp:(Pinned.dotLoop fa fb (Array.replicate 18 0) (Array.replicate 18 0) false true 0 n).special =false:=dotLoop_nsp fa fb n 0 _ _ true (λk _ h2=>hf k (by omega)) (by simp only[Array.size_replicate]) (by simp only[Array.size_replicate]) obtain ⟨-,-,hD,-⟩:=Pinned.dotLoopFacts fa fb (Array.ofFn (n:=n) λi=>fa i.val) (Array.ofFn (n:=n) λi=>fb i.val) n (Pinned.getElem!_ofFn n fa) (Pinned.getElem!_ofFn n fb) Pinned.Acc.empty 0 n (by omega) (by simp only[Pinned.Acc.empty,Array.size_replicate]) (by simp only[Pinned.Acc.empty,Array.size_replicate]) hsp refine ⟨decide (n≠0)&&(Pinned.dotLoop fa fb (Array.replicate 18 0) (Array.replicate 18 0) false true 0 n).negZero,?_⟩ dsimp only rw[if_neg (by simp only[hsp,Bool.false_eq_true,not_false_eq_true]),Pinned.finishFast_eq] congr 1 have h0:=Pinned.Acc.total_empty simp only[Pinned.Acc.empty] at hD h0 rw[h0,Int.zero_add] at hD exact hD lemma fexDot_eq (n:Nat) (fa fb:Nat->UInt32):fexDot n fa fb=dotOf n fa fb:=by unfold fexDot dsimp only split · rename_i h simp only[Bool.and_eq_true,bne_iff_ne,ne_eq] at h obtain ⟨hok,hne⟩:=h obtain ⟨hf,hv⟩:=fyLoop_spec fa fb (Array.ofFn (n:=n) λi=>fa i.val) (Array.ofFn (n:=n) λi=>fb i.val) n 0 0 0 0 (λk _ h2=>⟨Pinned.getElem!_ofFn n fa k (by omega),Pinned.getElem!_ofFn n fb k (by omega)⟩) hok obtain ⟨nz,hd⟩:=dotOf_fin n fa fb (λk hk=>hf k (by omega) (by omega)) rw[hd] simp only[UInt64.toNat_zero,Nat.cast_zero,sub_zero,zero_mul,zero_add] at hv rw[<-hv] generalize (fyLoop fa fb 0 n 0 0 0)=r at hne⊢ have hne':r.P.toNat≠r.N.toNat:= λh=>hne (UInt64.toNat_inj.mp h) rw[<-finishWord_scale] have e2:((r.lo.toNat:Int)-298)=-298+((r.lo.toNat:Nat):Int):=by ring split · rename_i hlt have hlt':=UInt64.lt_iff_toNat_lt.mp hlt have hs:(r.N-r.P).toNat=r.N.toNat-r.P.toNat:=UInt64.toNat_sub_of_le _ _ (UInt64.le_of_lt hlt) rw[FastRound.roundW_eq,<-Pinned.finishWord_signed _ _ _ nz (by omega),e2,hs] congr 1;simp only[ite_true];omega · rename_i hlt have hlt':r.N.toNat<=r.P.toNat:=by have:=UInt64.lt_iff_toNat_lt.not.mp hlt;omega have hs:(r.P-r.N).toNat=r.P.toNat-r.N.toNat:= UInt64.toNat_sub_of_le _ _ (UInt64.le_iff_toNat_le.mpr hlt') rw[FastRound.roundW_eq,<-Pinned.finishWord_signed _ _ _ nz (by omega),e2,hs] congr 1;simp only[Bool.false_eq_true,ite_false];omega · rw[Pinned.dotX_eq_spec];rfl end FexK namespace Submission open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats FloatLib.Floats.ExecFloat.Binary open _root_ renaming mul_le_mul_of_nonneg_right → ἀ, mul_le_mul_of_nonneg_left → ἁ, abs_of_nonneg → ἅ, abs_nonneg → Ἀ, dite_eq_left → Ἄ, mul_nonneg → Ἆ, ite_eq_right → ἐ, mul_le_mul → ἑ, zpow_le_zpow_right₀ → ἒ, two_ne_zero → ἓ, dite_eq_right → ἔ, abs_add_le → Ἐ, zpow_add₀ → Ἓ, getElem!_pos → Ἕ, abs_of_pos → ἡ, abs_mul → ἢ, abs_sub_comm → ἣ, zpow_natCast → Ἡ, lt_of_lt_of_le → Ἥ, mul_lt_mul_of_pos_right → Ἦ, ite_eq_left → ἱ, zpow_pos → ἵ, lt_of_le_of_lt → ἷ, pow_le_pow_left₀ → Ἳ, le_trans → ὂ, sq_nonneg → ὅ, getElem!_neg → ὑ, abs_sub → Ὕ, le_refl → Ὗ, FloatArray → ὤ, UInt32 → ὥ, USize → ὦ, Float → ὧ, UInt64 → Ὠ, Bool → Ὡ, Nat → Ὣ, abs_sub_abs_le_abs_sub → Ὥ, if_pos → Ὦ, if_neg → Ὧ, abs_le → ὸ, zpow_sub₀ → ᾂ open ExactRuntime renaming rationalWord → ἂ, toDyadic_ofUInt32 → ἶ, Word → Ὢ open UInt32 renaming le_iff_toNat_le → ἃ, toNat_inj → ἠ, toNat_and → Ἧ, lt_iff_toNat_lt → ἳ, toNat_toUSize → ὃ, toNat_sub_of_le → ὓ, le_refl → Ὓ, toNat_ofNat' → ὡ, ofNat → ὺ open List renaming range → ἄ, mem_range → Ἅ, nodup_range → Ὂ, foldl_cons → ὔ, mem_cons_of_mem → ὖ, range_eq_range' → ὗ, map_congr_left → ὠ, mem_cons_self → ὣ open FloatArray renaming emptyWithCapacity → ἆ open Array renaming replicate → ἇ open Nat renaming mod_eq_of_lt → Ἁ, and_two_pow_sub_one_eq_mod → Ἂ, zero_add → Ἇ, mul_le_mul_right → Ἒ, cast_nonneg → Ἔ, mul_comm → ἥ, div_lt_of_lt_mul → Ἰ, shiftRight_eq_div_pow → Ἱ, not_lt_zero → Ἲ, add_zero → Ἵ, mod_lt → ὀ, shiftLeft_eq → ὁ, div_eq_of_lt → Ὃ, le_mul_of_pos_right → Ὄ, zero_mul → ὒ, one_mul → Ὑ, add_assoc → ὢ, add_mul → ὰ, pos_of_ne_zero → ὼ, succ_mul → ᾀ open Float renaming ofBits → Ἃ, sqrt → Ἤ open FloatLib.Floats.Formats.BinaryInterchange.Model renaming roundDyadic → ἕ, isFinite → Ἑ, toReal_eq_unpackedToReal_toModel → ἦ, toReal → Ἢ, modelSignBit → Ἴ, toModel_ofFloatModel → Ὀ, modelSign → ὶ, roundAt → ᾁ open UInt64 renaming toNat_add → ἤ, toNat_shiftRight → ἰ, lt_iff_toNat_lt → ἴ, toNat_and → Ὅ, le_iff_toNat_le → Ὤ, toNat_sub → ὲ open Real renaming sqrt → ἧ open FloatLib.Numerics.Dyadic renaming cast_toRat → Ἠ, toRat_eq_zero_iff → ὐ open Finset renaming range → Ἣ, sum_congr → Ἷ, mem_range → Ὁ open FloatLib.Numerics renaming binaryRadix → ἲ open Float.Model.UnpackedFloat renaming unpack → Ἶ open USize renaming toNat_one → ὄ, ofNat → ὴ open Bool renaming and_eq_true_iff → ὕ local notation"А"=>USize.lt_iff_toNat_lt local notation"В"=>0x7FFFFFFF local notation"Е"=>0xFFFFFFFF local notation"У"=>0x7F800000 local notation"ь"=>0x3CE0000000000000 local notation"س"=>0x80000000 local notation"ظ"=>0x3370000000000000 local notation"א"=>by omega local notation"ב"=>by norm_num local notation"ג"=>by simp local notation"ѐ"=>Array UInt32 local notation"ё"=>Array Word local notation"ї"=>Array Nat local notation"љ"=>List Nat open USize (toNat) open UInt32 (toNat) open UInt64 (toNat) local notation:max"Ѡ"x:max=>toNat x open Array (size) open FloatArray (size) local notation:max"ѡ"x:max=>size x open Nat (toUSize) open UInt32 (toUSize) local notation:max"Ѣ"x:max=>toUSize x local notation:max"Ѥ"x:max=>USize.toNat x local notation:max"ѥ"x:max=>UInt32.toNat x local notation:max"Ѧ"x:max=>UInt64.toNat x local notation:max"ѧ"x:max=>Array.size x local notation:max"Ѩ"x:max=>FloatArray.size x local notation:max"ѩ"x:max=>Nat.toUSize x local notation:max"Ѫ"x:max=>UInt32.toUSize x local notation:max"ѣ"x:max=>List.length x open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats FloatLib.Floats.ExecFloat.Binary open FloatLib.Numerics.Dyadic (signedSignificand toRat_eq_zero_iff add_toRat mul_toRat mulFields) open UInt64 (toNat_sub_of_le) open Bool (false_eq_true and_eq_true or_eq_true) open USize (toNat) open UInt32 (toNat) open UInt64 (toNat) open Array (size) open FloatArray (size) open Nat (toUSize) open UInt32 (toUSize) local notation"Մ"=>Array.ext local notation"ה"=>(by decide) local notation"ו"=>(by positivity) local notation"ז"=>(by simp;omega) local notation"ט"=>(by rw[А];omega) local notation:max x:max "ᶠ"=>Float.isFinite x=true local notation "⟡"=>FloatFormat.binary64 local notation "⟠"=>Float.Model.Format.binary64 lemma omS3 {x0 x1:ℕ} (h0:x0/32+1<18) (h1:x1=18):x0/32+1=x1):x0=x1:=א lemma omS9 {x0:ℕ}:02^53+x0*2^30<2*(2^52+x1)+2^29:=א lemma omS120 {x0:ℕ}:2^53<2*(2^52+x0)+2^28:=א lemma omS121 {x0:ℕ} (h0:x0<2^52):2^52+x0<=2^53+0*2^30+2^29:=א lemma omS122 {x0:ℕ}:0≠0->2^53+0*2^30<2^52+x0+2^29:=א lemma omS123 {x0 x1:ℕ} (h0:((x1+1)*2^23+0)*2^29omega lemma omS162 {x0 x1:ℕ} (h0:x0omega lemma omS163 {x0 x1:ℕ} (h0:x0omega lemma omS164 {x0 x1:ℕ} (h0:x0omega lemma omS165 {x0 x1:ℕ} (h0:x0omega lemma omS166 {x0 x1:ℕ} (h0:x0omega lemma omS167 {x0 x1 x2 x3:ℕ} (h0:x2<8) (h1:x0=x1+8*(x3-x3)+x2):x0omega lemma omS170 {x0 x1 x2:ℕ} (h0:x2omega lemma omS319 {x0 x1 x2:ℕ} (h0:x10:=א lemma omS377 {x0 x1 x2:ℕ} (h0:x2+x0=x3\/x2-x1>=x4:=by simp_all+arith lemma omS383 {x0 x1 x2:ℕ} (h0:x1omega lemma omS384 {x0 x1 x2 x3 x4:ℕ} (h0:x1<=x0) (h1:x0-x1=x3\/x1+x2-x1>=x4):=by simp_all+arith lemma omS385 {x0 x1 x2 x3:ℕ} (h0:x1<2^32) (h1:x1=x2) (h2:x0+x3<=x2):x0<2^32:=by subst_vars;omega lemma omS386 {x0 x1 x2:ℕ} (h0:x2omega lemma omS387 {x0 x1 x2 x3 x4:ℕ}:x0=x4\/x1+(x2+x3)-x1>=x2:=by subst_vars;simp only[add_lt_iff_neg_left,not_lt_zero,ge_iff_le,add_tsub_cancel_left,le_add_iff_nonneg_right,zero_le,or_true] lemma omS388 {x0 x1 x2 x3 x4:ℕ} (h0: ¬(x0=x2\/x3-x1>=x4)):x0-x1=x3\/x2-x0>=x4)):x0<=x1:=by simp_all+arith lemma omS390 {x0 x1 x2 x3:ℕ} (h0:x0=x2) (h1:x1=x3) (h2:x2+x3<2^32):x0+x1<2^32:=by subst_vars;omega lemma omS391 {x0 x1 x2:ℕ}:x0+(x1+x2)=x0+x1+x2:=by simp+arith at* lemma omS392 {x0 x1 x2 x3 x4:ℕ} (h0:x1+x2<=x3) (h1:x3<2^32) (h2:x4+x0=s.h\/xx-s.pad>=s.w then 0 else inp[(c*s.h+(yy-s.pad))*s.w+(xx-s.pad)]! @[specialize] def conv2dWithO (dot:DotFn) (s:OS) (relu:Ὡ) (inp wts b:ё):ё:= let k:=s.cin*s.kh*s.kw Array.ofFn (n:=s.cout*(s.ho*s.wo)) λq=> let o:=q.val/(s.ho*s.wo) let y:=q.val/s.wo%s.ho let x:=q.val%s.wo act relu<| dot (k+1) (λt=>if tif t let c:=q.val/(s.ho*s.wo) let y:=q.val/s.wo%s.ho let x:=q.val%s.wo act relu<| dot (k+1) (λt=>if tif t let ch:=q.val/(h/k*(w/k)) let y:=q.val/(w/k)%(h/k) let x:=q.val%(w/k) let s:=dot (k*k) (poolAtO h w k inp ch y x) (λ_=>oneW) toWord (Model.div (ofW s) (ofW (natW (k*k)))) def avgpoolSpecO:=avgpoolWithO dotOf def maxpoolSpecO (c h w k:Nat) (inp:ё):ё:= Array.ofFn (n:=c*(h/k*(w/k))) λq=> let ch:=q.val/(h/k*(w/k)) let y:=q.val/(w/k)%(h/k) let x:=q.val%(w/k) toWord<| (ἄ (k*k)).foldl (λacc t=> Model.maximum acc (ofW (poolAtO h w k inp ch y x t))) (ofW (poolAtO h w k inp ch y x 0)) namespace C lemma zw_mant {w:ὥ} (h:w&&&В=0):mantOf w=0:=by have h1:(w&&&В).toNat=0:=by rw[h];rfl rw[Ἧ] at h1 have h3:(В:ὥ).toNat=2^31-1:=rfl rw[h3,Ἂ] at h1 have hl:=w.toNat_lt unfold mantOf expOf fracOf have he:(w>>>23)&&&0xFF=0:=by apply UInt32.toNat_inj.mp rw[Ἧ,UInt32.toNat_shiftRight] have h3:(0xFF:ὥ).toNat=2^8-1:=rfl have h4:(23:ὥ).toNat%32=23:=rfl rw[h3,h4,Ἂ,Ἱ] show _=0 exact omS52 h1 rw[ἱ he] rw[Ἧ] have h5:(0x7FFFFF:ὥ).toNat=2^23-1:=rfl rw[h5,Ἂ] omega def xLo (X:ѐ) (base i:Nat):Nat->Nat | 0=>i | n+1=>if X[base+i]!&&&В==0 then xLo X base (i+1) n else i def xHi (X:ѐ) (base:Nat):Nat->Nat | 0=>0 | n+1=>if X[base+n]!&&&В==0 then xHi X base n else n+1 lemma xLo_spec (X:ѐ) (base:Nat): ∀n i xx,i<=xx->xxmantOf X[base+xx]! =0:=by intro n induction n with | zero=>intro i xx h1 h2;simp only[xLo] at h2;omega | succ n ih=> intro i xx h1 h2 simp only[xLo] at h2 split at h2 · rename_i hz by_cases hx:xx=i · subst hx;exact zw_mant (by simpa only[beq_iff_eq] using hz) · exact ih (i+1) xx (by exact omS138 h1 hx) h2 · omega lemma xHi_spec (X:ѐ) (base:Nat): ∀n xx,xHi X base n<=xx->xxmantOf X[base+xx]! =0:=by intro n induction n with | zero=>intro xx _ h2;omega | succ n ih=> intro xx h1 h2 simp only[xHi] at h1 split at h1 · rename_i hz by_cases hx:xx=n · subst hx;exact zw_mant (by simpa only[beq_iff_eq] using hz) · exact ih xx h1 (by exact omS374 h2 hx) · omega lemma xHi_le (X:ѐ) (base:Nat): ∀n,xHi X base n<=n:=by intro n induction n with | zero=>simp only[xHi,Std.le_refl] | succ n ih=>simp only[xHi];split<;>omega lemma push2_getD (a:ї) (u v j:Nat): ((a.push u).push v).getD j 0=if jї->ї | 0,a=>a | n+1,a=>let p:=rowE X w pad r;rowsE X w pad (r+1) n ((a.push p.1).push p.2) def hullE (s:OS) (RE:ї) (c y0:Nat) (i:Nat) (L G:Nat):Nat->Nat×Nat | 0=>(L,G) | n+1=> if y0+iyi (xx pixZ s X c (y*s.stride+i) xx=true def ex3G (s:OS) (RE:ї) (ho:Nat) (c y:Nat):Nat->ї->ї | 0,a=>a | n+1,a=>let p:=hullE s RE c (y*s.stride) 0 (s.w+2*s.pad) (s.w+2*s.pad) s.kh ex3G s RE ho c (y+1) n ((a.push p.1).push p.2) def ex3D (s:OS) (RE:ї) (ho:Nat) (c:Nat):Nat->ї->ї | 0,a=>a | n+1,a=>ex3D s RE ho (c+1) n (ex3G s RE ho c 0 ho a) lemma pixZ_pad (s:OS) (X:ѐ) (c yy xx:Nat) (h:s.w+2*s.pad<=xx):pixZ s X c yy xx=true:=by unfold pixZ;simp only[Bool.or_eq_true,decide_eq_true_eq];exact Or.inl (Or.inr א) def RowOk (X:ѐ) (w pad R:Nat) (e:ї):Prop:= ∀r xx,r(xx xx (rowsE X w pad r n a).size=2*(r+n)/\(∀j,j(rowsE X w pad r n a).getD j 0=a.getD j 0)/\ ∀r' xx,r<=r'->r'(xx<(rowsE X w pad r n a).getD (2*r') 0\/w+2*pad-(rowsE X w pad r n a).getD (2*r'+1) 0<=xx)-> xxintro r a hs;simp only[rowsE];exact ⟨א, λ_ _=>by simp only, λr' _ h1 h2=>א⟩ | succ n ih=> intro r a hs simp only[rowsE] have hs2:((a.push (rowE X w pad r).1).push (rowE X w pad r).2).size=2*(r+1):=by simp only[Array.size_push];omega obtain ⟨a1,a2,a3⟩:=ih (r+1) _ hs2 refine ⟨by rw[a1];omega, λj hj=>?_, λr' xx h1 h2 h3=>?_⟩ · rw[a2 j (by simp only[Array.size_push,Order.lt_add_one_iff];omega),push2_getD,ἱ א] · by_cases hr:r'=r · subst hr rw[a2 _ (by simp only[Array.size_push,Order.lt_add_one_iff];omega),a2 _ (by simp only[Array.size_push,Order.lt_add_one_iff,add_le_add_iff_right];omega),push2_getD,push2_getD] at h3 rw[ἐ א,ἱ א] at h3 rw[ἐ א,ἐ א,ἱ א] at h3 exact rowE_ok X w pad r' xx h3 · exact a3 r' xx (by exact omS138 h1 hr) (by exact omS7 h2) h3 lemma hullE_spec (s:OS) (X:ѐ) (RE:ї) (hR:RowOk X s.w s.pad (s.cin*s.h) RE) (c y0:Nat) (hc:ci'< i+n->(xx<(hullE s RE c y0 i L G n).1\/s.w+2*s.pad-(hullE s RE c y0 i L G n).2<=xx)-> pixZ s X c (y0+i') xx=true:=by intro n induction n with | zero=>intro i L G;simp only[hullE];exact ⟨Nat.le_refl _,Nat.le_refl _, λi' xx h1 h2 _=>א⟩ | succ n ih=> intro i L G simp only[hullE] split · rename_i hp obtain ⟨a1,a2,a3⟩:=ih (i+1) L G refine ⟨a1,a2, λi' xx h1 h2 h3=>?_⟩ by_cases hi:i'=i · subst hi;unfold pixZ;simp only[Bool.or_eq_true,decide_eq_true_eq] rcases hp with hp | hp · exact Or.inl (Or.inl (Or.inl (Or.inl hp))) · exact Or.inl (Or.inl (Or.inr hp)) · exact a3 i' xx (by exact omS138 h1 hi) (by exact omS7 h2) h3 · rename_i hp obtain ⟨a1,a2,a3⟩:=ih (i+1) (min L (RE.getD (2*(c*s.h+(y0+i-s.pad))) 0)) (min G (RE.getD (2*(c*s.h+(y0+i-s.pad))+1) 0)) refine ⟨Nat.le_trans a1 (Nat.min_le_left _ _),Nat.le_trans a2 (Nat.min_le_left _ _), λi' xx h1 h2 h3=>?_⟩ by_cases hi:i'=i · subst hi have hm1:=Nat.min_le_right L (RE.getD (2*(c*s.h+(y0+i'-s.pad))) 0) have hm2:=Nat.min_le_right G (RE.getD (2*(c*s.h+(y0+i'-s.pad))+1) 0) have hrow:c*s.h+(y0+i'-s.pad)א) (λh=>א)) unfold pixZ;simp only[Bool.or_eq_true,decide_eq_true_eq,beq_iff_eq] rcases r with r | r | r · exact Or.inl (Or.inl (Or.inl (Or.inr r))) · exact Or.inl (Or.inr r) · exact Or.inr r · exact a3 i' xx (by exact omS138 h1 hi) (by exact omS7 h2) h3 lemma ex3G_spec (s:OS) (X:ѐ) (RE:ї) (hR:RowOk X s.w s.pad (s.cin*s.h) RE) (ho c:Nat) (hc:cy+n<=ho-> (ex3G s RE ho c y n a).size=2*(c*ho+y+n)/\ (∀j,j(ex3G s RE ho c y n a).getD j 0=a.getD j 0)/\ ∀y' xx i,y<=y'->y'i (xx<(ex3G s RE ho c y n a).getD (2*(c*ho+y')) 0\/s.w+2*s.pad-(ex3G s RE ho c y n a).getD (2*(c*ho+y')+1) 0<=xx)-> pixZ s X c (y'*s.stride+i) xx=true:=by intro n induction n with | zero=>intro y a hs _;simp only[ex3G];exact ⟨א, λ_ _=>by simp only, λy' _ _ h1 h2=>א⟩ | succ n ih=> intro y a hs hy simp only[ex3G] have hs2:((a.push (hullE s RE c (y*s.stride) 0 (s.w+2*s.pad) (s.w+2*s.pad) s.kh).1).push (hullE s RE c (y*s.stride) 0 (s.w+2*s.pad) (s.w+2*s.pad) s.kh).2).size=2*(c*ho+(y+1)):=by simp only[Array.size_push];omega obtain ⟨a1,a2,a3⟩:=ih (y+1) _ hs2 (by exact omS5 hy) obtain ⟨b1,b2,b3⟩:=hullE_spec s X RE hR c (y*s.stride) hc s.kh 0 (s.w+2*s.pad) (s.w+2*s.pad) refine ⟨by rw[a1];omega, λj hj=>?_, λy' xx i h1 h2 h4 h3=>?_⟩ · rw[a2 j (by simp only[Array.size_push,Order.lt_add_one_iff];omega),push2_getD,ἱ א] · by_cases hy':y'=y · subst hy' rw[a2 _ (by simp only[Array.size_push,Order.lt_add_one_iff];omega),a2 _ (by simp only[Array.size_push,Order.lt_add_one_iff,add_le_add_iff_right];omega),push2_getD,push2_getD] at h3 rw[ἐ א,ἱ א] at h3 rw[ἐ א,ἐ א,ἱ א] at h3 exact b3 i xx (Nat.zero_le _) א h3 · exact a3 y' xx i (by exact omS138 h1 hy') (by exact omS7 h2) h4 h3 lemma ex3D_spec (s:OS) (X:ѐ) (RE:ї) (hR:RowOk X s.w s.pad (s.cin*s.h) RE) (ho:Nat): ∀n c (a:ї),a.size=2*(c*ho)->c+n<=s.cin-> (ex3D s RE ho c n a).size=2*((c+n)*ho)/\(∀j,j(ex3D s RE ho c n a).getD j 0=a.getD j 0)/\ ∀c' y xx i,c<=c'->c'yi (xx<(ex3D s RE ho c n a).getD (2*(c'*ho+y)) 0\/s.w+2*s.pad-(ex3D s RE ho c n a).getD (2*(c'*ho+y)+1) 0<=xx)-> pixZ s X c' (y*s.stride+i) xx=true:=by intro n induction n with | zero=>intro c a hs _;simp only[ex3D];exact ⟨א, λ_ _=>by simp only, λc' _ _ _ h1 h2=>א⟩ | succ n ih=> intro c a hs hn simp only[ex3D] obtain ⟨b1,b2,b3⟩:=ex3G_spec s X RE hR ho c (by exact omS4 hn) ho 0 a א (by exact omS10) obtain ⟨a1,a2,a3⟩:=ih (c+1) (ex3G s RE ho c 0 ho a) (by rw[b1,ὰ,Ὑ];omega) (by exact omS5 hn) refine ⟨by rw[a1];congr 1;rw[show c+(n+1)=c+1+n by exact omS375], λj hj=>?_, λc' y xx i h1 h2 hy hi h3=>?_⟩ · rw[a2 j (by rw[b1];omega),b2 j hj] · by_cases hc:c'=c · subst hc have hlt:2*(c'*ho+y)+1<(ex3G s RE ho c' 0 ho a).size:=by rw[b1];omega rw[a2 _ א,a2 _ hlt] at h3 exact b3 y xx i (Nat.zero_le _) א hi h3 · exact a3 c' y xx i (by exact omS138 h1 hc) (by exact omS7 h2) hy hi h3 lemma sound3_empty (s:OS) (X:ѐ) (dw:Ὡ) (ho:Nat):Sound3 s X dw ho #[]:=by intro c y xx i _ _ _ h have e: ∀j,(#[]:ї).getD j 0=0:= λj=>rfl rw[e,e,Nat.sub_zero] at h rcases h with h | h · omega · exact pixZ_pad s X c _ xx h lemma rowsE_ok (s:OS) (X:ѐ):RowOk X s.w s.pad (s.cin*s.h) (rowsE X s.w s.pad 0 (s.cin*s.h) (Array.emptyWithCapacity (2*(s.cin*s.h)))):=by intro r xx hr h exact (rowsE_spec X s.w s.pad (s.cin*s.h) 0 _ (by simp only[Array.emptyWithCapacity_eq,List.size_toArray,List.length_nil,mul_zero])).2.2 r xx (Nat.zero_le _) א h @[noinline] def mkExS (s:OS) (X b:ѐ) (dw:Ὡ) (ho:Nat):{e:ї // Sound3 s X dw ho e}:= if dw then ⟨#[],sound3_empty s X dw ho⟩ else if hg:(b.all (· ==0)&&decide (1by have e:(if dw then c else 0)=c:=by cases hd:dw · simp only[hd,Bool.false_or,Bool.and_eq_true,beq_iff_eq] at hg simp only[Bool.false_eq_true,ite_false];omega · rfl rw[e] at h exact (ex3D_spec s X _ (rowsE_ok s X) ho s.cin 0 _ (by simp) (by omega)).2.2 c y xx i (Nat.zero_le _) (by omega) hy hi h⟩ else ⟨#[],sound3_empty s X dw ho⟩ structure D_Sc where (lo hi:ὥ) structure D_C where (dw relu f4:Ὡ) (s:OS) (X W b:ѐ) (k C ho wo wp:Ὣ) (step:ὦ) (hi:ὥ) (xd:ὤ) (nf:ὧ) (tab:ѐ) (ex:{e:ї // Sound3 s X dw ho e}) structure D_P where (g:D_C) (wd:ὤ) (off:ѐ) (e l1 l8:ὦ) (e0 bv ze:ὧ) (he:Ѥe<=ѧoff) (hw:Ѥe<=Ѩwd) (hs:g.xd.size<2^32) (h1:∀b:ὦ,b∀j (h:j< ѧoff),Ѥb+off[j].toNat+0∀j (h:j< ѧoff),Ѥb+off[j].toNat+7ὥ) (k:Ὣ) (hk:kf i.val)[k]! =f k:=by rw[Ἕ _ k (by simpa only[Array.size_ofFn] using hk),Array.getElem_ofFn] lemma qEb (z:Model Fmt):ofW (toWord z)=z:=by have h:z.toNatBits<2^32:=Model.toNatBits_lt_two_pow z;simp only[ofW,toWord,Model.ofUInt32,ὡ,Ἁ h];exact Model.ofNatBits_toNatBits z lemma qGw {w:ὥ} (h:expOf w≠255):Ἑ (ofW w)=true:=by simp only[ofW,isFinite_ofUInt32,bne_iff_ne,ne_eq,h,not_false_eq_true] lemma qEg (A B:ѐ) (hB:B.size=A.size) (hall:∀k,kexpOf A[k]!≠255/\expOf B[k]!≠255):finishWord (dsum A B 0 A.size) (-298) (decide (A.size≠0)&&dallNZ A B 0 A.size)=dotSpec A B:=by set L:=A.map (Model.ofUInt32 (fmt:=Fmt)) with hL set R:=B.map (Model.ofUInt32 (fmt:=Fmt)) with hR have hLR:L.size=R.size:=by simp only[hL,Array.size_map,hR,hB] have hLsize:L.size=A.size:=by simp only[hL,Array.size_map] have hLfin: ∀k (hk:k if m=0 then ⟨pos,ng,sp,nz&&neg⟩ else if neg then ⟨pos,addLimbs64 ng m.toUInt64 idx,sp,false⟩ else ⟨addLimbs64 pos m.toUInt64 idx,ng,sp,false⟩ lemma Acc.add_spec (acc:Acc) (m idx:Ὣ) (neg:Ὡ) (hp:acc.pos.size=18) (hn:acc.neg.size=18) (hm:m<2^64) (hi:idx/32+1<18):(acc.add m idx neg).pos.size=18/\(acc.add m idx neg).neg.size=18/\(acc.add m idx neg).special=acc.special/\(acc.add m idx neg).negZero=(acc.negZero&&(decide (m=0)&&neg))/\(acc.add m idx neg).total=acc.total+(if neg then-(m:Int) else m)*2^idx:=by obtain ⟨pos,ng,sp,nz⟩:=acc;simp only at hp hn;by_cases hm0:m=0;. simp only[add,hm0, ↓reduceIte,hp,hn,decide_true,Bool.true_and,total,CharP.cast_eq_zero,neg_zero,ite_self,zero_mul,add_zero,and_self] . cases neg;. refine ⟨by simp only[add,hm0, ↓reduceIte,false_eq_true,Nat.toUInt64_eq,addLimbs64_size,hp],by simp only[add,hm0, ↓reduceIte,false_eq_true,Nat.toUInt64_eq,hn],by simp only[add,hm0, ↓reduceIte,false_eq_true,Nat.toUInt64_eq],by simp only[add,hm0, ↓reduceIte,false_eq_true,Nat.toUInt64_eq,decide_false,Bool.and_self,Bool.and_false],?_⟩;simp only[Acc.add,hm0,ite_false,Bool.false_eq_true,addLimbs64_eq _ _ _ hm,Acc.total];rw[addLimbs_val _ _ _ (by clear hm hn hm0;exact omS3 hi hp)];push_cast;ring . refine ⟨by simp only[add,hm0, ↓reduceIte,Nat.toUInt64_eq,hp],by simp only[add,hm0, ↓reduceIte,Nat.toUInt64_eq,addLimbs64_size,hn],by simp only[add,hm0, ↓reduceIte,Nat.toUInt64_eq],by simp only[add,hm0, ↓reduceIte,Nat.toUInt64_eq,decide_false,Bool.and_true,Bool.and_false],?_⟩;simp only[Acc.add,hm0,ite_false,ite_true,addLimbs64_eq _ _ _ hm,Acc.total];rw[addLimbs_val _ _ _ (by clear hm hp hm0;exact omS3 hi hn)];push_cast;ring @[inline] def dotStep (acc:Acc) (wa wb:ὥ):Acc:= if expOf wa=255\/expOf wb=255 then ⟨acc.pos,acc.neg,true,acc.negZero⟩ else acc.add (mantOf wa*mantOf wb) (idxOf wa+idxOf wb) (Bool.xor (signOf wa) (signOf wb)) @[specialize] def dotLoop (fa fb:Ὣ->ὥ) (pos neg:ї) (sp nz:Ὡ) (index:Ὣ):Ὣ->Acc | 0=>⟨pos,neg,sp,nz⟩ | count+1=> match dotStep ⟨pos,neg,sp,nz⟩ (fa index) (fb index) with | ⟨p,n,s,z⟩=>dotLoop fa fb p n s z (index+1) count lemma qCb (fa fb:Ὣ->ὥ) (pos neg:ї) (nz:Ὡ) (index count:Ὣ):(dotLoop fa fb pos neg true nz index count).special=true:=by induction count generalizing pos neg nz index with | zero=>rfl | succ count ih=> rw[dotLoop];have hs:(dotStep ⟨pos,neg,true,nz⟩ (fa index) (fb index)).special=true:=by unfold dotStep Acc.add;split_ifs<;>rfl generalize dotStep ⟨pos,neg,true,nz⟩ (fa index) (fb index)=r at hs⊢;obtain ⟨p,q,s,z⟩:=r;simp only at hs;subst hs;exact ih .. lemma qC6 (fa fb:Ὣ->ὥ) (A B:ѐ) (n:Ὣ) (hA:∀k,kA[k]! =fa k) (hB:∀k,kB[k]! =fb k) (acc:Acc) (index remaining:Ὣ) (h:index+remaining<=n) (hp:acc.pos.size=18) (hn:acc.neg.size=18) (hfin:(dotLoop fa fb acc.pos acc.neg acc.special acc.negZero index remaining).special =false): (dotLoop fa fb acc.pos acc.neg acc.special acc.negZero index remaining).pos.size=18/\ (dotLoop fa fb acc.pos acc.neg acc.special acc.negZero index remaining).neg.size=18/\ acc.special=false/\ (∀k,index<=k->k< index+remaining->expOf A[k]!≠255/\expOf B[k]!≠255)/\ (dotLoop fa fb acc.pos acc.neg acc.special acc.negZero index remaining).total=acc.total+dsum A B index remaining/\ (dotLoop fa fb acc.pos acc.neg acc.special acc.negZero index remaining).negZero=(acc.negZero&&dallNZ A B index remaining):=by induction remaining generalizing acc index with | zero=>obtain ⟨p,n,s,z⟩:=acc;simp_all only[add_zero,dotLoop,ne_eq,isEmpty_Prop,not_lt,IsEmpty.forall_iff,implies_true,dsum,dallNZ,Bool.and_true,and_self] | succ count ih=> obtain ⟨p,q,s,z⟩:=acc simp only at hp hn have ha:=hA index (by clear hp hn;exact omS4 h) have hb:=hB index (by clear hp hn ha;exact omS4 h) by_cases he:expOf (fa index)=255\/expOf (fb index)=255 . exfalso;rw[dotLoop] at hfin;have hs:(dotStep ⟨p,q,s,z⟩ (fa index) (fb index)).special=true:=by simp only[dotStep,he, ↓reduceIte] generalize dotStep ⟨p,q,s,z⟩ (fa index) (fb index)=r at hs hfin;obtain ⟨p',q',s',z'⟩:=r;simp only at hs;subst hs;rw[qCb] at hfin;exact Bool.noConfusion hfin . have he':=not_or.mp he obtain ⟨h1,h2,h3,h4,h5⟩:= Acc.add_spec ⟨p,q,s,z⟩ (mantOf (fa index)*mantOf (fb index)) (idxOf (fa index)+idxOf (fb index)) (Bool.xor (signOf (fa index)) (signOf (fb index))) hp hn (mul_mant_lt _ _) (by have:=idxOf_le _ he'.1;have:=idxOf_le _ he'.2;(clear h hp hn ha hb he he';omega)) have hstep:dotStep ⟨p,q,s,z⟩ (fa index) (fb index)= Acc.add ⟨p,q,s,z⟩ (mantOf (fa index)*mantOf (fb index)) (idxOf (fa index)+idxOf (fb index)) (Bool.xor (signOf (fa index)) (signOf (fb index))):=by simp only[dotStep,he, ↓reduceIte] rw[dotLoop,hstep] at hfin⊢;obtain ⟨hP,hN,hs,hall,hD,hz⟩:=ih _ (index+1) (by clear hp hn ha hb he he' h1 h2 h5;exact omS5 h) h1 h2 hfin;refine ⟨hP,hN,by rw[<-h3,hs],?_,?_,?_⟩ . intro k k1 k2;rcases Nat.lt_or_ge k (index+1) with hk | hk;. have:k=index:=(by clear h hp hn ha hb he he' h1 h2 h5 hP hN hD k2;exact omS6 k1 hk);subst this;rw[ha,hb];exact he' . exact hall k hk (by clear h hp hn ha hb he he' h1 h2 h5 hP hN hD k1 hk;exact omS7 k2) . have sv2:(if Bool.xor (signOf (fa index)) (signOf (fb index)) then-((mantOf (fa index)*mantOf (fb index):Ὣ):Int) else ((mantOf (fa index)*mantOf (fb index):Ὣ):Int))=sv (fa index)*sv (fb index):=by unfold sv;cases signOf (fa index)<;>cases signOf (fb index)<;>simp only[bne_self_eq_false,false_eq_true, ↓reduceIte,Nat.cast_mul,Bool.bne_true,Bool.not_false,mul_neg,Bool.bne_false,neg_mul,neg_neg] rw[hD,h5,dsum,ha,hb,sv2];ring . rw[hz,h4,dallNZ,ha,hb];simp only[mul_eq_zero,Bool.decide_or,Bool.and_assoc] def Y_low (p q:ї) (k:Ὣ):Ὣ->Ὣ | 0=>k | f+1=>if p[k]! =0&&q[k]! =0 then Y_low p q (k+1) f else k lemma qD3 (p q:ї):∀f k,(∀j,jp[j]! =0/\q[j]! =0)-> ∀j,jp[j]! =0/\q[j]! =0:=by intro f;induction f with | zero=>exact λk h j hj=>h j hj | succ f ih=> intro k h j hj;unfold Y_low at hj;split at hj . rename_i hk;simp only[Bool.and_eq_true,decide_eq_true_eq] at hk;refine ih (k+1) (λi hi=>?_) j hj;rcases Nat.lt_or_ge i k with h1 | h1;. exact h i h1 . have:i=k:=(by clear hj hk;exact omS8 hi h1);subst this;exact hk . exact h j hj lemma qHd (L:љ):∀l,(∀j,jL[j]! =0)->limbVal L=2^(32*l)*limbVal (L.drop l):=by induction L with | nil=>simp only[List.length_nil,not_lt_zero,not_false_eq_true,ὑ,Nat.default_eq_zero,implies_true,limbVal,List.drop_nil,mul_zero,imp_self] | cons x xs ih=> intro l h;cases l with | zero=>simp only[mul_zero,pow_zero,List.drop_zero,one_mul] | succ l=> have h0:x=0:=by simpa only[List.length_cons,lt_add_iff_pos_left,Order.lt_add_one_iff,zero_le,Ἕ,List.getElem_cons_zero] using h 0 (by exact omS9) have:=ih l (λj hj=>by simpa only[List.getElem!_eq_getElem?_getD,Nat.default_eq_zero,List.getElem?_cons_succ] using h (j+1) (by exact Nat.lt_succ_of_le ‹_›));simp only[limbVal,List.drop_succ_cons,h0,this];rw[Nat.mul_add 32 l 1,pow_add];ring lemma qFr (A:ї) (l:Ὣ) (h:∀j,jA[j]! =0):limbVal A.toList=2^(32*l)*limbValA (A.extract l ѧA):=by rw[limbValA_eq,Array.toList_extract,List.extract_eq_drop_take,<-Array.length_toList];rw[List.take_of_length_le ג];refine qHd _ l λj hj=>?_;have:=h j hj;rw[getElem!_def] at this;simp only[getElem!_def] at*;cases e:A[j]?<;>simp_all only[Nat.default_eq_zero,getElem?_eq_none_iff,not_lt,Array.length_toList,getElem?_neg,Array.getElem?_toList] lemma qIo (S:Int) (l:Ὣ) (e:Int) (z:Ὡ):finishWord S (e+32*l) z=finishWord (2^(32*l)*S) e z:=by by_cases hS:S=0;. simp only[finishWord,hS, ↓reduceIte,mul_zero] have h2:(2:Int)^(32*l)*S≠0:=mul_ne_zero ו hS rw[finishWord_of_ne (ofIntDyadic (2^(32*l)*S) e) S (e+32*l) z hS (by rw[toRat_ofIntDyadic,Ἓ ו,show (32:ℤ)*l=((32*l:ℕ):ℤ) by push_cast;ring,Ἡ];push_cast;ring)] simp only[finishWord,h2, ↓reduceIte] @[inline] def dotFnO (n:Ὣ) (fa fb:Ὣ->ὥ):ὥ:= let acc:=dotLoop fa fb (ἇ 18 0) (ἇ 18 0) false true 0 n if acc.special then dotSpec (Array.ofFn (n:=n) λi=>fa i) (Array.ofFn (n:=n) λi=>fb i) else let l:=Y_low acc.pos acc.neg 0 18 finishWord ((limbValA (acc.pos.extract l 18):Int)-limbValA (acc.neg.extract l 18)) (-298+32*l) (n≠0&&acc.negZero) lemma qAiO:dotFnO=dotOf:=by funext n fa fb;unfold dotFnO dotOf;set A:=Array.ofFn (n:=n) λi=>fa i with hA;set B:=Array.ofFn (n:=n) λi=>fb i with hB;set acc:=dotLoop fa fb (ἇ 18 0) (ἇ 18 0) false true 0 n with hacc;by_cases hsp:acc.special=true;. simp only[hsp, ↓reduceIte] have hsp':acc.special=false:=by simpa only[Bool.not_eq_true] using hsp have hF:=qC6 fa fb A B n (qAb n fa) (qAb n fb) ⟨ἇ 18 0,ἇ 18 0,false,true⟩ 0 n (by exact omS10) ג ג hsp';obtain ⟨hP,hN,-,hall,hD,hz⟩:=hF;have hAs:ѧA=n:=by simp only[hA,Array.size_ofFn] have hBs:ѧB=n:=by simp only[hB,Array.size_ofFn] have hL:=qD3 acc.pos acc.neg 18 0 (λj hj=>absurd hj (Ἲ _));simp only[hsp',Bool.false_eq_true,ite_false];have e0:(⟨ἇ 18 0,ἇ 18 0,false,true⟩:Acc).total=0:=ה rw[e0,Int.zero_add] at hD;rw[Bool.true_and] at hz;generalize Y_low acc.pos acc.neg 0 18=l at hL⊢;have h1:=qFr acc.pos l (λj hj=>(hL j hj).1);have h2:=qFr acc.neg l (λj hj=>(hL j hj).2);rw[hP] at h1;rw[hN] at h2;rw[qIo,<-qEg A B (by clear hP hN hD e0 h1 h2;exact omS11 hAs hBs) (λk hk=>hall k (by exact Nat.zero_le _) (by clear hP hN hD e0 h1 h2;exact omS12 hAs hk)),hAs,<-hD,<-hz];congr 1;have:acc.total=(limbVal acc.pos.toList:Int)-limbVal acc.neg.toList:=rfl;rw[this,h1,h2];push_cast;ring @[inline] def dotFn (n:Ὣ) (fa fb:Ὣ->ὥ):ὥ:=FexK.fexDot n fa fb lemma qAi:dotFn=dotOf:=by funext n fa fb;exact FexK.fexDot_eq n fa fb lemma usz (t n:ὦ) (h:t=256 then 0x8000000000000000 else 0 if e==0 then Ἃ s else Ἃ (s ||| ((e+873)<<<(52:Ὠ))) def pw:ὤ:= (ἄ 512).foldl (λa i=>a.push (pwEntry i)) (ἆ 512) lemma qDx:pw.data=(ἄ 512).toArray.map pwEntry:=by have key:∀(l:љ) (a:ὤ),(l.foldl (λa i=>a.push (pwEntry i)) a).data=a.data++(l.toArray.map pwEntry):=by intro l;induction l with | nil=>intro a;simp only[List.foldl_nil,List.map_toArray,List.map_nil,Array.append_empty] | cons x l ih=>intro a;simp only[ὔ,ih];simp only[FloatArray.push,List.map_toArray,List.push_append_toArray,List.map_cons] simp only[pw,key];simp only[ἆ,List.toArray_range,Array.empty_append] lemma qGe:Ѩpw=512:=by simp only[FloatArray.size,qDx,List.toArray_range,Array.size_map,Array.size_range] lemma qCh (w:ὥ):(w>>>(23:ὥ)).toUSize.toNat< Ѩpw:=by rw[qGe];have h:=w.toNat_lt_size;simp only[ὃ,UInt32.toNat_shiftRight];norm_num[Ἱ] at h⊢;exact omS13 h def pwEntryN (z k i:Ὣ):ὧ:= if i%256a.push (pwEntryN z k i)) (ἆ 512) lemma qDj (z k:Ὣ):(pwTb z k).data=(ἄ 512).toArray.map (pwEntryN z k):=by have key:∀(l:љ) (a:ὤ),(l.foldl (λa i=>a.push (pwEntryN z k i)) a).data=a.data++(l.toArray.map (pwEntryN z k)):=by intro l;induction l with | nil=>intro a;simp only[List.foldl_nil,List.map_toArray,List.map_nil,Array.append_empty] | cons x l ih=>intro a;simp only[ὔ,ih];simp only[FloatArray.push,List.map_toArray,List.push_append_toArray,List.map_cons] simp only[pwTb,key];simp only[ἆ,List.toArray_range,Array.empty_append] lemma qTd (z k:Ὣ):(pwTb z k).size=512:=by simp only[FloatArray.size,qDj,Array.size_map,List.size_toArray,List.length_range] lemma qBx {T:ὤ} (hT:ѨT=512) (w:ὥ):(w>>>(23:ὥ)).toUSize.toNat< ѨT:=by rw[hT];have h:=w.toNat_lt_size;simp only[ὃ,UInt32.toNat_shiftRight];norm_num[Ἱ,UInt32.size] at h⊢;(clear hT;exact omS13 h) def tZa:ὤ:=pwTb 0 125 def tZb:ὤ:=pwTb 0 126 def tZc:ὤ:=pwTb 0 127 def tZd:ὤ:=pwTb 0 128 @[inline] def tZ (n:Ὣ):ὤ:=if 256<=n then tZa else if 64<=n then tZb else if 16<=n then tZc else tZd @[inline] def hvI (n:Ὣ):ὥ:=if 256<=n then 0x3E7FFFFF else if 64<=n then 0x3EFFFFFF else if 16<=n then 0x3F7FFFFF else 0x3FFFFFFF lemma qFz (z k:Ὣ) (i:ὦ) (h:Ѥi<(pwTb z k).size):(pwTb z k).uget i h=pwEntryN z k Ѥi:=by simp only[FloatArray.uget,qDj,List.toArray_range,Array.ugetElem_eq_getElem,Array.getElem_map,Array.getElem_range] def TOK (z:Ὣ) (T:ὤ) (h:ὥ):Prop:=∃k,ѨT=512/\(∀(i:ὦ) (p:Ѥi< ѨT),T.uget i p=pwEntryN z k Ѥi)/\2<=k/\k<=128/\ѥh+1=k*2^23 lemma qTs {z:Ὣ} {T:ὤ} {h:ὥ} (o:TOK z T h):ѨT=512:=by obtain ⟨k,e,-⟩:=o;exact e lemma qTZ (n:Ὣ):TOK 0 (tZ n) (hvI n):=by unfold tZ hvI;split . exact ⟨125,qTd _ _,qFz _ _,by (norm_num1),by (norm_num1),rfl⟩ . split . exact ⟨126,qTd _ _,qFz _ _,by (norm_num1),by (norm_num1),rfl⟩ . split . exact ⟨127,qTd _ _,qFz _ _,by (norm_num1),by (norm_num1),rfl⟩ . exact ⟨128,qTd _ _,qFz _ _,by (norm_num1),by (norm_num1),rfl⟩ @[inline] def dv (w:ὥ):ὧ:= ((w&&&0x7FFFFF) ||| 0x800000).toFloat*pw.uget (w>>>(23:ὥ)).toUSize (qCh w) @[inline] def dvB (v:ὧ) (w:ὥ):ὧ:= (v*pw.uget (w>>>(23:ὥ)).toUSize (qCh w))*((w&&&0x7FFFFF) ||| 0x800000).toFloat @[inline] def good (w:ὥ):Ὡ:= let v:=w&&&В v==0 || v-(0x00800000:ὥ)<=(0x7EFFFFFF:ὥ) def scan (A:ѐ) (n i:ὦ) (hn:Ѥn<=ѧA) (lo hi:ὥ):ὥ:= if h:it∉L->X[i*I+t]!&&&В=0 rd:∀k p:Ὣ,L[k]?=some p-> (ix[k]!:ὥ).toNat=p/\x.data[k]! =dv X[i*I+p]! ok:l=L.foldl (λ(a:ὧ) t=>a+(dv X[i*I+t]!).abs) 0 lemma qAc (a:ѐ):a.usize.toNat<=ѧa:=by simp only[Array.usize,Nat.toUSize_eq,USize.toNat_ofNat'];exact Nat.mod_le _ _ @[inline] def scanH (r:Ὣ) (A:ѐ):ὥ:= let h:=if r==1 then scanF A A.usize 0 (qAc A) 0 Е else Е if h==Е then scan A A.usize 0 (qAc A) Е 0 else h @[inline] def scanW (r:Ὣ) (A:ѐ):ὥ:= if r==8 || r==1 || r==4 then 0 else scanH r A def pushZ (n k:ὦ) (a:ὤ):ὤ:= if h:k>>(29:Ὠ) let y:Ὠ:=(B+(0x0FFFFFFF:Ὠ))>>>(29:Ὠ) let ex:Ὠ:=(x>>>(23:Ὠ))&&&(0x7FF:Ὠ) if x==y&&ex-(897:Ὠ)<(254:Ὠ) then (((x>>>(34:Ὠ))<<<(31:Ὠ)) ||| ((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<(23:Ὠ)))).toUInt32 else Е @[inline] def ziv (s e:ὧ):ὥ:= zivW (s+e).toBits (s-e).toBits @[noinline] def slowOut (inW:Ὣ) (relu:Ὡ) (X W b:@& ё) (i j:Ὣ):Ὢ:= act relu (dotFn (inW+1) (λt=>if t< inW then X[i*inW+t]! else oneW) (λt=>if t< inW then W[j*inW+t]! else b[j]!)) @[inline] def fin (inW:Ὣ) (relu:Ὡ) (X W b:ё) (i j:Ὣ) (s nf t:ὧ) (bw:ὥ):ὥ:= let bv:=dv bw let r:=ziv (s+bv) (nf*(t+bv.abs)) if r==Е then slowOut inW relu X W b i j else act relu r local instance ecNe0:Nonempty F1:=⟨by constructor <;> exact default⟩ def tightGo (X W:ѐ) (xo wo n t:ὦ) (s a:ὧ):F1:= if h:t>>(31:ὥ))-1)) def thOf (e:ὧ):Ὠ:= let E:=(e.toBits>>>(52:Ὠ))&&&0x7FF if E-1<1900 then (E+35)<<<(53:Ὠ) else 0xFFFFFFFFFFFFFFFF @[inline] def zivC (x:Ὠ):ὥ:= (((x>>>(34:Ὠ))<<<(31:Ὠ)) ||| ((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<(23:Ὠ)))).toUInt32 def loOf (e:ὧ):Ὠ:= let th:=thOf e if th<0x7040000000000000 then 0x7040000000000000 else th def spOf (lo:Ὠ):Ὠ:= if lo<0x8FA0000000000000 then 0x8FA0000000000000-lo else 0 def spR (relu:Ὡ) (lo:Ὠ):Ὠ:=if relu then 0 else spOf lo @[inline] def fin1 (lo sp:Ὠ) (s:ὧ):ὥ:= let w:=s.toBits let u:=w+0x0FDFFFFF if (w<<<(1:Ὠ))-lo>>(29:Ὠ)) else Е @[inline] def fz (relu:Ὡ) (r:ὥ):ὥ:=r&&&((if relu then (0:ὥ) else Е) ||| ((r>>>(31:ὥ))-1)) @[noinline] def fin8n (inW:Ὣ) (relu:Ὡ) (X W b:@& ё) (i j:Ὣ) (s nf a:ὧ) (hx bw:ὥ) (n:ὦ):ὥ:=fin8 inW relu X W b i j s nf a hx bw n @[inline] def fin8L (inW:Ὣ) (relu:Ὡ) (X W b:ё) (i j:Ὣ) (s nf a:ὧ) (hx:ὥ) (lo:Ὠ) (bw:ὥ) (n:ὦ):ὥ:= let t:=fin1 lo (spOf lo) (s+dv bw) if t==Е then fin8n inW relu X W b i j s nf a hx bw n else fz relu t structure R2 where (buf:ὤ) (l:ὧ) (ok:Ὡ) local instance ecNe1:Nonempty R2:=⟨by constructor <;> exact default⟩ def decD (X:ѐ) (o n t:ὦ) (buf:ὤ) (l:ὧ):R2:= if h:tk.val.toUInt32) lemma wi (w i m:ὦ) (W:ѐ) (hw:Ѥw+Ѥm<=ѧW) (hs:ѧW<2^32) (hi:Ѥi< Ѥm):(w+i).toNat< ѧW:=by rw[qAf _ _ (by exact omS14 hw hs hi)];(clear hs;exact omS15 hw hi) def armT:Ὡ:=System.Platform.target.startsWith "aarch64" local instance ecNe2:Nonempty F4:=⟨by constructor <;> exact default⟩ def go4B (x:ὤ) (ix W:ѐ) (w0 w1 w2 w3 m n t:ὦ) (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hs:ѧW<2^32) (h0:Ѥw0+Ѥm<=ѧW) (h1:Ѥw1+Ѥm<=ѧW) (h2:Ѥw2+Ѥm<=ѧW) (h3:Ѥw3+Ѥm<=ѧW) (a b c d:ὧ):F4:= if h:t exact default⟩ def go8V (x wb:ὤ) (p m n t:ὦ) (hx:Ѥn<=Ѩx) (hn:Ѥn<=Ѥm) (hb:Ѥp+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (a b c d e f g k:ὧ):G8:= if h:t exact default⟩ def go24V (x wb:ὤ) (p p' p'' m n t:ὦ) (hx:Ѥn<=Ѩx) (hn:Ѥn<=Ѥm) (hb:Ѥp+8*Ѥm<=Ѩwb) (hb':Ѥp'+8*Ѥm<=Ѩwb) (hb'':Ѥp''+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (a b c d e f g k a' b' c' d' e' f' g' k' a'' b'' c'' d'' e'' f'' g'' k'':ὧ):G24:= if h:t exact default⟩ def go16V (x wb:ὤ) (p p' m n t:ὦ) (hx:Ѥn<=Ѩx) (hn:Ѥn<=Ѥm) (hb:Ѥp+8*Ѥm<=Ѩwb) (hb':Ѥp'+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (a b c d e f g k a' b' c' d' e' f' g' k':ὧ):G16:= if h:t have h:¬tby have:=А.mp h;omega rw[go16V,go8V,go8V,ἔ h,ἔ h,ἔ h];rfl | succ N ih=> have h:t have h:¬tby have:=А.mp h;omega rw[go24V,go8V,go8V,go8V,ἔ h,ἔ h,ἔ h,ἔ h];rfl | succ N ih=> have h:t have h:¬tby have:=А.mp h;omega rw[go16F,go8F,go8F,ἔ h,ἔ h,ἔ h];rfl | succ N ih=> have h:t have h:¬tby have:=А.mp h;omega rw[go24F,go8F,go8F,go8F,ἔ h,ἔ h,ἔ h,ἔ h];rfl | succ N ih=> have h:tὧ | 0=>r.a | 1=>r.b | 2=>r.c | 3=>r.d | 4=>r.e | 5=>r.f | 6=>r.g | _=>r.k def cols1T (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (i:Ὣ) (nf a:ὧ) (hx:ὥ) (lo:Ὠ) (m:ὦ) (rr:G8) (j0 j:Ὣ) (base:ὦ) (out:ѐ):ѐ:= if h4:j+4<=outW then let ju:=ѩj let o0:=fin8L inW relu X W b i j (C_g8 rr (j-j0)) nf a hx lo (rdW b ju) m let o1:=fin8L inW relu X W b i (j+1) (C_g8 rr (j+1-j0)) nf a hx lo (rdW b (ju+1)) m let o2:=fin8L inW relu X W b i (j+2) (C_g8 rr (j+2-j0)) nf a hx lo (rdW b (ju+2)) m let o3:=fin8L inW relu X W b i (j+3) (C_g8 rr (j+3-j0)) nf a hx lo (rdW b (ju+3)) m let out:=wrW out (base+ju) o0 let out:=wrW out (base+ju+1) o1 let out:=wrW out (base+ju+2) o2 let out:=wrW out (base+ju+3) o3 cols1T inW outW relu X W b i nf a hx lo m rr j0 (j+4) base out else if h1:j>>(23:ὥ)).toUSize (qBx hT w) lemma xi (xs:ὤ) (i t n:ὦ) (k:Ὣ) (hk:k<8) (ht:Ѥt< Ѥn) (hi:Ѥi=8*Ѥt+1) (hx:8*Ѥn+1<=Ѩxs) (hs:Ѩxs<2^32):(i+ὴ k).toNat< Ѩxs:=by rw[qAf _ _ (by rw[uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)];exact omS23 hk ht hi hx hs),uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)];(clear hs;exact omS24 hk ht hi hx) local instance ecNe6:Nonempty F8:=⟨by constructor <;> exact default⟩ def go8Z (T:ὤ) (hT:ѨT=512) (xs:ὤ) (W:ѐ) (wo n t i:ὦ) (hx:8*Ѥn+1<=Ѩxs) (hsx:Ѩxs<2^32) (hs:ѧW<2^32) (hw:Ѥwo+Ѥn<=ѧW) (hi:Ѥi=8*Ѥt+1) (s0 s1 s2 s3 s4 s5 s6 s7:ὧ) (q:ὥ) (r:F8):F8:= if h:t⟨u,s0,s1,s2,s3,s4,s5,s6,s7,0,q⟩ partial_fixpoint def zA:ὤ:=pushZ 32 0 (ἆ 32) def z0:ὤ:=pushZ 128 0 (ἆ 128) def zB:ὤ:=pushZ 256 0 (ἆ 256) def zC:ὤ:=pushZ 512 0 (ἆ 512) def z1:ὤ:=pushZ 1024 0 (ἆ 1024) def z4:ὤ:=pushZ 4096 0 (ἆ 4096) def z8:ὤ:=pushZ 8192 0 (ἆ 8192) @[inline] def zFor (m:Ὣ):ὤ:= if m<=32 then zA else if m<=128 then z0 else if m<=256 then zB else if m<=512 then zC else if m<=1024 then z1 else if m<=4096 then z4 else if m<=8192 then z8 else pushZ ѩm 0 (ἆ m) @[inline] def wr8 (xs:ὤ) (i:ὦ) (a0 a1 a2 a3 a4 a5 a6 a7:ὧ):ὤ:= wrF (wrF (wrF (wrF (wrF (wrF (wrF (wrF xs (i+ὴ 0) a0) (i+ὴ 1) a1) (i+ὴ 2) a2) (i+ὴ 3) a3) (i+ὴ 4) a4) (i+ὴ 5) a5) (i+ὴ 6) a6) (i+ὴ 7) a7 def go8ZD (D:ὤ) (xs:ὤ) (W:ѐ) (hd:ѨD=ѧW) (wo n t i:ὦ) (hx:8*Ѥn+1<=Ѩxs) (hsx:Ѩxs<2^32) (hs:ѧW<2^32) (hw:Ѥwo+Ѥn<=ѧW) (hi:Ѥi=8*Ѥt+1) (s0 s1 s2 s3 s4 s5 s6 s7:ὧ) (q:ὥ) (r:F8):F8:= if h:t⟨u,s0,s1,s2,s3,s4,s5,s6,s7,0,q⟩ partial_fixpoint def go8ZS (D:ὤ) (xs:ὤ) (W:ѐ) (hd:ѨD=ѧW) (wo n t i:ὦ) (hx:8*Ѥn+1<=Ѩxs) (hsx:Ѩxs<2^32) (hs:ѧW<2^32) (hw:Ѥwo+Ѥn<=ѧW) (hi:Ѥi=8*Ѥt+1) (s0 s1 s2 s3 s4 s5 s6 s7:ὧ) (q:ὥ) (r:F8):F8:= if h:armT/\t rw[go8ZS];split . rename_i h;have:=usz t n h.2.1;have:=usz (t+1) n h.2.2;have:=А.mp h.2.2 rw[ih _ (by clear hi h;omega) (t+1+1) _ _ _ _ _ _ _ _ _ _ _ rfl];simp only[go8ZD.eq_1 D xs W hd wo n t,go8ZD.eq_1 D xs W hd wo n (t+1),Ἄ h.2.1,Ἄ h.2.2] . rfl def dnOf (T:ὤ) (hT:ѨT=512) (W:ѐ):ὤ:=⟨W.map (dvN T hT)⟩ lemma dnFoldL (f:ὥ->ὧ):∀(l:List ὥ) (a:ὤ),l.foldl (λa w=>a.push (f w)) a=⟨a.data++(l.map f).toArray⟩:=by intro l;induction l with | nil=>intro a;cases a;simp only[List.foldl_nil,List.map_nil,Array.append_empty] | cons x xs ih=>intro a;rw[ὔ,ih];cases a;simp only[FloatArray.push,List.push_append_toArray,List.map_cons] lemma dnFold (f:ὥ->ὧ) (W:ѐ):W.foldl (λa w=>a.push (f w)) (ἆ W.size)=⟨W.map f⟩:=by rw[<-Array.foldl_toList,dnFoldL];simp only[ἆ,List.append_toArray,List.nil_append,FloatArray.mk.injEq];apply Array.ext';simp only[Array.toList_map] @[inline] def nE (n:Ὣ) (W:ѐ):Ὣ:=let h:=scanH 2 W;if h<=hvI n then n else if h<=0x3EFFFFFF then 64 else if h<=0x3F7FFFFF then 16 else 0 def qScan (W:ѐ) (e i:ὦ) (q:ὥ):ὥ:= if h:iSubtype.ext (a.2.trans b.2.symm)⟩ structure WE8 where (w:ѐ) (n:Ὣ) (p:ὤ×ὥ×Ὣ) (g:ὦ) (ok:p=(dnOf (tZ (nE n w)) (qTs (qTZ (nE n w))) w,qScan w w.usize 0 Е,nE n w)) def wd8F (n:Ὣ) (W:ѐ) (g:ὦ) (s:Array WE8) (i:Ὣ):Option (WV8 n W):= if h:is[i].w==W) (λe=>by rw[e];exact beq_self_eq_true W) then some ⟨s[i].p,by rw[<-hn,<-eq_of_beq hk];exact s[i].ok⟩ else wd8F n W g s (i+1) else wd8F n W g s (i+1) else wd8F n W g s (i+1) else none partial_fixpoint @[noinline] def wd8S:ST.Ref Unit (Array WE8):=(ST.Prim.mkRef #[] (Void.mk ())).val @[inline] def wd8Get (n:Ὣ) (W:ѐ):WV8 n W:= withPtrAddr W (λg=> let s:=(ST.Prim.Ref.get wd8S (Void.mk ())).val match wd8F n W g s 0 with | some v=>v | none=> let p:=(dnOf (tZ (nE n W)) (qTs (qTZ (nE n W))) W,qScan W W.usize 0 Е,nE n W) let old:=(ST.Prim.Ref.swap wd8S (#[⟨W,n,p,g,rfl⟩]++(if s.size<256 then s else s.pop)) (Void.mk ())).val match wd8F n W g old 0 with | some v=>v | none=>⟨p,rfl⟩) (λ_ _=>Subsingleton.elim _ _) lemma dnU (T:ὤ) (hT:ѨT=512) (W:ѐ) (j:ὦ) (h1:Ѥj<(dnOf T hT W).size) (h2:Ѥj<ѧW):(dnOf T hT W).uget j h1=dvN T hT (W.uget j h2):=by simp only[FloatArray.uget,dnOf,Array.ugetElem_eq_getElem,Array.getElem_map,Array.uget] lemma g8ZE (T:ὤ) (hT:ѨT=512) (xs:ὤ) (W:ѐ) (hd:(dnOf T hT W).size=ѧW) (wo n t i:ὦ) (hx:8*Ѥn+1<=Ѩxs) (hsx:Ѩxs<2^32) (hs:ѧW<2^32) (hw:Ѥwo+Ѥn<=ѧW) (hi:Ѥi=8*Ѥt+1) (s0 s1 s2 s3 s4 s5 s6 s7:ὧ) (q q':ὥ) (r r':F8): go8ZD (dnOf T hT W) xs W hd wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q' r'=F8q (go8Z T hT xs W wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q r) r'.u q':=by rw[go8ZD,go8Z];by_cases h:tSubtype.ext (a.2.trans b.2.symm)⟩ structure WEB where (w:ѐ) (m o:Ὣ) (p:ὤ×ὥ) (g:ὦ) (ok:p=(wbOf m o w,scanH 2 w)) def wbF (m o:Ὣ) (W:ѐ) (g:ὦ) (s:Array WEB) (i:Ὣ):Option (WVB m o W):= if h:is[i].w==W) (λe=>by rw[e];exact beq_self_eq_true W) then some ⟨s[i].p,by rw[<-ho.1,<-ho.2,<-eq_of_beq hk];exact s[i].ok⟩ else wbF m o W g s (i+1) else wbF m o W g s (i+1) else wbF m o W g s (i+1) else none partial_fixpoint @[noinline] def wbS:ST.Ref Unit (Array WEB):=(ST.Prim.mkRef #[] (Void.mk ())).val @[inline] def wbGet (m o:Ὣ) (W:ѐ):WVB m o W:= withPtrAddr W (λg=> let s:=(ST.Prim.Ref.get wbS (Void.mk ())).val match wbF m o W g s 0 with | some v=>v | none=> let p:=(wbOf m o W,scanH 2 W) let old:=(ST.Prim.Ref.swap wbS (#[⟨W,m,o,p,g,rfl⟩]++(if s.size<256 then s else s.pop)) (Void.mk ())).val match wbF m o W g old 0 with | some v=>v | none=>⟨p,rfl⟩) (λ_ _=>Subsingleton.elim _ _) lemma qUs (a:ὤ) (i:ὦ) (v:ὧ) (h:Ѥi< Ѩa):(a.uset i v h).size=Ѩa:=by obtain ⟨ds⟩:=a;exact Array.size_uset _ def decE (X:ѐ) (o n t:ὦ) (buf:ὤ) (l:ὧ) (hX:Ѥo+Ѥn<=ѧX) (hs:ѧX<2^32) (hb:Ѥn<=Ѩbuf):R2:= if h:t exact default⟩ def decV (X:ѐ) (o n t:ὦ) (buf:ὤ) (l:ὧ) (lo hi:ὥ) (hX:Ѥo+Ѥn<=ѧX) (hs:ѧX<2^32) (hb:Ѥn<=Ѩbuf):R3:= if h:ta.push (dv w)) (ἆ b.size) lemma bOfF_eq (b:ѐ):bOfF b=bOf b:=dnFold _ b abbrev WVN (m o:Ὣ) (W b:ѐ):=({p:(ὤ×ὥ)×(ὤ×ὥ)//p=((wbOf m o W,scanH 2 W),(bOf b,scanH 1 b))}) structure WEN where (w b:ѐ) (m o:Ὣ) (p:(ὤ×ὥ)×(ὤ×ὥ)) (g:ὦ) (ok:p=((wbOf m o w,scanH 2 w),(bOf b,scanH 1 b))) def wnF (m o:Ὣ) (W b:ѐ) (g:ὦ) (s:Array WEN) (i:Ὣ):Option (WVN m o W b):= if h:is[i].w==W) (λe=>by rw[e];exact beq_self_eq_true W) then if hk2:withPtrEq s[i].b b (λ_=>s[i].b==b) (λe=>by rw[e];exact beq_self_eq_true b) then some ⟨s[i].p,by rw[<-ho.1,<-ho.2,<-eq_of_beq hk,<-eq_of_beq hk2];exact s[i].ok⟩ else wnF m o W b g s (i+1) else wnF m o W b g s (i+1) else wnF m o W b g s (i+1) else wnF m o W b g s (i+1) else none partial_fixpoint @[noinline] def wnS:ST.Ref Unit (Array WEN):=(ST.Prim.mkRef #[] (Void.mk ())).val @[inline] def wnGet (m o:Ὣ) (W b:ѐ):WVN m o W b:= withPtrAddr W (λg=> let s:=(ST.Prim.Ref.get wnS (Void.mk ())).val match wnF m o W b g s 0 with | some v=>v | none=> let p:=((wbOf m o W,scanH 2 W),(bOfF b,scanH 1 b)) let old:=(ST.Prim.Ref.swap wnS (#[⟨W,b,m,o,p,g,(congrArg (((wbOf m o W,scanH 2 W),·)) (congrArg (·,scanH 1 b) (bOfF_eq b)))⟩]++(if s.size<256 then s else s.pop)) (Void.mk ())).val match wnF m o W b g old 0 with | some v=>v | none=>⟨p,(congrArg (((wbOf m o W,scanH 2 W),·)) (congrArg (·,scanH 1 b) (bOfF_eq b)))⟩) (λ_ _=>Subsingleton.elim _ _) @[inline] def rdB (a:ὤ) (i:ὦ):ὧ:= if h:iὦ->ὤ->ѐ->ὦ->ὧ->ὥ->ὥ->(ὤ×ѐ)×(ὦ×ὧ)×(ὥ×ὥ) | 0,_,buf,ix,c,l,lo,hi=>((buf,ix),(c,l),(lo,hi)) | f+1,t,buf,ix,c,l,lo,hi=> if h:tὩ | 0=>true | f+1=>if rdW X i&&&В==0 then zgL X s (i+s) nz f else if nz==0 then false else zgL X s (i+s) (nz-1) f def linZc (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (c:(ὤ×ὥ)×(ὤ×ὥ)) (nf:ὧ) (n:ὦ) (z:ὤ) (hX:Ѥn<=ѧX):ѐ:= let r:=decZ X n hX Ѥn 0 z (ἇ Ѥn 0) 0 0 Е 0 if 0x007FFFFF<=r.2.2.1/\r.2.2.2<У then cols1W inW outW relu X W b 0 r.1.2 r.1.1 (ἆ 0) c.1.1 nf r.2.1.2 c.1.2 (loOf (nf*(dv c.1.2*r.2.1.2+dv c.2.2))) n r.2.1.1 0 (0*outW).toUSize (ἇ (1*outW) 0) else linF0 1 inW outW relu X W b @[noinline] def linNc (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (c:@& ((ὤ×ὥ)×(ὤ×ὥ))):ѐ:= if 1*inW=ѧX/\outW*inW=ѧW/\outW=ѧb/\0< inW/\0ὥ) (bw:ὥ):ℝ:= (Ἣ n).sum (λt=>wv (xw t)*wv (ww t))+wv bw def nfOf (n:Ὣ):ὧ:=(n.toUInt64+8).toFloat*Ἃ 0x3CA0000000000000 structure C_G (R I O:Ὣ) (X W b:ё):Prop where hX:R*I=ѧX hW:O*I=ѧW hb:O=ѧb pi:0good X[q]! =true gW:∀q,q< ѧW->good W[q]! =true gb:∀q,q< ѧb->good b[q]! =true lemma qAj:⟡.isIEEE=true:=ה lemma qAy (a:Model ⟡):Ἑ a=(Model.toModel a).isFinite:=by rw[<-Model.toDyadic?_isSome_eq_isFinite,Model.toDyadic?_ieee_eq_model _ qAj];cases Model.toModel a<;>rfl abbrev A_M (x:ὧ):Model ⟡:=Model.ofFloatModel x.toModel lemma A_R (x:ὧ):R x=Ἢ (A_M x):=rfl lemma qAh (x:ὧ):Ἑ (A_M x)=x.isFinite:=by rw[qAy,Ὀ];rfl lemma qA3 {x:ὧ} (h:xᶠ):Ἑ (A_M x)=true:=(qAh x).trans h lemma qA0 (e:ℤ):Formats.Flocq.bpow ἲ e=(2:ℝ)^e:=by simp only[Formats.Flocq.bpow,FloatLib.Numerics.Radix.toReal,ἲ,Nat.cast_ofNat] lemma qCd:(2:ℝ)^(1000:ℤ)<=Ἢ (Model.posMaxFinite ⟡):=by rw[Model.toReal_posMaxFinite,show Model.pow2 ⟡.fracWidth+⟡.maxFiniteFracField=2^53-1 by decide+kernel, show ⟡.maxNormalExponent-Int.ofNat ⟡.fracWidth=971 by decide+kernel,Model.bpow,qA0,show (1000:ℤ)=29+971 from rfl,Ἓ ἓ] exact ἀ (by norm_num1) ו open Float.Model.UnpackedFloat in lemma qDv {b:BitVec 64} {s m e h} (a:unpack ⟠ b=.finite s m e h):2^52<=m\/e=-1074:=by unfold Ἶ at a;simp only at a;rw[show (⟠.exponentBias:ℤ)=1023 by decide] at a;split_ifs at a with h1 h2 h3;. injection a with _ _ he;rw[show (unpackExponent (spec:=⟠) b).toNat=0 by simp only[h3,BitVec.toNat_ofNat,Nat.reducePow,Nat.zero_mod]] at he;exact omS27 he . injection a with _ hm;rw[<-hm,BitVec.toNat_append];exact .inl (ὂ (by simp only[Nat.reducePow,BitVec.toNat_ofNat,pow_one,Nat.mod_succ,ὁ,one_mul,Std.le_refl]) Nat.left_le_or) open Float.Model.UnpackedFloat in lemma qH1 {s₁ s₂ m₁ m₂ e₁ e₂ h₁ h₂} {f g:BitVec 64} (e:unpack ⟠ f=.finite s₁ m₁ e₁ h₁) (b:unpack ⟠ g=.finite s₂ m₂ e₂ h₂): e₁+e₂<=⟠.targetExponent (Float.Model.totalExponent (m₁*m₂) (e₁+e₂)):=by have a:2^52<=m₁*m₂->52<=(m₁*m₂).log2:=(Nat.le_log2 (Nat.mul_ne_zero h₁.ne' h₂.ne')).2 simp only[Float.Model.Format.targetExponent,Float.Model.totalExponent,Float.Model.Format.mantissaBits,Float.Model.Format.minExponent] (norm_num1) rcases qDv e with c | c . have:=a (c.trans (Ὄ _ h₂));(clear c;omega) rcases qDv b with d | d . have:=a (d.trans (Nat.le_mul_of_pos_left _ h₁));(clear d;omega) omega lemma qB0 (x y:ὧ) (a:xᶠ) (b:yᶠ):A_M (x*y)=Model.mul (A_M x) (A_M y):=by change Model.ofFloatModel (Float.Model.mul x.toModel y.toModel)=_;rw[Float.Model.mul,Model.ofFloatModel_pack,Model.Proof.mul_eq_spec,Model.Spec.mul];simp only[Model.toDyadic?_ieee_eq_model _ qAj,Model.toModel_ofFloatModel];change x.toModel.unpack.isFinite=true at a;change y.toModel.unpack.isFinite=true at b;have c:∀s t:Float.Model.UnpackedFloat.Sign,Model.ofModel ⟡ (.zero (s*t))=Model.zero _ (Ἴ s ^^ Ἴ t):=λs t=>by cases s<;>cases t<;>simp only[Model.modelSignBit,bne_self_eq_false,FloatFormat.isIEEE_binary64,Model.zero_eq_signedZero_of_isIEEE,false_eq_true, ↓reduceIte,Bool.bne_false,Bool.bne_true,Bool.not_false]<;>first | exact (Model.negZero_eq_ofModel_zero _).symm | exact (Model.posZero_eq_ofModel_zero _).symm cases hxm:x.toModel.unpack<;>cases hym:y.toModel.unpack<;>simp only[hxm,hym,Float.Model.UnpackedFloat.isFinite,Bool.false_eq_true] at a b case finite.finite s₁ m₁ e₁ h₁ s₂ m₂ e₂ h₂=> have d:(m₁==0 || m₂==0)=false:=by simp only[Bool.or_eq_false_iff,beq_eq_false_iff_ne,ne_eq,h₁.ne',not_false_eq_true,h₂.ne',and_self] have e:Model.modelSign (Ἴ s₁ ^^ Ἴ s₂)=s₁*s₂:=by cases s₁<;>cases s₂<;>rfl simp only[Model.unpackedToDyadic?,Float.Model.UnpackedFloat.mul];rw[Model.roundWithAccuracy_exact_eq_round_of_le_targetExponent _ _ _ _ (qH1 hxm hym),d];simp only[Bool.false_eq_true,ite_false,Model.roundDyadic,qAj,ite_true,Model.ieeeRoundDyadic,e];rfl all_goals simp only[Float.Model.UnpackedFloat.mul,c,FloatFormat.isIEEE_binary64,Model.zero_eq_signedZero_of_isIEEE,bne_iff_ne,ne_eq,ite_not,Model.unpackedToDyadic?,BEq.rfl,Bool.or_self, ↓reduceIte,Bool.true_or,Bool.or_true] lemma A_E (z:ὧ) {a:Model ⟡} {c:ℝ} (h:A_M z=a) (b:Ἑ a=true) (d:Ἢ a=Model.roundAt ⟡ c):zᶠ/\R z=Model.roundAt ⟡ c:=by subst h;exact ⟨(qAh z).symm.trans b,d⟩ lemma qEd (x y:ὧ) (hx:xᶠ) (hy:yᶠ) (hb: |R x| * |R y| <=2^(1000:ℤ)): (x*y)ᶠ /\R (x*y)=Model.roundAt ⟡ (R x*R y):= A_E _ (qB0 x y hx hy) (Model.isFinite_mul_of_abs_mul_le_posMaxFinite _ _ qAj (qA3 hx) (qA3 hy) (hb.trans qCd)) (Model.toReal_mul_eq_roundAt_of_abs_mul_le_posMaxFinite _ _ qAj (qA3 hx) (qA3 hy) (hb.trans qCd)) noncomputable def A_z:ℝ:=2^(-1021:ℤ) noncomputable def A_B:ℝ:=2^(300:ℤ) lemma qAr:0simp only[Float.Model.UnpackedFloat.isFinite,hu,false_eq_true] at hf | zero s=>rw[hu] at a;refine ⟨by rw[<-qAh,a];exact Model.isFinite_ofModel_zero _ qAj _,?_⟩;rw[A_R f.abs,a,qBk f,hu];simp only[Float.Model.UnpackedFloat.abs,Model.toReal_ofModel_zero _ (FloatFormat.supportsSignedZero_eq_true_of_isIEEE _ qAj),Model.unpackedToReal_zero,abs_zero] | finite s m e h=>have b:=qE0 hu;rw[hu] at a;have c:A_M f.abs=Model.ofModel ⟡ (.finite .positive m e h):=a;refine ⟨by rw[<-qAh,c,qAy,b];rfl,?_⟩;rw[A_R f.abs,c,qBk f,hu,ἦ qAj,b];simp only[Model.unpackedToReal_finite,qA0];cases s<;>simp only[Model.modelSignBit,false_eq_true, ↓reduceIte,one_mul,neg_mul,abs_neg,ἅ (by positivity:(0:ℝ)<=(m:ℝ)*2^e)] lemma qCl (f:ὧ) (k:ℕ) (g:k<2^53) (e:f.toModel=Float.Model.pack (Float.Model.UnpackedFloat.ofNat ⟠ k)):fᶠ/\R f=k:=by obtain ⟨d,b,c⟩:∃d,A_M f=ἕ ⟡ d/\d.toReal=k:=by refine ⟨.ofScaledInt k 0,?_,?_⟩;. change Model.ofFloatModel f.toModel=_;rw[e,Model.ofFloatModel_pack];exact Model.ofModel_ofInt_eq_roundDyadic _ qAj (k:ℤ) . rw[<-Ἠ,FloatLib.Numerics.Dyadic.ofScaledInt_toRat];simp only[Rat.ofInt_eq_cast,Int.cast_natCast,zpow_ofNat,pow_zero,mul_one,Rat.cast_natCast] have a:Ἑ (A_M f)=true:=by rw[b];apply Model.isFinite_roundDyadic_of_isIEEE_of_abs_toReal_le_posMaxFinite _ qAj;rw[c,ἅ (Ἔ _)];exact ((qE7 ((by exact Nat.le_of_lt (Nat.lt_of_lt_of_le ‹_› ה)):k<=2^128)).trans ((le_mul_of_one_le_right qI1.le one_le_two).trans qE3)).trans qCd refine ⟨(qAh f).symm.trans a,?_⟩;rw[A_R,b,Model.toReal_roundDyadic_eq_roundAt _ qAj _ (b▸a),c];simpa only[Int.cast_natCast,zpow_ofNat,pow_zero,mul_one] using qA2 k 0 (by simpa only[Int.natAbs_natCast,Nat.reducePow] using g) (by norm_num1) lemma qCk (m:Ὠ) (h:Ѧm<2^53):m.toFloatᶠ/\R m.toFloat=Ѧm:=qCl _ _ h rfl lemma qHg:(0:ὧ)ᶠ/\R 0=0:=by simpa only[CharP.cast_eq_zero] using qCl 0 0 ו rfl def A_bits (i:ℕ):Ὠ:= let e:=(i%256).toUInt64 let s:Ὠ:=if i>=256 then 0x8000000000000000 else 0 if e==0 then s else s ||| ((e+873)<<<(52:Ὠ)) lemma qCu (i:ℕ):pwEntry i=Ἃ (A_bits i):=by unfold pwEntry A_bits;dsimp only;split<;>rfl def A_chk (i:ℕ):Ὡ:= match Ἶ ⟠ (A_bits i).toBitVec with | .finite s m e _=>(Ἴ s==decide (256<=i))&&m==2^52&& e==((i%256:ℕ):ℤ)-202&&(i%256 != 0) | .zero _=>i%256==0 | _=>false lemma qEm:∀i,i<512->A_chk i=true:=by decide+kernel lemma qDa (i:ℕ) (b:i<512): (pwEntry i)ᶠ/\R (pwEntry i)=if i%256=0 then 0 else (if 256<=i then-1 else 1)*2^(((i%256:ℕ):ℤ)-150):=by have a:=qEm i b unfold A_chk at a rw[qCu,qBk] change (Ἃ (A_bits i)).toModel.unpack.isFinite=true/\_ rw[show (Ἃ (A_bits i)).toModel.unpack=Ἶ ⟠ (A_bits i).toBitVec from Model.unpack_pack_unpack _ _] generalize Ἶ ⟠ (A_bits i).toBitVec=u at a cases u with | notANumber | infinity _=>simp only[false_eq_true] at a | zero s=> simp only[beq_iff_eq] at a exact ⟨rfl,by simp only[Model.unpackedToReal_zero,a, ↓reduceIte]⟩ | finite s m e h=> simp only[Bool.and_eq_true,beq_iff_eq,bne_iff_ne] at a obtain ⟨⟨⟨g,d⟩,f⟩,c⟩:=a refine ⟨rfl,?_⟩ rw[Model.unpackedToReal_finite,qA0,f,g,d,mul_assoc, show ((2^52:ℕ):ℝ)*2^(((i%256:ℕ):ℤ)-202)=2^(((i%256:ℕ):ℤ)-150) by rw[Nat.cast_pow,Nat.cast_ofNat,<-Ἡ,<-Ἓ ἓ] congr 1 push_cast ring] simp only[decide_eq_true_eq,c,↓reduceIte] lemma qCw (i:ℕ) (a:i<512):∃σ:ℤ,σ.natAbs<=1/\R (pwEntry i)=σ*2^(((i%256:ℕ):ℤ)-150):=by rw[(qDa i a).2];split_ifs;exacts [⟨0,by (positivity),by simp only[Int.cast_zero,Int.natCast_emod,Nat.cast_ofNat,zero_mul]⟩,⟨-1,by (norm_num1),by simp only[Int.natCast_emod,Nat.cast_ofNat,neg_mul,one_mul,Int.reduceNeg,Int.cast_neg,Int.cast_one]⟩,⟨1,by (norm_num1),by simp only[Int.natCast_emod,Nat.cast_ofNat,one_mul,Int.cast_one]⟩] lemma qCm (f:ὧ) (i:ℕ) (g:i<512) (q:fᶠ) (c k:ℤ) (r:c.natAbs<2^53) (s:-900<=k) (m: |R f| <=A_B) (l:R f=c*2^k):(f*pwEntry i)ᶠ/\R (f*pwEntry i)=R f*R (pwEntry i):=by obtain ⟨b,a,d⟩:=qCw i g;have o:((i%256:ℕ):ℤ)-150<=128/\-150<=((i%256:ℕ):ℤ)-150:=(by clear g r s a;exact omS28);generalize ((i%256:ℕ):ℤ)-150=E at o d;have p: |(b:ℝ)| <=1:=by rw[<-Int.cast_abs,<-Nat.cast_natAbs];exact_mod_cast a have e:=ἵ (two_pos (α:=ℝ)) E;have h: |R (pwEntry i)| <=A_B:=by rw[d,ἢ,ἡ e,<-one_mul A_B];exact ἑ p (ἒ one_le_two (by clear g r s a;exact omS29 o)) e.le zero_le_one obtain ⟨j,n⟩:=qEd f _ q (qDa i g).1 ((ἑ m h (Ἀ _) qI1.le).trans qDe);refine ⟨j,?_⟩ have:=qA2 (c*b) (k+E) (by rw[Int.natAbs_mul];have:=Nat.mul_le_mul_left c.natAbs a (clear g s a o;omega)) (by clear g r a;exact omS30 s o) rw[Ἓ ἓ] at this;push_cast at this;rw[n,d,l,show (c:ℝ)*2^k*(b*2^E)=c*b*(2^k*2^E) by ring];exact this lemma qDc (i:ὦ) (h:Ѥi< Ѩpw):pw.uget i h=pwEntry Ѥi:=by simp only[FloatArray.uget,qDx,List.toArray_range,Array.ugetElem_eq_getElem,Array.getElem_map,Array.getElem_range] section variable (w:ὥ) include w lemma qAq:(w&&&В).toNat=ѥw%2^31:=by rw[Ἧ];exact Ἂ ѥw 31 lemma qCo:(w&&&0x7FFFFF).toNat=ѥw%2^23:=by rw[Ἧ];exact Ἂ ѥw 23 lemma qD8:(w>>>23).toNat=ѥw/2^23:=by rw[UInt32.toNat_shiftRight,Ἱ];rfl lemma qCa:(expOf w).toNat=ѥw/2^23%2^8:=by unfold expOf;rw[Ἧ,qD8];exact Ἂ _ 8 lemma qGl:signOf w=decide (2^31<=ѥw):=by have b:=w.toNat_lt;unfold signOf;have h:((w&&&س).toNat)=(ѥw/2^31%2)*2^31:=by rw[Ἧ];show ѥw&&&2^31=_;rw[Nat.and_two_pow,Nat.testBit_eq_decide_div_mod_eq];have a:ѥw/2^31%2=0\/ѥw/2^31%2=1:=(by clear b;exact omS31);rcases a with a | a<;>rw[a]<;>rfl rw[Bool.eq_iff_iff];simp only[bne_iff_ne,ne_eq,decide_eq_true_eq];rw[<-ἠ,h];simp only[UInt32.toNat_zero];exact omS32 b lemma qHa:((w&&&0x7FFFFF) ||| 0x800000).toNat=2^23+ѥw%2^23:=by rw[UInt32.toNat_or,qCo,Nat.or_comm];simpa only[UInt32.reduceToNat,Nat.reducePow,mul_one] using (Nat.two_pow_add_eq_or_of_lt (ὀ ѥw (by positivity:2^23>0)) 1).symm lemma qAz (h:good w=true): ѥw%2^31=0\/(2^23<=ѥw%2^31/\ѥw%2^31<У):=by have a:=qAq w;have b:=(w&&&В).toNat_lt;unfold good at h;simp only[Bool.or_eq_true,beq_iff_eq,decide_eq_true_eq] at h;rcases h with h | h;. left;rw[<-a,h];rfl . right;rw[ἃ,UInt32.toNat_sub] at h;rw[<-a];generalize (w&&&В).toNat=v at*;simp only[Nat.reducePow,UInt32.reduceToNat,Nat.reduceSub] at h;(clear b;exact omS33 a h) lemma qAe (h:good w=true):expOf w≠255:=by intro he;have a:=qCa w;rw[he] at a;change 255=_ at a;have:=qAz w h;have:=w.toNat_lt;(clear he this;exact omS34 a this) end noncomputable def A_mag (v:ℕ):ℝ:= if v=0 then 0 else ((2^23+v%2^23:ℕ):ℝ)*2^(((v/2^23:ℕ):ℤ)-150) lemma qAs (v:ℕ):0<=A_mag v:=by unfold A_mag;split_ifs<;>positivity lemma qA7 (w:ὥ) (hg:good w=true):wv w=(if 2^31<=ѥw then-1 else 1)*A_mag (ѥw%2^31):=by have g:=w.toNat_lt;have:=qAz w hg;have a:=qCa w;have d:(fracOf w).toNat=ѥw%2^23:=qCo w;have f:wv w=(decodeD w).toReal:=by unfold wv ofW;rw[Model.toReal_eq,ἶ w (qAe w hg)] rw[f];unfold decodeD A_mag;by_cases c:ѥw%2^31=0;. have b:expOf w=0:=ἠ.mp (by rw[a];show _=0;(clear g this;exact omS35 c));have e:fracOf w=0:=ἠ.mp (by rw[d];show _=0;(clear g this a b;exact omS36 c));simp only[b,e,c,↓reduceIte];simp only[FloatLib.Numerics.Dyadic.toReal,signedSignificand,Int.ofNat_eq_natCast,CharP.cast_eq_zero,neg_zero,ite_self,Int.cast_zero,zpow_ofNat,pow_zero,mul_one,Nat.reducePow,mul_zero] . have b:expOf w≠0:=λh=>by rw[h] at a;change 0=_ at a;(clear g h;exact omS37 this c a) simp only[b,c,↓reduceIte];rw[show ѥw%2^31%2^23=(fracOf w).toNat by rw[d];(clear g this a c b;exact omS38),show ѥw%2^31/2^23=(expOf w).toNat by rw[a];(clear g this c b;exact omS39)];simp only[FloatLib.Numerics.Dyadic.toReal,FloatLib.Numerics.Dyadic.signedSignificand,qGl];simp only[Nat.reducePow,decide_eq_true_eq,Int.ofNat_eq_natCast,Nat.cast_add,Nat.cast_ofNat,neg_add_rev,Int.reduceNeg,Int.cast_ite,Int.cast_add,Int.cast_neg,Int.cast_natCast,Int.cast_ofNat,ite_mul,neg_mul,one_mul];split_ifs<;>ring lemma qFb (v:ℕ) (h:v<У):A_mag v<=2^128:=by unfold A_mag;split_ifs with h0;. positivity . exact (ἑ (show ((2^23+v%2^23:ℕ):ℝ)<=((2^24:ℕ):ℝ) from Nat.cast_le.2 (by clear h h0;exact omS40)) (ἒ one_le_two (by (clear h0;exact omS41 h):_<=(104:ℤ))) ו ו).trans_eq (by norm_num1) lemma qA6 (a b:ℕ) (hab:a<=b) (ha:a=0\/2^23<=a):A_mag a<=A_mag b:=by rcases ha with rfl | ha;. simpa only[A_mag, ↓reduceIte,Nat.reducePow,Nat.cast_add,Nat.cast_ofNat,Int.natCast_ediv] using qAs b unfold A_mag;simp only[show ¬a=0 by (clear hab;exact omS42 ha),show ¬b=0 by exact omS43 hab ha,↓reduceIte];have c:a/2^23<=b/2^23:=Nat.div_le_div_right hab;rcases c.eq_or_lt with d | g;. rw[d];exact ἀ (Nat.cast_le.2 (by clear ha c;exact omS44 hab d)) ו . have e:(2:ℝ)^(((a/2^23:ℕ):ℤ)-150)*2<=2^(((b/2^23:ℕ):ℤ)-150):=by rw[<-zpow_add_one₀ ἓ];exact ἒ one_le_two (by clear hab ha c;exact omS45 g) have f:((2^23:ℕ):ℝ)<=((2^23+b%2^23:ℕ):ℝ):=Nat.cast_le.2 (by clear hab ha c g;exact omS46) calc _<=((2^23*2:ℕ):ℝ)*2^(((a/2^23:ℕ):ℤ)-150):= ἀ (Nat.cast_le.2 (by clear hab ha c g;exact omS47)) ו _=((2^23:ℕ):ℝ)*(2^(((a/2^23:ℕ):ℤ)-150)*2):=by push_cast;ring _<=_:=ἑ f e ו ו abbrev A_mf (w:ὥ):ὧ:=((w&&&0x7FFFFF) ||| 0x800000).toFloat lemma qD1 (w:ὥ):pw.uget (w>>>23).toUSize (qCh w)=pwEntry (ѥw/2^23)/\ѥw/2^23<512/\(A_mf w)ᶠ /\(A_mf w*pwEntry (ѥw/2^23))ᶠ /\R (A_mf w*pwEntry (ѥw/2^23))=R (A_mf w)*R (pwEntry (ѥw/2^23))/\R (A_mf w)=((2^23+ѥw%2^23:ℕ):ℝ):=by have g:=w.toNat_lt;have c:=qHa w;obtain ⟨d,a⟩:=qCl (A_mf w) _ (by rw[c];(clear g;(clear c;exact omS48))) rfl;rw[c] at a;have b:ѥw/2^23<512:=(by exact omS49 g) obtain ⟨f,e⟩:=qCm _ _ b d ((2^23+ѥw%2^23:ℕ):ℤ) 0 (by clear g b;(clear c;omega)) (by norm_num1) (by rw[a,ἅ (Ἔ _)] exact qE7 (by clear g b;(clear c;exact omS51))) (by rw[a,zpow_zero,mul_one,Int.cast_natCast]) refine ⟨?_,b,d,f,e,a⟩;rw[qDc,ὃ,qD8] lemma qDvF (w:ὥ):(dv w)ᶠ:=by obtain ⟨g,-,-,e,-,-⟩:=qD1 w;unfold dv;rw[g];exact e lemma qAm (w:ὥ) (hg:good w=true):(dv w)ᶠ/\R (dv w)=wv w:=by obtain ⟨g,a,-,e,d,c⟩:=qD1 w;have j:=w.toNat_lt;unfold dv;rw[g];refine ⟨e,?_⟩;rw[d,c,(qDa _ a).2,qA7 w hg];have b:=qAz w hg;generalize ѥw=v at*;rcases b with h | ⟨l,k⟩;. rw[h];simp only[show v/2^23%256=0 by (clear a j;exact omS52 h),↓reduceIte,mul_zero,show A_mag 0=0 by simp only[A_mag, ↓reduceIte]] . have f:(256<=v/2^23)↔2^31<=v:=(by exact omS53);unfold A_mag;rw[((by clear a j f;exact omS54):v%2^31/2^23=v/2^23%256),((by clear a j l k f;exact omS38):v%2^31%2^23=v%2^23),ἐ ((by clear a j f;exact omS55 l):¬v/2^23%256=0),ἐ ((by clear a j f;exact omS56 l):¬v%2^31=0)];by_cases i:2^31<=v<;>simp only[f,i,↓reduceIte]<;>ring lemma zFn0 (m:ℤ) (e:ℤ) (k:ℕ) (z:Float.Model.UnpackedFloat.Sign): Float.Model.UnpackedFloat.normalize ⟠ (m*2^k) (e-k) z=Float.Model.UnpackedFloat.normalize ⟠ m e z:=by have hk:(0:ℤ)<2^k:=ו unfold Float.Model.UnpackedFloat.normalize rcases lt_trichotomy m 0 with h | h | h . have h1:m*2^k<0:=Int.mul_neg_of_neg_of_pos h hk have c1:compare m 0=.lt:=by simp only[compare,compareOfLessAndEq,h, ↓reduceIte] have c2:compare (m*2^k) 0=.lt:=by simp only[compare,compareOfLessAndEq,h1, ↓reduceIte] rw[c1,c2];dsimp only have e2:(-(m*2^k)).toNat=(-m).toNat*2^k:=by have e1:-(m*2^k)=(((-m).toNat*2^k:ℕ):ℤ):=by push_cast;rw[Int.toNat_of_nonneg א];ring rw[e1,Int.toNat_natCast] rw[e2];exact ExactRuntime.round_scale ⟠ .negative _ e k א . subst h;simp only[zero_mul,Std.compare_self] . have h1:0< m*2^k:=Int.mul_pos h hk have c1:compare m 0=.gt:=by simp only[compare,compareOfLessAndEq,Int.not_lt.2 h.le, ↓reduceIte,h.ne'] have c2:compare (m*2^k) 0=.gt:=by simp only[compare,compareOfLessAndEq,Int.not_lt.2 h1.le, ↓reduceIte,h1.ne'] rw[c1,c2];dsimp only have e2:(m*2^k).toNat=m.toNat*2^k:=by have e1:m*2^k=((m.toNat*2^k:ℕ):ℤ):=by push_cast;rw[Int.toNat_of_nonneg א] rw[e1,Int.toNat_natCast] rw[e2];exact ExactRuntime.round_scale ⟠ .positive _ e k א lemma zFn1 (u u' f f':ℤ) (z:Float.Model.UnpackedFloat.Sign) (h:(u:ℝ)*2^f=(u':ℝ)*2^f'): Float.Model.UnpackedFloat.normalize ⟠ u f z=Float.Model.UnpackedFloat.normalize ⟠ u' f' z:=by obtain ⟨a,ha⟩:∃a:ℕ,f=min f f'+a:=⟨(f-min f f').toNat,א⟩ obtain ⟨b,hb⟩:∃b:ℕ,f'=min f f'+b:=⟨(f'-min f f').toNat,א⟩ have e1:=zFn0 u f a z have e2:=zFn0 u' f' b z rw[show f-a=min f f' by omega] at e1 rw[show f'-b=min f f' by omega] at e2 rw[<-e1,<-e2] congr 1 have h2:((u*2^a:ℤ):ℝ)*2^(min f f')=((u'*2^b:ℤ):ℝ)*2^(min f f'):=by have h':(u:ℝ)*2^(min f f'+(a:ℤ))=(u':ℝ)*2^(min f f'+(b:ℤ)):=by rw[<-ha,<-hb];exact h rw[Ἓ ἓ,Ἓ ἓ,Ἡ,Ἡ] at h' push_cast linarith only[h'] exact_mod_cast mul_right_cancel₀ ו h2 lemma zFd0 (m:ℕ) (e L:ℤ): (((Float.Model.UnpackedFloat.decreaseExponent m e L).1:ℕ):ℝ)*2^((Float.Model.UnpackedFloat.decreaseExponent m e L).2)=(m:ℝ)*2^e:=by unfold Float.Model.UnpackedFloat.decreaseExponent dsimp only rw[ὁ] push_cast rw[mul_assoc,<-Ἡ,<-Ἓ ἓ] congr 2 ring lemma zFd1 (m:ℕ) (e L:ℤ) (h:L<=e):(Float.Model.UnpackedFloat.decreaseExponent m e L).2=L:=by unfold Float.Model.UnpackedFloat.decreaseExponent;dsimp only;omega lemma zFd2 (m:ℕ) (e L:ℤ) (h:L<=e): ((((Float.Model.UnpackedFloat.decreaseExponent m e L).1:ℕ):ℤ):ℝ)*2^L=(m:ℝ)*2^e:=by have h0:=zFd0 m e L;rw[zFd1 m e L h] at h0;rw[Int.cast_natCast];exact h0 lemma zFs (s:Float.Model.UnpackedFloat.Sign) (n:ℤ):((s.apply n:ℤ):ℝ)=(if s=.negative then-1 else 1)*(n:ℝ):=by cases s<;>simp only[Float.Model.UnpackedFloat.Sign.apply,Int.cast_neg, ↓reduceIte,neg_mul,one_mul,reduceCtorEq] lemma zFz (s:Float.Model.UnpackedFloat.Sign):Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ (.zero s))=.zero s:=by cases s<;>rfl lemma zFf (s1 s2 s3:Float.Model.UnpackedFloat.Sign) (m1 m2 m3:ℕ) (e1 e2 e3:ℤ) (h1 h2 h3): Float.Model.UnpackedFloat.fma ⟠ (.finite s1 m1 e1 h1) (.finite s2 m2 e2 h2) (.finite s3 m3 e3 h3)= Float.Model.UnpackedFloat.normalize ⟠ ((s1*s2).apply ((Float.Model.UnpackedFloat.decreaseExponent (m1*m2) (e1+e2) (min (e1+e2) e3)).1:ℤ)+ s3.apply ((Float.Model.UnpackedFloat.decreaseExponent m3 e3 (min (e1+e2) e3)).1:ℤ)) (min (e1+e2) e3) .positive:=rfl lemma zFa (s1 s2:Float.Model.UnpackedFloat.Sign) (m1 m2:ℕ) (e1 e2:ℤ) (h1 h2): Float.Model.UnpackedFloat.add ⟠ (.finite s1 m1 e1 h1) (.finite s2 m2 e2 h2)= Float.Model.UnpackedFloat.normalize ⟠ (s1.apply ((Float.Model.UnpackedFloat.decreaseExponent m1 e1 (min e1 e2)).1:ℤ)+ s2.apply ((Float.Model.UnpackedFloat.decreaseExponent m2 e2 (min e1 e2)).1:ℤ)) (min e1 e2) .positive:=rfl lemma zFp (v:Float.Model):Float.Model.pack v.unpack=v:= FloatLib.Floats.Formats.BinaryInterchange.Model.toFloatModel_ofFloatModel v lemma zFM (x w a:Float.Model) (hx:x.unpack.isFinite=true) (hw:w.unpack.isFinite=true) (HP:∀s1 m1 e1 h1 s2 m2 e2 h2,x.unpack=.finite s1 m1 e1 h1->w.unpack=.finite s2 m2 e2 h2-> ∃M E h,(Float.Model.mul x w).unpack=.finite (s1*s2) M E h/\(M:ℝ)*2^E=((m1*m2:ℕ):ℝ)*2^(e1+e2)): Float.Model.fma x w a=Float.Model.add a (Float.Model.mul x w):=by have hP:(Float.Model.mul x w).unpack=Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ (Float.Model.UnpackedFloat.mul ⟠ x.unpack w.unpack)):=by simp only[Float.Model.unpack,Float.Model.mul,Float.Model.pack,UInt64.toBitVec_ofBitVec] unfold Float.Model.fma Float.Model.add cases hxu:x.unpack<;>cases hwu:w.unpack<;>simp only[hxu,hwu,Float.Model.UnpackedFloat.isFinite,Bool.false_eq_true] at hx hw case zero.zero s1 s2=> rw[hP,hxu,hwu] show _=Float.Model.pack (Float.Model.UnpackedFloat.add ⟠ a.unpack (Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ (.zero (s1*s2))))) rw[zFz] cases a.unpack with | zero s3=>cases s1<;>cases s2<;>cases s3<;>rfl | _=>rfl case zero.finite s1 s2 m2 e2 h2=> rw[hP,hxu,hwu] show _=Float.Model.pack (Float.Model.UnpackedFloat.add ⟠ a.unpack (Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ (.zero (s1*s2))))) rw[zFz] cases a.unpack with | zero s3=>cases s1<;>cases s2<;>cases s3<;>rfl | _=>rfl case finite.zero s1 m1 e1 h1 s2=> rw[hP,hxu,hwu] show _=Float.Model.pack (Float.Model.UnpackedFloat.add ⟠ a.unpack (Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ (.zero (s1*s2))))) rw[zFz] cases a.unpack with | zero s3=>cases s1<;>cases s2<;>cases s3<;>rfl | _=>rfl case finite.finite s1 m1 e1 h1 s2 m2 e2 h2=> obtain ⟨M,E,hM,hPU,hv⟩:=HP s1 m1 e1 h1 s2 m2 e2 h2 hxu hwu rw[hPU] cases ha:a.unpack with | notANumber=>rfl | infinity s3=>rfl | zero s3=> show Float.Model.pack (Float.Model.UnpackedFloat.mul ⟠ (.finite s1 m1 e1 h1) (.finite s2 m2 e2 h2))=Float.Model.pack (.finite (s1*s2) M E hM) rw[<-hPU,zFp] unfold Float.Model.mul rw[hxu,hwu] | finite s3 m3 e3 h3=> rw[zFf,zFa] congr 1 apply zFn1 push_cast rw[zFs,zFs,zFs,zFs,add_mul,add_mul,mul_assoc,mul_assoc,mul_assoc,mul_assoc, zFd2 _ _ _ (min_le_left _ _),zFd2 _ _ _ (min_le_right _ _),zFd2 _ _ _ (min_le_left _ _),zFd2 _ _ _ (min_le_right _ _),hv] push_cast;ring lemma zFR (f:ὧ) {s m e h} (hf:f.toModel.unpack=.finite s m e h):R f=(if Ἴ s then (-1:ℝ) else 1)*(m:ℝ)*2^e:=by rw[qBk,hf,FloatLib.Floats.Formats.BinaryInterchange.Model.unpackedToReal_finite,qA0] lemma zFH (x w:ὧ) (hf:(x*w)ᶠ) (hr:R (x*w)=R x*R w): ∀s1 m1 e1 h1 s2 m2 e2 h2,x.toModel.unpack=.finite s1 m1 e1 h1->w.toModel.unpack=.finite s2 m2 e2 h2-> ∃M E h,(Float.Model.mul x.toModel w.toModel).unpack=.finite (s1*s2) M E h/\(M:ℝ)*2^E=((m1*m2:ℕ):ℝ)*2^(e1+e2):=by intro s1 m1 e1 h1 s2 m2 e2 h2 hx hw have rx:=zFR x hx have rw':=zFR w hw have hm:(x*w).toModel=Float.Model.mul x.toModel w.toModel:=rfl change (x*w).toModel.unpack.isFinite=true at hf have q1:(0:ℝ)< m1:=by exact_mod_cast h1 have q2:(0:ℝ)< m2:=by exact_mod_cast h2 have p1:0<(m1:ℝ)*m2*2^(e1+e2):=ו cases hp:(Float.Model.mul x.toModel w.toModel).unpack with | notANumber=>rw[hm,hp] at hf;exact absurd hf (by simp only[Float.Model.UnpackedFloat.isFinite,false_eq_true,not_false_eq_true]) | infinity s=>rw[hm,hp] at hf;exact absurd hf (by simp only[Float.Model.UnpackedFloat.isFinite,false_eq_true,not_false_eq_true]) | zero s=> exfalso have r0:=qBk (x*w) rw[hm,hp,FloatLib.Floats.Formats.BinaryInterchange.Model.unpackedToReal_zero,hr,rx,rw'] at r0 have k:(if Ἴ s1 then (-1:ℝ) else 1)*(if Ἴ s2 then (-1:ℝ) else 1)*((m1:ℝ)*m2*2^(e1+e2))=0:=by rw[Ἓ ἓ];linear_combination r0 cases s1<;>cases s2<;>simp only[Ἴ,if_true,if_false,Bool.false_eq_true] at k<;>linarith only[p1,k] | finite s M E hM=> have rp:=zFR (x*w) (hm▸hp) rw[hr,rx,rw'] at rp have q3:(0:ℝ)cases s1<;>cases s2<;>simp only[Ἴ,if_true,if_false,Bool.false_eq_true] at k<;>first|exact ⟨M,E,hM,rfl,by linarith only[k]⟩|(exfalso;linarith only[p1,p2,k]) lemma zFdr (u:ὥ):(dv u)ᶠ/\∃c k:ℤ,R (dv u)=(c:ℝ)*2^k/\c.natAbs<2^24/\-150<=k/\k<=105:=by obtain ⟨g,a,-,e,d,c⟩:=qD1 u obtain ⟨σ,hσ,hp⟩:=qCw _ a have E:dv u=A_mf u*pwEntry (ѥu/2^23):=by unfold dv;rw[g] rw[E];refine ⟨e,((2^23+ѥu%2^23:ℕ):ℤ)*σ,((ѥu/2^23%256:ℕ):ℤ)-150,?_,?_,א,?_⟩ . rw[d,c,hp,Int.cast_mul,Int.cast_natCast];ring . rw[Int.natAbs_mul,Int.natAbs_natCast];have:=ὀ (ѥu) (show 2^23>0 by positivity);have:=Nat.mul_le_mul_left (2^23+ѥu%2^23) hσ;omega . have:=ὀ (ѥu/2^23) (show 256>0 by positivity);omega lemma zFdv (u w:ὥ):(dv u*dv w)ᶠ/\R (dv u*dv w)=R (dv u)*R (dv w):=by obtain ⟨fu,c,k,ru,hc,hk0,hk⟩:=zFdr u obtain ⟨fw,c',k',rw',hc',hk0',hk'⟩:=zFdr w have B:∀(c k:ℤ),c.natAbs<2^24->k<=105->|(c:ℝ)*2^k|<=2^(129:ℤ):=λc k h1 h2=>by rw[ἢ,ἡ (by positivity:(0:ℝ)<2^k)] have h3:|(c:ℝ)|<=2^24:=by rw[<-Int.cast_abs,<-Int.natCast_natAbs];exact_mod_cast h1.le calc |(c:ℝ)| *2^k<=2^24*2^(105:ℤ):=ἑ h3 (ἒ one_le_two h2) ו ו _=2^(129:ℤ):=ב obtain ⟨f,r⟩:=qEd _ _ fu fw (by rw[ru,rw'];calc |(c:ℝ)*2^k| * |(c':ℝ)*2^k'|<=2^(129:ℤ)*2^(129:ℤ):=ἑ (B c k hc hk) (B c' k' hc' hk') (Ἀ _) ו _<=2^(1000:ℤ):=by rw[<-Ἓ ἓ];exact ἒ one_le_two ב) refine ⟨f,?_⟩ have e2:(c:ℝ)*2^k*((c':ℝ)*2^k')=((c*c':ℤ):ℝ)*2^(k+k'):=by push_cast;rw[Ἓ ἓ];ring rw[r,ru,rw',e2] exact qA2 _ _ (by rw[Int.natAbs_mul];have:=Nat.mul_lt_mul'' hc hc';exact Ἥ this ב) א lemma zFV (u w:ὥ) (a:ὧ):Float.fma (dv u) (dv w) a=a+dv u*dv w:=by obtain ⟨f,r⟩:=zFdv u w show Float.ofModel (Float.Model.fma (dv u).toModel (dv w).toModel a.toModel)=Float.ofModel (Float.Model.add a.toModel (Float.Model.mul (dv u).toModel (dv w).toModel)) rw[zFM _ _ _ (qDvF u) (qDvF w) (zFH _ _ f r)] lemma zFE {v w:ὧ} (hv:∃u,v=dv u) (hw:∃u,w=dv u) (a:ὧ):Float.fma v w a=a+v*w:=by obtain ⟨u,rfl⟩:=hv;obtain ⟨u',rfl⟩:=hw;exact zFV u u' a def A_fsum (l:List ὧ):ὧ:=l.foldl (.+·) 0 noncomputable def A_sa (l:List ὧ):ℝ:=(l.map λq=>|R q|).sum noncomputable def A_sr (l:List ὧ):ℝ:=(l.map R).sum lemma qC4 {a:Type} (l:List a) (f:a->ℝ):0<=(l.map λq=>|f q|).sum:=List.sum_nonneg (by simp only[List.mem_map];rintro _ ⟨q,_,rfl⟩;exact Ἀ _) lemma qCe (l:List ὧ):0<=A_sa l:=qC4 l R lemma qGr (l:List ὧ) (q:ὧ):A_sa (l++[q])=A_sa l+ |R q| /\A_sr (l++[q])=A_sr l+R q/\A_fsum (l++[q])=A_fsum l+q:=by simp only[A_sa,List.map_append,List.map_cons,List.map_nil,List.sum_append,List.sum_cons,List.sum_nil,add_zero,A_sr,A_fsum,List.foldl_append,ὔ,List.foldl_nil,and_self] lemma qC7 (l:List ὧ): |A_sr l| <=A_sa l:=by induction l with | nil=>simp only[A_sr,List.map_nil,List.sum_nil,abs_zero,A_sa,Std.le_refl] | cons q l ih=>simp only[A_sa,A_sr,List.map_cons,List.sum_cons] at ih⊢;exact (Ἐ _ _).trans (by linarith only[ih]) lemma qBo:A_z<=1:=qAw.trans (by norm_num1) section variable (l:List ὧ) (hf:∀ q∈l,qᶠ) (hlen:ѣl<=2^21) (hb:A_sa l<=A_B/4) include l hf hlen hb lemma qDd: (A_fsum l)ᶠ /\ |R (A_fsum l)-A_sr l| <=(1+1/2^22)*ѣl*(1/2^53*(A_sa l+A_z)):=by have e2AB6:A_B/4<=A_B:=div_le_self qI1.le ב induction l using List.reverseRecOn with | nil=>exact ⟨qHg.1,by simp only[A_fsum,List.foldl_nil,qHg.2,A_sr,List.map_nil,List.sum_nil,sub_self,abs_zero,one_div,List.length_nil,CharP.cast_eq_zero,mul_zero,zero_mul,Std.le_refl]⟩ | append_singleton l q ih=> obtain ⟨e,f,n⟩:=qGr l q rw[e] at hb rw[List.length_append,List.length_singleton] at hlen have t:=qCe l have j:=Ἀ (R q) obtain ⟨h,v⟩:=ih (λx i=>hf x (by simp only[List.mem_append,i,List.mem_cons,List.not_mem_nil,or_false,true_or])) (by exact Nat.le_of_lt ‹_›) ((le_add_of_nonneg_right j).trans hb) have u:(ѣl:ℝ)+1<=2^21:=by exact_mod_cast hlen have d:(0:ℝ)<=ѣl:=Ἔ _ have y:=qC7 l have o:=qAr have m:=qBo have p:=qAn have s:=Ὥ (R (A_fsum l)) (A_sr l) have w:=ἀ ((le_add_of_nonneg_right zero_le_one).trans u:(ѣl:ℝ)<=2^21) (add_nonneg t o.le) obtain ⟨b,z⟩:=qBf _ q h (hf q ג) (by linarith only[hb,j,v,y,m,p,s,w]) ((le_add_of_nonneg_left t).trans (hb.trans e2AB6)) rw[n,e,f,List.length_append,List.length_singleton] refine ⟨b,?_⟩ push_cast generalize R (A_fsum l)=r at* generalize R q=a at* generalize A_sa l=P at* generalize A_sr l=S at* generalize (ѣl:ℝ)=k at* obtain ⟨W,g⟩:∃W:ℝ,W=1/2^53*(P+ |a| +A_z):=⟨_,rfl⟩ have c:0<=W:=(Ἆ (one_div_nonneg.mpr (pow_nonneg zero_le_two 53)) (add_nonneg (add_nonneg t j) o.le)).trans_eq g.symm rw[<-g] refine (abs_sub_le _ (r+a) (S+a)).trans ?_ rw[add_sub_add_right_eq_sub] linarith only[z,v,y,s,g,c,Ἐ r a,ἁ (show 1/2^53*(P+A_z)<=W from (ἁ (add_le_add (le_add_of_nonneg_right j) le_rfl) (one_div_nonneg.mpr (pow_nonneg zero_le_two 53))).trans_eq g.symm) d,ἀ ((le_add_of_nonneg_right zero_le_one).trans u:k<=2^21) c] lemma qBz: (A_fsum l)ᶠ /\ |R (A_fsum l)-A_sr l| <=2*ѣl*(1/2^53*(A_sa l+A_z)):=by obtain ⟨a,b⟩:=qDd l hf hlen hb have c:=Ἆ (Ἔ (α:=ℝ) ѣl) (add_nonneg (qCe l) qAr.le) exact ⟨a,b.trans (by linarith only[c])⟩ end lemma qB7 (l:List ὧ) (c:∀q∈l,qᶠ) (d:ѣl<=2^21) (f:A_sa l<=A_B/4): (A_fsum (l.map Float.abs))ᶠ /\ |R (A_fsum (l.map Float.abs))-A_sa l| <=2*ѣl*(1/2^53*(A_sa l+A_z)):=by have a:A_sa (l.map Float.abs)=A_sa l/\A_sr (l.map Float.abs)=A_sa l:=by constructor<;>simp only[A_sa,A_sr,List.map_map]<;>congr 1<;>exact ὠ λq b=>by simp only[Function.comp_apply,(qBl q (c q b)).2,abs_abs] have:=qBz (l.map Float.abs) (λq b=>by obtain ⟨x,e,rfl⟩:=List.mem_map.mp b exact (qBl x (c x e)).1) (by simpa only[List.length_map,Nat.reducePow]) (a.1.symm▸f) rwa[a.1,a.2,List.length_map] at this lemma qIn (n:ℕ) (g:n<2^20):(nfOf n)ᶠ/\R (nfOf n)=((n:ℝ)+8)/2^53:=by have b:(n.toUInt64+8).toNat=n+8:=by have c:(8:Ὠ).toNat=8:=rfl;simp only[Nat.toUInt64_eq,ἤ,UInt64.toNat_ofNat',Nat.reducePow,c,Nat.mod_add_mod,Nat.mod_succ_eq_iff_lt,Nat.succ_eq_add_one,Nat.reduceAdd,gt_iff_lt];(clear c;exact omS57 g) obtain ⟨f,a⟩:=qCk (n.toUInt64+8) (by rw[b];exact omS58 g);rw[b] at a obtain ⟨e,d⟩:=qCm _ 97 ב f ((n+8:ℕ):ℤ) 0 א ב (by rw[a,ἅ (Ἔ _)] exact qE7 (by exact omS60 g)) (by rw[a];simp only[Nat.cast_add,Nat.cast_ofNat,Int.cast_add,Int.cast_natCast,Int.cast_ofNat,zpow_ofNat,pow_zero,mul_one]) push_cast at a;rw[show nfOf n=(n.toUInt64+8).toFloat*pwEntry 97 by rw[nfOf,qCu];rfl];refine ⟨e,?_⟩;rw[d,a,(qDa 97 ב).2];norm_num;ring lemma qGb {n:ℕ} (l:n<2^20) {s t:ὧ} (k:sᶠ) (m:tᶠ) {X Y:ℝ} (e:0<=Y) (v:Y<=A_B/8) (y: |R s-X| <=((n:ℝ)+4)*(1/2^53*Y)+1/2^250) (u: |R t-Y| <=Y/2^30+1/2^250) (I: |R s| <=2*Y) (c:(2:ℝ)^(-127:ℤ)<= |R (s+nfOf n*t)|):R (s-nfOf n*t)a<=1/k*b->k*a<=b:=λhk h=>(le_div_iff₀' hk).mp (h.trans_eq (one_div_mul_eq_div _ _)) have e2d:∀{x:ℝ} (n:ℕ),0<=x->1/2^n*x<=x:=λn h0=>mul_le_of_le_one_left h0 (div_le_one_of_le₀ (one_le_pow₀ one_le_two) (pow_nonneg zero_le_two n)) have e2aa:∀(x y:ℝ),|x| <= |y| + |x-y|:=λx y=>sub_le_iff_le_add'.mp (Ὥ x y) have A:(n:ℝ)+1<=2^20:=by exact_mod_cast l have o:(0:ℝ)<=n:=Ἔ n;obtain ⟨h,b⟩:=qIn n l;have E:=qAr;have B:=qAw have B':(2:ℝ)^200*(2^200*A_z)<=1:=(le_div_iff₀' (by norm_num1)).mp ((le_div_iff₀' (by norm_num1)).mp (B.trans_eq (one_div_mul_eq_div _ _))) have b':(n:ℝ)+8=R (nfOf n)*2^53:=(div_eq_iff (by norm_num1)).mp b.symm have nf0:0<=R (nfOf n):=b▸div_nonneg (add_nonneg o (by norm_num1)) (by norm_num1) have c30:2^30*R (nfOf n)<=1:=by linarith only[b',A] have nf1:R (nfOf n)<=1:=by linarith only[c30,nf0] generalize hε:(1:ℝ)/2^250=ε at y u;have hε1:(2:ℝ)^250*ε=1:=by rw[<-hε];exact mul_one_div_cancel (by norm_num1) have hε0:0<=ε:=by linarith only[hε1] have hε2:ε<=1:=by linarith only[hε1] have y':2^53*|R s-X| <=((n:ℝ)+4)*Y+2^53*ε:=sck (by norm_num1) (y.trans_eq (by ring)) have u':2^30*|R t-Y| <=Y+2^30*ε:=(le_div_iff₀' (by norm_num1)).mp (u.trans_eq (by rw[add_div,mul_div_cancel_left₀ _ (by norm_num1)])) have i: |R t| <=2*Y+ε:=by linarith only[e2aa (R t) Y,ἅ e,u',e,hε0] have x':2^30*|R (nfOf n)*R t| <=2*Y+ε:=by rw[ἢ,ἅ nf0,<-mul_assoc];exact (ἑ c30 i (Ἀ _) zero_le_one).trans_eq (one_mul _) have h8:(2:ℝ)^3<=A_B:=(pow_le_pow_right₀ one_le_two (Nat.le_of_ble_eq_true rfl:3<=128)).trans qAn have kAB:∀{x:ℝ},x<=(2*Y+1)+((2*Y+1)+1)->x<=A_B:=λh=>h.trans (by linarith only[v,h8]) have nn':(0:ℝ)<=2*Y+1:=add_nonneg (Ἆ zero_le_two e) zero_le_one have nn:(0:ℝ)<=(2*Y+1)+1:=add_nonneg nn' zero_le_one obtain ⟨d,f⟩:=qCf _ _ h m ((ἅ nf0).le.trans (nf1.trans ((one_le_pow₀ one_le_two).trans qAn))) (kAB (i.trans (add_le_add (le_add_of_nonneg_right zero_le_one) (hε2.trans (le_add_of_nonneg_left nn'))))) have Xa: |R (nfOf n)*R t| <=2*Y+1:=by linarith only[x',hε2,e,hε0] have G6:=kAB ((e2aa _ (R (nfOf n)*R t)).trans (add_le_add Xa ((f.trans (e2d 53 (add_nonneg (Ἀ _) E.le))).trans (add_le_add Xa qBo)))) have D:=e2aa (R (nfOf n*t)) (R (nfOf n)*R t) obtain ⟨z,j⟩:=qBf s _ k d (kAB (I.trans (le_add_of_le_of_nonneg (le_add_of_nonneg_right zero_le_one) nn))) G6 obtain ⟨r,g⟩:=qDf s _ k d (kAB (I.trans (le_add_of_le_of_nonneg (le_add_of_nonneg_right zero_le_one) nn))) G6 have H:=e2aa (R (s+nfOf n*t)) (R s+R (nfOf n*t));have q:=Ἐ (R s) (R (nfOf n*t));have p:=Ὕ (R s) (R (nfOf n*t)) rw[zpow_neg,zpow_ofNat,<-one_div] at c;have c':=(div_le_iff₀' (by norm_num1:(0:ℝ)<2^127)).mp c have f':=sck (by norm_num1) f;have j':=sck (by norm_num1) j;have g':=sck (by norm_num1) g have M:=ἀ ((le_add_of_nonneg_right zero_le_one).trans A:(n:ℝ)<=2^20) e have bT:((n:ℝ)+8)*R t=R (nfOf n)*2^53*R t:=by rw[b'] have bY:((n:ℝ)+8)*Y=R (nfOf n)*2^53*Y:=by rw[b'] have nT:=ἁ (neg_abs_le (R t-Y)) nf0;have nU:=ἁ u' nf0;have nE:=ἀ c30 hε0 have pg:=le_abs_self (R (s-nfOf n*t)-(R s-R (nfOf n*t)));have nj:=neg_abs_le (R (s+nfOf n*t)-(R s+R (nfOf n*t))) have pf:=le_abs_self (R (nfOf n*t)-R (nfOf n)*R t);have nf':=neg_abs_le (R (nfOf n*t)-R (nfOf n)*R t) have py:=le_abs_self (R s-X);have ny:=neg_abs_le (R s-X);have nS:=Ἀ (R s);have nP:=Ἀ (R (nfOf n*t)) constructor . linarith only[y',py,g',pg,p,I,f',nf',x',D,bT,bY,nT,nU,nE,M,A,o,e,B',E,hε1,hε0,nf0,c30,c',H,j',q,nS,nP] . linarith only[y',ny,j',nj,q,I,f',nf',x',D,bT,bY,nT,nU,nE,M,A,o,e,B',E,hε1,hε0,nf0,c30,c',H,p,nS,nP] lemma qEv (g h:ℕ->ὧ) (l:List ℕ) (a b:ὧ): l.foldl (λ(d:F1) t=>F1.mk (d.s+g t) (d.t+h t)) ⟨a,b⟩=⟨l.foldl (λ(c:ὧ) t=>c+g t) a,l.foldl (λ(c:ὧ) t=>c+h t) b⟩:=by induction l generalizing a b with | nil=>rfl | cons x l ih=>simp only[ὔ,ih] lemma qC9 (a:List ℕ) (f:ℕ->ℝ) (M:ℝ) (h:∀t∈a,f t<=M):(a.map f).sum<=ѣa*M:=by simpa only[List.map_const',List.sum_replicate,nsmul_eq_mul] using List.sum_le_sum h section variable (w:ὥ) (hg:good w=true) include w hg lemma qB5: |wv w| =A_mag (ѥw%2^31):=by rw[qA7 w hg,ἢ,ἅ (qAs _)];split_ifs<;>simp only[abs_neg,abs_one,Nat.reducePow,one_mul] lemma qAo: |wv w| <=2^128:=by rw[qB5 w hg];apply qFb;rcases qAz w hg with h | h<;>omega lemma qBr (h:w&&&В=0):wv w=0:=by rw[qA7 w hg,<-qAq w,h];simp only[Nat.reducePow,A_mag,UInt32.toNat_zero, ↓reduceIte,mul_zero] end lemma qHc (a b:ὥ) (ha:good a=true) (hb:good b=true): (dv a*dv b)ᶠ /\ |R (dv a*dv b)-wv a*wv b| <=1/2^53*(|wv a*wv b| +A_z)/\ |wv a*wv b| <=2^256:=by obtain ⟨j,g⟩:=qAm a ha obtain ⟨i,d⟩:=qAm b hb have c:=qAo a ha have e:=qAo b hb obtain ⟨h,f⟩:=qCf _ _ j i (g▸c.trans qAn) (d▸e.trans qAn) rw[g,d] at f exact ⟨h,f,by rw[ἢ] exact (ἑ c e (Ἀ _) ו).trans_eq (by norm_num1)⟩ lemma qBs {n:ℕ} {a b:ℕ->ὥ} {f:ὥ} (g:∀t,tgood (a t)=true) (j:∀t,tgood (b t)=true) {l:List ℕ} (k:l.Nodup) (d:∀t∈l,tt∉l->a t&&&В=0\/b t&&&В=0):exactS n a b f=(l.map λt=>wv (a t)*wv (b t)).sum+wv f:=by unfold exactS;congr 1;rw[<-List.sum_toFinset _ k];refine (Finset.sum_subset (λt c=>by simpa only[Ὁ] using d t (by simpa only[List.mem_toFinset] using c)) λt c h=>?_).symm;have e:=Ὁ.mp c;rcases i t e (by simpa only[List.mem_toFinset] using h) with h | h;. simp only[qBr (a t) (g t e) h,zero_mul] . simp only[qBr (b t) (j t e) h,mul_zero] lemma qFu {n:ℕ} {l:List ℕ} (b:l.Nodup) (a:∀t∈l,tList.mem_range.2 (a t h)).length_le abbrev A_G (ts:List ℕ) (g:ℕ->ὧ) (p:ℕ->ℝ):Prop:= ∀t∈ts,(g t)ᶠ/\|R (g t)-p t| <=1/2^53*(|p t| +A_z)/\|p t| <=2^256 lemma qFj {b c:ℕ->ὥ} {l:List ℕ} {n:ℕ} (a:∀t∈l,tgood (b t)=true) (f:∀t,tgood (c t)=true):A_G l (λt=>dv (b t)*dv (c t)) λt=>wv (b t)*wv (c t):=λt d=>qHc _ _ (e t (a t d)) (f t (a t d)) lemma qCr {a:List ℕ} {g:ℕ->ὧ} {p:ℕ->ℝ} (b:ὧ) (c:A_G a g p):let A:=(a.map λt=>|p t|).sum let L:=a.map g++[b] |A_sr L-((a.map p).sum+R b)| <=1/2^53*(A+ѣa*A_z)/\A_sa L<=A+ |R b| +1/2^53*(A+ѣa*A_z)/\A<=2*A_sa L+ѣa*A_z:=by induction a with | nil=>simp only[A_sr,List.map_nil,List.nil_append,List.map_cons,List.sum_cons,List.sum_nil,add_zero,zero_add,sub_self,abs_zero,one_div,List.length_nil,CharP.cast_eq_zero,zero_mul,mul_zero,Std.le_refl,A_sa,Nat.ofNat_pos,mul_nonneg_iff_of_pos_left,Ἀ,and_self] | cons x a ih=> obtain ⟨d,i,j⟩:=ih (λt e=>c t (by simp only[List.mem_cons,e,or_true])) have f:=(c x ג).2.1 simp only[A_sa,A_sr,List.map_cons,List.sum_cons,List.length_cons,List.cons_append] at d i j⊢ have sck:∀{k a b:ℝ},0a<=1/k*b->k*a<=b:=λhk h=>(le_div_iff₀' hk).mp (h.trans_eq (one_div_mul_eq_div _ _)) have m:=qAr have f':=sck (by norm_num1) f have d':=sck (by norm_num1) d have i':=sck (by norm_num1) (sub_le_iff_le_add'.mpr i) have nf:=neg_abs_le (R (g x)-p x);have pf:=le_abs_self (R (g x)-p x) have nd:=neg_abs_le ((List.map R (List.map g a++[b])).sum-((List.map p a).sum+R b));have pd:=le_abs_self ((List.map R (List.map g a++[b])).sum-((List.map p a).sum+R b)) have k:=Ἀ (p x) have h:=Ὥ (p x) (R (g x)) have l:=Ὥ (R (g x)) (p x) rw[ἣ] at h refine ⟨abs_le.mpr ⟨?_,?_⟩,?_,?_⟩<;>push_cast . rw[one_div_mul_eq_div,<-neg_div,div_le_iff₀' (by norm_num1)];linarith only[nf,nd,f',d',m,k] . rw[one_div_mul_eq_div,le_div_iff₀' (by norm_num1)];linarith only[pf,pd,f',d',m,k] . rw[<-sub_le_iff_le_add',one_div_mul_eq_div,le_div_iff₀' (by norm_num1)];linarith only[i',l,f',m,k] . linarith only[j,h,f',m,k] lemma qHh (l:List ℕ) (g:ℕ->ὧ) (b:ὧ):((l.map g++[b]).length:ℝ)=ѣl+1:=by simp only[List.length_append,List.length_map,List.length_cons,List.length_nil,zero_add,Nat.cast_add,Nat.cast_one] lemma qHf {a:List ℕ} {g:ℕ->ὧ} {p:ℕ->ℝ} {b:ὧ} (d:A_G a g p) (c:bᶠ):∀q∈a.map g++[b],qᶠ:=by simp only[List.mem_append,List.mem_map,List.mem_singleton];rintro q (⟨t,e,rfl⟩ | rfl);. exact (d t e).1 . exact c lemma qCs {a:ὥ} (d:good a=true) (h:a<=В): 0<=wv a/\wv a<=2^128/\ ∀w,good w=true->w&&&В<=a->|wv w| <=wv a:=by have g:ѥa<=2147483647:=ἃ.mp h have b:wv a=A_mag ѥa:=by rw[qA7 a d,Ἁ (by exact Nat.lt_succ_of_le ‹_›)] simp only[show ¬2^31<=ѥa by (exact Nat.not_lt.mpr ‹_›),↓reduceIte,one_mul] refine ⟨b▸qAs _,(le_abs_self _).trans (qAo a d),λw c f=>?_⟩ have e:=ἃ.mp f rw[qAq] at e rw[qB5 _ c,b] exact qA6 _ _ e ((qAz _ c).imp_right (·.1)) section variable {n:ℕ} {ts:List ℕ} {g:ℕ->ὧ} {p:ℕ->ℝ} {bw hh:ὥ} {X Y J:ℝ} {s t a e:ὧ} (A:n<2^20) (B:ѣts<=n) (C:A_G ts g p) (D:good bw=true) (E:X=(ts.map p).sum+wv bw) (F:s=ts.foldl (λ(c:ὧ) t=>c+g t) 0+dv bw) (G:(2:ℝ)^(-127:ℤ) ≤ |R (s+e)|) include A B C D E F G lemma qEz (k:tᶠ) (b:Y<=A_B/8) (o:A_sa (ts.map g++[dv bw])+A_z<=(1+1/2^22)*Y) (u:(1+1/2^22)*((ѣts:ℝ)+1)*(A_sa (ts.map g++[dv bw])+A_z)+((ts.map λt=>|p t|).sum+ѣts*A_z)<=((ѣts:ℝ)+4)*Y+1/2^240) (m: |R t-Y| <=Y/2^30+1/2^250) (h:e=nfOf n*t): R (s-e)Y<=A_B/8->(1+1/2^22)*Y<=A_B/4:=λhY0 hY=>by linarith only[hY0,hY] subst h obtain rfl:s=A_fsum (ts.map g++[dv bw]):=by simp only[F,A_fsum,List.foldl_append,List.foldl_map,ὔ,List.foldl_nil] obtain ⟨c,d⟩:=qAm bw D obtain ⟨j,-,-⟩:=qCr (dv bw) C rw[d,<-E] at j have i:=qCe (ts.map g++[dv bw]) have r:=qAr have l:(ѣts:ℝ)<=n:=by exact_mod_cast B have q:(n:ℝ)+1<=2^20:=by exact_mod_cast A have a:0<=Y:=nonneg_of_mul_nonneg_right ((add_nonneg i r.le).trans o) ו obtain ⟨f,h⟩:=qDd _ (qHf C c) (by rw[List.length_append,List.length_map,List.length_singleton];exact (Nat.succ_le_of_lt (Nat.lt_of_le_of_lt B A)).trans (Nat.le_of_ble_eq_true rfl)) ((le_add_of_nonneg_right r.le).trans (o.trans (e2AB7 a b))) rw[qHh] at h generalize ts.map g++[dv bw]=L at* have x:=qC7 L have y:=ἀ l a have v:=ἑ ((add_le_add l le_rfl).trans q:(ѣts:ℝ)+1<=2^20) o (add_nonneg i r.le) ו have w:=abs_sub_le (R (A_fsum L)) (A_sr L) X have z:=Ὥ (R (A_fsum L)) (A_sr L) exact qGb A f k a b (by linarith only[u,j,h,y,w]) m (by linarith only[r,o,i,h,x,v,z]) G lemma qDi (P:good hh=true) (hp:hh<=В) (U:(ts.map λt=>|p t|).sum<=wv hh*J) (m:aᶠ) (d:0<=J) (z:J<=2^149) (v: |R a-J| <=(J+A_z)/2^32) (he:e=nfOf n*(dv hh*a+(dv bw).abs)):R (s-e)y<=2^b->a<=j->b<=j->x+y<=2^(j+1):=λ{x y a b j} hx hy ha hb=>(add_le_add (hx.trans (pow_le_pow_right₀ one_le_two ha)) (hy.trans (pow_le_pow_right₀ one_le_two hb))).trans_eq ((two_mul _).symm.trans (pow_succ' 2 j).symm) have e2z0:A_z<=2^0:=qBo.trans_eq (pow_zero 2).symm have e2d:∀{x:ℝ} (n:ℕ),0<=x->1/2^n*x<=x:=λn h0=>mul_le_of_le_one_left h0 (div_le_one_of_le₀ (one_le_pow₀ one_le_two) (pow_nonneg zero_le_two n)) have e2AB:∀{x:ℝ} {k:ℕ},x<=2^k->k+3<=256+42->x<=A_B/8:=λ{x k} h hk=>(le_div_iff₀ (by norm_num:(0:ℝ)<8)).mpr ((ἀ h (by norm_num:(0:ℝ)<=8)).trans ((((congrArg ((2:ℝ)^k*·) (by norm_num:(8:ℝ)=2^3)).trans (pow_add 2 k 3).symm).trans_le ((pow_le_pow_right₀ one_le_two hk).trans_eq (pow_add 2 256 42))).trans qCc)) have e2AB1:∀{x:ℝ} {k:ℕ},x<=2^k->k<=256+42->x<=A_B:=λh hk=>h.trans (((pow_le_pow_right₀ one_le_two hk).trans_eq (pow_add 2 256 42)).trans qCc) have e2aa:∀(x y:ℝ),|x| <= |y| + |x-y|:=λx y=>sub_le_iff_le_add'.mp (Ὥ x y) obtain ⟨b,h,-⟩:=qCs P hp;obtain ⟨Q,N⟩:=qAm hh P;obtain ⟨q,j⟩:=qAm bw D;obtain ⟨-,K,-⟩:=qCr (dv bw) C;rw[j] at K;have S:=qAo bw D;generalize wv hh=H at*;have hk:(ѣts:ℝ)+1<=2^20:=by exact_mod_cast (by (exact Nat.lt_of_le_of_lt ‹_› ‹_›):ѣts+1<=2^20) have L:(0:ℝ)<=ѣts:=Ἔ _;have hkN:(ѣts:ℝ)<=2^20:=(le_add_of_nonneg_right zero_le_one).trans hk;have M:=qAr;have x:=qAw;have r:=qC4 ts p;have u:=Ὥ (R a) J;rw[ἅ d] at u;obtain ⟨e1,W⟩:=abs_le.mp v;have e3:=ἁ e1 b;have e4:=ἁ W b;have e5:=ἑ h x M.le ו have e6':=(e2aa (R a) J).trans (add_le_add (ἅ d).le v);have e6: |H*R a| <=H*(J+(J+A_z)/2^32):=by rw[ἢ,ἅ b];exact ἁ e6' b have bRa: |R a| <=2^151:=e6'.trans (e2pa (j:=150) z ((div_le_self (add_nonneg d M.le) (one_le_pow₀ one_le_two)).trans (e2pa (j:=149) z e2z0 le_rfl (Nat.le_of_ble_eq_true rfl))) (Nat.le_of_ble_eq_true rfl) le_rfl) have hRa: |H*R a| <=2^279:=by rw[ἢ,ἅ b];exact (ἑ h bRa (Ἀ _) ו).trans_eq (pow_add 2 128 151).symm have hW:=Ἆ b d;have hHJ:H*J<=2^128*2^149:=ἑ h z d ו;obtain ⟨o,i⟩:=qCf _ a Q m (by rw[N,ἅ b];exact h.trans qAn) (e2AB1 bRa (Nat.le_of_ble_eq_true rfl));rw[N] at i;have e7:=Ὥ (R (dv hh*a)) (H*R a);obtain ⟨w,f⟩:=qBl (dv bw) q;rw[j] at f have bRha: |R (dv hh*a)| <=2^281:=(e2aa _ (H*R a)).trans (e2pa (j:=280) hRa (i.trans ((e2d 53 (add_nonneg (Ἀ _) M.le)).trans (e2pa (j:=279) hRa e2z0 le_rfl (Nat.le_of_ble_eq_true rfl)))) (Nat.le_of_ble_eq_true rfl) le_rfl) obtain ⟨y,k⟩:=qBf _ _ o w (e2AB1 bRha (Nat.le_of_ble_eq_true rfl)) (by rw[f,abs_abs];exact S.trans qAn);rw[f] at k;have e8:=Ἐ (R (dv hh*a)) |wv bw|;rw[abs_abs] at e8;obtain ⟨e9,Z⟩:=abs_le.mp i;obtain ⟨e11,V⟩:=abs_le.mp k;have hkz:=ἀ hkN M.le;have O:=Ἀ (wv bw);obtain ⟨Y,hY⟩:∃Y,Y=H*J+ |wv bw| +A_z:=⟨_,rfl⟩;have c:A_sa (ts.map g++[dv bw])+A_z<=(1+1/2^22)*Y:=(by linarith only[hY,O,hkz,r,M,U,K]);have d2: |H*R a-H*J| <=H*((J+A_z)/2^32):=by rw[<-mul_sub,ἢ,ἅ b];exact ἁ v b have d3: |R (dv hh*a+(dv bw).abs)-Y| <= |R (dv hh*a+(dv bw).abs)-(R (dv hh*a)+|wv bw|)|+(|R (dv hh*a)-H*R a|+(|H*R a-H*J|+A_z)):=by rw[hY,show R (dv hh*a+(dv bw).abs)-(H*J+|wv bw|+A_z)=(R (dv hh*a+(dv bw).abs)-(R (dv hh*a)+|wv bw|))+((R (dv hh*a)-H*R a)+((H*R a-H*J)-A_z)) by ring] exact (Ἐ _ _).trans (add_le_add le_rfl ((Ἐ _ _).trans (add_le_add le_rfl ((Ὕ _ _).trans (add_le_add le_rfl (ἅ M.le).le))))) have l: |R (dv hh*a+(dv bw).abs)-Y| <=Y/2^30+1/2^250:=d3.trans (by linarith only[k,i,d2,e8,e7,e6,e5,hY,O,x,M,hW]) have Y0:0<=Y:=(add_nonneg (add_nonneg hW O) M.le).trans_eq hY.symm refine qEz A B C D E F G y (e2AB (k:=279) (hY.trans_le (e2pa (j:=278) (e2pa (j:=277) (hHJ.trans_eq (pow_add 2 128 149).symm) S (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl)) e2z0 (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl))) (Nat.le_of_ble_eq_true rfl)) c ?_ l he have h3:=ἁ c (add_nonneg L zero_le_one);have h4:=ἀ hkN Y0 linarith only[h4,h3,hY,O,hkz,r,x,M,U] lemma qBm {a:ℕ->ὥ} (u:good hh=true) (w:hh<=В) (i:∀t∈ts,good (a t)=true) (o:∀t∈ts,|p t| <=wv hh* |wv (a t)|) (r:e=nfOf n*(dv hh*ts.foldl (λ(c:ὧ) t=>c+(dv (a t)).abs) 0+(dv bw).abs)):R (s-e)dv (a t))=(ts.map λt=>|wv (a t)|).sum:=by simp only[A_sa,List.map_map];congr 1;exact ὠ λt d=>by simp only[Function.comp_apply,(qAm _ (i t d)).2] have h:=(qC9 ts _ _ λt d=>qAo _ (i t d)).trans (ἀ f ו);rw[<-k] at h;have m:=qCc obtain ⟨j,b⟩:=qB7 _ (λq v=>by obtain ⟨t,d,rfl⟩:=List.mem_map.mp v exact (qAm _ (i t d)).1) (by simp only[List.length_map,Nat.reducePow];(clear w;exact omS62 A B)) (by linarith only[m,h,D]) rw[List.length_map] at b;have g:=qCe (ts.map λt=>dv (a t));have l:=qAr;refine qDi A B C D E F G u w ?_ j g (h.trans (by norm_num1)) ?_ (r.trans (by simp only[A_fsum,List.map_map,List.foldl_map,Function.comp_apply]));. rw[k,<-List.sum_map_mul_left];exact List.sum_le_sum o . refine b.trans ?_;have:=ἀ f (add_nonneg g l.le);linarith only[this,D] end section variable (n:Ὣ) (hn:n<2^20) (xw ww:Ὣ->ὥ) include n hn xw ww lemma qDm (bw:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (l:љ) (hl:l.Nodup) (hl2:∀t∈l,tt∉l->xw t&&&В=0\/ww t&&&В=0) (s e:ὧ) (hs:let r:=l.foldl (λ(acc:F1) t=>let q:=dv (xw t)*dv (ww t) F1.mk (acc.s+q) (acc.t+q.abs)) ⟨0,0⟩;s=r.s+dv bw/\e=nfOf n*(r.t+(dv bw).abs)) (hbig:(2:ℝ)^(-127:ℤ)<= |R (s+e)|): R (s-e)y<=2^b->a<=j->b<=j->x+y<=2^(j+1):=λ{x y a b j} hx hy ha hb=>(add_le_add (hx.trans (pow_le_pow_right₀ one_le_two ha)) (hy.trans (pow_le_pow_right₀ one_le_two hb))).trans_eq ((two_mul _).symm.trans (pow_succ' 2 j).symm) have e2z0:A_z<=2^0:=qBo.trans_eq (pow_zero 2).symm have e2d:∀{x:ℝ} (n:ℕ),0<=x->1/2^n*x<=x:=λn h0=>mul_le_of_le_one_left h0 (div_le_one_of_le₀ (one_le_pow₀ one_le_two) (pow_nonneg zero_le_two n)) have e2AB:∀{x:ℝ} {k:ℕ},x<=2^k->k+3<=256+42->x<=A_B/8:=λ{x k} h hk=>(le_div_iff₀ (by norm_num:(0:ℝ)<8)).mpr ((ἀ h (by norm_num:(0:ℝ)<=8)).trans ((((congrArg ((2:ℝ)^k*·) (by norm_num:(8:ℝ)=2^3)).trans (pow_add 2 k 3).symm).trans_le ((pow_le_pow_right₀ one_le_two hk).trans_eq (pow_add 2 256 42))).trans qCc)) have e2AB4:A_B/8<=A_B/4:=div_le_div_of_nonneg_left qI1.le ב ב have e2z250:A_z<=1/2^250:=qAw.trans ב simp only[qEv] at hs obtain ⟨hs,E⟩:=hs have a:=qFj hl2 hx hw have f:=qFu hl hl2 obtain ⟨h,i⟩:=qAm bw hb obtain ⟨-,m,y⟩:=qCr (dv bw) a rw[i] at m have b:=qCe (l.map (λt=>dv (xw t)*dv (ww t))++[dv bw]) have k:=qC9 l _ _ λt u=>(a t u).2.2 have v:(ѣl:ℝ)+1<=2^20:=by exact_mod_cast (by (exact Nat.lt_of_le_of_lt ‹_› ‹_›):ѣl+1<=2^20) have o:(0:ℝ)<=ѣl:=Ἔ _ have d:=qAr have D:=qAw have D':(2:ℝ)^200*(2^200*A_z)<=1:=(le_div_iff₀' (by norm_num1)).mp ((le_div_iff₀' (by norm_num1)).mp (qAw.trans_eq (one_div_mul_eq_div _ _))) have w:=qAo bw hb have z:=qCc have A:=qC4 l λt=>wv (xw t)*wv (ww t) have v':(ѣl:ℝ)<=2^20:=(le_add_of_nonneg_right zero_le_one).trans v have p:=(k.trans (ἀ v' ו)).trans_eq (pow_add 2 20 256).symm have C:=ἀ v' d.le have nz:=(C.trans (mul_le_of_le_one_right (pow_nonneg zero_le_two 20) qBo)) have pa:=e2pa (j:=276) p nz (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) have g:A_sa (l.map (λt=>dv (xw t)*dv (ww t))++[dv bw])+A_z<=A_B/8:=e2AB (k:=279) (e2pa (j:=278) (m.trans (e2pa (j:=277) (e2pa (j:=276) p w (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl)) ((e2d 53 (add_nonneg A (Ἆ o d.le))).trans pa) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl))) e2z0 (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl)) (Nat.le_of_ble_eq_true rfl) obtain ⟨j,c⟩:=qB7 _ (qHf a h) (by rw[List.length_append,List.length_map,List.length_singleton];exact (Nat.succ_le_of_lt (Nat.lt_of_le_of_lt f hn)).trans (Nat.le_of_ble_eq_true rfl)) (((le_add_of_nonneg_right d.le).trans g).trans e2AB4) rw[qHh] at c have B:=Ἆ o b have x:=ἀ v (add_nonneg b d.le) have Y0:=add_nonneg b d.le exact qEz hn f a hb (qBs hx hw hl hl2 hz) hs hbig j g (le_mul_of_one_le_left Y0 (le_add_of_nonneg_right (one_div_nonneg.mpr (pow_nonneg zero_le_two 22)))) (by have G:=(abs_le.mp c).1;have F:=(abs_le.mp c).2;linarith only[y,D',C,x,G,F]) ((congrArg (λr:ℝ=>|r|) (sub_sub _ _ _).symm).trans_le ((Ὕ _ _).trans (add_le_add (c.trans (by linarith only[x,Y0]:_<=(A_sa (l.map (λt=>dv (xw t)*dv (ww t))++[dv bw])+A_z)/2^30)) ((ἡ d).trans_le e2z250)))) (E.trans (by simp only[A_fsum,List.map_append,List.map_map,List.map_cons,List.map_nil,List.foldl_append,List.foldl_map,Function.comp_apply,ὔ,List.foldl_nil])) lemma qC8 (bw hv:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (hgv:good hv=true) (hpv:hv<=В) (l:љ) (hl:l.Nodup) (hl2:∀t∈l,tt∉l->xw t&&&В=0) (s e:ὧ) (hs:s=l.foldl (λ(acc:ὧ) t=>acc+dv (xw t)*dv (ww t)) 0+dv bw/\e=nfOf n*(dv hv*(l.foldl (λ(acc:ὧ) t=>acc+(dv (xw t)).abs) 0)+(dv bw).abs)) (hbig:(2:ℝ)^(-127:ℤ)<= |R (s+e)|): R (s-e).inl (hz t i z)) hs hbig hgv hpv (λt a=>hx t (hl2 t a)) (λt a=>by rw[ἢ,mul_comm] exact ἀ (c _ (hw t (hl2 t a)) (hmv t a)) (Ἀ _)) b end end section noncomputable def A_r (b:Ὡ):ℝ:=if b then-1 else 1 lemma qF9 (s t:Ὡ):A_r (s ^^ t)=A_r s*A_r t:=by cases s<;>cases t<;>simp only[A_r,bne_self_eq_false,false_eq_true, ↓reduceIte,mul_one,Bool.bne_true,Bool.not_false,mul_neg,Bool.bne_false,neg_neg] lemma qF8 (S T:Ὡ) (X Y:ℝ) (a:0cases T<;>simp only[A_r,false_eq_true, ↓reduceIte,one_mul,neg_mul,Bool.true_eq_false,neg_inj] at h⊢<;>linarith only[h,b,a] section variable (d:FloatLib.Numerics.Dyadic) include d lemma qD4:d.toReal=A_r d.negative*((d.significand:ℝ)*2^d.exponent):=by obtain ⟨n,m,e⟩:=d;cases n<;>simp only[FloatLib.Numerics.Dyadic.toReal,signedSignificand,false_eq_true, ↓reduceIte,Int.ofNat_eq_natCast,Int.cast_natCast,A_r,one_mul,Int.cast_neg,neg_mul] lemma A_s:d.toReal=0↔d.significand=0:=by have h:(2:ℝ)^d.exponent≠0:=zpow_ne_zero _ ἓ;rw[qD4];cases d.negative<;>simp only[A_r,false_eq_true, ↓reduceIte,one_mul,mul_eq_zero,Nat.cast_eq_zero,h,or_false,neg_mul,neg_eq_zero] lemma qE9 (h:d.significand≠0):0<(d.significand:ℝ)*2^d.exponent:=mul_pos (Nat.cast_pos.mpr (ὼ h)) (ἵ two_pos _) end lemma qIe (a b:ὧ) (h:A_M a=A_M b):a=b:=by have:=Model.ofFloatModel_injective h;cases a;cases b;simp_all only lemma qDk (f:ὧ) (h:fᶠ): ∃d,Model.toDyadic? (A_M f)=some d/\d.toReal=R f:=by obtain ⟨d,a⟩:=Model.exists_toDyadic?_of_isFinite ((qAh f).trans h);exact ⟨d,a,by rw[A_R,Model.toReal_eq,a]⟩ lemma qCq {a b:ὧ} {x y:FloatLib.Numerics.Dyadic} (f:Model.toDyadic? (A_M a)=some x) (d:Model.toDyadic? (A_M b)=some y) (e:aᶠ) (c:bᶠ): A_M (a*b)=if x.significand*y.significand=0 then Model.zero _ (x.negative ^^ y.negative) else ἕ _ ⟨x.negative ^^ y.negative,x.significand*y.significand,x.exponent+y.exponent⟩:=by rw[qB0 a b e c,Model.Proof.mul_eq_spec,Model.Spec.mul,f,d] simp only[or_eq_true,beq_iff_eq,FloatFormat.isIEEE_binary64,Model.zero_eq_signedZero_of_isIEEE,bne_iff_ne,ne_eq,ite_not,mul_eq_zero] lemma qHe {a b:ὧ} {x y z:FloatLib.Numerics.Dyadic} (m:Model.toDyadic? (A_M a)=some x) (n:Model.toDyadic? (A_M b)=some y) (e:Model.toDyadic? (A_M (a*b))=some z) (k:aᶠ) (l:bᶠ) (c:z.toReal=x.toReal*y.toReal):z.negative=(x.negative ^^ y.negative):=by by_cases g:x.significand*y.significand=0;. have d:=qCq m n k l;simp only[g,↓reduceIte] at d;rw[d,Model.toDyadic?_zero] at e;cases e;show Model.signBit _=_;cases x.negative<;>cases y.negative<;>simp only[Model.zero,bne_self_eq_false,FloatFormat.isIEEE_binary64,FloatFormat.supportsSignedZero_eq_true_of_isIEEE,Bool.and_true,false_eq_true, ↓reduceIte,Model.signBit_posZero,Bool.bne_true,Bool.not_false,Bool.and_self,Model.signBit_negZero,Bool.bne_false] . obtain ⟨f,i⟩:=Nat.mul_ne_zero_iff.mp g;have j:z.significand≠0:=λh=>by rw[(A_s z).2 h] at c;exact mul_ne_zero (mt (A_s x).1 f) (mt (A_s y).1 i) c.symm rw[qD4 z,qD4 x,qD4 y,mul_mul_mul_comm,<-qF9] at c;exact qF8 _ _ _ _ (qE9 z j) (mul_pos (qE9 x f) (qE9 y i)) c lemma qGg (v m p:ὧ) (f:vᶠ) (i:mᶠ) (h:pᶠ) (u:(v*p)ᶠ) (s:(m*p)ᶠ) (q:R (v*p)=R v*R p) (r:R (m*p)=R m*R p):v*p*m=v*(m*p):=by obtain ⟨a,o,n⟩:=qDk v f;obtain ⟨b,y,k⟩:=qDk p h;obtain ⟨c,w,A⟩:=qDk m i;obtain ⟨d,t,B⟩:=qDk _ u;obtain ⟨e,l,x⟩:=qDk _ s;have D:=qHe o y t f h (by rw[B,n,k,q]);have E:=qHe w y l i h (by rw[x,A,k,r]);have C:(d.negative ^^ c.negative)=(a.negative ^^ e.negative):=by rw[D,E];cases a.negative<;>cases b.negative<;>cases c.negative<;>rfl have j:d.toReal*c.toReal=a.toReal*e.toReal:=by rw[B,A,n,x,q,r];ring have g:d.significand*c.significand=0↔a.significand*e.significand=0:=by simp only[Nat.mul_eq_zero,<-A_s,<-mul_eq_zero,j] apply qIe;rw[qCq t w u i,qCq o l f s];by_cases z:d.significand*c.significand=0;. simp only[z,g.1 z,↓reduceIte,C] . simp only[z,mt g.2 z,↓reduceIte];refine ExactRuntime.roundDyadic_congr _ qAj _ _ z (mt g.2 z) (Rat.cast_injective (α:=ℝ) ?_);rw[Ἠ,Ἠ,Model.Dyadic.toReal_mul,Model.Dyadic.toReal_mul,j] lemma qFw (x w:ὥ) (hx:good x=true):dvB (dv x) w=dv x*dv w:=by obtain ⟨e,o⟩:=qAm x hx;obtain ⟨p,f,j,q,g,-⟩:=qD1 w;obtain ⟨d,a,-,-,l,b⟩:=qD1 x;obtain ⟨m,c,k⟩:=qCw _ a;have r:=x.toNat_lt;have h:R (dv x)=(((2^23+ѥx%2^23:ℕ)*m:ℤ):ℝ)*2^(((ѥx/2^23%256:ℕ):ℤ)-150):=by unfold dv;rw[d,l,b,k,Int.cast_mul,Int.cast_natCast,mul_assoc] obtain ⟨n,i⟩:=qCm (dv x) _ f e _ _ (by rw[Int.natAbs_mul,Int.natAbs_natCast];have:=Nat.mul_le_mul_left (2^23+ѥx%2^23) c (clear f a c r;omega)) (by clear f a c r;exact omS63) (by rw[o];exact (qAo x hx).trans qAn) h show dv x*pw.uget _ _*_=dv x*(_*pw.uget _ _);rw[p];exact qGg _ _ _ e j (qDa _ f).1 n q i g end section section open Float.Model Float.Model.UnpackedFloat lemma qFq (t:Int):Format.binary32.targetExponent t=max (t-24) (-149):=by simp only[Format.targetExponent,Format.mantissaBits,Nat.reduceAdd,Nat.cast_ofNat,Format.minExponent,Nat.add_one_sub_one,Int.reducePow,Int.reduceSub,Int.reduceNeg] lemma B_z (a b:ℤ) (n:ℕ) (h:a=n+b):(2:ℝ)^a=2^n*2^b:=by rw[h,Ἓ ἓ,Ἡ] lemma qDg (m L:Ὣ) (h1:2^L<=m) (h2:m<2^(L+1)):m.log2=L:=(Nat.log2_eq_iff (by have:=Nat.two_pow_pos L;(clear h2;omega))).2 ⟨h1,h2⟩ lemma qEa (M:Ὣ) (e T:Int) (K r:Ὣ) (d:T=e+(K+1:Ὣ)) (c:0rfl simp only[c,ite_false,a,ite_true,packComponents,BitVec.toNat_append,b,BitVec.toNat_ofNat] rw[Ἁ (by (clear h hM1 hM2 c a b;exact omS70 hb2):(E+150).toNat<2^8), <-Nat.shiftLeft_add_eq_or_of_lt (by (clear h hM1 hM2 c a b;exact omS70 hb2):(E+150).toNat<2^8), <-Nat.shiftLeft_add_eq_or_of_lt (ὀ _ ו:M%2^23<2^23)] split_ifs<;>simp only[ὁ,Nat.reducePow,one_mul,Nat.add_right_cancel_iff,zero_mul,zero_add,Nat.add_left_cancel_iff] (clear h hM1 hM2 hb1 hb2 c a b;omega) lemma qE4 (neg:Ὡ) (m:Ὣ) (e:Int) (P:Ὣ) (E:Int) (hm:m≠0) (hP1:2^23<=P) (hP2:P<2^24) (hE:-149<=E) (hE2:E+150<=254) (hhi:2*((m:ℝ)*2^e)<(2*P+1)*2^E) (hlo1:P≠2^23->(2*P-1)*2^E<2*((m:ℝ)*2^e)) (hlo2:P=2^23->33554431*2^E<4*((m:ℝ)*2^e)): toWord (ἕ Fmt ⟨neg,m,e⟩)=ὺ ((if neg then 2^31 else 0)+(E+150).toNat*2^23+P%2^23):=by have l:0Aby exact_mod_cast lt_of_mul_lt_mul_right h u.le push_cast at hhi hlo1 hlo2 have G:M<4*(P*2^g)+2*2^g:=f _ _ (by push_cast;linarith only[hhi]) have t:P≠2^23->4*(P*2^g)f _ _ (by push_cast;linarith only[hlo1 h]) have y:P=2^23->33554431*2^gf _ _ (by push_cast;linarith only[hlo2 h]) have C:P*2^g<=(2^24-1)*2^g:=Ἒ _ (by exact Nat.le_of_lt_succ ‹_›) have r:2*(P*2^(g+1))=4*(P*2^g):=by rw[Nat.pow_succ];ring have n:2^(g+1)=2*2^g:=by rw[Nat.pow_succ];ring have w:UnpackedFloat.round Format.binary32 (Model.modelSign neg) M q=.finite (Model.modelSign neg) P E l:=by rw[Model.round_exact_eq_finishRoundedMantissa _ _ _ _] have o:∀(L:ℕ) (T:ℤ),2^L*2^g<=M->M<2^L*2^g*2->max (((L+g:ℕ):ℤ)+1+q-24) (-149)=T->Format.binary32.targetExponent (totalExponent M q)=T:=λL T a c d=>by rw[<-Nat.pow_add] at a c simp only[totalExponent,qDg M _ a c,qFq];exact d by_cases v:2^25*2^g<=M . rw[o 25 E v (by clear hm hP1 hP2 hE hE2 l F H p z r n v;exact omS76 G C) (by clear hm hP1 hP2 l F H p G C r n v;exact omS77 hE z),qEa M q E (g+1) P (by clear hm hP1 hP2 hE hE2 l F H p G C r n v;(exact Eq.symm ‹_›)) l ?_ (by rw[r,n];(exact Nat.succ_le_of_lt ‹_›))];. exact qEf _ P E hP1 hP2 hE l . rw[r,n];by_cases j:P=2^23;. subst j;(clear hm hE hE2 F H p z n hP1 hP2 l C r;exact omS78 v G) . have:=t j;(exact Nat.succ_le_of_lt ‹_›) have j:P=2^23:=by by_contra hne have:=t hne have:(2^23+1)*2^g<=P*2^g:=Ἒ _ (by clear hm hE hE2 l F H p z G C r n v this;exact omS79 hP1 hne) (clear hm hP1 hP2 hE hE2 l F H p z C r n hne;(clear G;omega)) have D:=y j subst j by_cases x:-148<=E . rw[o 24 (E-1) (by clear hm hE hE2 F H p z n v hP1 hP2 l G C r x;exact omS80 D) (by clear hm hE hE2 F H p z n D hP1 hP2 l G C r x;exact omS81 v) (by clear hm F H p n v D hP1 hP2 l G C r;exact omS82 z x),qEa M q (E-1) g (2^24) (by clear hm hE hE2 F H p n v D hP1 hP2 l G C r x;exact omS83 z) ו (by clear hm hE hE2 F H p z n v hP1 hP2 l G C r x;exact omS84 D) (by clear hm hE hE2 F H p z n hP1 hP2 l G C r x;(clear D;exact omS85 v))];have:=Model.finishRoundedMantissa_normalized_carry FloatFormat.binary32 (Model.modelSign neg) (E-1+23) (by show-126<=E-1+23;(clear hm F H p n v D hP1 hP2 l G C r;exact omS86 x));rw[show (FloatFormat.binary32.fracWidth:ℤ)=23 from rfl] at this;rwa[((by clear hm hE hE2 F H p z n v D hP1 hP2 l G C r x;exact omS87):E-1+23-23=E-1),((by clear hm hE hE2 F H p z n v D hP1 hP2 l G C r x;exact omS88):E-1+23+1-23=E)] at this . rw[o 24 E (by clear hm hE hE2 F H p z n hP1 hP2 l G C r x;(clear v;exact omS80 D)) (by clear hm hE hE2 F H p z n D hP1 hP2 l G C r x;exact omS81 v) (by clear hm F H p n v D hP1 hP2 l G C r;exact omS89 hE z x),qEa M q E (g+1) (2^23) (by clear hm hE hE2 F H p n v D hP1 hP2 l G C r x;(exact Eq.symm ‹_›)) ו (by rw[n];(clear hm hE hE2 F H p z n hP1 hP2 l G C r x;exact omS90 D)) (by rw[n];(clear hm hE hE2 F H p z n v D hP1 hP2 l C r x;exact omS91 G))];exact qEf _ _ E (by norm_num1) (by norm_num1) hE l rw[w] simp only[toWord,Model.toNatBits,Model.ofModel,Model.ofModelBits] congr 1 show (UnpackedFloat.pack Format.binary32 _).toNat=_ rw[qBn _ _ _ _ hP1 hP2 (by clear hm hP1 hP2 F H p G C r n;exact omS92 hE) (by exact omS93 hE2)] cases neg<;>simp only[Model.modelSign,false_eq_true, ↓reduceIte,reduceCtorEq,Nat.reducePow,zero_add,Nat.add_left_cancel_iff] end abbrev B_D:=ExecFloat.Binary.descriptor (exponentBits:=11) (fractionBits:=52) lemma qFs (f:ὧ):Model.signBit (toModel (ofFloat f:Binary64))=decide (2^63<=f.toBits.toNat):=by rw[Model.signBit_eq_msb];show f.toBits.toBitVec.msb=_;rw[BitVec.msb_eq_decide];rfl lemma B_R (f:ὧ) (s:Ὡ) (E F:Ὣ) (hE1:1<=E) (hE:E<2047) (hF:F<2^52) (h:f.toBits.toNat=(if s then 2^63 else 0)+E*2^52+F): f.isFinite=true/\R f=(if s then-1 else 1)*((2^52+F:Ὣ):ℝ)*2^((E:Int)-1075):=by have g:Model.expField (toModel (ofFloat f:Binary64))=f.toBits.toNat/2^52%2^11:=by show ((f.toBits.toBitVec>>>52)&&&BitVec.ofNat 64 2047).toNat=_ rw[BitVec.toNat_and,BitVec.toNat_ushiftRight,BitVec.toNat_ofNat,Ἱ] exact Ἂ _ 11 have e:Model.fracField (toModel (ofFloat f:Binary64))=f.toBits.toNat%2^52:=by show (f.toBits.toBitVec&&&BitVec.ofNat 64 (2^52-1)).toNat=_ rw[BitVec.toNat_and,BitVec.toNat_ofNat] exact Ἂ _ 52 have i:Model.signBit (toModel (ofFloat f:Binary64))=s:=(qFs f).trans (by cases s<;>simp only[false_eq_true, ↓reduceIte,Nat.reducePow,zero_add,decide_eq_false_iff_not,not_le,decide_eq_true_eq] at h⊢<;>(clear g;omega)) have b:E<2^11:=(by exact Nat.lt_of_lt_of_le ‹_› ה) have hE':f.toBits.toNat/2^52%2^11=E:=by rw[h];cases s . rw[ἐ Bool.false_ne_true,Ἇ,ἥ E,Nat.mul_add_div ה,Ὃ hF,Ἵ,Ἁ b] . rw[ἱ rfl,show (2:ℕ)^63=2^11*2^52 by decide,<-ὰ,ἥ (2^11+E),Nat.mul_add_div ה,Ὃ hF,Ἵ,Nat.add_mod_left,Ἁ b] have hF':f.toBits.toNat%2^52=F:=by rw[h];cases s . rw[ἐ Bool.false_ne_true,Ἇ,ἥ E,Nat.mul_add_mod,Ἁ hF] . rw[ἱ rfl,show (2:ℕ)^63=2^11*2^52 by decide,<-ὰ,ἥ (2^11+E),Nat.mul_add_mod,Ἁ hF] have c:=Model.ofFields_signBit_expField_fracField (toModel (ofFloat f:Binary64)) rw[g,e,i,hE',hF'] at c have a:Ἑ (Model.ofFields B_D s E F)=true:=by rw[Model.isFinite_ofFields B_D _ _ _ b hF] show (E != 2047)=true simp only[bne_iff_ne,ne_eq];(clear hF h g e b;exact omS94 hE) have d:=Model.toDyadic?_ofFields_of_isFinite B_D _ _ _ b hF a rw[c,ἐ ((by clear hF h g e b;exact omS95 hE1):¬E=0)] at d rw[c] at a refine ⟨(qAh f).symm.trans a,?_⟩ rw[R,Model.toReal_eq,d] simp only[show Model.pow2 B_D.fracWidth=2^52 from rfl, show Int.ofNat E-Int.ofNat B_D.exponentBias-Int.ofNat B_D.fracWidth=(E:ℤ)-1075 by show (E:ℤ)-1023-52=_;(clear hE1 hE hF h g e b;exact omS96)] cases s<;>simp only[FloatLib.Numerics.Dyadic.toReal,signedSignificand,false_eq_true, ↓reduceIte,Nat.reducePow,Int.ofNat_eq_natCast,Nat.cast_add,Nat.cast_ofNat,Int.cast_add,Int.cast_ofNat,Int.cast_natCast,one_mul,neg_add_rev,Int.reduceNeg,Int.cast_neg,neg_mul] def B_near (A:Ὣ) (S:Ὡ) (ex fr:Ὣ):Prop:= ∃M,A=(if S then 2^63 else 0)+M/\(ex*2^23+fr)*2^29>>29=x) (h1:897<=Ѧx/2^23%2^11) (h2:Ѧx/2^23%2^11<1151): Ѧx<2^35/\B_near ѦA (decide (2^34<=Ѧx)) (Ѧx/2^23%2^11) (Ѧx%2^23):=by have a:=A.toNat_lt have e:Ѧx=(ѦA+268435455)%2^64/2^29:=by rw[<-hx,ἰ,ἤ] norm_num[Ἱ] refine ⟨by (clear hx h1 h2 a;exact omS97 e),?_⟩ unfold B_near by_cases h:2^34<=Ѧx . simp only[h,decide_true,ite_true];exact ⟨ѦA-2^63,by (clear hx;exact omS98 h1 e h),by (clear hx;exact omS99 e h),by (clear hx h1 h2;exact omS100 a e h)⟩ . simp only[h,decide_false,Bool.false_eq_true,ite_false];exact ⟨ѦA,by (clear hx h1 h2 a e h;exact omS101),by (clear hx h;exact omS102 e),by (clear hx;exact omS103 h1 a e h)⟩ lemma qHw (x:Ὠ) (hx:Ѧx<2^35) (h1:897<=Ѧx/2^23%2^11) (h2:Ѧx/2^23%2^11<1151): (((x>>>34)<<<31) ||| ((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<23))).toUInt32= ὺ ((if decide (2^34<=Ѧx) then 2^31 else 0)+(Ѧx/2^23%2^11-896)*2^23+Ѧx%2^23):=by have G1:Ѧx%2^34/2^23=Ѧx/2^23%2^11:=by rw[show (2:ℕ)^34=2^23*2^11 by decide];exact Nat.mod_mul_right_div_self _ _ _ have F1:Ѧx%2^34%2^23=Ѧx%2^23:=Nat.mod_mod_of_dvd _ (Nat.pow_dvd_pow 2 ה) have h1':897<=Ѧx%2^34/2^23:=by rw[G1];exact h1 have h2':Ѧx%2^34/2^23<1151:=by rw[G1];exact h2 have L896:896*2^23<=Ѧx%2^34:=Nat.le_trans ה ((Nat.le_div_iff_mul_le ה).mp h1') have b:((x>>>34)<<<31).toNat=(Ѧx/2^34)*2^31:=by rw[UInt64.toNat_shiftLeft,ἰ] norm_num[Ἱ,ὁ] exact Nat.lt_of_lt_of_le (Nat.mul_lt_mul_of_pos_right (Ἰ (hx:Ѧx<17179869184*2)) ה) ה have a:(x&&&(0x3FFFFFFFF:Ὠ)).toNat=Ѧx%2^34:=by rw[Ὅ] exact Ἂ _ 34 have d:((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<23)).toNat=Ѧx%2^34-896*2^23:=by rw[show ((896:Ὠ)<<<23)=7516192768 by decide,UInt64.toNat_sub_of_le,a] . rfl . rw[Ὤ,a];exact L896 have c:(Ѧx/2^34)*2^31 ||| (Ѧx%2^34-896*2^23)=(Ѧx/2^34)*2^31+(Ѧx%2^34-896*2^23):=by rw[ἥ (Ѧx/2^34)] exact (Nat.two_pow_add_eq_or_of_lt (Nat.lt_of_lt_of_le (Nat.sub_lt_sub_right L896 ((Nat.div_lt_iff_lt_mul ה).mp h2')) ה) _).symm have GEF:Ѧx%2^34-896*2^23=(Ѧx/2^23%2^11-896)*2^23+Ѧx%2^23:=by rw[<-Nat.div_add_mod' (Ѧx%2^34) (2^23),G1,F1,Nat.sub_add_comm (Ἒ _ (Nat.le_of_lt h1)),<-Nat.sub_mul] apply ἠ.mp rw[UInt64.toNat_toUInt32,UInt64.toNat_or,b,d,c,ὡ] simp only[decide_eq_true_eq] split_ifs with hh . rw[Nat.div_eq_of_lt_le (k:=1) (by rw[Ὑ];exact hh) hx,GEF,Ὑ,ὢ] . rw[Ὃ (Nat.not_le.mp hh),GEF,ὒ,Ἇ,Ἇ] lemma qEs (A B:Ὠ) (h:zivW A B≠Е): ∃(S:Ὡ) (ex fr:Ὣ),897<=ex/\ex<1151/\fr<2^23/\zivW A B=ὺ ((if S then 2^31 else 0)+(ex-896)*2^23+fr)/\B_near ѦA S ex fr/\B_near ѦB S ex fr:=by unfold zivW at h⊢ dsimp only at h⊢ generalize hx:(A+(0x0FFFFFFF:Ὠ))>>>(29:Ὠ)=x at h⊢ generalize hy:(B+(0x0FFFFFFF:Ὠ))>>>(29:Ὠ)=y at h⊢ have hex:((x>>>(23:Ὠ))&&&(0x7FF:Ὠ)).toNat=Ѧx/2^23%2^11:=by rw[Ὅ,ἰ] have:=Ἂ (Ѧx>>>23) 11 norm_num[Ἱ] at this⊢ exact this generalize (x>>>(23:Ὠ))&&&(0x7FF:Ὠ)=ex at h hex⊢ split at h . rename_i hc;have hc0:=hc;obtain ⟨hxy,hc⟩:=ὕ.mp hc;have hxy:x=y:=by simpa only[beq_iff_eq] using hxy subst hxy;have hc:ex-(897:Ὠ)<(254:Ὠ):=by simpa only[BEq.rfl,Bool.true_and,decide_eq_true_eq] using hc rw[ἴ,ὲ] at hc;have hv:=ex.toNat_lt;norm_num at hc hv;have h1:897<=Ѧx/2^23%2^11:=(by clear hx h hy hv;exact omS107 hex hc);have h2:Ѧx/2^23%2^11<1151:=(by clear hx h hy hv;exact omS108 hex hc);simp only[hc0,ite_true];obtain ⟨hx35,ha⟩:=B_x A x hx h1 h2;exact ⟨_,_,_,h1,h2,by (clear hx hex h hy hc hv h1 h2 hx35;exact omS109),qHw x hx35 h1 h2,ha,(B_x B x hy h1 h2).2⟩ . exact absurd rfl h lemma qR0 (Y:Ὡ) (r:ὥ) (he:expOf r≠255):r&&&((if Y then (0:ὥ) else Е) ||| ((r>>>(31:ὥ))-1))=act Y r:=by have b:=r.toNat_lt have f:∀u:ὥ,u&&&Е=u:=λu=>UInt32.toNat_inj.mp (by rw[Ἧ];show ѥu&&&(2^32-1)=_;rw[Ἂ];exact Ἁ u.toNat_lt) by_cases h:2^31<=ѥr . have e:r>>>(31:ὥ)=1:=UInt32.toNat_inj.mp (by rw[UInt32.toNat_shiftRight];show ѥr>>>31=1;rw[Ἱ];(clear he;exact omS110 b h)) have g:(r&&&س!=0)=true:=by have:(r&&&س).toNat≠0:=by rw[Ἧ];show ѥr&&&2^31≠0;rw[Nat.and_two_pow];simp only[Nat.testBit_eq_decide_div_mod_eq,Nat.reducePow,ne_eq,mul_eq_zero,Bool.toNat_eq_zero,decide_eq_false_iff_not,Nat.mod_two_not_eq_one,OfNat.ofNat_ne_zero,or_false,Nat.mod_two_not_eq_zero];(clear he e;exact omS111 b h) simp only[bne_iff_ne];intro c;rw[c] at this;exact this rfl cases Y<;>simp only[false_eq_true, ↓reduceIte,e,sub_self,UInt32.or_zero,f,act,UInt32.or_self,UInt32.and_zero,reluW,g,he,decide_false,Bool.false_and,Bool.not_false,Bool.and_self] . have e:r>>>(31:ὥ)=0:=UInt32.toNat_inj.mp (by rw[UInt32.toNat_shiftRight];show ѥr>>>31=0;rw[Ἱ];(clear he;exact omS112 h)) have g:(r&&&س)=0:=UInt32.toNat_inj.mp (by rw[Ἧ];show ѥr&&&2^31=0;rw[Nat.and_two_pow];simp only[Nat.testBit_eq_decide_div_mod_eq,Nat.reducePow,mul_eq_zero,Bool.toNat_eq_zero,decide_eq_false_iff_not,Nat.mod_two_not_eq_one,OfNat.ofNat_ne_zero,or_false];(clear he e;exact omS113 h)) cases Y<;>simp only[false_eq_true, ↓reduceIte,e,zero_sub,UInt32.or_neg_one,UInt32.and_neg_one,act,reluW,g,bne_self_eq_false,Bool.not_and,Bool.false_and] lemma qRe (w:ὥ):(expOf w).toNat=ѥw/2^23%2^8:=by unfold expOf rw[Ἧ,UInt32.toNat_shiftRight] show (ѥw>>>23)&&&(2^8-1)=_ rw[Ἂ,Ἱ] lemma qR1 (r:ὥ) (S:Ὡ) (ex fr:Ὣ) (h1:897<=ex) (h2:ex<1151) (h3:fr<2^23) (hz:r=ὺ ((if S then 2^31 else 0)+(ex-896)*2^23+fr)):expOf r≠255:=by intro e;have a:=qRe r;rw[e] at a;change 255=_ at a;rw[hz,ὡ] at a;cases S<;>simp only[Bool.false_eq_true,ite_false,ite_true] at a<;>(clear e hz;omega) lemma qB6 (s e:ὧ) (h:ziv s e≠Е): ∃(S:Ὡ) (ex fr:Ὣ),897<=ex/\ex<1151/\fr<2^23/\ziv s e=ὺ ((if S then 2^31 else 0)+(ex-896)*2^23+fr)/\B_near (s+e).toBits.toNat S ex fr/\B_near (s-e).toBits.toNat S ex fr:= qEs (s+e).toBits (s-e).toBits h set_option maxRecDepth 8192 in lemma qA4 (f:ὧ) (S:Ὡ) (ex fr:Ὣ) (h1:897<=ex) (h2:ex<1151) (hfr:fr<2^23) (hn:B_near f.toBits.toNat S ex fr): f.isFinite=true/\∃v:ℝ,R f=(if S then-v else v)/\v<=(2^53+fr*2^30+2^29)*2^((ex:Int)-1076)/\(fr≠0->(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)2^53+fr*2^30Ἦ ?_ c,Ἦ ?_ c⟩ . rw[l,mul_assoc,j];cases S<;>simp only[false_eq_true, ↓reduceIte,one_mul,neg_mul] . exact_mod_cast i . rw[sub_lt_iff_lt_add];exact_mod_cast e h . rw[sub_lt_iff_lt_add];exact_mod_cast g lemma qBw (s e:ὧ) (h:ziv s e≠Е):(s+e).isFinite=true/\(s-e).isFinite=true/\(2:ℝ)^(-127:ℤ)<= |R (s+e)|:=by obtain ⟨S,f,c,b,d,a,-,j,k⟩:=qB6 s e h;obtain ⟨g,v,i,-,-,l⟩:=qA4 _ S f c b d a j;refine ⟨g,(qA4 _ S f c b d a k).1,?_⟩ exact (show (2:ℝ)^(-127:ℤ)<=(2^53-2^28)*2^(-179:ℤ) by (norm_num1)).trans ((ἁ (ἒ one_le_two (by clear h a;exact omS124 b)) ו).trans (l.le.trans (by rw[i];cases S<;>simp only[false_eq_true, ↓reduceIte,le_abs_self,abs_neg]))) lemma qAx (w:ὥ) (h:expOf w≠255):wv w=(ἂ w:ℝ):=by rw[wv,Model.toReal_eq,ofW,ἶ w h];simp only[rationalWord,Ἠ] lemma qEl (a b:ѐ) (start n:Ὣ): (dsum a b start n:ℚ)*2^(-298:Int)=∑ j∈Ἣ n,ἂ a[start+j]!*ἂ b[start+j]!:=by have c:∀a b:ὥ,((sv a:ℚ)*sv b*(2:ℚ)^(idxOf a+idxOf b))*2^(-298:Int)=ἂ a*ἂ b:=λa b=>by simp only[rationalWord,decodeD_toRat] rw[show (-298:Int)=-149+-149 by (norm_num1),Ἓ ἓ] rw[ᾂ ἓ,ᾂ ἓ,Ἡ,Ἡ,pow_add] norm_num[zpow_neg,Ἡ] ring induction n generalizing start with | zero=>simp only[dsum,Int.cast_zero,Int.reduceNeg,zpow_neg,zpow_ofNat,zero_mul,Finset.range_zero,Finset.sum_empty] | succ n ih=> rw[dsum,Int.cast_add,Int.cast_mul,Int.cast_mul,Int.cast_pow,Int.cast_ofNat,add_mul,ih,Finset.sum_range_succ',Ἵ,c,add_comm] refine congrArg (· +_) ?_ apply Ἷ rfl intro j _ rw[ὢ,Nat.add_comm 1 j] lemma qEc (n:Ὣ) (fa fb:Ὣ->ὥ) (hf:∀j,jexpOf (fa j)≠255/\expOf (fb j)≠255) (hn:(∑ j∈Ἣ n,ἂ (fa j)*ἂ (fb j))≠0): ∃d:FloatLib.Numerics.Dyadic, d.toRat=(∑ j∈Ἣ n,ἂ (fa j)*ἂ (fb j))/\dotOf n fa fb=toWord (ἕ Fmt d):=by let a:=Array.ofFn (n:=n) λi=>fa i let b:=Array.ofFn (n:=n) λi=>fb i have e:ѧa=n:=by simp only[Array.size_ofFn,a] have g:ѧb=n:=by simp only[Array.size_ofFn,b] have c:(dsum a b 0 n:ℚ)*2^(-298:Int)=∑ j∈Ἣ n,ἂ (fa j)*ἂ (fb j):=by rw[qEl] refine Ἷ rfl λj m=>?_ have h:=Ὁ.mp m rw[Ἇ,qAb n fa j h,qAb n fb j h] have l:dsum a b 0 n≠0:=λh=>hn (by rw[<-c,h];simp only[Int.cast_zero,Int.reduceNeg,zpow_neg,zpow_ofNat,zero_mul]) have Z:=qEg a b (by rw[e,g]) λk f=>by rw[e] at f rw[qAb n fa k f,qAb n fb k f];exact hf k f rw[e] at Z refine ⟨ofIntDyadic (dsum a b 0 n) (-298),by rw[toRat_ofIntDyadic,c],?_⟩ show dotSpec a b=_ rw[<-Z];simp only[finishWord,l, ↓reduceIte,Int.reduceNeg] lemma qIg:ἂ oneW=1:=by norm_num[rationalWord,decodeD,show expOf oneW=127 by decide,show fracOf oneW=0 by decide,show signOf oneW=false by decide,FloatLib.Numerics.Dyadic.toRat,FloatLib.Numerics.Dyadic.signedSignificand] lemma qM1 (y:ὧ) (hy:yᶠ):y*dv oneW=y:=by obtain ⟨h1,h2⟩:=qAm oneW ה obtain ⟨x,hx,-⟩:=qDk y hy obtain ⟨o,ho,eo⟩:=qDk _ h1 have e1:o.toReal=1:=by rw[eo,h2,qAx oneW ה,qIg];norm_num have os:o.significand≠0:=λh=>by have:=(A_s o).2 h;rw[e1] at this;norm_num at this have on:o.negative=false:=by cases hn:o.negative · rfl · have q:=qD4 o;rw[hn,e1] at q;have:=qE9 o os;simp only[A_r,↓reduceIte] at q;linarith only[this,q] apply qIe rw[qCq hx ho hy h1] have hy':=Model.Internal.Directed.roundDyadic_toDyadic? qAj .nearest hx split · rename_i z have xs:x.significand=0:=by rcases Nat.mul_eq_zero.1 z with h|h;exact h;exact absurd h os rw[<-hy',on,Bool.xor_false] obtain ⟨n,m,e⟩:=x simp only at xs subst xs rw[Model.Internal.Directed.roundDyadic_zero] · rename_i z rw[<-hy'] exact ExactRuntime.roundDyadic_congr _ qAj _ _ z (λh=>z (by rw[h,ὒ])) (Rat.cast_injective (α:=ℝ) (by rw[Ἠ,Ἠ,Model.Dyadic.toReal_mul,e1,mul_one])) lemma qHv (n:Ὣ) (xw ww:Ὣ->ὥ) (bw:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true): ((∑ j∈Ἣ (n+1),ἂ (if j?_ have a:=Ὁ.mp b simp only[a,ite_true] rw[qAx _ (qAe _ (hx t a)),qAx _ (qAe _ (hw t a)),Rat.cast_mul] section variable (s e:ὧ) (V:ℝ) (hlo:R (s-e)< V) (hhi:V< R (s+e)) (h:ziv s e≠Е) include s e V hlo hhi h lemma qB8: ∃(S:Ὡ) (ex fr:Ὣ) (W:ℝ),897<=ex/\ex<1151/\fr<2^23/\ziv s e=ὺ ((if S then 2^31 else 0)+(ex-896)*2^23+fr)/\V=(if S then-W else W)/\W<(2^53+fr*2^30+2^29)*2^((ex:Int)-1076)/\(fr≠0->(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)(lob1 h).trans hlo . exact λh=>by linarith only[loa1 h,hhi,loa1,h] . exact lob.trans hlo . linarith only[loa,hhi] lemma qG5:V≠0:=by obtain ⟨S,ex,fr,W,-,-,-,-,hV,-,-,hW3⟩:=qB8 s e V hlo hhi h;have hb0:(0:ℝ)<2^((ex:Int)-1076):=ἵ ו _;have hA:(0:ℝ)<=(2^53-2^28)*2^((ex:Int)-1076):=Ἆ ו hb0.le;intro h0;rw[h0] at hV;cases S;. simp only[Bool.false_eq_true,ite_false] at hV;linarith only[hW3,hA,hV] . simp only[ite_true] at hV;linarith only[hW3,hA,hV] end lemma qEo (d:FloatLib.Numerics.Dyadic) (S:Ὡ) (ex fr:Ὣ) (h1:897<=ex) (h2:ex<1151) (h3:fr<2^23) (W:ℝ) (hd:(d.toRat:ℝ)=if S then-W else W) (hW1:W<(2^53+fr*2^30+2^29)*2^((ex:Int)-1076)) (hW2:fr≠0->(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)cases S<;> simp only[Bool.false_eq_true,ite_false,ite_true,Int.ofNat_eq_natCast,Int.cast_neg,Int.cast_natCast] at hdV . exact ⟨by linarith only[hdV],rfl⟩ . exfalso;linarith only[hW0,hmq,hdV] . exfalso;linarith only[hW0,hmq,hdV] . exact ⟨by linarith only[hdV],rfl⟩ obtain ⟨hMW,rfl⟩:=hMW have hm:m≠0:=by rintro rfl simp only[CharP.cast_eq_zero,zero_mul] at hMW linarith only[hW0,hMW] have hword:=qE4 neg m q (2^23+fr) ((ex:Int)-1046) hm (by clear h1 h2 hm;exact omS125) (by clear h1 h2 hm;exact omS126 h3) (by clear h3 hm;exact omS127 h1) (by clear h3 hm;exact omS128 h2) (by rw[hMW,hE];push_cast;linarith only[hW0,hW1]) (by intro hfr have hfr':fr≠0:=by intro h0;exact hfr (by clear h1 h2 h3 hm hfr;exact omS129 h0) have:=hW2 hfr' rw[hMW,hE];push_cast;linarith only[this]) (by intro _ rw[hMW,hE];linarith only[hW3]) have e1:((ex:Int)-1046+150).toNat=ex-896:=(by clear h3 hm hword;exact omS130) have e2:(2^23+fr)%2^23=fr:=(by clear h1 h2 hm hword e1;exact omS131 h3) rw[hword,e1,e2] lemma qIq (s e:ὧ) (d:FloatLib.Numerics.Dyadic) (hlo:R (s-e)<(d.toRat:ℝ)) (hhi:(d.toRat:ℝ)ὥ) (bw:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (s e:ὧ) (hlo:R (s-e)if tif tif tif tby by_cases hj:jqG5 s e _ hlo hhi h (by rw[<-hsum,h0,Rat.cast_zero]) have q:(d.toRat:ℝ)=exactS n xw ww bw:=by rw[hd,hsum] rw[hw'] exact qIq s e d (by rw[q];exact hlo) (by rw[q];exact hhi) h end section lemma qDn (n:Ὣ) (hn:n<2^20) (xw ww:Ὣ->ὥ) (bw:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (l:љ) (hl:l.Nodup) (hl2:∀t∈l,tt∉l->xw t&&&В=0\/ww t&&&В=0) (s e:ὧ) (hs:let r:=l.foldl (λ(acc:F1) t=>let q:=dv (xw t)*dv (ww t) F1.mk (acc.s+q) (acc.t+q.abs)) ⟨0,0⟩;s=r.s+dv bw/\e=nfOf n*(r.t+(dv bw).abs)) (h:ziv s e≠Е): ziv s e=dotOf (n+1) (λt=>if tif tsimp only[Array.uset_eq_set,Array.size_set] lemma qFo {α:Type} [Inhabited α] (a:Array α) (i q:Ὣ) (v:α) (hi:i< ѧa):(a.set i v hi)[q]! =if q=i then v else a[q]!:=by by_cases hq:q< ѧa . rw[Ἕ _ q (by simpa only[Array.size_set] using hq),Ἕ a q hq,Array.getElem_set];by_cases e:q=i;. simp only[e, ↓reduceIte] . rw[ἐ e,ἐ (λh=>e h.symm)] . rw[ὑ _ q (by simpa only[Array.size_set,not_lt] using hq),ὑ a q hq,ἐ (by exact omS132 hi hq)] lemma qBu (a:ѐ) (i:ὦ) (v:ὥ) (q:Ὣ) (hs:ѧa<2^32) (hi:Ѥi< ѧa):(wrW a i v)[q]! =if q=Ѥi then v else a[q]!:=by have h:iὪ) (S:Ὣ->Prop) (out:ё):Prop:= ѧout=N/\∀q,qS q->out[q]! =sp q section variable {N:Ὣ} {sp:Ὣ->Ὢ} include N sp lemma qAk {S:Ὣ->Prop} {out:ё} (hN:N<2^32) (h:C_Inv N sp S out) {u:ὦ} {p:Ὣ} {v:Ὢ} (hu:Ѥu=p) (hp:pq=p\/S q) (wrW out u v):=by obtain ⟨h1,h2⟩:=h;refine ⟨by rw[qBh,h1],λq hq hS=>?_⟩;rw[qBu _ _ _ _ (by clear hu hp hq;omega) (by clear hN hq;omega),hu];by_cases e:q=p;. rw[ἱ e,e,hv] . rw[ἐ e];exact h2 q hq (hS.resolve_left e) lemma qA5 {S S':Ὣ->Prop} {out:ё} (h:C_Inv N sp S out) (hS:∀q,qS' q->S q):C_Inv N sp S' out:=⟨h.1,λq hq h'=>h.2 q hq (hS q hq h')⟩ lemma qBv {S:Ὣ->Prop} {out:ё} (h:C_Inv N sp S out) (hS:∀q,qS q):out=Array.ofFn (n:=N) λq=>sp q.val:=by obtain ⟨h1,h2⟩:=h;apply Մ;. simp only[h1,Array.size_ofFn] . intro q h3 h4;have h5:qh0 (ἠ.mp h);(clear h1 h2 a1 a2 a3 a4 h0;omega) rw[ἃ,ὓ _ _ h3] at h1;rw[ἳ] at h2;have h4:(0x00800000:ὥ)<=v:=by rw[ἃ];(clear h2 a2 a4 h0 h3;exact omS133 h1 a1 a3 a5) simp only[Bool.or_eq_true,decide_eq_true_eq];right;rw[ἃ,ὓ _ _ h4];(clear h1 a1 a5 h0 h3 h4;exact omS134 h2 a2 a3 a4) lemma qHu (c u lo:ὥ) (h:c<=if uomega lemma qH2 (c v hi:ὥ) (h:(if hiomega lemma qB2 (w:ὥ) (h:good w=true):good (w&&&В)=true:=by have e:(w&&&В)&&&В=w&&&В:=by rw[UInt32.and_assoc,UInt32.and_self] unfold good at h⊢;simpa only[e] using h lemma qCx {h:ὥ} (h1:h<У):h<=В:=by have a1:(У:ὥ).toNat=У:=rfl;have a2:(В:ὥ).toNat=В:=rfl;rw[ἳ] at h1;rw[ἃ];(exact Nat.le_of_lt (Nat.lt_of_lt_of_le ‹_› ה)) def C_Hv (A:ё) (h:Ὢ):Prop:= good h=true/\h<=В/\(∀k,k< ѧA->good A[k]! =true)/\ ∀k,k< ѧA->A[k]!&&&В<=h lemma qFa (r v hi:ὥ) (h:(if hiomega lemma qHj (A:ѐ) (n:ὦ) (hn:Ѥn<=ѧA) (d:Ὣ): ∀(i:ὦ) (lo hi:ὥ),Ѥi+d=Ѥn->scan A n i hn lo hi≠Е-> (0x7FFFFF:ὥ)<=lo/\hi<У/\hi<=scan A n i hn lo hi/\scan A n i hn lo hi<У/\(good hi=true->good (scan A n i hn lo hi)=true)/\ ∀k,Ѥi<=k->k< Ѥn->good A[k]! =true/\A[k]!&&&В<=scan A n i hn lo hi:=by induction d with | zero=> intro i lo hi he h have e:scan A n i hn lo hi=if 0x007FFFFF<=lo/\hi<У then hi else Е:=by rw[scan,ἔ (by rw[А];(clear hn h;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))] rw[e] at h⊢ by_cases c:0x007FFFFF<=lo/\hi<У . rw[ἱ c];exact ⟨c.1,c.2,Ὓ _,c.2,id,λk h1 h2=>by (clear hn h e c;exact omS135 he h1 h2)⟩ . rw[ἐ c] at h;exact absurd rfl h | succ d ih=> intro i lo hi he h have hi':ih5 ?_,λk hk1 hk2=>?_⟩ . split;. exact qB2 _ hg . exact g0 . by_cases e2:k=Ѥi;. subst e2;rw[Ἕ A Ѥi hb];exact ⟨hg,h11⟩ . exact h6 k (by rw[usz i n hi'];(clear he hi' h e h1 h2 h3 h4 h7 h8 h9 h10 h11 h12 hk2;exact omS138 hk1 e2)) hk2 lemma qBi (A:ѐ) (hs:ѧA<2^32) (h:scan A A.usize 0 (qAc A) Е 0≠Е):C_Hv A (scan A A.usize 0 (qAc A) Е 0):=by have e:=qBe A hs;have h0:(0:ὦ).toNat=0:=rfl;obtain ⟨-,-,-,h4,h5,h6⟩:=qHj A A.usize (qAc A) ѧA 0 _ _ (by rw[h0,e];(clear hs h e h0;exact omS139)) h;have h7:∀k,k< ѧA->good A[k]! =true/\A[k]!&&&В<=scan A A.usize 0 (qAc A) Е 0:=λk hk=>h6 k (by exact Nat.zero_le _) (by clear hs h h0 h4;exact omS140 e hk);exact ⟨h5 rfl,qCx h4,λk hk=>(h7 k hk).1,λk hk=>(h7 k hk).2⟩ lemma qF6 (a b:ὥ):a<=a ||| b/\b<=a ||| b:=by rw[ἃ,ἃ,UInt32.toNat_or];exact ⟨Nat.left_le_or,Nat.right_le_or⟩ lemma qBt (v:ὥ) (h1:v=0\/0x800000<=v) (h2:v<У):(v==0 || v-(0x00800000:ὥ)<=(0x7EFFFFFF:ὥ))=true:=by rcases h1 with rfl | h1;. rfl . have a1:(У:ὥ).toNat=У:=rfl;have a2:(0x00800000:ὥ).toNat=0x00800000:=rfl;have a3:(0x7EFFFFFF:ὥ).toNat=0x7EFFFFFF:=rfl;simp only[Bool.or_eq_true,decide_eq_true_eq];right;rw[ἃ,ὓ _ _ h1];rw[ἳ] at h2;rw[ἃ] at h1;exact omS134 h2 a1 a2 a3 lemma qFe (a b:ὥ):a&&&b<=a/\a&&&b<=b:=by rw[ἃ,ἃ,Ἧ];exact ⟨Nat.and_le_left,Nat.and_le_right⟩ lemma qGi (v:ὥ) (h:0x7FFFFF<=v-1):v=0\/0x800000<=v:=by by_cases z:v=0;. exact .inl z . right;have a1:(0x7FFFFF:ὥ).toNat=0x7FFFFF:=rfl;have a2:(0x800000:ὥ).toNat=0x800000:=rfl;have a3:(1:ὥ).toNat=1:=rfl;have a4:ѥv≠0:=λe=>z (ἠ.mp (by rw[e];rfl));have a5:=v.toNat_lt;have h1:=ἃ.mp h;rw[a1,UInt32.toNat_sub,a3] at h1;rw[ἃ,a2];(clear h z a1 a2 a3;exact omS141 a4 h1) lemma qF3 (A:ѐ) (n:ὦ) (hn:Ѥn<=ѧA) (d:Ὣ): ∀(i:ὦ) (o s:ὥ),Ѥi+d=Ѥn->scanF A n i hn o s≠Е-> o<=scanF A n i hn o s/\scanF A n i hn o s<У/\0x7FFFFF<=s/\((o=0\/0x800000<=o)->scanF A n i hn o s=0\/0x800000<=scanF A n i hn o s)/\ ∀k,Ѥi<=k->k< Ѥn->good A[k]! =true/\A[k]!&&&В<=scanF A n i hn o s:=by induction d with | zero=> intro i o s he h rw[scanF,ἔ (by rw[А];(clear hn h;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))] at h⊢ by_cases c:0x7FFFFF<=s/\o<У . rw[ἱ c];exact ⟨Ὓ _,c.2,c.1,id,λk h1 h2=>by (clear hn h c;exact omS135 he h1 h2)⟩ . rw[ἐ c] at h;exact absurd rfl h | succ d ih=> intro i o s he h have hi':ih4 ?_,λk hk1 hk2=>?_⟩ . rcases hv with hv | hv . rcases g0 with g0 | g0;. left;rw[g0,hv];rfl . right;exact UInt32.le_trans g0 h6 . right;exact UInt32.le_trans hv h7 . by_cases e2:k=Ѥi;. subst e2;rw[Ἕ A Ѥi hb];exact ⟨qBt _ hv (UInt32.lt_of_le_of_lt hl h2),hl⟩ . exact h5 k (by rw[usz i n hi'];(clear he h hb h1 h2 h3 h6 h7 h8 h9 hv hl hk2;exact omS138 hk1 e2)) hk2 lemma qB1 (A:ѐ) (hs:ѧA<2^32) (h:scanF A A.usize 0 (qAc A) 0 Е≠Е):C_Hv A (scanF A A.usize 0 (qAc A) 0 Е):=by have e:=qBe A hs;have h0:(0:ὦ).toNat=0:=rfl;obtain ⟨-,h2,-,h4,h5⟩:=qF3 A A.usize (qAc A) ѧA 0 _ _ (by rw[h0,e];(clear hs h e h0;exact omS139)) h;generalize scanF A A.usize 0 (qAc A) 0 Е=S at*;have hp:=qCx h2;have hm:S&&&В=S:=by have a:(В:ὥ).toNat=2^31-1:=rfl;apply ἠ.mp;rw[ἃ,a] at hp;rw[Ἧ,a,Ἂ];(clear hs e h0 h h2 a;exact omS142 hp) have hg:good S=true:=by unfold good;dsimp only;rw[hm];exact qBt _ (h4 (Or.inl rfl)) h2 exact ⟨hg,hp,λk hk=>(h5 k (by exact Nat.zero_le _) (by clear hs h0 h h2 hp hm;omega)).1,λk hk=>(h5 k (by exact Nat.zero_le _) (by clear hs h0 h h2 hp hm;omega)).2⟩ lemma qA8 (r:Ὣ) (A:ѐ) (hs:ѧA<2^32) (h:scanH r A≠Е):C_Hv A (scanH r A):=by revert h;unfold scanH;dsimp only;by_cases c:(r==1)=true . rw[ἱ c];split;. exact qBi A hs . exact qB1 A hs . rw[ἐ c];exact qBi A hs lemma qGd (r:Ὣ) (A:ѐ) (h8:r≠8) (h1:r≠1) (h4:r≠4) (hs:ѧA<2^32) (h:scanW r A≠Е):C_Hv A (scanW r A):=by have e:scanW r A=scanH r A:=by unfold scanW;rw[ἐ (by simp only[or_eq_true,beq_iff_eq,h8,h1,or_self,h4,not_false_eq_true])] rw[e] at h⊢;exact qA8 r A hs h def C_out (I:Ὣ) (Y:Ὡ) (X W b:ё) (i j:Ὣ):Ὢ:= act Y (dotOf (I+1) (λt=>if tif tgood X[i*I+t]! =true:=λ_ ht=>G.gX _ (by rw[<-G.hX];exact qCj hi ht) lemma C_G.gw {j:Ὣ} (hj:jgood W[j*I+t]! =true:=λ_ ht=>G.gW _ (by rw[<-G.hW];exact qCj hj ht) lemma qHx (Y:Ὡ) {i j:Ὣ} (hi:i let q:=dv X[i*I+t]!*dv W[j*I+t]! F1.mk (acc.s+q) (acc.t+q.abs)) ⟨0,0⟩;s=r.s/\e=r.t): fin I Y X W b i j s (nfOf I) e b[j]! =C_out I Y X W b i j:=by obtain ⟨h1,h2⟩:=hs unfold fin dsimp only split . unfold slowOut C_out;rw[qAi] . rename_i h;unfold C_out;congr 1;exact qDn I G.ni (λt=>X[i*I+t]!) (λt=>W[j*I+t]!) b[j]! (G.gx hi) (G.gw hj) (G.gb j (by rw[<-G.hb];exact hj)) _ Ὂ (λt ht=>Ἅ.mp ht) (λt ht h3=>absurd (Ἅ.mpr ht) h3) _ _ ⟨by rw[h1],by rw[h2]⟩ (by simpa only[ne_eq,beq_iff_eq] using h) end lemma qE2 {X W:ѐ} {xo wo n:ὦ} (hX:ѧX<2^32) (hW:ѧW<2^32) (h1:Ѥxo+Ѥn<=ѧX) (h2:Ѥwo+Ѥn<=ѧW) (d:Ὣ):∀(t:ὦ) (s a:ὧ),Ѥt+d=Ѥn-> tightGo X W xo wo n t s a=(List.range' Ѥt d).foldl (λ(acc:F1) k=>let q:=dv X[Ѥxo+k]!*dv W[Ѥwo+k]! F1.mk (acc.s+q) (acc.t+q.abs)) ⟨s,a⟩:=by induction d with | zero=> intro t s a he rw[tightGo,ἔ (by rw[А];(clear hX hW h1 h2;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))] rfl | succ d ih=> intro t s a he have ht:t ziv (s+dv b[j]!) (nfOf I*(dv hh*a+(dv b[j]!).abs))= dotOf (I+1) (λt=>if tif tt∉L->X[i*I+t]!&&&В=0) (hs:s=L.foldl (λ(acc:ὧ) t=>acc+dv X[i*I+t]!*dv W[j*I+t]!) 0): fin8 I Y X W b i j s (nfOf I) (L.foldl (λ(a:ὧ) t=>a+(dv X[i*I+t]!).abs) 0) hv b[j]! ѩI=C_out I Y X W b i j:=by have gb:=G.gb j (by rw[<-G.hb];exact hj) exact qDw G Y hi hj λh=>by obtain ⟨-,-,k⟩:=qBw _ _ h obtain ⟨c1,c2⟩:=qC8 I G.ni (λt=>X[i*I+t]!) (λt=>W[j*I+t]!) b[j]! hv (G.gx hi) (G.gw hj) gb g1 g2 L hl hl2 g4 hz _ _ ⟨by rw[hs],rfl⟩ k exact qCn I G.ni _ _ _ (G.gx hi) (G.gw hj) gb _ _ c1 c2 h lemma qDu {s:ὧ} {hv:Ὢ} (g1:good hv=true) (g2:hv<=В) (g4:∀t,tW[j*I+t]!&&&В<=hv) (L:љ) (hl:L.Nodup) (hl2:∀t∈L,tt∉L->X[i*I+t]!&&&В=0) (hs:s=L.foldl (λ(acc:ὧ) t=>acc+dv X[i*I+t]!*dv W[j*I+t]!) 0): fin8 I Y X W b i j s (nfOf I) (L.foldl (λ(a:ὧ) t=>a+(dv X[i*I+t]!).abs) 0) hv b[j]! ѩI=C_out I Y X W b i j:= qDL G Y hi hj g1 g2 L hl hl2 (λt ht=>g4 t (hl2 t ht)) hz hs end end lemma qC5 (x:ὤ) (i:ὦ) (h:Ѥi< Ѩx):x.uget i h=x.data[Ѥi]!:=by obtain ⟨ds⟩:=x;have h':Ѥi< ѧds:=h;rw[Ἕ ds Ѥi h'];rfl lemma qC3 (a:ѐ) (i:ὦ) (h:Ѥi< ѧa):a.uget i h=a[Ѥi]!:=by rw[Ἕ a Ѥi h];rfl lemma qD6 (a:ὤ) (i:ὦ) (v:ὧ):(wrF a i v).size=Ѩa:=by unfold wrF;split;. obtain ⟨ds⟩:=a;exact Array.size_uset _ . rfl lemma qEt (a:ὤ) (i:ὦ) (v:ὧ) (q:Ὣ) (hs:Ѩa<2^32) (hi:Ѥi< Ѩa):(wrF a i v).data[q]! =if q=Ѥi then v else a.data[q]!:=by have h:iὪ) (t:Ὣ):љ:= (ἄ t).filter (λp=>xw p&&&В != 0) section variable (xw:Ὣ->Ὢ) (t:Ὣ) include xw t lemma qBj:(C_keep xw t).length<=t:=by have h:=List.length_filter_le (λp=>xw p&&&В != 0) (ἄ t);simpa only[C_keep,ge_iff_le,List.length_range] using h lemma qDp (h:xw t&&&В=0):C_keep xw (t+1)=C_keep xw t:=by simp only[C_keep,List.range_succ,List.filter_append,h,bne_self_eq_false,false_eq_true,not_false_eq_true,List.filter_cons_of_neg,List.filter_nil,List.append_nil] lemma qD5 (h:¬xw t&&&В=0):C_keep xw (t+1)=C_keep xw t++[t]:=by simp only[C_keep,List.range_succ,List.filter_append,bne_iff_ne,ne_eq,h,not_false_eq_true,List.filter_cons_of_pos,List.filter_nil] end lemma qAu (a:ὤ) (v:ὧ):(a.push v).size=Ѩa+1:=by obtain ⟨ds⟩:=a;exact Array.size_push _ lemma qDy (n:ὦ) (d:Ὣ):∀(k:ὦ) (a:ὤ),Ѥk+d=Ѥn->(pushZ n k a).size=Ѩa+d:=by induction d with | zero=>intro k a he;rw[pushZ,ἔ (by rw[А];(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))))];rfl | succ d ih=> intro k a he;have ht:kὧ) (ww:Ὣ->Ὢ) (hww:∀p,p< Ѥm->W[Ѥw0+p]! =ww p) (L:љ):∀(t:ὦ) (a:ὧ),Ѥt+ѣL=Ѥn-> (∀k p:Ὣ,L[k]?=some p->p< Ѥm/\(ix[Ѥt+k]!:ὥ).toNat=p/\x.data[Ѥt+k]! =xf p)-> go1 x ix W w0 m n t hx hi hs h0 a=L.foldl (λ(acc:ὧ) p=>acc+xf p*dv (ww p)) a:=by induction L with | nil=> intro t a he _ rw[go1,ἔ (by rw[А];simp only[List.length_nil,add_zero] at he;(clear hx hi hs h0;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))] rfl | cons p L ih=> intro t a he H simp only[List.length_cons] at he have ht:t∀q,q< ѧW->wd.data[q]! =dv W[q]! section variable {x:ὤ} {ix W:ѐ} {w0 w1 w2 w3 m n:ὦ} (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hs:ѧW<2^32) (h0:Ѥw0+Ѥm<=ѧW) (h1:Ѥw1+Ѥm<=ѧW) (h2:Ѥw2+Ѥm<=ѧW) (h3:Ѥw3+Ѥm<=ѧW) lemma qH0 (hv:∀j,j< Ѥn->∃w,good w=true/\x.data[j]! =dv w) (k:Ὣ): ∀(t:ὦ) (a b c d:ὧ),Ѥt+k=Ѥn-> go4B x ix W w0 w1 w2 w3 m n t hx hi hs h0 h1 h2 h3 a b c d= ⟨go1 x ix W w0 m n t hx hi hs h0 a,go1 x ix W w1 m n t hx hi hs h1 b,go1 x ix W w2 m n t hx hi hs h2 c,go1 x ix W w3 m n t hx hi hs h3 d⟩:=by induction k with | zero=> intro t a b c d he have hn:¬t intro t a b c d he have ht:tih (t+1) a b c d (by rw[usz t n ht];(clear ht htn;exact omS137 he)) split<;>simp only[B,J] end def C_sp (I O:Ὣ) (Y:Ὡ) (X W b:ё) (q:Ὣ):Ὢ:= C_out I Y X W b (q/O) (q%O) lemma qCi (I O:Ὣ) (Y:Ὡ) (X W b:ё) {i j:Ὣ} (hj:jὪ} {p:Ὣ} {out:ё} (hN:N<2^32) (h:C_Inv N sp (λq=>qq(by exact omS148 hq:q=p\/q(u+4).toNat=p+4):=by have l:∀k,k<5->p+k<2^32->(u+ὴ k).toNat=p+k:=λk hk h=>by rw[qAf _ _ (by rw[uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)];exact omS149 hu h),uk k (by exact Nat.lt_of_lt_of_le ‹_› ה),hu] exact ⟨l 1 ה (by exact omS150 h),l 2 ה (by exact Nat.le_of_lt ‹_›),l 3 ה (by exact Nat.succ_le_of_lt ‹_›),l 4 (by exact Nat.le_refl _)⟩ lemma qEq {N:Ὣ} {sp:Ὣ->Ὢ} {p:Ὣ} {out:ё} (hN:N<2^32) (h:C_Inv N sp (λq=>qqbuf.data[k]! =dv X[0*n+k]!):∀k p:Ὣ,(ἄ n)[k]?=some p->(idA[k]!).toNat=p/\buf.data[k]! =dv X[0*n+p]!:=λk p hk=>by by_cases hk2:k Ѥn<=Ѩbuf-> Ѩbuf<2^32->(∀k,k< Ѥt->buf.data[k]! =dv X[a+k]!)->l=(ἄ Ѥt).foldl (λ(acc:ὧ) p=>acc+(dv X[a+p]!).abs) 0->(decD X ѩa n t buf l).ok=true-> Ѩ(decD X ѩa n t buf l).buf=Ѩbuf/\(∀k,k< Ѥn->(decD X ѩa n t buf l).buf.data[k]! =dv X[a+k]!)/\(decD X ѩa n t buf l).l=(ἄ Ѥn).foldl (λ(acc:ὧ) p=>acc+(dv X[a+p]!).abs) 0:=by have ea:Ѥ(ѩa)=a:=qAd a (by exact omS154 hX hn) induction d with | zero=> intro t buf l he hb hs hd hl hok have hn':¬t intro t buf l he hb hs hd hl hok have ht:tby rw[u] at hk;rw[qEt buf t _ k hs (by (exact Nat.lt_of_lt_of_le ‹_› ‹_›))];split . rename_i e;rw[e] . exact hd k (by (clear hX hn ea he hb hs ht h1 er;(clear u;omega)))) (by rw[u,List.range_succ,List.foldl_append,hl];rfl) hok rw[qD6] at R;exact R lemma qDs (xw:Ὣ->Ὢ) (n:Ὣ):(C_keep xw n).Nodup/\(∀t∈C_keep xw n,tt∉C_keep xw n->xw t&&&В=0:= ⟨Ὂ.filter _,λt ht=>Ἅ.mp (List.mem_filter.mp ht).1, λt ht hn=>by by_contra hc exact hn (List.mem_filter.mpr ⟨Ἅ.mpr ht,by simpa only[bne_iff_ne,ne_eq] using hc⟩)⟩ lemma qW8p (a:ὤ) (v0 v1 v2 v3 v4 v5 v6 v7:ὧ) (q:Ὣ) (h:q< Ѩa):((((((((a.push v0).push v1).push v2).push v3).push v4).push v5).push v6).push v7).data[q]! =a.data[q]!:=by obtain ⟨ds⟩:=a;have h':qrfl . exact wbIn W m r (i+1) _ i' (by (clear h2 hk hq;exact omS138 h1 e)) h2 k hk q (by simp only[qAu];(clear h2 hk;exact omS169 h1 hq e)) termination_by m-i decreasing_by all_goals (clear hk e;exact omS170 h2 h1) lemma wbOp (W:ѐ) (m nb c:Ὣ) (a:ὤ) (q:Ὣ) (hq:q< Ѩa):(wbO W m nb c a).data[q]! =a.data[q]!:=by rw[wbO];split . rw[wbOp _ _ _ _ _ _ (by rw[wbIs];exact omS171 hq),wbIp _ _ _ _ _ _ hq] . rfl termination_by nb-c decreasing_by all_goals omega lemma wbOn (W:ѐ) (m nb c:Ὣ) (a:ὤ) (c':Ὣ) (h1:c<=c') (h2:c'rfl . exact wbITn W m r o (i+1) _ i' (by (clear h2 hk hq;exact omS138 h1 e)) h2 k hk q (by simp only[qAu];(clear h2 hk;exact omS169 h1 hq e)) termination_by m-i decreasing_by all_goals (clear hk e;exact omS170 h2 h1) lemma wbOs (W:ѐ) (m nb c:Ὣ) (a:ὤ):(wbO W m nb c a).size=Ѩa+(nb-c)*(8*m):=by rw[wbO];split . rename_i h;rw[wbOs,wbIs];have:(nb-c)=(nb-(c+1))+1:=by exact omS177 h rw[this,ὰ,Ὑ,Nat.sub_zero];omega . rename_i h;rw[show nb-c=0 by exact omS178 h,ὒ,Ἵ] termination_by nb-c decreasing_by all_goals omega lemma wbZs (n:Ὣ):(wbZ n).size=5:=by simp only[wbZ,qAu];simp only[FloatArray.size,ἆ,List.size_toArray,List.length_nil,zero_add,Nat.reduceAdd] lemma wbP0 (W:ѐ) (m o j i k:Ὣ) (hj:j%8=0) (ho:j+8<=o) (hi:i< m) (hk:k<8):(wbO W m (o/8) 0 (wbZ ѧW)).data[j*m+5+8*i+k]! =dv W[(j+k)*m+i]!:=by have e1:8*(j/8)=j:=by (clear ho hi hk;exact omS179 hj) have e0:(wbZ ѧW).size=5:=wbZs _ have e3:j/8*(8*m)=j*m:=by rw[<-Nat.mul_assoc,ἥ (j/8) 8,e1] have:=wbOn W m (o/8) 0 (wbZ ѧW) (j/8) (Nat.zero_le _) (by (clear hi hk e1 e0 e3;exact omS180 ho)) i hi k hk (j*m+5+8*i+k) (by rw[e0,Nat.sub_zero,e3];(clear hj ho hi hk e1 e0 e3;exact omS181)) rw[e1] at this;exact this lemma wbP (W:ѐ) (m o j i k:Ὣ) (hj:j%8=0) (ho:j+8<=o) (hi:i< m) (hk:k<8):(wbOf m o W).data[j*m+5+8*i+k]! =dv W[(j+k)*m+i]!:=by unfold wbOf;dsimp only;split . exact wbP0 W m o j i k hj ho hi hk . rw[wbITp _ _ _ _ _ _ _ (by rw[wbOs];have e0:(wbZ ѧW).size=5:=wbZs _ rw[e0,Nat.sub_zero] have e1:8*(j/8)=j:=by (clear ho hi hk;exact omS179 hj) have:j/8+1<=o/8:=by exact omS182 ho have:(j/8+1)*(8*m)<=(o/8)*(8*m):=Ἒ _ this have e3:j*m+8*m=(j/8+1)*(8*m):=by rw[ὰ,Ὑ,<-Nat.mul_assoc,ἥ (j/8) 8,e1] have:j*m+8*i+kwb.data[Ѥp+8*i+0]! =dv W[Ѥw0+i]!/\wb.data[Ѥp+8*i+1]! =dv W[Ѥw1+i]!/\wb.data[Ѥp+8*i+2]! =dv W[Ѥw2+i]!/\wb.data[Ѥp+8*i+3]! =dv W[Ѥw3+i]!/\ wb.data[Ѥp+8*i+4]! =dv W[Ѥv0+i]!/\wb.data[Ѥp+8*i+5]! =dv W[Ѥv1+i]!/\wb.data[Ѥp+8*i+6]! =dv W[Ѥv2+i]!/\wb.data[Ѥp+8*i+7]! =dv W[Ѥv3+i]!) (k:Ὣ):∀(t:ὦ) (a b c d e f g z:ὧ),Ѥt+k=Ѥn-> go8W x wb ix p m n t hx hi hb hs a b c d e f g z=(⟨go1 x ix W w0 m n t hx hi hs' h0 a,go1 x ix W w1 m n t hx hi hs' h1 b,go1 x ix W w2 m n t hx hi hs' h2 c,go1 x ix W w3 m n t hx hi hs' h3 d⟩,⟨go1 x ix W v0 m n t hx hi hs' g0 e,go1 x ix W v1 m n t hx hi hs' g1 f,go1 x ix W v2 m n t hx hi hs' g2 g,go1 x ix W v3 m n t hx hi hs' g3 z⟩):=by induction k with | zero=> intro t a b c d e f g z he have hn:¬t intro t a b c d e f g z he have ht:tih (t+1) a b c d e f g z (by rw[usz t n ht];(clear ht;exact omS137 he)) split . rename_i hm simp only[qC5,qC3] at hm⊢ generalize (ix[Ѥt]!).toUSize=i at hm⊢ have him:=А.mp hm obtain ⟨E0,E1,E2,E3,E4,E5,E6,E7⟩:=HB _ him have e8:(ὴ 8*i).toNat=8*Ѥi:=by rw[qWm _ _ (by rw[uk 8 ה];(clear he ht hm;exact omS16 hb hs him)),uk 8 ה] have T:∀kk,kk<8->(p+ὴ 8*i+ὴ kk).toNat=Ѥp+8*Ѥi+kk:=λkk hk=>by rw[qAf _ _ (by rw[qAf _ _ (by rw[e8];(clear he ht hm e8;exact omS17 hb hs him)),e8,uk kk (by exact Nat.lt_of_lt_of_le ‹_› ה)];(clear he ht hm e8;omega)),qAf _ _ (by rw[e8];(clear he ht hm e8;exact omS17 hb hs him)),e8,uk kk (by exact Nat.lt_of_lt_of_le ‹_› ה)] have V:∀w:ὦ,Ѥw+Ѥm<=ѧW->(w+i).toNat=Ѥw+Ѥi:=λw hw=>qAf _ _ (by (clear he ht hm e8;exact omS184 hs' him hw)) rw[T 0 ה,T 1 ה,T 2 ה,T 3 ה,T 4 ה,T 5 ה,T 6 ה,T 7 (by exact Nat.le_refl _),V w0 h0,V w1 h1,V w2 h2,V w3 h3,V v0 g0,V v1 g1,V v2 g2,V v3 g3,E0,E1,E2,E3,E4,E5,E6,E7] exact J _ _ _ _ _ _ _ _ . exact J _ _ _ _ _ _ _ _ lemma qR4 {x:ὤ} {ix W:ѐ} {wd:ὤ} {w0 w1 w2 w3 m n:ὦ} (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hs:ѧW<2^32) (h0:Ѥw0+Ѥm<=ѧW) (h1:Ѥw1+Ѥm<=ѧW) (h2:Ѥw2+Ѥm<=ѧW) (h3:Ѥw3+Ѥm<=ѧW) (HX:∀j,j< Ѥn->∃w,good w=true/\x.data[j]! =dv w) (Hd:C_Dw wd W): go4B x ix W w0 w1 w2 w3 m n 0 hx hi hs h0 h1 h2 h3 0 0 0 0=⟨go1 x ix W w0 m n 0 hx hi hs h0 0,go1 x ix W w1 m n 0 hx hi hs h1 0,go1 x ix W w2 m n 0 hx hi hs h2 0,go1 x ix W w3 m n 0 hx hi hs h3 0⟩:=by exact qH0 hx hi hs h0 h1 h2 h3 HX Ѥn 0 0 0 0 0 (Ἇ _) set_option maxRecDepth 8192 in lemma cT_eq (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (i:Ὣ) (ix:ѐ) (x wd:ὤ) (nf a:ὧ) (hx:ὥ) (lo:Ὠ) (m n:ὦ) (rr:G8) (j0:Ὣ) (HX:∀j,j< Ѥn->∃w,good w=true/\x.data[j]! =dv w) (Hd:C_Dw wd W) (hxn:Ѥn<=Ѩx) (hin:Ѥn<=ѧix) (hsW:ѧW<2^32) (HO:outW*Ѥm<=ѧW) (HO2:outW<2^32) (HL:∀(k:Ὣ) (w:ὦ) (hw:Ѥw=(j0+k)*Ѥm) (h0:Ѥw+Ѥm<=ѧW),j0+kC_g8 rr k=go1 x ix W w m n 0 hxn hin hsW h0 0) (j:Ὣ) (hj:j0<=j) (base:ὦ) (out:ѐ): cols1T inW outW relu X W b i nf a hx lo m rr j0 j base out=cols1 inW outW relu X W b i ix x wd nf a hx lo m n j base out:=by induction hd:outW-j using Nat.strong_induction_on generalizing j out with | _ d ih=> have M:∀(u:ὦ) (r:Ὣ),Ѥu=r->r+1<=outW->Ѥ(u*m)=r*Ѥm:=λu r hu hr=>by rw[qWm _ _ (by rw[hu];exact ἷ (ὂ (Ἒ _ (by (exact Nat.le_of_lt ‹_›))) HO) hsW),hu] have B:∀(u:ὦ) (r:Ὣ),Ѥu=r->r+1<=outW->Ѥ(u*m)+Ѥm<=ѧW:=λu r hu hr=>by rw[M u r hu hr];have:=Ἒ Ѥm hr;rw[ὰ,Ὑ] at this;exact this.trans HO have hW32:ѧW<=4294967295:=by exact omS185 hsW rw[cols1T,cols1] by_cases h4:j+4<=outW . rw[Ἄ h4,Ἄ h4] dsimp only have ej:Ѥ(ѩj)=j:=uk j (by exact omS186 HO2 h4) obtain ⟨e1,e2,e3,-⟩:=qFk ej (by exact omS151 HO2 h4) rw[Ἄ ⟨hxn,hin,hW32,B _ _ ej (by exact omS187 h4),B _ _ e1 (by exact omS188 h4),B _ _ e2 (by exact omS189 h4),B _ _ e3 (by exact omS190 h4)⟩] rw[qR4 _ _ _ _ _ _ _ HX Hd] dsimp only rw[HL (j-j0) (ѩj*m) (by rw[M _ _ ej (by exact omS187 h4)];congr 1;exact omS191 hj) (B _ _ ej (by exact omS187 h4)) (by exact omS192 hj h4), HL (j+1-j0) ((ѩj+1)*m) (by rw[M _ _ e1 (by exact omS188 h4)];congr 1;exact omS193 hj) (B _ _ e1 (by exact omS188 h4)) (by exact omS194 hj h4), HL (j+2-j0) ((ѩj+2)*m) (by rw[M _ _ e2 (by exact omS189 h4)];congr 1;exact omS195 hj) (B _ _ e2 (by exact omS189 h4)) (by exact omS196 hj h4), HL (j+3-j0) ((ѩj+3)*m) (by rw[M _ _ e3 (by exact omS190 h4)];congr 1;exact omS197 hj) (B _ _ e3 (by exact omS190 h4)) (by exact omS198 hj h4)] exact ih _ (by exact omS199 hd h4) (j+4) (by exact omS200 hj) _ rfl . rw[ἔ h4,ἔ h4] by_cases h1:jk<8->wb.data[(8*(outW/8))*Ѥm+5+8*i+k]! =dv W[(min (8*(outW/8)+k) (outW-1))*Ѥm+i]!): ∀(k:Ὣ) (w:ὦ) (hw:Ѥw=(j+k)*Ѥm) (h0:Ѥw+Ѥm<=ѧW),j+kC_g8 (g8of (go8W x wb ix (ѩj*m+ὴ 5) m n 0 hxn hin hb hs 0 0 0 0 0 0 0 0)) k=go1 x ix W w m n 0 hxn hin hsW h0 0:=by intro k w hw h0 hk have hk8:k<8:=by exact omS206 hj hk have hjm:Ѥ(ѩj*m)=j*Ѥm:=by rw[qWm _ _ (by rw[qAd j (by exact omS207 hj HO2)];exact ἷ (ὂ (Ἒ _ (by exact omS208 hj)) HO) hsW),qAd j (by exact omS207 hj HO2)] have twk:∀kk,kk<8-> Ѥ((ѩ(min (j+kk) (outW-1)))*m)=(min (j+kk) (outW-1))*Ѥm:=λkk hkk=>by rw[qWm _ _ (by rw[qAd _ א];exact ἷ (ὂ (Ἒ _ א) HO) hsW),qAd _ א] have bwk:∀kk,kk<8-> Ѥ((ѩ(min (j+kk) (outW-1)))*m)+Ѥm<=ѧW:=λkk hkk=>by rw[twk kk hkk];have:min (j+kk) (outW-1)+1<=outW:=by exact omS209 hk have:=Ἒ Ѥm this;rw[ὰ,Ὑ] at this;exact this.trans HO have HB8:∀i,i< Ѥm->wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+0]! =dv W[Ѥ((ѩ(min (j+0) (outW-1)))*m)+i]!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+1]! =dv W[Ѥ((ѩ(min (j+1) (outW-1)))*m)+i]!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+2]! =dv W[Ѥ((ѩ(min (j+2) (outW-1)))*m)+i]!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+3]! =dv W[Ѥ((ѩ(min (j+3) (outW-1)))*m)+i]!/\ wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+4]! =dv W[Ѥ((ѩ(min (j+4) (outW-1)))*m)+i]!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+5]! =dv W[Ѥ((ѩ(min (j+5) (outW-1)))*m)+i]!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+6]! =dv W[Ѥ((ѩ(min (j+6) (outW-1)))*m)+i]!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i+7]! =dv W[Ѥ((ѩ(min (j+7) (outW-1)))*m)+i]!:=λi hi=>by rw[he,hjm,twk 0 ה,twk 1 ה,twk 2 ה,twk 3 ה,twk 4 ה,twk 5 ה,twk 6 ה,twk 7 ה] have Q:=λkk (hkk:kk<8)=>HBt i kk hi hkk subst hj exact ⟨Q 0 ה,Q 1 ה,Q 2 ה,Q 3 ה,Q 4 ה,Q 5 ה,Q 6 ה,Q 7 ה⟩ rw[g8WE x wb ix W (ѩj*m+ὴ 5) _ _ _ _ _ _ _ _ m n hxn hin hb hs hsW (bwk 0 ה) (bwk 1 ה) (bwk 2 ה) (bwk 3 ה) (bwk 4 ה) (bwk 5 ה) (bwk 6 ה) (bwk 7 ה) HB8 Ѥn 0 0 0 0 0 0 0 0 0 (by simp only[USize.toNat_zero,zero_add])] have ew:w=(ѩ(min (j+k) (outW-1)))*m:=USize.toNat_inj.mp (by rw[hw,twk k hk8];congr 1;exact omS210 hk) subst ew interval_cases k<;>rfl lemma zFq (p i m:ὦ) (wb:ὤ) (k:Ὣ) (hk:k<8) (hb:Ѥp+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (him:Ѥi< Ѥm):(p+ὴ 8*i+ὴ k).toNat=Ѥp+8*Ѥi+k:=by have e8:(ὴ 8*i).toNat=8*Ѥi:=by rw[qWm _ _ (by rw[uk 8 ה];(clear hk;exact omS16 hb hs him)),uk 8 ה] rw[qAf _ _ (by rw[qAf _ _ (by rw[e8];(clear hk e8;exact omS17 hb hs him)),e8,uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)];(clear e8;exact omS18 hk hb hs him)),qAf _ _ (by rw[e8];(clear hk e8;exact omS17 hb hs him)),e8,uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)] lemma g8WF (x wb:ὤ) (ix:ѐ) (p m n:ὦ) (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hb:Ѥp+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (HX:∀j,j< Ѥn->∃w,x.data[j]! =dv w) (HB:∀i,i< Ѥm->∀k,k<8->∃w,wb.data[Ѥp+8*i+k]! =dv w) (k:Ὣ): ∀(t:ὦ) (a b c d e f g z:ὧ),Ѥn-Ѥt=k->go8WF x wb ix p m n t hx hi hb hs a b c d e f g z=go8W x wb ix p m n t hx hi hb hs a b c d e f g z:=by induction k with | zero=> intro t a b c d e f g z he have hn:¬t intro t a b c d e f g z he have ht:tih (t+1) a b c d e f g z (by rw[usz t n ht];omega) unfold go8WF go8W simp only[Ἄ ht] by_cases hm:(ix.uget t (Nat.lt_of_lt_of_le htn hi)).toUSize< m . simp only[Ἄ hm] simp only[qC5,qC3] at hm⊢ generalize (ix[Ѥt]!).toUSize=i at hm⊢ have him:=А.mp hm obtain ⟨u,hu⟩:=HX _ htn obtain ⟨w0,h0⟩:=HB _ him 0 ה obtain ⟨w1,h1⟩:=HB _ him 1 ה obtain ⟨w2,h2⟩:=HB _ him 2 ה obtain ⟨w3,h3⟩:=HB _ him 3 ה obtain ⟨w4,h4⟩:=HB _ him 4 ה obtain ⟨w5,h5⟩:=HB _ him 5 ה obtain ⟨w6,h6⟩:=HB _ him 6 ה obtain ⟨w7,h7⟩:=HB _ him 7 ה rw[zFq p i m wb 0 ה hb hs him,zFq p i m wb 1 ה hb hs him,zFq p i m wb 2 ה hb hs him,zFq p i m wb 3 ה hb hs him, zFq p i m wb 4 ה hb hs him,zFq p i m wb 5 ה hb hs him,zFq p i m wb 6 ה hb hs him,zFq p i m wb 7 ה hb hs him, hu,h0,h1,h2,h3,h4,h5,h6,h7,zFV,zFV,zFV,zFV,zFV,zFV,zFV,zFV] exact J _ _ _ _ _ _ _ _ . simp only[ἔ hm] exact J _ _ _ _ _ _ _ _ lemma g8WDE (x wb:ὤ) (ix:ѐ) (p m n:ὦ) (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hb:Ѥp+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (HX:∀j,j< Ѥn->∃w,x.data[j]! =dv w) (HB:∀i,i< Ѥm->∀k,k<8->∃w,wb.data[Ѥp+8*i+k]! =dv w) (t:ὦ) (a b c d e f g z:ὧ): go8WD x wb ix p m n t hx hi hb hs a b c d e f g z=go8W x wb ix p m n t hx hi hb hs a b c d e f g z:=by unfold go8WD;generalize armT=A;cases A . simp only[Bool.false_eq_true,ite_false] . simp only[ite_true];exact g8WF x wb ix p m n hx hi hb hs HX HB _ t a b c d e f g z rfl lemma zF8 {wb:ὤ} {P:Ὣ} {A0 A1 A2 A3 A4 A5 A6 A7:ὥ} (h:wb.data[P+0]! =dv A0/\wb.data[P+1]! =dv A1/\wb.data[P+2]! =dv A2/\wb.data[P+3]! =dv A3/\ wb.data[P+4]! =dv A4/\wb.data[P+5]! =dv A5/\wb.data[P+6]! =dv A6/\wb.data[P+7]! =dv A7): ∀k,k<8->∃w,wb.data[P+k]! =dv w:=by intro k hk;interval_cases k exacts[⟨_,h.1⟩,⟨_,h.2.1⟩,⟨_,h.2.2.1⟩,⟨_,h.2.2.2.1⟩,⟨_,h.2.2.2.2.1⟩,⟨_,h.2.2.2.2.2.1⟩,⟨_,h.2.2.2.2.2.2.1⟩,⟨_,h.2.2.2.2.2.2.2⟩] lemma c1WE (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (i:Ὣ) (ix:ѐ) (x wd wb:ὤ) (nf a:ὧ) (hx:ὥ) (lo:Ὠ) (m n:ὦ) (HX:∀j,j< Ѥn->∃w,good w=true/\x.data[j]! =dv w) (Hd:C_Dw wd W) (HO:outW*Ѥm<=ѧW) (HO2:outW<2^32) (HB:∀j i k,j%8=0->j+8<=outW->i< Ѥm->k<8->wb.data[j*Ѥm+5+8*i+k]! =dv W[(j+k)*Ѥm+i]!) (HBt:outW%8≠0-> ∀i k,i< Ѥm->k<8->wb.data[(8*(outW/8))*Ѥm+5+8*i+k]! =dv W[(min (8*(outW/8)+k) (outW-1))*Ѥm+i]!) (j:Ὣ) (hj:j%8=0) (base:ὦ) (out:ѐ): cols1W inW outW relu X W b i ix x wd wb nf a hx lo m n j base out=cols1 inW outW relu X W b i ix x wd nf a hx lo m n j base out:=by induction hd:outW-j using Nat.strong_induction_on generalizing j hj out with | _ d ih=> rw[cols1W];split . rename_i h8;dsimp only;split . rename_i hg have sW:ѧW<2^32:=qA9 hg.2.2.1 have ej:Ѥ(ѩj)=j:=uk j (by (clear HO hd hg sW;exact omS211 HO2 h8)) have ej4:Ѥ((j+4).toUSize)=j+4:=uk (j+4) (by (clear HO hd hg sW ej;exact omS212 HO2 h8)) obtain ⟨e1,e2,e3,-⟩:=qFk ej (by (clear HO hd hg sW ej ej4;exact omS213 HO2 h8)) obtain ⟨f1,f2,f3,-⟩:=qFk ej4 (by (clear HO hd hg sW ej ej4 e1 e2 e3;exact omS214 HO2 h8)) have M:∀(u:ὦ) (r:Ὣ),Ѥu=r->r+1<=outW->Ѥ(u*m)=r*Ѥm:=λu r hu hr=>by rw[qWm _ _ (by rw[hu];exact ἷ (ὂ (Ἒ _ (by (exact Nat.le_of_lt ‹_›))) HO) sW),hu] have HB8:∀i',i'< Ѥm->wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+0]! =dv W[Ѥ(ѩj*m)+i']!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+1]! =dv W[((ѩj+1)*m).toNat+i']!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+2]! =dv W[((ѩj+2)*m).toNat+i']!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+3]! =dv W[((ѩj+3)*m).toNat+i']!/\ wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+4]! =dv W[((j+4).toUSize*m).toNat+i']!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+5]! =dv W[(((j+4).toUSize+1)*m).toNat+i']!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+6]! =dv W[(((j+4).toUSize+2)*m).toNat+i']!/\wb.data[Ѥ(ѩj*m+ὴ 5)+8*i'+7]! =dv W[(((j+4).toUSize+3)*m).toNat+i']!:=λi' hi'=>by rw[(pk (ѩj*m) m wb hg.2.2.2.2.2.2.2.2.2.2.2.2 hg.2.2.2.2.2.2.2.2.2.2.2.1).2,M _ _ ej (by (clear HO HO2 hd hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS215 h8)),M _ _ e1 (by (clear HO HO2 hd hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS216 h8)),M _ _ e2 (by (clear HO HO2 hd hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS217 h8)),M _ _ e3 (by (clear HO HO2 hd hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS218 h8)),M _ _ ej4 (by (clear HO HO2 hd hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS219 h8)),M _ _ f1 (by (clear HO HO2 hd hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS220 h8)),M _ _ f2 (by (exact Nat.le_of_lt ‹_›)),M _ _ f3 (by (exact Nat.succ_le_of_lt ‹_›))] have Q:=λk hk=>HB j i' k hj h8 hi' hk refine ⟨by simpa only[add_zero] using Q 0 ה,Q 1 ה,Q 2 ה,Q 3 ה,Q 4 ה,?_,?_,?_⟩ . have:=Q 5 ה;rwa[show j+5=j+4+1 by (clear HO HO2 hj hd h8 hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS221)] at this . have:=Q 6 ה;rwa[show j+6=j+4+2 by (clear HO HO2 hj hd h8 hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS222)] at this . have:=Q 7 (by exact Nat.le_refl _);rwa[show j+7=j+4+3 by (clear HO HO2 hj hd h8 hg sW ej ej4 e1 e2 e3 f1 f2 f3 hi';exact omS223)] at this rw[g8WDE x wb ix (ѩj*m+ὴ 5) m n hg.1 hg.2.1 _ _ (λj hj=>let ⟨w,_,e⟩:=HX j hj;⟨w,e⟩) (λi' hi'=>zF8 (HB8 i' hi'))] rw[g8WE x wb ix W (ѩj*m+ὴ 5) (ѩj*m) ((ѩj+1)*m) ((ѩj+2)*m) ((ѩj+3)*m) ((j+4).toUSize*m) (((j+4).toUSize+1)*m) (((j+4).toUSize+2)*m) (((j+4).toUSize+3)*m) m n hg.1 hg.2.1 (pk (ѩj*m) m wb hg.2.2.2.2.2.2.2.2.2.2.2.2 hg.2.2.2.2.2.2.2.2.2.2.2.1).1 (qA9 hg.2.2.2.2.2.2.2.2.2.2.2.1) sW hg.2.2.2.1 hg.2.2.2.2.1 hg.2.2.2.2.2.1 hg.2.2.2.2.2.2.1 hg.2.2.2.2.2.2.2.1 hg.2.2.2.2.2.2.2.2.1 hg.2.2.2.2.2.2.2.2.2.1 hg.2.2.2.2.2.2.2.2.2.2.1 HB8 Ѥn 0 0 0 0 0 0 0 0 0 (Ἇ _)] rw[cols1,Ἄ (by (clear HO HO2 hd hg sW ej ej4 e1 e2 e3 f1 f2 f3;exact omS224 h8):j+4<=outW)];dsimp only;rw[Ἄ ⟨hg.1,hg.2.1,hg.2.2.1,hg.2.2.2.1,hg.2.2.2.2.1,hg.2.2.2.2.2.1,hg.2.2.2.2.2.2.1⟩] rw[qR4 _ _ _ _ _ _ _ HX Hd];dsimp only rw[cols1,Ἄ (by (exact Nat.succ_le_of_lt ‹_›):j+4+4<=outW)];dsimp only;rw[Ἄ ⟨hg.1,hg.2.1,hg.2.2.1,hg.2.2.2.2.2.2.2.1,hg.2.2.2.2.2.2.2.2.1,hg.2.2.2.2.2.2.2.2.2.1,hg.2.2.2.2.2.2.2.2.2.2.1⟩] rw[qR4 _ _ _ _ _ _ _ HX Hd];dsimp only exact ih (outW-(j+8)) (by (clear HO HO2 hg sW ej ej4 e1 e2 e3 f1 f2 f3;exact omS226 hd h8)) (j+8) (by (clear HO HO2 hd h8 hg sW ej ej4 e1 e2 e3 f1 f2 f3;exact omS227 hj)) _ rfl . rfl . rename_i h8 by_cases ht:j(ix[k]!).toNat=k) (k:Ὣ):∀(t:ὦ) (a b c d e f g z:ὧ),Ѥt+k=Ѥn-> go8V x wb p m n t hx hn hb hs a b c d e f g z=g8of (go8W x wb ix p m n t hx hi hb hs a b c d e f g z):=by induction k with | zero=> intro t a b c d e f g z he have hn':¬t intro t a b c d e f g z he have ht:tih (t+1) a b c d e f g z (by rw[usz t n ht];(clear ht;exact omS137 he)) have E:(ix[Ѥt]!).toUSize=t:=USize.toNat_inj.mp (by rw[ὃ];exact HI _ (А.mp ht)) rw[go8V,go8W,Ἄ ht,Ἄ ht];dsimp only;split . rename_i hm simp only[qC3] at hm⊢ rw[J];simp only[E] . rename_i hm simp only[qC3,E] at hm exact absurd (by rw[А];have:=А.mp ht;(exact Nat.lt_of_lt_of_le ‹_› ‹_›)) hm lemma g8VWF (x wb:ὤ) (ix:ѐ) (p m n:ὦ) (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hn:Ѥn<=Ѥm) (hb:Ѥp+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (HI:∀k,k< Ѥn->(ix[k]!).toNat=k) (k:Ὣ):∀(t:ὦ) (a b c d e f g z:ὧ),Ѥt+k=Ѥn-> go8F x wb p m n t hx hn hb hs a b c d e f g z=g8of (go8WF x wb ix p m n t hx hi hb hs a b c d e f g z):=by induction k with | zero=> intro t a b c d e f g z he have hn':¬t intro t a b c d e f g z he have ht:tih (t+1) a b c d e f g z (by rw[usz t n ht];(clear ht;exact omS137 he)) have E:(ix[Ѥt]!).toUSize=t:=USize.toNat_inj.mp (by rw[ὃ];exact HI _ (А.mp ht)) rw[go8F,go8WF,Ἄ ht,Ἄ ht];dsimp only;split . rename_i hm simp only[qC3] at hm⊢ rw[J];simp only[E] . rename_i hm simp only[qC3,E] at hm exact absurd (by rw[А];have:=А.mp ht;(exact Nat.lt_of_lt_of_le ‹_› ‹_›)) hm lemma g8VWD (x wb:ὤ) (ix:ѐ) (p m n:ὦ) (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hn:Ѥn<=Ѥm) (hb:Ѥp+8*Ѥm<=Ѩwb) (hs:Ѩwb<2^32) (HI:∀k,k< Ѥn->(ix[k]!).toNat=k) (k:Ὣ):∀(t:ὦ) (a b c d e f g z:ὧ),Ѥt+k=Ѥn-> go8D x wb p m n t hx hn hb hs a b c d e f g z=g8of (go8WD x wb ix p m n t hx hi hb hs a b c d e f g z):=by intro t a b c d e f g z he;unfold go8D go8WD;generalize armT=A;cases A . simp only[Bool.false_eq_true,ite_false];exact g8VW x wb ix p m n hx hi hn hb hs HI k t a b c d e f g z he . simp only[ite_true];exact g8VWF x wb ix p m n hx hi hn hb hs HI k t a b c d e f g z he lemma c1VW (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (i:Ὣ) (ix:ѐ) (x wd wb:ὤ) (nf a:ὧ) (hx:ὥ) (lo:Ὠ) (m n:ὦ) (HI:∀k,k< Ѥn->(ix[k]!).toNat=k) (hn:Ѥn<=Ѥm) (j:Ὣ) (base:ὦ) (out:ѐ): cols1V inW outW relu X W b i ix x wd wb nf a hx lo m n j base out=cols1W inW outW relu X W b i ix x wd wb nf a hx lo m n j base out:=by rw[cols1V];split . rename_i h8;rw[cols1W,Ἄ h8];dsimp only;split . rename_i hg obtain ⟨a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14⟩:=hg rw[Ἄ ⟨a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a14⟩] rw[g8VWD x wb ix _ m n a1 a2 a13 _ _ HI Ѥn 0 0 0 0 0 0 0 0 0 (Ἇ _)];dsimp only[g8of] exact c1VW inW outW relu X W b i ix x wd wb nf a hx lo m n HI hn (j+8) base _ . rename_i hg rw[ἔ (λh=>hg (by obtain ⟨a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a14⟩:=h;exact ⟨a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,hn,a14⟩))] . rename_i h8;rw[cols1W,ἔ h8] by_cases ht:jsimp only[false_eq_true, ↓reduceIte,Nat.reducePow,OfNat.zero_ne_ofNat,or_false,OfNat.ofNat_ne_zero,or_true]) s.toBits.toNat_lt e1 e2 (by clear ht h hz e1 l1 u1 e2 l2 u2;exact omS232 h1) (by clear ht h hz e1 l1 u1 e2 l2 u2;exact omS233 h2 h3) l1 u1 l2 u2;exact ⟨S,ex,fr,Q+2097152,h1,h2,h3,hz,a,b,c⟩ . exact absurd rfl h lemma qI5 (v W z u:ℝ) (hu:0linarith only[h2.1,h2.2,h2] set_option maxRecDepth 8192 in lemma qJi (ex fr E F:Ὣ) (h1:897<=ex) (h2:ex<1151) (hfr:fr<2^23) (hF:F<2^52) (hl:(ex*2^23+fr)*2^29+2097152(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)>>(52:Ὠ))&&&(0x7FF:Ὠ)).toNat=Ѧx/2^52%2^11:=by rw[Ὅ,ἰ];have:=Ἂ (Ѧx>>>52) 11;norm_num[Ἱ] at this⊢;exact this lemma qGj (b:Ὡ) (x y:ℝ) (hx:0<=x) (hy:0<=y): |(if b=true then (-1:ℝ) else 1)*x*y| =x*y:=by have h:=ἅ (Ἆ hx hy) cases b . rw[show (if false=true then (-1:ℝ) else 1)*x*y=x*y by simp only[false_eq_true, ↓reduceIte,one_mul]];exact h . rw[show (if true=true then (-1:ℝ) else 1)*x*y=-(x*y) by simp only[↓reduceIte,neg_mul,one_mul],abs_neg];exact h lemma qJb (a:Ὠ) (S:Ὡ) (M:Ὣ) (hM:M<2^63) (h:Ѧa=(if S then 2^63 else 0)+M):(a<<<(1:Ὠ)).toNat=2*M:=by rw[UInt64.toNat_shiftLeft,h];norm_num[ὁ];cases S<;>simp only[false_eq_true, ↓reduceIte,zero_add]<;>omega lemma kGw (e s:ὧ) (S:Ὡ) (M:Ὣ) (hM2:M<2047*2^52) (hs:s.toBits.toNat=(if S then 2^63 else 0)+M) (h:thOf e<=s.toBits<<<(1:Ὠ)):e.isFinite=true/\|R e| <=1/2^34* |R s|:=by have hl:=qJb s.toBits S M (by exact Nat.lt_of_lt_of_le ‹_› ה) hs;unfold thOf at h;dsimp only at h;have hx:=qJc e.toBits;generalize (e.toBits>>>(52:Ὠ))&&&(0x7FF:Ὠ)=E at h hx;rw[Ὤ,hl] at h;split at h . rename_i hc;rw[ἴ,ὲ] at hc;rw[UInt64.toNat_shiftLeft,ἤ] at h;have hA:=e.toBits.toNat_lt;norm_num[ὁ] at hc h hA;obtain ⟨sg,hsg⟩:∃sg:Ὡ,e.toBits.toNat=(if sg then 2^63 else 0)+ѦE*2^52+e.toBits.toNat%2^52:=by refine ⟨decide (2^63<=e.toBits.toNat),?_⟩;by_cases h6:2^63<=e.toBits.toNat<;>simp only[h6,decide_true,decide_false,ite_true,ite_false,false_eq_true]<;>(clear hM2 hs hl hc h;omega) have hFe:e.toBits.toNat%2^52<2^52:=ὀ _ ב;generalize e.toBits.toNat%2^52=Fe at hsg hFe;have hE1:1<=ѦE/\ѦE<=1900:=(by clear hM2 hs hl h hA hsg hFe;exact omS242 hx hc);have hEs:M=(M/2^52)*2^52+M%2^52:=(by clear hM2 hs hl hx hc h hA hsg hFe hE1;exact omS114);have hFs:M%2^52<2^52:=ὀ _ ב;generalize M/2^52=Es at hEs;generalize M%2^52=Fs at hEs hFs;subst hEs;have hle:ѦE+35<=Es:=(by clear hc hA hsg hFe hl;exact omS243 hE1 hFs h);obtain ⟨fe,re⟩:=B_R e sg ѦE Fe hE1.1 (by clear hc hA hsg hFe hFs hM2 hs hl h hle;exact omS244 hE1) hFe hsg;obtain ⟨-,rs⟩:=B_R s S Es Fs (by clear hA hsg hFe hE1 hM2 hl hle;exact omS245 hc hFs h) (by clear hx hc hA hsg hFe hE1 hl h hle;exact omS246 hM2) hFs (by rw[hs,ὢ]);refine ⟨fe,?_⟩;have hc0:(0:ℝ)<2^((ѦE:Int)-1075):=ἵ ב _;have h1:(2:ℝ)^((ѦE:Int)+35-1075)<=2^((Es:Int)-1075):=ἒ ב (by clear hc hA hsg hFe hE1 hFs hM2 hs hl h;exact omS247 hle);have h2:(2:ℝ)^((ѦE:Int)+35-1075)=2^35*2^((ѦE:Int)-1075):=by rw[show (ѦE:Int)+35-1075=35+((ѦE:Int)-1075) by ring,Ἓ ἓ];norm_num have hae: |R e| =((2^52+Fe:Ὣ):ℝ)*2^((ѦE:Int)-1075):=by rw[re];exact qGj _ _ _ (Ἔ _) hc0.le have has: |R s| =((2^52+Fs:Ὣ):ℝ)*2^((Es:Int)-1075):=by rw[rs];exact qGj _ _ _ (Ἔ _) (ἵ ב _).le rw[hae,has];have n1:((2^52+Fe:Ὣ):ℝ)<=2^53:=by have:2^52+Fe<=2^53:=(by clear hx hc hA hsg hE1 hFs hM2 hs hl h hle;exact omS236 hFe);exact_mod_cast this have n2:(2:ℝ)^52<=((2^52+Fs:Ὣ):ℝ):=by have:2^52<=2^52+Fs:=(by clear hx hc hA hsg hFe hE1 hM2 hl h hle;exact omS248);exact_mod_cast this generalize (2:ℝ)^((ѦE:Int)-1075)=c at*;generalize (2:ℝ)^((Es:Int)-1075)=d at*;rw[h2] at h1;have n3:=ἀ n1 hc0.le;have n0:0<=d:=(by linarith only[hc0,h1]);have n4:=ἁ (ἀ n2 n0) (by norm_num:(0:ℝ)<=1/2^34);have n5:(2:ℝ)^53*c<=1/2^34*(2^52*d):=(by linarith only[h1]);exact n3.trans (n5.trans n4) . exfalso;norm_num at h;exact omS249 hM2 h lemma qHs (s e:ὧ) (V:ℝ) (fs:s.isFinite=true) (fe:e.isFinite=true) (hrel: |R e| <=1/2^34* |R s|) (hB: |R s| <=2^(130:ℤ)) (hlo:R (s-e)a<=1/k*b->k*a<=b:=λhk h=>(le_div_iff₀' hk).mp (h.trans_eq (one_div_mul_eq_div _ _)) have hA:(2:ℝ)^(130:ℤ)<=A_B:=by unfold A_B;exact ἒ (by norm_num1) (by norm_num1) have h1: |R e| <=A_B:=hrel.trans ((mul_le_of_le_one_left (Ἀ _) (by norm_num1)).trans (hB.trans hA)) obtain ⟨-,p⟩:=qBf s e fs fe (hB.trans hA) h1;obtain ⟨-,m⟩:=qDf s e fs fe (hB.trans hA) h1 have p':=sck (by norm_num1) p;have m':=sck (by norm_num1) m;have p2:=le_abs_self (R (s+e)-(R s+R e));have m2:=neg_abs_le (R (s-e)-(R s-R e)) have q1:=Ἐ (R s) (R e);have q2:=Ὕ (R s) (R e);have a1: |R s| <= |V| + |R s-V|:=sub_le_iff_le_add'.mp (Ὥ (R s) V) have a2:=le_abs_self (R e);have a3:=neg_abs_le (R e);have hz:(0:ℝ)<=A_z:=by show (0:ℝ)<=(2:ℝ)^(-1021:ℤ);exact (ἵ two_pos _).le have hQ2:|2^53*(R s-V)| <=2^53* |R e| +(|R s| + |R e| +A_z):=abs_le.mpr ⟨by linarith only[a2,a3,q1,p',p2,hhi],by linarith only[a2,a3,q2,m',m2,hlo]⟩ rw[ἢ,ἡ (by norm_num1:(0:ℝ)<2^53)] at hQ2 have hrel2:=sck (by norm_num1) hrel rw[one_div_mul_eq_div,le_div_iff₀' (by norm_num1)] linarith only[hQ2,hz,a1,hrel2,Ἀ V] lemma U_w (T M:Ὣ) (h1:T+2097152rename_i hl . have a:=lo.toNat_lt;have b:=t.toNat_lt;rw[ἴ,ὲ,ὲ] at h;rw[ἴ] at hl;norm_num at h hl a b;constructor;. rw[Ὤ];(clear a;exact omS253 hl h) . rw[ἴ];norm_num;(clear a;exact omS254 hl h b) . exact absurd h ג lemma qIj (a:Ὠ) (h0:(0x7040000000000000:Ὠ)<=a<<<(1:Ὠ)) (h1:a<<<(1:Ὠ)<0x8FA0000000000000) (h2:(a+0x0FDFFFFF)&&&0x1FFFFFFF<0x1FC00000): zivW (a+0x200000) (a-0x200000)=zivC ((a+0x0FDFFFFF)>>>(29:Ὠ))/\zivC ((a+0x0FDFFFFF)>>>(29:Ὠ))≠Е:=by have ha:=a.toNat_lt have e0:(a<<<(1:Ὠ)).toNat=Ѧa*2%2^64:=by rw[UInt64.toNat_shiftLeft];norm_num[ὁ] rw[Ὤ,e0] at h0 rw[ἴ,e0] at h1 norm_num at h0 h1 ha have eu:(a+0x0FDFFFFF).toNat=Ѧa+266338303:=by rw[ἤ];norm_num;(clear h2;exact omS255 h1 ha) have em:((a+0x0FDFFFFF)&&&0x1FFFFFFF).toNat=(Ѧa+266338303)%2^29:=by rw[Ὅ,eu] have:=Ἂ (Ѧa+266338303) 29 norm_num at this⊢ exact this rw[ἴ,em] at h2 norm_num at h2 generalize hx:(a+0x0FDFFFFF)>>>(29:Ὠ)=x have ex:Ѧx=(Ѧa+266338303)/2^29:=by rw[<-hx,ἰ,eu];norm_num[Ἱ] have e1:(a+0x200000+0x0FFFFFFF)>>>(29:Ὠ)=x:=by apply UInt64.toNat_inj.mp rw[ex,ἰ,ἤ,ἤ] norm_num[Ἱ] (clear hx;exact omS256 h1 ha h2) have e2:(a-0x200000+0x0FFFFFFF)>>>(29:Ὠ)=x:=by apply UInt64.toNat_inj.mp rw[ex,ἰ,ἤ,ὲ] norm_num[Ἱ] (clear hx e1;exact omS257 h1 ha) have hE:((x>>>(23:Ὠ))&&&(0x7FF:Ὠ)).toNat=Ѧx/2^23%2^11:=by rw[Ὅ,ἰ] have:=Ἂ (Ѧx>>>23) 11 norm_num[Ἱ] at this⊢ exact this have r1:898<=Ѧx/2^23%2^11:=by rw[ex];norm_num;(clear ha hx e1 e2 hE;exact omS258 h0 h1) have r2:Ѧx/2^23%2^11<1151:=by rw[ex];norm_num;(clear ha hx e1 e2 hE r1;exact omS259 h1) have r3:Ѧx<2^35:=by rw[ex];norm_num;(clear hx e1 e2 hE r1 r2;exact omS260 h1 ha) constructor . unfold zivW zivC;dsimp only;rw[e1,e2];have hc:((x>>>(23:Ὠ))&&&(0x7FF:Ὠ))-(897:Ὠ)<(254:Ὠ):=by rw[ἴ,ὲ,hE];norm_num;norm_num at r1 r2;(clear e0 h0 h1 ha eu em h2 hx ex e1 e2 hE r3;exact omS261 r1 r2) simp only[BEq.rfl,hc,decide_true,Bool.and_self, ↓reduceIte,UInt64.toUInt32_or,UInt64.reduceLT,UInt64.toUInt32_shiftLeft,UInt64.toUInt32_ofNat,UInt64.toUInt32_sub,UInt64.toUInt32_and] . unfold zivC;rw[show ((x>>>(34:Ὠ))<<<(31:Ὠ)) ||| ((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<(23:Ὠ)))=((x>>>34)<<<31) ||| ((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<23)) from rfl,qHw x r3 (by clear e0 h0 h1 ha eu em h2 hx ex e1 e2 r3;(exact Nat.le_of_lt ‹_›)) r2];intro h;have h':=congrArg UInt32.toNat h;rw[ὡ] at h';have f:=ὀ Ѧx (ב:0<2^23);split at h'<;>norm_num at h' f r1 r2<;>(clear e0 h0 h1 ha eu em h2 hx ex e1 e2 hE r3 h f;omega) lemma qHy (e s:ὧ) (h1:(s.toBits<<<(1:Ὠ))-loOf e>>(29:Ὠ))/\zivT (thOf e) s≠Е:=by obtain ⟨l1,l2⟩:=kD1 _ _ h1 have l3:thOf e<=s.toBits<<<(1:Ὠ)/\(0x7040000000000000:Ὠ)<=s.toBits<<<(1:Ὠ):=by unfold loOf at l1 dsimp only at l1 rw[Ὤ] at l1⊢ split at l1<;>rename_i hc . rw[ἴ] at hc;constructor;. (clear h1 h2 l2;exact omS262 hc l1) . exact l1 . rw[ἴ] at hc;constructor;. exact l1 . rw[Ὤ];(clear h1 h2 l2;exact omS263 hc l1) have b:=qIj s.toBits l3.2 l2 h2 have e1:zivT (thOf e) s=zivC ((s.toBits+0x0FDFFFFF)>>>(29:Ὠ)):=by unfold zivT dsimp only rw[ἱ l3.1] exact b.1 exact ⟨e1,e1▸b.2⟩ lemma qCnF (n:Ὣ) (hn:n<2^20) (xw ww:Ὣ->ὥ) (bw:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (s e E:ὧ) (hlo:R (s-e)>>(29:Ὠ))=dotOf (n+1) (λt=>if tif tif tif tby by_cases hj:jqJr s _ hV hs1 (by rw[<-hsum,h0,Rat.cast_zero]) have q:(d.toRat:ℝ)=exactS n xw ww bw:=by rw[hd,hsum] rw[hw',<-a] exact kHv _ s d (by rw[q];exact hV) b set_option maxRecDepth 8192 in lemma qBgF (E s e:ὧ) (h1:(s.toBits<<<(1:Ὠ))-loOf Esimp only[Bool.false_eq_true,ite_false,ite_true,one_mul,neg_mul,abs_neg,ἢ,ἡ p]<;>rw[ἅ ו]<;>linarith only[q2,q4] have heb: |R e| <=1/2^34* |R s|:=hE.trans hr have hA:(2:ℝ)^(130:ℤ)<=A_B:=by unfold A_B;exact ἒ (by norm_num1) (by norm_num1) have hsA: |R s| <=A_B:=hB.trans hA have heA: |R e| <=A_B:=heb.trans (ὂ (by linarith only[Ἀ (R s)]) hsA) obtain ⟨-,hadd⟩:=qBf s e fs fe hsA heA have hzk:A_z<=(2:ℝ)^(-127:ℤ):=by show (2:ℝ)^(-1021:ℤ)<=_;exact ἒ ב ב have t0:=Ὥ (R s) (-(R e)) rw[sub_neg_eq_add,abs_neg] at t0 have t1: |R s| *(1-1/2^34)<= |R s+R e|:=by linarith only[le_abs_self (|R s|-|R e|),t0,heb] have t3:=Ὥ (R s+R e) (R (s+e)) rw[ἣ (R s+R e) (R (s+e))] at t3 linarith only[le_abs_self (|R s+R e|-|R (s+e)|),t3,hadd,hzk,t1,hs125,hk,Ἀ (R s+R e)] lemma qAddE (x y:ὧ) (hx:xᶠ) (hy:yᶠ) (h1: |R x| <=A_B) (h2: |R y| <=A_B):(x+y)ᶠ /\R (x+y)=Model.roundAt ⟡ (R x+R y):= A_E _ (toModel_ofFloat_add_of_isFinite x y hx hy) (Model.isFinite_add_of_abs_add_le_posMaxFinite _ _ qAj (qA3 hx) (qA3 hy) (qEe h1 h2)) (Model.toReal_add_eq_roundAt_of_abs_add_le_posMaxFinite _ _ qAj (qA3 hx) (qA3 hy) (qEe h1 h2)) set_option maxRecDepth 8192 in lemma qEmo (nf X v bm:ὧ) (fnf:nfᶠ) (fX:Xᶠ) (fv:vᶠ) (fbm:bmᶠ) (pnf:0<=R nf) (pX:0<=R X) (hvb: |R v| <=R bm) (bX:R X<=2^(290:ℤ)) (bb:R bm<=2^(290:ℤ)) (bnf:R nf<=1): (nf*(X+v.abs))ᶠ /\ |R (nf*(X+v.abs))| <= |R (nf*(X+bm))| :=by obtain ⟨fa,Ra⟩:=qBl v fv have hA:(2:ℝ)^(290:ℤ)<=A_B:=by unfold A_B;exact ἒ (by norm_num1) (by norm_num1) have pb:0<=R bm:=(Ἀ _).trans hvb obtain ⟨f1,R1⟩:=qAddE X v.abs fX fa (by rw[ἅ pX];exact bX.trans hA) (by rw[Ra,abs_abs];exact (hvb.trans bb).trans hA) obtain ⟨f2,R2⟩:=qAddE X bm fX fbm (by rw[ἅ pX];exact bX.trans hA) (by rw[ἅ pb];exact bb.trans hA) have m1:R (X+v.abs)<=R (X+bm):=by rw[R1,R2,Ra];exact Model.roundAt_mono _ (by linarith only[hvb]) have p1:0<=R (X+v.abs):=by rw[R1,<-Model.roundAt_zero ⟡];exact Model.roundAt_mono _ (by rw[Ra];linarith only[pX,Ἀ (R v)]) have b2:R (X+bm)<=2^(292:ℤ):=by obtain ⟨-,e2⟩:=qFc ⟨f2,R2⟩ rw[ἅ (add_nonneg pX pb)] at e2 have r1:=sub_le_iff_le_add'.mp ((le_abs_self _).trans e2) have hz:=qBo have q6:(1:ℝ)<=2^(290:ℤ):=one_le_zpow₀ (by norm_num1) (by norm_num1) rw[show (2:ℝ)^(292:ℤ)=4*2^(290:ℤ) by rw[show (292:ℤ)=2+290 by norm_num1,Ἓ ἓ];norm_num] generalize (2:ℝ)^(290:ℤ)=P at* linarith only[r1,bX,bb,q6,hz,pX,pb] have bp:|R nf| * |R (X+bm)|<=2^(1000:ℤ):=by rw[ἅ pnf,ἅ (p1.trans m1)] have:(2:ℝ)^(292:ℤ)<=2^(1000:ℤ):=ἒ ב ב have hm:=ἀ bnf (p1.trans m1) exact hm.trans ((one_mul _).le.trans (b2.trans this)) have bp1:|R nf| * |R (X+v.abs)|<=2^(1000:ℤ):=by refine ὂ ?_ bp;rw[ἅ p1,ἅ (p1.trans m1)];exact ἁ m1 (Ἀ _) obtain ⟨f3,R3⟩:=qEd nf (X+v.abs) fnf f1 bp1 obtain ⟨-,R4⟩:=qEd nf (X+bm) fnf f2 bp have m2:R (nf*(X+v.abs))<=R (nf*(X+bm)):=by rw[R3,R4];exact Model.roundAt_mono _ (ἁ m1 pnf) have p2:0<=R (nf*(X+v.abs)):=by rw[R3,<-Model.roundAt_zero ⟡];exact Model.roundAt_mono _ (Ἆ pnf p1) exact ⟨f3,by rw[ἅ p2,ἅ (p2.trans m2)];exact m2⟩ set_option maxRecDepth 8192 in lemma qFoldA (g:ℕ->ὧ): ∀(l:List ℕ) (c:ὧ),(∀t∈l,(g t)ᶠ /\ |R (g t)| <=2^(128:ℤ))->cᶠ ->0<=R c->R c<=2^(150:ℤ)-(ѣl:ℝ)*2^(129:ℤ)-> (l.foldl (λ(a:ὧ) t=>a+(g t).abs) c)ᶠ /\0<=R (l.foldl (λ(a:ὧ) t=>a+(g t).abs) c)/\R (l.foldl (λ(a:ὧ) t=>a+(g t).abs) c)<=2^(150:ℤ):=by intro l induction l with | nil=>intro c _ fc p b;simp only[List.foldl_nil,List.length_nil,Nat.cast_zero,zero_mul,sub_zero] at b⊢;exact ⟨fc,p,b⟩ | cons t l ih=> intro c hg fc p b simp only[ὔ] obtain ⟨ft,bt⟩:=hg t (ὣ ..) obtain ⟨fa,Ra⟩:=qBl (g t) ft have hA:(2:ℝ)^(150:ℤ)<=A_B:=by unfold A_B;exact ἒ (by norm_num1) (by norm_num1) have hA2:(2:ℝ)^(128:ℤ)<=A_B:=by unfold A_B;exact ἒ (by norm_num1) (by norm_num1) have h129:(0:ℝ)<=2^(129:ℤ):=(ἵ two_pos _).le have hl:(0:ℝ)<=(ѣl:ℝ):=Ἔ _ simp only[List.length_cons,Nat.cast_add,Nat.cast_one] at b have bc:R c<=2^(150:ℤ):=b.trans (sub_le_self _ (Ἆ (add_nonneg hl zero_le_one) h129)) obtain ⟨f1,R1⟩:=qAddE c (g t).abs fc fa (by rw[ἅ p];exact bc.trans hA) (by rw[Ra,abs_abs];exact bt.trans hA2) obtain ⟨-,e1⟩:=qFc ⟨f1,R1⟩ have p1:0<=R (c+(g t).abs):=by rw[R1,<-Model.roundAt_zero ⟡];exact Model.roundAt_mono _ (by rw[Ra];linarith only[p,Ἀ (R (g t))]) refine ih _ (λu hu=>hg u (ὖ _ hu)) f1 p1 ?_ have hz:A_z<=1:=by show (2:ℝ)^(-1021:ℤ)<=1;exact zpow_le_one_of_nonpos₀ ב ב have q1:(2:ℝ)^(129:ℤ)=2*2^(128:ℤ):=by rw[show (129:ℤ)=1+128 by norm_num,Ἓ ἓ];norm_num have q2:(2:ℝ)^(150:ℤ)=2^22*2^(128:ℤ):=by rw[show (150:ℤ)=22+128 by norm_num,Ἓ ἓ];norm_num have q3:(1:ℝ)<=2^(128:ℤ):=one_le_zpow₀ ב ב rw[Ra,ἅ (show (0:ℝ)<=R c+|R (g t)| by linarith only[p,Ἀ (R (g t))])] at e1 have:=le_abs_self (R (c+(g t).abs)-(R c+|R (g t)|)) have e1':=(le_div_iff₀' (by norm_num1:(0:ℝ)<2^53)).mp (e1.trans_eq (one_div_mul_eq_div _ _)) linarith only[e1',this,b,bt,hz,q1,q2,q3,p,Ἀ (R (g t)),hl] section variable {Rr I O:Ὣ} {X W b:ё} set_option maxRecDepth 8192 in lemma qDuF (G:C_G Rr I O X W b) (Y:Ὡ) {i j:Ὣ} (hi:iW[j*I+t]!&&&В<=hv) (L:љ) (hl:L.Nodup) (hl2:∀t∈L,tt∉L->X[i*I+t]!&&&В=0) (hs:s=L.foldl (λ(acc:ὧ) t=>acc+dv X[i*I+t]!*dv W[j*I+t]!) 0) (bm:ὧ) (fbm:bmᶠ) (hbm: |R (dv b[j]!)| <=R bm) (bb:R bm<=2^(290:ℤ)) (lo:Ὠ) (hlo:lo=loOf (nfOf I*(dv hv*(L.foldl (λ(a:ὧ) t=>a+(dv X[i*I+t]!).abs) 0)+bm))): (if fin1 lo (spOf lo) (s+dv b[j]!)==Е then fin8 I Y X W b i j s (nfOf I) (L.foldl (λ(a:ὧ) t=>a+(dv X[i*I+t]!).abs) 0) hv b[j]! ѩI else fz Y (fin1 lo (spOf lo) (s+dv b[j]!)))=C_out I Y X W b i j:=by split . exact qDu G Y hi hj g1 g2 g4 L hl hl2 hz hs . rename_i hne have hgx:=G.gx hi have hgw:=G.gw hj have gb:=G.gb j (by rw[<-G.hb];exact hj) have hlen:ѣL<=I:=qFu hl hl2 have ni:=G.ni obtain ⟨fA,pA,bA⟩:=qFoldA (λt=>dv X[i*I+t]!) L 0 (λt ht=>⟨(qAm _ (hgx t (hl2 t ht))).1,by rw[(qAm _ (hgx t (hl2 t ht))).2];exact qAo _ (hgx t (hl2 t ht))⟩) qHg.1 (by rw[qHg.2]) (by have:(ѣL:ℝ)<=2^20:=by exact_mod_cast (by exact omS268 hlen ni:ѣL<=2^20) have q:(2:ℝ)^(150:ℤ)=2^21*2^(129:ℤ):=by rw[show (150:ℤ)=21+129 by norm_num,Ἓ ἓ];norm_num have q2:(0:ℝ)<2^(129:ℤ):=ἵ two_pos _ rw[qHg.2,q,sub_nonneg];exact ἀ (this.trans (by norm_num1)) q2.le) generalize hA:L.foldl (λ(a:ὧ) t=>a+(dv X[i*I+t]!).abs) 0=A at hlo fA pA bA⊢ obtain ⟨fh,Rh⟩:=qAm hv g1 obtain ⟨ph,bh,-⟩:=qCs g1 g2 have hp:|R (dv hv)| * |R A| <=2^(1000:ℤ):=by rw[Rh,ἅ ph,ἅ pA] have:(2:ℝ)^128*2^(150:ℤ)<=2^(1000:ℤ):=by rw[show (2:ℝ)^128=2^(128:ℤ) by norm_num,<-Ἓ ἓ];exact ἒ ב ב exact (ἑ bh bA pA ו).trans this obtain ⟨fX,RX⟩:=qEd (dv hv) A fh fA hp have pX:0<=R (dv hv*A):=by rw[RX,<-Model.roundAt_zero ⟡];exact Model.roundAt_mono _ (by rw[Rh];exact Ἆ ph pA) have bX:R (dv hv*A)<=2^(290:ℤ):=by obtain ⟨-,e⟩:=qFc ⟨fX,RX⟩ have c0:R (dv hv)*R A<=2^(278:ℤ):=by have:(2:ℝ)^128*2^(150:ℤ)=2^(278:ℤ):=by rw[show (2:ℝ)^128=2^(128:ℤ) by norm_num,<-Ἓ ἓ];norm_num rw[Rh,<-this];exact ἑ bh bA pA ו have c1:(0:ℝ)<=R (dv hv)*R A:=by rw[Rh];exact Ἆ ph pA have hz:A_z<=1:=by show (2:ℝ)^(-1021:ℤ)<=1;exact zpow_le_one_of_nonpos₀ ב ב have q1:(2:ℝ)^(290:ℤ)=2^12*2^(278:ℤ):=by rw[show (290:ℤ)=12+278 by norm_num,Ἓ ἓ];norm_num have q2:(1:ℝ)<=2^(278:ℤ):=one_le_zpow₀ ב ב rw[ἅ c1] at e have:=le_abs_self (R (dv hv*A)-R (dv hv)*R A) rw[q1];clear hp;generalize (2:ℝ)^(278:ℤ)=P at*;generalize R (dv hv)*R A=Q at*;linarith only[e,this,c0,c1,hz,q2] obtain ⟨fnf,Rnf⟩:=qIn I ni have pnf:0<=R (nfOf I):=by rw[Rnf];exact div_nonneg (add_nonneg (Ἔ _) (by norm_num1)) (by norm_num1) have bnf:R (nfOf I)<=1:=by have hI:(I:ℝ)<2^20:=by exact_mod_cast ni rw[Rnf,div_le_one ו];linarith only[hI] obtain ⟨fv,-⟩:=qAm _ gb obtain ⟨fe,hE⟩:=qEmo (nfOf I) (dv hv*A) (dv b[j]!) bm fnf fX fv fbm pnf pX hbm bX bb bnf have key:fin1 lo (spOf lo) (s+dv b[j]!)≠Е:=by simpa only[ne_eq,beq_iff_eq] using hne unfold fin1 at key⊢ dsimp only at key⊢ split at key . rename_i ht simp only[Bool.and_eq_true,decide_eq_true_eq] at ht obtain ⟨h1,h2⟩:=ht rw[ἱ (by simp only[Bool.and_eq_true,decide_eq_true_eq];exact ⟨h1,h2⟩)] subst hlo have hbig:=qBgF _ _ _ h1 h2 fe hE obtain ⟨c1,c2⟩:=qC8 I ni (λt=>X[i*I+t]!) (λt=>W[j*I+t]!) b[j]! hv hgx hgw gb g1 g2 L hl hl2 (λt ht=>g4 t (hl2 t ht)) hz (s+dv b[j]!) (nfOf I*(dv hv*A+(dv b[j]!).abs)) ⟨by rw[hs],by rw[hA]⟩ hbig have e:=qCnF I ni _ _ _ hgx hgw gb _ _ _ c1 c2 fe hE h1 h2 obtain ⟨a,b'⟩:=qHy _ _ h1 h2 obtain ⟨-,S,ex,fr,M,a1,a2,a3,hz',-⟩:=kFh _ _ b' rw[a] at hz' have he:=qR1 _ S ex fr a1 a2 a3 hz' unfold fz C_out rw[qR0 Y _ he,e] . exact absurd rfl key end section variable {R I O:Ὣ} {X W b:ё} section variable (G:C_G R I O X W b) include G lemma C_G.nm:I.toUSize.toNat=I:=qAd _ (lt_trans G.ni (by norm_num1)) lemma C_G.wj {j:Ὣ} {u:ὦ} (hu:Ѥu=j) (hj:j |D.R (dv b[j]!)| <=D.R bm) (bb:D.R bm<=2^(290:ℤ)) {lo:Ὠ} (hlo:lo=loOf (nfOf I*(dv hv*l+bm))): fin8L I Y X W b i j (go1 x ix W (u*ѩI) ѩI c 0 hx hi' hs h0 0) (nfOf I) l hv lo (rdW b u) ѩI=C_out I Y X W b i j:=by have e:=qH6 hx hi' hs h0 (λp=>dv X[i*I+p]!) (λp=>W[j*I+p]!) (λp _=>by rw[(G.wj hu hj).1]) L 0 0 (by rw[C_z,Ἇ];exact Rw.len.symm) (λk p hk=>by have h1:=Rw.rd k p hk rw[C_z,Ἇ,G.nm] exact ⟨Rw.lt p (List.mem_of_getElem? hk),h1⟩) rw[qAg _ _ G.sb,hu,Rw.ok] rw[Rw.ok] at hlo unfold fin8L fin8n;dsimp only exact qDuF G Y hi hj Hv.1 Hv.2.1 (λt ht=>Hv.2.2.2 _ (by rw[<-G.hW];exact qCj hj ht)) L Rw.nd Rw.lt Rw.hz e bm fbm (hbm j hj) bb lo hlo lemma qD0 (Y:Ὡ) {i:Ὣ} (hi:i |D.R (dv b[j]!)| <=D.R bm) (bb:D.R bm<=2^(290:ℤ)) {lo:Ὠ} (hlo:lo=loOf (nfOf I*(dv hv*l+bm))) (d:Ὣ):∀(j:Ὣ) (out:ё),j+d=O->C_Inv (R*O) (C_sp I O Y X W b) (λq=>q< i*O+j) out-> C_Inv (R*O) (C_sp I O Y X W b) (λq=>q< i*O+O) (cols1 I O Y X W b i ix x wd (nfOf I) l hv lo ѩI c j base out):=by induction d using Nat.strong_induction_on with | _ d ih=> intro j out he H have hN:=G.sO have sW:ѧW<=4294967295:=by have:=G.sW;(exact Nat.le_of_lt_succ ‹_›) have hbs:=G.sb have hob:=G.hb have hle:=Rw.cle have h1c:Ѥc<=Ѩx:=by rw[Rw.len];exact hle.trans Rw.sx.1 have h2c:Ѥc<=ѧix:=by rw[Rw.len];exact hle.trans Rw.six have hsp:∀k,j+kC_out I Y X W b i (j+k)=C_sp I O Y X W b (i*O+j+k):=λk hk=>by rw[ὢ];exact (qCi I O Y X W b hk).symm by_cases h4:j+4<=O . have hP:=qCj hi ((by exact Nat.succ_le_of_lt ‹_›):j+3by rw[Rw.len] at hj;have hp:=List.getElem?_eq_getElem hj exact ⟨_,G.gx hi _ (Rw.lt _ (List.mem_of_getElem? hp)),(Rw.rd j _ hp).2⟩) Ѥc 0 _ _ _ _ (Ἇ _)] dsimp only;rw[o0,o1,o2,o3];refine ih (d-4) (by clear hi hb hN sW hbs hle h1c h2c hP g0 g1 g2 g3 a0 o0 o1 o2 o3;exact omS274 he h4) (j+4) _ (by clear hi hb hN sW hbs hle h1c h2c hP g0 g1 g2 g3 a0 o0 o1 o2 o3;exact omS275 he h4) ?_;rw[show i*O+(j+4)=i*O+j+4 by (clear hi hb he hN sW hbs hob hle h1c h2c h4 hP e0 e1 e2 e3 g0 g1 g2 g3 a0 o0 o1 o2 o3;exact omS276)];exact qEq hN H a0 (by exact Nat.succ_le_of_lt ‹_›) (hsp 0 (by clear hi hb hN sW hbs hle h1c h2c hP g0 g1 g2 g3 a0 o0 o1 o2 o3;exact omS277 h4)) (hsp 1 (by clear hi hb hN sW hbs hle h1c h2c hP g0 g1 g2 g3 a0 o0 o1 o2 o3;exact omS153 h4)) (hsp 2 (by exact Nat.le_of_lt ‹_›)) (hsp 3 (by exact Nat.succ_le_of_lt ‹_›)) . by_cases h1:jὧ | 0=>d.h0 | 1=>d.h1 | 2=>d.h2 | 3=>d.h3 | 4=>d.h4 | 5=>d.h5 | 6=>d.h6 | _=>d.h7 def C_fs (d:F8):Ὣ->ὧ | 0=>d.s0 | 1=>d.s1 | 2=>d.s2 | 3=>d.s3 | 4=>d.s4 | 5=>d.s5 | 6=>d.s6 | _=>d.s7 def C_lo (d:L8):Ὣ->Ὠ | 0=>d.l0 | 1=>d.l1 | 2=>d.l2 | 3=>d.l3 | 4=>d.l4 | 5=>d.l5 | 6=>d.l6 | _=>d.l7 @[inline] def mkL8 (nf hvv bm:ὧ) (d:H8):L8:=⟨loOf (nf*(hvv*d.h0+bm)),loOf (nf*(hvv*d.h1+bm)),loOf (nf*(hvv*d.h2+bm)),loOf (nf*(hvv*d.h3+bm)),loOf (nf*(hvv*d.h4+bm)),loOf (nf*(hvv*d.h5+bm)),loOf (nf*(hvv*d.h6+bm)),loOf (nf*(hvv*d.h7+bm))⟩ lemma qB3 {n t c:ὦ} {k:Ὣ} (hc:Ѥc=k) (h:k*Ѥn+Ѥt<2^32):(c*n+t).toNat=k*Ѥn+Ѥt:=by have h0:k*Ѥn<2^32:=(by clear hc;exact omS283 h);rw[qAf _ _ (by rw[qBa _ _ (by rw[hc];exact h0),hc];exact h),qBa _ _ (by rw[hc];exact h0),hc] lemma qWc (a:ὤ) (i:ὦ) (j:Ὣ) (hj:Ѥi=j) (v:ὧ) (hs:Ѩa<2^32) (hi:j< Ѩa) (q:Ὣ):(wrF a i v).data[q]! =if q=j then v else a.data[q]!:=by rw[qEt a i v q hs (by rw[hj];exact hi),hj] lemma qW8 (xs:ὤ) (t:ὦ) (a0 a1 a2 a3 a4 a5 a6 a7:ὧ) (hs:Ѩxs<2^32) (hb:8*Ѥt+9<=Ѩxs): (wr8 xs (8*t+ὴ 1) a0 a1 a2 a3 a4 a5 a6 a7).size=Ѩxs/\∀q,(wr8 xs (8*t+ὴ 1) a0 a1 a2 a3 a4 a5 a6 a7).data[q]! = if q=8*Ѥt+1+7 then a7 else if q=8*Ѥt+1+6 then a6 else if q=8*Ѥt+1+5 then a5 else if q=8*Ѥt+1+4 then a4 else if q=8*Ѥt+1+3 then a3 else if q=8*Ѥt+1+2 then a2 else if q=8*Ѥt+1+1 then a1 else if q=8*Ѥt+1+0 then a0 else xs.data[q]!:=by have l8:(8:ὦ).toNat=8:=uk 8 (by norm_num1) have e80:(8*t).toNat=8*Ѥt:=by rw[qBa _ _ (by rw[l8];(clear l8;exact omS284 hs hb)),l8] have e8:(8*t+ὴ 1).toNat=8*Ѥt+1:=by rw[qAf _ _ (by rw[e80,uk 1 ה];(clear l8 e80;exact omS285 hs hb)),e80,uk 1 ה] have E:∀k,k<8->(8*t+ὴ 1+ὴ k).toNat=8*Ѥt+1+k:=λk hk=>by rw[qAf _ _ (by rw[e8,uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)];(clear l8 e8;omega)),e8,uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)] unfold wr8 refine ⟨by simp only[qD6],λq=>?_⟩ rw[qWc _ _ _ (E 7 (by exact Nat.le_refl _)) _ (by simp only[qD6];exact hs) (by simp only[qD6];(clear l8 e8 e80;exact omS286 hb)) q, qWc _ _ _ (E 6 ה) _ (by simp only[qD6];exact hs) (by simp only[qD6];(clear l8 e8 e80;exact omS287 hb)) q, qWc _ _ _ (E 5 ה) _ (by simp only[qD6];exact hs) (by simp only[qD6];(clear hs l8 e8 e80;exact omS288 hb)) q, qWc _ _ _ (E 4 ה) _ (by simp only[qD6];exact hs) (by simp only[qD6];(clear hs l8 e8 e80;exact omS289 hb)) q, qWc _ _ _ (E 3 ה) _ (by simp only[qD6];exact hs) (by simp only[qD6];(clear hs l8 e8 e80;exact omS290 hb)) q, qWc _ _ _ (E 2 ה) _ (by simp only[qD6];exact hs) (by simp only[qD6];(clear hs l8 e8 e80;exact omS291 hb)) q, qWc _ _ _ (E 1 ה) _ (by simp only[qD6];exact hs) (by simp only[qD6];(clear hs l8 e8 e80;exact omS292 hb)) q, qWc _ _ _ (E 0 ה) _ hs (by (clear hs l8 e8 e80;exact omS293 hb)) q] lemma qZs (m:Ὣ) (h:m<2^32):(pushZ (ὴ m) 0 (ἆ m)).size=m:=by rw[qDy (ὴ m) m 0 _ (by rw[uk m h,C_z,Ἇ])];exact Ἇ _ lemma qZf (m:Ὣ) (h:m<2^32):m<=(zFor m).size/\(zFor m).size<2^32:=by unfold zFor by_cases hc32:m<=32 · rw[ἱ hc32];have e:ѨzA=32:=qZs 32 (by norm_num1);rw[e];omega rw[ἐ hc32] by_cases hc128:m<=128 · rw[ἱ hc128];have e:Ѩz0=128:=qZs 128 (by norm_num1);rw[e];omega rw[ἐ hc128] by_cases hc256:m<=256 · rw[ἱ hc256];have e:ѨzB=256:=qZs 256 (by norm_num1);rw[e];omega rw[ἐ hc256] by_cases hc512:m<=512 · rw[ἱ hc512];have e:ѨzC=512:=qZs 512 (by norm_num1);rw[e];omega rw[ἐ hc512] by_cases hc1024:m<=1024 · rw[ἱ hc1024];have e:Ѩz1=1024:=qZs 1024 (by norm_num1);rw[e];omega rw[ἐ hc1024] by_cases hc4096:m<=4096 · rw[ἱ hc4096];have e:Ѩz4=4096:=qZs 4096 (by norm_num1);rw[e];omega rw[ἐ hc4096] by_cases hc8192:m<=8192 · rw[ἱ hc8192];have e:Ѩz8=8192:=qZs 8192 (by norm_num1);rw[e];omega rw[ἐ hc8192] have e:(pushZ ѩm 0 (ἆ m)).size=m:=qZs m h;rw[e];omega lemma qBq {xs:ὤ} {i t n:ὦ} {xf:Ὣ->Ὣ->ὧ} (hxf:∀r k:Ὣ,r<8->k< Ѥn->xs.data[8*k+1+r]! =xf r k) (hi:Ѥi=8*Ѥt+1) (ht:Ѥt< Ѥn) (hsx:Ѩxs<2^32) (hx:8*Ѥn+1<=Ѩxs) (r:Ὣ) (hr:r<8) (pf:(i+ὴ r).toNat< Ѩxs):xs.uget (i+ὴ r) pf=xf r Ѥt:=by rw[qC5,qAf _ _ (by rw[uk r (by exact Nat.lt_of_lt_of_le ‹_› ה)];(clear pf;exact omS294 hi ht hsx hx hr)),uk r (by exact Nat.lt_of_lt_of_le ‹_› ה),hi,hxf r _ hr ht] end section open Float.Model Float.Model.UnpackedFloat lemma qD2 (s:Sign):(Float.Model.pack (UnpackedFloat.infinity s)).unpack.isFinite=false:=by cases s<;>decide+kernel lemma qFh:(Float.Model.pack UnpackedFloat.notANumber).unpack.isFinite=false:=by decide+kernel lemma qC1 (x y:ὧ) (h:(x*y)ᶠ):xᶠ/\yᶠ:=by change (Float.Model.mul x.toModel y.toModel).unpack.isFinite=true at h;change x.toModel.unpack.isFinite=true/\y.toModel.unpack.isFinite=true;rw[Float.Model.mul] at h;cases a:x.toModel.unpack<;>cases b:y.toModel.unpack<;>simp only[a,b,UnpackedFloat.mul,qD2,qFh,Bool.false_eq_true] at h<;>exact ⟨rfl,rfl⟩ lemma qC2 (x y:ὧ) (h:(x+y)ᶠ):xᶠ/\yᶠ:=by change (Float.Model.add x.toModel y.toModel).unpack.isFinite=true at h;change x.toModel.unpack.isFinite=true/\y.toModel.unpack.isFinite=true;rw[Float.Model.add] at h cases a:x.toModel.unpack<;>cases b:y.toModel.unpack<;>simp only[a,b,UnpackedFloat.add,qD2,qFh,Bool.false_eq_true] at h<;> first | exact ⟨rfl,rfl⟩ | (split at h<;>simp only[qD2,qFh,Bool.false_eq_true] at h) @[inline] def okF (t:ὧ):Ὡ:=t-t==t-t lemma fS1 (s:Sign):(Float.Model.pack (UnpackedFloat.sub ⟠ (UnpackedFloat.infinity s) (UnpackedFloat.infinity s))).unpack.beq (Float.Model.pack (UnpackedFloat.sub ⟠ (UnpackedFloat.infinity s) (UnpackedFloat.infinity s))).unpack=false:=by cases s<;>decide+kernel lemma fS2:(Float.Model.pack (UnpackedFloat.sub ⟠ UnpackedFloat.notANumber UnpackedFloat.notANumber)).unpack.beq (Float.Model.pack (UnpackedFloat.sub ⟠ UnpackedFloat.notANumber UnpackedFloat.notANumber)).unpack=false:=by decide+kernel lemma finSub (t:ὧ) (h:okF t=true):tᶠ :=by unfold okF at h change (Float.Model.beq (Float.Model.sub t.toModel t.toModel) (Float.Model.sub t.toModel t.toModel))=true at h change t.toModel.unpack.isFinite=true rw[Float.Model.sub,Float.Model.beq] at h cases a:t.toModel.unpack . rename_i s;rw[a,fS1] at h;exact absurd h ה . rw[a,fS2] at h;exact absurd h ה . rfl . rfl lemma qHz:(Ἃ 0x7FF8000000000000).isFinite=false:=by decide+kernel def N_ok (w:ὥ):Prop:=0x800000<=w&&&В/\w&&&В<0x40000000 lemma qEx {w:ὥ} (h:N_ok w):good w=true:=qBt _ (Or.inr h.1) (by have t:w&&&В<0x40000000:=h.2;have a:(0x40000000:ὥ).toNat=0x40000000:=rfl;have b:(У:ὥ).toNat=У:=rfl;rw[ἳ,a] at t;rw[ἳ,b];(exact Nat.lt_of_lt_of_le ‹_› ה)) def Z_ok (hv w:ὥ):Prop:=w&&&В<=hv lemma qTb {z:Ὣ} {T:ὤ} {h:ὥ} (o:TOK z T h):ѥh<0x40000000:=by obtain ⟨k,-,-,k2,k3,e⟩:=o;exact omS295 k3 e lemma qTg {z:Ὣ} {T:ὤ} {h:ὥ} (o:TOK z T h):good h=true/\h<=В:=by obtain ⟨k,-,-,k2,k3,e⟩:=o have a:=qAq h refine ⟨qEx ⟨?_,?_⟩,?_⟩ . rw[ἃ,a,show (0x800000:ὥ).toNat=0x800000 from rfl];exact omS296 k2 k3 e . rw[ἳ,a,show (0x40000000:ὥ).toNat=0x40000000 from rfl];exact omS297 k3 e . rw[ἃ,show (В:ὥ).toNat=В from rfl];(clear a;exact omS298 k3 e) lemma N_w {z:Ὣ} {T:ὤ} {h:ὥ} (o:TOK z T h) (hT:ѨT=512) (w:ὥ) (f:(T.uget (w>>>(23:ὥ)).toUSize (qBx hT w))ᶠ): T.uget (w>>>(23:ὥ)).toUSize (qBx hT w)=pw.uget (w>>>(23:ὥ)).toUSize (qCh w)/\z*0x800000<=(w&&&В).toNat/\w&&&В<=h:=by obtain ⟨k,-,eT,k2,k3,hk⟩:=o have s:=qD8 w rw[eT,ὃ,s] at f rw[eT,qDc,ὃ,s] unfold pwEntryN at f⊢ have e:=qAq w have g:=w.toNat_lt by_cases c:(decide (ѥw/2^23%256ὧ) (L:љ) (a:ὧ):ὧ:= L.foldl (λacc s=>acc+f s) a lemma qB4 (f:Ὣ->ὧ) (L:љ): ∀a,(N_ff f L a)ᶠ->aᶠ/\∀s∈L,(f s)ᶠ:=by induction L with | nil=>exact λa h=>⟨h,λs hs=>by simp only[List.not_mem_nil] at hs⟩ | cons p L ih=> intro a h;obtain ⟨h1,h2⟩:=ih _ h;obtain ⟨h3,h4⟩:=qC2 _ _ h1;refine ⟨h3,λs hs=>?_⟩;rcases List.mem_cons.mp hs with e | e;. rw[e];exact h4 . exact h2 s e section variable {T:ὤ} {hT:ѨT=512} {x:ὤ} {ix W:ѐ} {w0 w1 w2 w3 m n:ὦ} (f:ὧ->ὥ->ὧ) end section variable {T:ὤ} {hT:ѨT=512} {hv:ὥ} {x:ὤ} {W:ѐ} {u:Ὣ} {L:љ} include x W u L end section variable {T:ὤ} {hT:ѨT=512} {hv:ὥ} {I O:Ὣ} {X W b:ё} set_option maxRecDepth 8000 in lemma qS8 (R:F8) (H:(R.s0+R.s1+R.s2+R.s3+R.s4+R.s5+R.s6+R.s7)ᶠ):∀r,r<8->(C_fs R r)ᶠ:=by obtain ⟨h1,h7⟩:=qC2 _ _ H obtain ⟨h2,h6⟩:=qC2 _ _ h1 obtain ⟨h3,h5⟩:=qC2 _ _ h2 obtain ⟨h4,h4'⟩:=qC2 _ _ h3 obtain ⟨h9,h3'⟩:=qC2 _ _ h4 obtain ⟨h10,h2'⟩:=qC2 _ _ h9 obtain ⟨h0,h1'⟩:=qC2 _ _ h10 intro r hr interval_cases r . exact h0 . exact h1' . exact h2' . exact h3' . exact h4' . exact h5 . exact h6 . exact h7 lemma qZn (oT:TOK 0 T hv) (f:Ὣ->ὧ) (ww:Ὣ->ὥ) (L:љ) (h:(N_ff (λs=>f s*dvN T hT (ww s)) L 0)ᶠ): (∀s∈L,Z_ok hv (ww s))/\N_ff (λs=>f s*dvN T hT (ww s)) L 0=L.foldl (λacc s=>acc+f s*dv (ww s)) 0:=by have F:=(qB4 _ _ _ h).2 have G:=λs hs=>qZk oT (qC1 _ _ (F s hs)).2 exact ⟨λs hs=>(G s hs).2,List.foldl_ext _ _ _ λacc s hs=>by show acc+f s*dvN T hT (ww s)=_ rw[(G s hs).1]⟩ lemma qZg {hv w:ὥ} (t:ѥhv<0x40000000) (h:Z_ok hv w) (g:w&&&В=0\/0x800000<=w&&&В):good w=true:=qBt _ g (by have c:=ἃ.mp h;have b:(У:ὥ).toNat=У:=rfl;rw[ἳ,b];(clear g b;exact omS312 t c)) lemma qZm (ww:Ὣ->ὥ) (L:љ):∀q,0x7FFFFF<=L.foldl (λq s=>q&&&((ww s&&&В)-1)) q->0x7FFFFF<=q/\∀s∈L,ww s&&&В=0\/0x800000<=ww s&&&В:=by induction L with | nil=>exact λq h=>⟨h,λs hs=>by simp only[List.not_mem_nil] at hs⟩ | cons p L ih=> intro q h obtain ⟨h1,h2⟩:=ih _ h obtain ⟨h8,h9⟩:=qFe q ((ww p&&&В)-1) refine ⟨UInt32.le_trans h1 h8,λs hs=>?_⟩ rcases List.mem_cons.mp hs with e | e . rw[e];exact qGi _ (UInt32.le_trans h1 h9) . exact h2 s e lemma qZ1 {xs:ὤ} {W:ѐ} {wo n:ὦ} (hx:8*Ѥn+1<=Ѩxs) (hsx:Ѩxs<2^32) (hs:ѧW<2^32) (hw:Ѥwo+Ѥn<=ѧW) (ww:Ὣ->Ὢ) (hww:∀k,k< Ѥn->W[Ѥwo+k]! =ww k) (d:Ὣ): ∀(t i:ὦ) (hi:Ѥi=8*Ѥt+1) (s0 s1 s2 s3 s4 s5 s6 s7:ὧ) (q:ὥ) (r0:F8),Ѥt+d=Ѥn-> (∀r,r<8->C_fs (go8Z T hT xs W wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q r0) r= N_ff (λs=>xs.data[8*s+1+r]!*dvN T hT (ww s)) (List.range' Ѥt d) (C_fs ⟨0,s0,s1,s2,s3,s4,s5,s6,s7,0,0⟩ r))/\ (go8Z T hT xs W wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q r0).q=(List.range' Ѥt d).foldl (λq s=>q&&&((ww s&&&В)-1)) q:=by induction d with | zero=> intro t i hi s0 s1 s2 s3 s4 s5 s6 s7 q r0 he rw[go8Z,ἔ (by rw[А];(clear hx hsx hs hw hi;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))] cases r0 exact ⟨λr hr=>by interval_cases r<;>rfl,rfl⟩ | succ d ih=> intro t i hi s0 s1 s2 s3 s4 s5 s6 s7 q r0 he have ht:tqBq (xf:=λr k=>xs.data[8*k+1+r]!) (λ_ _ _ _=>rfl) hi htn hsx hx k hk rw[go8Z,Ἄ ht] dsimp only rw[e,B 0 ה,B 1 ה,B 2 ה,B 3 ה,B 4 ה,B 5 ה,B 6 ה,B 7 (by exact Nat.le_refl _)] obtain ⟨J1,J2⟩:=ih (t+1) (i+ὴ 8) (by rw[hu,qAf _ _ (by rw[uk 8 ה];(clear ht htn e;exact omS314 hx hsx hi he)),uk 8 ה];(clear he ht htn hu e;exact omS315 hi)) _ _ _ _ _ _ _ _ _ r0 (by rw[hu];(clear hi ht htn hu e;exact omS137 he)) have e5:List.range' (t+1).toNat d=List.range' (Ѥt+1) d:=by rw[hu] rw[e5] at J1 J2 refine ⟨λr hr=>(J1 r hr).trans ?_,J2.trans ?_⟩ . rw[List.range'_succ] unfold N_ff rw[ὔ] interval_cases r<;>rfl . rw[List.range'_succ];rfl @[noinline] def fin8o (inW:Ὣ) (relu:Ὡ) (X W b:ё) (ri K j:Ὣ) (s nf a:ὧ) (hx bw:ὥ) (n:ὦ):ὥ:= let bv:=dv bw let r:=ziv (s+bv) (nf*(dv hx*a+bv.abs)) if r==Е then let i:=ri+K let q:=tightGo X W (i*inW).toUSize (j*inW).toUSize n 0 0 0 fin inW relu X W b i j q.s nf q.t bw else r&&&((if relu then (0:ὥ) else Е) ||| ((r>>>(31:ὥ))-1)) local instance ecNe8:Nonempty H8:=⟨by constructor <;> exact default⟩ def dec8o (X:ѐ) (o n t:ὦ) (xs:ὤ) (h0 h1 h2 h3 h4 h5 h6 h7:ὧ):H8:= if h:t exact default⟩ def cols8Zo (T:ὤ) (hT:ѨT=512) (hv:ὥ) (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (d:H8) (nf:ὧ) (n:ὦ) (ri:Ὣ) (ob:ὦ) (j:Ὣ) (out:ѐ) (q:ὥ) (th:L8) (r0:F8):CN:= if hj:jr<8->d.xs.data[8*k+1+r]! =dv X[(ri+r)*m+k]!)/\ ∀r:Ὣ,r<8->C_hf d r=(ἄ t).foldl (λ(a:ὧ) k=>a+(dv X[(ri+r)*m+k]!).abs) 0 lemma qRo {X:ё} {o n t c:ὦ} {ri k:Ὣ} (hs:ѧX<2^32) (ho:Ѥo=ri*Ѥn) (hc:Ѥc=k) (h:(ri+k)*Ѥn+Ѥt<2^32):rdW X (o+(c*n+t))=X[(ri+k)*Ѥn+Ѥt]!:=by have h0:(ri+k)*Ѥn=ri*Ѥn+k*Ѥn:=ὰ _ _ _ have h1:k*Ѥn+Ѥt<2^32:=by (clear hs hc;exact omS316 h h0) rw[qAg _ _ hs,qAf _ _ (by rw[qB3 hc h1,ho];(clear hs ho hc h1;exact omS317 h h0)),qB3 hc h1,ho,h0,ὢ] lemma qGqo {X:ё} {o n:ὦ} {ri:Ὣ} (hs:ѧX<2^32) (ho:Ѥo=ri*Ѥn) (h8:(ri+8)*Ѥn<=ѧX) (d:Ὣ): ∀(t:ὦ) (xs:ὤ) (h0 h1 h2 h3 h4 h5 h6 h7:ὧ),Ѥt+d=Ѥn->C_D8o X ri Ѥn Ѥt ⟨xs,h0,h1,h2,h3,h4,h5,h6,h7⟩->C_D8o X ri Ѥn Ѥn (dec8o X o n t xs h0 h1 h2 h3 h4 h5 h6 h7):=by induction d with | zero=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 he H rw[dec8o,ἔ (by rw[А];(clear hs ho h8;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))] have e:Ѥt=Ѥn:=(by exact omS155 he) rw[e] at H;exact H | succ d ih=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 he H have ht:t(ri+k)*Ѥn+Ѥt<2^32:=λk hk=>by have a1:=Ἒ Ѥn (show ri+k+1<=ri+8 by (clear hs ho h8 he ht hu;exact omS318 hk)) have a2:(ri+k+1)*Ѥn=(ri+k)*Ѥn+Ѥn:=by rw[ὰ,Ὑ] (clear ho ht hk;omega) rw[dec8o,Ἄ ht] dsimp only rw[qRo hs ho (show (0:ὦ).toNat=0 from uk 0 ו) (bnd 0 ו),qRo hs ho (show (1:ὦ).toNat=1 from uk 1 (by norm_num1)) (bnd 1 (by norm_num1)),qRo hs ho (show (2:ὦ).toNat=2 from uk 2 (by norm_num1)) (bnd 2 (by norm_num1)),qRo hs ho (show (3:ὦ).toNat=3 from uk 3 (by norm_num1)) (bnd 3 (by norm_num1)),qRo hs ho (show (4:ὦ).toNat=4 from uk 4 (by norm_num1)) (bnd 4 (by norm_num1)),qRo hs ho (show (5:ὦ).toNat=5 from uk 5 (by norm_num1)) (bnd 5 (by norm_num1)),qRo hs ho (show (6:ὦ).toNat=6 from uk 6 (by norm_num1)) (bnd 6 (by norm_num1)),qRo hs ho (show (7:ὦ).toNat=7 from uk 7 (by norm_num1)) (bnd 7 (by norm_num1))] obtain ⟨H1,H2,H3⟩:=H dsimp only at H1 H2 obtain ⟨Z1,Z2⟩:=qW8 xs t (dv X[(ri+0)*Ѥn+Ѥt]!) (dv X[(ri+1)*Ѥn+Ѥt]!) (dv X[(ri+2)*Ѥn+Ѥt]!) (dv X[(ri+3)*Ѥn+Ѥt]!) (dv X[(ri+4)*Ѥn+Ѥt]!) (dv X[(ri+5)*Ѥn+Ѥt]!) (dv X[(ri+6)*Ѥn+Ѥt]!) (dv X[(ri+7)*Ѥn+Ѥt]!) H1.2 (by have:=H1.1;(clear hs ho h8 ht this;omega)) refine ih (t+1) _ _ _ _ _ _ _ _ _ (by clear hs ho h8 ht H1 Z1;exact omS157 he hu) ⟨?_,?_,?_⟩ . dsimp only;rw[Z1];exact H1 . intro k r hk hr;rw[hu] at hk;dsimp only;rw[Z2];by_cases e:k=Ѥt . subst e;interval_cases r<;>simp only[add_zero,Nat.left_eq_add,OfNat.ofNat_ne_zero, ↓reduceIte,one_ne_zero,Nat.add_left_cancel_iff,OfNat.one_ne_ofNat,Nat.reduceEqDiff] . have hk':k< Ѥt:=Nat.lt_of_le_of_ne (Nat.le_of_lt_succ hk) e have hlt:8*k+1+r<8*Ѥt+1:=by (clear hs ho h8 ht H1 Z1 hk e;omega) rw[ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _)))];exact H2 k r hk' hr . intro r hr;have h9:=H3 r hr;rw[hu,List.range_succ,List.foldl_append,<-h9];interval_cases r<;>rfl def C_B (ri O j q:Ὣ):Prop:=qsimp only[e3.symm,true_or,or_true] lemma qW9o {N O ri j:Ὣ} {sp:Ὣ->Ὢ} {out:ё} {ob:ὦ} (hN:N<2^32) (hR:(ri+8)*O<=N) (hob:Ѥob=ri*O) (hj:j(ri+k)*O+jby have a1:=Ἒ O (show ri+k+1<=ri+8 by (clear hN hR hob hj;exact omS318 hk)) have a2:(ri+k+1)*O=(ri+k)*O+O:=by rw[ὰ,Ὑ] have a3:(ri+k)*O=ri*O+k*O:=ὰ _ _ _ constructor<;>(clear hk;omega) have e0:j.toUSize.toNat=j:=qAd _ (by have:=bk 0 ו;(clear hN hR hob hj;omega)) have eo:O.toUSize.toNat=O:=qAd _ (by have:=bk 1 (by norm_num1);(clear hN hR hob;(clear hj;omega))) have pk:∀(c:ὦ) (k:Ὣ),k<8->Ѥc=k->(ob+(c*ѩO+ѩj)).toNat=(ri+k)*O+j:=λc k hk hc=>by obtain ⟨b1,b2⟩:=bk k hk have a3:(ri+k)*O=ri*O+k*O:=ὰ _ _ _ have i1:(c*ѩO+ѩj).toNat=k*O+j:=by rw[qB3 hc (by rw[eo,e0];(exact Nat.succ_le_of_lt ‹_›)),eo,e0] rw[qAf _ _ (by rw[i1,hob];(clear hR hob hj eo hk hc b2;(clear e0;exact omS320 hN b1 a3))),i1,hob];(clear hN hR hob hj e0 eo hk hc b1 b2 i1;omega) have u0:(ob+ѩj).toNat=(ri+0)*O+j:=by obtain ⟨b1,b2⟩:=bk 0 ו have a0:(ri+0)*O=ri*O:=by rw[Ἵ] rw[qAf _ _ (by rw[hob,e0];(clear hR hob hj eo b2;(clear e0;exact omS321 hN b1 a0))),hob,e0];(clear hN hR hob hj e0 eo b1 b2;omega) have u1:(ob+(ѩO+ѩj)).toNat=(ri+1)*O+j:=by obtain ⟨b1,b2⟩:=bk 1 (by norm_num1) have a1:(ri+1)*O=ri*O+O:=by rw[ὰ,Ὑ] have i1:(ѩO+ѩj).toNat=O+j:=by rw[qAf _ _ (by rw[eo,e0];(clear hN hR hob hj b1 a1;(clear e0 eo;exact omS322 b2))),eo,e0] rw[qAf _ _ (by rw[i1,hob];(clear hR hob hj b2 i1;(clear e0 eo;exact omS320 hN b1 a1))),i1,hob];(clear hN hR hob hj e0 u0 b1 b2 i1;(clear eo;omega)) have I0:=qAk hN H u0 (bk 0 ו).1 rfl have I1:=qAk hN I0 u1 (bk 1 (by norm_num1)).1 rfl have I2:=qAk hN I1 (pk 2 2 (by norm_num1) (uk 2 (by norm_num1))) (bk 2 (by norm_num1)).1 rfl have I3:=qAk hN I2 (pk 3 3 (by norm_num1) (uk 3 (by norm_num1))) (bk 3 (by norm_num1)).1 rfl have I4:=qAk hN I3 (pk 4 4 (by norm_num1) (uk 4 (by norm_num1))) (bk 4 (by norm_num1)).1 rfl have I5:=qAk hN I4 (pk 5 5 (by norm_num1) (uk 5 (by norm_num1))) (bk 5 (by norm_num1)).1 rfl have I6:=qAk hN I5 (pk 6 6 (by norm_num1) (uk 6 (by norm_num1))) (bk 6 (by norm_num1)).1 rfl have I7:=qAk hN I6 (pk 7 7 (by norm_num1) (uk 7 (by norm_num1))) (bk 7 (by norm_num1)).1 rfl exact qA5 I7 (λq _ hq'=>qF4o hj hq') set_option maxHeartbeats 1000000 in set_option maxRecDepth 8000 in lemma qZ8o (oT:TOK 0 T hv) {Y:Ὡ} {d:H8} {R ri:Ὣ} {ob:ὦ} (hob:Ѥob=ri*O) (hR:ri+8<=R) (hW:O*I=ѧW) (pi:0 |Submission.D.R (dv b[j]!)| <=Submission.D.R bm) (bb:Submission.D.R bm<=2^(290:ℤ)) (hth:∀r,r<8->C_lo th r=loOf (nfOf I*(dv hv*C_hf d r+bm))) (k:Ὣ): ∀(j:Ὣ) (out:ё) (q:ὥ) (r0:F8),j+k=O->(cols8Zo T hT hv I O Y X W b d (nfOf I) ѩI ri ob j out q th r0).ok=true-> 0x7FFFFF<=q/\(∀j',j<=j'->j'∀s,sgood W[j'*I+s]! =true/\W[j'*I+s]!&&&В<=hv)/\ ∀(G:C_G R I O X W b),C_D8o X ri I I d->C_Inv (R*O) (C_sp I O Y X W b) (C_B ri O j) out-> C_Inv (R*O) (C_sp I O Y X W b) (C_B ri O O) (cols8Zo T hT hv I O Y X W b d (nfOf I) ѩI ri ob j out q th r0).out:=by have hnm:I.toUSize.toNat=I:=qAd _ (by exact Nat.lt_of_lt_of_le ‹_› ה) have hO:O<2^32:=by have:=Ὄ O pi (clear hob hR pi ni hd hnm;omega) have W1:∀j,j<=O->(ѩj*ѩI).toNat=j*I:=λj hj=>by have h1:j*I<=O*I:=Ἒ _ hj rw[qBa _ _ (by rw[qAd _ (by exact Nat.lt_of_le_of_lt ‹_› ‹_›),hnm];(clear hob hR pi ni hd hnm hO hj;exact omS323 hW sW h1)),qAd _ (by exact Nat.lt_of_le_of_lt ‹_› ‹_›),hnm] induction k with | zero=> intro j out q r0 he ok rw[cols8Zo,ἔ (by clear hob hR hW pi ni sW hd hnm hO;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))))] at ok⊢ have e:j=O:=(by exact omS155 he) rw[e] exact ⟨of_decide_eq_true ok,λj' a b'=>by (clear hob hR hW pi ni sW hd hnm hO e;(clear he;omega)),λ_ _ H=>H⟩ | succ k ih=> intro j out q r0 he ok have hj:jW[j*I+k]!) (λk _=>by rw[w1]) I 0 (ὴ 1) hi0 0 0 0 0 0 0 0 0 q r0 (by rw[hnm,C_z,Ἇ]) rw[C_z,<-ὗ] at key kq rw[cols8Zo,Ἄ hj] at ok⊢ dsimp only at ok⊢ rw[Ἄ ⟨hx,by (exact Nat.le_of_lt_succ ‹_›),by (exact Nat.le_of_lt_succ ‹_›),hg⟩] at ok⊢ generalize go8Z T hT d.xs W (ѩj*ѩI) ѩI 0 (ὴ 1) hx hsx sW hg hi0 0 0 0 0 0 0 0 0 q r0=RR at key kq ok⊢ by_cases c':okF (RR.s0+RR.s1+RR.s2+RR.s3+RR.s4+RR.s5+RR.s6+RR.s7)=true . rw[ἱ c'] at ok⊢ have c:=finSub _ c' have F:=qS8 RR c have Ks:∀r,r<8->C_fs RR r=N_ff (λs=>d.xs.data[8*s+1+r]!*dvN T hT W[j*I+s]!) (ἄ I) 0:=λr hr=>by have k1:=key r hr have e1:C_fs ⟨0,0,0,0,0,0,0,0,0,0,0⟩ r=0:=by interval_cases r<;>rfl rw[e1] at k1 exact k1 have Zs:=λ(r:Ὣ) (hr:r<8)=>qZn oT (λs=>d.xs.data[8*s+1+r]!) (λs=>W[j*I+s]!) (ἄ I) (by have f:=F r hr;rw[Ks r hr] at f;exact f) obtain ⟨q1,IH,-⟩:=ih (j+1) _ _ _ (by clear hob hR hW pi ni sW hd hnm hO hj hlt w1 hg hx hsx hi0 kq;exact omS137 he) ok rw[kq] at q1 obtain ⟨q2,q3⟩:=qZm (λs=>W[j*I+s]!) (ἄ I) q q1 refine ⟨q2,λj' a b' s hs=>?_,λG D H=>?_⟩ . by_cases e:j'=j . rw[e];exact ⟨qZg (qTb oT) ((Zs 0 ה).1 s (Ἅ.2 hs)) (q3 s (Ἅ.2 hs)),(Zs 0 ה).1 s (Ἅ.2 hs)⟩ . exact IH j' (by clear hob hR hW pi ni sW hd hnm hO he hj hlt w1 hg hx hsx hi0 kq q1 q2 b' hs;exact omS138 a e) b' s hs . have hbs:=G.sb have e0:j.toUSize.toNat=j:=qAd _ (by clear hob hR hW pi ni sW hd hnm hj hlt w1 hg hx hsx hi0 kq q1 q2 hbs;exact omS324 hO he) have hN:R*O<2^32:=G.sO have hOR:O<=R*O:=Nat.le_mul_of_pos_left O (by (clear hob hW pi ni sW hd hnm hO he hj hlt w1 hg hx hsx hi0 kq q1 q2 hbs e0 hN;exact omS325 hR)) have gv:=(qTg oT).1 have hv1:=(qTg oT).2 have O':∀r,r<8->(if fin1 (C_lo th r) (spOf (C_lo th r)) (C_fs RR r+dv b[j]!)==Е then fin8 I Y X W b (ri+r) j (C_fs RR r) (nfOf I) (C_hf d r) hv b[j]! ѩI else fz Y (fin1 (C_lo th r) (spOf (C_lo th r)) (C_fs RR r+dv b[j]!)))=C_sp I O Y X W b ((ri+r)*O+j):=by intro r hr have hl:=hth r hr rw[qCi _ _ _ _ _ _ hj,D.2.2 r hr] rw[D.2.2 r hr] at hl obtain ⟨z1,z2⟩:=Zs r hr exact qDuF G Y (by (clear hob hW pi ni sW hd hnm hO he hj hlt w1 hg hx hsx hi0 kq q1 q2 hbs e0 hN hOR hv1;exact omS326 hR hr):ri+rz1 t (Ἅ.2 ht)) (ἄ I) Ὂ (λt h=>Ἅ.1 h) (λt ht hn=>absurd (Ἅ.2 ht) hn) ((Ks r hr).trans (z2.trans (List.foldl_ext _ _ _ λacc t ht=>by show acc+d.xs.data[8*t+1+r]!*_=_ rw[D.2.1 t r (Ἅ.1 ht) hr]))) bm fbm (hbm j hj) bb _ hl have o0:(if fin1 th.l0 (spOf th.l0) (RR.s0+dv b[j]!)==Е then fin8 I Y X W b (ri+0) j RR.s0 (nfOf I) d.h0 hv b[j]! ѩI else fz Y (fin1 th.l0 (spOf th.l0) (RR.s0+dv b[j]!)))=_:=O' 0 ה have o1:(if fin1 th.l1 (spOf th.l1) (RR.s1+dv b[j]!)==Е then fin8 I Y X W b (ri+1) j RR.s1 (nfOf I) d.h1 hv b[j]! ѩI else fz Y (fin1 th.l1 (spOf th.l1) (RR.s1+dv b[j]!)))=_:=O' 1 ה have o2:(if fin1 th.l2 (spOf th.l2) (RR.s2+dv b[j]!)==Е then fin8 I Y X W b (ri+2) j RR.s2 (nfOf I) d.h2 hv b[j]! ѩI else fz Y (fin1 th.l2 (spOf th.l2) (RR.s2+dv b[j]!)))=_:=O' 2 ה have o3:(if fin1 th.l3 (spOf th.l3) (RR.s3+dv b[j]!)==Е then fin8 I Y X W b (ri+3) j RR.s3 (nfOf I) d.h3 hv b[j]! ѩI else fz Y (fin1 th.l3 (spOf th.l3) (RR.s3+dv b[j]!)))=_:=O' 3 ה have o4:(if fin1 th.l4 (spOf th.l4) (RR.s4+dv b[j]!)==Е then fin8 I Y X W b (ri+4) j RR.s4 (nfOf I) d.h4 hv b[j]! ѩI else fz Y (fin1 th.l4 (spOf th.l4) (RR.s4+dv b[j]!)))=_:=O' 4 ה have o5:(if fin1 th.l5 (spOf th.l5) (RR.s5+dv b[j]!)==Е then fin8 I Y X W b (ri+5) j RR.s5 (nfOf I) d.h5 hv b[j]! ѩI else fz Y (fin1 th.l5 (spOf th.l5) (RR.s5+dv b[j]!)))=_:=O' 5 ה have o6:(if fin1 th.l6 (spOf th.l6) (RR.s6+dv b[j]!)==Е then fin8 I Y X W b (ri+6) j RR.s6 (nfOf I) d.h6 hv b[j]! ѩI else fz Y (fin1 th.l6 (spOf th.l6) (RR.s6+dv b[j]!)))=_:=O' 6 ה have o7:(if fin1 th.l7 (spOf th.l7) (RR.s7+dv b[j]!)==Е then fin8 I Y X W b (ri+7) j RR.s7 (nfOf I) d.h7 hv b[j]! ѩI else fz Y (fin1 th.l7 (spOf th.l7) (RR.s7+dv b[j]!)))=_:=O' 7 (by exact Nat.le_refl _) simp only[qAg _ _ hbs,e0,o0,o1,o2,o3,o4,o5,o6,o7] at ok⊢ exact (ih (j+1) _ _ _ (by clear hob hR hW pi ni sW hd hnm hO hj hlt w1 hg hx hsx hi0 kq q1 q2 hbs e0 hN hOR hv1 o0 o1 o2 o3 o4 o5 o6 o7;exact omS137 he) ok).2.2 G D (qW9o hN (Ἒ O hR) hob hj H) . rw[ἐ c'] at ok;exact absurd ok ג end section open Float.Model Float.Model.UnpackedFloat lemma d8ix {o n t c:ὦ} {k:Ὣ} (hc:Ѥc=k) (hb:Ѥo+(k*Ѥn+Ѥt)<2^32): Ѥ(o+(c*n+t))=Ѥo+(k*Ѥn+Ѥt):=by rw[qAf _ _ (by rw[qB3 hc א];exact hb),qB3 hc א] lemma d8rd {X:ѐ} {o n t c:ὦ} {k:Ὣ} (hc:Ѥc=k) (hb1:Ѥo+(k*Ѥn+Ѥt)< ѧX) (hb2:Ѥo+(k*Ѥn+Ѥt)<2^32): Ѥ(o+(c*n+t))< ѧX:=by rw[d8ix hc hb2];exact hb1 local instance ecNe10:Nonempty H8:=⟨by constructor <;> exact default⟩ lemma d8b {o n t:ὦ} {N:Ὣ} (k:Ὣ) (hk:k<8) (h:Ѥt<Ѥn) (hx:Ѥo+8*Ѥn<=N): Ѥo+(k*Ѥn+Ѥt)dec8oI X o n t xs h0 h1 h2 h3 h4 h5 h6 h7 hx hs=dec8o X o n t xs h0 h1 h2 h3 h4 h5 h6 h7:=by induction d with | zero=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 e rw[dec8oI,dec8o,ἔ (by rw[А];exact omS404 e),ἔ (by rw[А];exact omS404 e)] | succ d ih=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 e have ht:t have K:=mK1 hk have ht:=А.mp K.1 have hu:=А.mp K.2.1 have hj:(i+ὴ 8).toNat=8*(t+1).toNat+1:=mI8 hx hsx hi K.1 let v:=D.uget (wo+t) (hd▸wi wo t n W hw hs ht) let u:=D.uget (wo'+t) (hd▸wi wo' t n W hw' hs ht) let v':=D.uget (wo+(t+1)) (hd▸wi wo (t+1) n W hw hs hu) let u':=D.uget (wo'+(t+1)) (hd▸wi wo' (t+1) n W hw' hs hu) let x0:=xs.uget (i+ὴ 0) (xi xs i t n 0 (by decide) ht hi hx hsx) let x1:=xs.uget (i+ὴ 1) (xi xs i t n 1 (by decide) ht hi hx hsx) let x2:=xs.uget (i+ὴ 2) (xi xs i t n 2 (by decide) ht hi hx hsx) let x3:=xs.uget (i+ὴ 3) (xi xs i t n 3 (by decide) ht hi hx hsx) let x4:=xs.uget (i+ὴ 4) (xi xs i t n 4 (by decide) ht hi hx hsx) let x5:=xs.uget (i+ὴ 5) (xi xs i t n 5 (by decide) ht hi hx hsx) let x6:=xs.uget (i+ὴ 6) (xi xs i t n 6 (by decide) ht hi hx hsx) let x7:=xs.uget (i+ὴ 7) (xi xs i t n 7 (by decide) ht hi hx hsx) let y0:=xs.uget (i+ὴ 8+ὴ 0) (xi xs (i+ὴ 8) (t+1) n 0 (by decide) hu hj hx hsx) let y1:=xs.uget (i+ὴ 8+ὴ 1) (xi xs (i+ὴ 8) (t+1) n 1 (by decide) hu hj hx hsx) let y2:=xs.uget (i+ὴ 8+ὴ 2) (xi xs (i+ὴ 8) (t+1) n 2 (by decide) hu hj hx hsx) let y3:=xs.uget (i+ὴ 8+ὴ 3) (xi xs (i+ὴ 8) (t+1) n 3 (by decide) hu hj hx hsx) let y4:=xs.uget (i+ὴ 8+ὴ 4) (xi xs (i+ὴ 8) (t+1) n 4 (by decide) hu hj hx hsx) let y5:=xs.uget (i+ὴ 8+ὴ 5) (xi xs (i+ὴ 8) (t+1) n 5 (by decide) hu hj hx hsx) let y6:=xs.uget (i+ὴ 8+ὴ 6) (xi xs (i+ὴ 8) (t+1) n 6 (by decide) hu hj hx hsx) let y7:=xs.uget (i+ὴ 8+ὴ 7) (xi xs (i+ὴ 8) (t+1) n 7 (by decide) hu hj hx hsx) go2B D xs W hd wo wo' n hx hsx hs hw hw' k (t+1+1) (i+ὴ 8+ὴ 8) (mI8 hx hsx hj K.2.1) K.2.2 (Float.fma y0 v' (Float.fma x0 v s0)) (Float.fma y1 v' (Float.fma x1 v s1)) (Float.fma y2 v' (Float.fma x2 v s2)) (Float.fma y3 v' (Float.fma x3 v s3)) (Float.fma y4 v' (Float.fma x4 v s4)) (Float.fma y5 v' (Float.fma x5 v s5)) (Float.fma y6 v' (Float.fma x6 v s6)) (Float.fma y7 v' (Float.fma x7 v s7)) (Float.fma y0 u' (Float.fma x0 u t0)) (Float.fma y1 u' (Float.fma x1 u t1)) (Float.fma y2 u' (Float.fma x2 u t2)) (Float.fma y3 u' (Float.fma x3 u t3)) (Float.fma y4 u' (Float.fma x4 u t4)) (Float.fma y5 u' (Float.fma x5 u t5)) (Float.fma y6 u' (Float.fma x6 u t6)) (Float.fma y7 u' (Float.fma x7 u t7)) r | 0,_=> if h2:t (go8ZD D xs W hd wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q r).u=r.u/\(go8ZD D xs W hd wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q r).p=0/\(go8ZD D xs W hd wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q r).q=q:=by induction d with | zero=> intro t i hi s0 s1 s2 s3 s4 s5 s6 s7 he rw[go8ZD,ἔ (by rw[А];exact omS411 he)];cases r;exact ⟨rfl,rfl,rfl⟩ | succ d ih=> intro t i hi s0 s1 s2 s3 s4 s5 s6 s7 he have ht:tk< Ѥn->∃w,xs.data[8*k+1+r]! =dv w) (HD:∀k,k< ѨD->FSa D.data[k]!) (q:ὥ) (r r':F8) (R:F16) (m:Ὣ): ∀(t i:ὦ) (hi:Ѥi=8*Ѥt+1) (hk:2*m+Ѥt<=Ѥn/\Ѥn<=2*m+Ѥt+1) (s0 s1 s2 s3 s4 s5 s6 s7 t0 t1 t2 t3 t4 t5 t6 t7:ὧ), go2B D xs W hd wo wo' n hx hsx hs hw hw' m t i hi hk s0 s1 s2 s3 s4 s5 s6 s7 t0 t1 t2 t3 t4 t5 t6 t7 R= F16of R.u (go8ZD D xs W hd wo n t i hx hsx hs hw hi s0 s1 s2 s3 s4 s5 s6 s7 q r) (go8ZD D xs W hd wo' n t i hx hsx hs hw' hi t0 t1 t2 t3 t4 t5 t6 t7 q r'):=by induction m with | zero=> intro t i hi hk s0 s1 s2 s3 s4 s5 s6 s7 t0 t1 t2 t3 t4 t5 t6 t7 by_cases h2:tqBq (xf:=λr k=>xs.data[8*k+1+r]!) (λ_ _ _ _=>rfl) hi htn hsx hx k hk have X:=λ(r:Ὣ) (hr:r<8)=>mXF (HX r _ hr htn) have hv:FSa (D.uget (wo+t) (hd▸wi wo t n W hw hs htn)):=by rw[qC5];exact HD _ (hd▸wi wo t n W hw hs htn) have hu0:FSa (D.uget (wo'+t) (hd▸wi wo' t n W hw' hs htn)):=by rw[qC5];exact HD _ (hd▸wi wo' t n W hw' hs htn) simp only[mgB0,go8ZD.eq_1 D xs W hd wo n t,go8ZD.eq_1 D xs W hd wo' n t,go8ZD.eq_1 D xs W hd wo n (t+1),go8ZD.eq_1 D xs W hd wo' n (t+1),Ἄ h2,ἔ hn,B 0 ה,B 1 ה,B 2 ה,B 3 ה,B 4 ה,B 5 ה,B 6 ה,B 7 ה,X 0 ה _ hv,X 0 ה _ hu0,X 1 ה _ hv,X 1 ה _ hu0,X 2 ה _ hv,X 2 ה _ hu0,X 3 ה _ hv,X 3 ה _ hu0,X 4 ה _ hv,X 4 ה _ hu0,X 5 ה _ hv,X 5 ה _ hu0,X 6 ה _ hv,X 6 ה _ hu0,X 7 ה _ hv,X 7 ה _ hu0] cases R;cases r;cases r';rfl . simp only[mgB0,go8ZD.eq_1 D xs W hd wo n t,go8ZD.eq_1 D xs W hd wo' n t,ἔ h2] cases R;cases r;cases r';rfl | succ m ih=> intro t i hi hk s0 s1 s2 s3 s4 s5 s6 s7 t0 t1 t2 t3 t4 t5 t6 t7 have K:=mK1 hk have htn:=А.mp K.1 have hu:=А.mp K.2.1 have hj:=mI8 hx hsx hi K.1 have B:=λ(k:Ὣ) (hk:k<8)=>qBq (xf:=λr k=>xs.data[8*k+1+r]!) (λ_ _ _ _=>rfl) hi htn hsx hx k hk have B':=λ(k:Ὣ) (hk:k<8)=>qBq (xf:=λr k=>xs.data[8*k+1+r]!) (λ_ _ _ _=>rfl) hj hu hsx hx k hk have X:=λ(r:Ὣ) (hr:r<8)=>mXF (HX r _ hr htn) have Y:=λ(r:Ὣ) (hr:r<8)=>mXF (HX r _ hr hu) have hv:FSa (D.uget (wo+t) (hd▸wi wo t n W hw hs htn)):=by rw[qC5];exact HD _ (hd▸wi wo t n W hw hs htn) have hu0:FSa (D.uget (wo'+t) (hd▸wi wo' t n W hw' hs htn)):=by rw[qC5];exact HD _ (hd▸wi wo' t n W hw' hs htn) have hv1:FSa (D.uget (wo+(t+1)) (hd▸wi wo (t+1) n W hw hs hu)):=by rw[qC5];exact HD _ (hd▸wi wo (t+1) n W hw hs hu) have hu1:FSa (D.uget (wo'+(t+1)) (hd▸wi wo' (t+1) n W hw' hs hu)):=by rw[qC5];exact HD _ (hd▸wi wo' (t+1) n W hw' hs hu) simp only[mgB1,go8ZD.eq_1 D xs W hd wo n t,go8ZD.eq_1 D xs W hd wo' n t,go8ZD.eq_1 D xs W hd wo n (t+1),go8ZD.eq_1 D xs W hd wo' n (t+1),Ἄ K.1,Ἄ K.2.1,B 0 ה,B 1 ה,B 2 ה,B 3 ה,B 4 ה,B 5 ה,B 6 ה,B 7 ה,B' 0 ה,B' 1 ה,B' 2 ה,B' 3 ה,B' 4 ה,B' 5 ה,B' 6 ה,B' 7 ה,X 0 ה _ hv,X 0 ה _ hu0,X 1 ה _ hv,X 1 ה _ hu0,X 2 ה _ hv,X 2 ה _ hu0,X 3 ה _ hv,X 3 ה _ hu0,X 4 ה _ hv,X 4 ה _ hu0,X 5 ה _ hv,X 5 ה _ hu0,X 6 ה _ hv,X 6 ה _ hu0,X 7 ה _ hv,X 7 ה _ hu0,Y 0 ה _ hv1,Y 0 ה _ hu1,Y 1 ה _ hv1,Y 1 ה _ hu1,Y 2 ה _ hv1,Y 2 ה _ hu1,Y 3 ה _ hv1,Y 3 ה _ hu1,Y 4 ה _ hv1,Y 4 ה _ hu1,Y 5 ה _ hv1,Y 5 ה _ hu1,Y 6 ה _ hv1,Y 6 ה _ hu1,Y 7 ה _ hv1,Y 7 ה _ hu1] exact ih (t+1+1) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ lemma mN1 (x z:Float.Model.UnpackedFloat):Float.Model.UnpackedFloat.fma ⟠ x .notANumber z= .notANumber:=by cases x<;>cases z<;>rfl lemma mN2 (x:Float.Model.UnpackedFloat):Float.Model.UnpackedFloat.add ⟠ x .notANumber= .notANumber:=by cases x<;>rfl lemma mNp:Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ .notANumber)=.notANumber:=rfl lemma mN3 (x:Float.Model.UnpackedFloat):Float.Model.UnpackedFloat.mul ⟠ x .notANumber= .notANumber:=by cases x<;>rfl lemma mFN (v:ὧ) (h:v.toModel.unpack=.notANumber):FSa v:=by intro u a show Float.ofModel (Float.Model.fma (dv u).toModel v.toModel a.toModel)=Float.ofModel (Float.Model.add a.toModel (Float.Model.mul (dv u).toModel v.toModel)) have hP:(Float.Model.mul (dv u).toModel v.toModel).unpack=Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ (Float.Model.UnpackedFloat.mul ⟠ (dv u).toModel.unpack v.toModel.unpack)):=rfl unfold Float.Model.fma Float.Model.add rw[hP,h,mN1,mN3,mNp,mN2] lemma mNb:(Ἃ 0x7FF8000000000000).toModel.unpack=.notANumber:=rfl lemma mNm (x y:ὧ) (h:y.toModel.unpack=.notANumber):(x*y).toModel.unpack=.notANumber:=by have hP:(x*y).toModel.unpack=Ἶ ⟠ (Float.Model.UnpackedFloat.pack ⟠ (Float.Model.UnpackedFloat.mul ⟠ x.toModel.unpack y.toModel.unpack)):=rfl rw[hP,h,mN3];rfl lemma mFS {T:ὤ} {h:ὥ} (hT:ѨT=512) (o:TOK 0 T h) (w:ὥ):FSa (dvN T hT w):=by obtain ⟨k,-,hu,-⟩:=o have ei:((w>>>(23:ὥ)).toUSize).toNat=ѥw/2^23:=by simp only[ὃ,UInt32.toNat_shiftRight,Ἱ];rfl unfold dvN;rw[hu,ei] unfold pwEntryN;split . exact mFN _ (mNm _ _ mNb) . have e:dv w=A_mf w*pwEntry (ѥw/2^23):=by unfold dv;rw[(qD1 w).1] rw[<-e];exact λu a=>zFV u w a lemma mFD {T:ὤ} {h:ὥ} (hT:ѨT=512) (o:TOK 0 T h) (W:ѐ):∀k,k< Ѩ(dnOf T hT W)->FSa (dnOf T hT W).data[k]!:=by intro k hk have hk':k< ѧW:=by simpa only[FloatArray.size,dnOf,Array.size_map] using hk have:(dnOf T hT W).data[k]! =dvN T hT W[k]!:=by simp only[dnOf,Array.size_map,hk',Ἕ,Array.getElem_map] rw[this];exact mFS hT o _ lemma mGdv (X:ѐ) (o n:ὦ) (d:Ὣ): ∀(t:ὦ) (xs:ὤ) (h0 h1 h2 h3 h4 h5 h6 h7:ὧ),Ѥt+d=Ѥn-> Ѩxs<2^32->8*Ѥn+1<=Ѩxs-> (∀r k:Ὣ,r<8->k< Ѥt->∃w,xs.data[8*k+1+r]! =dv w)-> ∀r k:Ὣ,r<8->k< Ѥn->∃w,(dec8o X o n t xs h0 h1 h2 h3 h4 h5 h6 h7).xs.data[8*k+1+r]! =dv w:=by induction d with | zero=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 he _ _ H rw[dec8o,ἔ (by rw[А];exact omS404 he)] have e:Ѥt=Ѥn:=by exact omS155 he rw[e] at H;exact H | succ d ih=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 he hs hb H have ht:tsimp only[add_zero,Nat.left_eq_add,OfNat.ofNat_ne_zero, ↓reduceIte,one_ne_zero,Nat.add_left_cancel_iff,zero_mul,zero_add,exists_apply_eq_apply',OfNat.one_ne_ofNat,one_mul,Nat.reduceEqDiff] . have hk':k< Ѥt:=א have hlt:8*k+1+r<8*Ѥt+1:=א rw[ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _))),ἐ (Nat.ne_of_lt (hlt.trans_le (Nat.le_add_right _ _)))];exact H r k hr hk' @[inline] def mwc8 (hv:ὥ) (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (d:H8) (nf:ὧ) (n:ὦ) (ri:Ὣ) (ob:ὦ) (j:Ὣ) (out:ѐ) (th:L8) (s0 s1 s2 s3 s4 s5 s6 s7:ὧ):ѐ:= let ju:=ѩj let bw:=rdW b ju let ow:=ѩoutW let bv:=dv bw let t0:=fin1 th.l0 (spOf th.l0) (s0+bv) let out:=wrW out (ob+ju) (if t0==Е then fin8o inW relu X W b ri 0 j s0 nf d.h0 hv bw n else fz relu t0) let t1:=fin1 th.l1 (spOf th.l1) (s1+bv) let out:=wrW out (ob+(ow+ju)) (if t1==Е then fin8o inW relu X W b ri 1 j s1 nf d.h1 hv bw n else fz relu t1) let t2:=fin1 th.l2 (spOf th.l2) (s2+bv) let out:=wrW out (ob+(2*ow+ju)) (if t2==Е then fin8o inW relu X W b ri 2 j s2 nf d.h2 hv bw n else fz relu t2) let t3:=fin1 th.l3 (spOf th.l3) (s3+bv) let out:=wrW out (ob+(3*ow+ju)) (if t3==Е then fin8o inW relu X W b ri 3 j s3 nf d.h3 hv bw n else fz relu t3) let t4:=fin1 th.l4 (spOf th.l4) (s4+bv) let out:=wrW out (ob+(4*ow+ju)) (if t4==Е then fin8o inW relu X W b ri 4 j s4 nf d.h4 hv bw n else fz relu t4) let t5:=fin1 th.l5 (spOf th.l5) (s5+bv) let out:=wrW out (ob+(5*ow+ju)) (if t5==Е then fin8o inW relu X W b ri 5 j s5 nf d.h5 hv bw n else fz relu t5) let t6:=fin1 th.l6 (spOf th.l6) (s6+bv) let out:=wrW out (ob+(6*ow+ju)) (if t6==Е then fin8o inW relu X W b ri 6 j s6 nf d.h6 hv bw n else fz relu t6) let t7:=fin1 th.l7 (spOf th.l7) (s7+bv) let out:=wrW out (ob+(7*ow+ju)) (if t7==Е then fin8o inW relu X W b ri 7 j s7 nf d.h7 hv bw n else fz relu t7) out lemma mPh {ph:Ὡ} {P:Prop} (hc:ph=true\/P) (hp:¬ph=true):P:=hc.resolve_left hp @[inline] def F8x (r:F8) (s0 s1 s2 s3 s4 s5 s6 s7:ὧ) (q:ὥ):F8:=⟨r.u,s0,s1,s2,s3,s4,s5,s6,s7,0,q⟩ def cols8ZD2 (D:ὤ) (hv:ὥ) (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (hd:ѨD=ѧW) (d:H8) (nf:ὧ) (n:ὦ) (ri:Ὣ) (ob:ὦ) (q:ὥ) (th:L8):Ὣ->Ὣ->ѐ->F8->F16->Ὡ->CN | 0,j,out,r0,_,_=>cols8ZDo D hv inW outW relu X W b hd d nf n ri ob j out q th r0 | k+1,j,out,r0,R,ph=> if hc:ph=true\/(j+1d.xs.size<=4294967295->∀r k:Ὣ,r<8->k< Ѥn->∃w,d.xs.data[8*k+1+r]! =dv w) (HD:∀k,k< ѨD->FSa D.data[k]!) (m:Ὣ): ∀(j:Ὣ) (out:ѐ) (r0:F8) (R:F16) (ph:Ὡ),(ph=true->∃(hj:j cols8ZD2 D hv inW outW relu X W b hd d nf n ri ob q th m j out r0 R ph=cols8ZDo D hv inW outW relu X W b hd d nf n ri ob j out q th r0:=by induction m with | zero=>intro j out r0 R ph _;rfl | succ m ih=> intro j out r0 R ph I rw[cols8ZD2] cases ph . by_cases hc:j+1⟨hc.1,hg',hi0,by rw[hR2];exact ⟨rfl,rfl,rfl,rfl,rfl,rfl,rfl,rfl⟩⟩)] rfl . rw[ἔ (by simp only[Bool.false_eq_true,false_or];exact hc)] . obtain ⟨hj,hg,hi0,F⟩:=I rfl rw[Ἄ (Or.inl rfl)] simp only[↓reduceDIte,↓reduceIte,Bool.not_true] have u1:=mgZu D d.xs W hd (ѩj*n) n hg.1 (qA9 hg.2.1) (qA9 hg.2.2.1) hg.2.2.2 q r0 _ 0 (ὴ 1) hi0 0 0 0 0 0 0 0 0 rfl generalize hR1:go8ZD D d.xs W hd (ѩj*n) n 0 (ὴ 1) hg.1 (qA9 hg.2.1) (qA9 hg.2.2.1) hg.2.2.2 hi0 0 0 0 0 0 0 0 0 q r0=R1 at u1 F obtain ⟨f0,f1,f2,f3,f4,f5,f6,f7⟩:=F rw[mZo1 D hv inW outW relu X W b hd d nf n ri ob q th j out r0 R1 hj hg hi0 hR1,f0,f1,f2,f3,f4,f5,f6,f7,mF8x r0 R1 q u1.1 u1.2.1 u1.2.2,ih (j+1) _ R1 _ false (λh=>absurd h ה)] lemma mGsz (X:ѐ) (o n:ὦ) (d:Ὣ): ∀(t:ὦ) (xs:ὤ) (h0 h1 h2 h3 h4 h5 h6 h7:ὧ),Ѥn-Ѥt=d->(dec8o X o n t xs h0 h1 h2 h3 h4 h5 h6 h7).xs.size=Ѩxs:=by induction d with | zero=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 he rw[dec8o,ἔ (by rw[А];exact omS411 he)] | succ d ih=> intro t xs h0 h1 h2 h3 h4 h5 h6 h7 he have ht:td.xs.size<=4294967295->∀r k:Ὣ,r<8->k< Ѥn->∃w,d.xs.data[8*k+1+r]! =dv w) (HD:∀k,k< ѨD->FSa D.data[k]!): cols8ZDA D hv inW outW relu X W b hd d nf n ri ob j out q th r0=cols8ZDo D hv inW outW relu X W b hd d nf n ri ob j out q th r0:=by unfold cols8ZDA;split . exact mc2E D hv inW outW relu X W b hd d nf n ri ob q th HX HD _ j out r0 _ false (λh=>absurd h ה) . rfl lemma mGX (X:ѐ) (o n:ὦ) (xs:ὤ):8*Ѥn+1<=(dec8o X o n 0 xs 0 0 0 0 0 0 0 0).xs.size->(dec8o X o n 0 xs 0 0 0 0 0 0 0 0).xs.size<=4294967295-> ∀r k:Ὣ,r<8->k< Ѥn->∃w,(dec8o X o n 0 xs 0 0 0 0 0 0 0 0).xs.data[8*k+1+r]! =dv w:=by have e:=mGsz X o n Ѥn 0 xs 0 0 0 0 0 0 0 0 (by rw[C_z,Nat.sub_zero]) rw[e];intro h8 h9 exact mGdv X o n Ѥn 0 xs 0 0 0 0 0 0 0 0 (by rw[C_z,Ἇ]) א h8 (λr k _ hk=>absurd hk (by rw[C_z];exact Ἲ _)) lemma qZsh (W:ѐ) (c N:Ὣ):∀(a:Ὣ) (q:ὥ),(List.range' a N).foldl (λ(q:ὥ) (s:Ὣ)=>q&&&((W[c+s]!&&&В)-1)) q=(List.range' (c+a) N).foldl (λ(q:ὥ) (s:Ὣ)=>q&&&((W[s]!&&&В)-1)) q:=by induction N with | zero=>intro a q;rfl | succ N ih=>intro a q;rw[List.range'_succ,List.range'_succ,ὔ,ὔ,ih (a+1),show c+(a+1)=c+a+1 by exact omS329] lemma qZsp (W:ѐ) (m N:Ὣ):∀(s:Ὣ) (q:ὥ),(List.range' s (m+N)).foldl (λ(q:ὥ) (s:Ὣ)=>q&&&((W[s]!&&&В)-1)) q=(List.range' (s+m) N).foldl (λ(q:ὥ) (s:Ὣ)=>q&&&((W[s]!&&&В)-1)) ((List.range' s m).foldl (λ(q:ὥ) (s:Ὣ)=>q&&&((W[s]!&&&В)-1)) q):=by induction m with | zero=>intro s q;rw[Ἇ,Ἵ];rfl | succ m ih=>intro s q;rw[show m+1+N=(m+N)+1 by exact omS330,List.range'_succ,List.range'_succ,ὔ,ὔ,ih (s+1),show s+1+m=s+(m+1) by exact omS146] lemma qScanE (W:ѐ) (hs:ѧW<2^32) (d:Ὣ):∀(i:ὦ) (q:ὥ),Ѥi+d=ѧW->qScan W W.usize i q=(List.range' Ѥi d).foldl (λ(q:ὥ) (s:Ὣ)=>q&&&((W[s]!&&&В)-1)) q:=by have hu:W.usize.toNat=ѧW:=qBe _ hs induction d with | zero=>intro i q e;rw[qScan,ἔ (by rw[А,hu];(clear hs;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))];rfl | succ d ih=> intro i q e have hi:i cols8ZDo (dnOf T hT W) hv inW outW relu X W b hd d nf n ri ob j out ((List.range' (j*inW) (k*inW)).foldl (λ(q:ὥ) (s:Ὣ)=>q&&&((W[s]!&&&В)-1)) q) th r0'=cols8Zo T hT hv inW outW relu X W b d nf n ri ob j out q th r0:=by have hO:outW<2^32:=by have:=Ὄ outW pi;(clear hn pi;omega) have W1:∀j,j<=outW->(ѩj*n).toNat=j*inW:=λj hj=>by have h1:j*inW<=outW*inW:=Ἒ _ hj rw[qBa _ _ (by rw[qAd _ (by (exact Nat.lt_of_le_of_lt ‹_› ‹_›)),hn];(clear hn pi hO hj;exact omS323 hW hs h1)),qAd _ (by (exact Nat.lt_of_le_of_lt ‹_› ‹_›)),hn] induction k with | zero=> intro j out q r0 r0' e rw[cols8ZDo,cols8Zo,ἔ (by (clear hd hn hW hs pi hO;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))))),ἔ (by (clear hd hn hW hs pi hO;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))))),ὒ] rfl | succ k ih=> intro j out q r0 r0' e have hj:jW[j*inW+k]!) (λk _=>by rw[W1 j hj.le]) Ѥn 0 (ὴ 1) hi0 0 0 0 0 0 0 0 0 q r0 (by rw[C_z,Ἇ])).2 generalize go8Z T hT d.xs W (ѩj*n) n 0 (ὴ 1) hg.1 (qA9 hg.2.1) (qA9 hg.2.2.1) hg.2.2.2 hi0 0 0 0 0 0 0 0 0 q r0=R at hq⊢ rw[C_z,hn,qZsh W (j*inW) inW 0 q,Ἵ] at hq rw[show (k+1)*inW=inW+k*inW by ring,qZsp W inW (k*inW) (j*inW) q,<-hq,show j*inW+inW=(j+1)*inW by ring] dsimp only[F8q] exact if_congr Iff.rfl (ih (j+1) _ R.q R _ (by (clear hn hW hs pi hO hj hg hi0 hq;exact omS137 e))) rfl . rw[ἔ hg,ἔ hg] lemma c8ZSo (T:ὤ) (hT:ѨT=512) (hv:ὥ) (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (d:H8) (nf:ὧ) (n:ὦ) (ri:Ὣ) (ob:ὦ) (hn:Ѥn=inW) (hW:outW*inW=ѧW) (hs:ѧW<2^32) (pi:0< inW) (out:ѐ) (th:L8) (r0:F8): (if hd:(dnOf T hT W).size=ѧW then cols8ZDo (dnOf T hT W) hv inW outW relu X W b hd d nf n ri ob 0 out (qScan W W.usize 0 Е) th r0 else cols8Zo T hT hv inW outW relu X W b d nf n ri ob 0 out Е th r0)=cols8Zo T hT hv inW outW relu X W b d nf n ri ob 0 out Е th r0:=by split . rename_i hd have e:=c8ZEo T hT hv inW outW relu X W b hd d nf n ri ob hn hW hs pi th outW 0 out Е r0 r0 (by (clear hn hW hs pi hd;(clear hT;exact omS139))) rw[ὒ] at e rw[qScanE W hs ѧW 0 Е (by rw[C_z,Ἇ]),C_z,<-hW] exact e . rfl lemma qDE (X:ѐ) (o n:ὦ) (hX:Ѥo+Ѥn<=ѧX) (hs:ѧX<2^32) (t:ὦ) (buf:ὤ) (l:ὧ) (hb:Ѥn<=Ѩbuf) (hbs:Ѩbuf<2^32): decE X o n t buf l hX hs hb=decD X o n t buf l:=by rw[decE,decD];by_cases h:tgood W[q]! =true)=> (⟨h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,(qA8 0 X h7 h11).2.2.1,A,(qA8 1 b h9 h13).2.2.1⟩:C_G rows inW outW X W b) have e:linearSpec rows inW outW relu X W b=Array.ofFn (n:=rows*outW) λq=>C_sp inW outW relu X W b q.val:=rfl;have hnf:(inW.toUInt64+8).toFloat*Ἃ 0x3CA0000000000000=nfOf inW:=rfl;rw[e,hnf];split . rename_i hr1;have e1:rows=1:=by simpa only[beq_iff_eq] using hr1 subst e1;have GX:=(qA8 0 X h7 h11).2.2.1;have sX1:0*inW+inW<=ѧX:=(by clear h2 h3 h4 h5 h6 h11 h12 h13 h7 h8 h9 h10;exact omS332 h1);have nm:inW.toUSize.toNat=inW:=qAd _ (by exact Nat.lt_of_lt_of_le ‹_› ה);have P0:=qZf inW (by (exact Nat.lt_of_lt_of_le ‹_› ה)) have H0:C_Inv (1*outW) (C_sp inW outW relu X W b) (λq=>q<0) (ἇ (1*outW) 0):=⟨by simp only[one_mul,Array.size_replicate],λq _ h=>absurd h (Ἲ _)⟩ rw[(wbGet inW outW W).2];dsimp only;split . rename_i hv;have Hv:=qA8 2 W h8 hv;have G:=G0 Hv.2.2.1;have hb0:(0*outW).toUSize.toNat=0*outW:=qAd _ (by clear h2 h3 h4 h5 h6 h11 h12 h13 h7 h8 h9 h1 h10 sX1 nm P0 hv;exact omS333);have HdE:C_Dw (ἆ 0) W:=λh q hq=>by have e:0=ѧW:=h;(clear h2 h3 h4 h5 h6 h11 h12 h13 h7 h8 h9 h1 h10 sX1 nm P0 hv hb0;(clear h;omega)) split . rename_i hok;obtain ⟨o1,o2⟩:=Bool.and_eq_true_iff.mp hok;have h8k:inW<=8192:=by simpa only[decide_eq_true_eq] using o2 obtain ⟨v1,v2,v3⟩:=qVz (a:=0*inW) (n:=ѩinW) h7 (by rw[nm];exact sX1) inW 0 (zFor inW) 0 (by rw[C_z,Ἇ,nm]) (by rw[nm];exact P0.1) P0.2 (λk hk=>absurd hk (Ἲ _)) rfl o1 rw[nm] at v2 v3 have Rd:=qRd X inW _ h8k v2 have Rw:C_Row inW X 0 idA (decD X (0*inW).toUSize ѩinW 0 (zFor inW) 0).buf ѩinW (ἄ inW) (decD X (0*inW).toUSize ѩinW 0 (zFor inW) 0).l:=⟨by rw[nm,List.length_range],by simp only[List.length_range,Std.le_refl],by rw[qIs];exact h8k,⟨by rw[v1];exact P0.1,by rw[v1];exact P0.2⟩,Ὂ,λt ht=>Ἅ.1 ht,λt ht hn=>absurd (Ἅ.2 ht) hn,Rd,v3⟩ have HI:∀k,k< Ѥ(ѩinW)->(idA[k]!).toNat=k:=λk hk=>qIA k (Nat.lt_of_lt_of_le (by rwa[nm] at hk) h8k) rw[c1VS',c1VW _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ HI (Ὗ _)] rw[c1WE _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (λj hj=>by rw[Rw.len] at hj;have hp:=List.getElem?_eq_getElem hj;exact ⟨_,G.gx ((by exact Nat.le_refl _):0<1) _ (Rw.lt _ (List.mem_of_getElem? hp)),(Rw.rd j _ hp).2⟩) HdE (by rw[nm,h2]) (by rw[h3];exact h9) (λj i k a b c d=>by rw[nm] at c⊢;exact wbP W inW outW j i k a b c d) (λho i k hi hk=>by rw[nm] at hi⊢;exact wbPt W inW outW i k ho hi hk) 0 rfl] obtain ⟨gb1,gb2,-,gb4⟩:=qA8 1 b h9 h13 obtain ⟨pb0,pb1,pb2⟩:=qCs gb1 gb2 obtain ⟨fbm,Rbm⟩:=qAm _ gb1 have hbm:∀j,j |R (dv b[j]!)| <=R (dv (scanH 1 b)):=λj hj=>by have gj:=(qA8 1 b h9 h13).2.2.1 j (by rw[<-h3];exact hj) rw[(qAm _ gj).2,Rbm];exact pb2 _ gj (gb4 j (by rw[<-h3];exact hj)) have bb:R (dv (scanH 1 b))<=2^(290:ℤ):=by rw[Rbm];exact pb1.trans (by rw[show (2:ℝ)^128=2^(128:ℤ) by norm_num];exact ἒ ב ב) refine qBv (qD0 G relu ((by exact Nat.le_refl _):0<1) Hv Rw hb0 HdE (dv (scanH 1 b)) fbm hbm bb rfl outW 0 _ (Ἇ _) (by rw[ὒ,Ἵ];exact H0)) (λq hq=>by (clear h2 h4 h5 h6 h11 h12 h13 h7 h8 h9 h1 h10 sX1 nm P0 hv hb0 h8k v1;exact omS334 hq)) . rw[qAi];rfl . rw[qAi];rfl . rw[qAi];rfl . rw[qAi];rfl end lemma bOfS (b:ѐ):Ѩ(bOf b)=ѧb:=by simp only[FloatArray.size,bOf,Array.size_map] lemma rdBOf (b:ѐ) (u:ὦ) (h:Ѥu< ѧb) (hs:ѧb<2^32):rdB (bOf b) u=dv (rdW b u):=by have h2:ucolsN2 inW outW relu X W b i ix x wd wb (bOf b) nf a hx lo (spOf lo) m n j base out=cols1V inW outW relu X W b i ix x wd wb nf a hx lo m n j base out:=by intro d;induction d using Nat.strong_induction_on with | _ d ih=> intro j out hd rw[colsN2];by_cases h16:j+16<=outW . rw[Ἄ h16];dsimp only by_cases hg:Ѥn<=Ѩx/\Ѩwb<=4294967295/\Ѥn<=Ѥm/\Ѥ(ѩj*m)+5+8*Ѥm<=Ѩwb/\Ѥ((j+8).toUSize*m)+5+8*Ѥm<=Ѩwb . rw[Ἄ hg,fNw _ _ _ _ _ _ _ _ _ _ _ j _ _ _ _ _ _ _ _ _ _ א hs,fNw _ _ _ _ _ _ _ _ _ _ _ (j+8) _ _ _ _ _ _ _ _ _ _ א hs] rw[g16D];dsimp only[g16of,fw8] rw[cols1V,Ἄ (by omega:j+8<=outW)];dsimp only;rw[Ἄ (tileG j outW m n x wb ix W א hg.1 hix hW hOW hg.2.1 hg.2.2.1 hg.2.2.2.1 hm)] rw[cols1V,Ἄ (by omega:j+8+8<=outW)];dsimp only;rw[Ἄ (tileG (j+8) outW m n x wb ix W א hg.1 hix hW hOW hg.2.1 hg.2.2.1 hg.2.2.2.2 hm)] exact ih _ א _ _ rfl . rw[ἔ hg] . rw[ἔ h16] lemma cN3W (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (i:Ὣ) (ix:ѐ) (x wd wb:ὤ) (nf a:ὧ) (hx:ὥ) (lo:Ὠ) (m n:ὦ) (base:ὦ) (hob:outW<=ѧb) (hs:ѧb<2^32) (hix:Ѥn<=ѧix) (hW:ѧW<=4294967295) (hOW:outW*Ѥm<=ѧW) (hm:0<Ѥm): ∀(d j:Ὣ) (out:ѐ),outW-j=d->colsN3 inW outW relu X W b i ix x wd wb (bOf b) nf a hx lo (spOf lo) m n j base out=cols1V inW outW relu X W b i ix x wd wb nf a hx lo m n j base out:=by intro d;induction d using Nat.strong_induction_on with | _ d ih=> intro j out hd rw[colsN3];by_cases h24:j+24<=outW . rw[Ἄ h24];dsimp only by_cases hg:Ѥn<=Ѩx/\Ѩwb<=4294967295/\Ѥn<=Ѥm/\Ѥ(ѩj*m)+5+8*Ѥm<=Ѩwb/\Ѥ((j+8).toUSize*m)+5+8*Ѥm<=Ѩwb/\Ѥ((j+8+8).toUSize*m)+5+8*Ѥm<=Ѩwb . rw[Ἄ hg,fNw _ _ _ _ _ _ _ _ _ _ _ j _ _ _ _ _ _ _ _ _ _ א hs,fNw _ _ _ _ _ _ _ _ _ _ _ (j+8) _ _ _ _ _ _ _ _ _ _ א hs,fNw _ _ _ _ _ _ _ _ _ _ _ (j+8+8) _ _ _ _ _ _ _ _ _ _ א hs] rw[g24D];dsimp only[g24of,fw8] rw[cols1V,Ἄ (by omega:j+8<=outW)];dsimp only;rw[Ἄ (tileG j outW m n x wb ix W א hg.1 hix hW hOW hg.2.1 hg.2.2.1 hg.2.2.2.1 hm)] rw[cols1V,Ἄ (by omega:j+8+8<=outW)];dsimp only;rw[Ἄ (tileG (j+8) outW m n x wb ix W א hg.1 hix hW hOW hg.2.1 hg.2.2.1 hg.2.2.2.2.1 hm)] rw[cols1V,Ἄ (by omega:j+8+8+8<=outW)];dsimp only;rw[Ἄ (tileG (j+8+8) outW m n x wb ix W א hg.1 hix hW hOW hg.2.1 hg.2.2.1 hg.2.2.2.2.2 hm)] exact ih _ א _ _ rfl . rw[ἔ hg];exact cN2W inW outW relu X W b i ix x wd wb nf a hx lo m n base hob hs hix hW hOW hm _ j out rfl . rw[ἔ h24];exact cN2W inW outW relu X W b i ix x wd wb nf a hx lo m n base hob hs hix hW hOW hm _ j out rfl lemma dVE (X:ѐ) (o n t:ὦ) (buf:ὤ) (l:ὧ) (lo hi:ὥ) (hX:Ѥo+Ѥn<=ѧX) (hs:ѧX<2^32) (hb:Ѥn<=Ѩbuf): (decV X o n t buf l lo hi hX hs hb).buf=(decE X o n t buf l hX hs hb).buf/\(decV X o n t buf l lo hi hX hs hb).l=(decE X o n t buf l hX hs hb).l:=by rw[decV,decE];by_cases h:tὧ} {p:ℕ->ℝ} {bw hh:ὥ} {X Y J:ℝ} {s t a e:ὧ} (A:n<2^20) (B:ѣts<=n) (C:A_G ts g p) (D:good bw=true) (E:X=(ts.map p).sum+wv bw) (F:s=ts.foldl (λ(c:ὧ) t=>c+g t) 0+dv bw) (G:(2:ℝ)^(-127:ℤ) ≤ |R (s+e)|) include A B C D E F G end section variable (n:Ὣ) (hn:n<2^20) (xw ww:Ὣ->ὥ) include n hn xw ww end section variable {R I O:Ὣ} {X W b:ё} section variable (G:C_G R I O X W b) (Y:Ὡ) {i j:Ὣ} (hi:i< R) (hj:j< O) include G Y i j hi hj end end section variable {Rr I O:Ὣ} {X W b:ё} end section variable {R I O:Ὣ} {X W b:ё} section variable (G:C_G R I O X W b) include G end end def zI (X:ѐ) (k:Ὣ) (buf:ὤ) (ix:ѐ) (c:ὦ) (l:ὧ):Prop:=Ѥc=ѣ(C_keep (λp=>X[p]!) k)/\(∀q p:Ὣ,(C_keep (λp=>X[p]!) k)[q]?=some p->(ix[q]!:ὥ).toNat=p/\buf.data[q]! =dv X[p]!)/\l=(C_keep (λp=>X[p]!) k).foldl (λ(a:ὧ) p=>a+(dv X[p]!).abs) 0 def zO (X:ѐ) (k b0 i0:Ὣ) (r:(ὤ×ѐ)×(ὦ×ὧ)×(ὥ×ὥ)):Prop:=Ѩr.1.1=b0/\ѧr.1.2=i0/\zI X k r.1.1 r.1.2 r.2.1.1 r.2.1.2 lemma zN1 {t d n:Ὣ} (h:t+(d+1)=n):t Ѥn<=Ѩbuf-> Ѩbuf<2^32-> Ѥn<=ѧix-> ѧix<2^32-> zI X Ѥt buf ix c l->zO X Ѥn Ѩbuf ѧix (decZ X n hX d t buf ix c l lo hi):=by induction d with | zero=> intro t buf ix c l lo hi he hb hbs hix his hI rw[decZ];rw[Ἵ] at he;rw[he] at hI;exact ⟨rfl,rfl,hI⟩ | succ d ih=> intro t buf ix c l lo hi he hb hbs hix his hI obtain ⟨hc,hr,hl⟩:=hI have h1:=zN1 he have ht:tX[p]!) Ѥt (by simpa only[beq_iff_eq] using hv) exact ih (t+1) buf ix c l _ _ he' hb hbs hix his (by rw[u,zI,e];exact ⟨hc,hr,hl⟩) . rename_i hv have e:=qD5 (λp=>X[p]!) Ѥt (by simpa only[beq_iff_eq] using hv) have hcn:c?_,rfl⟩ rw[qEt _ _ _ _ hbs (zN3 hct h1 hb),qBu _ _ _ _ his (zN3 hct h1 hix)] by_cases hk2:q< ѣ(C_keep (λp=>X[p]!) Ѥt) . rw[List.getElem?_append_left hk2] at hq simp only[Nat.ne_of_lt (hc▸hk2),ite_false];exact hr q p hq . rw[List.getElem?_append_right (Nat.le_of_not_lt hk2)] at hq have e0:q-ѣ(C_keep (λp=>X[p]!) Ѥt)=0:=by by_contra hne;rw[List.getElem?_eq_none (by simpa only[List.length_cons,List.length_nil,zero_add] using zN4 hk2 hne)] at hq;exact absurd hq (by simp only[reduceCtorEq,not_false_eq_true]) rw[e0] at hq;simp only[List.getElem?_cons_zero,Option.some.injEq] at hq;subst hq simp only[zN5 hk2 e0 hc,ite_true,USize.toNat_toUInt32];exact ⟨Ἁ (zN6 h1 hX hs),trivial⟩ lemma dZS (X:ѐ) (n N:ὦ) (hNn:N=n) (hN':ѤN<=ѧX) (hX:Ѥn<=ѧX) (d:Ὣ): ∀(t:ὦ) (buf:ὤ) (ix:ѐ) (c:ὦ) (l:ὧ) (lo hi:ὥ),Ѥt+d=Ѥn-> scan X N t hN' lo hi=(if 0x007FFFFF<=(decZ X n hX d t buf ix c l lo hi).2.2.1/\(decZ X n hX d t buf ix c l lo hi).2.2.2<У then (decZ X n hX d t buf ix c l lo hi).2.2.2 else Е):=by induction d with | zero=> intro t buf ix c l lo hi he have h':¬t intro t buf ix c l lo hi he have h:tsimp only[hv,ite_true,Bool.false_eq_true,ite_false]<;>exact ih (t+1) _ _ _ _ _ _ he' lemma zM1 {a:Ὣ} (h:a<2^20):a<2^32:=by exact omS363 h lemma linZe (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ) (hh:1*inW=ѧX/\outW*inW=ѧW/\outW=ѧb/\0< inW/\0by simp only[C_keep,USize.toNat_zero,List.range_zero,List.filter_nil,List.length_nil,not_lt_zero,not_false_eq_true,getElem?_neg,reduceCtorEq] at h,by simp only[C_keep,USize.toNat_zero,List.range_zero,List.filter_nil,List.foldl_nil]⟩ have en:X.usize=ѩinW:=by rw[Array.usize,<-h1,Ὑ] have hS:=dZS X (ѩinW) X.usize en (qAc X) hX Ѥ(ѩinW) 0 (zFor inW) (ἇ Ѥ(ѩinW) 0) 0 0 Е 0 (by simp only[USize.toNat_zero,Nat.toUSize_eq,USize.toNat_ofNat',zero_add]) generalize decZ X (ѩinW) hX Ѥ(ѩinW) 0 (zFor inW) (ἇ Ѥ(ѩinW) 0) 0 0 Е 0=r at z1 z2 z3 z4 z5 hS⊢ obtain ⟨⟨rb,ri⟩,⟨rc,rl⟩,⟨rlo,rhi⟩⟩:=r dsimp only at z1 z2 z3 z4 z5 hS⊢ rw[nm] at z2 z3 z4 z5 split . rename_i hc have hsc:scanH 0 X≠Е:=by unfold scanH;simp only[show ((0:Ὣ)==1)=false by decide,Bool.false_eq_true,ite_false,beq_self_eq_true,ite_true] rw[hS,ἱ hc];exact ltUne _ hc.2 have Hv:=qA8 2 W h8 h13 have G:C_G 1 inW outW X W b:=⟨h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,(qA8 0 X h7 hsc).2.2.1,Hv.2.2.1,(qA8 1 b h9 h12).2.2.1⟩ have Rw:C_Row inW X 0 ri rb rc (C_keep (λp=>X[p]!) inW) rl:=⟨z3,qBj _ _,by rw[z2];simp only[Array.size_replicate,Std.le_refl],⟨by rw[z1];exact P0.1,by rw[z1];exact P0.2⟩,(qDs _ _).1,(qDs _ _).2.1,λt ht hn=>by simpa only[zero_mul,zero_add] using (qDs _ _).2.2 t ht hn,λk p hk=>by simpa only[zero_mul,zero_add] using z4 k p hk,by simpa only[zero_mul,zero_add] using z5⟩ rw[qEr0] have e:linearSpec 1 inW outW relu X W b=Array.ofFn (n:=1*outW) λq=>C_sp inW outW relu X W b q.val:=rfl rw[e] have HdE:C_Dw (ἆ 0) W:=λh q hq=>absurd hq (by rw[<-(h:0=ѧW)];exact Ἲ _) have hb0:(0*outW).toUSize.toNat=0*outW:=qAd _ omS333 rw[c1WE _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (λj hj=>by rw[Rw.len] at hj;have hp:=List.getElem?_eq_getElem hj;exact ⟨_,G.gx ((by exact Nat.le_refl _):0<1) _ (Rw.lt _ (List.mem_of_getElem? hp)),(Rw.rd j _ hp).2⟩) HdE (by rw[nm,h2]) (by rw[h3];exact h9) (λj i k a b c d=>by rw[nm] at c⊢;exact wbP W inW outW j i k a b c d) (λho i k hi hk=>by rw[nm] at hi⊢;exact wbPt W inW outW i k ho hi hk) 0 rfl] obtain ⟨gb1,gb2,-,gb4⟩:=qA8 1 b h9 h12 obtain ⟨pb0,pb1,pb2⟩:=qCs gb1 gb2 obtain ⟨fbm,Rbm⟩:=qAm _ gb1 have hbm:∀j,j |R (dv b[j]!)| <=R (dv (scanH 1 b)):=λj hj=>by have gj:=(qA8 1 b h9 h12).2.2.1 j (by rw[<-h3];exact hj) rw[(qAm _ gj).2,Rbm];exact pb2 _ gj (gb4 j (by rw[<-h3];exact hj)) have bb:R (dv (scanH 1 b))<=2^(290:ℤ):=by rw[Rbm];exact pb1.trans (by rw[show (2:ℝ)^128=2^(128:ℤ) by norm_num];exact ἒ ב ב) have H0:C_Inv (1*outW) (C_sp inW outW relu X W b) (λq=>q<0) (ἇ (1*outW) 0):=⟨by simp only[one_mul,Array.size_replicate],λq _ h=>absurd h (Ἲ _)⟩ exact qBv (qD0 G relu ((by exact Nat.le_refl _):0<1) Hv Rw hb0 HdE (dv (scanH 1 b)) fbm hbm bb rfl outW 0 _ (Ἇ _) (by rw[ὒ,Ἵ];exact H0)) (λq hq=>omS334 hq) . rfl lemma linNe (inW outW:Ὣ) (relu:Ὡ) (X W b:ѐ):linN inW outW relu X W b=linF0 1 inW outW relu X W b:=by unfold linN linNc;rw[(wnGet inW outW W b).2];dsimp only;rw[show fz0=(0:ὧ) from rfl] split . rename_i hh split . rename_i hz split . exact linZe inW outW relu X W b hh _ (qA9 hh.2.2.2.2.2.2.1) split . rename_i hc obtain ⟨h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14⟩:=hh have hs:ѧX<2^32:=א have en:X.usize=ѩinW:=by rw[Array.usize];congr 1;omega have hsc:scan X X.usize 0 (qAc X) Е 0≠Е:=by rw[dVS X _ _ X.usize en (by rw[ὒ];rfl) (by have:=hz.1;omega) (qAc X) hz.1 hs 0 (zFor inW) 0 Е 0 hz.2.1] rw[ἱ hc];exact ltUne _ hc.2 have hS:scanH 0 X≠Е:=by unfold scanH;simp only[show ((0:Ὣ)==1)=false by decide,Bool.false_eq_true,ite_false,beq_self_eq_true,ite_true];exact hsc unfold linF0;rw[(wbGet inW outW W).2];dsimp only have hG:1*inW=ѧX/\outW*inW=ѧW/\outW=ѧb/\0< inW/\0(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)<(m:ℝ)*2^q) (hW3:(2^53-2^28)*2^((ex:Int)-1076)<(m:ℝ)*2^q): toWord (ἕ Fmt ⟨S,m,q⟩)=ὺ ((if S then 2^31 else 0)+(ex-896)*2^23+fr):=by have hE:(2:ℝ)^((ex:Int)-1046)=2^30*2^((ex:Int)-1076):=by rw[<-Ἡ,<-Ἓ ἓ] congr 1;(clear h1 h2 h3 hm;exact omS335) rw[qE4 S m q (2^23+fr) ((ex:Int)-1046) hm (by clear h1 h2 hm;exact omS125) (by clear h1 h2 hm;exact omS126 h3) (by clear h3 hm;exact omS127 h1) (by clear h3 hm;exact omS128 h2) (by rw[hE];push_cast;linarith only[hW1]) (λ_=>by rw[hE];push_cast;linarith[hW2 (by clear h1 h2 h3 hm;omega)]) (λ_=>by rw[hE];linarith only[hW3]),show ((ex:Int)-1046+150).toNat=ex-896 by (clear h3 hm;exact omS130),show (2^23+fr)%2^23=fr by (clear h1 h2 hm;exact omS131 h3)] lemma qFt (a b:ℝ) (ha:0<=a) (h:asimp only[Nat.reducePow,Nat.cast_add,Nat.cast_ofNat,neg_add_rev,Int.reduceNeg,ne_eq]<;>(clear h0 h1;omega) simp only[qAx w h1,rationalWord,decodeD_toRat,Rat.cast_mul,Rat.cast_intCast,Rat.cast_zpow,Rat.cast_ofNat,ne_eq,mul_eq_zero,Int.cast_eq_zero,this,OfNat.ofNat_ne_zero,not_false_eq_true,zpow_ne_zero,or_self] lemma qDqW (S:Ὡ) (ex fr:Ὣ) (h1:897<=ex) (h2:ex<1151) (h3:fr<2^23) (V W:ℝ) (hV:V=if S then-W else W) (hW1:W<(2^53+fr*2^30+2^29)*2^((ex:Int)-1076)) (hW2:fr≠0->(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)split<;>omega have hb0:(0:ℝ)<2^((ex:Int)-1076):=ἵ ו _;have hA2:(0:ℝ)<=(2^53-2^28)*2^((ex:Int)-1076):=Ἆ ו hb0.le obtain ⟨Lo,hLo0,hLoW,hLo1,hLo2⟩:∃Lo:ℝ,0<=Lo/\Lo(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)<=Lo)/\(2^53-2^28)*2^((ex:Int)-1076)<=Lo:=by by_cases hfr:fr=0;. exact ⟨_,hA2,hW3,λh=>absurd hfr h,le_rfl⟩ . have hfr1:(1:ℝ)<=fr:=by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hfr refine ⟨_,?_,hW2 hfr,λ_=>le_rfl,?_⟩;. exact Ἆ (sub_nonneg.mpr ((pow_le_pow_right₀ one_le_two (Nat.le_of_ble_eq_true rfl:29<=53)).trans (le_add_of_nonneg_right ו))) hb0.le . exact ἀ (by linarith only[hfr1]) hb0.le have hW0:0ἷ (hLo1 h) hd1) (ἷ hLo2 hd1) have w2:=qGm S ex fr m2 q2 h1 h2 h3 hm2 (hd2'.trans_lt (add_div_two_lt_right.mpr (left_lt_add_div_two.mp (hd2.trans_le hd2')))) (λh=>by exact ἷ (hLo1 h) ((hd1.trans_le hd1').trans hd2)) (ἷ hLo2 ((hd1.trans_le hd1').trans hd2)) set z:=ὺ ((if S then 2^31 else 0)+(ex-896)*2^23+fr) with hzd;have hzn:ѥz=(if S then 2^31 else 0)+(ex-896)*2^23+fr:=by rw[hzd,ὡ,Ἁ];exact e2zw.1 have hexp:(expOf z).toNat=ex-896:=by rw[qCa,hzn];exact e2zw.2 have he0:expOf z≠0:=λh=>by rw[h] at hexp;exact absurd (Nat.sub_eq_zero_iff_le.mp hexp.symm) (Nat.not_le.mpr h1) have he1:expOf z≠255:=λh=>by rw[h] at hexp;exact absurd ((Nat.sub_eq_iff_eq_add (Nat.le_of_succ_le h1)).mp hexp.symm) (Nat.ne_of_lt h2) have r1:ἕ Fmt ⟨S,m1,q1⟩=ofW z:=by rw[<-w1,qGz] have r2:ἕ Fmt ⟨S,m2,q2⟩=ofW z:=by rw[<-w2,qGz] have fz:Ἑ (ofW z)=true:=by simp only[ofW,isFinite_ofUInt32,bne_iff_ne,ne_eq,he1,not_false_eq_true] have t1:=Model.toReal_roundDyadic_eq_roundAt Fmt ה ⟨S,m1,q1⟩ (by rw[r1];exact fz);have t2:=Model.toReal_roundDyadic_eq_roundAt Fmt ה ⟨S,m2,q2⟩ (by rw[r2];exact fz);rw[r1] at t1;rw[r2] at t2 have hv:Ἢ (ofW z)=Model.roundAt Fmt V:=by apply le_antisymm . cases S;. rw[t1];apply Model.roundAt_mono;simp only[FloatLib.Numerics.Dyadic.toReal,signedSignificand,false_eq_true, ↓reduceIte,Int.ofNat_eq_natCast,Int.cast_natCast,hV];linarith only[hd1'] . rw[t2];apply Model.roundAt_mono;simp only[FloatLib.Numerics.Dyadic.toReal,signedSignificand, ↓reduceIte,Int.ofNat_eq_natCast,Int.cast_neg,Int.cast_natCast,neg_mul,hV,neg_le_neg_iff];linarith only[hd2] . cases S;. rw[t2];apply Model.roundAt_mono;simp only[hV,false_eq_true, ↓reduceIte,FloatLib.Numerics.Dyadic.toReal,signedSignificand,Int.ofNat_eq_natCast,Int.cast_natCast];linarith only[hd2] . rw[t1];apply Model.roundAt_mono;simp only[hV, ↓reduceIte,FloatLib.Numerics.Dyadic.toReal,signedSignificand,Int.ofNat_eq_natCast,Int.cast_neg,Int.cast_natCast,neg_mul,neg_le_neg_iff];linarith only[hd1'] have hnz:Ἢ M≠0:=by rw[hM,<-hv];exact qIm z he0 he1 have:=Model.eq_of_toReal_eq_of_nonzero (hM.trans hv.symm) hnz;rw[this];have hr:toWord (ofW z)=z:=by rw[<-r1,w1] exact hr set_option maxRecDepth 8192 in lemma qDq (s e:ὧ) (V:ℝ) (hlo:R (s-e)ὦ->ὦ->Ὢ) (s:σ) (b j:ὦ) (o:ё):Ὣ->ё | 0=>o | k+1=>fC f s b (j+1) (wrW o (b+j) (f s (b+j) j)) k @[specialize] def fR {σ:Type} (h:Ὣ->σ) (f:σ->ὦ->ὦ->Ὢ) (n r:Ὣ) (o:ё):Ὣ->ё | 0=>o | k+1=>fR h f n (r+1) (fC f (h r) (r*n).toUSize 0 o n) k def lnSum (x:ё) (base n i:ὦ) (s t:ὧ):F1:= if h:i>>52)-1<1222)&& decide ((((a*b-Ἃ 0x3FF0000000000000)+Ἃ 0x3CD0000000000000).toBits>>>52)-972<2) @[inline] def lnQ (b:Ὡ) (n:Ὣ) (x:ё) (r:Ὣ):ℚ:=if b then 0 else rowMean n x r @[inline] def lnStat (b:Ὡ) (n:Ὣ) (eps:Ὢ) (x:ё) (r:Ὣ):LnS:= let base:=(r*n).toUSize let nu:=ѩn let nd:=n.toUInt64.toFloat let nf:=(n.toUInt64+8).toFloat*Ἃ ь let ind:=1.0/nd let a:=if b then F1.mk 0 0 else lnSum x base nu 0 0 0 let m:=if b then 0 else a.s*ind let v:=lnVar x base nu 0 m 0 let em:=(nf*a.t)*ind+Ἃ ظ let tt:=v*ind+dv eps let d:=Ἤ tt let z:=ziv d ((nf+nf)*d+em) let ir:=1.0/dv z if sm z&&decide ((0x1F800000:ὥ)<=z)&&decide (z<=(0x70FFFFFF:ὥ))&&decide ((tt.toBits>>>52)-1<1222)&&invOK ind nd&&invOK ir (dv z) then ⟨true,m,ir,em,z⟩ else ⟨false,0,0,0,sqrtRational (rowVariance n x r (lnQ b n x r)+ἂ eps)⟩ /-! -/ def mKf (f:Nat->ὥ) (L:љ) (k:Nat):Nat:= L.foldl (λk j=>if mantOf (f j)=0 then k else min k (idxOf (f j))) k def pw2T:ї:=Array.ofFn (n:=63) (λi=>2^i.val) @[inline] def pw2 (k:Nat):Nat:=if k<63 then pw2T[k]! else 2^k lemma pw2_eq (k:Nat):pw2 k=2^k:=by unfold pw2;split · rename_i h rw[Ἕ pw2T k (by simp only[pw2T,Array.size_ofFn];exact h)] simp only[pw2T,Array.getElem_ofFn] · rfl def mSf (f:Nat->ὥ) (K:Nat) (L:љ) (t:Int):Int:= L.foldl (λt j=>t+sv (f j)*((pw2 (idxOf (f j)-K):Nat):Int)) t lemma mKf_le (f:Nat->ὥ) (L:љ): ∀k,mKf f L k<=k:=by induction L with | nil=>intro k;exact Nat.le_refl k | cons p L ih=> intro k;unfold mKf;rw[ὔ] refine (ih _).trans ?_ split · exact Nat.le_refl k · exact Nat.min_le_left _ _ lemma mKf_lo (f:Nat->ὥ) (L:љ): ∀k, ∀j∈L,mantOf (f j)=0\/mKf f L k<=idxOf (f j):=by induction L with | nil=>intro k j hj;simp only[List.not_mem_nil] at hj | cons p L ih=> intro k j hj rcases List.mem_cons.1 hj with rfl | hj · by_cases h:mantOf (f j)=0 · exact Or.inl h · refine Or.inr ?_ unfold mKf;rw[ὔ];simp only[h,ite_false] exact (mKf_le f L _).trans (Nat.min_le_right _ _) · unfold mKf;rw[ὔ];exact ih _ j hj lemma sv_zero (w:ὥ) (h:mantOf w=0):sv w=0:=by unfold sv;split<;>simp only[h,CharP.cast_eq_zero,neg_zero] lemma mSf_eq (f:Nat->ὥ) (K:Nat) (L:љ) (hL:∀j∈L,mantOf (f j)=0\/K<=idxOf (f j)): ∀t:Int,L.foldl (λt j=>t+sv (f j)*((2^idxOf (f j):Nat):Int)) (t*((2^K:Nat):Int))=mSf f K L t*((2^K:Nat):Int):=by induction L with | nil=>intro t;rfl | cons p L ih=> intro t have hp:=hL p (ὣ ..) have hL': ∀j∈L,mantOf (f j)=0\/K<=idxOf (f j):= λj hj=>hL j (ὖ _ hj) unfold mSf;rw[ὔ,ὔ,pw2_eq] have e:t*((2^K:Nat):Int)+sv (f p)*((2^idxOf (f p):Nat):Int)=(t+sv (f p)*((2^(idxOf (f p)-K):Nat):Int))*((2^K:Nat):Int):=by rcases hp with h | h · rw[sv_zero _ h];ring · have:idxOf (f p)=(idxOf (f p)-K)+K:=(Nat.sub_add_cancel h).symm conv_lhs=>rw[this] push_cast;rw[pow_add];ring rw[e];exact ih hL' _ def meanI (n:Ὣ) (x:ё) (r:Ὣ):ℤ:= (ἄ n).foldl (λt j=>t+sv x[r*n+j]!*((2^idxOf x[r*n+j]!:ℕ):ℤ)) 0 def meanIK (n:Nat) (x:ё) (r K:Nat):Int:= mSf (λj=>x[r*n+j]!) K (ἄ n) 0*((2^K:Nat):Int) def meanIF (n:Nat) (x:ё) (r:Nat):Int:= meanIK n x r (mKf (λj=>x[r*n+j]!) (ἄ n) 1000) lemma meanIK_eq (n:Nat) (x:ё) (r K:Nat) (hK:∀j∈ἄ n,mantOf x[r*n+j]! =0\/K<=idxOf x[r*n+j]!): meanIK n x r K=meanI n x r:=by have h:=mSf_eq (λj=>x[r*n+j]!) K (ἄ n) hK 0 rw[Int.zero_mul] at h exact h.symm lemma meanIF_eq (n:Nat) (x:ё) (r:Nat):meanIF n x r=meanI n x r:= meanIK_eq n x r _ (λj hj=>mKf_lo (λj=>x[r*n+j]!) (ἄ n) 1000 j hj) def meanQ (n:Ὣ) (x:ё) (r:Ὣ):ℚ:=(meanIF n x r:ℚ)/((2^149*n:ℕ):ℚ) @[noinline] def lnSlow (x g b den:Ὢ) (mean:Unit->ℚ):Ὢ:= roundRational ((ἂ x-mean ())*ἂ g/ἂ den+ἂ b) @[inline] def lnFa (m ir em:ὧ) (den w gw bw:Ὢ) (gv bv:ὧ) (lo:Ὠ) (mean:Unit->ℚ):Ὢ:= let gd:=gv*ir let q:=(dv w-m)*gd let t:=fin1 lo (spOf lo) (q+bv) if t==Е then let r:=ziv (q+bv) (Ἃ 0x3D10000000000000*(q.abs+bv.abs)+em*gd.abs) if 0x7EFFFFFF<(r&&&В) then lnSlow w gw bw den mean else r else t @[inline] def lnFb (m ir em:ὧ) (den:Ὢ) (x g b:ё) (p j:ὦ) (gv bv:ὧ) (lo sp:Ὠ) (mean:Unit->ℚ):Ὢ:= let w:=rdW x p let gd:=gv*ir let q:=(dv w-m)*gd let t:=fin1 lo sp (q+bv) if t==Е then let r:=ziv (q+bv) (Ἃ 0x3D10000000000000*(q.abs+bv.abs)+em*gd.abs) if 0x7EFFFFFF<(r&&&В) then lnSlow w (rdW g j) (rdW b j) den mean else r else t @[inline] def lnFc (m ir em:ὧ) (den w:Ὢ) (g:ё) (j:ὦ) (gv:ὧ) (lo sp:Ὠ):Ὢ:= let gd:=gv*ir let q:=(dv w-m)*gd let t:=fin1 lo sp (q+dv 0) if t==Е then let r:=ziv (q+dv 0) (Ἃ 0x3D10000000000000*(q.abs+(dv 0).abs)+em*gd.abs) if 0x7EFFFFFF<(r&&&В) then lnSlow w (rdW g j) 0 den (λ_=>0) else r else t @[inline] def lnOutF (s:LnS) (lo:Ὠ) (w gw bw:Ὢ) (gv bv:ὧ) (mean:Unit->ℚ):Ὢ:= if s.fast then lnFa s.m s.ir s.em s.den w gw bw gv bv lo mean else lnSlow w gw bw s.den mean @[inline] def lnOut (s:LnS) (lo:Ὠ) (w gw bw:Ὢ) (mean:Unit->ℚ):Ὢ:=lnOutF s lo w gw bw (dv gw) (dv bw) mean @[inline] def lnEB (s:LnS) (xm gm bm:ὧ):ὧ:=Ἃ 0x3D10000000000000*((xm+s.m.abs)*(gm*s.ir)+bm)+s.em*(gm*s.ir) @[inline] def rdF (a:ὤ) (i:ὦ):ὧ:= if h:iℚ) (lo sp:Ὠ) (base n j:ὦ) (o:ё):ё:= if h:jℚ) (base n j:ὦ) (o:ё):ё:= if h:jmeanQ nN x rR) @[noinline] def lnRSM (x g b:ё) (den:Ὢ) (nN rR:Ὣ) (base n j:ὦ) (o:ё):ё:=lnRS x g b den (λ_=>meanQ nN x rR) base n j o @[noinline] def lnRFM (x g b:ё) (G B:ὤ) (m ir em:ὧ) (den:Ὢ) (nN rR:Ὣ) (lo sp:Ὠ) (base n j:ὦ) (o:ё):ё:=lnRF x g b G B m ir em den (λ_=>meanQ nN x rR) lo sp base n j o def lnRows (x g b:ё) (G B:ὤ) (eps:Ὢ) (xm gm bm:ὧ) (n r:Ὣ) (o:ё):Ὣ->ё | 0=>o | d+1=> let s:=lnStat false n eps x r lnRows x g b G B eps xm gm bm n (r+1) (if s.fast then lnRF x g b G B s.m s.ir s.em s.den (λ_=>meanQ n x r) (loOf (lnEB s xm gm bm)) (spOf (loOf (lnEB s xm gm bm))) (r*n).toUSize ѩn 0 o else lnRS x g b s.den (λ_=>meanQ n x r) (r*n).toUSize ѩn 0 o) d def lnDecB (x:ё) (base n j:ὦ) (buf:ὤ) (t s:ὧ):ὤ:= if h:j(lnDecB x base n j buf t s).size=Ѩbuf:=by induction k with | zero=> intro j buf t s e rw[lnDecB,ἔ (by rw[А];exact omS404 e),qD6,qD6] | succ k ih=> intro j buf t s e have hj:jlnDecI x base n j buf t s hx hs=lnDecB x base n j buf t s:=by induction k with | zero=> intro j buf t s e rw[lnDecI,lnDecB,ἔ (by rw[А];exact omS404 e),ἔ (by rw[А];exact omS404 e)] | succ k ih=> intro j buf t s e have hj:j>>52)-1<1222)&&okI&&invOK ir (dv z) then ⟨true,m,ir,em,z⟩ else ⟨false,0,0,0,sqrtRational (rowVariance n x r (lnQ false n x r)+ἂ eps)⟩ @[inline] def lnFvM (m ir em:ὧ) (den w:Ὢ) (v:ὧ) (g b:ё) (j:ὦ) (gv bv:ὧ) (lo sp:Ὠ) (nN:Ὣ) (x:ё) (rR:Ὣ):Ὢ:= let gd:=gv*ir let q:=(v-m)*gd let t:=fin1 lo sp (q+bv) if t==Е then let r:=ziv (q+bv) (Ἃ 0x3D10000000000000*(q.abs+bv.abs)+em*gd.abs) if 0x7EFFFFFF<(r&&&В) then lnSlowM w (rdW g j) (rdW b j) den nN x rR else r else t def lnRB (x g b:ё) (buf G B:ὤ) (m ir em:ὧ) (den:Ὢ) (nN rR:Ὣ) (lo sp:Ὠ) (base n j:ὦ) (o:ё) (hb:Ѥn<=Ѩbuf) (hG:Ѥn<=ѨG) (hB:Ѥn<=ѨB):ё:= if h:jё | 0=>o | d+1=> if h:n+2<=Ѩbuf/\Ѩbuf<=4294967295/\n<=ѨG/\ѨG<=4294967295/\n<=ѨB/\ѨB<=4294967295/\r*n+n<=ѧx/\ѧx<=4294967295 then let base:=(r*n).toUSize let bf:=lnDecC x base ѩn buf let s:=lnStatB n eps x r ind okI bf (by rw[lnDecC_sz0];omega) (by rw[lnDecC_sz0];omega) lnRowsB x g b G B eps xm gm bm n ind okI (r+1) bf (if s.fast then lnRB x g b bf G B s.m s.ir s.em s.den n r (loOf (lnEB s xm gm bm)) (spOf (loOf (lnEB s xm gm bm))) base ѩn 0 o (by rw[lnDecC_sz0,qAd n (by omega)];omega) (by rw[qAd n (by omega)];omega) (by rw[qAd n (by omega)];omega) else lnRSM x g b s.den n r base ѩn 0 o) d else let s:=lnStat false n eps x r lnRowsB x g b G B eps xm gm bm n ind okI (r+1) buf (if s.fast then lnRFM x g b G B s.m s.ir s.em s.den n r (loOf (lnEB s xm gm bm)) (spOf (loOf (lnEB s xm gm bm))) (r*n).toUSize ѩn 0 o else lnRSM x g b s.den n r (r*n).toUSize ѩn 0 o) d def rmsRF (rows:Ὣ) (x g:ё) (G:ὤ) (m ir em:ὧ) (den:Ὢ) (lo sp:Ὠ) (base n j:ὦ) (o:ё):ё:= if h:jё | 0=>o | d+1=> let s:=lnStat true n eps x r rmsRows rows x g G eps xm gm n (r+1) (if s.fast then rmsRF rows x g G s.m s.ir s.em s.den (loOf (lnEB s xm gm (dv 0))) (spOf (loOf (lnEB s xm gm (dv 0)))) (r*n).toUSize ѩn 0 o else fC (λs p j=>let w:=rdW x p if w&&&В==0 then 0 else lnOutF s.1 s.2 w (rdW g j) 0 (gdR rows g G j) (dv 0) λ_=>0) (s,loOf (lnEB s xm gm (dv 0))) (r*n).toUSize 0 o n) d @[inline] def okX (h:ὥ):Ὡ:=h != Е&&decide (h<=0x70FFFFFF) @[inline] def normOK2 (rows n:Ὣ) (eps:Ὢ) (x g:ё) (hx hg:ὥ):Ὡ:= decide (0s[i].g==g) (λe=>by rw[e];exact beq_self_eq_true g) then if hk2:withPtrEq s[i].b b (λ_=>s[i].b==b) (λe=>by rw[e];exact beq_self_eq_true b) then some ⟨s[i].p,by rw[<-ho,<-eq_of_beq hk,<-eq_of_beq hk2];exact s[i].ok⟩ else lnFd n g b k s (i+1) else lnFd n g b k s (i+1) else lnFd n g b k s (i+1) else lnFd n g b k s (i+1) else none partial_fixpoint @[noinline] def lnS:ST.Ref Unit (Array LNE):=(ST.Prim.mkRef #[] (Void.mk ())).val @[inline] def lnGet (n:Ὣ) (g b:ё):LNV n g b:= withPtrAddr g (λk=> let s:=(ST.Prim.Ref.get lnS (Void.mk ())).val match lnFd n g b k s 0 with | some v=>v | none=> let p:=((decG g ѩn 0 (zFor n),decG b ѩn 0 (zFor n)),(scan g g.usize 0 (qAc g) Е 0,scan b b.usize 0 (qAc b) Е 0)) let old:=(ST.Prim.Ref.swap lnS (#[⟨g,b,n,p,k,rfl⟩]++(if s.size<256 then s else s.pop)) (Void.mk ())).val match lnFd n g b k old 0 with | some v=>v | none=>⟨p,rfl⟩) (λ_ _=>Subsingleton.elim _ _) abbrev RNV (g:ё):=({h:ὥ//h=scan g g.usize 0 (qAc g) Е 0}) structure RNE where (g:ё) (h:ὥ) (k:ὦ) (ok:h=scan g g.usize 0 (qAc g) Е 0) def rnFd (g:ё) (k:ὦ) (s:Array RNE) (i:Ὣ):Option (RNV g):= if h:is[i].g==g) (λe=>by rw[e];exact beq_self_eq_true g) then some ⟨s[i].h,by rw[<-eq_of_beq hk];exact s[i].ok⟩ else rnFd g k s (i+1) else rnFd g k s (i+1) else none partial_fixpoint @[noinline] def rnS:ST.Ref Unit (Array RNE):=(ST.Prim.mkRef #[] (Void.mk ())).val @[inline] def rnGet (g:ё):RNV g:= withPtrAddr g (λk=> let s:=(ST.Prim.Ref.get rnS (Void.mk ())).val match rnFd g k s 0 with | some v=>v | none=> let h:=scan g g.usize 0 (qAc g) Е 0 let old:=(ST.Prim.Ref.swap rnS (#[⟨g,h,k,rfl⟩]++(if s.size<256 then s else s.pop)) (Void.mk ())).val match rnFd g k old 0 with | some v=>v | none=>⟨h,rfl⟩) (λ_ _=>Subsingleton.elim _ _) def lnFq (rows n:Ὣ) (eps:Ὢ) (x g b:ё) (hx:ὥ) (c:(ὤ×ὤ)×(ὥ×ὥ)):ё:= if normOK2 rows n eps x g hx c.2.1&& ѧb==n&&okX c.2.2 then let nd:=n.toUInt64.toFloat let ind:=oneF/nd lnRowsB x g b c.1.1 c.1.2 eps (dv hx) (dv c.2.1) (dv c.2.2) n ind (invOK ind nd) 0 (zFor (n+2)) (ἇ (rows*n) 0) rows else layernormSpec rows n eps x g b def lnF (rows n:Ὣ) (eps:Ὢ) (x g b:ё):ё:=lnFq rows n eps x g b (scan x x.usize 0 (qAc x) Е 0) (lnGet n g b).1 def rmsFz (rows n:Ὣ) (eps:Ὢ) (x g:ё) (hx hg:ὥ):ё:= if normOK2 rows n eps x g hx hg then rmsRows rows x g (gdF rows g n) eps (dv hx) (dv hg) n 0 (ἇ (rows*n) 0) rows else rmsnormSpec rows n eps x g def rmsF (rows n:Ὣ) (eps:Ὢ) (x g:ё):ё:=rmsFz rows n eps x g (scan x x.usize 0 (qAc x) Е 0) (rnGet g).1 section lemma qFv (x:Ὠ):(x>>>52).toNat=Ѧx/2^52:=by rw[ἰ,Ἱ];rfl lemma qEj (x k N:Ὠ) (h:x-k>>52).toNat=E) (hE1:1<=E) (hE:E<2047):f.isFinite=true/\(2:ℝ)^((E:ℤ)-1023)<=R f/\R f<2^((E:ℤ)-1022):=by rw[qFv] at h;obtain ⟨F,hF,hM⟩:∃F<2^52,f.toBits.toNat=E*2^52+F:=⟨f.toBits.toNat%2^52,by (clear hE1 hE;exact omS337),by (clear hE1 hE;exact omS338 h)⟩;obtain ⟨h1,h2⟩:=B_R f false E F hE1 hE hF (by simpa only[false_eq_true, ↓reduceIte,Nat.reducePow,zero_add] using hM);have hb:(0:ℝ)<2^((E:ℤ)-1075):=ἵ ו _;have hF0:(0:ℝ)<=F:=Ἔ _;have hF2:(F:ℝ)<2^52:=by exact_mod_cast hF simp only[Bool.false_eq_true,ite_false,one_mul] at h2;push_cast at h2;rw[h2,qEi ((E:ℤ)-1023) (E-1075) 52 (by clear h hE1 hE hF hM;exact omS339),qEi ((E:ℤ)-1022) (E-1075) 53 (by clear h hE1 hE hF hM;exact omS340)];exact ⟨h1,ἀ (by linarith only[hF]) hb.le,Ἦ (by linarith only[hF2]) hb⟩ lemma L_k (c:Ὠ) (E n:Ὣ) (hE1:1<=E) (hn:E+n=1023) (h:(Ἃ c).toBits.toNat=E*2^52):(Ἃ c).isFinite=true/\R (Ἃ c)=1/2^n:=by obtain ⟨h1,h2⟩:=B_R (Ἃ c) false E 0 hE1 (by clear h;exact omS341 hn) ב (by simpa only[false_eq_true, ↓reduceIte,Nat.reducePow,zero_add,add_zero] using h);refine ⟨h1,?_⟩;rw[h2,show (E:ℤ)-1075=-(52+(n:ℤ)) by (clear hE1 h;exact omS342 hn),zpow_neg,Ἓ ἓ];norm_num;field_simp lemma qGk {f:ὧ} {E:Ὣ} (h:(f.toBits>>>52).toNat=E) (hE1:1<=E) (hE:E<2047): (Ἤ f).isFinite=true/\0Ὡ) (h:a.all p=true) (i:ℕ) (hi:i< ѧa):p a[i]! =true:=by rw[Ἕ a i hi];simpa only using Array.all_eq_true.1 h i hi lemma qE6 (w:ὥ) (g:good w=true) (h:w&&&В=0):ἂ w=0:=by exact_mod_cast (qAx w (qAe _ g)).symm.trans (qBr w g h) lemma qIu (s e:ὧ) (V:ℝ) (hlo:R (s-e)(clear h0 h hz;omega) have hex:ex<=1149:=by by_contra hc apply h apply ἳ.mpr rw[qAq,hz,UInt32.toNat_ofNat_of_lt' hN,((by clear h0 h h3 hz hN;exact omS344 h2 hc):ex=1150)] show 2130706431<_ split<;>(clear h0 h h1 h2 hz hN hc;omega) have hF:(fr:ℝ)+1<=2^23:=by exact_mod_cast ((by clear h0 h h1 h2 hz hN hex;(exact Nat.succ_le_of_lt ‹_›)):fr+1<=2^23) rw[hV] have hW:W<=2^54*2^(73:ℤ):=hW1.le.trans (ἑ (by linarith only[hF]) (ἒ (by norm_num1) (by clear h0 h h3 hz hN;exact omS345 hex)) hb.le ו) rw[<-qEi 127 73 54 rfl] at hW split<;>simp only[abs_neg,ἡ hW0,hW] lemma L_I {n I:ℝ} (hn:1<=n) (h3:0a<=1/k*b->k*a<=b:=λhk h=>(le_div_iff₀' hk).mp (h.trans_eq (one_div_mul_eq_div _ _)) have hz1:z<=1:=hz.trans (by norm_num1) have lo':1<=2^51*rc:=(div_le_iff₀' (by norm_num1)).mp lo;have hi':2^49*rc<=1:=(le_div_iff₀' (by norm_num1)).mp hi have a1:=qAa (rs+1/2^50) rc;rw[ἣ (rs+1/2^50) rc] at a1;have a2: |rc| =rc:=ἅ (ὂ (by norm_num1) lo) generalize hq:(1:ℝ)/2^50=q at h3 a1;have hq':(2:ℝ)^50*q=1:=by rw[<-hq];exact mul_one_div_cancel (by norm_num1) have h1':=sck (by norm_num1) h1;have h2':=sck (by norm_num1) h2;have h3':=sck (by norm_num1) h3 have c1:=neg_abs_le (rc-(rs+q));have c2:=le_abs_self (rc-(rs+q)) have a3:2^49*|rs| <=1:=by rw[<-ἡ (by norm_num1:(0:ℝ)<2^49),<-ἢ];exact abs_le.mpr ⟨by linarith only[c1,c2,a1,a2,h3',lo',hi',hq',hz1,hz0],by linarith only[c1,c2,a1,a2,h3',lo',hi',hq',hz1,hz0]⟩ have b1:=qAa (rp-1) rs;rw[ἣ (rp-1) rs] at b1;have b2:2^50*|rp-1| <=3:=by linarith only[b1,a3,h2',hz1,hz0] have c3:=qAa (P-1) (rp-1);rw[sub_sub_sub_cancel_right,ἣ P rp] at c3;have c4:=qAa P 1;rw[abs_one] at c4 exact (le_div_iff₀' (by norm_num1)).mpr (by linarith only[c3,c4,b2,h1',hz1,hz0]) lemma qG0 {a Mr Rm Em g D b I RA Rg Rq RY RE Rsa Rcs Reg Hi Lo:ℝ} (hE0:0<=Em) (hE1:Em<=2^120) (hM:2* |Mr-Rm| <=Em) (hD:1/2^64<=D) (ha: |a| <=2^99) (hg: |g| <=2^99) (hm: |Rm| <=2^110) (h1: |RA-(a-Rm)| <=1/2^53*(|a-Rm| +z)) (h2: |I*D-1| <=1/2^48) (h3: |Rg-g*I| <=1/2^53*(|g*I| +z)) (h4: |Rq-RA*Rg| <=1/2^53*(|RA*Rg| +z)) (h5: |RY-(Rq+b)| <=1/2^53*(|Rq+b| +z)) (h6: |Rsa-(|Rq| + |b|)| <=1/2^53*(|(|Rq| + |b|)| +z)) (h7: |Rcs-1/2^46*Rsa| <=1/2^53*(|1/2^46*Rsa| +z)) (h8: |Reg-Em*(|Rg|)| <=1/2^53*(|Em*(|Rg|)| +z)) (h9: |RE-(Rcs+Reg)| <=1/2^53*(|Rcs+Reg| +z)) (h10: |Hi-(RY+RE)| <=1/2^53*(|RY+RE| +z)) (h11: |Lo-(RY-RE)| <=1/2^53*(|RY-RE| +z)) (hbig:1/2^127<= |Hi|):Lo<(a-Mr)*g/D+b/\(a-Mr)*g/D+ba<=1/k*b->k*a<=b:=λhk h=>(le_div_iff₀' hk).mp (h.trans_eq (one_div_mul_eq_div _ _)) have scu:∀{a b:ℝ},a<=1/2^53*b->2^53*a<=b:=sck (by norm_num1) have hDp:0|R| <=2*|x|+z:=λ{R x} h=>((qAa R x).trans (add_le_add le_rfl (h.trans (mul_le_of_le_one_left (add_nonneg (Ἀ x) hz0) (by norm_num1))))).trans_eq (by rw[<-add_assoc,two_mul]) have hz':(2:ℝ)^200*(2^200*z)<=1:=(le_div_iff₀' (by norm_num1)).mp ((le_div_iff₀' (by norm_num1)).mp (hz.trans_eq (one_div_mul_eq_div _ _))) have hz1:z<=1:=hz.trans (by norm_num1) have S1:=scu h1;have S3:=scu h3;have S4:=scu h4;have S5:=scu h5;have S6:=scu h6;have S9:=scu h9;have S10:=scu h10;have S11:=scu h11 have nX:=Ἀ X;have nG:=Ἀ G;have nA:=Ἀ RA;have nR:=Ἀ Rg;have a1:=qAa X RA;rw[ἣ X RA] at a1 have a4:2^53*|RA-X| <=2*|RA|+2*z:=by linarith only[a1,nX,S1,hz0] have a5: |RA| <=2^165:=((rU h1).trans (add_le_add (ἁ hXb zero_le_two) hz1)).trans (by norm_num1) have b1:=qAa Y G;have b2:=qAa G Rg;have b3:=abs_sub_le G Y Rg;rw[ἣ G Y,ἣ Y Rg] at b3 have b4:2^53*|G| <=(2^53+2^6)*|Rg|+2*z:=by linarith only[b3,b2,b1,nG,hgI,S3,hz0] have b5:2^53*|G-Rg| <=2^6*|Rg|+2*z:=by linarith only[b3,b2,b1,nR,hgI,S3,hz0] have c1: |Rg| <=2^165:=by have:=qAa Rg G;rw[ἣ] at this;linarith only[this,b3,b1,hgI,S3,hGb,hz'] have f1:=Ἐ ((X-RA)*G) (RA*(G-Rg));rw[ἢ,ἢ,show (X-RA)*G+RA*(G-Rg)=X*G-RA*Rg by rw[sub_mul,mul_sub,sub_add_sub_cancel],ἣ X RA] at f1 have f2:=ἑ a4 b4 (Ἆ (by norm_num1) nG) (add_nonneg (Ἆ (by norm_num1) nA) (Ἆ (by norm_num1) hz0));have f3:=ἁ b5 nA have zr:z* |RA| <=z*2^165:=ἁ a5 hz0;have zg:z* |Rg| <=z*2^165:=ἁ c1 hz0;have zz:z*z<=z*2^165:=ἁ (hz1.trans (by norm_num1)) hz0;have ze:z*Em<=z*2^165:=ἁ (hE1.trans (by norm_num1)) hz0;have nP:=Ἆ nA nR have f4:2^230*|X*G-RA*Rg| <=9*2^180*(|RA| * |Rg|)+1:=by linarith only[nP,zz,zg,zr,f3,f2,f1,hz'] have p1:2^53*|RA*Rg| <=(2^53+2)*|Rq|+2*z:=by have:=qAa (RA*Rg) Rq;rw[ἣ (RA*Rg) Rq] at this;have nq:=Ἀ (RA*Rg);linarith only[nq,this,S4,hz0] rw[<-ἢ] at f4;have q1:2^229*|X*G-Rq| <=5*2^180*|Rq|+1:=by have:=Ὕ (X*G-RA*Rg) (Rq-RA*Rg);rw[sub_sub_sub_cancel_right] at this;have nq:=Ἀ Rq;linarith only[nq,this,p1,f4,S4,hz'] generalize hT:Em* |Rg| =T at h8;have nT:0<=T:=hT▸Ἆ hE0 nR have e1:2^230*|(Rm-Mr)*G| <=5*2^227*T+1:=by rw[ἢ,ἣ];have h:=ἑ hM b4 (Ἆ (by norm_num1) nG) hE0;subst hT;linarith only[nT,h,ze,hz'] have s3:=rU h8;rw[ἅ nT] at h8 s3;have S8:=scu h8;have nq:=Ἀ Rq;have nb:=Ἀ b;have nS:0<= |Rq| + |b| :=add_nonneg nq nb;have s1:=rU h6;rw[ἅ nS] at h6 s1 S6;have s0: |Rq+b| <= |Rq| + |b|:=Ἐ _ _ generalize hV:(1:ℝ)/2^46*Rsa=V at h7;have hV':2^46*|V| = |Rsa|:=by rw[<-hV,ἢ,ἡ (div_pos one_pos (pow_pos two_pos 46):(0:ℝ)<1/2^46),<-mul_assoc,mul_one_div_cancel (by norm_num1),one_mul] have S7:=scu h7;have hV2:2^46*V=Rsa:=by rw[<-hV,<-mul_assoc,mul_one_div_cancel (by norm_num1),one_mul] have s2:2^44*|Rcs| <=(|Rq| + |b|)+2^44*z:=by have:=qAa Rcs V;linarith only[this,s1,nb,nq,S7,hV',hz0] have s4: |RY| <=2*(|Rq| + |b|)+z:=(rU h5).trans (add_le_add (ἁ s0 zero_le_two) le_rfl) have s5:=Ἐ Rcs Reg;have s6:2^43*|RE| <=(|Rq| + |b|)+2^45*T+2^45*z:=by have:=qAa RE (Rcs+Reg);linarith only[this,s5,s3,s2,nb,nq,nT,S9,hz0] have s7:=Ἐ RY RE;have s8:=Ὕ RY RE;have hb0:=qAa Hi (RY+RE) have hbig':1<=2^127*|Hi|:=(div_le_iff₀' (by norm_num1)).mp hbig have n9:=neg_abs_le (RE-(Rcs+Reg));have n8:=neg_abs_le (Reg-T);have n7:=neg_abs_le (Rcs-V);have n6:=neg_abs_le (Rsa-(|Rq|+|b|));have n10:=neg_abs_le (Hi-(RY+RE));have p10:=le_abs_self (Hi-(RY+RE));have n11:=neg_abs_le (Lo-(RY-RE));have p11:=le_abs_self (Lo-(RY-RE));have nq1:=neg_abs_le (X*G-Rq);have pq1:=le_abs_self (X*G-Rq);have ne1:=neg_abs_le ((Rm-Mr)*G);have pe1:=le_abs_self ((Rm-Mr)*G);have n5:=neg_abs_le (RY-(Rq+b));have p5:=le_abs_self (RY-(Rq+b)) have M:5*2^181*|Rq|+3+5*2^227*T+2^177*(|Rq+b|+z)+2^177*(|RY|+|RE|+z)<2^230*RE:=by linarith only[S9,n9,S8,n8,S7,n7,hV',hV2,S6,n6,hb0,s7,S10,n10,hbig',s6,s5,s4,s3,s2,s1,s0,nb,nq,nT,hz',hz0] constructor . linarith only[S11,p11,s8,S5,n5,p5,q1,nq1,e1,ne1,M] . linarith only[S10,n10,s7,S5,n5,p5,q1,pq1,e1,pe1,M] lemma qG3 {n Rs Rt I Rm N Y Em c:ℝ} (r Sb:ℝ) (hn1:1<=n) (hn2:n<=2^20) (hc:c=(n+8)/2^49) (hr: |r| <=Sb) (hS:Sb<=2^99) (h1: |Rs-n*r| <=2*n*(1/2^53*(n*Sb+z))) (h2: |Rt-n*Sb| <=2*n*(1/2^53*(n*Sb+z))) (h3:02^53*a<=b:=λh=>(le_div_iff₀' (by norm_num1)).mp (h.trans_eq (one_div_mul_eq_div _ _)) have hS0:0<=Sb:=ὂ (Ἀ _) hr;have n0:0<=n:=ὂ zero_le_one hn1;have nS:0<=n*Sb:=Ἆ n0 hS0;have nSb:n*Sb<=2^20*2^99:=ἑ hn2 hS hS0 (pow_nonneg zero_le_two 20);generalize hW:n*Sb+z=W at h1 h2;have nW:0<=W:=hW▸add_nonneg nS hz0;have hI2:=L_I hn1 h3 h4;generalize hE:201/100/2^53*W+Sb/2^48=E have hE':100*2^53*E=201*W+3200*Sb:=by rw[<-hE];ring have key:∀v t:ℝ,|t| <=Sb->|v-n*t| <=2*n*(1/2^53*W)->|v*I-t| <=E:= λv t ht hv=>by have:=qF0 n I v t Sb (2*(1/2^53*W)) 0 h3 h4 ht (hv.trans_eq (((mul_assoc 2 n _).trans (mul_left_comm 2 n _)).trans (add_zero _).symm)) (Ἆ zero_le_two (Ἆ (by norm_num1) nW));linarith only[this,hE',nW] have hr1:=key Rs r hr h1;have hA1:=key Rt Sb (by rw[ἅ hS0]) h2;generalize hA:Rt*I=A at hA1 have hc0:0<=c:=hc▸div_nonneg (add_nonneg n0 (by norm_num1)) (by norm_num1) have hc':n+8=c*2^49:=(div_eq_iff (by norm_num1)).mp hc.symm have hc1:2^28*c<=1:=by linarith only[hc',hn2] have b0:=qAa A Sb;rw[ἅ hS0] at b0 have b1:2^53*|N*I-c*A| <= |c*A|+2*z:=by rw[<-hA,show N*I-c*(Rt*I)=(N-c*Rt)*I by rw[sub_mul,mul_assoc],ἢ,ἡ h3,show |c*(Rt*I)| = |c*Rt| *I by rw[<-mul_assoc,ἢ (c*Rt),ἡ h3]];have u1:=ἀ (scu h6) h3.le;have u2:=ἁ hI2 hz0;linarith only[u1,u2] have b2:2^28*|c*A| <=Sb+E:=by rw[ἢ,ἅ hc0,<-mul_assoc];exact (ἑ hc1 (b0.trans (add_le_add le_rfl hA1)) (Ἀ _) zero_le_one).trans_eq (one_mul _) have h9:2^28*|c*(A-Sb)| <=E:=by rw[ἢ,ἅ hc0,<-mul_assoc];exact (ἑ hc1 hA1 (Ἀ _) zero_le_one).trans_eq (one_mul _) have b4:(n+8)*Sb=c*2^49*Sb:=by rw[hc'] have c1:=qAa (N*I) (c*A);have c2:=qAa Y (N*I);have c3:=Ἐ Y (1/2^200);rw[ἡ (by norm_num1:(0:ℝ)<1/2^200)] at c3;generalize hq:(1:ℝ)/2^200=q at h8 c3;have hq':2^200*q=1:=by rw[<-hq];exact mul_one_div_cancel (by norm_num1) have d1:=qAa Rm (Rs*I);have d2:=qAa (Rs*I) r;have d3:=abs_sub_le r (Rs*I) Rm;rw[ἣ r (Rs*I),ἣ (Rs*I) Rm] at d3 have s5:=scu h5;have s7:=scu h7;have s8:=scu h8;have hz':(2:ℝ)^200*(2^200*z)<=1:=(le_div_iff₀' (by norm_num1)).mp ((le_div_iff₀' (by norm_num1)).mp (hz.trans_eq (one_div_mul_eq_div _ _))) have g1:=le_abs_self (c*A);have n1:=neg_abs_le (N*I-c*A);have p1:=le_abs_self (N*I-c*A);have n7:=neg_abs_le (Y-N*I);have p7:=le_abs_self (Y-N*I);have n8:=neg_abs_le (Em-(Y+q));have p8:=le_abs_self (Em-(Y+q));have n9:=neg_abs_le (c*(A-Sb)) refine ⟨?_,?_,(div_le_iff₀' (by norm_num1)).mpr ?_,?_⟩ . linarith only[h9,n9,b2,hr1,s8,n8,s7,n7,b1,n1,d3,d2,c3,c2,c1,b4,nS,hS0,hr,hz',hq',hE',hW,s5] . linarith only[g1,b2,s8,p8,s7,p7,b1,p1,c3,c2,c1,nSb,hS,hz',hq',hE',hW] . linarith only[h9,n9,b2,s8,n8,s7,n7,b1,n1,c3,c2,c1,b4,nS,hS0,hz',hq',hE',hW] . linarith only[hr1,d2,d1,nSb,s5,hS,hr,hz',hW,hE'] lemma qHr {s c Em dd Rn2 Rmu ee hi lo:ℝ} (hs0:0<=s) (hs1:s<=2^101) (hc0:9/2^49<=c) (hc1:c<=1/2^20) (hE:1/2^201<=Em) (hE1:Em<=2^120) (h1: |dd-s| <=1/2^53*(s+z)) (h2: |Rn2-(c+c)| <=1/2^53*(|c+c| +z)) (h3: |Rmu-Rn2*dd| <=1/2^53*(|Rn2*dd| +z)) (h4: |ee-(Rmu+Em)| <=1/2^53*(|Rmu+Em| +z)) (h5: |hi-(dd+ee)| <=1/2^53*(|dd+ee| +z)) (h6: |lo-(dd-ee)| <=1/2^53*(|dd-ee| +z)):s*(1+3/2*c)+9/10*Em<=hi/\lo<=s*(1-3/2*c)-9/10*Em:=by have sc:∀{a b:ℝ},a<=1/2^53*b->2^53*a<=b:=λh=>(le_div_iff₀' (by norm_num1)).mp (h.trans_eq (one_div_mul_eq_div _ _)) have hcp:0a<=1/k*b->k*a<=b:=λhk h=>(le_div_iff₀' hk).mp (h.trans_eq (one_div_mul_eq_div _ _)) have nA:=Ἀ x have hz':(2:ℝ)^200*(2^200*z)<=1:=(le_div_iff₀' (by norm_num1)).mp ((le_div_iff₀' (by norm_num1)).mp (hz.trans_eq (one_div_mul_eq_div _ _))) have zA:=ἑ hz' hx (Ἀ x) zero_le_one have zz:z*z<=z*1:=ἁ (hz.trans (by norm_num1)) hz0 have hsq: |x| ^2=x^2:=sq_abs x generalize he:Rd-x=e at h1 have h1':=sck (by norm_num1) h1;have h2':=sck (by norm_num1) h2 have q1:=Ἳ (Ἆ (by norm_num1) (Ἀ e)) h1' 2 have q3:2^53* |2*x*e| <=2* |x| *(|x| +z):=by rw[ἢ,ἢ,abs_two,mul_left_comm] exact ἁ h1' (Ἆ zero_le_two nA) have q6: |Rd*Rd-x^2| <= |2*x*e| + |e| ^2:=by rw[show Rd*Rd-x^2=2*x*e+e^2 by rw[<-he];ring,<-abs_pow] exact Ἐ _ _ have q8:=qAa (Rd*Rd) (x^2) rw[ἅ (ὅ x)] at q8 have q9:=qAa (RQ-x^2) (RQ-Rd*Rd) rw[show RQ-x^2-(RQ-Rd*Rd)=Rd*Rd-x^2 by ring] at q9 have nX:=ὅ x have G:2^250*|RQ-x^2| <=2^199*x^2+1:=by linarith only[nX,q9,q8,q6,q3,q1,hsq,zz,zA,h2',hz',hz0,nA] exact ((le_div_iff₀' (by norm_num1)).mpr G).trans_eq (by ring) lemma qH9 {n Rv I Rp Rt ep c:ℝ} (Ws tau:ℝ) (hn1:1<=n) (hn2:n<=2^20) (hc:c=(n+8)/2^49) (hWs:0<=Ws) (hep:1/2^126<=ep) (ht0:0<=tau) (ht:tau<=1/2^229) (h1: |Rv-n*Ws| <=(2*n+6)/2^53*(n*Ws)+tau) (h3:0ℝ) (c:ℝ): (l.map λj=>(a j-c)^2).sum=(l.map λj=>a j^2).sum-2*c*(l.map a).sum+ѣl*c^2:=by induction l with | nil=>simp only[List.map_nil,List.sum_nil,mul_zero,sub_self,List.length_nil,CharP.cast_eq_zero,zero_mul,add_zero] | cons j l ih=> simp only[List.map_cons,List.sum_cons,List.length_cons,ih] push_cast ring lemma qGh (l:List ℕ) (a:ℕ->ℝ) (m:ℝ) (hl:(ѣl:ℝ)≠0): (l.map λj=>(a j-m)^2).sum= (l.map λj=>(a j-(l.map a).sum/ѣl)^2).sum+ ѣl*((l.map a).sum/ѣl-m)^2:=by rw[qHp,qHp] field_simp ring lemma qGx (l:List ℕ) (f w:ℕ->ℝ) (u t:ℝ) (hw:∀j∈l,0<=w j) (h:∀j∈l,|f j-w j| <=u*w j+t) (hu:0<=u) (ht:0<=t): |(l.map f).sum-(l.map w).sum| <=u*(l.map w).sum+ѣl*t/\(l.map λj=>|f j|).sum<=(1+u)*(l.map w).sum+ѣl*t/\0<=(l.map w).sum:=by induction l with | nil=>simp only[List.map_nil,List.sum_nil,sub_self,abs_zero,mul_zero,List.length_nil,CharP.cast_eq_zero,zero_mul,add_zero,Std.le_refl,and_self] | cons j l ih=> obtain ⟨i1,i2,i3⟩:=ih (λk hk=>hw k (ὖ _ hk)) (λk hk=>h k (ὖ _ hk)) have h0:=hw j ὣ have h1:=h j ὣ simp only[List.map_cons,List.sum_cons,List.length_cons] push_cast have a1:=Ἐ (f j-w j) ((l.map f).sum-(l.map w).sum) rw[show f j-w j+((l.map f).sum-(l.map w).sum)=f j+(l.map f).sum-(w j+(l.map w).sum) by ring] at a1 have a2:=qAa (f j) (w j) rw[ἅ h0] at a2 exact ⟨by linarith only[i1,h1,a1],by linarith only[i2,h1,a2],by linarith only[i3,h0]⟩ lemma qIr {σ:Type} {N n c:Ὣ} {sp:Ὣ->Ὢ} {f:σ->ὦ->ὦ->Ὢ} {s:σ} {b:ὦ} (hN:N<2^32) (hb:Ѥb=c) (hn:c+n<=N) (hf:∀p u:ὦ,Ѥp=c+Ѥu->Ѥuf s p u=sp Ѥp) (k:Ὣ): ∀(j:ὦ) (o:ё),Ѥj+k=n->C_Inv N sp (λq=>qC_Inv N sp (λq=>q intro j o e h rw[fC,<-e];exact h | succ k ih=> intro j o e h have a0:(b+j).toNat=c+Ѥj:=by rw[<-hb];exact qAf _ _ (by exact omS346 hN hb hn e) have a1:(j+1).toNat=Ѥj+1:=by rw[qAf _ _ (by rw[ὄ];exact omS347 hN hn e),ὄ] rw[fC] refine ih _ _ (by clear hN hb hn a0;exact omS157 e a1) ?_ rw[a1] exact qAp hN h a0 (by clear hN hb a1;exact omS348 hn e) (by rw[hf _ _ a0 (by clear hN hb hn a0 a1;exact omS136 e),a0]) lemma qDb {σ:Type} {R n:Ὣ} (F:Ὣ->Ὣ->Ὣ->Ὢ) {h:Ὣ->σ} {f:σ->ὦ->ὦ->Ὢ} (hN:R*n<2^32) (hn:0Ѥp=r*n+Ѥu->Ѥuf (h r) p u=F r Ѥu Ѥp): fR h f n 0 (ἇ (R*n) 0) R=Array.ofFn (n:=R*n) λq=>F (q.val/n) (q.val%n) q.val:=by let sp q:=F (q/n) (q%n) q have K:∀(d r:Ὣ) (o:ё),r+d=R->C_Inv (R*n) sp (λq=>qC_Inv (R*n) sp (λq=>qby induction d with | zero=> intro r o e H subst e exact H | succ d ih=> intro r o e H have h1:r*n+n<=R*n:=qBc ((by clear hN hn;exact omS136 e):rby rw[hf r p u (by clear hN hn h1 h2 h3;exact omS136 e) h2 h3] show F _ _ _=F _ _ _ rw[h2,ἥ r n,Nat.mul_add_div hn,Nat.mul_add_mod,Ὃ h3,Ἁ h3,Ἵ]) n 0 o (Ἇ _) H exact qBv (K R 0 _ (by clear hN hn;exact omS139) ⟨by simp only[Array.size_replicate],λq _ (h:q<0*n)=>א⟩) λq hq=>hq section variable (x:ѐ) (hx:ѧx<2^32) (base nu:ὦ) include x hx base nu lemma qG9 (hb:Ѥbase+Ѥnu<2^32) (d:ℕ) (i:ὦ) (s t:ὧ) (h:Ѥi+d=Ѥnu): lnSum x base nu i s t= ⟨((List.range' Ѥi d).map λj=>dv x[Ѥbase+j]!).foldl (.+·) s,((List.range' Ѥi d).map λj=>(dv x[Ѥbase+j]!).abs).foldl (.+·) t⟩:=by induction d generalizing i s t with | zero=> rw[lnSum,ἔ (by rw[А];(clear hx hb;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))];simp only[List.range'_zero,List.map_nil,List.foldl_nil] | succ d ih=> have hn:i(dv x[Ѥbase+j]!-m)*(dv x[Ѥbase+j]!-m)).foldl (.+·) v:=by induction d generalizing i v with | zero=> rw[lnVar,ἔ (by rw[А];(clear hx hb;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))];simp only[List.range'_zero,List.map_nil,List.foldl_nil] | succ d ih=> have hn:iℚ) (u:ℕ->ℝ) (c:ℚ) (h:∀j∈l,(f j:ℝ)=u j):((l.foldl (λt j=>t+f j) c:ℚ):ℝ)=c+(l.map u).sum:=by induction l generalizing c with | nil=>simp only[List.foldl_nil,List.map_nil,List.sum_nil,add_zero] | cons j l ih=>simp only[ὔ,List.map_cons,List.sum_cons];rw[ih _ λk hk=>h k (ὖ _ hk),<-h j ὣ];push_cast;ring lemma qIb (w:ὥ) (hg:good w=true) (h1:(0x1F800000:ὥ)<=w) (h2:w<=(0x70FFFFFF:ὥ)):1/2^64<=wv w:=by have a1:528482304<=ѥw:=ἃ.mp h1;have a2:ѥw<=1895825407:=ἃ.mp h2;rw[qA7 w hg,ἐ (by clear h1 h2;exact omS349 a2),one_mul];have h3:=qA6 528482304 (ѥw%2^31) (by clear h1 h2;exact omS350 a1 a2) ה;have:A_mag 528482304=1/2^64:=by unfold A_mag;norm_num rwa[this] at h3 lemma qH3 (w:ὥ) (hg:good w=true) (h0:0by rw[ἱ hc] at h0;linarith only[qAs (ѥw%2^31),h0] rw[ἐ hs,one_mul];have h3:=qA6 (2^23) (ѥw%2^31) hn ה;have:A_mag (2^23)=1/2^126:=by unfold A_mag;norm_num rwa[this] at h3 lemma qIi (n:ℕ) (hn:n<2^20): ((n.toUInt64+8).toFloat*Ἃ ь).isFinite=true/\R ((n.toUInt64+8).toFloat*Ἃ ь)=((n:ℝ)+8)/2^49:=by have ht:(n.toUInt64+8).toNat=n+8:=by have h8:(8:Ὠ).toNat=8:=rfl simp only[Nat.toUInt64_eq,ἤ,UInt64.toNat_ofNat',Nat.reducePow,h8,Nat.mod_add_mod,Nat.mod_succ_eq_iff_lt,Nat.succ_eq_add_one,Nat.reduceAdd,gt_iff_lt] (clear h8;exact omS57 hn) have h1:=qCk (n.toUInt64+8) (by rw[ht];exact omS58 hn) obtain ⟨h2,h3⟩:=L_k ь 974 49 (by norm_num1) rfl (by rfl) have h4:(n:ℝ)+8<=2^21:=by exact_mod_cast ((by exact omS351 hn):n+8<=2^21) obtain ⟨hf,he⟩:=qEd _ _ h1.1 h2 (by rw[h1.2,h3,ht] refine ὂ (ἑ (qAt ?_) (qAt (by rw[ἅ ו];(norm_num1))) (Ἀ _) qI1.le) qDe rw[Nat.cast_add,ἅ ו] push_cast linarith only[h4]) refine ⟨hf,?_⟩ rw[he,h1.2,h3,ht] have:=qA2 ((n:ℤ)+8) (-49) (by exact omS352 hn) (by norm_num1) push_cast at this⊢ rw[show (2:ℝ)^(-49:ℤ)=1/2^49 by (norm_num1)] at this rw[this] ring lemma qD7 {r x B:ℝ} (e: |r-x| <=1/2^53*(|x| +A_z)) (h: |x| <=B): |r| <=9/8*B+A_z:=by linarith only[qAa r x,Ἀ x,qAr,e,h] section variable (x y:ὧ) (B:ℝ) (hx:x.isFinite=true) (hy:y.isFinite=true) (h1 : |R x| ≤ B) (h2 : |R y| ≤ B) (hB:B<=2^256*2^44:=by norm_num) include x y B hx hy h1 h2 hB lemma qAv: (x+y).isFinite=true/\|R (x+y)-(R x+R y)| <=1/2^53*(|R x+R y| +A_z)/\ |R (x+y)| <=9/8*(B+B)+A_z:=by obtain ⟨f,e⟩:=qBf x y hx hy (h1.trans (qAt hB)) (h2.trans (qAt hB)) exact ⟨f,e,qD7 e ((Ἐ _ _).trans (add_le_add h1 h2))⟩ lemma qCg: (x-y).isFinite=true/\|R (x-y)-(R x-R y)| <=1/2^53*(|R x-R y| +A_z)/\ |R (x-y)| <=9/8*(B+B)+A_z:=by obtain ⟨f,e⟩:=qDf x y hx hy (h1.trans (qAt hB)) (h2.trans (qAt hB)) exact ⟨f,e,qD7 e ((Ὕ _ _).trans (add_le_add h1 h2))⟩ end lemma qAl (x y:ὧ) (B C:ℝ) (hx:x.isFinite=true) (hy:y.isFinite=true) (h1: |R x| <=B) (h2: |R y| <=C) (hB:B<=2^256*2^44:=by norm_num) (hC:C<=2^256*2^44:=by norm_num): (x*y).isFinite=true/\|R (x*y)-R x*R y| <=1/2^53*(|R x*R y| +A_z)/\ |R (x*y)| <=9/8*(B*C)+A_z:=by obtain ⟨f,e⟩:=qCf x y hx hy (h1.trans (qAt hB)) (h2.trans (qAt hC)) exact ⟨f,e,qD7 e (ἢ (R x) (R y)▸ἑ h1 h2 (Ἀ _) ((Ἀ _).trans h1))⟩ lemma qFy (a b:ὧ) (hb:b.isFinite=true) (hb2: |R b| <=2^99) (h:invOK a b=true):a.isFinite=true/\0ℝ) (B:ℝ) (h:∀j,jf j<=B):((ἄ n).map f).sum<=n*B:=by simpa only[List.length_map,List.length_range,nsmul_eq_mul] using List.sum_le_length_nsmul ((ἄ n).map f) B (by simpa only[List.mem_map,Ἅ,forall_exists_index,and_imp,forall_apply_eq_imp_iff₂] using λj hj=>h j hj) lemma qFm (n:ℕ) (hn:n<2^20) (f:ℕ->ὧ) (a b:ℕ->ℝ) (hf:∀j,j(f j).isFinite=true/\R (f j)=a j/\|a j| =b j) (hb:((ἄ n).map b).sum<=A_B/4):(A_fsum ((ἄ n).map f)).isFinite=true/\ |R (A_fsum ((ἄ n).map f))-((ἄ n).map a).sum| <=2*n*(1/2^53*(((ἄ n).map b).sum+A_z)):=by have s:∀(u:ὧ->ℝ) (v:ℕ->ℝ),(∀j,ju (f j)=v j)->(((ἄ n).map f).map u).sum=((ἄ n).map v).sum:=λu v h=>by simp only[List.map_map] exact congrArg _ (ὠ λj hj=>h j (Ἅ.1 hj)) have e1:=s (λq=>|R q|) b λj h=>by simp only[(hf j h).2.1,(hf j h).2.2] have e2:=s R a λj h=>(hf j h).2.1 have:=qBz ((ἄ n).map f) (λq hq=>by obtain ⟨j,hj,rfl⟩:=List.mem_map.1 hq exact (hf j (Ἅ.1 hj)).1) (by simp only[List.length_map,List.length_range,Nat.reducePow];(exact Nat.le_of_lt (Nat.lt_of_lt_of_le ‹_› ה))) (by rw[A_sa,e1];exact hb) rwa[A_sa,A_sr,e1,e2,List.length_map,List.length_range] at this lemma qGp (n:ℕ) (hn:n<2^20) (hn0:0ὧ) (m v:ὧ) (W:ℝ) (hv:v=A_fsum ((ἄ n).map λj=>(g j-m)*(g j-m))) (hW:W=((ἄ n).map λj=>(R (g j)-R m)^2).sum) (hg:∀j,j(g j).isFinite=true/\|R (g j)| <=2^99) (hm:m.isFinite=true) (hm2: |R m| <=2^110):v.isFinite=true/\|R v-W| <=(2*n+6)/2^53*W+1/2^229/\W<=n*2^222/\0<=W:=by have hz0:=qAr.le;have hzl:=qAw;have hzb:=qBo have hq:∀j,j((g j-m)*(g j-m)).isFinite=true/\ |R ((g j-m)*(g j-m))-(R (g j)-R m)^2| <=4/2^53*(R (g j)-R m)^2+1/2^250/\(R (g j)-R m)^2<=2^222:=by intro j hj obtain ⟨f,b⟩:=hg j hj have B1: |R (g j)| <=2^110:=b.trans (by norm_num1) obtain ⟨f1,e1,b1⟩:=qCg (g j) m (2^110) f hm B1 hm2 (by norm_num1) have b2: |R (g j-m)| <=2^112:=b1.trans ((add_le_add le_rfl hzb).trans (by norm_num1)) obtain ⟨f2,e2,-⟩:=qAl _ _ (2^112) (2^112) f1 f1 b2 b2 (by norm_num1) (by norm_num1) have hx: |R (g j)-R m| <=2^111:=(Ὕ _ _).trans ((add_le_add B1 hm2).trans (by norm_num1)) refine ⟨f2,qIw hz0 hzl hx e1 e2,?_⟩ have:=Ἳ (Ἀ _) hx 2 rw[sq_abs] at this exact this.trans (by norm_num1) obtain ⟨a1,a2,a3⟩:=qGx (ἄ n) (λj=>R ((g j-m)*(g j-m))) (λj=>(R (g j)-R m)^2) (4/2^53) (1/2^250) (λj _=>ὅ _) (λj hj=>(hq j (Ἅ.1 hj)).2.1) ו ו;simp only[List.length_range] at a1 a2;rw[<-hW] at a1 a2 a3;have hW':W<=n*2^222:=hW▸qDr n _ _ λj h=>(hq j h).2.2;have hnR:(n:ℝ)<=2^20:=by exact_mod_cast hn.le have hnR1:(1:ℝ)<=n:=by exact_mod_cast hn0 have h1:(n:ℝ)*2^222<=2^20*2^222:=ἀ hnR (pow_nonneg zero_le_two 222) have h2:(n:ℝ)*(1/2^250)<=2^20*(1/2^250):=ἀ hnR (div_nonneg zero_le_one (pow_nonneg zero_le_two 250)) obtain ⟨f2,e2⟩:=qFm n hn _ _ (λj=>|R ((g j-m)*(g j-m))|) (λj h=>⟨(hq j h).1,rfl,rfl⟩) (by exact ὂ a2 ((add_le_add (ἁ (hW'.trans h1) (by norm_num1)) h2).trans (ὂ (by norm_num1) (div_le_div_of_nonneg_right (qAt (k:=2^256*2^44) le_rfl) (by norm_num1))))) rw[<-hv] at e2 f2;exact ⟨f2,qG8 hz0 hzl hnR1 hnR a3 e2 a1 a2,hW',a3⟩ lemma qF2 (l:List ℕ) (f:ℕ->ℝ): |(l.map f).sum| <=(l.map λj=>|f j|).sum:=by induction l with | nil=>simp only[List.map_nil,List.sum_nil,abs_zero,Std.le_refl] | cons j l ih=>simp only[List.map_cons,List.sum_cons];exact (Ἐ _ _).trans (add_le_add le_rfl ih) def L_oF (s:LnS) (M:ℝ):Prop:= s.fast=true->s.m.isFinite=true/\s.ir.isFinite=true/\s.em.isFinite=true/\ R s.em<=2^120/\1/2^201<=R s.em/\2* |M-R s.m| <=R s.em/\ |R s.m| <=2^110/\good s.den=true/\1/2^64<=wv s.den/\ |R s.ir*wv s.den-1| <=1/2^48 def L_ok (b:Ὡ) (n:ℕ) (eps:Ὢ) (x:ё) (r:ℕ) (s:LnS):Prop:= s.den=sqrtRational (rowVariance n x r (lnQ b n x r)+ἂ eps)/\ L_oF s (lnQ b n x r:ℚ) lemma qHi (n r:ℕ) (x:ё) (g:ℕ->ὧ) (h:∀j,jR (g j)=(ἂ x[r*n+j]!:ℝ)) (q:ℚ):((rowMean n x r:ℚ):ℝ)=((ἄ n).map λj=>R (g j)).sum/n/\ ((rowVariance n x r q:ℚ):ℝ)=((ἄ n).map λj=>(R (g j)-(q:ℝ))^2).sum/n:=by constructor . rw[rowMean,Rat.cast_div,qEp _ _ (λj=>R (g j)) 0 λj hj=>(h j (Ἅ.1 hj)).symm];simp only[Rat.cast_zero,zero_add,Rat.cast_natCast] . rw[rowVariance,Rat.cast_div,qEp _ _ (λj=>(R (g j)-(q:ℝ))^2) 0 λj hj=>by rw[h j (Ἅ.1 hj)];push_cast;rfl] simp only[Rat.cast_zero,zero_add,Rat.cast_natCast] section variable (n:ℕ) (hnR1:(1:ℝ)<=n) (hnR2:(n:ℝ)<=2^20) include n hnR1 hnR2 lemma qG1 (Fs Ft ind nf m em:ὧ) (S Sa c:ℝ) (hc:c=((n:ℝ)+8)/2^49) (o1:Fs.isFinite=true) (o2:Ft.isFinite=true) (o3: |S| <=Sa) (o4:Sa<=n*2^99) (o5: |R Fs-S| <=2*n*(1/2^53*(Sa+A_z))) (o6: |R Ft-Sa| <=2*n*(1/2^53*(Sa+A_z))) (fnf:nf.isFinite=true) (Rnf:R nf=c) (fi:ind.isFinite=true) (pi:0>>52).toNat=E) (c P δ T:ℝ) (hc1:c<=1/2^20) (hc2:9/2^49<=c) (fnf:nf.isFinite=true) (Rnf:R nf=c) (fE:em.isFinite=true) (m2:R em<=2^120) (m3:1/2^201<=R em) (hP0:0(2:ℝ)^k<=2^256*2^44:=λh=>(pow_le_pow_right₀ one_le_two h).trans_eq (pow_add 2 256 44) have e2pf:∀{x P:ℝ},x<=9/8*P+A_z->1<=P->x<=2^2*P:=λ{x P} h h1=>h.trans ((add_le_add (ἀ (by norm_num1:(9:ℝ)/8<=3) (zero_le_one.trans h1)) (qBo.trans h1)).trans ((add_one_mul (3:ℝ) P).symm.trans (congrArg (·*P) (by norm_num1:(3:ℝ)+1=2^2))).le) have e2pk:∀{x:ℝ} {a k:ℕ},x<=9/8*((2:ℝ)^a+2^a)+A_z->2+(a+1)<=k->x<=2^k:=λ{x a k} h hk=>(e2pf (h.trans_eq (congrArg (λP:ℝ=>9/8*P+A_z) ((two_mul _).symm.trans (pow_succ' 2 a).symm))) (one_le_pow₀ one_le_two)).trans ((pow_add 2 2 (a+1)).symm.trans_le (pow_le_pow_right₀ one_le_two hk)) have e2pm:∀{x:ℝ} {a b k:ℕ},x<=9/8*((2:ℝ)^a*2^b)+A_z->2+(a+b)<=k->x<=2^k:=λ{x a b k} h hk=>(e2pf (h.trans_eq (congrArg (λP:ℝ=>9/8*P+A_z) (pow_add 2 a b).symm)) (one_le_pow₀ one_le_two)).trans ((pow_add 2 2 (a+b)).symm.trans_le (pow_le_pow_right₀ one_le_two hk)) have e2pa:∀{x y:ℝ} {a b j:ℕ},x<=2^a->y<=2^b->a<=j->b<=j->x+y<=2^(j+1):=λ{x y a b j} hx hy ha hb=>(add_le_add (hx.trans (pow_le_pow_right₀ one_le_two ha)) (hy.trans (pow_le_pow_right₀ one_le_two hb))).trans_eq ((two_mul _).symm.trans (pow_succ' 2 j).symm) have e2z0:A_z<=2^0:=qBo.trans_eq (pow_zero 2).symm have e2d:∀{x:ℝ} (n:ℕ),0<=x->1/2^n*x<=x:=λn h0=>mul_le_of_le_one_left h0 (div_le_one_of_le₀ (one_le_pow₀ one_le_two) (pow_nonneg zero_le_two n)) have e2c1:∀{c:ℝ} {n:ℕ},c<=1/2^n->c<=1:=λ{c n} h=>h.trans (div_le_one_of_le₀ (one_le_pow₀ one_le_two) (pow_nonneg zero_le_two n)) have hzb:=qBo have hc0:0k+3<=256+42->x<=A_B/8:=λ{x k} h hk=>(le_div_iff₀ (by norm_num:(0:ℝ)<8)).mpr ((ἀ h (by norm_num:(0:ℝ)<=8)).trans ((((congrArg ((2:ℝ)^k*·) (by norm_num:(8:ℝ)=2^3)).trans (pow_add 2 k 3).symm).trans_le ((pow_le_pow_right₀ one_le_two hk).trans_eq (pow_add 2 256 42))).trans qCc)) have e2AB4:A_B/8<=A_B/4:=div_le_div_of_nonneg_left qI1.le ב ב have hmul:r*n+n<=rows*n:=by have:=Ἒ n hr;rwa[ᾀ] at this generalize hgd:(λj:ℕ=>dv x[r*n+j]!)=g;have hg0:∀j,j(g j).isFinite=true/\|R (g j)| <=2^99/\R (g j)=(ἂ x[r*n+j]!:ℝ):=λj h=>by obtain ⟨a1,a2⟩:=qA1 _ (qBg x sm hx (r*n+j) (by rw[hs];exact (Nat.add_lt_add_left h _).trans_le hmul));obtain ⟨a3,a4⟩:=qAm _ a1;rw[<-hgd];beta_reduce;rw[a4];exact ⟨a3,a2,qAx _ (qAe _ a1)⟩ have hnR1:(1:ℝ)<=n:=by exact_mod_cast hn0 have hnR2:(n:ℝ)<=2^20:=by exact_mod_cast hn.le have o4:((ἄ n).map λj=>|R (g j)|).sum<=n*2^99:=qDr n _ _ λj h=>(hg0 j h).2.1;have hA2:((ἄ n).map λj=>|R (g j)|).sum<=A_B/4:=(e2AB (k:=20+99) (o4.trans ((ἀ hnR2 (by (positivity):(0:ℝ)<=2^99)).trans_eq (pow_add 2 20 99).symm)) (Nat.le_of_ble_eq_true rfl)).trans e2AB4 obtain ⟨o1,o5⟩:=qFm n hn g (λj=>R (g j)) (λj=>|R (g j)|) (λj h=>⟨(hg0 j h).1,rfl,rfl⟩) hA2 obtain ⟨o2,o6⟩:=qFm n hn (λj=>(g j).abs) (λj=>|R (g j)|) (λj=>|R (g j)|) (λj h=>by obtain ⟨p,q⟩:=qBl _ (hg0 j h).1 exact ⟨p,q,abs_abs _⟩) hA2 have o3:=qF2 (ἄ n) λj=>R (g j);obtain ⟨hMc,hVc⟩:=qHi n r x g (λj h=>(hg0 j h).2.2) (lnQ b n x r);generalize hQ:((lnQ b n x r:ℚ):ℝ)=Q at hVc;generalize hS:((ἄ n).map λj=>R (g j)).sum=S at o3 o5 hMc;generalize ((ἄ n).map λj=>|R (g j)|).sum=Sa at o3 o4 o5 o6;unfold lnStat;dsimp only;generalize hnu:ѩn=nu;generalize hbase:(r*n).toUSize=base;generalize hnd:n.toUInt64.toFloat=nd;generalize hnf:(n.toUInt64+8).toFloat*Ἃ ь=nf;generalize hind:(1.0:ὧ)/nd=ind;generalize ha:(if b=true then F1.mk 0 0 else lnSum x base nu 0 0 0)=a;generalize hm:(if b=true then (0:ὧ) else a.s*ind)=m;generalize hv:lnVar x base nu 0 m 0=v;generalize hem:nf*a.t*ind+Ἃ ظ=em;generalize htt:v*ind+dv eps=tt;generalize hd:Ἤ tt=d;generalize hz:ziv d ((nf+nf)*d+em)=z;generalize hir:(1.0:ὧ)/dv z=ir;split . rename_i hc;simp only[Bool.and_eq_true,decide_eq_true_eq] at hc;obtain ⟨⟨⟨⟨⟨c1,c2⟩,c3⟩,c4⟩,c5⟩,c6⟩:=hc;have hnp:(n:ℝ)≠0:=(zero_lt_one.trans_le hnR1).ne';have hzb:=qBo;have hz0:=qAr.le;have hu:Ѥnu=n:=by rw[<-hnu];exact qAd n (by exact Nat.lt_of_lt_of_le ‹_› ה) have hb:Ѥbase=r*n:=by rw[<-hbase];exact qAd _ (((Nat.le_add_right _ _).trans hmul).trans_lt hrn) have hxs:ѧx<2^32:=hs.trans_lt hrn;obtain ⟨fnf,Rnf⟩:=hnf▸qIi n hn;obtain ⟨c,hc⟩:∃c:ℝ,c=((n:ℝ)+8)/2^49:=⟨_,rfl⟩;rw[<-hc] at Rnf;have hc1:c<=1/2^20:=by rw[hc];exact (div_le_div_of_nonneg_right (add_le_add hnR2 le_rfl) (by norm_num1)).trans (by norm_num1) have hc2:9/2^49<=c:=by rw[hc];exact div_le_div_of_nonneg_right ((show (9:ℝ)=1+8 by norm_num1).trans_le (add_le_add hnR1 le_rfl)) (by norm_num1) obtain ⟨fnd,Rnd⟩:nd.isFinite=true/\R nd=n:=by rw[<-hnd];have e:n.toUInt64.toNat=n:=by simp only[Nat.toUInt64_eq,UInt64.toNat_ofNat',Nat.reducePow,Nat.mod_succ_eq_iff_lt,Nat.succ_eq_add_one,Nat.reduceAdd];(exact Nat.lt_of_lt_of_le ‹_› ה) have:=qCk n.toUInt64 (by rw[e];exact hn.trans ה);rwa[e] at this obtain ⟨fi,pi,-,ei⟩:=qFy ind nd fnd (by rw[Rnd,ἅ (zero_le_one.trans hnR1)];exact hnR2.trans (by norm_num1)) c5 rw[Rnd] at ei;obtain ⟨z1,z2⟩:=qHg obtain ⟨fm,fE,m2,m3,m1,m4⟩:m.isFinite=true/\em.isFinite=true/\R em<=2^120/\1/2^201<=R em/\2* |Q-R m| <=R em/\|R m| <=2^110:=by cases b with | true=> have e1:a=F1.mk 0 0:=ha.symm;have e2:m=0:=hm.symm;have e3:Q=0:=by rw[<-hQ];simp only[lnQ, ↓reduceIte,Rat.cast_zero] subst e1;obtain ⟨-,fE,m2,m3,-,-⟩:=qG1 n hnR1 hnR2 0 0 ind nf _ em 0 0 c hc z1 z1 ג ו (by rw[z2,sub_self,abs_zero];exact Ἆ (Ἆ zero_le_two (Ἔ n)) (Ἆ (div_nonneg zero_le_one (pow_nonneg zero_le_two 53)) (add_nonneg le_rfl hz0))) (by rw[z2,sub_self,abs_zero];exact Ἆ (Ἆ zero_le_two (Ἔ n)) (Ἆ (div_nonneg zero_le_one (pow_nonneg zero_le_two 53)) (add_nonneg le_rfl hz0))) fnf Rnf fi pi ei rfl hem;rw[e2,e3,z2];refine ⟨z1,fE,m2,m3,?_,by (norm_num1)⟩;simp only[sub_zero,abs_zero,mul_zero];exact ὂ ו m3 | false=> replace ha:lnSum x base nu 0 0 0=a:=ha;replace hm:a.s*ind=m:=hm;have hA:a=⟨A_fsum ((ἄ n).map g),A_fsum ((ἄ n).map λj=>(g j).abs)⟩:=by rw[<-ha,qG9 x hxs base nu (by rw[hb,hu];exact hmul.trans_lt hrn) n 0 0 0 (by simp only[USize.toNat_zero,zero_add,hu])];simp only[USize.toNat_zero,hb,<-hgd,A_fsum,ὗ] subst hA;rw[hQ.symm.trans hMc];exact qG1 n hnR1 hnR2 _ _ ind nf m em S Sa c hc o1 o2 o3 o4 o5 o6 fnf Rnf fi pi ei hm hem obtain ⟨p1,p2,p3,hW0⟩:=qGp n hn hn0 g m v _ (by rw[<-hv,qG2 x hxs base nu m (by rw[hb,hu];exact hmul.trans_lt hrn) n 0 0 (by simp only[USize.toNat_zero,zero_add,hu])] simp only[USize.toNat_zero,hb,<-hgd,A_fsum,ὗ]) rfl (λj h=>⟨(hg0 j h).1,(hg0 j h).2.1⟩) fm m4 generalize hW:((ἄ n).map λj=>(R (g j)-R m)^2).sum=W at p2 p3 hW0;generalize hV0:((ἄ n).map λj=>(R (g j)-Q)^2).sum=V0 at hVc;generalize hδ:Q-R m=δ at m1;have hnpos:(0:ℝ) have e2:m=0:=hm.symm;have e3:Q=0:=by rw[<-hQ];simp only[lnQ, ↓reduceIte,Rat.cast_zero] rw[<-hδ,<-hW,<-hV0,e2,e3,z2];simp only[sub_zero,sub_self,ne_eq,OfNat.ofNat_ne_zero,not_false_eq_true,zero_pow,add_zero] | false=>have hs2:=qGh (ἄ n) (λj=>R (g j)) (R m) (by rw[List.length_range];exact hnp);simp only[List.length_range] at hs2;rw[hS,hW,show S/n=Q from (hQ.symm.trans hMc).symm,hV0,hδ] at hs2;rw[hs2,add_div,mul_div_cancel_left₀ _ hnp] obtain ⟨gE,bE⟩:=qA1 eps he;have epsv:wv eps=(ἂ eps:ℝ):=qAx _ (qAe _ gE);have hep0:0?_) hnpos.le;obtain ⟨j,-,rfl⟩:=List.mem_map.1 hy;exact ὅ _ have hT:(q:ℝ)=(W/n+wv eps)-δ^2:=by rw[<-hq,Rat.cast_add,hVc,epsv,hWs];ring have hT0:(0:ℝ)⟨fm,fi2,fE,m2,m3,?_,m4,gZ,qIb z gZ c2 c3,ei2⟩⟩;dsimp only;rw[hQ,hδ];exact m1 . exact ⟨rfl,λh=>Bool.noConfusion h⟩ lemma qI0b (m ir em:ὧ) (w gw bw:Ὢ) (M D:ℝ) (fm:m.isFinite=true) (fi:ir.isFinite=true) (fe:em.isFinite=true) (e1:R em<=2^120) (e2:1/2^201<=R em) (e3:2* |M-R m| <=R em) (e4: |R m| <=2^110) (hD:1/2^64<=D) (hI: |R ir*D-1| <=1/2^48) (hw:sm w=true) (hg:sm gw=true) (hb:sm bw=true) (s e:ὧ) (hs:s=(dv w-m)*(dv gw*ir)+dv bw) (he:e=Ἃ 0x3D10000000000000*(((dv w-m)*(dv gw*ir)).abs+(dv bw).abs)+em*(dv gw*ir).abs) (big0:(2:ℝ)^(-127:ℤ)<= |R (s+e)|): R (s-e)<(wv w-M)*wv gw/D+wv bw/\(wv w-M)*wv gw/D+wv bw(2:ℝ)^k<=2^256*2^44:=λh=>(pow_le_pow_right₀ one_le_two h).trans_eq (pow_add 2 256 44) have e2pf:∀{x P:ℝ},x<=9/8*P+A_z->1<=P->x<=2^2*P:=λ{x P} h h1=>h.trans ((add_le_add (ἀ (by norm_num1:(9:ℝ)/8<=3) (zero_le_one.trans h1)) (qBo.trans h1)).trans ((add_one_mul (3:ℝ) P).symm.trans (congrArg (·*P) (by norm_num1:(3:ℝ)+1=2^2))).le) have e2pk:∀{x:ℝ} {a k:ℕ},x<=9/8*((2:ℝ)^a+2^a)+A_z->2+(a+1)<=k->x<=2^k:=λ{x a k} h hk=>(e2pf (h.trans_eq (congrArg (λP:ℝ=>9/8*P+A_z) ((two_mul _).symm.trans (pow_succ' 2 a).symm))) (one_le_pow₀ one_le_two)).trans ((pow_add 2 2 (a+1)).symm.trans_le (pow_le_pow_right₀ one_le_two hk)) have e2pm:∀{x:ℝ} {a b k:ℕ},x<=9/8*((2:ℝ)^a*2^b)+A_z->2+(a+b)<=k->x<=2^k:=λ{x a b k} h hk=>(e2pf (h.trans_eq (congrArg (λP:ℝ=>9/8*P+A_z) (pow_add 2 a b).symm)) (one_le_pow₀ one_le_two)).trans ((pow_add 2 2 (a+b)).symm.trans_le (pow_le_pow_right₀ one_le_two hk)) have e2p1:∀{x:ℝ} {b k:ℕ},x<=9/8*(1*(2:ℝ)^b)+A_z->2+b<=k->x<=2^k:=λ{x b k} h hk=>(e2pf (h.trans_eq (congrArg (λP:ℝ=>9/8*P+A_z) (one_mul _))) (one_le_pow₀ one_le_two)).trans ((pow_add 2 2 b).symm.trans_le (pow_le_pow_right₀ one_le_two hk)) have hzb:=qBo obtain ⟨gw1,bw1⟩:=qA1 w hw obtain ⟨gg1,bg1⟩:=qA1 gw hg obtain ⟨gb1,bb1⟩:=qA1 bw hb obtain ⟨fw,Rw⟩:=qAm w gw1 obtain ⟨fg,Rg⟩:=qAm gw gg1 obtain ⟨fb,Rb⟩:=qAm bw gb1 have hD0:0simp only[false_eq_true, ↓reduceIte,zero_eq_neg] at hVW<;>linarith only[hW0,hVW] have hf:=Model.isFinite_roundRatScaled_of_abs_le_posMaxFinite Fmt (decide (q<0)) q.num.natAbs q.den 0 ה q.den_nz (qFn q▸hb.trans qIx) have hMr:=Model.toReal_roundRatScaled_eq_roundAt Fmt _ _ _ 0 ה hf rw[hz] exact qDqW S ex fr h1 h2 h3 (q:ℝ) W hVW a b c _ hf (qFn q▸hMr) lemma qSubE (x y:ὧ) (hx:xᶠ) (hy:yᶠ) (h1: |R x| <=A_B) (h2: |R y| <=A_B):(x-y)ᶠ /\R (x-y)=Model.roundAt ⟡ (R x-R y):= A_E _ (toModel_ofFloat_sub_of_isFinite x y hx hy) (Model.isFinite_sub_of_abs_add_le_posMaxFinite _ _ qAj (qA3 hx) (qA3 hy) (qEe h1 h2)) (Model.toReal_sub_eq_roundAt_of_abs_add_le_posMaxFinite _ _ qAj (qA3 hx) (qA3 hy) (qEe h1 h2)) lemma rAbs (x:ℝ): |Model.roundAt ⟡ x| =Model.roundAt ⟡ |x| :=by rcases le_or_gt 0 x with h|h . rw[ἅ h,ἅ];rw[<-Model.roundAt_zero ⟡];exact Model.roundAt_mono _ h . rw[abs_of_neg h,abs_of_nonpos];. rw[Model.roundAt_neg ⟡ x .nearest];rfl . rw[<-Model.roundAt_zero ⟡];exact Model.roundAt_mono _ h.le lemma rUp (y:ℝ) (h:0<=y):Model.roundAt ⟡ y<=2*y+1:=by have e:=qFp y have hz:A_z<=1:=by show (2:ℝ)^(-1021:ℤ)<=1;exact zpow_le_one_of_nonpos₀ ב ב rw[ἅ h] at e have:=le_abs_self (Model.roundAt ⟡ y-y) linarith only[e,this,hz,h] set_option maxRecDepth 8192 in lemma mMul (a b c d:ὧ) (fa:aᶠ) (fb:bᶠ) (fc:cᶠ) (fd:dᶠ) (ha: |R a| <=R c) (hb: |R b| <=R d) (Bc Bd:ℝ) (hc:R c<=Bc) (hd:R d<=Bd) (hB:Bc*Bd<=2^256*2^256*2^256): (a*b)ᶠ /\(c*d)ᶠ /\ |R (a*b)| <=R (c*d)/\R (c*d)<=2*(Bc*Bd)+1:=by have pc:0<=R c:=(Ἀ _).trans ha have pd:0<=R d:=(Ἀ _).trans hb have k9:(2:ℝ)^256*2^256*2^256<=2^(1000:ℤ):=by rw[<-pow_add,<-pow_add,<-Ἡ];exact ἒ ב ב have hcd:R c*R d<=Bc*Bd:=ἑ hc hd pd (pc.trans hc) obtain ⟨f1,R1⟩:=qEd a b fa fb ((ἑ ha hb (Ἀ _) pc).trans (hcd.trans (hB.trans k9))) obtain ⟨f2,R2⟩:=qEd c d fc fd (by rw[ἅ pc,ἅ pd];exact hcd.trans (hB.trans k9)) refine ⟨f1,f2,?_,?_⟩ . rw[R1,R2,rAbs,ἢ];exact Model.roundAt_mono _ (ἑ ha hb (Ἀ _) pc) . rw[R2];exact (rUp _ (Ἆ pc pd)).trans (by linarith only[hcd]) set_option maxRecDepth 8192 in lemma mAdd (a b c d:ὧ) (fa:aᶠ) (fb:bᶠ) (fc:cᶠ) (fd:dᶠ) (ha: |R a| <=R c) (hb: |R b| <=R d) (Bc Bd:ℝ) (hc:R c<=Bc) (hd:R d<=Bd) (hB:Bc+Bd<=2^256*2^40): (a+b)ᶠ /\(c+d)ᶠ /\ |R (a+b)| <=R (c+d)/\R (c+d)<=2*(Bc+Bd)+1:=by have pc:0<=R c:=(Ἀ _).trans ha have pd:0<=R d:=(Ἀ _).trans hb have k1:Bc<=2^256*2^44:=by linarith only[hB,pc,pd,hc,hd] have k2:Bd<=2^256*2^44:=by linarith only[hB,pc,pd,hc,hd] obtain ⟨f1,R1⟩:=qAddE a b fa fb (qAt (ha.trans (hc.trans k1))) (qAt (hb.trans (hd.trans k2))) obtain ⟨f2,R2⟩:=qAddE c d fc fd (qAt (by rw[ἅ pc];exact hc.trans k1)) (qAt (by rw[ἅ pd];exact hd.trans k2)) refine ⟨f1,f2,?_,?_⟩ . rw[R1,R2,rAbs];exact Model.roundAt_mono _ ((Ἐ _ _).trans (add_le_add ha hb)) . rw[R2];exact (rUp _ (add_nonneg pc pd)).trans (by linarith only[hc,hd]) set_option maxRecDepth 8192 in lemma mSub (a b c d:ὧ) (fa:aᶠ) (fb:bᶠ) (fc:cᶠ) (fd:dᶠ) (ha: |R a| <=R c) (hb: |R b| <=R d) (Bc Bd:ℝ) (hc:R c<=Bc) (hd:R d<=Bd) (hB:Bc+Bd<=2^256*2^40): (a-b)ᶠ /\(c+d)ᶠ /\ |R (a-b)| <=R (c+d)/\R (c+d)<=2*(Bc+Bd)+1:=by have pc:0<=R c:=(Ἀ _).trans ha have pd:0<=R d:=(Ἀ _).trans hb have k1:Bc<=2^256*2^44:=by linarith only[hB,pc,pd,hc,hd] have k2:Bd<=2^256*2^44:=by linarith only[hB,pc,pd,hc,hd] obtain ⟨f1,R1⟩:=qSubE a b fa fb (qAt (ha.trans (hc.trans k1))) (qAt (hb.trans (hd.trans k2))) obtain ⟨f2,R2⟩:=qAddE c d fc fd (qAt (by rw[ἅ pc];exact hc.trans k1)) (qAt (by rw[ἅ pd];exact hd.trans k2)) refine ⟨f1,f2,?_,?_⟩ . rw[R1,R2,rAbs];exact Model.roundAt_mono _ ((Ὕ _ _).trans (add_le_add ha hb)) . rw[R2];exact (rUp _ (add_nonneg pc pd)).trans (by linarith only[hc,hd]) set_option maxRecDepth 8192 in lemma qLmo (m ir em xm gm bm:ὧ) (w gw bw:Ὢ) (fm:mᶠ) (fi:irᶠ) (fe:emᶠ) (fxm:xmᶠ) (fgm:gmᶠ) (fbm:bmᶠ) (hw:sm w=true) (hg:sm gw=true) (hb:sm bw=true) (pir:0 |R (dv A[k]!)| <=R (dv (scan A A.usize 0 (qAc A) Е 0)):=by unfold smA at h;simp only[Bool.and_eq_true,bne_iff_ne,ne_eq,decide_eq_true_eq] at h obtain ⟨h1,h2⟩:=h obtain ⟨g1,g2,g3,g4⟩:=qBi A hs h1 have hsm:sm (scan A A.usize 0 (qAc A) Е 0)=true:=by unfold sm;simp only[Bool.and_eq_true,decide_eq_true_eq];exact ⟨g1,UInt32.le_trans UInt32.and_le_left h2⟩ obtain ⟨-,b99⟩:=qA1 _ hsm obtain ⟨f,Rf⟩:=qAm _ g1 obtain ⟨p0,-,mono⟩:=qCs g1 g2 refine ⟨f,?_,λk hk=>?_⟩ . rw[Rf];exact (le_abs_self _).trans b99 . obtain ⟨-,Rk⟩:=qAm _ (g3 k hk);rw[Rk,Rf];exact mono _ (g3 k hk) (g4 k hk) set_option maxRecDepth 8192 in lemma qUb (E s:ὧ) (h1:(s.toBits<<<(1:Ὠ))-loOf Esimp only[Bool.false_eq_true,ite_false,ite_true,one_mul,neg_mul,abs_neg,ἢ,ἡ p]<;>rw[ἅ ו]<;>exact q5 set_option maxRecDepth 8192 in lemma qEkF (s:LnS) (M:ℚ) (mean:Unit->ℚ) (hmean:mean ()=M) (w gw bw:Ὢ) (hw:sm w=true) (hg:sm gw=true) (hb:sm bw=true) (h:L_oF s (M:ℝ)) (xm gm bm:ὧ) (fxm:xmᶠ) (fgm:gmᶠ) (fbm:bmᶠ) (hxm: |R (dv w)| <=R xm) (hgm: |R (dv gw)| <=R gm) (hbm: |R (dv bw)| <=R bm) (bxm:R xm<=2^99) (bgm:R gm<=2^99) (bbm:R bm<=2^99): lnOut s (loOf (lnEB s xm gm bm)) w gw bw mean=roundRational ((ἂ w-M)*ἂ gw/ἂ s.den+ἂ bw):=by unfold lnOut lnOutF split . rename_i hf;obtain ⟨fm,fi,fe,e1,e2,e3,e4,gd,hD,hI⟩:=h hf have ew:=qAx w (qAe _ (qA1 w hw).1);have eg:=qAx gw (qAe _ (qA1 gw hg).1);have eb:=qAx bw (qAe _ (qA1 bw hb).1);have ed:=qAx s.den (qAe _ gd);have hV:(((ἂ w-M)*ἂ gw/ἂ s.den+ἂ bw:ℚ):ℝ)=(wv w-M)*wv gw/wv s.den+wv bw:=by rw[ew,eg,eb,ed];push_cast;ring unfold lnFa;dsimp only;split . split;. unfold lnSlow;rw[hmean] . rename_i _ hc have hne:ziv ((dv w-s.m)*(dv gw*s.ir)+dv bw) (Ἃ 0x3D10000000000000*(((dv w-s.m)*(dv gw*s.ir)).abs+(dv bw).abs)+s.em*(dv gw*s.ir).abs)≠Е:=λe0=>by rw[e0] at hc exact hc ה obtain ⟨l1,l2⟩:=qI0b s.m s.ir s.em w gw bw M (wv s.den) fm fi fe e1 e2 e3 e4 hD hI hw hg hb _ _ rfl rfl (qBw _ _ hne).2.2 rw[<-hV] at l1 l2;exact (qH7 _ _ _ l1 l2 hne (qIu _ _ _ l1 l2 hne hc)).symm . rename_i hne have key:fin1 (loOf (lnEB s xm gm bm)) (spOf (loOf (lnEB s xm gm bm))) ((dv w-s.m)*(dv gw*s.ir)+dv bw)≠Е:=by simpa only[ne_eq,beq_iff_eq] using hne unfold fin1 at key⊢ dsimp only at key⊢ split at key . rename_i ht simp only[Bool.and_eq_true,decide_eq_true_eq] at ht obtain ⟨h1,h2⟩:=ht rw[Ὦ (by simp only[Bool.and_eq_true,decide_eq_true_eq];exact ⟨h1,h2⟩)] have hD0:0α) (hk:kf r.val)[k]! =f k:=by rw[Ἕ _ k (by simpa only[Array.size_ofFn] using hk),Array.getElem_ofFn] lemma qMf (f:Ὣ->Ὢ) (L:љ) (a:ℤ): L.foldl (λt j=>t+ἂ (f j)) ((a:ℚ)/2^149)=((L.foldl (λt j=>t+sv (f j)*((2^idxOf (f j):ℕ):ℤ)) a:ℤ):ℚ)/2^149:=by induction L generalizing a with | nil=>rfl | cons p L ih=> simp only[ὔ] rw[<-ih] congr 1 have e:ἂ (f p)=(sv (f p):ℚ)*2^((idxOf (f p):ℤ)-149):=by rw[rationalWord,decodeD_toRat] rw[e,ᾂ (by (positivity):(2:ℚ)≠0),Ἡ] push_cast ring lemma qMq (n:Ὣ) (x:ё) (r:Ὣ):meanQ n x r=rowMean n x r:=by have h:=qMf (λj=>x[r*n+j]!) (ἄ n) 0 simp only[Int.cast_zero,zero_div] at h unfold meanQ;rw[meanIF_eq];unfold meanI rowMean rw[h] by_cases c:(n:ℚ)=0 . simp only[Nat.cast_pow,Nat.cast_ofNat,Nat.reducePow,Nat.cast_mul,c,mul_zero,div_zero] . push_cast;rw[div_div];norm_num lemma qGD {A:ё} {n:ὦ} (hs:ѧA<2^32) (d:Ὣ): ∀(t:ὦ) (o:ὤ),Ѥt+d=Ѥn->(Ѥn<=Ѩo/\Ѩo<2^32)->(∀k,k< Ѥt->o.data[k]! =dv A[k]!)-> (Ѥn<=(decG A n t o).size/\(decG A n t o).size<2^32)/\∀k,k< Ѥn->(decG A n t o).data[k]! =dv A[k]!:=by induction d with | zero=> intro t o he H1 H2 rw[decG,ἔ (by rw[А];(clear hs H1;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))))] have e:Ѥt=Ѥn:=(by exact omS155 he) rw[e] at H2 exact ⟨H1,H2⟩ | succ d ih=> intro t o he H1 H2 have ht:tby rw[C_z] at hk;(clear hs hn hu ek P0;omega)) rw[ek] at D1 D3 generalize decG A ѩn 0 (zFor n)=a at D1 D2 D3⊢ have h:uℚ):lnOutF s lo w gw bw gv bv mean=lnFa s.m s.ir s.em s.den w gw bw gv bv lo mean:=by unfold lnOutF;rw[ἱ h] lemma lnRF_eq {rows:Ὣ} {x g b:ё} {G B G0 B0:ὤ} {s:LnS} {mean:Unit->ℚ} {lo:Ὠ} {base n:ὦ} (hf:s.fast=true) (hG:∀u:ὦ,Ѥu<Ѥn->rdF G u=gdR rows g G0 u) (hB:∀u:ὦ,Ѥu<Ѥn->rdF B u=gdR rows b B0 u) (k:Ὣ): ∀(j:ὦ) (o:ё),Ѥj+k=Ѥn->lnRF x g b G B s.m s.ir s.em s.den mean lo (spOf lo) base n j o= fC (λs p j=>lnOutF s.1 s.2.2 (rdW x p) (rdW g j) (rdW b j) (gdR rows g G0 j) (gdR rows b B0 j) s.2.1) (s,mean,lo) base j o k:=by induction k with | zero=> intro j o e rw[lnRF,ἔ (by rw[А];(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))),fC] | succ k ih=> intro j o e have hj:jℚ} {lo:Ὠ} {base n:ὦ} (hf:s.fast=false) (k:Ὣ): ∀(j:ὦ) (o:ё),Ѥj+k=Ѥn->lnRS x g b s.den mean base n j o= fC (λs p j=>lnOutF s.1 s.2.2 (rdW x p) (rdW g j) (rdW b j) (gdR rows g G0 j) (gdR rows b B0 j) s.2.1) (s,mean,lo) base j o k:=by have e:∀(w gw bw:Ὢ) (gv bv:ὧ),lnOutF s lo w gw bw gv bv mean=lnSlow w gw bw s.den mean:=by intro w gw bw gv bv;unfold lnOutF;rw[ἐ (by rw[hf];decide)] induction k with | zero=> intro j o e rw[lnRS,ἔ (by rw[А];(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))),fC] | succ k ih=> intro j o e' have hj:jrdF G u=gdR rows g G0 u) (hB:∀u:ὦ,ѤurdF B u=gdR rows b B0 u) (d:Ὣ): ∀(r:Ὣ) (o:ё),lnRows x g b G B eps xm gm bm n r o d=fR (λr=>(lnStat false n eps x r,λ_:Unit=>meanQ n x r,loOf (lnEB (lnStat false n eps x r) xm gm bm))) (λs p j=>lnOutF s.1 s.2.2 (rdW x p) (rdW g j) (rdW b j) (gdR rows g G0 j) (gdR rows b B0 j) s.2.1) n r o d:=by have hu:(ѩn:ὦ).toNat=n:=qAd n hn induction d with | zero=>intro r o;rfl | succ d ih=> intro r o rw[lnRows,fR,ih] try dsimp only congr 1 split . rename_i hf exact lnRF_eq hf (λu h=>hG u (by rw[hu] at h;exact h)) (λu h=>hB u (by rw[hu] at h;exact h)) n 0 o (by rw[hu];simp only[USize.toNat_zero,zero_add]) . rename_i hf exact lnRS_eq (by simpa only[Bool.not_eq_true] using hf) n 0 o (by rw[hu];simp only[USize.toNat_zero,zero_add]) lemma lnDecB_dat (x:ё) (base n:ὦ) (hs:Ѥbase+Ѥn<2^32) (hxs:ѧx<2^32) (k:Ὣ): ∀(j:ὦ) (buf:ὤ) (t s:ὧ),Ѥn+1< Ѩbuf-> Ѩbuf<2^32-> Ѥj+k=Ѥn-> ∀q,q< Ѥn->(lnDecB x base n j buf t s).data[q]! =if Ѥj<=q then dv x[Ѥbase+q]! else buf.data[q]!:=by induction k with | zero=> intro j buf t s hb hbs e q hq have e1:=uS1 n א rw[lnDecB,ἔ (by rw[А];exact omS404 e),qEt _ _ _ _ (by rw[qD6];exact hbs) (by rw[qD6,e1];exact hb),ἐ (by rw[e1];omega),qEt _ _ _ _ hbs א,ἐ א,ἐ א] | succ k ih=> intro j buf t s hb hbs e q hq have hj:j Ѩbuf<2^32-> Ѥj+k=Ѥn->(lnDecB x base n j buf t s).data[Ѥn]! =(lnSum x base n j s t).t:=by induction k with | zero=> intro j buf s t hb hbs e have e1:=uS1 n א rw[lnDecB,lnSum,ἔ (by rw[А];exact omS404 e),ἔ (by rw[А];exact omS404 e),qEt _ _ _ _ (by rw[qD6];exact hbs) (by rw[qD6,e1];exact hb),ἐ (by rw[e1];omega),qEt _ _ _ _ hbs א,ἱ rfl] | succ k ih=> intro j buf s t hb hbs e have hj:j Ѩbuf<2^32-> Ѥj+k=Ѥn->(lnDecB x base n j buf t s).data[Ѥn+1]! =(lnSum x base n j s t).s:=by induction k with | zero=> intro j buf s t hb hbs e have e1:=uS1 n א rw[lnDecB,lnSum,ἔ (by rw[А];exact omS404 e),ἔ (by rw[А];exact omS404 e),qEt _ _ _ _ (by rw[qD6];exact hbs) (by rw[qD6,e1];exact hb),ἱ (by rw[e1])] | succ k ih=> intro j buf s t hb hbs e have hj:jbuf.data[q]! =dv x[Ѥbase+q]!) (m:ὧ) (k:Ὣ): ∀(j:ὦ) (v:ὧ),Ѥj+k=Ѥn->lnVarB buf n j m v hb=lnVar x base n j m v:=by induction k with | zero=> intro j v e rw[lnVarB,lnVar,ἔ (by rw[А];exact omS404 e),ἔ (by rw[А];exact omS404 e)] | succ k ih=> intro j v e have hj:jbuf.data[q]! =dv x[r*n+q]!) (ht:buf.data[n]! =(lnSum x ((r*n).toUSize) ѩn 0 0 0).t) (hs2:buf.data[n+1]! =(lnSum x ((r*n).toUSize) ѩn 0 0 0).s): lnStatB n eps x r (oneF/n.toUInt64.toFloat) (invOK (oneF/n.toUInt64.toFloat) n.toUInt64.toFloat) buf hb hbs=lnStat false n eps x r:=by have e1:Ѥ(ѩn)=n:=qAd n א have e2:Ѥ((r*n).toUSize)=r*n:=qAd _ א have hs':Ѥ((r*n).toUSize)+Ѥ(ѩn)<2^32:=by rw[e1,e2];exact hs have hc':∀q,q< Ѥ(ѩn)->buf.data[q]! =dv x[Ѥ((r*n).toUSize)+q]!:=λq h=>by rw[e2];exact hc q (by rw[e1] at h;exact h) have e3:Ѥ(ѩ(n+1))=n+1:=qAd (n+1) א unfold lnStatB lnStat oneF simp only[Bool.false_eq_true,ite_false,qC5,e1,e3,ht,hs2] rw[lnVarB_eq x buf _ _ (by rw[e1];omega) hs' hxs hc' _ (Ѥ(ѩn)) 0 0 (by simp only[USize.toNat_zero,Nat.toUSize_eq,USize.toNat_ofNat',zero_add])] lemma lnRB_eq (x g b:ё) (buf G B:ὤ) (m ir em:ὧ) (den:Ὢ) (nN rR:Ὣ) (lo sp:Ὠ) (base n:ὦ) (hb:Ѥn<=Ѩbuf) (hG:Ѥn<=ѨG) (hB:Ѥn<=ѨB) (hs:Ѥbase+Ѥn<2^32) (hxs:ѧx<2^32) (hGs:ѨG<2^32) (hBs:ѨB<2^32) (hc:∀q,q< Ѥn->buf.data[q]! =dv x[Ѥbase+q]!) (k:Ὣ): ∀(j:ὦ) (o:ё),Ѥj+k=Ѥn->lnRB x g b buf G B m ir em den nN rR lo sp base n j o hb hG hB=lnRF x g b G B m ir em den (λ_=>meanQ nN x rR) lo sp base n j o:=by induction k with | zero=> intro j o e rw[lnRB,lnRF,ἔ (by rw[А];exact omS404 e),ἔ (by rw[А];exact omS404 e)] | succ k ih=> intro j o e have hj:jmeanQ nN x rR):=by unfold lnFb lnFvM lnSlowM rdF dsimp only rw[Ἄ p3,Ἄ p4,qC5,hc _ hj1,qAg x _ hxs,qAf base j א] rw[lnRB,lnRF,Ἄ hj,Ἄ hj,ev,ih (j+1) _ (by rw[usz j n hj];exact omS137 e)] lemma lnRowsB_eq (x g b:ё) (G B:ὤ) (eps:Ὢ) (xm gm bm:ὧ) (n:Ὣ) (d:Ὣ): ∀(r:Ὣ) (buf:ὤ) (o:ё),lnRowsB x g b G B eps xm gm bm n (oneF/n.toUInt64.toFloat) (invOK (oneF/n.toUInt64.toFloat) n.toUInt64.toFloat) r buf o d=lnRows x g b G B eps xm gm bm n r o d:=by induction d with | zero=>intro r buf o;rfl | succ d ih=> intro r buf o rw[lnRowsB,lnRows] simp only[lnRSM,lnRFM] split . rename_i h obtain ⟨h1,h2,h3,h3',h4,h4',h5,h6⟩:=h have e1:Ѥ(ѩn)=n:=qAd n א have e2:Ѥ((r*n).toUSize)=r*n:=qAd _ א have hbs:Ѩbuf<2^32:=א have hxs:ѧx<2^32:=א have hs':Ѥ((r*n).toUSize)+Ѥ(ѩn)<2^32:=by rw[e1,e2];omega have hc:∀q,q(lnDecB x ((r*n).toUSize) ѩn 0 buf 0 0).data[q]! =dv x[r*n+q]!:=λq hq=>by rw[lnDecB_dat x _ _ hs' hxs (Ѥ(ѩn)) 0 buf 0 0 (by rw[e1];omega) hbs (by simp only[USize.toNat_zero,Nat.toUSize_eq,USize.toNat_ofNat',zero_add]) q (by rw[e1];exact hq),ἱ (by simp only[USize.toNat_zero,zero_le]),e2] have hc':∀q,q< Ѥ(ѩn)->(lnDecB x ((r*n).toUSize) ѩn 0 buf 0 0).data[q]! =dv x[Ѥ((r*n).toUSize)+q]!:=λq hq=>by rw[e2];exact hc q (by rw[e1] at hq;exact hq) have ht:(lnDecB x ((r*n).toUSize) ѩn 0 buf 0 0).data[n]! =(lnSum x ((r*n).toUSize) ѩn 0 0 0).t:=by have:=lnDecB_t x ((r*n).toUSize) ѩn (Ѥ(ѩn)) 0 buf 0 0 (by rw[e1];omega) hbs (by simp only[USize.toNat_zero,Nat.toUSize_eq,USize.toNat_ofNat',zero_add]);rw[e1] at this;exact this have hs2:(lnDecB x ((r*n).toUSize) ѩn 0 buf 0 0).data[n+1]! =(lnSum x ((r*n).toUSize) ѩn 0 0 0).s:=by have:=lnDecB_s x ((r*n).toUSize) ѩn (Ѥ(ѩn)) 0 buf 0 0 (by rw[e1];omega) hbs (by simp only[USize.toNat_zero,Nat.toUSize_eq,USize.toNat_ofNat',zero_add]);rw[e1] at this;exact this simp only[lnDecC_eq] try dsimp only rw[lnStatB_eq n eps x r _ (by rw[lnDecB_sz0];omega) (by rw[lnDecB_sz0];omega) א hxs hc ht hs2,ih] congr 1 split . rw[lnRB_eq x g b _ G B _ _ _ _ _ _ _ _ _ ѩn _ _ _ hs' hxs א א hc' (Ѥ(ѩn)) 0 o (by simp only[USize.toNat_zero,Nat.toUSize_eq,USize.toNat_ofNat',zero_add])] . rfl . rw[ih] lemma rmsRF_eq {rows:Ὣ} {x g:ё} {G:ὤ} {s:LnS} {lo:Ὠ} {base n:ὦ} (hf:s.fast=true) (k:Ὣ): ∀(j:ὦ) (o:ё),Ѥj+k=Ѥn->rmsRF rows x g G s.m s.ir s.em s.den lo (spOf lo) base n j o= fC (λs p j=>let w:=rdW x p if w&&&В==0 then 0 else lnOutF s.1 s.2 w (rdW g j) 0 (gdR rows g G j) (dv 0) λ_=>0) (s,lo) base j o k:=by induction k with | zero=> intro j o e rw[rmsRF,ἔ (by rw[А];(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))),fC] | succ k ih=> intro j o e have hj:j(lnStat true n eps x r,loOf (lnEB (lnStat true n eps x r) xm gm (dv 0)))) (λs p j=>let w:=rdW x p if w&&&В==0 then 0 else lnOutF s.1 s.2 w (rdW g j) 0 (gdR rows g G j) (dv 0) λ_=>0) n r o d:=by have hu:(ѩn:ὦ).toNat=n:=qAd n hn induction d with | zero=>intro r o;rfl | succ d ih=> intro r o rw[rmsRows,fR,ih] try dsimp only congr 1 split . rename_i hf exact rmsRF_eq hf n 0 o (by rw[hu];simp only[USize.toNat_zero,zero_add]) . rfl lemma qGc:lnF=layernormSpec:=by funext rows n eps x g b;unfold lnF;rw[(lnGet n g b).2];unfold lnFq;try simp only[] simp only[lnRowsB_eq] split . rename_i hc;simp only[Bool.and_eq_true,beq_iff_eq] at hc;obtain ⟨⟨h0',h2⟩,hb'⟩:=hc;have h0:normOK rows n eps x g=true:=h0';have hb:smA b=true:=hb';obtain ⟨hD,h4,h5,h7,h8,h9⟩:=qNO h0;obtain ⟨h6,h3⟩:=qSm b (by (clear h9;exact omS362 h2 h8)) hb;have hs:(stableNormDomain rows n eps x g&& ѧb==n&&b.all finiteWord)=true:=by simp only[Bool.and_eq_true,beq_iff_eq];exact ⟨⟨hD,h2⟩,h3⟩ unfold layernormSpec layernormWith;rw[ἱ hs];unfold layernormStable;dsimp only;unfold stableNormDomain at hD;simp only[Bool.and_eq_true,beq_iff_eq,gt_iff_lt,decide_eq_true_eq] at hD;obtain ⟨⟨⟨⟨⟨⟨⟨h10,h11⟩,h12⟩,h13⟩,-⟩,-⟩,-⟩,h14⟩:=hD have hsx:smA x=true:=by unfold normOK at h0;simp only[Bool.and_eq_true] at h0;exact h0.1.1.1.1.2 have hsg:smA g=true:=by unfold normOK at h0;simp only[Bool.and_eq_true] at h0;exact h0.1.1.1.2 obtain ⟨fxm,bxm,hxm⟩:=qSmx x (by rw[h12];exact h9) hsx obtain ⟨fgm,bgm,hgm⟩:=qSmx g (by rw[h13];(clear h9 h12 h10;exact omS363 h8)) hsg obtain ⟨fbm,bbm,hbm⟩:=qSmx b (by rw[h2];(clear h9 h12 h10;exact omS363 h8)) hb rw[lnRows_eq (G0:=gdF rows g n) (B0:=gdF rows b n) (by (exact Nat.lt_of_lt_of_le ‹_› ה)) (λu hu=>(qGR (by (clear h9 h12 h10 hu;omega)) (by (exact Nat.lt_of_lt_of_le ‹_› ה)) u hu).trans (qGS (by (clear h9 h12 h10 hu;omega)) (by (exact Nat.lt_of_lt_of_le ‹_› ה)) u hu).symm) (λu hu=>(qGR (by (clear h9 h12 h10 hu;exact omS362 h2 h8)) (by (exact Nat.lt_of_lt_of_le ‹_› ה)) u hu).trans (qGS (by (clear h9 h12 h10 hu;exact omS362 h2 h8)) (by (exact Nat.lt_of_lt_of_le ‹_› ה)) u hu).symm)] simp only[qMq] rw[qDb (λr c q=>lnOut (lnStat false n eps x r) (loOf (lnEB (lnStat false n eps x r) (dv (scan x x.usize 0 (qAc x) Е 0)) (dv (scan g g.usize 0 (qAc g) Е 0)) (dv (scan b b.usize 0 (qAc b) Е 0)))) x[q]! g[c]! b[c]! λ_=>rowMean n x r) h9 h11 λr p u hr hp hu=>by rw[qGS (by clear h9 h12 h10 hr hp hu;omega) (by exact Nat.lt_of_lt_of_le ‹_› ה) u hu,qGS (by clear h9 h12 h10 hr hp hu;exact omS362 h2 h8) (by exact Nat.lt_of_lt_of_le ‹_› ה) u hu] repeat rw[qAg _ _ (by clear h10 hr hp hu;omega)] rfl] apply Մ ג;intro q h1 h1';simp only[Array.getElem_ofFn,Array.size_ofFn] at h1 h1'⊢;have hr:q/nrowMean n x r) hr have e3:=qBp rows (q/n) (λr=>sqrtRational (rowVariance n x r ((Array.ofFn (n:=rows) λr=>rowMean n x r.val)[r]!)+ἂ eps)) hr beta_reduce at e2 e3;rw[e3,e2];obtain ⟨o1,o2⟩:=qE1 false rows n eps x (q/n) hr h11 h8 h12 h9 h4 h7 h14;rw[qEkF _ (rowMean n x (q/n)) _ rfl _ _ _ (qBg x sm h4 q (by clear h2 h8 h9 h13 h10 h11 h1' hr hj e3 o1;exact omS140 h12 h1)) (qBg g sm h5 _ (by clear h2 h8 h9 h12 h10 h11 h1 h1' hr e3 o1;exact omS140 h13 hj)) (qBg b sm h6 _ (by clear h8 h9 h12 h10 h11 h1 h1' hr e3 o1;omega)) o2 _ _ _ fxm fgm fbm (hxm q (by clear h2 h8 h9 h13 h10 h11 h1' hr hj e3 o1;omega)) (hgm _ (by clear h2 h8 h9 h12 h10 h11 h1 h1' hr e3 o1;omega)) (hbm _ (by clear h8 h9 h12 h10 h11 h1 h1' hr e3 o1;exact omS140 h2 hj)) bxm bgm bbm,o1];rfl . rfl lemma qFf:rmsF=rmsnormSpec:=by funext rows n eps x g;unfold rmsF;rw[(rnGet g).2];unfold rmsFz;split . rename_i hc';have hc:normOK rows n eps x g=true:=hc';obtain ⟨hD,h4,h5,h7,h8,h9⟩:=qNO hc;unfold rmsnormSpec rmsnormWith;rw[ἱ hD];unfold rmsnormStable;dsimp only;unfold stableNormDomain at hD;simp only[Bool.and_eq_true,beq_iff_eq,gt_iff_lt,decide_eq_true_eq] at hD;obtain ⟨⟨⟨⟨⟨⟨⟨h10,h11⟩,h12⟩,h13⟩,-⟩,-⟩,-⟩,h14⟩:=hD have hsx:smA x=true:=by unfold normOK at hc;simp only[Bool.and_eq_true] at hc;exact hc.1.1.1.1.2 have hsg:smA g=true:=by unfold normOK at hc;simp only[Bool.and_eq_true] at hc;exact hc.1.1.1.2 obtain ⟨fxm,bxm,hxm⟩:=qSmx x (by rw[h12];exact h9) hsx obtain ⟨fgm,bgm,hgm⟩:=qSmx g (by rw[h13];(clear h9 h12 h10;exact omS363 h8)) hsg obtain ⟨f0,R0⟩:=qAm 0 ה have z0:R (dv 0)=0:=by rw[R0,qAx 0 (qAe _ ה)];exact_mod_cast qE6 0 ה rfl rw[rmsRows_eq (by (exact Nat.lt_of_lt_of_le ‹_› ה))] rw[qDb (λr c q=>if x[q]!&&&В==0 then 0 else lnOut (lnStat true n eps x r) (loOf (lnEB (lnStat true n eps x r) (dv (scan x x.usize 0 (qAc x) Е 0)) (dv (scan g g.usize 0 (qAc g) Е 0)) (dv 0))) x[q]! g[c]! 0 λ_=>0) h9 h11 λr p u hr hp hu=>by rw[qGS (by clear h9 h12 h10 hr hp hu;omega) (by exact Nat.lt_of_lt_of_le ‹_› ה) u hu] repeat rw[qAg _ _ (by clear h10 hr hp hu;omega)] rfl] apply Մ ג;intro q h1 h1';simp only[Array.getElem_ofFn,Array.size_ofFn] at h1 h1'⊢;have hr:q/nsqrtRational (rowVariance n x r 0+ἂ eps)) hr;beta_reduce at e3;rw[e3];have hw:=qBg x sm h4 q (by clear h8 h9 h13 h10 h11 h1' hr hj e3;exact omS140 h12 h1);split;. rename_i h0;rw[qE6 _ (qA1 _ hw).1 (by simpa only[beq_iff_eq] using h0),zero_mul,zero_div];rfl . obtain ⟨o1,o2⟩:=qE1 true rows n eps x (q/n) hr h11 h8 h12 h9 h4 h7 h14;rw[qEkF _ 0 _ rfl _ _ _ hw (qBg g sm h5 _ (by clear h8 h9 h12 h10 h11 h1 h1' hr e3 o1;exact omS140 h13 hj)) ה o2 _ _ _ fxm fgm f0 (hxm q (by clear h8 h9 h13 h10 h11 h1' hr hj e3 o1;omega)) (hgm _ (by clear h8 h9 h12 h10 h11 h1 h1' hr e3 o1;omega)) (by rw[z0,abs_zero]) bxm bgm (by rw[z0];norm_num),o1,qE6 0 ה rfl,sub_zero,add_zero];rfl . rfl end end D namespace C open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats FloatLib.Floats.ExecFloat.Binary open FloatLib.Numerics.Dyadic (signedSignificand toRat_eq_zero_iff add_toRat mul_toRat mulFields) open UInt64 (toNat_sub_of_le) open Bool (false_eq_true and_eq_true or_eq_true) open USize (toNat) open UInt32 (toNat) open UInt64 (toNat) open Array (size) open FloatArray (size) open Nat (toUSize) open UInt32 (toUSize) open Submission.D renaming Acc → Acc, Acc.total → Acc.total, Acc.add → Acc.add, dotStep → dotStep, dotLoop → dotLoop, Y_low → Y_low, dotFn → dotFn, rdW → rdW, wrF → wrF, wrW → wrW, pwEntry → pwEntry, pw → pw, dv → dv, dvB → dvB, good → good, scan → scan, scanF → scanF, pushZ → pushZ, zivW → zivW, ziv → ziv, F1 → F1, F4 → F4, go4B → go4B, go1 → go1, R → R, wv → wv, exactS → exactS, nfOf → nfOf, A_M → A_M, A_z → A_z, A_B → A_B, A_bits → A_bits, A_chk → A_chk, A_mag → A_mag, A_mf → A_mf, A_fsum → A_fsum, A_sa → A_sa, A_sr → A_sr, A_G → A_G, B_D → B_D, B_near → B_near, C_Inv → C_Inv, C_Hv → C_Hv, C_keep → C_keep, qAb → qAb, qEb → qAy, qGw → qBi, qEg → qEk, Acc.add_spec → Acc.add_spec, qCb → qCd, qC6 → qC0, qD3 → qEm, qHd → qH1, qFr → qGq, qIo → qJz, qAi → qAg, usz → usz, qAf → qAv, uk → uk, qDo → qDm, qBd → qAp, qDx → qDy, qGe → qG8, qCh → qB4, qAc → qAd, wi → wi, qWm → qJu, qAj → qAj, qAy → qBy, A_R → A_R, qAh → qAl, qA3 → qAu, qA0 → qBf, qCd → qB6, qDv → qD3, qH1 → qIz, qB0 → qDk, A_E → A_E, qEd → qD7, qAr → qAn, A_p → A_p, qAw → qB3, qI1 → qJ0, qCc → qBl, qAn → qAe, qE7 → qEo, qE3 → qFj, qDe → qDi, qFp → qIw, qFc → qF9, qEe → qEp, qBf → qA4, qDf → qC9, qCf → qB8, qA2 → qAt, qBk → qBj, qE0 → qE3, qBl → qCx, qCl → qCo, qCk → qDz, qHg → qJ1, qCu → qBb, qEm → qFk, qDa → qCm, qCw → qEu, qCm → qBu, qDc → qC2, qAq → qA0, qCo → qBt, qD8 → qEc, qCa → qAx, qGl → qEx, qHa → qH3, qAz → qBd, qAe → qAc, qAs → qA3, qA7 → qBe, qFb → qFs, qA6 → qD8, qD1 → qI2, qAm → qAs, qC4 → qC6, qCe → qB2, qGr → qHt, qC7 → qDc, qBo → qJm, qDd → qCy, qBz → qDj, qB7 → qB5, qIn → qJp, qGb → qGx, qEv → qHm, qC9 → qDb, qB5 → qCz, qAo → qAh, qBr → qA8, qHc → qEv, qBs → qCq, qFu → qGf, qFj → qH9, qCr → qCj, qHh → qH8, qHf → qId, qCs → qDw, qEz → qFg, qDi → qDe, qBm → qCw, qFq → qGo, B_z → B_z, qDg → qC8, qEa → qEs, qEf → qEf, qBb → qA5, qBn → qBk, qE4 → qHj, qFs → qIr, B_R → B_R, B_x → B_x, qHw → qEl, qEs → qCg, qB6 → qCa, qA4 → qAk, qBw → qCp, qAx → qA6, qEl → qE8, qEc → qBa, qIg → qGk, qHv → qGh, qB8 → qDd, qG5 → qH6, qEo → qDh, qIq → qEa, qCn → qD4, qDn → qDq, C_z → C_z, qAd → qAa, qBe → qBs, qAg → qAo, qBh → qAm, qFo → qGi, qBu → qAq, qAk → qF2, qA5 → qBg, qBv → qCe, qEn → qFl, qHu → qIs, qH2 → qI7, qB2 → qDt, qCx → qCt, qFa → qF1, qHj → qIa, qBi → qBh, qF6 → qGy, qBt → qBo, qFe → qFr, qGi → qHf, qF3 → qHe, qB1 → qDl, qCj → qDf, qBc → qBv, qC5 → qIg, qC3 → qFx, qD6 → qB9, qEt → qCr, qBj → qCb, qDp → qDs, qD5 → qEb, qAu → qA2, qDy → qG6, qAp → qBn, qDs → qG5, qIm → qFm, qD2 → qEt, qFh → qFn, qC1 → qGl, qC2 → qIu, qHz → qI6, qBg → qI1, qE6 → qJk, Acc.pos → Acc.pos, Acc.neg → Acc.neg, Acc.special → Acc.special, Acc.negZero → Acc.negZero, Acc.mk → Acc.mk, F1.s → F1.s, F1.t → F1.t, F1.mk → F1.mk, F4.a → F4.a, F4.b → F4.b, F4.c → F4.c, F4.d → F4.d, F4.mk → F4.mk, zivT → zivT, thOf → thOf, zivC → zivC, loOf → loOf, spOf → spOf, spR → spR, qI8 → qI8, qJh → qJh, kFh → qFh, qI5 → qI5, qJi → qJi, kHv → qHv, qJc → qJc, qGj → qGj, qJb → qJb, kGw → qGw, qHs → qHs, U_w → U_w, qI4 → qI4, qJr → qJr, kD1 → qD1, qIj → qIj, qHy → qHy section open FloatLib.Numerics end lemma qAw (w:Ὢ):toWord (ofW w)=w:=by apply ἠ.mp;simp only[toWord,ofW,Model.toNatBits,ofUInt32_bits,ὡ];exact Ἁ w.toBitVec.isLt @[inline] def keyOf (w:Ὢ):Int:= if signOf w then-((mantOf w<<simp only[ὁ,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,neg_mul] lemma qAf (w:Ὢ):(decodeD w).toReal=(keyOf w:ℝ)*2^(-149:Int):=by rw[<-Ἠ,decodeD_toRat,qGb];push_cast;rw[ᾂ ἓ,Ἡ];ring @[inline] def maxW (a b:Ὢ):Ὢ:= if expOf a=255\/expOf b=255 then toWord (Model.maximum (ofW a) (ofW b)) else match compare (keyOf a) (keyOf b) with | .lt=>b | .gt=>a | .eq=>toWord (if Model.isZero (ofW a)&&Model.isZero (ofW b) then Model.zero Fmt (Model.signBit (ofW a)&&Model.signBit (ofW b)) else ofW a) lemma qDo (a b:Ὢ):Model.cmpDyadic (decodeD a) (decodeD b)=compare (keyOf a) (keyOf b):=by have hs:(0:ℝ)<2^(-149:Int):=ἵ two_pos _;cases h:compare (keyOf a) (keyOf b);. rw[Model.cmpDyadic_lt_iff,qAf,qAf];exact Ἦ (by exact_mod_cast compare_lt_iff_lt.mp h) hs . rw[Model.cmpDyadic_eq_iff,qAf,qAf,compare_eq_iff_eq.mp h] . rw[Model.cmpDyadic_gt_iff,qAf,qAf];exact Ἦ (by exact_mod_cast compare_gt_iff_gt.mp h) hs lemma qFd (a b:Ὢ):ofW (maxW a b)=Model.maximum (ofW a) (ofW b):=by unfold maxW;split;. exact qAy _ . rename_i hs;have ha:=ἶ a (λh=>hs (Or.inl h));have hb:=ἶ b (λh=>hs (Or.inr h));have hna:=Model.isNaN_eq_false_of_toDyadic?_some ha;have hnb:=Model.isNaN_eq_false_of_toDyadic?_some hb;have hc:Model.compare (ofW a) (ofW b)=some _:=Model.compare_eq_some_cmpDyadic_of_toDyadic? _ _ ha hb;rw[qDo] at hc;have hnone:Model.chooseNaN2 (ofW a) (ofW b)=none:=(Model.chooseNaN2_eq_none_iff _ _).2 ⟨hna,hnb⟩;unfold Model.maximum Model.Internal.Value.maximum;rw[Model.withNaNSelection_of_none _ _ hnone];dsimp only;rw[Model.compareNonNaN_eq_of_compare_eq_some _ _ _ _ hc];cases compare (keyOf a) (keyOf b)<;>simp only[qAy] def maxpoolW (c h w k:Ὣ) (inp:ё):ё:= Array.ofFn (n:=c*(h/k*(w/k))) λq=> let ch:=q.val/(h/k*(w/k)) let y:=q.val/(w/k)%(h/k) let x:=q.val%(w/k) (ἄ (k*k)).foldl (λacc t=>maxW acc (poolAtO h w k inp ch y x t)) (poolAtO h w k inp ch y x 0) lemma qEj (p:Ὣ->Ὢ) (l:љ) (acc:Ὢ): l.foldl (λm t=>Model.maximum m (ofW (p t))) (ofW acc)=ofW (l.foldl (λa t=>maxW a (p t)) acc):=by induction l generalizing acc with | nil=>rfl | cons t l ih=>simp only[ὔ,<-qFd,ih] lemma qDn:maxpoolW=maxpoolSpecO:=by funext c h w k inp;simp only[maxpoolW,maxpoolSpecO,qEj,qAw] @[noinline] def E_div (n:Ὣ) (s:ὥ):ὥ:= toWord (Model.div (ofW s) (ofW (natW n))) lemma qIt:∀k:Fin 13,0expOf (natW (k.val*k.val))≠255/\signOf (natW (k.val*k.val))=false/\mantOf (natW (k.val*k.val))≠0/\mantOf (natW (k.val*k.val))*2^idxOf (natW (k.val*k.val))=k.val*k.val*2^149:=by decide+kernel lemma qJo:∀k,k<13->0E_div (k*k) (dotFn (k*k) (λ_=>0) (λ_=>oneW))=0:=by rw[show dotFn=Submission.D.dotFnO from Submission.D.qAi.trans Submission.D.qAiO.symm];decide+kernel lemma qJo14:E_div (14*14) (dotFn (14*14) (λ_=>0) (λ_=>oneW))=0:=by rw[show dotFn=Submission.D.dotFnO from Submission.D.qAi.trans Submission.D.qAiO.symm];decide+kernel def pwEntryN (i:Ὣ):ὧ:= if i%256==0 || i%256==255 then Ἃ 0x7FF8000000000000 else pwEntry i def pwN:ὤ:= (ἄ 512).foldl (λa i=>a.push (pwEntryN i)) (ἆ 512) lemma qDg:pwN.data=(ἄ 512).toArray.map pwEntryN:=by have key:∀(l:љ) (a:ὤ),(l.foldl (λa i=>a.push (pwEntryN i)) a).data=a.data++(l.toArray.map pwEntryN):=by intro l;induction l with | nil=>intro a;simp only[List.foldl_nil,List.map_toArray,List.map_nil,Array.append_empty] | cons x l ih=>intro a;simp only[ὔ,ih];simp only[FloatArray.push,List.map_toArray,List.push_append_toArray,List.map_cons] simp only[pwN,key];simp only[ἆ,List.toArray_range,Array.empty_append] lemma qCl (w:ὥ):(w>>>(23:ὥ)).toUSize.toNat< ѨpwN:=by have e:ѨpwN=512:=by simp only[FloatArray.size,qDg,List.toArray_range,Array.size_map,Array.size_range] rw[e];have h:=w.toNat_lt_size;simp only[ὃ,UInt32.toNat_shiftRight];norm_num[Ἱ] at h⊢;(clear e;exact omS13 h) @[inline] def dvN (w:ὥ):ὧ:= ((w&&&0x7FFFFF) ||| 0x800000).toFloat*pwN.uget (w>>>(23:ὥ)).toUSize (qCl w) @[inline] def scanH (A:ѐ):ὥ:= let h:=scanF A A.usize 0 (qAd A) 0 Е if h==Е then scan A A.usize 0 (qAd A) Е 0 else h @[inline] def zivS (s:ὧ):ὥ:= let a:=s.toBits zivW (a+2) (a-2) section open Float.Model.UnpackedFloat in open Float.Model.UnpackedFloat in section variable (x y:ὧ) (hx:xᶠ) (hy:yᶠ) (h1 : |R x| ≤ A_B) (h2 : |R y| ≤ A_B) include x y hx hy h1 h2 end section variable (w:ὥ) include w end section variable (l:List ὧ) (hf:∀ q∈l,qᶠ) (hlen:ѣl<=2^21) (hb:A_sa l<=A_B/4) include l hf hlen hb end section variable (w:ὥ) (hg:good w=true) include w hg end section variable {n:ℕ} {ts:List ℕ} {g:ℕ->ὧ} {p:ℕ->ℝ} {bw hh:ὥ} {X Y J:ℝ} {s t a e:ὧ} (A:n<2^20) (B:ѣts<=n) (C:A_G ts g p) (D:good bw=true) (E:X=(ts.map p).sum+wv bw) (F:s=ts.foldl (λ(c:ὧ) t=>c+g t) 0+dv bw) (G:(2:ℝ)^(-127:ℤ) ≤ |R (s+e)|) include A B C D E F G end section variable (n:Ὣ) (hn:n<2^20) (xw ww:Ὣ->ὥ) (bw:ὥ) (hx:∀ t,t< n->good (xw t)=true) (hw:∀ t,t< n->good (ww t)=true) (hb:good bw=true) (l:љ) (hl:l.Nodup) (hl2:∀ t∈l,t< n) include n hn xw ww bw hx hw hb l hl hl2 lemma qBx (hz:∀t,tt∉l->xw t&&&В=0\/ww t&&&В=0) (s e:ὧ) (hs:let r:=l.foldl (λ(acc:F1) t=>let q:=dv (xw t)*dv (ww t) F1.mk (acc.s+q) (acc.t+q.abs)) ⟨0,0⟩;s=r.s+dv bw/\e=nfOf n*(r.t+(dv bw).abs)) (hbig:(2:ℝ)^(-127:ℤ)<= |R (s+e)|): R (s-e)t∉l->xw t&&&В=0) (s e:ὧ) (hs:let r:=l.foldl (λ(acc:F1) t=>let q:=dv (xw t)*dv (ww t) F1.mk (acc.s+q) (acc.t+q.abs)) ⟨0,0⟩;s=r.s+dv bw/\e=nfOf n*(r.t+(dv bw).abs)) (hbig:(2:ℝ)^(-127:ℤ)<= |R (s+e)|): R (s-e).inl (hz t b a)) s e hs hbig end lemma qBr (n:Ὣ) (hn:n<2^20) (xw ww:Ὣ->ὥ) (bw hh:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (hg:good hh=true) (hm:∀t,txw t&&&В<=hh) (hp:hh<=В) (l:љ) (hl:l.Nodup) (hl2:∀t∈l,tt∉l->xw t&&&В=0\/ww t&&&В=0) (s e:ὧ) (hs:s=l.foldl (λ(acc:ὧ) t=>acc+dv (xw t)*dv (ww t)) 0+dv bw/\e=nfOf n*(dv hh*(l.foldl (λ(acc:ὧ) t=>acc+(dv (ww t)).abs) 0)+(dv bw).abs)) (hbig:(2:ℝ)^(-127:ℤ)<= |R (s+e)|): R (s-e)hw t (hl2 t a)) (λt a=>by rw[ἢ] exact ἀ (c _ (hx t (hl2 t a)) (hm t (hl2 t a))) (Ἀ _)) b end section end section section open Float.Model Float.Model.UnpackedFloat lemma qC1 (H a b:Ὣ) (hb:bὥ) (bw hh:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (hg:good hh=true) (hm:∀t,txw t&&&В<=hh) (hp:hh<=В) (l:љ) (hl:l.Nodup) (hl2:∀t∈l,tt∉l->xw t&&&В=0\/ww t&&&В=0) (s e:ὧ) (hs:s=l.foldl (λ(acc:ὧ) t=>acc+dv (xw t)*dv (ww t)) 0+dv bw/\e=nfOf n*(dv hh*(l.foldl (λ(acc:ὧ) t=>acc+(dv (ww t)).abs) 0)+(dv bw).abs)) (h:ziv s e≠Е): ziv s e=dotOf (n+1) (λt=>if tif tὥ) (bw hh:ὥ) (hx:∀t,tgood (xw t)=true) (hw:∀t,tgood (ww t)=true) (hb:good bw=true) (hg:good hh=true) (hm:∀t,txw t&&&В<=hh) (hp:hh<=В) (l:љ) (hl:l.Nodup) (hl2:∀t∈l,tt∉l->xw t&&&В=0\/ww t&&&В=0) (s e:ὧ) (hs:s=l.foldl (λ(acc:ὧ) t=>acc+dv (xw t)*dv (ww t)) 0+dv bw/\e=nfOf n*(dv hh*(l.foldl (λ(acc:ὧ) t=>acc+(dv (ww t)).abs) 0)+(dv bw).abs)) (h:zivT (thOf e) s≠Е): zivT (thOf e) s=dotOf (n+1) (λt=>if tif tif tif t>>(29:Ὠ))/\zivC ((a+0x0FFFFFFD)>>>(29:Ὠ))≠Е:=by have ha:=a.toNat_lt have e0:(a<<<(1:Ὠ)).toNat=Ѧa*2%2^64:=by rw[UInt64.toNat_shiftLeft];norm_num[ὁ] rw[Ὤ,e0] at h0 rw[ἴ,e0] at h1 norm_num at h0 h1 ha have eu:(a+0x0FFFFFFD).toNat=Ѧa+268435453:=by rw[ἤ];norm_num;(clear h2;exact omS364 h1 ha) have em:((a+0x0FFFFFFD)&&&0x1FFFFFFF).toNat=(Ѧa+268435453)%2^29:=by rw[Ὅ,eu] have:=Ἂ (Ѧa+268435453) 29 norm_num at this⊢ exact this rw[ἴ,em] at h2 norm_num at h2 generalize hx:(a+0x0FFFFFFD)>>>(29:Ὠ)=x have ex:Ѧx=(Ѧa+268435453)/2^29:=by rw[<-hx,ἰ,eu];norm_num[Ἱ] have e1:(a+2+0x0FFFFFFF)>>>(29:Ὠ)=x:=by apply UInt64.toNat_inj.mp rw[ex,ἰ,ἤ,ἤ] norm_num[Ἱ] (clear hx;exact omS365 h1 ha h2) have e2:(a-2+0x0FFFFFFF)>>>(29:Ὠ)=x:=by apply UInt64.toNat_inj.mp rw[ex,ἰ,ἤ,ὲ] norm_num[Ἱ] (clear hx e1;exact omS366 h1 ha) have hE:((x>>>(23:Ὠ))&&&(0x7FF:Ὠ)).toNat=Ѧx/2^23%2^11:=by rw[Ὅ,ἰ] have:=Ἂ (Ѧx>>>23) 11 norm_num[Ἱ] at this⊢ exact this have r1:898<=Ѧx/2^23%2^11:=by rw[ex];norm_num;(clear ha hx e1 e2 hE;exact omS367 h0 h1) have r2:Ѧx/2^23%2^11<1151:=by rw[ex];norm_num;(clear ha hx e1 e2 hE r1;exact omS368 h1) have r3:Ѧx<2^35:=by rw[ex];norm_num;(clear hx e1 e2 hE r1 r2;exact omS369 h1 ha) constructor . unfold zivW zivC;dsimp only;rw[e1,e2];have hc:((x>>>(23:Ὠ))&&&(0x7FF:Ὠ))-(897:Ὠ)<(254:Ὠ):=by rw[ἴ,ὲ,hE];norm_num;norm_num at r1 r2;(clear e0 h0 h1 ha eu em h2 hx ex e1 e2 hE r3;exact omS261 r1 r2) simp only[BEq.rfl,hc,decide_true,Bool.and_self, ↓reduceIte,UInt64.toUInt32_or,UInt64.reduceLT,UInt64.toUInt32_shiftLeft,UInt64.toUInt32_ofNat,UInt64.toUInt32_sub,UInt64.toUInt32_and] . unfold zivC;rw[show ((x>>>(34:Ὠ))<<<(31:Ὠ)) ||| ((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<(23:Ὠ)))=((x>>>34)<<<31) ||| ((x&&&(0x3FFFFFFFF:Ὠ))-((896:Ὠ)<<<23)) from rfl,qEl x r3 (by clear e0 h0 h1 ha eu em h2 hx ex e1 e2 r3;(exact Nat.le_of_lt ‹_›)) r2];intro h;have h':=congrArg UInt32.toNat h;rw[ὡ] at h';have f:=ὀ Ѧx (ב:0<2^23);split at h'<;>norm_num at h' f r1 r2<;>(clear e0 h0 h1 ha eu em h2 hx ex e1 e2 hE r3 h f;omega) lemma qIf (s:ὧ) (h1:(s.toBits<<<(1:Ὠ))-0x7040000000000000<0x1F60000000000000) (h2:(s.toBits+0x0FFFFFFD)&&&0x1FFFFFFF<0x1FFFFFFC):zivS s=zivC ((s.toBits+0x0FFFFFFD)>>>(29:Ὠ))/\zivS s≠Е:=by have sp0:spOf 0x7040000000000000=0x1F60000000000000:=ה obtain ⟨l1,l2⟩:=qD1 _ _ (sp0.symm▸h1);have b:=qH2 s.toBits l1 l2 h2;have e1:zivS s=zivC ((s.toBits+0x0FFFFFFD)>>>(29:Ὠ)):=b.1;exact ⟨e1,e1▸b.2⟩ end section lemma qIb (a b:ὦ) (h:Ѥa*Ѥb<2^32):(a*b).toNat=Ѥa*Ѥb:=qJu a b h section variable {N:Ὣ} {sp:Ὣ->Ὢ} include N sp end lemma qD0 (A:ѐ) (hs:ѧA<2^32) (h:scanH A≠Е):C_Hv A (scanH A):=by revert h;unfold scanH;dsimp only;split;. exact qBh A hs . exact qDl A hs section variable {R I O:Ὣ} {X W b:ё} end section variable (xw:Ὣ->Ὢ) (t:Ὣ) include xw t end section variable {x:ὤ} {ix W:ѐ} {w0 w1 w2 w3 m n:ὦ} (hx:Ѥn<=Ѩx) (hi:Ѥn<=ѧix) (hs:ѧW<2^32) (h0:Ѥw0+Ѥm<=ѧW) (h1:Ѥw1+Ѥm<=ѧW) (h2:Ѥw2+Ѥm<=ѧW) (h3:Ѥw3+Ѥm<=ѧW) end section variable {R I O:Ὣ} {X W b:ё} end lemma qGr (xs:ὤ) (v:ὧ) (q:Ὣ):(xs.push v).data[q]! =if q=Ѩxs then v else xs.data[q]!:=by obtain ⟨ds⟩:=xs;show (ds.push v)[q]! =if q=ѧds then v else ds[q]!;by_cases hq:q< ѧds . have h3:q<(ds.push v).size:=by simp only[Array.size_push,Order.lt_add_one_iff];(exact Nat.le_of_lt ‹_›) rw[Ἕ _ q h3,Ἕ ds q hq,ἐ (by clear h3;exact omS370 hq),Array.getElem_push_lt] . by_cases e:q=ѧds . subst e;have h3:ѧds<(ds.push v).size:=by simp only[Array.size_push,lt_add_iff_pos_right,Order.lt_one_iff] rw[Ἕ (ds.push v) ѧds h3,ἱ rfl,Array.getElem_push_eq] . have h3:¬q<(ds.push v).size:=by simp only[Array.size_push,Order.lt_add_one_iff,not_le];exact omS371 hq e rw[ὑ _ q h3,ὑ ds q hq,ἐ e] section variable {I O:Ὣ} {X W b:ё} end end section local instance ecNe11:Nonempty D_Sc:=⟨by constructor <;> exact default⟩ def D_scan (A:ѐ) (n i:ὦ) (hn:Ѥn<=ѧA) (lo hi:ὥ):D_Sc:= if h:ia | k+1=> if hg:USize.toNat o+w.toNat<=X.size then D_rw2 X hs w wp (o+w) (q+wp) k (D_cpz X o w 0 q hs hg a) else D_rw2 X hs w wp (o+w) (q+wp) k a def D_ch2 (s:OS) (X:ѐ) (hs:X.size<2^32) (wp:Nat) (c k:Nat) (a:ὤ):ὤ:= match k with | 0=>a | k+1=>D_ch2 s X hs wp (c+1) k (D_rw2 X hs s.w.toUSize wp.toUSize ((c*s.h)*s.w).toUSize ((c*(s.h+2*s.pad)+s.pad)*wp+s.pad).toUSize s.h a) lemma imz_skip (s:OS) (X:ѐ) (hs:X.size<2^32) (wp R r:Nat) (a:ὤ) (hr:rhn ⟨h.1,h.2.1⟩)] lemma imz_skipk (s:OS) (X:ѐ) (hs:X.size<2^32) (wp R:Nat) (k:Nat): ∀(r:Nat) (a:ὤ),r+k<=R-> (∀i,i ¬(s.pad<=(r+i)%(s.h+2*s.pad)/\(r+i)%(s.h+2*s.pad)-s.pad D_imz s X hs wp R r a=D_imz s X hs wp R (r+k) a:=by induction k with | zero=>intro r a _ _;rfl | succ k ih=> intro r a hk hi rw[imz_skip s X hs wp R r a (by exact omS4 hk) (by simpa only[not_and,not_lt,add_zero] using hi 0 (by exact omS9))] rw[ih (r+1) a (by exact omS5 hk) (λi hi'=>by have:=hi (i+1) א;rwa[show r+(i+1)=r+1+i by exact omS375] at this)] rw[show r+1+k=r+(k+1) by exact omS146] lemma cpz_congr (X:ѐ) (o1 o2 n t q:ὦ) (hs:X.size<2^32) (h1:USize.toNat o1+n.toNat<=X.size) (h2:USize.toNat o2+n.toNat<=X.size) (a:ὤ) (e:o1=o2): D_cpz X o1 n t q hs h1 a=D_cpz X o2 n t q hs h2 a:=by subst e;rfl lemma imz_rows (s:OS) (X:ѐ) (hs:X.size<2^32) (wp R c:Nat) (k:Nat): ∀(yy:Nat) (a:ὤ),s.pad<=yy->yy+k=s.pad+s.h->(c*(s.h+2*s.pad)+yy)+k<=R-> D_imz s X hs wp R (c*(s.h+2*s.pad)+yy) a= D_imz s X hs wp R (c*(s.h+2*s.pad)+yy+k) (D_rw2 X hs s.w.toUSize wp.toUSize ((c*s.h+(yy-s.pad))*s.w).toUSize ((c*(s.h+2*s.pad)+yy)*wp+s.pad).toUSize k a):=by induction k with | zero=>intro yy a _ _ _;rfl | succ k ih=> intro yy a h1 h2 h3 have hp:0hg (by rw[<-eo1];exact h.2.2) rw[dif_neg hc,dif_neg hg,eo,eq,e3] exact ih (yy+1) _ א א א lemma imz_chan (s:OS) (X:ѐ) (hs:X.size<2^32) (wp R c:Nat) (a:ὤ) (hR:(c+1)*(s.h+2*s.pad)<=R): D_imz s X hs wp R (c*(s.h+2*s.pad)) a=D_imz s X hs wp R ((c+1)*(s.h+2*s.pad)) (D_rw2 X hs s.w.toUSize wp.toUSize ((c*s.h)*s.w).toUSize ((c*(s.h+2*s.pad)+s.pad)*wp+s.pad).toUSize s.h a):=by have hR':c*(s.h+2*s.pad)+s.h+2*s.pad<=R:=by rw[ὰ,Ὑ] at hR;omega rw[imz_skipk s X hs wp R s.pad (c*(s.h+2*s.pad)) a א (λi hi=>by rw[ἥ,Nat.mul_add_mod,Ἁ (by exact omS381 hi)];omega)] rw[imz_rows s X hs wp R c s.h s.pad a (Nat.le_refl _) א א] rw[Nat.sub_self,Ἵ] rw[imz_skipk s X hs wp R s.pad _ _ א (λi hi=>by rw[show c*(s.h+2*s.pad)+s.pad+s.h+i=(s.pad+s.h+i)+(s.h+2*s.pad)*c by ring,Nat.add_mul_mod_self_left, Ἁ א];omega)] congr 1 rw[ὰ,Ὑ];omega lemma ch2_eq (s:OS) (X:ѐ) (hs:X.size<2^32) (wp R:Nat) (hR:R=s.cin*(s.h+2*s.pad)) (k:Nat): ∀(c:Nat) (a:ὤ),c+k=s.cin->D_ch2 s X hs wp c k a=D_imz s X hs wp R (c*(s.h+2*s.pad)) a:=by induction k with | zero=> intro c a h simp only[D_ch2] rw[D_imz,dif_neg (by subst hR;rw[<-h,Ἵ];exact omS491)] | succ k ih=> intro c a h simp only[D_ch2] rw[ih (c+1) _ (by exact omS137 h),imz_chan s X hs wp R c a (by subst hR;exact Ἒ _ (by exact omS492 h))] @[inline] def D_xs (s:OS) (X:ѐ) (hs:ѧX<2^32) (wp R:Ὣ):ὤ:= if R*wp+7<=16384 then D_ch2 s X hs wp 0 s.cin (D_zs (R*wp+7)) else D_fill (dv 0) 7 0 (D_img s X hs (dv 0) R 0 (ἆ (R*wp+7))) def D_off (s:OS) (t:Ὣ):Ὣ:= (t/(s.kh*s.kw)*(s.h+2*s.pad)+t/s.kw%s.kh)*(s.w+2*s.pad)+t%s.kw lemma qIo {n d:Ὣ} (b:ὦ) (u:ὥ) (hs:n<2^32) (h:Ѥb+ѥu+d exact default⟩ def D_go8R1 (xd wd:ὤ) (off:ѐ) (b e i:ὦ) (he:Ѥe<=ѧoff) (hw:Ѥe<=Ѩwd) (hs:Ѩxd<2^32) (hb:∀j (h:j< ѧoff),Ѥb+off[j].toNat+7< Ѩxd) (A B C D E F G I:ὧ) (r:D_R):D_R:= if h:i⟨t,A,B,C,D,E,F,G,I⟩ partial_fixpoint def D_go8RF (xd wd:ὤ) (off:ѐ) (b e i:ὦ) (he:Ѥe<=ѧoff) (hw:Ѥe<=Ѩwd) (hs:Ѩxd<2^32) (hb:∀j (h:j< ѧoff),Ѥb+off[j].toNat+7< Ѩxd) (A B C D E F G I:ὧ) (r:D_R):D_R:= if h:i∃u,wd.uget q h=dv u) (r:D_R) (i:ὦ) (A B C D E F G I:ὧ): D_go8RF xd wd off b e i he hw hs hb A B C D E F G I r=D_go8R1 xd wd off b e i he hw hs hb A B C D E F G I r:=by generalize hm:Ѥe-Ѥi=m induction m using Nat.strong_induction_on generalizing i A B C D E F G I with | _ m ih=> rw[D_go8RF];split . rename_i h;have:=usz i e h.1;have:=usz (i+1) e h.2;have:=А.mp h.2 have Ev:∀(p:ὦ) (hp:Ѥp< Ѩxd) (hq) (a:ὧ),Float.fma (xd.uget p hp) (wd.uget i hq) a=a+xd.uget p hp*wd.uget i hq:= λp hp hq a=>Submission.D.zFE (HX p hp) (HW i hq (А.mp h.1)) a simp only[Ev] rw[ih _ (by clear h;omega) (i+1+1) _ _ _ _ _ _ _ _ rfl];simp only[D_go8R1.eq_1 xd wd off b e i,D_go8R1.eq_1 xd wd off b e (i+1),Ἄ h.1,Ἄ h.2] . rfl @[inline] def D_go8R (xd wd:ὤ) (off:ѐ) (b e i:ὦ) (he:Ѥe<=ѧoff) (hw:Ѥe<=Ѩwd) (hs:Ѩxd<2^32) (hb:∀j (h:j< ѧoff),Ѥb+off[j].toNat+7< Ѩxd) (A B C D E F G I:ὧ) (r:D_R):D_R:= if Submission.D.armT then D_go8RF xd wd off b e i he hw hs hb A B C D E F G I r else D_go8R1 xd wd off b e i he hw hs hb A B C D E F G I r lemma qGR (xd wd:ὤ) (off:ѐ) (b e:ὦ) (he:Ѥe<=ѧoff) (hw:Ѥe<=Ѩwd) (hs:Ѩxd<2^32) (hb:∀j (h:j< ѧoff),Ѥb+off[j].toNat+7< Ѩxd) (HX:∀(p:ὦ) (h:Ѥp< Ѩxd),∃u,xd.uget p h=dv u) (HW:∀(q:ὦ) (h:Ѥq< Ѩwd),Ѥq< Ѥe->∃u,wd.uget q h=dv u) (r:D_R) (i:ὦ) (A B C D E F G I:ὧ): D_go8R xd wd off b e i he hw hs hb A B C D E F G I r=D_go8R1 xd wd off b e i he hw hs hb A B C D E F G I r:=by unfold D_go8R;split . exact vFgf xd wd off b e he hw hs hb HX HW r i A B C D E F G I . rfl local instance ecNe13:Nonempty F1:=⟨by constructor <;> exact default⟩ def D_goT (xd wd:ὤ) (off:ѐ) (b e i:ὦ) (he:Ѥe<=ѧoff) (hw:Ѥe<=Ѩwd) (hs:Ѩxd<2^32) (hb:∀j (h:j< ѧoff),Ѥb+off[j].toNat+0< Ѩxd) (a t:ὧ):F1:= if h:iὥ) (i:Nat):Nat->Ὡ | 0=>true | n+1=>(let a:=fa i;let b:=fb i;expOf a != 255&&expOf b != 255&&mantOf a*mantOf b==0)&&zAll fa fb (i+1) n @[specialize] def zNeg (fa fb:Nat->ὥ) (i:Nat):Nat->Ὡ | 0=>true | n+1=>(let a:=fa i;let b:=fb i;Bool.xor (signOf a) (signOf b))&&zNeg fa fb (i+1) n @[inline] def zdotFn (n:Nat) (fa fb:Nat->ὥ):ὥ:= if zAll fa fb 0 n then (if n≠0&&zNeg fa fb 0 n then س else 0) else dotFn n fa fb def zCols (s:OS) (X:ѐ) (c yy x0:Nat) (i:Nat):Nat->Ὡ | 0=>true | n+1=>pixZ s X c yy (x0+i)&&zCols s X c yy x0 (i+1) n def zRows (s:OS) (X:ѐ) (c y0 x0:Nat) (i:Nat):Nat->Ὡ | 0=>true | n+1=>zCols s X c (y0+i) x0 0 s.kw&&zRows s X c y0 x0 (i+1) n def wFin (W:ѐ) (base:Nat) (i:Nat):Nat->Ὡ | 0=>true | n+1=>expOf W[base+i]! != 255&&wFin W base (i+1) n def zWin (g:D_C) (o y x:Nat):Ὡ:= g.dw&&g.k==g.s.kh*g.s.kw&&decide (0Ὡ | 0=>true | n+1=>zRows s X i y0 x0 0 s.kh&&zChans s X y0 x0 (i+1) n def zWinC (g:D_C) (o y x:Nat):Ὡ:= !g.dw&&g.k==g.s.cin*(g.s.kh*g.s.kw)&&decide (0if tif tὩ | 0=>true | n+1=>(decide (b+(off[i]!).toNatD_ztF xd off b i e=true->D_zt xd off b.toNat i.toNat n=true:=by intro n induction n with | zero=>intro i _ _;rfl | succ n ih=> intro i hn h have hie:isimp only[FloatArray.get!,FloatArray.uget];exact Ἕ d _ h3.2 rw[g];exact h4 · rw[<-hi1];exact ih (i+1) א h5 · rw[dif_neg h3] at h;exact absurd h (by simp only[false_eq_true,not_false_eq_true]) · rw[dif_neg h2] at h;exact absurd h (by simp only[false_eq_true,not_false_eq_true]) lemma D_ztF_imp0 (xd:ὤ) (off:ѐ) (b e:ὦ) (h:D_ztF xd off b 0 e=true): D_zt xd off b.toNat 0 e.toNat=true:=by have:=D_ztF_imp xd off b e e.toNat 0 (by simp only[USize.toNat_zero,zero_add]) h simpa only[USize.toNat_zero] using this @[inline] def zbits (xd:ὤ) (p:ὦ):Ὠ:= if h:p.toNatsimp only[FloatArray.get!,FloatArray.uget];exact Ἕ d _ hp rw[g];exact h · exact absurd h ה lemma D_ztB_imp (xd:ὤ) (off:ѐ) (b e:ὦ): ∀n (i:ὦ),i.toNat+n=e.toNat->D_ztB xd off b i e=true-> ∀k,k<8->D_zt xd off (b.toNat+k) i.toNat n=true:=by intro n induction n with | zero=>intro i _ _ k _;rfl | succ n ih=> intro i hn h k hk have hie:izbits xd (P+c)<<<(1:Ὠ)=0:=by intro c hc have hc':c=(c.toNat:Nat).toUSize:=by simp only[Nat.toUSize_eq,USize.ofNat_toNat] generalize hcn:c.toNat=m at hc hc' subst hc' interval_cases m · have e0:Nat.toUSize 0=0:=rfl rw[e0,USize.add_zero];exact a0 · exact a1 · exact a2 · exact a3 · exact a4 · exact a5 · exact a6 · exact a7 have kU:(k.toUSize).toNat=k:=by rw[Nat.toUSize_eq];exact USize.toNat_ofNat_of_lt' (by have:=USize.le_size;omega) obtain ⟨z1,z2⟩:=zbits_ok xd _ (lane k.toUSize א) rw[zbP7 P h3.2 _ א,kU] at z1 z2 simp only[D_zt,Bool.and_eq_true,decide_eq_true_eq,beq_iff_eq] refine ⟨⟨by rw[Nat.add_right_comm,<-hp];exact z1,by rw[Nat.add_right_comm,<-hp];exact z2⟩,?_⟩ rw[<-hi1];exact ih (i+1) (by exact omS157 hn hi1) h5 k hk · rw[Ὧ h3] at h;exact absurd h (by simp only[false_eq_true,not_false_eq_true]) · rw[dif_neg h2] at h;exact absurd h (by simp only[false_eq_true,not_false_eq_true]) lemma D_ztB_imp0 (xd:ὤ) (off:ѐ) (b e:ὦ) (h:D_ztB xd off b 0 e=true) (k:Nat) (hk:k<8): D_zt xd off (b.toNat+k) 0 e.toNat=true:=by have:=D_ztB_imp xd off b e e.toNat 0 (by simp only[USize.toNat_zero,zero_add]) h k hk simpa only[USize.toNat_zero] using this @[noinline] def D_slowY (c:D_P) (o y x:Nat) (b:ὦ):ὥ:= if zWinX c.g o y x then 0 else if c.g.b[o]! ==0&&D_zt c.g.xd c.off b.toNat 0 c.e.toNat then 0 else D_slowZ c.g o y x @[inline] def D_zl (q n:ὦ) (k:Ὣ) (out:ѐ):ѐ:=if ὴ k>>(29:Ὠ)) else if w<<<(1:Ὠ)==0 then (if c.g.b[o]! ==0&&D_ztF c.g.xd c.off (b+ὴ k) 0 c.e then 0 else D_slowY c o y (x+k) (b+ὴ k)) else D_finK c o y x k b a @[inline] def D_l (c:D_P) (lo sp:Ὠ) (o y x:Ὣ) (b q n:ὦ) (k:Ὣ) (a:ὧ) (out:ѐ): ѐ:= if ὴ krename_i hc<;>rw[ἳ] at hc<;>(clear h;omega) rw[e];by_cases hc:comega . have e2:wrW off c f=off:=by unfold wrW;rw[ἔ hc] have h0:j< ѧoff:=by rw[e2] at h;exact h have g:=hm j h0;simp only[e2];(clear e hc;omega) lemma qF0 (k:Ὣ):∀j (h:j<(ἇ k (0:ὥ)).size),(ἇ k (0:ὥ))[j].toNat<=(0:ὥ).toNat:=by intro j h;simp only[Array.getElem_replicate,UInt32.toNat_zero,Std.le_refl] def D_dec (tab W:ѐ) (base:ὥ) (o n t:ὦ) (off:ѐ) (buf:ὤ) (c:ὦ) (l:ὧ) (m:ὥ) (hm:∀j (h:j< ѧoff),off[j].toNat<=ѥm):R2:= if h:tabsurd h (Ἲ _)⟩⟩ def D_decAll (tab W:ѐ) (dw:Ὡ) (s:OS) (wp k C:Ὣ):Array R2:= Array.ofFn (n:=C) λo=>D_dec tab W (if dw then (o.val*((s.h+2*s.pad)*wp)).toUInt32 else 0) (o.val*k).toUSize ѩk 0 (ἇ k 0) (pushZ ѩk 0 (ἆ k)) 0 0 0 (qF0 k) def mkCV (W b:ѐ) (s:OS) (dw:Ὡ) (k C:Ὣ):CV:= let tab:=D_tq k s.kw s.kh (s.h+2*s.pad) (s.w+2*s.pad) 0 0 0 0 (Array.emptyWithCapacity k) ⟨scanH W,scanH b,tab,D_decAll tab W dw s (s.w+2*s.pad) k C⟩ abbrev CVV (W b:ѐ) (s:OS) (dw:Ὡ) (k C:Ὣ):= {v:CV // v=mkCV W b s dw k C} local instance cvSub (W b:ѐ) (s:OS) (dw:Ὡ) (k C:Ὣ) : Subsingleton (CVV W b s dw k C):=⟨λa b=>Subtype.ext (a.2.trans b.2.symm)⟩ structure CE where (W b:ѐ) (s:OS) (dw:Ὡ) (k C:Ὣ) (v:CV) (g:ὦ) (ok:v=mkCV W b s dw k C) @[inline] def sEq (a b:OS):Ὡ:= a.cin==b.cin&&a.h==b.h&&a.w==b.w&&a.cout==b.cout&&a.kh==b.kh&&a.kw==b.kw&& a.stride==b.stride&&a.pad==b.pad lemma qH4 {a b:OS} (h:sEq a b=true):a=b:=by cases a;cases b;simp only[sEq,and_eq_true,beq_iff_eq] at h;obtain ⟨⟨⟨⟨⟨⟨⟨h1,h2⟩,h3⟩,h4⟩,h5⟩,h6⟩,h7⟩,h8⟩:=h;subst h1 h2 h3 h4 h5 h6 h7 h8;rfl def cvF (W b:ѐ) (s:OS) (dw:Ὡ) (k C:Ὣ) (g:ὦ) (es:Array CE) (i:Ὣ):Option (CVV W b s dw k C):= if h:i< ѧes then if es[i].g==g then if hk:withPtrEq es[i].W W (λ_=>es[i].W==W) (λe=>by rw[e];exact beq_self_eq_true W) then if hb:withPtrEq es[i].b b (λ_=>es[i].b==b) (λe=>by rw[e];exact beq_self_eq_true b) then if hs:sEq es[i].s s&&es[i].dw==dw&&es[i].k==k&&es[i].C==C then some ⟨es[i].v,by simp only[and_eq_true,beq_iff_eq] at hs obtain ⟨⟨⟨h1,h2⟩,h3⟩,h4⟩:=hs rw[<-eq_of_beq hk,<-eq_of_beq hb,<-qH4 h1,<-h2,<-h3,<-h4];exact es[i].ok⟩ else cvF W b s dw k C g es (i+1) else cvF W b s dw k C g es (i+1) else cvF W b s dw k C g es (i+1) else cvF W b s dw k C g es (i+1) else none partial_fixpoint @[noinline] def cvS:ST.Ref Unit (Array CE):=(ST.Prim.mkRef #[] (Void.mk ())).val @[inline] def cvGet (W b:ѐ) (s:OS) (dw:Ὡ) (k C:Ὣ):CVV W b s dw k C:= withPtrAddr W (λg=> let es:=(ST.Prim.Ref.get cvS (Void.mk ())).val match cvF W b s dw k C g es 0 with | some v=>v | none=> let v:=mkCV W b s dw k C let old:=(ST.Prim.Ref.swap cvS (#[⟨W,b,s,dw,k,C,v,g,rfl⟩]++ (if ѧes<256 then es else es.pop)) (Void.mk ())).val match cvF W b s dw k C g old 0 with | some v=>v | none=>⟨v,rfl⟩) (λ_ _=>Subsingleton.elim _ _) def D_outsC (g:D_C) (hs:g.xd.size<2^32) (o:Ὣ) (q:ὦ) (rs:Array R2) (out:ѐ):ѐ:= if o>>(23:ὥ))-((rx.lo+1)>>>(23:ὥ))>99 let R:=s.cin*hp let xd:=D_xs s X (Nat.lt_of_le_of_lt hg.1 (by norm_num)) wp R if hs:Ѩxd<=4294967295 then let g:D_C:=⟨dw,relu,s.stride==1&&!tight,s,X,W,b,k,C,s.ho,s.wo,wp, s.stride.toUSize,rx.hi,xd,(k.toUInt64+8).toFloat*Ἃ 0x3CA0000000000000, cv.tab,mkExS s X b dw s.ho⟩ D_outsC g (Nat.lt_of_le_of_lt hs (by norm_num)) 0 0 cv.rs (ἇ (C*(s.ho*s.wo)) 0) else if dw then depthwiseWithO dotFn s relu X W b else conv2dWithO dotFn s relu X W b else if dw then depthwiseWithO dotFn s relu X W b else conv2dWithO dotFn s relu X W b def D_F (dw:Ὡ) (s:OS) (relu:Ὡ) (X W b:ѐ) (k C:Ὣ): ѐ:= D_Fc dw s relu X W b k C (cvGet W b s dw k C).1 def Cn1 (s:OS):OS:= if s.kh=1/\s.kw=1/\s.stride=1/\s.pad=0/\0=s.h\/xx-s.pad>=s.w then 0 else X[(c*s.h+(yy-s.pad))*s.w+(xx-s.pad)]! def D_Fx (s:OS) (X:ё) (q:Ὣ):ὧ:= dv (D_px s X (q/(s.w+2*s.pad)/(s.h+2*s.pad)) (q/(s.w+2*s.pad)%(s.h+2*s.pad)) (q%(s.w+2*s.pad))) def D_Pre (F:Ὣ->ὧ) (m:Ὣ) (a:ὤ):Prop:= Ѩa=m/\∀q,q< m->a.data[q]! =F q lemma qCh {F:Ὣ->ὧ} {m:Ὣ} {a:ὤ} {v:ὧ} (h:D_Pre F m a) (hv:v=F m):D_Pre F (m+1) (a.push v):=by refine ⟨by rw[qA2,h.1],λq hq=>?_⟩;rw[qGr,h.1];split<;>rename_i e;. rw[e,hv] exact h.2 q (by exact omS374 hq e) lemma qFp (m d:Ὣ):m+(d+1)=m+1+d:=(by exact omS375) def D_Sp (F:Ὣ->ὧ) (m:Ὣ) (a:ὤ):Prop:= m<=Ѩa/\∀q,q< m->a.data[q]! =F q structure D_Ok (g:D_C):Prop where hk:g.k=if g.dw then g.s.kh*g.s.kw else g.s.cin*g.s.kh*g.s.kw hC:g.C=if g.dw then g.s.cin else g.s.cout ho:g.ho=g.s.ho wo:g.wo=g.s.wo wp:g.wp=g.s.w+2*g.s.pad st:g.step.toNat=g.s.stride nf:g.nf=nfOf g.k f4:g.f4=true->g.s.stride=1 p0:0(D_off g.s t.val).toUInt32 xv:∀q,q< Ѩg.xd->∃u,g.xd.data[q]! =dv u lemma qCk {i e:ὦ} (h:Ѥe<=Ѥi):¬iὧ} {v:ὧ} {n:ὦ} (d:Ὣ): ∀(k:ὦ) (m:Ὣ) (a:ὤ),Ѥk+d=Ѥn->D_Pre F m a->(∀i,m<=i->i< m+d->F i=v)->D_Pre F (m+d) (D_fill v n k a):=by induction' d with d ih<;>intro k m a he H hv . rw[D_fill,ἔ (qCk he.ge)];exact H obtain ⟨ht,hu⟩:=qBz he rw[D_fill,Ἄ ht,qFp] exact ih (k+1) (m+1) _ hu (qCh H (hv m (by exact Nat.le_refl _) (by clear he ht;(clear hu;omega))).symm) λi h1 h2=>hv i (by exact Nat.le_of_lt ‹_›) (by clear he ht h1;(clear hu;omega)) lemma qEr {F:Ὣ->ὧ} {X:ѐ} {o n:ὦ} (hs:ѧX<2^32) (ho:Ѥo+Ѥn<=ѧX) (d:Ὣ): ∀(t:ὦ) (m:Ὣ) (a:ὤ),Ѥt+d=Ѥn->D_Pre F m a->(∀j,jF (m+j)=dv X[Ѥo+Ѥt+j]!)->D_Pre F (m+d) (D_copy X o n t hs ho a):=by induction' d with d ih<;>intro t m a he H hv . rw[D_copy,ἔ (qCk he.ge)];exact H obtain ⟨ht,hu⟩:=qBz he rw[D_copy,Ἄ ht,qFp] refine ih (t+1) (m+1) _ hu (qCh H ?_) λj hj=>?_ . rw[qFx,qAv _ _ (by clear ht;omega)];exact (hv 0 (by clear he ht hu;exact omS9)).symm simpa only[usz t n ht,ὢ,Nat.add_comm 1] using hv (j+1) (by exact Nat.lt_succ_of_le ‹_›) lemma qCn {c:Ὣ} (a:Ὣ) {b:Ὣ} (h:bὧ} {v:ὧ} {n:ὦ} {m d:Ὣ} {a:ὤ} (hn:Ѥn=d) (H:D_Pre F m a) (hv:∀u,uF (m+u)=v):D_Pre F (m+d) (D_fill v n 0 a):= qCc d 0 m a (by rw[hn];exact Ἇ d) H λi h1 h2=>by obtain ⟨u,rfl⟩:=Nat.exists_eq_add_of_le h1 exact hv u (by clear hn h1;exact omS377 h2) lemma qF5 (m p w:Ὣ):m+(w+2*p)=m+p+w+p:=(by exact omS378) lemma qE0 (s:OS) (X:ѐ) (hs:ѧX<2^32) (hX:ѧX=s.cin*s.h*s.w) (hh:s.h+2*s.pad<2^32) (hw:s.w+2*s.pad<2^32) {R:Ὣ} (hR:R=s.cin*(s.h+2*s.pad)) (d:Ὣ): ∀(r:Ὣ) (a:ὤ),r+d=R->D_Pre (D_Fx s X) (r*(s.w+2*s.pad)) a->D_Pre (D_Fx s X) (R*(s.w+2*s.pad)) (D_img s X hs (dv 0) R r a):=by induction' d with d ih<;>intro r a he H . rw[D_img,ἔ (by clear hs hX hh hw;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))),<-he];exact H have hr:rqBv (qDf hc g) (Nat.le_refl s.w) rw[D_img,Ἄ hr] dsimp only split<;>rename_i g . obtain ⟨g1,g2,g3⟩:=g;have:=hO g2;apply ih (r+1) _ (by clear hX hh hw hr hc ep ew g1 g2 g3 this;exact omS137 he);rw[ᾀ,qF5];refine qFo ep (qEr hs g3 s.w 0 _ _ (by rw[ew];exact Ἇ _) (qFo ep H λu hu=>?_) λj hj=>?_) λu hu=>?_;. rw[qAi _ _ _ (by clear hX hh hw hR he hr hc g1 g2 g3 this;(clear ep;exact omS381 hu)),D_px,ἱ (by clear hX hh hw hR he hr hc ew g1 g2 g3 this;(clear ep;exact omS382 hu))] . rw[ὢ,qAi _ _ _ (by clear hX hw hR he hr hc g1 g2 g3 this;(clear ew;exact omS383 hj)),D_px,ἐ (by clear hX hh hw hR he hr hc g3 this;(clear ep ew;exact omS384 g1 g2 hj)),Nat.add_sub_cancel_left,qAa _ (by clear hR he hr hc g1 g2 g3 hj;exact omS385 hs hX this)];rfl . rw[ὢ,ὢ,qAi _ _ _ (by clear hX hh hw hR he hr hc ew g1 g2 g3 this;(clear ep;exact omS386 hu)),D_px,ἱ (by clear hh hw hR he hr hc ep g1 g2 this hu;exact omS387)] apply ih (r+1) _ (by clear hX hh hw hr hc ep ew g;exact omS137 he) rw[ᾀ] exact qFo (qAa _ hw) H λu hu=>by rw[qAi _ _ _ hu,D_px,ἱ] by_contra n have:=hO (by clear hX hh hw hR he hr hc ep ew g hu;exact omS388 n) exact g ⟨by (clear hX hh hw hR he hr hc ew g hu this;(clear ep;exact omS389 n)),by (clear hX hh hw hR he hr hc ep ew g hu this;exact omS388 n),by rw[qAa _ (by clear hh hw hR he hr hc ep g hu n;exact omS385 hs hX this),ew,hX];exact this⟩ def D_t0 (g:D_C) (o:Ὣ):Ὣ:=if g.dw then o*g.k else 0 def D_xw (g:D_C) (o y x t:Ὣ):Ὢ:=windowAtO g.s g.X y x (D_t0 g o+t) def D_out (g:D_C) (o y x:Ὣ):Ὢ:= act g.relu (dotOf (g.k+1) (λt=>if tif tt∉L->c.g.W[o*c.g.k+t]!&&&В=0 rd:∀j p:Ὣ,L[j]?=some p-> (c.off[j]!:ὥ).toNat=D_off c.g.s (D_t0 c.g o+p)/\ c.wd.data[j]! =dv c.g.W[o*c.g.k+p]! e0:c.e0=nfOf c.g.k*(dv c.g.hi*L.foldl (λacc t=>acc+(dv c.g.W[o*c.g.k+t]!).abs) 0+ (dv c.g.b[o]!).abs) bv:c.bv=dv c.g.b[o]! lemma qCv (g:D_C) (o y x:Ὣ):D_slow g o y x=D_out g o y x:=by unfold D_slow D_out D_xw D_t0;rw[qAg] lemma zAll_spec (fa fb:Nat->ὥ) (N:Nat): ∀n i,i+n<=N->zAll fa fb i n=true-> dsum (Array.ofFn (n:=N) λj=>fa j) (Array.ofFn (n:=N) λj=>fb j) i n=0/\ dallNZ (Array.ofFn (n:=N) λj=>fa j) (Array.ofFn (n:=N) λj=>fb j) i n=zNeg fa fb i n/\ (∀j,i<=j->j< i+n->expOf (fa j)≠255/\expOf (fb j)≠255):=by intro n induction n with | zero=>intro i _ _;exact ⟨rfl,rfl, λj h1 h2=>absurd h2 א⟩ | succ n ih=> intro i hi h simp only[zAll,Bool.and_eq_true,bne_iff_ne,ne_eq,beq_iff_eq] at h obtain ⟨⟨⟨h1,h2⟩,h3⟩,h4⟩:=h obtain ⟨r1,r2,r3⟩:=ih (i+1) (by exact omS5 hi) h4 have ea:(Array.ofFn (n:=N) λj=>fa j)[i]! =fa i:=Pinned.getElem!_ofFn N fa i (by exact omS4 hi) have eb:(Array.ofFn (n:=N) λj=>fb j)[i]! =fb i:=Pinned.getElem!_ofFn N fb i (by exact omS4 hi) have hsv:sv (fa i)*sv (fb i)=0:=by rcases Nat.mul_eq_zero.1 h3 with h | h<;>simp only[sv,h,CharP.cast_eq_zero,neg_zero,ite_self,mul_ite,mul_neg,zero_mul,mul_zero] refine ⟨?_,?_,?_⟩ · simp only[dsum,ea,eb,hsv,zero_mul,r1,add_zero] · simp only[dallNZ,ea,eb,h3,r2,zNeg,decide_true,Bool.true_and] · intro j hj1 hj2 by_cases hji:j=i · subst hji;exact ⟨h1,h2⟩ · exact r3 j (by exact omS138 hj1 hji) (by exact omS7 hj2) lemma zdotFn_eq:zdotFn=dotFn:=by funext n fa fb unfold zdotFn split · rename_i hz obtain ⟨r1,r2,r3⟩:=zAll_spec fa fb n n 0 (by exact omS10) hz rw[D.qAi] unfold dotOf have hs:(Array.ofFn (n:=n) λi=>fb i).size=(Array.ofFn (n:=n) λi=>fa i).size:=by simp only[Array.size_ofFn] have hall: ∀k,k<(Array.ofFn (n:=n) λi=>fa i).size-> expOf (Array.ofFn (n:=n) λi=>fa i)[k]!≠255/\expOf (Array.ofFn (n:=n) λi=>fb i)[k]!≠255:=by intro k hk simp only[Array.size_ofFn] at hk rw[Pinned.getElem!_ofFn n fa k hk,Pinned.getElem!_ofFn n fb k hk] exact r3 k א א rw[<-D.qEg _ _ hs hall] simp only[Array.size_ofFn,r1,r2] unfold finishWord simp only[ne_eq,decide_not,and_eq_true,Bool.not_eq_eq_eq_not,Bool.not_true,decide_eq_false_iff_not, ↓reduceIte] · rfl lemma zCols_spec (s:OS) (X:ѐ) (c yy x0:Nat): ∀n i,zCols s X c yy x0 i n=true-> ∀d,i<=d->d< i+n->pixZ s X c yy (x0+d)=true:=by intro n induction n with | zero=>intro i _ d h1 h2;omega | succ n ih=> intro i h d h1 h2 simp only[zCols,Bool.and_eq_true] at h by_cases hd:d=i · subst hd;exact h.1 · exact ih (i+1) h.2 d (by exact omS138 h1 hd) (by exact omS7 h2) lemma zRows_spec (s:OS) (X:ѐ) (c y0 x0:Nat): ∀n i,zRows s X c y0 x0 i n=true-> ∀e,i<=e->e< i+n->zCols s X c (y0+e) x0 0 s.kw=true:=by intro n induction n with | zero=>intro i _ e h1 h2;omega | succ n ih=> intro i h e h1 h2 simp only[zRows,Bool.and_eq_true] at h by_cases he:e=i · subst he;exact h.1 · exact ih (i+1) h.2 e (by exact omS138 h1 he) (by exact omS7 h2) lemma wFin_spec (W:ѐ) (base:Nat): ∀n i,wFin W base i n=true-> ∀d,i<=d->d< i+n->expOf W[base+d]!≠255:=by intro n induction n with | zero=>intro i _ d h1 h2;omega | succ n ih=> intro i h d h1 h2 simp only[wFin,Bool.and_eq_true,bne_iff_ne,ne_eq] at h by_cases hd:d=i · subst hd;exact h.1 · exact ih (i+1) h.2 d (by exact omS138 h1 hd) (by exact omS7 h2) lemma mantOf_fin {w:ὥ} (h:mantOf w=0):expOf w≠255:=by unfold mantOf at h split at h · rename_i he;rw[he];decide · omega lemma win_mant (s:OS) (X:ѐ) (o y x:Nat) (hk:0ὥ): ∀n i,(∀t,i<=t->t< i+n-> expOf (fa t)≠255/\expOf (fb t)≠255/\mantOf (fa t)*mantOf (fb t)=0)->zAll fa fb i n=true:=by intro n induction n with | zero=>intro i _;rfl | succ n ih=> intro i h obtain ⟨h1,h2,h3⟩:=h i (Nat.le_refl _) א simp only[zAll,Bool.and_eq_true,bne_iff_ne,ne_eq,beq_iff_eq] exact ⟨⟨⟨h1,h2⟩,h3⟩,ih (i+1) (λt a b=>h t א א)⟩ lemma zNeg_spec (fa fb:Nat->ὥ): ∀n i,zNeg fa fb i n=true-> ∀t,i<=t->t< i+n->Bool.xor (signOf (fa t)) (signOf (fb t))=true:=by intro n induction n with | zero=>intro i _ t h1 h2;omega | succ n ih=> intro i h t h1 h2 simp only[zNeg,Bool.and_eq_true] at h by_cases ht:t=i · subst ht;exact h.1 · exact ih (i+1) h.2 t (by exact omS138 h1 ht) (by exact omS7 h2) lemma zWin_out (g:D_C) (o y x:Nat) (h:zWin g o y x=true):D_out g o y x=0:=by simp only[zWin,Bool.and_eq_true,beq_iff_eq,decide_eq_true_eq] at h obtain ⟨⟨⟨⟨⟨hdw,hk⟩,hkw⟩,hb⟩,hw⟩,hr⟩:=h have hza:zAll (λt=>if tif tif tif tif tif trfl lemma zChans_spec (s:OS) (X:ѐ) (y0 x0:Nat): ∀n i,zChans s X y0 x0 i n=true-> ∀c,i<=c->c< i+n->zRows s X c y0 x0 0 s.kh=true:=by intro n induction n with | zero=>intro i _ c h1 h2;omega | succ n ih=> intro i h c h1 h2 simp only[zChans,Bool.and_eq_true] at h by_cases hc:c=i · subst hc;exact h.1 · exact ih (i+1) h.2 c (by exact omS138 h1 hc) (by exact omS7 h2) lemma zWinC_out (g:D_C) (o y x:Nat) (h:zWinC g o y x=true):D_out g o y x=0:=by simp only[zWinC,Bool.and_eq_true,beq_iff_eq,decide_eq_true_eq,Bool.not_eq_true'] at h obtain ⟨⟨⟨⟨⟨hdw,hk⟩,hkw⟩,hb⟩,hw⟩,hr⟩:=h have hza:zAll (λt=>if tif tif tif tif tif trfl lemma qCvZ (g:D_C) (o y x:Ὣ):D_slowZ g o y x=D_out g o y x:=by unfold D_slowZ;split · rename_i h;rcases Bool.or_eq_true_iff.1 h with h|h · exact (zWin_out g o y x h).symm · exact (zWinC_out g o y x h).symm · exact qCv .. lemma zCols_of (s:OS) (X:ѐ) (c yy x0:Nat): ∀n i, (∀d,i<=d->d< i+n->pixZ s X c yy (x0+d)=true)->zCols s X c yy x0 i n=true:=by intro n induction n with | zero=>intro i _;rfl | succ n ih=> intro i h simp only[zCols,Bool.and_eq_true] exact ⟨h i (Nat.le_refl _) א,ih (i+1) (λd h1 h2=>h d א א)⟩ lemma zRows_of (s:OS) (X:ѐ) (c y0 x0:Nat): ∀n i, (∀e,i<=e->e< i+n->zCols s X c (y0+e) x0 0 s.kw=true)->zRows s X c y0 x0 i n=true:=by intro n induction n with | zero=>intro i _;rfl | succ n ih=> intro i h simp only[zRows,Bool.and_eq_true] exact ⟨h i (Nat.le_refl _) א,ih (i+1) (λd h1 h2=>h d א א)⟩ lemma zChans_of (s:OS) (X:ѐ) (y0 x0:Nat): ∀n i, (∀c,i<=c->c< i+n->zRows s X c y0 x0 0 s.kh=true)->zChans s X y0 x0 i n=true:=by intro n induction n with | zero=>intro i _;rfl | succ n ih=> intro i h simp only[zChans,Bool.and_eq_true] exact ⟨h i (Nat.le_refl _) א,ih (i+1) (λd h1 h2=>h d א א)⟩ lemma wFin_of (W:ѐ) (base:Nat) (hW:∀q:Nat,good W[q]! =true): ∀n i,wFin W base i n=true:=by intro n induction n with | zero=>intro i;rfl | succ n ih=> intro i simp only[wFin,Bool.and_eq_true,bne_iff_ne,ne_eq] exact ⟨D.qAe _ (hW _),ih (i+1)⟩ lemma win_hull (g:D_C) (hwp:g.wp=g.s.w+2*g.s.pad) (c y x:Nat) (hc:cogood A[k]! =true) (q:Ὣ):good A[q]! =true:=by by_cases h:q< ѧA;. exact H q h rw[ὑ A q h];rfl lemma qBc {s:OS} {X:ё} {hi:Ὢ} (H:C_Hv X hi) (c yy xx:Ὣ):good (D_px s X c yy xx)=true/\D_px s X c yy xx&&&В<=hi:=by unfold D_px;split;. exact qE1 (A:=X) generalize (c*s.h+(yy-s.pad))*s.w+(xx-s.pad)=n;by_cases h:n< ѧX;. exact ⟨H.2.2.1 n h,H.2.2.2 n h⟩ rw[ὑ X n h];exact qE1 (A:=X) lemma qHk {g:D_C} (ok:D_Ok g) {o t:Ὣ} (hC:osimp only[hd,false_eq_true, ↓reduceIte,zero_add,gt_iff_lt] at h1 h2⊢;. rwa[<-Nat.mul_assoc,<-h1] exact h1▸qDf (h2▸hC) (h1▸ht) lemma qHl {n a b c:Ὣ} (h:nrefine ὼ λe=>?_<;>simp only[e,zero_mul,mul_zero,not_lt_zero] at h lemma qGd {a b st n m:Ὣ} (h0:0ὧ) (L:љ):∀(i:ὦ) (a t:ὧ),Ѥi+ѣL=c.e.toNat-> (∀j p:Ὣ,L[j]?=some p->c.g.xd.data[Ѥb+(c.off[Ѥi+j]!:ὥ).toNat]! =xf p/\c.wd.data[Ѥi+j]! =wf p)-> D_goT c.g.xd c.wd c.off b c.e i c.he c.hw c.hs hb a t=L.foldl (λ(acc:F1) p=>let q:=xf p*wf p F1.mk (acc.s+q) (acc.t+q.abs)) ⟨a,t⟩:=by have:=c.he induction' L with p L ih<;>intro i a t h0 H . rw[D_goT,ἔ (qCk h0.ge)];rfl rw[List.length_cons] at h0 obtain ⟨ht,hu⟩:=qBz h0 have h1:=H 0 p rfl rw[Ἵ] at h1 rw[D_goT,Ἄ ht] simp only[qIg] rw[(qH0 c.hs hb (by exact Nat.lt_of_lt_of_le ‹_› ‹_›)).1,h1.1,h1.2,ih (i+1) _ _ hu,@ὔ] intro j q hq rw[usz i _ ht,Nat.add_right_comm,ὢ] exact H (j+1) q hq def D_ff (xf:Ὣ->Ὣ->ὧ) (wf:Ὣ->ὧ) (L:љ) (k:Ὣ) (a:ὧ):ὧ:= L.foldl (λacc p=>acc+xf k p*wf p) a lemma qF7o {c:D_P} {b:ὦ} (hb:∀j (h:jὫ->ὧ) (wf:Ὣ->ὧ) (L:љ):∀(i:ὦ) (A B C D E F G I:ὧ),Ѥi+ѣL=c.e.toNat-> (∀j p:Ὣ,L[j]?=some p->c.wd.data[Ѥi+j]! =wf p/\∀d,d<8->c.g.xd.data[Ѥb+(c.off[Ѥi+j]!:ὥ).toNat+d]! =xf d p)-> D_go8R1 c.g.xd c.wd c.off b c.e i c.he c.hw c.hs hb A B C D E F G I r=⟨r.t,D_ff xf wf L 0 A,D_ff xf wf L 1 B,D_ff xf wf L 2 C,D_ff xf wf L 3 D,D_ff xf wf L 4 E,D_ff xf wf L 5 F,D_ff xf wf L 6 G,D_ff xf wf L 7 I⟩:=by have:=c.he have:=c.hs induction' L with p L ih<;>intro i A B C D E F G I h0 J . rw[D_go8R1,ἔ (qCk h0.ge)];cases r;rfl rw[List.length_cons] at h0 obtain ⟨ht,hu⟩:=qBz h0 obtain ⟨h1,h2⟩:=J 0 p rfl rw[Ἵ] at h1 h2 obtain ⟨ep,hbd⟩:=qH0 c.hs hb ((by exact Nat.lt_of_lt_of_le ‹_› ‹_›):Ѡi(qBm ep (uk k (by exact Nat.lt_of_lt_of_le ‹_› ה)) (by clear h0 hu;omega)).symm▸h2 k hk rw[D_go8R1,Ἄ ht] simp only[qIg] rw[ep,h1,U 1 ה,U 2 ה,U 3 ה,U 4 ה,U 5 ה,U 6 ה,U 7 (by exact Nat.le_refl _),<-Ἵ (_+_),h2 0 ה] refine ih (i+1) _ _ _ _ _ _ _ _ hu λj q hq=>?_ rw[usz i _ ht,Nat.add_right_comm,ὢ] exact J (j+1) q hq lemma vFug (a:ὤ) (p:ὦ) (h:Ѥp< Ѩa):a.uget p h=a.data[Ѥp]!:=by cases a with | mk d=>simp only[FloatArray.uget];exact (Ἕ d (Ѥp) h).symm lemma vFxv {g:D_C} (ok:D_Ok g) (p:ὦ) (hp:Ѥp< Ѩg.xd):∃u,g.xd.uget p hp=dv u:=by rw[vFug];exact ok.xv _ hp lemma vFwv {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) (q:ὦ) (hq:Ѥq< Ѩc.wd) (he:Ѥq< Ѥc.e):∃u,c.wd.uget q hq=dv u:=by rw[vFug];have hl:Ѥq< ѣL:=h.len▸he;exact ⟨_,(h.rd (Ѥq) L[Ѥq] (List.getElem?_eq_getElem hl)).2⟩ lemma qF7 {c:D_P} {b:ὦ} (hb:∀j (h:jὫ->ὧ) (wf:Ὣ->ὧ) (L:љ) (HX:∀(p:ὦ) (h:Ѥp< Ѩc.g.xd),∃u,c.g.xd.uget p h=dv u) (HW:∀(q:ὦ) (h:Ѥq< Ѩc.wd),Ѥq< Ѥc.e->∃u,c.wd.uget q h=dv u):∀(i:ὦ) (A B C D E F G I:ὧ),Ѥi+ѣL=c.e.toNat-> (∀j p:Ὣ,L[j]?=some p->c.wd.data[Ѥi+j]! =wf p/\∀d,d<8->c.g.xd.data[Ѥb+(c.off[Ѥi+j]!:ὥ).toNat+d]! =xf d p)-> D_go8R c.g.xd c.wd c.off b c.e i c.he c.hw c.hs hb A B C D E F G I r=⟨r.t,D_ff xf wf L 0 A,D_ff xf wf L 1 B,D_ff xf wf L 2 C,D_ff xf wf L 3 D,D_ff xf wf L 4 E,D_ff xf wf L 5 F,D_ff xf wf L 6 G,D_ff xf wf L 7 I⟩:=by intro i A B C D E F G I h0 J rw[qGR _ _ _ _ _ _ _ _ _ HX HW];exact qF7o hb r xf wf L i A B C D E F G I h0 J lemma D_zt_spec (xd:ὤ) (off:ѐ) (b:Nat): ∀n i,D_zt xd off b i n=true-> ∀j,i<=j->j< i+n->(xd.data[b+(off[j]!).toNat]!).toBits<<<(1:Ὠ)=0:=by intro n induction n with | zero=>intro i _ j h1 h2;omega | succ n ih=> intro i h j h1 h2 simp only[D_zt,Bool.and_eq_true,decide_eq_true_eq,beq_iff_eq] at h by_cases hj:j=i · subst hj have e:=h.1.2 have g:xd.get! (b+(off[j]!).toNat)=xd.data[b+(off[j]!).toNat]!:=by cases xd;rfl rw[g] at e exact e · exact ih (i+1) h.2 j (by exact omS138 h1 hj) (by exact omS7 h2) lemma Rz0 (f:ὧ) (h:f.toBits<<<(1:Ὠ)=0):D.R f=0:=by have h0:(f.toBits<<<(1:Ὠ)).toNat=0:=by rw[h];rfl rw[UInt64.toNat_shiftLeft] at h0 have hl:=f.toBits.toNat_lt have h1:(1:Ὠ).toNat%64=1:=rfl rw[h1,ὁ] at h0 have g:Model.expField (toModel (ofFloat f:Binary64))=f.toBits.toNat/2^52%2^11:=by show ((f.toBits.toBitVec>>>52)&&&BitVec.ofNat 64 2047).toNat=_ rw[BitVec.toNat_and,BitVec.toNat_ushiftRight,BitVec.toNat_ofNat,Ἱ] exact Ἂ _ 11 have e:Model.fracField (toModel (ofFloat f:Binary64))=f.toBits.toNat%2^52:=by show (f.toBits.toBitVec&&&BitVec.ofNat 64 (2^52-1)).toNat=_ rw[BitVec.toNat_and,BitVec.toNat_ofNat] exact Ἂ _ 52 have g0:f.toBits.toNat/2^52%2^11=0:=א have e0:f.toBits.toNat%2^52=0:=א have c:=Model.ofFields_signBit_expField_fracField (toModel (ofFloat f:Binary64)) rw[g,e,g0,e0] at c have a:Model.isFinite (Model.ofFields D.B_D (Model.signBit (toModel (ofFloat f:Binary64))) 0 0)=true:=by rw[Model.isFinite_ofFields D.B_D _ _ _ ה ה] rfl have d:=Model.toDyadic?_ofFields_of_isFinite D.B_D _ _ _ ה ה a rw[c] at d rw[D.R,Model.toReal_eq,d] simp only[↓reduceIte,Nat.reduceAdd,toModel_ofFloat,FloatLib.Numerics.Dyadic.toReal,signedSignificand,Int.ofNat_eq_natCast,CharP.cast_eq_zero,neg_zero,ite_self,Int.cast_zero,zpow_ofNat,pow_zero,mul_one] lemma mant_of_dv0 (w:ὥ) (hg:D.good w=true) (h:(D.dv w).toBits<<<(1:Ὠ)=0):mantOf w=0:=by have h1:=(D.qAm w hg).2 rw[Rz0 _ h,D.qA7 w hg] at h1 have h2:D.A_mag (w.toNat%2^31)=0:=by split at h1<;>linarith only[h1] unfold D.A_mag at h2 split at h2 · rename_i hv apply zw_mant apply UInt32.toNat_inj.mp rw[Ἧ] have h3:(В:ὥ).toNat=2^31-1:=rfl rw[h3,Ἂ,hv];rfl · exfalso have:(0:ℝ)<((2^23+w.toNat%2^31%2^23:ℕ):ℝ)*2^((((w.toNat%2^31)/2^23:ℕ):ℤ)-150):=ו linarith only[h2,this] lemma zt_out {c:D_P} {o:Nat} {L:љ} (h:D_PO c o L) {y x:Nat} {b:ὦ} (hy:yif tif tif tif tif tif trfl section variable {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) {y x:Ὣ} {b:ὦ} (hy:y< c.g.ho) (hx:x< c.g.wo) (hb:Ѥb=D_B c.g y x) include c o L h y x b hy hx hb lemma qCvY:D_slowY c o y x b=D_out c.g o y x:=by unfold D_slowY split · rename_i hz;exact (zWinX_out c.g h.ok.hk h.ok.pk h.ok.HW h.ok.wp o y x (λhd=>by have e:=h.ok.hC;simp only[hd,ite_true] at e;exact e▸h.hC) hy hz).symm split · rename_i hz;simp only[Bool.and_eq_true,beq_iff_eq] at hz;exact (zt_out h hy hx hb hz.2 hz.1).symm · exact qCvZ .. lemma qCu:D_finT c o y x b=D_out c.g o y x:=by unfold D_finT;split<;>rename_i hl;swap;. exact qCv .. have e:=qGc (c.h1 b hl) (dv∘D_xw c.g o y x) (λp=>dv c.g.W[o*c.g.k+p]!) L 0 0 0 ((Ἇ _).trans h.len.symm) λj p hj=>by have h1:=h.rd j p hj;rw[C_z,Ἇ,h1.1,hb];exact ⟨(qCf h.ok h.hC hy hx (h.lt p (List.mem_of_getElem? hj))).2,h1.2⟩ simp only[c.hz,e,h.bv,h.ok.nf];split<;>rename_i hz;. split;exact qCvY h hy hx hb;exact qCv .. exact congrArg (act _) (qDq c.g.k h.ok.nk _ _ _ (λt _=>(qBc h.ok.Hx _ _ _).1) (λt _=>h.ok.HW _) (h.ok.Hb _) L h.nd h.lt (λt a b=>.inr (h.hz t a b)) _ _ ⟨rfl,rfl⟩ (by simpa only[Function.comp_apply,ne_eq,beq_iff_eq] using hz)) lemma qF6 {a:ὧ} (ha:a=L.foldl (λacc t=>acc+dv (D_xw c.g o y x t)*dv c.g.W[o*c.g.k+t]!) 0):D_fin c o y x b a=D_out c.g o y x:=by subst ha;simp only[D_fin,h.bv,h.e0];split<;>rename_i hz;. split;exact qCvY h hy hx hb;exact qCu h hy hx hb exact congrArg (act _) (qC3 c.g.k h.ok.nk _ _ _ _ (λt _=>(qBc h.ok.Hx _ _ _).1) (λt _=>h.ok.HW _) (h.ok.Hb _) h.ok.Hx.1 (λt _=>(qBc h.ok.Hx _ _ _).2) h.ok.Hx.2.1 L h.nd h.lt (λt a b=>.inr (h.hz t a b)) _ _ ⟨rfl,rfl⟩ (by simpa only[ne_eq,beq_iff_eq] using hz)) end lemma qIk {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) {y x k:Ὣ} {b:ὦ} (hy:yacc+dv (D_xw c.g o y (x+k) t)*dv c.g.W[o*c.g.k+t]!) 0):D_w c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o y x b k a=D_out c.g o y (x+k):=by unfold D_w;dsimp only;split<;>rename_i hc . obtain ⟨h1,h2⟩:=ὕ.mp hc;have h1:((a+c.bv).toBits<<<(1:Ὠ))-loOf c.e0(qBc h.ok.Hx _ _ _).1) (λt _=>h.ok.HW _) (h.ok.Hb _) h.ok.Hx.1 (λt _=>(qBc h.ok.Hx _ _ _).2) h.ok.Hx.2.1 L h.nd h.lt (λt a b=>.inr (h.hz t a b)) _ _ ⟨rfl,rfl⟩ e2) . split . split . rename_i hz;simp only[Bool.and_eq_true,beq_iff_eq] at hz exact (zt_out h hy hx hb (D_ztF_imp0 _ _ _ _ hz.2) hz.1).symm . exact qCvY h hy hx hb . unfold D_finK;exact qF6 h hy hx hb ha def D_sp (g:D_C) (q:Ὣ):Ὢ:= D_out g (q/(g.ho*g.wo)) (q/g.wo%g.ho) (q%g.wo) lemma qG9 (g:D_C) {o y x:Ὣ} (hy:yp(xѤb=D_B c.g y x)->(xѤq=Q+x)->D_I c Q x out-> C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>pD_out c.g o y x'=D_sp c.g (Q+x'):=λ_ hx=>hQ▸qG9 c.g hy hx rw[D_cols] split<;>rename_i h8 . obtain ⟨hx,hf,hl⟩:=h8;have hb0:=hb hx;have hq0:=hq hx;have hB:=λk=>(qIn c.g y x k).trans (by rw[h.ok.f4 hf,Nat.mul_one]);have G:=λk (hk:x+kqBm hb0 (uk k (by clear hy he hx hl hb0;exact omS392 hN sN hk)) (hB k▸qGa h.ok h.hC hy hk);have V:=λk (hk:x+k<=c.g.wo)=>(qBm hq0 (uk k (by clear hy he hx hl hb0;exact omS393 hN sN hk)) (by clear hy he hx hl hb0;exact omS394 hN sN hk)).trans (ὢ Q x k) have R:=qF7 (c.h8 b hl) rr (D_xf c o b) (λp=>dv c.g.W[o*c.g.k+p]!) L (vFxv h.ok) (vFwv h) 0 0 0 0 0 0 0 0 0 ((Ἇ _).trans h.len.symm) λj p hj=>by have h1:=h.rd j p hj;rw[C_z,Ἇ,h1.1];exact ⟨h1.2,λ_ _=>rfl⟩ have wL:c.g.wo<2^32:=by have:=Nat.le_mul_of_pos_left c.g.wo ((by clear hQ hN he sN hx hb0 hq0;exact omS147 hy):0∀u,D_I c Q (x+k) u->D_I c Q (x+k+1) (D_l c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o y x b q (c.g.wo-x).toUSize k (D_ff (D_xf c o b) (λp=>dv c.g.W[o*c.g.k+p]!) L k 0) u):=λk k8 u H=>by have hN:(ὴ k<(c.g.wo-x).toUSize)↔x+krename_i hk;. rw[Nat.min_eq_left hk.le] at H;rw[Nat.min_eq_left hk];refine qBn sN H (V k (by exact Nat.le_of_lt ‹_›)) (by clear hy he sN hx hb0 wL k8 hN;exact omS397 hN hk) ((qIk h hy hk ((G k hk).trans (hB k).symm) (List.foldl_ext _ _ _ λ_ p hp=>?_)).trans (S _ hk));simp only[D_xf];rw[Nat.add_right_comm,hb0,<-hB,(qCf h.ok h.hC hy hk (h.lt p hp)).2] . rw[Nat.min_eq_right (Nat.not_lt.1 hk)] at H;rwa[Nat.min_eq_right (by exact omS398 hk)] simp only[c.hz,R];refine ih (c.g.wo-(x+8)) (by clear hy hQ hN sN hb0 hq0 wL;exact omS399 he hx) (x+8) _ _ _ _ rfl (λhk=>(G 8 hk).trans (hB 8).symm) (λhk=>V 8 hk.le) ?_ have A':∀k,k<8->8<=(c.g.wo-x).toUSize->∀u (hu:(q+ὴ k).toNat< ѧu),D_I c Q (x+k) u->D_I c Q (x+k+1) (u.uset (q+ὴ k) (D_w c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o y x b k (D_ff (D_xf c o b) (λp=>dv c.g.W[o*c.g.k+p]!) L k 0)) hu):=λk k8 h8 u hu H0=>by have h0:=A k k8 u H0;unfold D_l at h0;rw[ἱ (lcN8 h8 k k8)] at h0;unfold D_I C_Inv at H0;rwa[lcWU _ _ _ hu (by rw[H0.1];exact sN)] unfold D_g8;split . rename_i hzb;simp only[Bool.and_eq_true,beq_iff_eq,D_zbk] at hzb have B0:∀k,k<8->∀u,D_I c Q (x+k) u->D_I c Q (x+k+1) (D_zl q (c.g.wo-x).toUSize k u):=λk k8 u H=>by have hN:(ὴ k<(c.g.wo-x).toUSize)↔x+krename_i hk . rw[Nat.min_eq_left hk.le] at H;rw[Nat.min_eq_left hk];exact qBn sN H (V k (by exact Nat.le_of_lt ‹_›)) (by clear hy he sN hx hb0 wL k8 hN;exact omS397 hN hk) ((zt_out h hy hk ((G k hk).trans (hB k).symm) (by rw[G k hk,<-hb0];exact D_ztB_imp0 _ _ _ _ hzb.2.2 k k8) hzb.2.1).symm.trans (S _ hk)) . rw[Nat.min_eq_right (Nat.not_lt.1 hk)] at H;rwa[Nat.min_eq_right (by exact omS398 hk)] exact B0 7 ה _ (B0 6 ה _ (B0 5 ה _ (B0 4 ה _ (B0 3 ה _ (B0 2 ה _ (B0 1 ה _ (B0 0 ה _ H))))))) . unfold D_g8a;split . rename_i hq;exact A' 7 ה hq.1 _ _ (A' 6 ה hq.1 _ _ (A' 5 ה hq.1 _ _ (A' 4 ה hq.1 _ _ (A' 3 ה hq.1 _ _ (A' 2 ה hq.1 _ _ (A' 1 ה hq.1 _ _ (A' 0 ה hq.1 _ _ H))))))) . exact (A 7 (by exact Nat.le_refl _) _ (A 6 ה _ (A 5 ה _ (A 4 ה _ (A 3 ה _ (A 2 ה _ (A 1 ה _ (A 0 ה _ H)))))))) split<;>rename_i h1 . have hb0:=hb h1;unfold D_I at*;rw[Nat.min_eq_left h1.le] at H;refine ih (c.g.wo-(x+1)) (by clear hy hQ hN sN hb0;exact omS204 he h1) (x+1) _ _ _ _ rfl (λhx=>?_) (λ_=>(qBm (hq h1) ὄ (by clear hy he h8 h1 hb0;omega)).trans rfl) ?_;. have:=qGa h.ok h.hC hy hx;rw[qIn,Ὑ] at this⊢;exact qBm hb0 h.ok.st this . rw[qCu h hy h1 hb0,Nat.min_eq_left h1];exact qBn sN H (hq h1) (by clear hy he sN h8 hb0;exact omS15 hN h1) (S _ h1) unfold D_I at H rwa[Nat.min_eq_right (by clear hy hQ hN he sN h8;exact omS400 h1)] at H lemma qFeZ {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) {y Q:Ὣ} (hy:y(xѤb=D_B c.g y x)->(xѤq=Q+x)->D_I c Q x out-> C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>pD_out c.g o y x'=D_sp c.g (Q+x'):=λ_ hx=>hQ▸qG9 c.g hy hx rw[D_colsZ] split<;>rename_i h8 . obtain ⟨hx,hf,hl⟩:=h8;have hb0:=hb hx;have hq0:=hq hx;have hB:=λk=>(qIn c.g y x k).trans (by rw[h.ok.f4 hf,Nat.mul_one]);have G:=λk (hk:x+kqBm hb0 (uk k (by clear hy he hx hl hb0;exact omS392 hN sN hk)) (hB k▸qGa h.ok h.hC hy hk);have V:=λk (hk:x+k<=c.g.wo)=>(qBm hq0 (uk k (by clear hy he hx hl hb0;exact omS393 hN sN hk)) (by clear hy he hx hl hb0;exact omS394 hN sN hk)).trans (ὢ Q x k) have R:=qF7 (c.h8 b hl) rr (D_xf c o b) (λp=>dv c.g.W[o*c.g.k+p]!) L (vFxv h.ok) (vFwv h) 0 0 0 0 0 0 0 0 0 ((Ἇ _).trans h.len.symm) λj p hj=>by have h1:=h.rd j p hj;rw[C_z,Ἇ,h1.1];exact ⟨h1.2,λ_ _=>rfl⟩ have wL:c.g.wo<2^32:=by have:=Nat.le_mul_of_pos_left c.g.wo ((by clear hQ hN he sN hx hb0 hq0;exact omS147 hy):0∀u,D_I c Q (x+k) u->D_I c Q (x+k+1) (D_zl q (c.g.wo-x).toUSize k u):=λk k8 u H=>by have hN:(ὴ k<(c.g.wo-x).toUSize)↔x+krename_i hk . rw[Nat.min_eq_left hk.le] at H;rw[Nat.min_eq_left hk];exact qBn sN H (V k (by exact Nat.le_of_lt ‹_›)) (by clear hy he sN hx hb0 wL k8 hN;exact omS397 hN hk) ((zWinX_out c.g h.ok.hk h.ok.pk h.ok.HW h.ok.wp o y (x+k) (λhd=>by have e:=h.ok.hC;simp only[hd,ite_true] at e;exact e▸h.hC) hy (zBlk_lane c.g (h.ok.f4 hf) o y x k k8 hz)).symm.trans (S _ hk)) . rw[Nat.min_eq_right (Nat.not_lt.1 hk)] at H;rwa[Nat.min_eq_right (by exact omS398 hk)] exact ih (c.g.wo-(x+8)) (by clear hy hQ hN sN hb0 hq0 wL;exact omS399 he hx) (x+8) _ _ _ _ rfl (λhk=>(G 8 hk).trans (hB 8).symm) (λhk=>V 8 hk.le) (A0 7 ה _ (A0 6 ה _ (A0 5 ה _ (A0 4 ה _ (A0 3 ה _ (A0 2 ה _ (A0 1 ה _ (A0 0 ה _ H)))))))) simp only[hz,Bool.false_eq_true,↓reduceIte] have A:∀k,k<8->∀u,D_I c Q (x+k) u->D_I c Q (x+k+1) (D_l c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o y x b q (c.g.wo-x).toUSize k (D_ff (D_xf c o b) (λp=>dv c.g.W[o*c.g.k+p]!) L k 0) u):=λk k8 u H=>by have hN:(ὴ k<(c.g.wo-x).toUSize)↔x+krename_i hk;. rw[Nat.min_eq_left hk.le] at H;rw[Nat.min_eq_left hk];refine qBn sN H (V k (by exact Nat.le_of_lt ‹_›)) (by clear hy he sN hx hb0 wL k8 hN;exact omS397 hN hk) ((qIk h hy hk ((G k hk).trans (hB k).symm) (List.foldl_ext _ _ _ λ_ p hp=>?_)).trans (S _ hk));simp only[D_xf];rw[Nat.add_right_comm,hb0,<-hB,(qCf h.ok h.hC hy hk (h.lt p hp)).2] . rw[Nat.min_eq_right (Nat.not_lt.1 hk)] at H;rwa[Nat.min_eq_right (by exact omS398 hk)] simp only[c.hz,R];refine ih (c.g.wo-(x+8)) (by clear hy hQ hN sN hb0 hq0 wL;exact omS399 he hx) (x+8) _ _ _ _ rfl (λhk=>(G 8 hk).trans (hB 8).symm) (λhk=>V 8 hk.le) ?_ have A':∀k,k<8->8<=(c.g.wo-x).toUSize->∀u (hu:(q+ὴ k).toNat< ѧu),D_I c Q (x+k) u->D_I c Q (x+k+1) (u.uset (q+ὴ k) (D_w c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o y x b k (D_ff (D_xf c o b) (λp=>dv c.g.W[o*c.g.k+p]!) L k 0)) hu):=λk k8 h8 u hu H0=>by have h0:=A k k8 u H0;unfold D_l at h0;rw[ἱ (lcN8 h8 k k8)] at h0;unfold D_I C_Inv at H0;rwa[lcWU _ _ _ hu (by rw[H0.1];exact sN)] unfold D_g8a;split . rename_i hq;exact A' 7 ה hq.1 _ _ (A' 6 ה hq.1 _ _ (A' 5 ה hq.1 _ _ (A' 4 ה hq.1 _ _ (A' 3 ה hq.1 _ _ (A' 2 ה hq.1 _ _ (A' 1 ה hq.1 _ _ (A' 0 ה hq.1 _ _ H))))))) . exact (A 7 (by exact Nat.le_refl _) _ (A 6 ה _ (A 5 ה _ (A 4 ה _ (A 3 ה _ (A 2 ה _ (A 1 ה _ (A 0 ה _ H)))))))) split<;>rename_i h1 . have hb0:=hb h1;unfold D_I at*;rw[Nat.min_eq_left h1.le] at H;refine ih (c.g.wo-(x+1)) (by clear hy hQ hN sN hb0;exact omS204 he h1) (x+1) _ _ _ _ rfl (λhx=>?_) (λ_=>(qBm (hq h1) ὄ (by clear hy he h8 h1 hb0;omega)).trans rfl) ?_;. have:=qGa h.ok h.hC hy hx;rw[qIn,Ὑ] at this⊢;exact qBm hb0 h.ok.st this . rw[qCu h hy h1 hb0,Nat.min_eq_left h1];exact qBn sN H (hq h1) (by clear hy he sN h8 hb0;exact omS15 hN h1) (S _ h1) unfold D_I at H rwa[Nat.min_eq_right (by clear hy hQ hN he sN h8;exact omS400 h1)] at H lemma qHu {u v:ὦ} {a b:Ὣ} (hu:Ѥu=a) (hv:Ѥv=b) (h:a*b<2^32):(u*v).toNat=a*b:=by rw[qIb _ _ (by rw[hu,hv];exact h),hu,hv] lemma qEy {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) (hN:(o*c.g.ho+c.g.ho)*c.g.wo<=c.g.C*(c.g.ho*c.g.wo)) (d:Ὣ): ∀(y:Ὣ) (q:ὦ) (rs:List D_R) (out:ё),y+d=c.g.ho-> Ѥq=(o*c.g.ho+y)*c.g.wo->C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+y)*c.g.wo) out-> C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+c.g.ho)*c.g.wo) (D_rows c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o y q rs out):=by induction' d with d ih<;>intro y q rs out he hq H . rw[D_rows,ἐ (by clear hN hq;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))))];rwa[((by exact omS155 he):y=c.g.ho)] at H have hy:yrw[<-ὢ,Nat.add_one_mul] . exact qBm hq eW (by exact omS403 hN sN hA) exact qFe h hy rfl (by exact Nat.le_trans ‹_› ‹_›) c.g.wo 0 _ _ _ _ (Nat.sub_zero _) (λ_=>(qHu (qHu (qAa y א) h.ok.st (by exact Nat.lt_of_le_of_lt ‹_› ‹_›)) (qAa _ h.ok.wp2) bB).trans (by simp only[D_B,zero_mul,add_zero])) (λ_=>hq) (by unfold D_I;rw[Nat.zero_min];exact H) lemma qEyZ {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) (hN:(o*c.g.ho+c.g.ho)*c.g.wo<=c.g.C*(c.g.ho*c.g.wo)) (d:Ὣ): ∀(y:Ὣ) (q:ὦ) (rs:List D_R) (out:ё),y+d=c.g.ho-> Ѥq=(o*c.g.ho+y)*c.g.wo->C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+y)*c.g.wo) out-> C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+c.g.ho)*c.g.wo) (D_rowsZ c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o y q rs out):=by induction' d with d ih<;>intro y q rs out he hq H . rw[D_rowsZ,ἐ (by clear hN hq;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))))];rwa[((by exact omS155 he):y=c.g.ho)] at H have hy:yrw[<-ὢ,Nat.add_one_mul] . exact qBm hq eW (by exact omS403 hN sN hA) exact qFeZ h hy rfl (by exact Nat.le_trans ‹_› ‹_›) c.g.wo 0 _ _ _ _ (Nat.sub_zero _) (λ_=>(qHu (qHu (qAa y א) h.ok.st (by exact Nat.lt_of_le_of_lt ‹_› ‹_›)) (qAa _ h.ok.wp2) bB).trans (by simp only[D_B,zero_mul,add_zero])) (λ_=>hq) (by unfold D_I;rw[Nat.zero_min];exact H) lemma qGt (s:OS) (o:Ὣ) {p:Ὣ} (hp:pὪ) (sz t:Ὣ) (off:ѐ) (buf:ὤ) (c:ὦ) (l:ὧ):Prop:= Ѥc=(C_keep xw t).length/\ѧoff=sz/\Ѩbuf=sz/\ (∀k p:Ὣ,(C_keep xw t)[k]?=some p-> (off[k]!:ὥ)=(D_off g.s (D_t0 g o+p)).toUInt32/\buf.data[k]! =dv (xw p))/\ l=(C_keep xw t).foldl (λ(a:ὧ) p=>a+(dv (xw p)).abs) 0 lemma qHn {g:D_C} (ok:D_Ok g) {o' n:ὦ} (o:Ὣ) (xw:Ὣ->Ὢ) (hk:Ѥn=g.k) (hn:Ѥn<2^32) (hxw:∀t:ὦ,trdW g.W (o'+t)=xw Ѥt) (d:Ὣ): ∀(t:ὦ) (off:ѐ) (buf:ὤ) (c:ὦ) (l:ὧ) (m:ὥ) (hm:∀j (h:j< ѧoff),off[j].toNat<=ѥm),Ѥt+d=Ѥn->D_Dc g o xw Ѥn Ѥt off buf c l-> D_Dc g o xw Ѥn Ѥn (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) o' n t off buf c l m hm).off (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) o' n t off buf c l m hm).buf (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) o' n t off buf c l m hm).c (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) o' n t off buf c l m hm).l:=by induction d with | zero=> intro t off buf c l m hm he H rw[D_dec,ἔ (by rw[А];exact omS404 he)] have e:Ѥt=Ѥn:=(by exact omS155 he) rw[e] at H;exact H | succ d ih=> intro t off buf c l m hm he H have ht:t?_,by rw[List.foldl_append,<-h5];rfl⟩;. rw[qAv _ _ (by rw[ὄ];(exact Nat.lt_of_le_of_lt ‹_› ‹_›)),ὄ,h1];simp only[List.length_append,List.length_cons,List.length_nil,zero_add,Nat.add_left_cancel_iff] . rw[qAq _ _ _ _ (by clear ht h1 hl hc hcn;exact omS360 hn h2) (by clear hn ht hl hc;exact omS140 h2 hcn),qCr _ _ _ _ (by clear ht h1 hl hc hcn;exact omS360 hn h3) (by clear hn ht hl hc;exact omS140 h3 hcn)];rw[List.getElem?_append,<-h1] at hk2;by_cases e:k=Ѥc;. subst e;simp only[lt_self_iff_false, ↓reduceIte,tsub_self,List.length_cons,List.length_nil,zero_add,Order.lt_one_iff,getElem?_pos,List.getElem_cons_zero,Option.some.injEq] at hk2;subst hk2;rw[ἱ rfl,ἱ rfl];exact ⟨qHp ok o (by clear hn ht h1 hl hc hcn;exact omS406 hk he),rfl⟩ . rw[ἐ e,ἐ e];by_cases e2:k< Ѥc;. rw[ἱ e2] at hk2;exact h4 k p hk2 . rw[ἐ e2] at hk2;obtain ⟨z,hz'⟩:∃z,k-Ѥc=z+1:=⟨k-Ѥc-1,by (clear hk hn he ht hu h2 h3 hl hc hcn;exact omS407 e e2)⟩;rw[hz'] at hk2;simp only[List.length_cons,List.length_nil,zero_add,Order.lt_one_iff,Nat.add_eq_zero_iff,one_ne_zero,and_false,not_false_eq_true,getElem?_neg,reduceCtorEq] at hk2 lemma qIi {g:D_C} (ok:D_Ok g) {o:Ὣ} (hC:og.W[o*g.k+p]!) g.k g.k (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) (o*g.k).toUSize g.k.toUSize 0 off buf 0 0 m hm).off (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) (o*g.k).toUSize g.k.toUSize 0 off buf 0 0 m hm).buf (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) (o*g.k).toUSize g.k.toUSize 0 off buf 0 0 m hm).c (D_dec g.tab g.W (if g.dw then (o*((g.s.h+2*g.s.pad)*g.wp)).toUInt32 else 0) (o*g.k).toUSize g.k.toUSize 0 off buf 0 0 m hm).l:=by have hX:=ok.sW2 have hP:=(qBv hC (Nat.le_refl g.k)).trans_eq ok.sW.symm have eo:(o*g.k).toUSize.toNat=o*g.k:=qAa _ (by clear hC;exact omS154 hX hP) have ek:g.k.toUSize.toNat=g.k:=qAa _ (by clear hC h2;(clear h3;exact omS408 hX hP)) have D:=qHn (o':=(o*g.k).toUSize) (n:=g.k.toUSize) ok o (λp=>g.W[o*g.k+p]!) ek (by rw[ek];(clear hC h2;(clear h3;exact omS408 hX hP))) (λt ht=>by have h4:=А.mp ht rw[ek] at h4 rw[qAo _ _ hX,qAv _ _ (by rw[eo];(clear hC h2 ht;(clear h3;exact omS145 hX hP h4))),eo]) g.k 0 off buf 0 0 m hm (by rw[C_z,ek,Ἇ]) ⟨by simp only[USize.toNat_zero,C_keep,List.range_zero,List.filter_nil,List.length_nil],by rw[ek];exact h2,by rw[ek];exact h3,λk p hk=>by simp only[C_keep,USize.toNat_zero,List.range_zero,List.filter_nil,List.length_nil,not_lt_zero,not_false_eq_true,getElem?_neg,reduceCtorEq] at hk,by simp only[C_keep,USize.toNat_zero,List.range_zero,List.filter_nil,List.foldl_nil]⟩ rw[ek] at D exact D lemma qFi (A:ѐ) (n:ὦ) (hn:Ѥn<=ѧA) (d:Ὣ): ∀(i:ὦ) (lo hi:ὥ),Ѥi+d=Ѥn->scan A n i hn lo hi= if 0x007FFFFF<=(D_scan A n i hn lo hi).lo/\(D_scan A n i hn lo hi).hi<У then (D_scan A n i hn lo hi).hi else Е:=by induction' d with d ih<;>intro i lo hi he<;>rw[scan,D_scan] . simp only[ἔ (qCk he.ge)] simp only[Ἄ (qBz he).1] exact ih (i+1) _ _ (qBz he).2 lemma qFw (s:OS) {c r q:Ὣ} (hr:rt=(c*s.kh+r)*s.kw+q->rqa=(Array.ofFn (n:=t) λi=>(D_off s i.val).toUInt32)-> D_tq k s.kw s.kh (s.h+2*s.pad) (s.w+2*s.pad) t c r q a=Array.ofFn (n:=k) λi=>(D_off s i.val).toUInt32:=by induction d with | zero=> intro t c r q a h1 _ _ _ h5 have e:t=k:=h1 subst e rw[D_tq,ἐ (Nat.lt_irrefl _)] exact h5 | succ d ih=> intro t c r q a h1 h2 h3 h4 h5 have hp:a.push ((c*(s.h+2*s.pad)+r)*(s.w+2*s.pad)+q).toUInt32=Array.ofFn (n:=t+1) λi=>(D_off s i.val).toUInt32:=by rw[<-qFw s h3 h4,<-h2,h5,Array.ofFn_succ] rfl rw[D_tq,ἱ (by clear h3 h4;exact omS136 h1)] dsimp only rw[hp] split . exact ih (t+1) c r (q+1) _ (by exact omS137 h1) (by exact omS409 h2) h3 (by assumption) rfl split . have e:(c*s.kh+(r+1))*s.kw=(c*s.kh+r)*s.kw+s.kw:=by ring exact ih (t+1) c (r+1) 0 _ (by exact omS137 h1) א (by assumption) א rfl . have e2:s.kh=r+1:=א;have e:((c+1)*s.kh+0)*s.kw=(c*s.kh+r)*s.kw+s.kw:=by rw[e2];ring exact ih (t+1) (c+1) 0 0 _ (by exact omS137 h1) א א א rfl lemma qFz (c:D_P) (lo sp:Ὠ) (o y:Ὣ) (q0:ὦ) (hy:y ∃rr':D_R,D_rc c lo sp o y x b q q0 rr out= D_rc c lo sp o (y+1) 0 ((y+1).toUSize*c.g.step*c.g.wp.toUSize) (q0+c.g.wo.toUSize) (q0+c.g.wo.toUSize) rr' (D_cols c lo sp o y x b q rr out):=by induction' d using Nat.strong_induction_on with d ih intro x b q rr out he rw[D_rc,D_cols,Ἄ hy] by_cases h8:x ∃rs:List D_R,D_rc c lo sp o y 0 (ѩy*c.g.step*c.g.wp.toUSize) q0 q0 rr out=D_rows c lo sp o y q0 rs out:=by induction d with | zero=> intro y q0 rr out he have hy:¬y intro y q0 rr out he have hy:yrw[D_rows,ἱ hy] rfl lemma qF8 {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) (hN:(o*c.g.ho+c.g.ho)*c.g.wo<=c.g.C*(c.g.ho*c.g.wo)) {q:ὦ} {out:ё} (hq:Ѥq=(o*c.g.ho+0)*c.g.wo) (H:C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+0)*c.g.wo) out): C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+c.g.ho)*c.g.wo) (D_rc c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o 0 0 ((0:Ὣ).toUSize*c.g.step*c.g.wp.toUSize) q q ⟨0,0,0,0,0,0,0,0,0⟩ out):=by obtain ⟨rs,hrs⟩:=qFa c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o _ 0 q ⟨0,0,0,0,0,0,0,0,0⟩ out rfl rw[hrs] exact qEy h hN c.g.ho 0 q rs out (Ἇ _) hq H lemma qFzZ (c:D_P) (lo sp:Ὠ) (o y:Ὣ) (q0:ὦ) (hy:y ∃rr':D_R,D_rcZ c lo sp o y x b q q0 rr out= D_rcZ c lo sp o (y+1) 0 ((y+1).toUSize*c.g.step*c.g.wp.toUSize) (q0+c.g.wo.toUSize) (q0+c.g.wo.toUSize) rr' (D_colsZ c lo sp o y x b q rr out):=by induction' d using Nat.strong_induction_on with d ih intro x b q rr out he rw[D_rcZ,D_colsZ,Ἄ hy] by_cases h8:x ∃rs:List D_R,D_rcZ c lo sp o y 0 (ѩy*c.g.step*c.g.wp.toUSize) q0 q0 rr out=D_rowsZ c lo sp o y q0 rs out:=by induction d with | zero=> intro y q0 rr out he have hy:¬y intro y q0 rr out he have hy:yrw[D_rowsZ,ἱ hy] rfl lemma qF8Z {c:D_P} {o:Ὣ} {L:љ} (h:D_PO c o L) (hN:(o*c.g.ho+c.g.ho)*c.g.wo<=c.g.C*(c.g.ho*c.g.wo)) {q:ὦ} {out:ё} (hq:Ѥq=(o*c.g.ho+0)*c.g.wo) (H:C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+0)*c.g.wo) out): C_Inv (c.g.C*(c.g.ho*c.g.wo)) (D_sp c.g) (λp=>p<(o*c.g.ho+c.g.ho)*c.g.wo) (D_rcZ c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o 0 0 ((0:Ὣ).toUSize*c.g.step*c.g.wp.toUSize) q q ⟨0,0,0,0,0,0,0,0,0⟩ out):=by obtain ⟨rs,hrs⟩:=qFaZ c (loOf c.e0) (spR c.g.relu (loOf c.e0)) o _ 0 q ⟨0,0,0,0,0,0,0,0,0⟩ out rfl rw[hrs] exact qEyZ h hN c.g.ho 0 q rs out (Ἇ _) hq H section variable {g:D_C} (ok:D_Ok g) include g ok lemma qC4 {o:Ὣ} (hC:oѤq=o*(g.ho*g.wo)->C_Inv (g.C*(g.ho*g.wo)) (D_sp g) (λp=>p C_Inv (g.C*(g.ho*g.wo)) (D_sp g) (λp=>pintro o q out he hq H . rw[D_outsC,ἐ (by clear hs hq;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))))];rwa[((by exact omS155 he):o=g.C)] at H have hC:og.W[o*g.k+p]!) g.k have hlen:=d1.trans_le (qCb _ _) rw[D_outsC,ἱ hC] dsimp only simp only[qC4 ok hC] rw[Ἄ (by clear he hq hC hkn sW2 sN hP hO eB;(clear h2;exact omS414 d2 d3 hlen)),eB] refine ih (o+1) _ _ (by clear hq hC hkn sW2 sN hP hO eB h2 h3 d1 d2 d3 hlen;exact omS137 he) (Nat.add_one_mul o _▸qBm hq (qAa _ (by clear he hC hkn sW2 hP eB h2 h3 d1 d2 d3 hlen;exact omS408 sN hO)) (by exact Nat.lt_of_le_of_lt ‹_› ‹_›)) ?_ have E:(o*g.ho+g.ho)*g.wo=o*(g.ho*g.wo)+g.ho*g.wo:=by ring rw[Nat.add_one_mul,<-E] rw[<-Nat.mul_assoc o] at hq H by_cases hE:g.ex.1.isEmpty=true . rw[ἱ hE] refine qF8 (L:=C_keep _ g.k) ⟨ok,hC,d1,k1,k2,k3,λj p hj=>?_,by dsimp only;rw[ok.nf,d5],rfl⟩ (by dsimp only;(clear he hq hC hkn sW2 sN hP eB h2 h3 d1 d2 d3 hlen;exact omS415 hO E)) hq H have hjl:=(List.getElem?_eq_some_iff.mp hj).1 refine ⟨?_,(d4 j p hj).2⟩ dsimp only rw[(d4 j p hj).1] simpa only[Nat.toUInt32_eq,ὡ,Nat.reducePow,Nat.mod_succ_eq_iff_lt,Nat.succ_eq_add_one,Nat.reduceAdd] using Ἁ ((Nat.lt_of_add_left_lt (qCf ok hC (y:=0) (x:=0) (ok.ho▸Nat.succ_pos _) (ok.wo▸Nat.succ_pos _) (k2 _ (List.mem_of_getElem? hj))).1).trans ok.xs) . rw[ἐ hE] refine qF8Z (L:=C_keep _ g.k) ⟨ok,hC,d1,k1,k2,k3,λj p hj=>?_,by dsimp only;rw[ok.nf,d5],rfl⟩ (by dsimp only;(clear he hq hC hkn sW2 sN hP eB h2 h3 d1 d2 d3 hlen;exact omS415 hO E)) hq H have hjl:=(List.getElem?_eq_some_iff.mp hj).1 refine ⟨?_,(d4 j p hj).2⟩ dsimp only rw[(d4 j p hj).1] simpa only[Nat.toUInt32_eq,ὡ,Nat.reducePow,Nat.mod_succ_eq_iff_lt,Nat.succ_eq_add_one,Nat.reduceAdd] using Ἁ ((Nat.lt_of_add_left_lt (qCf ok hC (y:=0) (x:=0) (ok.ho▸Nat.succ_pos _) (ok.wo▸Nat.succ_pos _) (k2 _ (List.mem_of_getElem? hj))).1).trans ok.xs) lemma qHh (hs:g.xd.size<2^32): D_outsC g hs 0 0 (D_decAll g.tab g.W g.dw g.s g.wp g.k g.C) (ἇ (g.C*(g.ho*g.wo)) 0)=if g.dw then depthwiseSpecO g.s g.relu g.X g.W g.b else conv2dSpecO g.s g.relu g.X g.W g.b:=by refine (qCe (qEg ok hs g.C 0 0 _ (Ἇ _) ג ⟨by simp only[Array.size_replicate],λq _ h=>א⟩) λq h=>h).trans ?_ obtain ⟨dw,_,_,s,_,_,_,k,C,ho,wo⟩:=g obtain ⟨h1,h2,h3,h4⟩:=ok cases dw<;>simp only[false_eq_true, ↓reduceIte] at h1 h2 h3 h4<;>subst h1 h2 h3 h4<;>refine congrArg (Array.ofFn (n:=_)) (funext λq=>?_)<;>simp only[D_sp,D_out,D_xw,D_t0,false_eq_true, ↓reduceIte,zero_add] end def D_Zs (F:Ὣ->ὧ) (S m:Ὣ) (a:ὤ):Prop:= Ѩa=S/\S<2^32/\∀q,qa.data[q]! =if q< m then F q else dv 0 section variable {F:Ὣ->ὧ} {S m:Ὣ} {a:ὤ} include F S m a lemma qBq (d:Ὣ) (H:D_Zs F S m a) (hv:∀u,uF (m+u)=dv 0):D_Zs F S (m+d) a:=by refine ⟨H.1,H.2.1,λq hq=>?_⟩;rw[H.2.2 q hq];by_cases h1:q< m;. rw[ἱ h1,ἱ (Nat.lt_add_right d h1)] rw[ἐ h1];by_cases h2:q< m+d;. have e:=hv (q-m) (by clear hq;exact omS416 h1 h2);rw[Nat.add_sub_cancel' (Nat.not_lt.1 h1)] at e;rw[ἱ h2,e] rw[ἐ h2] lemma qGs (H:D_Zs F S m a) (i:ὦ) (hi:Ѥi=m) (hm:m?_⟩;rw[qCr _ _ _ _ hz (by rw[hi,H.1];exact hm),hi];by_cases e:q=m;. rw[ἱ e,ἱ (by clear hi hm hz hq;exact omS417 e),e] rw[ἐ e,H.2.2 q hq];by_cases h:q< m;. rw[ἱ h,ἱ (by clear hi hm hz hq e;exact omS418 h)] rw[ἐ h,ἐ (by clear hi hm hz hq;exact omS419 e h)] end lemma qE5 {F:Ὣ->ὧ} {S:Ὣ} {X:ѐ} {o n:ὦ} (hs:ѧX<2^32) (ho:Ѥo+Ѥn<=ѧX) (d:Ὣ): ∀(t q:ὦ) (m:Ὣ) (a:ὤ),Ѥt+d=Ѥn->Ѥq=m->m+d<=S->D_Zs F S m a->(∀j,jF (m+j)=dv X[Ѥo+Ѥt+j]!)->D_Zs F S (m+d) (D_cpz X o n t q hs ho a):=by induction' d with d ih<;>intro t q m a he hq hm H hv . rw[D_cpz,ἔ (qCk he.ge)];exact H obtain ⟨ht,hu⟩:=qBz he rw[D_cpz,Ἄ ht,qFp] have hS:=H.2.1 have e:∀h',dv (X.uget (o+t) h')=F m:=λh'=>by rw[qFx,qAv _ _ (by clear hq hm ht hS h';omega)];exact (hv 0 (by clear he hq hm ht hu hS h';exact omS9)).symm rw[e] refine ih (t+1) (q+1) (m+1) _ hu ?_ (by clear he hq ht hu hS;exact omS5 hm) (qGs H q hq (by clear he hq ht hu hS;exact omS4 hm)) λj hj=>?_ . exact (qAv q 1 (by rw[ὄ];(clear he ht hu;omega))).trans (by rw[ὄ,hq]) simpa only[usz t n ht,ὢ,Nat.add_comm 1] using hv (j+1) (by exact Nat.lt_succ_of_le ‹_›) lemma qE6 (s:OS) (X:ѐ) (hs:ѧX<2^32) (hX:ѧX=s.cin*s.h*s.w) (hh:s.h+2*s.pad<2^32) (hw:s.w+2*s.pad<2^32) {R S:Ὣ} (hR:R=s.cin*(s.h+2*s.pad)) (hS:R*(s.w+2*s.pad)<=S) (d:Ὣ): ∀(r:Ὣ) (a:ὤ),r+d=R->D_Zs (D_Fx s X) S (r*(s.w+2*s.pad)) a->D_Zs (D_Fx s X) S (R*(s.w+2*s.pad)) (D_imz s X hs (s.w+2*s.pad) R r a):=by induction' d with d ih<;>intro r a he H . rw[D_imz,ἔ (by clear hs hX hh hw hS;(exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›)))),<-he];exact H have hr:rqBv (qDf hc g) (Nat.le_refl s.w) have hT:=H.2.1 rw[D_imz,Ἄ hr] dsimp only split<;>rename_i g . obtain ⟨g1,g2,g3⟩:=g;have:=hO g2;have hl:(r+1)*(s.w+2*s.pad)<=R*(s.w+2*s.pad):=Ἒ _ hr;rw[ᾀ,qF5] at hl;apply ih (r+1) _ (by clear hX hh hw hS hr hc ep ew hT g1 g2 g3 this hl;exact omS137 he);rw[ᾀ,qF5];refine qBq s.pad (qE5 hs g3 s.w 0 _ _ _ (by rw[ew];exact Ἇ _) (qAa _ (by clear hX hR he hr hc g1 g2 g3 this;(clear hw;exact omS420 hS hT hl))) (by clear hX hw hR he hr hc hT g1 g2 g3 this;(clear ew;exact omS421 hS hl)) (qBq s.pad H λu hu=>?_) λj hj=>?_) λu hu=>?_;. rw[qAi _ _ _ (by clear hX hh hw hR hS he hr hc hT g1 g2 g3 this hl;(clear ep;exact omS381 hu)),D_px,ἱ (by clear hX hh hw hR hS he hr hc ew hT g1 g2 g3 this hl;(clear ep;exact omS382 hu))] . rw[ὢ,qAi _ _ _ (by clear hX hw hR hS he hr hc hT g1 g2 g3 this hl;(clear ew;exact omS383 hj)),D_px,ἐ (by clear hX hh hw hR hS he hr hc hT g3 this hl;(clear ep ew;exact omS384 g1 g2 hj)),Nat.add_sub_cancel_left,qAa _ (by clear hh hw hR hS he hr hc ep hT g1 g2 g3 hl;(clear hj;exact omS385 hs hX this))];rfl . rw[ὢ,ὢ,qAi _ _ _ (by clear hX hh hw hR hS he hr hc ew hT g1 g2 g3 this hl;(clear ep;exact omS386 hu)),D_px,ἱ (by clear hh hw hR hS he hr hc ep hT g1 g2 this hl hu;exact omS387)] apply ih (r+1) _ (by clear hX hh hw hS hr hc ep ew hT g;exact omS137 he) rw[ᾀ] exact qBq _ H λu hu=>by rw[qAi _ _ _ hu,D_px,ἱ] by_contra n have:=hO (by clear hX hh hw hR hS he hr hc ep ew hT g hu;exact omS388 n) exact g ⟨by (clear hX hh hw hR hS he hr hc ew hT g hu this;(clear ep;exact omS389 n)),by (clear hX hh hw hR hS he hr hc ep ew hT g hu this;exact omS388 n),by rw[qAa _ (by clear hh hw hR hS he hr hc ep hT g hu;(clear n;exact omS385 hs hX this)),ew,hX];exact this⟩ lemma qA1 (F:Ὣ->ὧ) {S:Ὣ} (N:ὦ) (c:Ὣ) (hN:ѤN=S) (hS:S<2^32):D_Zs F S 0 (D_fill (dv 0) N 0 (ἆ c)):=by have h:=qCc (F:=λ_=>dv 0) (v:=dv 0) (n:=N) S 0 0 (ἆ c) (by rw[C_z,hN,Ἇ]) ⟨rfl,λq hq=>absurd hq (Ἲ q)⟩ λ_ _ _=>rfl;rw[Ἇ] at h;exact ⟨h.1,hS,λq hq=>by rw[ἐ (Ἲ q)];exact h.2 q hq⟩ lemma qHd (F:Ὣ->ὧ) (n:Ὣ) (h:n<=16384):∃S,n<=S/\D_Zs F S 0 (D_zs n):=by unfold D_zs;split;. exact ⟨512,‹_›,qA1 F 512 512 (uk 512 (by norm_num1)) (by norm_num1)⟩ split;. exact ⟨1024,‹_›,qA1 F 1024 1024 (uk 1024 (by norm_num1)) (by norm_num1)⟩ split;. exact ⟨2048,‹_›,qA1 F 2048 2048 (uk 2048 (by norm_num1)) (by norm_num1)⟩ split;. exact ⟨4096,‹_›,qA1 F 4096 4096 (uk 4096 (by norm_num1)) (by norm_num1)⟩ split;. exact ⟨8192,‹_›,qA1 F 8192 8192 (uk 8192 (by norm_num1)) (by norm_num1)⟩ exact ⟨16384,h,qA1 F 16384 16384 (uk 16384 (by norm_num1)) (by norm_num1)⟩ lemma qG7 (s:OS) (X:ѐ) (a:ѧX<2^32) (e:ѧX=s.cin*s.h*s.w) (p:s.h+2*s.pad<2^32) (q:s.w+2*s.pad<2^32): D_Sp (D_Fx s X) (s.cin*(s.h+2*s.pad)*(s.w+2*s.pad)) (D_xs s X a (s.w+2*s.pad) (s.cin*(s.h+2*s.pad)))/\ ∀t,t< Ѩ(D_xs s X a (s.w+2*s.pad) (s.cin*(s.h+2*s.pad)))->∃u,(D_xs s X a (s.w+2*s.pad) (s.cin*(s.h+2*s.pad))).data[t]! =dv u:=by unfold D_xs split<;>rename_i hz . rw[ch2_eq s X a (s.w+2*s.pad) (s.cin*(s.h+2*s.pad)) rfl s.cin 0 _ (Ἇ _),ὒ] obtain ⟨S,h1,h2⟩:=qHd (D_Fx s X) _ hz;have P:=qE6 s X a e p q (S:=S) rfl (by clear a e p q hz;exact omS422 h1) _ 0 _ (Ἇ _) (by rw[ὒ];exact h2) refine ⟨⟨by rw[P.1];(clear e p q hz;exact omS422 h1),λt ht=>by rw[P.2.2 t (by clear e p q hz;exact omS423 h1 ht),ἱ ht]⟩,λt ht=>?_⟩ rw[P.2.2 t (P.1▸ht)];split;. exact ⟨_,rfl⟩ . exact ⟨0,rfl⟩ have Pz:=qE0 s X a e p q rfl _ 0 (ἆ (s.cin*(s.h+2*s.pad)*(s.w+2*s.pad)+7)) (Ἇ _) ⟨by rw[ὒ];rfl,λq hq=>א⟩ have Pf:D_Pre (λt=>if tby dsimp only;rw[Pz.2 t ht,ἱ ht]⟩ have P:=qCc (v:=dv 0) (n:=7) 7 0 _ _ (by rw[C_z,Ἇ];exact (uk 7 (by norm_num1)).symm) Pf λi h1 h2=>by rw[ἐ א] refine ⟨⟨by rw[P.1];omega,λt ht=>by rw[P.2 t א];dsimp only;rw[ἱ ht]⟩,λt ht=>?_⟩ rw[P.2 t (P.1▸ht)];dsimp only;split;. exact ⟨_,rfl⟩ . exact ⟨0,rfl⟩ lemma qFb (dw:Ὡ) (s:OS) (relu:Ὡ) (X W b:ѐ) {k C:Ὣ} (hk:k=if dw then s.kh*s.kw else s.cin*s.kh*s.kw) (hC:C=if dw then s.cin else s.cout): D_F dw s relu X W b k C=if dw then depthwiseSpecO s relu X W b else conv2dSpecO s relu X W b:=by unfold D_F rw[(cvGet W b s dw k C).2] unfold D_Fc dsimp only rw[qAg] split;swap;rfl split;swap;rfl rename_i hg hs obtain ⟨a,c,d,e,f,-,i,j,l,m,n,o,p,q,r,t,u,-,v,x⟩:=hg replace hs:=Nat.lt_of_le_of_lt hs (show 4294967295<2^32 by norm_num) replace a:=Nat.lt_of_le_of_lt a (show 4294967295<2^32 by norm_num) replace j:=Nat.lt_of_le_of_lt j (show 4294967295<2^32 by norm_num) replace p:=Nat.lt_of_le_of_lt p (show 4294967295<2^32 by norm_num) replace q:=Nat.lt_of_le_of_lt q (show 4294967295<2^32 by norm_num) replace r:=Nat.lt_of_le_of_lt r (show 4294967295<2^32 by norm_num) replace t:=Nat.lt_of_le_of_lt t (show 4294967295<2^32 by norm_num) replace u:=Nat.lt_of_le_of_lt u (show 4294967295<2^32 by norm_num) have y:=qFi X X.usize (qAd X) X.usize.toNat 0 Е 0 (Ἇ _) rw[ἱ ⟨c,d⟩] at y have Hx:=y▸qBh X a (by rw[y];intro h;rw[h] at d;exact absurd d ה) refine (qHh ?_ _).trans ?_ have hk0:k≠0:=(by clear hC hs y;exact omS424 l) rw[hk] at hk0 have k1:0hk0 (by rw[z];simp only[zero_mul,mul_zero,ite_self]) have k2:0hk0 (by rw[z];simp only[mul_zero,ite_self]) exact ⟨hk,hC,rfl,rfl,rfl,qAa _ j,rfl,λh=>beq_iff_eq.1 (ὕ.1 h).1,i,l,m,n,o,(qG7 s X a e p q).1,hs,Hx,qGp (qD0 W r v).2.2.1,qGp (qD0 b t x).2.2.1,f,r,t,u,q,qGz s k k 0 0 0 0 _ (Ἇ _) ג k1 k2 (by simp only[Array.emptyWithCapacity_eq,Nat.toUInt32_eq,Array.ofFn_zero]),(qG7 s X a e p q).2⟩ rfl lemma qC1x (d:DotFn) (s:OS) (r:Ὡ) (X W b:ё):conv2dWithO d (Cn1 s) r X W b=conv2dWithO d s r X W b:=by unfold Cn1 split · rename_i H obtain ⟨cin,h,w,co,kh,kw,st,pd⟩:=s obtain ⟨rfl,rfl,rfl,rfl,u,v⟩:=H simp only at u v have P:=Nat.mul_pos u v have e:∀n,0(n+2*0-1)/1+1=n:=λn h=>א simp only[conv2dWithO,OS.ho,OS.wo,e _ u,e _ v,e _ P,e 1 Nat.one_pos,Ὑ,Nat.mul_one] refine Մ (by simp only[Nat.mul_zero,Ἵ,Nat.add_one_sub_one,Nat.reduceDiv,Nat.reduceAdd,Array.size_ofFn,Nat.div_one,Nat.sub_add_cancel P,one_mul,Nat.sub_add_cancel u,Nat.sub_add_cancel v]) λq _ _=>?_ simp only[Array.getElem_ofFn,windowAtO,Nat.mul_one,Nat.div_one,Nat.mod_one,Ἵ,Nat.sub_zero,Ἲ,false_or] have:=ὀ q P have m:q%(h*w)=q%w+w*(q/w%h):=by rw[ἥ h w,Nat.mod_mul] have:=ὀ (q/w) u have:=ὀ q v congr 2 funext t split · rw[ἐ א,ἐ א,m] congr 1 ring · rfl · rfl lemma qB7:convF=conv2dSpecO:=by funext s r X W b;exact (qFb false (Cn1 s) r X W b (k:=s.cin*s.kh*s.kw) (C:=s.cout) (by unfold Cn1;split<;>split<;>simp_all only[false_eq_true,not_false_eq_true,mul_one,not_and,not_lt,nonpos_iff_eq_zero]) (by unfold Cn1;split<;>split<;>simp_all only[false_eq_true,not_false_eq_true,not_and,not_lt,nonpos_iff_eq_zero])).trans (qC1x _ s r X W b) lemma qDr:depthF=depthwiseSpecO:=by funext s r X W b;exact qFb true s r X W b rfl rfl end section open Float.Model Float.Model.UnpackedFloat @[noinline] def P39:Ὣ:=2^39 @[noinline] def P38:Ὣ:=2^38 def T_r (N:Ὣ):Ὣ:= N/P39+if P38omega set_option maxRecDepth 8192 in lemma qIc (neg:Ὡ) (N:Ὣ) (e':Int) (hN1:2^62<=N) (hN2:N<2^63) (h1:-148<=e'+39) (h2:e'+39+150<=253): toWord (Model.ofModel Fmt (UnpackedFloat.round Format.binary32 (ὶ neg) N e'))=ὺ ((if neg then 2^31 else 0)+(e'+39+149).toNat*2^23+T_r N):=by have hr1:2^23<=T_r N:=by unfold T_r P39 P38;split<;>omega have hr2:T_r N<=2^24:=by unfold T_r P39 P38;split<;>omega have hT:Format.binary32.targetExponent (totalExponent N e')=e'+39:=by simp only[totalExponent,qC8 N 62 hN1 hN2,qGo];(clear hN1 hN2 hr1 hr2;exact omS426 h1) have K:∀(P:Ὣ) (E:Int) (hp:0P<2^24->-149<=E->E<=104->(E+150).toNat*2^23+P%2^23=(e'+39+149).toNat*2^23+T_r N-> toWord (Model.ofModel Fmt (.finite (ὶ neg) P E hp))=ὺ ((if neg then 2^31 else 0)+(e'+39+149).toNat*2^23+T_r N):=by intro P E hp a b c d e simp only[toWord,Model.toNatBits,Model.ofModel,Model.ofModelBits] congr 1 show (UnpackedFloat.pack Format.binary32 _).toNat=_ rw[qBk _ _ _ _ a b (by clear hN1 hN2 h1 h2 hr1 hr2 hT hp a b e;exact omS92 c) (by clear hN1 hN2 h1 h2 hr1 hr2 hT hp a b e;exact omS427 d)] cases neg<;>simp only[Model.modelSign,false_eq_true, ↓reduceIte,reduceCtorEq,Nat.reducePow,zero_add]<;>(clear hN1 hN2 h1 h2 hr1 hr2 hT hp a b c d;omega) rw[Model.round_exact_eq_finishRoundedMantissa _ _ _ _,hT,Model.roundMantissaAtExponentEven,ἱ (by clear hN1 hN2 h1 h2 hr1 hr2 hT;exact omS429),show (e'+39-e').toNat=39 by (clear hN1 hN2 h1 h2 hr1 hr2 hT;exact omS430),qIv] by_cases hc:T_r N=2^24 . have h:=Model.finishRoundedMantissa_normalized_carry FloatFormat.binary32 (ὶ neg) (e'+39+23) (by show-126<=e'+39+23;(clear hN1 hN2 hr1 hr2 hc;exact omS431 h1));rw[show e'+39+23-(FloatFormat.binary32.fracWidth:ℤ)=e'+39 by show e'+39+23-23=_;(clear hN1 hN2 h1 h2 hr1 hr2 hT hc;exact omS432),show e'+39+23+1-(FloatFormat.binary32.fracWidth:ℤ)=e'+40 by show e'+39+23+1-23=_;(clear hN1 hN2 h1 h2 hr1 hr2 hT hc;exact omS433)] at h;rw[show Model.finishRoundedMantissa Format.binary32 (ὶ neg) (T_r N,e'+39)=.finite (ὶ neg) (2^23) (e'+40) ו by rw[hc];exact h] exact K (2^23) (e'+40) ו le_rfl (by norm_num1) (by clear hN1 hN2 hr1 hr2 hc;exact omS434 h1) (by clear hN1 hN2 hr1 hr2 hc;exact omS435 h2) (by rw[hc,show (e'+40+150).toNat=(e'+39+149).toNat+2 by (clear hN1 hN2 hr1 hr2 hc;exact omS436 h1)];(clear hN1 hN2 h1 h2 hr1 hr2 hT hc;exact omS437)) . rw[qEf _ _ _ hr1 (by clear hN1 hN2 h1 h2 hT;exact omS438 hr2 hc) (by clear hN1 hN2 hr1 hr2 hc;exact omS439 h1) (by clear hN1 hN2 h1 h2 hT hc;exact omS71 hr1)] exact K _ _ _ hr1 (by clear hN1 hN2 h1 h2 hT;exact omS438 hr2 hc) (by clear hN1 hN2 hr1 hr2 hc;exact omS439 h1) (by clear hN1 hN2 hr1 hr2 hc;exact omS440 h2) (by rw[show (e'+39+150).toNat=(e'+39+149).toNat+1 by (clear hN1 hN2 hr1 hr2 hc;exact omS441 h1)];(clear hN1 hN2;exact omS442 hr1 hr2 hc)) @[inline] def T_rd (neg:Ὡ) (mag e0 L:Ὠ):ὥ:= let n:=mag<<<(62-L) let q:=n>>>39 let rm:=n&&&0x7FFFFFFFFF let w:=((e0+L-24)<<<23)+q+ (if rm>0x4000000000 || (rm==0x4000000000&&q&&&1==1) then 1 else 0) (if neg then w ||| س else w).toUInt32 lemma qG4 (neg:Ὡ) (mag e0:Ὠ) (h0:Ѧmag≠0) (h1:Ѧmag<2^63) (h2:24< Ѧe0+mag.toNat.log2) (h3:Ѧe0+mag.toNat.log2<277):T_rd neg mag e0 mag.log2=toWord (ἕ Fmt ⟨neg,Ѧmag,(Ѧe0:Int)-150⟩):=by have l0:=Nat.log2_self_le h0;have l1:Ѧmag<2^(mag.toNat.log2+1):=Nat.lt_log2_self;have hL:mag.toNat.log2<=62:=Nat.lt_succ_iff.1 ((Nat.log2_lt h0).2 h1);obtain ⟨L,hLd⟩:∃L,L=mag.toNat.log2:=⟨_,rfl⟩;rw[<-hLd] at l0 l1 hL h2 h3;have eL:mag.log2.toNat=L:=hLd.symm;obtain ⟨N,hN⟩:∃N,N=Ѧmag*2^(62-L):=⟨_,rfl⟩;have p:2^L*2^(62-L)=2^62:=by rw[<-Nat.pow_add,Nat.add_sub_of_le hL] have hN1:2^62<=N:=by rw[hN,<-p];exact Ἒ _ l0 have hN2:N<2^63:=by have:=Nat.mul_lt_mul_of_pos_right l1 (Nat.two_pow_pos (62-L));rwa[<-hN,<-Nat.pow_add,show L+1+(62-L)=63 from (Nat.add_right_comm L 1 (62-L)).trans (congrArg (·+1) (Nat.add_sub_of_le hL))] at this have s4:Ѧe0+L-24<=252:=Nat.sub_le_iff_le_add.mpr (Nat.le_of_lt_succ h3) obtain ⟨i1,i2,i3⟩:(-148:Int)<=(Ѧe0:Int)-150-((62-L:Ὣ):Int)+39/\(Ѧe0:Int)-150-((62-L:Ὣ):Int)+39+150<=253/\((Ѧe0:Int)-150-((62-L:Ὣ):Int)+39+149).toNat=Ѧe0+L-24:=by (clear h0 h1 l1 l0 hN p hN1 hN2 hLd eL;omega) rw[qA5,<-ExactRuntime.round_scale _ _ _ _ (62-L) h0,<-hN,qIc neg N _ hN1 hN2 i1 i2];have eT:((Ѧe0:Int)-150-((62-L:Ὣ):Int)+39+149).toNat=Ѧe0+L-24:=i3 rw[eT];unfold T_rd;dsimp only;have e1:(62-mag.log2).toNat=62-L:=by rw[toNat_sub_of_le _ _ (Ὤ.2 (by rw[eL];exact hL)),eL];rfl have a1:(mag<<<(62-mag.log2)).toNat=N:=by rw[UInt64.toNat_shiftLeft,e1,Ἁ (Nat.lt_of_le_of_lt (Nat.sub_le 62 L) ה:62-L<64),ὁ,<-hN,Ἁ (by exact Nat.lt_of_lt_of_le ‹_› ה)] generalize mag<<<(62-mag.log2)=n at a1;have a2:(n>>>39).toNat=N/2^39:=by rw[ἰ,a1];simp only[UInt64.reduceToNat,Nat.reduceMod,Ἱ,Nat.reducePow] have a3:(n&&&0x7FFFFFFFFF).toNat=N%2^39:=by rw[Ὅ,a1];exact Ἂ N 39 generalize n>>>39=q at a2;generalize n&&&0x7FFFFFFFFF=rm at a3;have a4:(q&&&1).toNat=Ѧq%2:=by rw[Ὅ];exact Ἂ _ 1 have a5:(e0+mag.log2-24).toNat=Ѧe0+L-24:=by rw[toNat_sub_of_le _ _ (Ὤ.2 (by rw[ἤ,eL,Ἁ (by exact Nat.lt_of_lt_of_le ‹_› ה)];show 24<=_;(exact Nat.le_of_lt ‹_›))), ἤ,eL,Ἁ (by exact Nat.lt_of_lt_of_le ‹_› ה)] rfl have a6:((e0+mag.log2-24)<<<23).toNat=(Ѧe0+L-24)*2^23:=by rw[UInt64.toNat_shiftLeft,a5,ὁ];show _*2^23%_=_;rw[Ἁ (Nat.lt_of_le_of_lt (Ἒ (2^23) s4) ה)] generalize (e0+mag.log2-24)<<<23=hi at a6;have hup:(decide (rm>0x4000000000) || (rm==0x4000000000&&q&&&1==1))=decide (2^38simp only[false_eq_true,ite_false,ite_true]<;>(try rw[show (1:Ὠ).toNat=1 from rfl])<;>(try rw[show (0:Ὠ).toNat=0 from rfl]) . rw[Ἵ,Ἵ,Ἁ W0,Ἁ W0] . rw[Ἁ W0,Ἁ W1,ὢ] generalize hi+q+(if c=true then (1:Ὠ) else 0)=w at hw;have hw2:Ѧw<2^31:=by rw[hw,hr];split;exact U';exact Nat.lt_of_succ_lt U apply ἠ.mp;rw[ὡ];cases neg;. simp only[false_eq_true,ite_false,UInt64.toNat_toUInt32,Ἇ,hw] . simp only[ite_true,UInt64.toNat_toUInt32,UInt64.toNat_or];have h5:Ѧw ||| (2147483648:Ὠ).toNat=2^31+Ѧw:=by have:=Nat.two_pow_add_eq_or_of_lt hw2 1;simp only[Nat.mul_one] at this;rw[this,Nat.or_comm];rfl rw[h5];congr 1;rw[hw];exact (ὢ _ _ _).symm lemma qJf (w:ὥ) (h:(w&&&В)=0):ἂ w=0:=by have h1:=qA0 w;rw[h] at h1;have h2:=w.toNat_lt have h3:w=0\/w=س:=by have:ѥw=0\/ѥw=2147483648:=by simp only[UInt32.toNat_zero,Nat.reducePow] at h1;(clear h;exact omS452 h2 h1) rcases this with e | e;. exact Or.inl (ἠ.mp (by simpa only[UInt32.toNat_zero] using e)) . exact Or.inr (ἠ.mp (by simpa only[UInt32.reduceToNat] using e)) have h4:expOf w=0/\fracOf w=0:=by rcases h3 with rfl | rfl<;>decide simp only[rationalWord,decodeD,h4, ↓reduceIte,FloatLib.Numerics.Dyadic.toRat_mk_zero] @[inline] def T_e (w:ὥ):Ὠ:= if w&&&В==0 then 255 else (expOf w).toUInt64 @[inline] def T_m (w:ὥ):Ὠ:= if w&&&В==0 then 0 else (fracOf w+0x800000).toUInt64 @[inline] def T_s (e0:Ὠ) (w:ὥ):Ὠ:=T_m w<<<(T_e w-e0) @[inline] def T_ok (e0:Ὠ) (w:ὥ):Ὡ:= good w&&(w&&&В==0 || (e0<=T_e w&&T_e w-e0<=37)) @[inline] def T_p (e0:Ὠ) (w:ὥ) (p:Ὠ):Ὠ:= if signOf w then p else p+T_s e0 w @[inline] def T_n (e0:Ὠ) (w:ὥ) (n:Ὠ):Ὠ:= if signOf w then n+T_s e0 w else n lemma qJa (e0:Ὠ) (w:ὥ) (h:T_ok e0 w=true): (T_s e0 w).toNat<2^61/\ἂ w= (if signOf w then-((T_s e0 w).toNat:ℚ) else ((T_s e0 w).toNat:ℚ))*2^((Ѧe0:Int)-150):=by unfold T_ok at h simp only[and_eq_true,or_eq_true,beq_iff_eq,decide_eq_true_eq] at h obtain ⟨hg,hz⟩:=h by_cases h0:w&&&В=0 . have hs:T_s e0 w=0:=by unfold T_s T_m;simp only[h0,BEq.rfl, ↓reduceIte,UInt64.zero_shiftLeft] rw[hs,qJf w h0];simp only[UInt64.toNat_zero,Nat.reducePow,Nat.ofNat_pos,CharP.cast_eq_zero,neg_zero,ite_self,zero_mul,and_self] . obtain ⟨h1,h2⟩:=hz.resolve_left h0;have g:=qBd w hg;have a0:(w&&&В).toNat≠0:=λe=>h0 (ἠ.mp (by simpa only[Ἧ,UInt32.reduceToNat,UInt32.toNat_zero] using e));rw[qA0] at a0;have hx:=qAx w;have hf:(fracOf w).toNat=ѥw%2^23:=qBt w;have hl:=w.toNat_lt;have x1:1<=(expOf w).toNat:=(by clear hz h0 h1 h2 hl;exact omS453 g a0 hx);have x2:(expOf w).toNat<=254:=(by clear hz h0 h1 h2 hl;exact omS454 g hx);have f1:(fracOf w).toNat<2^23:=(by clear hz h0 h1 h2 g a0 hx hl x1 x2;exact omS455 hf);have ee:(T_e w).toNat=(expOf w).toNat:=by unfold T_e;simp only[beq_iff_eq,h0, ↓reduceIte,UInt32.toNat_toUInt64] have em:(T_m w).toNat=2^23+(fracOf w).toNat:=by unfold T_m;simp only[h0,beq_iff_eq,ite_false,UInt32.toNat_toUInt64];rw[UInt32.toNat_add,Ἁ (by show _+8388608<_;(clear hz h0 h1 h2 g a0 hx hl x1 x2 f1 ee;exact omS456 hf))];show _+8388608=_;(clear hz h0 h1 h2 g a0 hx hf hl x1 x2 f1 ee;exact omS457) have l1:=Ὤ.1 h1;have l2:=Ὤ.1 h2;rw[toNat_sub_of_le _ _ h1,ee] at l2;rw[ee] at l1;have l3:(expOf w).toNat-Ѧe0<=37:=l2 have es:(T_s e0 w).toNat=(2^23+(fracOf w).toNat)*2^((expOf w).toNat-Ѧe0):=by unfold T_s;have sh:(T_e w-e0).toNat%64=(expOf w).toNat-Ѧe0:=by rw[toNat_sub_of_le _ _ h1,ee];exact Ἁ (by exact Nat.lt_of_le_of_lt ‹_› ה) rw[UInt64.toNat_shiftLeft,em,sh,ὁ];apply Ἁ;have:2^((expOf w).toNat-Ѧe0)<=2^37:=Nat.pow_le_pow_right ו l3;have:(2^23+(fracOf w).toNat)*2^((expOf w).toNat-Ѧe0)<=2^24*2^37:=Nat.mul_le_mul (by clear hz h0 h1 h2 g a0 hx hl x1 x2 f1 ee l1 l2 l3 sh this;exact omS458 hf) this;(exact Nat.lt_of_le_of_lt ‹_› ה) refine ⟨?_,?_⟩;. have a:2^((expOf w).toNat-Ѧe0)<=2^37:=Nat.pow_le_pow_right ו l3;have b:(2^23+(fracOf w).toNat)*2^((expOf w).toNat-Ѧe0)<=(2^24-1)*2^37:=Nat.mul_le_mul (by clear hz h0 h1 h2 g a0 hx hl x1 x2 f1 ee l1 l2 l3 es a;exact omS459 hf) a;rw[es];(exact Nat.lt_of_le_of_lt ‹_› ה) . have nz:expOf w≠0:=λe=>by rw[e] at x1;simp only[UInt32.toNat_zero,nonpos_iff_eq_zero,one_ne_zero] at x1 have ew:(2:ℚ)^(((expOf w).toNat:Int)-150)=2^((expOf w).toNat-Ѧe0)*2^((Ѧe0:Int)-150):=by rw[<-Ἡ,<-Ἓ ἓ];congr 1;(clear hz h0 h1 h2 g a0 hf hl x1 x2 f1 em l2 l3 es nz;exact omS460 l1) rw[es];simp only[rationalWord,decodeD,nz,ite_false,FloatLib.Numerics.Dyadic.toRat,signedSignificand,ew];cases signOf w<;>simp only[false_eq_true, ↓reduceIte,Nat.reducePow,Int.ofNat_eq_natCast,Nat.cast_add,Nat.cast_ofNat,Rat.ofInt_eq_cast,Int.cast_add,Int.cast_ofNat,Int.cast_natCast,Nat.cast_mul,Nat.cast_pow,neg_add_rev,Int.reduceNeg,Int.cast_neg,neg_mul]<;>ring lemma qEn (e0:Ὠ) (w:ὥ) (p n:Ὠ) (V:ℚ) (B C:Ὣ) (hC:C=2^61-1) (hB:B+C<2^63) (hw:T_ok e0 w=true) (hp:Ѧp<=B) (hn:Ѧn<=B) (hV:V=((Ѧp:ℚ)-Ѧn)*2^((Ѧe0:Int)-150)): (T_p e0 w p).toNat<=B+C/\(T_n e0 w n).toNat<=B+C/\ V+ἂ w=(((T_p e0 w p).toNat:ℚ)-(T_n e0 w n).toNat)*2^((Ѧe0:Int)-150):=by obtain ⟨h1,h2⟩:=qJa e0 w hw have h3:(T_s e0 w).toNat<=C:=(by clear hB hp hn;exact omS461 hC h1) unfold T_p T_n rw[h2,hV] cases signOf w . simp only[false_eq_true,ite_false];have e:(p+T_s e0 w).toNat=Ѧp+(T_s e0 w).toNat:=by rw[ἤ];exact Ἁ (by clear hn h3;exact omS462 hB hp h1) rw[e];refine ⟨by (clear hB hn h3;exact omS463 hC hp h1),by (clear hB hp h1 h3 e;exact omS464 hn),?_⟩;push_cast;ring . simp only[ite_true];have e:(n+T_s e0 w).toNat=Ѧn+(T_s e0 w).toNat:=by rw[ἤ];exact Ἁ (by clear hp h3;exact omS462 hB hn h1) rw[e];refine ⟨by (clear hB hn h1 h3 e;exact omS464 hp),by (clear hB hp h3;exact omS463 hC hn h1),?_⟩;push_cast;ring @[inline] def T_lg (x:Ὠ):Ὠ:= let a:Ὠ:=if 0x100000000<=x then 32 else 0 let y:=x>>>a let b:Ὠ:=if 0x10000<=y then 16 else 0 let y:=y>>>b let c:Ὠ:=if 0x100<=y then 8 else 0 let y:=y>>>c let d:Ὠ:=if 0x10<=y then 4 else 0 let y:=y>>>d let e:Ὠ:=if 4<=y then 2 else 0 let y:=y>>>e a+b+c+d+e+(if 2<=y then 1 else 0) lemma lgS (n s:Nat) (h:2^s<=n):n.log2=(n/2^s).log2+s:=by have hn:n≠0:=by have:=Nat.one_le_two_pow (n:=s);omega have h1:=Nat.log2_self_le hn have h2:n<2^(n.log2+1):=Nat.lt_log2_self have hsL:s<=n.log2:=(Nat.le_log2 hn).2 h have q1:2^(n.log2-s)<=n/2^s:=by rw[Nat.le_div_iff_mul_le (Nat.two_pow_pos s),<-Nat.pow_add,Nat.sub_add_cancel hsL];exact h1 have q2:n/2^s<2^(n.log2-s+1):=by rw[Nat.div_lt_iff_lt_mul (Nat.two_pow_pos s),<-Nat.pow_add,show n.log2-s+1+s=n.log2+1 by omega];exact h2 have q0:n/2^s≠0:=by have:=Nat.one_le_two_pow (n:=n.log2-s);omega have:=(Nat.log2_eq_iff q0).2 ⟨q1,q2⟩ omega lemma lgU (y T c:Ὠ) (hT:T.toNat=2^c.toNat) (hc:c.toNat<64) (hy:y.toNat<2^(2*c.toNat)): (y>>>(if T<=y then c else 0)).toNat<2^c.toNat/\ y.toNat.log2=(y>>>(if T<=y then c else 0)).toNat.log2+(if T<=y then c else 0).toNat:=by by_cases hTy:T<=y . rw[ἱ hTy] have e:(y>>>c).toNat=y.toNat/2^c.toNat:=by rw[ἰ,Ἁ hc];exact Ἱ _ _ rw[e];constructor . rw[Nat.div_lt_iff_lt_mul (Nat.two_pow_pos _),<-Nat.pow_add];rw[show c.toNat+c.toNat=2*c.toNat by omega];exact hy . exact lgS _ _ (by rw[<-hT];exact UInt64.le_iff_toNat_le.mp hTy) . rw[ἐ hTy] have e:(y>>>(0:Ὠ)).toNat=y.toNat:=by simp only[UInt64.shiftRight_zero] rw[e];refine ⟨?_,by simp only[UInt64.toNat_zero,add_zero]⟩ have:=UInt64.lt_iff_toNat_lt.mp (UInt64.not_le.mp hTy);omega lemma lgF (y:Ὠ) (h:y.toNat<2^2):y.toNat.log2=(if 2<=y then (1:Ὠ) else 0).toNat:=by have h4:y.toNat<4:=by simpa only[Nat.reducePow] using h by_cases h2:(2:Ὠ)<=y . rw[ἱ h2];have:=UInt64.le_iff_toNat_le.mp h2 have e:(2:Ὠ).toNat=2:=rfl;rw[e] at this exact (Nat.log2_eq_iff א).2 ⟨by simpa only[UInt64.reduceToNat,pow_one] using this,by simpa only[UInt64.reduceToNat,Nat.reduceAdd,Nat.reducePow] using h4⟩ . rw[ἐ h2];have:=UInt64.lt_iff_toNat_lt.mp (UInt64.not_le.mp h2) have e:(2:Ὠ).toNat=2:=rfl;rw[e] at this have:y.toNat=0\/y.toNat=1:=א rcases this with e|e<;>rw[e]<;>decide lemma qLg (x:Ὠ):T_lg x=x.log2:=by apply UInt64.toNat_inj.mp have eL:x.log2.toNat=x.toNat.log2:=rfl rw[eL];unfold T_lg;dsimp only obtain ⟨y1,e1⟩:=lgU x 0x100000000 32 ה ה (by have:=x.toNat_lt;simpa only[UInt64.reduceToNat,Nat.reduceMul,Nat.reducePow,gt_iff_lt] using this) generalize (if (0x100000000:Ὠ)<=x then (32:Ὠ) else 0)=a at y1 e1⊢ generalize x>>>a=x1 at y1 e1⊢ obtain ⟨y2,e2⟩:=lgU x1 0x10000 16 ה ה (by simpa only[UInt64.reduceToNat,Nat.reduceMul,Nat.reducePow] using y1) generalize (if (0x10000:Ὠ)<=x1 then (16:Ὠ) else 0)=b at y2 e2⊢ generalize x1>>>b=x2 at y2 e2⊢ obtain ⟨y3,e3⟩:=lgU x2 0x100 8 ה ה (by simpa only[UInt64.reduceToNat,Nat.reduceMul,Nat.reducePow] using y2) generalize (if (0x100:Ὠ)<=x2 then (8:Ὠ) else 0)=c at y3 e3⊢ generalize x2>>>c=x3 at y3 e3⊢ obtain ⟨y4,e4⟩:=lgU x3 0x10 4 ה ה (by simpa only[UInt64.reduceToNat,Nat.reduceMul,Nat.reducePow] using y3) generalize (if (0x10:Ὠ)<=x3 then (4:Ὠ) else 0)=d at y4 e4⊢ generalize x3>>>d=x4 at y4 e4⊢ obtain ⟨y5,e5⟩:=lgU x4 4 2 ה ה (by simpa only[UInt64.reduceToNat,Nat.reduceMul,Nat.reducePow] using y4) generalize (if (4:Ὠ)<=x4 then (2:Ὠ) else 0)=e at y5 e5⊢ generalize x4>>>e=x5 at y5 e5⊢ have e6:=lgF x5 (by simpa only[Nat.reducePow,UInt64.reduceToNat] using y5) generalize (if (2:Ὠ)<=x5 then (1:Ὠ) else 0)=f at e6⊢ have hb:x.toNat.log2<2^64:=Nat.lt_of_le_of_lt (Nat.log2_le_self _) x.toNat_lt simp only[ἤ] omega @[inline] def T_fin (p n e0:Ὠ) (f:Unit->ὥ):ὥ:= if p==n then f () else let mag:=if p=277 then f () else T_rd (decide (pὥ) (hp:Ѧp<2^63) (hn:Ѧn<2^63) (he:Ѧe0<=255) (R:ὥ) (hf:f ()=R) (hR:p≠n->∃d:FloatLib.Numerics.Dyadic, d.toRat=((Ѧp:ℚ)-Ѧn)*2^((Ѧe0:Int)-150)/\R=toWord (ἕ Fmt d)):T_fin p n e0 f=R:=by unfold T_fin simp only[qLg] split . exact hf . rename_i hne;have hne':p≠n:=λe=>hne (by simp only[e,BEq.rfl]);have hnn:Ѧp≠Ѧn:=λe=>hne' (UInt64.toNat_inj.mp e);obtain ⟨d,hd,hR⟩:=hR hne';(try dsimp only);obtain ⟨mag,hm⟩:∃m,m=if pb1 (Ὤ.2 h);have b4:¬(277:Ὠ).toNat<=(e0+mag.log2).toNat:=λh=>b2 (Ὤ.2 h);rw[eA] at b3 b4;have t1:(24:Ὠ).toNat=24:=rfl;have t2:(277:Ὠ).toNat=277:=rfl;rw[qG4 _ _ _ m0 m1 (by clear hp hn he hf hne' hnn hR hm m0 m1 b1 b2 eL hL b4 t2;exact omS469 b3 t1) (by clear hp hn hf hne' hnn hR hm m0 m1 b1 b2 b3 t1;exact omS470 b4 t2),hR];refine congrArg toWord ?_ have s0:d.significand≠0:=by intro h0;have:d.toRat=0:=(ὐ d).2 h0;rw[hd] at this;have q:(Ѧp:ℚ)-Ѧn≠0:=by rw[sub_ne_zero];exact_mod_cast hnn exact (mul_ne_zero q (zpow_ne_zero _ ἓ)) this refine roundDyadic_congr Fmt ה _ _ m0 s0 ?_;rw[hd,<-m2];simp only[FloatLib.Numerics.Dyadic.toRat,signedSignificand];cases decide (psimp only[false_eq_true, ↓reduceIte,Int.ofNat_eq_natCast,Rat.ofInt_eq_cast,Int.cast_natCast,Int.cast_neg,neg_mul] lemma qHq (w:ὥ):(T_e w).toNat<=255:=by unfold T_e;split;. decide . have:=qAx w;simp only[UInt32.toNat_toUInt64];omega @[inline] def T_min (x y:Ὠ):Ὠ:=if xsimp only[false_eq_true, ↓reduceIte,Nat.reducePow,OfNat.zero_ne_ofNat,or_false,OfNat.ofNat_ne_zero,or_true]) s.toBits.toNat_lt e1 e2 (by clear h hz e1 l1 u1 e2 l2 u2;exact omS232 h1) (by clear h hz e1 l1 u1 e2 l2 u2;exact omS233 h2 h3) l1 u1 l2 u2 exact ⟨S,ex,fr,Q+2,h1,h2,h3,hz,a,b,c⟩ lemma qJd (v W z u:ℝ) (hu:0linarith only[h2.1,h2.2,h2] set_option maxRecDepth 8192 in lemma qJq (ex fr E F:Ὣ) (h1:897<=ex) (h2:ex<1151) (hfr:fr<2^23) (hF:F<2^52) (hl:(ex*2^23+fr)*2^29+2(2^53+fr*2^30-2^29)*2^((ex:Int)-1076)simp only[E_act,signOf,Bool.false_and,false_eq_true, ↓reduceIte,act,Bool.true_and,bne_iff_ne,ne_eq,ite_not,reluW,hf,decide_false,Bool.not_false,Bool.and_true] lemma qGg (relu:Ὡ) (s:ὧ) (h:zivS s≠Е):E_act relu (zivS s)=act relu (zivS s):=by apply qDx;obtain ⟨S,ex,fr,h1,h2,h3,hz,-,-⟩:=qCg _ _ h;have hz':zivS s=_:=hz;intro h0;have h4:(expOf (zivS s)).toNat=255:=by rw[h0];rfl rw[qAx,hz',ὡ] at h4;split at h4<;>(clear h hz hz' h0;omega) lemma qAr (z:Model FloatFormat.binary32):Ἑ z=(Model.toModel z).isFinite:=by have he:=Model.unpackExponent_toNat z;have ha:=Model.toNat_neg_one_exponentBits FloatFormat.binary32;have hm:Ἑ z=(Model.expField z != FloatFormat.expAllOnesNat FloatFormat.binary32):=rfl;rw[hm];unfold Model.toModel Ἶ;simp only[];by_cases h:Float.Model.UnpackedFloat.unpackExponent (spec:=FloatFormat.toModel FloatFormat.binary32) (Model.toModelBits z)=-BitVec.ofNat _ 1 . rw[ἱ h];have h2:Model.expField z=FloatFormat.expAllOnesNat FloatFormat.binary32:=by rw[<-he,h,ha] rw[h2];split<;>rfl . rw[ἐ h];have h2:Model.expField z≠FloatFormat.expAllOnesNat FloatFormat.binary32:=by intro h3;apply h;apply BitVec.eq_of_toNat_eq;rw[he,h3,<-ha] have h4:(Model.expField z != FloatFormat.expAllOnesNat FloatFormat.binary32)=true:=by simpa only[bne_iff_ne,ne_eq] using h2 rw[h4];split;. split<;>rfl . rfl def m32 (f:Float32):Model FloatFormat.binary32:=Model.ofFloat32Model f.toModel lemma qDu (f:Float32):Ἑ (m32 f)=f.isFinite:=by rw[qAr];rfl lemma qG3 (y:Model FloatFormat.binary32) (h:Ἑ y=true):Model.IsModelCanonical y:=by refine ⟨λhe _=>?_⟩;have hf:=qAr y;rw[h] at hf;unfold Model.toModel Ἶ at hf;simp only[] at hf;rw[ἱ he] at hf;split at hf<;>simp only[Float.Model.UnpackedFloat.isFinite,Bool.true_eq_false] at hf lemma qAz (w:Ὢ) (h:expOf w≠255):m32 (Float32.ofBits w)=ofW w:=by have hf:Ἑ (ofW w)=true:=by simp only[ofW,isFinite_ofUInt32,bne_iff_ne,ne_eq,h,not_false_eq_true] rw[<-Model.canonicalizeModel_eq_self _ (qG3 _ hf)];unfold m32 Model.canonicalizeModel;change Model.ofFloat32Model (Float32.Model.pack _)=_;rw[Model.ofFloat32Model_pack];congr 1;unfold Model.toModel;congr 1;apply BitVec.eq_of_toNat_eq;simp only[UInt32.toNat_toBitVec,Model.toModelBits,ofW,Model.ofUInt32,Model.ofNatBits,Model.ofBits,FloatFormat.ofWordNat];show ѥw=ѥw%2^32;have:=w.toNat_lt;(clear h;omega) lemma qEi (f:Float32):f.toBits=toWord (m32 f):=by unfold toWord m32 Model.ofFloat32Model Model.ofModelBits Model.toNatBits;simp only[Float32.toBits];exact UInt32.ofNat_toNat.symm lemma qD2 (x y:Ὢ) (hx:expOf x≠255) (hy:expOf y≠255):(Float32.ofBits x+Float32.ofBits y).toBits=toWord (Model.add (ofW x) (ofW y)):=by have hfx:Ἑ (ofW x)=true:=by simp only[ofW,isFinite_ofUInt32,bne_iff_ne,ne_eq,hx,not_false_eq_true] have hfy:Ἑ (ofW y)=true:=by simp only[ofW,isFinite_ofUInt32,bne_iff_ne,ne_eq,hy,not_false_eq_true] have fx:(Float32.ofBits x).isFinite=true:=by rw[<-qDu,qAz x hx];exact hfx have fy:(Float32.ofBits y).isFinite=true:=by rw[<-qDu,qAz y hy];exact hfy rw[qEi,show m32 (Float32.ofBits x+Float32.ofBits y)= Model.add (m32 (Float32.ofBits x)) (m32 (Float32.ofBits y)) from toModel_ofFloat32_add_of_isFinite _ _ fx fy,qAz x hx,qAz y hy] lemma qCs (relu:Ὡ) (x y:Ὢ):addOne relu x y=act relu (toWord (Model.add (ofW x) (ofW y))):=by unfold addOne;split . rename_i hc;simp only[and_eq_true,bne_iff_ne,ne_eq] at hc;dsimp only;split;. rename_i h2;rw[qDx _ _ (by simpa only[ne_eq,bne_iff_ne] using h2),qD2 x y hc.1 hc.2] . rw[qD2 x y hc.1 hc.2] . rfl lemma qE4 {L:ὦ->ѐ->ѐ} (f:ὦ->ὥ->ὥ) {e:ὦ} (hL:∀i x,L i x=if iѤe<=ѧx->ѧx<2^32-> (L i x).size=ѧx/\∀q,(L i x)[q]! =if Ѥi<=q/\q< Ѥe then f (ὴ q) x[q]! else x[q]!:=by induction d with | zero=> intro i x h1 _ _ rw[hL,ἐ (by rw[А];exact omS404 h1)] exact ⟨rfl,λq=>(ἐ (by exact omS483 h1)).symm⟩ | succ d ih=> intro i x h1 h2 h3 have hi:i?_⟩ rw[h5,qAq _ _ _ _ h3 (by exact Nat.lt_of_lt_of_le ‹_› ‹_›),usz i e hi,qAo _ _ h3] by_cases h6:q=Ѥi . subst h6;rw[ἐ (by clear h1 h2 h3 hi hs h4;exact omS485),ἱ rfl,ἱ (by clear h2 h3 hi hs h4;exact omS486 h1),USize.ofNat_toNat] . rw[ἐ h6];exact if_congr (by clear h2 h3 hi hs h4;exact omS487 h6) rfl rfl def addGo (relu:Ὡ) (y:ё) (e i:ὦ) (x:ё): ё:= if h:iaddGu relu y e i x hx hy=addGo relu y e i x:=by induction k with | zero=> intro i x hx hy h0 rw[addGu,addGo,ἔ ט,ἔ ט] | succ k ih=> intro i x hx hy h0 have hi:iaddOne relu a[i] b[i.val]! def addF (relu:Ὡ) (a b:ё):ё:= if h:ѧa=ѧb/\ѧa<=4294967295 then addGu relu b a.usize 0 a (by have:=h.2;simp only[Array.usize,Nat.toUSize_eq];exact (uk _ (by omega)).symm) (by have:=h.2;rw[<-h.1];simp only[Array.usize,Nat.toUSize_eq];exact (uk _ (by omega)).symm) else addFb relu a b lemma qFu:addF=addReluSpec:=by funext relu a b;unfold addF;split . rename_i h;obtain ⟨h1,h2'⟩:=h;have h2:ѧa<2^32:=א;have hu:a.usize.toNat=ѧa:=qAa _ h2;rw[addGu_eq relu b a.usize ѧa 0 a _ _ (by rw[hu];simp only[USize.toNat_zero,zero_add])];have hg:=qE4 (L:=addGo relu b a.usize) (λi w=>addOne relu w (rdW b i)) (λ_ _=>by rw[addGo];rfl) ѧa 0 a (by rw[hu,show (0:ὦ).toNat=0 from rfl,Ἇ]) (by clear h2;(exact Nat.le_of_eq ‹_›)) h2;apply Մ (by rw[hg.1];simp only[addReluSpec,Fin.getElem_fin,Array.size_ofFn]);intro i h3 h4;have hi:i< ѧa:=by rwa[hg.1] at h3 rw[<-Ἕ _ i h3,hg.2 i,ἱ ⟨Nat.zero_le _,by (clear h2 h4 hi;omega)⟩,qCs,Ἕ a i hi,qAo _ _ (by clear h3 h4 hi;omega),uk i (by clear h4 hi;omega)];simp only[addReluSpec,Fin.getElem_fin,Array.getElem_ofFn] . simp only[addFb,addReluSpec,qCs] end section @[noinline] def E_fma (relu:Ὡ) (w sw tw:ὥ):ὥ:= act relu (toWord (Model.fma (ofW w) (ofW sw) (ofW tw))) @[noinline] def E_fz (relu g:Ὡ) (sw tw:ὥ) (y z:ὧ) (w:ὥ):ὥ:= if g&&good w then let r:=zivS (dv w*y+z) if r==Е then E_fma relu w sw tw else E_act relu r else E_fma relu w sw tw @[inline] def E_el (relu g:Ὡ) (sw tw:ὥ) (y z:ὧ) (w:ὥ):ὥ:= let a:=((if w==0 then dv 0 else dvN w)*y+z).toBits let u:=a+0x0FFFFFFD if g&&(a<<<(1:Ὠ))-0x7040000000000000<0x1F60000000000000&&u&&&0x1FFFFFFF<0x1FFFFFFC then E_act relu (zivC (u>>>(29:Ὠ))) else E_fz relu g sw tw y z w @[specialize] def E_map (f:ὥ->ὥ) (e i:ὦ) (x:ѐ):ѐ:= if h:iὥ) (e i:ὦ) (x:ѐ) (he:Ѥe<=ѧx):ѐ:= if h:iὥ) (e:ὦ) (d:Ὣ): ∀(i:ὦ) (x:ѐ) (he:Ѥe<=ѧx),Ѥe-Ѥi=d->ѧx<2^32->E_mU f e i x he=E_map f e i x:=by induction d using Nat.strong_induction_on with | _ d ih=> intro i x he hd hs rw[E_mU,E_map] by_cases h:icases g<;>rfl def E_chs (relu:Ὡ) (c hw:Ὣ) (s t:ѐ) (ch:Ὣ) (x:ѐ):ѐ:= if chX[Ѥb+(t/k*w+t%k)]!) (λ_=>oneW) section open Float.Model Float.Model.UnpackedFloat def E_dotT (X:ѐ) (b:ὦ) (k w:Ὣ):ὥ:= if k=2 then let i:=Ѥb let a0:=X[i]! let a1:=X[i+1]! let a2:=X[i+w]! let a3:=X[i+(w+1)]! let e0:=T_min (T_min (T_e a0) (T_e a1)) (T_min (T_e a2) (T_e a3)) if T_ok e0 a0&&T_ok e0 a1&&T_ok e0 a2&&T_ok e0 a3 then T_fin (T_p e0 a3 (T_p e0 a2 (T_p e0 a1 (T_p e0 a0 0)))) (T_n e0 a3 (T_n e0 a2 (T_n e0 a1 (T_n e0 a0 0)))) e0 λ_=>E_dot X b k w else E_dot X b k w else E_dot X b k w lemma qE9 (X:ѐ) (b:ὦ) (k w:Ὣ):E_dotT X b k w=E_dot X b k w:=by unfold E_dotT;split;swap;rfl;subst_vars;dsimp only;split;swap;rfl;rename_i hc;simp only[and_eq_true] at hc;obtain ⟨⟨⟨h0,h1⟩,h2⟩,h3⟩:=hc;obtain ⟨p1,n1,v⟩:=qGv _ _ _ h0 h1;obtain ⟨p2,n2,v⟩:=qF4 _ _ _ _ _ _ p1 n1 v h2 h3;refine qFy _ _ _ _ p2 n2 ((qC5 _ _).trans ((qC5 _ _).trans (qHq _))) _ rfl λe=>?_;have B:=qBa (2*2) (λj=>X[Ѥb+(j/2*w+j%2)]!) (λ_=>oneW) λj g=>⟨by interval_cases j<;>simp only[Nat.zero_div,zero_mul,Nat.zero_mod,add_zero,ne_eq,qCi _ _ h0,not_false_eq_true,Nat.reduceDiv,Nat.mod_succ,zero_add,qCi _ _ h1,Order.lt_two_iff,zero_le,Nat.div_self,one_mul,Nat.mod_self,qCi _ _ h2,Nat.reduceMod,qCi _ _ h3],ה⟩;simp only[Nat.reduceMul,D.qIg,mul_one,Finset.sum_range_succ,Finset.range_one,Finset.sum_singleton,Nat.zero_div,zero_mul,Nat.zero_mod,add_zero,Nat.reduceDiv,Nat.mod_succ,zero_add,Order.lt_two_iff,zero_le,Nat.div_self,one_mul,Nat.mod_self,Nat.reduceMod,ne_eq] at B;rw[v] at B;rw[E_dot,qAg];exact B (mul_ne_zero (sub_ne_zero.2 λh=>e (UInt64.toNat_inj.1 (Nat.cast_injective h))) (zpow_ne_zero _ ἓ)) end def E_dq (n:Ὣ) (s:ὥ):ὥ:= if 1ὥ) (sx:ὦ) (W x:Ὣ) (b q:ὦ) (out:ѐ):ѐ:= if xὥ) (sy sx:ὦ) (W H y:Ὣ) (b q:ὦ) (out:ѐ):ѐ:= if yὥ) (sc sy sx:ὦ) (W H c ch:Ὣ) (b q:ὦ) (out:ѐ):ѐ:= if ch(t.val/k*w+t.val%k).toUInt32 @[noinline] def E_grid (c h w k n:Ὣ) (X off:ѐ) (j z:ὥ) (u nf zb zr:ὧ): ѐ:= G_c (λb=>E_win X off k w n j z u nf zb b ѩn 0 zr zr 0) (h*w).toUSize (k*w).toUSize ѩk (w/k) (h/k) c 0 0 0 (ἇ (c*(h/k*(w/k))) 0) @[inline] def E_w4 (X:ѐ) (k w n:Ὣ) (j z:ὥ) (u nf zb zr:ὧ) (a0 a1 a2 a3 b:ὦ):ὥ:= let v0:=rdW X (b+a0) let d0:=dv v0*u let v1:=rdW X (b+a1) let d1:=dv v1*u let v2:=rdW X (b+a2) let d2:=dv v2*u let v3:=rdW X (b+a3) let d3:=dv v3*u E_tl X b k w n j z nf zb (zr+d0+d1+d2+d3) (zr+d0.abs+d1.abs+d2.abs+d3.abs) (0 ||| v0 ||| v1 ||| v2 ||| v3) @[inline] def E_w4u (X:ѐ) (k w n:Ὣ) (j z:ὥ) (nf zb zr:ὧ) (a0 a1 a2 a3 b:ὦ):ὥ:= let v0:=rdW X (b+a0) let d0:=dv v0 let v1:=rdW X (b+a1) let d1:=dv v1 let v2:=rdW X (b+a2) let d2:=dv v2 let v3:=rdW X (b+a3) let d3:=dv v3 E_tl X b k w n j z nf zb (zr+d0+d1+d2+d3) (zr+d0.abs+d1.abs+d2.abs+d3.abs) (0 ||| v0 ||| v1 ||| v2 ||| v3) lemma qW4u (X:ѐ) (k w n:Ὣ) (j z:ὥ) (nf zb zr:ὧ) (a0 a1 a2 a3 b:ὦ): E_w4u X k w n j z nf zb zr a0 a1 a2 a3 b=E_w4 X k w n j z (dv oneW) nf zb zr a0 a1 a2 a3 b:=by unfold E_w4u E_w4;simp only[D.qM1 _ (D.qDvF _)] @[noinline] def E_gridK (c h w k n:Ὣ) (X off:ѐ) (j z:ὥ) (u nf zb zr:ὧ): ѐ:= if k==2 then let a0:=(rdW off 0).toUSize let a1:=(rdW off (0+1)).toUSize let a2:=(rdW off (0+1+1)).toUSize let a3:=(rdW off (0+1+1+1)).toUSize G_c (λb=>E_w4 X k w n j z u nf zb zr a0 a1 a2 a3 b) (h*w).toUSize (k*w).toUSize ѩk (w/k) (h/k) c 0 0 0 (ἇ (c*(h/k*(w/k))) 0) else E_grid c h w k n X off j z u nf zb zr def E_winC (X:ѐ) (k w n:Ὣ) (j z:ὥ) (u nf zb:ὧ) (b m t:ὦ) (s a:ὧ) (o:ὥ):ὥ:= if h:t< m then let v:=rdW X (b+t) let d:=dv v E_winC X k w n j z u nf zb b m (t+1) (s+d) (a+d.abs) (o ||| v) else E_tl X b k w n j z nf zb s a o partial_fixpoint @[noinline] def E_gridC (c h w k n:Ὣ) (X:ѐ) (j z:ὥ) (u nf zb zr:ὧ): ѐ:= G_c (λb=>E_winC X k w n j z u nf zb b ѩn 0 zr zr 0) (h*w).toUSize (k*w).toUSize ѩk (w/k) (h/k) c 0 0 0 (ἇ (c*(h/k*(w/k))) 0) def A_x (X:ѐ) (w:Ὣ) (wu:ὦ) (u nf zb zr:ὧ) (b q e:ὦ) (out:ѐ):ѐ:= if h:q0) (λ_=>oneW)) E_gridX c h w k n X j z (dv oneW) (nfOf n) (dv 0) D.fz0 else avgpoolSpecO c h w k X def E_d (x y z:ὥ):FloatLib.Numerics.Dyadic:= Model.addDyadic ⟨Bool.xor (decodeD x).negative (decodeD y).negative, (decodeD x).significand*(decodeD y).significand, (decodeD x).exponent+(decodeD y).exponent⟩ (decodeD z) section variable (x y z:ὥ) (hx:expOf x≠255) (hy:expOf y≠255) (hz:expOf z≠255) include x y z hx hy hz lemma qC7:Model.fma (ofW x) (ofW y) (ofW z)=ἕ Fmt (E_d x y z):=by rw[Model.Proof.fma_eq_spec];have e:=ἶ x hx;have f:=ἶ y hy;have g:=ἶ z hz;simp only[Model.Spec.fma,ofW,(Model.chooseNaN3_eq_none_iff _ _ _).2 ⟨Model.isNaN_eq_false_of_toDyadic?_some e,Model.isNaN_eq_false_of_toDyadic?_some f,Model.isNaN_eq_false_of_toDyadic?_some g⟩,Model.isInf_eq_false_of_toDyadic?_some e,Model.isInf_eq_false_of_toDyadic?_some f,Bool.or_self,false_eq_true, ↓reduceIte,Model.isInf_eq_false_of_toDyadic?_some g,e,f,g];rfl lemma qDv:((E_d x y z).toRat:ℝ)=wv x*wv y+wv z:=by have j:=mul_toRat (decodeD x) (decodeD y);simp only[FloatLib.Numerics.Dyadic.mul,mulFields] at j;rw[E_d,Model.addDyadic,add_toRat,j,qA6 x hx,qA6 y hy,qA6 z hz];simp only[Rat.cast_add,Rat.cast_mul,Ἠ,rationalWord] end section open Float.Model Float.Model.UnpackedFloat lemma qGe (i:ὦ) (h:Ѥi< ѨpwN):pwN.uget i h=pwEntryN Ѥi:=by simp only[FloatArray.uget,qDg,List.toArray_range,Array.ugetElem_eq_getElem,Array.getElem_map,Array.getElem_range] def N_ok (w:ὥ):Prop:=0x800000<=w&&&В/\w&&&В<У lemma qHr {w:ὥ} (h:N_ok w):good w=true:=qBo _ (Or.inr h.1) h.2 lemma N_w (w:ὥ) (h:(pwN.uget (w>>>(23:ὥ)).toUSize (qCl w))ᶠ): pwN.uget (w>>>(23:ὥ)).toUSize (qCl w)=pw.uget (w>>>(23:ὥ)).toUSize (qB4 w)/\N_ok w:=by have s:=qEc w rw[qGe,ὃ,s] at h rw[qGe,qC2,ὃ,s] unfold pwEntryN at h⊢ have e:=qA0 w have g:=w.toNat_lt by_cases c:(ѥw/2^23%256==0 || ѥw/2^23%256==255)=true . rw[ἱ c,qI6] at h;exact absurd h ה . rw[ἐ c];simp only[or_eq_true,beq_iff_eq,not_or] at c;refine ⟨rfl,?_,?_⟩;. rw[ἃ,e,show (0x800000:ὥ).toNat=0x800000 from rfl];(clear s g;exact omS488 c) . rw[ἳ,e,show (У:ὥ).toNat=У from rfl];(clear s g;exact omS489 c) lemma qJy {w:ὥ} (h:(dvN w)ᶠ):dvN w=dv w/\N_ok w:=by obtain ⟨e,o⟩:=N_w w (qGl _ _ h).2;exact ⟨by unfold dvN dv;rw[e],o⟩ end lemma S_w (T M:Ὣ) (h1:T+2good sw=true∧good tw=true) include relu g sw tw w hg lemma qGu:E_fz relu g sw tw (dv sw) (dv tw) w=E_fma relu w sw tw:=by unfold E_fz;split;swap;rfl;rename_i hc;obtain ⟨h1,h2⟩:=ὕ.1 hc;obtain ⟨h3,h4⟩:=hg h1;dsimp only;split;rfl;rename_i hr;have r:=mt beq_iff_eq.2 hr;have hf:=qAc _ h2;have g1:=qAc _ h3;have g2:=qAc _ h4;rw[qGg _ _ r,qEz _ (E_d w sw tw) (S_E w sw tw h2 h3 h4 _ (qDv _ _ _ hf g1 g2)) r,E_fma,qC7 _ _ _ hf g1 g2] lemma qHa:E_el relu g sw tw (dv sw) (dv tw) w=E_fma relu w sw tw:=by by_cases hw:w=0 . subst hw;unfold E_el;dsimp only;simp only[beq_self_eq_true,ite_true];split . rename_i hc;obtain ⟨hA,h9⟩:=ὕ.1 hc;obtain ⟨h1,h8⟩:=ὕ.1 hA;obtain ⟨h3,h4⟩:=hg h1 obtain ⟨e9,hr0⟩:=qIf (dv 0*dv sw+dv tw) (by simpa only[decide_eq_true_eq] using h8) (by simpa only[decide_eq_true_eq] using h9);rw[<-e9] have hr':=hr0;have h2:good 0=true:=ה have hf:=qAc _ h2;have g1:=qAc _ h3;have g2:=qAc _ h4 rw[qGg _ _ hr',qEz _ (E_d 0 sw tw) (S_E 0 sw tw h2 h3 h4 _ (qDv _ _ _ hf g1 g2)) hr',E_fma,qC7 _ _ _ hf g1 g2] . exact qGu relu g sw tw 0 hg . have hw':(w==0)=false:=by simpa only[beq_eq_false_iff_ne,ne_eq] using hw unfold E_el;dsimp only;simp only[hw',Bool.false_eq_true,ite_false];split . rename_i hc;obtain ⟨hA,h9⟩:=ὕ.1 hc;obtain ⟨h1,h8⟩:=ὕ.1 hA;obtain ⟨h3,h4⟩:=hg h1;obtain ⟨e9,hr0⟩:=qIf (dvN w*dv sw+dv tw) (by simpa only[decide_eq_true_eq] using h8) (by simpa only[decide_eq_true_eq] using h9);rw[<-e9];obtain ⟨e,o⟩:=qJy (qGl _ _ (qIu _ _ (qIx _ hr0)).1).1;rw[e] at hr0⊢;have hr':=hr0;have h2:=qHr o;have hf:=qAc _ h2;have g1:=qAc _ h3;have g2:=qAc _ h4;rw[qGg _ _ hr',qEz _ (E_d w sw tw) (S_E w sw tw h2 h3 h4 _ (qDv _ _ _ hf g1 g2)) hr',E_fma,qC7 _ _ _ hf g1 g2] . exact qGu relu g sw tw w hg end lemma qEh (relu:Ὡ) (c hw:Ὣ) (s t:ѐ) (d:Ὣ): ∀(ch:Ὣ) (x:ѐ),ch+d=c->ѧx=c*hw->ѧx<2^32-> (E_chs relu c hw s t ch x).size=ѧx/\∀q,q (E_chs relu c hw s t ch x)[q]! =if ch*hw<=q then E_fma relu x[q]! s[q/hw]! t[q/hw]! else x[q]!:=by induction d with | zero=> rintro ch x rfl _ _ rw[E_chs,ἐ (by exact omS491)] exact ⟨rfl,λq hq=>(ἐ (by simpa only[not_le,add_zero] using hq)).symm⟩ | succ d ih=> intro ch x h1 h2 h3 rw[E_chs,ἱ (by clear h2 h3;exact omS136 h1)] dsimp only have h4:=Ἒ hw ((by clear h2 h3;exact omS492 h1):ch+1<=c) have h5:=Nat.add_one_mul ch hw have e1:=qAa ((ch+1)*hw) (by clear h1;exact omS493 h2 h3 h4) have e0:=qAa (ch*hw) (by clear h1;exact omS494 h2 h3 h4 h5) rw[Ἄ (show Ѥ((ch+1)*hw).toUSize<=ѧx by rw[e1,h2];exact h4),lcBU,lcMU _ _ _ _ _ _ rfl h3] obtain ⟨h6,h7⟩:=qE4 (λ_=>E_el relu (good s[ch]!&&good t[ch]!) s[ch]! t[ch]! (dv s[ch]!) (dv t[ch]!)) (L:=E_map _ ((ch+1)*hw).toUSize) (λ_ _=>by rw[E_map];rfl) hw (ch*hw).toUSize x (by clear h1 h2 h3 h4;omega) (by clear h1 h3 e0;omega) h3 obtain ⟨h8,h9⟩:=ih (ch+1) _ (by clear h2 h3 h4 h5 e1 e0 h6;exact omS137 h1) (h6.trans h2) (by clear h1 h4 h5 e1 e0;omega) refine ⟨h8.trans h6,λq hq=>?_⟩ rw[h9 q hq,h7,e0,e1,qHa _ _ _ _ _ ὕ.1] by_cases a:(ch+1)*hw<=q . rw[ἱ a,ἐ (by clear h1 h2 h3 h4 e0 h6 h8 hq;omega),ἱ (by clear h1 h2 h3 h4 h6 h8 hq;omega)] . rw[ἐ a];by_cases b:ch*hw<=q;. rw[ἱ (by clear h1 h2 h3 h4 h6 h8 hq;omega),ἱ b,Nat.div_eq_of_lt_le b (by clear h1 h2 h3 h4 e0 h6 h8 hq b;omega)] . rw[ἐ (by clear h1 h2 h3 h4 h6 h8 hq a;omega),ἐ b] lemma qFf:scaleF=scaleShiftSpec:=by funext relu c hw x s t;unfold scaleF;split . rename_i h;obtain ⟨h1,h2⟩:=h;replace h2:=Nat.lt_of_le_of_lt h2 (show 4294967295<2^32 by norm_num);obtain ⟨h3,h4⟩:=qEh relu c hw s t c 0 x (by clear h1 h2;exact omS139) h1 h2;apply Մ;. simp only[h3,h1,scaleShiftSpec,Fin.is_lt,Ἕ,Array.size_ofFn] . intro i hi hj;have hi':iby simp only[h,UInt32.reduceToNat] at C;(clear a d e D h;omega) have q:expOf r≠0:=λh=>by simp only[h,UInt32.toNat_zero] at C;(clear f a d e D N O l h;omega) have t:expOf s≠0:=λh=>by simp only[h,UInt32.toNat_zero,not_lt_zero] at b have x:Ἢ (ofW y)=2^ѥj:=by rw[qBp _ d,sv,g,e,k];push_cast;rw[show (126+ѥj-149:ℤ)=ѥj-23 by ring,ᾂ ἓ,Ἡ];field_simp;(norm_num1) have I:Ἢ (ofW r)=Ἢ (ofW s)/Ἢ (ofW y):=by rw[x,qBp _ l,qBp _ a,show sv r=sv s by unfold sv mantOf;rw[E,D,ἐ q,ἐ t],show (idxOf r:ℤ)=idxOf s-ѥj by unfold idxOf;rw[ἐ q,ἐ t,C];(clear a d e C D O l q t;omega),sub_right_comm,ᾂ ἓ,Ἡ,mul_div_assoc] have o:=qBi a;have u:=qBi d;have v:=qBi l;have z:=Model.isFinite_div_of_abs_div_le_posMaxFinite _ _ ה o u B (I▸Model.abs_toReal_le_posMaxFinite_of_isFinite _ v);have p:=Model.toReal_div_eq_roundAt _ _ ה u z;rw[<-I,Model.roundAt_toReal_eq _ v] at p;rw[Model.eq_of_toReal_eq_of_nonzero p (p▸qFm r q l),qAw] lemma qH5 {a b:ℝ} (h:asimp only[false_eq_true,ite_true,ite_false]<;>(norm_num1)<;>(clear h w1 w2 hz;omega) have n255:expOf r≠255:=λg=>by rw[g] at l;simp only[UInt32.reduceToNat] at l;(clear h h3 w1 w2 hz g;omega) have n0:expOf r≠0:=λg=>by rw[g] at l;simp only[UInt32.toNat_zero] at l;(clear h h3 w1 w2 hz n255 g;omega) have f:=qBi n255;have m1:ἕ Fmt d1=ofW r:=by rw[w1,qAy] have m2:ἕ Fmt d2=ofW r:=by rw[w2,qAy] have t1:=Model.toReal_roundDyadic_eq_roundAt Fmt ה d1 (m1▸f);have t2:=Model.toReal_roundDyadic_eq_roundAt Fmt ה d2 (m2▸f);rw[m1] at t1;rw[m2] at t2;rw[Ἠ] at a2 b1;have c1:=Model.roundAt_mono Fmt a2.le;have c2:=Model.roundAt_mono Fmt b1.le;have E:ᾁ Fmt V=Ἢ (ofW r):=le_antisymm (t2▸c2) (t1▸c1);have z:=Model.isFinite_div_of_abs_div_le_posMaxFinite x y ה hx hy hy0 (hV▸hb);have p:=Model.toReal_div_eq_roundAt _ _ ה hy z;rw[hV,E] at p;rw[Model.eq_of_toReal_eq_of_nonzero p (p▸qFm r n0 n255),qAw] lemma qJx {a V W Q E P P' z:ℝ} (ha:0a<=1/k*b->k*a<=b:=λhk h=>(le_div_iff₀' hk).mp (h.trans_eq (one_div_mul_eq_div _ _)) have hz':(2:ℝ)^53*z<=a:=(le_div_iff₀' (by norm_num1)).mp hz;have hW':(2:ℝ)*|W| <=a:=(le_div_iff₀' (by norm_num1)).mp hW;have h4':(2:ℝ)^53*|V-W| <=a:=(le_div_iff₀' (by norm_num1)).mp h4 have h2':=sck (by norm_num1) h2;have hP':=sck (by norm_num1) hP;have hN':=sck (by norm_num1) hN;have hE':a=E*2^51:=(div_eq_iff (by norm_num1)).mp hE.symm have pQ:=le_abs_self (Q-W);have nQ:=neg_abs_le (Q-W);have pW:=le_abs_self W;have nW:=neg_abs_le W have b1: |Q+E| <=a:=ὸ.2 ⟨by linarith only[nQ,nW,h2',hW',hz',hE',ha,hz0],by linarith only[pQ,pW,h2',hW',hz',hE',ha,hz0]⟩ have b2: |Q-E| <=a:=ὸ.2 ⟨by linarith only[nQ,nW,h2',hW',hz',hE',ha,hz0],by linarith only[pQ,pW,h2',hW',hz',hE',ha,hz0]⟩ constructor . linarith only[le_abs_self (P'-(Q-E)),hN',b2,pQ,pW,h2',hW',neg_abs_le (V-W),h4',hz',hE',ha,hz0] . linarith only[neg_abs_le (P-(Q+E)),hP',b1,nQ,nW,h2',hW',le_abs_self (V-W),h4',hz',hE',ha,hz0] lemma qJn (s:ὥ) (h1:expOf s≠255) (h0:expOf s≠0):good s=true:=by have e:=qAx s;have b:=s.toNat_lt;have n1:(expOf s).toNat≠255:=λg=>h1 (ἠ.1 g);have n0:(expOf s).toNat≠0:=λg=>h0 (ἠ.1 g);have v:(s&&&В).toNat=ѥs%2^31:=by rw[Ἧ];exact Ἂ ѥs 31 unfold good;simp only[or_eq_true,decide_eq_true_eq,beq_iff_eq];right;have g:(0x00800000:ὥ)<=s&&&В:=by rw[ἃ,v];show 8388608<=_;(clear h1 h0 b n1;omega) rw[ἃ,ὓ _ _ g,v];show _-8388608<=2130706431;(clear h1 h0 b g;omega) lemma qG0 (n:Ὣ) (s:ὥ):E_dq n s=E_div n s:=by have e2pa:∀{x y:ℝ} {a b j:ℕ},x<=2^a->y<=2^b->a<=j->b<=j->x+y<=2^(j+1):=λ{x y a b j} hx hy ha hb=>(add_le_add (hx.trans (pow_le_pow_right₀ one_le_two ha)) (hy.trans (pow_le_pow_right₀ one_le_two hb))).trans_eq ((two_mul _).symm.trans (pow_succ' 2 j).symm) have e2z0:A_z<=2^0:=Submission.D.qBo.trans_eq (pow_zero 2).symm have e2d:∀{x:ℝ} (n:ℕ),0<=x->1/2^n*x<=x:=λn h0=>mul_le_of_le_one_left h0 (div_le_one_of_le₀ (one_le_pow₀ one_le_two) (pow_nonneg zero_le_two n)) have e2AB1:∀{x:ℝ} {k:ℕ},x<=2^k->k<=256+42->x<=A_B:=λh hk=>h.trans (((pow_le_pow_right₀ one_le_two hk).trans_eq (pow_add 2 256 42)).trans Submission.D.qCc) have e2aa:∀(x y:ℝ),|x| <= |y| + |x-y|:=λx y=>sub_le_iff_le_add'.mp (Ὥ x y) unfold E_dq;split;swap;. rfl rename_i h;obtain ⟨n1,n2,nsq,h255,h0⟩:=h;dsimp only;split;. rfl rename_i hr;have hr':ziv (dv s*(((0x20000000000000:Ὠ)/n.toUInt64).toFloat*Ἃ 0x3CA0000000000000)) ((dv s).abs*Ἃ 0x3CC0000000000000)≠Е:=by simpa only[Nat.toUInt64_eq,ne_eq,beq_iff_eq] using hr have hg:=qJn s h255 h0;obtain ⟨df,dR⟩:=qAs s hg;have wl:=qAh s hg;have wn:=qFm s h0 h255;have k13:n.sqrt<13:=by by_contra hc;have:=Nat.mul_le_mul (Nat.le_of_not_lt hc) (Nat.le_of_not_lt hc);(clear h255 h0 hr' hc;omega) have k0:0simp only[Int.cast_neg,Int.cast_natCast,abs_neg,Nat.abs_cast] have a0:0< |wv s|:=abs_pos.2 wn have mS:1<=mantOf s:=by rcases Nat.eq_zero_or_pos (mantOf s) with g | g;. rw[g] at sA;simp only[CharP.cast_eq_zero,zero_mul,abs_eq_zero] at sA;exact absurd sA wn . exact g have aL:(2:ℝ)^(-149:ℤ)<= |wv s|:=by rw[sA];have c:(1:ℝ)<=mantOf s:=by exact_mod_cast mS have d:(2:ℝ)^(-149:ℤ)<=2^((idxOf s:ℤ)-149):=ἒ one_le_two (neg_le_sub_iff_le_add.mpr (le_add_of_nonneg_left (Int.natCast_nonneg _)));exact d.trans (le_mul_of_one_le_left (ἵ (show (0:ℝ)<2 by norm_num) _).le c) obtain ⟨af,aR⟩:=qCx (dv s) df;have aB: |R (dv s).abs| <=A_B:=by rw[aR,dR,abs_abs];exact wl.trans qAe obtain ⟨ee,ed⟩:=qBu (dv s).abs 99 ב af (mantOf s:ℤ) ((idxOf s:ℤ)-149) (by have:=mantOf_lt_24 s;(exact Nat.lt_of_lt_of_le ‹_› ה)) (neg_le_sub_iff_le_add.mpr ((by norm_num1:(149:ℤ)<=900).trans (le_add_of_nonneg_left (Int.natCast_nonneg _)))) aB (by rw[aR,dR,sA];simp only[Int.cast_natCast]) have Re:R ((dv s).abs*pwEntry 99)= |wv s| /2^51:=by rw[ed,aR,dR,Rp];ring have dB: |R (dv s)| <=A_B:=by rw[dR];exact wl.trans qAe have uB0:(0:ℝ)<=(Ѧm:ℝ)/2^53:=div_nonneg (Ἔ _) (by norm_num1) have n2R:(2:ℝ)<=n:=by exact_mod_cast n1 have m1R:(n:ℝ)*Ѧm<=2^53:=by rw[mN];exact_mod_cast m1 have m2R:(2:ℝ)^53ὥ) (l:љ) (c:F1):F1:= l.foldl (λ(acc:F1) t=>let q:=dv (xw t)*dv oneW F1.mk (acc.s+q) (acc.t+q.abs)) c lemma qG2 (X off:ѐ) (k w n:Ὣ) (j z:ὥ) (u nf zb zr:ὧ) (b:ὦ) (hn:n.toUSize.toNat=4): E_win X off k w n j z u nf zb b ѩn 0 zr zr 0=E_w4 X k w n j z u nf zb zr (rdW off 0).toUSize (rdW off (0+1)).toUSize (rdW off (0+1+1)).toUSize (rdW off (0+1+1+1)).toUSize b:=by have h0:(0:ὦ)< ѩn:=by rw[А,hn];decide have e1:=usz _ _ h0 have h1:(0+1:ὦ)< ѩn:=by rw[А,hn,e1];decide have e2:=usz _ _ h1 have h2:(0+1+1:ὦ)< ѩn:=by rw[А,hn,e2,e1];decide have e3:=usz _ _ h2 have h3:(0+1+1+1:ὦ)< ѩn:=by rw[А,hn,e3,e2,e1];decide have e4:=usz _ _ h3 have h4:¬(0+1+1+1+1:ὦ)< ѩn:=by rw[А,hn,e4,e3,e2,e1];decide rw[E_win,Ἄ h0] dsimp only rw[E_win,Ἄ h1] dsimp only rw[E_win,Ἄ h2] dsimp only rw[E_win,Ἄ h3] dsimp only rw[E_win,ἔ h4] rfl lemma qEq (c h w k:Ὣ) (X off:ѐ) (j z:ὥ) (u nf zb zr:ὧ):E_gridK c h w k (k*k) X off j z u nf zb zr=E_grid c h w k (k*k) X off j z u nf zb zr:=by unfold E_gridK;split;. rename_i hk;have hk:=eq_of_beq hk;subst hk;have e:(λb=>E_w4 X 2 w (2*2) j z u nf zb zr (rdW off 0).toUSize (rdW off (0+1)).toUSize (rdW off (0+1+1)).toUSize (rdW off (0+1+1+1)).toUSize b)=λb=>E_win X off 2 w (2*2) j z u nf zb b (2*2).toUSize 0 zr zr 0:=funext λb=>(qG2 X off 2 w (2*2) j z u nf zb zr b (qAa _ (by norm_num1))).symm;dsimp only;rw[e,E_grid] . rfl lemma qF3 (X off:ѐ) (k w n:Ὣ) (j z:ὥ) (nf zb:ὧ) (b m:ὦ) (xw:Ὣ->ὥ) (hx:∀t:ὦ,t< m->rdW X (b+(rdW off t).toUSize)=xw Ѥt) (d:Ὣ):∀(t:ὦ) (s a:ὧ) (o:ὥ),Ѥt+d=Ѥm-> E_win X off k w n j z (dv oneW) nf zb b m t s a o=E_tl X b k w n j z nf zb (E_f xw (List.range' Ѥt d) ⟨s,a⟩).s (E_f xw (List.range' Ѥt d) ⟨s,a⟩).t ((List.range' Ѥt d).foldl (λc i=>c ||| xw i) o):=by induction d with | zero=> intro t s a o h rw[E_win,ἔ (by rw[А];exact omS404 h)] rfl | succ d ih=> intro t s a o h have ht:t< m:=А.2 (by exact omS136 h) rw[E_win,Ἄ ht] dsimp only rw[hx t ht,ih (t+1) _ _ _ (by rw[usz t m ht];(clear ht;exact omS137 h)),usz t m ht,List.range'_succ] rfl lemma qIy (xw:Ὣ->ὥ) (l:љ):∀o:ὥ,l.foldl (λc i=>c ||| xw i) o=0->o=0/\∀i∈l,xw i=0:=by induction l with | nil=>simp only[List.foldl_nil,List.not_mem_nil,IsEmpty.forall_iff,implies_true,and_true,imp_self] | cons i l ih=>intro o h;obtain ⟨h1,h2⟩:=ih _ h;obtain ⟨h3,h4⟩:=UInt32.or_eq_zero_iff.1 h1;exact ⟨h3,List.forall_mem_cons.2 ⟨h4,h2⟩⟩ lemma qIm (n:Ὣ) (hn:n<2^20) (xw:Ὣ->ὥ) (hg:∀t,tgood (xw t)=true) (r:ziv ((E_f xw (ἄ n) ⟨0,0⟩).s+dv 0) (nfOf n*((E_f xw (ἄ n) ⟨0,0⟩).t+(dv 0).abs))≠Е): ziv ((E_f xw (ἄ n) ⟨0,0⟩).s+dv 0) (nfOf n*((E_f xw (ἄ n) ⟨0,0⟩).t+(dv 0).abs))=dotOf n xw (λ_=>oneW):=by obtain ⟨-,-,hbig⟩:=qCp _ _ r obtain ⟨hlo,hhi⟩:=qEd n hn xw (λ_=>oneW) 0 hg (λ_ _=>ה) ה (ἄ n) Ὂ ג (λt h1 h2=>absurd (Ἅ.mpr h1) h2) _ _ ⟨rfl,rfl⟩ hbig have hsum:((∑ j∈Ἣ n,ἂ (xw j)*ἂ oneW:ℚ):ℝ)=exactS n xw (λ_=>oneW) 0:=by rw[exactS,qA8 0 ה ה,add_zero,Rat.cast_sum] refine Ἷ rfl λt ht=>?_ rw[Rat.cast_mul,qA6 _ (qAc _ (hg t (Ὁ.mp ht))),qA6 oneW ה] obtain ⟨d,hd,hw⟩:=qBa n xw (λ_=>oneW) (λj hj=>⟨qAc _ (hg j hj),ה⟩) λh=>qH6 _ _ _ hlo hhi r (by rw[<-hsum,h,Rat.cast_zero]) have q:(d.toRat:ℝ)=exactS n xw (λ_=>oneW) 0:=by rw[hd,hsum] rw[hw] exact qEa _ _ d (by rw[q];exact hlo) (by rw[q];exact hhi) r lemma qHc (X:ѐ) (b:ὦ) (k w n:Ὣ) (hn:n<2^20) (j:ὥ) (hj:j=255\/(j=2/\n=4)\/(j=6/\n=64)) (xw:Ὣ->ὥ) (hg:∀t,tgood (xw t)=true) (hs:E_dot X b k w=dotOf n xw (λ_=>oneW)): E_tl X b k w n j (E_div n (dotFn n (λ_=>0) (λ_=>oneW))) (nfOf n) (dv 0) (E_f xw (ἄ n) ⟨0,0⟩).s (E_f xw (ἄ n) ⟨0,0⟩).t ((ἄ n).foldl (λc i=>c ||| xw i) 0)=E_div n (dotOf n xw (λ_=>oneW)):=by unfold E_tl split next h1=> rw[qAg] unfold dotOf congr 3 funext i exact ((qIy xw _ _ h1).2 _ (Ἅ.2 i.2)).symm . dsimp only;rw[qFt _ _ _ hj];congr 1;split;. rwa[qE9] next hr=>exact qIm _ hn xw hg (mt beq_iff_eq.2 hr) lemma qEe {c h w k ch y x t:Ὣ} (hc:chὥ) (out:ѐ) (p:Ὣ):Prop:= ѧout=N/\N<2^32/\∀i,iout[i]! =sp i lemma qJl {N p:Ὣ} {sp:Ὣ->ὥ} {out:ѐ} (h:G_P N sp out p) (hp:p?_⟩;rw[qAq _ _ _ _ (by clear hp hq hi;omega) (by clear h2 hi;omega),hq];by_cases e:i=p;. rw[ἱ e,e] . rw[ἐ e];exact h3 i (by clear hp h1 h2;(clear hq;exact omS374 hi e)) lemma qH7 (a s i:Ὣ):(a+(i+1)*s).toUSize=(a+i*s).toUSize+ѩs:=by rw[show a+(i+1)*s=a+i*s+s by ring];simp only[Nat.toUSize_eq,USize.ofNat_add] lemma qD5 {L:Ὣ->ὦ->ὦ->ѐ->ѐ} {g:ὦ->ὦ->ѐ->ѐ} {sb S n N q0 b0:Ὣ} {sp:Ὣ->ὥ} (hL:∀i b q o,L i b q o=if iG_P N sp o (q0+i*S)->G_P N sp (g (b0+i*sb).toUSize (q0+i*S).toUSize o) (q0+(i+1)*S)) (d:Ὣ): ∀i o,i+d=n->G_P N sp o (q0+i*S)->G_P N sp (L i (b0+i*sb).toUSize (q0+i*S).toUSize o) (q0+n*S):=by induction d with | zero=> intro i o h1 h2 rw[hL,ἐ (by exact Nat.not_lt.mpr (Nat.le_of_eq (Eq.symm ‹_›))),<-h1] exact h2 | succ d ih=> intro i o h1 h2 rw[hL,ἱ (by exact omS136 h1),<-qH7,<-qH7] exact ih (i+1) _ (by exact omS137 h1) (hs i o (by exact omS136 h1) h2) lemma qIe {f:ὦ->ὥ} {sc sy sx W H c N:Ὣ} {sp:Ὣ->ὥ} (hN:c*(H*W)=N) (hs:∀ch y t,chytf (ch*sc+y*sy+t*sx).toUSize=sp (ch*(H*W)+y*W+t)) (o:ѐ) (ho:G_P N sp o 0): G_P N sp (G_c f ѩsc ѩsy ѩsx W H c 0 0 0 o) N:=by have:=qD5 (L:=G_c f ѩsc ѩsy ѩsx W H c) (sb:=sc) (S:=H*W) (n:=c) (N:=N) (q0:=0) (b0:=0) (sp:=sp) (λ_ _ _ _=>by rw[G_c]) (λch o a1 h=>by have h4:(ch+1)*(H*W)<=N:=hN▸Ἒ _ a1 have:=qD5 (L:=G_y f ѩsy ѩsx W H) (sb:=sy) (S:=W) (n:=H) (N:=N) (q0:=ch*(H*W)) (b0:=ch*sc) (sp:=sp) (λ_ _ _ _=>by rw[G_y]) (λy o a2 h=>by have h5:(y+1)*W<=H*W:=Ἒ _ a2 rw[ᾀ] at h4 h5 have:=qD5 (L:=G_x f ѩsx W) (g:=λb q o=>wrW o q (f b)) (sb:=sx) (S:=1) (n:=W) (N:=N) (q0:=ch*(H*W)+y*W) (b0:=ch*sc+y*sy) (sp:=sp) (λ_ _ _ _=>by rw[G_x];rfl) (λi o a3 h=>by have e1:ch*(H*W)+y*W+(i+1)*1=ch*(H*W)+y*W+i*1+1:=(by clear hN a1 h4 a2 h5 a3;omega) have e2:ch*(H*W)+y*W+i=ch*(H*W)+y*W+i*1:=(by clear hN a1 h4 a2 h5 a3 e1;omega) rw[e1,hs ch y i a1 a2 a3,e2] exact qJl h (by clear hN a1 a2 e1 e2;omega) _ (qAa _ (by have:=h.2.1;(clear a1 a2 e1 e2;omega)))) W 0 o (by clear hN a1 h4 a2 h5;exact omS139) (by simpa only[mul_one,add_zero] using h) simpa only[Nat.toUSize_eq,USize.ofNat_add,USize.ofNat_mul,ᾀ,zero_mul,add_zero,mul_one,ὢ] using this) H 0 o (by clear hN a1 h4;exact omS139) (by simpa only[zero_mul,add_zero,zero_add] using h) simpa only[Nat.toUSize_eq,zero_add,USize.ofNat_mul,ᾀ,zero_mul,add_zero] using this) c 0 o (by clear hN;exact omS139) (by simpa only[zero_mul,add_zero] using ho) simp only[ὒ,Ἇ,Ἵ,hN] at this exact this lemma qHz {c H W q:Ὣ} (hq:qὥ) (c h w k:Ὣ) (hs:c*h*w<2^32): G_c f (h*w).toUSize (k*w).toUSize ѩk (w/k) (h/k) c 0 0 0 (ἇ (c*(h/k*(w/k))) 0)= Array.ofFn (n:=c*(h/k*(w/k))) λq=>let ch:=q.val/(h/k*(w/k)) let y:=q.val/(w/k)%(h/k) let x:=q.val%(w/k) f ((ch*h+y*k)*w+x*k).toUSize:=by have hN:c*(h/k*(w/k))<2^32:=by have h1:h/k*(w/k)<=h*w:=Nat.mul_le_mul (Nat.div_le_self _ _) (Nat.div_le_self _ _) exact ἷ ((Nat.mul_le_mul_left c h1).trans (Nat.mul_assoc c h w).symm.le) hs generalize hH:h/k=H at* generalize hW:w/k=W at* have hp:=qIe (f:=f) (sc:=h*w) (sy:=k*w) (sx:=k) (W:=W) (H:=H) (c:=c) (sp:=λq=>f ((q/(H*W)*h+q/W%H*k)*w+q%W*k).toUSize) rfl (λch y t h1 h2 h3=>by obtain ⟨d1,d2⟩:=qC1 W (H*ch+y) t h3 obtain ⟨d3,d4⟩:=qC1 H ch y h2 have e:ch*(H*W)+y*W+t=W*(H*ch+y)+t:=by ring rw[e,d2,ἥ H W,<-Nat.div_div_eq_div_mul,d1,d3,d4] congr 2 ring) (ἇ (c*(H*W)) 0) ⟨by simp only[Array.size_replicate],hN,by simp only[not_lt_zero,Nat.toUSize_eq,USize.ofNat_add,USize.ofNat_mul,IsEmpty.forall_iff,implies_true]⟩ apply Մ (by rw[hp.1,Array.size_ofFn]) intro i h1 h2 rw[<-Ἕ _ i h1,hp.2.2 i (by simpa only[Nat.toUSize_eq,USize.ofNat_add,USize.ofNat_mul,Array.size_ofFn] using h2),Array.getElem_ofFn] lemma qGm {c h w k ch y x:Ὣ} {X:ѐ} (h1:c*h*w<2^32) (h2:ѧX<2^32) (h3:k*k<2^32) (hc:ch(t/k*w+t%k).toUInt32) _ ht,poolAtO] generalize hu:Ѥt/k*w+Ѥt%k=u have e1:u.toUInt32.toUSize.toNat=u:=by rw[ὃ,Nat.toUInt32_eq,ὡ,Ἁ (by clear h2 h3 hc hy hx ht;omega)] rw[qAv _ _ (by rw[e1,qAa _ (by clear h2 h3 hc hy hx ht;omega)];(clear h2 h3 hc hy hx ht;omega)),e1,qAa _ (by clear h2 h3 hc hy hx ht;omega)] congr 1 (clear h1 h2 h3 hc hy hx ht h4 e1;omega) lemma qI9 {c h w k ch y x:Ὣ} {X:ѐ} (h1:c*h*w<=ѧX) (h2:ѧX<2^32) (h3:k*k<2^20) (hg:∀i,i< ѧX->good X[i]! =true) (hc:ch0) (λ_=>oneW))) (dv oneW) (nfOf (k*k)) (dv 0) ((ch*h+y*k)*w+x*k).toUSize (k*k).toUSize 0 0 0 0= E_div (k*k) (dotOf (k*k) (poolAtO h w k X ch y x) (λ_=>oneW)):=by have hn:=qAa (k*k) (by exact Nat.lt_of_lt_of_le ‹_› ה) have hk:0qGm (by exact Nat.lt_of_le_of_lt ‹_› ‹_›) h2 (by exact Nat.lt_of_lt_of_le ‹_› ה) hc hy hx t (hn▸А.1 ht)) (k*k) 0 0 0 0 ((Ἇ _).trans hn.symm),USize.toNat_zero,<-ὗ] refine qHc X _ k w _ h3 j hj _ (λt ht=>hg _ (by have:=hI t ht;(exact Nat.lt_of_lt_of_le ‹_› ‹_›))) ?_ rw[E_dot,qAg] congr 1 funext t rw[e2,poolAtO] congr 1 ring lemma qWc (X off:ѐ) (k w n:Ὣ) (j z:ὥ) (u nf zb:ὧ) (hu:u=dv oneW) (b m:ὦ) (hx:∀t:ὦ,t< m->(rdW off t).toUSize=t) (d:Ὣ):∀(t:ὦ) (s a:ὧ) (o:ὥ),Ѥt+d=Ѥm->E_winC X k w n j z u nf zb b m t s a o=E_win X off k w n j z u nf zb b m t s a o:=by subst hu induction d with | zero=> intro t s a o h rw[E_winC,E_win,ἔ (by rw[А];exact omS404 h),ἔ (by rw[А];exact omS404 h)] | succ d ih=> intro t s a o h have ht:t< m:=А.2 (by exact omS136 h) rw[E_winC,E_win,Ἄ ht,Ἄ ht] dsimp only rw[hx t ht,D.qM1 _ (D.qDvF _),ih (t+1) _ _ _ (by rw[usz t m ht];exact omS137 h)] lemma qOC (k:Ὣ) (hk:k*k<2^32) (t:ὦ) (ht:Ѥt(t/k*k+t%k).toUInt32) _ ht,Nat.div_add_mod'] apply USize.toNat_inj.mp rw[ὃ,Nat.toUInt32_eq,ὡ,Ἁ (by exact omS201 hk ht)] lemma qAX (X:ѐ) (w:Ὣ) (wu:ὦ) (u nf zb zr:ὧ) (hu:u=dv oneW) (W:Ὣ) (e:ὦ) (d:Ὣ): ∀(x:Ὣ) (b q:ὦ) (out:ѐ),W-x=d->x<=W-> Ѥq+(W-x)=Ѥe-> A_x X w wu u nf zb zr b q e out=G_x (λb=>E_w4 X 2 w 4 2 0 u nf zb zr 0 1 wu (wu+1) b) 2 W x b q out:=by subst hu induction d with | zero=> intro x b q out h1 h2 h3 rw[A_x,G_x,ἔ ט,ἐ (by exact omS411 h1)] | succ d ih=> intro x b q out h1 h2 h3 have hq:q Ѥq+(H-y)*W<2^32-> A_y X w ѩw u nf zb zr W H y b q out=G_y (λb=>E_w4 X 2 w 4 2 0 u nf zb zr 0 1 ѩw (ѩw+1) b) (2*w).toUSize 2 W H y b q out:=by induction d with | zero=> intro y b q out h1 h2 rw[A_y,G_y,ἐ (by exact omS411 h1),ἐ (by exact omS411 h1)] | succ d ih=> intro y b q out h1 h2 rw[h1,ᾀ] at h2 rw[A_y,G_y,ἱ (by exact omS412 h1),ἱ (by exact omS412 h1)] have e1:b+ѩw+ѩw=b+(2*w).toUSize:=by rw[add_assoc,two_mul];simp only[Nat.toUSize_eq,USize.ofNat_add] have hW:Ѥ(q+ѩW)=Ѥq+W:=by rw[qAv _ _ (by rw[qAa _ א];omega),qAa _ א] rw[e1,qAX X w ѩw u nf zb zr hu W (q+ѩW) W 0 b q out א א (by rw[hW];omega)] exact ih (y+1) _ _ _ (by exact omS413 h1) (by rw[hW,show H-(y+1)=d by exact omS413 h1];omega) lemma qAC (X:ѐ) (w:Ὣ) (u nf zb zr:ὧ) (hu:u=dv oneW) (sc:ὦ) (W H c:Ὣ) (d:Ὣ): ∀(ch:Ὣ) (b q:ὦ) (out:ѐ),c-ch=d-> Ѥq+(c-ch)*(H*W)<2^32-> A_c X w ѩw u nf zb zr sc W H c ch b q out=G_c (λb=>E_w4 X 2 w 4 2 0 u nf zb zr 0 1 ѩw (ѩw+1) b) sc (2*w).toUSize 2 W H c ch b q out:=by induction d with | zero=> intro ch b q out h1 h2 rw[A_c,G_c,ἐ (by exact omS411 h1),ἐ (by exact omS411 h1)] | succ d ih=> intro ch b q out h1 h2 rw[h1,ᾀ] at h2 rw[A_c,G_c,ἱ (by exact omS412 h1),ἱ (by exact omS412 h1)] have hHW:Ѥ(q+(H*W).toUSize)=Ѥq+H*W:=by rw[qAv _ _ (by rw[qAa _ א];omega),qAa _ א] rw[qAY X w u nf zb zr hu W H H 0 b q out א (by rw[Nat.sub_zero];omega)] exact ih (ch+1) _ _ _ (by exact omS413 h1) (by rw[hHW,show c-(ch+1)=d by exact omS413 h1];omega) lemma qO2 (w t:Ὣ) (ht:t<4) (hw:t/2*w+t%2<2^32) (i:ὦ) (hi:Ѥi=t):(rdW (E_off 2 w) i).toUSize=ѩ(t/2*w+t%2):=by rw[qAo _ _ (by rw[E_off,Array.size_ofFn];norm_num),hi,E_off,qAb _ (λt=>(t/2*w+t%2).toUInt32) _ ht] apply USize.toNat_inj.mp rw[ὃ,Nat.toUInt32_eq,ὡ,Ἁ hw,qAa _ hw] lemma qZ2 (c h w:Ὣ) (X:ѐ) (u nf zb zr:ὧ) (hu:u=dv oneW) (hN:c*(h/2*(w/2))<2^32) (hw:w<2^31): E_grid2 c h w X u nf zb zr=E_gridK c h w 2 (2*2) X (E_off 2 w) 2 0 u nf zb zr:=by have i1:Ѥ(0+1:ὦ)=1:=by rw[qAv _ _ (by rw[USize.toNat_zero,ὄ];norm_num),USize.toNat_zero,ὄ] have i2:Ѥ(0+1+1:ὦ)=2:=by rw[qAv _ _ (by rw[i1,ὄ];norm_num),i1,ὄ] have i3:Ѥ(0+1+1+1:ὦ)=3:=by rw[qAv _ _ (by rw[i2,ὄ];norm_num),i2,ὄ] have o0:(rdW (E_off 2 w) 0).toUSize=0:=by rw[qO2 w 0 ב (by exact omS333) 0 ה,show 0/2*w+0%2=0 by omega];decide have o1:(rdW (E_off 2 w) (0+1)).toUSize=1:=by rw[qO2 w 1 ב א (0+1) i1,show 1/2*w+1%2=1 by omega];simp only[Nat.toUSize_eq];rfl have o2:(rdW (E_off 2 w) (0+1+1)).toUSize=ѩw:=by rw[qO2 w 2 ב א (0+1+1) i2,show 2/2*w+2%2=w by omega] have o3:(rdW (E_off 2 w) (0+1+1+1)).toUSize=ѩw+1:=by rw[qO2 w 3 ב א (0+1+1+1) i3,show 3/2*w+3%2=w+1 by omega];simp only[Nat.toUSize_eq,USize.ofNat_add];rfl unfold E_grid2 E_gridK rw[qAC X w u nf zb zr hu _ (w/2) (h/2) c c 0 0 0 _ א (by simp only[USize.toNat_zero,tsub_zero,zero_add,Nat.reducePow];omega)] simp only[beq_self_eq_true,ite_true] rw[o0,o1,o2,o3] rfl lemma qGX (c h w k:Ὣ) (X:ѐ) (j z:ὥ) (u nf zb zr:ὧ) (hu:u=dv oneW) (hk:k*k<2^32) (hj:k=2->j=2) (hz:k=2->z=0): E_gridX c h w k (k*k) X j z u nf zb zr=E_gridK c h w k (k*k) X (E_off k w) j z u nf zb zr:=by unfold E_gridX;split . rename_i e;subst e;rw[qEq];unfold E_gridC E_grid;congr 1;funext b exact qWc X (E_off k k) k k (k*k) j z u nf zb hu b ѩ(k*k) (λt ht=>qOC k hk t (by have:=А.mp ht;rwa[qAa _ hk] at this)) (k*k) 0 zr zr 0 (by rw[qAa _ hk];simp only[USize.toNat_zero,zero_add]) . split . rename_i _ e;obtain ⟨rfl,h1,h2⟩:=e;rw[hj rfl,hz rfl];exact qZ2 c h w X u nf zb zr hu (Nat.lt_of_le_of_lt h2 (show 4294967295<2^32 by norm_num)) h1 . rfl lemma qG1:avgF=avgpoolSpecO:=by funext c h w k X;unfold avgF;rw[show D.fz0=(0:ὧ) from rfl];split . rename_i hc;obtain ⟨h1,h2,h3,h4⟩:=hc;replace h2:=Nat.lt_of_le_of_lt h2 (show 4294967295<2^32 by norm_num);simp only[avgpoolSpecO,avgpoolWithO] rw[show (if 00) (λ_=>oneW)))=E_div (k*k) (dotFn (k*k) (λ_=>0) (λ_=>oneW)) by split;. rename_i e;exact (qJo k e.2 e.1).symm . split;. rename_i e;subst e;exact qJo14.symm . rfl] rw[qGX _ _ _ _ _ _ _ _ _ _ _ rfl (by exact omS363 h3) (λe=>by subst e;rfl) (λe=>by subst e;exact qJo 2 ה ה),qEq,E_grid,qIl _ c h w k (by exact Nat.lt_of_le_of_lt ‹_› ‹_›)];apply congrArg Array.ofFn;funext ⟨q,hq⟩;obtain ⟨a1,a2,a3⟩:=qHz hq;dsimp only;refine qI9 h1 h2 h3 (qBh X h2 h4).2.2.1 a1 a2 a3 _ ?_;split_ifs with e1 e2;. exact Or.inr (Or.inl ⟨rfl,e1⟩) . exact Or.inr (Or.inr ⟨rfl,e2⟩) . exact Or.inl rfl . rfl end section @[inline] def maxF (a b:Ὢ):Ὢ:= if a<У/\b<У then (if a?_;unfold Mk;by_cases hc:m%2^23+1<2^23 . rw[show (m+1)/2^23=m/2^23 by omega,show (m+1)%2^23=m%2^23+1 by omega];split;. (exact Nat.le_refl _) . exact Ἦ (by exact Nat.le_refl _) (Nat.two_pow_pos _) . rw[show (m+1)/2^23=m/2^23+1 by omega,show (m+1)%2^23=0 by omega,(א:m%2^23=2^23-1)];cases m/2^23 with | zero=>norm_num | succ e=>have:=Nat.two_pow_pos e;rw[ἐ (by clear hc this;omega),ἐ (by clear hc this;omega),Nat.add_sub_cancel,Nat.add_sub_cancel,pow_succ];(clear hc;omega) lemma Mk2 (w:Ὢ) (h:ѥw<2^31):(expOf w).toNat=ѥw/2^23/\(fracOf w).toNat=ѥw%2^23/\signOf w=false:=by have a2:(0xFF:ὥ).toNat=2^8-1:=rfl;have a3:(0x7FFFFF:ὥ).toNat=2^23-1:=rfl;have a4:(23:ὥ).toNat%32=23:=rfl;have a5:(س:ὥ).toNat=2^31:=rfl;unfold expOf fracOf signOf;rw[Ἧ,Ἧ,UInt32.toNat_shiftRight,a2,a3,a4,Ἂ,Ἂ,Ἱ];refine ⟨by (clear a2 a3 a4 a5;omega),rfl,?_⟩;rw[bne_eq_false_iff_eq,<-ἠ,Ἧ,a5,Nat.and_two_pow,Nat.testBit_lt_two_pow h];rfl lemma Mk3 (w:Ὢ) (h:ѥw<2^31):keyOf w=(Mk ѥw:Int):=by obtain ⟨h1,h2,h3⟩:=Mk2 w h;unfold keyOf;rw[ἐ (by simp only[h3,false_eq_true,not_false_eq_true])];congr 1;unfold mantOf idxOf Mk;rw[ὁ];by_cases e:expOf w=0;. rw[ἱ e,ἱ e,ἱ (by rw[<-h1,e];rfl),h2,pow_zero,Nat.mul_one] . rw[ἐ e,ἐ e,ἐ (λz=>e (ἠ.mp (by rw[h1,z];rfl))),h1,h2] lemma Mk4 (a b:Ὢ) (h:ѥa<ѥb) (hb:ѥb<2^31):keyOf a?_,by (exact Nat.lt_of_lt_of_le ‹_› ה)⟩;have:=(Mk2 w (by exact Nat.lt_of_lt_of_le ‹_› ה)).1;rw[z] at this;have u:(255:ὥ).toNat=255:=rfl;(clear z;omega) lemma Mk7 (a:Ὢ) (h:ѥa<2^31) (n:¬a=0) (hz:Model.isZero (ofW a)=true):False:=by obtain ⟨h1,h2,-⟩:=Mk2 a h;have e:ofW a=_:=ofUInt32_eq_ofFields a;rw[e,Model.isZero_ofFields Fmt _ _ _ (expOf_toNat_lt a) (fracOf_toNat_lt a)] at hz;have y:((expOf a).toNat==0&&(fracOf a).toNat==0)=true:=hz;simp only[and_eq_true,beq_iff_eq] at y;rw[h1,h2] at y;exact n (ἠ.mp (by rw[UInt32.toNat_zero];(clear h h1;(clear h2;omega)))) lemma Mk8 (a:Ὢ) (e:expOf a≠255) (h:ѥa<2^31) (n:¬a=0):maxW a a=a:=by unfold maxW;rw[ἐ (by simpa only[or_self,ne_eq] using e),compare_eq_iff_eq.mpr rfl];dsimp only;rw[ἐ (by simpa only[Bool.and_self,Bool.not_eq_true,imp_false] using Mk7 a h n)];exact qAw a lemma qHi (a b:Ὢ):maxF a b=maxW a b:=by unfold maxF;split . rename_i h;obtain ⟨ha,hb⟩:=h;obtain ⟨e1,a1⟩:=Mk5 a ha;obtain ⟨e2,b1⟩:=Mk5 b hb;have d:¬(expOf a=255\/expOf b=255):=by simp only[e1,e2,or_self,not_false_eq_true] by_cases c:ampWin inp off b (k*k).toUSize 0 (rdW inp b)) (h*w).toUSize (k*w).toUSize ѩk (w/k) (h/k) c 0 0 0 (ἇ (c*(h/k*(w/k))) 0) else maxpoolW c h w k inp lemma qFv (X off:ѐ) (b m:ὦ) (xw:Ὣ->ὥ) (hx:∀t:ὦ,t< m->rdW X (b+(rdW off t).toUSize)=xw Ѥt) (d:Ὣ): ∀(t:ὦ) (a:ὥ),Ѥt+d=Ѥm->mpWin X off b m t a=(List.range' Ѥt d).foldl (λa i=>maxF a (xw i)) a:=by induction d with | zero=> intro t a h rw[mpWin,ἔ (by rw[А];exact omS404 h)] rfl | succ d ih=> intro t a h have ht:t< m:=by rw[А];exact omS136 h rw[mpWin,Ἄ ht,hx t ht,ih (t+1) _ (by rw[usz t m ht];(clear ht;exact omS137 h)),usz t m ht,List.range'_succ,ὔ] @[inline] def mp4 (X:ѐ) (w b:ὦ):ὥ:= let v0:=D.rdW X b maxF (maxF (maxF (maxF v0 v0) (D.rdW X (b+1))) (D.rdW X (b+w))) (D.rdW X (b+w+1)) lemma rdOff (w k:Nat) (hk:k<4):D.rdW (E_off 2 w) k.toUSize=(k/2*w+k%2).toUInt32:=by have hs:(E_off 2 w).size=4:=by simp only[E_off,Nat.reduceMul,Nat.toUInt32_eq,UInt32.ofNat_add,UInt32.ofNat_mul,Array.size_ofFn] have hku:(k.toUSize).toNat=k:=D.uk k א have hlt:k.toUSize<(E_off 2 w).usize:=by rw[А,hku];simp only[Array.usize,hs];rw[D.uk 4 ב];exact hk unfold D.rdW;rw[dif_pos hlt] simp only[Array.uget,E_off,Nat.reduceMul,Nat.toUInt32_eq,UInt32.ofNat_add,UInt32.ofNat_mul,Nat.toUSize_eq,hku,Array.getElem_ofFn] lemma mp4_eq (X:ѐ) (w:Nat) (hw:w<2^31) (b:ὦ): mp4 X w.toUSize b=mpWin X (E_off 2 w) b (2*2:Nat).toUSize 0 (D.rdW X b):=by have hm:USize.toNat (2*2:Nat).toUSize=4:=D.uk 4 ב rw[qFv X (E_off 2 w) b (2*2:Nat).toUSize (λj=>D.rdW X (b+(D.rdW (E_off 2 w) j.toUSize).toUSize)) (λt _=>by simp only[USize.ofNat_toNat]) 4 0 (D.rdW X b) (by rw[hm];rfl)] have o0:D.rdW (E_off 2 w) (0:Nat).toUSize=0:=by rw[rdOff w 0 ב];simp only[Nat.zero_div,zero_mul,Nat.zero_mod,add_zero,Nat.toUInt32_eq,UInt32.reduceOfNat] have o1:D.rdW (E_off 2 w) (1:Nat).toUSize=1:=by rw[rdOff w 1 ב];simp only[Nat.reduceDiv,zero_mul,Nat.mod_succ,zero_add,Nat.toUInt32_eq,UInt32.ofNat_one] have o2:D.rdW (E_off 2 w) (2:Nat).toUSize=w.toUInt32:=by rw[rdOff w 2 ב];simp only[Order.lt_two_iff,zero_le,Nat.div_self,one_mul,Nat.mod_self,add_zero,Nat.toUInt32_eq] have o3:D.rdW (E_off 2 w) (3:Nat).toUSize=(w+1).toUInt32:=by rw[rdOff w 3 ב];simp only[Nat.reduceDiv,one_mul,Nat.reduceMod,Nat.toUInt32_eq,UInt32.ofNat_add,UInt32.ofNat_one] have e2:w.toUInt32.toUSize=w.toUSize:=by apply USize.toNat_inj.mp;rw[ὃ,ὡ,D.uk w א];omega have e3:(w+1).toUInt32.toUSize=w.toUSize+1:=by apply USize.toNat_inj.mp;rw[ὃ,ὡ,USize.toNat_add,D.uk w א,ὄ] have:2^32<=USize.size:=USize.le_size have h1:(w+1)%2^32=w+1:=Ἁ א have h2:(w+1)%USize.size=w+1:=Ἁ א simp only[h1,h2] have z0:USize.toNat 0=0:=rfl have u0:(0:ὥ).toUSize=0:=rfl have u1:(1:ὥ).toUSize=1:=by apply USize.toNat_inj.mp;rw[ὃ,ὄ];rfl simp only[List.range',List.foldl,mp4,z0,Nat.reduceAdd,o0,o1,o2,o3,e2,e3,u0,u1,add_zero,USize.add_assoc] def maxpoolF2 (c h w k:Nat) (inp:ѐ):ѐ:= if k=2/\w<2^31/\c*h*w<=4294967295/\inp.size<=4294967295 then G_c (λb=>mp4 inp w.toUSize b) (h*w).toUSize (2*w).toUSize (2:Nat).toUSize (w/2) (h/2) c 0 0 0 (ἇ (c*(h/2*(w/2))) 0) else maxpoolF c h w k inp lemma maxpoolF2_eq:maxpoolF2=maxpoolF:=by funext c h w k inp unfold maxpoolF2 split · rename_i hc obtain ⟨rfl,hw,h1,h2⟩:=hc unfold maxpoolF rw[Ὦ ⟨h1,h2,ב⟩] dsimp only simp only[mp4_eq inp w hw] · rfl lemma qDp:maxpoolF=maxpoolSpecO:=by rw[<-qDn];funext c h w k inp;unfold maxpoolF;split . rename_i hc;obtain ⟨h1,h2,h3⟩:=hc;replace h1:=Nat.lt_of_le_of_lt h1 (show 4294967295<2^32 by norm_num);replace h2:=Nat.lt_of_le_of_lt h2 (show 4294967295<2^32 by norm_num);replace h3:=Nat.lt_of_le_of_lt h3 (show 4294967295<2^32 by norm_num);rw[qIl _ c h w k h1];simp only[maxpoolW];apply congrArg Array.ofFn;funext ⟨q,hq⟩;obtain ⟨a1,a2,a3⟩:=qHz hq;dsimp only;have hn:(k*k).toUSize.toNat=k*k:=qAa _ h3 have e:∀{ch y x:Ὣ},chyxrdW inp ((ch*h+y*k)*w+x*k).toUSize=poolAtO h w k inp ch y x 0:=by intro ch y x b1 b2 b3 have h4:=qEe (t:=0) b1 b2 b3 (by rcases Nat.eq_zero_or_pos k with rfl | h0;. simp only[Nat.div_zero,not_lt_zero] at b2 . exact Nat.mul_pos h0 h0) simp only[Nat.zero_div,Nat.zero_mod,Ἵ] at h4;rw[qAo _ _ h2,qAa _ (by clear h2 h3 hq a1 a2 a3 hn b1 b2 b3;exact omS279 h1 h4)];simp only[poolAtO,Nat.zero_div,add_zero,Nat.zero_mod] rw[e a1 a2 a3,qFv inp _ _ _ (poolAtO h w k inp _ _ _) (λt ht=>qGm h1 h2 h3 a1 a2 a3 t (by rw[А,hn] at ht;exact ht)) (k*k) 0 _ (by rw[hn,show (0:ὦ).toNat=0 from rfl,Ἇ]),show (0:ὦ).toNat=0 from rfl,<-ὗ];simp only[qHi] . rfl end section section variable {z:ℝ} (hz0:0<=z) (hz:z<=1/2^200*(1/2^200)) include hz0 hz end lemma qHo (a b:ѐ) (hs:ѧa=ѧb) (hf:∀j,j< ѧa->expOf a[j]!≠255/\expOf b[j]!≠255) (hz:(dsum a b 0 ѧa:ℚ)*2^(-298:Int)=0):dotSpec a b=toWord (Model.zero Fmt (decide (ѧa≠0)&&dallNZ a b 0 ѧa)):=by rw[<-qEk a b hs.symm hf,show dsum a b 0 ѧa=0 by simpa only[Int.reduceNeg,zpow_neg,zpow_ofNat,mul_eq_zero,Int.cast_eq_zero,inv_eq_zero,ne_eq,OfNat.ofNat_ne_zero,not_false_eq_true,pow_eq_zero_iff,or_false] using hz,finishWord_zero] lemma qD6 (n:Ὣ) (a b:Ὣ->ὥ) (hf:∀t,texpOf (a t)≠255/\expOf (b t)≠255) (hS:∑ j∈Ἣ n,ἂ (a j)*ἂ (b j)=0): dotOf n a b=toWord (Model.zero Fmt (decide (n≠0)&&dallNZ (Array.ofFn (n:=n) λi=>a i.val) (Array.ofFn (n:=n) λi=>b i.val) 0 n)):=by have gA:=qAb n a have gB:=qAb n b have s:(Array.ofFn (n:=n) λi=>a i.val).size=n:=by simp only[Array.size_ofFn] have e:=qHo (Array.ofFn (n:=n) λi=>a i.val) (Array.ofFn (n:=n) λi=>b i.val) ג (λj hj=>by rw[s] at hj;rw[gA j hj,gB j hj];exact hf j hj) (by rw[s,qE8,<-hS] refine Ἷ rfl λj hj=>?_ have h:=Ὁ.mp hj rw[Ἇ,gA j h,gB j h]) rw[s] at e exact e lemma qJw (a b:ѐ) (r i:Ὣ): dallNZ a b i (r+1)=(dallNZ a b i r&&(decide (mantOf a[i+r]!*mantOf b[i+r]! =0)&&Bool.xor (signOf a[i+r]!) (signOf b[i+r]!))):=by induction r generalizing i with | zero=>simp only[dallNZ,mul_eq_zero,Bool.decide_or,Bool.and_true,add_zero,Bool.true_and] | succ r ih=> rw[dallNZ,ih (i+1),dallNZ] simp only[Bool.and_assoc,show i+1+r=i+(r+1) by exact omS146] lemma qIp (a b u v:ѐ) (r i:Ὣ) (h:∀j,i<=j->j< i+r->a[j]! =u[j]!/\b[j]! =v[j]!):dallNZ a b i r=dallNZ u v i r:=by induction r generalizing i with | zero=>rfl | succ r ih=>rw[dallNZ,dallNZ,ih (i+1) (λj h1 h2=>h j (by exact Nat.le_of_lt ‹_›) (by clear h1;omega)),(h i (by exact Nat.le_refl _) א).1,(h i (by exact Nat.le_refl _) א).2] lemma qI0 (k:Ὣ) (a b:Ὣ->ὥ) (hk:0expOf (a t)≠255/\expOf (b t)≠255): dotOf (k+1) (λt=>if tif texpOf (if jby by_cases h:jby simp only[Finset.mem_range.mp hj, ↓reduceIte] by_cases hS:(∑ j∈Ἣ k,ἂ (a j)*ἂ (b j))=0 . have g1:=qAb (k+1) λt=>if tif ta i.val) (Array.ofFn (n:=k) λi=>b i.val) k 0 (λj _ h2=>by rw[g1 j א,g2 j א,qAb k a j א,qAb k b j א] simp only[show jhS (hd.symm.trans (h3.symm.trans ((t _).2 h)))) (λh=>hS (hd.symm.trans ((t _).2 h))) h3] lemma qD9 (A:ѐ) (h:A.all finiteWord=true) (t:Ὣ):expOf A[t]!≠255:=by by_cases ht:t< ѧA;. simpa only[ne_eq,finiteWord,bne_iff_ne] using qI1 A _ h t ht . rw[ὑ A t ht];decide end def linRg (inW m outW:Ὣ) (relu:Ὡ) (X W b:ё) (Dw:ὤ) (hd:ѨDw=ѧW) (q:ὥ) (nf bm:ὧ) (n:ὦ):Ὣ->Ὣ->ё->ὤ->D.CN | 0,_,out,_=>⟨out,true⟩ | k+1,r0,out,xs=> let d:=D.dec8oC X (r0*inW).toUSize n xs let c:=D.cols8ZDA Dw (D.hvI m) inW outW relu X W b hd d nf n r0 (r0*outW).toUSize 0 out q (D.mkL8 nf (D.dv (D.hvI m)) bm d) ⟨0,0,0,0,0,0,0,0,0,0,0⟩ if c.ok then linRg inW m outW relu X W b Dw hd q nf bm n k (r0+8) c.out d.xs else ⟨c.out,false⟩ def linR (rows inW outW:Ὣ) (relu:Ὡ) (X W b:ё):ё:= if rows*inW=ѧX/\outW*inW=ѧW/\outW=ѧb/\0< inW/\0if t< inW then X[q/outW*inW+t]! else oneW) (λt=>if t< inW then W[q%outW*inW+t]! else b[q%outW]!)) lemma qRgE {m:Ὣ} (inW outW:Ὣ) (relu:Ὡ) (X W b:ё) (HD:(D.dnOf (D.tZ m) (D.qTs (D.qTZ m)) W).size=ѧW) (o:ὦ) (xs:ὤ) (n:ὦ) (hn:Ѥn=inW) (hW:outW*inW=ѧW) (hs:ѧW<2^32) (pi:0< inW) (ri:Ὣ) (ob:ὦ) (out:ё) (th:D.L8) (r0:D.F8): D.cols8ZDA (D.dnOf (D.tZ m) (D.qTs (D.qTZ m)) W) (D.hvI m) inW outW relu X W b HD (D.dec8o X o n 0 xs 0 0 0 0 0 0 0 0) (D.nfOf inW) n ri ob 0 out (D.qScan W W.usize 0 Е) th r0 =D.cols8Zo (D.tZ m) (D.qTs (D.qTZ m)) (D.hvI m) inW outW relu X W b (D.dec8o X o n 0 xs 0 0 0 0 0 0 0 0) (D.nfOf inW) n ri ob 0 out Е th r0:=by rw[D.mcA (HX:=D.mGX X o n xs) (HD:=D.mFD (D.qTs (D.qTZ m)) (D.qTZ m) W)] have e:=D.c8ZSo (D.tZ m) (D.qTs (D.qTZ m)) (D.hvI m) inW outW relu X W b (D.dec8o X o n 0 xs 0 0 0 0 0 0 0 0) (D.nfOf inW) n ri ob hn hW hs pi out th r0 rw[Ἄ HD] at e;exact e lemma qRg {rows inW outW m:Ὣ} {relu:Ὡ} {X W b:ё} (G:D.C_G rows inW outW X W b) (HD:(D.dnOf (D.tZ m) (D.qTs (D.qTZ m)) W).size=ѧW) (bm:ὧ) (fbm:bmᶠ) (hbm:∀j,j |R (D.dv b[j]!)| <=R bm) (bb:R bm<=2^(290:ℤ)): ∀k r0 (out:ё) (xs:ὤ),8*inW+1<=xs.size->xs.size<2^32->r0+8*k<=rows->D.C_Inv (rows*outW) (D.C_sp inW outW relu X W b) (λq=>q (linRg inW m outW relu X W b (D.dnOf (D.tZ m) (D.qTs (D.qTZ m)) W) HD (D.qScan W W.usize 0 Е) (D.nfOf inW) bm (ѩinW) k r0 out xs).ok=true-> D.C_Inv (rows*outW) (D.C_sp inW outW relu X W b) (λq=>q<(r0+8*k)*outW) (linRg inW m outW relu X W b (D.dnOf (D.tZ m) (D.qTs (D.qTZ m)) W) HD (D.qScan W W.usize 0 Е) (D.nfOf inW) bm (ѩinW) k r0 out xs).out:=by intro k induction k with | zero=> intro r0 out xs _ _ _ H _ simp only[linRg,Nat.mul_zero,Ἵ];exact H | succ k ih=> intro r0 out xs hx1 hx2 hk H ok have hni:=G.ni have hpi:=G.pi have hpo:=G.po have hr8:r0+8<=rows:=by (clear hni hpi hpo;omega) have nm:inW.toUSize.toNat=inW:=D.qAd _ (by (exact Nat.lt_of_lt_of_le ‹_› ה)) have hX32:ѧX<2^32:=G.sX have hrO:(r0+8)*outW<=rows*outW:=Ἒ _ hr8 have hrI:(r0+8)*inW<=rows*inW:=Ἒ _ hr8 have hRO:=G.sO have hRI:rows*inW<2^32:=by rw[G.hX];exact hX32 have e8:(r0+8)*outW=r0*outW+8*outW:=ὰ _ _ _ have e8i:(r0+8)*inW=r0*inW+8*inW:=ὰ _ _ _ have hob:((r0*outW).toUSize).toNat=r0*outW:=D.qAd _ (by (clear hk hni hpi hr8 nm hX32 hrI hRI e8i;omega)) have ho:((r0*inW).toUSize).toNat=r0*(ѩinW).toNat:=by rw[nm];exact D.qAd _ (by (clear hk hpo hr8 hX32 hrO hRO e8 hob;omega)) have h8X:(r0+8)*(ѩinW).toNat<=ѧX:=by rw[nm,<-G.hX];exact hrI have P0:8*inW+1<=xs.size/\xs.size<2^32:=⟨hx1,hx2⟩ have D0:D.C_D8o X r0 (ѩinW).toNat (0:ὦ).toNat ⟨xs,0,0,0,0,0,0,0,0⟩:=by rw[nm,D.C_z];exact ⟨P0,λk r hk=>absurd hk (Ἲ _),λr hr=>by interval_cases r<;>rfl⟩ have Dd:=D.qGqo hX32 ho h8X (ѩinW).toNat 0 _ 0 0 0 0 0 0 0 0 (by rw[D.C_z,Ἇ]) D0 rw[nm] at Dd simp only[linRg] at ok⊢ simp only[D.dec8oC_eq _ _ _ _ hX32] at ok⊢ rw[qRgE inW outW relu X W b HD _ _ _ nm G.hW G.sW hpi] at ok⊢ by_cases hc:(D.cols8Zo (D.tZ m) (D.qTs (D.qTZ m)) (D.hvI m) inW outW relu X W b (D.dec8o X (r0*inW).toUSize (ѩinW) 0 xs 0 0 0 0 0 0 0 0) (D.nfOf inW) (ѩinW) r0 (r0*outW).toUSize 0 out Е (D.mkL8 (D.nfOf inW) (D.dv (D.hvI m)) bm (D.dec8o X (r0*inW).toUSize (ѩinW) 0 xs 0 0 0 0 0 0 0 0)) ⟨0,0,0,0,0,0,0,0,0,0,0⟩).ok=true . rw[ἱ hc] at ok⊢ obtain ⟨-,-,A2⟩:=D.qZ8o (D.qTZ m) hob hr8 G.hW hpi hni G.sW Dd.1 _ bm fbm hbm bb (λr hr=>by interval_cases r<;>rfl) outW 0 _ _ _ (Ἇ _) hc have H1:=A2 G Dd (D.qA5 H (λq _ hq=>by unfold D.C_B at hq;rcases hq with h|⟨_,_,h⟩;exact h;exact absurd h (Ἲ _))) have H2:D.C_Inv (rows*outW) (D.C_sp inW outW relu X W b) (λq=>q<(r0+8)*outW) _:=D.qA5 H1 (λq _ hq=>by unfold D.C_B;by_cases e:qlinSp inW outW relu X W b q.val:=by have FB:D.linF rows inW outW relu X W b=Array.ofFn (n:=rows*outW) λq=>linSp inW outW relu X W b q.val:=by rw[D.qDz];rfl unfold linR;dsimp only by_cases h:rows*inW=ѧX/\outW*inW=ѧW/\outW=ѧb/\0< inW/\0absurd hk (Ἲ _),λr hr=>by interval_cases r<;>rfl⟩ have Dd0:=D.qGqo h7 ho0 h8X0 (ѩinW).toNat 0 _ 0 0 0 0 0 0 0 0 (by rw[D.C_z,Ἇ]) D00 rw[nm] at Dd0 obtain ⟨gb1,gb2,-,gb4⟩:=D.qA8 1 b h9 h13 obtain ⟨pb0,pb1,pb2⟩:=D.qCs gb1 gb2 obtain ⟨fbm,Rbm⟩:=D.qAm _ gb1 have hbm:∀j,j |R (D.dv b[j]!)| <=R (D.dv (D.scanH 1 b)):=λj hj=>by have gj:=(D.qA8 1 b h9 h13).2.2.1 j (by rw[<-h3];exact hj) rw[(D.qAm _ gj).2,Rbm];exact pb2 _ gj (gb4 j (by rw[<-h3];exact hj)) have bb:R (D.dv (D.scanH 1 b))<=2^(290:ℤ):=by rw[Rbm];exact pb1.trans (by rw[show (2:ℝ)^128=2^(128:ℤ) by norm_num];exact ἒ ב ב) obtain ⟨-,A1,-⟩:=D.qZ8o (R:=rows) (D.qTZ (D.nE inW W)) hob0 (by (exact Nat.succ_le_of_lt ‹_›)) h2 h4 h6 h8 Dd0.1 _ (D.dv (D.scanH 1 b)) fbm hbm bb (λr hr=>by interval_cases r<;>rfl) outW 0 _ _ _ (Ἇ _) c1 have A:∀q,q< ѧW->D.good W[q]! =true:=λq hq=>by have e1:=(A1 (q/inW) (Nat.zero_le _) (Ἰ (by rw[ἥ,h2];exact hq)) (q%inW) (ὀ _ h4)).1 rwa[Nat.div_add_mod' q inW] at e1 have G:D.C_G rows inW outW X W b:=⟨h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,(D.qA8 0 X h7 h11).2.2.1,A,(D.qA8 1 b h9 h13).2.2.1⟩ have R1:=qRg G HD (D.dv (D.scanH 1 b)) fbm hbm bb (rows/8) 0 _ (D.zFor (8*inW+1)) P0.1 P0.2 (by (clear hX hN hNi h1 h2 h3 h4 h5 h6 h11 h13 hr8 h7 h8 h9 h10 nm hob0 P0 ho0 h8X0;omega)) ⟨by simp only[Array.size_replicate],λq _ hq=>absurd hq (by simp only[zero_mul,not_lt_zero,not_false_eq_true])⟩ hok rw[Ἇ] at R1 rw[e] by_cases hm:rows%8=0 . rw[ἱ hm];have e2:8*(rows/8)=rows:=by (clear hX hN hNi h1 h2 h3 h4 h5 h6 h11 h13 hr8 h7 h8 h9 h10 nm hob0 P0 ho0 h8X0;omega) rw[e2] at R1;exact D.qBv R1 (λq hq=>hq) . rw[ἐ hm];by_cases h5:1<=rows%8 . rw[ἱ h5] split . rename_i hok2 have R2:=qRg G HD (D.dv (D.scanH 1 b)) fbm hbm bb 1 (rows-8) _ (D.zFor (8*inW+1)) P0.1 P0.2 א (D.qA5 R1 (λq _ hq=>by have:=Ἒ outW (show rows-8<=8*(rows/8) by omega);(exact Nat.lt_of_lt_of_le ‹_› ‹_›))) hok2 have e3:rows-8+8*1=rows:=א rw[e3] at R2;exact D.qBv R2 (λq hq=>hq) . rw[<-e];exact FB . rw[ἐ h5] rw[<-e];exact FB . rw[ἐ hok];exact FB . rw[ἔ HD];exact FB . rw[ἐ h];exact FB lemma qHb:linG=linearSpec:=by funext rows inW outW relu X W b;unfold linG;split;. rw[D.qDz] . split;. rename_i _ h;obtain ⟨hs,hN,hNi⟩:=h;rw[qRR rows inW outW relu X W b hs (Nat.lt_of_le_of_lt hN (show 4294967295<2^32 by norm_num)) (Nat.lt_of_le_of_lt hNi (show 4294967295<2^32 by norm_num))];rfl . rw[D.qDz] def linRb (inW outW:Ὣ) (relu:Ὡ) (X W b:ё) (c:(ὤ×ὥ)×(ὤ×ὥ)) (nf:ὧ) (n:ὦ):Ὣ->Ὣ->ὤ->ё->D.CN | 0,_,_,out=>⟨out,true⟩ | k+1,i,buf,out=> let v:=D.decF X (i*inW).toUSize n buf 0 if v.ok then let lo:=D.loOf (nf*(D.dv c.1.2*v.l+D.dv c.2.2)) linRb inW outW relu X W b c nf n k (i+1) v.buf (if 128<=inW then D.colsN3 inW outW relu X W b i D.idA v.buf (ἆ 0) c.1.1 c.2.1 nf v.l c.1.2 lo (D.spOf lo) n n 0 (i*outW).toUSize out else D.colsN2 inW outW relu X W b i D.idA v.buf (ἆ 0) c.1.1 c.2.1 nf v.l c.1.2 lo (D.spOf lo) n n 0 (i*outW).toUSize out) else ⟨out,false⟩ def linH (rows inW outW:Ὣ) (relu:Ὡ) (X W b:ё):ё:= let cb:=(D.wnGet inW outW W b).1 if rows*inW=ѧX/\outW*inW=ѧW/\outW=ѧb/\0< inW/\0buf.data[k]! =D.dv X[i*n+k]!):∀k p:Ὣ,(ἄ n)[k]?=some p->(D.idA[k]!).toNat=p/\buf.data[k]! =D.dv X[i*n+p]!:=λk p hk=>by by_cases hk2:k |R (D.dv b[j]!)| <=R (D.dv (D.scanH 1 b))) (bb:R (D.dv (D.scanH 1 b))<=2^(290:ℤ)): ∀k i (buf:ὤ) (out:ё),i+k<=rows->inW<=Ѩbuf-> Ѩbuf<2^32->D.C_Inv (rows*outW) (D.C_sp inW outW relu X W b) (λq=>q< i*outW) out-> (linRb inW outW relu X W b ((D.wbOf inW outW W,D.scanH 2 W),(D.bOf b,D.scanH 1 b)) (D.nfOf inW) (ѩinW) k i buf out).ok=true-> D.C_Inv (rows*outW) (D.C_sp inW outW relu X W b) (λq=>q<(i+k)*outW) (linRb inW outW relu X W b ((D.wbOf inW outW W,D.scanH 2 W),(D.bOf b,D.scanH 1 b)) (D.nfOf inW) (ѩinW) k i buf out).out:=by intro k induction k with | zero=> intro i buf out _ _ _ H _ simp only[linRb,Ἵ];exact H | succ k ih=> intro i buf out hk hb1 hb2 H ok have hi:iabsurd hk (Ἲ _)) rfl hc rw[nm] at v2 v3 have Rd:=qRdI X inW i _ h8k v2 have Rw:D.C_Row inW X i D.idA (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).buf (ѩinW) (ἄ inW) (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l:=⟨by rw[nm,List.length_range],by simp only[List.length_range,Std.le_refl],by rw[D.qIs];exact h8k,⟨by rw[v1];exact hb1,by rw[v1];exact hb2⟩,Ὂ,λt ht=>Ἅ.1 ht,λt ht hn=>absurd (Ἅ.2 ht) hn,Rd,v3⟩ have Hv:=D.qA8 2 W G.sW hv have HdE:D.C_Dw (ἆ 0) W:=λh q hq=>by have e:0=ѧW:=h;omega have hob:((i*outW).toUSize).toNat=i*outW:=D.qAd _ א have hix:Ѥ(ѩinW)<=ѧD.idA:=by rw[D.qIs,nm];omega have hOW:outW*Ѥ(ѩinW)<=ѧW:=by rw[nm,G.hW] have hm0:0<Ѥ(ѩinW):=by rw[nm];exact G.pi have hBo:outW<=ѧb:=by rw[G.hb] have hW8:ѧW<=4294967295:=by have:=G.sW;omega have HI:∀k,k< Ѥ(ѩinW)->(D.idA[k]!).toNat=k:=λk hk=>D.qIA k (Nat.lt_of_lt_of_le (by rwa[nm] at hk) h8k) have HX:∀j,j< Ѥ(ѩinW)->∃w,D.good w=true/\(D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).buf.data[j]! =D.dv w:=λj hj=>by rw[Rw.len] at hj;have hp:=List.getElem?_eq_getElem hj;exact ⟨_,G.gx hi _ (Rw.lt _ (List.mem_of_getElem? hp)),(Rw.rd j _ hp).2⟩ have HB:∀j i k,j%8=0->j+8<=outW->i< Ѥ(ѩinW)->k<8->(D.wbOf inW outW W).data[j*Ѥ(ѩinW)+5+8*i+k]! =D.dv W[(j+k)*Ѥ(ѩinW)+i]!:=λj i k a b c d=>by rw[nm] at c⊢;exact D.wbP W inW outW j i k a b c d have HBt:outW%8≠0-> ∀i k,i< Ѥ(ѩinW)->k<8->(D.wbOf inW outW W).data[(8*(outW/8))*Ѥ(ѩinW)+5+8*i+k]! =D.dv W[(min (8*(outW/8)+k) (outW-1))*Ѥ(ѩinW)+i]!:=λho i k hi hk=>by rw[nm] at hi⊢;exact D.wbPt W inW outW i k ho hi hk have HO2:outW<2^32:=by rw[G.hb];exact G.sb have E:(if 128<=inW then D.colsN3 inW outW relu X W b i D.idA (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).buf (ἆ 0) (D.wbOf inW outW W) (D.bOf b) (D.nfOf inW) (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l (D.scanH 2 W) (D.loOf (D.nfOf inW*(D.dv (D.scanH 2 W)*(D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l+D.dv (D.scanH 1 b)))) (D.spOf (D.loOf (D.nfOf inW*(D.dv (D.scanH 2 W)*(D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l+D.dv (D.scanH 1 b))))) (ѩinW) (ѩinW) 0 (i*outW).toUSize out else D.colsN2 inW outW relu X W b i D.idA (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).buf (ἆ 0) (D.wbOf inW outW W) (D.bOf b) (D.nfOf inW) (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l (D.scanH 2 W) (D.loOf (D.nfOf inW*(D.dv (D.scanH 2 W)*(D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l+D.dv (D.scanH 1 b)))) (D.spOf (D.loOf (D.nfOf inW*(D.dv (D.scanH 2 W)*(D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l+D.dv (D.scanH 1 b))))) (ѩinW) (ѩinW) 0 (i*outW).toUSize out) =D.cols1 inW outW relu X W b i D.idA (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).buf (ἆ 0) (D.nfOf inW) (D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l (D.scanH 2 W) (D.loOf (D.nfOf inW*(D.dv (D.scanH 2 W)*(D.decD X (i*inW).toUSize (ѩinW) 0 buf 0).l+D.dv (D.scanH 1 b)))) (ѩinW) (ѩinW) 0 (i*outW).toUSize out:=by split . rw[D.cN3W inW outW relu X W b i D.idA _ (ἆ 0) _ _ _ _ _ _ _ _ hBo G.sb hix hW8 hOW hm0 _ 0 _ rfl] rw[D.c1VW _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ HI (Ὗ _),D.c1WE _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ HX HdE hOW HO2 HB HBt 0 rfl] . rw[D.cN2W inW outW relu X W b i D.idA _ (ἆ 0) _ _ _ _ _ _ _ _ hBo G.sb hix hW8 hOW hm0 _ 0 _ rfl] rw[D.c1VW _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ HI (Ὗ _),D.c1WE _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ HX HdE hOW HO2 HB HBt 0 rfl] rw[E] at ok⊢ have R1:=D.qD0 G relu hi Hv Rw hob HdE (D.dv (D.scanH 1 b)) fbm hbm bb rfl outW 0 out (Ἇ _) (by rw[Ἵ];exact H) have R2:=ih (i+1) _ _ א (by rw[v1];exact hb1) (by rw[v1];exact hb2) (D.qA5 R1 (λq _ hq=>by rw[ὰ,Ὑ] at hq;exact hq)) ok rw[show i+(k+1)=i+1+k by omega];exact R2 . rw[ἐ hc] at ok;exact absurd ok (by simp only[false_eq_true,not_false_eq_true]) lemma qRH (rows inW outW:Ὣ) (relu:Ὡ) (X W b:ё): linH rows inW outW relu X W b=Array.ofFn (n:=rows*outW) λq=>linSp inW outW relu X W b q.val:=by have FB:D.linF rows inW outW relu X W b=Array.ofFn (n:=rows*outW) λq=>linSp inW outW relu X W b q.val:=by rw[D.qDz];rfl unfold linH;rw[(D.wnGet inW outW W b).2];dsimp only by_cases h:rows*inW=ѧX/\outW*inW=ѧW/\outW=ѧb/\0< inW/\0 |R (D.dv b[j]!)| <=R (D.dv (D.scanH 1 b)):=λj hj=>by have gj:=(D.qA8 1 b h9 h13).2.2.1 j (by rw[<-h3];exact hj) rw[(D.qAm _ gj).2,Rbm];exact pb2 _ gj (gb4 j (by rw[<-h3];exact hj)) have bb:R (D.dv (D.scanH 1 b))<=2^(290:ℤ):=by rw[Rbm];exact pb1.trans (by rw[show (2:ℝ)^128=2^(128:ℤ) by norm_num];exact ἒ ב ב) rw[hnf,(D.wd8Get inW W).2];dsimp only;by_cases HD:(D.dnOf (D.tZ (D.nE inW W)) (D.qTs (D.qTZ (D.nE inW W))) W).size=ѧW . rw[Ἄ HD] have P0:=D.qZf (8*inW+1) א by_cases hok:(linRg inW (D.nE inW W) outW relu X W b (D.dnOf (D.tZ (D.nE inW W)) (D.qTs (D.qTZ (D.nE inW W))) W) HD (D.qScan W W.usize 0 Е) (D.nfOf inW) (D.dv (D.scanH 1 b)) (ѩinW) (rows/8) 0 (ἇ (rows*outW) 0) (D.zFor (8*inW+1))).ok=true . rw[ἱ hok] have R1:=qRg G HD (D.dv (D.scanH 1 b)) fbm hbm bb (rows/8) 0 _ (D.zFor (8*inW+1)) P0.1 P0.2 א ⟨by simp only[Array.size_replicate],λq _ hq=>absurd hq (by simp only[zero_mul,not_lt_zero,not_false_eq_true])⟩ hok have P1:=D.qZf inW א by_cases hok2:(linRb inW outW relu X W b ((D.wbOf inW outW W,D.scanH 2 W),(D.bOf b,D.scanH 1 b)) (D.nfOf inW) (ѩinW) (rows%8) (rows/8*8) (D.zFor inW) (linRg inW (D.nE inW W) outW relu X W b (D.dnOf (D.tZ (D.nE inW W)) (D.qTs (D.qTZ (D.nE inW W))) W) HD (D.qScan W W.usize 0 Е) (D.nfOf inW) (D.dv (D.scanH 1 b)) (ѩinW) (rows/8) 0 (ἇ (rows*outW) 0) (D.zFor (8*inW+1))).out).ok=true . rw[ἱ hok2] have R2:=qRb G h8k hv fbm hbm bb (rows%8) (rows/8*8) _ _ א P1.1 P1.2 (D.qA5 R1 (λq _ hq=>by rw[Ἇ,ἥ 8 (rows/8)];exact hq)) hok2 rw[show rows/8*8+rows%8=rows by omega] at R2 rw[e];exact D.qBv R2 (λq hq=>hq) . rw[ἐ hok2];exact FB . rw[ἐ hok];exact FB . rw[ἔ HD];exact FB . rw[ἐ h];exact FB lemma qHb2:linG2=linearSpec:=by funext rows inW outW relu X W b;unfold linG2;split . rw[D.qDz] . split . rw[qRH];rfl . rw[qHb] lemma qJj (a b:ѐ) (i r:Ὣ):dallNZ a b i r=dallNZ b a i r:=by induction r generalizing i with | zero=>rfl | succ r ih=>rw[dallNZ,dallNZ,ih (i+1),ἥ (mantOf a[i]!),Bool.xor_comm] lemma qIh (n:Ὣ) (fa fb:Ὣ->ὥ) (hf:∀j,jexpOf (fa j)≠255/\expOf (fb j)≠255):dotOf n fa fb=dotOf n fb fa:=by have hf':∀j,jexpOf (fb j)≠255/\expOf (fa j)≠255:=λj h=>(hf j h).symm;have hs:(∑ j∈Ἣ n,ἂ (fb j)*ἂ (fa j))=∑ j∈Ἣ n,ἂ (fa j)*ἂ (fb j):=Ἷ rfl (λj _=>mul_comm _ _);by_cases hS:(∑ j∈Ἣ n,ἂ (fa j)*ἂ (fb j))=0;. rw[qD6 n fa fb hf hS,qD6 n fb fa hf' (hs.trans hS),qJj] . obtain ⟨d,hd,hw⟩:=qBa n fa fb hf hS;obtain ⟨e,he,hw'⟩:=qBa n fb fa hf' (by rw[hs];exact hS);have t:=@toRat_eq_zero_iff;have h3:d.toRat=e.toRat:=by rw[hd,he,hs] rw[hw,hw',roundDyadic_congr Fmt ה d e (λh=>hS (hd.symm.trans ((t _).2 h))) (λh=>hS (hd.symm.trans (h3.trans ((t _).2 h)))) h3] def gemmC (batch m k n:Ὣ) (A B:ё):ё:= if batch==1&& ѧA==m*k&& ѧB==k*n&&decide (0if tif tif tif tB[t*n+q%n]!) (λt=>A[q/n*k+t]!) h5 (λt _=>⟨qD9 B h7 _,qD9 A h6 _⟩),qIh k _ _ (λt _=>⟨qD9 B h7 _,qD9 A h6 _⟩)];simp only[e1,e2,ὒ,Ἇ] . rfl lemma tDm {a b c d n:Nat} (hb:b (tJ A r c i N hA hN h2 hi j k o ho ek).size=N/\ (∀ja,j.toNat<=ja->ja(tJ A r c i N hA hN h2 hi j k o ho ek)[ja*r.toNat+i.toNat]! =A[i.toNat*c.toNat+ja]!)/\ ∀q,(∀ja,j.toNat<=ja->jaq≠ja*r.toNat+i.toNat)->(tJ A r c i N hA hN h2 hi j k o ho ek)[q]! = o[q]!:=by induction d with | zero=> intro j k o ho ek hd rw[tJ,dif_neg (by rw[А];omega)] exact ⟨ho,λja h1 h2=>א,λ_ _=>rfl⟩ | succ d ih=> intro j k o ho ek hd have h:j?_,λq hq=>?_⟩ · by_cases e:ja=j.toNat · subst e;rw[a3 _ (λjb hb1 hb2 he=>by rw[e1] at hb1;obtain ⟨x,-⟩:=tDm hi hi he;omega),rd,Ὦ rfl] · exact a2 ja (by rw[e1];omega) h3 · rw[a3 q (λjb hb1 hb2=>hq jb (by rw[e1] at hb1;omega) hb2),rd,Ὧ (hq _ (Nat.le_refl _) hj)] def tI (A:ѐ) (r c:ὦ) (N:Nat) (hA:A.size=N) (hN:r.toNat*c.toNat=N) (h2:N<2^32) (i:ὦ) (o:ѐ) (ho:o.size=N):ѐ:= if h:i (tI A r c N hA hN h2 i o ho).size=N/\ (∀ia ja,i.toNat<=ia->iaja(tI A r c N hA hN h2 i o ho)[ja*r.toNat+ia]! =A[ia*c.toNat+ja]!)/\ ∀q,(∀ia ja,i.toNat<=ia->iajaq≠ja*r.toNat+ia)->(tI A r c N hA hN h2 i o ho)[q]! = o[q]!:=by induction d with | zero=> intro i o ho hd rw[tI,dif_neg (by rw[А];omega)] exact ⟨ho,λia ja h1 h3 h4=>א,λ_ _=>rfl⟩ | succ d ih=> intro i o ho hd have h:i?_,λq hq=>?_⟩ · by_cases e:ia=i.toNat · subst e rw[a3 _ (λib jb h5 h6 h7 he=>by rw[e1] at h5;obtain ⟨-,x⟩:=tDm hi h6 he;omega),j2 ja (by simp only[USize.toNat_zero,zero_le]) h4] · exact a2 ia ja (by rw[e1];omega) h3 h4 · rw[a3 q (λib jb h5 h6 h7=>hq ib jb (by rw[e1] at h5;omega) h6 h7),j3 q (λjb h5 h6=>hq i.toNat jb (Nat.le_refl _) hi h6)] @[inline] def trT (r c:Nat) (A:ѐ):ѐ:= if h:A.size=r*c/\r<2^32/\c<2^32/\r*c<2^32 then tI A r.toUSize c.toUSize (r*c) h.1 (by rw[D.qAd r h.2.1,D.qAd c h.2.2.1]) h.2.2.2 0 (ἇ (r*c) 0) (by simp) else A lemma trT_spec (A:ѐ) (r c:Nat) (hA:A.size=r*c) (hN:r*c<2^32) (hr0:0ja(trT r c A)[ja*r+ia]! =A[ia*c+ja]!:=by have h1:=Ὄ r hc have h3:=Nat.le_mul_of_pos_left c hr0 have er:=D.qAd r א have ec:=D.qAd c א unfold trT;rw[dif_pos ⟨hA,א,א,hN⟩] obtain ⟨a1,a2,-⟩:=tI_spec A r.toUSize c.toUSize (r*c) hA (by rw[er,ec]) hN _ 0 (ἇ (r*c) 0) (by simp only[Array.size_replicate]) rfl refine ⟨a1,λia ja h4 h5=>?_⟩ have:=a2 ia ja (by simp only[USize.toNat_zero,zero_le]) (by rw[er];exact h4) (by rw[ec];exact h5) rw[show ja*r+ia=ja*r.toUSize.toNat+ia by rw[er],show ia*c+ja=ia*c.toUSize.toNat+ja by rw[ec]];exact this lemma qGT (m k n:Nat) (A B:ѐ) (hB:B.size=k*n) (hk:0rw[eq,T2 _ _ hc hi] have b1:(q%n*m+q/n)/m=q%n:=by rw[Nat.add_comm,Nat.add_mul_div_right _ _ א,Ὃ hi,Ἇ] have b2:(q%n*m+q/n)%m=q/n:=by rw[Nat.add_comm,Nat.add_mul_mod_self_right,Ἁ hi] have hlt:q%n*m+q/nif tif tif tif tB[t*n+q%n]!) (λt=>A[q/n*k+t]!) hk (λt _=>⟨fB _,fA _⟩),qIh k _ _ (λt _=>⟨fB _,fA _⟩)] lemma oAm (a b m:ὥ) (h:(a ||| b)&&&m=0):b&&&m=0/\a&&&m=0:=by rw[show (a ||| b)&&&m=(a&&&m) ||| (b&&&m) from UInt32.toBitVec_inj.1 (by simp only[UInt32.toBitVec_and,UInt32.toBitVec_or,BitVec.and_or_distrib_right]),UInt32.or_eq_zero_iff] at h;exact ⟨h.2,h.1⟩ def fsc (A:ѐ) (c:ὥ) (i:ὦ) (acc:ὥ):ὥ:= if h:ifsc A c i acc&&&m=0-> acc&&&m=0/\ ∀k,i.toNat<=k->kexpOf A[k]!≠255:=by have hu:=D.qBe A hs induction d with | zero=> intro i acc hd h rw[fsc,dif_neg (by rw[А];omega)] at h exact ⟨h,λk h1 h2=>א⟩ | succ d ih=> intro i acc hd h have hi:i?_⟩ by_cases hk:k=i.toNat · subst hk;intro e;rw[Ἕ A _ h2] at e;simp only[Array.uget] at b1;rw[e] at b1;exact hm b1 · exact a2 k (by rw[e1];omega) h2 lemma fsc_fin (A:ѐ) (c m:ὥ) (hm:(255+c)&&&m≠0) (hs:A.size<2^32) (h:fsc A c 0 0&&&m=0) (t:Nat):expOf A[t]!≠255:=by by_cases ht:tὥ): ∀(count index:Nat) (pos neg:ї) (nz:Ὡ), (∀k,index<=k->k< index+count->expOf (fa k)≠255/\expOf (fb k)≠255)-> (Pinned.dotLoop fa fb pos neg false nz index count).special=false | 0,_,_,_,_,_=>by simp only[Pinned.dotLoop] | count+1,index,pos,neg,nz,hfin=>by have h:=hfin index le_rfl א simp only[Pinned.dotLoop] have hstep:(Pinned.dotStep ⟨pos,neg,false,nz⟩ (fa index) (fb index)).special=false:=by unfold Pinned.dotStep rw[Ὧ (by push_neg;exact h)] simp only[Pinned.Acc.add] split_ifs<;>rfl generalize Pinned.dotStep ⟨pos,neg,false,nz⟩ (fa index) (fb index)=acc at hstep obtain ⟨p,n,sp,z⟩:=acc simp only at hstep subst hstep exact dotLoop_special_false fa fb count (index+1) p n z (λk h1 h2=>hfin k א א) lemma dotFn_finite (n:Nat) (fa fb:Nat->ὥ) (hfin: ∀k,kexpOf (fa k)≠255/\expOf (fb k)≠255): Pinned.dotFn n fa fb= finishWord (dsum (Array.ofFn (n:=n) λi=>fa i) (Array.ofFn (n:=n) λi=>fb i) 0 n) (-298) (n≠0&&dallNZ (Array.ofFn (n:=n) λi=>fa i) (Array.ofFn (n:=n) λi=>fb i) 0 n):=by unfold Pinned.dotFn have hsp:=dotLoop_special_false fa fb n 0 (ἇ 18 0) (ἇ 18 0) true (λk _ hk=>hfin k א) obtain ⟨-,-,hD,hz⟩:=Pinned.dotLoopFacts fa fb (Array.ofFn (n:=n) λi=>fa i) (Array.ofFn (n:=n) λi=>fb i) n (Pinned.getElem!_ofFn n fa) (Pinned.getElem!_ofFn n fb) Pinned.Acc.empty 0 n א (by simp only[Pinned.Acc.empty,Array.size_replicate]) (by simp only[Pinned.Acc.empty,Array.size_replicate]) hsp simp only[Pinned.Acc.empty] at hD hz hsp simp only[hsp,Bool.false_eq_true,ite_false] rw[Pinned.finishFast_eq] change finishWord (Pinned.Acc.total _) _ _=_ have h0:(⟨ἇ 18 0,ἇ 18 0,false,true⟩:Pinned.Acc).total=0:= Pinned.Acc.total_empty rw[hD,hz,h0] simp only[zero_add,Int.reduceNeg,ne_eq,decide_not,Bool.true_and] lemma qEcP (n:Nat) (fa fb:Nat->ὥ) (hf: ∀j,jexpOf (fa j)≠255/\expOf (fb j)≠255) (hn:(∑ j∈Ἣ n,rationalWord (fa j)*rationalWord (fb j))≠0): ∃d:FloatLib.Numerics.Dyadic, d.toRat=(∑ j∈Ἣ n,rationalWord (fa j)*rationalWord (fb j))/\ Pinned.dotFn n fa fb=toWord (Model.roundDyadic Fmt d):=by let a:=Array.ofFn (n:=n) λi=>fa i let b:=Array.ofFn (n:=n) λi=>fb i have c:(dsum a b 0 n:ℚ)*2^(-298:Int)= ∑ j∈Ἣ n,rationalWord (fa j)*rationalWord (fb j):=by rw[qEl] refine Ἷ rfl λj m=>?_ have h:=Finset.mem_range.mp m rw[Ἇ,qAb n fa j h,qAb n fb j h] have l:dsum a b 0 n≠0:= λh=>hn (by rw[<-c,h];simp only[Int.cast_zero,Int.reduceNeg,zpow_neg,zpow_ofNat,zero_mul]) refine ⟨ofIntDyadic (dsum a b 0 n) (-298),by rw[toRat_ofIntDyadic,c],?_⟩ rw[dotFn_finite n fa fb hf] exact finishWord_of_ne _ _ _ _ l (toRat_ofIntDyadic _ _) /-! -/ /-! -/ section RnnK @[inline] def stp (acc:F1) (q:ὧ):F1:=⟨acc.s+q,acc.t+q.abs⟩ @[specialize] def fpush (f:Nat->ὧ):Nat->Nat->ὤ->ὤ | _,0,a=>a | i,k+1,a=>fpush f (i+1) k (a.push (f i)) @[specialize] def allLt (f:Nat->Ὡ):Nat->Ὡ | 0=>true | k+1=>f k&&allLt f k @[specialize] def build2 (f:Nat->Word×Word):Nat->Nat->ё->ё-> ё×ё | _,0,a,b=>(a,b) | k,n+1,a,b=> let p:=f k build2 f (k+1) n (a.push p.1) (b.push p.2) @[specialize] def rowsB (row:Nat->ὤ->ὤ):Nat->Nat->ὤ->ὤ | _,0,acc=>acc | r,n+1,acc=>rowsB row (r+1) n (row r acc) @[specialize] def recFlat (step:Nat->ё×ё->ё×ё): Nat->Nat->ё×ё->ё->ё | _,0,_,out=>out | t,n+1,st,out=> let st':=step t st recFlat step (t+1) n st' (out++st'.1) def zF0:ὧ:=0 def zFd:ὧ:=dv 0 def nfG1:ὧ:=nfOf 1 def nfG2:ὧ:=nfOf 2 def nfG3:ὧ:=nfOf 3 def oneD:ὧ:=dv oneW def zFa:ὧ:=zFd.abs @[noinline] def cellSlow (f i c g:Word):Word:= Pinned.dotFn 2 (λj=>if j=0 then f else i) (λj=>if j=0 then c else g) @[inline] def cellF (f i c g:Word):Word:= if good f&&good i&&good c&&good g then let r:=stp (stp ⟨zF0,zF0⟩ (dv f*dv c)) (dv i*dv g) let z:=zFd let w:=ziv (r.s+z) (nfG2*(r.t+zFa)) if w==Е then cellSlow f i c g else w else cellSlow f i c g @[inline] def small (w:Word):Ὡ:=(w&&&В)<0x40000000 @[noinline] def mulSlow (o t:Word):Word:=toWord (Model.mul (ofW o) (ofW t)) @[inline] def mulF (o t:Word):Word:= if good o&&good t&&small o&&small t then let r:=stp ⟨zF0,zF0⟩ (dv o*dv t) let z:=zFd let w:=ziv (r.s+z) (nfG1*(r.t+zFa)) if w==Е then mulSlow o t else w else mulSlow o t @[noinline] def candSlow (inW H:Nat) (x wih bih:ё) (t u:Nat) (hu ru:Word):Word:= Pinned.dotFn (inW+2) (λj=>if j< inW then x[t*inW+j]! else if j=inW then oneW else hu) (λj=>if j< inW then wih[(2*H+u)*inW+j]! else if j=inW then bih[2*H+u]! else ru) @[noinline] def upd3Slow (nu zu hu:Word):Word:= Pinned.dotFn 3 (λj=>if j=2 then hu else nu) (λj=>if j=0 then oneW else if j=1 then negW zu else zu) @[inline] def updF (nu zu hu:Word):Word:= if good nu&&good zu&&good hu&&good (negW zu) then let r:=stp (stp (stp ⟨zF0,zF0⟩ (dv nu*oneD)) (dv nu*dv (negW zu))) (dv hu*dv zu) let z:=zFd let w:=ziv (r.s+z) (nfG3*(r.t+zFa)) if w==Е then upd3Slow nu zu hu else w else upd3Slow nu zu hu end RnnK section RnnP lemma fa_push_get (a:ὤ) (v:ὧ) (j:Nat): (a.push v).get! j=if jὧ): ∀(i k:Nat) (a:ὤ),(fpush f i k a).size=a.size+k | _,0,_=>rfl | i,k+1,a=>by rw[fpush,fpush_size f (i+1) k,fa_push_size];omega lemma fpush_get (f:Nat->ὧ): ∀(i k:Nat) (a:ὤ) (j:Nat), (j(fpush f i k a).get! j=a.get! j)/\ (a.size<=j->j(fpush f i k a).get! j=f (i+(j-a.size))) | _,0,a,j=>⟨λ_=>rfl, λh1 h2=>א⟩ | i,k+1,a,j=>by obtain ⟨ih1,ih2⟩:=fpush_get f (i+1) k (a.push (f i)) j rw[fa_push_size] at ih1 ih2 refine ⟨λh=>?_, λh1 h2=>?_⟩ · rw[fpush,ih1 א,fa_push_get,Ὦ h] · rw[fpush] by_cases hj:j=a.size · subst hj rw[ih1 א,fa_push_get,Ὧ א,Ὦ rfl];simp only[tsub_self,add_zero] · rw[ih2 א א];congr 1;omega lemma foldl_stp_congr (g g':Nat->ὧ): ∀(l:љ) (acc:F1), (∀t∈l,g t=g' t)-> l.foldl (λacc t=>stp acc (g t)) acc=l.foldl (λacc t=>stp acc (g' t)) acc:= λ_ _ h=>List.foldl_ext _ _ _ λ_ t ht=>by rw[h t ht] lemma allLt_spec (f:Nat->Ὡ): ∀n,allLt f n=true-> ∀j,jf j=true | 0,_,j,hj=>א | n+1,h,j,hj=>by simp only[allLt,Bool.and_eq_true] at h rcases Nat.lt_succ_iff_lt_or_eq.mp hj with hj | hj · exact allLt_spec f n h.2 j hj · subst hj;exact h.1 lemma good_zero:good 0=true:=ה lemma good_one:good oneW=true:=ה lemma all_good (a:ё) (h:a.all good=true) (i:Nat):good a[i]! =true:=by by_cases hi:iWord) (hx: ∀t,tgood (fa t)=true) (hw: ∀t,tgood (fb t)=true) (g:Nat->ὧ) (hg: ∀t,tg t=dv (fa t)*dv (fb t)) (h:ziv (((ἄ N).foldl (λacc t=>stp acc (g t)) ⟨0,0⟩).s+dv 0) (nfOf N*(((ἄ N).foldl (λacc t=>stp acc (g t)) ⟨0,0⟩).t+(dv 0).abs))≠Е): ziv (((ἄ N).foldl (λacc t=>stp acc (g t)) ⟨0,0⟩).s+dv 0) (nfOf N*(((ἄ N).foldl (λacc t=>stp acc (g t)) ⟨0,0⟩).t+(dv 0).abs))= Pinned.dotFn N fa fb:=by have hr:(ἄ N).foldl (λacc t=>stp acc (g t)) ⟨0,0⟩= (ἄ N).foldl (λacc t=>stp acc (dv (fa t)*dv (fb t))) ⟨0,0⟩:= foldl_stp_congr _ _ _ _ λt ht=>hg t (List.mem_range.mp ht) rw[hr] at h⊢ obtain ⟨-,-,hbig⟩:=qBw _ _ h obtain ⟨hlo,hhi⟩:=qDm N hN fa fb 0 hx hw good_zero (ἄ N) Ὂ (λt ht=>List.mem_range.mp ht) (λt ht hn=>absurd (List.mem_range.mpr ht) hn) _ _ ⟨rfl,rfl⟩ hbig have hsum:((∑ j∈Ἣ N,rationalWord (fa j)*rationalWord (fb j):ℚ):ℝ)=exactS N fa fb 0:=by rw[Rat.cast_sum,exactS,qAx 0 (qAe _ good_zero),rat_zero,Rat.cast_zero,add_zero] refine Ἷ rfl λt ht=>?_ have a:=Finset.mem_range.mp ht rw[qAx _ (qAe _ (hx t a)),qAx _ (qAe _ (hw t a)),Rat.cast_mul] have hne:(∑ j∈Ἣ N,rationalWord (fa j)*rationalWord (fb j))≠0:= λh0=> qG5 _ _ _ hlo hhi h (by rw[<-hsum,h0,Rat.cast_zero]) obtain ⟨d,hd,hD⟩:=qEcP N fa fb (λj hj=>⟨qAe _ (hx j hj),qAe _ (hw j hj)⟩) hne rw[hD] exact qIq _ _ d (by rw[hd,hsum];exact hlo) (by rw[hd,hsum];exact hhi) h lemma small_le (w:Word) (hg:good w=true) (hs:small w=true): |wv w| <=2:=by have h1:=qB5 w hg have hq:=qAq w have hlt:(w&&&В).toNat<2^30:=by have:(w&&&В)<0x40000000:=by simpa only[small,decide_eq_true_eq] using hs exact (UInt32.lt_iff_toNat_lt.mp this) rw[hq] at hlt rw[h1] have h2:=qA6 (w.toNat%2^31) (2^30) hlt.le (by rcases qAz w hg with h | h<;>omega) refine h2.trans (le_of_eq ?_) norm_num[A_mag] lemma posMax32:(4:ℝ)<=Model.toReal (Model.posMaxFinite Fmt):=by rw[Model.toReal_posMaxFinite,show Model.pow2 Fmt.fracWidth+Fmt.maxFiniteFracField=2^24-1 by decide+kernel,show Fmt.maxNormalExponent-Int.ofNat Fmt.fracWidth=104 by decide+kernel, Model.bpow,qA0] norm_num lemma fastMul (o t:Word) (ho:good o=true) (ht:good t=true) (so:small o=true) (st:small t=true) (h:ziv ((stp ⟨0,0⟩ (dv o*dv t)).s+dv 0) (nfOf 1*((stp ⟨0,0⟩ (dv o*dv t)).t+(dv 0).abs))≠Е): ziv ((stp ⟨0,0⟩ (dv o*dv t)).s+dv 0) (nfOf 1*((stp ⟨0,0⟩ (dv o*dv t)).t+(dv 0).abs))= toWord (Model.mul (ofW o) (ofW t)):=by have hl:(ἄ 1).foldl (λacc j=>stp acc (dv ((λ_=>o) j)*dv ((λ_=>t) j))) ⟨0,0⟩= stp ⟨0,0⟩ (dv o*dv t):=by simp only[List.range_one,ὔ,List.foldl_nil] rw[<-hl] at h⊢ obtain ⟨-,-,hbig⟩:=qBw _ _ h obtain ⟨hlo,hhi⟩:=qDm 1 ב (λ_=>o) (λ_=>t) 0 (λ_ _=>ho) (λ_ _=>ht) good_zero (ἄ 1) Ὂ (λt ht=>List.mem_range.mp ht) (λt ht hn=>absurd (List.mem_range.mpr ht) hn) _ _ ⟨rfl,rfl⟩ hbig have hv:exactS 1 (λ_=>o) (λ_=>t) 0=Model.toReal (ofW o)*Model.toReal (ofW t):=by have h0:Model.toReal (ofW 0)=0:=by have:=qAx 0 (qAe _ good_zero) rw[wv] at this;rw[this,rat_zero,Rat.cast_zero] simp only[exactS,Finset.range_one,wv,Finset.sum_const,Finset.card_singleton,one_smul,h0,add_zero] rw[hv] at hlo hhi have hfo:=fin_ofW (qAe _ ho) have hft:=fin_ofW (qAe _ ht) have hbound: |Model.toReal (ofW o)| * |Model.toReal (ofW t)| <=Model.toReal (Model.posMaxFinite Fmt):=by have a:=small_le o ho so have b:=small_le t ht st simp only[wv] at a b exact ὂ (ἑ a b (Ἀ _) zero_le_two) (ὂ (le_of_eq ב) posMax32) have hf:=Model.isFinite_mul_of_abs_mul_le_posMaxFinite (ofW o) (ofW t) ה hfo hft hbound have hM:=Model.toReal_mul_eq_roundAt_of_abs_mul_le_posMaxFinite (ofW o) (ofW t) ה hfo hft hbound exact (qDq _ _ _ hlo hhi h _ hf hM).symm lemma ofFn_get! (n:Nat) (g:Nat->Word) (i:Nat) (h:ig j.val)[i]! =g i:=by rw[Ἕ _ i (by simpa only[Array.size_ofFn] using h),Array.getElem_ofFn] lemma push_ofFnA {α:Type} (g:Nat->α) (k:Nat): (Array.ofFn (n:=k) λi=>g i.val).push (g k)=Array.ofFn (n:=k+1) λi=>g i.val:=by apply Մ · simp only[Array.size_push,Array.size_ofFn,Nat.add_left_cancel_iff] · intro i h1 h2 simp only[Array.size_push,Array.size_ofFn] at h1 rw[Array.getElem_ofFn] by_cases hi:iα) (i:Nat) (h:ig j.val)[i]! =g i:=by rw[Ἕ _ i (by simpa only[Array.size_ofFn] using h),Array.getElem_ofFn] lemma ofFn_get!F {α:Type} [Inhabited α] {n:Nat} (f:Fin n->α) (i:Nat) (h:iWord×Word): ∀(n k:Nat) (a b:ё), a=Array.ofFn (n:=k) (λi=>(f i.val).1)->b=Array.ofFn (n:=k) (λi=>(f i.val).2)-> build2 f k n a b= (Array.ofFn (n:=k+n) (λi=>(f i.val).1),Array.ofFn (n:=k+n) (λi=>(f i.val).2)) | 0,k,a,b,ha,hb=>by rw[build2,ha,hb];rfl | n+1,k,a,b,ha,hb=>by rw[build2] try dsimp only rw[build2_spec f n (k+1) _ _ (by rw[ha];exact push_ofFnA (λi=>(f i).1) k) (by rw[hb];exact push_ofFnA (λi=>(f i).2) k),show k+1+n=k+(n+1) by omega] lemma build2_zero (f:Nat->Word×Word) (n c:Nat): build2 f 0 n (Array.emptyWithCapacity c) (Array.emptyWithCapacity c)= (Array.ofFn (n:=n) (λi=>(f i.val).1),Array.ofFn (n:=n) (λi=>(f i.val).2)):=by rw[build2_spec f n 0 _ _ (by simp only[Array.emptyWithCapacity_eq,Array.ofFn_zero]) (by simp only[Array.emptyWithCapacity_eq,Array.ofFn_zero]),Ἇ] lemma rowsB_spec (N:Nat) (row:Nat->ὤ->ὤ) (g:Nat->Nat->ὧ) (hsz: ∀r acc,(row r acc).size=acc.size+N) (hold: ∀r acc j,j(row r acc).get! j=acc.get! j) (hnew: ∀r acc j,j(row r acc).get! (acc.size+j)=g r j): ∀(n r:Nat) (acc:ὤ),acc.size=r*N-> (∀r' j,r'jacc.get! (r'*N+j)=g r' j)-> (rowsB row r n acc).size=(r+n)*N/\ ∀r' j,r'j(rowsB row r n acc).get! (r'*N+j)=g r' j | 0,r,acc,hs,hg=>by rw[rowsB,Ἵ];exact ⟨hs,hg⟩ | n+1,r,acc,hs,hg=>by rw[rowsB] have:=rowsB_spec N row g hsz hold hnew n (r+1) (row r acc) (by rw[hsz,hs,ὰ,Ὑ]) (λr' j hr hj=>by rcases Nat.lt_succ_iff_lt_or_eq.mp hr with hr | hr · have hlt:r'*N+jё×ё->ё×ё) (iniS:ё×ё): Nat->ё×ё | 0=>iniS | t+1=>step t (traj step iniS t) lemma foldl_traj (step:Nat->ё×ё->ё×ё) (iniS:ё×ё): ∀T,(ἄ T).foldl (λ(acc:(ё×ё)×Array (ё)) t=> let st:=step t acc.1 (st,acc.2.push st.1)) (iniS, #[])= (traj step iniS T,Array.ofFn (n:=T) λt=>(traj step iniS (t.val+1)).1) | 0=>by simp only[List.range_zero,List.foldl_nil,traj,Array.ofFn_zero] | T+1=>by rw[List.range_succ,List.foldl_append,foldl_traj step iniS T] simp only[ὔ,List.foldl_nil] rw[show step T (traj step iniS T)=traj step iniS (T+1) from rfl, push_ofFnA (λt=>(traj step iniS (t+1)).1) T] lemma divH (q t H:Nat) (h1:t*H<=q) (h2:q<(t+1)*H):q/H=t/\q%H=q-t*H:=by have hH:0ё×ё->ё×ё) (iniS:ё×ё) (H:Nat) (hsz: ∀t st,(step t st).1.size=H): ∀(n t:Nat) (out:ё), out=Array.ofFn (n:=t*H) (λq=>(traj step iniS (q.val/H+1)).1[q.val%H]!)-> recFlat step t n (traj step iniS t) out= Array.ofFn (n:=(t+n)*H) (λq=>(traj step iniS (q.val/H+1)).1[q.val%H]!) | 0,t,out,ho=>by rw[recFlat,ho,Ἵ] | n+1,t,out,ho=>by rw[recFlat] try dsimp only rw[show step t (traj step iniS t)=traj step iniS (t+1) from rfl] rw[recFlat_traj step iniS H hsz n (t+1) _ ?_,show t+1+n=t+(n+1) by omega] rw[ho] have hs:(traj step iniS (t+1)).1.size=H:=hsz _ _ apply Մ · simp only[Array.size_append,Array.size_ofFn,hs,ὰ,one_mul,Nat.add_left_cancel_iff] · intro q h1 h2 simp only[Array.size_append,Array.size_ofFn,hs] at h1 rw[Array.getElem_ofFn] by_cases hq:qё×ё->ё×ё) (iniS:ё×ё) (hsz: ∀t st,(step t st).1.size=H): recFlat step 0 T iniS (Array.emptyWithCapacity (T*H))=recurWith T H step iniS:=by have:=recFlat_traj step iniS H hsz T 0 (Array.emptyWithCapacity (T*H)) (by simp only[Array.emptyWithCapacity_eq,Array.empty_eq,Array.ofFn_eq_empty_iff,zero_mul]) rw[show traj step iniS 0=iniS from rfl,Ἇ] at this rw[this,recurWith] simp only[foldl_traj] congr 1 funext q have hq:q.val/H(traj step iniS (t+1)).1) _ hq] end RnnP section RnnS lemma cellF_eq (f i c g:Word): cellF f i c g=Pinned.dotFn 2 (λj=>if j=0 then f else i) (λj=>if j=0 then c else g):=by unfold cellF cellSlow zFa zF0 zFd nfG2 simp only[] split_ifs with hg hw · rfl · rw[beq_iff_eq] at hw simp only[Bool.and_eq_true] at hg obtain ⟨⟨⟨h1,h2⟩,h3⟩,h4⟩:=hg have hl:(ἄ 2).foldl (λacc j=>stp acc (dv ((λj=>if j=0 then f else i) j)* dv ((λj=>if j=0 then c else g) j))) ⟨0,0⟩=stp (stp ⟨0,0⟩ (dv f*dv c)) (dv i*dv g):=by simp only[List.range_succ,List.range_zero,List.nil_append,List.cons_append,ὔ, ↓reduceIte,one_ne_zero,List.foldl_nil] rw[<-hl] at hw⊢ exact fastNB 2 ה _ _ (λj hj=>by rcases (by omega:j=0\/j=1) with rfl | rfl<;>simp only[↓reduceIte,h1,one_ne_zero,h2]) (λj hj=>by rcases (by omega:j=0\/j=1) with rfl | rfl<;>simp only[↓reduceIte,h3,one_ne_zero,h4]) _ (λ_ _=>rfl) hw · rfl lemma mulF_eq (o t:Word):mulF o t=toWord (Model.mul (ofW o) (ofW t)):=by unfold mulF mulSlow zFa zF0 zFd nfG1 simp only[] split_ifs with hg hw · rfl · rw[beq_iff_eq] at hw simp only[Bool.and_eq_true] at hg obtain ⟨⟨⟨h1,h2⟩,h3⟩,h4⟩:=hg exact fastMul o t h1 h2 h3 h4 hw · rfl lemma updF_eq (nu zu hu:Word): updF nu zu hu=Pinned.dotFn 3 (λj=>if j=2 then hu else nu) (λj=>if j=0 then oneW else if j=1 then negW zu else zu):=by unfold updF upd3Slow zFa zF0 zFd nfG3 oneD simp only[] split_ifs with hg hw · rfl · rw[beq_iff_eq] at hw simp only[Bool.and_eq_true] at hg obtain ⟨⟨⟨h1,h2⟩,h3⟩,h4⟩:=hg have hl:(ἄ 3).foldl (λacc j=>stp acc (dv ((λj=>if j=2 then hu else nu) j)* dv ((λj=>if j=0 then oneW else if j=1 then negW zu else zu) j))) ⟨0,0⟩= stp (stp (stp ⟨0,0⟩ (dv nu*dv oneW)) (dv nu*dv (negW zu))) (dv hu*dv zu):=by simp only[List.range_succ,List.range_zero,List.nil_append,List.cons_append,ὔ,OfNat.zero_ne_ofNat, ↓reduceIte,OfNat.one_ne_ofNat,one_ne_zero,OfNat.ofNat_ne_zero,OfNat.ofNat_ne_one,List.foldl_nil] rw[<-hl] at hw⊢ exact fastNB 3 ה _ _ (λj hj=>by rcases (by omega:j=0\/j=1\/j=2) with rfl | rfl | rfl<;>simp only[OfNat.zero_ne_ofNat, ↓reduceIte,h1,OfNat.one_ne_ofNat,h3]) (λj hj=>by rcases (by omega:j=0\/j=1\/j=2) with rfl | rfl | rfl<;>simp only[↓reduceIte,good_one,one_ne_zero,h4,OfNat.ofNat_ne_zero,OfNat.ofNat_ne_one,h2]) _ (λ_ _=>rfl) hw · rfl end RnnS section RnnT lemma stepIdx4 (H u:Nat) (hu:unone | some e1=> let t:=(mulDn e1.1 e1.1,min one (mulUp e1.2 e1.2)) if d.negative then match divLo t.1 (one+t.1),divHi t.2 (one+t.2) with | some ql,some qh=>settle false ql qh | _,_=>none else none open FastAct in lemma sigmoidFastX_spec {w a:ὥ} (h:sigmoidFastX w=some a):sigmoidCR w=a:=by unfold sigmoidFastX at h split at h · simp only[reduceCtorEq] at h rename_i hfin dsimp only at h have hx:=toReal_ofW_decode hfin generalize decodeD w=d at h hx have hspec:=(toReal_sigmoidModel (fmt:=Fmt) ה (input:=Model.ofUInt32 w) (by simp only[isFinite_ofUInt32,bne_iff_ne,ne_eq,hfin,not_false_eq_true])).2 change Model.toReal (sigmoidModel (ofW w))=Model.roundAt Fmt (realSigmoid (Model.toReal (ofW w))) at hspec rw[hx] at hspec change toWord (sigmoidModel (ofW w))=a split at h · simp only[reduceCtorEq] at h rename_i e1 he1 have hE1:=expNeg_spec he1 set C:=(d.significand:ℝ)*(2:ℝ)^d.exponent have hE:=hE1.mul hE1 have hC:(d.significand:ℝ)*(2:ℝ)^(d.exponent-1)+ (d.significand:ℝ)*(2:ℝ)^(d.exponent-1)=C:=by simp only[C];rw[ᾂ ἓ,zpow_one];ring rw[hC] at hE set T:=Real.exp (-C) have hT:0a | none=>FastAct.sigmoidF w @[noinline] def tanhF9 (w:ὥ):ὥ:=FastAct.tanhF w lemma sigmoidF9_eq (w:ὥ):sigmoidF9 w=sigmoidCR w:=by unfold sigmoidF9 cases h:sigmoidFastX w with | some a=>exact (sigmoidFastX_spec h).symm | none=>exact congrFun FastAct.sigmoidF_eq w lemma tanhF9_eq (w:ὥ):tanhF9 w=tanhCR w:=by unfold tanhF9;exact congrFun FastAct.tanhF_eq w end ActF /-! -/ section ActG def enclK (k:Nat):Nat×Nat:= let n:=k/64 let F:=FastAct.fracTab[k%64]! let I:=if n<=16 then FastAct.intTab[n]! else (FastAct.mulDn FastAct.intTab[16]!.1 FastAct.intTab[n-16]!.1, min FastAct.one (FastAct.mulUp FastAct.intTab[16]!.2 FastAct.intTab[n-16]!.2)) (FastAct.mulDn I.1 F.1,min FastAct.one (FastAct.mulUp I.2 F.2)) def toF62 (lo:Nat):ὧ:= let sh:=lo.log2-52 (lo>>>sh).toUInt64.toFloat*D.pwEntry (88+sh) def expTabG:ὤ:=⟨Array.ofFn (n:=1280) λk=>toF62 (enclK k.val).1⟩ def tabOK:Ὡ:=(ἄ 1280).all λk=> let e:=enclK k decide (e.2-e.1<=2^14)&&(decide (1088<=k) || decide ((e.2-e.1)*2^36<=e.1)) def oneG:ὧ:=(1:Ὠ).toFloat def halfG:ὧ:=oneG/(2:Ὠ).toFloat def c6G:ὧ:=oneG/(6:Ὠ).toFloat def c24G:ὧ:=oneG/(24:Ὠ).toFloat def c120G:ὧ:=oneG/(120:Ὠ).toFloat def m34G:ὧ:=D.pwEntry 116 def m41G:ὧ:=D.pwEntry 109 def m26G:ὧ:=D.pwEntry 124 def negOneG:ὧ:=0-oneG def loA:Ὠ:=D.loOf m41G def spA:Ὠ:=D.spOf loA def e0G:ὧ:=m34G*m34G def lo0:Ὠ:=D.loOf e0G def sp0:Ὠ:=D.spOf lo0 @[inline] def zA (lo sp:Ὠ) (q e:ὧ):ὥ:= let r:=D.fin1 lo sp q if r==Е then D.ziv q e else r @[inline] def polyG (r:ὧ):ὧ:= let r2:=r*r (oneG-r)+r2*((halfG-r*c6G)+r2*(c24G-r*c120G)) lemma tabG_size:expTabG.size=1280:=by simp only[FloatArray.size,expTabG,Array.size_ofFn] lemma kidx {k b:ὥ} (h:k>>23).toUSize.toNat>>sOfG F @[inline] def rOfG (m F:ὥ) (h:F.toUSize.toNat>>23 if F-1<131 then let m:=(a&&&0x7FFFFF) ||| 0x800000 if w<س then if h:kOfG m F<1216 then let t:=tOfG m F (eidx a) (kLt h (by decide)) let q:=oneG/(oneG+t) zA loA spA q m41G else ziv oneG m26G else if h:kOfG m F<1088 then let t:=tOfG m F (eidx a) (kLt h (by decide)) let q:=t/(oneG+t) zA lo0 sp0 q (q*m34G) else Е else if 131>>23 if F-2<131 then let m:=(a&&&0x7FFFFF) ||| 0x800000 if h:kOfG m F<1280 then let t:=tOfG m F (eidx _) h let q:=(if w<س then oneG-t else t-oneG)/(oneG+t) zA loA spA q m41G else ziv (if w<س then oneG else negOneG) m26G else if 132rfl | true=>exact absurd (Model.toReal_eq_zero_of_isZero _ h) hy0 have hB: |Model.toReal (D.A_M x)/Model.toReal (D.A_M y)| <=Model.toReal (Model.posMaxFinite ⟡):= have h1:=ὂ (by linarith only[gAB]:D.A_B<=D.A_B*2) D.qE3 hb.trans (h1.trans D.qCd) exact D.qFc (D.A_E _ (toModel_ofFloat_div_of_isFinite x y hx hy) (Model.isFinite_div_of_abs_div_le_posMaxFinite _ _ D.qAj (D.qA3 hx) (D.qA3 hy) hz hB) (Model.toReal_div_eq_roundAt_of_abs_div_le_posMaxFinite _ _ D.qAj (D.qA3 hx) (D.qA3 hy) hz hB)) end GTool section GTool2 lemma gAp_div {x y:ὧ} {X Y ε δ M m:ℝ} (hx:gAp x X ε) (hy:gAp y Y δ) (hX: |X| <=M) (hm:m<=Y) (hδ:δ< m) (hq:(M+ε)/(m-δ)<=2^100): gAp (x/y) (X/Y) (ε/(m-δ)+M*δ/((m-δ)*m)+1/2^53*((M+ε)/(m-δ))+1/2^153):=by have h1:=hx.absR have e0:0<=ε:=(Ἀ _).trans hx.2 have d0:0<=δ:=(Ἀ _).trans hy.2 have hmd:0< m-δ:=by linarith only[hδ] have hm0:0< m:=by linarith only[hδ,d0] have hY0:0linarith only[h1,h0] have m6:=(gAp_mul hr gC6 hρ (by norm_num: |(1:ℝ)/6| <=1/6) ב ב).mono (show _<=(1:ℝ)/2^60 by norm_num) have bm6: |ρ*(1/6)| <=1/384:=by rw[ἢ,ἅ h0];norm_num;linarith only[h1] have b:=(gAp_sub gHalf m6 (by norm_num: |(1:ℝ)/2| <=1/2) bm6 ב ב).mono (show _<=(1:ℝ)/2^52 by norm_num) have bb: |1/2-ρ*(1/6)| <=1/2:=by rw[ὸ];constructor<;>linarith only[h1,h0] have m120:=(gAp_mul hr gC120 hρ (by norm_num: |(1:ℝ)/120| <=1/120) ב ב).mono (show _<=(1:ℝ)/2^64 by norm_num) have bm120: |ρ*(1/120)| <=1/7680:=by rw[ἢ,ἅ h0];norm_num;linarith only[h1] have c:=(gAp_sub gC24 m120 (by norm_num: |(1:ℝ)/24| <=1/24) bm120 ב ב).mono (show _<=(1:ℝ)/2^56 by norm_num) have bc: |1/24-ρ*(1/120)| <=1/24:=by rw[ὸ];constructor<;>linarith only[h1,h0] have rc:=(gAp_mul r2 c b2 bc ב ב).mono (show _<=(1:ℝ)/2^60 by norm_num) have brc: |ρ*ρ*(1/24-ρ*(1/120))| <=1/98304:=by rw[ἢ] calc |ρ*ρ| * |1/24-ρ*(1/120)| <=(1/4096)*(1/24):= ἑ b2 bc (Ἀ _) ב _=1/98304:=ב have s:=(gAp_add b rc bb brc ב ב).mono (show _<=(1:ℝ)/2^51 by norm_num) have bs: |1/2-ρ*(1/6)+ρ*ρ*(1/24-ρ*(1/120))| <=1:=by have:=Ἐ (1/2-ρ*(1/6)) (ρ*ρ*(1/24-ρ*(1/120))) linarith only[bb,brc,this] have rs:=(gAp_mul r2 s b2 bs ב ב).mono (show _<=(1:ℝ)/2^59 by norm_num) have brs: |ρ*ρ*(1/2-ρ*(1/6)+ρ*ρ*(1/24-ρ*(1/120)))| <=1/4096:=by rw[ἢ] calc |ρ*ρ| * |1/2-ρ*(1/6)+ρ*ρ*(1/24-ρ*(1/120))| <=(1/4096)*1:= ἑ b2 bs (Ἀ _) ב _=1/4096:=ב have p:=(gAp_add a rs ba brs ב ב).mono (show _<=(1:ℝ)/2^51 by norm_num) refine ⟨p.1,?_⟩ have hT:=exp_neg_taylor5 h0 (by linarith only[h1]) have h6:ρ^6<=(1/64)^6:=Ἳ h0 h1 6 have eq:1-ρ+ρ*ρ*(1/2-ρ*(1/6)+ρ*ρ*(1/24-ρ*(1/120)))= 1-ρ*(1-ρ*(1/2-ρ*(1/6-ρ*(1/24-ρ*(1/120))))):=by ring have e2:D.R (polyG r)=D.R ((oneG-r)+r*r*((halfG-r*c6G)+r*r*(c24G-r*c120G))):=rfl have hp:=p.2 rw[<-e2,eq] at hp have:=abs_sub_le (D.R (polyG r)) (1-ρ*(1-ρ*(1/2-ρ*(1/6-ρ*(1/24-ρ*(1/120)))))) (Real.exp (-ρ)) rw[ἣ (1-_) (Real.exp _)] at this have h7:=ἀ h6 (by norm_num:(0:ℝ)<=7/4320) have h8:(1/2^51:ℝ)+(1/64)^6*(7/4320)<=1/2^45:=ב linarith only[hT,h6,hp,this] end GPoly section GTab lemma gPw (i:Nat) (h0:0< i) (h1:i<256): (D.pwEntry i).isFinite=true/\D.R (D.pwEntry i)=(2:ℝ)^((i:ℤ)-150):=by obtain ⟨f,e⟩:=D.qDa i א refine ⟨f,?_⟩ rw[e,Ὧ א,Ὧ א,Ἁ h1,one_mul] lemma toF62_spec (lo:Nat) (h:lo<=2^62): (toF62 lo).isFinite=true/\D.R (toF62 lo)<=FastAct.V lo/\ FastAct.V lo-D.R (toF62 lo)<=FastAct.V lo/2^52:=by unfold toF62 generalize hsh:lo.log2-52=sh have hL:lo.log2<=62:=by rcases Nat.eq_zero_or_pos lo with h0 | h0 · subst h0;simp only[Nat.log2_zero,zero_le] · exact Nat.lt_succ_iff.mp ((Nat.log2_lt h0.ne').mpr (ἷ h ב)) have hsh10:sh<=10:=א have hq:lo>>>sh=lo/2^sh:=Ἱ lo sh have hlt:=(Nat.lt_log2_self (n:=lo)) have hq53:lo/2^sh<2^53:=by rw[Nat.div_lt_iff_lt_mul ו,<-pow_add] exact Ἥ hlt (Nat.pow_le_pow_right ב א) have hqu:(lo>>>sh).toUInt64.toNat=lo/2^sh:=by rw[hq,Nat.toUInt64,UInt64.toNat_ofNat'];exact Ἁ (lt_trans hq53 ב) obtain ⟨fq,rq⟩:=D.qCk (lo>>>sh).toUInt64 (by rw[hqu];exact hq53) rw[hqu] at rq obtain ⟨fp,rp⟩:=gPw (88+sh) א א obtain ⟨f,e⟩:=D.qCm _ (88+sh) א fq ((lo/2^sh:Nat):ℤ) 0 א ב (by rw[rq,ἅ ו] exact ὂ (show ((lo/2^sh:Nat):ℝ)<=2^53 by exact_mod_cast hq53.le) (ὂ ב gAB)) (by rw[rq,zpow_zero,mul_one,Int.cast_natCast]) refine ⟨f,?_⟩ rw[e,rq,rp] have hval:((lo/2^sh:Nat):ℝ)*(2:ℝ)^(((88+sh:Nat):ℤ)-150)= ((lo/2^sh*2^sh:Nat):ℝ)/2^62:=by rw[show (((88+sh:Nat):ℤ)-150)=(sh:ℤ)-62 by push_cast;ring,ᾂ ב, Ἡ] push_cast;ring rw[hval] unfold FastAct.V have hm:lo/2^sh*2^sh<=lo:=Nat.div_mul_le_self lo _ have hr:lo-lo/2^sh*2^sh<2^sh:=by have:=ὀ lo (show 0<2^sh by positivity) have:=Nat.div_add_mod lo (2^sh) rw[ἥ] at this;omega refine ⟨div_le_div_of_nonneg_right (by exact_mod_cast hm) ו,?_⟩ rcases Nat.eq_zero_or_pos sh with h0 | h0 · subst h0;simp only[pow_zero,Nat.div_one,mul_one,sub_self] positivity · have hlo:2^(sh+52)<=lo:=by have hne:lo≠0:=by rintro rfl;simp only[Nat.log2_zero,zero_tsub] at hsh;omega exact (Nat.le_log2 hne).mp א rw[div_div,<-sub_div,div_le_div_iff₀ ו ו] have h1:((lo:ℝ)-((lo/2^sh*2^sh:Nat):ℝ))<=2^sh:=by rw[<-Nat.cast_sub hm];exact_mod_cast hr.le have h2:(2:ℝ)^(sh+52)<=lo:=by exact_mod_cast hlo rw[pow_add] at h2 linarith only[h1,h2] lemma Encl_congr {iv:Nat×Nat} {a b:ℝ} (h:FastAct.Encl iv a) (e:a=b):FastAct.Encl iv b:= e▸h lemma enclK_spec {k:Nat} (hk:k<1280):FastAct.Encl (enclK k) (k*(1/64)):=by unfold enclK have hj:k%64<64:=ὀ _ ב have hF:=FastAct.fracTab_spec hj have hkd:(k:ℝ)=((k/64:Nat):ℝ)*64+((k%64:Nat):ℝ):=by have:=Nat.div_add_mod k 64;exact_mod_cast (by omega:k=k/64*64+k%64) dsimp only split · rename_i hn exact Encl_congr ((FastAct.intTab_spec א).mul hF) (by rw[hkd];ring) · rename_i hn have hI:=(FastAct.intTab_spec (n:=16) ב).mul (FastAct.intTab_spec (n:=k/64-16) א) refine Encl_congr (hI.mul hF) ?_ rw[hkd,Nat.cast_sub א];push_cast;ring lemma tabOK_spec (h:tabOK=true) {k:Nat} (hk:k<1280): (enclK k).2-(enclK k).1<=2^14/\(k<1088->((enclK k).2-(enclK k).1)*2^36<=(enclK k).1):=by unfold tabOK at h have:=List.all_eq_true.mp h k (List.mem_range.mpr hk) simp only[Bool.and_eq_true,Bool.or_eq_true,decide_eq_true_eq] at this refine ⟨this.1, λh2=>?_⟩ rcases this.2 with h3 | h3 · omega · exact h3 lemma tabG_get {k:ὥ} (hk:k.toUSize.toNattoF62 (enclK k.val).1)[k.toNat]'(by simpa only[Array.size_ofFn] using hk'):=rfl rw[e] simp only[Array.getElem_ofFn] lemma tabG_spec (hok:tabOK=true) {k:ὥ} (hk:k.toUSize.toNatReal.exp (-(k.toNat*(1/64)))-D.R (expTabG.uget k.toUSize hk)<= (1/2^36+1/2^52)*Real.exp (-(k.toNat*(1/64)))):=by have hk':k.toNat<1280:=by rw[tabG_size] at hk;simpa only[ὃ] using hk rw[tabG_get] obtain ⟨e1,e2,e3⟩:=enclK_spec hk' obtain ⟨w1,w2⟩:=tabOK_spec hok hk' generalize enclK k.toNat=iv at e1 e2 e3 w1 w2 obtain ⟨lo,hi⟩:=iv simp only at e1 e2 e3 w1 w2⊢ have hlohi:lo<=hi:=by by_contra hc have:FastAct.V hi?_⟩ · rw[ἣ,ἅ (by linarith only[r1,e1])] have:FastAct.V lo/2^52<=1/2^52:=div_le_div_of_nonneg_right hVlo ו linarith only[r2,e2,hVlo,hw1] · have w3:=w2 h2 have hw2:FastAct.V hi-FastAct.V lo<=FastAct.V lo/2^36:=by rw[hw];unfold FastAct.V have:((hi-lo:Nat):ℝ)<=lo/2^36:=by rw[le_div_iff₀ ו];exact_mod_cast w3 calc ((hi-lo:Nat):ℝ)/2^62<=(lo/2^36)/2^62:=div_le_div_of_nonneg_right this ו _=lo/2^62/2^36:=by ring have:FastAct.V lo/2^36<=E/2^36:=div_le_div_of_nonneg_right e1 ו have:FastAct.V lo/2^52<=E/2^52:=div_le_div_of_nonneg_right e1 ו linarith only[r1,r2,e2,hw2] end GTab section GSplit lemma sOfG_toNat (F:ὥ) (hF:F.toNat<=144):(sOfG F).toNat=min (144-F.toNat) 31:=by unfold sOfG have e:(144-F).toNat=144-F.toNat:=by rw[ὓ _ _ (UInt32.le_iff_toNat_le.mpr (by simpa only[UInt32.reduceToNat] using hF))];simp only[UInt32.reduceToNat] split · rename_i h rw[ἳ,e] at h simp only[UInt32.reduceToNat] at h rw[e];omega · rename_i h rw[ἳ,e] at h simp only[UInt32.reduceToNat,not_lt] at h simp only[UInt32.reduceToNat,right_eq_inf,ge_iff_le];omega lemma kOfG_toNat (m F:ὥ) (hF:F.toNat<=144): (kOfG m F).toNat=m.toNat/2^(sOfG F).toNat:=by unfold kOfG have hs:=sOfG_toNat F hF rw[UInt32.toNat_shiftRight,Ἱ,Ἁ א] lemma split_spec (m F:ὥ) (hm2:m.toNat<2^24) (hF1:1<=F.toNat) (hF2:F.toNat<=144) (h:F.toUSize.toNat |D.R (tOfG m F h hk)-Real.exp (-((m.toNat:ℝ)*2^((F.toNat:ℤ)-150)))| <= (1/2^36+1/2^44)*Real.exp (-((m.toNat:ℝ)*2^((F.toNat:ℤ)-150))))/\ (kOfG m F).toNat*(1/64:ℝ)<=(m.toNat:ℝ)*2^((F.toNat:ℤ)-150)/\ (m.toNat:ℝ)*2^((F.toNat:ℤ)-150)<((kOfG m F).toNat+1)*(1/64):=by obtain ⟨hr,r0,r1⟩:=split_spec m F hm2 hF1 hF2 h set C:=(m.toNat:ℝ)*2^((F.toNat:ℤ)-150) set kk:=(kOfG m F).toNat set ρ:=C-kk*(1/64) with hρ have r0':(kk:ℝ)*(1/64)<=C:=by rw[hρ] at r0;linarith only[r0] have r1':C<((kk:ℝ)+1)*(1/64):=by rw[hρ] at r1;linarith only[r1] have hP:=gPoly hr r0 r1.le obtain ⟨hT,hT1,hT2⟩:=tabG_spec hok (k:=kOfG m F) (kidx hk ה) set E:=Real.exp (-(kk*(1/64:ℝ))) have hE1:E<=1:=Real.exp_le_one_iff.mpr (by have:(0:ℝ)<=kk:=Ἔ _;linarith only[]) have hE0:0?_,r0',r1'⟩ have hC17:C<17:=by have:(kk:ℝ)+1<=1088:=by exact_mod_cast h1088 linarith only[r1,hρ,this] have hEC:1/2^25<=Real.exp (-C):=exp17.trans (Real.exp_le_exp.mpr (by linarith only[hC17])) have hrel:=hT2 h1088 set T:=expTabG.uget (kOfG m F).toUSize (kidx hk ה) set P:=polyG (rOfG m F h) have hPab:=abs_le.mp hP.2 have hRP0:0<=D.R P:=by linarith only[hp0,hp63,hPab] obtain ⟨-,eR⟩:=D.qCf T P hT.1 hP.1 (hT.bnd (M:=1) (by rw[ἡ hE0];exact hE1) ב) (hP.bnd (M:=1) (by rw[ἡ hp0];exact hp1) ב) have hTP: |D.R T*D.R P-E*Real.exp (-ρ)| <=(1/2^36+1/2^52)*E*(Real.exp (-ρ)+1/2^45)+ E*(1/2^45):=by have:D.R T*D.R P-E*Real.exp (-ρ)=(D.R T-E)*D.R P+E*(D.R P-Real.exp (-ρ)):=by ring rw[this] refine (Ἐ _ _).trans (add_le_add ?_ ?_) · rw[ἢ,ἅ hRP0,ἣ,ἅ (by linarith only[hT1])] exact ἑ hrel (by linarith only[hPab]) hRP0 ו · rw[ἢ,ἡ hE0];exact ἁ hP.2 hE0.le have hEQ:E<=(64/63)*(E*Real.exp (-ρ)):=by have:=ἁ hp63 hE0.le;linarith only[this] have hTPa: |D.R T*D.R P| <=2*Real.exp (-C):=by have:=Ὥ (D.R T*D.R P) (E*Real.exp (-ρ)) rw[ἡ (mul_pos hE0 hp0)] at this have:(1/2^36+1/2^52)*E*(Real.exp (-ρ)+1/2^45)+E*(1/2^45)<=E*Real.exp (-ρ):=by linarith only[hE0,hEQ] rw[<-hX];linarith have hz:=gAz have hc:=abs_sub_le (D.R (T*P)) (D.R T*D.R P) (Real.exp (-C)) rw[<-hX] at hc hEC hTPa⊢ have key:(1/2^36+1/2^52)*E*(Real.exp (-ρ)+1/2^45)+E*(1/2^45)+ 1/2^53*(2*(E*Real.exp (-ρ))+1/2^100)<=(1/2^36+1/2^44)*(E*Real.exp (-ρ)):=by have h100:(1:ℝ)/2^100<=1/2^75*(E*Real.exp (-ρ)):=by have:(1:ℝ)/2^100=1/2^75*(1/2^25):=ב rw[this];exact ἁ hEC ב linarith only[hE0,hEC,hEQ] have e1:1/2^53*(|D.R T*D.R P| +D.A_z)<=1/2^53*(2*(E*Real.exp (-ρ))+1/2^100):= ἁ (by linarith only[hTPa,hz]) ב rw[tOfG_def] linarith only[hk,h,hE0,hEC,eR,hTP,hEQ,hTPa,hz,hc] end GCore section GFin lemma gZiv {q e:ὧ} {V δ:ℝ} (hq:gAp q V δ) (he:e.isFinite=true) (hqB: |D.R q| <=2^90) (heB: |D.R e| <=2^90) (hm:δ+1/2^53*(|D.R q| + |D.R e|)+1/2^150δ<=1/2^33*(|V| +D.A_z)) (hz:zA lo sp q e≠Е) {M:Model Fmt} (hf:M.isFinite=true) (hM:M.toReal=Model.roundAt Fmt V): toWord M=zA lo sp q e:=by subst hlo hsp unfold zA at hz⊢ dsimp only at hz⊢ by_cases hr:D.fin1 (D.loOf E) (D.spOf (D.loOf E)) q=Е · rw[Ὦ (by rw[hr];rfl)] at hz⊢ exact gZiv hq he hqB heB hm hz hf hM · rw[Ὧ (by simpa only[beq_iff_eq] using hr)] obtain ⟨a,b⟩:=fin1T E q hr obtain ⟨-,-,h34,-,-,-⟩:=D.qI4 E q b rw[a] exact kHvR _ q V (hq.2.trans (hrel h34)) b M hf hM def gApR (x:ὧ) (X a:ℝ):Prop:=x.isFinite=true/\ |D.R x-X| <=a*X lemma gApR_div {x y:ὧ} {X Y a b:ℝ} (hx:gApR x X a) (hy:gApR y Y b) (hX:0>>23).toNat) (h2:((w&&&В)>>>23).toNat<=254): expOf w≠255/\2^23<=(((w&&&В)&&&0x7FFFFF) ||| 0x800000).toNat/\ (((w&&&В)&&&0x7FFFFF) ||| 0x800000).toNat<2^24/\ D.wv w=(if w<س then (1:ℝ) else-1)* ((((w&&&В)&&&0x7FFFFF) ||| 0x800000).toNat* (2:ℝ)^((((w&&&В)>>>23).toNat:ℤ)-150)):=by have ha:=D.qAq w have hm:=D.qHa (w&&&В) have hF:((w&&&В)>>>23).toNat=w.toNat%2^31/2^23:=by rw[UInt32.toNat_shiftRight,Ἱ,ha];rfl rw[ha] at hm rw[hm] rw[hF] at h1 h2⊢ have hw:=w.toNat_lt have hg:D.good w=true:=by unfold D.good simp only[Bool.or_eq_true,beq_iff_eq,decide_eq_true_eq] right rw[ἃ,ὓ _ _ (by rw[ἃ,ha];simp only[UInt32.reduceToNat,Nat.reducePow];omega),ha] simp only[Nat.reducePow,UInt32.reduceToNat,tsub_le_iff_right,Nat.reduceAdd];omega have he:=D.qAe w hg refine ⟨he,א,א,?_⟩ rw[D.qA7 w hg] unfold D.A_mag rw[Ὧ (show ¬(w.toNat%2^31=0) by omega)] have hs:(w<س)↔ ¬(2^31<=w.toNat):=by rw[ἳ];simp only[UInt32.reduceToNat,Nat.reducePow,not_le] by_cases hneg:2^31<=w.toNat · rw[Ὦ hneg,Ὧ (hs.not.mpr (not_not.mpr hneg))] · rw[Ὧ hneg,Ὦ (hs.mpr hneg)] end GFin section GSig lemma gOneR:oneG.isFinite=true/\D.R oneG=1:=by obtain ⟨f,r⟩:=D.qCk 1 ה exact ⟨f,by rw[oneG,r];simp only[UInt64.reduceToNat,Nat.cast_one]⟩ lemma gM34:(m34G).isFinite=true/\D.R m34G=1/2^34:=by obtain ⟨f,e⟩:=gPw 116 ב ב exact ⟨f,by rw[m34G,e];norm_num⟩ lemma gM41:(m41G).isFinite=true/\D.R m41G=1/2^41:=by obtain ⟨f,e⟩:=gPw 109 ב ב exact ⟨f,by rw[m41G,e];norm_num⟩ lemma gM26:(m26G).isFinite=true/\D.R m26G=1/2^26:=by obtain ⟨f,e⟩:=gPw 124 ב ב exact ⟨f,by rw[m26G,e];norm_num⟩ lemma sigPos (hok:tabOK=true) (m F:ὥ) (hm2:m.toNat<2^24) (hF1:1<=F.toNat) (hF2:F.toNat<=144) (h:F.toUSize.toNatlinarith only[hT0,hρT,hRt,hT1] have h2:=abs_sub_le (D.R (oneG+t)) (1+D.R t) (1+T) have h3: |1+D.R t-(1+T)| <=ρ*T:=by rw[show 1+D.R t-(1+T)=D.R t-T by ring];exact hrel' have h4:1/2^53*(|1+D.R t| +D.A_z)<=1/2^53*(2+ρ+1/2^100):= ἁ (by linarith only[hz0,h1]) ב have h6:1/2^53*(2+ρ+1/2^100)<=1/2^51:=by have:1/2^53*(2+1/2^35+1/2^100)<=(1:ℝ)/2^51:=ב have:1/2^53*(2+ρ+1/2^100)<=1/2^53*(2+1/2^35+1/2^100):= ἁ (by linarith only[hρdef]) ב linarith only[hρdef] have h7:(0:ℝ)<=1/2^51*T:=ו have:b*(1+T)=ρ/2+ρ*T/2+1/2^51+1/2^51*T:=by rw[hbdef];ring linarith only[hρdef,hz0,hT0,hρT,ed,h1,h2,h3,this] have hb0:0<=b:=by rw[hbdef];positivity have hb1:b<=1/2:=by rw[hbdef];linarith only[hρdef] have hq:=gApR_div htR hdR hT0 (by linarith only[hT0]) hρ0 hb0 hb1 (by rw[le_div_iff₀ (by linarith only[hT0])];linarith only[hT0,hT25]) (by rw[div_le_iff₀ (by linarith only[hT0])];linarith only[hT0]) (by linarith only[hρdef]) obtain ⟨r,hrdef⟩: ∃r:ℝ,r=(ρ+b)/(1-b)+1/2^53*(1+(ρ+b)/(1-b))+1/2^120:= ⟨_,rfl⟩ rw[<-hrdef] at hq have hr:r<=(4/5)/2^35:=by rw[hrdef,hbdef,hρdef];norm_num have hV:realSigmoid (-C)=T/(1+T):=FastAct.realSigmoid_neg_eq C rw[hV] at hM set V:=T/(1+T) have hV0:0linarith only[hT1,hT0]) (by linarith only[hT0]) ב ב).mono (show _<=(1:ℝ)/2^42 by norm_num) rw[show-(2*C)=-2*C by ring,<-tanh_eq_exp_neg_two] at hq obtain ⟨f41,r41⟩:=gM41 have hqa:=hq.absR have hV: |Real.tanh C| <=1:=abs_le.mpr ⟨(Real.neg_one_lt_tanh C).le,(Real.tanh_lt_one C).le⟩ refine gZA (E:=m41G) rfl rfl hq f41 (by linarith only[h,hk,hqa,hV]) (by rw[r41];norm_num) ?_ ?_ hz hf hM rotate_left · intro h34 rw[r41,ἡ (show (0:ℝ)<1/2^41 by norm_num)] at h34 have h3:=gAz0 have h5:=Ὥ (D.R ((oneG-tOfG m F h hk)/(oneG+tOfG m F h hk))) (Real.tanh C) have h6:=hq.2 linarith only[h,hk,hqa,h34,h3] rw[r41,ἡ (show (0:ℝ)<1/2^41 by norm_num)] have:1/2^53*(|D.R ((oneG-tOfG m F h hk)/(oneG+tOfG m F h hk))| +1/2^41)<= 1/2^53*(1+1/2^42+1/2^41):=by gcongr;linarith only[h,hk,hqa,hV] have:(1:ℝ)/2^42+1/2^53*(1+1/2^42+1/2^41)+1/2^150<1/2^41:=ב linarith only[h,hk,hqa,hV] lemma tanhNeg (hok:tabOK=true) (m F:ὥ) (hm2:m.toNat<2^24) (hF1:1<=F.toNat) (hF2:F.toNat<=144) (h:F.toUSize.toNatlinarith only[hT0,hT1]) (by linarith only[hT0]) ב ב).mono (show _<=(1:ℝ)/2^42 by norm_num) have hV:(Real.exp (-(2*C))-1)/(1+Real.exp (-(2*C)))=Real.tanh (-C):=by rw[Real.tanh_neg,tanh_eq_exp_neg_two,show-2*C=-(2*C) by ring,<-neg_div];ring_nf rw[hV] at hq obtain ⟨f41,r41⟩:=gM41 have hqa:=hq.absR have hV1: |Real.tanh (-C)| <=1:=abs_le.mpr ⟨(Real.neg_one_lt_tanh _).le,(Real.tanh_lt_one _).le⟩ refine gZA (E:=m41G) rfl rfl hq f41 (by linarith only[h,hk,hqa,hV1]) (by rw[r41];norm_num) ?_ ?_ hz hf hM rotate_left · intro h34 rw[r41,ἡ (show (0:ℝ)<1/2^41 by norm_num)] at h34 have h3:=gAz0 have h5:=Ὥ (D.R ((tOfG m F h hk-oneG)/(oneG+tOfG m F h hk))) (Real.tanh (-C)) have h6:=hq.2 linarith only[h,hk,hqa,h34,h3] rw[r41,ἡ (show (0:ℝ)<1/2^41 by norm_num)] have:1/2^53*(|D.R ((tOfG m F h hk-oneG)/(oneG+tOfG m F h hk))| +1/2^41)<= 1/2^53*(1+1/2^42+1/2^41):=by gcongr;linarith only[h,hk,hqa,hV1] have:(1:ℝ)/2^42+1/2^53*(1+1/2^42+1/2^41)+1/2^150<1/2^41:=ב linarith only[h,hk,hqa,hV1] lemma tanh_sat {C:ℝ} (hC:10<=C):1-1/2^27<=Real.tanh C/\Real.tanh C<1:=by refine ⟨?_,Real.tanh_lt_one C⟩ have hT0:=Real.exp_pos (-(2*C)) have hT:Real.exp (-(2*C))<=1/2^28:=exp_neg_le_inv_two_pow 28 (by norm_num;linarith only[hC]) rw[tanh_eq_exp_neg_two,show-2*C=-(2*C) by ring,le_div_iff₀ (by linarith only[hT0,hT])] linarith only[hT0,hT] lemma gNegOne:gAp negOneG (-1) (1/2^52):=by have h0:gAp (0:ὧ) 0 0:=gAp_exact D.qHg.1 D.qHg.2 have:=gAp_sub h0 gOne (M:=0) (N:=1) ב ב ב ב exact (by simpa only[one_div,zero_sub] using this.mono (show _<=(1:ℝ)/2^52 by norm_num):gAp (0-oneG) (-1) (1/2^52)) lemma tanhSatPos {C:ℝ} (hC:10<=C) {M:Model Fmt} (hf:M.isFinite=true) (hM:M.toReal=Model.roundAt Fmt (Real.tanh C)) (hz:D.ziv oneG m26G≠Е): toWord M=D.ziv oneG m26G:=by obtain ⟨t1,t2⟩:=tanh_sat hC have hq:gAp oneG (Real.tanh C) (1/2^27):= ⟨gOneR.1,by rw[gOneR.2,ὸ];constructor<;>linarith only[t1,t2]⟩ obtain ⟨f26,r26⟩:=gM26 refine gZiv hq f26 (by rw[gOneR.2];norm_num) (by rw[r26];norm_num) ?_ hz hf hM rw[r26,gOneR.2];norm_num lemma tanhSatNeg {C:ℝ} (hC:10<=C) {M:Model Fmt} (hf:M.isFinite=true) (hM:M.toReal=Model.roundAt Fmt (Real.tanh (-C))) (hz:D.ziv negOneG m26G≠Е): toWord M=D.ziv negOneG m26G:=by obtain ⟨t1,t2⟩:=tanh_sat hC have hn:=gNegOne have hq:gAp negOneG (Real.tanh (-C)) (1/2^27+1/2^52):=by refine ⟨hn.1,?_⟩ rw[Real.tanh_neg] have:=abs_le.mp hn.2 rw[ὸ];constructor<;>linarith only[t1,this,t2] have hqa:=hq.absR have hV1: |Real.tanh (-C)| <=1:=abs_le.mpr ⟨(Real.neg_one_lt_tanh _).le,(Real.tanh_lt_one _).le⟩ obtain ⟨f26,r26⟩:=gM26 refine gZiv hq f26 (by linarith only[t1,t2,hqa,hV1]) (by rw[r26];norm_num) ?_ hz hf hM rw[r26,ἡ (show (0:ℝ)<1/2^26 by norm_num)] have:1/2^53*(|D.R negOneG| +1/2^26)<=1/2^53*(2+1/2^26):=by gcongr;linarith only[t1,t2,hqa,hV1] have:(1:ℝ)/2^27+1/2^52+1/2^53*(2+1/2^26)+1/2^150<1/2^26:=ב linarith only[t1,t2,hqa,hV1] end GTanh section GMain lemma sigModel (w:ὥ) (hfin:expOf w≠255): (sigmoidModel (ofW w)).isFinite=true/\ (sigmoidModel (ofW w)).toReal=Model.roundAt Fmt (realSigmoid (D.wv w)):= toReal_sigmoidModel (fmt:=Fmt) ה (input:=Model.ofUInt32 w) (by simp only[isFinite_ofUInt32,bne_iff_ne,ne_eq,hfin,not_false_eq_true]) lemma tanhModel' (w:ὥ) (hfin:expOf w≠255): (tanhModel (ofW w)).isFinite=true/\ (tanhModel (ofW w)).toReal=Model.roundAt Fmt (Real.tanh (D.wv w)):= toReal_tanhModel (fmt:=Fmt) ה (input:=Model.ofUInt32 w) (by simp only[isFinite_ofUInt32,bne_iff_ne,ne_eq,hfin,not_false_eq_true]) lemma sigCR_eq (w:ὥ):sigmoidCR w=toWord (sigmoidModel (ofW w)):=rfl lemma tanhCR_eq (w:ὥ):tanhCR w=toWord (tanhModel (ofW w)):=rfl lemma fRange {F:ὥ} (h:F-1<131):1<=F.toNat/\F.toNat<=131:=by rw[ἳ,UInt32.toNat_sub] at h have:=F.toNat_lt;simp only[Nat.reducePow,UInt32.reduceToNat,Nat.add_one_sub_one] at h;omega lemma fRange2 {F:ὥ} (h:F-2<131):2<=F.toNat/\F.toNat<=132:=by rw[ἳ,UInt32.toNat_sub] at h have:=F.toNat_lt;simp only[Nat.reducePow,UInt32.reduceToNat,Nat.reduceSub] at h;omega lemma sigG_spec (hok:tabOK=true) (w:ὥ):sigG w≠Е->sigG w=sigmoidCR w:=by unfold sigG dsimp only rw[sigCR_eq] split · rename_i hE obtain ⟨hF1,hF2⟩:=fRange hE obtain ⟨he,hm1,hm2,hx⟩:=decW w hF1 א obtain ⟨hf,hM⟩:=sigModel w he rw[hx] at hM split · rename_i hs rw[Ὦ hs,one_mul] at hM split · rename_i hk intro hz exact (sigPos hok _ _ hm2 hF1 א _ _ hf hM hz).symm · rename_i hk intro hz refine (sigSat ?_ hf hM hz).symm obtain ⟨-,hlo,-⟩:=split_spec _ _ hm2 hF1 א (eidx _) rw[ἳ] at hk;simp only[UInt32.reduceToNat,not_lt] at hk have:(1216:ℝ)<=((kOfG ((w&&&2147483647)&&&8388607 ||| 8388608) ((w&&&2147483647)>>>23)).toNat:ℝ):=by exact_mod_cast hk linarith only[hlo,this] · rename_i hs rw[Ὧ hs,neg_one_mul] at hM split · rename_i hk intro hz exact (sigNeg hok _ _ hm2 hF1 א _ _ (by rw[ἳ] at hk;simpa only[UInt32.reduceToNat] using hk) hf hM hz).symm · intro hz;exact absurd rfl hz · rename_i hE split · rename_i hc simp only[Bool.and_eq_true,decide_eq_true_eq] at hc obtain ⟨⟨h1,h2⟩,hs⟩:=hc rw[ἳ] at h1 h2 simp only[UInt32.reduceToNat] at h1 h2 obtain ⟨he,hm1,hm2,hx⟩:=decW w א א obtain ⟨hf,hM⟩:=sigModel w he rw[hx,Ὦ hs,one_mul] at hM intro hz refine (sigSat ?_ hf hM hz).symm have hp:(2:ℝ)^(5:ℤ)<=2^((((w&&&2147483647)>>>23).toNat:ℤ)-150+23):= ἒ ב א have hm:(2:ℝ)^23<=(((w&&&2147483647)&&&8388607 ||| 8388608).toNat:ℝ):=by exact_mod_cast hm1 rw[Ἓ ב] at hp have:(2:ℝ)^((((w&&&2147483647)>>>23).toNat:ℤ)-150)*2^23<= (((w&&&2147483647)&&&8388607 ||| 8388608).toNat:ℝ)*2^((((w&&&2147483647)>>>23).toNat:ℤ)-150):=by rw[mul_comm];exact ἀ hm ו norm_num at hp this⊢ linarith only[hp,this] · intro hz;exact absurd rfl hz end GMain section GMain2 lemma fPlus (w:ὥ): (((w&&&В)+0x800000)>>>23).toNat=((w&&&В)>>>23).toNat+1:=by have ha:=D.qAq w have hw:=w.toNat_lt rw[UInt32.toNat_shiftRight,UInt32.toNat_shiftRight,Ἱ,Ἱ, UInt32.toNat_add,ha] simp only[UInt32.reduceToNat,Nat.reduceMod,Nat.reducePow] have:w.toNat%2^31<2^31:=ὀ _ ב rw[Ἁ א] omega lemma twoC (mm:ℝ) (E F:Nat) (h:F=E+1): mm*(2:ℝ)^((F:ℤ)-150)=2*(mm*2^((E:ℤ)-150)):=by subst h rw[show ((E+1:Nat):ℤ)-150=((E:ℤ)-150)+1 by push_cast;ring,zpow_add_one₀ ב] ring lemma bigC (mm E:Nat) (hm:2^23<=mm) (hE:132<=E):(10:ℝ)<=(mm:ℝ)*2^((E:ℤ)-150):=by have h1:(2:ℝ)^23<=(mm:ℝ):=by exact_mod_cast hm have h2:(2:ℝ)^(-18:ℤ)<=2^((E:ℤ)-150):=ἒ ב א have h3:(2:ℝ)^23*2^(-18:ℤ)<=(mm:ℝ)*2^((E:ℤ)-150):= ἑ h1 h2 ו ו have h4:(2:ℝ)^23*2^(-18:ℤ)=32:=ב linarith only[h3,h4] lemma tanhG_spec (hok:tabOK=true) (w:ὥ):tanhG w≠Е->tanhG w=tanhCR w:=by unfold tanhG dsimp only rw[tanhCR_eq] have hFE:=fPlus w split · rename_i hE obtain ⟨hF1,hF2⟩:=fRange2 hE obtain ⟨he,hm1,hm2,hx⟩:=decW w א א obtain ⟨hf,hM⟩:=tanhModel' w he rw[hx] at hM have hC:=twoC ((((w&&&2147483647)&&&8388607 ||| 8388608).toNat:ℝ)) _ _ hFE split · rename_i hk split · rename_i hs rw[Ὦ hs,one_mul] at hM intro hz refine (tanhPos hok _ _ hm2 ?_ ?_ _ _ hC hf hM hz).symm<;>omega · rename_i hs rw[Ὧ hs,neg_one_mul] at hM intro hz refine (tanhNeg hok _ _ hm2 ?_ ?_ _ _ hC hf hM hz).symm<;>omega · rename_i hk obtain ⟨-,hlo,-⟩:=split_spec ((w&&&2147483647)&&&8388607 ||| 8388608) (((w&&&2147483647)+8388608)>>>23) hm2 א א (eidx _) rw[ἳ] at hk;simp only[UInt32.reduceToNat,not_lt] at hk have h1280:(1280:ℝ)<=((kOfG ((w&&&2147483647)&&&8388607 ||| 8388608) (((w&&&2147483647)+8388608)>>>23)).toNat:ℝ):=by exact_mod_cast hk rw[hC] at hlo have hC10:(10:ℝ)<=(((w&&&2147483647)&&&8388607 ||| 8388608).toNat:ℝ)* (2:ℝ)^((((w&&&2147483647)>>>23).toNat:ℤ)-150):=by linarith only[hlo,h1280] split · rename_i hs rw[Ὦ hs,one_mul] at hM intro hz exact (tanhSatPos hC10 hf hM hz).symm · rename_i hs rw[Ὧ hs,neg_one_mul] at hM intro hz exact (tanhSatNeg hC10 hf hM hz).symm · rename_i hE split · rename_i hc simp only[Bool.and_eq_true,decide_eq_true_eq] at hc obtain ⟨h1,h2⟩:=hc rw[ἳ] at h1 h2 simp only[UInt32.reduceToNat] at h1 h2 obtain ⟨he,hm1,hm2,hx⟩:=decW w א א obtain ⟨hf,hM⟩:=tanhModel' w he rw[hx] at hM have hC10:=bigC _ _ hm1 (show 132<=((w&&&2147483647)>>>23).toNat by omega) split · rename_i hs rw[Ὦ hs,one_mul] at hM intro hz exact (tanhSatPos hC10 hf hM hz).symm · rename_i hs rw[Ὧ hs,neg_one_mul] at hM intro hz exact (tanhSatNeg hC10 hf hM hz).symm · intro hz;exact absurd rfl hz lemma sigmoidF2_eq' (w:ὥ):sigmoidF2 w=sigmoidCR w:=by unfold sigmoidF2 dsimp only split · rename_i hok split · rw[sigmoidF9_eq] · rename_i hne exact sigG_spec hok w (by simpa only[ne_eq,beq_iff_eq] using hne) · simp only[beq_self_eq_true,ite_true];exact sigmoidF9_eq w lemma tanhF2_eq' (w:ὥ):tanhF2 w=tanhCR w:=by unfold tanhF2 dsimp only split · rename_i hok split · rw[tanhF9_eq] · rename_i hne exact tanhG_spec hok w (by simpa only[ne_eq,beq_iff_eq] using hne) · simp only[beq_self_eq_true,ite_true];exact tanhF9_eq w lemma sigmoidF2_eq:sigmoidF2=FastAct.sigmoidF:=by rw[FastAct.sigmoidF_eq];funext w;exact sigmoidF2_eq' w lemma tanhF2_eq:tanhF2=FastAct.tanhF:=by rw[FastAct.tanhF_eq];funext w;exact tanhF2_eq' w end GMain2 section RnnX /-! -/ def xNZ:ὧ:=dv س def xNA:ὧ:=xNZ.abs @[inline] def gT (lo sp:Ὠ) (e s0:ὧ) (sl:Unit->Word):Word:= let s:=s0+xNZ let w:=D.fin1 lo sp s if w==Е then let w2:=ziv s e if w2==Е then sl () else w2 else w lemma good_nz:good س=true:=ה lemma fin1_split (lo sp:Ὠ) (s:ὧ) (h:D.fin1 lo sp s≠Е): (s.toBits<<<(1:Ὠ))-lo>>(29:Ὠ)):=by unfold D.fin1 at h⊢ dsimp only at h⊢ split at h · rename_i hc simp only[Bool.and_eq_true,decide_eq_true_eq] at hc exact ⟨hc.1,hc.2,by rw[Ὦ (by simp only[Bool.and_eq_true,decide_eq_true_eq];exact hc)]⟩ · exact absurd rfl h lemma gT_eq (n:Nat) (hn:n<2^20) (hn0:0Word) (hx: ∀t,tgood (xw t)=true) (hw: ∀t,tgood (ww t)=true) (hv:Word) (hgv:good hv=true) (hpv:hv<=В) (hmv: ∀t,tww t&&&В<=hv) (s0 a:ὧ) (hs0:s0=(ἄ n).foldl (λacc t=>acc+dv (xw t)*dv (ww t)) 0) (ha:a=(ἄ n).foldl (λacc t=>acc+(dv (xw t)).abs) 0) (sl:Unit->Word) (hsl:sl ()=dotOf n xw ww): gT (D.loOf (nfOf n*(dv hv*a+xNA))) (D.spOf (D.loOf (nfOf n*(dv hv*a+xNA)))) (nfOf n*(dv hv*a+xNA)) s0 sl=dotOf n xw ww:=by have hf: ∀t,texpOf (xw t)≠255/\expOf (ww t)≠255:= λt ht=>⟨qAe _ (hx t ht),qAe _ (hw t ht)⟩ have hI:=C.qI0 n xw ww hn0 hf have hs:s0+xNZ=(ἄ n).foldl (λ(acc:ὧ) t=>acc+dv (xw t)*dv (ww t)) 0+dv س/\ nfOf n*(dv hv*a+xNA)= nfOf n*(dv hv*((ἄ n).foldl (λ(acc:ὧ) t=>acc+(dv (xw t)).abs) 0)+ (dv س).abs):=by rw[hs0,ha];exact ⟨rfl,rfl⟩ have br:= λhbig=>D.qC8 n hn xw ww س hv hx hw good_nz hgv hpv (ἄ n) (Ὂ) (λt ht=>List.mem_range.mp ht) (λt ht=>hmv t (List.mem_range.mp ht)) (λt ht hnot=>absurd (List.mem_range.mpr ht) hnot) (s0+xNZ) _ hs hbig unfold gT dsimp only split · rename_i h1 split · exact hsl · rename_i h2 have hz:ziv (s0+xNZ) (nfOf n*(dv hv*a+xNA))≠Е:= λh=>h2 (by rw[h];rfl) obtain ⟨-,-,hbig⟩:=D.qBw _ _ hz obtain ⟨hlo,hhi⟩:=br hbig rw[D.qCn n hn xw ww س hx hw good_nz _ _ hlo hhi hz,hI] · rename_i h1 have hz:D.fin1 (D.loOf (nfOf n*(dv hv*a+xNA))) (D.spOf (D.loOf (nfOf n*(dv hv*a+xNA)))) (s0+xNZ)≠Е:= λh=>h1 (by rw[h];rfl) obtain ⟨c1,c2,c3⟩:=fin1_split _ _ _ hz obtain ⟨-,hT⟩:=D.qHy _ _ c1 c2 obtain ⟨-,fe,-⟩:=D.qI4 _ _ hT have hbig:=D.qBgF _ _ _ c1 c2 fe le_rfl obtain ⟨hlo,hhi⟩:=br hbig rw[c3,D.qCnF n hn xw ww س hx hw good_nz _ _ _ hlo hhi fe le_rfl c1 c2,hI] end RnnX section RnnX2 /-! -/ @[inline] def pW (H K:Nat) (wf:Nat->Nat->Nat->Word) (c r0:Nat):Word:= if 4*(c/K/2)+(8*(c/K%2)+r0)/4Nat->Nat->Word):ὤ:= rowsB (λc acc=>fpush (λr0=>dv (pW H K wf c r0)) 0 8 acc) 0 ((H+3)/4*2*K) (ἆ ((H+3)/4*16*K)) lemma pnOf_spec (H K:Nat) (wf:Nat->Nat->Nat->Word): (pnOf H K wf).size=(H+3)/4*2*K*8/\ ∀c r0,c<(H+3)/4*2*K->r0<8->(pnOf H K wf).get! (c*8+r0)=dv (pW H K wf c r0):=by have:=rowsB_spec 8 (λc acc=>fpush (λr0=>dv (pW H K wf c r0)) 0 8 acc) (λc r0=>dv (pW H K wf c r0)) (λr acc=>fpush_size _ 0 8 acc) (λr acc j hj=>(fpush_get _ 0 8 acc j).1 hj) (λr acc j hj=>by rw[(fpush_get _ 0 8 acc (acc.size+j)).2 א א];congr 2;omega) ((H+3)/4*2*K) 0 (ἆ ((H+3)/4*16*K)) (by rw[ὒ];rfl) (λr' j h _=>absurd h (Ἲ _)) rw[Ἇ] at this exact this lemma ugetE (a:ὤ) (i:ὦ) (h:i.toNatacc+V.get! i*P.get! (p+8*i+r)) a lemma mxS_step (V P:ὤ) (p r t n:Nat) (a:ὧ) (h:t mxV V P p p' m n t hx hn hb hb' hs a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S= (((((((((((((((S.push (mxS V P p.toNat 0 t.toNat n.toNat a0)).push (mxS V P p.toNat 1 t.toNat n.toNat a1)).push (mxS V P p.toNat 2 t.toNat n.toNat a2)).push (mxS V P p.toNat 3 t.toNat n.toNat a3)).push (mxS V P p.toNat 4 t.toNat n.toNat a4)).push (mxS V P p.toNat 5 t.toNat n.toNat a5)).push (mxS V P p.toNat 6 t.toNat n.toNat a6)).push (mxS V P p.toNat 7 t.toNat n.toNat a7)).push (mxS V P p'.toNat 0 t.toNat n.toNat b0)).push (mxS V P p'.toNat 1 t.toNat n.toNat b1)).push (mxS V P p'.toNat 2 t.toNat n.toNat b2)).push (mxS V P p'.toNat 3 t.toNat n.toNat b3)).push (mxS V P p'.toNat 4 t.toNat n.toNat b4)).push (mxS V P p'.toNat 5 t.toNat n.toNat b5)).push (mxS V P p'.toNat 6 t.toNat n.toNat b6)).push (mxS V P p'.toNat 7 t.toNat n.toNat b7):=by intro N induction N with | zero=> intro t a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S hN have h: ¬tby have:=USize.lt_iff_toNat_lt.mp h;omega have h': ¬t.toNat intro t a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S hN have h:t ∃w,V.get! i=dv w) (hP: ∀i,i ∃w,P.get! i=dv w): ∀(N:Nat) (t:ὦ) (a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7:ὧ) (S:ὤ), n.toNat-t.toNat=N-> mxF V P p p' m n t hx hn hb hb' hs a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S= mxV V P p p' m n t hx hn hb hb' hs a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S:=by intro N induction N with | zero=> intro t a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S hN have h: ¬tby have:=USize.lt_iff_toNat_lt.mp h;omega rw[mxV,mxF,dif_neg h,dif_neg h] | succ N ih=> intro t a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S hN have h:t let ⟨w,hw⟩:=hP _ hq ⟨w,(ugetE _ _ _).trans hw⟩ obtain ⟨w0,e0⟩:=hq p 0 ה hb (D.wq0 p t m P hb hs him) obtain ⟨w1,e1⟩:=hq p 1 ה hb (D.wq1 p t m P hb hs him) obtain ⟨w2,e2⟩:=hq p 2 ה hb (D.wq2 p t m P hb hs him) obtain ⟨w3,e3⟩:=hq p 3 ה hb (D.wq3 p t m P hb hs him) obtain ⟨w4,e4⟩:=hq p 4 ה hb (D.wq4 p t m P hb hs him) obtain ⟨w5,e5⟩:=hq p 5 ה hb (D.wq5 p t m P hb hs him) obtain ⟨w6,e6⟩:=hq p 6 ה hb (D.wq6 p t m P hb hs him) obtain ⟨w7,e7⟩:=hq p 7 ה hb (D.wq7 p t m P hb hs him) obtain ⟨w8,e8⟩:=hq p' 0 ה hb' (D.wq0 p' t m P hb' hs him) obtain ⟨w9,e9⟩:=hq p' 1 ה hb' (D.wq1 p' t m P hb' hs him) obtain ⟨w10,e10⟩:=hq p' 2 ה hb' (D.wq2 p' t m P hb' hs him) obtain ⟨w11,e11⟩:=hq p' 3 ה hb' (D.wq3 p' t m P hb' hs him) obtain ⟨w12,e12⟩:=hq p' 4 ה hb' (D.wq4 p' t m P hb' hs him) obtain ⟨w13,e13⟩:=hq p' 5 ה hb' (D.wq5 p' t m P hb' hs him) obtain ⟨w14,e14⟩:=hq p' 6 ה hb' (D.wq6 p' t m P hb' hs him) obtain ⟨w15,e15⟩:=hq p' 7 ה hb' (D.wq7 p' t m P hb' hs him) rw[hv,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15] simp only[fmaE] lemma usz2 (t n:ὦ) (h:t ∃w,V.get! i=dv w) (hP: ∀i,i ∃w,P.get! i=dv w) (i j:ὦ) (h:i.toNat ∃w,V.get! i=dv w) (hP: ∀i,i ∃w,P.get! i=dv w): ∀(N:Nat) (t:ὦ) (a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7:ὧ) (S:ὤ), n.toNat-t.toNat<=N-> mxF2 V P p p' m n t hx hn hb hb' hs a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S= mxV V P p p' m n t hx hn hb hb' hs a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S:=by intro N induction N with | zero=> intro t a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S hN have h: ¬(tby have:=USize.lt_iff_toNat_lt.mp h.1;omega rw[mxF2,dif_neg h,mxF_eq V P p p' m n hx hn hb hb' hs hV hP _ t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ S rfl] | succ N ih=> intro t a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2 b3 b4 b5 b6 b7 S hN by_cases h:trw[mxV,dif_pos h.1] dsimp only conv_rhs=>rw[mxV,dif_pos h1] dsimp only simp only[fmaU V P hV hP] · rw[mxF2,dif_neg h,mxF_eq V P p p' m n hx hn hb hb' hs hV hP _ t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ S rfl] @[inline] def mxD (V P:ὤ) (p p' m n t:ὦ) (hx:n.toNat<=V.size) (hn:n.toNat<=m.toNat) (hb:p.toNat+8*m.toNat<=P.size) (hb':p'.toNat+8*m.toNat<=P.size) (hs:P.size<2^32) (S:ὤ):ὤ:= if D.armT then mxF2 V P p p' m n t hx hn hb hb' hs 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 S else mxV V P p p' m n t hx hn hb hb' hs 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 S end RnnX2 section RnnX3 lemma mxV_zero (V P:ὤ) (p p' m n:ὦ) (hx:n.toNat<=V.size) (hn:n.toNat<=m.toNat) (hb:p.toNat+8*m.toNat<=P.size) (hb':p'.toNat+8*m.toNat<=P.size) (hs:P.size<2^32) (S:ὤ): mxV V P p p' m n 0 hx hn hb hb' hs 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 S= fpush (λr=>if r<8 then mxS V P p.toNat r 0 n.toNat 0 else mxS V P p'.toNat (r-8) 0 n.toNat 0) 0 16 S:=by rw[mxV_eq V P p p' m n hx hn hb hb' hs _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 S rfl] rfl lemma mxD_eq (V P:ὤ) (p p' m n:ὦ) (hx:n.toNat<=V.size) (hn:n.toNat<=m.toNat) (hb:p.toNat+8*m.toNat<=P.size) (hb':p'.toNat+8*m.toNat<=P.size) (hs:P.size<2^32) (hV: ∀i,i ∃w,V.get! i=dv w) (hP: ∀i,i ∃w,P.get! i=dv w) (S:ὤ): mxD V P p p' m n 0 hx hn hb hb' hs S= fpush (λr=>if r<8 then mxS V P p.toNat r 0 n.toNat 0 else mxS V P p'.toNat (r-8) 0 n.toNat 0) 0 16 S:=by unfold mxD split · rw[mxF2_eq V P p p' m n hx hn hb hb' hs hV hP _ 0 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ S le_rfl,mxV_zero] · rw[mxV_zero] lemma blk_le (b K P:Nat) (h:(b+1)*16*K<=P): b*16*K+8*K+8*K<=P/\b*16*K+8*K<=P:=by have e:(b+1)*16*K=b*16*K+16*K:=by ring omega @[inline] def mxRow (V P:ὤ) (K:ὦ) (hx:K.toNat<=V.size) (hs:P.size<2^32) (b:Nat) (S:ὤ):ὤ:= if h:(b+1)*16*K.toNat<=P.size then mxD V P (ὴ (b*16*K.toNat)) (ὴ (b*16*K.toNat+8*K.toNat)) K K 0 hx (Nat.le_refl _) (by rw[D.uk _ (by have:=blk_le b K.toNat P.size h;omega)];have:=blk_le b K.toNat P.size h;omega) (by rw[D.uk _ (by have:=blk_le b K.toNat P.size h;omega)];have:=blk_le b K.toNat P.size h;omega) hs S else fpush (λ_=>0) 0 16 S def mxB (V P:ὤ) (K b sl:Nat):ὧ:= if (b+1)*16*K<=P.size then (if sl<8 then mxS V P (b*16*K) sl 0 K 0 else mxS V P (b*16*K+8*K) (sl-8) 0 K 0) else 0 lemma mxRow_spec (V P:ὤ) (K:ὦ) (hx:K.toNat<=V.size) (hs:P.size<2^32) (hV: ∀i,i ∃w,V.get! i=dv w) (hP: ∀i,i ∃w,P.get! i=dv w) (n:Nat): (rowsB (mxRow V P K hx hs) 0 n (ἆ (n*16))).size=n*16/\ ∀b sl,bsl<16->(rowsB (mxRow V P K hx hs) 0 n (ἆ (n*16))).get! (b*16+sl)= mxB V P K.toNat b sl:=by have:=rowsB_spec 16 (mxRow V P K hx hs) (λb sl=>mxB V P K.toNat b sl) (λr acc=>by unfold mxRow;split<;>(try rw[mxD_eq _ _ _ _ _ _ _ _ _ _ _ hV hP])<;>exact fpush_size _ 0 16 acc) (λr acc j hj=>by unfold mxRow;split<;>(try rw[mxD_eq _ _ _ _ _ _ _ _ _ _ _ hV hP])<;>exact (fpush_get _ 0 16 acc j).1 hj) (λr acc j hj=>by unfold mxRow mxB split · rename_i h rw[mxD_eq _ _ _ _ _ _ _ _ _ _ _ hV hP,(fpush_get _ 0 16 acc (acc.size+j)).2 א א, D.uk _ (by have:=blk_le r K.toNat P.size h;omega),D.uk _ (by have:=blk_le r K.toNat P.size h;omega)] simp only[Ἇ,Nat.add_sub_cancel_left] · rename_i h rw[(fpush_get _ 0 16 acc (acc.size+j)).2 א א]) n 0 (ἆ (n*16)) (by rw[ὒ];rfl) (λr' j h _=>absurd h (Ἲ _)) rw[Ἇ] at this exact this @[inline] def vOf (inW H:Nat) (x h:ё) (t:Nat):ὤ:= ((fpush (λq=>dv h[q]!) 0 H (fpush (λq=>dv x[q]!) (t*inW) inW (ἆ (inW+H+2)))).push oneD).push oneD @[inline] def gX (inW H:Nat) (x h:ё) (t j:Nat):Word:= if j< inW then x[t*inW+j]! else if j< inW+H then h[j-inW]! else oneW @[inline] def gWt (inW H:Nat) (wih whh bih bhh:ё) (k j:Nat):Word:= if j< inW then wih[k*inW+j]! else if j< inW+H then whh[k*H+(j-inW)]! else if j=inW+H then bih[k]! else bhh[k]! lemma vOf_spec (inW H:Nat) (x h:ё) (t:Nat): (vOf inW H x h t).size=inW+H+2/\ ∀j,j< inW+H+2->(vOf inW H x h t).get! j=dv (gX inW H x h t j):=by have e0:(ἆ (inW+H+2)).size=0:=rfl have s1:=fpush_size (λq=>dv x[q]!) (t*inW) inW (ἆ (inW+H+2)) have s2:=fpush_size (λq=>dv h[q]!) 0 H (fpush (λq=>dv x[q]!) (t*inW) inW (ἆ (inW+H+2))) rw[s1,e0,Ἇ] at s2 refine ⟨by unfold vOf;rw[fa_push_size,fa_push_size,s2], λj hj=>?_⟩ unfold vOf gX rw[fa_push_get,fa_push_size,s2] by_cases j1:j< inW · rw[Ὦ א,fa_push_get,s2,Ὦ א,(fpush_get _ 0 H _ j).1 (by rw[s1,e0];omega), (fpush_get _ _ inW _ j).2 (by rw[e0];omega) (by rw[e0];omega),Ὦ j1,e0] simp only[Nat.sub_zero] by_cases j2:j< inW+H · rw[Ὦ א,fa_push_get,s2,Ὦ א,(fpush_get _ 0 H _ j).2 (by rw[s1,e0];omega) (by rw[s1,e0];omega),Ὧ j1,Ὦ j2,s1,e0] simp only[Ἇ] · rw[Ὧ j1,Ὧ j2] by_cases j3:j=inW+H+1 · rw[Ὧ א,Ὦ j3];rfl · rw[Ὦ א,fa_push_get,s2,Ὧ א,Ὦ א];rfl def aSN (V:ὤ):Nat->Nat->ὧ->ὧ | _,0,a=>a | i,k+1,a=>aSN V (i+1) k (a+(V.get! i).abs) lemma aSN_eq (V:ὤ): ∀k i a,aSN V i k a=(List.range' i k).foldl (λacc j=>acc+(V.get! j).abs) a | 0,_,_=>rfl | k+1,i,a=>by rw[aSN,aSN_eq V k (i+1),List.range'_succ,ὔ] def aU (V:ὤ) (n i:ὦ) (hn:n.toNat<=V.size) (a:ὧ):ὧ:= if h:iaU V n i hn a=aSN V i.toNat (n.toNat-i.toNat) a:=by intro N induction N with | zero=> intro i a hN have h: ¬iby have:=USize.lt_iff_toNat_lt.mp h;omega rw[aU,dif_neg h,hN];rfl | succ N ih=> intro i a hN have h:iacc+(V.get! j).abs) a:=by unfold aS split · rename_i h rw[aU_eq V _ _ _ _ a rfl,D.uk _ א,D.uk _ א,Nat.add_sub_cancel_left,aSN_eq] · rw[aSN_eq] lemma foldl_ext {α:Type} (f g:α->Nat->α): ∀(l:љ) (a:α),(∀j∈l, ∀b,f b j=g b j)-> l.foldl f a=l.foldl g a | [],_,_=>rfl | j::l,a,h=>by rw[ὔ,ὔ,h j (ὣ ..) a] exact foldl_ext f g l _ λu hu=>h u (ὖ _ hu) lemma divmodK (m i K:Nat) (hi:iNat->Nat->Word) (V:ὤ) (hK:K<2^32) (hVs:V.size=K) (xw:Nat->Word) (hVx: ∀j,jV.get! j=dv (xw j)) (hs:(pnOf H K wf).size<2^32) (hx:(ὴ K).toNat<=V.size) (u g:Nat) (hu:uacc+dv (xw j)*dv (wf u g j)) 0:=by obtain ⟨hPs,hPg⟩:=pnOf_spec H K wf have hV: ∀i,i ∃w,V.get! i=dv w:= λi hi=>⟨xw i,hVx i א⟩ have hP: ∀i,i<(pnOf H K wf).size-> ∃w,(pnOf H K wf).get! i=dv w:= λi hi=>by rw[hPs] at hi refine ⟨pW H K wf (i/8) (i%8),?_⟩ rw[<-hPg (i/8) (i%8) א א,Nat.div_add_mod'] have hKn:(ὴ K).toNat=K:=D.uk K hK have hb4:u/4<(H+3)/4:=א obtain ⟨-,hS⟩:=mxRow_spec V (pnOf H K wf) (ὴ K) hx hs hV hP ((H+3)/4) rw[show 4*u+g=u/4*16+(4*(u%4)+g) by omega,hS _ _ hb4 א] unfold mxB have hbl:(u/4+1)*16*K<=(pnOf H K wf).size:=by rw[hPs];have:=Ἒ K (Ἒ 16 (show u/4+1<=(H+3)/4 by omega)) calc (u/4+1)*16*K<=(H+3)/4*16*K:=this _=(H+3)/4*2*K*8:=by ring rw[hKn,Ὦ hbl] have hs8: ∀(hf:Nat),hf<2->4*(u%4)+g=8*hf+(4*(u%4)+g-8*hf)-> (4*(u%4)+g-8*hf)<8-> mxS V (pnOf H K wf) (u/4*16*K+8*K*hf) (4*(u%4)+g-8*hf) 0 K 0= (ἄ K).foldl (λacc j=>acc+dv (xw j)*dv (wf u g j)) 0:=by intro hf hf2 hsl hr unfold mxS rw[Nat.sub_zero,<-ὗ] apply foldl_ext intro j hj b have hjK:=List.mem_range.mp hj have hc:(2*(u/4)+hf)*K+j<(H+3)/4*2*K:=by have:=Ἒ K (show 2*(u/4)+hf+1<=(H+3)/4*2 by omega) rw[ὰ] at this;omega rw[hVx j hjK,show u/4*16*K+8*K*hf+8*j+(4*(u%4)+g-8*hf)= ((2*(u/4)+hf)*K+j)*8+(4*(u%4)+g-8*hf) by ring,hPg _ _ hc hr] unfold pW obtain ⟨d1,d2⟩:=divmodK (2*(u/4)+hf) j K hjK rw[d1,d2,show (2*(u/4)+hf)/2=u/4 by omega,show (2*(u/4)+hf)%2=hf by omega, show 8*hf+(4*(u%4)+g-8*hf)=4*(u%4)+g by omega, show 4*(u/4)+(4*(u%4)+g)/4=u by omega,show (4*(u%4)+g)%4=g by omega,Ὦ hu] by_cases h8:4*(u%4)+g<8 · rw[Ὦ h8] have:=hs8 0 ה א א rw[Nat.mul_zero,Ἵ,Nat.mul_zero,Nat.sub_zero] at this exact this · rw[Ὧ h8] have:=hs8 1 ה א א rw[Nat.mul_one,Nat.mul_one] at this exact this end RnnX3 section RnnX4 def mxW (m:Word) (a:ё):Word:= a.foldl (λm w=>if m<(w&&&В) then (w&&&В) else m) m @[inline] def wHN (inW H:Nat) (whh bhh:ё) (u j:Nat):Word:= if j< inW then 0 else if j< inW+H then whh[(2*H+u)*H+(j-inW)]! else if j=inW+H then 0 else bhh[2*H+u]! @[inline] def wCD (inW H:Nat) (wih bih:ё) (u j:Nat):Word:= if j< inW then wih[(2*H+u)*inW+j]! else if j< inW+H then 0 else if j=inW+H then bih[2*H+u]! else 0 @[inline] def wfX (gru:Ὡ) (inW H:Nat) (wih whh bih bhh:ё) (u g j:Nat):Word:= if gru then (if g<2 then gWt inW H wih whh bih bhh (g*H+u) j else if g=2 then wHN inW H whh bhh u j else wCD inW H wih bih u j) else gWt inW H wih whh bih bhh (g*H+u) j def xpOf (gru:Ὡ) (inW H:Nat) (wih whh bih bhh:ё):ὤ×Word×Ὡ:= let hv:=mxW (mxW (mxW (mxW (if gru then 0x3F800000 else 0) wih) whh) bih) bhh let P:=pnOf H (inW+H+2) (wfX gru inW H wih whh bih bhh) (P,hv,wih.all good&&whh.all good&&bih.all good&&bhh.all good&&good hv&&decide (hv<=В)&& wih.all (λw=>w&&&В<=hv)&&whh.all (λw=>w&&&В<=hv)&& bih.all (λw=>w&&&В<=hv)&&bhh.all (λw=>w&&&В<=hv)&& decide (inW+H+3<2^20)&&decide (P.size<2^32)&&decide (H<2^20)&& decide (gru=false\/0x3F800000<=hv)) abbrev XPc (gru:Ὡ) (inW H:Nat) (wih whh bih bhh:ё):= {p:ὤ×Word×Ὡ // p=xpOf gru inW H wih whh bih bhh} local instance xpcSub (gru : Bool) (inW H : Nat) (wih whh bih bhh : Array Word) : Subsingleton (XPc gru inW H wih whh bih bhh) := ⟨fun a b => Subtype.ext (a.2.trans b.2.symm)⟩ structure XPE where (k:Ὡ) (nI nH:Nat) (a b c d:ё) (g:ὦ) (p:ὤ×Word×Ὡ) (ok:p=xpOf k nI nH a b c d) def xpF (gru:Ὡ) (inW H:Nat) (wih whh bih bhh:ё) (g:ὦ) (s:Array XPE) (i:Nat): Option (XPc gru inW H wih whh bih bhh):= if h:is[i].a==wih) (λe=>by rw[e];exact beq_self_eq_true wih) then if hb:withPtrEq s[i].b whh (λ_=>s[i].b==whh) (λe=>by rw[e];exact beq_self_eq_true whh) then if hc:withPtrEq s[i].c bih (λ_=>s[i].c==bih) (λe=>by rw[e];exact beq_self_eq_true bih) then if hd:withPtrEq s[i].d bhh (λ_=>s[i].d==bhh) (λe=>by rw[e];exact beq_self_eq_true bhh) then some ⟨s[i].p,by rw[<-hn.1,<-hn.2.1,<-hn.2.2,<-eq_of_beq ha,<-eq_of_beq hb,<-eq_of_beq hc,<-eq_of_beq hd] exact s[i].ok⟩ else xpF gru inW H wih whh bih bhh g s (i+1) else xpF gru inW H wih whh bih bhh g s (i+1) else xpF gru inW H wih whh bih bhh g s (i+1) else xpF gru inW H wih whh bih bhh g s (i+1) else xpF gru inW H wih whh bih bhh g s (i+1) else xpF gru inW H wih whh bih bhh g s (i+1) else none partial_fixpoint @[noinline] def xpS:ST.Ref Unit (Array XPE):=(ST.Prim.mkRef #[] (Void.mk ())).val @[inline] def xpGet (gru:Ὡ) (inW H:Nat) (wih whh bih bhh:ё):XPc gru inW H wih whh bih bhh:= withPtrAddr wih (λg=> let s:=(ST.Prim.Ref.get xpS (Void.mk ())).val match xpF gru inW H wih whh bih bhh g s 0 with | some v=>v | none=> let p:=xpOf gru inW H wih whh bih bhh let old:=(ST.Prim.Ref.swap xpS (#[⟨gru,inW,H,wih,whh,bih,bhh,g,p,rfl⟩]++ (if s.size<64 then s else s.pop)) (Void.mk ())).val match xpF gru inW H wih whh bih bhh g old 0 with | some v=>v | none=>⟨p,rfl⟩) (λ_ _=>Subsingleton.elim _ _) lemma all_le (a:ё) (hv:Word) (h:a.all (λw=>w&&&В<=hv)=true) (i:Nat): a[i]!&&&В<=hv:=by by_cases hi:iWord) (inW H:Nat) (x wih whh bih bhh h cs:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e:ὧ) (u:Nat):Word×Word:= let gi:=gT lo sp e (S.get! (4*u)) (λ_=>xSlow inW H x wih whh bih bhh h t u) let gf:=gT lo sp e (S.get! (4*u+1)) (λ_=>xSlow inW H x wih whh bih bhh h t (H+u)) let gg:=gT lo sp e (S.get! (4*u+2)) (λ_=>xSlow inW H x wih whh bih bhh h t (2*H+u)) let go:=gT lo sp e (S.get! (4*u+3)) (λ_=>xSlow inW H x wih whh bih bhh h t (3*H+u)) let c':=cellF (sig gf) (sig gi) cs[u]! (tanh gg) (mulF (sig go) (tanh c'),c') @[specialize] def lsU (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h cs:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e:ὧ):Nat->Nat->ё->ё->ё×ё | _,0,a,b=>(a,b) | u,n+1,a,b=> let p:=lstmUX sig tanh inW H x wih whh bih bhh h cs t S lo sp e u lsU sig tanh inW H x wih whh bih bhh h cs t S lo sp e (u+1) n (a.push p.1) (b.push p.2) lemma lsU_eq (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h cs:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e:ὧ): ∀n u a b, lsU sig tanh inW H x wih whh bih bhh h cs t S lo sp e u n a b= build2 (lstmUX sig tanh inW H x wih whh bih bhh h cs t S lo sp e) u n a b | 0,_,_,_=>rfl | n+1,u,a,b=>by rw[lsU,build2,lsU_eq sig tanh inW H x wih whh bih bhh h cs t S lo sp e n] lemma oK (S:ὤ) (o:ὦ) (u k:Nat) (hk:k<4) (ho:o.toNat=4*u) (hS:4*u+3Word) (inW H:Nat) (x wih whh bih bhh h cs:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e:ὧ) (hs:S.size<2^32) (u:Nat) (o:ὦ) (ho:o.toNat=4*u) (hS:4*u+3xSlow inW H x wih whh bih bhh h t u) let gf:=gT lo sp e (S.uget (o+ὴ 1) (oK S o u 1 (by decide) ho hS hs).2) (λ_=>xSlow inW H x wih whh bih bhh h t (H+u)) let gg:=gT lo sp e (S.uget (o+ὴ 2) (oK S o u 2 (by decide) ho hS hs).2) (λ_=>xSlow inW H x wih whh bih bhh h t (2*H+u)) let go:=gT lo sp e (S.uget (o+ὴ 3) (oK S o u 3 (by decide) ho hS hs).2) (λ_=>xSlow inW H x wih whh bih bhh h t (3*H+u)) let c':=cellF (sig gf) (sig gi) cs[u]! (tanh gg) (mulF (sig go) (tanh c'),c') lemma o4 (S:ὤ) (o:ὦ) (u:Nat) (ho:o.toNat=4*u) (hS:4*u+3Word) (inW H:Nat) (x wih whh bih bhh h cs:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e:ὧ) (hs:S.size<2^32): (n u:Nat)->(o:ὦ)->o.toNat=4*u->4*(u+n)<=S.size->ё->ё->ё×ё | 0,_,_,_,_,a,b=>(a,b) | n+1,u,o,ho,hn,a,b=> let p:=lstmUX2 sig tanh inW H x wih whh bih bhh h cs t S lo sp e hs u o ho (by omega) lsU2 sig tanh inW H x wih whh bih bhh h cs t S lo sp e hs n (u+1) (o+ὴ 4) (o4 S o u ho (by omega) hs) (by omega) (a.push p.1) (b.push p.2) lemma lsU2_eq (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h cs:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e:ὧ) (hs:S.size<2^32): ∀n u o (ho:o.toNat=4*u) (hn:4*(u+n)<=S.size) a b, lsU2 sig tanh inW H x wih whh bih bhh h cs t S lo sp e hs n u o ho hn a b=lsU sig tanh inW H x wih whh bih bhh h cs t S lo sp e u n a b | 0,_,_,_,_,_,_=>rfl | n+1,u,o,ho,hn,a,b=>by have hS:4*u+3Word) (inW H:Nat) (x wih whh bih bhh h cs:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e:ὧ): (if hS:S.size<2^32/\4*(0+H)<=S.size then lsU2 sig tanh inW H x wih whh bih bhh h cs t S lo sp e hS.1 H 0 0 rfl hS.2 (Array.emptyWithCapacity H) (Array.emptyWithCapacity H) else lsU sig tanh inW H x wih whh bih bhh h cs t S lo sp e 0 H (Array.emptyWithCapacity H) (Array.emptyWithCapacity H))= lsU sig tanh inW H x wih whh bih bhh h cs t S lo sp e 0 H (Array.emptyWithCapacity H) (Array.emptyWithCapacity H):=by split · exact lsU2_eq _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ · rfl lemma vx_le (inW H:Nat) (x h:ё) (t:Nat) (hK:inW+H+3<2^20): (ὴ (inW+H+2)).toNat<=(vOf inW H x h t).size:=by rw[D.uk _ א,(vOf_spec inW H x h t).1] lemma xS_size (gru:Ὡ) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (hk:inW+H+3<2^20/\(xpOf gru inW H wih whh bih bhh).1.size<2^32): (xSum gru inW H wih whh bih bhh (vOf inW H x h t) (xpOf gru inW H wih whh bih bhh).1 (vx_le inW H x h t hk.1) hk.2).size= (H+3)/4*16:=by obtain ⟨hVs,hVg⟩:=vOf_spec inW H x h t obtain ⟨hPs,hPg⟩:=pnOf_spec H (inW+H+2) (wfX gru inW H wih whh bih bhh) have hV: ∀i,i<(vOf inW H x h t).size-> ∃w,(vOf inW H x h t).get! i=dv w:= λi hi=>⟨gX inW H x h t i,hVg i א⟩ have hP: ∀i,i<(xpOf gru inW H wih whh bih bhh).1.size-> ∃w,(xpOf gru inW H wih whh bih bhh).1.get! i=dv w:=by intro i hi show ∃w,(pnOf H (inW+H+2) (wfX gru inW H wih whh bih bhh)).get! i=dv w have hi':i<(pnOf H (inW+H+2) (wfX gru inW H wih whh bih bhh)).size:=hi rw[hPs] at hi' refine ⟨pW H (inW+H+2) (wfX gru inW H wih whh bih bhh) (i/8) (i%8),?_⟩ rw[<-hPg (i/8) (i%8) א א,Nat.div_add_mod'] exact (mxRow_spec _ _ _ _ _ hV hP _).1 @[specialize] def lstmStepX (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh:ё) (P:ὤ) (hv:Word) (t:Nat) (st:ё×ё):ё×ё:= if hc:st.1.all good=true then if hk:inW+H+3<2^20/\P.size<2^32 then let V:=vOf inW H x st.1 t let e:=nfOf (inW+H+2)*(dv hv*aS V 0 (inW+H+2) 0+xNA) let lo:=D.loOf e let S:=xSum false inW H wih whh bih bhh V P (vx_le inW H x st.1 t hk.1) hk.2 if hS:S.size<2^32/\4*(0+H)<=S.size then lsU2 sig tanh inW H x wih whh bih bhh st.1 st.2 t S lo (D.spOf lo) e hS.1 H 0 0 rfl hS.2 (Array.emptyWithCapacity H) (Array.emptyWithCapacity H) else lsU sig tanh inW H x wih whh bih bhh st.1 st.2 t S lo (D.spOf lo) e 0 H (Array.emptyWithCapacity H) (Array.emptyWithCapacity H) else lstmStepWith Pinned.dotFn sig tanh inW H x wih whh bih bhh t st else lstmStepWith Pinned.dotFn sig tanh inW H x wih whh bih bhh t st lemma gateX_eq (gru:Ὡ) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (hq:(xpOf gru inW H wih whh bih bhh).2.2=true) (hx: ∀i:Nat,good x[i]! =true) (hc:h.all good=true) (hk:inW+H+3<2^20/\(xpOf gru inW H wih whh bih bhh).1.size<2^32) (u g:Nat) (hu:uWord) (hww: ∀j,ww j=wfX gru inW H wih whh bih bhh u g j) (sl:Unit->Word) (hsl:sl ()=dotOf (inW+H+2) (gX inW H x h t) ww): let V:=vOf inW H x h t let e:=nfOf (inW+H+2)*(dv (xpOf gru inW H wih whh bih bhh).2.1*aS V 0 (inW+H+2) 0+xNA) let S:=xSum gru inW H wih whh bih bhh V (xpOf gru inW H wih whh bih bhh).1 (vx_le inW H x h t hk.1) hk.2 (∀j,good (ww j)=true/\ww j&&&В<=(xpOf gru inW H wih whh bih bhh).2.1)-> gT (D.loOf e) (D.spOf (D.loOf e)) e (S.get! (4*u+g)) sl=dotOf (inW+H+2) (gX inW H x h t) ww:=by intro V e S hwv obtain ⟨q,-,-,-⟩:=xq_of gru inW H wih whh bih bhh hq obtain ⟨hVs,hVg⟩:=vOf_spec inW H x h t have hS:S.get! (4*u+g)=(ἄ (inW+H+2)).foldl (λacc j=>acc+dv (gX inW H x h t j)*dv (ww j)) 0:=by have:=slot_eq H (inW+H+2) (wfX gru inW H wih whh bih bhh) V א hVs (gX inW H x h t) hVg hk.2 (vx_le inW H x h t hk.1) u g hu hg simp only[<-hww] at this exact this have ha:aS V 0 (inW+H+2) 0=(ἄ (inW+H+2)).foldl (λacc j=>acc+(dv (gX inW H x h t j)).abs) 0:=by rw[aS_eq,<-ὗ] exact foldl_ext _ _ _ _ λj hj b=>by rw[hVg j (List.mem_range.mp hj)] exact gT_eq (inW+H+2) א א (gX inW H x h t) ww (λj _=>gX_good inW H x h t hx hc j) (λj _=>(hwv j).1) _ q.gv q.pv (λj _=>(hwv j).2) _ _ hS ha sl hsl lemma lstmStepX_eq (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh:ё) (hq:(xpOf false inW H wih whh bih bhh).2.2=true) (hx: ∀i:Nat,good x[i]! =true): lstmStepX sig tanh inW H x wih whh bih bhh (xpOf false inW H wih whh bih bhh).1 (xpOf false inW H wih whh bih bhh).2.1= lstmStepWith dotOf sig tanh inW H x wih whh bih bhh:=by funext t st obtain ⟨q,-,-,-⟩:=xq_of false inW H wih whh bih bhh hq unfold lstmStepX split · rename_i hc split · rename_i hk have hg: ∀g u,ug<4-> gT (D.loOf (nfOf (inW+H+2)*(dv (xpOf false inW H wih whh bih bhh).2.1* aS (vOf inW H x st.1 t) 0 (inW+H+2) 0+xNA))) (D.spOf (D.loOf (nfOf (inW+H+2)*(dv (xpOf false inW H wih whh bih bhh).2.1* aS (vOf inW H x st.1 t) 0 (inW+H+2) 0+xNA)))) (nfOf (inW+H+2)*(dv (xpOf false inW H wih whh bih bhh).2.1* aS (vOf inW H x st.1 t) 0 (inW+H+2) 0+xNA)) ((xSum false inW H wih whh bih bhh (vOf inW H x st.1 t) (xpOf false inW H wih whh bih bhh).1 (vx_le inW H x st.1 t hk.1) hk.2).get! (4*u+g)) (λ_=>xSlow inW H x wih whh bih bhh st.1 t (g*H+u))= gateWith dotOf inW H x wih whh bih bhh st.1 t (g*H+u):= λg u hu hg4=> gateX_eq false inW H x wih whh bih bhh st.1 t hq hx hc hk u g hu hg4 (gWt inW H wih whh bih bhh (g*H+u)) (λj=>rfl) _ (by unfold xSlow;rw[Pinned.dotFn_eq_dotOf]) (λj=>gWt_good q _ j) dsimp only rw[dite_lsU,lsU_eq,build2_zero] unfold lstmStepWith simp only[] congr 1 · congr 1;funext u obtain ⟨i1,i2,i3,i4⟩:=stepIdx4 H u.val u.isLt unfold lstmUX simp only[cellF_eq,mulF_eq,Pinned.dotFn_eq_dotOf] rw[ofFn_get!F _ u.val u.isLt] try dsimp only have h0:=hg 0 u.val u.isLt ה have h1:=hg 1 u.val u.isLt ה have h2:=hg 2 u.val u.isLt ה have h3:=hg 3 u.val u.isLt ה simp only[ὒ,Ἇ,Ὑ,Ἵ] at h0 h1 h2 h3 rw[h0,h1,h2,h3,ofFn_get! _ _ _ i4,ofFn_get! _ _ _ i1,ofFn_get! _ _ _ i2,ofFn_get! _ _ _ i3] · congr 1;funext u obtain ⟨i1,i2,i3,i4⟩:=stepIdx4 H u.val u.isLt unfold lstmUX simp only[cellF_eq,Pinned.dotFn_eq_dotOf] have h0:=hg 0 u.val u.isLt ה have h1:=hg 1 u.val u.isLt ה have h2:=hg 2 u.val u.isLt ה simp only[ὒ,Ἇ,Ὑ,Ἵ] at h0 h1 h2 rw[h0,h1,h2,ofFn_get! _ _ _ i1,ofFn_get! _ _ _ i2,ofFn_get! _ _ _ i3] · rw[Pinned.dotFn_eq_dotOf] · rw[Pinned.dotFn_eq_dotOf] @[specialize] def lstmLX (sig tanh:Word->Word) (T inW H:Nat) (x wih whh bih bhh:ё):ё:= let p:=(xpGet false inW H wih whh bih bhh).1 if p.2.2&&x.all good then recFlat (lstmStepX sig tanh inW H x wih whh bih bhh p.1 p.2.1) 0 T (ἇ H 0,ἇ H 0) (Array.emptyWithCapacity (T*H)) else lstmWith Pinned.dotFn sig tanh T inW H x wih whh bih bhh lemma lstmLX_eq (sig tanh:Word->Word):lstmLX sig tanh=lstmWith Pinned.dotFn sig tanh:=by funext T inW H x wih whh bih bhh unfold lstmLX rw[(xpGet false inW H wih whh bih bhh).2] dsimp only split · rename_i hq simp only[Bool.and_eq_true] at hq rw[lstmStepX_eq sig tanh inW H x wih whh bih bhh hq.1 (all_good x hq.2), recFlat_eq T H _ _ (λt st=>by unfold lstmStepWith;exact Array.size_ofFn),Pinned.dotFn_eq_dotOf] rfl · rfl end RnnX4 section RnnX5 /-! -/ lemma dotOf_sum (n1 n2:Nat) (a1 b1 a2 b2:Nat->Word) (hf1: ∀j,jexpOf (a1 j)≠255/\expOf (b1 j)≠255) (hf2: ∀j,jexpOf (a2 j)≠255/\expOf (b2 j)≠255) (hS:(∑ j∈Ἣ n1,rationalWord (a1 j)*rationalWord (b1 j))= ∑ j∈Ἣ n2,rationalWord (a2 j)*rationalWord (b2 j)) (h0:(∑ j∈Ἣ n1,rationalWord (a1 j)*rationalWord (b1 j))≠0): dotOf n1 a1 b1=dotOf n2 a2 b2:=by obtain ⟨d1,e1,w1⟩:=D.qEc n1 a1 b1 hf1 h0 obtain ⟨d2,e2,w2⟩:=D.qEc n2 a2 b2 hf2 (hS▸h0) have t:= @ὐ rw[w1,w2,ExactRuntime.roundDyadic_congr Fmt ה d1 d2 (λh=>h0 (e1.symm.trans ((t _).2 h))) (λh=>h0 (hS.trans (e2.symm.trans ((t _).2 h)))) (by rw[e1,e2,hS])] lemma dotOf_zero (n:Nat) (a b:Nat->Word) (hf: ∀t,texpOf (a t)≠255/\expOf (b t)≠255) (hS:(∑ j∈Ἣ n,rationalWord (a j)*rationalWord (b j))=0): dotOf n a b&&&В=0:=by rw[C.qD6 n a b hf hS] generalize (decide (n≠0)&&_)=s cases s<;>decide lemma gT_or (n:Nat) (hn:n<2^20) (hn0:0Word) (hx: ∀t,tgood (xw t)=true) (hw: ∀t,tgood (ww t)=true) (hv:Word) (hgv:good hv=true) (hpv:hv<=В) (hmv: ∀t,tww t&&&В<=hv) (s0 a:ὧ) (hs0:s0=(ἄ n).foldl (λacc t=>acc+dv (xw t)*dv (ww t)) 0) (ha:a=(ἄ n).foldl (λacc t=>acc+(dv (xw t)).abs) 0) (sl:Unit->Word): gT (D.loOf (nfOf n*(dv hv*a+xNA))) (D.spOf (D.loOf (nfOf n*(dv hv*a+xNA)))) (nfOf n*(dv hv*a+xNA)) s0 sl=sl ()\/ gT (D.loOf (nfOf n*(dv hv*a+xNA))) (D.spOf (D.loOf (nfOf n*(dv hv*a+xNA)))) (nfOf n*(dv hv*a+xNA)) s0 sl=dotOf n xw ww:=by by_cases h:gT (D.loOf (nfOf n*(dv hv*a+xNA))) (D.spOf (D.loOf (nfOf n*(dv hv*a+xNA)))) (nfOf n*(dv hv*a+xNA)) s0 sl=sl () · exact Or.inl h · refine Or.inr ?_ rw[<-gT_eq n hn hn0 xw ww hx hw hv hgv hpv hmv s0 a hs0 ha (λ_=>dotOf n xw ww) rfl] revert h unfold gT dsimp only split · split · intro h;exact absurd rfl h · intro _;rfl · intro _;rfl @[inline] def gZ (s0 e:ὧ) (sl:Unit->Word):Word:= let w:=ziv (s0+xNZ) e if w==Е then sl () else w lemma gZ_or (n:Nat) (hn:n<2^20) (xw ww:Nat->Word) (hx: ∀t,tgood (xw t)=true) (hw: ∀t,tgood (ww t)=true) (hv:Word) (hgv:good hv=true) (hpv:hv<=В) (hmv: ∀t,tww t&&&В<=hv) (s0 a:ὧ) (hs0:s0=(ἄ n).foldl (λacc t=>acc+dv (xw t)*dv (ww t)) 0) (ha:a=(ἄ n).foldl (λacc t=>acc+(dv (xw t)).abs) 0) (sl:Unit->Word): gZ s0 (nfOf n*(dv hv*a+xNA)) sl=sl ()\/ gZ s0 (nfOf n*(dv hv*a+xNA)) sl=dotOf (n+1) (λt=>if tif tacc+dv (xw t)*dv (ww t)) 0+dv س/\ nfOf n*(dv hv*a+xNA)= nfOf n*(dv hv*((ἄ n).foldl (λ(acc:ὧ) t=>acc+(dv (xw t)).abs) 0)+ (dv س).abs):=by rw[hs0,ha];exact ⟨rfl,rfl⟩ unfold gZ dsimp only split · exact Or.inl rfl · rename_i h2 refine Or.inr ?_ have hz:ziv (s0+xNZ) (nfOf n*(dv hv*a+xNA))≠Е:= λh=>h2 (by rw[h];rfl) obtain ⟨-,-,hbig⟩:=D.qBw _ _ hz obtain ⟨hlo,hhi⟩:=D.qC8 n hn xw ww س hv hx hw good_nz hgv hpv (ἄ n) (Ὂ) (λt ht=>List.mem_range.mp ht) (λt ht=>hmv t (List.mem_range.mp ht)) (λt ht hnot=>absurd (List.mem_range.mpr ht) hnot) (s0+xNZ) _ hs hbig exact D.qCn n hn xw ww س hx hw good_nz _ _ hlo hhi hz @[noinline] def hnSlow (H:Nat) (whh bhh h:ё) (u:Nat):Word:= Pinned.dotFn (H+1) (λj=>if jif jcandSlow inW H x wih bih t u hn r) if w&&&В==0 then candSlow inW H x wih bih t u hn r else w else candSlow inW H x wih bih t u hn r @[inline] def gruUX (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e a:ὧ) (hv:Word) (u:Nat):Word:= let gr:=gT lo sp e (S.get! (4*u)) (λ_=>xSlow inW H x wih whh bih bhh h t u) let gz:=gT lo sp e (S.get! (4*u+1)) (λ_=>xSlow inW H x wih whh bih bhh h t (H+u)) let ghn:=hnX H whh bhh h u (gT lo sp e (S.get! (4*u+2)) (λ_=>hnSlow H whh bhh h u)) let r:=sig gr updF (tanh (cdX inW H x wih bih t u (S.get! (4*u+3)) a hv ghn r)) (sig gz) h[u]! @[specialize] def grU (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e a:ὧ) (hv:Word):Nat->Nat->ё->ё | _,0,acc=>acc | u,n+1,acc=>grU sig tanh inW H x wih whh bih bhh h t S lo sp e a hv (u+1) n (acc.push (gruUX sig tanh inW H x wih whh bih bhh h t S lo sp e a hv u)) lemma grU_eq (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e a:ὧ) (hv:Word): ∀n k (acc:ё), acc=Array.ofFn (n:=k) (λi=>gruUX sig tanh inW H x wih whh bih bhh h t S lo sp e a hv i.val)-> grU sig tanh inW H x wih whh bih bhh h t S lo sp e a hv k n acc= Array.ofFn (n:=k+n) (λi=>gruUX sig tanh inW H x wih whh bih bhh h t S lo sp e a hv i.val) | 0,k,acc,h0=>by rw[grU,h0];rfl | n+1,k,acc,h0=>by rw[grU,grU_eq sig tanh inW H x wih whh bih bhh h t S lo sp e a hv n (k+1) _ (by rw[h0];exact push_ofFnA (λi=>gruUX sig tanh inW H x wih whh bih bhh h t S lo sp e a hv i) k), show k+1+n=k+(n+1) by omega] @[inline] def gruUX2 (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e a:ὧ) (hv:Word) (hs:S.size<2^32) (u:Nat) (o:ὦ) (ho:o.toNat=4*u) (hS:4*u+3xSlow inW H x wih whh bih bhh h t u) let gz:=gT lo sp e (S.uget (o+ὴ 1) (oK S o u 1 (by decide) ho hS hs).2) (λ_=>xSlow inW H x wih whh bih bhh h t (H+u)) let ghn:=hnX H whh bhh h u (gT lo sp e (S.uget (o+ὴ 2) (oK S o u 2 (by decide) ho hS hs).2) (λ_=>hnSlow H whh bhh h u)) let r:=sig gr updF (tanh (cdX inW H x wih bih t u (S.uget (o+ὴ 3) (oK S o u 3 (by decide) ho hS hs).2) a hv ghn r)) (sig gz) h[u]! @[specialize] def grU2 (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e a:ὧ) (hv:Word) (hs:S.size<2^32): (n u:Nat)->(o:ὦ)->o.toNat=4*u->4*(u+n)<=S.size->ё->ё | 0,_,_,_,_,acc=>acc | n+1,u,o,ho,hn,acc=>grU2 sig tanh inW H x wih whh bih bhh h t S lo sp e a hv hs n (u+1) (o+ὴ 4) (o4 S o u ho (by omega) hs) (by omega) (acc.push (gruUX2 sig tanh inW H x wih whh bih bhh h t S lo sp e a hv hs u o ho (by omega))) lemma grU2_eq (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e a:ὧ) (hv:Word) (hs:S.size<2^32): ∀n u o (ho:o.toNat=4*u) (hn:4*(u+n)<=S.size) acc, grU2 sig tanh inW H x wih whh bih bhh h t S lo sp e a hv hs n u o ho hn acc= grU sig tanh inW H x wih whh bih bhh h t S lo sp e a hv u n acc | 0,_,_,_,_,_=>rfl | n+1,u,o,ho,hn,acc=>by have hS:4*u+3Word) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (S:ὤ) (lo sp:Ὠ) (e a:ὧ) (hv:Word): (if hS:S.size<2^32/\4*(0+H)<=S.size then grU2 sig tanh inW H x wih whh bih bhh h t S lo sp e a hv hS.1 H 0 0 rfl hS.2 (Array.emptyWithCapacity H) else grU sig tanh inW H x wih whh bih bhh h t S lo sp e a hv 0 H (Array.emptyWithCapacity H))= grU sig tanh inW H x wih whh bih bhh h t S lo sp e a hv 0 H (Array.emptyWithCapacity H):=by split · exact grU2_eq _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ · rfl @[specialize] def gruStepX (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh:ё) (P:ὤ) (hv:Word) (t:Nat) (st:ё×ё):ё×ё:= if hc:st.1.all good=true then if hk:inW+H+3<2^20/\P.size<2^32 then let V:=vOf inW H x st.1 t let a:=aS V 0 (inW+H+2) 0 let e:=nfOf (inW+H+2)*(dv hv*a+xNA) let lo:=D.loOf e let S:=xSum true inW H wih whh bih bhh V P (vx_le inW H x st.1 t hk.1) hk.2 ((if hS:S.size<2^32/\4*(0+H)<=S.size then grU2 sig tanh inW H x wih whh bih bhh st.1 t S lo (D.spOf lo) e a hv hS.1 H 0 0 rfl hS.2 (Array.emptyWithCapacity H) else grU sig tanh inW H x wih whh bih bhh st.1 t S lo (D.spOf lo) e a hv 0 H (Array.emptyWithCapacity H)),st.2) else gruStepWith Pinned.dotFn sig tanh inW H x wih whh bih bhh t st else gruStepWith Pinned.dotFn sig tanh inW H x wih whh bih bhh t st lemma rw_zero (w:Word):rationalWord w*rationalWord 0=0:=by rw[rat_zero,mul_zero] lemma gX_x (inW H:Nat) (x h:ё) (t j:Nat) (hj:j< inW):gX inW H x h t j=x[t*inW+j]!:=by unfold gX;rw[Ὦ hj] lemma gX_h (inW H:Nat) (x h:ё) (t j:Nat) (hj:jby rw[wHN_x _ _ _ _ _ _ (Finset.mem_range.mp hj)];exact rw_zero _ rw[e1,zero_add,wHN_1,rw_zero,add_zero,wHN_2,gX_1 _ _ _ _ _ _ א,Ὧ (Nat.lt_irrefl H), Ὧ (Nat.lt_irrefl H)] congr 1 refine Ἷ rfl λj hj=>?_ have:=Finset.mem_range.mp hj rw[gX_h _ _ _ _ _ _ this,wHN_h _ _ _ _ _ _ this,Ὦ this,Ὦ this] lemma cd_sum (inW H:Nat) (x wih bih h:ё) (t u:Nat) (hn r:Word): (∑ j∈Ἣ (inW+H+2+1), rationalWord (if j< inW+H+2 then gX inW H x h t j else hn)* rationalWord (if j< inW+H+2 then wCD inW H wih bih u j else r))= ∑ j∈Ἣ (inW+2), rationalWord (if j< inW then x[t*inW+j]! else if j=inW then oneW else hn)* rationalWord (if j< inW then wih[(2*H+u)*inW+j]! else if j=inW then bih[2*H+u]! else r):=by rw[Finset.sum_range_succ,Ὧ (Nat.lt_irrefl _),Ὧ (Nat.lt_irrefl _), show inW+H+2=inW+H+1+1 by omega,Finset.sum_range_succ,Finset.sum_range_succ, Finset.sum_range_add,show inW+2=inW+1+1 by omega,Finset.sum_range_succ,Finset.sum_range_succ] have e1: ∑ j∈Ἣ H,rationalWord (if inW+j< inW+H+1+1 then gX inW H x h t (inW+j) else hn)* rationalWord (if inW+j< inW+H+1+1 then wCD inW H wih bih u (inW+j) else r)=0:= Finset.sum_eq_zero λj hj=>by have:=Finset.mem_range.mp hj rw[Ὦ א,Ὦ א,wCD_h _ _ _ _ _ _ this];exact rw_zero _ rw[e1,add_zero,Ὦ א,Ὦ א,Ὦ א,Ὦ א,wCD_2,rw_zero, add_zero,wCD_1,gX_1 _ _ _ _ _ _ א,Ὧ (Nat.lt_irrefl _),Ὦ rfl,Ὧ (Nat.lt_irrefl _), Ὦ rfl,Ὧ א,Ὧ א,Ὧ א,Ὧ א] congr 2 refine Ἷ rfl λj hj=>?_ have:=Finset.mem_range.mp hj rw[Ὦ א,Ὦ א,gX_x _ _ _ _ _ _ this,wCD_x _ _ _ _ _ _ this,Ὦ this,Ὦ this] end RnnX5 section RnnX6 lemma slotF (gru:Ὡ) (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (hk:inW+H+3<2^20/\(xpOf gru inW H wih whh bih bhh).1.size<2^32) (u g:Nat) (hu:uWord) (hww: ∀j,ww j=wfX gru inW H wih whh bih bhh u g j): (xSum gru inW H wih whh bih bhh (vOf inW H x h t) (xpOf gru inW H wih whh bih bhh).1 (vx_le inW H x h t hk.1) hk.2).get! (4*u+g)=(ἄ (inW+H+2)).foldl (λacc j=>acc+dv (gX inW H x h t j)*dv (ww j)) 0/\ aS (vOf inW H x h t) 0 (inW+H+2) 0= (ἄ (inW+H+2)).foldl (λacc j=>acc+(dv (gX inW H x h t j)).abs) 0:=by obtain ⟨hVs,hVg⟩:=vOf_spec inW H x h t refine ⟨?_,?_⟩ · have:=slot_eq H (inW+H+2) (wfX gru inW H wih whh bih bhh) (vOf inW H x h t) א hVs (gX inW H x h t) hVg hk.2 (vx_le inW H x h t hk.1) u g hu hg simp only[<-hww] at this exact this · rw[aS_eq,<-ὗ] exact foldl_ext _ _ _ _ λj hj b=>by rw[hVg j (List.mem_range.mp hj)] lemma hnX_eq (inW H:Nat) (x wih whh bih bhh h:ё) (t:Nat) (hq:(xpOf true inW H wih whh bih bhh).2.2=true) (hx: ∀i:Nat,good x[i]! =true) (hc:h.all good=true) (hk:inW+H+3<2^20/\(xpOf true inW H wih whh bih bhh).1.size<2^32) (u:Nat) (hu:uhnSlow H whh bhh h u))= hnSlow H whh bhh h u:=by intro V e S obtain ⟨q,-,-,-⟩:=xq_of true inW H wih whh bih bhh hq obtain ⟨hS,ha⟩:=slotF true inW H x wih whh bih bhh h t hk u 2 hu ה (wHN inW H whh bhh u) (λj=>rfl) have hwg: ∀j,good (wHN inW H whh bhh u j)=true/\wHN inW H whh bhh u j&&&В<= (xpOf true inW H wih whh bih bhh).2.1:= λj=>by unfold wHN split · exact ⟨good_zero,by rw[show (0:Word)&&&В=0 from rfl];exact UInt32.zero_le⟩ split · exact ⟨q.gu _,q.lu _⟩ split · exact ⟨good_zero,by rw[show (0:Word)&&&В=0 from rfl];exact UInt32.zero_le⟩ · exact ⟨q.gc _,q.lc _⟩ have hf1: ∀j,j< inW+H+2->expOf (gX inW H x h t j)≠255/\expOf (wHN inW H whh bhh u j)≠255:= λj _=>⟨qAe _ (gX_good inW H x h t hx hc j),qAe _ (hwg j).1⟩ rcases gT_or (inW+H+2) א א (gX inW H x h t) (wHN inW H whh bhh u) (λj _=>gX_good inW H x h t hx hc j) (λj _=>(hwg j).1) _ q.gv q.pv (λj _=>(hwg j).2) _ _ hS ha (λ_=>hnSlow H whh bhh h u) with h1 | h1 · rw[h1];unfold hnX;split<;>rfl · rw[h1] unfold hnX split · rfl · rename_i hnz have h0:(∑ j∈Ἣ (inW+H+2),rationalWord (gX inW H x h t j)* rationalWord (wHN inW H whh bhh u j))≠0:= λhz=> hnz (by rw[dotOf_zero _ _ _ hf1 hz];rfl) unfold hnSlow rw[Pinned.dotFn_eq_dotOf] refine dotOf_sum _ _ _ _ _ _ hf1 (λj hj=>?_) (hn_sum inW H x whh bhh h t u) h0 by_cases hjH:jrfl) unfold cdX split · rename_i hg simp only[Bool.and_eq_true,decide_eq_true_eq] at hg obtain ⟨⟨ghn,gr⟩,rle⟩:=hg let K:=inW+H+2 let xw:Nat->Word:= λj=>if jWord:= λj=>if jby unfold wCD split · exact ⟨q.gw _,q.lw _⟩ split · exact ⟨good_zero,by rw[show (0:Word)&&&В=0 from rfl];exact UInt32.zero_le⟩ split · exact ⟨q.gb _,q.lb _⟩ · exact ⟨good_zero,by rw[show (0:Word)&&&В=0 from rfl];exact UInt32.zero_le⟩ have hxg: ∀j,jgood (xw j)=true:= λj _=>by show good (if jgood (ww j)=true/\ww j&&&В<=(xpOf true inW H wih whh bih bhh).2.1:= λj _=>by show good (if jacc+dv (xw j)*dv (ww j)) 0:=by rw[List.range_succ,List.foldl_append,hS] simp only[ὔ,List.foldl_nil,xw,ww,Nat.lt_irrefl,ite_false] congr 1 exact foldl_ext _ _ _ _ λj hj b=>by rw[Ὦ (List.mem_range.mp hj),Ὦ (List.mem_range.mp hj)] have ha0:aS V 0 (inW+H+2) 0+(dv hn).abs= (ἄ (K+1)).foldl (λacc j=>acc+(dv (xw j)).abs) 0:=by rw[List.range_succ,List.foldl_append,ha] simp only[ὔ,List.foldl_nil,xw,Nat.lt_irrefl,ite_false] congr 1 exact foldl_ext _ _ _ _ λj hj b=>by rw[Ὦ (List.mem_range.mp hj)] have hf1: ∀j,jexpOf (xw j)≠255/\expOf (ww j)≠255:= λj hj=>⟨qAe _ (hxg j hj),qAe _ (hwg' j hj).1⟩ dsimp only rcases gZ_or (K+1) א xw ww hxg (λj hj=>(hwg' j hj).1) _ q.gv q.pv (λj hj=>(hwg' j hj).2) _ _ hs0 ha0 (λ_=>candSlow inW H x wih bih t u hn r) with h1 | h1 · rw[h1];split<;>rfl · rw[h1,C.qI0 (K+1) xw ww א hf1] split · rfl · rename_i hnz have h0:(∑ j∈Ἣ (K+1),rationalWord (xw j)*rationalWord (ww j))≠0:= λhz=> hnz (by rw[dotOf_zero _ _ _ hf1 hz];rfl) unfold candSlow rw[Pinned.dotFn_eq_dotOf] refine dotOf_sum _ _ _ _ _ _ hf1 (λj hj=>?_) (cd_sum inW H x wih bih h t u hn r) h0 by_cases j1:j< inW · rw[Ὦ j1,Ὦ j1];exact ⟨qAe _ (hx _),qAe _ (q.gw _)⟩ · by_cases j2:j=inW · subst j2;rw[Ὧ (Nat.lt_irrefl _),Ὦ rfl,Ὧ (Nat.lt_irrefl _),Ὦ rfl] exact ⟨qAe _ good_one,qAe _ (q.gb _)⟩ · rw[Ὧ j1,Ὧ j2,Ὧ j1,Ὧ j2];exact ⟨qAe _ ghn,qAe _ gr⟩ · rfl lemma gruStepX_eq (sig tanh:Word->Word) (inW H:Nat) (x wih whh bih bhh:ё) (hq:(xpOf true inW H wih whh bih bhh).2.2=true) (hx: ∀i:Nat,good x[i]! =true): gruStepX sig tanh inW H x wih whh bih bhh (xpOf true inW H wih whh bih bhh).1 (xpOf true inW H wih whh bih bhh).2.1= gruStepWith Pinned.dotFn sig tanh inW H x wih whh bih bhh:=by funext t st obtain ⟨q,-,-,-⟩:=xq_of true inW H wih whh bih bhh hq unfold gruStepX split · rename_i hc split · rename_i hk have hg: ∀g u,ug<2-> gT (D.loOf (nfOf (inW+H+2)*(dv (xpOf true inW H wih whh bih bhh).2.1* aS (vOf inW H x st.1 t) 0 (inW+H+2) 0+xNA))) (D.spOf (D.loOf (nfOf (inW+H+2)*(dv (xpOf true inW H wih whh bih bhh).2.1* aS (vOf inW H x st.1 t) 0 (inW+H+2) 0+xNA)))) (nfOf (inW+H+2)*(dv (xpOf true inW H wih whh bih bhh).2.1* aS (vOf inW H x st.1 t) 0 (inW+H+2) 0+xNA)) ((xSum true inW H wih whh bih bhh (vOf inW H x st.1 t) (xpOf true inW H wih whh bih bhh).1 (vx_le inW H x st.1 t hk.1) hk.2).get! (4*u+g)) (λ_=>xSlow inW H x wih whh bih bhh st.1 t (g*H+u))= gateWith Pinned.dotFn inW H x wih whh bih bhh st.1 t (g*H+u):= λg u hu hg2=>by rw[Pinned.dotFn_eq_dotOf] exact gateX_eq true inW H x wih whh bih bhh st.1 t hq hx hc hk u g hu א (gWt inW H wih whh bih bhh (g*H+u)) (λj=>by unfold wfX;rw[Ὦ rfl,Ὦ hg2]) _ (by unfold xSlow;rw[Pinned.dotFn_eq_dotOf]) (λj=>gWt_good q _ j) dsimp only rw[dite_grU,grU_eq _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ H 0 _ (by rfl),Ἇ] unfold gruStepWith simp only[] congr 1 congr 1;funext u unfold gruUX rw[updF_eq] repeat (rw[ofFn_get!F _ _ u.isLt];try dsimp only) have h0:=hg 0 u.val u.isLt ה have h1:=hg 1 u.val u.isLt ה simp only[ὒ,Ἇ,Ὑ,Ἵ] at h0 h1 have hn:=hnX_eq inW H x wih whh bih bhh st.1 t hq hx hc hk u.val u.isLt simp only[] at hn rw[h0,h1,hn,cdX_eq inW H x wih whh bih bhh st.1 t hq hx hc hk u.val u.isLt] unfold candSlow hnSlow rfl · rfl · rfl @[specialize] def gruLX (sig tanh:Word->Word) (T inW H:Nat) (x wih whh bih bhh:ё):ё:= let p:=(xpGet true inW H wih whh bih bhh).1 if p.2.2&&x.all good then recFlat (gruStepX sig tanh inW H x wih whh bih bhh p.1 p.2.1) 0 T (ἇ H 0, #[]) (Array.emptyWithCapacity (T*H)) else gruWith Pinned.dotFn sig tanh T inW H x wih whh bih bhh lemma gruLX_eq (sig tanh:Word->Word):gruLX sig tanh=gruWith Pinned.dotFn sig tanh:=by funext T inW H x wih whh bih bhh unfold gruLX rw[(xpGet true inW H wih whh bih bhh).2] dsimp only split · rename_i hq simp only[Bool.and_eq_true] at hq rw[gruStepX_eq sig tanh inW H x wih whh bih bhh hq.1 (all_good x hq.2), recFlat_eq T H _ _ (λt st=>by unfold gruStepWith;exact Array.size_ofFn)] rfl · rfl end RnnX6 end RnnFast def kernels:Kernels where core:=specCore dense:=⟨C.linG2,C.gemmC2⟩ conv:=⟨ConvFast.conv2dF,ConvFast.depthwiseF,Pinned.kernels.conv.convTranspose⟩ elem:=⟨ConvFast.avgpoolF,ConvFast.maxpoolF,C.addF,C.scaleF⟩ norm:=⟨D.rmsF,D.lnF⟩ attn:=specAttn rnn:=⟨RnnFast.lstmLX RnnFast.sigmoidF2 RnnFast.tanhF2,RnnFast.gruLX RnnFast.sigmoidF2 RnnFast.tanhF2⟩ lemma correct:Obligation kernels:=by have hP:=Pinned.correct have hc:Pinned.kernels.conv=specConv:=congrArg Kernels.conv hP refine obligation_of_families kernels rfl ?_ ?_ ?_ ?_ ?_ ?_ · show (⟨C.linG2,C.gemmC2⟩:DenseKernels)=specDense rw[C.qHb2,C.qGm2];rfl · show (⟨ConvFast.conv2dF,ConvFast.depthwiseF,Pinned.kernels.conv.convTranspose⟩:ConvKernels)=specConv rw[ConvFast.conv2dF_eq,ConvFast.depthwiseF_eq, show Pinned.kernels.conv.convTranspose=convTransposeSpec from congrArg ConvKernels.convTranspose hc];rfl · show (⟨ConvFast.avgpoolF,ConvFast.maxpoolF,C.addF,C.scaleF⟩:ElementKernels)=specElem rw[ConvFast.avgpoolF_eq,ConvFast.maxpoolF_eq,C.qFu,C.qFf];rfl · show (⟨D.rmsF,D.lnF⟩:NormKernels)=specNorm rw[D.qFf,D.qGc];rfl · exact rfl · show (⟨RnnFast.lstmLX RnnFast.sigmoidF2 RnnFast.tanhF2,RnnFast.gruLX RnnFast.sigmoidF2 RnnFast.tanhF2⟩:RecurrentKernels)=specRnn rw[RnnFast.lstmLX_eq,RnnFast.gruLX_eq,RnnFast.sigmoidF2_eq,RnnFast.tanhF2_eq,FastAct.sigmoidF_eq,FastAct.tanhF_eq,Pinned.dotFn_eq_dotOf];rfl end Submission