P826_T1_RightStepCertificate

Lean checked

Statement

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

Helper · Exponent-independent certificate for a loop-0 step

For a decimal record r, write r.p for r.\mathsf{decimal\_point}.\mathsf{val} and put
D(r)=\operatorname{map}(q\mapsto q.\mathsf{val}, \operatorname{take}(r.\mathsf{num\_digits}.\mathsf{val}, r.\mathsf{digits}.\mathsf{val})), \quad I(r)=\operatorname{foldl}((n,q)\mapsto10n+q,0,D(r)), \quad V(r)=I(r)10^{r.p-r.\mathsf{num\_digits}.\mathsf{val}}.
Let X,Y\in\mathbb R, let d,d' be decimal records, and let e,e' be signed machine exponents; in formulas, each exponent denotes its signed integer value. Assume
1\leq d.p<310,qquad d.\mathsf{num\_digits}.\mathsf{val}\leq768, \qquad \forall q\in\operatorname{take}(d.\mathsf{num\_digits}.\mathsf{val}, d.\mathsf{digits}.\mathsf{val}), \quad q.\mathsf{val}<10,
and assume that there are z\in\mathbb N and a list z_s with
D(d)=z::z_s,qquad1\leq z<10,qquad |D(d)|=d.\mathsf{num\_digits}.\mathsf{val}. \tag{S}
Assume there are \eta,u\in\mathbb R such that
X=V(d)+\eta,qquad Y=V(d)+u,qquad0\leq\eta<u,qquad (d.\mathsf{truncated}=\mathsf{true}\Longleftrightarrow0<\eta). \tag{E}
If the exact extracted loop-0 body call at exponent e, with the zero biased-float sentinel and early-result input \mathsf{none}, returns \mathsf{ok}(\mathsf{cont}(d',e',\mathsf{none})), then there exist machine naturals n,k such that
n.\mathsf{val}=d.p,qquad \mathsf{selector}(n)=\mathsf{ok}(k),qquad \mathsf{right\_shift}(d,k)=\mathsf{ok}(d'),qquad k.\mathsf{val}\leq60,qquad e'=e+k. \tag{R}
Here \mathsf{selector} is the extracted decimal-shift closure call. The point alternatives are
\begin{aligned} 19\leq d.p&\Longrightarrow(d'.p=d.p-18\ \vee\ d'.p=d.p-19),\\ d.p\leq18&\Longrightarrow(d'.p=0\ \vee\ d'.p=1). \end{aligned} \tag{P}
Moreover,
d'.\mathsf{num\_digits}.\mathsf{val}\leq768,qquad \forall q\in\operatorname{take}(d'.\mathsf{num\_digits}.\mathsf{val}, d'.\mathsf{digits}.\mathsf{val}), \quad q.\mathsf{val}<10,
and there are z'\in\mathbb N and a list z'_s such that
D(d')=z'::z'_s,qquad1\leq z'<10,qquad |D(d')|=d'.\mathsf{num\_digits}.\mathsf{val}. \tag{S'}
Finally, there are \eta',u'\in\mathbb R satisfying all transported output equations and remainder clauses
X/2^{k.\mathsf{val}}=V(d')+\eta',\qquad Y/2^{k.\mathsf{val}}=V(d')+u',\qquad 0\leq\eta'<u',\qquad (d'.\mathsf{truncated}=\mathsf{true}\Longleftrightarrow0<\eta'). \tag{E'}

Lean statement

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

import Tablet.P826_T1_RightBodySelector

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_RightStepCertificate]
theorem P826_T1_RightStepCertificate
    (X Y : Real) (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (e e' : Std.I32)
    (hpointLo : 1 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (hinput :
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun q => q.val)
      d.num_digits.val <= 768 /\
      (forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10) /\
      (exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
        digits.length = d.num_digits.val))
    (hend :
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun q => q.val)
      let I : Nat := digits.foldl (fun n q => 10 * n + q) 0
      let V : Real := I * (10 : Real) ^
        (d.decimal_point.val - (d.num_digits.val : Int))
      exists eta u : Real, X = V + eta /\ Y = V + u /\
        0 <= eta /\ eta < u /\ (d.truncated = true <-> 0 < eta))
    (hbody :
      num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 0#i32 }
        d.num_digits d.decimal_point d.truncated d.digits e none =
          ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
            d'.digits, e', none))) :
    exists (n shift : Std.Usize),
      (n.val : Int) = d.decimal_point.val /\
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift /\
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift = ok d' /\
      shift.val <= 60 /\
      e'.val = e.val + (shift.val : Int) /\
      (19 <= d.decimal_point.val ->
        d'.decimal_point.val = d.decimal_point.val - 18 \/
        d'.decimal_point.val = d.decimal_point.val - 19) /\
      (d.decimal_point.val <= 18 ->
        d'.decimal_point.val = 0 \/ d'.decimal_point.val = 1) /\
      (let digits' :=
        (d'.digits.val.take d'.num_digits.val).map (fun q => q.val)
       let I' : Nat := digits'.foldl (fun n q => 10 * n + q) 0
       let V' : Real := I' * (10 : Real) ^
         (d'.decimal_point.val - (d'.num_digits.val : Int))
       d'.num_digits.val <= 768 /\
       (forall q, q ∈ d'.digits.val.take d'.num_digits.val -> q.val < 10) /\
       (exists z zs, digits' = z :: zs /\ 1 <= z /\ z < 10 /\
         digits'.length = d'.num_digits.val) /\
       (exists eta' u' : Real,
         X / (2 : Real) ^ shift.val = V' + eta' /\
         Y / (2 : Real) ^ shift.val = V' + u' /\
         0 <= eta' /\ eta' < u' /\
         (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 RightBodySelector to the actual body equality. It inverts the body to give the selector input n, shift k, right-shift result d', bound k\le60, and exponent equation e'=e+k.
Apply RightLoopStep to the same X,Y,d at the synthetic exponent zero. Its exponent bounds are immediate, and it supplies a synthetic selector shift k_s, right-shift record d_s, point progress, and all output shape and endpoint clauses. Apply RightBodySelector again to that synthetic body equality. The actual and synthetic recovered selector inputs both have integer value equal to the point of d, hence are the same machine natural. Injectivity of the two successful calls of the deterministic extracted selector identifies their recovered shifts. Comparing the synthetic exponent equations e_s=0+k_s and e_s=0+k identifies the shift displayed by RightLoopStep with that recovered shift as well.
Consequently the actual and synthetic extracted right shifts have identical input and shift. Injectivity of their successful results gives d_s=d'. Substitute these record and shift equalities in the point-progress, digit, capacity, and fixed-endpoint clauses supplied by RightLoopStep; combine them with the actual selector and exponent equations from RightBodySelector. This is exactly the stated certificate.

Lean proof


  dsimp only at hinput hend
  obtain ⟨na, ka, hna, hsela, hrighta, hka60, he'a⟩ :=
    P826_T1_RightBodySelector d d' e e' (by omega) hbody
  have hsynth := P804_T1_RightLoopStep X Y d 0#i32 hpointLo hpointHi
    (by norm_num) (by norm_num) hinput hend
  rcases hsynth with ⟨ds, ks, es, read, acc, hbodys, hrights, hks60,
    hes, hlarge, hsmall, hout, hstall, hnostall⟩
  obtain ⟨nb, kb, hnb, hselb, hrightb, hkb60, hesb⟩ :=
    P826_T1_RightBodySelector d ds 0#i32 es (by omega) hbodys
  have hn : na = nb := by
    apply UScalar.eq_of_val_eq
    omega
  subst nb
  have hakb : ka = kb := Result.ok.inj (hsela.symm.trans hselb)
  subst kb
  have haks : ka = ks := by
    apply UScalar.eq_of_val_eq
    omega
  subst ka
  have hds : ds = d' := by
    rw [hrighta] at hrights
    exact (Result.ok.inj hrights).symm
  subst ds
  dsimp only at hout ⊢
  exact ⟨na, ks, hna, hsela, hrighta, hks60, he'a, hlarge, hsmall, hout⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P826_T1_RightBodySelector

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_RightStepCertificate]
theorem P826_T1_RightStepCertificate
    (X Y : Real) (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (e e' : Std.I32)
    (hpointLo : 1 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (hinput :
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun q => q.val)
      d.num_digits.val <= 768 /\
      (forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10) /\
      (exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
        digits.length = d.num_digits.val))
    (hend :
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun q => q.val)
      let I : Nat := digits.foldl (fun n q => 10 * n + q) 0
      let V : Real := I * (10 : Real) ^
        (d.decimal_point.val - (d.num_digits.val : Int))
      exists eta u : Real, X = V + eta /\ Y = V + u /\
        0 <= eta /\ eta < u /\ (d.truncated = true <-> 0 < eta))
    (hbody :
      num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 0#i32 }
        d.num_digits d.decimal_point d.truncated d.digits e none =
          ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
            d'.digits, e', none))) :
    exists (n shift : Std.Usize),
      (n.val : Int) = d.decimal_point.val /\
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift /\
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift = ok d' /\
      shift.val <= 60 /\
      e'.val = e.val + (shift.val : Int) /\
      (19 <= d.decimal_point.val ->
        d'.decimal_point.val = d.decimal_point.val - 18 \/
        d'.decimal_point.val = d.decimal_point.val - 19) /\
      (d.decimal_point.val <= 18 ->
        d'.decimal_point.val = 0 \/ d'.decimal_point.val = 1) /\
      (let digits' :=
        (d'.digits.val.take d'.num_digits.val).map (fun q => q.val)
       let I' : Nat := digits'.foldl (fun n q => 10 * n + q) 0
       let V' : Real := I' * (10 : Real) ^
         (d'.decimal_point.val - (d'.num_digits.val : Int))
       d'.num_digits.val <= 768 /\
       (forall q, q ∈ d'.digits.val.take d'.num_digits.val -> q.val < 10) /\
       (exists z zs, digits' = z :: zs /\ 1 <= z /\ z < 10 /\
         digits'.length = d'.num_digits.val) /\
       (exists eta' u' : Real,
         X / (2 : Real) ^ shift.val = V' + eta' /\
         Y / (2 : Real) ^ shift.val = V' + u' /\
         0 <= eta' /\ eta' < u' /\
         (d'.truncated = true <-> 0 < eta'))) := by
-- BODY
  dsimp only at hinput hend
  obtain ⟨na, ka, hna, hsela, hrighta, hka60, he'a⟩ :=
    P826_T1_RightBodySelector d d' e e' (by omega) hbody
  have hsynth := P804_T1_RightLoopStep X Y d 0#i32 hpointLo hpointHi
    (by norm_num) (by norm_num) hinput hend
  rcases hsynth with ⟨ds, ks, es, read, acc, hbodys, hrights, hks60,
    hes, hlarge, hsmall, hout, hstall, hnostall⟩
  obtain ⟨nb, kb, hnb, hselb, hrightb, hkb60, hesb⟩ :=
    P826_T1_RightBodySelector d ds 0#i32 es (by omega) hbodys
  have hn : na = nb := by
    apply UScalar.eq_of_val_eq
    omega
  subst nb
  have hakb : ka = kb := Result.ok.inj (hsela.symm.trans hselb)
  subst kb
  have haks : ka = ks := by
    apply UScalar.eq_of_val_eq
    omega
  subst ka
  have hds : ds = d' := by
    rw [hrighta] at hrights
    exact (Result.ok.inj hrights).symm
  subst ds
  dsimp only at hout ⊢
  exact ⟨na, ks, hna, hsela, hrighta, hks60, he'a, hlarge, hsmall, hout⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (151)
More program dependencies (109)
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 125 entries
Technical checking records
Local closure summary
{
  "node": "P826_T1_RightStepCertificate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f8699a1d19b6e3c987d4628fd22015cbdc0540e1424446e0ce811e2540c045c6",
  "active_statement_hash": "400eaa382276d970c0e12ed04ebd6ebdfc3e8f43599548ce798c99761d65f4a2",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-196",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P804_T1_RightLoopStep": "10bf9572ca2b2ae4",
    "P826_T1_RightBodySelector": "0c2042c27a728cb4"
  },
  "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_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_slow_parse_long_mantissa": "0ce7bdcf55d68c29",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "7df8a2c8e3717790"
  }
}
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:553b4d08c8edc546cd2dd2e6f47246a3ebac30cccb0ddb3be3784b8d85402609",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}