P826_T1_RightBodySelector

Lean checked

Statement

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

Helper · Recovering the exact loop-0 selector shift

Let d have positive decimal point, and suppose one extracted loop-0 body evaluation at exponent e successfully continues with record d' and exponent e', retaining an empty early-result field. Then there are machine naturals n,k such that n is exactly the integer value of the point of d, the extracted slow-shift selector returns k on n, the extracted right shift of d by k\leq60 returns d', and
e'=e+k.

Lean statement

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

import Tablet.P804_T1_RightLoopStep

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_RightBodySelector]
theorem P826_T1_RightBodySelector
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (e e' : Std.I32)
    (hp : 0 < d.decimal_point.val)
    (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) := 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-0 body in num imp dec2flt slow parse long mantissa. Positivity selects its continuation branch. Invert, in order, the checked cast of the point, the selector call, the decimal right shift, the checked negation of the decimal point limit, and the checked exponent addition. Failure, divergence, and the reset/early-result branch contradict the stated successful continuation with an empty result field; injectivity of the returned tuple identifies the right-shift result with d'. The successful cast specification identifies n with the point value. The selector bound from SlowShiftSelectorCertificate gives k\leq60, so its cast to the signed exponent type has value k. Finally the checked-add specification identifies the returned exponent value with e+k, as claimed.

Lean proof


  unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
  have hpw : d.decimal_point > 0#i32 := by
    change d.decimal_point.val > 0
    omega
  simp only [hpw, if_true, core.option.Option.is_none, lift] at hbody
  let n : Std.Usize := IScalar.hcast .Usize d.decimal_point
  rw [show IScalar.hcast .Usize d.decimal_point = n by rfl] at hbody
  simp only [bind_tc_ok] at hbody
  cases hs :
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
  | fail err => simp [hs] at hbody
  | div => simp [hs] at hbody
  | ok shift =>
    rw [hs] at hbody
    simp only [bind_tc_ok] at hbody
    cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift with
    | fail err => simp [hr] at hbody
    | div => simp [hr] at hbody
    | ok q =>
      rw [hr] at hbody
      simp only [bind_tc_ok] at hbody
      cases hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE with
      | fail err => simp [hneg] at hbody
      | div => simp [hneg] at hbody
      | ok negRange =>
        rw [hneg] at hbody
        simp only [bind_tc_ok] at hbody
        by_cases hreset : q.decimal_point < negRange
        · simp [hreset] at hbody
        · simp only [hreset, if_false] at hbody
          let shiftI : Std.I32 := UScalar.hcast .I32 shift
          rw [show UScalar.hcast .I32 shift = shiftI by rfl] at hbody
          cases ha : e + shiftI with
          | fail err => simp [ha] at hbody
          | div => simp [ha] at hbody
          | ok eout =>
            rw [ha] 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 heq : eout = e' := by tauto
            subst q
            subst eout
            have hnval := IScalar.hcast_inBounds_spec .Usize d.decimal_point
              (by scalar_tac)
            simp only [lift, WP.spec_ok] at hnval
            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
              num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
                  F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok k /\
                k.val <= 60 /\ _ at hcert
            have hk : k = shift := by
              exact Result.ok.inj (hcert.1.symm.trans hs)
            rw [hk] at hcert
            have hshift60 := hcert.2.1
            have hcval := UScalar.hcast_inBounds_spec .I32 shift
              (by rw [IScalar.max_I32_eq]; omega)
            simp only [lift, WP.spec_ok] at hcval
            have haval := IScalar.add_equiv e shiftI
            rw [ha] at haval
            refine ⟨n, shift, ?_, hs, hr, hshift60, ?_⟩
            · simpa using hnval
            · rw [haval.2.1]
              simpa using hcval

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P804_T1_RightLoopStep

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P826_T1_RightBodySelector]
theorem P826_T1_RightBodySelector
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (e e' : Std.I32)
    (hp : 0 < d.decimal_point.val)
    (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) := by
-- BODY
  unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hbody
  have hpw : d.decimal_point > 0#i32 := by
    change d.decimal_point.val > 0
    omega
  simp only [hpw, if_true, core.option.Option.is_none, lift] at hbody
  let n : Std.Usize := IScalar.hcast .Usize d.decimal_point
  rw [show IScalar.hcast .Usize d.decimal_point = n by rfl] at hbody
  simp only [bind_tc_ok] at hbody
  cases hs :
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
  | fail err => simp [hs] at hbody
  | div => simp [hs] at hbody
  | ok shift =>
    rw [hs] at hbody
    simp only [bind_tc_ok] at hbody
    cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift with
    | fail err => simp [hr] at hbody
    | div => simp [hr] at hbody
    | ok q =>
      rw [hr] at hbody
      simp only [bind_tc_ok] at hbody
      cases hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE with
      | fail err => simp [hneg] at hbody
      | div => simp [hneg] at hbody
      | ok negRange =>
        rw [hneg] at hbody
        simp only [bind_tc_ok] at hbody
        by_cases hreset : q.decimal_point < negRange
        · simp [hreset] at hbody
        · simp only [hreset, if_false] at hbody
          let shiftI : Std.I32 := UScalar.hcast .I32 shift
          rw [show UScalar.hcast .I32 shift = shiftI by rfl] at hbody
          cases ha : e + shiftI with
          | fail err => simp [ha] at hbody
          | div => simp [ha] at hbody
          | ok eout =>
            rw [ha] 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 heq : eout = e' := by tauto
            subst q
            subst eout
            have hnval := IScalar.hcast_inBounds_spec .Usize d.decimal_point
              (by scalar_tac)
            simp only [lift, WP.spec_ok] at hnval
            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
              num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
                  F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok k /\
                k.val <= 60 /\ _ at hcert
            have hk : k = shift := by
              exact Result.ok.inj (hcert.1.symm.trans hs)
            rw [hk] at hcert
            have hshift60 := hcert.2.1
            have hcval := UScalar.hcast_inBounds_spec .I32 shift
              (by rw [IScalar.max_I32_eq]; omega)
            simp only [lift, WP.spec_ok] at hcval
            have haval := IScalar.add_equiv e shiftI
            rw [ha] at haval
            refine ⟨n, shift, ?_, hs, hr, hshift60, ?_⟩
            · simpa using hnval
            · rw [haval.2.1]
              simpa using hcval

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_RightBodySelector",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "29d883f71e32babf8337ef7d47dbd74396336df5cee29d32e5c9dd5edf8ab47a",
  "active_statement_hash": "f0bdaeb7166ffa2ebba7fdc6f3f75f6d07e7940aba81216829d0748eb7bfcda9",
  "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": "d2b4145772dccc04"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "SlowShiftSelectorCertificate": "7ebc2b39d69850c4",
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "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": "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:5d74801edfd817a0d72bc61bcf6b4cd73f3682f6d5ba6c6f0254b4c090c69006",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}