ParserSpecialRejectionSafeLength

Lean checked

Statement

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

Helper · Exact rejection by the extracted special-literal helper

For every byte slice s and Boolean n, if the complete byte list of s is neither an unsigned case-insensitive infinity literal nor an unsigned case-insensitive NaN literal, then the extracted specialized parse_inf_nan operation for binary64 returns normally with None on (s,n).

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_modelNumImpTraitsFloatU64
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.NumberHelperReadEightBytes
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_parse_parse_inf_nan

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSpecialRejectionSafeLength]
theorem ParserSpecialRejectionSafeLength :
    ∀ (s : Slice Std.U8) (negative : Bool),
      (¬ DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes s) none false) ->
      (¬ DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes s) none true) ->
      num.imp.dec2flt.parse.parse_inf_nan
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative = ok none := 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 parse parse inf nan. Its only potentially successful lengths are eight and three. If the slice length is neither, both length tests are false and the definition returns ok none without indexing the slice.
Suppose first that the length is eight. By NumberHelperReadEightBytes, the extracted read succeeds with a 64-bit word w whose ith little-endian byte is exactly byte i of s, for every 0\leq i<8. The following AND clears bit 5 in every byte, as specified by ModelU64BitAnd, because every byte of \mathtt{0xdfdfdfdfdfdfdfdf} is \mathtt{0xdf}. Among the three displayed match constants in the eight-byte branch, only 6436850368004902473=\mathtt{0x5954494e49464e49} can return Some; in little-endian order its bytes spell INFINITY. If the masked word equalled this constant, extracting each of its eight bytes would show that the corresponding input byte is either the displayed uppercase byte or that byte plus \mathtt{0x20}, namely the lowercase form. The complete input list would therefore satisfy the eight-letter infinity alternative of specialLiteral in DecimalGoalVocabularyDefault with sign none and kind false, contrary to the first hypothesis. Thus this successful match is impossible. The other two constants and the default branch return None directly.
Now suppose the length is three. The indices 0,1,2 are in bounds, so the three indexing operations succeed with the corresponding bytes. Each widening cast from u8 to u64 preserves the byte value. The shift counts 16 and 8 are nonnegative and below 64, hence the checked shifts succeed. Their occupied bit ranges are disjoint, and the two ORs described by ModelU64BitOr assemble b_0+b_1 2^8+b_2 2^{16}. The final AND again clears exactly the ASCII case bit of each byte.
There are two successful three-byte constants. The little-endian bytes of 4607561=\mathtt{0x464e49} spell INF. Equality with this masked word forces the three input bytes to be uppercase or lowercase variants of inf; choosing the complete input as the body gives an unsigned infinity witness under DecimalGoalVocabularyDefault, contradicting the first hypothesis. Likewise the little-endian bytes of 5128526=\mathtt{0x4e414e} spell NAN, and equality would give the unsigned NaN witness forbidden by the second hypothesis. The remaining displayed constant and the default branch return None. Both successful guards have therefore been excluded, independently of the separate Boolean sign argument, and every length case returns ok none.

Lean proof


  intro s negative hnotInf hnotNan
  unfold num.imp.dec2flt.parse.parse_inf_nan
  simp only
  by_cases h8 : Slice.len s = 8#usize
  · simp only [h8, if_pos]
    have hlen : 8 <= s.val.length := by
      have hv := congrArg UScalar.val h8
      simp [Slice.len] at hv
      omega
    obtain ⟨w, hw, hbytes⟩ := NumberHelperReadEightBytes s hlen
    rw [hw]
    simp only [lift]
    by_cases hmatch :
        (w &&& 16131858542891098079#u64) = 6436850368004902473#u64
    · exfalso
      apply hnotInf
      dsimp [DecimalGoalVocabularyDefault]
      refine ⟨s.val.map (fun b : Std.U8 => b.val), by simp, Or.inr ?_⟩
      apply (List.forall₂_iff_get).2
      constructor
      · have hv := congrArg UScalar.val h8
        simpa [Slice.len] using hv
      · intro i hiSource hiTarget
        have hi : i < 8 := by simpa using hiTarget
        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
        have hmatchBv :
            w.bv &&& (16131858542891098079#u64).bv =
              (6436850368004902473#u64).bv := by
          exact congrArg UScalar.bv hmatch
        have caseI : ∀ x : BitVec 8,
            x &&& 223#8 = 73#8 -> x.toNat = 105 ∨ x.toNat + 32 = 105 := by
          decide +kernel
        have caseN : ∀ x : BitVec 8,
            x &&& 223#8 = 78#8 -> x.toNat = 110 ∨ x.toNat + 32 = 110 := by
          decide +kernel
        have caseF : ∀ x : BitVec 8,
            x &&& 223#8 = 70#8 -> x.toNat = 102 ∨ x.toNat + 32 = 102 := by
          decide +kernel
        have caseT : ∀ x : BitVec 8,
            x &&& 223#8 = 84#8 -> x.toNat = 116 ∨ x.toNat + 32 = 116 := by
          decide +kernel
        have caseY : ∀ x : BitVec 8,
            x &&& 223#8 = 89#8 -> x.toNat = 121 ∨ x.toNat + 32 = 121 := by
          decide +kernel
        have hmasked :
            (s.val[i]'(by omega)).bv &&&
                (16131858542891098079#u64).bv.extractLsb' (8 * i) 8 =
              (6436850368004902473#u64).bv.extractLsb' (8 * i) 8 := by
          rw [← hextract, ← BitVec.extractLsb'_and]
          exact congrArg (fun z : BitVec 64 => z.extractLsb' (8 * i) 8) hmatchBv
        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 simp at hiSource hiTarget ⊢
        · have hm : (s.val[0]'(by omega)).bv &&& 223#8 = 73#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseI _ hm
        · have hm : (s.val[1]'(by omega)).bv &&& 223#8 = 78#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseN _ hm
        · have hm : (s.val[2]'(by omega)).bv &&& 223#8 = 70#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseF _ hm
        · have hm : (s.val[3]'(by omega)).bv &&& 223#8 = 73#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseI _ hm
        · have hm : (s.val[4]'(by omega)).bv &&& 223#8 = 78#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseN _ hm
        · have hm : (s.val[5]'(by omega)).bv &&& 223#8 = 73#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseI _ hm
        · have hm : (s.val[6]'(by omega)).bv &&& 223#8 = 84#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseT _ hm
        · have hm : (s.val[7]'(by omega)).bv &&& 223#8 = 89#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseY _ hm
    · unfold num.imp.dec2flt.parse.parse_inf_nan.match_1
      simp_all
      intro _ heq
      exfalso
      apply hmatch
      simpa using congrArg BitVec.toNat heq
  · by_cases h3 : Slice.len s = 3#usize
    · have hp :
          num.imp.dec2flt.parse.parse_inf_nan
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative
            ⦃ o => o = none ⦄ := by
        unfold num.imp.dec2flt.parse.parse_inf_nan
        simp only
        rw [if_neg h8, if_pos h3]
        step
        step
        step
        step
        step
        step
        step
        step
        step
        step
        step
        unfold num.imp.dec2flt.parse.parse_inf_nan.match_1
        have hlen : s.val.length = 3 := by
          have hv := congrArg UScalar.val h3
          simpa [Slice.len] using hv
        have haBv : a.bv = i2.bv.zeroExtend 64 := by
          change a.bv = (UScalar.cast .U64 i2).bv
          exact congrArg UScalar.bv a_post
        have hbBv : b.bv = i3.bv.zeroExtend 64 := by
          change b.bv = (UScalar.cast .U64 i3).bv
          exact congrArg UScalar.bv b_post
        have hcBv : c.bv = i4.bv.zeroExtend 64 := by
          change c.bv = (UScalar.cast .U64 i4).bv
          exact congrArg UScalar.bv c_post
        have hregister1Bv :
            register1.bv = register.bv &&& (16131858542891098079#64) := by
          simpa using register1_post2
        have caseA : ∀ x : BitVec 8,
            x &&& 223#8 = 65#8 -> x.toNat = 97 ∨ x.toNat + 32 = 97 := by
          decide +kernel
        have caseF : ∀ x : BitVec 8,
            x &&& 223#8 = 70#8 -> x.toNat = 102 ∨ x.toNat + 32 = 102 := by
          decide +kernel
        have caseI : ∀ x : BitVec 8,
            x &&& 223#8 = 73#8 -> x.toNat = 105 ∨ x.toNat + 32 = 105 := by
          decide +kernel
        have caseN : ∀ x : BitVec 8,
            x &&& 223#8 = 78#8 -> x.toNat = 110 ∨ x.toNat + 32 = 110 := by
          decide +kernel
        have makeSpecial (l0 l1 l2 : Nat)
            (r0 : i2.bv.toNat = l0 ∨ i2.bv.toNat + 32 = l0)
            (r1 : i3.bv.toNat = l1 ∨ i3.bv.toNat + 32 = l1)
            (r2 : i4.bv.toNat = l2 ∨ i4.bv.toNat + 32 = l2) :
            List.Forall₂ (fun actual lower =>
              actual = lower ∨ actual + 32 = lower)
              (DecimalGoalVocabularyDefault.bytes s) [l0, l1, l2] := by
          apply (List.forall₂_iff_get).2
          constructor
          · simpa [DecimalGoalVocabularyDefault] using hlen
          · intro i hiSource hiTarget
            have hi : i < 3 := by simpa using hiTarget
            have hiCases : i = 0 ∨ i = 1 ∨ i = 2 := by omega
            rcases hiCases with rfl | rfl | rfl
            · simpa [DecimalGoalVocabularyDefault, i2_post] using r0
            · simpa [DecimalGoalVocabularyDefault, i3_post] using r1
            · simpa [DecimalGoalVocabularyDefault, i4_post] using r2
        have slices : ∀ q : BitVec 8,
            (q.zeroExtend 64).extractLsb' 0 8 = q ∧
            (q.zeroExtend 64).extractLsb' 8 8 = 0#8 ∧
            (q.zeroExtend 64).extractLsb' 16 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 8).extractLsb' 0 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 8).extractLsb' 8 8 = q ∧
            (q.zeroExtend 64 <<< 8).extractLsb' 16 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 16).extractLsb' 0 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 16).extractLsb' 8 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 16).extractLsb' 16 8 = q := by
          decide +kernel
        have decodeBytes : ∀ (x y z : BitVec 8) (word : BitVec 64),
            ((((z.zeroExtend 64 <<< 16) ||| (y.zeroExtend 64 <<< 8)) |||
                x.zeroExtend 64) &&& (16131858542891098079#64)) =
                word ->
              x &&& 223#8 = word.extractLsb' 0 8 ∧
                y &&& 223#8 = word.extractLsb' 8 8 ∧
                z &&& 223#8 = word.extractLsb' 16 8 := by
          intro x y z word hword
          have h0 := congrArg (fun w : BitVec 64 => w.extractLsb' 0 8) hword
          have h1 := congrArg (fun w : BitVec 64 => w.extractLsb' 8 8) hword
          have h2 := congrArg (fun w : BitVec 64 => w.extractLsb' 16 8) hword
          simp [BitVec.extractLsb'_and, BitVec.extractLsb'_or] at h0 h1 h2
          obtain ⟨x0, x8, x16, _, _, _, _, _, _⟩ := slices x
          obtain ⟨_, _, _, ys0, ys8, ys16, _, _, _⟩ := slices y
          obtain ⟨_, _, _, _, _, _, zss0, zss8, zss16⟩ := slices z
          simp only [x0, x8, x16, ys0, ys8, ys16, zss0, zss8, zss16,
            BitVec.zero_or, BitVec.or_zero] at h0 h1 h2
          exact ⟨h0, h1, h2⟩
        have decodeInf : ∀ x y z : BitVec 8,
            ((((z.zeroExtend 64 <<< 16) ||| (y.zeroExtend 64 <<< 8)) |||
                x.zeroExtend 64) &&& (16131858542891098079#64)) =
                4607561#64 ->
              x &&& 223#8 = 73#8 ∧ y &&& 223#8 = 78#8 ∧
                z &&& 223#8 = 70#8 := by
          intro x y z hword
          simpa using decodeBytes x y z 4607561#64 hword
        have decodeNan : ∀ x y z : BitVec 8,
            ((((z.zeroExtend 64 <<< 16) ||| (y.zeroExtend 64 <<< 8)) |||
                x.zeroExtend 64) &&& (16131858542891098079#64)) =
                5128526#64 ->
              x &&& 223#8 = 78#8 ∧ y &&& 223#8 = 65#8 ∧
                z &&& 223#8 = 78#8 := by
          intro x y z hword
          simpa using decodeBytes x y z 5128526#64 hword
        by_cases hinf : register1.bv = 4607561#64
        · exfalso
          apply hnotInf
          dsimp [DecimalGoalVocabularyDefault]
          refine ⟨s.val.map (fun b : Std.U8 => b.val), by simp, Or.inl ?_⟩
          have hassembled :
              ((((i4.bv.zeroExtend 64 <<< 16) |||
                  (i3.bv.zeroExtend 64 <<< 8)) ||| i2.bv.zeroExtend 64) &&&
                  (16131858542891098079#64)) = 4607561#64 := by
            rw [← haBv, ← hbBv, ← hcBv, ← i5_post2, ← i6_post2,
              ← i7_post2, ← register_post2, ← hregister1Bv]
            exact hinf
          obtain ⟨hm0, hm1, hm2⟩ := decodeInf _ _ _ hassembled
          exact makeSpecial 105 110 102
            (caseI _ hm0) (caseN _ hm1) (caseF _ hm2)
        · by_cases hinfinity : register1.bv = 6436850368004902473#64
          · simp [hinfinity, Aeneas.Std.WP.spec,
              Aeneas.Std.WP.theta, Aeneas.Std.WP.wp_return]
          · by_cases hnan : register1.bv = 5128526#64
            · exfalso
              apply hnotNan
              dsimp [DecimalGoalVocabularyDefault]
              refine ⟨s.val.map (fun b : Std.U8 => b.val), by simp, ?_⟩
              have hassembled :
                  ((((i4.bv.zeroExtend 64 <<< 16) |||
                      (i3.bv.zeroExtend 64 <<< 8)) ||| i2.bv.zeroExtend 64) &&&
                      (16131858542891098079#64)) = 5128526#64 := by
                rw [← haBv, ← hbBv, ← hcBv, ← i5_post2, ← i6_post2,
                  ← i7_post2, ← register_post2, ← hregister1Bv]
                exact hnan
              obtain ⟨hm0, hm1, hm2⟩ := decodeNan _ _ _ hassembled
              exact makeSpecial 110 97 110
                (caseN _ hm0) (caseA _ hm1) (caseN _ hm2)
            · simp [hinf, hinfinity, hnan, Aeneas.Std.WP.spec,
                Aeneas.Std.WP.theta, Aeneas.Std.WP.wp_return]
      obtain ⟨o, ho, rfl⟩ := Aeneas.Std.WP.spec_imp_exists hp
      exact ho
    · simp only [h8, h3, if_false, lift]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.NumberHelperReadEightBytes
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_parse_parse_inf_nan

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSpecialRejectionSafeLength]
theorem ParserSpecialRejectionSafeLength :
    ∀ (s : Slice Std.U8) (negative : Bool),
      (¬ DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes s) none false) ->
      (¬ DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.bytes s) none true) ->
      num.imp.dec2flt.parse.parse_inf_nan
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative = ok none := by
-- BODY
  intro s negative hnotInf hnotNan
  unfold num.imp.dec2flt.parse.parse_inf_nan
  simp only
  by_cases h8 : Slice.len s = 8#usize
  · simp only [h8, if_pos]
    have hlen : 8 <= s.val.length := by
      have hv := congrArg UScalar.val h8
      simp [Slice.len] at hv
      omega
    obtain ⟨w, hw, hbytes⟩ := NumberHelperReadEightBytes s hlen
    rw [hw]
    simp only [lift]
    by_cases hmatch :
        (w &&& 16131858542891098079#u64) = 6436850368004902473#u64
    · exfalso
      apply hnotInf
      dsimp [DecimalGoalVocabularyDefault]
      refine ⟨s.val.map (fun b : Std.U8 => b.val), by simp, Or.inr ?_⟩
      apply (List.forall₂_iff_get).2
      constructor
      · have hv := congrArg UScalar.val h8
        simpa [Slice.len] using hv
      · intro i hiSource hiTarget
        have hi : i < 8 := by simpa using hiTarget
        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
        have hmatchBv :
            w.bv &&& (16131858542891098079#u64).bv =
              (6436850368004902473#u64).bv := by
          exact congrArg UScalar.bv hmatch
        have caseI : ∀ x : BitVec 8,
            x &&& 223#8 = 73#8 -> x.toNat = 105 ∨ x.toNat + 32 = 105 := by
          decide +kernel
        have caseN : ∀ x : BitVec 8,
            x &&& 223#8 = 78#8 -> x.toNat = 110 ∨ x.toNat + 32 = 110 := by
          decide +kernel
        have caseF : ∀ x : BitVec 8,
            x &&& 223#8 = 70#8 -> x.toNat = 102 ∨ x.toNat + 32 = 102 := by
          decide +kernel
        have caseT : ∀ x : BitVec 8,
            x &&& 223#8 = 84#8 -> x.toNat = 116 ∨ x.toNat + 32 = 116 := by
          decide +kernel
        have caseY : ∀ x : BitVec 8,
            x &&& 223#8 = 89#8 -> x.toNat = 121 ∨ x.toNat + 32 = 121 := by
          decide +kernel
        have hmasked :
            (s.val[i]'(by omega)).bv &&&
                (16131858542891098079#u64).bv.extractLsb' (8 * i) 8 =
              (6436850368004902473#u64).bv.extractLsb' (8 * i) 8 := by
          rw [← hextract, ← BitVec.extractLsb'_and]
          exact congrArg (fun z : BitVec 64 => z.extractLsb' (8 * i) 8) hmatchBv
        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 simp at hiSource hiTarget ⊢
        · have hm : (s.val[0]'(by omega)).bv &&& 223#8 = 73#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseI _ hm
        · have hm : (s.val[1]'(by omega)).bv &&& 223#8 = 78#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseN _ hm
        · have hm : (s.val[2]'(by omega)).bv &&& 223#8 = 70#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseF _ hm
        · have hm : (s.val[3]'(by omega)).bv &&& 223#8 = 73#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseI _ hm
        · have hm : (s.val[4]'(by omega)).bv &&& 223#8 = 78#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseN _ hm
        · have hm : (s.val[5]'(by omega)).bv &&& 223#8 = 73#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseI _ hm
        · have hm : (s.val[6]'(by omega)).bv &&& 223#8 = 84#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseT _ hm
        · have hm : (s.val[7]'(by omega)).bv &&& 223#8 = 89#8 := by
            norm_num at hmasked ⊢
            exact hmasked
          simpa using caseY _ hm
    · unfold num.imp.dec2flt.parse.parse_inf_nan.match_1
      simp_all
      intro _ heq
      exfalso
      apply hmatch
      simpa using congrArg BitVec.toNat heq
  · by_cases h3 : Slice.len s = 3#usize
    · have hp :
          num.imp.dec2flt.parse.parse_inf_nan
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative
            ⦃ o => o = none ⦄ := by
        unfold num.imp.dec2flt.parse.parse_inf_nan
        simp only
        rw [if_neg h8, if_pos h3]
        step
        step
        step
        step
        step
        step
        step
        step
        step
        step
        step
        unfold num.imp.dec2flt.parse.parse_inf_nan.match_1
        have hlen : s.val.length = 3 := by
          have hv := congrArg UScalar.val h3
          simpa [Slice.len] using hv
        have haBv : a.bv = i2.bv.zeroExtend 64 := by
          change a.bv = (UScalar.cast .U64 i2).bv
          exact congrArg UScalar.bv a_post
        have hbBv : b.bv = i3.bv.zeroExtend 64 := by
          change b.bv = (UScalar.cast .U64 i3).bv
          exact congrArg UScalar.bv b_post
        have hcBv : c.bv = i4.bv.zeroExtend 64 := by
          change c.bv = (UScalar.cast .U64 i4).bv
          exact congrArg UScalar.bv c_post
        have hregister1Bv :
            register1.bv = register.bv &&& (16131858542891098079#64) := by
          simpa using register1_post2
        have caseA : ∀ x : BitVec 8,
            x &&& 223#8 = 65#8 -> x.toNat = 97 ∨ x.toNat + 32 = 97 := by
          decide +kernel
        have caseF : ∀ x : BitVec 8,
            x &&& 223#8 = 70#8 -> x.toNat = 102 ∨ x.toNat + 32 = 102 := by
          decide +kernel
        have caseI : ∀ x : BitVec 8,
            x &&& 223#8 = 73#8 -> x.toNat = 105 ∨ x.toNat + 32 = 105 := by
          decide +kernel
        have caseN : ∀ x : BitVec 8,
            x &&& 223#8 = 78#8 -> x.toNat = 110 ∨ x.toNat + 32 = 110 := by
          decide +kernel
        have makeSpecial (l0 l1 l2 : Nat)
            (r0 : i2.bv.toNat = l0 ∨ i2.bv.toNat + 32 = l0)
            (r1 : i3.bv.toNat = l1 ∨ i3.bv.toNat + 32 = l1)
            (r2 : i4.bv.toNat = l2 ∨ i4.bv.toNat + 32 = l2) :
            List.Forall₂ (fun actual lower =>
              actual = lower ∨ actual + 32 = lower)
              (DecimalGoalVocabularyDefault.bytes s) [l0, l1, l2] := by
          apply (List.forall₂_iff_get).2
          constructor
          · simpa [DecimalGoalVocabularyDefault] using hlen
          · intro i hiSource hiTarget
            have hi : i < 3 := by simpa using hiTarget
            have hiCases : i = 0 ∨ i = 1 ∨ i = 2 := by omega
            rcases hiCases with rfl | rfl | rfl
            · simpa [DecimalGoalVocabularyDefault, i2_post] using r0
            · simpa [DecimalGoalVocabularyDefault, i3_post] using r1
            · simpa [DecimalGoalVocabularyDefault, i4_post] using r2
        have slices : ∀ q : BitVec 8,
            (q.zeroExtend 64).extractLsb' 0 8 = q ∧
            (q.zeroExtend 64).extractLsb' 8 8 = 0#8 ∧
            (q.zeroExtend 64).extractLsb' 16 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 8).extractLsb' 0 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 8).extractLsb' 8 8 = q ∧
            (q.zeroExtend 64 <<< 8).extractLsb' 16 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 16).extractLsb' 0 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 16).extractLsb' 8 8 = 0#8 ∧
            (q.zeroExtend 64 <<< 16).extractLsb' 16 8 = q := by
          decide +kernel
        have decodeBytes : ∀ (x y z : BitVec 8) (word : BitVec 64),
            ((((z.zeroExtend 64 <<< 16) ||| (y.zeroExtend 64 <<< 8)) |||
                x.zeroExtend 64) &&& (16131858542891098079#64)) =
                word ->
              x &&& 223#8 = word.extractLsb' 0 8 ∧
                y &&& 223#8 = word.extractLsb' 8 8 ∧
                z &&& 223#8 = word.extractLsb' 16 8 := by
          intro x y z word hword
          have h0 := congrArg (fun w : BitVec 64 => w.extractLsb' 0 8) hword
          have h1 := congrArg (fun w : BitVec 64 => w.extractLsb' 8 8) hword
          have h2 := congrArg (fun w : BitVec 64 => w.extractLsb' 16 8) hword
          simp [BitVec.extractLsb'_and, BitVec.extractLsb'_or] at h0 h1 h2
          obtain ⟨x0, x8, x16, _, _, _, _, _, _⟩ := slices x
          obtain ⟨_, _, _, ys0, ys8, ys16, _, _, _⟩ := slices y
          obtain ⟨_, _, _, _, _, _, zss0, zss8, zss16⟩ := slices z
          simp only [x0, x8, x16, ys0, ys8, ys16, zss0, zss8, zss16,
            BitVec.zero_or, BitVec.or_zero] at h0 h1 h2
          exact ⟨h0, h1, h2⟩
        have decodeInf : ∀ x y z : BitVec 8,
            ((((z.zeroExtend 64 <<< 16) ||| (y.zeroExtend 64 <<< 8)) |||
                x.zeroExtend 64) &&& (16131858542891098079#64)) =
                4607561#64 ->
              x &&& 223#8 = 73#8 ∧ y &&& 223#8 = 78#8 ∧
                z &&& 223#8 = 70#8 := by
          intro x y z hword
          simpa using decodeBytes x y z 4607561#64 hword
        have decodeNan : ∀ x y z : BitVec 8,
            ((((z.zeroExtend 64 <<< 16) ||| (y.zeroExtend 64 <<< 8)) |||
                x.zeroExtend 64) &&& (16131858542891098079#64)) =
                5128526#64 ->
              x &&& 223#8 = 78#8 ∧ y &&& 223#8 = 65#8 ∧
                z &&& 223#8 = 78#8 := by
          intro x y z hword
          simpa using decodeBytes x y z 5128526#64 hword
        by_cases hinf : register1.bv = 4607561#64
        · exfalso
          apply hnotInf
          dsimp [DecimalGoalVocabularyDefault]
          refine ⟨s.val.map (fun b : Std.U8 => b.val), by simp, Or.inl ?_⟩
          have hassembled :
              ((((i4.bv.zeroExtend 64 <<< 16) |||
                  (i3.bv.zeroExtend 64 <<< 8)) ||| i2.bv.zeroExtend 64) &&&
                  (16131858542891098079#64)) = 4607561#64 := by
            rw [← haBv, ← hbBv, ← hcBv, ← i5_post2, ← i6_post2,
              ← i7_post2, ← register_post2, ← hregister1Bv]
            exact hinf
          obtain ⟨hm0, hm1, hm2⟩ := decodeInf _ _ _ hassembled
          exact makeSpecial 105 110 102
            (caseI _ hm0) (caseN _ hm1) (caseF _ hm2)
        · by_cases hinfinity : register1.bv = 6436850368004902473#64
          · simp [hinfinity, Aeneas.Std.WP.spec,
              Aeneas.Std.WP.theta, Aeneas.Std.WP.wp_return]
          · by_cases hnan : register1.bv = 5128526#64
            · exfalso
              apply hnotNan
              dsimp [DecimalGoalVocabularyDefault]
              refine ⟨s.val.map (fun b : Std.U8 => b.val), by simp, ?_⟩
              have hassembled :
                  ((((i4.bv.zeroExtend 64 <<< 16) |||
                      (i3.bv.zeroExtend 64 <<< 8)) ||| i2.bv.zeroExtend 64) &&&
                      (16131858542891098079#64)) = 5128526#64 := by
                rw [← haBv, ← hbBv, ← hcBv, ← i5_post2, ← i6_post2,
                  ← i7_post2, ← register_post2, ← hregister1Bv]
                exact hnan
              obtain ⟨hm0, hm1, hm2⟩ := decodeNan _ _ _ hassembled
              exact makeSpecial 110 97 110
                (caseN _ hm0) (caseA _ hm1) (caseN _ hm2)
            · simp [hinf, hinfinity, hnan, Aeneas.Std.WP.spec,
                Aeneas.Std.WP.theta, Aeneas.Std.WP.wp_return]
      obtain ⟨o, ho, rfl⟩ := Aeneas.Std.WP.spec_imp_exists hp
      exact ho
    · simp only [h8, h3, if_false, lift]

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (81)
More program dependencies (39)
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": "ParserSpecialRejectionSafeLength",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "209499fbe889b83a23569327bf7ea861ffe14105d758f46ed7916c5cf306047b",
  "active_statement_hash": "cc79454212499a69d15200565a9ad061013bf3ce8e9b2b6fe0328a6f4ebfad47",
  "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-117",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "NumberHelperReadEightBytes": "134d29b1dd90f0d5",
    "num_imp_dec2flt_parse_parse_inf_nan": "faf0081b4c91301b"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "0717fd246d7ea78a",
    "DecimalGoalVocabularyDefault": "55eb6bce0e8a4131",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_INFINITY": "618a328783684238",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_NAN": "faf51f3aa8d94806",
    "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": "4c41a56bf44cb31e",
    "num_imp_dec2flt_parse_parse_inf_nan": "f0fbcb51738b1e4e",
    "num_imp_traits_Float": "062e1d14cad682f2"
  }
}
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:f4e9bb790ce4afccd04a576fdeb1936531205786a7cc27dae9304ce51ebfe0d4",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}