P661_T1_SlowExecution

Lean checked

Statement

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

Lemma · Unrestricted unsigned numeric slow execution

Every source-valid byte slice s rendering an unsigned valid numeric lexeme x has a normal actual slow-converter return: \exists fp,\ \mathrm{P9\_T1\_ActualDispatchOperations.slow}(s) =\mathrm{ok}(fp). There is no A/B bound, public reachability condition, or successful-slow premise. The conclusion is existence only, not a claim that a synthetic endpoint equals the true decimal magnitude.

Lean statement

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

import Tablet.P495_T1_DecimalSeqReconstruction
import Tablet.P529_T1_RegularSlowExecution
import Tablet.ParserExponentConstants
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Mathlib.Tactic.Linarith

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_SlowExecution]
theorem P661_T1_SlowExecution (s : Slice Std.U8) (x : DecimalLexeme)
    (hsource : SourceValidByteSlice s) (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hbytes : DecimalGoalVocabularyDefault.renderNumeric x =
      DecimalGoalVocabularyDefault.bytes s) :
    exists fp : num.imp.dec2flt.common.BiasedFp,
      P9_T1_ActualDispatchOperations.slow s = ok fp := 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 DecimalSeqReconstruction with precisely the source-validity, absent-leading-sign, validity and rendering hypotheses. It constructs an actual normal parse to d, count r\le768, all-array digit values below ten, and the equivalence C=[]\iff r=0, where C is the leading-zero-stripped full significand. For nonempty C, it also supplies a digit h with 1\le h<10 and stored head value h.
Unfold the slow field of ActualDispatchOperations and num imp dec2flt slow parse long mantissa. ParserExponentConstants supplies its normal infinite-power call with I32 value 2047 at the same binary64 Float instance. num imp dec2flt common BiasedFp zero pow2 normally constructs the initial (0,0) and (0,2047) pairs. Substitute the reconstructed parse equation at the next bind. If r=0, equality of Usize values identifies the count with Usize zero and the source returns the zero pair. If r>0 and the I32 point p<-324, its next comparison returns the zero pair; if p\ge310, the subsequent comparison returns the infinity pair. The comparisons are total, use representable I32 constants, and require no loop or arithmetic side condition. These exits cover zero and both initial point cutoffs directly in source order.
Otherwise 0<r\le768 and -324\le p<310. The fixed array type gives length 768 under the existing width of Assumptions. Consequently taking r cells and mapping their values produces a list D of length exactly r, hence a nonempty list z::t. The all-array digit bound restricts to every cell of that take. Since r>0, its head is the array's first cell. The reconstruction equivalence excludes C=[], so the reconstructed stored head is h, forcing z=h. Thus 1\le z<10, |z::t|=r, and the count, cell, head and exact-length clauses are exactly the input-shape hypotheses of RegularSlowExecution.
Let V be that principal's retained decimal value of d and \epsilon=10^{p-768}>0. Set Y=V+\epsilon. When d.\mathit{truncated} is false, put \eta=0 and X=V; when it is true, put \eta=\epsilon/2 and X=V+\epsilon/2. In both cases X=V+\eta, 0\le\eta<\epsilon, and d.\mathit{truncated}=\mathrm{true}\iff0<\eta; for the true case these are immediate from 0<\epsilon/2<\epsilon. All premises of the regular execution principal now hold without reference to the true lexeme magnitude and without assuming a slow result. Applying that principal constructs fp with the actual normal slow equation; project its first conjunct and discard its synthetic-X rounding certificate. That first conjunct is precisely this lemma's conclusion. Together with the direct exits this covers the unrestricted source-valid unsigned numeric domain. True-magnitude correctness, when needed later, must be obtained from the separate on-normal contract, not by identifying this chosen X with the lexeme value.

Lean proof


  obtain ⟨d, scan, n, f, e, hparse, hn, hnval, hfval, heval, hnlen,
    hflen, hslen, hfinal, hpoint, hcount, hcap, hprefix, htrunc,
    hscanpoint, hscantrunc, hscanprefix, hkeep, hfill, hall,
    hzero, hzeroinfo, hhead⟩ :=
    P495_T1_DecimalSeqReconstruction s x hsource hsign hvalid hbytes
  obtain ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hconstants⟩ :=
    ParserExponentConstants
  have hinf' :
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.traitsFloatExtInst.FloatInst.INFINITE_POWER =
        ok 2047#i32 := hinf
  have early (hz : d.num_digits.val = 0 ∨ d.decimal_point.val < -324 ∨
      310 <= d.decimal_point.val) :
      exists fp, P9_T1_ActualDispatchOperations.slow s = ok fp := by
    change exists fp, num.imp.dec2flt.slow.parse_long_mantissa
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.traitsFloatExtInst.FloatInst s = ok fp
    unfold num.imp.dec2flt.slow.parse_long_mantissa
    rw [hinf']
    simp only [bind_tc_ok, num.imp.dec2flt.common.BiasedFp.zero_pow2]
    rw [hparse]
    simp only [bind_tc_ok]
    rcases hz with hz | hlow | hhigh
    · have hz' : d.num_digits = 0#usize := UScalar.eq_of_val_eq hz
      simp only [hz', if_true]
      exact ⟨_, rfl⟩
    · by_cases hz' : d.num_digits = 0#usize
      · simp only [hz', if_true]
        exact ⟨_, rfl⟩
      · have hlow' : d.decimal_point < (-324)#i32 := hlow
        simp only [hz', if_false, hlow', if_true]
        exact ⟨_, rfl⟩
    · by_cases hz' : d.num_digits = 0#usize
      · simp only [hz', if_true]
        exact ⟨_, rfl⟩
      · by_cases hlow' : d.decimal_point < (-324)#i32
        · simp only [hz', if_false, hlow', if_true]
          exact ⟨_, rfl⟩
        · have hhigh' : d.decimal_point >= 310#i32 := hhigh
          simp only [hz', if_false, hlow', hhigh', if_true]
          exact ⟨_, rfl⟩
  by_cases hz : d.num_digits.val = 0
  · exact early (Or.inl hz)
  by_cases hlow : d.decimal_point.val < -324
  · exact early (Or.inr (Or.inl hlow))
  by_cases hhigh : 310 <= d.decimal_point.val
  · exact early (Or.inr (Or.inr hhigh))
  have hpositive : 0 < d.num_digits.val := by omega
  have hCne :
      (x.integerDigits ++ (match x.fractionDigits with | none => [] | some ds => ds)).dropWhile
        (fun z => z == 0) ≠ [] := by
    intro hnil
    exact hz (hzero.mp hnil)
  obtain ⟨head, hChead, hheadlo, hheadhi, hstored⟩ := hhead hCne
  let digits := (d.digits.val.take d.num_digits.val).map (fun b => b.val)
  have harray : d.digits.val.length = 768 := by simpa using d.digits.property
  have hlen : digits.length = d.num_digits.val := by
    simp only [digits, List.length_map, List.length_take, harray]
    exact Nat.min_eq_left hcap
  have hne : digits ≠ [] := by
    intro hnil
    rw [hnil] at hlen
    simp only [List.length_nil] at hlen
    omega
  obtain ⟨z, tail, hshape⟩ := List.exists_cons_of_ne_nil hne
  have hfirst : digits.head? = some head := by
    rw [List.head?_eq_getElem?]
    simp only [digits, List.getElem?_map, List.getElem?_take, if_pos hpositive]
    exact hstored
  have hzhead : z = head := by
    rw [hshape] at hfirst
    simpa using hfirst
  have 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) := by
    refine ⟨hcap, ?_, z, tail, hshape, ?_, ?_, ?_⟩
    · intro b hb
      exact hall b (List.mem_of_mem_take hb)
    · simpa [hzhead] using hheadlo
    · simpa [hzhead] using hheadhi
    · rw [← hshape]
      exact hlen
  let V : Real :=
    ((((d.digits.val.take d.num_digits.val).map (fun b => b.val)).foldl
      (fun n z => 10 * n + z) 0 : Nat) : Real) *
      (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int))
  let eps : Real := (10 : Real) ^ (d.decimal_point.val - 768)
  have heps : 0 < eps := zpow_pos (by norm_num) _
  have hwitness : exists X Y eta : Real,
      Y = V + eps /\ X = V + eta /\ 0 <= eta /\ eta < eps /\
      (d.truncated = true <-> 0 < eta) := by
    cases ht : d.truncated with
    | false =>
      refine ⟨V, V + eps, 0, rfl, by simp, le_rfl, heps, ?_⟩
      simp
    | true =>
      refine ⟨V + eps / 2, V + eps, eps / 2, rfl, rfl, ?_, ?_, ?_⟩
      all_goals first | linarith | (simp only [true_iff]; linarith)
  obtain ⟨X, Y, eta, hY, hX, heta0, hetaHi, hsticky⟩ := hwitness
  obtain ⟨fp, hfp, hrest⟩ := P529_T1_RegularSlowExecution s X Y d hparse
    (by omega) (by omega) hinput hY ⟨eta, hX, heta0, hetaHi, hsticky⟩
  exact ⟨fp, hfp⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P495_T1_DecimalSeqReconstruction
import Tablet.P529_T1_RegularSlowExecution
import Tablet.ParserExponentConstants
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Mathlib.Tactic.Linarith

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_SlowExecution]
theorem P661_T1_SlowExecution (s : Slice Std.U8) (x : DecimalLexeme)
    (hsource : SourceValidByteSlice s) (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hbytes : DecimalGoalVocabularyDefault.renderNumeric x =
      DecimalGoalVocabularyDefault.bytes s) :
    exists fp : num.imp.dec2flt.common.BiasedFp,
      P9_T1_ActualDispatchOperations.slow s = ok fp := by
-- BODY
  obtain ⟨d, scan, n, f, e, hparse, hn, hnval, hfval, heval, hnlen,
    hflen, hslen, hfinal, hpoint, hcount, hcap, hprefix, htrunc,
    hscanpoint, hscantrunc, hscanprefix, hkeep, hfill, hall,
    hzero, hzeroinfo, hhead⟩ :=
    P495_T1_DecimalSeqReconstruction s x hsource hsign hvalid hbytes
  obtain ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hconstants⟩ :=
    ParserExponentConstants
  have hinf' :
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.traitsFloatExtInst.FloatInst.INFINITE_POWER =
        ok 2047#i32 := hinf
  have early (hz : d.num_digits.val = 0 ∨ d.decimal_point.val < -324 ∨
      310 <= d.decimal_point.val) :
      exists fp, P9_T1_ActualDispatchOperations.slow s = ok fp := by
    change exists fp, num.imp.dec2flt.slow.parse_long_mantissa
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.traitsFloatExtInst.FloatInst s = ok fp
    unfold num.imp.dec2flt.slow.parse_long_mantissa
    rw [hinf']
    simp only [bind_tc_ok, num.imp.dec2flt.common.BiasedFp.zero_pow2]
    rw [hparse]
    simp only [bind_tc_ok]
    rcases hz with hz | hlow | hhigh
    · have hz' : d.num_digits = 0#usize := UScalar.eq_of_val_eq hz
      simp only [hz', if_true]
      exact ⟨_, rfl⟩
    · by_cases hz' : d.num_digits = 0#usize
      · simp only [hz', if_true]
        exact ⟨_, rfl⟩
      · have hlow' : d.decimal_point < (-324)#i32 := hlow
        simp only [hz', if_false, hlow', if_true]
        exact ⟨_, rfl⟩
    · by_cases hz' : d.num_digits = 0#usize
      · simp only [hz', if_true]
        exact ⟨_, rfl⟩
      · by_cases hlow' : d.decimal_point < (-324)#i32
        · simp only [hz', if_false, hlow', if_true]
          exact ⟨_, rfl⟩
        · have hhigh' : d.decimal_point >= 310#i32 := hhigh
          simp only [hz', if_false, hlow', hhigh', if_true]
          exact ⟨_, rfl⟩
  by_cases hz : d.num_digits.val = 0
  · exact early (Or.inl hz)
  by_cases hlow : d.decimal_point.val < -324
  · exact early (Or.inr (Or.inl hlow))
  by_cases hhigh : 310 <= d.decimal_point.val
  · exact early (Or.inr (Or.inr hhigh))
  have hpositive : 0 < d.num_digits.val := by omega
  have hCne :
      (x.integerDigits ++ (match x.fractionDigits with | none => [] | some ds => ds)).dropWhile
        (fun z => z == 0) ≠ [] := by
    intro hnil
    exact hz (hzero.mp hnil)
  obtain ⟨head, hChead, hheadlo, hheadhi, hstored⟩ := hhead hCne
  let digits := (d.digits.val.take d.num_digits.val).map (fun b => b.val)
  have harray : d.digits.val.length = 768 := by simpa using d.digits.property
  have hlen : digits.length = d.num_digits.val := by
    simp only [digits, List.length_map, List.length_take, harray]
    exact Nat.min_eq_left hcap
  have hne : digits ≠ [] := by
    intro hnil
    rw [hnil] at hlen
    simp only [List.length_nil] at hlen
    omega
  obtain ⟨z, tail, hshape⟩ := List.exists_cons_of_ne_nil hne
  have hfirst : digits.head? = some head := by
    rw [List.head?_eq_getElem?]
    simp only [digits, List.getElem?_map, List.getElem?_take, if_pos hpositive]
    exact hstored
  have hzhead : z = head := by
    rw [hshape] at hfirst
    simpa using hfirst
  have 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) := by
    refine ⟨hcap, ?_, z, tail, hshape, ?_, ?_, ?_⟩
    · intro b hb
      exact hall b (List.mem_of_mem_take hb)
    · simpa [hzhead] using hheadlo
    · simpa [hzhead] using hheadhi
    · rw [← hshape]
      exact hlen
  let V : Real :=
    ((((d.digits.val.take d.num_digits.val).map (fun b => b.val)).foldl
      (fun n z => 10 * n + z) 0 : Nat) : Real) *
      (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int))
  let eps : Real := (10 : Real) ^ (d.decimal_point.val - 768)
  have heps : 0 < eps := zpow_pos (by norm_num) _
  have hwitness : exists X Y eta : Real,
      Y = V + eps /\ X = V + eta /\ 0 <= eta /\ eta < eps /\
      (d.truncated = true <-> 0 < eta) := by
    cases ht : d.truncated with
    | false =>
      refine ⟨V, V + eps, 0, rfl, by simp, le_rfl, heps, ?_⟩
      simp
    | true =>
      refine ⟨V + eps / 2, V + eps, eps / 2, rfl, rfl, ?_, ?_, ?_⟩
      all_goals first | linarith | (simp only [true_iff]; linarith)
  obtain ⟨X, Y, eta, hY, hX, heta0, hetaHi, hsticky⟩ := hwitness
  obtain ⟨fp, hfp, hrest⟩ := P529_T1_RegularSlowExecution s X Y d hparse
    (by omega) (by omega) hinput hY ⟨eta, hX, heta0, hetaHi, hsticky⟩
  exact ⟨fp, hfp⟩

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 240 entries
Technical checking records
Local closure summary
{
  "node": "P661_T1_SlowExecution",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "afecc862962b9854b31ea4e7a16b0ade9607d049511f5a47d6844783d446f482",
  "active_statement_hash": "27913b6060d70a111417154bb6352828c0d8780a5c93596dabb3ee8c414e0731",
  "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": {
    "P495_T1_DecimalSeqReconstruction": "393ebac809bfdedd",
    "P529_T1_RegularSlowExecution": "401420802ff70ad0",
    "ParserExponentConstants": "e2a30a7b0c5e9c91",
    "num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f3e5cc6a65d812e",
    "num_imp_dec2flt_slow_parse_long_mantissa": "a4d13e23fad8f54e",
    "num_imp_traits_Float_EXP_BIAS_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_BITS_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_EXP_MIN_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_SAT_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "e78adeb2dfab360a",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "250be645520aec86",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS": "d9fd91641cb78c5e",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "P495_T1_DecimalSeqReconstruction": "55eb6bce0e8a4131",
    "P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
    "P9_T1_DispatchOperations": "9a657a317bca572b",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f99ae12c6707137",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_round": "8ea3c058fea09978",
    "num_imp_dec2flt_decimal_seq_final_decimal_point": "4f8088dec06d629a",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "f7442f2664cfd5f2",
    "num_imp_dec2flt_slow_parse_long_mantissa": "b1ccfebea6d0fad3",
    "num_imp_traits_Float": "c984d3e2bb33a27e",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
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:176d0983a35275ef7fd232a7d53c97d9591b9f6174013890332d5ead048ec971",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}