P529_T1_NormalizationBounds

Lean checked

Statement

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

Lemma · Sharp bound for the original adjacent endpoint

Let d have positive exact-length decimal shape, count at most 768 and -324\le p<310. Let
X=V(d)+\eta,\quad Y=V(d)+10^{p-768},\quad 0\le\eta<10^{p-768},\quad d.\mathit{truncated}\iff\eta>0 .
Assume the actual specialized loop-zero call from exponent zero with zero sentinel returns (d_0,e_0,\mathsf{none}), and the actual loop-one call from there with infinity sentinel returns (d_1,e_1,\mathsf{none}). Then
10^{-325}\le X<Y,\quad Y/2^{e_1}\le1,\quad -1079\le e_1\le1260 .
This assertion concerns the original adjacent cell and these exact histories, not an arbitrary generic upper endpoint.

Lean statement

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

import Tablet.P529_T1_LeftHistoryBoundary
import Tablet.P529_T1_RightHistoryBoundary
import Tablet.P826_T1_ExponentLowerBound
import Tablet.P798_T1_GridAlignment
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P856_T1_CoefficientGridAlignment
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_NormalizationBounds]
theorem P529_T1_NormalizationBounds (X Y : Real)
    (d d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 exp1 : Std.I32)
    (hpointLo : -324 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (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))
    (hloop0 : num.imp.dec2flt.slow.parse_long_mantissa_loop0
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#i32 }
      d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
        ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, exp0, none))
    (hloop1 : num.imp.dec2flt.slow.parse_long_mantissa_loop1
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 2047#i32 }
      d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
        ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits, exp1, none)) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
        (fun n z => 10 * n + z) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
      (d.truncated = true <-> 0 < eta)) ->
    (10 : Real) ^ (-325 : Int) <= X /\ X < Y /\
    Y / (2 : Real) ^ exp1.val <= 1 /\
    -1079 <= exp1.val /\ exp1.val <= 1260 := 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 SlowLoop0Execution to the original package and identify its result by normal-result injectivity. This gives 10^{-325}\le X, 0\le e_0\le1260, point in [-324,0], positive exact-length decimal shape and both endpoint equations at d_0. Apply Loop1Execution there and identify its final record and exponent with the supplied call. Its output has point zero, positive decimal shape, and e_1\le e_0\le1260. DecimalValueBounds gives V(d_1)<1.
The first two clauses of LeftHistoryBoundary give C_0=e_1-e_0+768-p_0\ge0 and 2^{e_1-e_0}\le V(d_0)\Longrightarrow1\le V(d_1). Since V(d_1)<1, contraposition gives V(d_0)<2^{e_1-e_0}. Apply RightHistoryBoundary with c=1,R=e_1 and this terminal capacity/order. It gives
C=e_1+768-p\ge0,\qquad V(d)<2^{e_1}. \tag{1}
The point bound p<310<768 and (1) allow CoefficientGridAlignment at the INITIAL state, with coefficient one and exponent e_1: 2^{e_1}=bq for a natural b, where q=10^{p-768}>0. GridAlignment writes V(d)=aq for a natural a, using precisely the initial count bound. If Y/2^{e_1}>1, positivity gives 2^{e_1}<Y=(a+1)q. Cancel q to get b<a+1, hence b\le a by natural discreteness. This gives 2^{e_1}\le V(d), contradicting (1). Thus Y/2^{e_1}\le1.
The initial errors give X<Y directly. Now ExponentLowerBound applies to 10^{-325}\le X<Y and the endpoint bound just proved, and yields e_1\ge-1079. Together with the earlier upper bound this proves the whole statement. In particular no generic \eta<u inference was used to obtain the endpoint bound.

Lean proof


  intro V hY herrors
  obtain ⟨dw, ew, steps, h0w, hsteps, hewlo, hewhi, hXlo,
      hplo, hphi, hcountw, hdigitsw, hshapeW, hlast, hpackage⟩ :=
    P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput hY herrors
  have htuple0 := Result.ok.inj (h0w.symm.trans hloop0)
  simp only [Prod.mk.injEq] at htuple0
  rcases htuple0 with ⟨hnum0, hp0, htr0, hdigits0, hexp0, hnone0⟩
  have hdw : dw = d0 := by
    cases dw
    cases d0
    simp_all
  subst dw
  subst ew
  have hpack0 :
      (exists eta0 u0 : Real,
        X / (2 : Real) ^ exp0.val = V d0 + eta0 /\
        Y / (2 : Real) ^ exp0.val = V d0 + u0 /\
        0 <= eta0 /\ eta0 < u0 /\ (d0.truncated = true <-> 0 < eta0)) := by
    simpa [V] using hpackage
  obtain ⟨d1w, e1w, bound, h1w, hbound, hboundlo, hboundhi,
      hp1, hnum1, hfirstLo, hfirstHi, hcount1, hdigits1,
      hshapeExists, hpackage1⟩ :=
    P529_T1_Loop1Execution X Y d0 exp0 hplo hphi hewlo
      ⟨hcountw, hdigitsw, hshapeW⟩ (by simpa [V] using hpack0)
  have htuple1 := Result.ok.inj (h1w.symm.trans hloop1)
  simp only [Prod.mk.injEq] at htuple1
  rcases htuple1 with ⟨hnum1eq, hp1eq, htr1eq, hdigits1eq, hexp1eq, hnone1⟩
  have hd1w : d1w = d1 := by
    cases d1w
    cases d1
    simp_all
  subst d1w
  subst e1w
  have hV1 : V d1 < 1 := by
    rcases hshapeExists with ⟨z, zs, hxs, hz, hzlt, hlen⟩
    have hshape := P472_T1_DecimalValueBounds
      ((d1.digits.val.take d1.num_digits.val).map (fun b => b.val))
      z zs hxs (by omega)
      (by
        intro q hq
        rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
        exact hdigits1 b hb)
      d1.decimal_point.val
    have hlen' :
        ((d1.digits.val.take d1.num_digits.val).map (fun b => b.val)).length =
          d1.num_digits.val := by
      rw [hxs]
      simpa using hlen
    have hshapeUpper := hshape.2
    rw [hlen'] at hshapeUpper
    simpa [V, hp1] using hshapeUpper
  have hleft := P529_T1_LeftHistoryBoundary X Y d0 d1 exp0 exp1
    hplo hphi hewlo ⟨hcountw, hdigitsw, hshapeW⟩ hloop1
    (by simpa [V] using hpackage)
  have hcap0 : 0 <= exp1.val - exp0.val + 768 - d0.decimal_point.val := hleft.1
  have hV0lt : V d0 < (2 : Real) ^ (exp1.val - exp0.val) := by
    by_contra hn
    have hge : (2 : Real) ^ (exp1.val - exp0.val) <= V d0 := le_of_not_gt hn
    have hge1 := hleft.2.1 hge
    linarith
  have hright := P529_T1_RightHistoryBoundary X Y d d0 exp0
    hpointLo hpointHi hinput hloop0 hY herrors
  have hcap : 0 <= exp1.val + 768 - d.decimal_point.val :=
    (hright.2 1 exp1 hcap0).1
  have hVdlt : V d < (1 : Real) * (2 : Real) ^ exp1.val :=
    by
      simpa [V] using (hright.2 1 exp1 hcap0).2 (by simpa [V] using hV0lt)
  obtain ⟨a, ha⟩ := P798_T1_GridAlignment d hinput.1
  have hp768 : d.decimal_point.val <= 768 := by omega
  obtain ⟨b, hb⟩ := P856_T1_CoefficientGridAlignment 1 exp1.val
    d.decimal_point.val hp768 hcap
  have hqpos : 0 < (10 : Real) ^ (d.decimal_point.val - 768) :=
    zpow_pos (by norm_num) _
  have hagrid : V d = (a : Real) * (10 : Real) ^ (d.decimal_point.val - 768) := by
    simpa [V] using ha
  have hbgrid : (2 : Real) ^ exp1.val = (b : Real) *
      (10 : Real) ^ (d.decimal_point.val - 768) := by
    simpa using hb
  have hab : a < b := by
    have hlt : (a : Real) * (10 : Real) ^ (d.decimal_point.val - 768) <
        (b : Real) * (10 : Real) ^ (d.decimal_point.val - 768) := by
      rw [← hagrid, ← hbgrid]
      simpa using hVdlt
    exact_mod_cast (lt_of_mul_lt_mul_right hlt (le_of_lt hqpos))
  have ha1b : a + 1 <= b := by omega
  have hYbound : Y / (2 : Real) ^ exp1.val <= 1 := by
    have hYeq : Y = ((a + 1 : Nat) : Real) *
        (10 : Real) ^ (d.decimal_point.val - 768) := by
      rw [hY, hagrid]
      push_cast
      ring
    have hle : Y <= (2 : Real) ^ exp1.val := by
      rw [hYeq, hbgrid]
      exact mul_le_mul_of_nonneg_right (by exact_mod_cast ha1b) (le_of_lt hqpos)
    exact (div_le_iff₀ (zpow_pos (by norm_num) _)).2 (by simpa using hle)
  have hXY : X < Y := by
    rcases herrors with ⟨eta, hX, heta0, hetaLt, htr⟩
    rw [hX, hY]
    have hq : 0 < (10 : Real) ^ (d.decimal_point.val - 768) := hqpos
    linarith
  have hloexp := P826_T1_ExponentLowerBound X Y exp1.val hXlo hXY hYbound
  have hhi : exp1.val <= 1260 := by omega
  exact ⟨hXlo, hXY, hYbound, hloexp, hhi⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P529_T1_LeftHistoryBoundary
import Tablet.P529_T1_RightHistoryBoundary
import Tablet.P826_T1_ExponentLowerBound
import Tablet.P798_T1_GridAlignment
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P856_T1_CoefficientGridAlignment
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_NormalizationBounds]
theorem P529_T1_NormalizationBounds (X Y : Real)
    (d d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 exp1 : Std.I32)
    (hpointLo : -324 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (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))
    (hloop0 : num.imp.dec2flt.slow.parse_long_mantissa_loop0
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#i32 }
      d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
        ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, exp0, none))
    (hloop1 : num.imp.dec2flt.slow.parse_long_mantissa_loop1
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 2047#i32 }
      d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
        ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits, exp1, none)) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
        (fun n z => 10 * n + z) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
      (d.truncated = true <-> 0 < eta)) ->
    (10 : Real) ^ (-325 : Int) <= X /\ X < Y /\
    Y / (2 : Real) ^ exp1.val <= 1 /\
    -1079 <= exp1.val /\ exp1.val <= 1260 := by
-- BODY
  intro V hY herrors
  obtain ⟨dw, ew, steps, h0w, hsteps, hewlo, hewhi, hXlo,
      hplo, hphi, hcountw, hdigitsw, hshapeW, hlast, hpackage⟩ :=
    P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput hY herrors
  have htuple0 := Result.ok.inj (h0w.symm.trans hloop0)
  simp only [Prod.mk.injEq] at htuple0
  rcases htuple0 with ⟨hnum0, hp0, htr0, hdigits0, hexp0, hnone0⟩
  have hdw : dw = d0 := by
    cases dw
    cases d0
    simp_all
  subst dw
  subst ew
  have hpack0 :
      (exists eta0 u0 : Real,
        X / (2 : Real) ^ exp0.val = V d0 + eta0 /\
        Y / (2 : Real) ^ exp0.val = V d0 + u0 /\
        0 <= eta0 /\ eta0 < u0 /\ (d0.truncated = true <-> 0 < eta0)) := by
    simpa [V] using hpackage
  obtain ⟨d1w, e1w, bound, h1w, hbound, hboundlo, hboundhi,
      hp1, hnum1, hfirstLo, hfirstHi, hcount1, hdigits1,
      hshapeExists, hpackage1⟩ :=
    P529_T1_Loop1Execution X Y d0 exp0 hplo hphi hewlo
      ⟨hcountw, hdigitsw, hshapeW⟩ (by simpa [V] using hpack0)
  have htuple1 := Result.ok.inj (h1w.symm.trans hloop1)
  simp only [Prod.mk.injEq] at htuple1
  rcases htuple1 with ⟨hnum1eq, hp1eq, htr1eq, hdigits1eq, hexp1eq, hnone1⟩
  have hd1w : d1w = d1 := by
    cases d1w
    cases d1
    simp_all
  subst d1w
  subst e1w
  have hV1 : V d1 < 1 := by
    rcases hshapeExists with ⟨z, zs, hxs, hz, hzlt, hlen⟩
    have hshape := P472_T1_DecimalValueBounds
      ((d1.digits.val.take d1.num_digits.val).map (fun b => b.val))
      z zs hxs (by omega)
      (by
        intro q hq
        rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
        exact hdigits1 b hb)
      d1.decimal_point.val
    have hlen' :
        ((d1.digits.val.take d1.num_digits.val).map (fun b => b.val)).length =
          d1.num_digits.val := by
      rw [hxs]
      simpa using hlen
    have hshapeUpper := hshape.2
    rw [hlen'] at hshapeUpper
    simpa [V, hp1] using hshapeUpper
  have hleft := P529_T1_LeftHistoryBoundary X Y d0 d1 exp0 exp1
    hplo hphi hewlo ⟨hcountw, hdigitsw, hshapeW⟩ hloop1
    (by simpa [V] using hpackage)
  have hcap0 : 0 <= exp1.val - exp0.val + 768 - d0.decimal_point.val := hleft.1
  have hV0lt : V d0 < (2 : Real) ^ (exp1.val - exp0.val) := by
    by_contra hn
    have hge : (2 : Real) ^ (exp1.val - exp0.val) <= V d0 := le_of_not_gt hn
    have hge1 := hleft.2.1 hge
    linarith
  have hright := P529_T1_RightHistoryBoundary X Y d d0 exp0
    hpointLo hpointHi hinput hloop0 hY herrors
  have hcap : 0 <= exp1.val + 768 - d.decimal_point.val :=
    (hright.2 1 exp1 hcap0).1
  have hVdlt : V d < (1 : Real) * (2 : Real) ^ exp1.val :=
    by
      simpa [V] using (hright.2 1 exp1 hcap0).2 (by simpa [V] using hV0lt)
  obtain ⟨a, ha⟩ := P798_T1_GridAlignment d hinput.1
  have hp768 : d.decimal_point.val <= 768 := by omega
  obtain ⟨b, hb⟩ := P856_T1_CoefficientGridAlignment 1 exp1.val
    d.decimal_point.val hp768 hcap
  have hqpos : 0 < (10 : Real) ^ (d.decimal_point.val - 768) :=
    zpow_pos (by norm_num) _
  have hagrid : V d = (a : Real) * (10 : Real) ^ (d.decimal_point.val - 768) := by
    simpa [V] using ha
  have hbgrid : (2 : Real) ^ exp1.val = (b : Real) *
      (10 : Real) ^ (d.decimal_point.val - 768) := by
    simpa using hb
  have hab : a < b := by
    have hlt : (a : Real) * (10 : Real) ^ (d.decimal_point.val - 768) <
        (b : Real) * (10 : Real) ^ (d.decimal_point.val - 768) := by
      rw [← hagrid, ← hbgrid]
      simpa using hVdlt
    exact_mod_cast (lt_of_mul_lt_mul_right hlt (le_of_lt hqpos))
  have ha1b : a + 1 <= b := by omega
  have hYbound : Y / (2 : Real) ^ exp1.val <= 1 := by
    have hYeq : Y = ((a + 1 : Nat) : Real) *
        (10 : Real) ^ (d.decimal_point.val - 768) := by
      rw [hY, hagrid]
      push_cast
      ring
    have hle : Y <= (2 : Real) ^ exp1.val := by
      rw [hYeq, hbgrid]
      exact mul_le_mul_of_nonneg_right (by exact_mod_cast ha1b) (le_of_lt hqpos)
    exact (div_le_iff₀ (zpow_pos (by norm_num) _)).2 (by simpa using hle)
  have hXY : X < Y := by
    rcases herrors with ⟨eta, hX, heta0, hetaLt, htr⟩
    rw [hX, hY]
    have hq : 0 < (10 : Real) ^ (d.decimal_point.val - 768) := hqpos
    linarith
  have hloexp := P826_T1_ExponentLowerBound X Y exp1.val hXlo hXY hYbound
  have hhi : exp1.val <= 1260 := by omega
  exact ⟨hXlo, hXY, hYbound, hloexp, hhi⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (152)
More program dependencies (110)
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 149 entries
Technical checking records
Local closure summary
{
  "node": "P529_T1_NormalizationBounds",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "a1dfd11c9fcf3f96bfaa33cdc3b382f0a5951f0d262e307671a524dd9b9fec97",
  "active_statement_hash": "422a7b47ac04874eac215f8b41969dba5f62cfbd213a15cad06dbb430c2df320",
  "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": {
    "P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "P495_T1_SlowLoop0Execution": "5a1e49d921a1825a",
    "P529_T1_LeftHistoryBoundary": "81ad17a70873ae99",
    "P529_T1_Loop1Execution": "da66766413255a0f",
    "P529_T1_RightHistoryBoundary": "2f9292b355b28e68",
    "P798_T1_GridAlignment": "f2e86c75264ff7d3",
    "P826_T1_ExponentLowerBound": "5a0b94e823acb335",
    "P856_T1_CoefficientGridAlignment": "811bf9ec1aa2ffd7"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
    "num_imp_dec2flt_slow_parse_long_mantissa": "a3ed147b34a97b11"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:e0a4064f7188523b2d6c28ff065a85d4e56b73f2fd8f08d57bd1c6446b0043b2",
  "current_fingerprint": "sound-v2:e0a4064f7188523b2d6c28ff065a85d4e56b73f2fd8f08d57bd1c6446b0043b2",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}