NumberHelperEightDigitWord

Lean checked

Statement

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

Helper · Accepted eight-byte words contain only decimal digits

If the extracted eight-digit predicate accepts a 64-bit word w, then for each i<8 the ith little-endian byte
\left\lfloor w/256^i\right\rfloor\bmod 256
lies in the interval [48,57].

Lean statement

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

import Tablet.num_imp_dec2flt_common_is_8digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: NumberHelperEightDigitWord]
theorem NumberHelperEightDigitWord (w : Std.U64)
    (h : num.imp.dec2flt.common.is_8digits w = ok true) :
    forall i : Nat, i < 8 ->
      48 <= (w.val / (256^i)) % 256 ∧
        (w.val / (256^i)) % 256 <= 57 := 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 common is 8digits. Its accepted equality says that every bit selected by the mask 0x8080808080808080 is zero in both the wrapping sum w+\texttt{0x4646464646464646} and the wrapping difference w-\texttt{0x3030303030303030}. In particular, for every i<8, bit 8i+7 is zero in both results. This is exactly the high bit of byte i.
For k=i+1, truncate both operations to their least significant 8k bits. Truncation commutes with wrapping addition, and subtraction is addition by the two's-complement negative. Thus the zero high bit gives the following two inequalities modulo P_k=256^k:
(w\bmod P_k+A_k)\bmod P_k<P_k/2, \qquad (w\bmod P_k+B_k)\bmod P_k<P_k/2,
where A_k and B_k are the low 8k bits of the addition constant and the negative subtraction constant. Kernel-checked evaluation gives the successive values
\begin{array}{c|rrrrrrrr} k&1&2&3&4&5&6&7&8\\ \hline A_k&70&17990&4605510&1179010630&301826721350&77267640665670&19780516010411590&5063812098665367110\\ B_k&208&53200&13619152&3486502864&892544733136&228491451682768&58493811630788560&14974415777481871312. \end{array}
We now induct across byte boundaries. At k=1, the two modular inequalities and 0\leq w\bmod256<256 imply 48\leq w\bmod256\leq57. If the first k-1 bytes are in [48,57], their packed prefix lies between the corresponding prefixes of 0x3030303030303030 and 0x3939393939393939. Substituting that interval into the two inequalities for P_k shows that the next quotient byte is at least 48 and at most 57; the lower inequality excludes a borrow and the upper one excludes a carry into the byte's high bit. The resulting packed prefix is again between the two constant prefixes. Applying this step successively for k=2,\ldots,8 proves the claimed bounds for all eight little-endian bytes, including every cross-byte borrow and carry boundary.

Lean proof


  have r0 := rawBounds w h 0 (by omega)
  have o0 := operationValues w 0 (by omega)
  have c0 := constantValues 0 (by omega)
  have ra0 := r0.1
  have rs0 := r0.2
  rw [o0.1, prefixValue, c0.1, c0.2.2.1, c0.2.2.2] at ra0
  rw [o0.2, prefixValue, c0.2.1, c0.2.2.1, c0.2.2.2] at rs0
  norm_num only at ra0 rs0
  clear r0 o0 c0
  have hm0 : w.val % 256 < 256 := Nat.mod_lt _ (by omega)
  have h0 : 48 <= w.val % 256 ∧ w.val % 256 <= 57 := by omega
  have r1 := rawBounds w h 1 (by omega)
  have o1 := operationValues w 1 (by omega)
  have c1 := constantValues 1 (by omega)
  have ra1 := r1.1
  have rs1 := r1.2
  rw [o1.1, prefixValue, c1.1, c1.2.2.1, c1.2.2.2] at ra1
  rw [o1.2, prefixValue, c1.2.1, c1.2.2.1, c1.2.2.2] at rs1
  norm_num only at ra1 rs1
  clear r1 o1 c1
  have hm1 : w.val % 65536 < 65536 := Nat.mod_lt _ (by omega)
  have h1 : 48 <= (w.val / 256) % 256 ∧
      (w.val / 256) % 256 <= 57 := by omega
  have hp2 : 12336 <= w.val % 65536 ∧
      w.val % 65536 <= 14649 := by omega
  have r2 := rawBounds w h 2 (by omega)
  have o2 := operationValues w 2 (by omega)
  have c2 := constantValues 2 (by omega)
  have ra2 := r2.1
  have rs2 := r2.2
  rw [o2.1, prefixValue, c2.1, c2.2.2.1, c2.2.2.2] at ra2
  rw [o2.2, prefixValue, c2.2.1, c2.2.2.1, c2.2.2.2] at rs2
  norm_num only at ra2 rs2
  clear r2 o2 c2
  have hm2 : w.val % 16777216 < 16777216 := Nat.mod_lt _ (by omega)
  have h2 : 48 <= (w.val / 65536) % 256 ∧
      (w.val / 65536) % 256 <= 57 := by omega
  have hp3 : 3158064 <= w.val % 16777216 ∧
      w.val % 16777216 <= 3750201 := by omega
  have r3 := rawBounds w h 3 (by omega)
  have o3 := operationValues w 3 (by omega)
  have c3 := constantValues 3 (by omega)
  have ra3 := r3.1
  have rs3 := r3.2
  rw [o3.1, prefixValue, c3.1, c3.2.2.1, c3.2.2.2] at ra3
  rw [o3.2, prefixValue, c3.2.1, c3.2.2.1, c3.2.2.2] at rs3
  norm_num only at ra3 rs3
  clear r3 o3 c3
  have hm3 : w.val % 4294967296 < 4294967296 := Nat.mod_lt _ (by omega)
  have h3 : 48 <= (w.val / 16777216) % 256 ∧
      (w.val / 16777216) % 256 <= 57 := by omega
  have hp4 : 808464432 <= w.val % 4294967296 ∧
      w.val % 4294967296 <= 960051513 := by omega
  have r4 := rawBounds w h 4 (by omega)
  have o4 := operationValues w 4 (by omega)
  have c4 := constantValues 4 (by omega)
  have ra4 := r4.1
  have rs4 := r4.2
  rw [o4.1, prefixValue, c4.1, c4.2.2.1, c4.2.2.2] at ra4
  rw [o4.2, prefixValue, c4.2.1, c4.2.2.1, c4.2.2.2] at rs4
  norm_num only at ra4 rs4
  clear r4 o4 c4
  have hm4 : w.val % 1099511627776 < 1099511627776 :=
    Nat.mod_lt _ (by omega)
  have h4 : 48 <= (w.val / 4294967296) % 256 ∧
      (w.val / 4294967296) % 256 <= 57 := by omega
  have hp5 : 206966894640 <= w.val % 1099511627776 ∧
      w.val % 1099511627776 <= 245773187385 := by omega
  have r5 := rawBounds w h 5 (by omega)
  have o5 := operationValues w 5 (by omega)
  have c5 := constantValues 5 (by omega)
  have ra5 := r5.1
  have rs5 := r5.2
  rw [o5.1, prefixValue, c5.1, c5.2.2.1, c5.2.2.2] at ra5
  rw [o5.2, prefixValue, c5.2.1, c5.2.2.1, c5.2.2.2] at rs5
  norm_num only at ra5 rs5
  clear r5 o5 c5
  have hm5 : w.val % 281474976710656 < 281474976710656 :=
    Nat.mod_lt _ (by omega)
  have h5 : 48 <= (w.val / 1099511627776) % 256 ∧
      (w.val / 1099511627776) % 256 <= 57 := by omega
  have hp6 : 52983525027888 <= w.val % 281474976710656 ∧
      w.val % 281474976710656 <= 62917935970617 := by omega
  have r6 := rawBounds w h 6 (by omega)
  have o6 := operationValues w 6 (by omega)
  have c6 := constantValues 6 (by omega)
  have ra6 := r6.1
  have rs6 := r6.2
  rw [o6.1, prefixValue, c6.1, c6.2.2.1, c6.2.2.2] at ra6
  rw [o6.2, prefixValue, c6.2.1, c6.2.2.1, c6.2.2.2] at rs6
  norm_num only at ra6 rs6
  clear r6 o6 c6
  have hm6 : w.val % 72057594037927936 < 72057594037927936 :=
    Nat.mod_lt _ (by omega)
  have h6 : 48 <= (w.val / 281474976710656) % 256 ∧
      (w.val / 281474976710656) % 256 <= 57 := by omega
  have hp7 : 13563782407139376 <= w.val % 72057594037927936 ∧
      w.val % 72057594037927936 <= 16106991608478009 := by omega
  have r7 := rawBounds w h 7 (by omega)
  have o7 := operationValues w 7 (by omega)
  have c7 := constantValues 7 (by omega)
  have ra7 := r7.1
  have rs7 := r7.2
  rw [o7.1, prefixValue, c7.1, c7.2.2.1, c7.2.2.2] at ra7
  rw [o7.2, prefixValue, c7.2.1, c7.2.2.1, c7.2.2.2] at rs7
  norm_num only at ra7 rs7
  clear r7 o7 c7
  have hm7 : w.val < 18446744073709551616 := by scalar_tac
  have h7 : 48 <= (w.val / 72057594037927936) % 256 ∧
      (w.val / 72057594037927936) % 256 <= 57 := by omega
  intro i hi
  have hi_cases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨ i = 5 ∨
      i = 6 ∨ i = 7 := by omega
  rcases hi_cases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
    norm_num <;> assumption
where
  maskBits (w : Std.U64)
      (h : num.imp.dec2flt.common.is_8digits w = ok true) :
      forall i : Nat, i < 8 ->
        ((w.bv + 5063812098665367110#64).extractLsb' (8*i) 8).msb = false ∧
        ((w.bv - 3472328296227680304#64).extractLsb' (8*i) 8).msb = false := by
    simp [num.imp.dec2flt.common.is_8digits, Aeneas.Std.lift,
      core.num.U64.wrapping_add, core.num.U64.wrapping_sub,
      HOr.hOr, HAnd.hAnd, UScalar.or, UScalar.and] at h
    have hb : (((w.bv + 5063812098665367110#64) |||
        (w.bv - 3472328296227680304#64)) &&&
        9259542123273814144#64) = 0#64 := by
      simpa [UScalar.or, UScalar.and] using congrArg UScalar.bv h
    intro i hi
    have hm : (9259542123273814144#64).getLsbD (8*i+7) = true := by
      have hi_cases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨
          i = 5 ∨ i = 6 ∨ i = 7 := by omega
      rcases hi_cases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
        decide +kernel
    have q := congrArg (fun z : BitVec 64 => z.getLsbD (8*i+7)) hb
    simp only [BitVec.getLsbD_and, BitVec.getLsbD_or, hm, Bool.and_true,
      BitVec.getLsbD_zero] at q
    constructor <;> grind

  rawBounds (w : Std.U64)
      (h : num.imp.dec2flt.common.is_8digits w = ok true) :
      forall i : Nat, i < 8 ->
        (BitVec.extractLsb' 0 (8*(i+1))
          (w.bv + 5063812098665367110#64)).toNat < 2^(8*(i+1)-1) ∧
        (BitVec.extractLsb' 0 (8*(i+1))
          (w.bv - 3472328296227680304#64)).toNat < 2^(8*(i+1)-1) := by
    intro i hi
    have hc := maskBits w h i hi
    have hk : 0 < 8*(i+1) := by omega
    have ha0 : (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv + 5063812098665367110#64)).msb = false := by
      simp only [BitVec.msb, BitVec.getMsbD_eq_getLsbD,
        BitVec.getLsbD_extractLsb'] at hc ⊢
      simp [hk]
      simpa [Nat.mul_add] using hc.1
    have hs0 : (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv - 3472328296227680304#64)).msb = false := by
      simp only [BitVec.msb, BitVec.getMsbD_eq_getLsbD,
        BitVec.getLsbD_extractLsb'] at hc ⊢
      simp [hk]
      simpa [Nat.mul_add] using hc.2
    exact ⟨BitVec.toNat_lt_of_msb_false ha0,
      BitVec.toNat_lt_of_msb_false hs0⟩

  operationValues (w : Std.U64) (i : Nat) (hi : i < 8) :
      (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv + 5063812098665367110#64)).toNat =
          ((BitVec.extractLsb' 0 (8*(i+1)) w.bv).toNat +
            (BitVec.extractLsb' 0 (8*(i+1))
              (5063812098665367110#64)).toNat) % 2^(8*(i+1)) ∧
      (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv - 3472328296227680304#64)).toNat =
          ((BitVec.extractLsb' 0 (8*(i+1)) w.bv).toNat +
            (BitVec.extractLsb' 0 (8*(i+1))
              (-3472328296227680304#64)).toNat) % 2^(8*(i+1)) := by
    have hk : 8*(i+1) <= 64 := by omega
    constructor
    · rw [BitVec.extractLsb'_add hk, BitVec.toNat_add]
    · rw [sub_eq_add_neg, BitVec.extractLsb'_add hk, BitVec.toNat_add]

  prefixValue (w : Std.U64) (k : Nat) :
      (BitVec.extractLsb' 0 k w.bv).toNat = w.val % 2^k := by
    rw [BitVec.extractLsb'_toNat]
    simp [Nat.shiftRight_eq_div_pow]

  constantValues : forall i : Nat, i < 8 ->
      (BitVec.extractLsb' 0 (8*(i+1)) (5063812098665367110#64)).toNat =
        (match i with
        | 0 => 70 | 1 => 17990 | 2 => 4605510 | 3 => 1179010630
        | 4 => 301826721350 | 5 => 77267640665670
        | 6 => 19780516010411590 | _ => 5063812098665367110) ∧
      (BitVec.extractLsb' 0 (8*(i+1))
        (-3472328296227680304#64)).toNat =
        (match i with
        | 0 => 208 | 1 => 53200 | 2 => 13619152 | 3 => 3486502864
        | 4 => 892544733136 | 5 => 228491451682768
        | 6 => 58493811630788560 | _ => 14974415777481871312) ∧
      2^(8*(i+1)) =
        (match i with
        | 0 => 256 | 1 => 65536 | 2 => 16777216 | 3 => 4294967296
        | 4 => 1099511627776 | 5 => 281474976710656
        | 6 => 72057594037927936 | _ => 18446744073709551616) ∧
      2^(8*(i+1)-1) =
        (match i with
        | 0 => 128 | 1 => 32768 | 2 => 8388608 | 3 => 2147483648
        | 4 => 549755813888 | 5 => 140737488355328
        | 6 => 36028797018963968 | _ => 9223372036854775808) := by
    intro i hi
    have hi_cases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨
        i = 5 ∨ i = 6 ∨ i = 7 := by omega
    rcases hi_cases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
      decide +kernel

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_common_is_8digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: NumberHelperEightDigitWord]
theorem NumberHelperEightDigitWord (w : Std.U64)
    (h : num.imp.dec2flt.common.is_8digits w = ok true) :
    forall i : Nat, i < 8 ->
      48 <= (w.val / (256^i)) % 256 ∧
        (w.val / (256^i)) % 256 <= 57 := by
-- BODY
  have r0 := rawBounds w h 0 (by omega)
  have o0 := operationValues w 0 (by omega)
  have c0 := constantValues 0 (by omega)
  have ra0 := r0.1
  have rs0 := r0.2
  rw [o0.1, prefixValue, c0.1, c0.2.2.1, c0.2.2.2] at ra0
  rw [o0.2, prefixValue, c0.2.1, c0.2.2.1, c0.2.2.2] at rs0
  norm_num only at ra0 rs0
  clear r0 o0 c0
  have hm0 : w.val % 256 < 256 := Nat.mod_lt _ (by omega)
  have h0 : 48 <= w.val % 256 ∧ w.val % 256 <= 57 := by omega
  have r1 := rawBounds w h 1 (by omega)
  have o1 := operationValues w 1 (by omega)
  have c1 := constantValues 1 (by omega)
  have ra1 := r1.1
  have rs1 := r1.2
  rw [o1.1, prefixValue, c1.1, c1.2.2.1, c1.2.2.2] at ra1
  rw [o1.2, prefixValue, c1.2.1, c1.2.2.1, c1.2.2.2] at rs1
  norm_num only at ra1 rs1
  clear r1 o1 c1
  have hm1 : w.val % 65536 < 65536 := Nat.mod_lt _ (by omega)
  have h1 : 48 <= (w.val / 256) % 256 ∧
      (w.val / 256) % 256 <= 57 := by omega
  have hp2 : 12336 <= w.val % 65536 ∧
      w.val % 65536 <= 14649 := by omega
  have r2 := rawBounds w h 2 (by omega)
  have o2 := operationValues w 2 (by omega)
  have c2 := constantValues 2 (by omega)
  have ra2 := r2.1
  have rs2 := r2.2
  rw [o2.1, prefixValue, c2.1, c2.2.2.1, c2.2.2.2] at ra2
  rw [o2.2, prefixValue, c2.2.1, c2.2.2.1, c2.2.2.2] at rs2
  norm_num only at ra2 rs2
  clear r2 o2 c2
  have hm2 : w.val % 16777216 < 16777216 := Nat.mod_lt _ (by omega)
  have h2 : 48 <= (w.val / 65536) % 256 ∧
      (w.val / 65536) % 256 <= 57 := by omega
  have hp3 : 3158064 <= w.val % 16777216 ∧
      w.val % 16777216 <= 3750201 := by omega
  have r3 := rawBounds w h 3 (by omega)
  have o3 := operationValues w 3 (by omega)
  have c3 := constantValues 3 (by omega)
  have ra3 := r3.1
  have rs3 := r3.2
  rw [o3.1, prefixValue, c3.1, c3.2.2.1, c3.2.2.2] at ra3
  rw [o3.2, prefixValue, c3.2.1, c3.2.2.1, c3.2.2.2] at rs3
  norm_num only at ra3 rs3
  clear r3 o3 c3
  have hm3 : w.val % 4294967296 < 4294967296 := Nat.mod_lt _ (by omega)
  have h3 : 48 <= (w.val / 16777216) % 256 ∧
      (w.val / 16777216) % 256 <= 57 := by omega
  have hp4 : 808464432 <= w.val % 4294967296 ∧
      w.val % 4294967296 <= 960051513 := by omega
  have r4 := rawBounds w h 4 (by omega)
  have o4 := operationValues w 4 (by omega)
  have c4 := constantValues 4 (by omega)
  have ra4 := r4.1
  have rs4 := r4.2
  rw [o4.1, prefixValue, c4.1, c4.2.2.1, c4.2.2.2] at ra4
  rw [o4.2, prefixValue, c4.2.1, c4.2.2.1, c4.2.2.2] at rs4
  norm_num only at ra4 rs4
  clear r4 o4 c4
  have hm4 : w.val % 1099511627776 < 1099511627776 :=
    Nat.mod_lt _ (by omega)
  have h4 : 48 <= (w.val / 4294967296) % 256 ∧
      (w.val / 4294967296) % 256 <= 57 := by omega
  have hp5 : 206966894640 <= w.val % 1099511627776 ∧
      w.val % 1099511627776 <= 245773187385 := by omega
  have r5 := rawBounds w h 5 (by omega)
  have o5 := operationValues w 5 (by omega)
  have c5 := constantValues 5 (by omega)
  have ra5 := r5.1
  have rs5 := r5.2
  rw [o5.1, prefixValue, c5.1, c5.2.2.1, c5.2.2.2] at ra5
  rw [o5.2, prefixValue, c5.2.1, c5.2.2.1, c5.2.2.2] at rs5
  norm_num only at ra5 rs5
  clear r5 o5 c5
  have hm5 : w.val % 281474976710656 < 281474976710656 :=
    Nat.mod_lt _ (by omega)
  have h5 : 48 <= (w.val / 1099511627776) % 256 ∧
      (w.val / 1099511627776) % 256 <= 57 := by omega
  have hp6 : 52983525027888 <= w.val % 281474976710656 ∧
      w.val % 281474976710656 <= 62917935970617 := by omega
  have r6 := rawBounds w h 6 (by omega)
  have o6 := operationValues w 6 (by omega)
  have c6 := constantValues 6 (by omega)
  have ra6 := r6.1
  have rs6 := r6.2
  rw [o6.1, prefixValue, c6.1, c6.2.2.1, c6.2.2.2] at ra6
  rw [o6.2, prefixValue, c6.2.1, c6.2.2.1, c6.2.2.2] at rs6
  norm_num only at ra6 rs6
  clear r6 o6 c6
  have hm6 : w.val % 72057594037927936 < 72057594037927936 :=
    Nat.mod_lt _ (by omega)
  have h6 : 48 <= (w.val / 281474976710656) % 256 ∧
      (w.val / 281474976710656) % 256 <= 57 := by omega
  have hp7 : 13563782407139376 <= w.val % 72057594037927936 ∧
      w.val % 72057594037927936 <= 16106991608478009 := by omega
  have r7 := rawBounds w h 7 (by omega)
  have o7 := operationValues w 7 (by omega)
  have c7 := constantValues 7 (by omega)
  have ra7 := r7.1
  have rs7 := r7.2
  rw [o7.1, prefixValue, c7.1, c7.2.2.1, c7.2.2.2] at ra7
  rw [o7.2, prefixValue, c7.2.1, c7.2.2.1, c7.2.2.2] at rs7
  norm_num only at ra7 rs7
  clear r7 o7 c7
  have hm7 : w.val < 18446744073709551616 := by scalar_tac
  have h7 : 48 <= (w.val / 72057594037927936) % 256 ∧
      (w.val / 72057594037927936) % 256 <= 57 := by omega
  intro i hi
  have hi_cases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨ i = 5 ∨
      i = 6 ∨ i = 7 := by omega
  rcases hi_cases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
    norm_num <;> assumption
where
  maskBits (w : Std.U64)
      (h : num.imp.dec2flt.common.is_8digits w = ok true) :
      forall i : Nat, i < 8 ->
        ((w.bv + 5063812098665367110#64).extractLsb' (8*i) 8).msb = false ∧
        ((w.bv - 3472328296227680304#64).extractLsb' (8*i) 8).msb = false := by
    simp [num.imp.dec2flt.common.is_8digits, Aeneas.Std.lift,
      core.num.U64.wrapping_add, core.num.U64.wrapping_sub,
      HOr.hOr, HAnd.hAnd, UScalar.or, UScalar.and] at h
    have hb : (((w.bv + 5063812098665367110#64) |||
        (w.bv - 3472328296227680304#64)) &&&
        9259542123273814144#64) = 0#64 := by
      simpa [UScalar.or, UScalar.and] using congrArg UScalar.bv h
    intro i hi
    have hm : (9259542123273814144#64).getLsbD (8*i+7) = true := by
      have hi_cases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨
          i = 5 ∨ i = 6 ∨ i = 7 := by omega
      rcases hi_cases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
        decide +kernel
    have q := congrArg (fun z : BitVec 64 => z.getLsbD (8*i+7)) hb
    simp only [BitVec.getLsbD_and, BitVec.getLsbD_or, hm, Bool.and_true,
      BitVec.getLsbD_zero] at q
    constructor <;> grind

  rawBounds (w : Std.U64)
      (h : num.imp.dec2flt.common.is_8digits w = ok true) :
      forall i : Nat, i < 8 ->
        (BitVec.extractLsb' 0 (8*(i+1))
          (w.bv + 5063812098665367110#64)).toNat < 2^(8*(i+1)-1) ∧
        (BitVec.extractLsb' 0 (8*(i+1))
          (w.bv - 3472328296227680304#64)).toNat < 2^(8*(i+1)-1) := by
    intro i hi
    have hc := maskBits w h i hi
    have hk : 0 < 8*(i+1) := by omega
    have ha0 : (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv + 5063812098665367110#64)).msb = false := by
      simp only [BitVec.msb, BitVec.getMsbD_eq_getLsbD,
        BitVec.getLsbD_extractLsb'] at hc ⊢
      simp [hk]
      simpa [Nat.mul_add] using hc.1
    have hs0 : (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv - 3472328296227680304#64)).msb = false := by
      simp only [BitVec.msb, BitVec.getMsbD_eq_getLsbD,
        BitVec.getLsbD_extractLsb'] at hc ⊢
      simp [hk]
      simpa [Nat.mul_add] using hc.2
    exact ⟨BitVec.toNat_lt_of_msb_false ha0,
      BitVec.toNat_lt_of_msb_false hs0⟩

  operationValues (w : Std.U64) (i : Nat) (hi : i < 8) :
      (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv + 5063812098665367110#64)).toNat =
          ((BitVec.extractLsb' 0 (8*(i+1)) w.bv).toNat +
            (BitVec.extractLsb' 0 (8*(i+1))
              (5063812098665367110#64)).toNat) % 2^(8*(i+1)) ∧
      (BitVec.extractLsb' 0 (8*(i+1))
        (w.bv - 3472328296227680304#64)).toNat =
          ((BitVec.extractLsb' 0 (8*(i+1)) w.bv).toNat +
            (BitVec.extractLsb' 0 (8*(i+1))
              (-3472328296227680304#64)).toNat) % 2^(8*(i+1)) := by
    have hk : 8*(i+1) <= 64 := by omega
    constructor
    · rw [BitVec.extractLsb'_add hk, BitVec.toNat_add]
    · rw [sub_eq_add_neg, BitVec.extractLsb'_add hk, BitVec.toNat_add]

  prefixValue (w : Std.U64) (k : Nat) :
      (BitVec.extractLsb' 0 k w.bv).toNat = w.val % 2^k := by
    rw [BitVec.extractLsb'_toNat]
    simp [Nat.shiftRight_eq_div_pow]

  constantValues : forall i : Nat, i < 8 ->
      (BitVec.extractLsb' 0 (8*(i+1)) (5063812098665367110#64)).toNat =
        (match i with
        | 0 => 70 | 1 => 17990 | 2 => 4605510 | 3 => 1179010630
        | 4 => 301826721350 | 5 => 77267640665670
        | 6 => 19780516010411590 | _ => 5063812098665367110) ∧
      (BitVec.extractLsb' 0 (8*(i+1))
        (-3472328296227680304#64)).toNat =
        (match i with
        | 0 => 208 | 1 => 53200 | 2 => 13619152 | 3 => 3486502864
        | 4 => 892544733136 | 5 => 228491451682768
        | 6 => 58493811630788560 | _ => 14974415777481871312) ∧
      2^(8*(i+1)) =
        (match i with
        | 0 => 256 | 1 => 65536 | 2 => 16777216 | 3 => 4294967296
        | 4 => 1099511627776 | 5 => 281474976710656
        | 6 => 72057594037927936 | _ => 18446744073709551616) ∧
      2^(8*(i+1)-1) =
        (match i with
        | 0 => 128 | 1 => 32768 | 2 => 8388608 | 3 => 2147483648
        | 4 => 549755813888 | 5 => 140737488355328
        | 6 => 36028797018963968 | _ => 9223372036854775808) := by
    intro i hi
    have hi_cases : i = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨
        i = 5 ∨ i = 6 ∨ i = 7 := by omega
    rcases hi_cases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
      decide +kernel

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (45)
More program dependencies (12)
Standard-library dependencies (30)

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
Technical checking records
Local closure summary
{
  "node": "NumberHelperEightDigitWord",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "14443f7f2cbfd7f0c1b3ce9e4dae6d660d60625e730f4d50a4d295381cd01866",
  "active_statement_hash": "005605a4788516818b8ee9a28aa2d4aa4134dc3df6d1a11e7adf4e01abf2d391",
  "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-108",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "num_imp_dec2flt_common_is_8digits": "effb8a26907859a5"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_common_is_8digits": "53e9de5212d69bf5"
  }
}
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:408fd1eb30662ecc914016e74daeb88a78ff97c1f74191e22df8f4452ab2a966",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}