P616_T1_LexemeExactTransportB

Lean checked

Statement

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

Lemma · Full-significand exact transport through B

Let x be any valid numeric lexeme in DecimalGoalVocabularyDefault, including either optional leading sign and either independent exponent sign. If its entire rendering has length at most B=576460752303421440, then, for every binary64 word t, t rounds its full-significand accumulated-exponent magnitude if and only if it rounds its ordinary mathematical exact magnitude. No parser, finalizer, slow-call, or compliance hypothesis is required.

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.DecimalDigitTrimDecomposition
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P616_T1_CutoffFoldComparison
import Tablet.P616_T1_BinaryDecimalSeparation
import Tablet.P616_T1_ExtremeRounding
import Tablet.ExponentValueAgreement
import Tablet.RoundingDeterminism
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Positivity

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_LexemeExactTransportB]
theorem P616_T1_LexemeExactTransportB (x : DecimalLexeme)
    (hx : DecimalGoalVocabularyDefault.validNumeric x)
    (hB : (DecimalGoalVocabularyDefault.renderNumeric x).length <= 576460752303421440) :
    forall target : F64,
      DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target ↔
      DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.exactMagnitude x) target := 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

All notation in this proof is expanded from DecimalGoalVocabularyDefault. Let S be the integer digit list followed by the entire fractional digit list (empty when no fraction is present), and let f be that fractional list's length. Let C=S.\mathrm{dropWhile}(d=0), n=|C|, and M its decimal fold from zero. Validity gives digits below ten. The leading-zero decomposition and nonzero-head alternative in DecimalDigitTrimDecomposition give S=0^z C, where z=|S|-|C|, and either C is empty or its head is positive. Folding each initial zero from zero keeps zero, so induction on z gives \operatorname{fold}_{10}(S,0)=M. Trailing zeros are retained in C; no trimmed length replaces n.
Write L for the full rendered length. The rendering concatenates the leading-sign bytes, mapped integer digits, the optional dot and mapped fractional digits, and the optional exponent marker, sign and digits. Maps preserve length and all added lengths are nonnegative. Hence f\leq|S|\leq L\leq B and n\leq|S|\leq B. For either explicit integer exponent e, the magnitude equals M10^{e-f}. It is nonnegative since M\geq0 and every integer power of ten is positive.
If C is empty, M=0, so both magnitudes are zero, independently of their exponents. Equality of their real arguments proves the equivalence. If there is no explicit exponent, the two explicit exponents are both zero; ExponentValueAgreement, with the given validity hypothesis, proves the equivalence (reverse its displayed orientation).
Otherwise let D be the explicit exponent digit list, and set
H=576460752303423488=2^{59},\quad a=\operatorname{fold}_{\mathrm{cutoff},H}(D,0),\quad b=\operatorname{fold}_{10}(D,0).
CutoffFoldComparison gives a\leq b and (a=b\text{ or }H\leq a). If a=b, applying the same exponent sign to these natural values gives equal explicit integer exponents; ExponentValueAgreement again applies. This includes equal folds at or above the cutoff and exponents consisting entirely of zeros. It remains to consider unequal folds with nonempty C. Then n\geq1, and write C=c::C' with 1\leq c<10.
For a positive or absent exponent sign, use the unclipped integer points p_a=n-f+a and p_b=n-f+b. Since H-B=2048, the established bounds give p_a\geq1-B+H=2049 and p_b\geq p_a. For a negative exponent sign, the points are instead p_a=n-f-a and p_b=n-f-b, and the bounds give p_a\leq B-H=-2048 and p_b\leq p_a. These calculations take place in the integers after embedding natural lengths and folds; there is no clipped decimal point or machine cast. For either point p, integer exponent arithmetic gives M10^{p-n}=M10^{e-f}. Apply DecimalValueBounds to C=c::C', its valid digits, and 1\leq c. Its conclusions imply
10^{p-1}\leq M10^{p-n}<10^p. \tag{1}
In the positive case both points are at least 2049, so both magnitudes are at least 10^{2048}\geq10^{309}>2^{1024}>T, where T=2^{1024}-2^{970}. The strict middle inequality is the first natural-number certificate of BinaryDecimalSeparation, embedded in the reals; order of powers of the positive base ten gives the preceding comparison. The first assertion of ExtremeRounding therefore makes the same infinity word a target of both magnitudes.
In the negative case both points are at most -2048. The upper bound in (1), monotonicity of integer powers of ten, and positivity give
0\leq M10^{p-n}<10^p\leq10^{-2048}\leq10^{-325}<2^{-1075}.
The last inequality follows by taking reciprocals of the positive real embedding of 2^{1075}<10^{325} from BinaryDecimalSeparation; the integer-power reciprocal identity identifies 10^{-325}. The second assertion of ExtremeRounding makes the same zero word a target of both magnitudes.
In either unequal-fold case let w be that common certified target. If t rounds the accumulated magnitude, its nonnegativity and RoundingDeterminism identify t=w; substitute into the certificate for the exact magnitude. Conversely a target of the exact magnitude equals w by the same determinism theorem, and hence rounds the accumulated magnitude. This proves both implications for arbitrary t. The zero, absent-exponent, equal-fold, and unequal-fold cases are exhaustive. The proof uses the pre-update cutoff with overshoot, never a clamp, and uses the full rendered length including any leading sign.

Lean proof


  let S := x.integerDigits ++
    match x.fractionDigits with | none => [] | some ds => ds
  let f := match x.fractionDigits with | none => 0 | some ds => ds.length
  let C := S.dropWhile (fun d => d == 0)
  let M := C.foldl (fun n d => 10 * n + d) 0
  have hSL : S.length <= (DecimalGoalVocabularyDefault.renderNumeric x).length := by
    cases hf : x.fractionDigits <;>
      simp only [S, DecimalGoalVocabularyDefault, hf, List.length_append,
        List.length_map, List.length_nil, List.length_cons] <;> omega
  have hCL : C.length <= 576460752303421440 :=
    le_trans (List.length_dropWhile_le _ _) (le_trans hSL hB)
  have hfL : f <= 576460752303421440 := by
    have hsf : f <= S.length := by
      cases hf : x.fractionDigits <;> simp [f, S, hf]
    exact le_trans hsf (le_trans hSL hB)
  have hfold (ds : List Nat) :
      (ds.dropWhile (fun d => d == 0)).foldl (fun n d => 10 * n + d) 0 =
        ds.foldl (fun n d => 10 * n + d) 0 := by
    induction ds with
    | nil => rfl
    | cons d ds ih =>
      by_cases hz : d = 0
      · subst d; simpa using ih
      · simp [List.dropWhile, beq_eq_false_iff_ne.mpr hz]
  have hacc : DecimalGoalVocabularyDefault.accumulatedMagnitude x =
      (M : Real) * (10 : Real) ^
        (DecimalGoalVocabularyDefault.accumulatedExplicitExponent x - (f : Int)) := by
    simp only [DecimalGoalVocabularyDefault]
    cases hf : x.fractionDigits <;>
      simp only [S, f, M, C, hf, hfold, List.append_nil, Nat.cast_zero]
  have hexact : DecimalGoalVocabularyDefault.exactMagnitude x =
      (M : Real) * (10 : Real) ^
        (DecimalGoalVocabularyDefault.mathExplicitExponent x - (f : Int)) := by
    simp only [DecimalGoalVocabularyDefault]
    cases hf : x.fractionDigits <;>
      simp only [S, f, M, C, hf, hfold, List.append_nil, Nat.cast_zero]
  have hacc0 : 0 <= DecimalGoalVocabularyDefault.accumulatedMagnitude x := by
    rw [hacc]
    exact mul_nonneg (Nat.cast_nonneg _) (le_of_lt (zpow_pos (by norm_num) _))
  have hexact0 : 0 <= DecimalGoalVocabularyDefault.exactMagnitude x := by
    rw [hexact]
    exact mul_nonneg (Nat.cast_nonneg _) (le_of_lt (zpow_pos (by norm_num) _))
  have common (w : F64)
      (ha : DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.accumulatedMagnitude x) w)
      (hb : DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.exactMagnitude x) w) :
      forall target : F64,
        DecimalGoalVocabularyDefault.roundsMagnitude
          (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target ↔
        DecimalGoalVocabularyDefault.roundsMagnitude
          (DecimalGoalVocabularyDefault.exactMagnitude x) target := by
    intro target
    constructor
    · intro ht
      have heq := RoundingDeterminism _ target w hacc0 ht ha
      simpa [heq] using hb
    · intro ht
      have heq := RoundingDeterminism _ target w hexact0 ht hb
      simpa [heq] using ha
  by_cases hC : C = []
  · have hM : M = 0 := by simp [M, hC]
    intro target
    rw [hacc, hexact, hM]
    simp only [Nat.cast_zero, zero_mul]
  have hdS : ∀ d ∈ S, d < 10 := by
    have hvalid := hx
    dsimp only [DecimalGoalVocabularyDefault] at hvalid
    intro d hd
    obtain hi | hf := List.mem_append.mp hd
    · exact hvalid.1 d hi
    · cases hfrac : x.fractionDigits with
      | none => simp [hfrac] at hf
      | some ds =>
        have hd : ∀ d ∈ ds, d < 10 := by simpa only [hfrac] using hvalid.2.1
        exact hd d (by simpa only [hfrac] using hf)
  have hdC : ∀ d ∈ C, d < 10 := fun d hd => hdS d (List.dropWhile_subset _ hd)
  obtain ⟨z, zs, hc⟩ := List.exists_cons_of_ne_nil hC
  have hz : 1 <= z := by
    have hs := List.head_dropWhile_not (fun d => d == 0) (l := S) hC
    have hh : C.head hC = z := by simp [hc]
    change (C.head hC == 0) = false at hs
    rw [hh] at hs
    have hz0 : z ≠ 0 := by simpa using hs
    omega
  have hbnd (p : Int) :
      (10 : Real) ^ (p - 1) <= (M : Real) * (10 : Real) ^ (p - (C.length : Int)) ∧
      (M : Real) * (10 : Real) ^ (p - (C.length : Int)) < (10 : Real) ^ p := by
    have hh := P472_T1_DecimalValueBounds C z zs hc hz hdC p
    dsimp only at hh
    have hzR : (1 : Real) <= z := by exact_mod_cast hz
    have hpow := mul_le_mul_of_nonneg_right hzR
      (le_of_lt (zpow_pos (show (0 : Real) < 10 by norm_num) (p - 1)))
    refine ⟨?_, hh.2⟩
    exact le_trans (by simpa only [one_mul] using hpow) hh.1
  have hOver (p : Int) (hp : 2049 <= p) :
      (2 : Real)^1024 - (2 : Real)^970 <=
        (M : Real) * (10 : Real)^(p - (C.length : Int)) := by
    have hbase : (2 : Real)^(1024 : Nat) < (10 : Real)^(309 : Nat) := by
      exact_mod_cast P616_T1_BinaryDecimalSeparation.1
    have hten : (10 : Real)^(309 : Nat) <= (10 : Real)^(p-1) := by
      have hh := zpow_le_zpow_right₀ (show (1 : Real) <= 10 by norm_num)
        (show (309 : Int) <= p - 1 by omega)
      simpa only [zpow_natCast] using hh
    exact le_trans (sub_le_self _ (by positivity))
      (le_trans (le_of_lt hbase) (le_trans hten (hbnd p).1))
  have hUnder (p : Int) (hp : p <= -2048) :
      (M : Real) * (10 : Real)^(p - (C.length : Int)) <=
        1 / (2 : Real)^(1075 : Nat) := by
    have hbase : (2 : Real)^(1075 : Nat) < (10 : Real)^(325 : Nat) := by
      exact_mod_cast P616_T1_BinaryDecimalSeparation.2
    have hten := zpow_le_zpow_right₀ (show (1 : Real) <= 10 by norm_num)
      (show p <= (-325 : Int) by omega)
    have hinv : (10 : Real)^(-325 : Int) = 1 / (10 : Real)^(325 : Nat) := by
      rw [zpow_neg, inv_eq_one_div]
      rfl
    have hrecip : 1 / (10 : Real)^(325 : Nat) < 1 / (2 : Real)^(1075 : Nat) :=
      one_div_lt_one_div_of_lt (by positivity) hbase
    exact le_of_lt (lt_trans (lt_of_lt_of_le (hbnd p).2 hten)
      (by simpa only [hinv] using hrecip))
  cases he : x.exponent with
  | none =>
    have heq : DecimalGoalVocabularyDefault.accumulatedExplicitExponent x =
        DecimalGoalVocabularyDefault.mathExplicitExponent x := by
      simp [DecimalGoalVocabularyDefault, he]
    intro target
    exact (ExponentValueAgreement x hx heq target).symm
  | some exponent =>
    obtain ⟨upper, sign, ds⟩ := exponent
    let a := ds.foldl (fun n d => if n < 576460752303423488 then 10 * n + d else n) 0
    let b := ds.foldl (fun n d => 10 * n + d) 0
    have heacc : DecimalGoalVocabularyDefault.accumulatedExplicitExponent x =
        if sign = some true then -(a : Int) else (a : Int) := by
      cases sign with
      | none => simp [DecimalGoalVocabularyDefault, he, a]
      | some neg => cases neg <;> simp [DecimalGoalVocabularyDefault, he, a]
    have hemath : DecimalGoalVocabularyDefault.mathExplicitExponent x =
        if sign = some true then -(b : Int) else (b : Int) := by
      cases sign with
      | none => simp [DecimalGoalVocabularyDefault, he, b]
      | some neg => cases neg <;> simp [DecimalGoalVocabularyDefault, he, b]
    have hcFold := P616_T1_CutoffFoldComparison 576460752303423488 ds
    change a <= b ∧ (a = b ∨ 576460752303423488 <= a) at hcFold
    obtain ⟨hab, heq | hcap⟩ := hcFold
    · have heqexp : DecimalGoalVocabularyDefault.accumulatedExplicitExponent x =
          DecimalGoalVocabularyDefault.mathExplicitExponent x := by
        rw [heacc, hemath, heq]
      intro target
      exact (ExponentValueAgreement x hx heqexp target).symm
    · by_cases hneg : sign = some true
      · let pa : Int := (C.length : Int) - f - a
        let pb : Int := (C.length : Int) - f - b
        have hpa : pa <= -2048 := by dsimp [pa]; omega
        have hpb : pb <= -2048 := by dsimp [pb]; omega
        have haccP : DecimalGoalVocabularyDefault.accumulatedMagnitude x =
            (M : Real) * (10 : Real)^(pa - (C.length : Int)) := by
          rw [hacc, heacc, if_pos hneg]
          congr 1
          congr 1
          dsimp [pa]; omega
        have hexactP : DecimalGoalVocabularyDefault.exactMagnitude x =
            (M : Real) * (10 : Real)^(pb - (C.length : Int)) := by
          rw [hexact, hemath, if_pos hneg]
          congr 1
          congr 1
          dsimp [pb]; omega
        apply common (0#u64)
        · apply P616_T1_ExtremeRounding.2 _ hacc0
          rw [haccP]
          exact hUnder pa hpa
        · apply P616_T1_ExtremeRounding.2 _ hexact0
          rw [hexactP]
          exact hUnder pb hpb
      · let pa : Int := (C.length : Int) - f + a
        let pb : Int := (C.length : Int) - f + b
        have hn : 1 <= C.length := by rw [hc]; simp
        have hpa : 2049 <= pa := by dsimp [pa]; omega
        have hpb : 2049 <= pb := by dsimp [pb]; omega
        have haccP : DecimalGoalVocabularyDefault.accumulatedMagnitude x =
            (M : Real) * (10 : Real)^(pa - (C.length : Int)) := by
          rw [hacc, heacc, if_neg hneg]
          congr 1
          congr 1
          dsimp [pa]; omega
        have hexactP : DecimalGoalVocabularyDefault.exactMagnitude x =
            (M : Real) * (10 : Real)^(pb - (C.length : Int)) := by
          rw [hexact, hemath, if_neg hneg]
          congr 1
          congr 1
          dsimp [pb]; omega
        apply common (9218868437227405312#u64)
        · apply P616_T1_ExtremeRounding.1 _ hacc0
          rw [haccP]
          exact hOver pa hpa
        · apply P616_T1_ExtremeRounding.1 _ hexact0
          rw [hexactP]
          exact hOver pb hpb
end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.DecimalDigitTrimDecomposition
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P616_T1_CutoffFoldComparison
import Tablet.P616_T1_BinaryDecimalSeparation
import Tablet.P616_T1_ExtremeRounding
import Tablet.ExponentValueAgreement
import Tablet.RoundingDeterminism
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Positivity

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_LexemeExactTransportB]
theorem P616_T1_LexemeExactTransportB (x : DecimalLexeme)
    (hx : DecimalGoalVocabularyDefault.validNumeric x)
    (hB : (DecimalGoalVocabularyDefault.renderNumeric x).length <= 576460752303421440) :
    forall target : F64,
      DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target ↔
      DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.exactMagnitude x) target := by
-- BODY
  let S := x.integerDigits ++
    match x.fractionDigits with | none => [] | some ds => ds
  let f := match x.fractionDigits with | none => 0 | some ds => ds.length
  let C := S.dropWhile (fun d => d == 0)
  let M := C.foldl (fun n d => 10 * n + d) 0
  have hSL : S.length <= (DecimalGoalVocabularyDefault.renderNumeric x).length := by
    cases hf : x.fractionDigits <;>
      simp only [S, DecimalGoalVocabularyDefault, hf, List.length_append,
        List.length_map, List.length_nil, List.length_cons] <;> omega
  have hCL : C.length <= 576460752303421440 :=
    le_trans (List.length_dropWhile_le _ _) (le_trans hSL hB)
  have hfL : f <= 576460752303421440 := by
    have hsf : f <= S.length := by
      cases hf : x.fractionDigits <;> simp [f, S, hf]
    exact le_trans hsf (le_trans hSL hB)
  have hfold (ds : List Nat) :
      (ds.dropWhile (fun d => d == 0)).foldl (fun n d => 10 * n + d) 0 =
        ds.foldl (fun n d => 10 * n + d) 0 := by
    induction ds with
    | nil => rfl
    | cons d ds ih =>
      by_cases hz : d = 0
      · subst d; simpa using ih
      · simp [List.dropWhile, beq_eq_false_iff_ne.mpr hz]
  have hacc : DecimalGoalVocabularyDefault.accumulatedMagnitude x =
      (M : Real) * (10 : Real) ^
        (DecimalGoalVocabularyDefault.accumulatedExplicitExponent x - (f : Int)) := by
    simp only [DecimalGoalVocabularyDefault]
    cases hf : x.fractionDigits <;>
      simp only [S, f, M, C, hf, hfold, List.append_nil, Nat.cast_zero]
  have hexact : DecimalGoalVocabularyDefault.exactMagnitude x =
      (M : Real) * (10 : Real) ^
        (DecimalGoalVocabularyDefault.mathExplicitExponent x - (f : Int)) := by
    simp only [DecimalGoalVocabularyDefault]
    cases hf : x.fractionDigits <;>
      simp only [S, f, M, C, hf, hfold, List.append_nil, Nat.cast_zero]
  have hacc0 : 0 <= DecimalGoalVocabularyDefault.accumulatedMagnitude x := by
    rw [hacc]
    exact mul_nonneg (Nat.cast_nonneg _) (le_of_lt (zpow_pos (by norm_num) _))
  have hexact0 : 0 <= DecimalGoalVocabularyDefault.exactMagnitude x := by
    rw [hexact]
    exact mul_nonneg (Nat.cast_nonneg _) (le_of_lt (zpow_pos (by norm_num) _))
  have common (w : F64)
      (ha : DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.accumulatedMagnitude x) w)
      (hb : DecimalGoalVocabularyDefault.roundsMagnitude
        (DecimalGoalVocabularyDefault.exactMagnitude x) w) :
      forall target : F64,
        DecimalGoalVocabularyDefault.roundsMagnitude
          (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target ↔
        DecimalGoalVocabularyDefault.roundsMagnitude
          (DecimalGoalVocabularyDefault.exactMagnitude x) target := by
    intro target
    constructor
    · intro ht
      have heq := RoundingDeterminism _ target w hacc0 ht ha
      simpa [heq] using hb
    · intro ht
      have heq := RoundingDeterminism _ target w hexact0 ht hb
      simpa [heq] using ha
  by_cases hC : C = []
  · have hM : M = 0 := by simp [M, hC]
    intro target
    rw [hacc, hexact, hM]
    simp only [Nat.cast_zero, zero_mul]
  have hdS : ∀ d ∈ S, d < 10 := by
    have hvalid := hx
    dsimp only [DecimalGoalVocabularyDefault] at hvalid
    intro d hd
    obtain hi | hf := List.mem_append.mp hd
    · exact hvalid.1 d hi
    · cases hfrac : x.fractionDigits with
      | none => simp [hfrac] at hf
      | some ds =>
        have hd : ∀ d ∈ ds, d < 10 := by simpa only [hfrac] using hvalid.2.1
        exact hd d (by simpa only [hfrac] using hf)
  have hdC : ∀ d ∈ C, d < 10 := fun d hd => hdS d (List.dropWhile_subset _ hd)
  obtain ⟨z, zs, hc⟩ := List.exists_cons_of_ne_nil hC
  have hz : 1 <= z := by
    have hs := List.head_dropWhile_not (fun d => d == 0) (l := S) hC
    have hh : C.head hC = z := by simp [hc]
    change (C.head hC == 0) = false at hs
    rw [hh] at hs
    have hz0 : z ≠ 0 := by simpa using hs
    omega
  have hbnd (p : Int) :
      (10 : Real) ^ (p - 1) <= (M : Real) * (10 : Real) ^ (p - (C.length : Int)) ∧
      (M : Real) * (10 : Real) ^ (p - (C.length : Int)) < (10 : Real) ^ p := by
    have hh := P472_T1_DecimalValueBounds C z zs hc hz hdC p
    dsimp only at hh
    have hzR : (1 : Real) <= z := by exact_mod_cast hz
    have hpow := mul_le_mul_of_nonneg_right hzR
      (le_of_lt (zpow_pos (show (0 : Real) < 10 by norm_num) (p - 1)))
    refine ⟨?_, hh.2⟩
    exact le_trans (by simpa only [one_mul] using hpow) hh.1
  have hOver (p : Int) (hp : 2049 <= p) :
      (2 : Real)^1024 - (2 : Real)^970 <=
        (M : Real) * (10 : Real)^(p - (C.length : Int)) := by
    have hbase : (2 : Real)^(1024 : Nat) < (10 : Real)^(309 : Nat) := by
      exact_mod_cast P616_T1_BinaryDecimalSeparation.1
    have hten : (10 : Real)^(309 : Nat) <= (10 : Real)^(p-1) := by
      have hh := zpow_le_zpow_right₀ (show (1 : Real) <= 10 by norm_num)
        (show (309 : Int) <= p - 1 by omega)
      simpa only [zpow_natCast] using hh
    exact le_trans (sub_le_self _ (by positivity))
      (le_trans (le_of_lt hbase) (le_trans hten (hbnd p).1))
  have hUnder (p : Int) (hp : p <= -2048) :
      (M : Real) * (10 : Real)^(p - (C.length : Int)) <=
        1 / (2 : Real)^(1075 : Nat) := by
    have hbase : (2 : Real)^(1075 : Nat) < (10 : Real)^(325 : Nat) := by
      exact_mod_cast P616_T1_BinaryDecimalSeparation.2
    have hten := zpow_le_zpow_right₀ (show (1 : Real) <= 10 by norm_num)
      (show p <= (-325 : Int) by omega)
    have hinv : (10 : Real)^(-325 : Int) = 1 / (10 : Real)^(325 : Nat) := by
      rw [zpow_neg, inv_eq_one_div]
      rfl
    have hrecip : 1 / (10 : Real)^(325 : Nat) < 1 / (2 : Real)^(1075 : Nat) :=
      one_div_lt_one_div_of_lt (by positivity) hbase
    exact le_of_lt (lt_trans (lt_of_lt_of_le (hbnd p).2 hten)
      (by simpa only [hinv] using hrecip))
  cases he : x.exponent with
  | none =>
    have heq : DecimalGoalVocabularyDefault.accumulatedExplicitExponent x =
        DecimalGoalVocabularyDefault.mathExplicitExponent x := by
      simp [DecimalGoalVocabularyDefault, he]
    intro target
    exact (ExponentValueAgreement x hx heq target).symm
  | some exponent =>
    obtain ⟨upper, sign, ds⟩ := exponent
    let a := ds.foldl (fun n d => if n < 576460752303423488 then 10 * n + d else n) 0
    let b := ds.foldl (fun n d => 10 * n + d) 0
    have heacc : DecimalGoalVocabularyDefault.accumulatedExplicitExponent x =
        if sign = some true then -(a : Int) else (a : Int) := by
      cases sign with
      | none => simp [DecimalGoalVocabularyDefault, he, a]
      | some neg => cases neg <;> simp [DecimalGoalVocabularyDefault, he, a]
    have hemath : DecimalGoalVocabularyDefault.mathExplicitExponent x =
        if sign = some true then -(b : Int) else (b : Int) := by
      cases sign with
      | none => simp [DecimalGoalVocabularyDefault, he, b]
      | some neg => cases neg <;> simp [DecimalGoalVocabularyDefault, he, b]
    have hcFold := P616_T1_CutoffFoldComparison 576460752303423488 ds
    change a <= b ∧ (a = b ∨ 576460752303423488 <= a) at hcFold
    obtain ⟨hab, heq | hcap⟩ := hcFold
    · have heqexp : DecimalGoalVocabularyDefault.accumulatedExplicitExponent x =
          DecimalGoalVocabularyDefault.mathExplicitExponent x := by
        rw [heacc, hemath, heq]
      intro target
      exact (ExponentValueAgreement x hx heqexp target).symm
    · by_cases hneg : sign = some true
      · let pa : Int := (C.length : Int) - f - a
        let pb : Int := (C.length : Int) - f - b
        have hpa : pa <= -2048 := by dsimp [pa]; omega
        have hpb : pb <= -2048 := by dsimp [pb]; omega
        have haccP : DecimalGoalVocabularyDefault.accumulatedMagnitude x =
            (M : Real) * (10 : Real)^(pa - (C.length : Int)) := by
          rw [hacc, heacc, if_pos hneg]
          congr 1
          congr 1
          dsimp [pa]; omega
        have hexactP : DecimalGoalVocabularyDefault.exactMagnitude x =
            (M : Real) * (10 : Real)^(pb - (C.length : Int)) := by
          rw [hexact, hemath, if_pos hneg]
          congr 1
          congr 1
          dsimp [pb]; omega
        apply common (0#u64)
        · apply P616_T1_ExtremeRounding.2 _ hacc0
          rw [haccP]
          exact hUnder pa hpa
        · apply P616_T1_ExtremeRounding.2 _ hexact0
          rw [hexactP]
          exact hUnder pb hpb
      · let pa : Int := (C.length : Int) - f + a
        let pb : Int := (C.length : Int) - f + b
        have hn : 1 <= C.length := by rw [hc]; simp
        have hpa : 2049 <= pa := by dsimp [pa]; omega
        have hpb : 2049 <= pb := by dsimp [pb]; omega
        have haccP : DecimalGoalVocabularyDefault.accumulatedMagnitude x =
            (M : Real) * (10 : Real)^(pa - (C.length : Int)) := by
          rw [hacc, heacc, if_neg hneg]
          congr 1
          congr 1
          dsimp [pa]; omega
        have hexactP : DecimalGoalVocabularyDefault.exactMagnitude x =
            (M : Real) * (10 : Real)^(pb - (C.length : Int)) := by
          rw [hexact, hemath, if_neg hneg]
          congr 1
          congr 1
          dsimp [pb]; omega
        apply common (9218868437227405312#u64)
        · apply P616_T1_ExtremeRounding.1 _ hacc0
          rw [haccP]
          exact hOver pa hpa
        · apply P616_T1_ExtremeRounding.1 _ hexact0
          rw [hexactP]
          exact hOver pb hpb
end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (199)
More program dependencies (157)
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 15 entries
Technical checking records
Local closure summary
{
  "node": "P616_T1_LexemeExactTransportB",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f6618f5b87c2afe0a55626e98e3de827516015d3b0af5a2a3cb9b54b429a0298",
  "active_statement_hash": "01bc932db26e437f235859ed87f7e1baec91b3ecf754dc05a9903e6df5a90fe3",
  "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-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "ExponentValueAgreement": "4586adc775a37002",
    "P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "P616_T1_BinaryDecimalSeparation": "d033f207ea8cdfae",
    "P616_T1_CutoffFoldComparison": "b78dbd9d3d465fe8",
    "P616_T1_ExtremeRounding": "23833a96cb991f3a",
    "RoundingDeterminism": "6500074d31847e13"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "55eb6bce0e8a4131",
    "DecimalLexeme": "8127b3eaeae00dd2",
    "F64": "ec4e25fbaf4e11d4",
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_Decimal": "63fd2f021dd0ef41"
  }
}
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:8a72ab481ed012d65a63cee19ec259cdf5be784d518f526c4e47677b9cd3772e",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}