SpecialHelperInfinity

Lean checked

Statement

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

Theorem

For every Rust byte slice spelling unsigned inf or infinity ASCII case-insensitively, and either separate sign argument, the specialized parse_inf_nan returns normally with Some of infinity having that sign.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.ModelF64Infinity
import Tablet.ModelF64Neg
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.NumberHelperReadEightBytes
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: SpecialHelperInfinity]
theorem SpecialHelperInfinity :
    ∀ (s : Slice Std.U8) (negative : Bool), DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) none false ->
      ∃ f : F64, num.imp.dec2flt.parse.parse_inf_nan
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative = ok (some f) ∧
        DecimalGoalVocabularyDefault.isInfinity negative 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

Fix a slice s, a Boolean negative, and the stated special-literal hypothesis. Unfold DecimalGoalVocabularyDefault. For sign none, the sign-byte prefix is empty, and for kind false the body is related case-insensitively either to [105,110,102] or to [105,110,102,105,110,105,116,121]. The equality with the empty prefix makes that body the complete list of unsigned values of the bytes of s. The bytes field maps each underlying slice element to its unsigned value once and in order, so this mapping preserves length. Since List.Forall2 also forces its two lists to have equal lengths, there are exactly two cases: the slice has length three and spells inf, or it has length eight and spells infinity, in each case ASCII case-insensitively. More explicitly, at a position whose required lowercase byte is l, the component condition is x=l or x+32=l. For the letters here this says that x is the lowercase code l or the uppercase code l-32.
Unfold num imp dec2flt parse parse inf nan at the supplied binary64 trait instance. First suppose the eight-letter alternative holds. The initial comparison with eight is true. In SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64, Array.repeat constructs a destination of exactly eight bytes and the lifted pure result of Array.to_slice_mut succeeds and exposes that whole destination. The source range request self[..8] is in bounds because the established source length is exactly eight. Its result also has length eight, so the source and destination lengths required by copy_from_slice agree. Hence the range and copy binds both succeed; the back function restores the copied array, and the total from_le_bytes operation returns
r=\sum_{j=0}^{7}b_j2^{8j},
where b_j is the unsigned value of byte j. No read failure is possible in this branch.
The next bind ANDs r with M=16131858542891098079=\mathtt{0xdfdfdfdfdfdfdfdf}. By ModelU64BitAnd, the operation succeeds and is the exact bounded bitwise conjunction. Each byte of M is 0xdf, which has every bit set except 0x20, the ASCII case bit. Thus byte j of r\mathbin{\mathtt{\&}}M is b_j\mathbin{\mathtt{\&}}\mathtt{0xdf}. For the two admitted codes l and l-32 at each position, this value is in both cases l-32. Reading the resulting uppercase bytes in their original little-endian order gives
\begin{split} r\mathbin{\mathtt{\&}}M &=\mathtt{0x49}+\mathtt{0x4e}2^8+\mathtt{0x46}2^{16} +\mathtt{0x49}2^{24}+\mathtt{0x4e}2^{32}\\ &\quad+\mathtt{0x49}2^{40}+\mathtt{0x54}2^{48} +\mathtt{0x59}2^{56}\\ &=\mathtt{0x5954494e49464e49}=6436850368004902473. \end{split}
This is exactly the successful eight-byte match displayed in the extracted definition, so execution enters its infinity branch rather than either rejection or default branch.
Now suppose the three-letter alternative holds. The comparison with eight is false and the following comparison with three is true. Call the three byte values a,b,c in input order. Their case alternatives are
a\in\{105,73\},\qquad b\in\{110,78\},\qquad c\in\{102,70\}.
The indices 0, 1, and 2 are each strictly below the established length 3, so all three Slice.index_usize binds succeed and return exactly those bytes. Each value lies in 0,\ldots,255. The three displayed lift (UScalar.cast .U64 ...) binds use Aeneas's total unsigned cast, which zero-extends or truncates before lift returns it in ok. Here the conversion widens from eight to 64 bits, so there is no truncation: all three lifts succeed and preserve the values exactly.
The next binds are specifically the Aeneas operations c <<< 16#i32 and b <<< 8#i32; their counts are signed i32, not unsigned shift operands. Directly from the extracted UScalar-by-IScalar semantics, each operation first checks that its signed count is nonnegative, converts that count to its natural value, and checks that value is strictly below the unsigned left operand's bit width, failing with integer overflow if either check fails. Here 16 and 8 are nonnegative, their natural values are still 16 and 8, and both are below the u64 width 64. Both shifts therefore succeed. Moreover, byte bounds give
c2^{16}\leq255\,2^{16}<2^{24}<2^{64},\qquad b2^8\leq255\,2^8<2^{16}<2^{64},
so the bounded shift results are exactly c2^{16} and b2^8, with no discarded high bit. Their possible occupied ranges, bits 16--23 and 8--15, are disjoint from each other and from the widened a in bits 0--7. Each of the two OR binds therefore succeeds by ModelU64BitOr, and exact disjoint-range bitwise assembly gives
r=(c2^{16})\mathbin{\mathtt{|}}(b2^8)\mathbin{\mathtt{|}}a =a+b2^8+c2^{16}<2^{24}.
The following AND bind succeeds by ModelU64BitAnd. Its low three mask bytes again clear only the ASCII case bit, and its five high bytes leave the five high zero bytes unchanged. Consequently
r\mathbin{\mathtt{\&}}M =\mathtt{0x49}+\mathtt{0x4e}2^8+\mathtt{0x46}2^{16} =\mathtt{0x464e49}=4607561.
This is exactly the first successful three-byte match, so this execution also enters the infinity branch rather than either rejection, NaN, or default branch.
It remains to evaluate that common infinity branch and its sign conditional. Unfolding the trait record F64 Insts Dec2flt modelNumImpTraitsFloatU64, its INFINITY field is the constant operation whose direct paired semantics is ModelF64Infinity. It succeeds with the raw word
p=\mathtt{0x7ff0000000000000}=2047\,2^{52}.
Thus the constant lookup cannot fail. If negative is false, the conditional performs no negation and returns ok (some p). If negative is true, the selected extracted negation operation has the direct paired semantics ModelF64Neg: it succeeds and toggles exactly raw bit 63. Since p<2^{63}, that bit is initially zero, and the returned word is
p'=p+2^{63}=\mathtt{0xfff0000000000000}.
The true branch therefore returns ok (some p').
Finally unfold the isInfinity field of DecimalGoalVocabularyDefault. Its required equation is
f.\mathit{val}=2047\,2^{52}+ \begin{cases}2^{63},&\texttt{negative}=\texttt{true},\\ 0,&\texttt{negative}=\texttt{false}. \end{cases}
For the false branch, the returned F64 word has value p=2047\,2^{52}+0, which proves this equation. For the true branch, the returned word has value p'=2047\,2^{52}+2^{63}, which proves it. Taking the respective returned F64 word as f supplies the existential witness. The two grammar alternatives and the two Boolean sign values are exhaustive, so the claimed normal return and exactly signed infinity hold in every case.

Lean proof


  intro s negative h
  dsimp [DecimalGoalVocabularyDefault] at h
  rcases h with ⟨body, hbody, hfor | hfor⟩
  · have hlen : s.val.length = 3 := by
      rw [← List.length_map (fun b : Std.U8 => b.val), hbody]
      exact List.Forall₂.length_eq hfor
    obtain ⟨a, b, c, hvals⟩ := (List.length_eq_three).mp hlen
    rcases s with ⟨vals, bound⟩
    dsimp at hvals
    subst vals
    rw [← hbody] at hfor
    simp at hfor
    have value_identity (x : Std.U8) :
        x = @UScalar.ofNatCore .U8 x.val x.bv.isLt := by
      apply UScalar.eq_of_val_eq
      simp
    have cast105 : UScalar.cast .U64 (105#u8) = 105#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast73 : UScalar.cast .U64 (73#u8) = 73#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast110 : UScalar.cast .U64 (110#u8) = 110#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast78 : UScalar.cast .U64 (78#u8) = 78#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast102 : UScalar.cast .U64 (102#u8) = 102#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast70 : UScalar.cast .U64 (70#u8) = 70#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have shift102 : (102#u64 <<< 16#i32) = ok (6684672#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have shift70 : (70#u64 <<< 16#i32) = ok (4587520#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have shift110 : (110#u64 <<< 8#i32) = ok (28160#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have shift78 : (78#u64 <<< 8#i32) = ok (19968#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have maskA : ((6684672#u64 ||| 28160#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskB : ((6684672#u64 ||| 28160#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskC : ((6684672#u64 ||| 19968#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskD : ((6684672#u64 ||| 19968#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskE : ((4587520#u64 ||| 28160#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskF : ((4587520#u64 ||| 28160#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskG : ((4587520#u64 ||| 19968#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskH : ((4587520#u64 ||| 19968#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have tagTarget : (4607561#u64 : Std.U64) = 4607561#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have length_value : Usize.ofNatCore 3 (by scalar_tac) = 3#usize := by
      apply UScalar.eq_of_val_eq
      simp [UScalar.ofNatCore_val_eq]
    have infinity_value : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY =
        ok (9218868437227405312#u64) := by
      simp only [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY,
        core.f64.F64.INFINITY, ModelF64Infinity]
      rfl
    have neg_infinity_value : F64.Insts.CoreOpsArithNegF64.neg
        (9218868437227405312#u64) = ok (18442240474082181120#u64) := by
      simp only [F64.Insts.CoreOpsArithNegF64.neg, ModelF64Neg]
      rfl
    rcases hfor with ⟨ha | ha, hb | hb, hc | hc⟩
    all_goals
      rw [value_identity a, value_identity b, value_identity c]
      simp [ha, hb, hc]
      cases negative
      · refine ⟨9218868437227405312#u64, ?_, ?_⟩
        · simp [num.imp.dec2flt.parse.parse_inf_nan, Slice.len, Slice.index_usize,
            lift, cast105, cast73, cast110, cast78, cast102, cast70,
            shift102, shift70, shift110, shift78, maskA, maskB, maskC,
            maskD, maskE, maskF, maskG, maskH, tagTarget, length_value,
            infinity_value]
        · dsimp [DecimalGoalVocabularyDefault]
          norm_num
      · refine ⟨18442240474082181120#u64, ?_, ?_⟩
        · simp [num.imp.dec2flt.parse.parse_inf_nan, Slice.len, Slice.index_usize,
            lift, cast105, cast73, cast110, cast78, cast102, cast70,
            shift102, shift70, shift110, shift78, maskA, maskB, maskC,
            maskD, maskE, maskF, maskG, maskH, tagTarget, length_value,
            infinity_value, neg_infinity_value]
        · dsimp [DecimalGoalVocabularyDefault]
          norm_num
  · rw [← hbody] at hfor
    have hlen : s.val.length = 8 := by
      rw [← List.length_map (fun b : Std.U8 => b.val)]
      exact List.Forall₂.length_eq hfor
    have hlen_u : Slice.len s = 8#usize := by
      apply UScalar.eq_of_val_eq
      simpa [Slice.len]
    obtain ⟨w, hread, hbytes⟩ := NumberHelperReadEightBytes s (by omega)
    have caseI : ∀ x : BitVec 8,
        (x.toNat = 105 ∨ x.toNat + 32 = 105) -> x &&& 223#8 = 73#8 := by
      decide +kernel
    have caseN : ∀ x : BitVec 8,
        (x.toNat = 110 ∨ x.toNat + 32 = 110) -> x &&& 223#8 = 78#8 := by
      decide +kernel
    have caseF : ∀ x : BitVec 8,
        (x.toNat = 102 ∨ x.toNat + 32 = 102) -> x &&& 223#8 = 70#8 := by
      decide +kernel
    have caseT : ∀ x : BitVec 8,
        (x.toNat = 116 ∨ x.toNat + 32 = 116) -> x &&& 223#8 = 84#8 := by
      decide +kernel
    have caseY : ∀ x : BitVec 8,
        (x.toNat = 121 ∨ x.toNat + 32 = 121) -> x &&& 223#8 = 89#8 := by
      decide +kernel
    have hblock : ∀ i : Nat, i < 8 ->
        (w.bv &&& (16131858542891098079#u64).bv).extractLsb' (8 * i) 8 =
          (6436850368004902473#u64).bv.extractLsb' (8 * i) 8 := by
      intro i hi
      have hbyte := hbytes i hi
      have hextract :
          w.bv.extractLsb' (8 * i) 8 = (s.val[i]'(by omega)).bv := by
        apply BitVec.eq_of_toNat_eq
        have hpow : 2 ^ (8 * i) = 256 ^ i := by
          calc
            2 ^ (8 * i) = (2 ^ 8) ^ i := by rw [pow_mul]
            _ = 256 ^ i := by norm_num
        simpa [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow,
          hpow] using hbyte
      rw [BitVec.extractLsb'_and, hextract]
      have hrel := (List.forall₂_iff_get).mp hfor |>.2 i
        (by simpa [DecimalGoalVocabularyDefault, hlen] using hi)
        (by simpa using hi)
      simp at hrel
      have hiCases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨
          i = 4 ∨ i = 5 ∨ i = 6 ∨ i = 7 := by omega
      rcases hiCases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl
      all_goals norm_num at hrel ⊢
      · exact caseI _ hrel
      · exact caseN _ hrel
      · exact caseF _ hrel
      · exact caseI _ hrel
      · exact caseN _ hrel
      · exact caseI _ hrel
      · exact caseT _ hrel
      · exact caseY _ hrel
    have hword :
        w.bv &&& (16131858542891098079#u64).bv =
          (6436850368004902473#u64).bv := by
      apply BitVec.eq_of_getLsbD_eq
      intro j hj
      have hi : j / 8 < 8 := by omega
      have hk : j % 8 < 8 := Nat.mod_lt _ (by omega)
      have hb := congrArg (fun z : BitVec 8 => z.getLsbD (j % 8))
        (hblock (j / 8) hi)
      simp only [BitVec.getLsbD_extractLsb'] at hb
      simp [hk] at hb
      have hdecomp : 8 * (j / 8) + j % 8 = j := by omega
      simpa [hdecomp] using hb
    have hmask :
        (w &&& 16131858542891098079#u64) = 6436850368004902473#u64 := by
      apply UScalar.eq_of_val_eq
      exact congrArg BitVec.toNat hword
    have tagTarget : (6436850368004902473#u64 : Std.U64) =
        6436850368004902473#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have infinity_value : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY =
        ok (9218868437227405312#u64) := by
      simp only [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY,
        core.f64.F64.INFINITY, ModelF64Infinity]
      rfl
    have neg_infinity_value : F64.Insts.CoreOpsArithNegF64.neg
        (9218868437227405312#u64) = ok (18442240474082181120#u64) := by
      simp only [F64.Insts.CoreOpsArithNegF64.neg, ModelF64Neg]
      rfl
    cases negative
    · refine ⟨9218868437227405312#u64, ?_, ?_⟩
      · simp [num.imp.dec2flt.parse.parse_inf_nan, hlen_u, hread, lift,
          hmask, tagTarget, infinity_value]
      · dsimp [DecimalGoalVocabularyDefault]
        norm_num
    · refine ⟨18442240474082181120#u64, ?_, ?_⟩
      · simp [num.imp.dec2flt.parse.parse_inf_nan, hlen_u, hread, lift,
          hmask, tagTarget, infinity_value, neg_infinity_value]
      · dsimp [DecimalGoalVocabularyDefault]
        norm_num

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.ModelF64Infinity
import Tablet.ModelF64Neg
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.NumberHelperReadEightBytes
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: SpecialHelperInfinity]
theorem SpecialHelperInfinity :
    ∀ (s : Slice Std.U8) (negative : Bool), DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) none false ->
      ∃ f : F64, num.imp.dec2flt.parse.parse_inf_nan
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative = ok (some f) ∧
        DecimalGoalVocabularyDefault.isInfinity negative f := by
-- BODY
  intro s negative h
  dsimp [DecimalGoalVocabularyDefault] at h
  rcases h with ⟨body, hbody, hfor | hfor⟩
  · have hlen : s.val.length = 3 := by
      rw [← List.length_map (fun b : Std.U8 => b.val), hbody]
      exact List.Forall₂.length_eq hfor
    obtain ⟨a, b, c, hvals⟩ := (List.length_eq_three).mp hlen
    rcases s with ⟨vals, bound⟩
    dsimp at hvals
    subst vals
    rw [← hbody] at hfor
    simp at hfor
    have value_identity (x : Std.U8) :
        x = @UScalar.ofNatCore .U8 x.val x.bv.isLt := by
      apply UScalar.eq_of_val_eq
      simp
    have cast105 : UScalar.cast .U64 (105#u8) = 105#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast73 : UScalar.cast .U64 (73#u8) = 73#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast110 : UScalar.cast .U64 (110#u8) = 110#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast78 : UScalar.cast .U64 (78#u8) = 78#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast102 : UScalar.cast .U64 (102#u8) = 102#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have cast70 : UScalar.cast .U64 (70#u8) = 70#u64 := by
      apply UScalar.eq_of_val_eq
      simp
    have shift102 : (102#u64 <<< 16#i32) = ok (6684672#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have shift70 : (70#u64 <<< 16#i32) = ok (4587520#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have shift110 : (110#u64 <<< 8#i32) = ok (28160#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have shift78 : (78#u64 <<< 8#i32) = ok (19968#u64) := by
      simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_IScalar, UScalar.shiftLeft]
      rw [if_pos (by norm_num), if_pos (by norm_num)]
      congr 1
    have maskA : ((6684672#u64 ||| 28160#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskB : ((6684672#u64 ||| 28160#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskC : ((6684672#u64 ||| 19968#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskD : ((6684672#u64 ||| 19968#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskE : ((4587520#u64 ||| 28160#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskF : ((4587520#u64 ||| 28160#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskG : ((4587520#u64 ||| 19968#u64 ||| 105#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have maskH : ((4587520#u64 ||| 19968#u64 ||| 73#u64) &&&
        16131858542891098079#u64) = 4607561#u64 := by rfl
    have tagTarget : (4607561#u64 : Std.U64) = 4607561#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have length_value : Usize.ofNatCore 3 (by scalar_tac) = 3#usize := by
      apply UScalar.eq_of_val_eq
      simp [UScalar.ofNatCore_val_eq]
    have infinity_value : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY =
        ok (9218868437227405312#u64) := by
      simp only [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY,
        core.f64.F64.INFINITY, ModelF64Infinity]
      rfl
    have neg_infinity_value : F64.Insts.CoreOpsArithNegF64.neg
        (9218868437227405312#u64) = ok (18442240474082181120#u64) := by
      simp only [F64.Insts.CoreOpsArithNegF64.neg, ModelF64Neg]
      rfl
    rcases hfor with ⟨ha | ha, hb | hb, hc | hc⟩
    all_goals
      rw [value_identity a, value_identity b, value_identity c]
      simp [ha, hb, hc]
      cases negative
      · refine ⟨9218868437227405312#u64, ?_, ?_⟩
        · simp [num.imp.dec2flt.parse.parse_inf_nan, Slice.len, Slice.index_usize,
            lift, cast105, cast73, cast110, cast78, cast102, cast70,
            shift102, shift70, shift110, shift78, maskA, maskB, maskC,
            maskD, maskE, maskF, maskG, maskH, tagTarget, length_value,
            infinity_value]
        · dsimp [DecimalGoalVocabularyDefault]
          norm_num
      · refine ⟨18442240474082181120#u64, ?_, ?_⟩
        · simp [num.imp.dec2flt.parse.parse_inf_nan, Slice.len, Slice.index_usize,
            lift, cast105, cast73, cast110, cast78, cast102, cast70,
            shift102, shift70, shift110, shift78, maskA, maskB, maskC,
            maskD, maskE, maskF, maskG, maskH, tagTarget, length_value,
            infinity_value, neg_infinity_value]
        · dsimp [DecimalGoalVocabularyDefault]
          norm_num
  · rw [← hbody] at hfor
    have hlen : s.val.length = 8 := by
      rw [← List.length_map (fun b : Std.U8 => b.val)]
      exact List.Forall₂.length_eq hfor
    have hlen_u : Slice.len s = 8#usize := by
      apply UScalar.eq_of_val_eq
      simpa [Slice.len]
    obtain ⟨w, hread, hbytes⟩ := NumberHelperReadEightBytes s (by omega)
    have caseI : ∀ x : BitVec 8,
        (x.toNat = 105 ∨ x.toNat + 32 = 105) -> x &&& 223#8 = 73#8 := by
      decide +kernel
    have caseN : ∀ x : BitVec 8,
        (x.toNat = 110 ∨ x.toNat + 32 = 110) -> x &&& 223#8 = 78#8 := by
      decide +kernel
    have caseF : ∀ x : BitVec 8,
        (x.toNat = 102 ∨ x.toNat + 32 = 102) -> x &&& 223#8 = 70#8 := by
      decide +kernel
    have caseT : ∀ x : BitVec 8,
        (x.toNat = 116 ∨ x.toNat + 32 = 116) -> x &&& 223#8 = 84#8 := by
      decide +kernel
    have caseY : ∀ x : BitVec 8,
        (x.toNat = 121 ∨ x.toNat + 32 = 121) -> x &&& 223#8 = 89#8 := by
      decide +kernel
    have hblock : ∀ i : Nat, i < 8 ->
        (w.bv &&& (16131858542891098079#u64).bv).extractLsb' (8 * i) 8 =
          (6436850368004902473#u64).bv.extractLsb' (8 * i) 8 := by
      intro i hi
      have hbyte := hbytes i hi
      have hextract :
          w.bv.extractLsb' (8 * i) 8 = (s.val[i]'(by omega)).bv := by
        apply BitVec.eq_of_toNat_eq
        have hpow : 2 ^ (8 * i) = 256 ^ i := by
          calc
            2 ^ (8 * i) = (2 ^ 8) ^ i := by rw [pow_mul]
            _ = 256 ^ i := by norm_num
        simpa [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow,
          hpow] using hbyte
      rw [BitVec.extractLsb'_and, hextract]
      have hrel := (List.forall₂_iff_get).mp hfor |>.2 i
        (by simpa [DecimalGoalVocabularyDefault, hlen] using hi)
        (by simpa using hi)
      simp at hrel
      have hiCases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨
          i = 4 ∨ i = 5 ∨ i = 6 ∨ i = 7 := by omega
      rcases hiCases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl
      all_goals norm_num at hrel ⊢
      · exact caseI _ hrel
      · exact caseN _ hrel
      · exact caseF _ hrel
      · exact caseI _ hrel
      · exact caseN _ hrel
      · exact caseI _ hrel
      · exact caseT _ hrel
      · exact caseY _ hrel
    have hword :
        w.bv &&& (16131858542891098079#u64).bv =
          (6436850368004902473#u64).bv := by
      apply BitVec.eq_of_getLsbD_eq
      intro j hj
      have hi : j / 8 < 8 := by omega
      have hk : j % 8 < 8 := Nat.mod_lt _ (by omega)
      have hb := congrArg (fun z : BitVec 8 => z.getLsbD (j % 8))
        (hblock (j / 8) hi)
      simp only [BitVec.getLsbD_extractLsb'] at hb
      simp [hk] at hb
      have hdecomp : 8 * (j / 8) + j % 8 = j := by omega
      simpa [hdecomp] using hb
    have hmask :
        (w &&& 16131858542891098079#u64) = 6436850368004902473#u64 := by
      apply UScalar.eq_of_val_eq
      exact congrArg BitVec.toNat hword
    have tagTarget : (6436850368004902473#u64 : Std.U64) =
        6436850368004902473#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have infinity_value : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY =
        ok (9218868437227405312#u64) := by
      simp only [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITY,
        core.f64.F64.INFINITY, ModelF64Infinity]
      rfl
    have neg_infinity_value : F64.Insts.CoreOpsArithNegF64.neg
        (9218868437227405312#u64) = ok (18442240474082181120#u64) := by
      simp only [F64.Insts.CoreOpsArithNegF64.neg, ModelF64Neg]
      rfl
    cases negative
    · refine ⟨9218868437227405312#u64, ?_, ?_⟩
      · simp [num.imp.dec2flt.parse.parse_inf_nan, hlen_u, hread, lift,
          hmask, tagTarget, infinity_value]
      · dsimp [DecimalGoalVocabularyDefault]
        norm_num
    · refine ⟨18442240474082181120#u64, ?_, ?_⟩
      · simp [num.imp.dec2flt.parse.parse_inf_nan, hlen_u, hread, lift,
          hmask, tagTarget, infinity_value, neg_infinity_value]
      · dsimp [DecimalGoalVocabularyDefault]
        norm_num

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 81 entries
Technical checking records
Local closure summary
{
  "node": "SpecialHelperInfinity",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "b6264860aa49673f3ee8fcba250d74a1745f2571d40a4cfd70b62dacff5bd873",
  "active_statement_hash": "182ccfe02ff0a21118ae552c99c758c3d56a3b880089c5dfbfdd062710a8e600",
  "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-124",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_INFINITY": "3feae47e2e2f9c18",
    "NumberHelperReadEightBytes": "134d29b1dd90f0d5",
    "num_imp_dec2flt_parse_parse_inf_nan": "213cd80a9d5d7110"
  },
  "strict_definition_deps": {
    "Binary64Model": "5786328d6a028d83",
    "Binary64ModelDefault": "47013ebe5c83894c",
    "DecimalGoalVocabulary": "0717fd246d7ea78a",
    "DecimalGoalVocabularyDefault": "55eb6bce0e8a4131",
    "DecimalLexeme": "250be645520aec86",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_INFINITY": "618a328783684238",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_NAN": "faf51f3aa8d94806",
    "ModelF64Infinity": "172db09b8469299c",
    "ModelF64Neg": "78a021de99eb373b",
    "Preamble": "5575719dcb1443eb",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64": "279b0c1cd8ec9e39",
    "core_ops_arith_Neg": "0ff07135a60bcbf9",
    "num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
    "num_imp_dec2flt_decimal_Decimal": "63fd2f021dd0ef41",
    "num_imp_dec2flt_parse_parse_inf_nan": "85655c19a8791b54",
    "num_imp_traits_Float": "062e1d14cad682f2"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:55c69ac9345b5a6343a4545f3cb851f9eeaa3aff0ea416ea9b93358a78a65463",
  "current_fingerprint": "sound-v2:55c69ac9345b5a6343a4545f3cb851f9eeaa3aff0ea416ea9b93358a78a65463",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}