import ContractExact set_option maxRecDepth 8192 set_option maxHeartbeats 4000000 namespace Submission open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats open ExactRuntime renaming idxOf->γ,Word->δ,mantOf->ε,oneW->ζ,signOf->η,expOf->θ,ofW->ι,Fmt->κ,toWord->π,finishWord->ρ,ConvShape->σ,dotOf->Β,windowAt->Δ,decodeD->Ο,decodeD_toRat->ϕ,mantOf_lt_24->ϖ,toDyadic_ofUInt32->Ϟ,finishWord_scale->ἄ,isFinite_ofUInt32->ἐ,decodeD_negative->ἑ open Nat renaming mod_eq_of_lt->ν,shiftLeft_eq->υ,two_pow_pos->ψ,shiftRight_eq_div_pow->ω,mul_le_mul_right->Ε,pow_le_pow_right->Η,pow_add->Θ,zero_add->Λ,le_trans->Μ,mod_lt->Χ,lt_of_le_of_lt->ϊ,mul_comm->ό,mul_pos->ύ,div_eq_of_lt->ϑ,pos_of_ne_zero->ϒ,and_two_pow_sub_one_eq_mod->Ϙ,add_mul_div_right->ϙ,lt_of_lt_of_le->ϛ,mul_zero->Ϝ,add_comm->ϝ,le_mul_of_pos_right->ϟ,div_div_eq_div_mul->Ϡ,mul_assoc->ϡ,add_mul->Ϣ,add_mul_mod_self_right->Ϧ,zero_mul->Ϫ,one_mul->ϫ,lt_of_le_of_ne->ϰ,log2_self_le->ϲ,le_add_right->ϳ,div_lt_of_lt_mul->Ϸ,mul_eq_zero->ϸ,eq_zero_or_pos->Ϲ,div_add_mod'->Ϻ,cast_sub->ἂ,mul_lt_mul_of_pos_right->ἇ,le_mul_of_pos_left->Ἀ,lt_log2_self->Ἂ,toUInt64_eq->Ἄ,log2_eq_iff->Ἅ,add_le_add->Ἆ,add_zero->Ἇ,mul_lt_mul_of_lt_of_le->ἕ,le_div_iff_mul_le->Ἑ,div_lt_iff_lt_mul->Ἒ,div_add_mod->ἦ,mul_le_mul->Ἢ,cast_ofNat->Ἣ,pos_iff_ne_zero->Ἧ,div_mul_le_self->ἲ,le_one_iff_eq_zero_or_eq_one->ἷ open UInt64 renaming toNat_add->ξ,toNat_inj->ο,toNat_sub_of_le->Α,toNat_shiftRight->Ζ,lt_iff_toNat_lt->Ι,le_iff_toNat_le->Κ,toNat_shiftLeft->Ρ,toNat_sub->Φ,le_iff_toNat_le->ϐ,toNat_zero->ϔ,toNat_lt_size->Ϛ,toNat_toUInt32->ϧ,toNat_lt->Ϩ,le_iff_toNat_le->Ϯ,toNat_mul->ϱ,toNat_inj->ἡ,toNat_and->ἢ,toNat->Ἡ,toNat_ofNat'->ἱ open USize renaming lt_iff_toNat_lt->τ,le_size->φ,size->Ξ,lt_iff_toNat_lt->ϋ,toNat_one->ϻ,toNat_sub_of_le->ἰ,toNat_inj->ἶ open Bool renaming false_eq_true->χ,xor->Γ,and_eq_true->ϓ,or_eq_true->ἀ,eq_iff_iff->ἁ,not_eq_true'->ἠ,false_ne_true->ἳ open UInt32 renaming toNat_inj->Ν,ofNat->ϣ,toNat_toUInt64->ϯ,toNat_shiftRight->϶,toNat_lt_size->Ἁ,le_iff_toNat_le->Ἐ,toNat_ofNat'->Ἓ,toNat_and->ἣ,toNat_toUSize->ἥ,toNat_inj->Ἥ,lt_iff_toNat_lt->Ἦ open List renaming range'_succ->ϴ,ext_getElem->ἤ,foldl_cons->ἧ open Array renaming replicate->Υ,getElem_ofFn->Ἃ,size_ofFn->Ἠ,ofFn->Ἲ open Or renaming inl->Ω open Model renaming toReal->ϥ,roundDyadicGeneral->ἒ,addDyadic->ἓ,isFinite->ἔ,roundDyadicGeneral_eq_roundDyadic->Ἤ open Int renaming add_emod->ϩ,negSucc->ἃ open Int64 renaming ofInt->ϵ open FloatLib.Numerics renaming roundShiftRightEven->ἵ,shiftRightJam->Ἰ open Model.Reduction.Internal renaming State->Ἱ open Array renaming mkEmpty->kA,size_uset->kB,size_replicate->kg,ext->kj,toList_empty->kr,size_extract->kt,uset_eq_set->ky,getElem_set->kz,mkEmpty_eq->KH,ugetElem_eq_getElem->KR,getElem_replicate->KX open USize renaming toNat_zero->kC,le_iff_toNat_le->kD,ofNat_toNat->kH,ofNat_add->kS,toNat->KI,toNat_mul->KJ,toNat_add->KK,ofNat_mul->KL,zero_add->KP open Model renaming packRoundedSubnormal->kE,isNaN->kG,nativeOverflow->kI,packRoundedNormal->kJ,isInf_eq_false_of_toDyadic?_some->kM,div->kN,ofUInt32->kO,ofFields->kP,zero->kQ,pow2->kp,fma->KG,fracField_ofFields->KS,expField_ofFields->KV open UInt32 renaming toUInt32_toUInt64->kF,toNat_sub_of_le->kZ,toNat->kv,toNat_shiftLeft->KU open Nat renaming log2_lt->kK,reducePow->kL,add_assoc->kR,shiftLeft_add_eq_or_of_lt->kT,sub_zero->kV,sub_add_cancel->kW,mul_add_mod_self_right->kX,toUSize->kY,pos_of_mul_pos_left->kc,and_le_right->kd,le_of_eq->ke,div_le_self->kf,and_two_pow_sub_one_of_lt_two_pow->km,add_le_add_left->ko,zero_div->KC,testBit_eq_decide_div_mod_eq->KD,lt_trans->KE,div_self->KF,mod_one->KN,min_eq_left->KQ open UInt64 renaming reduceToNat->kU,toNat_not->KA,add_assoc->KB open List renaming range'->ki,nil_append->KO,drop_eq_getElem_cons->KT,map_cons->KW open Bool renaming true_and->kq open Int renaming natAbs_natCast->kx,ModEq->KM local notation:max x:max "˟"=>UInt64.toNat (x :) local notation:max x:max "߷"=>KI (x :) local notation:max x:max "؟"=>kv (x :) local notation:max x:max "۞"=>kY (x :) local notation:max x:max "۩"=>Nat.log2 (x :) local notation:max x:max "܁"=>Fin.val (x :) local notation:max x:max "܆"=>Array.size (x :) local notation:max x:max "܋"=>ExactRuntime.ConvShape.stride (x :) local notation:max x:max "܌"=>UInt32.toUInt64 (x :) local notation:max x:max "߾"=>UInt64.toNat_lt (x :) local notation:max x:max "֍"=>Array.toList (x :) local notation:max x:max "؉"=>FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.fracWidth (x :) local notation:max x:max "؛"=>UInt64.toUInt32 (x :) local notation:max x:max "؝"=>Nat.toUInt64 (x :) local notation:max x:max "٪"=>Int.toNat (x :) local notation"א"=>by omega local notation"ב"=>by norm_num local notation"ג"=>by simp local notation"ד"=>by decide local notation"ה"=>by positivity local notation"ו"=>by simp;omega local notation"ז"=>by grind local notation"ח"=>by ring local notation"ט"=>by simp_all local notation"߿"=>0x80000000 local notation"ר"=>0x100000000 local notation"ש"=>0x7FFFFFFF local notation"ת"=>ite_true local notation"ؠ"=>ite_false local notation"ء"=>decide_eq_true_eq local notation"ا"=>zpow_natCast local notation"ث"=>decide_eq_true_iff local notation"ذ"=>getElem!_pos local notation"غ"=>Fmt.minSubnormalExponent local notation"ق"=>UInt64 local notation"ك"=>UInt32 local notation"ل"=>Array local notation"م"=>USize local notation"ه"=>Bool local notation"ٽ"=>Nat local notation"پ"=>Int local notation"ٿ"=>Model.isNaN_eq_false_of_toDyadic?_some local postfix:max"چ"=>Array.size local postfix:max"ڇ"=>UInt64.toNat local postfix:max"ڇ"=>KI local postfix:max"ڇ"=>kv local postfix:max"ڇ"=>Int.toNat local postfix:max"ڈ"=>kY local postfix:max"ڈ"=>UInt64.toUSize local postfix:max"ڈ"=>UInt32.toUSize local notation:max"ډ"k:max=>Array.ofFn (n:=k) @[inline] def Yn (n:Nat) (a b:Nat→UInt32):UInt32:=dotOf n a b lemma Zn (a b:ك):(if Γ (η a) (η b) then -((ε a*ε b:ٽ):پ) else ((ε a*ε b:ٽ):پ))=sv a*sv b:=by unfold sv;cases η a<;>cases η b<;>simp lemma Ze (n:ٽ) (f:ٽ -> ك) (k:ٽ) (a:kf i܁)[k]! = f k:=ט lemma Zi:Yn=dotOf:=rfl lemma O0 (w:δ):π (ι w)=w:=by apply Ν.mp;simp only[toWord,ofW,Model.toNatBits,ofUInt32_bits];exact ν w.toBitVec.isLt lemma N9 (z:Model κ):ι (π z)=z:=by have h:z.toNatBits<2^32:=Model.toNatBits_lt_two_pow z;simp only[ofW,toWord,kO,Ἓ,ν h];exact Model.ofNatBits_toNatBits z lemma ZH (w:ك):(θ w)؟=w؟/2^23%256:=by simp only[expOf,ἣ,϶,ω];exact Ϙ _ 8 lemma ZR (w:ك):(fracOf w)؟=w؟%2^23:=by exact Ϙ _ 23 def Yo (fa fb:ٽ -> ك) (i:ٽ):ٽ -> پ | 0=>0 | r+1=>sv (fa i)*sv (fb i)*2^(γ (fa i)+γ (fb i))+Yo fa fb (i+1) r def Yq (fa fb:ٽ -> ك) (i:ٽ):ٽ -> ه | 0=>true | r+1=>(decide (ε (fa i)*ε (fb i)=0)&&Γ (η (fa i)) (η (fb i))) && Yq fa fb (i+1) r lemma eP (n:ٽ) (a b:ٽ -> ك) (i r:ٽ) (h:i+r<=n):dsum (ډ n λ k=>a k܁) (ډ n λ k=>b k܁) i r=Yo a b i r:=by induction r generalizing i with | zero=>rfl | succ r d=>rw[dsum,Yo,Ze n a i א,Ze n b i א,d (i+1) א] lemma eO (n:ٽ) (a b:ٽ -> ك) (i r:ٽ) (h:i+r<=n):dallNZ (ډ n λ k=>a k܁) (ډ n λ k=>b k܁) i r=Yq a b i r:=by induction r generalizing i with | zero=>rfl | succ r d=>rw[dallNZ,Yq,Ze n a i א,Ze n b i א,d (i+1) א] lemma bZ (A B:Array UInt32)(hAB:A.size=B.size) (g:∀ k,k k expOf 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 let n:=A.size let S:=dsum A B 0 n have l:S=dsum A B 0 n:=rfl have w:A.size=n:=rfl have x:B.size=n:=hAB.symm change finishWord S (-298) (decide (n≠0)&&dallNZ A B 0 n)=dotSpec A B set L:=A.map (kO (fmt:=κ)) with f set R:=B.map (kO (fmt:=κ)) with F have e:Lچ=Rچ:=ז have y:Lچ=n:=ז have p:∀ k (q:ka i.val) let B:=Ἲ (n:=n) (fun i=>b i.val) have hAB:A.size=B.size:=by simp[A,B] have fin:∀ k,ka i.val))[k]!)≠255 ∧ expOf ((Ἲ (n:=n) (fun i=>b i.val))[k]!)≠255 rw[Ze n a k kn,Ze n b k kn] exact d k kn have H:=bZ A B hAB fin change dotSpec A B=_ rw[← H] simp only[A,B,Ἠ,eP n a b 0 n (by omega),eO n a b 0 n (by omega)] def YC (w2 w1 w0:ق):پ := ((w2ڇ*2^128+w1ڇ*2^64+w0ڇ:ٽ):پ) - (if w2ڇ<2^63 then 0 else 2^192) def Ym (w:ق):پ:=(wڇ:پ)-(if wڇ<2^63 then 0 else 2^64) lemma eN (s:ه) (E F:ٽ) (b:E<256) (a:F<2^23):(kP κ s E F).toNatBits=(if s then 2^31 else 0)+E*2^23+F:=by rw[Model.ofFields_eq_ofFieldsImpl];simp only[Model.ofFieldsImpl,Model.mkBitsImpl,Model.ofBits,Model.toNatBits,BitVec.toNat_ofNatLT];have d:E&&&Fmt.expAllOnesNat=E:=km (n:=8) b;have e:F&&&Fmt.fracMaskNat=F:=km (n:=23) a;rw[d,e,show E.shiftLeft Fmt؉=E<<<23 from rfl,Nat.or_assoc,<- kT a] have f:E<<<23+F<2^31:=א cases s . simp[υ] . simp only[ת];rw[show Nat.shiftLeft 1 (Fmt.expWidth+Fmt؉)=1<<<31 from rfl,<- kT f];simp;omega @[inline] def Yv (neg:ه) (E F:ك):ك:=(if neg then (0x80000000:ك) else 0)+(E<<<23)+F lemma ZT (a:ه) (E F:ك) (b:E؟<256) (d:F؟<2^23):Yv a E F=π (kP κ a E؟ F؟):=by unfold toWord;rw[eN a _ _ b d];apply Ν.mp;unfold Yv;cases a<;>simp<;>omega lemma N7 (a:ه):Yv a 255 0=π (kI κ a):=by rw[Model.nativeOverflow_eq_signedInf_of_isIEEE Fmt ד];cases a<;>decide lemma eM (a:ه):Yv a 0 0=π (kQ κ a):=by cases a<;>decide lemma af (x:ق) (d:ٽ) (hd:d<64): (x>>>d.toUInt64)˟.log2=x˟.log2-d:=by have dm:d.toUInt64˟=d:=ν (by omega) rw[Ζ,dm,ν hd, ω,Nat.log2_eq_log_two,Nat.log_div_base_pow,←Nat.log2_eq_log_two] lemma ag(x r:ق)(d:ٽ)(hd:0= (2^d).toUInt64 let rn:=if h then r+d.toUInt64 else r let xn:=if h then x>>>d.toUInt64 else x rn˟+xn˟.log2=r˟+x˟.log2 ∧ xn˟.log2= (2^d).toUInt64 · simp only[h,ite_true] have hh:2^d<=x˟:=by simpa only[Κ,pm] using h have hn:x˟≠0:=by have:=ψ d;omega have ld:d<=x˟.log2:=(Nat.le_log2 hn).mpr hh rw[ξ,dm,af x d hD] omega · simp only[h,ite_false] have hh:x˟<2^d:=by change ¬(2^d).toUInt64 <= x at h rw[Κ,pm]at h;omega by_cases hn:x˟=0 · simp[hn,hd] · exact ⟨trivial,(kK hn).mpr hh⟩ def aa : ByteArray:=⟨Ἲ (fun i:Fin 256=>i.val.log2.toUInt8)⟩ lemma ab (x:UInt64): let x1:=if x>=4294967296 then x>>>32 else x let x2:=if x1>=65536 then x1>>>16 else x1 let x3:=if x2>=256 then x2>>>8 else x2 x3.toNat<256:=by have lim:x.toNat.log2<64:=by by_cases h:x.toNat=0 · simp[h] · exact (kK h).mpr x.toNat_lt let r0:UInt64:=0 have hz:r0.toNat=0:=rfl let r1:UInt64:=if x >= 4294967296 then r0+32 else r0 let x1:UInt64:=if x >= 4294967296 then x>>>32 else x have t1:r1.toNat+x1.toNat.log2=r0.toNat+x.toNat.log2 ∧ x1.toNat.log2<32:=ag x r0 32 (by decide) (by decide) (by simpa[r0] using lim) lim let r2:UInt64:=if x1 >= 65536 then r1+16 else r1 let x2:UInt64:=if x1 >= 65536 then x1>>>16 else x1 have t2:r2.toNat+x2.toNat.log2=r1.toNat+x1.toNat.log2 ∧ x2.toNat.log2<16:=ag x1 r1 16 (by decide) (by decide) (by simp only[r0,ϔ,Λ]at t1;omega) (by omega) let r3:UInt64:=if x2 >= 256 then r2+8 else r2 let x3:UInt64:=if x2 >= 256 then x2>>>8 else x2 have t3:r3.toNat+x3.toNat.log2=r2.toNat+x2.toNat.log2 ∧ x3.toNat.log2<8:=ag x2 r2 8 (by decide) (by decide) (by omega) (by omega) change x3.toNat<256 by_cases hn:x3.toNat=0 · omega · exact (kK hn).mp t3.2 @[inline] def ac (x:UInt64):UInt64:= let r0:UInt64:=0 let r1:UInt64:=if x >= 4294967296 then r0+32 else r0 let x1:UInt64:=if x >= 4294967296 then x>>>32 else x let r2:UInt64:=if x1 >= 65536 then r1+16 else r1 let x2:UInt64:=if x1 >= 65536 then x1>>>16 else x1 let r3:UInt64:=if x2 >= 256 then r2+8 else r2 let x3:UInt64:=if x2 >= 256 then x2>>>8 else x2 r3+(aa.uget x3.toUSize (by change x3.toUSize.toNat<256 rw[UInt64.toNat_toUSize] exact ϊ (Nat.mod_le _ _) (ab x))).toUInt64 lemma ad (x:UInt64) (h:x.toNat<256) (hx:x.toUSize.toNat= 4294967296 then r0+32 else r0 let x1:UInt64:=if x >= 4294967296 then x>>>32 else x have t1:r1.toNat+x1.toNat.log2=r0.toNat+x.toNat.log2 ∧ x1.toNat.log2<32:=ag x r0 32 (by decide) (by decide) (by simpa[r0] using lim) lim let r2:UInt64:=if x1 >= 65536 then r1+16 else r1 let x2:UInt64:=if x1 >= 65536 then x1>>>16 else x1 have t2:r2.toNat+x2.toNat.log2=r1.toNat+x1.toNat.log2 ∧ x2.toNat.log2<16:=ag x1 r1 16 (by decide) (by decide) (by simp only[r0,ϔ,Λ]at t1;omega) (by omega) let r3:UInt64:=if x2 >= 256 then r2+8 else r2 let x3:UInt64:=if x2 >= 256 then x2>>>8 else x2 have t3:r3.toNat+x3.toNat.log2=r2.toNat+x2.toNat.log2 ∧ x3.toNat.log2<8:=ag x2 r2 8 (by decide) (by decide) (by omega) (by omega) have hx:x3.toNat<256:=ab x change (r3 + _).toNat=x.toNat.log2 rw[ξ,ad x3 hx] have he:r3.toNat+x3.toNat.log2=x.toNat.log2:=by omega rw[he] exact ν (by omega) def Yl0 (x n:ق):ق:=if h:x=0 then n else Yl0 (x>>>1) (n+1) termination_by x.toNat decreasing_by have a:x.toNat≠0:=fun e=>h (ο.mp (by simpa using e)) have b:(x>>>1).toNat=x.toNat/2:=by simp[Ζ,ω] rw[b];omega lemma Yl1 (m:ٽ):∀ (x n:ق), x.toNat ≤ m → x ≠ 0 → n.toNat+x.toNat.log2 < 64 → (Yl0 x n).toNat=n.toNat+x.toNat.log2+1:=by induction m with | zero=> intro x n a b exact absurd (ο.mp (by simpa using a)) b | succ m ih=> intro x n a b c have a0:x.toNat≠0:=fun e=>b (ο.mp (by simpa using e)) have d:(x>>>1).toNat=x.toNat/2:=by simp[Ζ,ω] have n1:(n+1).toNat=n.toNat+1:=by rw[ξ];have:(1:UInt64).toNat=1:=rfl;rw[this] exact ν (by have:n.toNat<64:=א;omega) rw[Yl0,dif_neg b] by_cases e:x>>>1=0 · have g:x.toNat/2=0:=by rw[<-d,e];rfl have f:x.toNat.log2=0:=by have:x.toNat<2:=by omega rw[Nat.log2_def];simp[show ¬ 2≤x.toNat by omega] rw[e,Yl0,dif_pos rfl,n1,f] · have g:x.toNat/2≠0:=fun q=>e (ο.mp (by rw[d,q];rfl)) have f:x.toNat.log2=(x.toNat/2).log2+1:=by rw[Nat.log2_def];simp[show 2≤x.toNat by omega] rw[ih (x>>>1) (n+1) (by rw[d];omega) e (by rw[d,n1];omega),d,n1,f] omega def Xarm:ه:=System.Platform.target.startsWith "a" @[inline] def Yj (x:ق):ق:=if Xarm then Yl0 x 0-1 else ac x lemma Zj (x:ق) (h:x≠0):(Yj x)˟=x˟۩:=by have a0:x.toNat≠0:=fun e=>h (ο.mp (by simpa using e)) have l:x.toNat.log2<64:=(kK a0).mpr x.toNat_lt have b:=Yl1 x.toNat x 0 (le_refl _) h (by simpa using l) have z:(0:UInt64).toNat=0:=rfl rw[z] at b unfold Yj split swap · exact ae x rw[Α _ _ (by rw[Κ,b];exact Nat.succ_le_of_lt (by omega))] rw[b];have:(1:UInt64).toNat=1:=rfl;omega @[inline] def eo (m:ق) (e:پ):ق := match e+149 with | .ofNat k=>m<<FloatLib.Numerics.FixedWord.roundShiftRightEven m (k+1) @[inline] def el (neg:ه) (m:ق) (e:پ):ك := let fr:=eo m e if fr==0 then Yv neg 0 0 else if (0x800000:ق)<=fr then Yv neg 1 0 else Yv neg 0 fr.toUInt32 lemma eL (a:ه) (m:ق) (e:پ) (b:m˟≠0) (h:(m˟۩:پ)+e < -126) : el a m e=π (kE κ a (kQ κ a) (match e-غ with | Int.ofNat shift=>m˟<<ἵ m˟ (shift+1))):=by have j:m˟<2^(m˟۩+1):=Ἂ;rw[show e-Fmt.minSubnormalExponent=e+149 by rw[show Fmt.minSubnormalExponent = -149 from rfl];omega];unfold el eo;generalize o:e+149=s;suffices H:∀ (d:ق) (F:ٽ),d˟=F -> F<=2^23 -> (if d==0 then Yv a 0 0 else if (0x800000:ق)<=d then Yv a 1 0 else Yv a 0 d؛)=π (kE κ a (kQ κ a) F) by cases s with | ofNat k => have l:(k:پ)=e+149:=ז have t:m˟*2^k<2^23:=by calc m˟*2^k<2^(m˟۩+1)*2^k:=ἇ j (ψ k) _=2^(m˟۩+1+k):=by rw[<- Θ] _<=2^23:=Η ב א apply H _ (m˟<< have l:ἃ k=e+149:=by rw[o] apply H _ _ (FloatLib.Numerics.FixedWord.roundShiftRightEven_toNat m (k+1));have u:m˟/2^(k+1)<2^23:=by rw[Ἒ (ψ _)];calc m˟<2^(m˟۩+1):=j _<=2^(23+(k+1)):=Η ב (by rw[Int.negSucc_eq]at l;omega) _=2^23*2^(k+1):=by rw[Θ] have:=FloatLib.Numerics.roundShiftRightEven_le_succ m˟ (k+1);omega intro d F q v;subst q;unfold kE;by_cases g:d=0 . subst g;exact eM a have r:(d˟==0)=false:=by simpa using λ h=>g (ο.mp (by simpa using h)) simp only[show(d==0)=false by simpa using g,r,χ,ؠ];by_cases f:d˟>=2^23 . have:(0x800000:ق)<=d:=by rw[Κ];simpa using f simp only[this,ת,show d˟>=kp Fmt؉ from f] exact ZT a 1 0 ד ד . have:¬ (0x800000:ق)<=d:=by rw[Κ];simpa using f simp only[this,ؠ,show ¬ d˟>=kp Fmt؉ from f] have n:d؛؟=d˟:=by rw[ϧ];omega rw[ZT a 0 _ ד (by rw[n];omega),n];rfl @[inline] def YK (m L:ق):ق := if 23<=L then FloatLib.Numerics.FixedWord.roundShiftRightEven m (L-23).toNat else m<<<(23-L) @[inline] def dN (neg:ه) (m L:ق) (t:پ):ك := let rm:=YK m L if rm==0x1000000 then (if t+1>127 then Yv neg 255 0 else Yv neg (t+128).toNat.toUInt32 0) else Yv neg (t+127).toNat.toUInt32 (rm.toUInt32-0x800000) lemma Z7 (m:ق) (a:m≠0):(YK m (Yj m))˟=(if κ؉<=m˟۩ then ἵ m˟ (m˟۩-κ؉) else m˟<<<(κ؉-m˟۩)) /\ 2^23<=(YK m (Yj m))˟/\(YK m (Yj m))˟<=2^24:=by have j:m˟≠0:=λ h=>a (ο.mp (by simpa using h));have b:=Zj m a;have f:2^m˟۩<=m˟:=ϲ j;have g:m˟<2^(m˟۩+1):=Ἂ;rw[show Fmt؉=23 from rfl];unfold YK;generalize Yj m=L at b ⊢;generalize n:m˟۩=N at * by_cases h:23<=N . have d:(23:ق)<=L:=by rw[Κ,b];simp;omega have e:(L-23)˟=N-23:=ט simp only[d,ת,h,e,FloatLib.Numerics.FixedWord.roundShiftRightEven_toNat];have o:2^23<=m˟/2^(N-23):=by rw[Ἑ (ψ _),<- Θ,show 23+(N-23)=N by omega] exact f have p:m˟/2^(N-23)<2^24:=by rw[Ἒ (ψ _),<- Θ,show 24+(N-23)=N+1 by omega];exact g have:=FloatLib.Numerics.div_two_pow_le_roundShiftRightEven m˟ (N-23);have:=FloatLib.Numerics.roundShiftRightEven_le_succ m˟ (N-23);refine⟨trivial,by omega,by omega⟩ . have d:¬ (23:ق)<=L:=by rw[Κ,b];simp;omega have e:(23-L)˟=23-N:=by rw[Α _ _ (by rw[Κ,b];simp;omega),b];rfl simp only[d,ؠ,h];have k:2^23<=m˟*2^(23-N):=by calc 2^23=2^N*2^(23-N):=by rw[<- Θ];congr 1;omega _<=m˟*2^(23-N):=Ε _ f have q:m˟*2^(23-N)<2^24:=by calc m˟*2^(23-N)<2^(N+1)*2^(23-N):=ἇ g (ψ _) _=2^24:=by rw[<- Θ];congr 1;omega have l:(m<<<(23-L))˟=m˟*2^(23-N):=by rw[Ρ,e,ν (show 23-N<64 by omega),υ];exact ν א rw[l,υ];exact⟨rfl,k,by omega⟩ lemma C4 (n:ٽ) (h:n<2^32):n.toUInt32؟=n:=by rw[Nat.toUInt32_eq,Ἓ,ν h] lemma eK (a:ه) (m:ق) (e:پ) (b:m≠0) (d:¬ ((m˟۩:پ)+e>127)) (f:¬ ((m˟۩:پ)+e < -126)) : dN a m (Yj m) ((m˟۩:پ)+e)=π (kJ κ a (kI κ a) (↑m˟۩+e) (if κ؉<=m˟۩ then ἵ m˟ (m˟۩-κ؉) else m˟<<<(κ؉-m˟۩))):=by obtain⟨q,r,s⟩:=Z7 m b;rw[<- q];unfold dN kJ;generalize YK m (Yj m)=g at r s ⊢;generalize (m˟۩:پ)+e=t at d f ⊢;simp only[Model.pow2_eq_two_pow,show Fmt؉=23 from rfl,show Fmt.maxNormalExponent=127 from rfl,show Fmt.exponentBias=127 from rfl,show Fmt.maxFiniteExpField=254 from rfl,show Fmt.maxFiniteFracField=8388607 from rfl,kL,Nat.reduceAdd,Int.ofNat_eq_natCast,Ἣ] by_cases k:g˟=16777216 . have l:(g==0x1000000)=true:=by rw[beq_iff_eq];apply ο.mp;rw[k];rfl simp only[l,ת,k,BEq.rfl,Nat.reduceSub];by_cases o:t+1>127 . simp only[o,ת];exact N7 a . simp only[o,ؠ];have j:((t+128)٪.toUInt32)؟=(t+1+127)٪:=by rw[C4 (t+128)٪ א];omega have n:((t+1+127)٪>254||((t+1+127)٪==254&&decide (0>8388607)))=false:=ז simp only[n,χ,ؠ];rw[ZT a _ 0 (by rw[j];omega) ד,j];rfl . have l:(g==0x1000000)=false:=by rw[beq_eq_false_iff_ne];intro h;apply k;rw[h];rfl have u:(g˟==16777216)=false:=ז simp only[l,u,χ,ؠ,show ¬ t>127 by omega] have j:=C4 (t+127)٪ א have p:(g؛-0x800000)؟=g˟-8388608:=by rw[kZ _ _ (by rw[Ἐ,ϧ];simp;omega),ϧ];simp;omega have n:((t+127)٪>254||((t+127)٪==254&&decide (g˟-8388608>8388607)))=false:=ז simp only[n,χ,ؠ];rw[ZT a _ _ (by rw[j];omega) (by rw[p];omega),j,p] @[inline] def YA (neg:ه) (m:ق) (e:پ):ك := let L:=Yj m let t:پ:=(Lڇ:پ)+e if t>127 then Yv neg 255 0 else if t < -126 then el neg m e else dN neg m L t lemma ZU (a:ه) (m:ق) (e:پ) (b:m≠0):YA a m e=π (ἒ κ ⟨a,m˟,e⟩):=by have g:m˟≠0:=λ h=>b (ο.mp (by simpa using h));have j:=Zj m b;unfold YA ἒ;simp only[show(m˟==0)=false by simpa using g,χ,ؠ,j,show Fmt.maxNormalExponent=127 from rfl,show Fmt.minNormalExponent = -126 from rfl] by_cases f:(m˟۩:پ)+e>127 . simp only[f,ת];exact N7 a . simp only[f,ؠ];by_cases d:(m˟۩:پ)+e < -126 . simp only[d,ת];exact eL a m e g d . simp only[d,ؠ];exact eK a m e b f d @[noinline] def d9 (neg:ه) (m:ق) (e:پ):ك:=YA neg m e @[noinline] def dn (neg:ه) (m:ق) (e:پ) (L c:ق):ك := YA neg m (e+((Lڇ+cڇ:ٽ):پ)) @[inline] def YY (n:ق):ق := let q:=n>>>40 q+(((n&&&0xFFFFFFFFFF)+0x7FFFFFFFFF+(q&&&1))>>>40) lemma eJ (n:ق):(YY n)˟=ἵ n˟ 40:=by rw[FloatLib.Numerics.roundShiftRightEven_eq_guard_sticky _ _ ד];have j:=n߾;have b:(n>>>40)˟=n˟/2^40:=by rw[Ζ,ω];rfl have d:(n&&&0xFFFFFFFFFF)˟=n˟%2^40:=by rw[ἢ,show(0xFFFFFFFFFF:ق)˟=2^40-1 from rfl,Ϙ] have e:((n>>>40)&&&1)˟=n˟/2^40%2:=ט have f:n˟/2^(40-1)%2=n˟%2^40/2^39:=by rw[show(2:Nat)^40=2^39*2 by norm_num,Nat.mod_mul_right_div_self] have g:n˟%2^(40-1)=n˟%2^40%2^39:=by rw[show(2:Nat)^40=2^39*2 by norm_num,Nat.mod_mul_right_mod] have k:=Χ n˟ (show 0<2^40 by decide);have l:n˟/2^40<2^24:=by rw[Ἒ ד];exact j unfold YY;simp only[ξ,Ζ,b,d,e,KD,f,g];clear b d e f g;generalize n˟%2^40=R at *;simp only[kU,Nat.reduceMod,kL,ω]at *;split . rename_i h;simp at h;generalize n˟/1099511627776=Q at *;rw[ν (a:=R+549755813887) א,ν (a:=R+549755813887+Q%2) א,show(R+549755813887+Q%2)/1099511627776=1 by omega];exact ν א . rename_i h;simp at h;generalize n˟/1099511627776=Q at *;rw[ν (a:=R+549755813887) א,ν (a:=R+549755813887+Q%2) א,show(R+549755813887+Q%2)/1099511627776=0 by omega];exact ν א lemma Z8 (a:ه) (E F:ك) (h:E؟*2^23+F؟<2^31):(Yv a E F)؟=(if a then 2^31 else 0)+E؟*2^23+F؟:=by unfold Yv;cases a<;>simp<;>omega @[inline] def YZ (neg:ه) (u n:ق):ك := (if neg then (0x80000000:ك) else 0)+((u<<<23)+YY n).toUInt32 lemma eI (a:ه) (u n:ق) (b:u˟<=253) (d:(YY n)˟<=2^24):(YZ a u n)؟=(if a then 2^31 else 0)+u˟*2^23+(YY n)˟:=by have e:(u<<<23)˟=u˟*2^23:=by rw[Ρ];simp;omega unfold YZ;cases a<;>simp<;>omega lemma N6 (a:ه) (m:ق) (e:پ) (u:ق) (b:m≠0) (d:(u˟:پ)=(m˟۩:پ)+e+126) (f:u˟<=253) : YZ a u (m<<<(63-Yj m))=YA a m e:=by have r:m˟≠0:=λ h=>b (ο.mp (by simpa using h));have k:=Zj m b;obtain⟨s,v,w⟩:=Z7 m b;have B:m˟۩<64:=(kK r).mpr m߾;have x:m˟<2^(m˟۩+1):=Ἂ;have n:(YY (m<<<(63-Yj m)))˟=(YK m (Yj m))˟:=by rw[eJ,s];have y:(63-Yj m)˟=63-m˟۩:=by rw[Α _ _ (by rw[Κ,k];simp;omega -splitDisjunctions),k];rfl have z:(m<<<(63-Yj m))˟=m˟*2^(63-m˟۩):=by rw[Ρ,y,ν (show 63-m˟۩<64 by omega),υ];apply ν calc m˟*2^(63-m˟۩)<2^(m˟۩+1)*2^(63-m˟۩):=ἇ x (ψ _) _=2^64:=by rw[<- Θ,show m˟۩+1+(63-m˟۩)=64 by omega] rw[z,show Fmt؉=23 from rfl];split . rw[show(40:Nat)=(m˟۩-23)+(63-m˟۩) by omega,FloatLib.Numerics.roundShiftRightEven_mul_two_pow] . rw[FloatLib.Numerics.roundShiftRightEven_mul_two_pow_of_le _ _ _ א,υ,show 63-m˟۩-40=23-m˟۩ by omega] have A:(YY (m<<<(63-Yj m)))˟<=2^24:=א rw[show YA a m e=dN a m (Yj m) ((m˟۩:Int)+e) by unfold YA;simp only[k,show ¬ ((m˟۩:Int)+e>127) by omega -splitDisjunctions,show ¬ ((m˟۩:Int)+e < -126) by omega -splitDisjunctions,ؠ]] apply Ν.mp;rw[eI a u _ f A,n];unfold dN;generalize YK m (Yj m)=g at n v w ⊢;generalize (m˟۩:پ)+e=t at d ⊢;by_cases o:g˟=16777216 . have l:(g==0x1000000)=true:=by rw[beq_iff_eq];apply ο.mp;rw[o];rfl simp only[l,ת];by_cases p:t+1>127 . simp only[p,ת];rw[Z8 a 255 0 ד];simp;omega . simp only[p,ؠ];have j:=C4 (t+128)٪ א rw[Z8 a _ 0 (by rw[j];simp;omega),j];simp;omega . have l:(g==0x1000000)=false:=by rw[beq_eq_false_iff_ne];intro h;apply o;rw[h];rfl simp only[l,χ,ؠ];have j:=C4 (t+127)٪ א have q:(g؛-0x800000)؟=g˟-8388608:=by rw[kZ _ _ (by rw[Ἐ,ϧ];simp;omega -splitDisjunctions),ϧ];simp;omega rw[Z8 a _ _ (by rw[j,q];omega),j,q];omega lemma N5 (a:ه) (n:ق) (E:پ) (u:ق) (b:2^63<=n˟) (e:(u˟:پ)=E+189) (d:u˟<=253) : YZ a u n=YA a n E:=by have f:n˟≠0:=Ἧ.mp (lt_of_lt_of_le (ψ 63) b);have g:n≠0:=λ h=>f (by rw[h];rfl);have j:n˟۩=63:=(Ἅ f).mpr ⟨b,n߾⟩;have k:Yj n=63:=ο.mp (by rw[Zj n g,j];rfl);have:=N6 a n E u g (by rw[j];push_cast;omega) d;rw[k,show n<<<(63-63:ق)=n from ο.mp (by rw[Ρ];simp only[UInt64.reduceSub,Nat.zero_mod,Nat.shiftLeft_zero];exact ν n߾)]at this exact this lemma eH (e:پ) (c:ق) (b:c˟<2^62) (h:(ϵ e).toInt=e) (a:((ϵ e).toUInt64+c)˟<=253) : (((ϵ e).toUInt64+c)˟:پ)=e+c˟:=by have d:=Int64.toInt_lt (ϵ e);have f:=Int64.le_toInt (ϵ e);have g:((ϵ e).toUInt64˟:پ)=e%2^64:=by simp;exact Int.toNat_of_nonneg (Int.emod_nonneg _ ד) rw[ξ]at a ⊢;omega def Y0 (e:پ) (ok:ه) (B:ق):Prop := ∀ c:ق,cڇ<2^62 -> ok=true -> (B+c).toNat<=253 -> ((B+c).toNat:پ)=e+cڇ lemma N4 (e:پ):Y0 e ((ϵ e).toInt==e) (ϵ e).toUInt64:=λ c a b d=>eH e c a (beq_iff_eq.mp b) d @[inline] def dY (neg:ه) (m:ق) (e:پ) (ok:ه) (b:ق):ك := let L:=Yj m let u:=b+L+126 if ok&&u<=253 then YZ neg u (m<<<(63-L)) else d9 neg m e lemma N3 (a:ه) (m:ق) (e:پ) (d:ه) (B:ق) (b:m≠0) (f:Y0 e d B):dY a m e d B=YA a m e:=by have k:m˟≠0:=λ h=>b (ο.mp (by simpa using h));have l:=Zj m b;have q:m˟۩<64:=(kK k).mpr m߾;unfold dY d9;dsimp only;split . rename_i h;simp at h;obtain⟨n,g⟩:=h;have o:(Yj m+126)˟=m˟۩+126:=by rw[ξ,l];simp;omega rw[KB]at g ⊢;have j:(B+(Yj m+126))˟<=253:=by have:=ϐ.mp g;simpa using this have p:=f _ (by rw[o];omega) n j;exact N6 a m e _ b (by rw[p];push_cast;omega) j . rfl @[inline] def d5 (w:ق) (e:پ) (negZero ok:ه) (B:ق):ك := if w=0 then (if negZero then 0x80000000 else 0) else let neg:=w>>>63 != 0 dY neg (if neg then 0-w else w) e ok B lemma J2 (w:ق) (e:پ) (a b:ه) (B:ق) (d:Y0 e b B):d5 w e a b B=ρ (Ym w) e a:=by unfold d5 finishWord;by_cases f:w=0 . subst f;simp[Ym] . have r:w˟≠0:=λ h=>f (ο.mp (by simpa using h)) have s:=w߾;obtain⟨k,l,n⟩:(w>>>63 != 0)=decide (Ym w<0) /\ (if (w>>>63 != 0)=true then 0-w else w)˟=(Ym w).natAbs/\Ym w≠0:=by by_cases h:w˟<2^63 . have g:Ym w=(w˟:پ):=by unfold Ym;omega have o:(w>>>63 != 0)=false:=by simp;apply ο.mp;simp;omega rw[g,o];simp only[χ,ؠ,kx];refine⟨by simp,trivial,by omega⟩ . have g:Ym w=(w˟:پ)-2^64:=by unfold Ym;simp only[h,ؠ] have p:(w>>>63 != 0)=true:=by simp;intro e;have:=congrArg Ἡ e;simp at this;omega have q:(0-w)˟=2^64-w˟:=by rw[Φ];simp;omega rw[g,p];simp only[ת,q];refine⟨by simp;omega,by omega,by omega⟩ simp only[f,ؠ,n];rw[<- Ἤ];have j:(if (w>>>63 != 0)=true then 0-w else w)≠0:=ז rw[N3 _ _ _ _ _ j d,ZU _ _ _ j,l,k];rfl def ek (w:ق) (e:پ) (negZero:ه):ك := d5 w e negZero ((ϵ e).toInt==e) (ϵ e).toUInt64 lemma F7 (w:ق) (e:پ) (a:ه):ek w e a=ρ (Ym w) e a := J2 w e a _ _ (N4 e) lemma W3 (V s:ٽ) (h:s+25<=V۩):(Ἰ V s)۩=V۩-s:=by have d:V≠0:=by intro e;subst e;simp at h have f:2^V۩<=V:=ϲ d;have g:V<2^(V۩+1):=Ἂ;have a:2^(V۩-s)<=V/2^s:=by rw[Ἑ (ψ _),<- Θ,show V۩-s+s=V۩ by omega];exact f have b:V/2^s<2^(V۩-s+1):=by rw[Ἒ (ψ _),<- Θ,show V۩-s+1+s=V۩+1 by omega];exact g unfold Ἰ;simp only;split . exact(Ἅ א).mpr ⟨a,b⟩ . rw[FloatLib.Numerics.or_one_eq];split . rename_i _ j;apply(Ἅ א).mpr omega . exact(Ἅ א).mpr ⟨a,b⟩ lemma N2 (b:ه) (V s:ٽ) (e:پ) (h:s+25<=V۩):ἒ κ ⟨b,Ἰ V s,e+s⟩=ἒ κ ⟨b,V,e⟩:=by have d:V≠0:=by intro j;subst j;simp at h have k:2^s<=V:=le_trans (Η ב א) (ϲ d) have l:Ἰ V s≠0:=FloatLib.Numerics.shiftRightJam_ne_zero V s k;have n:=W3 V s h;unfold ἒ;simp only[show(Ἰ V s==0)=false by simpa using l,show(V==0)=false by simpa using d,χ,ؠ,n] have o:((V۩-s:ٽ):پ)+(e+s)=V۩+e:=א rw[o];split . rfl . split . rename_i _ f;have t:غ = -149:=rfl;have u:(V۩:پ)+e < -126:=lt_of_lt_of_eq f rfl;obtain⟨a,g⟩:∃ a:ٽ,e-غ=ἃ a/\s+2<=a+1:=by refine⟨(-(e+149)-1)٪,?_,by omega⟩;omega have p:e+(s:پ)-غ=ἃ (a-s):=א rw[g.1,p];simp only;rw[show a-s+1=a+1-s by omega,FloatLib.Numerics.roundShiftRightEven_shiftRightJam V s (a+1) g.2] . rename_i _ f;have q:κ؉<=V۩-s:=by rw[show Fmt؉=23 from rfl];omega have r:κ؉<=V۩:=א simp only[q,r,ת];rw[show Fmt؉=23 from rfl,show V۩-s-23=V۩-23-s by omega,FloatLib.Numerics.roundShiftRightEven_shiftRightJam V s (V۩-23) א] lemma Z9 (b a d:ق) (L:ٽ) (f:d˟=L) (j:L<=63) (g:b˟<2^(L+1)):((b<<<(63-d))|||((a>>>d)>>>1))˟=(b˟*2^64+a˟)/2^(L+1) /\ ((a<<<(63-d)) != 0)=decide ((b˟*2^64+a˟)%2^(L+1)≠0):=by have n:(63-d)˟=63-L:=by rw[Α _ _ (by rw[Κ,f];simp;omega),f];rfl have k:(2:ٽ)^64=2^(63-L)*2^(L+1):=by rw[<- Θ];congr 1;omega have q:(b<<<(63-d))˟=b˟*2^(63-L):=by rw[Ρ,n,ν (show 63-L<64 by omega),υ] apply ν;calc b˟*2^(63-L)<2^(L+1)*2^(63-L):=ἇ g (ψ _) _=2^64:=by rw[<- Θ];congr 1;omega have r:((a>>>d)>>>1)˟=a˟/2^(L+1):=by rw[Ζ,Ζ,f,ν (show L<64 by omega)];simp only[kU,Nat.reduceMod,ω,Ϡ,<- Nat.pow_succ] have s:a˟/2^(L+1)<2^(63-L):=by rw[Ἒ (ψ _),<- k];exact a߾ have t:(b˟*2^64+a˟)/2^(L+1)=b˟*2^(63-L)+a˟/2^(L+1):=by rw[k,<- ϡ,ϝ,ϙ _ _ (ψ _),ϝ] have u:(b˟*2^64+a˟)%2^(L+1)=a˟%2^(L+1):=by rw[k,<- ϡ,ϝ,Ϧ] refine⟨?_,?_⟩ . rw[UInt64.toNat_or,q,r,t,<- υ,<- kT s] . rw[u];have o:(a<<<(63-d))˟=a˟%2^(L+1)*2^(63-L):=by rw[Ρ,n,ν (show 63-L<64 by omega),υ,k,ό (2^(63-L)),Nat.mul_mod_mul_right] have v:0<2^(63-L):=ψ _;by_cases l:a˟%2^(L+1)=0 . have:a<<<(63-d)=0:=ο.mp (by rw[o,l,ϔ];simp);simp[this,l] . have:a<<<(63-d)≠0:=λ e=>by have p:=congrArg Ἡ e;rw[o,ϔ]at p;rcases ϸ.mp p with h | h . exact l h . exact absurd h (Ἧ.mp v) simp[this,l] @[inline] def dD (w0:ق):ق := ~~~w0+1 @[inline] def dC (w1 w0:ق):ق := ~~~w1+(if w0==0 then 1 else 0) @[inline] def dB (w2 w1 w0:ق):ق := ~~~w2+(if w1==0&&w0==0 then 1 else 0) lemma W1 (d b a:ق) (h:d˟*2^128+b˟*2^64+a˟≠0):(dB d b a)˟*2^128+(dC b a)˟*2^64+(dD a)˟=2^192-(d˟*2^128+b˟*2^64+a˟):=by have n:=d߾;have o:=b߾;have p:=a߾;unfold dB dC dD;by_cases e:a=0 . have f:a˟=0:=ט by_cases l:b=0 . have g:b˟=0:=ז simp only[e,l,Bool.and_self,ת,KA]at *;simp at *;omega . have j:(b==0)=false:=ז have g:b˟≠0:=λ h=>l (ο.mp (by rw[h];rfl)) simp only[e,j,beq_self_eq_true,Bool.false_and,χ,ؠ,ת,ξ,KA]at *;simp at *;omega . have k:(a==0)=false:=ז have f:a˟≠0:=λ h=>e (ο.mp (by rw[h];rfl)) simp only[k,Bool.and_false,χ,ؠ,ξ,KA]at *;simp at *;omega @[inline] def dM (neg:ه) (m2 m1 m0:ق) (e:پ):ك := let L:=Yj m2 let x:=(m2<<<(63-L))|||((m1>>>L)>>>1) let st:=(m1<<<(63-L)) != 0||m0 != 0 YA neg (if st then x|||1 else x) (e+((Lڇ+65:ٽ):پ)) @[inline] def dL (neg:ه) (m1 m0:ق) (e:پ):ك := let L:=Yj m1 let x:=(m1<<<(63-L))|||((m0>>>L)>>>1) let st:=(m0<<<(63-L)) != 0 YA neg (if st then x|||1 else x) (e+((Lڇ+1:ٽ):پ)) @[inline] def dX (neg:ه) (m2 m1 m0:ق) (e:پ):ك := if m2 != 0 then dM neg m2 m1 m0 e else if m1 != 0 then dL neg m1 m0 e else YA neg m0 e lemma N1 (x:ق) (a:ه) (Q R:ٽ) (b:x˟=Q) (d:a=decide (R≠0)) (e:2<=Q):(if a then x|||1 else x)˟=(if R==0 then Q else Q|||1):=by subst b d;by_cases f:R=0 . simp[f] . simp[f] lemma QF (m:ق) (h:m≠0):m˟۩<=63/\m˟<2^(m˟۩+1)/\2^m˟۩<=m˟:=by have a:m˟≠0:=λ b=>h (ο.mp (by rw[b];rfl)) exact⟨by have:=(kK a).mpr m߾;omega,Ἂ,ϲ a⟩ lemma QH (m r K:ٽ) (a:2^K<=m):2<=(m*2^64+r)/2^(K+1):=by rw[Ἑ (ψ _)];calc 2*2^(K+1)=2^K*2^2:=by rw[<- Θ,<- Nat.pow_succ'] _<=m*2^64:=Ἢ a (Η ב ב) _<=_:=ϳ _ _ lemma QL (m:ق) (s r:ٽ) (h:m≠0) (a:r<2^s):(m˟*2^s+r)۩=s+m˟۩:=by have b:m˟≠0:=λ d=>h (ο.mp (by rw[d];rfl)) have e:=@Ἂ m˟;apply(Ἅ (Nat.ne_of_gt (ϛ (ύ (ϒ b) (ψ s)) (ϳ _ _)))).mpr;constructor . rw[Θ,ό];exact(Ε _ (ϲ b)).trans (ϳ _ _) . calc m˟*2^s+r < (m˟+1)*2^s:=by rw[Ϣ,ϫ];omega _<=2^(m˟۩+1)*2^s:=Ε _ e _=2^(s+m˟۩+1):=by rw[<- Θ];ring_nf lemma QN (x:ق) (a:ه) (Q R:ٽ) (b:(if a then x|||1 else x)˟=(if R==0 then Q else Q|||1)) (d:2<=Q):(if a then x|||1 else x)≠0:=by intro h;have e:=congrArg Ἡ h;rw[b,ϔ]at e;split at e . omega . rw[FloatLib.Numerics.or_one_eq]at e;split at e<;>omega lemma W0 (b:ه) (a d:ق) (e:پ) (f:a≠0):dL b a d e=π (ἒ κ ⟨b,a˟*2^64+d˟,e⟩):=by have t:=a߾;have q:=d߾;unfold dL;have g:=Zj a f;obtain⟨h,j,k⟩:=QF a f;generalize r:a˟۩=K at g h j k;obtain⟨l,n⟩:=Z9 a d (Yj a) K g h j;generalize Yj a=L at g l n ⊢;have o:=QH _ d˟ K k;have p:=N1 _ _ _ _ l n o;rw[ZU _ _ _ (QN _ _ _ _ p o),p,g];have s:=QL a 64 _ f q;rw[r]at s;have:=N2 b (a˟*2^64+d˟) (K+1) e א;unfold Ἰ at this;rw[this] lemma V9 (f:ه) (a d b:ق) (e:پ) (g:a≠0):dM f a d b e=π (ἒ κ ⟨f,a˟*2^128+d˟*2^64+b˟,e⟩):=by have w:=d߾;have x:=b߾;unfold dM;have y:a˟≠0:=λ h=>g (ο.mp (by rw[h];rfl));have M:a˟*2^128+d˟*2^64+b˟≠0:=by have z:0 < a˟*2^128:=ύ (ϒ y) (ψ _);rw[kR];exact Nat.ne_of_gt (ϛ z (ϳ _ _)) have j:=Zj a g;obtain⟨p,q,r⟩:=QF a g;generalize B:a˟۩=K at j p q r;obtain⟨k,n⟩:=Z9 a d (Yj a) K j p q;generalize Yj a=L at j k n ⊢;obtain⟨A,o⟩:∃ A,a˟*2^64+d˟=A:=⟨_,rfl⟩;rw[o]at k n;have C:A=A/2^(K+1)*2^(K+1)+A%2^(K+1):=(Ϻ A _).symm;have D:A%2^(K+1)<2^(K+1):=Χ _ (ψ _);have s:(2:ٽ)^(K+65)=2^(K+1)*2^64:=ז have t:a˟*2^128+d˟*2^64+b˟=(A%2^(K+1)*2^64+b˟)+A/2^(K+1)*2^(K+65):=by have:a˟*2^128+d˟*2^64=A*2^64:=by rw[<- o];ring rw[this,s];conv_lhs=>rw[C] ring have u:A%2^(K+1)*2^64+b˟<2^(K+65):=by rw[s];calc A%2^(K+1)*2^64+b˟h (ο.mp (by rw[I];rfl));simp[h,this] rw[H];by_cases N:A%2^(K+1)=0<;>by_cases O:b˟=0<;>simp have l:=QH _ d˟ K r;rw[o]at l;rw[<- E]at k l;have v:=N1 _ _ _ _ k G l;rw[ZU _ _ _ (QN _ _ _ _ v l),v,j];have J:=QL a 128 (d˟*2^64+b˟) g (by clear * - x w;omega);rw[<- kR,B]at J have:=N2 f (a˟*2^128+d˟*2^64+b˟) (K+65) e א;unfold Ἰ at this;rw[this] lemma N0 (a:ه) (d b f:ق) (e:پ) (g:d˟*2^128+b˟*2^64+f˟≠0) : dX a d b f e=π (ἒ κ ⟨a,d˟*2^128+b˟*2^64+f˟,e⟩):=by unfold dX;by_cases j:d=0 . subst j;simp only[ؠ,ϔ,Ϫ,Λ]at g ⊢;by_cases k:b=0 . subst k;simp at g ⊢;exact ZU a f e (λ h=>g (by rw[h];rfl)) . simp only[show(b != 0)=true by simpa using k,ת];exact W0 a b f e k . simp only[show(d != 0)=true by simpa using j,ת];exact V9 a d b f e j lemma eQ (a d b:ق) (L:ٽ) (f:b˟=L) (g:L<=63) (h:a˟<2^(L+1)) (j:2^L<=a˟) (e:ه) : 2^63<=(if e then ((a<<<(63-b))|||((d>>>b)>>>1))|||1 else (a<<<(63-b))|||((d>>>b)>>>1))˟:=by obtain⟨k,-⟩:=Z9 a d b L f g h;have l:2^63<=(a˟*2^64+d˟)/2^(L+1):=by rw[Ἑ (ψ _)];calc 2^63*2^(L+1)=2^L*2^64:=by rw[<- Θ,<- Θ,show 63+(L+1)=L+64 by omega] _<=a˟*2^64:=Ε _ j _<=_:=ϳ _ _ cases e . simp only[χ,ؠ];rw[k];exact l . simp only[ת];rw[UInt64.toNat_or,k,show(1:ق)˟=1 from rfl,FloatLib.Numerics.or_one_eq];split<;>omega @[inline] def ej (neg:ه) (m1 m0:ق) (e:پ) (ok:ه) (b:ق):ك := let L:=Yj m1 let x:=(m1<<<(63-L))|||((m0>>>L)>>>1) let st:=(m0<<<(63-L)) != 0 let x':=if st then x|||1 else x let u:=b+L+190 if ok&&u<=253 then YZ neg u x' else dn neg x' e L 1 lemma I3 (a b:ق) (h:a≠0):(Yj a)˟=a˟۩/\a˟۩<=63/\∀ g:ه,2^63<=(if g then ((a<<<(63-Yj a))|||((b>>>Yj a)>>>1))|||1 else (a<<<(63-Yj a))|||((b>>>Yj a)>>>1))˟:=by have d:a˟≠0:=λ e=>h (ο.mp (by rw[e];rfl)) have f:a˟۩<=63:=by have:=(kK d).mpr a߾;omega exact⟨Zj a h,f,eQ a b (Yj a) _ (Zj a h) f Ἂ (ϲ d)⟩ lemma V8 (a:ه) (b d:ق) (e:پ) (f:ه) (B:ق) (g:b≠0) (j:Y0 e f B):ej a b d e f B=dL a b d e:=by obtain⟨k,p,l⟩:=I3 b d g;generalize b˟۩=K at k p;unfold ej dL dn;dsimp only;generalize Yj b=L at k l ⊢;split . rename_i h;simp at h;obtain⟨q,n⟩:=h;have r:(L+190)˟=K+190:=by rw[ξ,k];simp;omega rw[KB]at n ⊢;have o:(B+(L+190))˟<=253:=by have:=ϐ.mp n;simpa using this have s:=j _ (by rw[r];omega) q o;exact N5 a _ _ _ (l _) (by rw[s];push_cast;omega) o . rfl @[inline] def eh (neg:ه) (m2 m1 m0:ق) (e:پ) (ok:ه) (b:ق):ك := let L:=Yj m2 let x:=(m2<<<(63-L))|||((m1>>>L)>>>1) let st:=(m1<<<(63-L)) != 0||m0 != 0 let x':=if st then x|||1 else x let u:=b+L+254 if ok&&u<=253 then YZ neg u x' else dn neg x' e L 65 lemma V7 (a:ه) (b d f:ق) (e:پ) (g:ه) (B:ق) (j:b≠0) (k:Y0 e g B):eh a b d f e g B=dM a b d f e:=by obtain⟨l,q,n⟩:=I3 b d j;generalize b˟۩=K at l q;unfold eh dM dn;dsimp only;generalize Yj b=L at l n ⊢;split . rename_i h;simp at h;obtain⟨r,o⟩:=h;have s:(L+254)˟=K+254:=by rw[ξ,l];simp;omega rw[KB]at o ⊢;have p:(B+(L+254))˟<=253:=by have:=ϐ.mp o;simpa using this have t:=k _ (by rw[s];omega) r p;exact N5 a _ _ _ (n _) (by rw[t];push_cast;omega) p . rfl @[inline] def dW (neg:ه) (m2 m1 m0:ق) (e:پ) (ok:ه) (b:ق):ك := if m2 != 0 then eh neg m2 m1 m0 e ok b else if m1 != 0 then ej neg m1 m0 e ok b else dY neg m0 e ok b lemma M9 (a:ه) (d b f:ق) (e:پ) (g:ه) (B:ق) (k:d˟*2^128+b˟*2^64+f˟≠0) (j:Y0 e g B) : dW a d b f e g B=dX a d b f e:=by unfold dW dX;by_cases l:d=0 . subst l;by_cases n:b=0 . subst n;exact N3 a f e g B (λ h=>k (by rw[h];rfl)) j . simp only[show(b != 0)=true by simpa using n,ת];exact V8 a b f e g B n j . simp only[show(d != 0)=true by simpa using l,ת];exact V7 a d b f e g B l j @[inline] def d0 (w2 w1 w0:ق) (e:پ) (negZero ok:ه) (B:ق):ك := if w2=0/\w1=0/\w0=0 then (if negZero then 0x80000000 else 0) else if w2>>>63 != 0 then dW true (dB w2 w1 w0) (dC w1 w0) (dD w0) e ok B else dW false w2 w1 w0 e ok B lemma J1 (a b d:ق) (e:پ) (f g:ه) (B:ق) (h:Y0 e g B):d0 a b d e f g B=ρ (YC a b d) e f:=by have u:=a߾;have v:=b߾;have w:=d߾;have q:a˟*2^128+b˟*2^64+d˟<2^192:=by have:b˟*2^64+d˟<2^128:=by calc b˟*2^64+d˟>>63 != 0)=false:=by simp;apply ο.mp;simp;omega have p:YC a b d≠0:=א simp only[n,χ,ؠ,p];rw[<- Ἤ,M9 false a b d e _ _ (by rw[j];exact k) h,N0 false a b d e (by rw[j];exact k),j] unfold ofIntDyadic;rw[o,kx,decide_eq_false (Int.not_lt.mpr (Int.natCast_nonneg N))] . have o:YC a b d=(N:پ)-2^192:=by unfold YC;rw[j];simp only[r,ؠ] have H:(a>>>63 != 0)=true:=by simp;intro e;have:=congrArg Ἡ e;simp at this;omega have I:(N:پ)-2^192 = -((2^192-N:ٽ):پ):=א have p:YC a b d≠0:=א have s:=W1 a b d (by rw[j];exact k);rw[j]at s;have t:(dB a b d)˟*2^128+(dC b d)˟*2^64+(dD d)˟≠0:=א simp only[H,ת,p,ؠ];rw[<- Ἤ,M9 true _ _ _ e _ _ t h,N0 true _ _ _ e t,s];unfold ofIntDyadic;rw[o,I,Int.natAbs_neg,kx,decide_eq_true (Int.neg_neg_of_pos (Int.natCast_pos.mpr (Nat.sub_pos_of_lt q)))] @[inline] def dE (neg:ه) (m:ق) (e:Unit -> پ) (ok:ه) (b:ق):ك := let L:=Yj m let u:=b+L+126 if ok&&u<=253 then YZ neg u (m<<<(63-L)) else d9 neg m (e ()) @[inline] def ei (neg:ه) (m1 m0:ق) (e:Unit -> پ) (ok:ه) (b:ق):ك := let L:=Yj m1 let x:=(m1<<<(63-L))|||((m0>>>L)>>>1) let st:=(m0<<<(63-L)) != 0 let x':=if st then x|||1 else x let u:=b+L+190 if ok&&u<=253 then YZ neg u x' else dn neg x' (e ()) L 1 @[inline] def eg (neg:ه) (m2 m1 m0:ق) (e:Unit -> پ) (ok:ه) (b:ق):ك := let L:=Yj m2 let x:=(m2<<<(63-L))|||((m1>>>L)>>>1) let st:=(m1<<<(63-L)) != 0||m0 != 0 let x':=if st then x|||1 else x let u:=b+L+254 if ok&&u<=253 then YZ neg u x' else dn neg x' (e ()) L 65 @[inline] def dA (neg:ه) (m2 m1 m0:ق) (e:Unit -> پ) (ok:ه) (b:ق):ك := if m2 != 0 then eg neg m2 m1 m0 e ok b else if m1 != 0 then ei neg m1 m0 e ok b else dE neg m0 e ok b @[inline] def dg (w2 w1 w0:ق) (e:Unit -> پ) (negZero ok:ه) (B:ق):ك := if w2=0/\w1=0/\w0=0 then (if negZero then 0x80000000 else 0) else if w2>>>63 != 0 then dA true (dB w2 w1 w0) (dC w1 w0) (dD w0) e ok B else dA false w2 w1 w0 e ok B @[inline] def cc (w:ق) (e:Unit -> پ) (negZero ok:ه) (B:ق):ك := if w=0 then (if negZero then 0x80000000 else 0) else let neg:=w>>>63 != 0 dE neg (if neg then 0-w else w) e ok B lemma B5 (a b d:ق) (e:پ) (f g:ه) (B:ق):dg a b d (λ _=>e) f g B=d0 a b d e f g B:=rfl lemma B6 (w:ق) (e:پ) (a b:ه) (B:ق):cc w (λ _=>e) a b B=d5 w e a b B:=rfl def en (w2 w1 w0:ق) (e:پ) (negZero:ه):ك := d0 w2 w1 w0 e negZero ((ϵ e).toInt==e) (ϵ e).toUInt64 lemma V6 (b d f:ق) (e:پ) (a:ه):en b d f e a=ρ (YC b d f) e a := J1 b d f e a _ _ (N4 e) @[inline] def Yf (w:ك):ق := if θ w=0 then (fracOf w).toUInt64 else (fracOf w).toUInt64+0x800000 @[inline] def Yd (w:ك):ق := if θ w=0 then 0 else (θ w).toUInt64-1 lemma Zk (w:ك):(Yf w)˟=ε w:=by have:=fracOf_toNat_lt w;unfold Yf mantOf;split_ifs . simp . simp only[ξ];show((fracOf w)؟+8388608)%2^64=2^23+(fracOf w)؟;omega lemma Zf (w:ك):(Yd w)˟=γ w:=by unfold Yd idxOf;split_ifs with h . rfl . have b:1<=(θ w)؟:=by rcases Ϲ (θ w)؟ with a | a . exact absurd (Ν.mp (by simpa using a)) h . exact a rw[Α _ _ (by rw[Κ];simp;omega)];simp lemma Zc (a b:م) (h:a߷+b߷<Ξ):(a+b)߷=a߷+b߷:=by exact ν h lemma A1 (A:ل δ) (a n k:م) (b:a߷+n߷<=Aچ) (d:a߷+n߷<Ξ) (h:k>>1)>>>(63-r))˟=m˟/2^(64-r˟):=by rw[Ζ,Ζ,V5 r a,ω,ω,ν (show 63-r˟<64 by omega),show(1:ق)˟%64=1 from rfl,Ϡ,<- Θ] congr 2;omega lemma M6 (m r:ٽ) (a:r<64):m*2^r%2^64+m/2^(64-r)*2^64=m*2^r:=by have h:m*2^r/2^64=m/2^(64-r):=by rw[show(2:Nat)^64=2^r*2^(64-r) by rw[<- Θ];congr 1;omega,<- Ϡ,Nat.mul_div_cancel _ (ψ r)] rw[<- h];exact Nat.mod_add_div' _ _ lemma V4 (m s:ق) (a:s˟<64):((m>>>1)>>>(63-(s&&&63)))˟*2^64+(m<<<(s&&&63))˟ =m˟*2^s˟:=by have b:(s&&&63)˟=s˟:=by rw[F6];exact ν a rw[M8 _ _ א,M7 _ _ א,b] have Zh:=M6 m˟ s˟ a;omega lemma V3 (m s:ق) (a:64<=s˟) (b:s˟<128):((m>>>1)>>>(63-(s&&&63)))˟*2^128+(m<<<(s&&&63))˟*2^64 =m˟*2^s˟:=by have d:(s&&&63)˟=s˟-64:=by rw[F6];omega rw[M8 _ _ א,M7 _ _ א,d] have Zh:=M6 m˟ (s˟-64) א have e:m˟*2^s˟=m˟*2^(s˟-64)*2^64:=by rw[ϡ,<- Θ];congr 2;omega omega lemma V2 (m s:ق) (a:s˟<128):(if s<64 then (0:ق) else (m>>>1)>>>(63-(s&&&63)))˟*2^128 + (if s<64 then (m>>>1)>>>(63-(s&&&63)) else m<<<(s&&&63))˟*2^64 + (if s<64 then m<<<(s&&&63) else 0)˟=m˟*2^s˟:=by by_cases h:s<64 . rw[if_pos h,if_pos h,if_pos h,ϔ,Ϫ,Λ];exact V4 m s (Ι.mp h) . rw[if_neg h,if_neg h,if_neg h,ϔ,Ἇ];exact V3 m s (by have:=Ι.not.mp h;simp at this;omega) a lemma F5 (y a:ق) (h:a˟<=1):(y^^^(0-a))˟=if a˟=1 then 2^64-1-y˟ else y˟:=by rcases ἷ.mp h with b | d . have:a=0:=ο.mp (by simpa using b);subst this;simp . have:a=1:=ο.mp (by simpa using d) subst this;show(y.toBitVec^^^BitVec.allOnes 64).toNat=_;rw[BitVec.xor_allOnes,BitVec.toNat_not];simp lemma ZJ (a b:ق):(a+b)˟=(a˟+b˟)%2^64 /\ (if a+brcases Nat.lt_or_ge j˟ 1 with u | u . rw[show h˟=0 by omega,show j˟=0 by omega];rfl . rw[show h˟=0 by omega,Nat.zero_or];omega . rw[show j˟=0 by omega,Nat.or_zero];omega . omega -splitDisjunctions rw[ξ,ξ,s,r,p,l,o,q,k];omega lemma V0 (d b a c:ق):(d+(if b+(if a+comega lemma I9 (a b d:ق):((a|||b|||d)==0)=decide (d˟*2^128+b˟*2^64+a˟=0):=by have e:a=0↔a˟=0:=by rw[<- ἡ];simp have f:b=0↔b˟=0:=by rw[<- ἡ];simp have g:d=0↔d˟=0:=by rw[<- ἡ];simp rw[ἁ,beq_iff_eq,ث,UInt64.or_eq_zero_iff,UInt64.or_eq_zero_iff,e,f,g];omega lemma C6 (a b:ك):((a^^^b)>>>31)܌˟=if Γ (η a) (η b) then 1 else 0:=by have n:a؟<2^32:=Ἁ a;have o:b؟<2^32:=Ἁ b;have g:η a=decide (a؟/2^31=1):=by unfold signOf;have j:(a؟&&&2^31)%2^31=0:=by rw[Nat.and_mod_two_pow,Nat.mod_self,Nat.and_zero] have k:(a؟&&&2^31)/2^31=a؟/2^31%2:=by rw[Nat.and_div_two_pow,KF (ψ 31),Nat.and_one_is_mod] have d:(a&&&߿)؟=a؟&&&2^31:=ג have e:(a&&&߿ != 0)=decide ((a&&&߿)؟≠0):=by rw[ἁ,bne_iff_ne,ث,ne_eq,ne_eq,<- Ἥ];simp rw[e,d,ἁ,ث,ث];omega have l:η b=decide (b؟/2^31=1):=by unfold signOf;have j:(b؟&&&2^31)%2^31=0:=by rw[Nat.and_mod_two_pow,Nat.mod_self,Nat.and_zero] have k:(b؟&&&2^31)/2^31=b؟/2^31%2:=by rw[Nat.and_div_two_pow,KF (ψ 31),Nat.and_one_is_mod] have d:(b&&&߿)؟=b؟&&&2^31:=ג have e:(b&&&߿ != 0)=decide ((b&&&߿)؟≠0):=by rw[ἁ,bne_iff_ne,ث,ne_eq,ne_eq,<- Ἥ];simp rw[e,d,ἁ,ث,ث];omega rw[ϯ,϶,UInt32.toNat_xor,show(31:ك)؟%32=31 from rfl,Nat.shiftRight_xor_distrib,ω,ω,g,l] have:a؟/2^31<=1:=א have:b؟/2^31<=1:=א rcases ἷ.mp ‹aڇ/2^31<=1› with h | h<;>rcases ἷ.mp ‹bڇ/2^31<=1› with f | f <;> rw[h,f]<;>decide @[inline] def YL {β:Type} (lo:ق) (a b:ك) (w2 w1 w0 c:ق) (kont:ق -> ق -> ق -> ق -> β):β := let m:=Yf a*Yf b let s:=Yd a+Yd b-lo let rr:=s&&&63 let x0:=m<<>>1)>>>(63-rr) let lowq:=s<64 let y0:=if lowq then x0 else 0 let y1:=if lowq then x1 else x0 let y2:=if lowq then 0 else x1 let ng:=((a^^^b)>>>31).toUInt64 let mk:ق:=0-ng let s0:=w0+(y0^^^mk) let k0:ق:=if s0>>1)>>>(63-(s&&&63)))˟*2^128 + (if s<64 then (m>>>1)>>>(63-(s&&&63)) else m<<<(s&&&63))˟*2^64 + (if s<64 then m<<<(s&&&63) else 0)˟=0:=by have b:m=0:=ο.mp (by simpa using a);subst b;split_ifs<;>simp<;>rfl lemma Zg (w:ك):γ w<=254:=by have:=expOf_toNat_lt w;unfold idxOf;split_ifs<;>omega lemma ZK (a b:ك):ε a*ε b<2^48:=calc ε a*ε b<2^24*2^24:=Nat.mul_lt_mul'' (ϖ a) (ϖ b) lemma C5 (a b:δ):(Yf a*Yf b)˟=ε a*ε b:=by rw[ϱ,Zk,Zk];exact ν (by have:=ZK a b;omega) lemma D5 (a b:δ):(Yd a+Yd b)˟=γ a+γ b:=by have:=Zg a;have:=Zg b;rw[ξ,Zf,Zf,ν א] lemma I1 (a b:δ):Yf a*Yf b=0↔ε a*ε b=0:=by rw[<- C5,<- ἡ];rfl lemma I4 (w:δ):(Yf w==0)=decide (ε w=0):=by rw[ἁ,beq_iff_eq,ث,<- Zk,<- ἡ];rfl lemma Zr {β:Type} (d:ق) (a b:ك) (f g h c:ق) (e:ق -> ق -> ق -> ق -> β) (k:c˟+1<2^64) (j:ε a*ε b≠0 -> d˟<=γ a+γ b/\γ a+γ b>>31)܌=l at p ⊢ . rw[ξ];have:l˟<=1:=by rw[p];split_ifs<;>omega -splitDisjunctions omega -splitDisjunctions · have n:(if s<64 then (0:ق) else (m>>>1)>>>(63-(s&&&63)))˟*2^128+(if s<64 then (m>>>1)>>>(63-(s&&&63)) else m<<<(s&&&63))˟*2^64 + (if s<64 then m<<<(s&&&63) else 0)˟=ε a*ε b*2^(γ a+γ b-d˟):=by by_cases r:ε a*ε b=0 . rw[r,Ϫ];exact U9 m s (by rw[q,r]) . obtain⟨I,J⟩:=j r;have B:s˟=γ a+γ b-d˟:=by rw[<- A,Α _ _ (by rw[Κ,ξ,Zf,Zf];have:=Zg a;have:=Zg b;omega -splitDisjunctions), ξ,Zf,Zf] have:=Zg a;have:=Zg b;rw[ν (by omega -splitDisjunctions)] rw[<- q,<- B];exact V2 m s א generalize (if s<64 then (0:ق) else (m>>>1)>>>(63-(s&&&63)))=t at n ⊢;generalize (if s<64 then (m>>>1)>>>(63-(s&&&63)) else m<<<(s&&&63))=u at n ⊢;generalize (if s<64 then m<<<(s&&&63) else 0)=v at n ⊢;have w:l˟<=1:=ז have C:=F5 t l w;have D:=F5 u l w;have E:=F5 v l w;have K:t˟<2^64:=Ϛ t;have L:u˟<2^64:=Ϛ u;have M:v˟<2^64:=Ϛ v;unfold Yx;rw[V1,ξ,ν (a:=c˟+l˟) (by omega -splitDisjunctions),<- Zn] generalize F:ε a*ε b*2^(γ a+γ b-d˟)=P at n;have G:(if Γ (η a) (η b) then -((ε a*ε b:ٽ):پ) else ((ε a*ε b:ٽ):پ))*2^(γ a+γ b-d˟) = if Γ (η a) (η b) then -(P:پ) else (P:پ):=by rw[<- F];split_ifs<;>push_cast<;>ring rw[G];split_ifs at p C D E ⊢ with N O<;>omega @[inline] def YD (w2 w1 w0 c:ق) (e:پ):ق := let t0:=w0+c let k0:ق:=if t0>>23).toNat def YM (a:ك):ٽ:=((a&&&0x7FFFFFFF)>>>23).toNat lemma U8 (a:ك):(a&&&ש)؟=(θ a)؟*2^23+(fracOf a)؟:=by simp only[ἣ,expOf,fracOf,϶];rw[show(ש:ك)؟=2^31-1 from rfl,show(0xFF:ك)؟=2^8-1 from rfl,show(0x7FFFFF:ك)؟=2^23-1 from rfl,show(23:ك)؟%32=23 from rfl,Ϙ,Ϙ,Ϙ,ω] omega lemma Zb (a:ك):YR a<=511/\YM a<=255/\(YM a<255 -> θ a≠255) /\ (ε a≠0 -> YR a<=γ a+1/\γ a+1<=max (YM a) 1):=by have f:=U8 a;have n:=expOf_toNat_lt a;have o:=fracOf_toNat_lt a;have g:YR a=if (a&&&ש)؟=0 then 511 else ((a&&&ש)؟-1)/2^23:=by unfold YR;rw[϶,UInt32.toNat_sub,show(23:ك)؟%32=23 from rfl,ω,show(1:ك)؟=1 from rfl] split_ifs with b<;>omega have j:YM a=(θ a)؟:=by unfold YM;rw[϶,show(23:ك)؟%32=23 from rfl,ω,f] omega have d:θ a=0↔(θ a)؟=0:=by rw[<- Ἥ];simp have k:θ a=255↔(θ a)؟=255:=by rw[<- Ἥ];simp unfold mantOf idxOf;rw[g,j];refine⟨by split_ifs<;>omega,by omega -splitDisjunctions,λ h l=>by rw[k]at l;omega -splitDisjunctions,λ e=>?_⟩;by_cases b:θ a=0 . rw[if_pos b]at e ⊢;rw[d]at b;split_ifs<;>omega . rw[if_neg b]at e ⊢;rw[d]at b;split_ifs<;>omega def dK (A:ل δ) (base n:م) (hA:baseڇ+nڇ<=Aچ) (hs:baseڇ+nڇ<Ξ) (lo hi:ك) (k:م):ك := if h:k>>23 let kh:=v>>>23 dK A base n hA hs (if kl t L<=YR A[a߷+t]! /\ YM A[a߷+t]! <= H:=by generalize C:n߷-k߷=d;induction d generalizing k b e with | zero => have p:¬ kby omega⟩ rw[UInt32.toNat_add,KU,show(16:ك)؟%32=16 from rfl,υ] omega | succ d s => have p:k>>23)؟=YR w:=rfl;have F:((w&&&ש)>>>23)؟=YM w:=rfl;obtain⟨G,I,-,-⟩:=Zb w;obtain⟨L,H,q,r,v,J,K,x⟩:=s (if ((w&&&ש)-1)>>>23>>23 else b) (if e < (w&&&ש)>>>23 then (w&&&ש)>>>23 else e) (k+1) א (by split_ifs<;>omega) (by split_ifs<;>omega) א have M:(if ((w&&&ש)-1)>>>23>>23 else b)؟<=b؟/\(if ((w&&&ש)-1)>>>23>>23 else b)؟<=YR w:=by split_ifs with o . rw[Ἦ]at o;omega . rw[Ἦ]at o;omega have N:e؟<=(if e < (w&&&ש)>>>23 then (w&&&ש)>>>23 else e)؟/\YM w<=(if e < (w&&&ש)>>>23 then (w&&&ש)>>>23 else e)؟:=by split_ifs with o . rw[Ἦ]at o;omega . rw[Ἦ]at o;omega refine⟨L,H,q,r,v,by omega,by omega,λ t O y=>?_⟩;rcases Nat.lt_or_ge t (k߷+1) with z | z . have B:t=k߷:=א subst B;rw[u];omega . exact x t א y lemma ZL (a b:ك) (d:ٽ) (h:ε a*ε b≠0 -> d<=γ a+γ b/\γ a+γ b<=d+122) : -(2^170:پ)<=sv a*sv b*2^(γ a+γ b-d) /\ sv a*sv b*2^(γ a+γ b-d)<=2^170:=by rw[<- Zn];have g:=ZK a b;by_cases e:ε a*ε b=0 . rw[e];split_ifs<;>simp . obtain⟨j,k⟩:=h e;have f:2^(γ a+γ b-d)<=2^122:=Η ב א;have l:ε a*ε b*2^(γ a+γ b-d)<=2^170:=calc ε a*ε b*2^(γ a+γ b-d)<=2^48*2^122:=Ἢ א f _=2^170:=ב have Zh:((ε a*ε b:ٽ):پ)*2^(γ a+γ b-d)=((ε a*ε b*2^(γ a+γ b-d):ٽ):پ):=by push_cast;ring split_ifs . rw[neg_mul,Zh];omega . rw[Zh];omega lemma ZW (a b:ٽ -> ك):∀ r k,Yo a b k (r+1)=Yo a b k r+sv (a (k+r))*sv (b (k+r))*2^(γ (a (k+r))+γ (b (k+r))):=by intro r;induction r with | zero=>intro k;simp[Yo] | succ r d=>intro k;rw[Yo,d (k+1),Yo,show k+1+r=k+(r+1) by omega];ring lemma ZA (a b:ك) (d:ٽ) (h:ε a*ε b≠0 -> d<=γ a+γ b):sv a*sv b*2^(γ a+γ b)=2^d*(sv a*sv b*2^(γ a+γ b-d)):=by by_cases e:ε a*ε b=0 . have:sv a*sv b=0:=by rw[<- Zn,e];split_ifs<;>simp rw[this];ring rw[show idxOf a+idxOf b=d+(idxOf a+idxOf b-d) by omega,pow_add];rw[show d+(idxOf a+idxOf b-d)-d=idxOf a+idxOf b-d by omega];ring @[inline] def Yc (A:ل δ) (inW i:ٽ):ك := if h:i*inW+inW<=Aچ/\i*inW+inW<=4294967295 then dK A (i*inW).toUSize inWڈ (by rw[Za _ א,Za _ א];exact h.1) (by rw[Za _ א,Za _ א];have:=φ;omega) 511 0 0 else 0x01FF00FF @[inline] def Yk (k:ك):ق:=(if k=0 then 0 else k-1).toUInt64 @[inline] def Yp (bx bv bw:ك):ق := let lo0:=Yk (bx>>>16)+Yk (bv>>>16) let xb:=Yd ζ+Yd bw if !(Yf bw==0)&&xb ٽ -> δ) (ch j:ٽ) (acc:ل δ):ل δ := if j ٽ -> δ) (ch:ٽ) (acc:ل δ):ل δ := if ch ٽ -> δ):ل δ:=dI c hw f 0 (kA (c*hw)) lemma I8 (a:ٽ) (f:ٽ -> ٽ -> δ) (b:ٽ):∀ k j (d:ل δ),a-j=k -> (dJ a f b j d)֍=d֍++(ki j (a-j)).map (f b):=by intro k;induction k with | zero=>intro j d h;unfold dJ;rw[if_neg א];simp[h] | succ k e=> intro j d h;unfold dJ;rw[if_pos א,e (j+1) _ א,show a-j=(a-(j+1))+1 by omega,ϴ];simp lemma U4 (c a:ٽ) (f:ٽ -> ٽ -> δ):∀ k b (d:ل δ),c-b=k -> (dI c a f b d)֍=d֍++(ki (b*a) ((c-b)*a)).map (λ i=>f (i/a) (i%a)):=by intro k;induction k with | zero=>intro b d h;unfold dI;rw[if_neg א];simp[h] | succ k e=> intro b d h;unfold dI;rw[if_pos א,e (b+1) _ א,I8 a f b _ 0 _ rfl,show(c-b)*a=a+(c-(b+1))*a by rw[show c-b=(c-(b+1))+1 by omega,Ϣ,ϫ,ϝ],<- List.range'_append,List.map_append,Nat.succ_mul] simp only[List.append_assoc,kV];congr 2 . rw[show ki (b*a) a=(ki 0 a).map (b*a+·) by rw[List.map_add_range'];simp,List.map_map];apply List.map_congr_left;intro j g;rw[List.mem_range'_1]at g;simp only[Function.comp_def,ϝ (b*a) j,ϙ _ _ (show 0 ٽ -> δ):YT c a f=ډ N λ i=>f (i܁/a) (i܁%a):=by subst b;apply Array.ext';rw[YT,U4 c a f _ 0 _ rfl];apply ἤ<;>simp @[inline] def cq (w:δ) (m:ق):ق := let v:=Yf w<<<(Yd w-m) if (w>>>31).toUInt64==0 then v else 0-v @[inline] def Y4 (w:δ) (m:ق):ك:=(cq w m+0x80000000).toUInt32 lemma Zq (k:ك):(Yk k)˟=k؟-1:=by unfold Yk;split_ifs with h . subst h;rfl . rw[ϯ,kZ _ _ (by rw[Ἐ];have:k؟≠0:=λ a=>h (Ν.mp (by simpa using a));show 1<=k؟;omega)] rfl lemma I2 (x y:ك):(Yk x+Yk y)˟=x؟-1+(y؟-1):=by rw[ξ,Zq,Zq];have:x؟<2^32:=Ἁ _;have:y؟<2^32:=Ἁ _;exact ν א lemma ZM (a:ك):(Yd ζ+Yd a)˟=γ ζ+γ a:=by rw[ξ,Zf,Zf];have:=Zg ζ;have:=Zg a;exact ν א lemma F4 (b d a:ك):(Yp b d a)˟<=((b>>>16)؟-1)+((d>>>16)؟-1) /\ (ε a≠0 -> (Yp b d a)˟<=γ ζ+γ a):=by have h:=I2 (b>>>16) (d>>>16);have j:=ZM a;have f:=I4 a;unfold Yp;dsimp only;rw[f];split_ifs with e . simp only[ϓ,ἠ,decide_eq_false_iff_not,ء,Ι]at e;omega . simp only[ϓ,ἠ,decide_eq_false_iff_not,ء,Ι,not_and,not_lt]at e;constructor . omega . intro g;have:=e g;omega lemma F3 (b d a:ك):((b&&&0xFFFF)؟-1)+((d&&&0xFFFF)؟-1)<=(Yu b d a)˟ /\ (ε a≠0 -> γ ζ+γ a<=(Yu b d a)˟):=by have h:=I2 (b&&&0xFFFF) (d&&&0xFFFF);have j:=ZM a;have f:=I4 a;unfold Yu;dsimp only;rw[f];split_ifs with e . simp only[ϓ,ἠ,decide_eq_false_iff_not,ء,Ι]at e;omega . simp only[ϓ,ἠ,decide_eq_false_iff_not,ء,Ι,not_and,not_lt]at e;constructor . omega . intro g;have:=e g;omega lemma Zo (a:ك) (L H:ٽ) (h:a؟=L*2^16+H) (b:H<2^16):(a>>>16)؟=L/\(a&&&0xFFFF)؟=H:=by constructor . rw[϶,show(16:ك)؟%32=16 from rfl,ω,h];omega . rw[ἣ,show(0xFFFF:ك)؟=2^16-1 from rfl,Ϙ,h];omega lemma Zp (A:ل δ) (a i:ٽ) (b:i*a+a<=Aچ) (d:i*a+a<=4294967295) : ∃ L H:ٽ,(Yc A a i)؟=L*2^16+H/\L<=511/\H<=255 /\ ∀ t,t < a -> L<=YR A[i*a+t]! /\ YM A[i*a+t]! <= H:=by have f:(i*a)۞߷=i*a:=Za _ א;have g:a۞߷=a:=Za _ א;unfold Yc;rw[dif_pos ⟨b,by omega⟩];obtain⟨L,H,e,h,j,-,-,k⟩:=U7 A (i*a)۞ a۞ (by rw[f,g];exact b) (by rw[f,g];have:=φ;omega) 511 0 0 ג ד ד refine⟨L,H,e,h,j,λ t l=>?_⟩;have:=k t ג (by rw[g];exact l);rwa[f]at this lemma A4 (S:پ) (a:ق) (c:ه) (b D:δ) (d:S=0 -> b=D) (e:D=ρ (S*2^a˟) (-298) c) : (if (if S=0 then 4294967296 else (ρ S ((a˟:پ)-298) false)܌)<4294967296 then (if S=0 then 4294967296 else (ρ S ((a˟:پ)-298) false)܌)؛ else b)=D:=by by_cases f:S=0 . rw[if_pos f,if_neg ד,d f] . rw[if_neg f];have g:(ρ S ((a˟:پ)-298) false)܌<4294967296:=by rw[Ι];simpa using Ἁ (ρ S ((a˟:پ)-298) false) rw[if_pos g,e,<- ἄ];have h:(ρ S ((a˟:پ)-298) false)܌؛=ρ S ((a˟:پ)-298) false:=by apply Ν.mp;simp rw[h];unfold finishWord;rw[if_neg f,if_neg f,show(-298:Int)+(a˟:Int)=(a˟:Int)-298 by ring] lemma D6 (u p:ق) (b:¬u122):p˟<=u˟/\u˟-p˟<=122:=by rw[Ι]at b;have d:p˟<=u˟:=א rw[gt_iff_lt,Ι,Α _ _ (Ϯ.mpr d)]at a;exact⟨d,Nat.not_lt.mp a⟩ lemma G0 {L r i:ٽ} (a:L<=r) (b:r<=i+1):L-1<=i:=א lemma F9 {m H i:ٽ} (a:m<=H) (b:i+1<=max m 1):i<=H-1:=א lemma ZQ {p u a b c d B:ٽ} {x w:δ} (h:p<=(a-1)+(b-1)) (j:(c-1)+(d-1)<=u) (k:u-p<=B) (e:a<=YR x/\YM x<=c) (f:b<=YR w/\YM w<=d) (g:ε x*ε w≠0):p<=γ x+γ w/\γ x+γ w<=p+B:= have l:=(Zb x).2.2.2 (left_ne_zero_of_mul g);have n:=(Zb w).2.2.2 (right_ne_zero_of_mul g);⟨h.trans (Ἆ (G0 e.1 l.1) (G0 f.1 n.1)),(Ἆ (F9 e.2 l.2) (F9 f.2 n.2)).trans (j.trans (Nat.sub_le_iff_le_add'.mp k))⟩ lemma M5 (x y:FloatLib.Numerics.Dyadic) (h:(ἓ x y).significand=0) : (ἓ x y).negative=(x.negative&&y.negative):=by unfold ἓ FloatLib.Numerics.Dyadic.add FloatLib.Numerics.Dyadic.addFields at h ⊢;dsimp only at h ⊢;split_ifs at h ⊢<;>simp_all only[beq_iff_eq,Int.ofNat_eq_natCast,Nat.shiftLeft_eq',Int.natCast_shiftLeft,Bool.and_self,Int.natAbs_eq_zero,Bool.not_eq_true,Bool.and_false,Bool.and_true,not_le] lemma M4 (d:FloatLib.Numerics.Dyadic) (h:d.significand=0):Model.roundDyadic κ d=kQ κ d.negative:=by rw[Model.roundDyadic_eq_roundDyadicImpl];unfold Model.roundDyadicImpl;rw[if_pos ד];unfold Model.ieeeRoundDyadicImpl;rw[if_pos (by simp[h])];cases d.negative<;>rfl lemma ZN (k:ٽ):(2:ℚ)^((k:ℤ)-149)=2^k*2^(-149:ℤ):=by rw[sub_eq_add_neg,zpow_add₀ two_ne_zero,ا] lemma F0:(2:ℚ)^(-149:ℤ)*2^(-149:ℤ)=2^(-298:ℤ):=by rw[<- zpow_add₀ two_ne_zero];norm_num lemma M3 (x y z:δ) (a:θ x≠255) (b:θ y≠255) (d:θ z≠255):π (KG (ι x) (ι y) (ι z))=ρ (sv x*sv y*2^(γ x+γ y)+sv z*2^(γ z+149)) (-298) (Γ (η x) (η y)&&η z):=by rw[Model.Proof.fma_eq_spec];have e:=Ϟ x a;have f:=Ϟ y b;have g:=Ϟ z d;have o:Model.chooseNaN3 (kO x:Model κ) (kO y) (kO z)=none := (Model.chooseNaN3_eq_none_iff _ _ _).2 ⟨ٿ e,ٿ f,ٿ g⟩ simp only[Model.Spec.fma,ofW,o,kM e,kM f,kM g, Bool.or_false,χ,ؠ,e,f,g] set P:FloatLib.Numerics.Dyadic := { negative:=Γ (Ο x).negative (Ο y).negative significand:=(Ο x).significand*(Ο y).significand exponent:=(Ο x).exponent+(Ο y).exponent } with h have p:(ἓ P (Ο z)).toRat=((sv x*sv y*2^(γ x+γ y)+sv z*2^(γ z+149):پ):ℚ)*2^(-298:ℤ):=by have j:=FloatLib.Numerics.Dyadic.mul_toRat (Ο x) (Ο y);simp only[FloatLib.Numerics.Dyadic.mul,FloatLib.Numerics.Dyadic.mulFields]at j;rw[ἓ,FloatLib.Numerics.Dyadic.add_toRat,h,j,ϕ,ϕ,ϕ,ZN,ZN,ZN,<- F0] have k:(2:ℚ)^(γ z+149)*2^(-298:ℤ)=2^γ z*2^(-149:ℤ):=by rw[pow_add,<- F0,mul_assoc] norm_num push_cast;rw[<- F0]at k;linear_combination (sv z:ℚ)*k by_cases l:sv x*sv y*2^(γ x+γ y)+sv z*2^(γ z+149)=0 . have n:(ἓ P (Ο z)).significand=0:=ט rw[M4 _ n,M5 _ _ n,h];rw[ἑ,ἑ,ἑ,l,finishWord_zero] . exact(finishWord_of_ne _ _ _ _ l p).symm lemma M2 (j:ٽ) (a:j<=6):θ (natW (2^j))≠255/\η (natW (2^j))=false /\ ε (natW (2^j))=2^23/\γ (natW (2^j))=126+j:=by interval_cases j<;>decide lemma E9 (w:ك):η w=decide (2^31<=w؟):=by have a:=w.toNat_lt_size;have h:(w&&&߿)؟=2^31*(w؟/2^31%2):=by rw[ἣ,show(߿:ك)؟=2^31 from rfl,Nat.and_two_pow,KD] have b:w؟/2^31%2<2:=Χ _ ב;generalize w؟/2^31%2=q at b ⊢;interval_cases q<;>rfl unfold signOf;rw[ἁ];simp;rw[<- Ν,h,show(0:ك)؟=0 from rfl];simp only[UInt32.size]at a;omega lemma ey (s:δ) (j:ٽ) (b:j<=6) (a:j < (θ s)؟):(θ (s-(ϣ j<<<23)))؟=(θ s)؟-j /\ fracOf (s-(ϣ j<<<23))=fracOf s /\ η (s-(ϣ j<<<23))=η s:=by rw[ZH]at a;have e:(ϣ j<<<23)؟=j*2^23:=by rw[KU,Ἓ,υ,show(23:ك)؟%32=23 from rfl,ν (by omega:j<2^32)] exact ν א have f:ϣ j<<<23<=s:=by rw[Ἐ,e];omega have d:(s-(ϣ j<<<23))؟=s؟-j*2^23:=ט refine⟨?_,?_,?_⟩ . rw[ZH,ZH,d];omega . apply Ν.mp;rw[ZR,ZR,d];omega . rw[E9,E9,d];simp;omega lemma ZX (w:δ) (a:θ w≠255):ϥ (ι w)=(sv w:ℝ)*2^((γ w:ℤ)-149):=by rw[Model.toReal_eq];simp only[ofW,Ϟ w a];rw[<- FloatLib.Numerics.Dyadic.cast_toRat,ϕ];push_cast;rfl lemma ex (s y:δ) (j:ٽ) (f:j<=6) (a:θ s≠255) (b:j < (θ s)؟) (d:θ y≠255) (g:η y=false) (e:ε y=2^23) (k:γ y=126+j) : π (kN (ι s) (ι y))=s-(ϣ j<<<23):=by have A:sv y=2^23:=by unfold sv;rw[g,e];rfl have B:Model.isZero (ι y)=false:=by rw[ofW,Model.isZero_eq_beq_zero_of_toDyadic?_some (Ϟ y d),decodeD_sig_zero,e];decide obtain⟨C,D,E⟩:=ey s j f b;set r:=s-(ϣ j<<<23) with M;have N:=expOf_toNat_lt s;have l:θ r≠255:=by intro h;have n:=congrArg kv h;simp at n;have O:(θ s)؟≠255:=λ F=>a (Ν.mp (by simpa using F));omega have q:θ r≠0:=by intro h;have n:=congrArg kv h;simp at n;omega have t:θ s≠0:=by intro h;rw[h]at b;simp at b have G:sv r=sv s:=by unfold sv mantOf;rw[E,D,if_neg q,if_neg t] have H:(γ r:ℤ)=(γ s:ℤ)-j:=by unfold idxOf;rw[if_neg q,if_neg t,C];omega have o:ἔ (ι s)=true:=by simp[ofW,ἐ,a] have u:ἔ (ι y)=true:=by simp[ofW,ἐ,d] have v:ἔ (ι r)=true:=by simp[ofW,ἐ,l] have w:Model.isZero (ι y)=false:=B;have x:ϥ (ι y)=2^j:=by rw[ZX _ d,A,k];push_cast;rw[show((126:ℤ)+j-149)=(j:ℤ)+(-23) by ring,zpow_add₀ two_ne_zero,ا] field_simp;norm_num have I:ϥ (ι r)=ϥ (ι s)/2^j:=by rw[ZX _ l,ZX _ a,G,H,show((idxOf s:ℤ)-j-149)=((idxOf s:ℤ)-149) + -(j:ℤ) by ring,zpow_add₀ two_ne_zero,zpow_neg,ا] field_simp have J : |ϥ (ι s)/ϥ (ι y)| <= ϥ (Model.posMaxFinite κ):=by rw[x,abs_div,abs_of_pos (by positivity:(0:ℝ)<2^j)] calc |ϥ (ι s)| / 2^j <= |ϥ (ι s)| := div_le_self (abs_nonneg _) (one_le_pow₀ ב) _<=_:=Model.abs_toReal_le_posMaxFinite_of_isIEEE_of_isFinite _ ד o have z:ἔ (kN (ι s) (ι y))=true:=Model.isFinite_div_of_abs_div_le_posMaxFinite _ _ ד o u w J have p:=Model.toReal_div_eq_roundAt _ _ ד o u w z;rw[x,<- I,Model.roundAt_toReal_eq _ v]at p;have K:ϥ (kN (ι s) (ι y))≠0:=by rw[p,ZX _ l];apply mul_ne_zero _ (zpow_ne_zero _ two_ne_zero);have:sv r≠0:=by unfold sv mantOf;split<;>omega exact_mod_cast this have L:=Model.eq_of_toReal_eq_of_nonzero z v p K;rw[L,O0] lemma ev (s:δ) (j:ٽ) (a:j<=6) (b:θ s≠255) (d:j < (θ s)؟) : π (kN (ι s) (ι (natW (2^j))))=s-(ϣ j<<<23):=by obtain⟨e,f,g,h⟩:=M2 j a;exact ex s _ j a b d e f g h lemma eu (s y:δ) (a:θ s=0) (b:fracOf s=0) (d:θ y≠255) (e:η y=false) (f:ε y≠0) : π (kN (ι s) (ι y))=s:=by have n:θ s≠255:=ז rw[Model.Proof.div_eq_spec];simp only[Model.Spec.div,ofW,Ϟ s n,Ϟ _ d];have o:Ο s=⟨η s,0,0⟩:=by simp[decodeD,a,b] have p:((Ο y).significand==0)=false:=by rw[decodeD_sig_zero];simp[f] rw[o,p,ἑ,e];have q:=s.toNat_lt_size;simp only[UInt32.size]at q;have j:=ZH s;have k:=ZR s;rw[a]at j;rw[b]at k;simp at j k;have g:=E9 s;cases l:η s . rw[l]at g;have:s؟<2^31:=by simpa using g.symm have h:s=0:=Ν.mp ו rw[h];rfl . rw[l]at g;have:2^31<=s؟:=by simpa using g.symm have h:s=߿:=Ν.mp ו rw[h];rfl lemma X9 (s:δ) (j:ٽ) (a:j<=6) (b:θ s=0) (d:fracOf s=0) : π (kN (ι s) (ι (natW (2^j))))=s:=by obtain⟨e,f,g,-⟩:=M2 j a;exact eu s _ b d e f (by rw[g];norm_num) @[inline] def Yl (w:δ):ق := if θ w=0 then (fracOf w).toUInt64 else (fracOf w).toUInt64+0x800000 lemma Zs (w:δ):(Yl w)˟=ε w:=by have a:=fracOf_toNat_lt w;unfold Yl mantOf;split . simp . rw[ξ,ϯ,show(0x800000:ق)˟=2^23 from rfl,ν א] omega lemma X8 (m:ق) (a:ه) (b:m˟<2^63):Ym (if a then 0-m else m)=if a then -(m˟:پ) else (m˟:پ):=by cases a . simp only[χ,ؠ,Ym];rw[if_pos b];simp . simp only[ת,Ym];rw[Φ,show(0:ق)˟=0 from rfl];by_cases d:m˟=0 . rw[d];norm_num . have e:(2^64-m˟+0)%2^64=2^64-m˟:=א omega lemma M1 (x y:ق) (a : -2^63<=Ym x+Ym y) (b:Ym x+Ym y<2^63):Ym (x+y)=Ym x+Ym y:=by unfold Ym at a b ⊢;rw[ξ];split_ifs at a b ⊢<;>omega lemma X7 (m:ق) (d:ٽ) (a:d<64) (h:m˟*2^d<2^64):(m<<simp[h] lemma ZY (m:ق) (d:ٽ) (a:ه) (b:d<64) (h:m˟*2^d<2^62) : Ym (if a then 0-(m<<simp[Nat.cast_mul,Nat.cast_pow] lemma E8 (w:δ):(if η w then -((Yl w)˟:پ) else ((Yl w)˟:پ))=sv w:=by rw[Zs];rfl lemma ZO:sv ζ=2^23/\γ ζ=126:=ד lemma P1 (a b:δ) (e:ٽ) (h:ε a*ε b≠0 -> e<128) : -2^175constructor<;>linarith lemma X5 (S e:پ) (a b:ه) (h:S≠0):ρ S e a=ρ S e b:=by simp[finishWord,h] lemma X4 (a b p q:ق):(a≠0 -> (if a=0 then q else if b=0 then p else if p<=q then p else q)<=p) /\ (b≠0 -> (if a=0 then q else if b=0 then p else if p<=q then p else q)<=q):=ז @[inline] def dH (a b c d:δ) (nz:ه) (slow:Unit -> δ):δ := let p:=Yd a+Yd b let q:=Yd c+Yd d let m1:=Yf a*Yf b let m2:=Yf c*Yf d let lo:=if m1=0 then q else if m2=0 then p else if p<=q then p else q if (m1=0\/p-lo<128)/\(m2=0\/q-lo<128) then YL lo a b 0 0 0 0 λ w2 w1 w0 k => YL lo c d w2 w1 w0 k λ v2 v1 v0 k' => let r:=YD v2 v1 v0 k' ((loڇ:پ)-298) if r=0x100000000 then (if nz then 0x80000000 else 0) else r.toUInt32 else slow () lemma I5 (a b:δ) (d:ق) (e:(Yd a+Yd b)˟=γ a+γ b) (z:Yf a*Yf b=0↔ε a*ε b=0) (L:Yf a*Yf b≠0 -> d<=Yd a+Yd b) (f:Yf a*Yf b=0\/Yd a+Yd b-d<128) : ε a*ε b≠0 -> d˟<=γ a+γ b/\γ a+γ bk (z.mp h);have l:=L g;have j:Yd a+Yd b-d<128:=f.resolve_left g rw[Κ,e]at l;rw[Ι,Α _ _ (L g),e]at j;simp at j;omega lemma P0 (a b c d:δ) (f:ه) (e:Unit -> δ) (g:e ()=ρ (sv a*sv b*2^(γ a+γ b)+sv c*sv d*2^(γ c+γ d)) (-298) f) : dH a b c d f e=ρ (sv a*sv b*2^(γ a+γ b)+sv c*sv d*2^(γ c+γ d)) (-298) f:=by unfold dH;dsimp only;have O:=Zg a;have P:=Zg b;have Q:=Zg c;have id:=Zg d;have D:=D5 a b have E:=D5 c d have R:=C5 a b have S:=C5 c d have F:=I1 a b have G:=I1 c d obtain⟨L1,L2⟩:=X4 (Yf a*Yf b) (Yf c*Yf d) (Yd a+Yd b) (Yd c+Yd d) generalize T:(if Yf a*Yf b=0 then Yd c+Yd d else if Yf c*Yf d=0 then Yd a+Yd b else if Yd a+Yd b<=Yd c+Yd d then Yd a+Yd b else Yd c+Yd d)=j at L1 L2 ⊢ split . rename_i y;have F1:=I5 a b j D F L1 y.1;have F2:=I5 c d j E G L2 y.2 obtain⟨t,u,v,k,w,H,z⟩:=Zr j a b 0 0 0 0 (λ t u v k=>YL j c d t u v k λ n o p q=>let r:=YD n o p q ((j˟:پ)-298);if r=ר then (if f then (߿:ك) else 0) else r؛) ג F1 rw[w];obtain⟨n,o,p,q,x,U,I⟩:=Zr j c d t u v k (λ n o p q=>let r:=YD n o p q ((j˟:پ)-298);if r=ר then (if f then (߿:ك) else 0) else r؛) (by simp at H;omega) F2 rw[x];have A:=P1 a b (γ a+γ b-j˟) (λ l=>by omega) have B:=P1 c d (γ c+γ d-j˟) (λ l=>by omega) have J:Yx 0 0 0=0:=rfl;rw[J,show(0:ق)˟=0 from rfl]at z;have K:((Yx n o p+q˟:ٽ):پ)%2^192=(sv a*sv b*2^(γ a+γ b-j˟)+sv c*sv d*2^(γ c+γ d-j˟))%2^192:=by rw[I];rw[ϩ,z,<- ϩ];simp rw[ZV n o p q _ _ (by linarith [A.1,B.1]) (by linarith [A.2,B.2]) K];have C:sv a*sv b*2^(γ a+γ b)+sv c*sv d*2^(γ c+γ d)=(sv a*sv b*2^(γ a+γ b-j˟)+sv c*sv d*2^(γ c+γ d-j˟))*2^j˟:=by have w:=ZC (sv a*sv b) (γ a+γ b) j˟ (by by_cases l:ε a*ε b=0 . left;rw[<- Zn,l];simp . right;exact(F1 l).1) have x:=ZC (sv c*sv d) (γ c+γ d) j˟ (by by_cases l:ε c*ε d=0 . left;rw[<- Zn,l];simp . right;exact(F2 l).1) rw[w,x];ring by_cases s:sv a*sv b*2^(γ a+γ b-j˟)+sv c*sv d*2^(γ c+γ d-j˟)=0 . rw[if_pos s,if_pos rfl,C,s,zero_mul];cases f<;>rfl . rw[if_neg s];have L:(ρ (sv a*sv b*2^(γ a+γ b-j˟)+sv c*sv d*2^(γ c+γ d-j˟)) ((j˟:پ)-298) false)܌ ≠ר:=by intro h;have M:=congrArg Ἡ h;have:=Ἁ (ρ (sv a*sv b*2^(γ a+γ b-j˟)+sv c*sv d*2^(γ c+γ d-j˟)) ((j˟:پ)-298) false) simp only[UInt32.size]at this;simp at M;omega rw[if_neg L,kF,C,show((j˟:Int)-298) = -298+(j˟:Int) by ring,ἄ] apply X5;intro h;apply s;have N:(2:پ)^j˟≠0:=pow_ne_zero _ two_ne_zero;exact(mul_eq_zero.mp h).resolve_right N . exact g @[inline] def Y1 (ma mb:ق) (ia ib:ٽ):ٽ := if ma=0 then ib else if mb=0 then ia else min ia ib lemma O9 (a b:ق) (d e:ٽ):(a=0\/Y1 a b d e<=d)/\(b=0\/Y1 a b d e<=e):=by unfold Y1;refine⟨?_,?_⟩<;>split_ifs<;>first | (left;assumption) | (right;omega) @[inline] def cW (x y z:δ):δ := if θ x=255\/θ y=255\/θ z=255 then π (KG (ι x) (ι y) (ι z)) else let mp:=Yl x*Yl y let mz:=Yl z let p:=γ x+γ y let q:=γ z+149 let k:=Y1 mp mz p q let dp:=p-k let dq:=q-k if dp<=14/\dq<=38 then let neg:=Γ (η x) (η y) let tp:=mp<<π (KG (ι x) (ι y) (ι z))) lemma X1 (x y z:δ):cW x y z=π (KG (ι x) (ι y) (ι z)):=by unfold cW;split . rfl . rename_i h;have n:θ x≠255:=λ d=>h (Ω d);have o:θ y≠255:=λ d=>h (Or.inr (Ω d));have p:θ z≠255:=λ d=>h (Or.inr (Or.inr d));dsimp only;split . rename_i q;rw[M3 x y z n o p];have g:(Yl x*Yl y)˟=ε x*ε y:=by rw[ϱ,Zs,Zs];exact ν (mul_mant_lt x y) have B:(Yl x*Yl y)˟<2^48:=by rw[g];calc ε x*ε y<2^24*2^24:=Nat.mul_lt_mul'' (ϖ x) (ϖ y) _=2^48:=ב have C:(Yl z)˟<2^24:=by rw[Zs];exact ϖ z obtain⟨D,E⟩:=O9 (Yl x*Yl y) (Yl z) (γ x+γ y) (γ z+149);set k:=Y1 (Yl x*Yl y) (Yl z) (γ x+γ y) (γ z+149);set a:=Yl x*Yl y;have j:a˟*2^(γ x+γ y-k)<2^62:=calc a˟*2^(γ x+γ y-k)<2^48*2^14:=ἕ B (Η ב q.1) ה _=2^62:=ב have l:(Yl z)˟*2^(γ z+149-k)<2^62:=calc (Yl z)˟*2^(γ z+149-k)<2^24*2^38:=ἕ C (Η ב q.2) ה _=2^62:=ב have e:=ZY a (γ x+γ y-k) (Γ (η x) (η y)) א j have f:=ZY (Yl z) (γ z+149-k) (η z) א l;have r:(if Γ (η x) (η y) then -(a˟:پ) else (a˟:پ))=sv x*sv y:=by rw[g,Zn] have s:(if η z then -((Yl z)˟:پ) else ((Yl z)˟:پ))=sv z:=E8 z;rw[r]at e;rw[s]at f;have t:(0:پ)<=a˟*2^(γ x+γ y-k):=ג have u:(0:پ)<=(Yl z)˟*2^(γ z+149-k):=ג have v:(sv x*sv y)*2^(γ x+γ y-k)=(if Γ (η x) (η y) then -(a˟:پ) else (a˟:پ))*2^(γ x+γ y-k):=by rw[r] have w:sv z*2^(γ z+149-k)=(if η z then -((Yl z)˟:پ) else ((Yl z)˟:پ))*2^(γ z+149-k):=by rw[s] have F : -2^63<=sv x*sv y*2^(γ x+γ y-k)+sv z*2^(γ z+149-k):=by rw[v,w];cases Γ (η x) (η y)<;>cases η z<;>simp<;>linarith only[t,u,j,l] have G:sv x*sv y*2^(γ x+γ y-k)+sv z*2^(γ z+149-k)<2^63:=by rw[v,w];cases Γ (η x) (η y)<;>cases η z<;>simp<;>linarith only[t,u,j,l] rw[F7,M1 _ _ (by rw[e,f];exact F) (by rw[e,f];exact G),e,f,show((k:پ)-298) = -298+(k:پ) by ring,ἄ] have H:=ZC (sv x*sv y) (γ x+γ y) k (by rcases D with b | b . left;have:ε x*ε y=0:=by rw[<- g,b];rfl rw[<- Zn,this];simp . right;exact b) have I:=ZC (sv z) (γ z+149) k (by rcases E with b | b . left;have:ε z=0:=by rw[<- Zs];simp[b] exact X6 z this . right;exact b) rw[H,I];ring . have J:=M3 x y z n o p;have A:π (KG (ι x) (ι y) (ι z))=ρ (sv x*sv y*2^(γ x+γ y)+sv z*sv ζ*2^(γ z+γ ζ)) (-298) (Γ (η x) (η y)&&η z):=by rw[J,ZO.1,ZO.2];ring rw[P0 _ _ _ _ _ _ A,A] @[inline] def dr (j:ٽ) (s:δ):δ := if θ s≠255/\j < (θ s).toNat then s-(ϣ j<<<23) else if θ s=0/\fracOf s=0 then s else π (kN (ι s) (ι (natW (2^j)))) lemma O8 (j:ٽ) (a:j<=6) (s:δ):dr j s=π (kN (ι s) (ι (natW (2^j)))):=by unfold dr;split . rename_i h;exact(ev s j a h.1 h.2).symm . split . rename_i b;exact(X9 s j a b.1 b.2).symm . rfl @[inline] def dh (kk:ٽ) (s:δ):δ := if kk=4 then dr 2 s else if kk=64 then dr 6 s else π (kN (ι s) (ι (natW kk))) lemma O7 (a:ٽ) (s:δ):dh a s=π (kN (ι s) (ι (natW a))):=by unfold dh;split . rename_i h;subst h;exact O8 2 ב s . split . rename_i h;subst h;exact O8 6 ב s . rfl def ed (c h w k:ٽ) (aC:ل δ):ل δ := Ἲ (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) dh (k*k) (Yn (k*k) (poolAt h w k aC ch y x) (λ _=>ζ)) lemma X0:ed=avgpoolSpec:=by funext c h w k a;simp only[ed,avgpoolSpec,avgpoolWith,O7,Zi] @[specialize] def YE (n:م) (fx fw:(t:م) -> t δ) (lo:ق) (e:پ) (bx bw:ك) (w2 w1 w0 c:ق) (k:م):ق := if h:k YE n fx fw lo e bx bw v2 v1 v0 c' (k+1) else YL lo bx bw w2 w1 w0 c λ v2 v1 v0 c'=>YD v2 v1 v0 c' e termination_by nڇ-kڇ decreasing_by exact ZI n k h def Yr (fa fb:ٽ -> δ) (lo k:ٽ):ٽ -> پ | 0=>0 | r+1=>sv (fa k)*sv (fb k)*2^(γ (fa k)+γ (fb k)-lo)+Yr fa fb lo (k+1) r lemma F8 (n:م) (o p:(t:م) -> t δ) (g a:ٽ -> δ) (q:∀ t h,o t h=g t߷) (r:∀ t h,p t h=a t߷) (f:ق) (e:پ) (j l:ك) (s:n߷<2^32) (b:ε j*ε l≠0 -> f˟<=γ j+γ l/\γ j+γ l k߷<=n߷ -> c˟<=k߷ -> (∀ t,k߷<=t -> t ε (g t)*ε (a t)≠0 -> f˟<=γ (g t)+γ (a t)/\γ (g t)+γ (a t) ((Yx C D E+c˟:ٽ):پ)%2^192=S0%2^192 -> S=S0+Yr g a f˟ k߷ (n߷-k߷)+sv j*sv l*2^(γ j+γ l-f˟) -> -2^191<=S -> S<2^191 -> YE n o p f e j l C D E c k=if S=0 then ר else (ρ S e false)܌:=by intro d;induction d with | zero => intro k C D E c S0 S J K L G x u v w;have F:¬ kYD y z A B e) (by clear x u v w b;omega) b rw[H];apply ZV y z A B e S v w;rw[I,u,show n߷-k߷=0 by clear x u v w b;omega,Yr];omega | succ d N => intro k C D E c S0 S J K L G x u v w;have F:kYE n o p f e j l y z A B (k+1)) (by clear x u v w b;omega) (G k߷ (le_refl _) (by clear x u v w b;omega)) rw[H];refine N (k+1) y z A B (S0+sv (g k߷)*sv (a k߷)*2^(γ (g k߷)+γ (a k߷)-f˟)) S (by clear x u v w b;omega) (by clear x u v w b;omega) (by clear x u v w b;omega) (λ t Q P=>G t (by clear x u v w b;omega) P) ?_ ?_ v w . rw[I];omega . rw[u,show n߷-k߷=(n߷-(k+1)߷)+1 by clear x u v w b;omega,Yr,O];ring lemma C7 (a b:ٽ -> δ) (d:ٽ):∀ (r k:ٽ),(∀ t,k<=t -> t ε (a t)*ε (b t)≠0 -> d<=γ (a t)+γ (b t)/\γ (a t)+γ (b t)<=d+122) -> -((r:پ)*2^170)<=Yr a b d k r/\Yr a b d k r<=(r:پ)*2^170:=by intro r;induction r with | zero=>intro k _;simp[Yr] | succ r e=>intro k h;obtain⟨f,g⟩:=ZL (a k) (b k) d (h k (le_refl _) א);obtain⟨j,l⟩:=e (k+1) (λ t n o=>h t א א);rw[Yr];push_cast;constructor<;>linarith lemma O6 (a b:ٽ -> δ) (K d:ٽ) (e f:ك):∀ r k,k+r<=K -> (∀ t,k<=t -> t ε (a t)*ε (b t)≠0 -> d<=γ (a t)+γ (b t)) -> Yo (λ t=>if tif tintro k _ _;simp[Yo,Yr] | succ r g=>intro k j h;rw[Yo,Yr,g (k+1) א (λ t l n=>h t א א)];simp only[show k t δ) (e a:ٽ -> δ) (o:∀ t h,f t h=e t߷) (p:∀ t h,g t h=a t߷) (b:ك) (d:ق) (v:K<1048576) (q:∀ t,t θ (e t)≠255) (r:∀ t,t θ (a t)≠255) (s:θ b≠255) (l:∀ t,t ε (e t)*ε (a t)≠0 -> d˟<=γ (e t)+γ (a t)/\γ (e t)+γ (a t)<=d˟+122) (j:ε ζ*ε b≠0 -> d˟<=γ ζ+γ b/\γ ζ+γ b<=d˟+122) (n:δ) (u:n=Β (K+1) (λ t=>if tif tif tif tl t א w);have H:=ZL ζ b d˟ j;generalize A:Yr e a d˟ 0 K+sv ζ*sv b*2^(γ ζ+γ b-d˟)=Srel have B : -2^191<=Srel:=א have C:Srel<2^191:=א have D:=F8 K۞ f g e a o p d ((d˟:پ)-298) ζ b א (λ h=>⟨(j h).1,by have:=(j h).2;omega⟩) K 0 0 0 0 0 0 Srel (by simp[y]) ג ג (λ t _ z w=>by have:=l t א w;exact⟨this.1,by omega⟩) (by simp[Yx]) (by rw[<- A,y];simp) B C rw[D];have E:∀ k,k θ ((λ t=>if tif tif tif tif tif t(l t א w).1)] simp;rw[ZA oneW b d˟ (λ h=>(j h).1),<- A];ring exact A4 _ _ _ _ _ (λ _=>u) F @[inline] def Yb (s:σ):ٽ:=s.h+2*s.pad @[inline] def Ya (s:σ):ٽ:=s.w+2*s.pad @[inline] def YI (s:σ) (aC:ل δ) (idx:ٽ):δ := let c:=idx/(Yb s*Ya s) let yy:=idx/Ya s%Yb s let xx:=idx%Ya s if yy=s.h\/xx-s.pad>=s.w then 0 else aC[(c*s.h+(yy-s.pad))*s.w+(xx-s.pad)]! @[inline] def Ys (s:σ) (t:ٽ):ٽ := t/(s.kh*s.kw)*(Yb s*Ya s)+t/s.kw%s.kh*Ya s+t%s.kw lemma O5 (c a b A B:ٽ) (e:a b+(a[t]!)؟if tif tif tif t pbn+(off[t]!).toNat122 then dG s aC aD b k o cw y x else let r:=YE kڈ (λ t ht=>P.uget (pbnڈ+(off.uget t (by rw[hoff];rw[τ,Za _ א] at ht;exact ht)).toUSize) (by have:=O3 P off k pbn hoff hPs hix t ht א (by rw[hoff];rw[τ,Za _ א] at ht;exact ht) rw[this.1];exact this.2)) (λ t ht=>aD.uget ((o*k).toUSize+t) (by have:=Z0 aD o k h t ht rw[this.1];exact this.2)) lo ((loڇ:پ)-298) ζ bw 0 0 0 0 0 if r<0x100000000 then r.toUInt32 else dG s aC aD b k o cw y x else dG s aC aD b k o cw y x lemma L3 (s:σ) (d P:ل δ) (e:ل ك) (a b:ل δ) (k o g y x f:ٽ) (l:e܆=k) (n:k<1048576) (p:Pچ<4294967296) (j:∀ t,t f+(e[t]!)؟ P[f+(e[t]!)؟]! = Δ s d y x (g+t)) : d6 s d P e a b k o g y x f (Yc P Pچ 0) (Yc a k o) l n p j = Β (k+1) (λ t=>if tif tW (Ν.mp (by rw[K,h];rfl));have d2:Hv≠255:=λ h=>X (Ν.mp (by rw[L,h];rfl));obtain⟨d4,N⟩:=D6 _ _ Z c5 have O:∀ t,t Δ s d y x (g+t)=P[0*Pچ+(f+(e[t]!)؟)]! :=λ t r=>by rw[Ϫ,Λ];exact(q t r).symm apply J3 k _ _ (λ t=>Δ s d y x (g+t)) (λ t=>a[o*k+t]!) _ _ b[o]! (Yp z A b[o]!) n . intro t r;rw[O t r];exact(Zb _).2.2.1 (ϊ (H _ (j t r)).2 (ϰ S d1)) . intro t r;exact(Zb _).2.2.1 (ϊ (J t r).2 (ϰ T d2)) . exact Y . intro t r B;rw[O t r]at B ⊢;exact ZQ u v N (H _ (j t r)) (J t r) B . intro B;have Q:ε b[o]! ≠ 0:=λ h=>B (by rw[h,Ϝ]);exact⟨D Q,(E Q).trans (Nat.sub_le_iff_le_add'.mp N)⟩ . exact E7 s d a b k o g y x . intro t r;have hi:k۞߷=k:=Za _ א have hh:t߷(Ys s t܁).toUInt32)[t]!)؟=Ys s t:=ט def ds (s:σ) (aB:ه) (aC aD b:ل δ):ل δ := if hg:s.kh<=Yb s/\s.kw<=Ya s/\s.cin*(Yb s*Ya s)<=4294967295 /\ s.cin*s.kh*s.kw<1048576 then let P:ل δ:=ډ (s.cin*(Yb s*Ya s)) λ i=>YI s aC i.val let off:ل ك:=ډ (s.cin*s.kh*s.kw) λ t=>(Ys s t.val).toUInt32 let bp:=Yc P Pچ 0 let BW:ل ك:=ډ s.cout λ o=>Yc aD (s.cin*s.kh*s.kw) o.val ډ (s.cout*(s.ho*s.wo)) λ q => act aB (d6 s aC P off aD b (s.cin*s.kh*s.kw) (q.val/(s.ho*s.wo)) 0 (q.val/s.wo%s.ho) (q.val%s.wo) (q.val/s.wo%s.ho*s.stride*Ya s+q.val%s.wo*s.stride) bp BW[q.val/(s.ho*s.wo)]! (by simp[off]) hg.2.2.2 (by simp[P];have:=hg.2.2.1;omega) (λ t ht=>by obtain ⟨hy,hx,-⟩:=Zt s.cout s.ho s.wo q.val q.isLt obtain ⟨w1,-⟩:=E6 s aC hg.1 hg.2.1 _ _ t hy hx ht simp only[P,off,Ἠ] rw[ZD s _ t ht א] exact w1)) else conv2dWith Yn s aB aC aD b lemma W8:ds=conv2dSpec:=by funext s aB a d b;unfold ds conv2dSpec;split . rename_i e;dsimp only;congr 1;funext q;obtain⟨g,h,j⟩:=Zt s.cout s.ho s.wo q܁ q.isLt;rw[Ze s.cout (λ o=>Yc d (s.cin*s.kh*s.kw) o) _ j];congr 1;refine(L3 s a _ _ d b _ _ 0 _ _ _ _ _ _ _ ?_).trans ?_ . intro t f;obtain⟨k,l⟩:=E6 s a e.1 e.2.1 _ _ t g h f;rw[ZD s _ t f א,Λ,Ze _ (λ i=>YI s a i) _ k] exact l . simp . simp only[Zi] def dk (s:σ) (aB:ه) (aC aD b:ل δ):ل δ := if hg:s.kh<=Yb s/\s.kw<=Ya s/\s.cin*(Yb s*Ya s)<=4294967295 /\ s.kh*s.kw<1048576 then let P:ل δ:=ډ (s.cin*(Yb s*Ya s)) λ i=>YI s aC i.val let off:ل ك:=ډ (s.kh*s.kw) λ t=>(Ys s t.val).toUInt32 let bp:=Yc P Pچ 0 let BW:ل ك:=ډ s.cin λ c=>Yc aD (s.kh*s.kw) c.val ډ (s.cin*(s.ho*s.wo)) λ q => act aB (d6 s aC P off aD b (s.kh*s.kw) (q.val/(s.ho*s.wo)) (q.val/(s.ho*s.wo)*(s.kh*s.kw)) (q.val/s.wo%s.ho) (q.val%s.wo) (q.val/(s.ho*s.wo)*(Yb s*Ya s) + (q.val/s.wo%s.ho*s.stride*Ya s+q.val%s.wo*s.stride)) bp BW[q.val/(s.ho*s.wo)]! (by simp[off]) hg.2.2.2 (by simp[P];have:=hg.2.2.1;omega) (λ t ht=>by obtain ⟨hy,hx,hc⟩:=Zt s.cin s.ho s.wo q.val q.isLt obtain ⟨w1,-⟩:=ZZ s aC _ t _ _ hg.1 hg.2.1 hc ht hy hx simp only[P,off,Ἠ] rw[ZD s _ t ht א] exact w1)) else depthwiseWith Yn s aB aC aD b lemma W7:dk=depthwiseSpec:=by funext s aB a d b;unfold dk depthwiseSpec;split . rename_i e;dsimp only;congr 1;funext q;obtain⟨h,j,f⟩:=Zt s.cin s.ho s.wo q܁ q.isLt;rw[Ze s.cin (λ c=>Yc d (s.kh*s.kw) c) _ f];congr 1;refine(L3 s a _ _ d b _ _ _ _ _ _ _ _ _ _ ?_).trans rfl;intro t g;obtain⟨k,l⟩:=ZZ s a _ t _ _ e.1 e.2.1 f g h j;rw[ZD s _ t g א,Ze _ (λ i=>YI s a i) _ k];exact l . simp only[Zi] section open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats FloatLib.Numerics open Model open RationalBinary (floorLog2 scaleByPowerOfTwo scaleByPowerOfTwo_snd_ne_zero) open FloatLib.Numerics (binaryRadix Radix.toReal) end section open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats FloatLib.Floats.Formats.Flocq open Float.Model.UnpackedFloat open FloatLib.Numerics (binaryRadix Radix.toReal) end section open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats open Float.Model.UnpackedFloat end section open ExactRuntime FloatLib.Floats.Formats.BinaryInterchange FloatLib.Floats end def Yh (s:ه) (m:ٽ):پ:=if s then -(m:پ) else m lemma ZF (w:δ):sv w=Yh (η w) (ε w):=rfl lemma gO {α:Type} [Inhabited α] (n:ٽ) (f:ٽ -> α) (k:ٽ) (a:kf i܁)[k]! = f k:=ט def Ye (q:ق):پ:=(qڇ:پ)-2^64*(qڇ/2^63:ٽ) termination_by nڇ-kڇ decreasing_by exact ZI n k h lemma D1 (w:ك) (m:ق) (k:ٽ) (a:k<=39) (h:ε w=0\/(m˟<=γ w/\γ w-m˟<=k)) : (Yf w<<<(Yd w-m))˟=ε w*2^(γ w-m˟) /\ ε w*2^(γ w-m˟)<2^(24+k):=by rcases h with b | ⟨e,f⟩ . have:Yf w=0:=ο.mp (by rw[Zk,b];rfl);rw[this,b];simp . have g:(Yd w-m)˟=γ w-m˟:=by rw[Α _ _ (Ϯ.mpr (by rw[Zf];exact e)),Zf] have j:=ϖ w;have d:ε w*2^(γ w-m˟)<2^(24+k):=calc _<2^24*2^(γ w-m˟):=ἇ j (ψ _) _<=2^24*2^k:=Nat.mul_le_mul_left _ (Η ב f) _=2^(24+k):=by rw[pow_add] refine⟨?_,d⟩;rw[Ρ,g,Zk,ν (show idxOf w-m˟<64 by omega),υ] exact ν (lt_of_lt_of_le d (Η ב א)) lemma I7 (p:ق) (a:ه) (b:p˟<2^63):Ye (if a then (0:ق)-p else p)=if a then -(p˟:پ) else p˟:=by unfold Ye;cases a . simp only[χ,ؠ];rw[ϑ b];simp . simp only[ת];rw[Φ];simp only[show(0:ق)˟=0 from rfl,Ἇ];by_cases d:p˟=0 . rw[d];simp omega lemma QE {x y m:پ} (k:پ) (h:x=y+m*k):x%m=y%m:=by rw[h,Int.add_mul_emod_self_left] lemma Q8 (V:ٽ) (a:پ) (h:(V:پ)%2^128=a%2^128) (b:V<2^128) (d : -2^127<=a) (e:a<2^127) : (((2^64-V/2^127)%2^64*2^128+V:ٽ):پ)%2^192=a%2^192:=by obtain⟨c,f⟩:=Int.ModEq.dvd h;clear h;exact QE (V/2^127:ٽ) א lemma D7 (a b c:ق) (d:پ) (e:c˟=0) (h:((a˟*2^64+b˟:ٽ):پ)%2^128=d%2^128) (f : -2^127<=d) (g:d<2^127) : ((Yx ((0:ق)-(a>>>63)) a b+c˟:ٽ):پ)%2^192=d%2^192:=by have j:((0:ق)-(a>>>63))˟=(2^64-a˟/2^63)%2^64:=by rw[Φ,Ζ];simp[ω] have n:=b߾;have o:=a߾;have k:a˟/2^63=(a˟*2^64+b˟)/2^127:=א have l:a˟*2^64+b˟<2^128:=א unfold Yx;rw[j,e,Ἇ,kR,k];exact Q8 _ d h l f g def ep (A:ل δ) (a n:ٽ) (m:ق) (s:ٽ):Prop := ∀ t,t ε A[a+t]! = 0\/(mڇ<=γ A[a+t]! /\ γ A[a+t]! - mڇ<=s) @[inline] def YU (bx:ك):ق:=Yk (bx&&&0xFFFF)-Yk (bx>>>16) lemma J6 (A:ل δ) (a i:ٽ) (b:i*a+a<=Aچ) (g:i*a+a<4294967296) (d:(Yc A a i&&&0xFFFF)≠255) (f:Yk (Yc A a i>>>16)<=Yk (Yc A a i&&&0xFFFF)) : ep A (i*a) a (Yk (Yc A a i>>>16)) (YU (Yc A a i))˟ /\ (YU (Yc A a i))˟<=254/\(Yk (Yc A a i>>>16))˟<=511 /\ ∀ t,t < a -> θ A[i*a+t]! ≠ 255:=by obtain⟨L,H,o,p,q,k⟩:=Zp A a i b א;obtain⟨u1,l⟩:=Zo _ L H o א;have r:H≠255:=λ h=>d (Ν.mp (by rw[l,h];rfl));have e:(YU (Yc A a i))˟=(H-1)-(L-1):=by unfold YU;rw[Α _ _ f,Zq,Zq,u1,l] have m:(Yk (Yc A a i>>>16))˟=L-1:=by rw[Zq,u1] refine⟨?_,by omega,by omega,λ t j=>(Zb A[i*a+t]!).2.2.1 (by have:=(k t j).2;omega)⟩ intro t j;by_cases n:ε A[i*a+t]! = 0 . exact Ω n . have s:=(Zb A[i*a+t]!).2.2.2 n;have u:=k t j;right;constructor<;>omega lemma I6 (a:ك) (b:ق) (d:Yf a=0\/(b<=Yd ζ+Yd a/\Yd ζ+Yd a-b<80)) : ε ζ*ε a≠0 -> b˟<=γ ζ+γ a/\γ ζ+γ a<=b˟+79:=by intro f;have g:Yf a≠0:=by intro h;apply f;rw[<- Zk a,h];simp obtain⟨e,j⟩:=d.resolve_left g;have k:=ϐ.mp e;have l:=Ι.mp j;rw[ZM]at k;rw[Α _ _ e,ZM]at l;have:(80:ق)˟=80:=rfl;constructor<;>omega def df (aB:ه) (c hw:ٽ) (x s t:ل δ):ل δ := YT c hw λ ch j=>act aB (cW x[ch*hw+j]! s[ch]! t[ch]!) lemma E0:df=scaleShiftSpec:=by funext aB c a x s t;simp only[df,ZB c a _ rfl,scaleShiftSpec,X1,Ϻ] lemma A8 (q:ق) (z:پ) (a : -2^63<=z) (b:z<2^63) (h:((q˟:پ)-z)%2^64=0):Ye q=z:=by have:=q߾;unfold Ye;omega lemma J5 (a:ق):(a˟:پ) ≡ Ye a [ZMOD 2^64]:=by unfold Ye;rw[Int.modEq_iff_dvd];exact⟨-(a˟/2^63:ٽ),by ring⟩ lemma B1 (a b:ق) (d : -2^63<=Ye a*Ye b) (e:Ye a*Ye b<2^63):Ye (a*b)=Ye a*Ye b:=by apply A8 _ _ d e;have Zh:((a˟*b˟%2^64:ٽ):پ) ≡ Ye a*Ye b [ZMOD 2^64]:=by push_cast;exact(Int.mod_modEq _ _).trans ((J5 a).mul (J5 b)) rw[ϱ];exact Int.emod_eq_zero_of_dvd Zh.symm.dvd lemma G4 (w:δ) (m:ق):cq w m=if η w then 0-Yf w<<<(Yd w-m) else Yf w<<<(Yd w-m):=by have h:=C6 w 0;rw[UInt32.xor_zero,show signOf 0=false from rfl,Bool.xor_false]at h unfold cq;dsimp only;generalize Yf w<<<(Yd w-m)=v;cases a:η w<;>simp only[a]at h . rw[show(w>>>31)܌=0 from ο.mp (by rw[h];rfl)];simp . rw[show(w>>>31)܌=1 from ο.mp (by rw[h];rfl)];simp lemma H6 (w:δ) (m:ق) (k:ٽ) (a:k<=39) (h:ε w=0\/(m˟<=γ w/\γ w-m˟<=k)) : Ye (cq w m)=sv w*2^(γ w-m˟) /\ |sv w*2^(γ w-m˟)| < 2^(24+k):=by obtain⟨b,d⟩:=D1 w m k a h;have:=Η (show 0<2 by omega) (show 24+k<=63 by omega);rw[G4];rw[I7 _ _ א,b,ZF];unfold Yh;cases η w<;>simp<;>exact_mod_cast d @[inline] def YV (w:δ) (m:ق):ٽ:=(cq w m+0x200000000000000).toNat @[inline] def sx (v:ق):ق:=v.toUInt32.toInt32.toInt64.toUInt64 theorem dj (t:ق) (h:t.toNat<2^31∨2^64-2^31≤t.toNat):sx t=t:=by apply UInt64.toBitVec_inj.mp have e:(sx t).toBitVec=(t.toBitVec.setWidth 32).signExtend 64:=by simp[sx] rw[e] have hv:t.toBitVec.toNat=t.toNat:=rfl apply BitVec.eq_of_toNat_eq rw[BitVec.toNat_signExtend] have hb:t.toNat<2^64:=t.toNat_lt_size have hm:(t.toBitVec.setWidth 32).msb=decide (2^31≤t.toNat%2^32):=by simp[BitVec.msb_eq_decide] simp[hm,hv] split<;>omega @[inline] def Y9 (a b:ق):ق:=sx (a&&&0x1FFFFFF)*sx (b-0x80000000) @[inline] def b8 (a b:ق):ق:=sx ((a>>>25)-0x100000000)*sx (b-0x80000000) theorem dx (u:UInt32):sx (u.toUInt64-0x80000000)=u.toUInt64-0x80000000:=by apply dj have:u.toUInt64.toNat<2^32:=by simpa using u.toNat_lt_size have e:(0x80000000:ق).toNat=2147483648:=rfl rw[Φ,e];omega theorem eU (a:ق) (u:UInt32):Y9 a u.toUInt64=(a&&&0x1FFFFFF)*(u.toUInt64-0x80000000):=by unfold Y9;rw[dx,dj (a&&&0x1FFFFFF)];left have:(a&&&0x1FFFFFF).toNat≤0x1FFFFFF:=by rw[ἢ];exact kd omega theorem d7 (a:ق) (u:UInt32) (h1:2^56≤a.toNat) (h2:a.toNat<2^57+2^56):b8 a u.toUInt64=((a>>>25)-0x100000000)*(u.toUInt64-0x80000000):=by unfold b8;rw[dx,dj ((a>>>25)-0x100000000)] have:(a>>>25).toNat=a.toNat/2^25:=by simp[Ζ,ω] have e:(0x100000000:ق).toNat=4294967296:=rfl rw[Φ,e];omega @[inline] def di (B0:ق) (bw:ك) (hi lo:ق):ق := let s:=Yd bw+126-B0 if (Yf bw==0||s<=78)&&B0<=1000 then let m:=Yf bw<<<23 let bh:=if s<64 then (m>>>1)>>>(63-s) else m<<<(s-64) let bl:=if s<64 then m<<>>63) if (t0|||t1|||t2)==0 then 0x100000000 else (dg t2 t1 t0 (λ _=>((B0ڇ:پ)-298)) false true (B0-298)).toUInt64 else YL B0 ζ bw ((0:ق)-(hi>>>63)) hi lo 0 λ v2 v1 v0 c' => YD v2 v1 v0 c' ((B0ڇ:پ)-298) @[inline] def dP (B0:ق) (bw:ك) (a0 a1:ق):ق := let l:=a1<<<25 let lo:=l+a0 di B0 bw ((a1>>>39)+(((0:ق)-(a1>>>63))<<<25)+((0:ق)-(a0>>>63))+(if lo t ق) (B0:ق) (bw:ك) (a0 a1:ق) (k:م):ق := if h:k>>25)-ר)=X/2^25:=by constructor<;>apply A8 _ _ א א . rw[ἢ,show(0x1FFFFFF:ق)˟=2^25-1 from rfl,Ϙ];omega . rw[Φ,Ζ,show(25:ق)˟%64=25 from rfl,ω,show(ר:ق)˟=2^32 from rfl];push_cast;omega lemma tC (b:ق) (W:پ) (a : -2^31simp[sv,h] . have r:=f.resolve_left (λ h=>l (by simp[h]));have s:=g.resolve_left (λ h=>l (by simp[h]));rw[show idxOf x+idxOf w-(a˟+b˟)=(idxOf x-a˟)+(idxOf w-b˟) by omega,pow_add] ring lemma tw (x w:ك) (d e:ق) (g f:ٽ) (o:g+f<=31) (h:f<=6) (j:ε x=0\/(d˟<=γ x/\γ x-d˟<=g)) (k:ε w=0\/(e˟<=γ w/\γ w-e˟<=f)) (a b:ق) (l:a=(YV x d)؝) (n:b=(Y4 w e)܌) : Ye (Y9 a b)+2^25*Ye (b8 a b)=sv x*sv w*2^(γ x+γ w-(d˟+e˟)) /\ -2^55>>39)+(((0:ق)-(a>>>63))<<<25)+((0:ق)-(b>>>63))+(if (a<<<25)+bomega lemma P4 (k:ق) (a:k˟<1024):Y0 ((k˟:پ)-298) true (k-298):=by intro c d _ b;rw[ξ,Φ,show(298:ق)˟=298 from rfl]at b ⊢ push_cast at b ⊢;omega lemma eV (a:ك) (s:ق) (b:ε a=0\/s˟<=78) : ((if s<64 then ((Yf a<<<23)>>>1)>>>(63-s) else (Yf a<<<23)<<<(s-64))˟*2^64 + (if s<64 then (Yf a<<<23)<<simp[Ζ,Ρ] . generalize k:Yf a<<<23=M at d ⊢;split_ifs with h . rw[Ι]at h;simp at h;rw[Ζ,Ζ,Ρ,Α _ _ (by rw[Κ];simp;omega),d] simp only[show(1:ق)˟=1 from rfl,show(63:ق)˟=63 from rfl,ω,υ,ν (show 63-s˟<64 by omega),ν (show s˟<64 by omega),Ϡ,<- pow_add] rw[show 1+(63-s˟)=64-s˟ by omega] have g:2^64=2^(64-s˟)*2^s˟:=by rw[<- pow_add,show 64-s˟+s˟=64 by omega] rw[g,Nat.mul_mod_mul_right,<- ϡ,<- Ϣ,Ϻ] . rw[Ι]at h;simp at h;rw[Ρ,Α _ _ (by rw[Κ];simp;omega),d] rw[show(64:ق)˟=64 from rfl,υ,ν (show s˟-64<64 by omega),ϔ,Ἇ] have j:ε a*2^23*2^(s˟-64)<2^64:=by calc ε a*2^23*2^(s˟-64)<2^24*2^23*2^14:=ἕ (ἇ f ה) (Η א א) ה _<2^64:=ב rw[ν j,ϡ,<- pow_add,show s˟-64+64=s˟ by omega] lemma C9 (d a e b:ق):((((d+e+(if a+bomega lemma eT (a b d:ق) (h:a˟*2^128+b˟*2^64+d˟=0):YC a b d=0:=by have:=a߾;unfold YC;rw[h];split_ifs<;>omega lemma B9 (b:ق) (a:ك) (f d:ق) (A S:پ) (j:ε ζ*ε a≠0 -> b˟<=γ ζ+γ a/\γ ζ+γ a<=b˟+122) (k : -2^120>>1)>>>(63-s) else (Yf a<<<23)<<<(s-64))=t at o ⊢;generalize (if s<64 then (Yf a<<<23)<<push_cast<;>ring have Q:t˟*2^64+n˟<=2^125:=by rw[o];rcases r with h|⟨M,N,x⟩ . simp only[h,kL,zero_mul,zero_le] . have:=ϖ a;calc ε a*2^23*2^s˟<=2^24*2^23*2^78:=Ἢ (Ε _ (le_of_lt this)) (Η א M) _=2^125:=ב have D:((((if η a then f-t-(if domega have hSb2:S<2^127:=by rw[g,hbias];split_ifs<;>omega have x:=D7 q u 0 S rfl D hSb1 hSb2;generalize (0:ق)-(q>>>63)=v at x ⊢;unfold Yx at x;have R:=(Ϩ v);have T:=(Ϩ q);have U:=(Ϩ u);have E:YC v q u=S:=J0 v q u S א א (by push_cast at x ⊢;omega) rw[I9];by_cases p:S=0 . have:=eS v q u (by rw[E,p]) rw[if_pos (decide_eq_true this),if_pos p] . have:v˟*2^128+q˟*2^64+u˟≠0:=λ V=>p (by rw[<- E];exact eT v q u V) rw[if_neg (by simpa using this),if_neg p,B5,J1 _ _ _ _ _ _ _ (P4 b א),E] . obtain⟨F,G,H,I,W,-,O⟩:=Zr b ζ a _ _ d 0 (λ F G H I=>YD F G H I ((b˟:پ)-298)) (by simp only[ϔ,zero_add,kL,Nat.one_lt_ofNat]) (λ h=>⟨(j h).1,by have:=(j h).2;omega⟩) rw[W];have X:=ZL ζ a b˟ j;generalize sv ζ*sv a*2^(γ ζ+γ a-b˟)=bi at X g O;apply ZV F G H I _ S א א have Y:=D7 f d 0 A rfl e א א rw[O,ϩ,Y,<- ϩ,g] lemma B2 (K:ٽ) (d e:ٽ -> δ) (b:ق) (a:ك) (o:K<=4096) (j:∀ t,t θ (d t)≠255) (k:∀ t,t θ (e t)≠255) (l:θ a≠255) (f:ε ζ*ε a≠0 -> b˟<=γ ζ+γ a/\γ ζ+γ a<=b˟+122) (g:∀ t,t ε (d t)*ε (e t)≠0 -> b˟<=γ (d t)+γ (e t) /\ γ (d t)+γ (e t)<=b˟+122) (v:ق) (n:∀ S:پ,S=Yr d e b˟ 0 K+sv ζ*sv a*2^(γ ζ+γ a-b˟) -> v=if S=0 then ר else (ρ S ((b˟:پ)-298) false)܌) : (if v<ר then v؛ else if Yq (λ t=>if tif tif tif tg t א p);have w:=ZL ζ a b˟ f rw[n _ rfl];generalize u:Yr d e b˟ 0 K+sv ζ*sv a*2^(γ ζ+γ a-b˟)=S;have q:Β (K+1) (λ t=>if tif tif tif tby by_cases h:tsimp[h,j,k,l]<;>decide)];congr 1;rw[ZW,O6 d e K b˟ oneW a K 0 א (λ t _ s p=>(g t א p).1)] simp only[Λ,Nat.lt_irrefl,if_false];rw[ZA oneW a b˟ (λ h=>(f h).1),<- u];ring exact A4 _ _ _ _ _ (λ h=>by rw[q,h];simp[finishWord]) q lemma T9 (K:ٽ) (n o:(t:م) -> t ق) (g j:ٽ -> δ) (e f:ق) (q p:ٽ) (x:q+p<=31) (y:p<=6) (G:K<=256) (z:∀ t h,n t h=(YV (g t߷) e)؝) (B:∀ t h,o t h=(Y4 (j t߷) f)܌) (r:∀ t,t ε (g t)=0\/(e˟<=γ (g t)/\γ (g t)-e˟<=q)) (s:∀ t,t ε (j t)=0\/(f˟<=γ (j t)/\γ (j t)-f˟<=p)) (C:(e+f)˟=e˟+f˟) (l:ك) (D:∀ t,t θ (g t)≠255) (E:∀ t,t θ (j t)≠255) (F:θ l≠255) (w:ε ζ*ε l≠0 -> (e+f)˟<=γ ζ+γ l/\γ ζ+γ l<=(e+f)˟+122) : (if Y5 K۞ n o (e+f) l 0 0 0<ר then (Y5 K۞ n o (e+f) l 0 0 0)؛ else if Yq (λ t=>if tif tif tif t k߷<=K -> -((k߷:پ)*2^55)<=Ye H -> Ye H<=k߷*2^55 -> -((k߷:پ)*2^55)<=Ye I -> Ye I<=k߷*2^55 -> S=Ye H+2^25*Ye I+Yr g j (e+f)˟ k߷ (K-k߷)+sv ζ*sv l*2^(γ ζ+γ l-(e+f)˟) -> Y5 K۞ n o (e+f) l H I k=if S=0 then ר else (ρ S (((e+f)˟:پ)-298) false)܌:=by intro d induction d with | zero => intro k H I S hd hk O P Q u1 M;rw[Y5,dif_neg (by rw[τ,X];omega)];unfold dP;dsimp only have T:(2:پ)^55=36028797018963968:=ב have hk2:(k߷:پ)<=256:=א rw[T]at O P Q u1 exact B9 _ _ _ _ (Ye H+2^25*Ye I) S w (by linarith) (by linarith) (U0 H I) (by rw[M,show K-k߷=0 by omega,Yr];ring) | succ d ih => intro k H I S hd hk O P Q u1 M have Y:k ε (g t)*ε (j t)≠0 -> (e+f)˟<=γ (g t)+γ (j t) /\ γ (g t)+γ (j t)<=(e+f)˟+122:=by intro t ht hm;have u:=(r t ht).resolve_left (λ h=>hm (by rw[h,Ϫ]));have v:=(s t ht).resolve_left (λ h=>hm (by rw[h,Ϝ]));constructor<;>omega exact B2 K g j (e+f) l א D E F w he _ (λ S M=>A K 0 0 0 S ג ג (by simp[Ye]) (by simp[Ye]) (by simp[Ye]) (by simp[Ye]) (by rw[M];simp[Ye])) @[inline] def c6 (w:δ) (m:ق):ق:=cq w m+0x8000000000000000 @[inline] def aY (j:ٽ) (v:ق):ك:=(if j=0 then v&&&0x1FFFFF else if j=1 then (v>>>21)&&&0x1FFFFF else v>>>42).toUInt32 @[inline] def MM (l w:ق):ق:=sx l*sx (w-0x80000000) lemma et (v:ق) (u:ك):MM (aY 0 v).toUInt64 u.toUInt64=(aY 0 v).toUInt64*(u.toUInt64-0x80000000):=by have e:aY 0 v=(v&&&0x1FFFFF).toUInt32:=rfl unfold MM;rw[dx,dj];left;rw[e];simp;exact ϊ kd (by decide) lemma es (v:ق) (u:ك):MM (aY 1 v).toUInt64 u.toUInt64=(aY 1 v).toUInt64*(u.toUInt64-0x80000000):=by have e:aY 1 v=((v>>>21)&&&0x1FFFFF).toUInt32:=rfl unfold MM;rw[dx,dj];left;rw[e];simp;exact ϊ kd (by decide) lemma er (v:ق) (u:ك):MM ((aY 2 v).toUInt64-0x200000) u.toUInt64=((aY 2 v).toUInt64-0x200000)*(u.toUInt64-0x80000000):=by have e:aY 2 v=(v>>>42).toUInt32:=rfl have b:(v>>>42).toNat=v.toNat/2^42:=by simp[Ζ,ω] have c:v.toNat<2^64:=v.toNat_lt_size have d:(0x200000:ق).toNat=2097152:=rfl unfold MM;rw[dx,dj];rw[e,Φ,d];simp;omega lemma A2 (p W:پ) (b : -2^21<=p) (d:p<2^21) (a : -2^30nlinarith lemma Q2 (x w:ك) (a d:ق) (e f:ٽ) (g:e<=39) (h:f<=6) (j:ε x=0\/(a˟<=γ x/\γ x-a˟<=e)) (k:ε w=0\/(d˟<=γ w/\γ w-d˟<=f)) (v b:ق) (l:v=c6 x a) (n:b=(Y4 w d)܌) : Ye (MM (aY 0 v)܌ b)+(2:پ)^21*Ye (MM (aY 1 v)܌ b)+(2:پ)^42*Ye (MM ((aY 2 v)܌-0x200000) b)=sv x*sv w*2^(γ x+γ w-(a˟+d˟)) /\ -(2:پ)^51>>21)&&&0x1FFFFF)؛ from rfl,show aY 2 v=(v>>>42)؛ from rfl] obtain⟨X,W,E,u,F,y,z⟩:=H1 x w a d e f g h j k;rw[abs_lt]at u y;have J : -2^63<=X/\X<2^63:=by have:(2:پ)^(24+e)<=2^63:=pow_le_pow_right₀ ב א;exact⟨by linarith only[u.1,this],by linarith only[u.2,this]⟩ have p : -2^30>>21)&&&0x1FFFFF)؛܌)˟=v˟/2^21%2^21:=by rw[ϯ,ϧ,ἢ,show(0x1FFFFF:ق)˟=2^21-1 from rfl,Ϙ,Ζ,show(21:ق)˟%64=21 from rfl,ω];omega have I:((v>>>42)؛܌)˟=v˟/2^42:=by rw[ϯ,ϧ,Ζ,show(42:ق)˟%64=42 from rfl,ω];omega have A:Ye ((v&&&0x1FFFFF)؛܌)=((v˟%2^21:ٽ):پ):=A8 _ _ א א (by rw[G];simp only[kL,Int.natCast_emod,Ἣ,sub_self,Int.reducePow,EuclideanDomain.zero_mod]) have B:Ye (((v>>>21)&&&0x1FFFFF)؛܌)=((v˟/2^21%2^21:ٽ):پ):=A8 _ _ א א (by rw[H];simp only[kL,Int.natCast_emod,Int.natCast_ediv,Ἣ,sub_self,Int.reducePow,EuclideanDomain.zero_mod]) have C:Ye (((v>>>42)؛܌)-0x200000)=((v˟/2^42:ٽ):پ)-2^21:=A8 _ _ א א (by rw[Φ,I,show(0x200000:ق)˟=2^21 from rfl];push_cast;omega) have r:=A2 ((v˟%2^21:ٽ):پ) W א א p have s:=A2 ((v˟/2^21%2^21:ٽ):پ) W א א p have t:=A2 (((v˟/2^42:ٽ):پ)-2^21) W א א p rw[B1 _ _ (by rw[A,o];linarith only[r.1]) (by rw[A,o];linarith only[r.2]),B1 _ _ (by rw[B,o];linarith only[s.1]) (by rw[B,o];linarith only[s.2]),B1 _ _ (by rw[C,o];linarith only[t.1]) (by rw[C,o];linarith only[t.2]),A,B,C,o] refine⟨?_,r.1,r.2,s.1,s.2,t.1,t.2⟩;have D:((v˟%2^21:ٽ):پ)+2^21*((v˟/2^21%2^21:ٽ):پ)+2^42*(((v˟/2^42:ٽ):پ)-2^21)=X:=א rw[z];push_cast at D ⊢;linear_combination W*D @[specialize] def br (n:م) (g fb:(t:م) -> t ق) (B0:ق) (bw:ك) (a0 a1 a2:ق) (k:م):ق := if h:k>>63))+((a1>>>43)+(((0:ق)-(a1>>>63))<<<21))+(if a0+(a1<<<21)>>22)+(((0:ق)-(a2>>>63))<<<42))+(if a0+(a1<<<21)+(a2<<<42)>>63))˟*2^64+a˟:ٽ):پ)%2^128=Ye a%2^128:=by have:=(Ϩ a);unfold Ye;simp only[Φ,Ζ,ω];norm_num;omega lemma D4 (a:ق):((((a>>>43)+(((0:ق)-(a>>>63))<<<21))˟*2^64+(a<<<21)˟:ٽ):پ)%2^128=(2^21*Ye a)%2^128:=by have:=(Ϩ a);unfold Ye;simp only[ξ,Φ,Ρ,Ζ,υ,ω];norm_num;omega lemma D3 (a:ق):((((a>>>22)+(((0:ق)-(a>>>63))<<<42))˟*2^64+(a<<<42)˟:ٽ):پ)%2^128=(2^42*Ye a)%2^128:=by have:=(Ϩ a);unfold Ye;simp only[ξ,Φ,Ρ,Ζ,υ,ω];norm_num;omega lemma D9 (b a d:ق):(((((0:ق)-(b>>>63))+((a>>>43)+(((0:ق)-(a>>>63))<<<21))+(if b+(a<<<21)>>22)+(((0:ق)-(d>>>63))<<<42))+(if b+(a<<<21)+(d<<<42)>>63))+((a>>>43)+(((0:ق)-(a>>>63))<<<21))+(if b+(a<<<21)>>22)+(((0:ق)-(d>>>63))<<<42)) (d<<<42);have f:KM (2^128) _ _:=C9 ((0:ق)-(b>>>63)) b ((a>>>43)+(((0:ق)-(a>>>63))<<<21)) (a<<<21);have g:KM (2^128) _ _:=Q5 b;have h:KM (2^128) _ _:=D4 a;have j:KM (2^128) _ _:=D3 d;exact e.trans ((f.trans (g.add h)).add j) lemma D8 (K:ٽ) (g n:(t:م) -> t ق) (f j:ٽ -> δ) (a e:ق) (o p:ٽ) (x:o<=39) (y:p<=6) (F:K<4096) (z:∀ t h,g t h=c6 (f t߷) a) (B:∀ t h,n t h=(Y4 (j t߷) e)܌) (q:∀ t,t ε (f t)=0\/(a˟<=γ (f t)/\γ (f t)-a˟<=o)) (r:∀ t,t ε (j t)=0\/(e˟<=γ (j t)/\γ (j t)-e˟<=p)) (s:(a+e)˟=a˟+e˟) (l:ك) (C:∀ t,t θ (f t)≠255) (D:∀ t,t θ (j t)≠255) (E:θ l≠255) (w:ε ζ*ε l≠0 -> (a+e)˟<=γ ζ+γ l/\γ ζ+γ l<=(a+e)˟+122) : (if br K۞ g n (a+e) l 0 0 0 0<ר then (br K۞ g n (a+e) l 0 0 0 0)؛ else if Yq (λ t=>if tif tif tif t k߷<=K -> -((k߷:پ)*2^51)<=Ye H -> Ye H<=k߷*2^51 -> -((k߷:پ)*2^51)<=Ye I -> Ye I<=k߷*2^51 -> -((k߷:پ)*2^51)<=Ye J -> Ye J<=k߷*2^51 -> S=Ye H+2^21*Ye I+2^42*Ye J+Yr f j (a+e)˟ k߷ (K-k߷)+sv ζ*sv l*2^(γ ζ+γ l-(a+e)˟) -> br K۞ g n (a+e) l H I J k=if S=0 then ר else (ρ S (((a+e)˟:پ)-298) false)܌:=by intro d induction d with | zero => intro k H I J S hd hk N O P u1 Q R T;rw[br,dif_neg (by rw[τ,hc];omega)] have L:(2:پ)^51=2251799813685248:=ב have hk2:(k߷:پ)<=4096:=א rw[L]at N O P u1 Q R exact B9 _ _ _ _ (Ye H+2^21*Ye I+2^42*Ye J) S w (by linarith) (by linarith) (D9 H I J) (by rw[T,show K-k߷=0 by omega,Yr];ring) | succ d ih => intro k H I J S hd hk N O P u1 Q R T have hf:k ε (f t)*ε (j t)≠0 -> (a+e)˟<=γ (f t)+γ (j t) /\ γ (f t)+γ (j t)<=(a+e)˟+122:=by intro t ht hm;have u:=(q t ht).resolve_left (λ h=>hm (by rw[h,Ϫ]));have v:=(r t ht).resolve_left (λ h=>hm (by rw[h,Ϝ]));rw[s];constructor<;>omega exact B2 K f j (a+e) l א C D E w he _ (λ S T=>A K 0 0 0 0 S ג ג (by simp[Ye]) (by simp[Ye]) (by simp[Ye]) (by simp[Ye]) (by simp[Ye]) (by simp[Ye]) (by rw[T];simp[Ye])) lemma u1 (n:م) (h:¬n=0):(n-1)߷h (ἶ.mp (by rw[e];rfl));rw[ἰ _ _ (USize.le_iff_toNat_le.mpr ו)];simp;omega @[specialize] def YO {α:Type} (B C:م) (f:م -> م -> م -> α) (n:م) (a b c:م) (acc:ل α):ل α := if h:n=0 then acc else let acc:=acc.push (f a b c) if c+1 م -> م -> α) (g:0 b߷ c߷ i+n<4294967296 -> (YO B C f n۞ a b c k)֍=k֍ ++ (ki i n).map (λ j=>f (j/(B߷*C߷))۞ (j/C߷%B߷)۞ (j%C߷)۞):=by intro n;induction n with | zero=>intro i a b c k _ _ _ _;unfold YO;rw[dif_pos (ἶ.mp ג)];simp | succ n q => intro i a b c k D t E J;have K:=φ;obtain⟨v,w,A⟩:=O5 a߷ b߷ c߷ B߷ C߷ t E;rw[D]at v w A;have L:a߷<=a߷*(B߷*C߷):=ϟ _ (ύ g d);have M:b߷<=b߷*C߷:=ϟ _ d;have u:∀ (x:م) (y:ٽ),y=x߷ -> y<4294967296 -> y۞=x := λ x y h F=>ἶ.mp (by rw[Za _ F,h]) have G:f (i/(B߷*C߷))۞ (i/C߷%B߷)۞ (i%C߷)۞=f a b c:=by rw[u a _ v א,u b _ w א,u c _ A א] have r:∀ x:م,x߷<=i -> (x+1)߷=x߷+1:=λ x h=>by rw[Zc _ _ (by simp only[ϻ];omega),ϻ] have l:=r c א;have o:=r b א;have H:=r a א;have z:(0:م)߷=0:=rfl;have p:(n+1)۞߷=n+1:=Za _ א;unfold YO;rw[dif_neg (λ e=>by rw[e]at p;simp at p),show(n+1)۞-1=n۞ from ἶ.mp (by rw[ἰ _ _ (USize.le_iff_toNat_le.mpr (by rw[p];simp)),p,Za _ א];simp)] rw[ϴ,KW,G];split . rename_i h;rw[τ,l]at h;rw[q (i+1) a b (c+1) _ (by rw[l];omega) t (by rw[l];omega) א];simp . rename_i h;rw[τ,l]at h;have I:C߷=c߷+1:=א split . rename_i s;rw[τ,o]at s;rw[q (i+1) a (b+1) 0 _ (by rw[o,z,Ϣ,ϫ];omega) (by rw[o];omega) (by rw[z];omega) א] simp . rename_i s;rw[τ,o]at s;have N:B߷*C߷=b߷*C߷+c߷+1:=by rw[show B߷=b߷+1 by omega,Ϣ,I];omega rw[q (i+1) (a+1) 0 0 _ (by rw[H,z,Ϣ,ϫ];omega) (by rw[z];omega) (by rw[z];omega) א] simp lemma E1 {α:Type} (B C:م) (f:م -> م -> م -> α) (a:0f (q܁/(B߷*C߷))۞ (q܁/C߷%B߷)۞ (q܁%C߷)۞:=by apply Array.ext';rw[T8 B C f a b N 0 0 0 0 _ ג ו ו א];apply ἤ<;>simp @[inline] def YG (bv bw:ك) (xm:ق):ق := if bv>>>16==511 then Yd ζ+Yd bw-xm else Yk (bv>>>16) @[inline] def dS (w:ه):ٽ:=if w then 4096 else 256 @[inline] def dU (w:ه):ق:=if w then 39 else 31 @[inline] def dT (w:ه):ق:=if w then 45 else 31 lemma Q6 (w:ه):(w=false -> dS w<=256/\(dT w)˟<=31)/\dS w<=4096/\(dU w)˟<=39/\(dU w)˟<=(dT w)˟:=by cases w<;>decide @[inline] def cS (bv bw bp:ك) (k:ٽ) (xm:ق) (w:ه):ه := let xb:=Yd ζ+Yd bw k>>16) && Yk (bp>>>16)<=Yk (bp&&&0xFFFF)&&Yk (bp&&&0xFFFF)-xm<=dU w && (if bv>>>16==511 then xm<=xb else Yk (bv>>>16)<=Yk (bv&&&0xFFFF)&&YU bv<=6 && Yk (bp&&&0xFFFF)-xm+YU bv<=dT w)&&θ bw != 255 && (Yf bw==0||(xm+YG bv bw xm<=xb&&xb-(xm+YG bv bw xm)<80)) @[inline] def dl (bp:ك) (BW:ل ك) (b:ل δ):ق := (Array.range BWچ).foldl (λ (m:ق) (o:ٽ) => let wm:=Yk ((BW[o]! : ك)>>>16) let xb:=Yd ζ+Yd b[o]! if (BW[o]! : ك)>>>16 != 511&&Yf b[o]! != 0&&xb < m+wm then xb-wm else m) (Yk (bp>>>16)) @[inline] def em (s:σ) (aC:ل δ) (c yy xx:ٽ):δ := if yy=s.h\/xx-s.pad>=s.w then 0 else aC[(c*s.h+(yy-s.pad))*s.w+(xx-s.pad)]! @[inline] def de (pd h w:م) (aC:ل δ) (c yy xx:م):δ := if yy=h || xx - pd>=w then 0 else let j:=(c*h+(yy - pd))*w+(xx - pd) if hj:jڇ < aCچ then aC.uget j hj else 0 @[inline] def c8 (w:δ) (m:ق):ٽ:=(c6 w m%0x40000000000).toNat @[inline] def c7 (w:δ) (m:ق):ٽ:=(c6 w m/0x40000000000).toNat lemma eR (w:δ) (m:ق):(c8 w m)؝+(c7 w m)؝*0x40000000000=c6 w m:=by unfold c8 c7;generalize c6 w m=v;simp only[Ἄ,UInt64.ofNat_toNat];apply ο.mp;simp only[ξ,ϱ,UInt64.toNat_mod,UInt64.toNat_div,show(0x40000000000:ق)˟=4398046511104 from rfl];have:=v߾;omega @[inline] def cC (s:σ) (aC:ل δ) (xm:ق) (g:δ -> ق -> ٽ):ل ٽ := let pd:=s.padڈ let h:=s.hڈ let w:=s.wڈ YO (Yb s).toUSize (Ya s).toUSize (λ c yy xx=>g (de pd h w aC c yy xx) xm) (s.cin*(Yb s*Ya s)).toUSize 0 0 0 (kA (s.cin*(Yb s*Ya s))) lemma E2 (s:σ) (g:ل δ) (c e f:ٽ) (k:crename_i d . rw[if_pos (by simpa using d)] . rw[if_neg (by simpa using d)];simp only[ἀ,ء,not_or,Nat.not_le]at d have z:c*s.h+(e-s.pad) < (c+1)*s.h:=by rw[Nat.succ_mul];omega have E:(c*s.h+(e-s.pad))*s.w+(f-s.pad) < (c+1)*s.h*s.w:=calc _ < (c*s.h+(e-s.pad))*s.w+s.w:=א _=(c*s.h+(e-s.pad)+1)*s.w:=by rw[Nat.succ_mul] _<=_:=Ε _ z have F:c*s.h<=(c*s.h+(e-s.pad))*s.w:=Μ (ϳ _ _) (ϟ _ א) have M:∀ x,x<4294967296 -> x%2^System.Platform.numBits=x:=λ x h=>ν (ϛ h L) have G:(c+1)*s.h<=(c+1)*s.h*s.w:=ϟ _ א have j:((c۞*s.hڈ+(e۞-s.padڈ))*s.wڈ+(f۞-s.padڈ))߷=(c*s.h+(e-s.pad))*s.w+(f-s.pad):=by simp only[KK,KJ,Za c א,u,v,w,y] rw[M (c*s.h) א,M (c*s.h+(e-s.pad)) א,M ((c*s.h+(e-s.pad))*s.w) א,M _ א] split<;>rename_i t . rw[<- j,ذ g _ t];rfl . rw[j]at t;rw[getElem!_neg g _ t];rfl lemma B3 (s:σ) (a:ل δ) (b:ق) (g:δ -> ق -> ٽ) (d:0g (YI s a i܁) b:=by have j:0by simp[h]at d);have k:0by simp[h]at d);have o:Yb s<=Yb s*Ya s:=ϟ _ k;have p:Ya s<=Yb s*Ya s:=Ἀ _ j;have l:(Yb s)۞߷=Yb s:=Za _ א;have n:(Ya s)۞߷=Ya s:=Za _ א;unfold cC;dsimp only;rw[E1 _ _ _ (by rw[l];omega) (by rw[n];omega) _ _ e];refine congrArg _ (funext λ i=>?_);rw[l,n] exact congrArg (g · b) ((E2 s a _ _ _ (Ϸ (lt_of_lt_of_eq i.isLt (ό _ _))) (Χ _ j) (Χ _ k) e).trans rfl) lemma uk {t:م} {k:ٽ} (a:t ه | 0=>true | r+1 => (let p:=if iif t < k then Δ s a y x (e+t) else ζ) (λ t=>if t < k then d[o*k+t]! else b[o]!) i r:=by intro r; induction r <;> intro i <;> simp only[zW,Yq, *] @[noinline] def cB (s:σ) (aC aD b:ل δ) (k:ٽ) (o y x:م) (dw:ه):δ := if zW s aC aD b k oڇ (if dw then oڇ*k else 0) yڇ xڇ 0 (k+1) then 0x80000000 else 0 @[inline] def bU (s:σ) (aC:ل δ) (P2 PH:ل ٽ) (off:ل ك) (aD:ل δ) (W2:ل ك) (b:ل δ) (k:ٽ) (o y x:م) (dw:ه) (pb wa:م) (B0:ق) (w:ه) (hk:k<1048576) (hoff:offچ=k) (hH:PHچ=P2چ) (hix:∀ t,t pbڇ+(off[t]!).toNat waڇ+t(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64+(PH.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox,hH];exact hix _ (uk ht hk)))).toUInt64*0x40000000000) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) B0 b[oڇ]! 0 0 0 0 else Y5 kڈ (λ t ht=>(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) B0 b[oڇ]! 0 0 0 if v<0x100000000 then v.toUInt32 else cB s aC aD b k o y x dw lemma A7 {α:Type} [Inhabited α] (A:ل α) (i:م) (h:i߷ u߷+(g[t]!)؟ C߷+t ∀ t,t p[u߷+(g[t]!)؟]! = YV (Δ s d y x (l+t)) f) (T:w -> ∀ t,t p[u߷+(g[t]!)؟]! = c8 (Δ s d y x (l+t)) f/\A[u߷+(g[t]!)؟]! = c7 (Δ s d y x (l+t)) f) (U:∀ t,t r[C߷+t]! = Y4 a[o*k+t]! (YG (Yc a k o) b[o]! f)) (V:d܆<4294967296) (q:o*k+k<=a܆/\a܆<4294967296) (M:ق) (W:M=f+YG (Yc a k o) b[o]! f) : bU s d p A g a r b k E F G I u C M w B R v D J = Β (k+1) (λ t=>if tif t>>16))˟:=by unfold YU;rw[Α _ _ c5] set wm:=YG (Yc a k o) b[o]! f with h5;have Zh:∃ sw,sw<=6/\(Yk (Y&&&0xFFFF))˟-f˟+sw<=L2˟ /\ (∀ t,t ε a[o*k+t]! = 0\/(wm˟<=γ a[o*k+t]! /\ γ a[o*k+t]! - wm˟<=sw))/\(∀ t,t θ a[o*k+t]! ≠ 255) /\ (f+wm)˟=f˟+wm˟:=by by_cases hz:Yc a k o>>>16=511 . simp only[hz,if_true,ء]at cD;obtain⟨L,H,hb,-,v,h4⟩:=Zp a k o q.1 (Nat.le_of_lt_succ (ϊ q.1 q.2));obtain⟨u1,u2⟩:=Zo _ L H hb (ϊ v ד);rw[hz]at u1;have he:H≠255:=λ h=>c3 (Ν.mp (by rw[u2,h];rfl));have hd:=ZM b[o]!;have:=Zg b[o]!;have:=(ZO).2;have z:∀ t,t ε a[o*k+t]! = 0/\θ a[o*k+t]! ≠ 255:=λ t X=>by obtain⟨k1,k2⟩:=h4 t X;obtain⟨-,-,k3,k4⟩:=Zb a[o*k+t]!;exact⟨by by_contra hm;have:=(k4 hm).1;simp at u1;exact absurd (Μ (Μ (Μ (ke u1) k1) this) (Μ (k4 hm).2 (Nat.max_le.mpr ⟨Μ k2 v,by decide⟩))) ד,k3 (ϊ k2 (ϰ v he))⟩ refine⟨0,Nat.zero_le _,Μ e5 hL3,λ t X=>Ω (z t X).1,λ t X=>(z t X).2,?_⟩;simp only[h5,YG,hz,beq_self_eq_true,if_true];rw[ξ,Α _ _ cD];exact ν (ϊ (ko (Nat.sub_le _ _) _) (ϊ (Ἆ (Μ e1 xm5) (Μ (ke hd) (Ἆ (ke (ZO).2) (Zg b[o]!)))) ד)) . simp only[hz,if_false,ϓ,ء]at cD;obtain⟨⟨d1,d2⟩,d3⟩:=cD;obtain⟨wf,ws,wm5,wfin⟩:=J6 a k o q.1 (ϊ q.1 q.2) c3 d1;have e3:=ϐ.mp d2;have e4:=ϐ.mp d3;rw[ξ,Α _ _ (UInt64.le_trans c4 c5)]at e4;simp only[show(6:ق)˟=6 from rfl]at e3;have ew:wm=Yk (Yc a k o>>>16):=by simp[h5,YG,hz] rw[ew];exact⟨_,e3,Μ (ke (ν (ϊ (Ἆ (Μ e5 hL2) e3) ד)).symm) e4,wf,wfin,by rw[ξ];exact ν (ϊ (Ἆ (Μ e1 xm5) wm5) ד)⟩ obtain⟨sw,k6,ks,wf,wfin,hB⟩:=Zh;have hx:∀ t,t ε (Δ s d y x (l+t))=0\/(f˟<=γ (Δ s d y x (l+t))/\γ (Δ s d y x (l+t))-f˟<=(Yk (Y&&&0xFFFF))˟-f˟):=λ t _=>by rcases L5 s d y x (l+t) with h | ⟨j,hj,h⟩<;>rw[h] . exact Ω rfl . rcases xf j hj with h' | h'<;>simp only[Λ]at h' . exact Ω h' . right;exact⟨Μ e1 h'.1,Nat.sub_le_sub_right (by have:=Nat.add_le_add_right (Μ h'.2 (ke sp)) (Yk (Y>>>16))˟;rwa[kW h'.1,kW e2]at this) _⟩ have hf:∀ t,t θ (Δ s d y x (l+t))≠255:=λ t _=>by rcases L5 s d y x (l+t) with h | ⟨j,hj,h⟩<;>rw[h] . decide . exact xfin j hj cases w;rw[if_neg ἳ];refine T9 k _ _ (λ t=>Δ s d y x (l+t)) (λ t=>a[o*k+t]!) f _ ((Yk (Y&&&0xFFFF))˟-f˟) sw (Μ ks (hL0 rfl).2) k6 (Nat.le_of_lt (ϛ c1 (hL0 rfl).1)) ?_ ?_ hx wf hB b[o]! hf wfin c9 (λ h=>⟨(h6 h).1,Μ (h6 h).2 (ko ד _)⟩) intro t X;have h0:=uk X B;have Z:=D _ h0;rw[A7 p _ _ _ (by rw[Zc _ _ (by rw[ox];exact ϛ (KE Z.1 Z.2) φ),ox]),S rfl _ h0] rotate_left;rw[if_pos rfl];refine D8 k _ _ (λ t=>Δ s d y x (l+t)) (λ t=>a[o*k+t]!) f _ ((Yk (Y&&&0xFFFF))˟-f˟) sw (Μ e5 hL2) k6 (ϛ c1 hL1) ?_ ?_ hx wf hB b[o]! hf wfin c9 (λ h=>⟨(h6 h).1,Μ (h6 h).2 (ko ד _)⟩) intro t X;have h0:=uk X B;have Z:=D _ h0;have e:=T rfl _ h0;rw[A7 p _ _ _ (by rw[Zc _ _ (by rw[ox];exact ϛ (KE Z.1 Z.2) φ),ox]),A7 A _ _ _ (by rw[Zc _ _ (by rw[ox];exact ϛ (KE Z.1 Z.2) φ),ox]),e.1,e.2,eR] all_goals (intro t X;have h0:=uk X B;have Z:=J _ h0;rw[A7 r _ _ _ (Zc _ _ (ϛ (KE Z.1 Z.2) φ)),U _ h0]) lemma Z4 {a:م} {n:ٽ} (h:aomega);rw[g,f]at u;cases a . simp only[χ,if_false,Λ]at h ⊢;rw[KP,u] . simp only[if_true]at h ⊢;rw[Zc _ _ (by rw[um _ _ (by rw[e];omega),u,e];have:=φ;omega),um _ _ (by rw[e];omega),u,e] lemma H9 (a:ه) (s:σ) (o y x:م) (b:0omega have h3:y߷*s܋≤y߷*s܋*Ya s:=ϟ _ pa have h4:(y*s܋۞)߷=y߷*s܋:=by rw[um _ _ (by rw[g];omega),g] have E:IX a o y x (Yb s*Ya s)۞ s܋۞ (Ya s)۞=(if a then o*(Yb s*Ya s)۞ else 0)+(y*s܋۞*(Ya s)۞+x*s܋۞):=by unfold IX rw[mq y s܋۞ hy (by rw[g];omega),mq (y*s܋۞) (Ya s)۞ (by rw[h4];omega) (by rw[f];omega),mq x s܋۞ hx (by rw[g];omega)] cases a . simp . simp only[if_true];rw[mq o _ (ho rfl) (by rw[e];omega)] rw[E];exact H0 a s o y x b d h lemma L4 (b:ه) (s:σ) (a:ل δ) (k o y x t:ٽ) (j:k=if b then s.kh*s.kw else s.cin*s.kh*s.kw) (d:s.kh<=Yb s) (e:s.kw<=Ya s) (l:b -> oY4 aD[t.val]! (YG BW[t.val/k]! b[t.val/k]! xm) else let ku:=kڈ YO 1 ku (λ o _ j => let i:=o*ku+j Y4 (if h:iڇY4 a[t܁]! (YG d[t܁/k]! b[t܁/k]! f):=by unfold dt;split · rfl · rename_i l;have h:k۞߷=k:=Za k e;rw[E1 1 k۞ _ ג (by rw[h];omega) a܆ _ g] refine congrArg _ (funext λ q=>?_) have r:=q.isLt;simp only[h,ϻ,ϫ];have j:(q܁/k)۞߷=q܁/k:=Za _ (by have:=kf q܁ k;omega) have n:(q܁%k)۞߷=q܁%k:=Za _ (by have:=Nat.mod_le q܁ k;omega) have o:q܁/k*k+q܁%k=q܁:=by rw[ό];exact ἦ q܁ k have p:((q܁/k)۞*k۞+(q܁%k)۞)߷=q܁:=by rw[KK,KJ,j,h,n,ν (lt_of_lt_of_le (show q܁/k*k<4294967296 by omega) φ),ν (lt_of_lt_of_le (show q܁/k*k+q܁%k<4294967296 by omega) φ),o] congr 1 · exact A6 a _ q܁ p 0 rfl · congr 1 · exact A6 d _ (q܁/k) j 0 rfl · exact A6 b _ (q܁/k) j 0 rfl @[inline] def cJ (dw:ه) (s:σ) (aB:ه) (aC aD 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) : ل δ := let off:ل ك:=ډ k λ t=>(Ys s t.val).toUInt32 let bp:=Yc aC aCچ 0 let BW:ل ك:=ډ C λ o=>Yc aD k o.val let xm:=dl bp BW b let g:=(Array.range C).all (λ o=>cS BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0cS BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then cC s aC xm YV else cC s aC xm c8 let PH:=if g then P2 else cC s aC xm c7 let W2:ل ك:=dt aD BW b xm k have hP2:P2چ=s.cin*(Yb s*Ya s):=by simp only[P2];split<;>rw[B3 s aC xm _ hg.2.2.1 א א,Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א,Ἠ] have a:=D2 s C hg.2.2.1 let B0s:ل ق:=ډ C λ o=>xm+YG BW[o.val]! b[o.val]! xm let hw:=(Yb s*Ya s).toUSize let st:=s.strideڈ let wp:=(Ya s).toUSize let ku:=kڈ YO s.hoڈ s.woڈ (λ o y x => if h:oby obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ xڇ t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h.2.2 א) ht rw[H9 dw s o y x hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h.2.2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by have:=Ε k (show oڇ+1<=C from Z4 h.1 א) rw[Ϣ,ϫ] at this rw[um _ _ (by rw[Za _ א];omega),Za _ א] simp only[W2,B7 aD BW b xm k א א,Ἠ];omega)) else 0) (C*(s.ho*s.wo)).toUSize 0 0 0 (kA (C*(s.ho*s.wo))) else if dw then dk s aB aC aD b else ds s aB aC aD b lemma T5 (d:ه) (s:σ) (a:ه) (e f b:ل δ) (k C:ٽ) (g:k=if d then s.kh*s.kw else s.cin*s.kh*s.kw) (h:C=if d then s.cin else s.cout) : (if d then depthwiseSpec else conv2dSpec) s a e f b=ډ (C*(s.ho*s.wo)) λ q=>act a (Β (k+1) (λ t=>if tif tsimp[depthwiseSpec,depthwiseWith,conv2dSpec,conv2dWith] lemma E3 (g:ه) (s:σ) (f:ه) (a e b:ل δ) (k C:ٽ) (h:k=if g then s.kh*s.kw else s.cin*s.kh*s.kw) (j:C=if g then s.cin else s.cout) : cJ g s f a e b k C h j=(if g then depthwiseSpec else conv2dSpec) s f a e b:=by unfold cJ;dsimp only;split . rename_i F;obtain⟨G,H,p,K,L,M,I⟩:=F;obtain⟨N,O,P,Q⟩:=D2 s C p;have x:s.ho.toUSizeڇ=s.ho:=Za _ א;have y:s.wo.toUSizeڇ=s.wo:=Za _ א;rw[E1 _ _ _ (by rw[x];exact(ZG s).1) (by rw[y];exact(ZG s).2) _ _ א,T5 g s f a e b k C h j] refine congrArg _ (funext fun q=>?_);obtain⟨A,B,n⟩:=Zt C s.ho s.wo q܁ q.isLt;have l:(q܁/(s.ho*s.wo))۞߷=q܁/(s.ho*s.wo):=Za _ (by have:=kf q܁ (s.ho*s.wo);have:=q.isLt;omega) have r:(q܁/s.wo%s.ho)۞߷=q܁/s.wo%s.ho:=Za _ א;have u:(q܁%s.wo)۞߷=q܁%s.wo:=Za _ א;have D:k۞߷=k:=Za _ א;have J:q܁/(s.ho*s.wo)*k+k<=e܆:=by have:=Ε k (show q܁/(s.ho*s.wo)+1<=C by omega);rw[Ϣ,ϫ]at this;omega simp only[x,y];rw[dif_pos ⟨by rw[τ,l,Za _ א];exact n,by rw[τ,r,x];exact A,by rw[τ,u,y];exact B⟩] apply congrArg;refine T6 s a _ _ _ e _ b _ _ _ _ _ _ _ _ _ l r u rfl _ _ (dl (Yc a a܆ 0) (ډ C λ o=>Yc e k o܁) b) _ _ _ _ _ _ ?_ ?_ ?_ ?_ א ⟨J,by omega⟩ _ ?_ . have:=Array.all_eq_true.mp I (q܁/(s.ho*s.wo)) ו;simpa[gO C (λ o=>Yc e k o) _ n] using this all_goals try (intro v t w;obtain⟨z,E⟩:=L4 g s a k (q܁/(s.ho*s.wo)) _ _ t h G H (by intro d;subst d j;simpa using n) A B w;rw[H9 g s _ _ _ p א (by rw[l,r,u];omega) (by rw[r];exact lt_trans A א) (by rw[u];exact lt_trans B א) (fun _=>by rw[l];exact lt_trans n א),l,r,u,ZD s _ t w א]) . simp only[Bool.not_eq_false']at v;rw[v,if_pos rfl,B3 s a _ _ p א א,gO _ (λ i=>YV (YI s a i) _) _ z,E] . simp only[ἠ]at v;rw[v,if_neg ἳ,if_neg ἳ,B3 s a _ _ p א א,B3 s a _ _ p א א,gO _ (λ i=>c8 (YI s a i) _) _ z,gO _ (λ i=>c7 (YI s a i) _) _ z,E];exact⟨rfl,rfl⟩ . intro t w;rw[um _ _ (by rw[l,D];omega),l,D,B7 _ _ _ _ _ א א,gO _ (λ t=>Y4 e[t]! (YG (ډ C λ o=>Yc e k o܁)[t/k]! b[t/k]! (dl (Yc a a܆ 0) (ډ C λ o=>Yc e k o܁) b))) _ א, show(q܁/(s.ho*s.wo)*k+t)/k=q܁/(s.ho*s.wo) by rw[ϝ,ϙ _ _ א,ϑ w,Λ], gO C (λ o=>Yc e k o) _ n] . rw[A7 _ _ _ _ l,gO C (λ o=>_+YG (ډ C λ o=>Yc e k o܁)[o]! b[o]! _) _ n,gO C (λ o=>Yc e k o) _ n] . subst h j;cases g . exact W8 ▸ rfl . exact W7 ▸ rfl lemma dz (n:ٽ) (F:ٽ -> δ) (e:0 θ (F t)≠255) : Β (n+1) (λ t=>if tif tζ):=by have l:∀ r k,k+r<=n -> Yo (λ t=>if tif tζ) k r /\ Yq (λ t=>if tif tζ) k r:=by intro r;induction r with | zero=>intro k _;exact⟨rfl,rfl⟩ | succ r j=>intro k h;obtain⟨a,b⟩:=j (k+1) א;simp only[Yo,Yq,a,b,if_pos (show k δ) r k,Yq f g k (r+1)=(Yq f g k r && (decide (ε (f (k+r))*ε (g (k+r))=0)&&Γ (η (f (k+r))) (η (g (k+r))))):=by intro f g r;induction r with | zero=>intro k;simp[Yq] | succ r j => intro k;conv_lhs=>rw[Yq,j (k+1)] conv_rhs=>rw[Yq] rw[show k+1+r=k+(r+1) by omega];simp only[Bool.and_assoc] rw[Zy (n+1) _ _ (λ t _=>by by_cases h:tsimp[h,d]<;>decide),Zy n _ _ (λ t p=>⟨d t p,by decide⟩),ZW,o,(l n 0 א).1,(l n 0 א).2] have q:sv (߿:ك)=0:=ד have s:((decide (ε ζ*ε (߿:ك)=0)) && Γ (η ζ) (η (߿:ك)))=true:=ד simp only[Λ,Nat.lt_irrefl,if_false,q,mul_zero,zero_mul,add_zero,s,Bool.and_true,show(n+1≠0)=True from eq_true א,show(n≠0)=True from eq_true א] lemma wp (c h w k a y x t:ٽ) (b:ل δ) (e:yr (Ν.mp (by rw[v,e];rfl));omega) . rw[getElem!_neg a j d];decide have g:ConvShape.ho ⟨c,h,w,c,k,k,k,0⟩=h/k:=by show(h-k)/k+1=h/k;conv_rhs=>rw[show h=(h-k)+k by omega];rw[Nat.add_div_right _ b] have l:ConvShape.wo ⟨c,h,w,c,k,k,k,0⟩=w/k:=by show(w-k)/k+1=w/k;conv_rhs=>rw[show w=(w-k)+k by omega];rw[Nat.add_div_right _ b] rw[E3,if_pos rfl];unfold depthwiseSpec depthwiseWith avgpoolSpec avgpoolWith;apply kj . simp only[l,g,Array.map_ofFn,Ἠ] . intro i D E;simp only[Array.getElem_map,Ἃ,g,l];have x:is _)] unfold act;simp only[χ,↓reduceIte];congr 1<;>funext t<;>split . rename_i n;exact wp c h w k _ _ _ t a y z n . rfl . rename_i n;rw[ذ _ _ (by simp only[kg];omega)];simp only[KX] . rw[ذ _ _ (by simp only[kg];omega)];simp only[KX] . rw[X0] @[noinline] def cV (x y z:δ):δ:=cW x y z @[inline] def dR (x y z:δ) (my iy mz iq:ق):δ := if θ x != 255 then let mp:=Yl x*my let p:=Yd x+iy let k:=if mp==0 then iq else if mz==0 then p else if p<=iq then p else iq let dp:=if k<=p then p-k else 0 let dq:=if k<=iq then iq-k else 0 if dp<=14 && dq<=38 then let neg:=Γ (η x) (η y) let tp:=mp<<((kڇ:پ)-298)) (neg&&η z) true (k-298) else cV x y z else cV x y z lemma P3 (P K:ق):(if K<=P then P-K else 0)˟=P˟-K˟:=by split . rename_i h;rw[Α _ _ h] . rename_i h;rw[Κ]at h;simp;omega lemma G1 (x y z:δ) (a:θ y≠255) (b:θ z≠255) : dR x y z (Yl y) (Yd y) (Yl z) (Yd z+149)=cW x y z:=by unfold dR;by_cases l:θ x=255 . rw[if_neg (by simp[l])];rfl . rw[if_pos (by simpa using l)] have g:=D5 x y;have j:(Yd z+149)˟=γ z+149:=by rw[ξ,Zf];have:=Zg z;simp;omega have w:γ x+γ y<=508:=by have:=Zg x;have:=Zg y;omega have A:γ z+149<=403:=by have:=Zg z;omega dsimp only;generalize Yd x+Yd y=P at g ⊢;generalize Yd z+149=Q at j ⊢;generalize o:(if Yl x*Yl y==0 then Q else if Yl z==0 then P else if P<=Q then P else Q)=K;have n:K˟=Y1 (Yl x*Yl y) (Yl z) (γ x+γ y) (γ z+149):=by rw[<- o,<- g,<- j];unfold Y1;by_cases e:Yl x*Yl y=0 . simp[e] . by_cases k:Yl z=0 . simp[e,k] . have p:(Yl x*Yl y==0)=false:=by simpa using e have q:(Yl z==0)=false:=by simpa using k simp only[p,q,e,k,χ,ؠ];by_cases f:P<=Q . rw[if_pos f];rw[Κ]at f;omega . rw[if_neg f];rw[Κ]at f;omega have B:K˟<=508:=by rw[n];unfold Y1;split_ifs<;>omega generalize r:(if K<=P then P-K else 0)=D;generalize s:(if K<=Q then Q-K else 0)=E;have eD:D˟=P˟-K˟:=by rw[<- r];exact P3 P K have t:E˟=Q˟-K˟:=by rw[<- s];exact P3 Q K by_cases d:(D<=14 && E<=38)=true . rw[if_pos d];simp only[ϓ,ء]at d;have C:D˟<=14:=by have:=ϐ.mp d.1;simpa using this have F:E˟<=38:=by have:=ϐ.mp d.2;simpa using this unfold cW;rw[if_neg (show ¬(expOf x=255\/expOf y=255\/expOf z=255) by rintro (h|h|h)<;>contradiction)] dsimp only;rw[<- n,<- g,<- j,if_pos (And.intro (show P˟-K˟<=14 by omega) (show Q˟-K˟<=38 by omega))] have u:(P˟-K˟)؝=D:=ο.mp (by rw[Ἄ,ἱ,eD];omega) have v:(Q˟-K˟)؝=E:=ο.mp (by rw[Ἄ,ἱ,t];omega) rw[u,v,F7,B6,J2 _ _ _ _ _ (P4 K א)] . rw[if_neg d];rfl structure aJ where bh:UInt64 bl:UInt64 neg:Bool fast:Bool local instance : Inhabited aJ:=⟨⟨0,0,false,false⟩⟩ def aK (B0:UInt64) (bw:UInt32):aJ:= let s:=Yd bw+126-B0 let m:=Yf bw<<<23 ⟨(if s<64 then (m>>>1)>>>(63-s) else m<<<(s-64)),(if s<64 then m<<>>63) if (t0|||t1|||t2)==0 then 0x100000000 else (dg t2 t1 t0 (fun _=>((B0.toNat:Int)-298)) false true (B0-298)).toUInt64 else YL B0 oneW bw ((0:UInt64)-(hi>>>63)) hi lo 0 (fun v2 v1 v0 c'=>YD v2 v1 v0 c' ((B0.toNat:Int)-298)) lemma cK (B0:UInt64) (bw:UInt32) (hi lo:UInt64): b7 B0 bw (aK B0 bw) hi lo=di B0 bw hi lo:=by unfold b7 aK di rfl @[inline] def bS (B0:UInt64) (bw:UInt32) (c:aJ) (a0 a1:UInt64):UInt64:= let l:=a1<<<25 let lo:=l+a0 b7 B0 bw c ((a1>>>39)+(((0:UInt64)-(a1>>>63))<<<25)+((0:UInt64)-(a0>>>63))+(if loaK A[j.val]! b[j.val]!)).uget i (by simpa using hi)=aK (A.uget i hA) b[i.toNat]!:=by rw[A7 _ i _ _ rfl,getElem!_pos _ _ (by simpa using hi)] simp only[Ἃ] rw[A7 A i hA _ rfl] @[specialize] def cx (n:م) (fa fb0 fb1:(t:م) -> t ق) (B0 B1:ق) (bw0 bw1:ك) (cb0 cb1:aJ) (z0 z1:ق -> δ) (a0 a1 b0 b1:ق) (k:م):ق := if h:ktUInt64) (B C:UInt64)(bw cw:UInt32) (cb0 cb1:aJ) (hc0:cb0=aK B bw) (hc1:cb1=aK C cw)(z0 z1:UInt64->UInt32)(a b c d:UInt64)(k:USize): cx n fa fb fc B C bw cw cb0 cb1 z0 z1 a b c d k= (z0 (Y5 n fa fb B bw a b k)).toUInt64 ||| ((z1 (Y5 n fa fc C cw c d k)).toUInt64<<<32):=by rw[cx] split · rename_i h have h0:Y5 n fa fb B bw a b k=Y5 n fa fb B bw (a+Y9 (fa k h) (fb k h)) (b+b8 (fa k h) (fb k h)) (k+1):=by rw[Y5,dif_pos h] have h1:Y5 n fa fc C cw c d k=Y5 n fa fc C cw (c+Y9 (fa k h) (fc k h)) (d+b8 (fa k h) (fc k h)) (k+1):=by rw[Y5,dif_pos h] rw[h0,h1] exact cZ n fa fb fc B C bw cw cb0 cb1 hc0 hc1 z0 z1 _ _ _ _ (k+1) · rename_i h rw[Y5,dif_neg h,Y5,dif_neg h,hc0,hc1,cA,cA] termination_by n.toNat-k.toNat decreasing_by exact ZI n k ‹kb7 B bw cb (((0:UInt64)-(a0>>>63))+((a1>>>43)+(((0:UInt64)-(a1>>>63))<<<21))+(if a0+(a1<<<21)>>22)+(((0:UInt64)-(a2>>>63))<<<42))+(if a0+(a1<<<21)+(a2<<<42) pb.toNat+(off[t]!).toNat wa.toNat+t waB.toNat+t(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64+(PH.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox,hH];exact hix _ (uk ht hk)))).toUInt64*0x40000000000) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) (λ t ht=>(W2.uget (waB+t) (A9 _ _ _ (hWB _ (uk ht hk)))).toUInt64) B0 B1 b[o.toNat]! b[(o+1:USize).toNat]! cb0 cb1 (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k o y x false) (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k (o+1) y x false) 0 0 0 0 0 0 0 else cx k.toUSize (λ t ht=>(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) (λ t ht=>(W2.uget (waB+t) (A9 _ _ _ (hWB _ (uk ht hk)))).toUInt64) B0 B1 b[o.toNat]! b[(o+1:USize).toNat]! cb0 cb1 (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k o y x false) (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k (o+1) y x false) 0 0 0 0 0 lemma cM (s:σ) (aC:ل δ) (P2 PH:ل ٽ) (off:ل ك) (aD:ل δ) (W2:ل ك) (b:ل δ) (k:ٽ) (o y x:م) (pb wa waB:م) (B0 B1:ق) (cb0 cb1:aJ) (w:ه) (hk:k<1048576) (hoff:offچ=k) (hH:PHچ=P2چ) (hix:∀ t,t pb.toNat+(off[t]!).toNat wa.toNat+t waB.toNat+t t ق) (B0:ق) (bw:ك) (cb:aJ) (finish0 finish1:ق -> δ) (a0 a1 b0 b1:ق) (k:م):ق := if h:k t ق) (B:ق) (bw:ك) (cb:aJ) (hc:cb=aK B bw) (z0 z1:ق -> δ) (a b c d:ق) (k:م): bJ n f g w B bw cb z0 z1 a b c d k= (z0 (Y5 n f w B bw a b k)).toUInt64 ||| ((z1 (Y5 n g w B bw c d k)).toUInt64<<<32):=by rw[bJ] split · rename_i h have h0:Y5 n f w B bw a b k=Y5 n f w B bw (a+Y9 (f k h) (w k h)) (b+b8 (f k h) (w k h)) (k+1):=by rw[Y5,dif_pos h] have h1:Y5 n g w B bw c d k=Y5 n g w B bw (c+Y9 (g k h) (w k h)) (d+b8 (g k h) (w k h)) (k+1):=by rw[Y5,dif_pos h] rw[h0,h1] exact cj n f g w B bw cb hc z0 z1 _ _ _ _ (k+1) · rename_i h rw[Y5,dif_neg h,Y5,dif_neg h,hc,cA,cA] termination_by n.toNat-k.toNat decreasing_by exact ZI n k ‹k>>63))+((a1>>>43)+(((0:ق)-(a1>>>63))<<<21))+(if a0+(a1<<<21)>>22)+(((0:ق)-(a2>>>63))<<<42))+(if a0+(a1<<<21)+(a2<<<42) t ق) (B0:ق) (bw:ك) (cb:aJ) (finish0 finish1:ق -> δ) (a0 a1 a2 b0 b1 b2:ق) (k:م):ق := if h:kh0 (ἶ.mp (by simpa using e)) have hn1:n.toNat≠1:=λ e=>h1 (ἶ.mp (by simpa using e)) have h2:(2:USize).toNat=2:=Za 2 (by decide) have hn:2<=n.toNat:=by omega rw[ἰ n 2 (by rw[kD,h2];exact hn)] rw[h2] omega @[specialize] def aN (B C:م) (f:م -> م -> م -> ق) (n:م) (a b c:م) (acc:ل δ):ل δ := if h:n=0 then acc else let v:=f a b c let acc:=acc.push v.toUInt32 if h1:n=1 then acc else if c+1>>32).toUInt32 if c+2>>63))+((a1>>>43)+(((0:ق)-(a1>>>63))<<<21))+(if a0+(a1<<<21)>>22)+(((0:ق)-(a2>>>63))<<<42))+(if a0+(a1<<<21)+(a2<<<42) pbڇ+(off[t]!).toNat pbBڇ+(off[t]!).toNat waڇ+t(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64+(PH.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox,hH];exact hix _ (uk ht hk)))).toUInt64*0x40000000000) (λ t ht=>(P2.uget (pbB+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hixB _ (uk ht hk)))).toUInt64+(PH.uget (pbB+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox,hH];exact hixB _ (uk ht hk)))).toUInt64*0x40000000000) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) B0 b[o.toNat]! cb (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k o y x dw) (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k o y (x+1) dw) 0 0 0 0 0 0 0 else bJ k.toUSize (λ t ht=>(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64) (λ t ht=>(P2.uget (pbB+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hixB _ (uk ht hk)))).toUInt64) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) B0 b[o.toNat]! cb (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k o y x dw) (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b k o y (x+1) dw) 0 0 0 0 0 lemma qz (n:م)(h:n≠0):0h (ἶ.mp (by simpa using e)) omega lemma qr (n:م)(h:n≠0):(n-1).toNat=n.toNat-1:=by rw[ἰ n 1 (by simp only[kD,ϻ];have:=qz n h;omega),ϻ] lemma qs (n:م)(h:n≠0)(h1:n≠1):(n-2).toNat=n.toNat-2:=by have hn:=qz n h have hn1:n.toNat≠1:=fun e=>h1 (ἶ.mp (by simpa using e)) have h2:(2:م).toNat=2:=Za 2 (by decide) rw[ἰ n 2 (by rw[kD,h2];omega),h2] lemma qt (j:م)(out:ل ك)(hj:j.toNath1 (ἶ.mp (by simpa using e));omega let zz:=z.uset (j+1) (v>>>32).toUInt32 (by simp only[z,kB];omega) have hh: (n-2).toNat+(j+2).toNat=zz.size:=by have hj2:(j+2).toNat=j.toNat+2:=by rw[Zc,show (2:م).toNat=2 from Za 2 (by decide)] have:=φ;rw[show (2:م).toNat=2 from Za 2 (by decide)];omega simp only[zz,z,kB];rw[qs n h h1,hj2];omega if c+2(out.uset j (f a b c).toUInt32 hj).extract 0 k) hz _ = _:=qx out j (f a b c).toUInt32 hj · rw[dif_neg h1,dif_neg h1] by_cases hc:c+1h1 (ἶ.mp (by simpa using e));omega have hj2:(j+2).toNat=j.toNat+2:=by rw[Zc,show (2:م).toNat=2 from Za 2 (by decide)] have:=φ;rw[show (2:م).toNat=2 from Za 2 (by decide)];omega have hx:(j+2).toNat=(j+1).toNat+1:=by omega let zz:=z.uset (j+1) ((f a b c)>>>32).toUInt32 (by simp only[z,kB];omega) have hss:zz.size<4294967296:=by simpa only[zz,z,kB]using hs have hvv:(n-2).toNat+(j+2).toNat=zz.size:=by simp only[zz,z,kB];rw[qs n h h1,hj2];omega have H (aa bb cc:م): qu B C f (n-2) aa bb cc zz (j+2) hss hvv = aN B C f (n-2) aa bb cc (((out.extract 0 j.toNat).push (f a b c).toUInt32).push ((f a b c)>>>32).toUInt32):=by rw[qy] dsimp only[zz,z] rw[hx,qx,hj1,qx] split · exact H _ _ _ · split <;> exact H _ _ _ · rw[if_neg hc,if_neg hc] have hss:z.size<4294967296:=by simpa only[z,kB]using hs have hvv:(n-1).toNat+(j+1).toNat=z.size:=by simp only[z,kB];rw[qr n h,hj1];have:=qz n h;omega have H (aa bb cc:م): qu B C f (n-1) aa bb cc z (j+1) hss hvv = aN B C f (n-1) aa bb cc ((out.extract 0 j.toNat).push (f a b c).toUInt32):=by rw[qy];dsimp only[z];rw[hj1,qx] split <;> exact H _ _ _ termination_by n.toNat decreasing_by all_goals first | exact u1 n h | exact cu n h h1 @[inline] def qA (B C:م)(f:م→م→م→ق)(n a b c:م)(hn:n.toNat<4294967296):ل ك:= qu B C f n a b c (Υ n.toNat 0) 0 (by simp only[kg];exact hn) (by simp) lemma qB (B C:م)(f:م→م→م→ق)(n a b c:م)(hn:n.toNat<4294967296): qA B C f n a b c hn=aN B C f n a b c #[]:=by rw[qA,qy] simp only[kC,Array.extract_zero] @[inline] def ak (dw:ه) (s:σ) (aB:ه) (aC aD 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) : ل δ := let off:ل ك:=ډ k λ t=>(Ys s t.val).toUInt32 let bp:=Yc aC aCچ 0 let BW:ل ك:=ډ C λ o=>Yc aD k o.val let xm:=dl bp BW b let g:=(Array.range C).all (λ o=>cS BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0cS BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then cC s aC xm YV else cC s aC xm c8 let PH:=if g then P2 else cC s aC xm c7 let W2:ل ك:=dt aD BW b xm k have hP2:P2چ=s.cin*(Yb s*Ya s):=by simp only[P2];split<;>rw[B3 s aC xm _ hg.2.2.1 א א,Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א,Ἠ] have a:=D2 s C hg.2.2.1 let B0s:ل ق:=ډ C λ o=>xm+YG BW[o.val]! b[o.val]! xm let BCs:Array aJ:=Ἲ (n:=C) (fun o=>aK B0s[o.val]! b[o.val]!) let hw:=(Yb s*Ya s).toUSize let st:=s.strideڈ let wp:=(Ya s).toUSize let ku:=kڈ qA s.hoڈ s.woڈ (λ o y x => if h:oby obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ xڇ t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h.2.2 א) ht rw[H9 dw s o y x hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h.2.2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ (x+1 : USize).toNat t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h2 א) ht rw[H9 dw s o y (x+1) hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by have:=Ε k (show oڇ+1<=C from Z4 h.1 א) rw[Ϣ,ϫ] at this rw[um _ _ (by rw[Za _ א];omega),Za _ א] simp only[W2,B7 aD BW b xm k א א,Ἠ];omega) (cz C B0s b o (Z4 h.1 (by omega)) (by simp only[B0s,Ἠ];exact Z4 h.1 (by omega))) (act aB v.toUInt32).toUInt64 ||| ((act aB (v>>>32).toUInt32).toUInt64<<<32) else (act aB (bU s aC P2 PH off aD W2 b k o y x dw (IX dw o y x hw st wp) (o*ku) (B0s.uget o (by simp only[B0s,Ἠ];exact Z4 h.1 א)) (!g) א (by simp[off]) hH (λ t ht=>by obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ xڇ t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h.2.2 א) ht rw[H9 dw s o y x hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h.2.2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by have:=Ε k (show oڇ+1<=C from Z4 h.1 א) rw[Ϣ,ϫ] at this rw[um _ _ (by rw[Za _ א];omega),Za _ א] simp only[W2,B7 aD BW b xm k א א,Ἠ];omega))).toUInt64 else 0) (C*(s.ho*s.wo)).toUSize 0 0 0 (by rw[Za _ (by omega)];omega) else if dw then dk s aB aC aD b else ds s aB aC aD b lemma bY (b:UInt32):(b.toUInt64<<<32).toUInt32=0:=by apply Ν.mp have hb:=b.toNat_lt_size simp only[ϧ,Ρ,ϯ] norm_num[υ] at hb ⊢ lemma bR (b:UInt32):(b.toUInt64<<<32)>>>32=b.toUInt64:=by apply ο.mp have hb:=b.toNat_lt_size simp only[Ζ,Ρ,ϯ] norm_num[υ,ω] at hb ⊢ omega lemma bo (a:UInt32):a.toUInt64>>>32=0:=by apply ο.mp have ha:=a.toNat_lt_size simp only[Ζ,ϯ] norm_num[ω] at ha ⊢ omega lemma bz (a b:UInt32): (a.toUInt64 ||| (b.toUInt64<<<32)).toUInt32=a:=by rw[UInt64.toUInt32_or,kF,bY,UInt32.or_zero] lemma bA (a b:UInt32): ((a.toUInt64 ||| (b.toUInt64<<<32))>>>32).toUInt32=b:=by rw[UInt64.shiftRight_or,bo,bR,UInt64.zero_or,kF] lemma dv (B C:USize) (f:USize->USize->USize->UInt32) (a b c:USize) (acc:Array UInt32): YO B C f 1 a b c acc=acc.push (f a b c):=by rw[YO,dif_neg (by intro e;have:=congrArg KI e;simp at this)] dsimp only split_ifs <;> rw[USize.sub_self 1,YO,dif_pos rfl] lemma ct : (1:USize)+1=2:=by apply ἶ.mp rw[KK,ϻ] have h2:(2:USize).toNat=2:=USize.toNat_ofNat_of_lt_32 (by decide) rw[h2] change 2%Ξ=2 exact ν (by have:=φ;omega) lemma dy (n:USize):n-1-1=n-2:=by apply USize.toBitVec_inj.mp simp only[USize.toBitVec_sub] rw[BitVec.sub_sub] exact congrArg (n.toBitVec-·) (by simpa only[USize.toBitVec_add] using congrArg USize.toBitVec ct) lemma du (B C:USize) (f:USize->USize->USize->UInt32) (n a b c:USize) (acc:Array UInt32) (h0:n≠0) (h1:n≠1) (hc:c+1h0 (ἶ.mp (by simpa using e)) have he:=congrArg KI e rw[ἰ n 1 (by rw[kD,ϻ];omega),ϻ,kC]at he exact h1 (ἶ.mp (by simpa using (show n.toNat=1 by omega))) rw[YO,dif_neg h0] dsimp only rw[if_pos hc,YO,dif_neg hn] dsimp only rw[USize.add_assoc,ct,dy] lemma aL (B C:USize) (p:USize->USize->USize->UInt64) (f:USize->USize->USize->UInt32) (hC:0 (p a b c).toUInt32=f a b c) (hhi:∀ a b c,c c+1 ((p a b c)>>>32).toUInt32=f a b (c+1)) (n a b c:USize) (acc:Array UInt32) (hc:c pbڇ+(off[t]!).toNat pbBڇ+(off[t]!).toNat waڇ+thn (ἶ.mp (by simpa using e))) have hs:0hn (ἶ.mp (by simpa using e))) have hxadd:(x+1).toNat=x߷+1:=QK C x (ϋ.mpr hv.xx) have hyadd:(y+1).toNat=y߷+1:=QK B y (ϋ.mpr hv.yy) have hnsub:(n-1).toNat=n߷-1:=by rw[ἰ n 1 (USize.le_iff_toNat_le.mpr (by rw[ϻ];omega)),ϻ] have hns:n߷-1+1=n߷:=kW (by omega) have h2:(2:م).toNat=2:=USize.toNat_ofNat_of_lt (ϛ (by decide:2 < 4294967296) φ) have ho:=qN A B C n o y x hv hn have hoadd:(o+2).toNat=o߷+2:=by rw[Zc _ _ (by rw[h2];have:=hv.ab;have:=φ;omega),h2] by_cases hX:x+1z*C߷) hey] have:=hv.rem;nlinarith lemma qQ (A B C o y x i:ٽ) (hB:0 < B) (hC:0 < C) (ho:o < A) (he:o%2=0) (hy:y < B) (hx:x < C) (hi:i < A*(B*C)): (i/(B*C)/2)*(B*C)+i%(B*C) = (o/2)*(B*C)+y*C+x ↔ i=o*(B*C)+y*C+x ∨ (o+1 < A ∧ i=(o+1)*(B*C)+y*C+x):=by let M:=B*C let t:=y*C+x have hM:0 < M:=ύ hB hC have ht:t < M:=by have hm:=Ε C (show y+1≤B by omega) dsimp only[t,M];nlinarith have hch:i/M < A:=(Ἒ hM).mpr (by simpa[M,ό]using hi) simp only[kR] change (i/M/2)*M+i%M=(o/2)*M+t ↔ i=o*M+t ∨ (o+1 < A ∧ i=(o+1)*M+t) have dv (a r:ٽ) (hr:r < M):(a*M+r)/M=a:=by rw[ϝ,ϙ _ _ hM,ϑ hr,Λ] constructor · intro hk have hr:i%M=t:=by have hm:=congrArg (fun z=>z%M) hk simpa only[kX,Nat.mod_mod,ν ht]using hm have hd:i/M/2=o/2:=by have hm:=congrArg (fun z=>z/M) hk rw[dv _ _ (Χ i hM),dv _ _ ht]at hm exact hm have ho2:=ἦ o 2 have hc2:=ἦ (i/M) 2 have hr2:=Χ (i/M) (by decide:0 < 2) have hc:i/M=o ∨ i/M=o+1:=by omega have hir:=ἦ i M rcases hc with hc|hc · left;rw[hc,hr]at hir;nlinarith only[hir] · right;constructor;omega;rw[hc,hr]at hir;nlinarith only[hir] · rintro (h|⟨hh,h⟩) · rw[h] rw[dv _ _ ht] simp only[kX,ν ht] · rw[h] rw[dv _ _ ht] simp only[kX,ν ht] have hh2:(o+1)/2=o/2:=by omega rw[hh2] lemma qR (A B C i:ٽ) (hB:0 < B) (hC:0 < C) (hi:i < A*(B*C)): (i/(B*C)/2)*(B*C)+i%(B*C) < ((A+1)/2)*(B*C):=by have hM:0 < B*C:=ύ hB hC have hc:i/(B*C) < A:=(Ἒ hM).mpr (by simpa[ό]using hi) have hd:i/(B*C)/2+1 ≤ (A+1)/2:=by omega have hm:=Ε (B*C) hd have hr:=Χ i hM nlinarith lemma qS (A B C:ٽ) (hB:0 < B) (hC:0 < C) (ha:A+4 < 4294967296) (hb:B+4 < 4294967296) (hc:C+4 < 4294967296) (hs:A*(B*C) < 4294967296): qM A.toUSize B.toUSize C.toUSize (((A+1)/2)*(B*C)).toUSize 0 0 0:=by have hhalf:(A+1)/2 ≤ A:=by omega have hn:((A+1)/2)*(B*C) < 4294967296:=lt_of_le_of_lt (Ε (B*C) hhalf) hs have aA:A.toUSize߷=A:=Za A (by omega) have aB:B.toUSize߷=B:=Za B (by omega) have aC:C.toUSize߷=C:=Za C (by omega) have aN:((((A+1)/2)*(B*C)).toUSize).toNat=((A+1)/2)*(B*C):=Za _ hn constructor · simpa only[aB]using hB · simpa only[aC]using hC · simpa only[aA]using ha · simpa only[aB]using hb · simpa only[aC]using hc · simpa only[aA,aB,aC]using hs · simp · simpa only[kC,aB]using hB · simpa only[kC,aC]using hC · simp only[aA,aB,aC,aN,kC,KC,Ϫ,Ἇ] lemma qT (A B C n o y x:م) (hv:qM A B C n o y x) (hn:n≠0) (ho:o+1>>32).toUInt32 (by rw[kB,hs];exact (qT A B C n o y x hv hn ho).2) else out lemma qW (A B C n o y x:م) (hv:qM A B C n o y x) (hn:n≠0) (out:ل ك) (hs:out.size=A߷*(B߷*C߷)) (v:ق): (qV A B C n o y x hv hn out hs v).size=out.size:=by unfold qV dsimp only split <;> simp only[kB] lemma qX (A B C n o y x:م) (hv:qM A B C n o y x) (hn:n≠0) (out:ل ك) (hs:out.size=A߷*(B߷*C߷)) (v:ق) (i:ٽ) (hi:i>>32).toUInt32 else if i=o߷*(B߷*C߷)+y߷*C߷+x߷ then v.toUInt32 else out[i]!:=by unfold qV dsimp only split · rename_i ho rw[qU _ _ _ _ i (by simpa only[kB]using hi),qU _ _ _ _ i hi] rw[(qO A B C n o y x hv hn).1,(qT A B C n o y x hv hn ho).1] simp only[ho,true_and,eq_comm] · rename_i ho rw[qU _ _ _ _ i hi,(qO A B C n o y x hv hn).1] simp only[ho,false_and,if_false,eq_comm] lemma qY (A B C n o y x:م) (hv:qM A B C n o y x) (hn:n≠0) (out:ل ك) (hs:out.size=A߷*(B߷*C߷)) (v:ق) (F:ٽ→ك) (hlo:v.toUInt32=F (o߷*(B߷*C߷)+y߷*C߷+x߷)) (hhi:∀ho:o+1>>32).toUInt32=F ((o߷+1)*(B߷*C߷)+y߷*C߷+x߷)) (hinv:∀i,ihn (ἶ.mp (by simpa using e)) have hsub:(n-1).toNat=n߷-1:=by rw[ἰ n 1 (by rw[kD,ϻ];omega),ϻ] have h:=hv.rem have h':=hv'.rem omega lemma qb (A B C:م) (f:م→م→م→ق) (n o y x:م) (out:ل ك) (hv:qM A B C n o y x) (hs:out.size=A߷*(B߷*C߷)) (F:ٽ→ك) (hcb:∀o y x:م,o߷>>32).toUInt32=F ((o߷+1)*(B߷*C߷)+y߷*C߷+x߷)) (hinv:∀i,iih.2 i (by rwa[hnsize])⟩ · rename_i hx split · rename_i hy have hv2:qM A B C (n-1) o (y+1) 0:=by simpa only[if_neg hx,if_pos hy]using hv' have hq:=qa A B C n o y x o (y+1) 0 hv h hv2 have ih:=qb A B C f (n-1) o (y+1) 0 _ hv2 (hnsize.trans hs) F hcb (by intro i hi hk apply hninv i (by rwa[hnsize]at hi) rw[←hq] exact hk) exact ⟨ih.1.trans hnsize,fun i hi=>ih.2 i (by rwa[hnsize])⟩ · rename_i hy have hv2:qM A B C (n-1) (o+2) 0 0:=by simpa only[if_neg hx,if_neg hy]using hv' have hq:=qa A B C n o y x (o+2) 0 0 hv h hv2 have ih:=qb A B C f (n-1) (o+2) 0 0 _ hv2 (hnsize.trans hs) F hcb (by intro i hi hk apply hninv i (by rwa[hnsize]at hi) rw[←hq] exact hk) exact ⟨ih.1.trans hnsize,fun i hi=>ih.2 i (by rwa[hnsize])⟩ termination_by n߷ decreasing_by all_goals exact u1 n (by assumption) lemma qc (B C o y x:ٽ)(hB:0>>32).toUInt32=F ((o߷+1)*(B߷*C߷)+y߷*C߷+x߷)): qd A B C f (((A߷+1)/2)*(B߷*C߷)).toUSize 0 0 0 (kA (A߷*(B߷*C߷))) (kA (B߷*C߷))= Ἲ (n:=A߷*(B߷*C߷)) (fun q=>F q.val):=by unfold qd rw[dif_pos ⟨g,d,hA,hB,hC,hs⟩] have hv:qM A B C (((A߷+1)/2)*(B߷*C߷)).toUSize 0 0 0:=by simpa only[kY,kH]using qS A߷ B߷ C߷ g d hA hB hC hs have hp:=qb A B C f _ 0 0 0 (Υ (A߷*(B߷*C߷)) 0) hv (by simp) F (fun o y x ho hy hx=>⟨hlo o y x ho hy hx,fun hh=>hhi o y x (by have ha:=(QK A o (ϋ.mpr ho)) have ht:=ϋ.mp hh rw[ha]at ht;exact ht) hy hx⟩) (by intro i hi hk;simp only[kC,KC,Ϫ,Λ]at hk;omega) apply kj · simpa using hp.1 · intro i hi hj rw[←getElem!_pos _ i hi,hp.2 i (by simpa using hj)] simp only[Ἃ] lemma qf (A B C:م) (f:م→م→م→ق) (p:م→م→م→ك) (hA:A߷+4<4294967296)(hB:B߷+4<4294967296)(hC:C߷+4<4294967296) (g:0>>32).toUInt32=p (o+1) y x): qd A B C f (((A߷+1)/2)*(B߷*C߷)).toUSize 0 0 0 (kA (A߷*(B߷*C߷))) (kA (B߷*C߷))= YO B C p (A߷*(B߷*C߷)).toUSize 0 0 0 (kA (A߷*(B߷*C߷))):=by let F:ٽ→ك:=fun q=>p (q/(B߷*C߷)).toUSize (q/C߷%B߷).toUSize (q%C߷).toUSize have hn':((A߷+1)/2)*(B߷*C߷)<4294967296:= (Ε _ (show (A߷+1)/2<=A߷ by omega)).trans_lt hn rw[qe A B C f F hA hB hC g d hn _ _,E1 B C p g d _ _ hn] · intro o y x ho hy hx rw[hlo o y x ho hy hx] dsimp only[F] obtain ⟨h0,h1,h2⟩:=qc B߷ C߷ o߷ y߷ x߷ g d hy hx rw[h0,h1,h2] simp only[Nat.toUSize_eq,kH] · intro o y x ho hy hx rw[hhi o y x ho hy hx] dsimp only[F] obtain ⟨h0,h1,h2⟩:=qc B߷ C߷ (o߷+1) y߷ x߷ g d hy hx rw[h0,h1,h2] have ho1:(o+1).toNat=o߷+1:=by rw[Zc _ _ (by have:=φ;simp only[ϻ];omega),ϻ] rw[←ho1] simp only[Nat.toUSize_eq,kH] @[inline] def ah (dw:ه) (s:σ) (aB:ه) (aC aD 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) : ل δ := if dw then cJ dw s aB aC aD b k C hk hC else let off:ل ك:=ډ k λ t=>(Ys s t.val).toUInt32 let bp:=Yc aC aCچ 0 let BW:ل ك:=ډ C λ o=>Yc aD k o.val let xm:=dl bp BW b let g:=(Array.range C).all (λ o=>cS BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0cS BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then cC s aC xm YV else cC s aC xm c8 let PH:=if g then P2 else cC s aC xm c7 let W2:ل ك:=dt aD BW b xm k have hP2:P2چ=s.cin*(Yb s*Ya s):=by simp only[P2];split<;>rw[B3 s aC xm _ hg.2.2.1 א א,Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א,Ἠ] have a:=D2 s C hg.2.2.1 let B0s:ل ق:=ډ C λ o=>xm+YG BW[o.val]! b[o.val]! xm let BCs:Array aJ:=Ἲ (n:=C) (fun o=>aK B0s[o.val]! b[o.val]!) let hw:=(Yb s*Ya s).toUSize let st:=s.strideڈ let wp:=(Ya s).toUSize let ku:=kڈ qd C.toUSize s.hoڈ s.woڈ (λ o y x => if h:oby obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ xڇ t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h.2.2 א) ht rw[H9 dw s o y x hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h.2.2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by have:=Ε k (show oڇ+1<=C from Z4 h.1 א) rw[Ϣ,ϫ] at this rw[um _ _ (by rw[Za _ א];omega),Za _ א] simp only[W2,B7 aD BW b xm k א א,Ἠ];omega) (by have hc:(o+1).toNat>>32).toUInt32).toUInt64<<<32) else (act aB (bU s aC P2 PH off aD W2 b k o y x dw (IX dw o y x hw st wp) (o*ku) (B0s.uget o (by simp only[B0s,Ἠ];exact Z4 h.1 א)) (!g) א (by simp[off]) hH (λ t ht=>by obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ xڇ t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h.2.2 א) ht rw[H9 dw s o y x hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h.2.2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by have:=Ε k (show oڇ+1<=C from Z4 h.1 א) rw[Ϣ,ϫ] at this rw[um _ _ (by rw[Za _ א];omega),Za _ א] simp only[W2,B7 aD BW b xm k א א,Ἠ];omega))).toUInt64 else 0) (((C+1)/2)*(s.ho*s.wo)).toUSize 0 0 0 (kA (C*(s.ho*s.wo))) (kA (s.ho*s.wo)) else if dw then dk s aB aC aD b else ds s aB aC aD b @[inline] def ai (dw:Bool) (s:ConvShape) (aB:Bool) (aC aD b:Array Word) (k C:Nat) (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):Array Word:= if hs:C+4<4294967296 ∧ s.ho+4<4294967296 ∧ s.wo+4<4294967296 then ah dw s aB aC aD b k C hk hC else cJ dw s aB aC aD b k C hk hC lemma cr (A B C:Nat) (f:USize→USize→USize→UInt64) (p:USize→USize→USize→UInt32) (hA:A+4<4294967296)(hB:B+4<4294967296)(hC:C+4<4294967296) (g:0>>32).toUInt32=p (o+1) y x): qd A.toUSize B.toUSize C.toUSize f (((A+1)/2)*(B*C)).toUSize 0 0 0 (kA (A*(B*C))) (kA (B*C))= YO B.toUSize C.toUSize p (A*(B*C)).toUSize 0 0 0 (kA (A*(B*C))):=by have hA':A.toUSize.toNat=A:=Za _ (by omega) have hB':B.toUSize.toNat=B:=Za _ (by omega) have hC':C.toUSize.toNat=C:=Za _ (by omega) simpa only[hA',hB',hC'] using qf A.toUSize B.toUSize C.toUSize f p (by rwa[hA']) (by rwa[hB']) (by rwa[hC']) (by rwa[hB']) (by rwa[hC']) (by rwa[hA',hB',hC']) (by simpa only[hA',hB',hC'] using hlo) (by simpa only[hA',hB',hC'] using hhi) lemma aj (dw:Bool) (s:ConvShape) (aB:Bool) (aC aD b:Array Word) (k C:Nat) (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): ai dw s aB aC aD b k C hk hC=cJ dw s aB aC aD b k C hk hC:=by unfold ai split · rename_i hs cases dw · unfold ah cJ dsimp only simp only[χ,ite_false] split · rename_i hg apply cr · exact hs.1 · exact hs.2.1 · exact hs.2.2 · exact (ZG s).1 · exact (ZG s).2 · omega · intro o y x ho hy hx have hh:oP p.1) (by intro j _ hj;exact hp j hj) z hz def aH (off w:Array UInt32) (wa n i:USize):List (UInt32×UInt32):= if h:ip.2!=0x80000000):=by rw[aE,aH] split · generalize hv:(if h:(wa+i).toNatp.2!=0x80000000)).foldl f s=l.foldl f s:=by induction l generalizing s with | nil=>rfl | cons p l ih=> obtain ⟨o,w⟩:=p by_cases hw:w=0x80000000 · subst w;simpa[hz] using ih s · simpa[hw] using ih (f s (o,w)) lemma a6 {S:Type} (off w:Array UInt32) (wa n i:USize) (f:S→(UInt32×UInt32)→S) (hz:∀ s o,f s (o,0x80000000)=s) (s:S): (aE off w wa n i).foldl f s=(aH off w wa n i).foldl f s:=by rw[aP];exact bC _ f hz s def aS (f:UInt32→UInt64) (s:UInt64×UInt64) (p:UInt32×UInt32):UInt64×UInt64:= (s.1+Y9 (f p.1) p.2.toUInt64,s.2+b8 (f p.1) p.2.toUInt64) def aR (f:UInt32→UInt64) (s:UInt64×UInt64×UInt64) (p:UInt32×UInt32):UInt64×UInt64×UInt64:= let x:=f p.1 let w:=p.2.toUInt64 (s.1+MM (aY 0 x).toUInt64 w,s.2.1+MM (aY 1 x).toUInt64 w,s.2.2+MM ((aY 2 x).toUInt64-0x200000) w) lemma bF (f:UInt32→UInt64) (s:UInt64×UInt64) (o:UInt32):aS f s (o,0x80000000)=s:=by have z:sx 0=0:=rfl simp[aS,Y9,b8,z] lemma bE (f:UInt32→UInt64) (s:UInt64×UInt64×UInt64) (o:UInt32):aR f s (o,0x80000000)=s:=by have z:sx 0=0:=rfl simp[aR,MM,z] lemma bH (off w:Array UInt32) (wa n i:USize) (f:UInt32→UInt64) (s:UInt64×UInt64): (aE off w wa n i).foldl (aS f) s=(aH off w wa n i).foldl (aS f) s:= a6 off w wa n i _ (bF f) s lemma bG (off w:Array UInt32) (wa n i:USize) (f:UInt32→UInt64) (s:UInt64×UInt64×UInt64): (aE off w wa n i).foldl (aR f) s=(aH off w wa n i).foldl (aR f) s:= a6 off w wa n i _ (bE f) s lemma bV (n i:USize) (hi:ihi (τ.mpr h);omega rw[List.drop_eq_nil_of_le (by simpa using hle),List.drop_eq_nil_of_le (as:=w.toList) (i:=i.toNat) (by simpa[hw] using hle)] rfl termination_by n.toNat-i.toNat decreasing_by exact ZI n i ‹irfl | cons p l ih=>cases p;simp only[KW,List.zip_cons_cons,ih] lemma aW (off w:Array UInt32) (wa n:USize) (hn:n.toNat<4294967296): let row:=aA off w wa n 0 #[] #[] aH row.offsets row.values 0 row.values.size.toUSize 0=aE off w wa n 0:=by dsimp only let row:=aA off w wa n 0 #[] #[] change aH row.offsets row.values 0 row.values.size.toUSize 0=_ have hl:=a5 off w wa n have hm:row.values.size<4294967296:=by exact hl.2.trans_lt hn rw[be row.offsets row.values row.values.size.toUSize 0 ((Za _ hm).trans hl.1.symm) hl.1.symm] dsimp only[row] rw[(aI off w wa n 0 #[] #[]).1,(aI off w wa n 0 #[] #[]).2] simp only[kr,KO,kC,List.drop_zero] exact bP _ lemma bB (a:Array UInt32) (i:USize): (if h:i.toNatpb.toNat+q.toNat pbڇ+(off[t]!).toNat pbBڇ+(off[t]!).toNat waڇ+t(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64+(PH.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox,hH];exact hix _ (uk ht hk)))).toUInt64*0x40000000000) (λ t ht=>(P2.uget (pbB+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hixB _ (uk ht hk)))).toUInt64+(PH.uget (pbB+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox,hH];exact hixB _ (uk ht hk)))).toUInt64*0x40000000000) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) B0 b[o.toNat]! cb (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b originalK o y x dw) (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b originalK o y (x+1) dw) 0 0 0 0 0 0 0 else bJ k.toUSize (λ t ht=>(P2.uget (pb+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hix _ (uk ht hk)))).toUInt64) (λ t ht=>(P2.uget (pbB+(off.uget t (by rw[hoff];exact uk ht hk)).toUSize) (A9 _ _ _ (by rw[ox];exact hixB _ (uk ht hk)))).toUInt64) (λ t ht=>(W2.uget (wa+t) (A9 _ _ _ (hW _ (uk ht hk)))).toUInt64) B0 b[o.toNat]! cb (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b originalK o y x dw) (λ v=>if v<0x100000000 then v.toUInt32 else cB s aC aD b originalK o y (x+1) dw) 0 0 0 0 0 lemma dc (s:ConvShape) (aC:Array Word) (P2 PH:Array Nat) (off:Array UInt32) (aD:Array Word) (W2:Array UInt32) (b:Array Word) (k:Nat) (o y x:USize) (dw:Bool) (pb pbB wa:USize) (B0:UInt64) (cb:aJ) (wide:Bool) (hk:k<1048576) (hoff:off.size=k) (hH:PH.size=P2.size) (hix:∀ t,t(P2[(pb+q.toUSize).toNat]!).toUInt64 let f1:UInt32→UInt64:=fun q=>(P2[(pbB+q.toUSize).toNat]!).toUInt64 let g0:UInt32→UInt64:=fun q=>(P2[(pb+q.toUSize).toNat]!).toUInt64+(PH[(pb+q.toUSize).toNat]!).toUInt64*0x40000000000 let g1:UInt32→UInt64:=fun q=>(P2[(pbB+q.toUSize).toNat]!).toUInt64+(PH[(pbB+q.toUSize).toNat]!).toUInt64*0x40000000000 have hn:k.toUSize.toNat<4294967296:=by rw[Za _ (by omega)];omega unfold cf cases wide · rw[if_neg ἳ,cj (hc:=hc)] simp only[aO,aM] rw[bO off W2 wa k.toUSize hn f0 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl), bO off W2 wa k.toUSize hn f1 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl)] simp only[bU,if_false,aO,aM] rfl · rw[if_pos rfl,cg (hc:=hc)] simp only[aO,aM] rw[bD off W2 wa k.toUSize hn g0 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl), bD off W2 wa k.toUSize hn g1 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl)] simp only[bU,if_true,aO,aM] rfl @[inline] def ce (s:ConvShape) (aC:Array Word) (P2 PH:Array Nat) (off:Array UInt32) (aD:Array Word) (W2:Array UInt32) (b:Array Word) (k:Nat) (o y x:USize) (dw:Bool) (pb pbB wa:USize) (B0:UInt64) (cb:aJ) (wide:Bool) (hk:k<1048576) (hoff:off.size=k) (hH:PH.size=P2.size) (hix:∀ t,t(Ys s t.val).toUInt32 let bp:=Yc aC aCچ 0 let BW:ل ك:=ډ C λ o=>Yc aD k o.val let xm:=dl bp BW b let g:=(Array.range C).all (λ o=>cS BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0cS BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then cC s aC xm YV else cC s aC xm c8 let PH:=if g then P2 else cC s aC xm c7 let W2:ل ك:=dt aD BW b xm k let rows:=Ἲ (n:=C) (λ o=>aA off W2 (o.val*k).toUSize k.toUSize 0 (kA k) (kA k)) have hP2:P2چ=s.cin*(Yb s*Ya s):=by simp only[P2];split<;>rw[B3 s aC xm _ hg.2.2.1 א א,Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א,Ἠ] have a:=D2 s C hg.2.2.1 let B0s:ل ق:=ډ C λ o=>xm+YG BW[o.val]! b[o.val]! xm let BCs:Array aJ:=Ἲ (n:=C) (fun o=>aK B0s[o.val]! b[o.val]!) let hw:=(Yb s*Ya s).toUSize let st:=s.strideڈ let wp:=(Ya s).toUSize let ku:=kڈ qA s.hoڈ s.woڈ (λ o y x => if h:oaA off W2 (j*k).toUSize k.toUSize 0 (kA k) (kA k)) o.toNat ho simpa only[KH,hwa] using hr0 let v:=ce s aC P2 PH off aD W2 b k o y x dw (IX dw o y x hw st wp) (IX dw o y (x+1) hw st wp) (o*ku) (B0s.uget o (by simp only[B0s,Ἠ];exact Z4 h.1 א)) (BCs.uget o (by simp only[BCs,Ἠ];exact Z4 h.1 (by omega))) (!g) א (by simp[off]) hH (λ t ht=>by obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ xڇ t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h.2.2 א) ht rw[H9 dw s o y x hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h.2.2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ (x+1 : USize).toNat t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h2 א) ht rw[H9 dw s o y (x+1) hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by have:=Ε k (show oڇ+1<=C from Z4 h.1 א) rw[Ϣ,ϫ] at this rw[um _ _ (by rw[Za _ א];omega),Za _ א] simp only[W2,B7 aD BW b xm k א א,Ἠ];omega) (cz C B0s b o (Z4 h.1 (by omega)) (by simp only[B0s,Ἠ];exact Z4 h.1 (by omega))) row hrow (act aB v.toUInt32).toUInt64 ||| ((act aB (v>>>32).toUInt32).toUInt64<<<32) else (act aB (bU s aC P2 PH off aD W2 b k o y x dw (IX dw o y x hw st wp) (o*ku) (B0s.uget o (by simp only[B0s,Ἠ];exact Z4 h.1 א)) (!g) א (by simp[off]) hH (λ t ht=>by obtain ⟨w1,-⟩:=L4 dw s aC k oڇ yڇ xڇ t hk hg.1 hg.2.1 (by intro d;subst d hC;simpa using Z4 h.1 א) (Z4 h.2.1 א) (Z4 h.2.2 א) ht rw[H9 dw s o y x hg.2.2.1 א א (lt_trans (Z4 h.2.1 א) א) (lt_trans (Z4 h.2.2 א) א) (fun _=>lt_trans (Z4 h.1 א) א),hP2,ZD s _ t ht א];omega) (λ t ht=>by have:=Ε k (show oڇ+1<=C from Z4 h.1 א) rw[Ϣ,ϫ] at this rw[um _ _ (by rw[Za _ א];omega),Za _ א] simp only[W2,B7 aD BW b xm k א א,Ἠ];omega))).toUInt64 else 0) (C*(s.ho*s.wo)).toUSize 0 0 0 (by rw[Za _ (by omega)];omega) else if dw then dk s aB aC aD b else ds s aB aC aD b lemma an (dw:ه) (s:σ) (aB:ه) (aC aD 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): am dw s aB aC aD b k C hk hC=cJ dw s aB aC aD b k C hk hC:=by unfold am cJ dsimp only simp only[qB,KH] split · rename_i hg apply aL · rw[Za _ (by have:=D2 s C hg.2.2.1;omega)] exact (ZG s).2 · intro o y x hx split · rename_i hh by_cases hx1:x+1(m.toNat:Int)-149) nz true (m-149) termination_by n.toNat-i.toNat decreasing_by exact ZI n i h def aZ (F:Nat→UInt32) (m:UInt64) (i:Nat):Nat→Int | 0=>0 | r+1=> sv (F i)*2^(idxOf (F i)-m.toNat)+aZ F m (i+1) r def bt (F:Nat→UInt32) (i:Nat):Nat→Bool | 0=> true | r+1=>(F i==0x80000000) && bt F (i+1) r lemma dd (m:UInt64) (h:m.toNat<1024):Y0 ((m.toNat:Int)-149) true (m-149):=by intro c d _ b rw[ξ,Φ,show(149:UInt64).toNat=149 from rfl]at b ⊢ push_cast at b ⊢ omega lemma cO (a:UInt64):Ym a=Ye a:=by have:=a.toNat_lt unfold Ym Ye split_ifs <;> omega lemma cP (n:USize) (fa:(t:USize)→t< n→UInt32) (F:Nat→UInt32) (m:UInt64) (hm:m.toNat<1024) (hn:n.toNat≤256) (hf:∀ t h,fa t h=F t.toNat) (hb:∀ t,t< n.toNat→mantOf (F t)=0 ∨ (m.toNat≤ idxOf (F t) ∧ idxOf (F t)-m.toNat≤30)): ∀ d (i:USize) (a:UInt64) (nz:Bool),n.toNat-i.toNat=d→i.toNat≤ n.toNat→ -(i.toNat:Int)*2^54≤ Ye a→Ye a≤(i.toNat:Int)*2^54→ aF n fa m a nz i=finishWord (Ye a+aZ F m i.toNat d) ((m.toNat:Int)-149) (nz && bt F i.toNat d):=by intro d induction d with | zero=> intro i a nz hd hi hlo hhi rw[aF,dif_neg (by rw[τ];omega),B6,J2 _ _ _ _ _ (dd m hm),cO] simp[aZ,bt] | succ d ih=> intro i a nz hd hi hlo hhi have hu:i< n:=by rw[τ];omega have hii: (i+1).toNat=i.toNat+1:=QK n i hu obtain⟨he,habs⟩:=H6 (F i.toNat) m 30 (by omega) (hb i.toNat (by omega)) have hbound:=abs_lt.mp habs norm_num at hbound hlo hhi have hadd:Ye (a+cq (F i.toNat) m)=Ye a+sv (F i.toNat)*2^(idxOf (F i.toNat)-m.toNat):=by rw[B4,he] all_goals norm_num at hbound ⊢; norm_num at hlo hhi; omega rw[aF,dif_pos hu] dsimp only rw[hf,ih (i+1) _ _ (by omega) (by omega) (by rw[hadd,hii];push_cast;linarith [hbound.1]) (by rw[hadd,hii];push_cast;linarith [hbound.2]),hadd,hii,aZ,bt] congr 1 · ring · simp only[Bool.and_assoc] lemma bW (w:UInt32): (w==0x80000000)=(decide (mantOf w=0) && signOf w):=by apply ἁ.mpr simp only[beq_iff_eq,ϓ,decide_eq_true_eq] constructor · intro h;subst w;decide · rintro ⟨hm,hs⟩ have he:expOf w=0:=by unfold mantOf at hm;split_ifs at hm <;> omega have hf:fracOf w=0:=by apply Ν.mp simpa only[mantOf,he,ite_true,UInt32.toNat_zero] using hm have hmod:=ofUInt32_eq_ofFields w change ofW w=_ at hmod rw[he,hf,hs]at hmod have:=congrArg toWord hmod rw[O0]at this exact this lemma cT (F:Nat→UInt32) (i r:Nat):bt F i r=Yq F (fun _=> oneW) i r:=by induction r generalizing i with | zero=> rfl | succ r ih=> rw[bt,Yq,bW,ih] simp only[show mantOf oneW=2^23 from rfl,show signOf oneW=false from rfl,Bool.xor_false] congr 2 simp lemma bX (F:Nat→UInt32) (m:UInt64) (i r:Nat) (h:∀ t,i ≤ t → t < i+r → mantOf (F t)=0 ∨ m.toNat≤ idxOf (F t)): Yo F (fun _=> oneW) i r=aZ F m i r*2^(m.toNat+149):=by induction r generalizing i with | zero=> simp[Yo,aZ] | succ r ih=> rw[Yo,aZ,ih (i+1) (fun t ht htr=> h t (by omega) (by omega)),add_mul] congr 1 have ht:=h i (by omega) (by omega) rcases ht with hz|hb · rw[X6 _ hz];simp · rw[show sv oneW=(2:Int)^23 from rfl,show idxOf oneW=126 from rfl] rw[mul_assoc,←pow_add,show 23+(idxOf (F i)+126)=idxOf (F i)-m.toNat+(m.toNat+149) by omega,pow_add,mul_assoc] lemma cE (n:USize) (fa:(t:USize)→t< n→UInt32) (F:Nat→UInt32) (m:UInt64) (hm:m.toNat<1024) (hn:n.toNat≤256) (hp:0< n.toNat) (hf:∀ t h,fa t h=F t.toNat) (hb:∀ t,t< n.toNat→mantOf (F t)=0 ∨ (m.toNat≤ idxOf (F t) ∧ idxOf (F t)-m.toNat≤30)) (hfin:∀ t,t< n.toNat→expOf (F t)≠255): aF n fa m 0 true 0=dotOf n.toNat F (fun _=> oneW):=by rw[cP n fa F m hm hn hf hb n.toNat 0 0 true (by simp) (by simp) (by simp[Ye]) (by simp[Ye])] simp only[kC,Ye,ϔ,KC,Nat.cast_zero,mul_zero,sub_self,zero_add,kq] rw[cT,Zy _ _ _ (fun t ht=>⟨hfin t ht,by decide⟩),bX F m 0 n.toNat (fun t _ ht=> by rcases hb t (by simpa using ht) with hz|hz · exact Ω hz · exact Or.inr hz.1)] have hs:=finishWord_scale (aZ F m 0 n.toNat) (-298) (m.toNat+149) (Yq F (fun _=> oneW) 0 n.toNat) have hnz:n.toNat≠0:=by omega rw[show decide (n.toNat≠0)=true from decide_eq_true hnz,kq] convert hs using 1 <;> push_cast <;> ring lemma a8 (c h w k ch y x t:Nat) (hk:0< k) (hc:ch< c) (hy:y< h/k) (hx:x< w/k) (ht:t< k*k): (ch*h+y*k+t/k)*w+x*k+t%k< c*h*w:=by have htk:t/k< k:=Ἒ hk |>.mpr ht have htm:t%k< k:=Χ _ hk have hyr:(y+1)*k≤ h:=le_trans (Ε k (show y+1≤ h/k by omega)) (ἲ h k) have hxr:(x+1)*k≤ w:=le_trans (Ε k (show x+1≤ w/k by omega)) (ἲ w k) have hyy:y*k+t/k< h:=by nlinarith have hxx:x*k+t%k< w:=by nlinarith have ha:ch*h+y*k+t/k+1≤(ch+1)*h:=by nlinarith have hb:(ch*h+y*k+t/k+1)*w≤(ch+1)*h*w:=Ε w ha have hd:(ch+1)*h*w≤ c*h*w:=Ε w (Ε h (show ch+1≤ c by omega)) nlinarith lemma bM (ch y x t:USize) (h w:Nat) (hb:(ch.toNat*h+y.toNat*2+t.toNat/2)*w+x.toNat*2+t.toNat%2<4294967296): ((ch*h.toUSize+y*2+t/2)*w.toUSize+x*2+t%2).toNat= (ch.toNat*h+y.toNat*2+t.toNat/2)*w+x.toNat*2+t.toNat%2:=by have htdiv:t.toNat/2=(t/2).toNat:=by simp have htmod:t.toNat%2=(t%2).toNat:=by simp have he:((ch*h.toUSize+y*2+t/2)*w.toUSize+x*2+t%2)= ((ch.toNat*h+y.toNat*2+t.toNat/2)*w+x.toNat*2+t.toNat%2).toUSize:=by rw[htdiv,htmod] simp only[kY,kS,KL,kH] rfl rw[he,Za _ hb] lemma aQ {a:USize} {n:Nat} (h:a< n.toUSize):a.toNat< n:=by have hh:=τ.mp h change a.toNat< n%Ξ at hh exact lt_of_lt_of_le hh (Nat.mod_le _ _) lemma bu (c h w:Nat) (aC:Array UInt32) (ch y x t:USize) (hp:c*h*w≤ aC.size) (hs:aC.size<4294967296) (hc:ch< c.toUSize) (hy:y<(h/2).toUSize) (hx:x<(w/2).toUSize) (ht:t<4): ((ch*h.toUSize+y*2+t/2)*w.toUSize+x*2+t%2).toNat< aC.size:=by have H:=a8 c h w 2 ch.toNat y.toNat x.toNat t.toNat (by omega) (aQ hc) (aQ hy) (aQ hx) (by have:=τ.mp ht;simpa using this) have HH:(ch.toNat*h+y.toNat*2+t.toNat/2)*w+x.toNat*2+t.toNat%2<4294967296:=by omega rw[bM _ _ _ _ _ _ HH] omega lemma a3 (ch t:USize) (k:Nat) (hb:ch.toNat*(k*k)+t.toNat<4294967296): (ch*(k*k).toUSize+t).toNat=ch.toNat*(k*k)+t.toNat:=by have he:ch*(k*k).toUSize+t=(ch.toNat*(k*k)+t.toNat).toUSize:=by simp only[kY,kS,KL,kH] rw[he,Za _ hb] lemma bd (c k:Nat) (aC:Array UInt32) (ch t:USize) (hp:c*k*k≤ aC.size) (hs:aC.size<4294967296) (hc:ch< c.toUSize) (ht:t<(k*k).toUSize): (ch*(k*k).toUSize+t).toNat< aC.size:=by have HC:=aQ hc have HT:=aQ ht have HH:ch.toNat*(k*k)+t.toNat< c*k*k:=by nlinarith rw[a3 _ _ _ (by omega)] omega @[inline] def bK (fa:(t:USize)→t<4→UInt32) (m:UInt64):UInt32 := let v0:=fa 0 (by rw[τ];norm_num) let v1:=fa 1 (by rw[τ];norm_num) let v2:=fa 2 (by rw[τ];norm_num) let v3:=fa 3 (by rw[τ];norm_num) cc (((cq v0 m+cq v1 m)+cq v2 m)+cq v3 m) (fun _=>(m.toNat:Int)-149) (((v0==0x80000000 && v1==0x80000000) && v2==0x80000000) && v3==0x80000000) true (m-149) lemma cl (fa:(t:USize)→t<4→UInt32) (m:UInt64): bK fa m=aF 4 fa m 0 true 0:=by have h2:(1:USize)+1=2:=(kS 1 1).symm have h3:(2:USize)+1=3:=(kS 2 1).symm have h4:(3:USize)+1=4:=(kS 3 1).symm rw[aF,dif_pos (by rw[τ];norm_num)] dsimp only simp only[KP] rw[aF,dif_pos (by rw[τ];norm_num)] dsimp only rw[h2, aF,dif_pos (by rw[τ];norm_num)] dsimp only rw[h3,aF,dif_pos (by rw[τ];norm_num)] dsimp only rw[h4,aF,dif_neg (by rw[τ];norm_num)] simp only[bK,UInt64.zero_add,kq] def ay (c h w k:Nat) (aC:Array UInt32):Array UInt32 := let bx:=Yc aC aC.size 0 let m:=Yk (bx>>>16) if hfast:c*h*w≤ aC.size ∧ c*h*w+aC.size<4294967296 ∧ (bx&&&0xFFFF)!=255 ∧ m≤ Yk (bx&&&0xFFFF) ∧ YU bx≤30 then if hcase:k=2 ∧ 2≤ h ∧ 2≤ w then YO (h/2).toUSize (w/2).toUSize (fun ch y x=> if hout:ch< c.toUSize ∧ y<(h/2).toUSize ∧ x<(w/2).toUSize then dh 4 (bK (fun t ht=> aC.uget ((ch*h.toUSize+y*2+t/2)*w.toUSize+x*2+t%2) (bu c h w aC ch y x t hfast.1 (by omega) hout.1 hout.2.1 hout.2.2 ht)) m) else 0) (c*(h/2*(w/2))).toUSize 0 0 0 (kA (c*(h/2*(w/2)))) else if hglob:k=h ∧ k=w ∧ 0< k ∧ k*k≤256 then YO 1 1 (fun ch _ _=> if hout:ch< c.toUSize then (if k*k=16 then dr 4 else dh (k*k)) (aF (k*k).toUSize (fun t ht=> aC.uget (ch*(k*k).toUSize+t) (bd c k aC ch t (by rcases hglob with ⟨rfl,rfl,hp,hk⟩;exact hfast.1) (by omega) hout ht)) m 0 true 0) else 0) c.toUSize 0 0 0 (kA c) else dV c h w k aC else dV c h w k aC lemma bn (aC:Array UInt32) (n:USize) (fa:(t:USize)→t< n→UInt32) (F:Nat→UInt32) (hs:aC.size<4294967296) (hn:n.toNat≤256) (hp:0< n.toNat) (hg:(Yc aC aC.size 0&&&0xFFFF)≠255) (hle:Yk (Yc aC aC.size 0>>>16)≤ Yk (Yc aC aC.size 0&&&0xFFFF)) (hb:YU (Yc aC aC.size 0)≤30) (hf:∀ t h,fa t h=F t.toNat) (hF:∀ t,t< n.toNat→∃ j,j< aC.size ∧ F t=aC[j]!): aF n fa (Yk (Yc aC aC.size 0>>>16)) 0 true 0=dotOf n.toNat F (fun _=> oneW):=by obtain⟨hok,hr,hm,hfin⟩:=J6 aC aC.size 0 (by simp) (by simpa using hs) hg hle have hspan:(YU (Yc aC aC.size 0)).toNat≤30:=by exact Κ.mp hb apply cE n fa F _ (by omega) hn hp hf · intro t ht obtain⟨j,hj,hjF⟩:=hF t ht rw[hjF] have H:=hok j hj simp only[Ϫ,Λ]at H rcases H with H|H · exact Ω H · exact Or.inr ⟨H.1,le_trans H.2 hspan⟩ · intro t ht obtain⟨j,hj,hjF⟩:=hF t ht rw[hjF] simpa using hfin j hj lemma cF (n:Nat) (s:UInt32): (if n=16 then dr 4 else dh n) s=toWord (FloatLib.Floats.Formats.BinaryInterchange.Model.div (ofW s) (ofW (natW n))):=by by_cases hn:n=16 · subst n;rw[if_pos rfl];exact O8 4 (by omega) s · rw[if_neg hn,O7] lemma bL (h w k:Nat) (aC:Array UInt32):ay 0 h w k aC=avgpoolSpec 0 h w k aC:=by unfold ay dsimp only split · split · simp only[Ϫ,show (0:Nat).toUSize=(0:USize) from rfl] rw[YO,dif_pos rfl] simp[avgpoolSpec,avgpoolWith] · split · simp only[Ϫ,show (0:Nat).toUSize=(0:USize) from rfl] rw[YO,dif_pos rfl] simp[avgpoolSpec,avgpoolWith] · rw[T2] · rw[T2] lemma az (c h w k:Nat) (aC:Array UInt32):ay c h w k aC=avgpoolSpec c h w k aC:=by by_cases hc0:c=0 · subst c;exact bL h w k aC have hcpos:0< c:=by omega unfold ay dsimp only split · rename_i hg obtain⟨Hprod,Hsize,Hfin,Hmin,Hspan⟩:=hg have hs:aC.size<4294967296:=by omega split · rename_i hk obtain⟨rfl,Hh,Hw⟩:=hk have hh:h<4294967296:=by have H1:=Ἀ h hcpos have H2:=ϟ (c*h) (show 0rw[show 2*2=4 from rfl,←show (4:USize).toNat=4 from by norm_num] apply bn aC 4 _ (poolAt h w 2 aC (q.val/(h/2*(w/2))) (q.val/(w/2)%(h/2)) (q.val%(w/2))) hs (by norm_num) (by norm_num) (by simpa using Hfin) Hmin Hspan · intro t ht apply A7 have Ht:t.toNat<4:=by have:=τ.mp ht;simpa using this have HB:=a8 c h w 2 (q.val/(h/2*(w/2))) (q.val/(w/2)%(h/2)) (q.val%(w/2)) t.toNat (by omega) hch hy hx Ht rw[bM _ _ _ _ _ _ (by rw[Za _ hch32,Za _ hy32,Za _ hx32];omega),Za _ hch32,Za _ hy32,Za _ hx32] · intro t ht let j:=((q.val/(h/2*(w/2)))*h+(q.val/(w/2)%(h/2))*2+t/2)*w+(q.val%(w/2))*2+t%2 refine ⟨j,?_,rfl⟩ exact lt_of_lt_of_le (a8 _ _ _ _ _ _ _ _ (by omega) hch hy hx (by simpa using ht)) Hprod · split · rename_i hglob obtain⟨rfl,rfl,hkp,hkk⟩:=hglob have hc32:c<4294967296:=by have hh:=ϟ c hkp have hw:=ϟ (c*k) hkp omega have hku:(k*k).toUSize.toNat=k*k:=Za _ (by omega) rw[E1 _ _ _ (by norm_num) (by norm_num) _ _ hc32] change _=avgpoolWith dotOf c k k k aC unfold avgpoolWith simp only[show k/k=1 from KF (by omega),Nat.mul_one,Nat.div_one,KN] simp only[show (1:USize).toNat=1 from by norm_num,Nat.mul_one,Nat.div_one,KN] apply kj · simp[KF hkp] · intro i hi hj simp only[Ἠ]at hi simp only[Ἃ] let q:Fin c:=⟨i,by simpa using hi⟩ have hq32:q.val<4294967296:=by omega rw[dif_pos (by rw[τ,Za _ hq32,Za _ hc32];exact q.isLt),cF] congr 3 have hF:poolAt k k k aC q.val 0 0=(fun t=>aC[q.val*(k*k)+t]!):=by funext t unfold poolAt simp only[Ϫ,Ἇ,Λ] congr 1 have ht:=ἦ t k nlinarith rw[hF] conv_rhs=>arg 1; rw[←hku] apply bn aC _ _ _ hs (by rw[hku];exact hkk) (by rw[hku];exact ύ hkp hkp) (by simpa using Hfin) Hmin Hspan · intro t ht apply A7 have Hiz:i<4294967296:=by simpa[q] using hq32 have H:=aQ ht have H2:i*(k*k)+t.toNat254) at HE omega lemma bT (d:FloatLib.Numerics.Dyadic) (hs:d.negative=true): (ἒ Fmt d).signBit=true ∧ kG (ἒ Fmt d)=false:=by unfold ἒ rw[hs] dsimp only split · exact b9 · split · exact a9 · split · exact cU _ · exact cn _ _ lemma cp (S e:Int) (nz:Bool) (hs:S<0):reluW (finishWord S e nz)=0:=by unfold finishWord rw[if_neg (by omega)] apply cH · rw[←Ἤ] exact (bT (ofIntDyadic S e) (by simp[ofIntDyadic,hs])).1 · rw[←Ἤ] exact (bT (ofIntDyadic S e) (by simp[ofIntDyadic,hs])).2 lemma cQ (s:UInt64) (e:Int) (nz:Bool) (B:UInt64) (h:Y0 e true B) (hs:s>>>63!=0): reluW (cc s (fun _=>e) nz true B)=0:=by rw[B6,J2 _ _ _ _ _ h] apply cp have hss:s.toNat/2^63≠0:=by intro H apply (bne_iff_ne.mp hs) apply ο.mp simp only[Ζ,ω]at * simpa using H have H:=s.toNat_lt unfold Ym split_ifs <;>omega lemma co (x y z:UInt32): (let mp:=Yl x*Yl y let p:=Yd x+Yd y let iq:=Yd z+149 (if mp==0 then iq else if Yl z==0 then p else if p≤ iq then p else iq)).toNat<1024:=by have hp:(Yd x+Yd y).toNat≤508:=by rw[ξ,Zf,Zf] have:=Zg x;have:=Zg y norm_num omega have hq:(Yd z+149).toNat≤403:=by rw[ξ,Zf] have:=Zg z norm_num omega dsimp only split_ifs <;> omega @[inline] def b6 (aB:Bool) (x y z:UInt32) (my iy mz iq:UInt64):UInt32 := if expOf x != 255 then let mp:=Yl x*my let p:=Yd x+iy let k:=if mp==0 then iq else if mz==0 then p else if p≤ iq then p else iq let dp:=if k≤ p then p-k else 0 let dq:=if k≤ iq then iq-k else 0 if dp≤14 && dq≤38 then let neg:=Γ (signOf x) (signOf y) let tp:=mp<<< dp let tq:=mz<<< dq let ss:=(if neg then 0-tp else tp)+(if signOf z then 0-tq else tq) if aB && ss>>>63 != 0 then 0 else act aB (cc ss (fun _=>(k.toNat:Int)-298) (neg&&signOf z) true (k-298)) else act aB (cV x y z) else act aB (cV x y z) lemma cm (r:Bool) (s k:UInt64) (nz:Bool) (hk:k.toNat<1024): (if r && s>>>63 != 0 then 0 else act r (cc s (fun _=>(k.toNat:Int)-298) nz true (k-298)))= act r (cc s (fun _=>(k.toNat:Int)-298) nz true (k-298)):=by split · rename_i H have H' : r=true ∧ (s>>>63 !=0)=true:=by simpa only[ϓ] using H obtain⟨hr,hs⟩:=H' rw[hr] change 0=reluW _ exact (cQ s _ nz _ (P4 k hk) hs).symm · rfl lemma cG (r:Bool) (x y z:UInt32): b6 r x y z (Yl y) (Yd y) (Yl z) (Yd z+149)=act r (dR x y z (Yl y) (Yd y) (Yl z) (Yd z+149)):=by let mp:=Yl x*Yl y let p:=Yd x+Yd y let iq:=Yd z+149 let k:=if mp==0 then iq else if Yl z==0 then p else if p≤ iq then p else iq have hk:k.toNat<1024:=co x y z have HH:=fun (s:UInt64) (nz:Bool)=>cm r s k nz hk dsimp only[k,p,iq,mp]at HH unfold b6 dR dsimp only simp only[apply_ite (act r),HH] @[specialize] def bs (f:δ→δ) (stop j:م) (x:ل δ) (hs:stop.toNat<=x.size):ل δ:= if h:jb6 av w y z (Yl y) (Yd y) (Yl z) (Yd z+149)) ((ch+1)*hw).toUSize (ch*hw).toUSize x (by rw[Za _ (by have:=Ε hw (show ch+1<=c from א);omega)]; have:=Ε hw (show ch+1<=c from א);omega) else bs (fun w=>act av (cW w y z)) ((ch+1)*hw).toUSize (ch*hw).toUSize x (by rw[Za _ (by have:=Ε hw (show ch+1<=c from א);omega)]; have:=Ε hw (show ch+1<=c from א);omega) aT av c hw s t hc (ch+1) xx (by dsimp[xx];split <;> rw[(dQ ..).1] <;> exact hx) else x termination_by c-ch lemma d8 (av:ه) (c hw:ٽ) (s t:ل δ) (hc:c*hw<=4294967295) (ch:ٽ) (x:ل δ) (hx:x.size=c*hw): (aT av c hw s t hc ch x hx).size=x.size ∧ ∀ i,ib6 av w s[ch]! t[ch]! (Yl s[ch]!) (Yd s[ch]!) (Yl t[ch]!) (Yd t[ch]!+149)) ((ch+1)*hw).toUSize (ch*hw).toUSize x (by rw[Za _ hsn]; have:=Ε hw (show ch+1<=c from א);omega) have ih:=d8 av c hw s t hc (ch+1) _ (hm.1.trans hx) constructor · exact ih.1.trans hm.1 · intro i hi rw[ih.2 i (by rw[hm.1];exact hi),hm.2 i hi] rw[Za _ hsn,Za _ hjn] simp only[cG,G1 _ _ _ hff.1 hff.2] by_cases ha:(ch+1)*hw<=i · have hb:ch*hw<=i:=by have:=Ε hw (show ch<=ch+1 from א);omega simp[ha,hb,show ¬i<(ch+1)*hw from א] · by_cases hb:ch*hw<=i · have hh:0act av (cW w s[ch]! t[ch]!)) ((ch+1)*hw).toUSize (ch*hw).toUSize x (by rw[Za _ hsn]; have:=Ε hw (show ch+1<=c from א);omega) have ih:=d8 av c hw s t hc (ch+1) _ (hm.1.trans hx) constructor · exact ih.1.trans hm.1 · intro i hi rw[ih.2 i (by rw[hm.1];exact hi),hm.2 i hi] rw[Za _ hsn,Za _ hjn] by_cases ha:(ch+1)*hw<=i · have hb:ch*hw<=i:=by have:=Ε hw (show ch<=ch+1 from א);omega simp[ha,hb,show ¬i<(ch+1)*hw from א] · by_cases hb:ch*hw<=i · have hh:0ru w y z (by have hh:expOf y≠255 ∧ expOf z≠255:=(by simpa using hf);exact hh.1) (by have hh:expOf y≠255 ∧ expOf z≠255:=(by simpa using hf);exact hh.2)) ((ch+1)*hw).toUSize (ch*hw).toUSize x (by rw[Za _ (by have:=Ε hw (show ch+1<=c from א);omega)];have:=Ε hw (show ch+1<=c from א);omega) else bs (fun w=>act true (cW w y z)) ((ch+1)*hw).toUSize (ch*hw).toUSize x (by rw[Za _ (by have:=Ε hw (show ch+1<=c from א);omega)];have:=Ε hw (show ch+1<=c from א);omega) rS c hw s t hc (ch+1) xx (by dsimp[xx];split <;> rw[(dQ ..).1] <;> exact hx) else x termination_by c-ch lemma rz (c hw:ٽ) (s t:ل ك) (hc:c*hw<=4294967295) (ch:ٽ) (x:ل ك) (hx:x.size=c*hw): rS c hw s t hc ch x hx=aT true c hw s t hc ch x hx:=by rw[rS,aT] split · dsimp only simp only[rv] apply rz · rfl termination_by c-ch lemma rA (av:ه) (c hw:ٽ) (s t:ل ك) (hc:c*hw<=4294967295) (x:ل ك) (hx:x.size=c*hw): (if av then rS c hw s t hc 0 x hx else aT false c hw s t hc 0 x hx)=aT av c hw s t hc 0 x hx:=by cases av <;> simp only[χ,if_false,if_true,rz] def bj (av:ه) (c hw:ٽ) (x s t:ل δ):ل δ:= if h:x.size=c*hw ∧ c*hw<=4294967295 then (if av then rS c hw s t h.2 0 x h.1 else aT false c hw s t h.2 0 x h.1) else df av c hw x s t lemma cd:bj=scaleShiftSpec:=by funext av c hw x s t unfold bj simp only[rA] split · rename_i h have hp:=d8 av c hw s t h.2 0 x h.1 apply kj · simpa[scaleShiftSpec] using hp.1.trans h.1 · intro i hi hj have hi':iv&&&0x7fffffff==0) then am false s r i w b _ _ rfl rfl else ai false s r i w b _ _ rfl rfl def ap (s:ConvShape) (r:Bool) (i w b:Array UInt32):Array UInt32:= if w.any (fun v=>v&&&0x7fffffff==0) then am true s r i w b _ _ rfl rfl else ak true s r i w b _ _ rfl rfl lemma aq:ao=conv2dSpec:=by funext s r i w b unfold ao split · rw[an];exact E3 false s r i w b _ _ rfl rfl · rw[aj];exact E3 false s r i w b _ _ rfl rfl lemma ar:ap=depthwiseSpec:=by funext s r i w b unfold ap split · rw[an];exact E3 true s r i w b _ _ rfl rfl · rw[al];exact E3 true s r i w b _ _ rfl rfl lemma au:ay=avgpoolSpec:=by funext c h w k i;exact az c h w k i lemma av (iw ow:Nat) (r:Bool) (x w b:Array UInt32): conv2dSpec ⟨iw,1,1,ow,1,1,1,0⟩ r x w b=linearSpec 1 iw ow r x w b:=by simp only[conv2dSpec,conv2dWith,ConvShape.ho,ConvShape.wo,linearSpec,linearWith] simp only[Ϝ,Ἇ,Nat.sub_self,KC,Λ,Nat.mul_one,ϫ,Nat.div_one,KN] apply kj · simp · intro i hi hj simp only[Ἠ]at hi simp only[Ἃ] have hd:i/ow=0:=ϑ (by simpa using hi) have hm:i%ow=i:=ν (by simpa using hi) simp[hd,hm,windowAt,KN] def aw (rows iw ow:Nat) (r:Bool) (x w b:Array UInt32):Array UInt32:= if rows=1 then cJ false ⟨iw,1,1,ow,1,1,1,0⟩ r x w b _ _ rfl rfl else linearSpec rows iw ow r x w b lemma ax:aw=linearSpec:=by funext rows iw ow r x w b unfold aw split · rename_i h;subst rows rw[E3] exact av iw ow r x w b · rfl def kernels:Kernels where core:=specCore dense:=⟨aw,gemmSpec⟩ conv:=⟨ao,ap⟩ elem:=⟨ay,maxpoolSpec,addReluSpec,bj⟩ norm:=specNorm theorem correct:Obligation kernels:=by simp only[Obligation,kernels,specKernels,specDense,specConv,specElem,ax,aq,ar,au,cd] end Submission