P472_T1_LoopZeroRightShiftTransport

Lean checked

Statement

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

Lemma · Nonreset loop-zero right shift with exact error transport

Let V(d) be the natural base-ten fold of the retained cells scaled by 10^{d.\mathit{decimal\_point}-d.\mathit{num\_digits}}. Suppose 0\le k\le60, 0\le d.\mathit{decimal\_point}<310, and d retains at most 768 decimal cells. Require its retained value list to have exactly its count as length and to start with a digit in [1,9]. Suppose also V(d)>0 and
X=V(d)+\eta,\qquad 0\le\eta<u,\qquad d.\mathit{truncated}=\mathrm{true}\ \Longleftrightarrow\ 0<\eta.
Then the actual right shift returns normally with a record d' whose point is in [-2047,309] and whose count is nonzero. There exist real \eta',u' with
X/2^k=V(d')+\eta',\quad 0\le\eta'<u',\quad d'.\mathit{truncated}=\mathrm{true}\ \Longleftrightarrow\ 0<\eta', \quad V(d')+u'=(V(d)+u)/2^k.
For every real H, division by 2^k preserves and reflects all three comparisons X<H, X=H, and H<X.

Lean statement

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

import Tablet.P472_T1_DecimalRightShiftLoop0Execution
import Tablet.P472_T1_DecimalSeqDyadicShiftSemantics

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P472_T1_LoopZeroRightShiftTransport]
theorem P472_T1_LoopZeroRightShiftTransport
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize)
    (X eta u : Real) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun z => z.val)).foldl
        (fun b digit => 10 * b + digit) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    shift.val <= 60 ->
    0 <= d.decimal_point.val -> d.decimal_point.val < 310 ->
    d.num_digits.val <= 768 ->
    (forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) ->
    (exists z zs,
      (d.digits.val.take d.num_digits.val).map (fun a => a.val) = z :: zs /\
      1 <= z /\ z < 10 /\ (z :: zs).length = d.num_digits.val) ->
    0 < V d -> X = V d + eta -> 0 <= eta -> eta < u ->
    (d.truncated = true <-> 0 < eta) ->
    exists (d' : num.imp.dec2flt.decimal_seq.DecimalSeq) (eta' u' : Real),
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift = ok d' /\
      -2047 <= d'.decimal_point.val /\ d'.decimal_point.val <= 309 /\
      d'.num_digits.val ≠ 0 /\
      X / (2 : Real) ^ shift.val = V d' + eta' /\
      0 <= eta' /\ eta' < u' /\
      (d'.truncated = true <-> 0 < eta') /\
      V d' + u' = (V d + u) / (2 : Real) ^ shift.val /\
      (forall H : Real,
        (X < H <-> X / (2 : Real) ^ shift.val < H / (2 : Real) ^ shift.val) /\
        (X = H <-> X / (2 : Real) ^ shift.val = H / (2 : Real) ^ shift.val) /\
        (H < X <-> H / (2 : Real) ^ shift.val < X / (2 : Real) ^ shift.val)) := 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 DecimalRightShiftLoop0Execution. The shift bound, point range, retained-count bound, retained digit bounds, and positive-head list with exact length are exactly its hypotheses. It supplies a normal right-shift result d', a prospective point in [-2047,309], equality of the returned point with that prospective point, and a nonzero returned count. In particular no separate termination or no-fail premise is being assumed.
Apply the right-shift conjunct of DecimalSeqDyadicShiftSemantics to this normal call. Its positivity and digit hypotheses are explicit here, and its value, error interval and sticky hypotheses are exactly the displayed input relations. Its reset alternative would give a zero count for d', contradicting the execution theorem's nonzero count. Therefore its nonreset alternative supplies the same \eta',u' with all four asserted error/endpoint relations and all three comparison equivalences. Combining them with the already proved normal call, point range and nonzero count proves the conclusion.

Lean proof


  dsimp only
  intro hshift hlo hhi hn hdigit hlead hV hX heta hetau hsticky
  obtain ⟨read, acc, d', _, _, _, _, _, hprospective⟩ :=
    P472_T1_DecimalRightShiftLoop0Execution d shift hshift hlo hhi
      ⟨hn, hdigit, hlead⟩
  dsimp only at hprospective
  rcases hprospective with ⟨hpLo, hpHi, hcall, hp, hnz⟩
  have hnz' : d'.num_digits.val ≠ 0 := by simpa using hnz
  have htransport := P472_T1_DecimalSeqDyadicShiftSemantics.2
    d d' shift X eta u hshift hV hdigit hcall hX heta hetau hsticky
  rcases htransport with hreset | hregular
  · exact False.elim (hnz' hreset.1)
  · obtain ⟨eta', u', hvalue, heta', hu', hsticky', hendpoint, hcompare⟩ := hregular
    exact ⟨d', eta', u', hcall, by omega, by omega, hnz',
      hvalue, heta', hu', hsticky', hendpoint, hcompare⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P472_T1_DecimalRightShiftLoop0Execution
import Tablet.P472_T1_DecimalSeqDyadicShiftSemantics

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P472_T1_LoopZeroRightShiftTransport]
theorem P472_T1_LoopZeroRightShiftTransport
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize)
    (X eta u : Real) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun z => z.val)).foldl
        (fun b digit => 10 * b + digit) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    shift.val <= 60 ->
    0 <= d.decimal_point.val -> d.decimal_point.val < 310 ->
    d.num_digits.val <= 768 ->
    (forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) ->
    (exists z zs,
      (d.digits.val.take d.num_digits.val).map (fun a => a.val) = z :: zs /\
      1 <= z /\ z < 10 /\ (z :: zs).length = d.num_digits.val) ->
    0 < V d -> X = V d + eta -> 0 <= eta -> eta < u ->
    (d.truncated = true <-> 0 < eta) ->
    exists (d' : num.imp.dec2flt.decimal_seq.DecimalSeq) (eta' u' : Real),
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift = ok d' /\
      -2047 <= d'.decimal_point.val /\ d'.decimal_point.val <= 309 /\
      d'.num_digits.val ≠ 0 /\
      X / (2 : Real) ^ shift.val = V d' + eta' /\
      0 <= eta' /\ eta' < u' /\
      (d'.truncated = true <-> 0 < eta') /\
      V d' + u' = (V d + u) / (2 : Real) ^ shift.val /\
      (forall H : Real,
        (X < H <-> X / (2 : Real) ^ shift.val < H / (2 : Real) ^ shift.val) /\
        (X = H <-> X / (2 : Real) ^ shift.val = H / (2 : Real) ^ shift.val) /\
        (H < X <-> H / (2 : Real) ^ shift.val < X / (2 : Real) ^ shift.val)) := by
-- BODY
  dsimp only
  intro hshift hlo hhi hn hdigit hlead hV hX heta hetau hsticky
  obtain ⟨read, acc, d', _, _, _, _, _, hprospective⟩ :=
    P472_T1_DecimalRightShiftLoop0Execution d shift hshift hlo hhi
      ⟨hn, hdigit, hlead⟩
  dsimp only at hprospective
  rcases hprospective with ⟨hpLo, hpHi, hcall, hp, hnz⟩
  have hnz' : d'.num_digits.val ≠ 0 := by simpa using hnz
  have htransport := P472_T1_DecimalSeqDyadicShiftSemantics.2
    d d' shift X eta u hshift hV hdigit hcall hX heta hetau hsticky
  rcases htransport with hreset | hregular
  · exact False.elim (hnz' hreset.1)
  · obtain ⟨eta', u', hvalue, heta', hu', hsticky', hendpoint, hcompare⟩ := hregular
    exact ⟨d', eta', u', hcall, by omega, by omega, hnz',
      hvalue, heta', hu', hsticky', hendpoint, hcompare⟩

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 27 entries
Technical checking records
Local closure summary
{
  "node": "P472_T1_LoopZeroRightShiftTransport",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "7f51a46888eebe932bfe0cae32a0f9b90f8adebbf35b3c8c4fa0180a8e26216b",
  "active_statement_hash": "b5b62b9c5c86294ab885a512d1392457e4e70724f51d6ff6bc178d90b8ade3f6",
  "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": {
    "P472_T1_DecimalRightShiftLoop0Execution": "e27252660de78d95",
    "P472_T1_DecimalSeqDyadicShiftSemantics": "9d844d655b9f8a27"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "4db7c37f5da1c6e0"
  }
}
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:04a5e87e980a0453b6b3cba68be2df113e8177b710f011acf20f26a55aab64e4",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}