P826_T1_LeftBodySelector

Lean checked

Statement

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

Helper · Recovering a successful loop-1 continuation

Let d have decimal point at most zero, let its leading stored digit be z\in[1,10), and suppose one extracted loop-1 body evaluation at exponent e successfully continues with record d' and exponent e', retaining an empty early-result field. Then there is a machine-natural shift k\leq60 such that the extracted left shift of d by k returns d' and
e'=e-k.
Moreover, exactly the applicable selector description is exposed: if the point is negative, there is a machine natural n=-p on which the extracted slow-shift selector returns k; otherwise p=0, z<5, and k=2 for z=1 while k=1 for z\ne1.

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
import Tablet.P804_T1_LeftLoopStep

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_LeftBodySelector]
theorem P826_T1_LeftBodySelector
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (e e' : Std.I32) (z : Nat)
    (hp : d.decimal_point.val <= 0)
    (hzLo : 1 <= z) (hzHi : z < 10)
    (hhead : d.digits.val[0].val = z)
    (hbody :
      num.imp.dec2flt.slow.parse_long_mantissa_loop1.body
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#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 shift : Std.Usize,
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d' /\
      shift.val <= 60 /\
      e'.val = e.val - (shift.val : Int) /\
      ((d.decimal_point.val < 0 /\
          exists n : 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) \/
        (d.decimal_point.val = 0 /\ z < 5 /\
          shift = if z = 1 then 2#usize else 1#usize)) := 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

Unfold the loop-1 body in num imp dec2flt slow parse long mantissa. The point hypothesis and empty result select the normalization branch. If the point is zero, invert the array read at index zero. Its returned byte is the stated leading digit z. A successful continuation excludes the exit test z\ge5. The three literal byte-match cases then give shift two for z=1 (the zero case contradicts z\ge1) and shift one otherwise.
If the point is negative, invert the checked negation and cast; their value specifications give the machine natural n with integer value -p. Invert the extracted selector call to obtain its returned shift k. In either point case, continue inverting the monadic body: the left-shift result must be d', since the alternative point-overflow branch stores a nonempty infinity result, whereas the assumed continuation stores none. Finally invert the checked cast of k and checked exponent subtraction. The selector certificate SlowShiftSelectorCertificate gives k\le60, so the cast has integer value k, and the subtraction result is exactly e-k. These inversions establish every conjunct of the claim.

Lean proof


  let chooseShift (u : Std.U8) : Result Std.Usize :=
    match u with
    | 0#uscalar => ok 2#usize
    | 1#uscalar => ok 2#usize
    | _ => ok 1#usize
  have chooseShift_eq (u : Std.U8) :
      (match u with
        | 0#uscalar => ok 2#usize
        | 1#uscalar => ok 2#usize
        | _ => ok 1#usize) = chooseShift u := by
    rfl
  have choose_spec (u : Std.U8) (w : Nat)
      (hwLo : 1 <= w) (hwHi : w < 5) (hw : u.val = w) :
      chooseShift u =
        ok (if w = 1 then 2#usize else 1#usize) := by
    have hwCases : w = 1 \/ w = 2 \/ w = 3 \/ w = 4 := by omega
    rcases hwCases with rfl | rfl | rfl | rfl
    · have hu : u = 1#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
    · have hu : u = 2#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
    · have hu : u = 3#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
    · have hu : u = 4#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
  unfold num.imp.dec2flt.slow.parse_long_mantissa_loop1.body at hbody
  have hple : d.decimal_point <= 0#i32 := by
    change d.decimal_point.val <= 0
    omega
  simp only [hple, if_true, core.option.Option.is_none] at hbody
  simp only [show (none : Option num.imp.dec2flt.common.BiasedFp).isNone =
    true by rfl, if_true] at hbody
  by_cases hp0 : d.decimal_point.val = 0
  · have hpeq : d.decimal_point = 0#i32 :=
      IScalar.eq_of_val_eq (by simpa using hp0)
    rw [hpeq] at hbody
    simp only [if_true] at hbody
    cases hread : Array.index_usize d.digits 0#usize with
    | fail err => simp [hread] at hbody
    | div => simp [hread] at hbody
    | ok head =>
      rw [hread] at hbody
      simp only [bind_tc_ok] at hbody
      have hheadEq : head.val = z := by
        have hs := Array.index_usize_spec d.digits 0#usize (by
          simp [Array.length])
        rw [hread] at hs
        simp only [WP.spec_ok] at hs
        rw [← hhead]
        congr
      have hnotge : ¬ head >= 5#u8 := by
        by_contra hge
        simp [hge] at hbody
      simp only [hnotge, if_false] at hbody
      have hdZeroEta :
          ({ num_digits := d.num_digits,
             decimal_point := 0#i32,
             truncated := d.truncated,
             digits := d.digits } :
            num.imp.dec2flt.decimal_seq.DecimalSeq) = d := by
        rw [← hpeq]
      rw [hdZeroEta] at hbody
      let State := Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp
      have finish (shift : Std.Usize) (hshift60 : shift.val <= 60)
          (hselect : shift = if z = 1 then 2#usize else 1#usize)
          (htail :
            (do
              let q ←
                num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift
              if q.decimal_point >
                  num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
              then
                ok (cont (q.num_digits, q.decimal_point, q.truncated,
                  q.digits, e,
                  some ({ m := 0#u64, p_biased := 2047#i32 } :
                    num.imp.dec2flt.common.BiasedFp)) : ControlFlow State State)
              else
                let shiftI ← lift (UScalar.hcast .I32 shift)
                let eout ← e - shiftI
                ok (cont (q.num_digits, q.decimal_point, q.truncated,
                  q.digits, eout, none) : ControlFlow State State)) =
              ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
                d'.digits, e', none) : ControlFlow State State)) :
          exists shift : Std.Usize,
            num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d' /\
            shift.val <= 60 /\
            e'.val = e.val - (shift.val : Int) /\
            ((d.decimal_point.val < 0 /\
                exists n : 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) \/
              (d.decimal_point.val = 0 /\ z < 5 /\
                shift = if z = 1 then 2#usize else 1#usize)) := by
        cases hleft :
            num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift with
        | fail err => simp [hleft] at htail
        | div => simp [hleft] at htail
        | ok q =>
          rw [hleft] at htail
          simp only [bind_tc_ok] at htail
          by_cases hover : q.decimal_point >
              num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
          · simp only [hover, if_true] at htail
            have hstate := Result.ok.inj htail
            have htuple := ControlFlow.cont.inj hstate
            have hopt := congrArg (fun x : State => x.2.2.2.2.2) htuple
            simp at hopt
          · simp only [hover, if_false] at htail
            let shiftI : Std.I32 := UScalar.hcast .I32 shift
            rw [show UScalar.hcast .I32 shift = shiftI by rfl] at htail
            simp only [lift, bind_tc_ok] at htail
            cases hsub : e - shiftI with
            | fail err => simp [hsub] at htail
            | div => simp [hsub] at htail
            | ok eout =>
              rw [hsub] at htail
              simp only [bind_tc_ok] at htail
              have hstate := Result.ok.inj htail
              have htuple := ControlFlow.cont.inj hstate
              have hq : q = d' := by
                have hnum := congrArg (fun x : State => x.1) htuple
                have hpnt := congrArg (fun x : State => x.2.1) htuple
                have htr := congrArg (fun x : State => x.2.2.1) htuple
                have hdig := congrArg (fun x : State => x.2.2.2.1) htuple
                cases q
                cases d'
                simp_all only
              have heout : eout = e' :=
                congrArg (fun x : State => x.2.2.2.2.1) htuple
              subst q
              subst eout
              have hcast := UScalar.hcast_inBounds_spec .I32 shift (by
                rw [IScalar.max_I32_eq]
                omega)
              simp only [lift, WP.spec_ok] at hcast
              have hsubVal := IScalar.sub_equiv e shiftI
              rw [hsub] at hsubVal
              refine ⟨shift, hleft, hshift60, ?_, Or.inr ⟨hp0, ?_,
                hselect⟩⟩
              · rw [hsubVal.2.1]
                simpa [shiftI] using hcast
              · change ¬ head.val >= 5 at hnotge
                omega
      split at hbody
      · change 0 = z at hheadEq
        omega
      · have hz1 : z = 1 := by
          change 1 = z at hheadEq
          omega
        simp only [bind_tc_ok] at hbody
        exact finish 2#usize (by norm_num) (by rw [hz1]; rfl) hbody
      · have hz1 : z ≠ 1 := by
          intro hz
          have hu : head = 1#u8 := by
            apply UScalar.eq_of_val_eq
            rw [hheadEq, hz]
            norm_num [UScalar.cast_val_eq]
          contradiction
        simp only [bind_tc_ok] at hbody
        exact finish 1#usize (by norm_num) (by simp only [if_neg hz1]) hbody
  · have hpneg : d.decimal_point.val < 0 := by omega
    have hpne : ¬ d.decimal_point = 0#i32 := by
      intro h
      have := congrArg IScalar.val h
      simp at this
      omega
    simp only [hpne, if_false] at hbody
    cases hneg : -. d.decimal_point with
    | fail err => simp [hneg] at hbody
    | div => simp [hneg] at hbody
    | ok negp =>
      rw [hneg] at hbody
      simp only [bind_tc_ok, lift] at hbody
      let n : Std.Usize := IScalar.hcast .Usize negp
      rw [show IScalar.hcast .Usize negp = n by rfl] at hbody
      cases hsel :
          num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
      | fail err => simp [hsel] at hbody
      | div => simp [hsel] at hbody
      | ok shift =>
        rw [hsel] at hbody
        simp only [bind_tc_ok] at hbody
        cases hleft : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift with
        | fail err => simp [hleft] at hbody
        | div => simp [hleft] at hbody
        | ok q =>
          rw [hleft] at hbody
          simp only [bind_tc_ok] at hbody
          by_cases hover : q.decimal_point >
              num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
          · simp [hover] at hbody
          · simp only [hover, if_false, lift] at hbody
            let shiftI : Std.I32 := UScalar.hcast .I32 shift
            rw [show UScalar.hcast .I32 shift = shiftI by rfl] at hbody
            cases hsub : e - shiftI with
            | fail err => simp [hsub] at hbody
            | div => simp [hsub] at hbody
            | ok eout =>
              rw [hsub] at hbody
              simp only [bind_tc_ok] at hbody
              have hstate := Result.ok.inj hbody
              simp only [ControlFlow.cont.injEq, Prod.mk.injEq] at hstate
              have hq : q = d' := by
                cases q
                cases d'
                simp only [num.imp.dec2flt.decimal_seq.DecimalSeq.mk.injEq]
                tauto
              have heout : eout = e' := by tauto
              subst q
              subst eout
              have hcert := SlowShiftSelectorCertificate
                F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n
              let k : Std.Usize := match n.val with
                | 0 => 0#usize | 1 => 3#usize | 2 => 6#usize
                | 3 => 9#usize | 4 => 13#usize | 5 => 16#usize
                | 6 => 19#usize | 7 => 23#usize | 8 => 26#usize
                | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
                | 12 => 39#usize | 13 => 43#usize | 14 => 46#usize
                | 15 => 49#usize | 16 => 53#usize | 17 => 56#usize
                | 18 => 59#usize | _ => 60#usize
              change _ = ok k /\ k.val <= 60 /\ _ at hcert
              have hk : k = shift := Result.ok.inj (hcert.1.symm.trans hsel)
              rw [hk] at hcert
              change IScalar.neg d.decimal_point = ok negp at hneg
              unfold IScalar.neg at hneg
              have hnegVal := IScalar.tryMk_eq .I32
                (-d.decimal_point.val)
              rw [hneg] at hnegVal
              have hnval := IScalar.hcast_inBounds_spec .Usize negp (by
                rw [hnegVal.1]
                constructor <;> scalar_tac)
              simp only [lift, WP.spec_ok] at hnval
              have hnInt : (n.val : Int) = -d.decimal_point.val := by
                simpa [n, hnegVal.1] using hnval
              have hcast := UScalar.hcast_inBounds_spec .I32 shift (by
                rw [IScalar.max_I32_eq]
                omega)
              simp only [lift, WP.spec_ok] at hcast
              have hsubVal := IScalar.sub_equiv e shiftI
              rw [hsub] at hsubVal
              refine ⟨shift, hleft, hcert.2.1, ?_, Or.inl ⟨hpneg, n,
                hnInt, hsel⟩⟩
              rw [hsubVal.2.1]
              simpa [shiftI] using hcast

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P826_T1_RightBodySelector
import Tablet.P804_T1_LeftLoopStep

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_LeftBodySelector]
theorem P826_T1_LeftBodySelector
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (e e' : Std.I32) (z : Nat)
    (hp : d.decimal_point.val <= 0)
    (hzLo : 1 <= z) (hzHi : z < 10)
    (hhead : d.digits.val[0].val = z)
    (hbody :
      num.imp.dec2flt.slow.parse_long_mantissa_loop1.body
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#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 shift : Std.Usize,
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d' /\
      shift.val <= 60 /\
      e'.val = e.val - (shift.val : Int) /\
      ((d.decimal_point.val < 0 /\
          exists n : 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) \/
        (d.decimal_point.val = 0 /\ z < 5 /\
          shift = if z = 1 then 2#usize else 1#usize)) := by
-- BODY
  let chooseShift (u : Std.U8) : Result Std.Usize :=
    match u with
    | 0#uscalar => ok 2#usize
    | 1#uscalar => ok 2#usize
    | _ => ok 1#usize
  have chooseShift_eq (u : Std.U8) :
      (match u with
        | 0#uscalar => ok 2#usize
        | 1#uscalar => ok 2#usize
        | _ => ok 1#usize) = chooseShift u := by
    rfl
  have choose_spec (u : Std.U8) (w : Nat)
      (hwLo : 1 <= w) (hwHi : w < 5) (hw : u.val = w) :
      chooseShift u =
        ok (if w = 1 then 2#usize else 1#usize) := by
    have hwCases : w = 1 \/ w = 2 \/ w = 3 \/ w = 4 := by omega
    rcases hwCases with rfl | rfl | rfl | rfl
    · have hu : u = 1#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
    · have hu : u = 2#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
    · have hu : u = 3#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
    · have hu : u = 4#u8 := UScalar.eq_of_val_eq (by simpa using hw)
      subst u
      rfl
  unfold num.imp.dec2flt.slow.parse_long_mantissa_loop1.body at hbody
  have hple : d.decimal_point <= 0#i32 := by
    change d.decimal_point.val <= 0
    omega
  simp only [hple, if_true, core.option.Option.is_none] at hbody
  simp only [show (none : Option num.imp.dec2flt.common.BiasedFp).isNone =
    true by rfl, if_true] at hbody
  by_cases hp0 : d.decimal_point.val = 0
  · have hpeq : d.decimal_point = 0#i32 :=
      IScalar.eq_of_val_eq (by simpa using hp0)
    rw [hpeq] at hbody
    simp only [if_true] at hbody
    cases hread : Array.index_usize d.digits 0#usize with
    | fail err => simp [hread] at hbody
    | div => simp [hread] at hbody
    | ok head =>
      rw [hread] at hbody
      simp only [bind_tc_ok] at hbody
      have hheadEq : head.val = z := by
        have hs := Array.index_usize_spec d.digits 0#usize (by
          simp [Array.length])
        rw [hread] at hs
        simp only [WP.spec_ok] at hs
        rw [← hhead]
        congr
      have hnotge : ¬ head >= 5#u8 := by
        by_contra hge
        simp [hge] at hbody
      simp only [hnotge, if_false] at hbody
      have hdZeroEta :
          ({ num_digits := d.num_digits,
             decimal_point := 0#i32,
             truncated := d.truncated,
             digits := d.digits } :
            num.imp.dec2flt.decimal_seq.DecimalSeq) = d := by
        rw [← hpeq]
      rw [hdZeroEta] at hbody
      let State := Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp
      have finish (shift : Std.Usize) (hshift60 : shift.val <= 60)
          (hselect : shift = if z = 1 then 2#usize else 1#usize)
          (htail :
            (do
              let q ←
                num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift
              if q.decimal_point >
                  num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
              then
                ok (cont (q.num_digits, q.decimal_point, q.truncated,
                  q.digits, e,
                  some ({ m := 0#u64, p_biased := 2047#i32 } :
                    num.imp.dec2flt.common.BiasedFp)) : ControlFlow State State)
              else
                let shiftI ← lift (UScalar.hcast .I32 shift)
                let eout ← e - shiftI
                ok (cont (q.num_digits, q.decimal_point, q.truncated,
                  q.digits, eout, none) : ControlFlow State State)) =
              ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
                d'.digits, e', none) : ControlFlow State State)) :
          exists shift : Std.Usize,
            num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d' /\
            shift.val <= 60 /\
            e'.val = e.val - (shift.val : Int) /\
            ((d.decimal_point.val < 0 /\
                exists n : 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) \/
              (d.decimal_point.val = 0 /\ z < 5 /\
                shift = if z = 1 then 2#usize else 1#usize)) := by
        cases hleft :
            num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift with
        | fail err => simp [hleft] at htail
        | div => simp [hleft] at htail
        | ok q =>
          rw [hleft] at htail
          simp only [bind_tc_ok] at htail
          by_cases hover : q.decimal_point >
              num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
          · simp only [hover, if_true] at htail
            have hstate := Result.ok.inj htail
            have htuple := ControlFlow.cont.inj hstate
            have hopt := congrArg (fun x : State => x.2.2.2.2.2) htuple
            simp at hopt
          · simp only [hover, if_false] at htail
            let shiftI : Std.I32 := UScalar.hcast .I32 shift
            rw [show UScalar.hcast .I32 shift = shiftI by rfl] at htail
            simp only [lift, bind_tc_ok] at htail
            cases hsub : e - shiftI with
            | fail err => simp [hsub] at htail
            | div => simp [hsub] at htail
            | ok eout =>
              rw [hsub] at htail
              simp only [bind_tc_ok] at htail
              have hstate := Result.ok.inj htail
              have htuple := ControlFlow.cont.inj hstate
              have hq : q = d' := by
                have hnum := congrArg (fun x : State => x.1) htuple
                have hpnt := congrArg (fun x : State => x.2.1) htuple
                have htr := congrArg (fun x : State => x.2.2.1) htuple
                have hdig := congrArg (fun x : State => x.2.2.2.1) htuple
                cases q
                cases d'
                simp_all only
              have heout : eout = e' :=
                congrArg (fun x : State => x.2.2.2.2.1) htuple
              subst q
              subst eout
              have hcast := UScalar.hcast_inBounds_spec .I32 shift (by
                rw [IScalar.max_I32_eq]
                omega)
              simp only [lift, WP.spec_ok] at hcast
              have hsubVal := IScalar.sub_equiv e shiftI
              rw [hsub] at hsubVal
              refine ⟨shift, hleft, hshift60, ?_, Or.inr ⟨hp0, ?_,
                hselect⟩⟩
              · rw [hsubVal.2.1]
                simpa [shiftI] using hcast
              · change ¬ head.val >= 5 at hnotge
                omega
      split at hbody
      · change 0 = z at hheadEq
        omega
      · have hz1 : z = 1 := by
          change 1 = z at hheadEq
          omega
        simp only [bind_tc_ok] at hbody
        exact finish 2#usize (by norm_num) (by rw [hz1]; rfl) hbody
      · have hz1 : z ≠ 1 := by
          intro hz
          have hu : head = 1#u8 := by
            apply UScalar.eq_of_val_eq
            rw [hheadEq, hz]
            norm_num [UScalar.cast_val_eq]
          contradiction
        simp only [bind_tc_ok] at hbody
        exact finish 1#usize (by norm_num) (by simp only [if_neg hz1]) hbody
  · have hpneg : d.decimal_point.val < 0 := by omega
    have hpne : ¬ d.decimal_point = 0#i32 := by
      intro h
      have := congrArg IScalar.val h
      simp at this
      omega
    simp only [hpne, if_false] at hbody
    cases hneg : -. d.decimal_point with
    | fail err => simp [hneg] at hbody
    | div => simp [hneg] at hbody
    | ok negp =>
      rw [hneg] at hbody
      simp only [bind_tc_ok, lift] at hbody
      let n : Std.Usize := IScalar.hcast .Usize negp
      rw [show IScalar.hcast .Usize negp = n by rfl] at hbody
      cases hsel :
          num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
      | fail err => simp [hsel] at hbody
      | div => simp [hsel] at hbody
      | ok shift =>
        rw [hsel] at hbody
        simp only [bind_tc_ok] at hbody
        cases hleft : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift with
        | fail err => simp [hleft] at hbody
        | div => simp [hleft] at hbody
        | ok q =>
          rw [hleft] at hbody
          simp only [bind_tc_ok] at hbody
          by_cases hover : q.decimal_point >
              num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
          · simp [hover] at hbody
          · simp only [hover, if_false, lift] at hbody
            let shiftI : Std.I32 := UScalar.hcast .I32 shift
            rw [show UScalar.hcast .I32 shift = shiftI by rfl] at hbody
            cases hsub : e - shiftI with
            | fail err => simp [hsub] at hbody
            | div => simp [hsub] at hbody
            | ok eout =>
              rw [hsub] at hbody
              simp only [bind_tc_ok] at hbody
              have hstate := Result.ok.inj hbody
              simp only [ControlFlow.cont.injEq, Prod.mk.injEq] at hstate
              have hq : q = d' := by
                cases q
                cases d'
                simp only [num.imp.dec2flt.decimal_seq.DecimalSeq.mk.injEq]
                tauto
              have heout : eout = e' := by tauto
              subst q
              subst eout
              have hcert := SlowShiftSelectorCertificate
                F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n
              let k : Std.Usize := match n.val with
                | 0 => 0#usize | 1 => 3#usize | 2 => 6#usize
                | 3 => 9#usize | 4 => 13#usize | 5 => 16#usize
                | 6 => 19#usize | 7 => 23#usize | 8 => 26#usize
                | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
                | 12 => 39#usize | 13 => 43#usize | 14 => 46#usize
                | 15 => 49#usize | 16 => 53#usize | 17 => 56#usize
                | 18 => 59#usize | _ => 60#usize
              change _ = ok k /\ k.val <= 60 /\ _ at hcert
              have hk : k = shift := Result.ok.inj (hcert.1.symm.trans hsel)
              rw [hk] at hcert
              change IScalar.neg d.decimal_point = ok negp at hneg
              unfold IScalar.neg at hneg
              have hnegVal := IScalar.tryMk_eq .I32
                (-d.decimal_point.val)
              rw [hneg] at hnegVal
              have hnval := IScalar.hcast_inBounds_spec .Usize negp (by
                rw [hnegVal.1]
                constructor <;> scalar_tac)
              simp only [lift, WP.spec_ok] at hnval
              have hnInt : (n.val : Int) = -d.decimal_point.val := by
                simpa [n, hnegVal.1] using hnval
              have hcast := UScalar.hcast_inBounds_spec .I32 shift (by
                rw [IScalar.max_I32_eq]
                omega)
              simp only [lift, WP.spec_ok] at hcast
              have hsubVal := IScalar.sub_equiv e shiftI
              rw [hsub] at hsubVal
              refine ⟨shift, hleft, hcert.2.1, ?_, Or.inl ⟨hpneg, n,
                hnInt, hsel⟩⟩
              rw [hsubVal.2.1]
              simpa [shiftI] using hcast

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 102 entries
Technical checking records
Local closure summary
{
  "node": "P826_T1_LeftBodySelector",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "1e710d940b1810991a730f3111c006e451ec61be1d7a472f90e673920497d171",
  "active_statement_hash": "2c34045ab60b4750e52196725b38dfb3abb310a8e06258f37b0191e3cb01804d",
  "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": "revalidate-cycle-194",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "SlowShiftSelectorCertificate": "963b7a2e670856e8",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "3c283430b9003d37",
    "num_imp_dec2flt_slow_parse_long_mantissa": "0eb6fb2627d0ff5c"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "SlowShiftSelectorCertificate": "7ebc2b39d69850c4",
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "eaf981d0a5d9f472",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "0cc5155758bc976a",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_slow_parse_long_mantissa": "c03771a4216d102f",
    "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:e183667c7947bcbb1a5f8822517f92f6d36b0ea4d0c6bca169198289f6630811",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}