ParserSlowLoopMinimumExponent

Lean checked

Statement

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

Helper

If slow-conversion loop 2 for the extracted binary64 traits returns normally, the signed exponent in its output is at least -1022.

Lean statement

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

import Tablet.ResultLoopPartial
import Tablet.ParserExponentConstants

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSlowLoopMinimumExponent]
theorem ParserSlowLoopMinimumExponent
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (e : I32)
    (out : num.imp.dec2flt.decimal_seq.DecimalSeq × I32)
    (h : num.imp.dec2flt.slow.parse_long_mantissa_loop2
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d e = ok out) :
    -1022 ≤ out.2.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

By ParserExponentConstants, the binary64 minimum exponent is -1022. Apply ResultLoopPartial with the trivial continuation invariant and the postcondition that the returned exponent is at least -1022. Unfold loop 2 and its body in num imp dec2flt slow parse long mantissa. When -1022 is greater than the current exponent, invert the successful difference, cast, capped shift selection, decimal right shift, reverse cast, and exponent addition; the body continues, so the trivial invariant holds. Otherwise the body finishes immediately with the current exponent, and the false comparison is exactly the required inequality. Failure or divergence of any predecessor cannot yield the assumed normal loop return. The partial-loop principle therefore establishes the postcondition.

Lean proof


  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  let Inv := fun (_ : num.imp.dec2flt.decimal_seq.DecimalSeq × I32) => True
  let Post := fun (x : num.imp.dec2flt.decimal_seq.DecimalSeq × I32) =>
    -1022 ≤ x.2.val
  let Body := fun (x : num.imp.dec2flt.decimal_seq.DecimalSeq × I32) =>
    match x with
    | (d, e) => num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d e
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (f : α → Result β) y,
      Bind.bind r f = ok y → ∃ x, r = ok x ∧ f x = ok y := by
    intro α β r f y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok x => exact ⟨x, rfl, hr⟩
  have hbody : ∀ x, Inv x → ∀ r, Body x = ok r →
      match r with | done y => Post y | cont x' => Inv x' := by
    intro x hx r hb
    rcases x with ⟨d, e⟩
    simp only [Body] at hb
    unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body at hb
    rw [hmin] at hb
    simp only [bind_tc_ok] at hb
    by_cases hgt : (-1022)#i32 > e
    · simp only [hgt, if_true] at hb
      obtain ⟨diff, hdiff, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨n, hn, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨n1, hn1, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨d1, hd1, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨step32, hstep32, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨e', he', hb⟩ := bind_ok_inv _ _ _ hb
      cases hb
      trivial
    · simp only [hgt, if_false] at hb
      cases hb
      change -1022 ≤ e.val
      change ¬ -1022 > e.val at hgt
      omega
  unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2 at h
  refine ResultLoopPartial Inv Post Body ?_ _ _ trivial h
  intro x hx r hr
  cases r with
  | done y => exact hbody x hx (done y) hr
  | cont x' => exact hbody x hx (cont x') hr

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.ResultLoopPartial
import Tablet.ParserExponentConstants

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSlowLoopMinimumExponent]
theorem ParserSlowLoopMinimumExponent
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (e : I32)
    (out : num.imp.dec2flt.decimal_seq.DecimalSeq × I32)
    (h : num.imp.dec2flt.slow.parse_long_mantissa_loop2
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d e = ok out) :
    -1022 ≤ out.2.val := by
-- BODY
  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  let Inv := fun (_ : num.imp.dec2flt.decimal_seq.DecimalSeq × I32) => True
  let Post := fun (x : num.imp.dec2flt.decimal_seq.DecimalSeq × I32) =>
    -1022 ≤ x.2.val
  let Body := fun (x : num.imp.dec2flt.decimal_seq.DecimalSeq × I32) =>
    match x with
    | (d, e) => num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d e
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (f : α → Result β) y,
      Bind.bind r f = ok y → ∃ x, r = ok x ∧ f x = ok y := by
    intro α β r f y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok x => exact ⟨x, rfl, hr⟩
  have hbody : ∀ x, Inv x → ∀ r, Body x = ok r →
      match r with | done y => Post y | cont x' => Inv x' := by
    intro x hx r hb
    rcases x with ⟨d, e⟩
    simp only [Body] at hb
    unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body at hb
    rw [hmin] at hb
    simp only [bind_tc_ok] at hb
    by_cases hgt : (-1022)#i32 > e
    · simp only [hgt, if_true] at hb
      obtain ⟨diff, hdiff, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨n, hn, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨n1, hn1, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨d1, hd1, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨step32, hstep32, hb⟩ := bind_ok_inv _ _ _ hb
      obtain ⟨e', he', hb⟩ := bind_ok_inv _ _ _ hb
      cases hb
      trivial
    · simp only [hgt, if_false] at hb
      cases hb
      change -1022 ≤ e.val
      change ¬ -1022 > e.val at hgt
      omega
  unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2 at h
  refine ResultLoopPartial Inv Post Body ?_ _ _ trivial h
  intro x hx r hr
  cases r with
  | done y => exact hbody x hx (done y) hr
  | cont x' => exact hbody x hx (cont x') hr

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (152)
More program dependencies (110)
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 104 entries
Technical checking records
Local closure summary
{
  "node": "ParserSlowLoopMinimumExponent",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "d08804081bff4f67119efd4ac76cc8939427d8c2bf6a9137da900c90dda483e1",
  "active_statement_hash": "9a54f6b5db1303c8a084d66a3ccebbe96f1e1fc008d68dbf0263319f6d9fda38",
  "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": {
    "ParserExponentConstants": "e2a30a7b0c5e9c91",
    "ResultLoopPartial": "566d2aeb76ed9100"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "ResultLoopPartial": "1b58e96ad00b23c2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_slow_parse_long_mantissa": "6301f3828274183b",
    "num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT": "32f403f33bee78a7",
    "num_imp_traits_Float": "e6fdcaf2f38244d3"
  }
}
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:aacb364168140a16c6252ca34c0fc8e0b67adcff58bd13377dadb5448264ca88",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}