P347_T1_SpecialDispatch

Lean checked

Statement

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

Lemma

Let s be any model string and let \sigma be an optional Boolean sign. If its complete byte list satisfies the special-literal predicate of DecimalGoalVocabularyDefault with sign \sigma and Boolean kind n, then there exists a model byte slice u satisfying the same predicate with sign none and kind n, such that for every binary64 word f, the implication below holds. If the specialized parse_inf_nan on u, with negative argument \operatorname{decide}(\sigma=\texttt{some true}), returns ok (Some f), then the actual specialized dec2flt on s returns ok (Rust Ok f). The specialization is ActualDispatchOperations's actual binary64 specialization.

Lean statement

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

import Tablet.P347_T1_UnsignedSpecialRejection
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_dec2flt

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P347_T1_SpecialDispatch]
theorem P347_T1_SpecialDispatch
    (s : Str) (sign : Option Bool) (nan : Bool)
    (h : DecimalGoalVocabularyDefault.specialLiteral
      (DecimalGoalVocabularyDefault.bytes s) sign nan) :
    exists body : Slice Std.U8,
      DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes body) none nan /\
      forall f : F64,
        num.imp.dec2flt.parse.parse_inf_nan
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 body
          (decide (sign = some true)) = ok (some f) ->
        num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
          F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
          F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) := 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 DecimalGoalVocabularyDefault's literal predicate. There is a body list B with \mathit{bytes}(s)=\mathit{signBytes}(\sigma)\mathbin{++}B and the required case relation for kind n. Unfold the actual parser using num imp dec2flt dec2flt and num imp dec2flt dec2flt with trace, specialized as in ActualDispatchOperations. Its first bind has the meaning ModelStrAsBytes: it succeeds with the same underlying slice. Its first-byte observation has the meaning ModelSliceFirst.
If \sigma=\texttt{none}, take u=s. The prefix is empty, so u satisfies the unsigned special-literal predicate. By UnsignedSpecialShape, its list is a::T, of length three or eight, and a.\mathit{val}\in\{73,78,105,110\}. Thus the first-byte bind succeeds with Some a; neither sign comparison, with 45 or 43, is true. The parser's body-selection bind returns u unchanged. It is nonempty, so the sign-only branch is not selected. The negative Boolean used by the parser is false, exactly \operatorname{decide}(\sigma=\texttt{some true}).
If \sigma=\texttt{some negative}, its sign prefix is the one byte 45 for negative=true, or 43 for negative=false. The byte-list equality forces s to be nonempty, with list p::T, p.\mathit{val} equal to that sign code, and T.\mathit{map}(b\mapsto b.\mathit{val})=B. Scalar value injectivity identifies p with the corresponding literal byte. Take u to be T with its inherited length proof: |T|\le|p::T|\le\texttt{Usize.max}. Then the unsigned predicate on u follows from that exact tail equality and the unchanged case relation on B. By UnsignedSpecialShape, T=a::R has length three or eight. The first-byte observation therefore succeeds with the sign byte. For minus, the first sign comparison is true; for plus, the minus test is false and the plus test is true. In either case the extracted guarded range-from index at 1#usize is in bounds because 1\le|p::a::R|. Its Slice.drop removes exactly p, yielding u: its list is T, and proof irrelevance identifies the slice length proofs. The next emptiness test is false because T=a::R. The parser's negative Boolean is true exactly in the minus case, hence is again \operatorname{decide}(\sigma=\texttt{some true}).
In all three sign cases, the numeric-helper bind returns normal None by UnsignedSpecialRejection applied to the established unsigned predicate on the exact selected body u. The extracted dispatch therefore reaches parse_inf_nan, with the binary64 trait instance and negative argument in the lemma's premise. For any f satisfying that premise, this bind succeeds with Some f. Its match returns normally the pair consisting of Rust Ok f and the Special trace. It does not enter any numeric fast path, assembly, or subsequent negation. Finally dec2flt projects the first component of this successful trace pair, returning the same Rust Ok f. This proves the universal implication for the exhibited u.

Lean proof


  dsimp [DecimalGoalVocabularyDefault] at h
  rcases h with ⟨body, hbytes, hcase⟩
  rcases s with ⟨vals, bound⟩
  cases sign with
  | none =>
    have hunsigned : DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes (⟨vals, bound⟩ : Slice Std.U8))
        none nan := by
      dsimp [DecimalGoalVocabularyDefault]
      exact ⟨body, hbytes, hcase⟩
    obtain ⟨hlen, a, tail, hs, ha⟩ :=
      P347_T1_UnsignedSpecialShape (⟨vals, bound⟩ : Slice Std.U8) nan hunsigned
    dsimp at hs
    subst vals
    have hminus : a ≠ 45#u8 := by
      intro heq
      have hval := congrArg UScalar.val heq
      simp at hval
      omega
    have hplus : a ≠ 43#u8 := by
      intro heq
      have hval := congrArg UScalar.val heq
      simp at hval
      omega
    have hnumber := P347_T1_UnsignedSpecialRejection
      (⟨a :: tail, bound⟩ : Slice Std.U8) nan hunsigned
    refine ⟨⟨a :: tail, bound⟩, hunsigned, ?_⟩
    intro f hspecial
    simp at hspecial
    simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
      core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
      ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
      hminus, hplus, hnumber, hspecial]
  | some negative =>
    cases vals with
    | nil =>
      cases negative <;> simp at hbytes
    | cons p tail =>
      have htail : tail.map (fun b : Std.U8 => b.val) = body := by
        have ht := congrArg List.tail hbytes
        cases negative <;> simpa using ht
      have hp : p = if negative then 45#u8 else 43#u8 := by
        have hv := congrArg List.head? hbytes
        apply UScalar.eq_of_val_eq
        cases negative <;> simpa using hv
      have hbound : tail.length <= Usize.max := by
        simp only [List.length_cons] at bound
        omega
      have hunsigned : DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes (⟨tail, hbound⟩ : Slice Std.U8))
          none nan := by
        dsimp [DecimalGoalVocabularyDefault]
        exact ⟨body, htail, hcase⟩
      obtain ⟨hlen, a, rest, hs, ha⟩ :=
        P347_T1_UnsignedSpecialShape (⟨tail, hbound⟩ : Slice Std.U8) nan hunsigned
      dsimp at hs
      subst tail
      have hnumber := P347_T1_UnsignedSpecialRejection
        (⟨a :: rest, hbound⟩ : Slice Std.U8) nan hunsigned
      refine ⟨⟨a :: rest, hbound⟩, hunsigned, ?_⟩
      intro f hspecial
      cases negative <;> simp at hspecial <;>
        simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
          core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
          ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
          core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
          hp, hnumber, hspecial]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P347_T1_UnsignedSpecialRejection
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_dec2flt

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P347_T1_SpecialDispatch]
theorem P347_T1_SpecialDispatch
    (s : Str) (sign : Option Bool) (nan : Bool)
    (h : DecimalGoalVocabularyDefault.specialLiteral
      (DecimalGoalVocabularyDefault.bytes s) sign nan) :
    exists body : Slice Std.U8,
      DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes body) none nan /\
      forall f : F64,
        num.imp.dec2flt.parse.parse_inf_nan
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 body
          (decide (sign = some true)) = ok (some f) ->
        num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
          F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
          F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) := by
-- BODY
  dsimp [DecimalGoalVocabularyDefault] at h
  rcases h with ⟨body, hbytes, hcase⟩
  rcases s with ⟨vals, bound⟩
  cases sign with
  | none =>
    have hunsigned : DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes (⟨vals, bound⟩ : Slice Std.U8))
        none nan := by
      dsimp [DecimalGoalVocabularyDefault]
      exact ⟨body, hbytes, hcase⟩
    obtain ⟨hlen, a, tail, hs, ha⟩ :=
      P347_T1_UnsignedSpecialShape (⟨vals, bound⟩ : Slice Std.U8) nan hunsigned
    dsimp at hs
    subst vals
    have hminus : a ≠ 45#u8 := by
      intro heq
      have hval := congrArg UScalar.val heq
      simp at hval
      omega
    have hplus : a ≠ 43#u8 := by
      intro heq
      have hval := congrArg UScalar.val heq
      simp at hval
      omega
    have hnumber := P347_T1_UnsignedSpecialRejection
      (⟨a :: tail, bound⟩ : Slice Std.U8) nan hunsigned
    refine ⟨⟨a :: tail, bound⟩, hunsigned, ?_⟩
    intro f hspecial
    simp at hspecial
    simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
      core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
      ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
      hminus, hplus, hnumber, hspecial]
  | some negative =>
    cases vals with
    | nil =>
      cases negative <;> simp at hbytes
    | cons p tail =>
      have htail : tail.map (fun b : Std.U8 => b.val) = body := by
        have ht := congrArg List.tail hbytes
        cases negative <;> simpa using ht
      have hp : p = if negative then 45#u8 else 43#u8 := by
        have hv := congrArg List.head? hbytes
        apply UScalar.eq_of_val_eq
        cases negative <;> simpa using hv
      have hbound : tail.length <= Usize.max := by
        simp only [List.length_cons] at bound
        omega
      have hunsigned : DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes (⟨tail, hbound⟩ : Slice Std.U8))
          none nan := by
        dsimp [DecimalGoalVocabularyDefault]
        exact ⟨body, htail, hcase⟩
      obtain ⟨hlen, a, rest, hs, ha⟩ :=
        P347_T1_UnsignedSpecialShape (⟨tail, hbound⟩ : Slice Std.U8) nan hunsigned
      dsimp at hs
      subst tail
      have hnumber := P347_T1_UnsignedSpecialRejection
        (⟨a :: rest, hbound⟩ : Slice Std.U8) nan hunsigned
      refine ⟨⟨a :: rest, hbound⟩, hunsigned, ?_⟩
      intro f hspecial
      cases negative <;> simp at hspecial <;>
        simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
          core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
          ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
          core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
          hp, hnumber, hspecial]

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (199)
More program dependencies (157)
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 158 entries
Technical checking records
Local closure summary
{
  "node": "P347_T1_SpecialDispatch",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "1c0d22f280cc75035c52c2ec02d35d3c11ac1ddd00127227f4f6e0e5e0b461bb",
  "active_statement_hash": "bcdf6e01c9b1220288cca2b874dcb6bef9a1f8171112c131993f80a4f5819b96",
  "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": {
    "P347_T1_UnsignedSpecialRejection": "474a3ff71059e9a4",
    "P347_T1_UnsignedSpecialShape": "414dfcc312f29b3f",
    "num_imp_dec2flt_dec2flt_with_trace": "8f54814ba9c190ea",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "65227461bf3cac06",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "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",
    "ModelSliceFirst": "a31394b3c1080f71",
    "ModelStrAsBytes": "024fe35b4dbfa9a3",
    "Preamble": "7a79218b23bce03e",
    "core_ops_arith_Div": "6e5df64b87169aa0",
    "core_ops_arith_Mul": "6e5df64b87169aa0",
    "core_ops_arith_Neg": "94ab5f784cdf5db8",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "1cacb7f8b1927ad5",
    "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": "f9f7d93449a25efa",
    "num_imp_dec2flt_dec2flt_with_trace": "5665189e0304a27e",
    "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": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:53a1f38b9ab5b1a495274467b4c9c524abb549022eea70b188313f052839886d",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}