import Tablet.DecimalGoalVocabularyDefault import Tablet.Binary64ModelDefault import Tablet.ParserExactRoundingExecution import Tablet.ParserExactRoundingWitness import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64 import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_DISGUISED_FAST_PATH import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path import Tablet.F64_Insts_CoreOpsArithDivF64F64 import Tablet.F64_Insts_CoreOpsArithMulF64F64 import Tablet.F64_Insts_CoreOpsArithNegF64 import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64 import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64 import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS import Tablet.ModelF64FromBits import Tablet.ModelF64FromU64 import Tablet.ModelF64MantissaDigits import Tablet.ModelF64Mul import Tablet.ModelOptionBranch import Tablet.ModelSliceFirst import Tablet.ModelSliceSplitFirst import Tablet.ModelStrAsBytes import Tablet.ModelU64BitAnd import Tablet.ModelU64BitOr import Tablet.ModelU64Shl import Tablet.ModelU8IsAsciiDigit import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64 import Tablet.U64_Insts_CoreOpsBitBitAndU64U64 import Tablet.U64_Insts_CoreOpsBitBitOrU64U64 import Tablet.U64_Insts_CoreOpsBitShlU32U64 import Tablet.num_imp_dec2flt_Lemire_MAX_MANTISSA_FAST_PATH_default import Tablet.num_imp_dec2flt_Lemire_MIN_EXPONENT_FAST_PATH_default import Tablet.num_imp_dec2flt_common_is_8digits import Tablet.num_imp_dec2flt_dec2flt import Tablet.num_imp_dec2flt_dec2flt_with_trace import Tablet.num_imp_dec2flt_decimal_Decimal import Tablet.num_imp_dec2flt_decimal_Decimal_can_use_fast_path import Tablet.num_imp_dec2flt_decimal_INT_POW10 import Tablet.num_imp_dec2flt_fpu_fpu_precision_set_precision import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count import Tablet.num_imp_dec2flt_parse_parse_8digits import Tablet.num_imp_dec2flt_parse_parse_8digits_MASK import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL1 import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL2 import Tablet.num_imp_dec2flt_parse_parse_number import Tablet.num_imp_dec2flt_parse_parse_partial_number import Tablet.num_imp_dec2flt_parse_parse_scientific import Tablet.num_imp_dec2flt_parse_try_parse_digits import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path open Aeneas Aeneas.Std Result ControlFlow Error set_option autoImplicit false set_option maxHeartbeats 0 set_option maxRecDepth 1000000 namespace dec2flt_model -- [TABLET NODE: ParserExactRounding__Refutation] theorem ParserExactRounding__Refutation : ¬ (∀ (s : Str) (x : DecimalLexeme) (f : F64), 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 = ok (core.result.Result.Ok f) -> ∃ magnitude : F64, DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.exactMagnitude x) magnitude ∧ DecimalGoalVocabularyDefault.signedMagnitude (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude f) := by -- BODY let zeros : List Nat := List.replicate 65535 0 let fraction : List Nat := zeros ++ [1] let lexeme : DecimalLexeme := { leadingSign := none integerDigits := [0] fractionDigits := some fraction exponent := some (false, none, [6, 5, 5, 3, 6, 0]) } let witnessBytes : List Std.U8 := [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++ [49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] have witnessBytes_length : witnessBytes.length = 65545 := by simp only [witnessBytes, List.length_append, List.length_replicate, List.length_cons, List.length_nil] let witness : Str := ⟨witnessBytes, by rw [witnessBytes_length] rcases Usize.bounds_eq with q | q <;> norm_num [q, U32.max_eq, U64.max_eq]⟩ let one : F64 := ⟨BitVec.ofNat 64 4607182418800017408⟩ 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 _) let witnessString : String := String.ofList (['0', '.'] ++ List.replicate 65535 '0' ++ ['1', 'e', '6', '5', '5', '3', '6', '0']) 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] have witness_source : DecimalGoalVocabularyDefault.sourceString witness := by dsimp only [DecimalGoalVocabularyDefault] constructor · change witnessBytes.length ≤ 9223372036854775807 rw [witnessBytes_length] norm_num · refine ⟨witnessString, ?_⟩ simp only [witnessString] rw [utf8_ofList] simp only [witness, witnessBytes, 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 hd : (String.utf8EncodeChar '.').map UInt8.toNat = [46] := by decide have h1 : (String.utf8EncodeChar '1').map UInt8.toNat = [49] := by decide have he : (String.utf8EncodeChar 'e').map UInt8.toNat = [101] := by decide have h6 : (String.utf8EncodeChar '6').map UInt8.toNat = [54] := by decide have h5 : (String.utf8EncodeChar '5').map UInt8.toNat = [53] := by decide have h3 : (String.utf8EncodeChar '3').map UInt8.toNat = [51] := by decide rw [h0, hd, h1, he, h6, h5, h3] 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 u101 : (101#u8 : Std.U8).val = 101 := by decide have u54 : (54#u8 : Std.U8).val = 54 := by decide have u53 : (53#u8 : Std.U8).val = 53 := by decide have u51 : (51#u8 : Std.U8).val = 51 := by decide have ui48 : UInt8.toNat (48 : UInt8) = 48 := by decide rw [u48, u46, u49, u101, u54, u53, u51, ui48] rfl have zeros_fold : zeros.foldl (fun a d => 10 * a + d) 0 = 0 := by have fold_zeros (k : Nat) : (List.replicate k 0).foldl (fun a d => 10 * a + d) 0 = 0 := by induction k with | zero => rfl | succ k ih => simpa [List.replicate_succ] using ih exact fold_zeros 65535 have fraction_length : fraction.length = 65536 := by simp only [fraction, zeros, List.length_append, List.length_replicate, List.length_cons, List.length_nil] have significand_fold : ([0] ++ fraction).foldl (fun a d => 10 * a + d) 0 = 1 := by rw [List.foldl_append] simp only [List.foldl_cons, List.foldl_nil, mul_zero, zero_add] simp only [fraction] rw [List.foldl_append, zeros_fold] rfl have lexeme_valid : DecimalGoalVocabularyDefault.validNumeric lexeme := by have zeros_mem {d : Nat} (h : d ∈ zeros) : d = 0 := by simp only [zeros, List.mem_replicate] at h exact h.2 dsimp only [DecimalGoalVocabularyDefault] constructor · simp [lexeme] constructor · simp only [lexeme] intro d hd simp only [fraction] at hd rcases List.mem_append.mp hd with hd | hd · rw [zeros_mem hd] norm_num · simp only [List.mem_singleton] at hd omega constructor · left simp [lexeme] · simp [lexeme] have lexeme_render : DecimalGoalVocabularyDefault.bytes witness = DecimalGoalVocabularyDefault.renderNumeric lexeme := by dsimp only [DecimalGoalVocabularyDefault] simp only [lexeme, witness, witnessBytes, fraction, zeros, List.map_append, List.map_cons, List.map_nil, List.map_replicate, Bool.false_eq_true, reduceIte, Nat.reduceAdd, List.nil_append, List.cons_append] norm_num have lexeme_exact : DecimalGoalVocabularyDefault.exactMagnitude lexeme = (10 : Real) ^ (589824 : Nat) := by dsimp only [DecimalGoalVocabularyDefault, lexeme] rw [significand_fold, fraction_length] norm_num rfl let infinityBits : Nat := 2047 * 2 ^ 52 have huge_target_is_infinity (w : F64) (hw : DecimalGoalVocabularyDefault.roundsMagnitude ((10 : Real) ^ (589824 : Nat)) w) : w.val = infinityBits := by dsimp only [DecimalGoalVocabularyDefault] at hw rcases hw with ⟨_, _, hw⟩ by_contra hne have hne' : w.val ≠ 2047 * 2 ^ 52 := by simpa [infinityBits] using hne rw [if_neg hne'] at hw have hthreshold : ((2 : Real) ^ (1024 : Nat)) - ((2 : Real) ^ (970 : Nat)) ≤ (10 : Real) ^ (589824 : Nat) := by calc (2 : Real) ^ 1024 - 2 ^ 970 ≤ 2 ^ 1024 := sub_le_self _ (by positivity) _ ≤ 10 ^ 1024 := by gcongr <;> norm_num _ ≤ 10 ^ 589824 := by rw [show (589824 : Nat) = 1024 + 588800 by norm_num, pow_add] exact le_mul_of_one_le_right (by positivity) (one_le_pow₀ (by norm_num)) exact (not_lt_of_ge hthreshold) hw.1 have hRun : num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64 F64.Insts.CoreOpsArithNegF64 witness = ok (core.result.Result.Ok one) := by exact ParserExactRoundingExecution witness (by rfl) intro hPositive rcases hPositive witness lexeme one witness_source lexeme_valid lexeme_render hRun with ⟨magnitude, hround, hsigned⟩ rw [lexeme_exact] at hround have hinf := huge_target_is_infinity magnitude hround dsimp only [DecimalGoalVocabularyDefault, lexeme, one] at hsigned rw [hinf] at hsigned have bad := hsigned.2 change (4607182418800017408 : Nat) = infinityBits + 0 at bad have harithmetic : False := by norm_num [infinityBits] at bad obtain ⟨s, x, f, _, _, _, hsource, hvalid, hrender, hrun, hfalse⟩ := ParserExactRoundingWitness exact hfalse (hPositive s x f hsource hvalid hrender hrun)