P529_T1_ReachableCapacity

Lean checked

Statement

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

Lemma · History-based capacity before final rounding

Let the original record d have positive exact-length decimal shape, count at most 768 and -324\le p<310, and let X=V(d)+\eta, Y=V(d)+10^{p-768}, 0\le\eta<10^{p-768}, sticky iff \eta>0. Follow the actual specialized loop-zero and loop-one equations to (d_0,e_0,\mathsf{none}) and (d_1,e_1,\mathsf{none}). For any I32 e_2 with e_2=\max(e_1-1,-1022),
0\le e_2-e_0+715-p_0 .

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_NormalizationBounds
import Tablet.P529_T1_RightHistoryBoundary
import Tablet.P856_T1_DecimalBinaryExponentBound
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_ReachableCapacity]
theorem P529_T1_ReachableCapacity (X Y : Real)
    (d d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 exp1 exp2 : 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))
    (hexp2 : exp2.val = max (exp1.val - 1) (-1022)) :
    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)) ->
    0 <= exp2.val - exp0.val + 715 - d0.decimal_point.val := 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

SlowLoop0Execution, identified with the given equation, supplies -324\le p_0\le0, positive decimal shape, e_0\ge0 and the endpoint equations at d_0. NormalizationBounds supplies X<Y and Y\le2^{e_1}. The exponent hypothesis gives e_2\ge-1022 and e_2\ge e_1-1.
If p_0\le-307, it is negative and RightHistoryBoundary gives e_0=0 for this exact loop-zero history. Hence e_2-e_0+715-p_0\ge-1022+715+307=0.
Otherwise -306\le p_0\le0. DecimalValueBounds gives 10^{p_0-1}\le V(d_0) from its positive head and exact length. Its loop-zero error is nonnegative, so
10^{p_0-1}\le V(d_0)\le X/2^{e_0} <Y/2^{e_0}\le2^{e_1-e_0}.
The strict middle inequality uses X<Y and positivity of 2^{e_0}. DecimalBinaryExponentBound at p_0,e_1-e_0 now gives p_0\le e_1-e_0+714. Combine this with e_2\ge e_1-1 to get p_0\le e_2-e_0+715, the required capacity. This calculation uses the actual negative loop-zero exit and the original endpoint bound, not just the retained count or an uncorrelated step budget.

Lean proof


  dsimp only
  intro hY hX
  obtain ⟨d0', exp0', steps, hloop0', hsteps, hexp0lo, hexp0hi,
    hXlo, hp0lo, hp0hi, hcount0, hdigits0, hshape0, hlast0, herror0⟩ :=
    P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput hY hX
  have hloop0eq := hloop0'
  rw [hloop0] at hloop0eq
  injection hloop0eq with htuple
  have hd0eq : d0' = d0 := by
    cases d0'
    cases d0
    simp_all
  have hexp0eq : exp0' = exp0 := by
    simp_all
  subst d0'
  subst exp0'
  have hnorm := P529_T1_NormalizationBounds X Y d d0 d1 exp0 exp1
    hpointLo hpointHi hinput hloop0 hloop1 hY hX
  rcases hnorm with ⟨_, hXltY, hYnorm, _, _⟩
  have hboundary := P529_T1_RightHistoryBoundary X Y d d0 exp0
    hpointLo hpointHi hinput hloop0 hY hX
  by_cases hpneg : d0.decimal_point.val ≤ -307
  · have he0zero : exp0.val = 0 := hboundary.1 (by omega)
    rw [hexp2]
    omega
  · have hp0lo' : -306 ≤ d0.decimal_point.val := by omega
    have hdigits : ∀ q, q ∈
        (d0.digits.val.take d0.num_digits.val).map (fun b => b.val) → q < 10 := by
      intro q hq
      obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hq
      exact hdigits0 b hb
    obtain ⟨head, tail, hshape, hheadlo, hheadhi, hlen⟩ := hshape0
    let xs : List Nat :=
      (d0.digits.val.take d0.num_digits.val).map (fun b => b.val)
    have hvalue := P472_T1_DecimalValueBounds xs head tail hshape
      hheadlo hdigits d0.decimal_point.val
    have hval : (10 : Real) ^ (d0.decimal_point.val - 1) ≤
        ((((d0.digits.val.take d0.num_digits.val).map (fun b => b.val)).foldl
          (fun n z => 10 * n + z) 0 : Nat) : Real) *
          (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) := by
      have hpowpos : 0 < (10 : Real) ^ (d0.decimal_point.val -
          (d0.num_digits.val : Int)) := zpow_pos (by norm_num) _
      have hone : (1 : Real) ≤ (head : Real) := by exact_mod_cast hheadlo
      calc
        (10 : Real) ^ (d0.decimal_point.val - 1) =
            (1 : Real) * (10 : Real) ^ (d0.decimal_point.val - 1) := by ring
        _ ≤ (head : Real) * (10 : Real) ^ (d0.decimal_point.val - 1) :=
          mul_le_mul_of_nonneg_right hone (le_of_lt (zpow_pos (by norm_num) _))
        _ ≤ ((xs.foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
            (10 : Real) ^ (d0.decimal_point.val - (xs.length : Int)) := hvalue.1
        _ = ((((d0.digits.val.take d0.num_digits.val).map
              (fun b => b.val)).foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
            (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) := by
          simp [xs, hshape, hlen]
    obtain ⟨eta0, u0, hXscaled, _, heta0, _, _⟩ := herror0
    have hVle :
        ((((d0.digits.val.take d0.num_digits.val).map (fun b => b.val)).foldl
          (fun n z => 10 * n + z) 0 : Nat) : Real) *
          (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) ≤
        X / (2 : Real) ^ exp0.val := by
      rw [hXscaled]
      exact le_add_of_nonneg_right heta0
    have hden0 : 0 < (2 : Real) ^ exp0.val :=
      zpow_pos (by norm_num : (0 : Real) < 2) _
    have hden1 : 0 < (2 : Real) ^ exp1.val :=
      zpow_pos (by norm_num : (0 : Real) < 2) _
    have hYle : Y ≤ (2 : Real) ^ exp1.val := by
      have htmp := (div_le_iff₀ hden1).mp hYnorm
      simpa using htmp
    have hYscaled : Y / (2 : Real) ^ exp0.val ≤
        (2 : Real) ^ (exp1.val - exp0.val) := by
      have hdiv := div_le_div_of_nonneg_right hYle (le_of_lt hden0)
      calc
        Y / (2 : Real) ^ exp0.val ≤
            (2 : Real) ^ exp1.val / (2 : Real) ^ exp0.val := hdiv
        _ = (2 : Real) ^ (exp1.val - exp0.val) := by
          rw [← zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)]
    have hpow : (10 : Real) ^ (d0.decimal_point.val - 1) <
        (2 : Real) ^ (exp1.val - exp0.val) := by
      calc
        (10 : Real) ^ (d0.decimal_point.val - 1) ≤
            ((((d0.digits.val.take d0.num_digits.val).map (fun b => b.val)).foldl
              (fun n z => 10 * n + z) 0 : Nat) : Real) *
              (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) := hval
        _ ≤ X / (2 : Real) ^ exp0.val := hVle
        _ < Y / (2 : Real) ^ exp0.val :=
          div_lt_div_of_pos_right hXltY hden0
        _ ≤ (2 : Real) ^ (exp1.val - exp0.val) := hYscaled
    have hpbound := P856_T1_DecimalBinaryExponentBound
      d0.decimal_point.val (exp1.val - exp0.val) hp0lo' hp0hi hpow
    rw [hexp2]
    omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P529_T1_NormalizationBounds
import Tablet.P529_T1_RightHistoryBoundary
import Tablet.P856_T1_DecimalBinaryExponentBound
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_ReachableCapacity]
theorem P529_T1_ReachableCapacity (X Y : Real)
    (d d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 exp1 exp2 : 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))
    (hexp2 : exp2.val = max (exp1.val - 1) (-1022)) :
    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)) ->
    0 <= exp2.val - exp0.val + 715 - d0.decimal_point.val := by
-- BODY
  dsimp only
  intro hY hX
  obtain ⟨d0', exp0', steps, hloop0', hsteps, hexp0lo, hexp0hi,
    hXlo, hp0lo, hp0hi, hcount0, hdigits0, hshape0, hlast0, herror0⟩ :=
    P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput hY hX
  have hloop0eq := hloop0'
  rw [hloop0] at hloop0eq
  injection hloop0eq with htuple
  have hd0eq : d0' = d0 := by
    cases d0'
    cases d0
    simp_all
  have hexp0eq : exp0' = exp0 := by
    simp_all
  subst d0'
  subst exp0'
  have hnorm := P529_T1_NormalizationBounds X Y d d0 d1 exp0 exp1
    hpointLo hpointHi hinput hloop0 hloop1 hY hX
  rcases hnorm with ⟨_, hXltY, hYnorm, _, _⟩
  have hboundary := P529_T1_RightHistoryBoundary X Y d d0 exp0
    hpointLo hpointHi hinput hloop0 hY hX
  by_cases hpneg : d0.decimal_point.val ≤ -307
  · have he0zero : exp0.val = 0 := hboundary.1 (by omega)
    rw [hexp2]
    omega
  · have hp0lo' : -306 ≤ d0.decimal_point.val := by omega
    have hdigits : ∀ q, q ∈
        (d0.digits.val.take d0.num_digits.val).map (fun b => b.val) → q < 10 := by
      intro q hq
      obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hq
      exact hdigits0 b hb
    obtain ⟨head, tail, hshape, hheadlo, hheadhi, hlen⟩ := hshape0
    let xs : List Nat :=
      (d0.digits.val.take d0.num_digits.val).map (fun b => b.val)
    have hvalue := P472_T1_DecimalValueBounds xs head tail hshape
      hheadlo hdigits d0.decimal_point.val
    have hval : (10 : Real) ^ (d0.decimal_point.val - 1) ≤
        ((((d0.digits.val.take d0.num_digits.val).map (fun b => b.val)).foldl
          (fun n z => 10 * n + z) 0 : Nat) : Real) *
          (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) := by
      have hpowpos : 0 < (10 : Real) ^ (d0.decimal_point.val -
          (d0.num_digits.val : Int)) := zpow_pos (by norm_num) _
      have hone : (1 : Real) ≤ (head : Real) := by exact_mod_cast hheadlo
      calc
        (10 : Real) ^ (d0.decimal_point.val - 1) =
            (1 : Real) * (10 : Real) ^ (d0.decimal_point.val - 1) := by ring
        _ ≤ (head : Real) * (10 : Real) ^ (d0.decimal_point.val - 1) :=
          mul_le_mul_of_nonneg_right hone (le_of_lt (zpow_pos (by norm_num) _))
        _ ≤ ((xs.foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
            (10 : Real) ^ (d0.decimal_point.val - (xs.length : Int)) := hvalue.1
        _ = ((((d0.digits.val.take d0.num_digits.val).map
              (fun b => b.val)).foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
            (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) := by
          simp [xs, hshape, hlen]
    obtain ⟨eta0, u0, hXscaled, _, heta0, _, _⟩ := herror0
    have hVle :
        ((((d0.digits.val.take d0.num_digits.val).map (fun b => b.val)).foldl
          (fun n z => 10 * n + z) 0 : Nat) : Real) *
          (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) ≤
        X / (2 : Real) ^ exp0.val := by
      rw [hXscaled]
      exact le_add_of_nonneg_right heta0
    have hden0 : 0 < (2 : Real) ^ exp0.val :=
      zpow_pos (by norm_num : (0 : Real) < 2) _
    have hden1 : 0 < (2 : Real) ^ exp1.val :=
      zpow_pos (by norm_num : (0 : Real) < 2) _
    have hYle : Y ≤ (2 : Real) ^ exp1.val := by
      have htmp := (div_le_iff₀ hden1).mp hYnorm
      simpa using htmp
    have hYscaled : Y / (2 : Real) ^ exp0.val ≤
        (2 : Real) ^ (exp1.val - exp0.val) := by
      have hdiv := div_le_div_of_nonneg_right hYle (le_of_lt hden0)
      calc
        Y / (2 : Real) ^ exp0.val ≤
            (2 : Real) ^ exp1.val / (2 : Real) ^ exp0.val := hdiv
        _ = (2 : Real) ^ (exp1.val - exp0.val) := by
          rw [← zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)]
    have hpow : (10 : Real) ^ (d0.decimal_point.val - 1) <
        (2 : Real) ^ (exp1.val - exp0.val) := by
      calc
        (10 : Real) ^ (d0.decimal_point.val - 1) ≤
            ((((d0.digits.val.take d0.num_digits.val).map (fun b => b.val)).foldl
              (fun n z => 10 * n + z) 0 : Nat) : Real) *
              (10 : Real) ^ (d0.decimal_point.val - (d0.num_digits.val : Int)) := hval
        _ ≤ X / (2 : Real) ^ exp0.val := hVle
        _ < Y / (2 : Real) ^ exp0.val :=
          div_lt_div_of_pos_right hXltY hden0
        _ ≤ (2 : Real) ^ (exp1.val - exp0.val) := hYscaled
    have hpbound := P856_T1_DecimalBinaryExponentBound
      d0.decimal_point.val (exp1.val - exp0.val) hp0lo' hp0hi hpow
    rw [hexp2]
    omega

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 151 entries
Technical checking records
Local closure summary
{
  "node": "P529_T1_ReachableCapacity",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "67e0a346f9ad039f1d293f4b569563cfeca12fa592dba703fba58333db1beac2",
  "active_statement_hash": "98ff20fc5b938edb6c5eb9a58c021c1a57523b81c210c95c32a95464e463205d",
  "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_NormalizationBounds": "deb4bf7513f18e80",
    "P529_T1_RightHistoryBoundary": "2f9292b355b28e68",
    "P856_T1_DecimalBinaryExponentBound": "c090950acf612415"
  },
  "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:3dd28d9a05936d23ebad1e4195b3a098bb628ea541f345aaf6c3a7aef79068bf",
  "current_fingerprint": "sound-v2:3dd28d9a05936d23ebad1e4195b3a098bb628ea541f345aaf6c3a7aef79068bf",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}