P13_T1_SlowAccumulatedRounding

Lean checked

Statement

This explanation was written alongside the formalization to describe the statement and its reasoning.

Theorem

For every source-valid byte slice s spelling a complete unsigned numeric literal x, any normal result p of the specialized parse_long_mantissa has an unrestricted assembled word that is the nonnegative nearest-even binary64 rounding of x's accumulated-exponent value. This retains every significand digit and uses the signed explicit exponent fold that updates a to 10a+d while the previous a<2^{59}, allows overshoot, and continues scanning digits after updates stop. There is no A or B bound and no dispatcher-reachability premise. Source validity is SourceValidByteSlice, not a UTF-8 restriction; the actual slow call is ActualDispatchOperations. Values, binary64 rounding (including subnormals, zero and infinity), and assembly for all pair fields are DecimalGoalVocabularyDefault. This on-normal assertion does not require unrestricted helper termination.

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

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
Proof

Natural-language proof

The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.

Explanatory prose status

Prose retained as authored. The explanatory prose is preserved as it stood when captured.

Proof

Apply SlowInitialCertificate with the given source validity, unsignedness, complete numeric validity, rendering equality and normal slow return. Its first alternative is exactly the required assembled-word and full accumulated-value rounding conclusion, covering zero and the initial extreme-point exits.
In its regular alternative, put X=\operatorname{accumulatedMagnitude}(x). It gives an actual normal decimal parse to d, positive count n\le768, point -324\le p<310, decimal cells throughout the array, a first cell with value h\in[1,9], and
X=V(d)+\eta,\qquad 0\le\eta<10^{p-768},\qquad d.\mathit{truncated}\iff\eta>0 .
The array length is 768. Thus the retained list, formed by taking n cells and mapping their values, has length exactly n. Since n>0 it is nonempty, its first entry is the supplied h, and it has positive exact-length decimal shape. The all-array digit bound restricts to the retained prefix. No terminal-trim claim about this initial capped prefix is needed.
Set Y=V(d)+10^{p-768}. All hypotheses of RegularSlowExecution are now established: the actual parse equation, regular point range, count, decimal positive shape, original adjacent endpoint and exact sticky error witnesses. That principal independently constructs a normal actual slow result fp' and an assembled magnitude that nearest-even rounds this X, using its explicit raw-word certificate. Both the constructed result and the theorem's given result are normal returns of the SAME deterministic modeled call on s. The equations \mathsf{slow}(s)=\operatorname{ok}(fp') and \mathsf{slow}(s)=\operatorname{ok}(fp) therefore imply fp'=fp by injectivity of the normal-result constructor. Substitute this equality into the constructed assembled-word and rounding conclusion. It is precisely the theorem's assertion.
The supporting principal constructs the actual normalization, checked decrement, subnormal adjustment and encoding, keeps this original Y, and separately proves the first-round and carry-reround separations. The final conclusion concerns the accumulated-exponent value supplied by the initial certificate, with every significand digit retained in X. No A/B restriction, public reachability or enclosing-success premise has been added to any operational construction or to this goal.

Lean proof


  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

Download Lean source · Download TeX source

Complete Lean module
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

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (198)
More program dependencies (156)
Standard-library dependencies (39)

Related source and models come from the extraction records and declared dependencies.

Proof assumptions and review

Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.

Transitive assumptions

This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.

Helper theorems included
All 247 entries
Technical checking records
Local closure summary
{
  "node": "P13_T1_SlowAccumulatedRounding",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "170dbd3a9f51a904632d2f5864606f4f9f3bc8af01293fb1b181efbb4f01e1ad",
  "active_statement_hash": "485cba7dafb1514541ade0e343c6b0ae7ed2f82d3731257891f58127ddb1371c",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-200",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P495_T1_SlowInitialCertificate": "bed4b47febe2e909",
    "P529_T1_RegularSlowExecution": "401420802ff70ad0"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
    "P9_T1_DispatchOperations": "9a657a317bca572b",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "13e3cec939d02f51",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "f7442f2664cfd5f2"
  }
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:6820c30a3e73220d91f39c09d2c1f50cb2222f5195f7b7653c6cbbe1db648665",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}