ParserAssemblyResidue

Lean checked

Statement

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

Lemma · Final assembled-trace word

Whenever the traced dispatcher is invoked on a source-valid string s and returns successfully with an assembled trace t, its field t.\mathit{assembly\_result} is the unrestricted assembled word of t.\mathit{selected\_pair} in the sense of assembledWord. No exponent-range or mantissa-mask hypothesis is required.

Lean statement

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

import Tablet.AssemblyCorrespondence
import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.num_imp_dec2flt_Dec2FltAssemblyTrace
import Tablet.num_imp_dec2flt_dec2flt_with_trace

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserAssemblyResidue]
theorem ParserAssemblyResidue :
    forall (s : Str) (f : F64)
      (tr : num.imp.dec2flt.Dec2FltAssemblyTrace F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
          ok (core.result.Result.Ok f,
            num.imp.dec2flt.Dec2FltTrace.Assembled tr) ->
      DecimalGoalVocabularyDefault.assembledWord
        tr.selected_pair tr.assembly_result := 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 num imp dec2flt dec2flt with trace along the assumed assembled return. All preceding failure cases are excluded by normal return. After the selected pair has been chosen, the dispatcher first casts its I32 biased exponent to U64 with Rust's sign-extending cast, then obtains the binary64 significand-width value 52, shifts the cast word left by 52 in a 64-bit word, and bitwise-ORs that result with the selected mantissa. It stores this word in assembled_word. The shift count 52<64, so the shift cannot fail; the OR is total.
The next call is biased_fp_to_float on exactly the selected pair, and its returned value is stored in assembly_result. By AssemblyCorrespondence, this call succeeds for every unrestricted pair and its returned raw F64 word satisfies assembledWord(selected_pair, assembly_result). Constructor injectivity for both the negative-sign and nonnegative-sign assembled return arms identifies those local values with the corresponding fields of t. The later lexical negation changes only the separate final result field, not assembly_result. Hence the asserted field relation holds in either sign arm.

Lean proof


  intro s f tr hsource htrace
  have bind_ok_inv : forall {alpha beta : Type} (x : Result alpha)
      (g : alpha -> Result beta) y,
      Bind.bind x g = ok y -> exists z, x = ok z /\ g z = ok y := by
    intro alpha beta x g y hx
    cases x with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hx
    | div => simp [Bind.bind, Aeneas.Std.bind] at hx
    | ok z => exact ⟨z, rfl, hx⟩
  unfold num.imp.dec2flt.dec2flt_with_trace at htrace
  obtain ⟨body, hbody, htrace⟩ := bind_ok_inv _ _ _ htrace
  obtain ⟨first, hfirst, htrace⟩ := bind_ok_inv _ _ _ htrace
  cases first with
  | none =>
      obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
      cases htrace
  | some c =>
      obtain ⟨body1, hbody1, htrace⟩ := bind_ok_inv _ _ _ htrace
      obtain ⟨empty, hempty, htrace⟩ := bind_ok_inv _ _ _ htrace
      by_cases he : empty = true
      · simp only [he, if_true] at htrace
        obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases htrace
      · have hef : empty = false := Bool.eq_false_of_not_eq_true he
        simp only [hef] at htrace
        obtain ⟨parsed, hparsed, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases parsed with
        | none =>
            obtain ⟨special, hspecial, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases special with
            | none =>
                obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
                cases htrace
            | some value => cases htrace
        | some parsedRecord =>
            obtain ⟨fast, hfast, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases fast with
            | some value => cases htrace
            | none =>
                obtain ⟨firstPair, hfirstPair, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                obtain ⟨phase1, hphase1, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase1 with
                  ⟨many1, many2, firstPair1, fp, secondGuard⟩
                obtain ⟨phase2, hphase2, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase2 with
                  ⟨post, secondExp, secondMant, secondResult, secondEqual,
                    forced⟩
                obtain ⟨phase3, hphase3, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase3 with ⟨selected, slowGuard, slowResult⟩
                obtain ⟨i, hi, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i1, hi1, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i2, hi2, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨word, hwordValue, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨assembled, hassembled, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                rcases AssemblyCorrespondence selected with
                  ⟨expected, hexpected, hword⟩
                rw [hassembled] at hexpected
                cases hexpected
                by_cases hnegative : c = 45#u8
                · simp only [hnegative, if_true] at htrace
                  obtain ⟨result, hresult, htrace⟩ :=
                    bind_ok_inv _ _ _ htrace
                  cases htrace
                  exact hword
                · simp only [hnegative, if_false] at htrace
                  cases htrace
                  exact hword

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.AssemblyCorrespondence
import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.num_imp_dec2flt_Dec2FltAssemblyTrace
import Tablet.num_imp_dec2flt_dec2flt_with_trace

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserAssemblyResidue]
theorem ParserAssemblyResidue :
    forall (s : Str) (f : F64)
      (tr : num.imp.dec2flt.Dec2FltAssemblyTrace F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
          ok (core.result.Result.Ok f,
            num.imp.dec2flt.Dec2FltTrace.Assembled tr) ->
      DecimalGoalVocabularyDefault.assembledWord
        tr.selected_pair tr.assembly_result := by
-- BODY
  intro s f tr hsource htrace
  have bind_ok_inv : forall {alpha beta : Type} (x : Result alpha)
      (g : alpha -> Result beta) y,
      Bind.bind x g = ok y -> exists z, x = ok z /\ g z = ok y := by
    intro alpha beta x g y hx
    cases x with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hx
    | div => simp [Bind.bind, Aeneas.Std.bind] at hx
    | ok z => exact ⟨z, rfl, hx⟩
  unfold num.imp.dec2flt.dec2flt_with_trace at htrace
  obtain ⟨body, hbody, htrace⟩ := bind_ok_inv _ _ _ htrace
  obtain ⟨first, hfirst, htrace⟩ := bind_ok_inv _ _ _ htrace
  cases first with
  | none =>
      obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
      cases htrace
  | some c =>
      obtain ⟨body1, hbody1, htrace⟩ := bind_ok_inv _ _ _ htrace
      obtain ⟨empty, hempty, htrace⟩ := bind_ok_inv _ _ _ htrace
      by_cases he : empty = true
      · simp only [he, if_true] at htrace
        obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases htrace
      · have hef : empty = false := Bool.eq_false_of_not_eq_true he
        simp only [hef] at htrace
        obtain ⟨parsed, hparsed, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases parsed with
        | none =>
            obtain ⟨special, hspecial, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases special with
            | none =>
                obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
                cases htrace
            | some value => cases htrace
        | some parsedRecord =>
            obtain ⟨fast, hfast, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases fast with
            | some value => cases htrace
            | none =>
                obtain ⟨firstPair, hfirstPair, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                obtain ⟨phase1, hphase1, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase1 with
                  ⟨many1, many2, firstPair1, fp, secondGuard⟩
                obtain ⟨phase2, hphase2, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase2 with
                  ⟨post, secondExp, secondMant, secondResult, secondEqual,
                    forced⟩
                obtain ⟨phase3, hphase3, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase3 with ⟨selected, slowGuard, slowResult⟩
                obtain ⟨i, hi, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i1, hi1, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i2, hi2, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨word, hwordValue, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨assembled, hassembled, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                rcases AssemblyCorrespondence selected with
                  ⟨expected, hexpected, hword⟩
                rw [hassembled] at hexpected
                cases hexpected
                by_cases hnegative : c = 45#u8
                · simp only [hnegative, if_true] at htrace
                  obtain ⟨result, hresult, htrace⟩ :=
                    bind_ok_inv _ _ _ htrace
                  cases htrace
                  exact hword
                · simp only [hnegative, if_false] at htrace
                  cases htrace
                  exact hword

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (201)
More program dependencies (159)
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 150 entries
Technical checking records
Local closure summary
{
  "node": "ParserAssemblyResidue",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "837aebecfd625b312e42985e65cdebe4f5bb1f4cf094888aa8c524d66c76a1fe",
  "active_statement_hash": "3ad302fdaa1c907b48fa940ea39f57c546f8638955efe85323606b7ab8102e1f",
  "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": "worker-result-local-closure-issuance-cycle-165",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "AssemblyCorrespondence": "e3495a6647394e20",
    "num_imp_dec2flt_dec2flt_with_trace": "8f54814ba9c190ea",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "d8d2f621d2f6aa27",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_CoreOpsArithDivF64F64": "dc44e13a99fc6bed",
    "F64_Insts_CoreOpsArithMulF64F64": "1ae1a9021a654abd",
    "F64_Insts_CoreOpsArithNegF64": "2d9be310c546ea2e",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64": "60afe26c6a80cf0f",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "Preamble": "86dc391ab250c79b",
    "core_ops_arith_Neg": "0ff07135a60bcbf9",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "9e332236ff8bbccd",
    "num_imp_dec2flt_Dec2FltTrace": "27322b4608129f59",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_dec2flt_with_trace": "ebe6a57c6dce0df6",
    "num_imp_dec2flt_decimal_Decimal": "b702e549017701b8",
    "num_imp_dec2flt_decimal_Decimal_try_fast_path": "2e4888f65a06b49f",
    "num_imp_dec2flt_lemire_compute_float": "39d89e3f0a8a9d4c",
    "num_imp_dec2flt_parse_parse_inf_nan": "85655c19a8791b54",
    "num_imp_dec2flt_parse_parse_number": "f73f8bc11faa6db3",
    "num_imp_dec2flt_pfe_empty": "89046d1da5ac1ce2",
    "num_imp_dec2flt_pfe_invalid": "21db875427d92c6d",
    "num_imp_dec2flt_slow_parse_long_mantissa": "cd8af64c3688b60f",
    "num_imp_traits_Float": "02acccb9db3e30f2",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:bcb63d392cbbaa4b82eed338c42628f2a954f9a62b31efd6f83b95507eec9895",
  "current_fingerprint": "sound-v2:bcb63d392cbbaa4b82eed338c42628f2a954f9a62b31efd6f83b95507eec9895",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}