P826_T1_RightHistoryBoundary

Lean checked

Statement

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

Helper · Boundary order through a reachable loop-0 history

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 A,B\in\mathbb R, let d,d_0,d_1 be decimal records, and let e_{\rm in},e_0,e_1 be signed machine exponents; in formulas, each exponent denotes its signed integer value. Assume
-324\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 such that
D(d)=z::z_s,qquad1\leq z<10,qquad |D(d)|=d.\mathsf{num\_digits}.\mathsf{val}. \tag{S}
Assume also that there are \eta,u\in\mathbb R satisfying
A/2^{e_{\rm in}}=V(d)+\eta,qquad B/2^{e_{\rm in}}=V(d)+u,qquad 0\leq\eta<u,qquad (d.\mathsf{truncated}=\mathsf{true}\Longleftrightarrow0<\eta). \tag{E}
Suppose the exact extracted loop-0 call, with the zero biased-float sentinel and no early result, from (d,e_{\rm in},\mathsf{none}) returns (d_0,e_0,\mathsf{none}). Fix d_1,e_1 and assume
0\leq e_1-e_0+768-d_0.p,\qquad 2^{e_1-e_0}\leq V(d_0)\Longrightarrow1\leq V(d_1). \tag{1}
Then
0\leq e_1-e_{\rm in}+768-d.p,\qquad 2^{e_1-e_{\rm in}}\leq V(d)\Longrightarrow1\leq V(d_1). \tag{2}

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_ResultLoopBackward
import Tablet.P826_T1_RightDoneCertificate
import Tablet.P826_T1_RightStepCertificate
import Tablet.P826_T1_RightCapacityStep
import Tablet.P826_T1_PowerGridAlignment
import Tablet.P798_T1_RightBoundaryTransport
import Tablet.P804_T1_DecimalValueBounds

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_RightHistoryBoundary]
theorem P826_T1_RightHistoryBoundary
    (A B : Real)
    (d d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (ein e0 e1 : Std.I32)
    (hpLo : -324 <= d.decimal_point.val)
    (hpHi : d.decimal_point.val < 310)
    (hshape :
      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,
        A / (2 : Real) ^ ein.val = V + eta /\
        B / (2 : Real) ^ ein.val = V + u /\
        0 <= eta /\ eta < u /\ (d.truncated = true <-> 0 < eta))
    (hloop :
      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 ein none =
          ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits,
            e0, none))
    (hbase :
      let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
        (q.digits.val.take q.num_digits.val).map (fun w => w.val)
      let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
        ((Digits q).foldl (fun n w => 10 * n + w) 0 : Nat) *
          (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
      0 <= e1.val - e0.val + 768 - d0.decimal_point.val /\
      ((2 : Real) ^ (e1.val - e0.val) <= Value d0 -> 1 <= Value d1)) :
    let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      (q.digits.val.take q.num_digits.val).map (fun w => w.val)
    let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((Digits q).foldl (fun n w => 10 * n + w) 0 : Nat) *
        (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
    0 <= e1.val - ein.val + 768 - d.decimal_point.val /\
      ((2 : Real) ^ (e1.val - ein.val) <= Value d -> 1 <= Value d1) := 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

Use ResultLoopBackward on the exact extracted loop-0 history, taking (1) as the terminal certificate. A successful done body is classified by RightDoneCertificate: it returns the unchanged record and exponent and has nonpositive point. Thus its desired certificate is exactly the supplied terminal one. As in loop 1, unfolding the option branch shows backwards that a final \mathsf{none} result forces every current result to be \mathsf{none}.
For a continuing state, the body equation itself forces the current point to be positive. Apply RightStepCertificate to expose the exact selector input n=d.p, right shift k, update e'=e+k, output point clauses, digit shape, and scaled endpoint equations. Those clauses preserve -324\leq d'.p<310, and division by 2^k plus the exponent update converts the endpoint equations to exponent e'. The induction hypothesis therefore applies at (d',e').
By RightCapacityStep, d.p-d'.p\leq k. Consequently
e_1-e+768-d.p =(e_1-e'+768-d'.p)+k-(d.p-d'.p)\geq0,
which proves the capacity part at the predecessor.
For order, output capacity and PowerGridAlignment give a natural b with
2^{e_1-e'}=b10^{d'.p-768}. \tag{3}
The lower half of DecimalValueBounds gives V(d)>0 from the positive leading digit. Since e'=e+k,
2^{e_1-e'}=2^{e_1-e}/2^k.
Thus 2^{e_1-e}\leq V(d) places the boundary (3) below V(d)/2^k. The output digit list is nonempty, hence its count is positive, so it cannot be the all-zero reset record. Apply RightBoundaryTransport to the exact right shift. Its aligned-grid argument invokes GridAlignment and the strict loss reduction GridBoundaryRetained, yielding 2^{e_1-e'}\leq V(d'). The induction hypothesis now gives 1\leq V(d_1). Backward induction reaches the supplied initial state and proves both clauses of (2).

Lean proof


  dsimp only at hshape hend hbase ⊢
  classical
  let State := Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
    Std.I32 × Option num.imp.dec2flt.common.BiasedFp
  let recordOf : State -> num.imp.dec2flt.decimal_seq.DecimalSeq := fun x =>
    { num_digits := x.1, decimal_point := x.2.1, truncated := x.2.2.1,
      digits := x.2.2.2.1 }
  let exponentOf : State -> Std.I32 := fun x => x.2.2.2.2.1
  let resultOf : State -> Option num.imp.dec2flt.common.BiasedFp := fun x =>
    x.2.2.2.2.2
  let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    (q.digits.val.take q.num_digits.val).map (fun w => w.val)
  let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    ((Digits q).foldl (fun n w => 10 * n + w) 0 : Nat) *
      (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
  let Shape := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    q.num_digits.val <= 768 /\
    (forall w, w ∈ q.digits.val.take q.num_digits.val -> w.val < 10) /\
    (exists z zs, Digits q = z :: zs /\ 1 <= z /\ z < 10 /\
      (Digits q).length = q.num_digits.val)
  let Endpoints := fun (q : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (e : Std.I32) =>
    exists eta u : Real,
      A / (2 : Real) ^ e.val = Value q + eta /\
      B / (2 : Real) ^ e.val = Value q + u /\
      0 <= eta /\ eta < u /\ (q.truncated = true <-> 0 < eta)
  let Body := fun x : State =>
    num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#i32 }
      x.1 x.2.1 x.2.2.1 x.2.2.2.1 x.2.2.2.2.1 x.2.2.2.2.2
  let Base := fun y : State =>
    resultOf y = none /\
    0 <= e1.val - (exponentOf y).val + 768 -
      (recordOf y).decimal_point.val /\
    ((2 : Real) ^ (e1.val - (exponentOf y).val) <= Value (recordOf y) ->
      1 <= Value d1)
  let Rel := fun (x y : State) =>
    Base y -> resultOf x = none /\
    (-324 <= (recordOf x).decimal_point.val ->
      (recordOf x).decimal_point.val < 310 ->
      Shape (recordOf x) -> Endpoints (recordOf x) (exponentOf x) ->
      0 <= e1.val - (exponentOf x).val + 768 -
        (recordOf x).decimal_point.val /\
      ((2 : Real) ^ (e1.val - (exponentOf x).val) <= Value (recordOf x) ->
        1 <= Value d1))
  have hrel : Rel
      (d.num_digits, d.decimal_point, d.truncated, d.digits, ein, none)
      (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, e0, none) := by
    apply P826_T1_ResultLoopBackward Rel Body
    · intro x y hbody
      rcases x with ⟨i, p, t, a, e, lr⟩
      rcases y with ⟨iy, py, ty, ay, ey, lry⟩
      simp only [Rel, Base, resultOf, recordOf, exponentOf]
      intro hbaseY
      rcases hbaseY with ⟨hy, hcapY, horderY⟩
      rw [hy] at hbody
      have hx : lr = none := by
        cases lr with
        | none => rfl
        | some v =>
          simp only [Body] at hbody
          unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
          by_cases hp : p > 0#i32 <;> simp [hp] at hbody
      subst lr
      refine ⟨rfl, ?_⟩
      intro hpLoX hpHiX hshapeX hendX
      have hdone := P826_T1_RightDoneCertificate
        { num_digits := i, decimal_point := p, truncated := t, digits := a }
        { num_digits := iy, decimal_point := py, truncated := ty, digits := ay }
        e ey (by simpa [Body] using hbody)
      rcases hdone with ⟨hdy, hey, hpDone⟩
      have hpEq : py.val = p.val := by
        exact congrArg (fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
          q.decimal_point.val) hdy
      subst ey
      constructor
      · rw [hpEq] at hcapY
        exact hcapY
      · intro horder
        apply horderY
        rw [hdy]
        exact horder
    · intro x x' y hbody ih
      rcases x with ⟨i, p, t, a, e, lr⟩
      rcases x' with ⟨i', p', t', a', e', lr'⟩
      rcases y with ⟨iy, py, ty, ay, ey, lry⟩
      simp only [Rel, Base, resultOf, recordOf, exponentOf] at ih ⊢
      intro hbaseY
      have hi := ih hbaseY
      rcases hi with ⟨hx'none, hi⟩
      have hxnone : lr = none := by
        cases lr with
        | none => rfl
        | some v =>
          simp only [Body] at hbody
          unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
          by_cases hp : p > 0#i32 <;> simp [hp] at hbody
      subst lr
      subst lr'
      refine ⟨rfl, ?_⟩
      intro hpLoX hpHiX hshapeX hendX
      have hpPos : 1 <= p.val := by
        by_contra h
        simp only [Body] at hbody
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
        have hpnot : ¬ p > 0#i32 := by
          change ¬ p.val > 0
          omega
        simp [hpnot] at hbody
      simp only [Shape, Digits] at hshapeX
      simp only [Endpoints, Value, Digits] at hendX
      obtain ⟨z0, zs0, hshape0X, hz0Lo, hz0Hi, hlen0X⟩ := hshapeX.2.2
      obtain ⟨n, shift, hn, hsel, hright, hk, heq, hlarge, hsmall, hout⟩ :=
        P826_T1_RightStepCertificate
          (A / (2 : Real) ^ e.val) (B / (2 : Real) ^ e.val)
          { num_digits := i, decimal_point := p, truncated := t, digits := a }
          { num_digits := i', decimal_point := p', truncated := t', digits := a' }
          e e' hpPos hpHiX hshapeX hendX (by simpa [Body] using hbody)
      change (19 <= p.val -> p'.val = p.val - 18 \/
        p'.val = p.val - 19) at hlarge
      change (p.val <= 18 -> p'.val = 0 \/ p'.val = 1) at hsmall
      dsimp only at hout
      rcases hout with ⟨hcap', hdigit', hpositive', hend'⟩
      have hp'Lo : -324 <= p'.val := by
        by_cases hp19 : 19 <= p.val
        · rcases hlarge hp19 with h | h <;> omega
        · rcases hsmall (by omega) with h | h <;> omega
      have hp'Hi : p'.val < 310 := by
        by_cases hp19 : 19 <= p.val
        · rcases hlarge hp19 with h | h <;> omega
        · rcases hsmall (by omega) with h | h <;> omega
      have hshape' : Shape
          { num_digits := i', decimal_point := p', truncated := t',
            digits := a' } := by
        simp only [Shape, Digits]
        exact ⟨hcap', hdigit', hpositive'⟩
      have hscaleA :
          (A / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val =
            A / (2 : Real) ^ e'.val := by
        rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        norm_num only [zpow_natCast]
        rw [div_div]
      have hscaleB :
          (B / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val =
            B / (2 : Real) ^ e'.val := by
        rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        norm_num only [zpow_natCast]
        rw [div_div]
      have hendNext : Endpoints
          { num_digits := i', decimal_point := p', truncated := t',
            digits := a' } e' := by
        simp only [Endpoints, Value, Digits]
        rcases hend' with ⟨eta, u, hA, hB, heta, hetau, hsticky⟩
        refine ⟨eta, u, ?_, ?_, heta, hetau, hsticky⟩
        · rw [← hscaleA]
          exact hA
        · rw [← hscaleB]
          exact hB
      have hnext := hi hp'Lo hp'Hi hshape' hendNext
      rcases hnext with ⟨hcapNext, horderNext⟩
      have hdrop := P826_T1_RightCapacityStep p.val p'.val n shift hpPos
        hn hsel hlarge hsmall
      constructor
      · omega
      · intro horder
        obtain ⟨b, hb⟩ := P826_T1_PowerGridAlignment
          (e1.val - e'.val) p'.val (by omega) hcapNext
        let dx : num.imp.dec2flt.decimal_seq.DecimalSeq :=
          { num_digits := i, decimal_point := p, truncated := t, digits := a }
        have hvaluePos : 0 < Value
            { num_digits := i, decimal_point := p, truncated := t,
              digits := a } := by
          have hv := P804_T1_DecimalValueBounds (Digits dx) z0 zs0
            (by simpa [dx, Digits] using hshape0X) hz0Lo (by
              intro q hq
              simp only [dx, Digits, List.mem_map] at hq
              rcases hq with ⟨q8, hq8, rfl⟩
              exact hshapeX.2.1 q8 hq8) p.val
          have hvlow := hv.1
          have hpow : 0 < (z0 : Real) * (10 : Real) ^ (p.val - 1) :=
            mul_pos (by exact_mod_cast hz0Lo)
              (zpow_pos (by norm_num : (0 : Real) < 10) _)
          change 0 < Value dx
          simp only [Value, dx, Digits]
          rw [hlen0X] at hvlow
          nlinarith
        have hnonreset : ¬ (i'.val = 0 /\ p'.val = 0 /\ t' = false) := by
          intro hr
          rcases hpositive' with ⟨w, ws, hw, hwLo, hwHi, hwlen⟩
          have hlenPos : 0 <
              ((a'.val.take i'.val).map (fun q => q.val)).length := by
            rw [hw]
            simp
          omega
        have hpowScale :
            (2 : Real) ^ (e1.val - e'.val) =
              (2 : Real) ^ (e1.val - e.val) /
                (2 : Real) ^ shift.val := by
          rw [heq]
          rw [show e1.val - (e.val + (shift.val : Int)) =
            (e1.val - e.val) - (shift.val : Int) by omega]
          rw [zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)]
          norm_num only [zpow_natCast]
        have hboundary :
            (b : Real) * (10 : Real) ^ (p'.val - 768) <=
              Value dx / (2 : Real) ^ shift.val := by
          rw [← hb, hpowScale]
          exact div_le_div_of_nonneg_right (by simpa [dx] using horder)
            (le_of_lt (pow_pos (by norm_num : (0 : Real) < 2) _))
        have htransport := P798_T1_RightBoundaryTransport
          dx
          { num_digits := i', decimal_point := p', truncated := t', digits := a' }
          shift b hk (by
            simpa [dx, Value, Digits, List.map_take] using hvaluePos)
          (by simpa [dx] using hshapeX.2.1)
          (by simpa [dx] using hright) hnonreset hcap' hboundary
        apply horderNext
        rw [hb]
        exact htransport
    · unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0 at hloop
      simpa [Body] using hloop
  simp only [Rel, Base, resultOf, recordOf, exponentOf] at hrel
  have h := hrel ⟨trivial, hbase⟩
  rcases h with ⟨_, hmain⟩
  have hmain' := hmain hpLo hpHi (by simpa [Shape, Digits] using hshape)
    (by simpa [Endpoints, Value, Digits] using hend)
  simpa [Value, Digits] using hmain'

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P826_T1_ResultLoopBackward
import Tablet.P826_T1_RightDoneCertificate
import Tablet.P826_T1_RightStepCertificate
import Tablet.P826_T1_RightCapacityStep
import Tablet.P826_T1_PowerGridAlignment
import Tablet.P798_T1_RightBoundaryTransport
import Tablet.P804_T1_DecimalValueBounds

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_RightHistoryBoundary]
theorem P826_T1_RightHistoryBoundary
    (A B : Real)
    (d d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (ein e0 e1 : Std.I32)
    (hpLo : -324 <= d.decimal_point.val)
    (hpHi : d.decimal_point.val < 310)
    (hshape :
      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,
        A / (2 : Real) ^ ein.val = V + eta /\
        B / (2 : Real) ^ ein.val = V + u /\
        0 <= eta /\ eta < u /\ (d.truncated = true <-> 0 < eta))
    (hloop :
      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 ein none =
          ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits,
            e0, none))
    (hbase :
      let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
        (q.digits.val.take q.num_digits.val).map (fun w => w.val)
      let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
        ((Digits q).foldl (fun n w => 10 * n + w) 0 : Nat) *
          (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
      0 <= e1.val - e0.val + 768 - d0.decimal_point.val /\
      ((2 : Real) ^ (e1.val - e0.val) <= Value d0 -> 1 <= Value d1)) :
    let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      (q.digits.val.take q.num_digits.val).map (fun w => w.val)
    let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((Digits q).foldl (fun n w => 10 * n + w) 0 : Nat) *
        (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
    0 <= e1.val - ein.val + 768 - d.decimal_point.val /\
      ((2 : Real) ^ (e1.val - ein.val) <= Value d -> 1 <= Value d1) := by
-- BODY
  dsimp only at hshape hend hbase ⊢
  classical
  let State := Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
    Std.I32 × Option num.imp.dec2flt.common.BiasedFp
  let recordOf : State -> num.imp.dec2flt.decimal_seq.DecimalSeq := fun x =>
    { num_digits := x.1, decimal_point := x.2.1, truncated := x.2.2.1,
      digits := x.2.2.2.1 }
  let exponentOf : State -> Std.I32 := fun x => x.2.2.2.2.1
  let resultOf : State -> Option num.imp.dec2flt.common.BiasedFp := fun x =>
    x.2.2.2.2.2
  let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    (q.digits.val.take q.num_digits.val).map (fun w => w.val)
  let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    ((Digits q).foldl (fun n w => 10 * n + w) 0 : Nat) *
      (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
  let Shape := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    q.num_digits.val <= 768 /\
    (forall w, w ∈ q.digits.val.take q.num_digits.val -> w.val < 10) /\
    (exists z zs, Digits q = z :: zs /\ 1 <= z /\ z < 10 /\
      (Digits q).length = q.num_digits.val)
  let Endpoints := fun (q : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (e : Std.I32) =>
    exists eta u : Real,
      A / (2 : Real) ^ e.val = Value q + eta /\
      B / (2 : Real) ^ e.val = Value q + u /\
      0 <= eta /\ eta < u /\ (q.truncated = true <-> 0 < eta)
  let Body := fun x : State =>
    num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#i32 }
      x.1 x.2.1 x.2.2.1 x.2.2.2.1 x.2.2.2.2.1 x.2.2.2.2.2
  let Base := fun y : State =>
    resultOf y = none /\
    0 <= e1.val - (exponentOf y).val + 768 -
      (recordOf y).decimal_point.val /\
    ((2 : Real) ^ (e1.val - (exponentOf y).val) <= Value (recordOf y) ->
      1 <= Value d1)
  let Rel := fun (x y : State) =>
    Base y -> resultOf x = none /\
    (-324 <= (recordOf x).decimal_point.val ->
      (recordOf x).decimal_point.val < 310 ->
      Shape (recordOf x) -> Endpoints (recordOf x) (exponentOf x) ->
      0 <= e1.val - (exponentOf x).val + 768 -
        (recordOf x).decimal_point.val /\
      ((2 : Real) ^ (e1.val - (exponentOf x).val) <= Value (recordOf x) ->
        1 <= Value d1))
  have hrel : Rel
      (d.num_digits, d.decimal_point, d.truncated, d.digits, ein, none)
      (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, e0, none) := by
    apply P826_T1_ResultLoopBackward Rel Body
    · intro x y hbody
      rcases x with ⟨i, p, t, a, e, lr⟩
      rcases y with ⟨iy, py, ty, ay, ey, lry⟩
      simp only [Rel, Base, resultOf, recordOf, exponentOf]
      intro hbaseY
      rcases hbaseY with ⟨hy, hcapY, horderY⟩
      rw [hy] at hbody
      have hx : lr = none := by
        cases lr with
        | none => rfl
        | some v =>
          simp only [Body] at hbody
          unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
          by_cases hp : p > 0#i32 <;> simp [hp] at hbody
      subst lr
      refine ⟨rfl, ?_⟩
      intro hpLoX hpHiX hshapeX hendX
      have hdone := P826_T1_RightDoneCertificate
        { num_digits := i, decimal_point := p, truncated := t, digits := a }
        { num_digits := iy, decimal_point := py, truncated := ty, digits := ay }
        e ey (by simpa [Body] using hbody)
      rcases hdone with ⟨hdy, hey, hpDone⟩
      have hpEq : py.val = p.val := by
        exact congrArg (fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
          q.decimal_point.val) hdy
      subst ey
      constructor
      · rw [hpEq] at hcapY
        exact hcapY
      · intro horder
        apply horderY
        rw [hdy]
        exact horder
    · intro x x' y hbody ih
      rcases x with ⟨i, p, t, a, e, lr⟩
      rcases x' with ⟨i', p', t', a', e', lr'⟩
      rcases y with ⟨iy, py, ty, ay, ey, lry⟩
      simp only [Rel, Base, resultOf, recordOf, exponentOf] at ih ⊢
      intro hbaseY
      have hi := ih hbaseY
      rcases hi with ⟨hx'none, hi⟩
      have hxnone : lr = none := by
        cases lr with
        | none => rfl
        | some v =>
          simp only [Body] at hbody
          unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
          by_cases hp : p > 0#i32 <;> simp [hp] at hbody
      subst lr
      subst lr'
      refine ⟨rfl, ?_⟩
      intro hpLoX hpHiX hshapeX hendX
      have hpPos : 1 <= p.val := by
        by_contra h
        simp only [Body] at hbody
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
        have hpnot : ¬ p > 0#i32 := by
          change ¬ p.val > 0
          omega
        simp [hpnot] at hbody
      simp only [Shape, Digits] at hshapeX
      simp only [Endpoints, Value, Digits] at hendX
      obtain ⟨z0, zs0, hshape0X, hz0Lo, hz0Hi, hlen0X⟩ := hshapeX.2.2
      obtain ⟨n, shift, hn, hsel, hright, hk, heq, hlarge, hsmall, hout⟩ :=
        P826_T1_RightStepCertificate
          (A / (2 : Real) ^ e.val) (B / (2 : Real) ^ e.val)
          { num_digits := i, decimal_point := p, truncated := t, digits := a }
          { num_digits := i', decimal_point := p', truncated := t', digits := a' }
          e e' hpPos hpHiX hshapeX hendX (by simpa [Body] using hbody)
      change (19 <= p.val -> p'.val = p.val - 18 \/
        p'.val = p.val - 19) at hlarge
      change (p.val <= 18 -> p'.val = 0 \/ p'.val = 1) at hsmall
      dsimp only at hout
      rcases hout with ⟨hcap', hdigit', hpositive', hend'⟩
      have hp'Lo : -324 <= p'.val := by
        by_cases hp19 : 19 <= p.val
        · rcases hlarge hp19 with h | h <;> omega
        · rcases hsmall (by omega) with h | h <;> omega
      have hp'Hi : p'.val < 310 := by
        by_cases hp19 : 19 <= p.val
        · rcases hlarge hp19 with h | h <;> omega
        · rcases hsmall (by omega) with h | h <;> omega
      have hshape' : Shape
          { num_digits := i', decimal_point := p', truncated := t',
            digits := a' } := by
        simp only [Shape, Digits]
        exact ⟨hcap', hdigit', hpositive'⟩
      have hscaleA :
          (A / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val =
            A / (2 : Real) ^ e'.val := by
        rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        norm_num only [zpow_natCast]
        rw [div_div]
      have hscaleB :
          (B / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val =
            B / (2 : Real) ^ e'.val := by
        rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        norm_num only [zpow_natCast]
        rw [div_div]
      have hendNext : Endpoints
          { num_digits := i', decimal_point := p', truncated := t',
            digits := a' } e' := by
        simp only [Endpoints, Value, Digits]
        rcases hend' with ⟨eta, u, hA, hB, heta, hetau, hsticky⟩
        refine ⟨eta, u, ?_, ?_, heta, hetau, hsticky⟩
        · rw [← hscaleA]
          exact hA
        · rw [← hscaleB]
          exact hB
      have hnext := hi hp'Lo hp'Hi hshape' hendNext
      rcases hnext with ⟨hcapNext, horderNext⟩
      have hdrop := P826_T1_RightCapacityStep p.val p'.val n shift hpPos
        hn hsel hlarge hsmall
      constructor
      · omega
      · intro horder
        obtain ⟨b, hb⟩ := P826_T1_PowerGridAlignment
          (e1.val - e'.val) p'.val (by omega) hcapNext
        let dx : num.imp.dec2flt.decimal_seq.DecimalSeq :=
          { num_digits := i, decimal_point := p, truncated := t, digits := a }
        have hvaluePos : 0 < Value
            { num_digits := i, decimal_point := p, truncated := t,
              digits := a } := by
          have hv := P804_T1_DecimalValueBounds (Digits dx) z0 zs0
            (by simpa [dx, Digits] using hshape0X) hz0Lo (by
              intro q hq
              simp only [dx, Digits, List.mem_map] at hq
              rcases hq with ⟨q8, hq8, rfl⟩
              exact hshapeX.2.1 q8 hq8) p.val
          have hvlow := hv.1
          have hpow : 0 < (z0 : Real) * (10 : Real) ^ (p.val - 1) :=
            mul_pos (by exact_mod_cast hz0Lo)
              (zpow_pos (by norm_num : (0 : Real) < 10) _)
          change 0 < Value dx
          simp only [Value, dx, Digits]
          rw [hlen0X] at hvlow
          nlinarith
        have hnonreset : ¬ (i'.val = 0 /\ p'.val = 0 /\ t' = false) := by
          intro hr
          rcases hpositive' with ⟨w, ws, hw, hwLo, hwHi, hwlen⟩
          have hlenPos : 0 <
              ((a'.val.take i'.val).map (fun q => q.val)).length := by
            rw [hw]
            simp
          omega
        have hpowScale :
            (2 : Real) ^ (e1.val - e'.val) =
              (2 : Real) ^ (e1.val - e.val) /
                (2 : Real) ^ shift.val := by
          rw [heq]
          rw [show e1.val - (e.val + (shift.val : Int)) =
            (e1.val - e.val) - (shift.val : Int) by omega]
          rw [zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)]
          norm_num only [zpow_natCast]
        have hboundary :
            (b : Real) * (10 : Real) ^ (p'.val - 768) <=
              Value dx / (2 : Real) ^ shift.val := by
          rw [← hb, hpowScale]
          exact div_le_div_of_nonneg_right (by simpa [dx] using horder)
            (le_of_lt (pow_pos (by norm_num : (0 : Real) < 2) _))
        have htransport := P798_T1_RightBoundaryTransport
          dx
          { num_digits := i', decimal_point := p', truncated := t', digits := a' }
          shift b hk (by
            simpa [dx, Value, Digits, List.map_take] using hvaluePos)
          (by simpa [dx] using hshapeX.2.1)
          (by simpa [dx] using hright) hnonreset hcap' hboundary
        apply horderNext
        rw [hb]
        exact htransport
    · unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0 at hloop
      simpa [Body] using hloop
  simp only [Rel, Base, resultOf, recordOf, exponentOf] at hrel
  have h := hrel ⟨trivial, hbase⟩
  rcases h with ⟨_, hmain⟩
  have hmain' := hmain hpLo hpHi (by simpa [Shape, Digits] using hshape)
    (by simpa [Endpoints, Value, Digits] using hend)
  simpa [Value, Digits] using hmain'

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 133 entries
Technical checking records
Local closure summary
{
  "node": "P826_T1_RightHistoryBoundary",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f9256003d3ce99674fa2c5fa4a064510c4497b535d46db9d7f29bf08d12f9e75",
  "active_statement_hash": "6a7bb30ca78379312cafdb8e37582bed728e46d2f3f2649dcefee51599df9e74",
  "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": {
    "P798_T1_RightBoundaryTransport": "d22f654164869df6",
    "P804_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "P826_T1_PowerGridAlignment": "0cee3aaeb64f7353",
    "P826_T1_ResultLoopBackward": "46222c89d1819e7b",
    "P826_T1_RightCapacityStep": "0d2a812defd92500",
    "P826_T1_RightDoneCertificate": "f8c284a2343da052",
    "P826_T1_RightStepCertificate": "6f0da345dd2e64cc",
    "num_imp_dec2flt_slow_parse_long_mantissa": "0eb6fb2627d0ff5c"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "0cc5155758bc976a",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_slow_parse_long_mantissa": "71d9bebe88212f80",
    "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:c0eeedabc9c58248e8fad871f891f0c81475d93926ed3d48c118ac87b897bd2d",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}