P472_T1_RetainedRegularPoint

Lean checked

Statement

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

Lemma · Regular-point retained value from logical scan counts

Let x be a valid unsigned numeric lexeme and d a decimal sequence. Let Usize counts n,f be bounded by M=9223372036854775807 with n\ne0, and let e be an I64 exponent. Suppose the actual finalizer on n,f,e returns d.\mathit{decimal\_point}, whose value lies in [-324,310). Write S for all significand digits, C for S with leading zeros removed, and T for C with trailing zeros removed. Require n=|C|, f= the original fractional digit count, and e=\operatorname{accumulatedExplicitExponent}(x). Require also the lexical storage equations
r:=d.\mathit{num\_digits}=\min(|T|,768),\quad \operatorname{values}(d.\mathit{digits}[0:r])=T[0:r],\quad d.\mathit{truncated}=\mathrm{true}\ \Longleftrightarrow\ 768<|T|.
Then r\le768, all retained cells are decimal digits, and, writing I for their natural base-ten fold, there exists real \eta with
\operatorname{accumulatedMagnitude}(x) =I10^{d.\mathit{decimal\_point}-r}+\eta,\qquad 0\le\eta<10^{d.\mathit{decimal\_point}-768},\qquad d.\mathit{truncated}=\mathrm{true}\ \Longleftrightarrow\ 0<\eta.
In particular the saved count n precedes both terminal-zero trimming and storage capping; it is not the retained count r.

Lean statement

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

import Tablet.P472_T1_FinalPointRegimes
import Tablet.DecimalSeqRetainedValue

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P472_T1_RetainedRegularPoint]
theorem P472_T1_RetainedRegularPoint
    (x : DecimalLexeme) (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (n f : Std.Usize) (e : Std.I64)
    (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hn : n.val <= 9223372036854775807)
    (hf : f.val <= 9223372036854775807)
    (hnz : n.val ≠ 0)
    (hcall : num.imp.dec2flt.decimal_seq.final_decimal_point n f e =
      ok d.decimal_point)
    (hlo : -324 <= d.decimal_point.val)
    (hhi : d.decimal_point.val < 310) :
    let S := x.integerDigits ++
      match x.fractionDigits with | none => [] | some ds => ds
    let C := S.dropWhile (fun digit => digit == 0)
    let T := (C.reverse.dropWhile (fun digit => digit == 0)).reverse
    n.val = C.length ->
    f.val = (match x.fractionDigits with | none => 0 | some ds => ds.length) ->
    e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x ->
    d.num_digits.val = min T.length 768 ->
    (d.digits.val.take d.num_digits.val).map (fun z => z.val) =
      T.take d.num_digits.val ->
    (d.truncated = true <-> 768 < T.length) ->
    d.num_digits.val <= 768 /\
    (forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
    let I : Nat := ((d.digits.val.take d.num_digits.val).map (fun z => z.val)).foldl
      (fun a digit => 10 * a + digit) 0
    exists eta : Real,
      DecimalGoalVocabularyDefault.accumulatedMagnitude x =
        (I : Real) * (10 : Real) ^
          (d.decimal_point.val - (d.num_digits.val : Int)) + eta /\
      0 <= eta /\ eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
      (d.truncated = true <-> 0 < eta) := 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 FinalPointRegimes to the actual finalizer equation and the two saved-count bounds. Because n\ne0 and the returned point is in [-324,310), its regular-point clause gives exactly d.\mathit{decimal\_point}=n-f+e, with no clipping left in this equation.
Let a be the integer digit count and z=|S|-|C| the leading zero count. Deleting a prefix cannot increase length, so |C|\le|S| and |C|=|S|-z. Since |S|=a+f, all of these are ordinary natural-length identities and n-f=|C|-f=a-z after passing to integers. Substituting the required count and exponent equations therefore gives
d.\mathit{decimal\_point} =a-z+\operatorname{accumulatedExplicitExponent}(x).
This is precisely the exact point hypothesis of DecimalSeqRetainedValue. Its other hypotheses are the unsigned validity and the three lexical storage equations stated here. Applying that theorem supplies the retained-count bound, digit bounds, value equation, strict error bound, and exact sticky equivalence, with the same real error \eta. Nothing has identified a clipped point with its unclipped input, or replaced a saved logical count by a stored count.

Lean proof


  dsimp only
  intro hnCount hfCount he hnum hstored htruncated
  have hp := (P472_T1_FinalPointRegimes n f e d.decimal_point hn hf hcall).2 hnz
  dsimp only at hp
  have hpoint := hp.1 hlo hhi
  rw [hnCount, hfCount, he] at hpoint
  have hlength :
      (x.integerDigits ++
        match x.fractionDigits with | none => [] | some ds => ds).length =
      x.integerDigits.length +
        (match x.fractionDigits with | none => 0 | some ds => ds.length) := by
    cases x.fractionDigits <;> simp
  have hdrop := List.length_dropWhile_le
    (l := x.integerDigits ++
      match x.fractionDigits with | none => [] | some ds => ds)
    (p := fun digit => digit == 0)
  have hpoint' : d.decimal_point.val =
      (x.integerDigits.length : Int) -
        (((x.integerDigits ++
          match x.fractionDigits with | none => [] | some ds => ds).length -
          ((x.integerDigits ++
            match x.fractionDigits with | none => [] | some ds => ds).dropWhile
              (fun digit => digit == 0)).length : Nat) : Int) +
        DecimalGoalVocabularyDefault.accumulatedExplicitExponent x := by
    omega
  exact DecimalSeqRetainedValue x d hsign hvalid hnum hstored htruncated hpoint'

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P472_T1_FinalPointRegimes
import Tablet.DecimalSeqRetainedValue

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P472_T1_RetainedRegularPoint]
theorem P472_T1_RetainedRegularPoint
    (x : DecimalLexeme) (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (n f : Std.Usize) (e : Std.I64)
    (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hn : n.val <= 9223372036854775807)
    (hf : f.val <= 9223372036854775807)
    (hnz : n.val ≠ 0)
    (hcall : num.imp.dec2flt.decimal_seq.final_decimal_point n f e =
      ok d.decimal_point)
    (hlo : -324 <= d.decimal_point.val)
    (hhi : d.decimal_point.val < 310) :
    let S := x.integerDigits ++
      match x.fractionDigits with | none => [] | some ds => ds
    let C := S.dropWhile (fun digit => digit == 0)
    let T := (C.reverse.dropWhile (fun digit => digit == 0)).reverse
    n.val = C.length ->
    f.val = (match x.fractionDigits with | none => 0 | some ds => ds.length) ->
    e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x ->
    d.num_digits.val = min T.length 768 ->
    (d.digits.val.take d.num_digits.val).map (fun z => z.val) =
      T.take d.num_digits.val ->
    (d.truncated = true <-> 768 < T.length) ->
    d.num_digits.val <= 768 /\
    (forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
    let I : Nat := ((d.digits.val.take d.num_digits.val).map (fun z => z.val)).foldl
      (fun a digit => 10 * a + digit) 0
    exists eta : Real,
      DecimalGoalVocabularyDefault.accumulatedMagnitude x =
        (I : Real) * (10 : Real) ^
          (d.decimal_point.val - (d.num_digits.val : Int)) + eta /\
      0 <= eta /\ eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
      (d.truncated = true <-> 0 < eta) := by
-- BODY
  dsimp only
  intro hnCount hfCount he hnum hstored htruncated
  have hp := (P472_T1_FinalPointRegimes n f e d.decimal_point hn hf hcall).2 hnz
  dsimp only at hp
  have hpoint := hp.1 hlo hhi
  rw [hnCount, hfCount, he] at hpoint
  have hlength :
      (x.integerDigits ++
        match x.fractionDigits with | none => [] | some ds => ds).length =
      x.integerDigits.length +
        (match x.fractionDigits with | none => 0 | some ds => ds.length) := by
    cases x.fractionDigits <;> simp
  have hdrop := List.length_dropWhile_le
    (l := x.integerDigits ++
      match x.fractionDigits with | none => [] | some ds => ds)
    (p := fun digit => digit == 0)
  have hpoint' : d.decimal_point.val =
      (x.integerDigits.length : Int) -
        (((x.integerDigits ++
          match x.fractionDigits with | none => [] | some ds => ds).length -
          ((x.integerDigits ++
            match x.fractionDigits with | none => [] | some ds => ds).dropWhile
              (fun digit => digit == 0)).length : Nat) : Int) +
        DecimalGoalVocabularyDefault.accumulatedExplicitExponent x := by
    omega
  exact DecimalSeqRetainedValue x d hsign hvalid hnum hstored htruncated hpoint'

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (46)
More program dependencies (13)
Standard-library dependencies (30)

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 15 entries
Technical checking records
Local closure summary
{
  "node": "P472_T1_RetainedRegularPoint",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c1e1498d6f2a6bfea750ec320b00ed456de691807c07424b0cd31c845b313668",
  "active_statement_hash": "c4a24a77ca4b186c6897e2a0260bc9c104773c72fd04481f80da5957db08f105",
  "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-99",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalSeqRetainedValue": "05913e15e9364215",
    "P472_T1_FinalPointRegimes": "0130b3c2850fe799"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "e78adeb2dfab360a",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "250be645520aec86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_final_decimal_point": "4f8088dec06d629a"
  }
}
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:32cab1834c77027dc31589eab76b12ff5f62ac91b145887db703dac6e70cbec8",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}