P804_T1_LeftShiftPointGrowth

Lean checked

Statement

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

Helper · Left-shift point update uses the computed digit growth

Let a nonempty decimal sequence d have digit-growth routine result q\leq19 for a shift k. If the extracted decimal left shift by k returns d' normally, then its decimal point satisfies
p(d')=p(d)+q.
Here q is the machine-natural value returned by the digit-growth routine.

Lean statement

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

import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.DecimalSeqTrimSemantics
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_LeftShiftPointGrowth]
theorem P804_T1_LeftShiftPointGrowth
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (shift growth : Std.Usize)
    (hne : d.num_digits.val != 0)
    (hgrowth :
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d shift = ok growth)
    (hgrowthBound : growth.val <= 19)
    (hcall :
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d') :
    d'.decimal_point.val = d.decimal_point.val + (growth.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 extracted left shift num imp dec2flt decimal seq DecimalSeq left shift. Nonemptiness selects its nonzero-count branch, and the assumed digit-growth equation fixes the value q. A normal final return forces, in order, success of the checked count addition, the first digit loop, the carry loop, the cap at 768, the Usize-to-I32 cast of q, the checked point addition, and trim. Failed or divergent results at any bind cannot equal the assumed normal result.
The cap chooses either the checked width or the extracted constant 768, so the record passed to trim has a count at most the length 768 of its fixed array. The cast is exact: q\leq19 lies in the nonnegative I32 range. Thus the checked point addition has mathematical result p(d)+q. Apply DecimalSeqTrimSemantics to the final trim call. Its statement says that trim preserves the decimal-point field exactly. Consequently the returned record has point p(d)+q, as claimed.

Lean proof


  have hneWord : d.num_digits ≠ 0#usize := by
    intro h
    have hv := congrArg UScalar.val h
    simp at hv
    exact (by simpa [hv] using hne)
  unfold num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift at hcall
  simp only [hneWord, if_false, hgrowth, bind_tc_ok] at hcall
  cases hadd : d.num_digits + growth with
  | fail e => simp [hadd] at hcall
  | div => simp [hadd] at hcall
  | ok width =>
    simp only [hadd, bind_tc_ok] at hcall
    cases hloop0 :
        num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop0
          d.truncated d.digits shift d.num_digits width 0#u64 with
    | fail e => simp [hloop0] at hcall
    | div => simp [hloop0] at hcall
    | ok out0 =>
      rcases out0 with ⟨b0, a0, cursor, carry⟩
      simp only [hloop0, bind_tc_ok] at hcall
      change (do
        let (bc, ac) ←
          num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop1
            b0 a0 cursor carry
        let count ←
          if width > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          then ok num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          else ok width
        let delta ← lift (UScalar.hcast .I32 growth)
        let point ← d.decimal_point + delta
        num.imp.dec2flt.decimal_seq.DecimalSeq.trim
          { num_digits := count, decimal_point := point,
            truncated := bc, digits := ac }) = ok d' at hcall
      cases hloop1 :
          num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop1
            b0 a0 cursor carry with
      | fail e => simp [hloop1] at hcall
      | div => simp [hloop1] at hcall
      | ok out1 =>
        rcases out1 with ⟨b1, a1⟩
        rw [hloop1] at hcall
        simp only [bind_tc_ok] at hcall
        let count : Std.Usize :=
          if width > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          then num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS else width
        have hcount :
            (if width > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
              then ok num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
              else ok width) = ok count := by
          unfold count
          split <;> rfl
        rw [hcount] at hcall
        let delta : Std.I32 := UScalar.hcast .I32 growth
        rw [show UScalar.hcast .I32 growth = delta by rfl] at hcall
        simp only [lift, bind_tc_ok] at hcall
        cases hpoint : d.decimal_point + delta with
        | fail e => simp [hpoint] at hcall
        | div => simp [hpoint] at hcall
        | ok point =>
          rw [hpoint] at hcall
          simp only [bind_tc_ok] at hcall
          let pre : num.imp.dec2flt.decimal_seq.DecimalSeq :=
            { num_digits := count, decimal_point := point,
              truncated := b1, digits := a1 }
          have hcountBound : count.val <= a1.val.length := by
            rw [a1.property]
            by_cases hgt : width >
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
            · rw [show count =
                  num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS by
                simp [count, hgt]]
              simp [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
            · rw [show count = width by simp [count, hgt]]
              have hw : width.val <= 768 := by
                simpa [gt_iff_lt, UScalar.lt_equiv,
                  num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
                  using hgt
              exact hw
          have htrim := DecimalSeqTrimSemantics pre d'
            (by simpa [pre] using hcountBound) (by simpa [pre] using hcall)
          dsimp only at htrim
          have hpointEq := htrim.2.1
          have hdelta : delta.val = (growth.val : Int) := by
            have hs := UScalar.hcast_inBounds_spec .I32 growth (by
              rw [IScalar.max_I32_eq]
              omega)
            simpa [delta, lift, WP.spec_ok] using hs
          have hpointVal : point.val = d.decimal_point.val + delta.val := by
            have hs := IScalar.add_equiv d.decimal_point delta
            rw [hpoint] at hs
            exact hs.2.1
          rw [hpointEq]
          simpa [pre, hdelta] using hpointVal

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.DecimalSeqTrimSemantics
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_LeftShiftPointGrowth]
theorem P804_T1_LeftShiftPointGrowth
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (shift growth : Std.Usize)
    (hne : d.num_digits.val != 0)
    (hgrowth :
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d shift = ok growth)
    (hgrowthBound : growth.val <= 19)
    (hcall :
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d') :
    d'.decimal_point.val = d.decimal_point.val + (growth.val : Int) := by
-- BODY
  have hneWord : d.num_digits ≠ 0#usize := by
    intro h
    have hv := congrArg UScalar.val h
    simp at hv
    exact (by simpa [hv] using hne)
  unfold num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift at hcall
  simp only [hneWord, if_false, hgrowth, bind_tc_ok] at hcall
  cases hadd : d.num_digits + growth with
  | fail e => simp [hadd] at hcall
  | div => simp [hadd] at hcall
  | ok width =>
    simp only [hadd, bind_tc_ok] at hcall
    cases hloop0 :
        num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop0
          d.truncated d.digits shift d.num_digits width 0#u64 with
    | fail e => simp [hloop0] at hcall
    | div => simp [hloop0] at hcall
    | ok out0 =>
      rcases out0 with ⟨b0, a0, cursor, carry⟩
      simp only [hloop0, bind_tc_ok] at hcall
      change (do
        let (bc, ac) ←
          num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop1
            b0 a0 cursor carry
        let count ←
          if width > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          then ok num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          else ok width
        let delta ← lift (UScalar.hcast .I32 growth)
        let point ← d.decimal_point + delta
        num.imp.dec2flt.decimal_seq.DecimalSeq.trim
          { num_digits := count, decimal_point := point,
            truncated := bc, digits := ac }) = ok d' at hcall
      cases hloop1 :
          num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift_loop1
            b0 a0 cursor carry with
      | fail e => simp [hloop1] at hcall
      | div => simp [hloop1] at hcall
      | ok out1 =>
        rcases out1 with ⟨b1, a1⟩
        rw [hloop1] at hcall
        simp only [bind_tc_ok] at hcall
        let count : Std.Usize :=
          if width > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          then num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS else width
        have hcount :
            (if width > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
              then ok num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
              else ok width) = ok count := by
          unfold count
          split <;> rfl
        rw [hcount] at hcall
        let delta : Std.I32 := UScalar.hcast .I32 growth
        rw [show UScalar.hcast .I32 growth = delta by rfl] at hcall
        simp only [lift, bind_tc_ok] at hcall
        cases hpoint : d.decimal_point + delta with
        | fail e => simp [hpoint] at hcall
        | div => simp [hpoint] at hcall
        | ok point =>
          rw [hpoint] at hcall
          simp only [bind_tc_ok] at hcall
          let pre : num.imp.dec2flt.decimal_seq.DecimalSeq :=
            { num_digits := count, decimal_point := point,
              truncated := b1, digits := a1 }
          have hcountBound : count.val <= a1.val.length := by
            rw [a1.property]
            by_cases hgt : width >
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
            · rw [show count =
                  num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS by
                simp [count, hgt]]
              simp [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
            · rw [show count = width by simp [count, hgt]]
              have hw : width.val <= 768 := by
                simpa [gt_iff_lt, UScalar.lt_equiv,
                  num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
                  using hgt
              exact hw
          have htrim := DecimalSeqTrimSemantics pre d'
            (by simpa [pre] using hcountBound) (by simpa [pre] using hcall)
          dsimp only at htrim
          have hpointEq := htrim.2.1
          have hdelta : delta.val = (growth.val : Int) := by
            have hs := UScalar.hcast_inBounds_spec .I32 growth (by
              rw [IScalar.max_I32_eq]
              omega)
            simpa [delta, lift, WP.spec_ok] using hs
          have hpointVal : point.val = d.decimal_point.val + delta.val := by
            have hs := IScalar.add_equiv d.decimal_point delta
            rw [hpoint] at hs
            exact hs.2.1
          rw [hpointEq]
          simpa [pre, hdelta] using hpointVal

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (117)
More program dependencies (84)
Standard-library dependencies (30)

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 10 entries
Technical checking records
Local closure summary
{
  "node": "P804_T1_LeftShiftPointGrowth",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "b9bc8bb80ba6ed717c106de54dd633e488348691f2c1c0289ecf17f1cd2727c1",
  "active_statement_hash": "4d306b0000e518e69ea4950b79aba699631ba202b5b798ea6bd7f7315cf9c4f5",
  "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-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalSeqTrimSemantics": "e4b2cbb62f7171af",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "0eb6fb2627d0ff5c",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "0eb6fb2627d0ff5c"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "57f9712103d3acf6",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_trim": "faa9fd92b8c29c14",
    "num_imp_dec2flt_decimal_seq_number_of_digits_decimal_left_shift": "b3efbd0e6b3fe061"
  }
}
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:d4f53b179ae60ab042cfb9d44abfb4467864ef353f0f227f1680178f869e0d26",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}