import Tablet.DecimalGoalVocabularyDefault import Tablet.F64_Insts_CoreOpsArithDivF64F64 import Tablet.F64_Insts_CoreOpsArithMulF64F64 import Tablet.F64_Insts_CoreOpsArithNegF64 import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64 import Tablet.ModelSliceFirst import Tablet.ModelStrAsBytes import Tablet.ParserNumericSlowPathOverflowWitness import Tablet.num_imp_dec2flt_dec2flt import Tablet.num_imp_dec2flt_dec2flt_with_trace open Aeneas Aeneas.Std Result ControlFlow Error set_option autoImplicit false set_option maxRecDepth 10000 namespace dec2flt_model -- [TABLET NODE: ParserNumericPublicOverflowWitness] theorem ParserNumericPublicOverflowWitness : exists (s : Str) (x : DecimalLexeme), s.val = [48#u8, 46#u8] ++ List.replicate 11 48#u8 ++ [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++ List.replicate 2147483618 48#u8 /\ s.val.length = 2147483650 /\ x = { leadingSign := none integerDigits := [0] fractionDigits := some (List.replicate 11 0 ++ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0] ++ List.replicate 2147483618 0) exponent := none } /\ DecimalGoalVocabularyDefault.sourceString s /\ DecimalGoalVocabularyDefault.validNumeric x /\ DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x /\ num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64 F64.Insts.CoreOpsArithNegF64 s = fail integerOverflow := by -- BODY obtain ⟨body, first, remainder, d, hfirst, hbody, hremainder, hbodyLen, hfirstLen, hremainderLen, hparse, hd, hfast, hcompute0, hcompute1, hne, heq, hcast, hsub, hdecimal, hslow⟩ := ParserNumericSlowPathOverflowWitness let s : Str := body let x : DecimalLexeme := { leadingSign := none integerDigits := [0] fractionDigits := some (List.replicate 11 0 ++ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0] ++ List.replicate 2147483618 0) exponent := none } have hsVal : s.val = [48#u8, 46#u8] ++ List.replicate 11 48#u8 ++ [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++ List.replicate 2147483618 48#u8 := by simp only [s] rw [hbody, hfirst] simp only [List.append_assoc] have hsLen : s.val.length = 2147483650 := by simpa only [s] using hbodyLen have hsource : DecimalGoalVocabularyDefault.sourceString s := by as_aux_lemma => have byteArray_toList_eq_data (b : ByteArray) : b.toList = b.data.toList := by have aux (i : Nat) (r : List UInt8) (hi : i ≤ b.size) : ByteArray.toList.loop b i r = r.reverse ++ b.data.toList.drop i := by fun_induction ByteArray.toList.loop b i r with | case1 i r h ih => rw [ih (by omega)] simp only [List.reverse_cons, List.append_assoc, List.singleton_append] have hlen : i < b.data.toList.length := by simpa using h rw [List.drop_eq_getElem_cons hlen] congr cases b rename_i data exact getElem!_pos data i (by simpa using h) | case2 i r h => have hieq : i = b.size := by omega simp [hieq] unfold ByteArray.toList simpa using aux 0 [] (Nat.zero_le _) have utf8_ofList (l : List Char) : (String.ofList l).toUTF8.toList = l.flatMap String.utf8EncodeChar := by rw [String.toUTF8, String.toByteArray_ofList] rw [byteArray_toList_eq_data] simp only [List.utf8Encode, List.toList_data_toByteArray] have utf8_zeros (n : Nat) : (List.replicate n '0').flatMap String.utf8EncodeChar = List.replicate n (48 : UInt8) := by rw [List.flatMap_replicate] have h : String.utf8EncodeChar '0' = [(48 : UInt8)] := by decide rw [h, List.flatten_replicate_singleton] dsimp only [DecimalGoalVocabularyDefault] constructor · rw [hsLen] norm_num · refine ⟨String.ofList (['0', '.'] ++ List.replicate 11 '0' ++ ['1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '8', '0'] ++ List.replicate 2147483618 '0'), ?_⟩ rw [hsVal, utf8_ofList] simp only [List.flatMap_append, utf8_zeros, List.flatMap_cons, List.flatMap_nil, List.map_append, List.map_replicate, List.map_cons, List.map_nil] have h0 : (String.utf8EncodeChar '0').map UInt8.toNat = [48] := by decide have h1 : (String.utf8EncodeChar '1').map UInt8.toNat = [49] := by decide have h8 : (String.utf8EncodeChar '8').map UInt8.toNat = [56] := by decide have hpoint : (String.utf8EncodeChar '.').map UInt8.toNat = [46] := by decide rw [h0, h1, h8, hpoint] have u48 : (48#u8 : Std.U8).val = 48 := by decide have u46 : (46#u8 : Std.U8).val = 46 := by decide have u49 : (49#u8 : Std.U8).val = 49 := by decide have u56 : (56#u8 : Std.U8).val = 56 := by decide have ui48 : UInt8.toNat (48 : UInt8) = 48 := by decide rw [u48, u46, u49, u56, ui48] simp only [List.singleton_append, List.append_nil, List.append_assoc] have hvalid : DecimalGoalVocabularyDefault.validNumeric x := by as_aux_lemma => dsimp only [DecimalGoalVocabularyDefault] constructor · intro digit hdigit simp only [x] at hdigit simp at hdigit omega constructor · intro digit hdigit rcases List.mem_append.mp hdigit with hdigit | hdigit · rcases List.mem_append.mp hdigit with hdigit | hdigit · have hz : digit = 0 := (List.mem_replicate.mp hdigit).2 omega · simp at hdigit omega · have hz : digit = 0 := (List.mem_replicate.mp hdigit).2 omega constructor · left simp only [x] exact List.cons_ne_nil _ _ · trivial have hrenders : DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x := by as_aux_lemma => rw [show DecimalGoalVocabularyDefault.bytes s = ([48#u8, 46#u8] ++ List.replicate 11 48#u8 ++ [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++ List.replicate 2147483618 48#u8).map (fun b : Std.U8 => b.val) by dsimp only [DecimalGoalVocabularyDefault] rw [hsVal]] rw [List.map_append, List.map_append, List.map_append, List.map_replicate] have hprefix : [48#u8, 46#u8].map (fun b : Std.U8 => b.val) = [48, 46] := by decide have hfixed : [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 56#u8, 48#u8].map (fun b : Std.U8 => b.val) = [49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 56, 48] := by decide have hu48 : (48#u8 : Std.U8).val = 48 := by decide rw [List.map_replicate, hprefix, hfixed, hu48] rw [show DecimalGoalVocabularyDefault.renderNumeric x = [48, 46] ++ List.replicate 11 48 ++ [49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 56, 48] ++ List.replicate 2147483618 48 by simp only [x] dsimp only [DecimalGoalVocabularyDefault] rw [List.map_append, List.map_append, List.map_replicate, List.map_replicate] simp only [List.nil_append, List.cons_append, List.append_nil] norm_num] subst d have hpublic : num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64 F64.Insts.CoreOpsArithNegF64 s = fail integerOverflow := by have hcompact : s.val = 48#u8 :: 46#u8 :: first.val := by simp only [s] rw [hbody] rfl have hadd : (1000000000000000080#u64 + 1#u64) = ok 1000000000000000081#u64 := by rfl simp [s, num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace, core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes, ModelSliceFirst, hcompact, hparse, hfast, hcompute0, hadd, hcompute1, heq, hslow] exact ⟨s, x, hsVal, hsLen, rfl, hsource, hvalid, hrenders, hpublic⟩