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->ρ,rationalWord->ς,ConvShape->σ,dotOf->Β,windowAt->Δ,decodeD->Ο,sqrtLower->Ψ,limbVal->Ϗ,decodeD_toRat->ϕ,mantOf_lt_24->ϖ,addLimbs64->ϗ,toDyadic_ofUInt32->Ϟ,sqrtAccuracy->Ϭ,rowVariance->ϭ,finishWord_scale->ἄ,sqrtRational->ἆ,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->Ἒ,lt_succ_iff->Ἔ,lt_or_eq_of_le->Ἕ,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->Τ,range'_succ->ϴ,ext_getElem->ἤ,foldl_cons->ἧ open Array renaming replicate->Υ,getElem_ofFn->Ἃ,size_ofFn->Ἠ,ofFn->Ἲ open Or renaming inl->Ω open FloatFormat renaming toModel->ώ open Model.NativeBinary32 renaming mkBits->Ϥ open Model renaming toReal->ϥ,roundDyadicGeneral->ἒ,addDyadic->ἓ,isFinite->ἔ,roundDyadicGeneral_eq_roundDyadic->Ἤ open Int renaming add_emod->ϩ,negSucc->ἃ open Int64 renaming ofInt->ϵ open FloatLib.Numerics renaming roundQuotientEven->ἅ,roundShiftRightEven->ἵ,shiftRightJam->Ἰ open Float.Model renaming totalExponent->ἴ open Model.Reduction.Internal renaming State->Ἱ local notation:max x:max "˟"=>UInt64.toNat (x :) local notation:max x:max "߷"=>USize.toNat (x :) local notation:max x:max "؟"=>UInt32.toNat (x :) local notation:max x:max "۞"=>Nat.toUSize (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"ڇ"=>USize.toNat local postfix:max"ڇ"=>UInt32.toNat local postfix:max"ڇ"=>Int.toNat local postfix:max"ڈ"=>Nat.toUSize 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→ك):ك:=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,Model.ofUInt32,Ἓ,ν 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 Zb0 (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 Zb1 (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 finiteBridge (A B:Array ك)(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 (Model.ofUInt32 (fmt:=κ)) with f set R:=B.map (Model.ofUInt32 (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:=finiteBridge A B hAB fin change dotSpec A B=_ rw[← H] simp only[A,B,Ἠ,Zb0 n a b 0 n (by omega),Zb1 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 Zb3 (s:ه) (E F:ٽ) (b:E<256) (a:F<2^23):(Model.ofFields κ 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:=Nat.and_two_pow_sub_one_of_lt_two_pow (n:=8) b;have e:F&&&Fmt.fracMaskNat=F:=Nat.and_two_pow_sub_one_of_lt_two_pow (n:=23) a;rw[d,e,show E.shiftLeft Fmt؉=E<<<23 from rfl,Nat.or_assoc,<- Nat.shiftLeft_add_eq_or_of_lt 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,<- Nat.shiftLeft_add_eq_or_of_lt f];simp;omega @[inline] def Yv (neg:ه) (E F:ك):ك:=(if neg then (߿:ك) else 0)+(E<<<23)+F lemma ZT (a:ه) (E F:ك) (b:E؟<256) (d:F؟<2^23):Yv a E F=π (Model.ofFields κ a E؟ F؟):=by unfold toWord;rw[Zb3 a _ _ b d];apply Ἥ.mp;unfold Yv;cases a<;>simp<;>omega lemma N7 (a:ه):Yv a 255 0=π (Model.nativeOverflow κ a):=by rw[Model.nativeOverflow_eq_signedInf_of_isIEEE Fmt ד];cases a<;>decide lemma Zb4 (a:ه):Yv a 0 0=π (Model.zero κ 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,(Nat.log2_lt hn).mpr hh⟩ def aa : ByteArray:=⟨Ἲ (fun i:Fin 256=>i.val.log2.toUInt8)⟩ lemma ab (x:ق): 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 (Nat.log2_lt h).mpr x.toNat_lt let r0:ق:=0 have hz:r0.toNat=0:=rfl let r1:ق:=if x >= 4294967296 then r0+32 else r0 let x1:ق:=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:ق:=if x1 >= 65536 then r1+16 else r1 let x2:ق:=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:ق:=if x2 >= 256 then r2+8 else r2 let x3:ق:=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 (Nat.log2_lt hn).mp t3.2 @[inline] def ac (x:ق):ق:= let r0:ق:=0 let r1:ق:=if x >= 4294967296 then r0+32 else r0 let x1:ق:=if x >= 4294967296 then x>>>32 else x let r2:ق:=if x1 >= 65536 then r1+16 else r1 let x2:ق:=if x1 >= 65536 then x1>>>16 else x1 let r3:ق:=if x2 >= 256 then r2+8 else r2 let x3:ق:=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:ق) (h:x.toNat<256) (hx:x.toUSize.toNat= 4294967296 then r0+32 else r0 let x1:ق:=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:ق:=if x1 >= 65536 then r1+16 else r1 let x2:ق:=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:ق:=if x2 >= 256 then r2+8 else r2 let x3:ق:=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) @[inline] def Yj (x:ق):ق:=ac x lemma Zj (x:ق) (_:x≠0):(Yj x)˟=x˟۩:=ae x @[inline] def Xz0 (g m:ق):ق := let s:=(g-1)&&&63 let h:=m>>>s if h-1<7 then s+(if h>=2 then 1 else 0)+(if h>=4 then 1 else 0) else Yj m lemma Xz1 (g m:ق) (hm:m≠0):Xz0 g m=Yj m:=by unfold Xz0;dsimp only;split · rename_i hh apply ἡ.mp;rw[Zj m hm] have hm0:mڇ≠0:=λ e=>hm (ἡ.mp (by rw[e];rfl)) have hS:((g-1)&&&63).toNat<64:=by rw[ἢ];exact ϊ Nat.and_le_right (by decide) generalize ((g-1)&&&63)=s at hS hh ⊢ have hH:(m>>>s).toNat=mڇ/2^sڇ:=by rw[Ζ,ν hS,ω] generalize m>>>s=h at hh hH ⊢ have hb:1<=hڇ∧hڇ<=7:=by have a:(h-1).toNat<(7:ق).toNat:=Ι.mp hh have b:=h.toNat_lt rw[Φ]at a simp only[show (7:ق).toNat=7 from rfl,show (1:ق).toNat=1 from rfl,show (2:Nat)^64=18446744073709551616 from rfl]at a b omega have e1:hڇ*2^sڇ<=mڇ:=hH▸ἲ _ _ have e2:mڇ<2^sڇ*(hڇ+1):=hH▸Nat.lt_mul_div_succ _ (ψ _) have p:0<2^sڇ:=ψ _ have q2:(2<=h)↔2<=hڇ:=Ϯ have q4:(4<=h)↔4<=hڇ:=Ϯ have t1:(1:ق).toNat=1:=rfl have t0:(0:ق).toNat=0:=rfl by_cases h2:2<=h<;>by_cases h4:4<=h<;>simp only[h2,h4,ite_true,ite_false] · have a:=q4.mp h4 have r:(s+1+1).toNat=sڇ+2:=by simp only[ξ,t1];omega rw[r];symm;rw[Ἅ hm0,show sڇ+2+1=sڇ+3 from rfl,Θ,Θ] constructor<;>nlinarith · have a:=q2.mp h2;have b:¬4<=hڇ:=λ e=>h4 (q4.mpr e) have r:(s+1+0).toNat=sڇ+1:=by simp only[ξ,t1,t0];omega rw[r];symm;rw[Ἅ hm0,show sڇ+1+1=sڇ+2 from rfl,Θ,Θ] constructor<;>nlinarith · have b:¬2<=hڇ:=λ e=>h2 (q2.mpr e);have a:=q4.mp h4 exact absurd (by omega:2<=hڇ) b · have b:¬2<=hڇ:=λ e=>h2 (q2.mpr e) have r:(s+0+0).toNat=sڇ:=by simp only[ξ,t0];omega rw[r];symm;rw[Ἅ hm0,Θ] constructor<;>nlinarith · rfl @[inline] def Ybm (m:ق) (e:پ):ق := match e+149 with | .ofNat k=>m<<FloatLib.Numerics.FixedWord.roundShiftRightEven m (k+1) @[inline] def YaO (neg:ه) (m:ق) (e:پ):ك := let fr:=Ybm 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 Zb5 (a:ه) (m:ق) (e:پ) (b:m˟≠0) (h:(m˟۩:پ)+e < -126) : YaO a m e=π (Model.packRoundedSubnormal κ a (Model.zero κ 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 YaO Ybm;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؛)=π (Model.packRoundedSubnormal κ a (Model.zero κ 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 Model.packRoundedSubnormal;by_cases g:d=0 . subst g;exact Zb4 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˟>=Model.pow2 Fmt؉ from f] exact ZT a 1 0 ד ד . have:¬ (0x800000:ق)<=d:=by rw[Κ];simpa using f simp only[this,ؠ,show ¬ d˟>=Model.pow2 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 Yae (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 Zb6 (a:ه) (m:ق) (e:پ) (b:m≠0) (d:¬ ((m˟۩:پ)+e>127)) (f:¬ ((m˟۩:پ)+e < -126)) : Yae a m (Yj m) ((m˟۩:پ)+e)=π (Model.packRoundedNormal κ a (Model.nativeOverflow κ a) (↑m˟۩+e) (if κ؉<=m˟۩ then ἵ m˟ (m˟۩-κ؉) else m˟<<<(κ؉-m˟۩))):=by obtain⟨q,r,s⟩:=Z7 m b;rw[<- q];unfold Yae Model.packRoundedNormal;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,Nat.reducePow,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[UInt32.toNat_sub_of_le _ _ (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 YaO neg m e else Yae 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 Zb5 a m e g d . simp only[d,ؠ];exact Zb6 a m e b f d @[noinline] def Ybn (neg:ه) (m:ق) (e:پ):ك:=YA neg m e @[noinline] def Yat (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 Zb7 (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,Nat.testBit_eq_decide_div_mod_eq,f,g];clear b d e f g;generalize n˟%2^40=R at *;simp only[UInt64.reduceToNat,Nat.reduceMod,Nat.reducePow,ω]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 (߿:ك) else 0)+((u<<<23)+YY n).toUInt32 lemma Zb8 (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:=(Nat.log2_lt r).mpr m߾;have x:m˟<2^(m˟۩+1):=Ἂ;have n:(YY (m<<<(63-Yj m)))˟=(YK m (Yj m))˟:=by rw[Zb7,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=Yae 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[Zb8 a u _ f A,n];unfold Yae;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[UInt32.toNat_sub_of_le _ _ (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 Zb9 (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=>Zb9 e c a (beq_iff_eq.mp b) d @[inline] def Yau (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 Ybn neg m e lemma N3 (a:ه) (m:ق) (e:پ) (d:ه) (B:ق) (b:m≠0) (f:Y0 e d B):Yau 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:=(Nat.log2_lt k).mpr m߾;unfold Yau Ybn;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[UInt64.add_assoc]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 YaP (w:ق) (e:پ) (negZero ok:ه) (B:ق):ك := if w=0 then (if negZero then ߿ else 0) else let neg:=w>>>63 != 0 Yau neg (if neg then 0-w else w) e ok B lemma J2 (w:ق) (e:پ) (a b:ه) (B:ق) (d:Y0 e b B):YaP w e a b B=ρ (Ym w) e a:=by unfold YaP 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[χ,ؠ,Int.natAbs_natCast];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 YaQ (w:ق) (e:پ) (negZero:ه):ك := YaP w e negZero ((ϵ e).toInt==e) (ϵ e).toUInt64 lemma F7 (w:ق) (e:پ) (a:ه):YaQ 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[UInt64.reduceToNat,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,<- υ,<- Nat.shiftLeft_add_eq_or_of_lt 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 Yav (w0:ق):ق := ~~~w0+1 @[inline] def Yaw (w1 w0:ق):ق := ~~~w1+(if w0==0 then 1 else 0) @[inline] def Yax (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):(Yax d b a)˟*2^128+(Yaw b a)˟*2^64+(Yav a)˟=2^192-(d˟*2^128+b˟*2^64+a˟):=by have n:=d߾;have o:=b߾;have p:=a߾;unfold Yax Yaw Yav;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,ת,UInt64.toNat_not]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,χ,ؠ,ת,ξ,UInt64.toNat_not]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,χ,ؠ,ξ,UInt64.toNat_not]at *;simp at *;omega @[inline] def Yaf (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 Yag (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 Yay (neg:ه) (m2 m1 m0:ق) (e:پ):ك := if m2 != 0 then Yaf neg m2 m1 m0 e else if m1 != 0 then Yag 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:=(Nat.log2_lt 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):Yag b a d e=π (ἒ κ ⟨b,a˟*2^64+d˟,e⟩):=by have t:=a߾;have q:=d߾;unfold Yag;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):Yaf f a d b e=π (ἒ κ ⟨f,a˟*2^128+d˟*2^64+b˟,e⟩):=by have w:=d߾;have x:=b߾;unfold Yaf;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[Nat.add_assoc];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[<- Nat.add_assoc,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) : Yay a d b f e=π (ἒ κ ⟨a,d˟*2^128+b˟*2^64+f˟,e⟩):=by unfold Yay;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 ZaP (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 YaR (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 Yat 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:=(Nat.log2_lt d).mpr a߾;omega exact⟨Zj a h,f,ZaP 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):YaR a b d e f B=Yag a b d e:=by obtain⟨k,p,l⟩:=I3 b d g;generalize b˟۩=K at k p;unfold YaR Yag Yat;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[UInt64.add_assoc]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 YaS (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 Yat neg x' e L 65 lemma V7 (a:ه) (b d f:ق) (e:پ) (g:ه) (B:ق) (j:b≠0) (k:Y0 e g B):YaS a b d f e g B=Yaf a b d f e:=by obtain⟨l,q,n⟩:=I3 b d j;generalize b˟۩=K at l q;unfold YaS Yaf Yat;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[UInt64.add_assoc]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 Yaz (neg:ه) (m2 m1 m0:ق) (e:پ) (ok:ه) (b:ق):ك := if m2 != 0 then YaS neg m2 m1 m0 e ok b else if m1 != 0 then YaR neg m1 m0 e ok b else Yau 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) : Yaz a d b f e g B=Yay a d b f e:=by unfold Yaz Yay;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 YaT (w2 w1 w0:ق) (e:پ) (negZero ok:ه) (B:ق):ك := if w2=0/\w1=0/\w0=0 then (if negZero then ߿ else 0) else if w2>>>63 != 0 then Yaz true (Yax w2 w1 w0) (Yaw w1 w0) (Yav w0) e ok B else Yaz false w2 w1 w0 e ok B lemma J1 (a b d:ق) (e:پ) (f g:ه) (B:ق) (h:Y0 e g B):YaT 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,Int.natAbs_natCast,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:(Yax a b d)˟*2^128+(Yaw b d)˟*2^64+(Yav 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,Int.natAbs_natCast,decide_eq_true (Int.neg_neg_of_pos (Int.natCast_pos.mpr (Nat.sub_pos_of_lt q)))] @[inline] def YauT (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 Ybn neg m (e ()) @[inline] def YaRT (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 Yat neg x' (e ()) L 1 @[inline] def YaST (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 Yat neg x' (e ()) L 65 @[inline] def YazT (neg:ه) (m2 m1 m0:ق) (e:Unit -> پ) (ok:ه) (b:ق):ك := if m2 != 0 then YaST neg m2 m1 m0 e ok b else if m1 != 0 then YaRT neg m1 m0 e ok b else YauT neg m0 e ok b @[inline] def YaTT (w2 w1 w0:ق) (e:Unit -> پ) (negZero ok:ه) (B:ق):ك := if w2=0/\w1=0/\w0=0 then (if negZero then ߿ else 0) else let s:=w2>>>63 let mk:ق:=0-s let n0:=(w0^^^mk)+s let c0:ق:=if n0پ) (f g:ه) (B:ق):YaTT a b d e f g B=(if a=0/\b=0/\d=0 then (if f then ߿ else 0) else if a>>>63 != 0 then YazT true (Yax a b d) (Yaw b d) (Yav d) e g B else YazT false a b d e g B):=by unfold YaTT split · rfl · dsimp only have hs:a>>>63=0∨a>>>63=1:=by have:(a>>>63).toNat<2:=by rw[UInt64.toNat_shiftRight];have:=a.toNat_lt;simp;omega rcases (by omega:(a>>>63).toNat=0∨(a>>>63).toNat=1) with h|h · left;exact UInt64.toNat_inj.1 (by simp[h]) · right;exact UInt64.toNat_inj.1 (by simp[h]) rcases hs with h|h<;>rw[h] · simp[Xq4] · simp only[Xq1] by_cases hd:d=0<;>by_cases hb:b=0<;>simp[hd,hb,Xq2,Xq4,Xq5,Yax,Yaw,Yav] @[inline] def YaPT (w:ق) (e:Unit -> پ) (negZero ok:ه) (B:ق):ك := if w=0 then (if negZero then ߿ else 0) else let neg:=w>>>63 != 0 YauT neg (if neg then 0-w else w) e ok B lemma B5 (a b d:ق) (e:پ) (f g:ه) (B:ق):YaTT a b d (λ _=>e) f g B=YaT a b d e f g B:=by rw[B5x];rfl lemma B6 (w:ق) (e:پ) (a b:ه) (B:ق):YaPT w (λ _=>e) a b B=YaP w e a b B:=rfl @[inline] def Xz2 (neg:ه) (m g:ق) (e:Unit -> پ) (ok:ه) (b:ق):ك := let L:=Xz0 g m let u:=b+L+126 if ok&&u<=253 then YZ neg u (m<<<(63-L)) else Ybn neg m (e ()) @[inline] def Xz3 (w g:ق) (e:Unit -> پ) (negZero ok:ه) (B:ق):ك := if w=0 then (if negZero then ߿ else 0) else let neg:=w>>>63 != 0 Xz2 neg (if neg then 0-w else w) g e ok B lemma Xz4 (n:ه) (m g:ق) (e:Unit -> پ) (ok:ه) (b:ق) (hm:m≠0):Xz2 n m g e ok b=YauT n m e ok b:=by unfold Xz2 YauT;rw[Xz1 g m hm] lemma Xz5 (w g:ق) (e:Unit -> پ) (a b:ه) (B:ق):Xz3 w g e a b B=YaPT w e a b B:=by unfold Xz3 YaPT;split · rfl · rename_i h;dsimp only;apply Xz4;split · intro e;apply h;simpa using e · exact h def Ybo (w2 w1 w0:ق) (e:پ) (negZero:ه):ك := YaT w2 w1 w0 e negZero ((ϵ e).toInt==e) (ϵ e).toUInt64 lemma V6 (b d f:ق) (e:پ) (a:ه):Ybo 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,Nat.div_self (ψ 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,Nat.div_self (ψ 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 Yah (A:ل δ) (base n:م) (hA:baseڇ+nڇ<=Aچ) (hs:baseڇ+nڇ<Ξ) (lo hi:ك) (k:م):ك := if h:k>>23 let kh:=v>>>23 Yah 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,UInt32.toNat_shiftLeft,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 Yah 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 ٽ -> δ):ل δ:=Yak c hw f 0 (Array.mkEmpty (c*hw)) lemma I8 (a:ٽ) (f:ٽ -> ٽ -> δ) (b:ٽ):∀ k j (d:ل δ),a-j=k -> (Yaj a f b j d)֍=d֍++(List.range' j (a-j)).map (f b):=by intro k;induction k with | zero=>intro j d h;unfold Yaj;rw[if_neg א];simp[h] | succ k e=> intro j d h;unfold Yaj;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 -> (Yak c a f b d)֍=d֍++(List.range' (b*a) ((c-b)*a)).map (λ i=>f (i/a) (i%a)):=by intro k;induction k with | zero=>intro b d h;unfold Yak;rw[if_neg א];simp[h] | succ k e=> intro b d h;unfold Yak;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,Nat.sub_zero];congr 2 . rw[show List.range' (b*a) a=(List.range' 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 YaJ (w:δ) (m:ق):ق := let v:=Yf w<<<(Yd w-m) if η w then 0-v else v @[inline] def Y4 (w:δ) (m:ق):ك:=(YaJ w m+߿).toUInt32 lemma Xq6 (x:ك):x^^^߿^^^߿=x:=by rw[UInt32.xor_assoc,UInt32.xor_self,UInt32.xor_zero] lemma Zq (k:ك):(Yk k)˟=k؟-1:=by unfold Yk;split_ifs with h . subst h;rfl . rw[ϯ,UInt32.toNat_sub_of_le _ _ (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=Model.zero κ 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):π (Model.fma (ι 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 (Model.ofUInt32 x:Model κ) (Model.ofUInt32 y) (Model.ofUInt32 z)=none := (Model.chooseNaN3_eq_none_iff _ _ _).2 ⟨ٿ e,ٿ f,ٿ g⟩ simp only[Model.Spec.fma,ofW,o,Model.isInf_eq_false_of_toDyadic?_some e,Model.isInf_eq_false_of_toDyadic?_some f,Model.isInf_eq_false_of_toDyadic?_some 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,Nat.testBit_eq_decide_div_mod_eq] 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 ZcE (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[UInt32.toNat_shiftLeft,Ἓ,υ,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 ZcF (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) : π (Model.div (ι 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⟩:=ZcE 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 UInt32.toNat 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 UInt32.toNat 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:ἔ (Model.div (ι 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:ϥ (Model.div (ι 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 ZcG (s:δ) (j:ٽ) (a:j<=6) (b:θ s≠255) (d:j < (θ s)؟) : π (Model.div (ι s) (ι (natW (2^j))))=s-(ϣ j<<<23):=by obtain⟨e,f,g,h⟩:=M2 j a;exact ZcF s _ j a b d e f g h lemma ZcH (s y:δ) (a:θ s=0) (b:fracOf s=0) (d:θ y≠255) (e:η y=false) (f:ε y≠0) : π (Model.div (ι 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) : π (Model.div (ι s) (ι (natW (2^j))))=s:=by obtain⟨e,f,g,-⟩:=M2 j a;exact ZcH 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 Yal (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=ר then (if nz then ߿ 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) : Yal a b c d f e=ρ (sv a*sv b*2^(γ a+γ b)+sv c*sv d*2^(γ c+γ d)) (-298) f:=by unfold Yal;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,UInt32.toUInt32_toUInt64,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 YaY (x y z:δ):δ := if θ x=255\/θ y=255\/θ z=255 then π (Model.fma (ι 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<<π (Model.fma (ι x) (ι y) (ι z))) lemma X1 (x y z:δ):YaY x y z=π (Model.fma (ι x) (ι y) (ι z)):=by unfold YaY;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:π (Model.fma (ι 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 YaA (j:ٽ) (s:δ):δ := if θ s≠255/\j < (θ s).toNat then s-(ϣ j<<<23) else if θ s=0/\fracOf s=0 then s else π (Model.div (ι s) (ι (natW (2^j)))) lemma O8 (j:ٽ) (a:j<=6) (s:δ):YaA j s=π (Model.div (ι s) (ι (natW (2^j)))):=by unfold YaA;split . rename_i h;exact(ZcG 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 YaB (kk:ٽ) (s:δ):δ := if kk=4 then YaA 2 s else if kk=64 then YaA 6 s else π (Model.div (ι s) (ι (natW kk))) lemma O7 (a:ٽ) (s:δ):YaB a s=π (Model.div (ι s) (ι (natW a))):=by unfold YaB;split . rename_i h;subst h;exact O8 2 ב s . split . rename_i h;subst h;exact O8 6 ב s . rfl def YaZ (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) YaB (k*k) (Yn (k*k) (poolAt h w k aC ch y x) (λ _=>ζ)) lemma X0:YaZ=avgpoolSpec:=by funext c h w k a;simp only[YaZ,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 Yam 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<ר then r.toUInt32 else Yam s aC aD b k o cw y x else Yam 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)) : YaC 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 Ya0 (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 (YaC 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:Ya0=conv2dSpec:=by funext s aB a d b;unfold Ya0 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 dwF (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 (YaC 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:dwF=depthwiseSpec:=by funext s aB a d b;unfold dwF 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,Ἇ,Nat.add_assoc,k];exact Q8 _ d h l f g def okF (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)) : okF 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 YbeO (aB:ه) (c hw:ٽ) (x s t:ل δ):ل δ := YT c hw λ ch j=>act aB (YaY x[ch*hw+j]! s[ch]! t[ch]!) lemma E0:YbeO=scaleShiftSpec:=by funext aB c a x s t;simp only[YbeO,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:ق):YaJ w m=if η w then 0-Yf w<<<(Yd w-m) else Yf w<<<(Yd w-m):=rfl lemma H6 (w:δ) (m:ق) (k:ٽ) (a:k<=39) (h:ε w=0\/(m˟<=γ w/\γ w-m˟<=k)) : Ye (YaJ 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:ق):ٽ:=(YaJ w m+0x200000000000000).toNat @[inline] def QSx (v:ق):ق:=v.toUInt32.toInt32.toInt64.toUInt64 @[inline] def QM (a b:ق):ق:=QSx a*QSx b @[inline] def Y9 (a b:ق):ق:=QSx (a&&&0x1FFFFFF)*QSx (b-߿) @[inline] def cq1 (a b:ق):ق:=QSx ((a>>>25)-ר)*QSx (b-߿) @[inline] def Y5t (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 ר else (YaTT 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 Y5g (B0:ق) (bw:ك) (a0 a1:ق):ق := let l:=a1<<<25 let lo:=l+a0 Y5t 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 Xsx (v:ق) (h:-2^31<=Ye v/\Ye v<2^31):QSx v=v:=by apply UInt64.toBitVec_inj.mp have e:(QSx v).toBitVec=BitVec.ofInt 64 v.toUInt32.toBitVec.toInt:=by simp[QSx,BitVec.signExtend] have f:v.toUInt32.toBitVec.toInt=v.toBitVec.toInt:=by have:=v.toNat_lt;unfold Ye at h;push_cast at h;rw[BitVec.toInt_eq_toNat_cond,BitVec.toInt_eq_toNat_cond];simp only[UInt32.toNat_toBitVec,ϧ,UInt64.toNat_toBitVec];split_ifs<;>push_cast<;>omega rw[e,f];exact BitVec.ofInt_toInt lemma XQM (a b:ق) (h:-2^31<=Ye a/\Ye a<2^31) (k:-2^31<=Ye b/\Ye b<2^31):QM a b=a*b:=by unfold QM;rw[Xsx a h,Xsx b k] 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 (cq1 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 Y5w (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 YCn (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,Nat.reducePow,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:=YCz 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 YCn 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,Nat.reducePow,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 Y5g;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 YwV (w:δ) (m:ق):ق:=YaJ w m+0x8000000000000000 @[inline] def YL3 (j:ٽ) (v:ق):ك:=(if j=0 then v&&&0x1FFFFF else if j=1 then (v>>>21)&&&0x1FFFFF else v>>>42).toUInt32 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=YwV x a) (n:b=(Y4 w d)܌) : Ye (QM (YL3 0 v)܌ (b-߿))+(2:پ)^21*Ye (QM (YL3 1 v)܌ (b-߿))+(2:پ)^42*Ye (QM ((YL3 2 v)܌-0x200000) (b-߿))=sv x*sv w*2^(γ x+γ w-(a˟+d˟)) /\ -(2:پ)^51>>21)&&&0x1FFFFF)؛ from rfl,show YL3 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[Nat.reducePow,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[Nat.reducePow,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[XQM _ _ (by rw[A];omega) (by rw[o];omega),XQM _ _ (by rw[B];omega) (by rw[o];omega),XQM _ _ (by rw[C];omega) (by rw[o];omega)] 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 Y53 (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:Int.ModEq (2^128) _ _:=C9 ((0:ق)-(b>>>63)) b ((a>>>43)+(((0:ق)-(a>>>63))<<<21)) (a<<<21);have g:Int.ModEq (2^128) _ _:=Q5 b;have h:Int.ModEq (2^128) _ _:=D4 a;have j:Int.ModEq (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=YwV (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 Y53 K۞ g n (a+e) l 0 0 0 0<ר then (Y53 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)˟) -> Y53 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[Y53,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 YOq {α: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 -> (YOq B C f n۞ a b c k)֍=k֍ ++ (List.range' 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 YOq;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 YOq;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[ϴ,List.map_cons,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 lemma Xz6 {α:Type} (k:ل α) (v x:α) (r:List α) (hk:k.size.toUSizeڇ=k.size) (h:k.size.toUSizeڇ<(k++(v::r).toArray).size): (k++(v::r).toArray).uset k.size.toUSize x h=(k.push x)++r.toArray:=by apply Array.ext' simp only[Array.uset,Array.toList_set,Array.toList_append,Array.toList_push,List.append_assoc,hk] rw[List.set_append_right _ _ (by simp)];simp lemma Xz7 {α:Type} (k:ل α) (x:α) (J:k.size+1<Ξ):k.size.toUSize+1=(k.push x).size.toUSize:=by have hU:Ξ=2^System.Platform.numBits:=rfl have hk:k.size.toUSizeڇ=k.size:=USize.toNat_ofNat_of_lt (by omega) have hk2:(k.size+1).toUSizeڇ=k.size+1:=USize.toNat_ofNat_of_lt J apply ἶ.mp;rw[USize.toNat_add,hk,ϻ,Array.size_push,hk2];exact ν (by rw[←hU];omega) lemma Xz8 (n:م) (j:ٽ) (h:j<=nڇ):(n-j.toUSize).toNat=nڇ-j:=by have:=USize.toNat_lt_size n have e:(j.toUSize).toNat=j:=USize.toNat_ofNat_of_lt (by omega) rw[ἰ _ _ (USize.le_iff_toNat_le.mpr (by rw[e];omega)),e] lemma Uz {α:Type} {a:Array α} {i:USize} (h:i م -> م -> α) (n:م) (a b c i:م) (acc:ل α):ل α := if h:n=0 then acc else let acc:=if hi:i م -> م -> α):∀ (r:List α) (n a b c:م) (k:ل α), r.length=nڇ -> k.size+nڇ<Ξ -> Xz9 B C f n a b c k.size.toUSize (k++r.toArray)=YOq B C f n a b c k:=by intro r;induction r with | nil=> intro n a b c k h _ have:n=0:=ἶ.mp (by simp at h;simp[h]) subst this;unfold Xz9 YOq;simp | cons v r q=> intro n a b c k h J simp only[List.length_cons]at h have hn:n≠0:=λ e=>by subst e;simp at h have hn1:(n-1).toNat=r.length:=by have:=Xz8 n 1 (by omega);simp at this;omega have hk:k.size.toUSizeڇ=k.size:=USize.toNat_ofNat_of_lt (by omega) have hi:k.size.toUSizeڇ<(k++(v::r).toArray).size:=by rw[hk];simp have J':(k.push (f a b c)).size+(n-1).toNat<Ξ:=by simp only[Array.size_push];omega rw[Xz9,YOq,dif_neg hn,dif_neg hn];dsimp only;rw[dif_pos (Uz2 hi (by simp;omega)),Xz6 _ _ _ _ hk,Xz7 _ _ (by omega)] split · exact q _ _ _ _ _ hn1.symm J' · split<;>exact q _ _ _ _ _ hn1.symm J' lemma Xy1 {α:Type} (B C:م) (f:م -> م -> م -> α) (n:م) (d:α): Xz9 B C f n 0 0 0 0 (Υ nڇ d)=YOq B C f n 0 0 0 (Array.mkEmpty nڇ):=by have h:=Xy0 B C f (List.replicate nڇ d) n 0 0 0 (Array.mkEmpty nڇ) (by simp) (by simp;exact n.toNat_lt_size) have h0:(Array.mkEmpty (α:=α) nڇ).size.toUSize=0:=rfl have h1:Array.mkEmpty (α:=α) nڇ++(List.replicate nڇ d).toArray=Υ nڇ d:=by simp rw[h0,h1]at h;exact h @[inline] def YG (bv bw:ك) (xm:ق):ق := if bv>>>16==511 then Yd ζ+Yd bw-xm else Yk (bv>>>16) @[inline] def YgK (w:ه):ٽ:=if w then 4096 else 256 @[inline] def YgA (w:ه):ق:=if w then 39 else 31 @[inline] def YgB (w:ه):ق:=if w then 45 else 31 lemma Q6 (w:ه):(w=false -> YgK w<=256/\(YgB w)˟<=31)/\YgK w<=4096/\(YgA w)˟<=39/\(YgA w)˟<=(YgB w)˟:=by cases w<;>decide @[inline] def Ybg (bv bw bp:ك) (k:ٽ) (xm:ق) (w:ه):ه := let xb:=Yd ζ+Yd bw k>>16) && Yk (bp>>>16)<=Yk (bp&&&0xFFFF)&&Yk (bp&&&0xFFFF)-xm<=YgA w && (if bv>>>16==511 then xm<=xb else Yk (bv>>>16)<=Yk (bv&&&0xFFFF)&&YU bv<=6 && Yk (bp&&&0xFFFF)-xm+YU bv<=YgB w)&&θ bw != 255 && (Yf bw==0||(xm+YG bv bw xm<=xb&&xb-(xm+YG bv bw xm)<80)) @[inline] def Ybh (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 Ybs (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 YbsU (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.usize then aC.uget j (Uz hj) else 0 @[inline] def YVa (w:δ) (m:ق):ٽ:=(YwV w m%0x40000000000).toNat @[inline] def YVb (w:δ) (m:ق):ٽ:=(YwV w m/0x40000000000).toNat lemma ZVw (w:δ) (m:ق):(YVa w m)؝+(YVb w m)؝*0x40000000000=YwV w m:=by unfold YVa YVb;generalize YwV 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 Ybi (s:σ) (aC:ل δ) (xm:ق) (g:δ -> ق -> ٽ):ل ٽ := let pd:=s.padڈ let h:=s.hڈ let w:=s.wڈ Xz9 (Yb s).toUSize (Ya s).toUSize (λ c yy xx=>g (YbsU pd h w aC c yy xx) xm) (s.cin*(Yb s*Ya s)).toUSize 0 0 0 0 (Υ (s.cin*(Yb s*Ya s)).toUSize.toNat 0) 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[USize.toNat_add,USize.toNat_mul,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 _ (Uz t)];rfl . have t':=λ hh=>t (Uz2 hh hz);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 Ybi;dsimp only;rw[Xy1,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 hz).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 Ybz (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 ߿ else 0 @[inline] def Ybj (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<ר then v.toUInt32 else Ybz 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]!)؟]! = YVa (Δ s d y x (l+t)) f/\A[u߷+(g[t]!)؟]! = YVb (Δ 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) : Ybj 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 (Μ (Μ (Μ (Nat.le_of_eq 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 ν (ϊ (Nat.add_le_add_left (Nat.sub_le _ _) _) (ϊ (Ἆ (Μ e1 xm5) (Μ (Nat.le_of_eq hd) (Ἆ (Nat.le_of_eq (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,Μ (Nat.le_of_eq (ν (ϊ (Ἆ (Μ 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 (Nat.le_of_eq sp)) (Yk (Y>>>16))˟;rwa[Nat.sub_add_cancel h'.1,Nat.sub_add_cancel 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 (Nat.add_le_add_left ד _)⟩) intro t X;have h0:=uk X B;have Z:=D _ h0;rw[A7 p _ _ _ (by rw[Zc _ _ (by rw[ox];exact ϛ (Nat.lt_trans 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 (Nat.add_le_add_left ד _)⟩) 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 ϛ (Nat.lt_trans Z.1 Z.2) φ),ox]),A7 A _ _ _ (by rw[Zc _ _ (by rw[ox];exact ϛ (Nat.lt_trans Z.1 Z.2) φ),ox]),e.1,e.2,ZVw] all_goals (intro t X;have h0:=uk X B;have Z:=J _ h0;rw[A7 r _ _ _ (Zc _ _ (ϛ (Nat.lt_trans Z.1 Z.2) φ)),U _ h0,Xq6]) lemma Z4 {a:م} {n:ٽ} (h:aomega);rw[g,f]at u;cases a . simp only[χ,if_false,Λ]at h ⊢;rw[USize.zero_add,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 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ڈ Xz9 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 YW2;split · rfl · rename_i l;have h:k۞߷=k:=Za k e;rw[Xy1,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:=Nat.div_le_self 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[USize.toNat_add,USize.toNat_mul,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] refine congrArg (·^^^߿) ?_ 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 cdQ (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:=Ybh bp BW b let g:=(Array.range C).all (λ o=>Ybg BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0Ybg BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then Ybi s aC xm YV else Ybi s aC xm YVa let PH:=if g then P2 else Ybi s aC xm YVb let W2:ل ك:=YW2 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 א א (by have:=φ;omega),Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א (by have:=φ;omega),Ἠ] 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ڈ Xz9 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 א א,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 0 (Υ (C*(s.ho*s.wo)).toUSize.toNat 0) else if dw then dwF s aB aC aD b else Ya0 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) : cdQ g s f a e b k C h j=(if g then depthwiseSpec else conv2dSpec) s f a e b:=by unfold cdQ;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[Xy1,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:=Nat.div_le_self 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 _ _ (Ybh (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),l,r,u,ZD s _ t w א]) . simp only[Bool.not_eq_false']at v;rw[v,if_pos rfl,B3 s a _ _ p א א (by have:=φ;omega),gO _ (λ i=>YV (YI s a i) _) _ z,E] . simp only[ἠ]at v;rw[v,if_neg ἳ,if_neg ἳ,B3 s a _ _ p א א (by have:=φ;omega),B3 s a _ _ p א א (by have:=φ;omega),gO _ (λ i=>YVa (YI s a i) _) _ z,gO _ (λ i=>YVb (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]! (Ybh (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 Array.ext . 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[Array.size_replicate];omega)];simp only[Array.getElem_replicate] . rw[ذ _ _ (by simp only[Array.size_replicate];omega)];simp only[Array.getElem_replicate] . rw[X0] @[noinline] def YaYs (x y z:δ):δ:=YaY x y z @[inline] def Ysx (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 YaYs x y z else YaYs 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) : Ysx x y z (Yl y) (Yd y) (Yl z) (Yd z+149)=YaY x y z:=by unfold Ysx;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 YaY;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 qCtx0 where bh:ق bl:ق neg:Bool fast:Bool local instance : Inhabited qCtx0:=⟨⟨0,0,false,false⟩⟩ def qCtx1 (B0:ق) (bw:ك):qCtx0:= 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 ר else (YaTT t2 t1 t0 (fun _=>((B0.toNat:Int)-298)) false true (B0-298)).toUInt64 else YL B0 oneW bw ((0:ق)-(hi>>>63)) hi lo 0 (fun v2 v1 v0 c'=>YD v2 v1 v0 c' ((B0.toNat:Int)-298)) lemma qCtx3 (B0:ق) (bw:ك) (hi lo:ق): qCtx2 B0 bw (qCtx1 B0 bw) hi lo=Y5t B0 bw hi lo:=by unfold qCtx2 qCtx1 Y5t rfl @[inline] def qCtx4 (B0:ق) (bw:ك) (c:qCtx0) (a0 a1:ق):ق:= let l:=a1<<<25 let lo:=l+a0 qCtx2 B0 bw c ((a1>>>39)+(((0:ق)-(a1>>>63))<<<25)+((0:ق)-(a0>>>63))+(if loqCtx1 A[j.val]! b[j.val]!)).uget i (by simpa using hi)=qCtx1 (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 qCtx7 (n:م) (fa fb0 fb1:(t:م) -> t ق) (B0 B1:ق) (bw0 bw1:ك) (cb0 cb1:qCtx0) (z0 z1:ق -> δ) (a0 a1 b0 b1:ق) (k:م):ق := if h:ktق) (B C:ق)(bw cw:ك) (cb0 cb1:qCtx0) (hc0:cb0=qCtx1 B bw) (hc1:cb1=qCtx1 C cw)(z0 z1:ق->ك)(a b c d:ق)(k:USize): qCtx7 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[qCtx7] 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+cq1 (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+cq1 (fa k h) (fc k h)) (k+1):=by rw[Y5,dif_pos h] rw[h0,h1] exact qCtx8 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,qCtx5,qCtx5] termination_by n.toNat-k.toNat decreasing_by exact ZI n k ‹kqCtx2 B bw cb (((0:ق)-(a0>>>63))+((a1>>>43)+(((0:ق)-(a1>>>63))<<<21))+(if a0+(a1<<<21)>>22)+(((0:ق)-(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<ר then v.toUInt32 else Ybz s aC aD b k o y x false) (λ v=>if v<ר then v.toUInt32 else Ybz s aC aD b k (o+1) y x false) 0 0 0 0 0 0 0 else qCtx7 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<ר then v.toUInt32 else Ybz s aC aD b k o y x false) (λ v=>if v<ר then v.toUInt32 else Ybz s aC aD b k (o+1) y x false) 0 0 0 0 0 lemma qCtx12 (s:σ) (aC:ل δ) (P2 PH:ل ٽ) (off:ل ك) (aD:ل δ) (W2:ل ك) (b:ل δ) (k:ٽ) (o y x:م) (pb wa waB:م) (B0 B1:ق) (cb0 cb1:qCtx0) (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:qCtx0) (finish0 finish1:ق -> δ) (a0 a1 b0 b1:ق) (k:م):ق := if h:k t ق) (B:ق) (bw:ك) (cb:qCtx0) (hc:cb=qCtx1 B bw) (z0 z1:ق -> δ) (a b c d:ق) (k:م): qCtx13 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[qCtx13] 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+cq1 (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+cq1 (g k h) (w k h)) (k+1):=by rw[Y5,dif_pos h] rw[h0,h1] exact qCtx14 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,qCtx5,qCtx5] 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:qCtx0) (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[USize.le_iff_toNat_le,h2];exact hn)] rw[h2] omega @[specialize] def Xw5 (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 م -> م -> ق) (n:م) (a b c i:م) (acc:ل δ):ل δ := if h:n=0 then acc else let v:=f a b c let acc:=if hi:i>>32).toUInt32 (Uz hi) else acc if c+2 م -> م -> ق):∀ (m:ٽ) (r:List δ) (n a b c:م) (k:ل δ), r.length=m -> r.length=nڇ -> k.size+nڇ<Ξ -> Xy2 B C f n a b c k.size.toUSize (k++r.toArray)=Xw5 B C f n a b c k:=by intro m;induction m using Nat.strong_induction_on with | _ m ih=> intro r n a b c k hm h J rcases r with _|⟨v,r⟩ · have:n=0:=ἶ.mp (by simp at h;simp[h]) subst this;unfold Xy2 Xw5;simp · have hL:r.length+1=nڇ:=by simpa using h have hm':r.length+1=m:=by simpa using hm have hn:n≠0:=λ e=>by subst e;simp at hL have hk:k.size.toUSizeڇ=k.size:=USize.toNat_ofNat_of_lt (by omega) have hi:k.size.toUSizeڇ<(k++(v::r).toArray).size:=by rw[hk];simp rw[Xy2,Xw5,dif_neg hn,dif_neg hn];dsimp only;simp only[dif_pos (Uz2 hi (by simp;omega)),Xz6 _ _ _ _ hk] by_cases h1:n=1 · have h0:r.length=0:=by subst h1;simp only[ϻ]at hL;omega have:r=[]:=List.eq_nil_of_length_eq_zero h0 subst this;rw[dif_pos h1,dif_pos h1];simp · rw[dif_neg h1,dif_neg h1] have hn1':nڇ≠1:=λ e=>h1 (ἶ.mp (by simp[e])) have hn1:(n-1).toNat=r.length:=by have:=Xz8 n 1 (by omega);simp at this;omega have i1:=Xz7 k (f a b c).toUInt32 (by omega) split · rcases r with _|⟨w,rt⟩ · simp at hL;omega · have hL2:rt.length+2=nڇ:=by simp at hL;omega have hk2:(k.push (f a b c).toUInt32).size.toUSizeڇ=(k.push (f a b c).toUInt32).size:=USize.toNat_ofNat_of_lt (by simp;omega) have hi2:(k.size.toUSize+1).toNat<(k.push (f a b c).toUInt32++(w::rt).toArray).size:=by rw[i1,hk2];simp simp only[dif_pos (Uz2 hi2 (by simp;omega))] have E2:=Xz6 (k.push (f a b c).toUInt32) w ((f a b c)>>>32).toUInt32 rt hk2 (by rw[←i1];exact hi2) have i2:=Xz7 (k.push (f a b c).toUInt32) ((f a b c)>>>32).toUInt32 (by simp;omega) have t2:(2:USize).toNat=2:=USize.toNat_ofNat_of_lt_32 (by decide) have hn2:(n-2).toNat=rt.length:=by rw[ἰ _ _ (USize.le_iff_toNat_le.mpr (by rw[t2];omega)),t2];omega have J2:((k.push (f a b c).toUInt32).push ((f a b c)>>>32).toUInt32).size+(n-2).toNat<Ξ:=by simp;omega simp only[i1] at E2 ⊢;rw[E2,i2] split · exact ih rt.length (by omega) rt _ _ _ _ _ rfl hn2.symm J2 · split<;>exact ih rt.length (by omega) rt _ _ _ _ _ rfl hn2.symm J2 · have J1:(k.push (f a b c).toUInt32).size+(n-1).toNat<Ξ:=by simp only[Array.size_push];omega rw[i1] split<;>exact ih r.length (by omega) r _ _ _ _ _ rfl hn1.symm J1 lemma Xy4 (B C:م) (f:م -> م -> م -> ق) (n:م): Xy2 B C f n 0 0 0 0 (Υ nڇ 0)=Xw5 B C f n 0 0 0 (Array.mkEmpty nڇ):=by have h:=Xy3 B C f nڇ (List.replicate nڇ 0) n 0 0 0 (Array.mkEmpty nڇ) (by simp) (by simp) (by simp;exact n.toNat_lt_size) have h0:(Array.mkEmpty (α:=δ) nڇ).size.toUSize=0:=rfl have h1:Array.mkEmpty (α:=δ) nڇ++(List.replicate nڇ 0).toArray=Υ nڇ 0:=by simp rw[h0,h1]at h;exact h @[inline] def Y53FinishP (B0:ق) (bw:ك) (a0 a1 a2:ق):ق := Y5t B0 bw (((0:ق)-(a0>>>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<ר then v.toUInt32 else Ybz s aC aD b k o y x dw) (λ v=>if v<ר then v.toUInt32 else Ybz s aC aD b k o y (x+1) dw) 0 0 0 0 0 0 0 else qCtx13 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<ר then v.toUInt32 else Ybz s aC aD b k o y x dw) (λ v=>if v<ר then v.toUInt32 else Ybz s aC aD b k o y (x+1) dw) 0 0 0 0 0 @[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:=Ybh bp BW b let g:=(Array.range C).all (λ o=>Ybg BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0Ybg BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then Ybi s aC xm YV else Ybi s aC xm YVa let PH:=if g then P2 else Ybi s aC xm YVb let W2:ل ك:=YW2 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 א א (by have:=φ;omega),Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א (by have:=φ;omega),Ἠ] 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 qCtx0:=Ἲ (n:=C) (fun o=>qCtx1 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ڈ Xy2 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 א א,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 א א,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) (qCtx6 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 (Ybj s aC P2 PH off aD W2 b k o y x dw ((if dw then o*hw else 0)+(y*st*wp+x*st)) (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 א א,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 0 (Υ (C*(s.ho*s.wo)).toUSize.toNat 0) else if dw then dwF s aB aC aD b else Ya0 s aB aC aD b lemma packShiftLow (b:ك):(b.toUInt64<<<32).toUInt32=0:=by apply Ἥ.mp have hb:=b.toNat_lt_size simp only[ϧ,Ρ,ϯ] norm_num[υ] at hb ⊢ lemma packShiftBack (b:ك):(b.toUInt64<<<32)>>>32=b.toUInt64:=by apply ἡ.mp have hb:=b.toNat_lt_size simp only[Ζ,Ρ,ϯ] norm_num[υ,ω] at hb ⊢ omega lemma packShiftHighZero (a:ك):a.toUInt64>>>32=0:=by apply ἡ.mp have ha:=a.toNat_lt_size simp only[Ζ,ϯ] norm_num[ω] at ha ⊢ omega lemma packLo (a b:ك): (a.toUInt64 ||| (b.toUInt64<<<32)).toUInt32=a:=by rw[UInt64.toUInt32_or,UInt32.toUInt32_toUInt64,packShiftLow,UInt32.or_zero] lemma packHi (a b:ك): ((a.toUInt64 ||| (b.toUInt64<<<32))>>>32).toUInt32=b:=by rw[UInt64.shiftRight_or,packShiftHighZero,packShiftBack,UInt64.zero_or,UInt32.toUInt32_toUInt64] lemma yoOne (B C:USize) (f:USize->USize->USize->ك) (a b c:USize) (acc:Array ك): YOq B C f 1 a b c acc=acc.push (f a b c):=by rw[YOq,dif_neg (by intro e;have:=congrArg USize.toNat e;simp at this)] dsimp only split_ifs <;> rw[USize.sub_self 1,YOq,dif_pos rfl] lemma uoneone : (1:USize)+1=2:=by apply ἶ.mp rw[USize.toNat_add,ϻ] have h2:(2:USize).toNat=2:=USize.toNat_ofNat_of_lt_32 (by decide) rw[h2] change 2%Ξ=2 exact ν (by have:=φ;omega) lemma sub11 (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 uoneone) lemma yoTwo (B C:USize) (f:USize->USize->USize->ك) (n a b c:USize) (acc:Array ك) (h0:n≠0) (h1:n≠1) (hc:c+1h0 (ἶ.mp (by simpa using e)) have he:=congrArg USize.toNat e rw[ἰ n 1 (by rw[USize.le_iff_toNat_le,ϻ];omega),ϻ,USize.toNat_zero]at he exact h1 (ἶ.mp (by simpa using (show n.toNat=1 by omega))) rw[YOq,dif_neg h0] dsimp only rw[if_pos hc,YOq,dif_neg hn] dsimp only rw[USize.add_assoc,uoneone,sub11] lemma Xw7 (B C:USize) (p:USize->USize->USize->ق) (f:USize->USize->USize->ك) (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 ك) (hc:c pbڇ+(off[t]!).toNat pbBڇ+(off[t]!).toNat waڇ+t>>32).toUInt32 (Uz hj) else out) else out @[specialize] def Xy6 (A B C:م) (f:م -> م -> م -> ق) (n:م) (o y x:م) (out:ل δ):ل δ := if h:n=0 then out else let out:=Xy5 A B C o ((o*B+y)*C+x) (f o y x) out if x+1(Ys s t.val).toUInt32 let bp:=Yc aC aCچ 0 let BW:ل ك:=ډ C λ o=>Yc aD k o.val let xm:=Ybh bp BW b let g:=(Array.range C).all (λ o=>Ybg BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0Ybg BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then Ybi s aC xm YV else Ybi s aC xm YVa let PH:=if g then P2 else Ybi s aC xm YVb let W2:ل ك:=YW2 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 א א (by have:=φ;omega),Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א (by have:=φ;omega),Ἠ] 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 qCtx0:=Ἲ (n:=C) (fun o=>qCtx1 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ڈ Xy6 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 א א,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 (Ybj s aC P2 PH off aD W2 b k o y x dw ((if dw then o*hw else 0)+(y*st*wp+x*st)) (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 א א,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 (Υ (C*(s.ho*s.wo)) 0) else if dw then dwF s aB aC aD b else Ya0 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 cdQ dw s aB aC aD b k C hk hC lemma Xy7 (a:ل δ) (i:م) (v:δ) (h:iڇ(i+B*C).toNat>>32).toUInt32 else if iڇ=k then v.toUInt32 else out[k]!:=by unfold Xy5;dsimp only;simp only[dif_pos (Uz2 hi hz)] split · rename_i ho;have hj':=hj ho;have hj2:(i+B*C)<(out.uset i v.toUInt32 (Uz (Uz2 hi hz))).usize:=Uz2 (by simpa using hj') (by simpa using hz);simp only[dif_pos hj2] refine⟨by simp,?_⟩;rw[Xy7,Xy7];simp only[ho,true_and] · rename_i ho;refine⟨by simp,?_⟩;rw[Xy7];simp only[ho,false_and,if_false] lemma Xy9 (P c q c' q':ٽ) (hq:qUSize->USize->ق)(F:Nat->ك) (hA:Aڇ+4<4294967296)(hB:Bڇ+4<4294967296)(hC:Cڇ+4<4294967296) (g:0 yڇ xڇ (f o y x).toUInt32=F (oڇ*(Bڇ*Cڇ)+yڇ*Cڇ+xڇ)) (hhi:∀o y x:USize,oڇ+1 yڇ xڇ ((f o y x)>>>32).toUInt32=F ((oڇ+1)*(Bڇ*Cڇ)+yڇ*Cڇ+xڇ)): ∀ n (o y x:USize)(out:Array ك),n<4294967296 -> oڇ<=Aڇ+1 -> yڇ xڇ n+(yڇ*Cڇ+xڇ)=((Aڇ-oڇ+1)/2)*(Bڇ*Cڇ) -> out.size=Aڇ*(Bڇ*Cڇ) -> (Xy6 A B C f n.toUSize o y x out).size=out.size ∧ ∀ c q,q c (Xy6 A B C f n.toUSize o y x out)[c*(Bڇ*Cڇ)+q]! = if oڇ<=c∧(oڇ+2<=c∨yڇ*Cڇ+xڇ<=q) then F (c*(Bڇ*Cڇ)+q) else out[c*(Bڇ*Cڇ)+q]!:=by intro n induction n with | zero=> intro o y x out hn ho hy hx fuel hs have hp:=spatial_lt Bڇ Cڇ yڇ xڇ hy hx have hnot:Aڇ<=oڇ:=by by_contra ha have hq:1<=((Aڇ-oڇ+1)/2):=by omega have prod:=Ε (Bڇ*Cڇ) hq simp only[one_mul]at prod omega have zz:(0:Nat).toUSize=(0:USize):=by apply ἶ.mp;rw[Za _ (by decide),USize.toNat_zero] rw[zz,Xy6,dif_pos rfl] refine⟨rfl,λ c q _ hc=>?_⟩ rw[if_neg (by omega)] | succ n ih=> intro o y x out hn ho hy hx fuel hs generalize hP:Bڇ*Cڇ=P at * generalize hp:yڇ*Cڇ+xڇ=p at fuel have hpP:p((o*B+y)*C+x+B*C).toNat=(oڇ+1)*P+p:=by intro h2;have:=Ε P (show oڇ+2<=Aڇ by omega);rw[Zc _ _ (by rw[hI,hBC];have:=φ;nlinarith),hI,hBC];ring rw[Xy6,dif_neg nz];dsimp only;rw[dec] have G:=λ k=>Xy8 A B C o ((o*B+y)*C+x) (f o y x) out k (by rw[hI,hs];exact ϛ (Nat.add_lt_add_left hpP _) oP) (hz:=by rw[hs];exact lt_of_lt_of_le hN φ) (λ h2=>by have h3:oڇ+1cout2[c*P+q]! =if oڇ<=c∧c<=oڇ+1∧q=p then F (c*P+q) else out[c*P+q]!:=by intro c q hq hc;rw[(G _).2] by_cases e1:o+1?_⟩;rw[r2 c q hq hc,key c q hq hc,pp] split_ifs<;>first|rfl|omega · rename_i hx1 have xc:xڇ+1=Cڇ:=by rw[ϋ,xx]at hx1;omega split · rename_i hy1 have hh:yڇ+1?_⟩;rw[r2 c q hq hc,key c q hq hc,pp] split_ifs<;>first|rfl|omega · rename_i hy1 have yb:yڇ+1=Bڇ:=by rw[ϋ,yy]at hy1;omega have pp:p+1=P:=by rw[←hp,←hP,←yb,Ϣ,one_mul];omega have q:((Aڇ-oڇ+1)/2)=((Aڇ-(oڇ+2)+1)/2)+1:=by omega have next:n=((Aڇ-(oڇ+2)+1)/2)*P:=by rw[q,Ϣ,one_mul]at fuel;omega obtain⟨r1,r2⟩:=ih (o+2) 0 0 out2 (by omega) (by omega) (by simpa) (by simpa) (by rw[ox2];simpa using next) (by rw[s2,hs]) refine⟨r1.trans s2,λ c q hq hc=>?_⟩;rw[r2 c q hq hc,key c q hq hc,ox2] simp only[USize.toNat_zero,zero_mul,zero_add] split_ifs<;>first|rfl|omega lemma Xx1 (A B C:Nat) (f:USize→USize→USize→ق) (p:USize→USize→USize→ك) (hA:A+4<4294967296)(hB:B+4<4294967296)(hC:C+4<4294967296) (g:0>>32).toUInt32=p (o+1) y x): Xy6 A.toUSize B.toUSize C.toUSize f (((A+1)/2)*(B*C)).toUSize 0 0 0 (Υ (A*(B*C)) 0)= YOq B.toUSize C.toUSize p (A*(B*C)).toUSize 0 0 0 (Array.mkEmpty (A*(B*C))):=by have a:A.toUSizeڇ=A:=Za _ (by omega) have b:B.toUSizeڇ=B:=Za _ (by omega) have c:C.toUSizeڇ=C:=Za _ (by omega) let F:Nat→ك:=fun q=>p (q/(B*C)).toUSize (q/C%B).toUSize (q%C).toUSize obtain⟨r1,r2⟩:=Xx0 A.toUSize B.toUSize C.toUSize f F (by rwa[a]) (by rwa[b]) (by rwa[c]) (by rwa[b]) (by rwa[c]) (by rwa[a,b,c]) (λ o y x ho hy hx=>by rw[a]at ho;rw[b]at hy;rw[c]at hx;rw[b,c];rw[hlo o y x ho hy hx];obtain⟨h0,h1,h2⟩:=channelCoords B C oڇ yڇ xڇ g d hy hx dsimp only[F];rw[h0,h1,h2];simp only[Nat.toUSize_eq,USize.ofNat_toNat]) (λ o y x ho hy hx=>by rw[a]at ho;rw[b]at hy;rw[c]at hx;rw[b,c];rw[hhi o y x ho hy hx];obtain⟨h0,h1,h2⟩:=channelCoords B C (oڇ+1) yڇ xڇ g d hy hx dsimp only[F];rw[h0,h1,h2] have e:(o+1).toNat=oڇ+1:=by rw[Zc _ _ (by have:=φ;simp only[ϻ];omega),ϻ] rw[←e];simp only[Nat.toUSize_eq,USize.ofNat_toNat]) _ 0 0 0 (Υ (A*(B*C)) 0) ((Ε _ (show (A+1)/2<=A by omega)).trans_lt hn) (by simp) (by rw[b];simpa using g) (by rw[c];simpa using d) (by simp[a,b,c]) (by simp[a,b,c]) rw[E1 _ _ p (by rwa[b]) (by rwa[c]) _ _ hn] rw[a,b,c]at r2 apply Array.ext · rw[r1];simp · intro j h1 h2 have hq:=Χ j (ύ g d) have hc:j/(B*C)P p.1) (by intro j _ hj;exact hp j hj) z hz def Xw3 (off w:Array ك) (wa n i:USize):List (ك×ك):= if h:ip.2!=0):=by rw[Xw1,Xw3] split · generalize hv:(if h:(wa+i).toNatp.2!=0)).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=0 · subst w;simpa[hz] using ih s · simpa[hw] using ih (f s (o,w)) lemma Xu0 {S:Type} (off w:Array ك) (wa n i:USize) (f:S→(ك×ك)→S) (hz:∀ s o,f s (o,0)=s) (s:S): (Xw1 off w wa n i).foldl f s=(Xw3 off w wa n i).foldl f s:=by rw[Xw8];exact filter_fold_zero _ f hz s def Xv2 (f:ك→ق) (s:ق×ق) (p:ك×ك):ق×ق:= (s.1+Y9 (f p.1) (p.2^^^߿).toUInt64,s.2+cq1 (f p.1) (p.2^^^߿).toUInt64) def Xv1 (f:ك→ق) (s:ق×ق×ق) (p:ك×ك):ق×ق×ق:= let x:=f p.1 let w:=(p.2^^^߿).toUInt64-߿ (s.1+QM (YL3 0 x).toUInt64 w,s.2.1+QM (YL3 1 x).toUInt64 w,s.2.2+QM ((YL3 2 x).toUInt64-0x200000) w) lemma chunkStep2_zero (f:ك→ق) (s:ق×ق) (o:ك):Xv2 f s (o,0)=s:=by simp[Xv2,Y9,cq1,show QSx 0=0 from rfl] lemma chunkStep3_zero (f:ك→ق) (s:ق×ق×ق) (o:ك):Xv1 f s (o,0)=s:=by simp[Xv1,QM,show QSx 0=0 from rfl] lemma sparse_chunks2 (off w:Array ك) (wa n i:USize) (f:ك→ق) (s:ق×ق): (Xw1 off w wa n i).foldl (Xv2 f) s=(Xw3 off w wa n i).foldl (Xv2 f) s:= Xu0 off w wa n i _ (chunkStep2_zero f) s lemma sparse_chunks3 (off w:Array ك) (wa n i:USize) (f:ك→ق) (s:ق×ق×ق): (Xw1 off w wa n i).foldl (Xv1 f) s=(Xw3 off w wa n i).foldl (Xv1 f) s:= Xu0 off w wa n i _ (chunkStep3_zero f) s lemma usizeSuccNat (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[List.map_cons,List.zip_cons_cons,ih] lemma Xv5 (off w:Array ك) (wa n:USize) (hn:n.toNat<4294967296): let row:=Xw0 off w wa n 0 #[] #[] Xw3 row.offsets row.values 0 row.values.size.toUSize 0=Xw1 off w wa n 0:=by dsimp only let row:=Xw0 off w wa n 0 #[] #[] change Xw3 row.offsets row.values 0 row.values.size.toUSize 0=_ have hl:=Xv9 off w wa n have hm:row.values.size<4294967296:=by exact hl.2.trans_lt hn rw[denseItems_zip row.offsets row.values row.values.size.toUSize 0 ((Za _ hm).trans hl.1.symm) hl.1.symm] dsimp only[row] rw[(Xw4 off w wa n 0 #[] #[]).1,(Xw4 off w wa n 0 #[] #[]).2] simp only[Array.toList_empty,List.nil_append,USize.toNat_zero,List.drop_zero] exact zip_pair_maps _ lemma maybeUget (a:Array ك) (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<ר then v.toUInt32 else Ybz s aC aD b originalK o y x dw) (λ v=>if v<ר then v.toUInt32 else Ybz s aC aD b originalK o y (x+1) dw) 0 0 0 0 0 0 0 else qCtx13 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<ר then v.toUInt32 else Ybz s aC aD b originalK o y x dw) (λ v=>if v<ר then v.toUInt32 else Ybz s aC aD b originalK o y (x+1) dw) 0 0 0 0 0 lemma qCtx19 (s:ConvShape) (aC:Array Word) (P2 PH:Array Nat) (off:Array ك) (aD:Array Word) (W2:Array ك) (b:Array Word) (k:Nat) (o y x:USize) (dw:Bool) (pb pbB wa:USize) (B0:ق) (cb:qCtx0) (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:ك→ق:=fun q=>(P2[(pbB+q.toUSize).toNat]!).toUInt64 let g0:ك→ق:=fun q=>(P2[(pb+q.toUSize).toNat]!).toUInt64+(PH[(pb+q.toUSize).toNat]!).toUInt64*0x40000000000 let g1:ك→ق:=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 qCtx18 cases wide · rw[if_neg ἳ,qCtx14 (hc:=hc)] simp only[Xw9,Xw6] rw[Y5_compact off W2 wa k.toUSize hn f0 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl), Y5_compact off W2 wa k.toUSize hn f1 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl)] simp only[Ybj,if_false,Xw9,Xw6] rfl · rw[if_pos rfl,qCtx17 (hc:=hc)] simp only[Xw9,Xw6] rw[Y53_compact off W2 wa k.toUSize hn g0 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl), Y53_compact off W2 wa k.toUSize hn g1 _ _ (by intros;rfl) (by intros;rfl) _ _ (by intros;rfl) (by intros;rfl)] simp only[Ybj,if_true,Xw9,Xw6] rfl @[inline] def qCtx20 (s:ConvShape) (aC:Array Word) (P2 PH:Array Nat) (off:Array ك) (aD:Array Word) (W2:Array ك) (b:Array Word) (k:Nat) (o y x:USize) (dw:Bool) (pb pbB wa:USize) (B0:ق) (cb:qCtx0) (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:=Ybh bp BW b let g:=(Array.range C).all (λ o=>Ybg BW[o]! b[o]! bp k xm false) if hg:s.kh<=Yb s/\s.kw<=Ya s/\0Ybg BW[o]! b[o]! bp k xm (!g)) then let P2:=if g then Ybi s aC xm YV else Ybi s aC xm YVa let PH:=if g then P2 else Ybi s aC xm YVb let W2:ل ك:=YW2 aD BW b xm k let rows:=Ἲ (n:=C) (λ o=>Xw0 off W2 (o.val*k).toUSize k.toUSize 0 (Array.mkEmpty k) (Array.mkEmpty k)) have hP2:P2چ=s.cin*(Yb s*Ya s):=by simp only[P2];split<;>rw[B3 s aC xm _ hg.2.2.1 א א (by have:=φ;omega),Ἠ] have hH:PHچ=P2چ:=by simp only[PH];split;rfl;rw[hP2,B3 s aC xm _ hg.2.2.1 א א (by have:=φ;omega),Ἠ] 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 qCtx0:=Ἲ (n:=C) (fun o=>qCtx1 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ڈ Xy2 s.hoڈ s.woڈ (λ o y x => if h:oXw0 off W2 (j*k).toUSize k.toUSize 0 (Array.mkEmpty k) (Array.mkEmpty k)) o.toNat ho simpa only[Array.mkEmpty_eq,hwa] using hr0 let v:=qCtx20 s aC P2 PH off aD W2 b k o y x dw ((if dw then o*hw else 0)+(y*st*wp+x*st)) ((if dw then o*hw else 0)+(y*st*wp+(x+1)*st)) (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 א א,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 א א,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) (qCtx6 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 (Ybj s aC P2 PH off aD W2 b k o y x dw ((if dw then o*hw else 0)+(y*st*wp+x*st)) (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 א א,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 0 (Υ (C*(s.ho*s.wo)).toUSize.toNat 0) else if dw then dwF s aB aC aD b else Ya0 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=cdQ dw s aB aC aD b k C hk hC:=by unfold am cdQ dsimp only simp only[Xy1,Xy4] split · rename_i hg apply Xw7 · 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 poolInt (F:Nat→ك) (m:ق) (i:Nat):Nat→Int | 0=>0 | r+1=> sv (F i)*2^(idxOf (F i)-m.toNat)+poolInt F m (i+1) r def poolNZ (F:Nat→ك) (i:Nat):Nat→Bool | 0=> true | r+1=>(F i==߿) && poolNZ F (i+1) r lemma poolY0 (m:ق) (h:m.toNat<1024):Y0 ((m.toNat:Int)-149) true (m-149):=by intro c d _ b rw[ξ,Φ,show(149:ق).toNat=149 from rfl]at b ⊢ push_cast at b ⊢ omega lemma poolYmYe (a:ق):Ym a=Ye a:=by have:=a.toNat_lt unfold Ym Ye split_ifs <;> omega lemma poolLoop (n:USize) (fa:(t:USize)→t< n→ك) (F:Nat→ك) (m:ق) (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:ق) (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→ Xw2 n fa m a nz i=finishWord (Ye a+poolInt F m i.toNat d) ((m.toNat:Int)-149) (nz && poolNZ F i.toNat d):=by intro d induction d with | zero=> intro i a nz hd hi hlo hhi rw[Xw2,dif_neg (by rw[ϋ];omega),B6,J2 _ _ _ _ _ (poolY0 m hm),poolYmYe] simp[poolInt,poolNZ] | 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+YaJ (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[Xw2,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,poolInt,poolNZ] congr 1 · ring · simp only[Bool.and_assoc] lemma poolZeroWord (w:ك): (w==߿)=(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 poolNZQ (F:Nat→ك) (i r:Nat):poolNZ F i r=Yq F (fun _=> oneW) i r:=by induction r generalizing i with | zero=> rfl | succ r ih=> rw[poolNZ,Yq,poolZeroWord,ih] simp only[show mantOf oneW=2^23 from rfl,show signOf oneW=false from rfl,Bool.xor_false] congr 2 simp lemma poolIntScale (F:Nat→ك) (m:ق) (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=poolInt F m i r*2^(m.toNat+149):=by induction r generalizing i with | zero=> simp[Yo,poolInt] | succ r ih=> rw[Yo,poolInt,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 poolSumEq (n:USize) (fa:(t:USize)→t< n→ك) (F:Nat→ك) (m:ق) (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): Xw2 n fa m 0 true 0=dotOf n.toNat F (fun _=> oneW):=by rw[poolLoop 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[USize.toNat_zero,Ye,ϔ,Nat.zero_div,Nat.cast_zero,mul_zero,sub_self,zero_add,Bool.true_and] rw[poolNZQ,Zy _ _ _ (fun t ht=>⟨hfin t ht,by decide⟩),poolIntScale 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 (poolInt 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,Bool.true_and] convert hs using 1 <;> push_cast <;> ring lemma Xu2 (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 poolIdx2Eq (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[Nat.toUSize,USize.ofNat_add,USize.ofNat_mul,USize.ofNat_toNat] rfl rw[he,Za _ hb] lemma Xv0 {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 pool2IndexBounds (c h w:Nat) (aC:Array ك) (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:=Xu2 c h w 2 ch.toNat y.toNat x.toNat t.toNat (by omega) (Xv0 hc) (Xv0 hy) (Xv0 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[poolIdx2Eq _ _ _ _ _ _ HH] omega lemma Xv7 (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[Nat.toUSize,USize.ofNat_add,USize.ofNat_mul,USize.ofNat_toNat] rw[he,Za _ hb] lemma poolGlobalIndexBounds (c k:Nat) (aC:Array ك) (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:=Xv0 hc have HT:=Xv0 ht have HH:ch.toNat*(k*k)+t.toNat< c*k*k:=by nlinarith rw[Xv7 _ _ _ (by omega)] omega @[inline] def poolSum4 (fa:(t:USize)→t<4→ك) (m:ق):ك := 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) YaPT (((YaJ v0 m+YaJ v1 m)+YaJ v2 m)+YaJ v3 m) (fun _=>(m.toNat:Int)-149) (((v0==߿ && v1==߿) && v2==߿) && v3==߿) true (m-149) lemma poolSum4Eq (fa:(t:USize)→t<4→ك) (m:ق): poolSum4 fa m=Xw2 4 fa m 0 true 0:=by have h2:(1:USize)+1=2:=(USize.ofNat_add 1 1).symm have h3:(2:USize)+1=3:=(USize.ofNat_add 2 1).symm have h4:(3:USize)+1=4:=(USize.ofNat_add 3 1).symm rw[Xw2,dif_pos (by rw[ϋ];norm_num)] dsimp only simp only[USize.zero_add] rw[Xw2,dif_pos (by rw[ϋ];norm_num)] dsimp only rw[h2, Xw2,dif_pos (by rw[ϋ];norm_num)] dsimp only rw[h3,Xw2,dif_pos (by rw[ϋ];norm_num)] dsimp only rw[h4,Xw2,dif_neg (by rw[ϋ];norm_num)] simp only[poolSum4,UInt64.zero_add,Bool.true_and] def ay (c h w k:Nat) (aC:Array ك):Array ك := 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 Xz9 (h/2).toUSize (w/2).toUSize (fun ch y x=> if hout:ch< c.toUSize ∧ y<(h/2).toUSize ∧ x<(w/2).toUSize then YaB 4 (poolSum4 (fun t ht=> aC.uget ((ch*h.toUSize+y*2+t/2)*w.toUSize+x*2+t%2) (pool2IndexBounds 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 0 (Υ (c*(h/2*(w/2))).toUSize.toNat 0) else if hglob:k=h ∧ k=w ∧ 0< k ∧ k*k≤256 then Xz9 1 1 (fun ch _ _=> if hout:ch< c.toUSize then (if k*k=16 then YaA 4 else YaB (k*k)) (Xw2 (k*k).toUSize (fun t ht=> aC.uget (ch*(k*k).toUSize+t) (poolGlobalIndexBounds 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 0 (Υ c.toUSize.toNat 0) else Ybk c h w k aC else Ybk c h w k aC lemma poolSumInput (aC:Array ك) (n:USize) (fa:(t:USize)→t< n→ك) (F:Nat→ك) (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]!): Xw2 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 poolSumEq 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 poolDiv16 (n:Nat) (s:ك): (if n=16 then YaA 4 else YaB 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 poolProvedZero (h w k:Nat) (aC:Array ك):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[Xz9,dif_pos rfl] simp[avgpoolSpec,avgpoolWith] · split · simp only[Ϫ,show (0:Nat).toUSize=(0:USize) from rfl] rw[Xz9,dif_pos rfl] simp[avgpoolSpec,avgpoolWith] · rw[T2] · rw[T2] lemma az (c h w k:Nat) (aC:Array ك):ay c h w k aC=avgpoolSpec c h w k aC:=by by_cases hc0:c=0 · subst c;exact poolProvedZero 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 poolSumInput 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:=Xu2 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[poolIdx2Eq _ _ _ _ _ _ (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 (Xu2 _ _ _ _ _ _ _ _ (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[Xy1,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 Nat.div_self (by omega),Nat.mul_one,Nat.div_one,Nat.mod_one] simp only[show (1:USize).toNat=1 from by norm_num,Nat.mul_one,Nat.div_one,Nat.mod_one] apply Array.ext · simp[Nat.div_self 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),poolDiv16] 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 poolSumInput 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:=Xv0 ht have H2:i*(k*k)+t.toNat254) at HE omega lemma clipRound (d:FloatLib.Numerics.Dyadic) (hs:d.negative=true): (ἒ Fmt d).signBit=true ∧ Model.isNaN (ἒ Fmt d)=false:=by unfold ἒ rw[hs] dsimp only split · exact clipZero · split · exact clipOverflow · split · exact clipSub _ · exact clipNormal _ _ lemma clipFinish (S e:Int) (nz:Bool) (hs:S<0):reluW (finishWord S e nz)=0:=by unfold finishWord rw[if_neg (by omega)] apply clipModel · rw[←Ἤ] exact (clipRound (ofIntDyadic S e) (by simp[ofIntDyadic,hs])).1 · rw[←Ἤ] exact (clipRound (ofIntDyadic S e) (by simp[ofIntDyadic,hs])).2 lemma clipYaPT (s:ق) (e:Int) (nz:Bool) (B:ق) (h:Y0 e true B) (hs:s>>>63!=0): reluW (YaPT s (fun _=>e) nz true B)=0:=by rw[B6,J2 _ _ _ _ _ h] apply clipFinish 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 clipKBound (x y z:ك): (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 YsxAct (aB:Bool) (x y z:ك) (my iy mz iq:ق):ك := 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) let mb:ق:=mp>>>(47:ق) let ga:ق:=dp+mb+(46:ق) let gb:ق:=dq+(23:ق) if aB && ss>>>63 != 0 then 0 else act aB (Xz3 ss (if ga<=gb then gb else ga) (fun _=>(k.toNat:Int)-298) (neg&&signOf z) true (k-298)) else act aB (YaYs x y z) else act aB (YaYs x y z) lemma clipResult (r:Bool) (s k:ق) (nz:Bool) (hk:k.toNat<1024): (if r && s>>>63 != 0 then 0 else act r (YaPT s (fun _=>(k.toNat:Int)-298) nz true (k-298)))= act r (YaPT 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 (clipYaPT s _ nz _ (P4 k hk) hs).symm · rfl lemma clipPoint (r:Bool) (x y z:ك): YsxAct r x y z (Yl y) (Yd y) (Yl z) (Yd z+149)=act r (Ysx 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:=clipKBound x y z have HH:=fun (s:ق) (nz:Bool)=>clipResult r s k nz hk dsimp only[k,p,iq,mp]at HH unfold YsxAct Ysx dsimp only simp only[Xz5] simp only[apply_ite (act r),HH] @[inline] def Xx2 (aB:Bool) (x y z:ك) (my iy mz iq:ق):ك := if ((x>>>23)&&&0xFF)-1<254 && my>>>23 != 0 && mz>>>23 != 0 then let mp:=((x&&&0x7FFFFF).toUInt64+0x800000)*my let p:=((x>>>23)&&&0xFF).toUInt64-1+iy let k:=if p≤ iq then p else iq let dp:=p-k let dq:=iq-k 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) let mb:ق:=mp>>>(47:ق) let ga:ق:=dp+mb+(46:ق) let gb:ق:=dq+(23:ق) if aB && ss>>>63 != 0 then 0 else act aB (Xz3 ss (if ga<=gb then gb else ga) (fun _=>(kڇ:Int)-298) (neg&&signOf z) true (k-298)) else act aB (YaYs x y z) else YsxAct aB x y z my iy mz iq lemma Xx3 (aB:Bool) (x y z:ك) (iy iq:ق):Xx2 aB x y z (Yl y) iy (Yl z) iq=YsxAct aB x y z (Yl y) iy (Yl z) iq:=by unfold Xx2 split · rename_i hc simp only[ϓ,decide_eq_true_eq,bne_iff_ne,ne_eq]at hc obtain⟨⟨h1,h2⟩,h3⟩:=hc have e:expOf x=(x>>>23)&&&0xFF:=rfl have b1:((x>>>23)&&&0xFF).toNat<256:=by rw[ἣ];exact ϊ Nat.and_le_right (by decide) have b2:=Ἦ.mp h1 rw[UInt32.toNat_sub]at b2 simp only[show (254:ك).toNat=254 from rfl,show (1:ك).toNat=1 from rfl,show (2:Nat)^32=4294967296 from rfl]at b2 have hx0:expOf x≠0:=λ h=>by rw[e]at h;rw[h]at b2;simp at b2 have hx5:expOf x≠255:=λ h=>by rw[e]at h;rw[h]at b2;simp at b2 have hYl:Yl x=(x&&&0x7FFFFF).toUInt64+0x800000:=by unfold Yl;rw[if_neg hx0];rfl have hYd:Yd x=((x>>>23)&&&0xFF).toUInt64-1:=by unfold Yd;rw[if_neg hx0];rfl have fx:((x&&&0x7FFFFF)).toNat<2^23:=by rw[ἣ];exact ϊ Nat.and_le_right (by decide) have s23:∀ v:ق,(v>>>23).toNat=vڇ/2^23:=λ v=>by rw[Ζ,ω];rfl have ly0:2^23<=(Yl y).toNat:=by by_contra hh;apply h2;apply ἡ.mp;rw[s23];simp only[ϔ];exact ϑ (by omega) have ly1:(Yl y).toNat<2^24:=by rw[Zs];exact ϖ y have c8:(0x800000:ق).toNat=8388608:=rfl have P:(2:Nat)^64=18446744073709551616:=rfl have a1:((x&&&0x7FFFFF).toUInt64+0x800000).toNat=(x&&&0x7FFFFF).toNat+8388608:=by rw[ξ,ϯ,c8];exact ν (by rw[P];omega) have mp0:((x&&&0x7FFFFF).toUInt64+0x800000)*Yl y≠0:=by intro h;have:=congrArg Ἡ h;rw[ϱ,a1]at this;simp only[ϔ]at this rw[ν (by rw[P];nlinarith)]at this have:0<((x&&&0x7FFFFF).toNat+8388608)*(Yl y).toNat:=ύ (by omega) (by omega) omega have mz0:Yl z≠0:=λ h=>h3 (by rw[h];rfl) unfold YsxAct rw[if_pos (bne_iff_ne.mpr hx5)] simp only[hYl,hYd,beq_iff_eq,mp0,mz0,if_false] have K:∀ p q:ق,(if p≤q then p else q)≤p∧(if p≤q then p else q)≤q:=by intro p q;split<;>rename_i h<;>simp only[Ϯ]at h ⊢<;>omega simp only[if_pos (K _ _).1,if_pos (K _ _).2] · rfl lemma Xx5 (x y z:ك) (hx:expOf x≠255) (hy:expOf y≠255) (hz:expOf z≠255) (hp:Γ (signOf x) (signOf y)=true) (hs:signOf z=true):act true (YaY x y z)=0:=by change reluW (YaY x y z)=0 rw[X1,M3 x y z hx hy hz] have hxy:sv x*sv y=-((mantOf x*mantOf y:ٽ):پ):=by simpa only[hp,ite_true]using (Zn x y).symm have hzv:sv z≤0:=by rw[←E8 z,hs];simp have hxyv:sv x*sv y≤0:=by rw[hxy];omega have H:sv x*sv y*2^(idxOf x+idxOf y)+sv z*2^(idxOf z+149)≤0:= add_nonpos (mul_nonpos_of_nonpos_of_nonneg hxyv (by positivity)) (mul_nonpos_of_nonpos_of_nonneg hzv (by positivity)) by_cases he:sv x*sv y*2^(idxOf x+idxOf y)+sv z*2^(idxOf z+149)=0 · rw[he] simp only[hp,hs,Bool.true_and] decide · apply clipFinish omega @[inline] def Xx6 (aB:Bool) (x y z:ك) (my iy mz iq:ق):ك := if aB && expOf x != 255 && Γ (signOf x) (signOf y) && signOf z then 0 else Xx2 aB x y z my iy mz iq lemma Xx7 (aB:Bool) (x y z:ك) (hy:expOf y≠255) (hz:expOf z≠255): Xx6 aB x y z (Yl y) (Yd y) (Yl z) (Yd z+149)=act aB (YaY x y z):=by unfold Xx6 split · rename_i H have HH:((aB=true ∧ expOf x≠255) ∧ Γ (signOf x) (signOf y)=true) ∧ signOf z=true:=by simpa only[ϓ,bne_iff_ne] using H obtain ⟨⟨⟨ha,hx⟩,hp⟩,hs⟩:=HH subst ha exact (Xx5 x y z hx hy hz hp hs).symm · rw[Xx3,clipPoint,G1 _ _ _ hy hz] @[specialize] def rBnMap (f:δ→δ) (stop j:م) (x:ل δ) (hs:stop.toNat<=x.size):ل δ:= if h:jXx6 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 rBnMap (fun w=>act av (YaY 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) Xv3 av c hw s t hc (ch+1) xx (by dsimp[xx];split <;> rw[(bMp ..).1] <;> exact hx) else x termination_by c-ch lemma bCp (av:ه) (c hw:ٽ) (s t:ل δ) (hc:c*hw<=4294967295) (ch:ٽ) (x:ل δ) (hx:x.size=c*hw): (Xv3 av c hw s t hc ch x hx).size=x.size ∧ ∀ i,iXx6 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:=bCp 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[Xx7 _ _ _ _ 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 (YaY 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:=bCp 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:0v&&&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 ك):Array ك:= 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 ك): 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,Nat.zero_div,Λ,Nat.mul_one,ϫ,Nat.div_one,Nat.mod_one] apply Array.ext · 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,Nat.mod_one] def aw (rows iw ow:Nat) (r:Bool) (x w b:Array ك):Array ك:= if rows=1 then cdQ 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,rBnInplace⟩ norm:=specNorm theorem correct:Obligation kernels:=by simp only[Obligation,kernels,specKernels,specDense,specConv,specElem,ax,aq,ar,au,rBnCorrect] end Submission