P13_T1_NumberHelperAccumulatedValue

Lean checked

Statement

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

Theorem

For every source-valid unsigned numeric byte slice s of length at most A=3458764513820540928 and every normally returned record d from parse_number, put V equal to the full-significand accumulated-exponent magnitude of its complete lexeme. If d.\mathit{many\_digits}=\texttt{false}, then d.\mathit{mantissa}\,10^{d.\mathit{exponent}}=V. Otherwise,
d.\mathit{mantissa}\,10^{d.\mathit{exponent}} \le V < (d.\mathit{mantissa}+1)10^{d.\mathit{exponent}}.
The successor in the upper endpoint is mathematical, not a checked or wrapping machine operation. Source-valid arbitrary-byte slices are SourceValidByteSlice, and the actual call is ActualDispatchOperations. Grammar and magnitudes are DecimalGoalVocabularyDefault: every significand digit is retained, and the signed exponent fold updates a to 10a+d only while the previous a<2^{59}, with overshoot and continued digit scanning. No exponent-digit limit or additional termination claim is imposed.

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.P367_T1_NumberHelperRenderedAccountingA
import Tablet.NumberHelperDecimalPrefixInterval

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P13_T1_NumberHelperAccumulatedValue]
theorem P13_T1_NumberHelperAccumulatedValue :
    forall (s : Slice Std.U8) (x : DecimalLexeme) (d : num.imp.dec2flt.decimal.Decimal),
      SourceValidByteSlice s -> s.val.length <= 3458764513820540928 ->
      x.leadingSign = none -> DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s ->
      P9_T1_ActualDispatchOperations.parseNumber s = ok (some d) ->
      if d.many_digits then
        DecimalGoalVocabularyDefault.decimalMagnitude d <=
          DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
        DecimalGoalVocabularyDefault.accumulatedMagnitude x <
          (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val)
      else DecimalGoalVocabularyDefault.decimalMagnitude d =
        DecimalGoalVocabularyDefault.accumulatedMagnitude x := 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

Fix s,x,d satisfying the statement. Put S equal to the integer digits followed by the optional fractional digits, f equal to the fractional digit count, and E=\texttt{accumulatedExplicitExponent}(x) in DecimalGoalVocabularyDefault. By that definition the asserted target magnitude is V=v(S)10^{E-f}, where v is the natural decimal fold from zero. Its record magnitude is d.\mathit{mantissa}.\mathit{val}\,10^{d.\mathit{exponent}.\mathit{val}}. NumberHelperRenderedAccountingA applies with exactly the A-bound, absent-leading-sign, validity, whole-rendering and successful record premises in the statement. Source validity is retained unchanged.
If d.\mathit{many\_digits}=\texttt{false}, its first clause gives mantissa value v(S) and exponent value E-f. Substitution yields the asserted equality of real magnitudes.
If the field is true, its second clause supplies S=P\mathbin{++}Q, mantissa value v(P), and exponent value E-f+|Q|. Every digit in Q is a member of S; validity says the integer and optional fractional lists contain only digits below ten, so Q does too. Apply NumberHelperDecimalPrefixInterval with prefix P, suffix Q and integer exponent E-f. Its two conclusions are exactly
v(P)10^{E-f+|Q|}\le v(PQ)10^{E-f} <(v(P)+1)10^{E-f+|Q|}.
Substitute the supplied partition and the record field equations to obtain the desired half-open interval. This includes an empty or all-zero discarded suffix: the lower bound may be equality, while the upper bound remains strict. The successor is a natural-number successor before real embedding, not a machine-word addition. Boolean case exhaustion proves the stated conditional, without substituting the unrestricted mathematical exponent for E.

Lean proof


  intro s x d hsource hlen hsign hvalid hrender hparse
  have accounting := P367_T1_NumberHelperRenderedAccountingA s x d
    hlen hsign hvalid hrender hparse
  dsimp only at accounting
  let digits := x.integerDigits ++
    (match x.fractionDigits with | none => [] | some ds => ds)
  let fractionCount : Int := match x.fractionDigits with | none => 0 | some ds => ds.length
  let explicit := DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
  have hdigits : forall b, b ∈ digits -> b < 10 := by
    dsimp only [DecimalGoalVocabularyDefault] at hvalid
    rcases hvalid with ⟨hi, hf, hnonempty, he⟩
    intro b hb
    rcases List.mem_append.mp hb with hb | hb
    · exact hi b hb
    · cases hfrac : x.fractionDigits with
      | none => simp [hfrac] at hb
      | some ds =>
        have hmem : b ∈ ds := by simpa [hfrac] using hb
        have hds : forall b, b ∈ ds -> b < 10 := by simpa [hfrac] using hf
        exact hds b hmem
  cases hmany : d.many_digits with
  | false =>
    simp only [Bool.false_eq_true, if_false]
    obtain ⟨hmantissa, hexponent⟩ := accounting.1 hmany
    dsimp only [DecimalGoalVocabularyDefault]
    rw [hmantissa, hexponent]
    rfl
  | true =>
    simp only [if_true]
    obtain ⟨consumed, remaining, hpartition, hmantissa, hexponent⟩ := accounting.2 hmany
    change digits = consumed ++ remaining at hpartition
    have hremaining : forall b, b ∈ remaining -> b < 10 := by
      intro b hb
      apply hdigits b
      rw [hpartition]
      exact List.mem_append_right _ hb
    have interval := NumberHelperDecimalPrefixInterval consumed remaining hremaining
      (explicit - fractionCount)
    dsimp only at interval
    have hmantissa' : d.mantissa.val =
        consumed.foldl (fun a b => 10 * a + b) 0 := hmantissa
    have hexponent' : d.exponent.val = explicit - fractionCount +
        (remaining.length : Int) := hexponent
    change (d.mantissa.val : Real) * (10 : Real) ^ d.exponent.val <=
        ((digits.foldl (fun a b => 10 * a + b) 0 : Nat) : Real) *
          (10 : Real) ^ (explicit - fractionCount) /\
      ((digits.foldl (fun a b => 10 * a + b) 0 : Nat) : Real) *
          (10 : Real) ^ (explicit - fractionCount) <
        ((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val
    rw [hpartition, hmantissa', hexponent']
    exact interval

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.P367_T1_NumberHelperRenderedAccountingA
import Tablet.NumberHelperDecimalPrefixInterval

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P13_T1_NumberHelperAccumulatedValue]
theorem P13_T1_NumberHelperAccumulatedValue :
    forall (s : Slice Std.U8) (x : DecimalLexeme) (d : num.imp.dec2flt.decimal.Decimal),
      SourceValidByteSlice s -> s.val.length <= 3458764513820540928 ->
      x.leadingSign = none -> DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s ->
      P9_T1_ActualDispatchOperations.parseNumber s = ok (some d) ->
      if d.many_digits then
        DecimalGoalVocabularyDefault.decimalMagnitude d <=
          DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
        DecimalGoalVocabularyDefault.accumulatedMagnitude x <
          (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val)
      else DecimalGoalVocabularyDefault.decimalMagnitude d =
        DecimalGoalVocabularyDefault.accumulatedMagnitude x := by
-- BODY
  intro s x d hsource hlen hsign hvalid hrender hparse
  have accounting := P367_T1_NumberHelperRenderedAccountingA s x d
    hlen hsign hvalid hrender hparse
  dsimp only at accounting
  let digits := x.integerDigits ++
    (match x.fractionDigits with | none => [] | some ds => ds)
  let fractionCount : Int := match x.fractionDigits with | none => 0 | some ds => ds.length
  let explicit := DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
  have hdigits : forall b, b ∈ digits -> b < 10 := by
    dsimp only [DecimalGoalVocabularyDefault] at hvalid
    rcases hvalid with ⟨hi, hf, hnonempty, he⟩
    intro b hb
    rcases List.mem_append.mp hb with hb | hb
    · exact hi b hb
    · cases hfrac : x.fractionDigits with
      | none => simp [hfrac] at hb
      | some ds =>
        have hmem : b ∈ ds := by simpa [hfrac] using hb
        have hds : forall b, b ∈ ds -> b < 10 := by simpa [hfrac] using hf
        exact hds b hmem
  cases hmany : d.many_digits with
  | false =>
    simp only [Bool.false_eq_true, if_false]
    obtain ⟨hmantissa, hexponent⟩ := accounting.1 hmany
    dsimp only [DecimalGoalVocabularyDefault]
    rw [hmantissa, hexponent]
    rfl
  | true =>
    simp only [if_true]
    obtain ⟨consumed, remaining, hpartition, hmantissa, hexponent⟩ := accounting.2 hmany
    change digits = consumed ++ remaining at hpartition
    have hremaining : forall b, b ∈ remaining -> b < 10 := by
      intro b hb
      apply hdigits b
      rw [hpartition]
      exact List.mem_append_right _ hb
    have interval := NumberHelperDecimalPrefixInterval consumed remaining hremaining
      (explicit - fractionCount)
    dsimp only at interval
    have hmantissa' : d.mantissa.val =
        consumed.foldl (fun a b => 10 * a + b) 0 := hmantissa
    have hexponent' : d.exponent.val = explicit - fractionCount +
        (remaining.length : Int) := hexponent
    change (d.mantissa.val : Real) * (10 : Real) ^ d.exponent.val <=
        ((digits.foldl (fun a b => 10 * a + b) 0 : Nat) : Real) *
          (10 : Real) ^ (explicit - fractionCount) /\
      ((digits.foldl (fun a b => 10 * a + b) 0 : Nat) : Real) *
          (10 : Real) ^ (explicit - fractionCount) <
        ((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val
    rw [hpartition, hmantissa', hexponent']
    exact interval

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 175 entries
Technical checking records
Local closure summary
{
  "node": "P13_T1_NumberHelperAccumulatedValue",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "e0ca5e88309e022d90f26988abcfb77063463930ffaaf8ce706dcc107c1019bd",
  "active_statement_hash": "e9a879704fc43575a3bb4e13c35efcb6ae70f2e283b46c5cc7aab83cf6dc2828",
  "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-182",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "NumberHelperDecimalPrefixInterval": "5c32858414034b55",
    "P367_T1_NumberHelperRenderedAccountingA": "3f4df2d4f1c2b7d0"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "895e8e2ceadc7913",
    "DecimalLexeme": "c43614ff2149ecf2",
    "P367_T1_NumberHelperRenderedAccountingA": "55eb6bce0e8a4131",
    "P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
    "P9_T1_DispatchOperations": "9b177bb1b830a655",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2"
  }
}
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:a0f965399dc38bc44d5fdb410932214d973dcb5e5be17bb55e7e5da53b5364fe",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}