import Tablet.DecimalGoalVocabularyDefault import Tablet.SourceValidByteSlice import Tablet.P9_T1_ActualDispatchOperations import Tablet.P495_T1_SlowInitialCertificate import Tablet.P495_T1_SlowLoop0Execution import Tablet.P529_T1_RegularSlowExecution import Tablet.P472_T1_LexemeSignificantMagnitude import Tablet.P472_T1_InitialPointCutoffRounding import Tablet.P472_T1_RetainedRegularPoint import Tablet.P472_T1_LoopZeroRightShiftTransport import Tablet.P472_T1_DecimalSeqDyadicShiftSemantics import Tablet.P9_T1_ScientificVocabularyFold import Tablet.P9_T1_FinalPointExact import Tablet.P401_T1_ZeroRounding import Tablet.P798_T1_LeftBoundaryTransport import Tablet.P856_T1_CoefficientGridAlignment import Tablet.Binary64NearestEvenAssembly import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq import Tablet.num_imp_dec2flt_slow_parse_long_mantissa open Aeneas Aeneas.Std Result ControlFlow Error set_option autoImplicit false namespace dec2flt_model -- [TABLET NODE: P13_T1_SlowAccumulatedRounding] theorem P13_T1_SlowAccumulatedRounding : forall (s : Slice Std.U8) (x : DecimalLexeme) (fp : num.imp.dec2flt.common.BiasedFp), SourceValidByteSlice s -> x.leadingSign = none -> DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s -> P9_T1_ActualDispatchOperations.slow s = ok fp -> exists magnitude : F64, DecimalGoalVocabularyDefault.assembledWord fp magnitude ∧ DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.accumulatedMagnitude x) magnitude := by -- BODY intro s x fp hsource hsign hvalid hbytes hslow rcases P495_T1_SlowInitialCertificate s x fp hsource hsign hvalid hbytes hslow with hdone | ⟨d, eta, head, hparse, hnum, hcap, hpLo, hpHi, hall, hhead, hlo, hhi, hX, heta0, hetaCut, hsticky⟩ · exact hdone · let digits := (d.digits.val.take d.num_digits.val).map (fun b => b.val) have harray : d.digits.val.length = 768 := by simpa using d.digits.property have hlen : digits.length = d.num_digits.val := by simp only [digits, List.length_map, List.length_take, harray] exact Nat.min_eq_left hcap have hnonempty : digits ≠ [] := by intro hnil rw [hnil] at hlen simp only [List.length_nil] at hlen omega obtain ⟨z, tail, hshape⟩ := List.exists_cons_of_ne_nil hnonempty have hfirst : digits.head? = some head := by rw [List.head?_eq_getElem?] simp only [digits, List.getElem?_map, List.getElem?_take, if_pos hnum] exact hhead have hz : z = head := by rw [hshape] at hfirst simpa using hfirst have hinput : d.num_digits.val <= 768 ∧ (forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) ∧ (exists h tail, (d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail ∧ 1 <= h ∧ h < 10 ∧ (h :: tail).length = d.num_digits.val) := by refine ⟨hcap, ?_, z, tail, hshape, ?_, ?_, ?_⟩ · intro b hb exact hall b ((List.take_sublist _ _).mem hb) · simpa [hz] using hlo · simpa [hz] using hhi · rw [← hshape] exact hlen let X := DecimalGoalVocabularyDefault.accumulatedMagnitude x let Y := ((((d.digits.val.take d.num_digits.val).map (fun b => b.val)).foldl (fun n z => 10 * n + z) 0 : Nat) : Real) * (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) + (10 : Real) ^ (d.decimal_point.val - 768) obtain ⟨fp', hcall, _, hrounds⟩ := P529_T1_RegularSlowExecution s X Y d hparse hpLo hpHi hinput rfl ⟨eta, hX, heta0, hetaCut, hsticky⟩ have hfp : fp' = fp := Result.ok.inj (hcall.symm.trans hslow) subst fp' exact hrounds end dec2flt_model