import Tablet.DecimalGoalVocabularyDefault import Tablet.P9_T1_ActualDispatchOperations import Tablet.P13_T1_NumberHelperRejection import Tablet.SpecialHelperRejection import Tablet.ModelSliceFirst import Tablet.ModelStrAsBytes import Tablet.num_imp_dec2flt_dec2flt open Aeneas Aeneas.Std Result ControlFlow Error set_option autoImplicit false namespace dec2flt_model -- [TABLET NODE: P13_T1_ParserInvalidRejection] theorem P13_T1_ParserInvalidRejection : forall s : Str, DecimalGoalVocabularyDefault.sourceString s -> s.val.length <= 3458764513820540928 -> DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s) none -> exists error : num.float_parse.ParseFloatError, num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64 F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Err error) := by -- BODY intro s hsource hlen hclass change (¬ ∃ x : DecimalLexeme, DecimalGoalVocabularyDefault.validNumeric x ∧ DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s) ∧ (¬ ∃ sign nan, DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) sign nan) at hclass rcases hclass with ⟨hnum, hspecial⟩ have rejectBody (body : Slice Std.U8) (sign : Option Bool) (hvalid : SourceValidByteSlice body) (hne : body.val ≠ []) (hbodylen : body.val.length ≤ 3458764513820540928) (hbytes : DecimalGoalVocabularyDefault.bytes s = (match sign with | none => [] | some neg => [if neg then 45 else 43]) ++ DecimalGoalVocabularyDefault.bytes body) : num.imp.dec2flt.parse.parse_number body = ok none ∧ ∀ negative : Bool, num.imp.dec2flt.parse.parse_inf_nan F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 body negative = ok none := by have noNumeric : ¬ ∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧ DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body := by rintro ⟨x, hxsign, hxvalid, hxrender⟩ apply hnum let y : DecimalLexeme := { x with leadingSign := sign } refine ⟨y, ?_, ?_⟩ · simpa [DecimalGoalVocabularyDefault, y] using hxvalid · dsimp [DecimalGoalVocabularyDefault] at hbytes hxrender ⊢ cases sign <;> simpa [y, hxsign, List.append_assoc, ← hxrender] using hbytes.symm have noSpecial (nan : Bool) : ¬ DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes body) none nan := by intro hbody apply hspecial refine ⟨sign, nan, ?_⟩ dsimp [DecimalGoalVocabularyDefault] at hbody ⊢ rcases hbody with ⟨word, hword, hcase⟩ refine ⟨word, ?_, hcase⟩ dsimp [DecimalGoalVocabularyDefault] at hbytes simpa [hword] using hbytes constructor · exact P13_T1_NumberHelperRejection body hvalid hne hbodylen noNumeric · intro negative exact SpecialHelperRejection body negative hvalid (noSpecial false) (noSpecial true) rcases s with ⟨xs, hbound⟩ cases xs with | nil => refine ⟨{ kind := num.float_parse.FloatErrorKind.Empty }, ?_⟩ simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace, core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes, ModelSliceFirst, num.imp.dec2flt.pfe_empty] | cons a tail => have tailBound : tail.length ≤ Usize.max := by simp only [List.length_cons] at hbound omega let body : Slice Std.U8 := ⟨tail, tailBound⟩ have bodyValid : SourceValidByteSlice body := by have hslen : (a :: tail).length ≤ 9223372036854775807 := hsource.1 simp [SourceValidByteSlice, body] simp only [List.length_cons] at hslen omega have bodyLength : body.val.length ≤ 3458764513820540928 := by simp only [List.length_cons] at hlen change tail.length ≤ 3458764513820540928 omega by_cases hminus : a = 45#u8 · subst a by_cases htail : tail = [] · subst tail refine ⟨{ kind := num.float_parse.FloatErrorKind.Invalid }, ?_⟩ simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace, core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes, ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop, num.imp.dec2flt.pfe_invalid] · obtain ⟨numberResult, specialResult⟩ := rejectBody body (some true) bodyValid htail bodyLength (by simp [DecimalGoalVocabularyDefault, body]) refine ⟨{ kind := num.float_parse.FloatErrorKind.Invalid }, ?_⟩ simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace, core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes, ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop, body, htail, numberResult, specialResult, num.imp.dec2flt.pfe_invalid] · by_cases hplus : a = 43#u8 · subst a by_cases htail : tail = [] · subst tail refine ⟨{ kind := num.float_parse.FloatErrorKind.Invalid }, ?_⟩ simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace, core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes, ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop, num.imp.dec2flt.pfe_invalid] · obtain ⟨numberResult, specialResult⟩ := rejectBody body (some false) bodyValid htail bodyLength (by simp [DecimalGoalVocabularyDefault, body]) refine ⟨{ kind := num.float_parse.FloatErrorKind.Invalid }, ?_⟩ simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace, core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes, ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop, body, htail, numberResult, specialResult, num.imp.dec2flt.pfe_invalid] · let whole : Slice Std.U8 := ⟨a :: tail, hbound⟩ obtain ⟨numberResult, specialResult⟩ := rejectBody whole none hsource.1 (by simp [whole]) hlen (by simp [whole]) refine ⟨{ kind := num.float_parse.FloatErrorKind.Invalid }, ?_⟩ simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace, core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes, ModelSliceFirst, whole, numberResult, specialResult, num.imp.dec2flt.pfe_invalid, hminus, hplus] end dec2flt_model