Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Exact eight-digit decoder
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Mathlib.Tactic.IntervalCases
import Tablet.NumberHelperEightDigitWord
import Tablet.num_imp_dec2flt_parse_parse_8digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 10000
namespace dec2flt_model
-- [TABLET NODE: NumberHelperParseEightDigitsExact]
theorem NumberHelperParseEightDigitsExact (w : Std.U64)
(h : num.imp.dec2flt.common.is_8digits w = ok true) :
exists z, num.imp.dec2flt.parse.parse_8digits w = ok z /\
z.val =
10000000 * ((w.val / (256^0)) % 256 - 48) +
1000000 * ((w.val / (256^1)) % 256 - 48) +
100000 * ((w.val / (256^2)) % 256 - 48) +
10000 * ((w.val / (256^3)) % 256 - 48) +
1000 * ((w.val / (256^4)) % 256 - 48) +
100 * ((w.val / (256^5)) % 256 - 48) +
10 * ((w.val / (256^6)) % 256 - 48) +
((w.val / (256^7)) % 256 - 48) := 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
Lean proof
have hb0 := NumberHelperEightDigitWord w h 0 (by omega)
have hb1 := NumberHelperEightDigitWord w h 1 (by omega)
have hb2 := NumberHelperEightDigitWord w h 2 (by omega)
have hb3 := NumberHelperEightDigitWord w h 3 (by omega)
have hb4 := NumberHelperEightDigitWord w h 4 (by omega)
have hb5 := NumberHelperEightDigitWord w h 5 (by omega)
have hb6 := NumberHelperEightDigitWord w h 6 (by omega)
have hb7 := NumberHelperEightDigitWord w h 7 (by omega)
have hx0 : (w.bv.extractLsb' 0 8).toNat = (w.val / (256^0)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx1 : (w.bv.extractLsb' 8 8).toNat = (w.val / (256^1)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx2 : (w.bv.extractLsb' 16 8).toNat = (w.val / (256^2)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx3 : (w.bv.extractLsb' 24 8).toNat = (w.val / (256^3)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx4 : (w.bv.extractLsb' 32 8).toNat = (w.val / (256^4)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx5 : (w.bv.extractLsb' 40 8).toNat = (w.val / (256^5)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx6 : (w.bv.extractLsb' 48 8).toNat = (w.val / (256^6)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx7 : (w.bv.extractLsb' 56 8).toNat = (w.val / (256^7)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hd0 : 48#8 <= w.bv.extractLsb' 0 8 /\ w.bv.extractLsb' 0 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 0 8).toNat
rw [hx0]
exact hb0.1
· change (w.bv.extractLsb' 0 8).toNat <= 57
rw [hx0]
exact hb0.2
have hd1 : 48#8 <= w.bv.extractLsb' 8 8 /\ w.bv.extractLsb' 8 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 8 8).toNat
rw [hx1]
exact hb1.1
· change (w.bv.extractLsb' 8 8).toNat <= 57
rw [hx1]
exact hb1.2
have hd2 : 48#8 <= w.bv.extractLsb' 16 8 /\ w.bv.extractLsb' 16 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 16 8).toNat
rw [hx2]
exact hb2.1
· change (w.bv.extractLsb' 16 8).toNat <= 57
rw [hx2]
exact hb2.2
have hd3 : 48#8 <= w.bv.extractLsb' 24 8 /\ w.bv.extractLsb' 24 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 24 8).toNat
rw [hx3]
exact hb3.1
· change (w.bv.extractLsb' 24 8).toNat <= 57
rw [hx3]
exact hb3.2
have hd4 : 48#8 <= w.bv.extractLsb' 32 8 /\ w.bv.extractLsb' 32 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 32 8).toNat
rw [hx4]
exact hb4.1
· change (w.bv.extractLsb' 32 8).toNat <= 57
rw [hx4]
exact hb4.2
have hd5 : 48#8 <= w.bv.extractLsb' 40 8 /\ w.bv.extractLsb' 40 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 40 8).toNat
rw [hx5]
exact hb5.1
· change (w.bv.extractLsb' 40 8).toNat <= 57
rw [hx5]
exact hb5.2
have hd6 : 48#8 <= w.bv.extractLsb' 48 8 /\ w.bv.extractLsb' 48 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 48 8).toNat
rw [hx6]
exact hb6.1
· change (w.bv.extractLsb' 48 8).toNat <= 57
rw [hx6]
exact hb6.2
have hd7 : 48#8 <= w.bv.extractLsb' 56 8 /\ w.bv.extractLsb' 56 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 56 8).toNat
rw [hx7]
exact hb7.1
· change (w.bv.extractLsb' 56 8).toNat <= 57
rw [hx7]
exact hb7.2
have hid := parse8BitVecIdentity w.bv hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7
have hs0 := digitSubSetWidthToNat (w.bv.extractLsb' 0 8)
(by omega) (by omega)
have hs1 := digitSubSetWidthToNat (w.bv.extractLsb' 8 8)
(by omega) (by omega)
have hs2 := digitSubSetWidthToNat (w.bv.extractLsb' 16 8)
(by omega) (by omega)
have hs3 := digitSubSetWidthToNat (w.bv.extractLsb' 24 8)
(by omega) (by omega)
have hs4 := digitSubSetWidthToNat (w.bv.extractLsb' 32 8)
(by omega) (by omega)
have hs5 := digitSubSetWidthToNat (w.bv.extractLsb' 40 8)
(by omega) (by omega)
have hs6 := digitSubSetWidthToNat (w.bv.extractLsb' 48 8)
(by omega) (by omega)
have hs7 := digitSubSetWidthToNat (w.bv.extractLsb' 56 8)
(by omega) (by omega)
have hv0 : (w.bv.extractLsb' 0 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 0 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs0]
simp
omega
have hv1 : (w.bv.extractLsb' 8 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 8 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs1]
simp
omega
have hv2 : (w.bv.extractLsb' 16 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 16 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs2]
simp
omega
have hv3 : (w.bv.extractLsb' 24 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 24 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs3]
simp
omega
have hv4 : (w.bv.extractLsb' 32 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 32 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs4]
simp
omega
have hv5 : (w.bv.extractLsb' 40 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 40 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs5]
simp
omega
have hv6 : (w.bv.extractLsb' 48 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 48 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs6]
simp
omega
have hv7 : (w.bv.extractLsb' 56 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 56 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs7]
simp
omega
have he := parse8Execution w h
obtain ⟨z, hz, hzpost⟩ := Aeneas.Std.WP.spec_imp_exists he
refine ⟨z, hz, ?_⟩
have hzbits := hzpost.trans hid
rw [hv0, hv1, hv2, hv3, hv4, hv5, hv6, hv7] at hzbits
simp only [bitVec64OfNatMul, bitVec64OfNatAdd] at hzbits
change z.bv.toNat = _
rw [hzbits]
simp only [BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (by omega)]
rw [hx0, hx1, hx2, hx3, hx4, hx5, hx6, hx7]
simp only [Nat.mul_comm]
where
parse8BitVecIdentity (w : BitVec 64)
(h0 : 48#8 <= w.extractLsb' 0 8 /\ w.extractLsb' 0 8 <= 57#8)
(h1 : 48#8 <= w.extractLsb' 8 8 /\ w.extractLsb' 8 8 <= 57#8)
(h2 : 48#8 <= w.extractLsb' 16 8 /\ w.extractLsb' 16 8 <= 57#8)
(h3 : 48#8 <= w.extractLsb' 24 8 /\ w.extractLsb' 24 8 <= 57#8)
(h4 : 48#8 <= w.extractLsb' 32 8 /\ w.extractLsb' 32 8 <= 57#8)
(h5 : 48#8 <= w.extractLsb' 40 8 /\ w.extractLsb' 40 8 <= 57#8)
(h6 : 48#8 <= w.extractLsb' 48 8 /\ w.extractLsb' 48 8 <= 57#8)
(h7 : 48#8 <= w.extractLsb' 56 8 /\ w.extractLsb' 56 8 <= 57#8) :
let v1 := w - 3472328296227680304#64
let v2 := v1 * 10#64 + (v1 >>> 8)
let a := (v2 &&& 1095216660735#64) * 4294967296000100#64
let b := ((v2 >>> 16) &&& 1095216660735#64) * 42949672960001#64
(((a + b) >>> 32).setWidth 32).setWidth 64 =
(w.extractLsb' 0 8 - 48#8).setWidth 64 * 10000000#64 +
(w.extractLsb' 8 8 - 48#8).setWidth 64 * 1000000#64 +
(w.extractLsb' 16 8 - 48#8).setWidth 64 * 100000#64 +
(w.extractLsb' 24 8 - 48#8).setWidth 64 * 10000#64 +
(w.extractLsb' 32 8 - 48#8).setWidth 64 * 1000#64 +
(w.extractLsb' 40 8 - 48#8).setWidth 64 * 100#64 +
(w.extractLsb' 48 8 - 48#8).setWidth 64 * 10#64 +
(w.extractLsb' 56 8 - 48#8).setWidth 64 := by
have hlo0 : 48 <= (w.extractLsb' 0 8).toNat := by exact h0.1
have hlo1 : 48 <= (w.extractLsb' 8 8).toNat := by exact h1.1
have hlo2 : 48 <= (w.extractLsb' 16 8).toNat := by exact h2.1
have hlo3 : 48 <= (w.extractLsb' 24 8).toNat := by exact h3.1
have hlo4 : 48 <= (w.extractLsb' 32 8).toNat := by exact h4.1
have hlo5 : 48 <= (w.extractLsb' 40 8).toNat := by exact h5.1
have hlo6 : 48 <= (w.extractLsb' 48 8).toNat := by exact h6.1
have hlo7 : 48 <= (w.extractLsb' 56 8).toNat := by exact h7.1
have hhi0 : (w.extractLsb' 0 8).toNat <= 57 := by exact h0.2
have hhi1 : (w.extractLsb' 8 8).toNat <= 57 := by exact h1.2
have hhi2 : (w.extractLsb' 16 8).toNat <= 57 := by exact h2.2
have hhi3 : (w.extractLsb' 24 8).toNat <= 57 := by exact h3.2
have hhi4 : (w.extractLsb' 32 8).toNat <= 57 := by exact h4.2
have hhi5 : (w.extractLsb' 40 8).toNat <= 57 := by exact h5.2
have hhi6 : (w.extractLsb' 48 8).toNat <= 57 := by exact h6.2
have hhi7 : (w.extractLsb' 56 8).toNat <= 57 := by exact h7.2
let d0 := (w.extractLsb' 0 8).toNat - 48
let d1 := (w.extractLsb' 8 8).toNat - 48
let d2 := (w.extractLsb' 16 8).toNat - 48
let d3 := (w.extractLsb' 24 8).toNat - 48
let d4 := (w.extractLsb' 32 8).toNat - 48
let d5 := (w.extractLsb' 40 8).toNat - 48
let d6 := (w.extractLsb' 48 8).toNat - 48
let d7 := (w.extractLsb' 56 8).toNat - 48
have hd0 : d0 <= 9 := by change (w.extractLsb' 0 8).toNat - 48 <= 9; omega
have hd1 : d1 <= 9 := by change (w.extractLsb' 8 8).toNat - 48 <= 9; omega
have hd2 : d2 <= 9 := by change (w.extractLsb' 16 8).toNat - 48 <= 9; omega
have hd3 : d3 <= 9 := by change (w.extractLsb' 24 8).toNat - 48 <= 9; omega
have hd4 : d4 <= 9 := by change (w.extractLsb' 32 8).toNat - 48 <= 9; omega
have hd5 : d5 <= 9 := by change (w.extractLsb' 40 8).toNat - 48 <= 9; omega
have hd6 : d6 <= 9 := by change (w.extractLsb' 48 8).toNat - 48 <= 9; omega
have hd7 : d7 <= 9 := by change (w.extractLsb' 56 8).toNat - 48 <= 9; omega
let v1 := w - 3472328296227680304#64
let v2 := v1 * 10#64 + (v1 >>> 8)
have hv1 : v1.toNat = d0 + 256*d1 + 65536*d2 + 16777216*d3 +
4294967296*d4 + 1099511627776*d5 + 281474976710656*d6 +
72057594037927936*d7 := by
dsimp [v1, d0, d1, d2, d3, d4, d5, d6, d7]
exact subDigits w hlo0 hlo1 hlo2 hlo3 hlo4 hlo5 hlo6 hlo7
have hv2 : v2.toNat =
(10*d0+d1) + 256*(10*d1+d2) + 65536*(10*d2+d3) +
16777216*(10*d3+d4) + 4294967296*(10*d4+d5) +
1099511627776*(10*d5+d6) + 281474976710656*(10*d6+d7) +
72057594037927936*(10*d7) := by
exact pairedDigits v1 d0 d1 d2 d3 d4 d5 d6 d7
hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7 hv1
let p0 := 10*d0+d1
let p1 := 10*d1+d2
let p2 := 10*d2+d3
let p3 := 10*d3+d4
let p4 := 10*d4+d5
let p5 := 10*d5+d6
let p6 := 10*d6+d7
let p7 := 10*d7
have hp0 : p0 <= 99 := by change 10*d0+d1 <= 99; omega
have hp1 : p1 <= 99 := by change 10*d1+d2 <= 99; omega
have hp2 : p2 <= 99 := by change 10*d2+d3 <= 99; omega
have hp3 : p3 <= 99 := by change 10*d3+d4 <= 99; omega
have hp4 : p4 <= 99 := by change 10*d4+d5 <= 99; omega
have hp5 : p5 <= 99 := by change 10*d5+d6 <= 99; omega
have hp6 : p6 <= 99 := by change 10*d6+d7 <= 99; omega
have hp7 : p7 <= 99 := by change 10*d7 <= 99; omega
have hv2' : v2.toNat = p0 + 256*p1 + 65536*p2 + 16777216*p3 +
4294967296*p4 + 1099511627776*p5 + 281474976710656*p6 +
72057594037927936*p7 := by
simpa [p0, p1, p2, p3, p4, p5, p6, p7] using hv2
have hs := selectedPairs v2 p0 p1 p2 p3 p4 p5 p6 p7
hp0 hp1 hp2 hp3 hp4 hp5 hp6 hp7 hv2'
have hd0bv : (w.extractLsb' 0 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d0 := by
simpa [d0] using digitBitVec (w.extractLsb' 0 8) hlo0 hhi0
have hd1bv : (w.extractLsb' 8 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d1 := by
simpa [d1] using digitBitVec (w.extractLsb' 8 8) hlo1 hhi1
have hd2bv : (w.extractLsb' 16 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d2 := by
simpa [d2] using digitBitVec (w.extractLsb' 16 8) hlo2 hhi2
have hd3bv : (w.extractLsb' 24 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d3 := by
simpa [d3] using digitBitVec (w.extractLsb' 24 8) hlo3 hhi3
have hd4bv : (w.extractLsb' 32 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d4 := by
simpa [d4] using digitBitVec (w.extractLsb' 32 8) hlo4 hhi4
have hd5bv : (w.extractLsb' 40 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d5 := by
simpa [d5] using digitBitVec (w.extractLsb' 40 8) hlo5 hhi5
have hd6bv : (w.extractLsb' 48 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d6 := by
simpa [d6] using digitBitVec (w.extractLsb' 48 8) hlo6 hhi6
have hd7bv : (w.extractLsb' 56 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d7 := by
simpa [d7] using digitBitVec (w.extractLsb' 56 8) hlo7 hhi7
change (((((v2 &&& 1095216660735#64) * 4294967296000100#64 +
(((v2 >>> 16) &&& 1095216660735#64) * 42949672960001#64)) >>> 32
).setWidth 32).setWidth 64) = _
rw [maskBytes v2, maskBytes (v2 >>> 16)]
rw [hs.1, hs.2.1, hs.2.2.1, hs.2.2.2]
rw [hd0bv, hd1bv, hd2bv, hd3bv, hd4bv, hd5bv, hd6bv, hd7bv]
exact combinePairs d0 d1 d2 d3 d4 d5 d6 d7
hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7
maskBytes (x : BitVec 64) :
x &&& 1095216660735#64 =
(x.extractLsb' 0 8).setWidth 64 |||
((x.extractLsb' 32 8).setWidth 64 <<< 32) := by
have hm : 1095216660735#64 =
(BitVec.allOnes 8).setWidth 64 |||
((BitVec.allOnes 8).setWidth 64 <<< 32) := by decide +kernel
apply BitVec.eq_of_getLsbD_eq
intro i hi
have hmi := congrArg (fun z : BitVec 64 => z.getLsbD i) hm
simp only [BitVec.getLsbD_and, BitVec.getLsbD_or, BitVec.getLsbD_setWidth,
BitVec.getLsbD_allOnes, BitVec.getLsbD_shiftLeft,
BitVec.getLsbD_extractLsb'] at hmi ⊢
rw [hmi]
by_cases h32 : i < 32
· simp [h32, Bool.and_comm, Bool.and_left_comm, Bool.and_assoc]
· have hle : 32 <= i := by omega
simp [h32, Nat.add_sub_of_le hle, Bool.and_or_distrib_left,
Bool.and_comm, Bool.and_left_comm, Bool.and_assoc]
digitBitVec (b : BitVec 8) (hlo : 48 <= b.toNat) (hhi : b.toNat <= 57) :
(b - 48#8).setWidth 64 = BitVec.ofNat 64 (b.toNat - 48) := by
apply BitVec.eq_of_toNat_eq
simp only [BitVec.toNat_setWidth, BitVec.toNat_sub, BitVec.toNat_ofNat]
norm_num
omega
wordDecomp (w : BitVec 64) :
w.toNat =
(w.extractLsb' 0 8).toNat +
256 * (w.extractLsb' 8 8).toNat +
65536 * (w.extractLsb' 16 8).toNat +
16777216 * (w.extractLsb' 24 8).toNat +
4294967296 * (w.extractLsb' 32 8).toNat +
1099511627776 * (w.extractLsb' 40 8).toNat +
281474976710656 * (w.extractLsb' 48 8).toNat +
72057594037927936 * (w.extractLsb' 56 8).toNat := by
simp only [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hw := w.isLt
norm_num at *
omega
subDigits (w : BitVec 64)
(h0 : 48 <= (w.extractLsb' 0 8).toNat)
(h1 : 48 <= (w.extractLsb' 8 8).toNat)
(h2 : 48 <= (w.extractLsb' 16 8).toNat)
(h3 : 48 <= (w.extractLsb' 24 8).toNat)
(h4 : 48 <= (w.extractLsb' 32 8).toNat)
(h5 : 48 <= (w.extractLsb' 40 8).toNat)
(h6 : 48 <= (w.extractLsb' 48 8).toNat)
(h7 : 48 <= (w.extractLsb' 56 8).toNat) :
(w - 3472328296227680304#64).toNat =
((w.extractLsb' 0 8).toNat - 48) +
256 * ((w.extractLsb' 8 8).toNat - 48) +
65536 * ((w.extractLsb' 16 8).toNat - 48) +
16777216 * ((w.extractLsb' 24 8).toNat - 48) +
4294967296 * ((w.extractLsb' 32 8).toNat - 48) +
1099511627776 * ((w.extractLsb' 40 8).toNat - 48) +
281474976710656 * ((w.extractLsb' 48 8).toNat - 48) +
72057594037927936 * ((w.extractLsb' 56 8).toNat - 48) := by
rw [BitVec.toNat_sub, wordDecomp]
norm_num at *
omega
pairedDigits (v1 : BitVec 64) (d0 d1 d2 d3 d4 d5 d6 d7 : Nat)
(h0 : d0 <= 9) (h1 : d1 <= 9) (h2 : d2 <= 9) (h3 : d3 <= 9)
(h4 : d4 <= 9) (h5 : d5 <= 9) (h6 : d6 <= 9) (h7 : d7 <= 9)
(hv1 : v1.toNat = d0 + 256*d1 + 65536*d2 + 16777216*d3 +
4294967296*d4 + 1099511627776*d5 + 281474976710656*d6 +
72057594037927936*d7) :
(v1 * 10#64 + (v1 >>> 8)).toNat =
(10*d0+d1) + 256*(10*d1+d2) + 65536*(10*d2+d3) +
16777216*(10*d3+d4) + 4294967296*(10*d4+d5) +
1099511627776*(10*d5+d6) + 281474976710656*(10*d6+d7) +
72057594037927936*(10*d7) := by
have hshift : (v1 >>> 8).toNat = d1 + 256*d2 + 65536*d3 +
16777216*d4 + 4294967296*d5 + 1099511627776*d6 +
281474976710656*d7 := by
simp [hv1, Nat.shiftRight_eq_div_pow]
omega
simp only [BitVec.toNat_add, BitVec.toNat_mul, BitVec.toNat_ofNat]
rw [hshift, hv1]
norm_num at *
omega
selectedPairs (v2 : BitVec 64) (p0 p1 p2 p3 p4 p5 p6 p7 : Nat)
(h0 : p0 <= 99) (h1 : p1 <= 99) (h2 : p2 <= 99) (h3 : p3 <= 99)
(h4 : p4 <= 99) (h5 : p5 <= 99) (h6 : p6 <= 99) (h7 : p7 <= 99)
(hv2 : v2.toNat = p0 + 256*p1 + 65536*p2 + 16777216*p3 +
4294967296*p4 + 1099511627776*p5 + 281474976710656*p6 +
72057594037927936*p7) :
(v2.extractLsb' 0 8).setWidth 64 = BitVec.ofNat 64 p0 ∧
((v2 >>> 16).extractLsb' 0 8).setWidth 64 = BitVec.ofNat 64 p2 ∧
(v2.extractLsb' 32 8).setWidth 64 = BitVec.ofNat 64 p4 ∧
((v2 >>> 16).extractLsb' 32 8).setWidth 64 = BitVec.ofNat 64 p6 := by
constructor
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
constructor
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
constructor
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
packOrEqAdd (a b : Nat) (ha : a <= 99) :
(BitVec.ofNat 64 a ||| (BitVec.ofNat 64 b <<< 32)) =
BitVec.ofNat 64 a + (BitVec.ofNat 64 b <<< 32) := by
rw [BitVec.add_eq_or_of_and_eq_zero]
ext i hi
simp only [BitVec.getElem_and, BitVec.getElem_shiftLeft, BitVec.getElem_zero,
Bool.and_eq_false_imp]
intro hai
have hpow' := BitVec.two_pow_le_toNat_of_getElem_eq_true hi hai
have ha64 : a < 2 ^ 64 := by norm_num; omega
rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt ha64] at hpow'
interval_cases i <;> norm_num at hpow' ⊢ <;> omega
prodA (p0 p4 : Nat) (h0 : p0 <= 99) (_h4 : p4 <= 99) :
(BitVec.ofNat 64 p0 ||| (BitVec.ofNat 64 p4 <<< 32)) *
4294967296000100#64 =
BitVec.ofNat 64 (100*p0 + 4294967296*(1000000*p0 + 100*p4)) := by
rw [packOrEqAdd p0 p4 h0]
simp only [BitVec.shiftLeft_eq_mul_twoPow, BitVec.ofNat_add,
BitVec.ofNat_mul]
have hpow : BitVec.twoPow 64 32 = 4294967296#64 := by decide +kernel
rw [hpow]
have hc0 : 4294967296000100#64 =
100#64 + 4294967296#64 * 1000000#64 := by decide +kernel
have hsq : 4294967296#64 * 4294967296#64 = 0#64 := by decide +kernel
rw [hc0]
calc
_ = 100#64 * BitVec.ofNat 64 p0 +
4294967296#64 * (1000000#64 * BitVec.ofNat 64 p0 +
100#64 * BitVec.ofNat 64 p4) +
BitVec.ofNat 64 p4 *
(4294967296#64 * 4294967296#64) * 1000000#64 := by ring
_ = _ := by rw [hsq]; simp
prodB (p2 p6 : Nat) (h2 : p2 <= 99) (_h6 : p6 <= 99) :
(BitVec.ofNat 64 p2 ||| (BitVec.ofNat 64 p6 <<< 32)) *
42949672960001#64 =
BitVec.ofNat 64 (p2 + 4294967296*(10000*p2 + p6)) := by
rw [packOrEqAdd p2 p6 h2]
simp only [BitVec.shiftLeft_eq_mul_twoPow, BitVec.ofNat_add,
BitVec.ofNat_mul]
have hpow : BitVec.twoPow 64 32 = 4294967296#64 := by decide +kernel
rw [hpow]
have hc2 : 42949672960001#64 =
(1 : BitVec 64) + 4294967296#64 * 10000#64 := by decide +kernel
have hsq : 4294967296#64 * 4294967296#64 = 0#64 := by decide +kernel
rw [hc2]
calc
_ = BitVec.ofNat 64 p2 +
4294967296#64 * (10000#64 * BitVec.ofNat 64 p2 +
BitVec.ofNat 64 p6) +
BitVec.ofNat 64 p6 *
(4294967296#64 * 4294967296#64) * 10000#64 := by ring
_ = _ := by rw [hsq]; simp
combinePairs (d0 d1 d2 d3 d4 d5 d6 d7 : Nat)
(h0 : d0 <= 9) (h1 : d1 <= 9) (h2 : d2 <= 9) (h3 : d3 <= 9)
(h4 : d4 <= 9) (h5 : d5 <= 9) (h6 : d6 <= 9) (h7 : d7 <= 9) :
(((((BitVec.ofNat 64 (10*d0+d1) |||
(BitVec.ofNat 64 (10*d4+d5) <<< 32)) * 4294967296000100#64 +
(BitVec.ofNat 64 (10*d2+d3) |||
(BitVec.ofNat 64 (10*d6+d7) <<< 32)) * 42949672960001#64) >>> 32
).setWidth 32).setWidth 64) =
BitVec.ofNat 64 d0 * 10000000#64 +
BitVec.ofNat 64 d1 * 1000000#64 +
BitVec.ofNat 64 d2 * 100000#64 +
BitVec.ofNat 64 d3 * 10000#64 +
BitVec.ofNat 64 d4 * 1000#64 +
BitVec.ofNat 64 d5 * 100#64 +
BitVec.ofNat 64 d6 * 10#64 +
BitVec.ofNat 64 d7 := by
have hp0 : 10*d0+d1 <= 99 := by as_aux_lemma => omega
have hp2 : 10*d2+d3 <= 99 := by as_aux_lemma => omega
have hp4 : 10*d4+d5 <= 99 := by as_aux_lemma => omega
have hp6 : 10*d6+d7 <= 99 := by as_aux_lemma => omega
rw [prodA _ _ hp0 hp4, prodB _ _ hp2 hp6]
have hdecimal : d0*10000000 + d1*1000000 + d2*100000 + d3*10000 +
d4*1000 + d5*100 + d6*10 + d7 < 100000000 := by as_aux_lemma => omega
have hlow : 100*(10*d0+d1) + (10*d2+d3) < 4294967296 := by
as_aux_lemma => omega
have hform :
100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7))) =
(100*(10*d0+d1) + (10*d2+d3)) + 4294967296 *
(d0*10000000 + d1*1000000 + d2*100000 + d3*10000 +
d4*1000 + d5*100 + d6*10 + d7) := by ring
have htotal :
100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7))) <
18446744073709551616 := by as_aux_lemma =>
rw [hform]
omega
have hquot :
(100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7)))) /
4294967296 =
d0*10000000 + d1*1000000 + d2*100000 + d3*10000 +
d4*1000 + d5*100 + d6*10 + d7 := by as_aux_lemma =>
rw [hform, Nat.add_mul_div_left _ _ (by norm_num),
Nat.div_eq_of_lt hlow, Nat.zero_add]
have addOfNat (a b : Nat) : BitVec.ofNat 64 a + BitVec.ofNat 64 b =
BitVec.ofNat 64 (a+b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_add, Nat.add_mod]
have mulOfNat (a b : Nat) : BitVec.ofNat 64 a * BitVec.ofNat 64 b =
BitVec.ofNat 64 (a*b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_mul, Nat.mul_mod]
have hsum :
BitVec.ofNat 64 (100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5))) +
BitVec.ofNat 64 ((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7))) =
BitVec.ofNat 64 (100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7)))) := by
apply addOfNat
have hright :
BitVec.ofNat 64 d0 * 10000000#64 +
BitVec.ofNat 64 d1 * 1000000#64 +
BitVec.ofNat 64 d2 * 100000#64 +
BitVec.ofNat 64 d3 * 10000#64 +
BitVec.ofNat 64 d4 * 1000#64 +
BitVec.ofNat 64 d5 * 100#64 +
BitVec.ofNat 64 d6 * 10#64 +
BitVec.ofNat 64 d7 =
BitVec.ofNat 64 (d0*10000000 + d1*1000000 + d2*100000 +
d3*10000 + d4*1000 + d5*100 + d6*10 + d7) := by
simp only [mulOfNat, addOfNat]
rw [hsum, hright]
apply BitVec.eq_of_toNat_eq
simp [Nat.shiftRight_eq_div_pow, Nat.mod_eq_of_lt htotal, hquot,
Nat.mod_eq_of_lt (show d0*10000000 + d1*1000000 + d2*100000 +
d3*10000 + d4*1000 + d5*100 + d6*10 + d7 < 4294967296 by omega),
Nat.mod_eq_of_lt (show d0*10000000 + d1*1000000 + d2*100000 +
d3*10000 + d4*1000 + d5*100 + d6*10 + d7 <
18446744073709551616 by omega)]
digitSubSetWidthToNat (b : BitVec 8)
(hlo : 48 <= b.toNat) (hhi : b.toNat <= 57) :
((b - 48#8).setWidth 64).toNat = b.toNat - 48 := by
simp only [BitVec.toNat_setWidth, BitVec.toNat_sub, BitVec.toNat_ofNat]
norm_num
omega
bitVec64OfNatMul (a b : Nat) :
(BitVec.ofNat 64 a) * (BitVec.ofNat 64 b) =
BitVec.ofNat 64 (a * b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_mul, Nat.mul_mod]
bitVec64OfNatAdd (a b : Nat) :
(BitVec.ofNat 64 a) + (BitVec.ofNat 64 b) =
BitVec.ofNat 64 (a + b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_add, Nat.add_mod]
parse8Execution (w : Std.U64)
(h : num.imp.dec2flt.common.is_8digits w = ok true) :
num.imp.dec2flt.parse.parse_8digits w
⦃ q => q.bv =
let v1 := w.bv - 3472328296227680304#64
let v2 := v1 * 10#64 + (v1 >>> 8)
let a := (v2 &&& 1095216660735#64) * 4294967296000100#64
let b := ((v2 >>> 16) &&& 1095216660735#64) * 42949672960001#64
(((a + b) >>> 32).setWidth 32).setWidth 64 ⦄ := by
have h0 := NumberHelperEightDigitWord w h 0 (by omega)
have h1 := NumberHelperEightDigitWord w h 1 (by omega)
have hp2 : 12336 <= w.val % 65536 /\
w.val % 65536 <= 14649 := by omega
clear h0 h1
have h2 := NumberHelperEightDigitWord w h 2 (by omega)
have hp3 : 3158064 <= w.val % 16777216 /\
w.val % 16777216 <= 3750201 := by omega
clear hp2 h2
have h3 := NumberHelperEightDigitWord w h 3 (by omega)
have hp4 : 808464432 <= w.val % 4294967296 /\
w.val % 4294967296 <= 960051513 := by omega
clear hp3 h3
have h4 := NumberHelperEightDigitWord w h 4 (by omega)
have hp5 : 206966894640 <= w.val % 1099511627776 /\
w.val % 1099511627776 <= 245773187385 := by omega
clear hp4 h4
have h5 := NumberHelperEightDigitWord w h 5 (by omega)
have hp6 : 52983525027888 <= w.val % 281474976710656 /\
w.val % 281474976710656 <= 62917935970617 := by omega
clear hp5 h5
have h6 := NumberHelperEightDigitWord w h 6 (by omega)
have hp7 : 13563782407139376 <= w.val % 72057594037927936 /\
w.val % 72057594037927936 <= 16106991608478009 := by omega
clear hp6 h6
have h7 := NumberHelperEightDigitWord w h 7 (by omega)
have hw : w.val < 18446744073709551616 := by scalar_tac
have hv : 3472328296227680304 <= w.val /\
w.val <= 4123389851770370361 := by omega
unfold num.imp.dec2flt.parse.parse_8digits
step
step
step
have hi1le : i1.val <= v1.val := by
rw [i1_post1]
exact Nat.shiftRight_le _ _
have hmax : i.val + i1.val <= U64.max := by
rw [U64.max_eq]
omega
step with UScalar.add_spec
step
step
step
step
step
step
step
step
have hv1bv : v1.bv = w.bv - 3472328296227680304#64 := by
apply BitVec.eq_of_toNat_eq
simp [v1_post1, BitVec.toNat_sub]
omega
have hibv : i.bv = v1.bv * 10#64 := by
apply BitVec.eq_of_toNat_eq
simp [i_post, BitVec.toNat_mul]
have hiBound := UScalar.hrBounds i
simp [UScalar.rMax_eq_max, U64.max_eq, i_post] at hiBound
rw [Nat.mod_eq_of_lt]
omega
have hv2bv : v2.bv = i.bv + i1.bv := by
apply BitVec.eq_of_toNat_eq
simp [v2_post, BitVec.toNat_add]
rw [Nat.mod_eq_of_lt]
rw [U64.max_eq] at hmax
omega
rw [i7_post]
change (i6.bv.setWidth 32).setWidth 64 = _
congr 1
congr 1
apply Eq.trans i6_post2
rw [i5_post, v11_post, v21_post]
change ((i2.bv * num.imp.dec2flt.parse.parse_8digits.MUL1.bv) +
(i4.bv * num.imp.dec2flt.parse.parse_8digits.MUL2.bv)) >>> 32 = _
simp_rw [i4_post2, i3_post2, i2_post2]
rw [num.imp.dec2flt.parse.parse_8digits.MASK.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL1.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL2.eq_def]
simp_rw [hv2bv, hibv, i1_post2, hv1bv]
simp
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Mathlib.Tactic.IntervalCases
import Tablet.NumberHelperEightDigitWord
import Tablet.num_imp_dec2flt_parse_parse_8digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 10000
namespace dec2flt_model
-- [TABLET NODE: NumberHelperParseEightDigitsExact]
theorem NumberHelperParseEightDigitsExact (w : Std.U64)
(h : num.imp.dec2flt.common.is_8digits w = ok true) :
exists z, num.imp.dec2flt.parse.parse_8digits w = ok z /\
z.val =
10000000 * ((w.val / (256^0)) % 256 - 48) +
1000000 * ((w.val / (256^1)) % 256 - 48) +
100000 * ((w.val / (256^2)) % 256 - 48) +
10000 * ((w.val / (256^3)) % 256 - 48) +
1000 * ((w.val / (256^4)) % 256 - 48) +
100 * ((w.val / (256^5)) % 256 - 48) +
10 * ((w.val / (256^6)) % 256 - 48) +
((w.val / (256^7)) % 256 - 48) := by
-- BODY
have hb0 := NumberHelperEightDigitWord w h 0 (by omega)
have hb1 := NumberHelperEightDigitWord w h 1 (by omega)
have hb2 := NumberHelperEightDigitWord w h 2 (by omega)
have hb3 := NumberHelperEightDigitWord w h 3 (by omega)
have hb4 := NumberHelperEightDigitWord w h 4 (by omega)
have hb5 := NumberHelperEightDigitWord w h 5 (by omega)
have hb6 := NumberHelperEightDigitWord w h 6 (by omega)
have hb7 := NumberHelperEightDigitWord w h 7 (by omega)
have hx0 : (w.bv.extractLsb' 0 8).toNat = (w.val / (256^0)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx1 : (w.bv.extractLsb' 8 8).toNat = (w.val / (256^1)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx2 : (w.bv.extractLsb' 16 8).toNat = (w.val / (256^2)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx3 : (w.bv.extractLsb' 24 8).toNat = (w.val / (256^3)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx4 : (w.bv.extractLsb' 32 8).toNat = (w.val / (256^4)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx5 : (w.bv.extractLsb' 40 8).toNat = (w.val / (256^5)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx6 : (w.bv.extractLsb' 48 8).toNat = (w.val / (256^6)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hx7 : (w.bv.extractLsb' 56 8).toNat = (w.val / (256^7)) % 256 := by
simp [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hd0 : 48#8 <= w.bv.extractLsb' 0 8 /\ w.bv.extractLsb' 0 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 0 8).toNat
rw [hx0]
exact hb0.1
· change (w.bv.extractLsb' 0 8).toNat <= 57
rw [hx0]
exact hb0.2
have hd1 : 48#8 <= w.bv.extractLsb' 8 8 /\ w.bv.extractLsb' 8 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 8 8).toNat
rw [hx1]
exact hb1.1
· change (w.bv.extractLsb' 8 8).toNat <= 57
rw [hx1]
exact hb1.2
have hd2 : 48#8 <= w.bv.extractLsb' 16 8 /\ w.bv.extractLsb' 16 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 16 8).toNat
rw [hx2]
exact hb2.1
· change (w.bv.extractLsb' 16 8).toNat <= 57
rw [hx2]
exact hb2.2
have hd3 : 48#8 <= w.bv.extractLsb' 24 8 /\ w.bv.extractLsb' 24 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 24 8).toNat
rw [hx3]
exact hb3.1
· change (w.bv.extractLsb' 24 8).toNat <= 57
rw [hx3]
exact hb3.2
have hd4 : 48#8 <= w.bv.extractLsb' 32 8 /\ w.bv.extractLsb' 32 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 32 8).toNat
rw [hx4]
exact hb4.1
· change (w.bv.extractLsb' 32 8).toNat <= 57
rw [hx4]
exact hb4.2
have hd5 : 48#8 <= w.bv.extractLsb' 40 8 /\ w.bv.extractLsb' 40 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 40 8).toNat
rw [hx5]
exact hb5.1
· change (w.bv.extractLsb' 40 8).toNat <= 57
rw [hx5]
exact hb5.2
have hd6 : 48#8 <= w.bv.extractLsb' 48 8 /\ w.bv.extractLsb' 48 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 48 8).toNat
rw [hx6]
exact hb6.1
· change (w.bv.extractLsb' 48 8).toNat <= 57
rw [hx6]
exact hb6.2
have hd7 : 48#8 <= w.bv.extractLsb' 56 8 /\ w.bv.extractLsb' 56 8 <= 57#8 := by
constructor
· change 48 <= (w.bv.extractLsb' 56 8).toNat
rw [hx7]
exact hb7.1
· change (w.bv.extractLsb' 56 8).toNat <= 57
rw [hx7]
exact hb7.2
have hid := parse8BitVecIdentity w.bv hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7
have hs0 := digitSubSetWidthToNat (w.bv.extractLsb' 0 8)
(by omega) (by omega)
have hs1 := digitSubSetWidthToNat (w.bv.extractLsb' 8 8)
(by omega) (by omega)
have hs2 := digitSubSetWidthToNat (w.bv.extractLsb' 16 8)
(by omega) (by omega)
have hs3 := digitSubSetWidthToNat (w.bv.extractLsb' 24 8)
(by omega) (by omega)
have hs4 := digitSubSetWidthToNat (w.bv.extractLsb' 32 8)
(by omega) (by omega)
have hs5 := digitSubSetWidthToNat (w.bv.extractLsb' 40 8)
(by omega) (by omega)
have hs6 := digitSubSetWidthToNat (w.bv.extractLsb' 48 8)
(by omega) (by omega)
have hs7 := digitSubSetWidthToNat (w.bv.extractLsb' 56 8)
(by omega) (by omega)
have hv0 : (w.bv.extractLsb' 0 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 0 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs0]
simp
omega
have hv1 : (w.bv.extractLsb' 8 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 8 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs1]
simp
omega
have hv2 : (w.bv.extractLsb' 16 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 16 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs2]
simp
omega
have hv3 : (w.bv.extractLsb' 24 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 24 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs3]
simp
omega
have hv4 : (w.bv.extractLsb' 32 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 32 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs4]
simp
omega
have hv5 : (w.bv.extractLsb' 40 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 40 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs5]
simp
omega
have hv6 : (w.bv.extractLsb' 48 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 48 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs6]
simp
omega
have hv7 : (w.bv.extractLsb' 56 8 - 48#8).setWidth 64 =
BitVec.ofNat 64 ((w.bv.extractLsb' 56 8).toNat - 48) := by
apply BitVec.eq_of_toNat_eq
rw [hs7]
simp
omega
have he := parse8Execution w h
obtain ⟨z, hz, hzpost⟩ := Aeneas.Std.WP.spec_imp_exists he
refine ⟨z, hz, ?_⟩
have hzbits := hzpost.trans hid
rw [hv0, hv1, hv2, hv3, hv4, hv5, hv6, hv7] at hzbits
simp only [bitVec64OfNatMul, bitVec64OfNatAdd] at hzbits
change z.bv.toNat = _
rw [hzbits]
simp only [BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (by omega)]
rw [hx0, hx1, hx2, hx3, hx4, hx5, hx6, hx7]
simp only [Nat.mul_comm]
where
parse8BitVecIdentity (w : BitVec 64)
(h0 : 48#8 <= w.extractLsb' 0 8 /\ w.extractLsb' 0 8 <= 57#8)
(h1 : 48#8 <= w.extractLsb' 8 8 /\ w.extractLsb' 8 8 <= 57#8)
(h2 : 48#8 <= w.extractLsb' 16 8 /\ w.extractLsb' 16 8 <= 57#8)
(h3 : 48#8 <= w.extractLsb' 24 8 /\ w.extractLsb' 24 8 <= 57#8)
(h4 : 48#8 <= w.extractLsb' 32 8 /\ w.extractLsb' 32 8 <= 57#8)
(h5 : 48#8 <= w.extractLsb' 40 8 /\ w.extractLsb' 40 8 <= 57#8)
(h6 : 48#8 <= w.extractLsb' 48 8 /\ w.extractLsb' 48 8 <= 57#8)
(h7 : 48#8 <= w.extractLsb' 56 8 /\ w.extractLsb' 56 8 <= 57#8) :
let v1 := w - 3472328296227680304#64
let v2 := v1 * 10#64 + (v1 >>> 8)
let a := (v2 &&& 1095216660735#64) * 4294967296000100#64
let b := ((v2 >>> 16) &&& 1095216660735#64) * 42949672960001#64
(((a + b) >>> 32).setWidth 32).setWidth 64 =
(w.extractLsb' 0 8 - 48#8).setWidth 64 * 10000000#64 +
(w.extractLsb' 8 8 - 48#8).setWidth 64 * 1000000#64 +
(w.extractLsb' 16 8 - 48#8).setWidth 64 * 100000#64 +
(w.extractLsb' 24 8 - 48#8).setWidth 64 * 10000#64 +
(w.extractLsb' 32 8 - 48#8).setWidth 64 * 1000#64 +
(w.extractLsb' 40 8 - 48#8).setWidth 64 * 100#64 +
(w.extractLsb' 48 8 - 48#8).setWidth 64 * 10#64 +
(w.extractLsb' 56 8 - 48#8).setWidth 64 := by
have hlo0 : 48 <= (w.extractLsb' 0 8).toNat := by exact h0.1
have hlo1 : 48 <= (w.extractLsb' 8 8).toNat := by exact h1.1
have hlo2 : 48 <= (w.extractLsb' 16 8).toNat := by exact h2.1
have hlo3 : 48 <= (w.extractLsb' 24 8).toNat := by exact h3.1
have hlo4 : 48 <= (w.extractLsb' 32 8).toNat := by exact h4.1
have hlo5 : 48 <= (w.extractLsb' 40 8).toNat := by exact h5.1
have hlo6 : 48 <= (w.extractLsb' 48 8).toNat := by exact h6.1
have hlo7 : 48 <= (w.extractLsb' 56 8).toNat := by exact h7.1
have hhi0 : (w.extractLsb' 0 8).toNat <= 57 := by exact h0.2
have hhi1 : (w.extractLsb' 8 8).toNat <= 57 := by exact h1.2
have hhi2 : (w.extractLsb' 16 8).toNat <= 57 := by exact h2.2
have hhi3 : (w.extractLsb' 24 8).toNat <= 57 := by exact h3.2
have hhi4 : (w.extractLsb' 32 8).toNat <= 57 := by exact h4.2
have hhi5 : (w.extractLsb' 40 8).toNat <= 57 := by exact h5.2
have hhi6 : (w.extractLsb' 48 8).toNat <= 57 := by exact h6.2
have hhi7 : (w.extractLsb' 56 8).toNat <= 57 := by exact h7.2
let d0 := (w.extractLsb' 0 8).toNat - 48
let d1 := (w.extractLsb' 8 8).toNat - 48
let d2 := (w.extractLsb' 16 8).toNat - 48
let d3 := (w.extractLsb' 24 8).toNat - 48
let d4 := (w.extractLsb' 32 8).toNat - 48
let d5 := (w.extractLsb' 40 8).toNat - 48
let d6 := (w.extractLsb' 48 8).toNat - 48
let d7 := (w.extractLsb' 56 8).toNat - 48
have hd0 : d0 <= 9 := by change (w.extractLsb' 0 8).toNat - 48 <= 9; omega
have hd1 : d1 <= 9 := by change (w.extractLsb' 8 8).toNat - 48 <= 9; omega
have hd2 : d2 <= 9 := by change (w.extractLsb' 16 8).toNat - 48 <= 9; omega
have hd3 : d3 <= 9 := by change (w.extractLsb' 24 8).toNat - 48 <= 9; omega
have hd4 : d4 <= 9 := by change (w.extractLsb' 32 8).toNat - 48 <= 9; omega
have hd5 : d5 <= 9 := by change (w.extractLsb' 40 8).toNat - 48 <= 9; omega
have hd6 : d6 <= 9 := by change (w.extractLsb' 48 8).toNat - 48 <= 9; omega
have hd7 : d7 <= 9 := by change (w.extractLsb' 56 8).toNat - 48 <= 9; omega
let v1 := w - 3472328296227680304#64
let v2 := v1 * 10#64 + (v1 >>> 8)
have hv1 : v1.toNat = d0 + 256*d1 + 65536*d2 + 16777216*d3 +
4294967296*d4 + 1099511627776*d5 + 281474976710656*d6 +
72057594037927936*d7 := by
dsimp [v1, d0, d1, d2, d3, d4, d5, d6, d7]
exact subDigits w hlo0 hlo1 hlo2 hlo3 hlo4 hlo5 hlo6 hlo7
have hv2 : v2.toNat =
(10*d0+d1) + 256*(10*d1+d2) + 65536*(10*d2+d3) +
16777216*(10*d3+d4) + 4294967296*(10*d4+d5) +
1099511627776*(10*d5+d6) + 281474976710656*(10*d6+d7) +
72057594037927936*(10*d7) := by
exact pairedDigits v1 d0 d1 d2 d3 d4 d5 d6 d7
hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7 hv1
let p0 := 10*d0+d1
let p1 := 10*d1+d2
let p2 := 10*d2+d3
let p3 := 10*d3+d4
let p4 := 10*d4+d5
let p5 := 10*d5+d6
let p6 := 10*d6+d7
let p7 := 10*d7
have hp0 : p0 <= 99 := by change 10*d0+d1 <= 99; omega
have hp1 : p1 <= 99 := by change 10*d1+d2 <= 99; omega
have hp2 : p2 <= 99 := by change 10*d2+d3 <= 99; omega
have hp3 : p3 <= 99 := by change 10*d3+d4 <= 99; omega
have hp4 : p4 <= 99 := by change 10*d4+d5 <= 99; omega
have hp5 : p5 <= 99 := by change 10*d5+d6 <= 99; omega
have hp6 : p6 <= 99 := by change 10*d6+d7 <= 99; omega
have hp7 : p7 <= 99 := by change 10*d7 <= 99; omega
have hv2' : v2.toNat = p0 + 256*p1 + 65536*p2 + 16777216*p3 +
4294967296*p4 + 1099511627776*p5 + 281474976710656*p6 +
72057594037927936*p7 := by
simpa [p0, p1, p2, p3, p4, p5, p6, p7] using hv2
have hs := selectedPairs v2 p0 p1 p2 p3 p4 p5 p6 p7
hp0 hp1 hp2 hp3 hp4 hp5 hp6 hp7 hv2'
have hd0bv : (w.extractLsb' 0 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d0 := by
simpa [d0] using digitBitVec (w.extractLsb' 0 8) hlo0 hhi0
have hd1bv : (w.extractLsb' 8 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d1 := by
simpa [d1] using digitBitVec (w.extractLsb' 8 8) hlo1 hhi1
have hd2bv : (w.extractLsb' 16 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d2 := by
simpa [d2] using digitBitVec (w.extractLsb' 16 8) hlo2 hhi2
have hd3bv : (w.extractLsb' 24 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d3 := by
simpa [d3] using digitBitVec (w.extractLsb' 24 8) hlo3 hhi3
have hd4bv : (w.extractLsb' 32 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d4 := by
simpa [d4] using digitBitVec (w.extractLsb' 32 8) hlo4 hhi4
have hd5bv : (w.extractLsb' 40 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d5 := by
simpa [d5] using digitBitVec (w.extractLsb' 40 8) hlo5 hhi5
have hd6bv : (w.extractLsb' 48 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d6 := by
simpa [d6] using digitBitVec (w.extractLsb' 48 8) hlo6 hhi6
have hd7bv : (w.extractLsb' 56 8 - 48#8).setWidth 64 = BitVec.ofNat 64 d7 := by
simpa [d7] using digitBitVec (w.extractLsb' 56 8) hlo7 hhi7
change (((((v2 &&& 1095216660735#64) * 4294967296000100#64 +
(((v2 >>> 16) &&& 1095216660735#64) * 42949672960001#64)) >>> 32
).setWidth 32).setWidth 64) = _
rw [maskBytes v2, maskBytes (v2 >>> 16)]
rw [hs.1, hs.2.1, hs.2.2.1, hs.2.2.2]
rw [hd0bv, hd1bv, hd2bv, hd3bv, hd4bv, hd5bv, hd6bv, hd7bv]
exact combinePairs d0 d1 d2 d3 d4 d5 d6 d7
hd0 hd1 hd2 hd3 hd4 hd5 hd6 hd7
maskBytes (x : BitVec 64) :
x &&& 1095216660735#64 =
(x.extractLsb' 0 8).setWidth 64 |||
((x.extractLsb' 32 8).setWidth 64 <<< 32) := by
have hm : 1095216660735#64 =
(BitVec.allOnes 8).setWidth 64 |||
((BitVec.allOnes 8).setWidth 64 <<< 32) := by decide +kernel
apply BitVec.eq_of_getLsbD_eq
intro i hi
have hmi := congrArg (fun z : BitVec 64 => z.getLsbD i) hm
simp only [BitVec.getLsbD_and, BitVec.getLsbD_or, BitVec.getLsbD_setWidth,
BitVec.getLsbD_allOnes, BitVec.getLsbD_shiftLeft,
BitVec.getLsbD_extractLsb'] at hmi ⊢
rw [hmi]
by_cases h32 : i < 32
· simp [h32, Bool.and_comm, Bool.and_left_comm, Bool.and_assoc]
· have hle : 32 <= i := by omega
simp [h32, Nat.add_sub_of_le hle, Bool.and_or_distrib_left,
Bool.and_comm, Bool.and_left_comm, Bool.and_assoc]
digitBitVec (b : BitVec 8) (hlo : 48 <= b.toNat) (hhi : b.toNat <= 57) :
(b - 48#8).setWidth 64 = BitVec.ofNat 64 (b.toNat - 48) := by
apply BitVec.eq_of_toNat_eq
simp only [BitVec.toNat_setWidth, BitVec.toNat_sub, BitVec.toNat_ofNat]
norm_num
omega
wordDecomp (w : BitVec 64) :
w.toNat =
(w.extractLsb' 0 8).toNat +
256 * (w.extractLsb' 8 8).toNat +
65536 * (w.extractLsb' 16 8).toNat +
16777216 * (w.extractLsb' 24 8).toNat +
4294967296 * (w.extractLsb' 32 8).toNat +
1099511627776 * (w.extractLsb' 40 8).toNat +
281474976710656 * (w.extractLsb' 48 8).toNat +
72057594037927936 * (w.extractLsb' 56 8).toNat := by
simp only [BitVec.extractLsb'_toNat, Nat.shiftRight_eq_div_pow]
have hw := w.isLt
norm_num at *
omega
subDigits (w : BitVec 64)
(h0 : 48 <= (w.extractLsb' 0 8).toNat)
(h1 : 48 <= (w.extractLsb' 8 8).toNat)
(h2 : 48 <= (w.extractLsb' 16 8).toNat)
(h3 : 48 <= (w.extractLsb' 24 8).toNat)
(h4 : 48 <= (w.extractLsb' 32 8).toNat)
(h5 : 48 <= (w.extractLsb' 40 8).toNat)
(h6 : 48 <= (w.extractLsb' 48 8).toNat)
(h7 : 48 <= (w.extractLsb' 56 8).toNat) :
(w - 3472328296227680304#64).toNat =
((w.extractLsb' 0 8).toNat - 48) +
256 * ((w.extractLsb' 8 8).toNat - 48) +
65536 * ((w.extractLsb' 16 8).toNat - 48) +
16777216 * ((w.extractLsb' 24 8).toNat - 48) +
4294967296 * ((w.extractLsb' 32 8).toNat - 48) +
1099511627776 * ((w.extractLsb' 40 8).toNat - 48) +
281474976710656 * ((w.extractLsb' 48 8).toNat - 48) +
72057594037927936 * ((w.extractLsb' 56 8).toNat - 48) := by
rw [BitVec.toNat_sub, wordDecomp]
norm_num at *
omega
pairedDigits (v1 : BitVec 64) (d0 d1 d2 d3 d4 d5 d6 d7 : Nat)
(h0 : d0 <= 9) (h1 : d1 <= 9) (h2 : d2 <= 9) (h3 : d3 <= 9)
(h4 : d4 <= 9) (h5 : d5 <= 9) (h6 : d6 <= 9) (h7 : d7 <= 9)
(hv1 : v1.toNat = d0 + 256*d1 + 65536*d2 + 16777216*d3 +
4294967296*d4 + 1099511627776*d5 + 281474976710656*d6 +
72057594037927936*d7) :
(v1 * 10#64 + (v1 >>> 8)).toNat =
(10*d0+d1) + 256*(10*d1+d2) + 65536*(10*d2+d3) +
16777216*(10*d3+d4) + 4294967296*(10*d4+d5) +
1099511627776*(10*d5+d6) + 281474976710656*(10*d6+d7) +
72057594037927936*(10*d7) := by
have hshift : (v1 >>> 8).toNat = d1 + 256*d2 + 65536*d3 +
16777216*d4 + 4294967296*d5 + 1099511627776*d6 +
281474976710656*d7 := by
simp [hv1, Nat.shiftRight_eq_div_pow]
omega
simp only [BitVec.toNat_add, BitVec.toNat_mul, BitVec.toNat_ofNat]
rw [hshift, hv1]
norm_num at *
omega
selectedPairs (v2 : BitVec 64) (p0 p1 p2 p3 p4 p5 p6 p7 : Nat)
(h0 : p0 <= 99) (h1 : p1 <= 99) (h2 : p2 <= 99) (h3 : p3 <= 99)
(h4 : p4 <= 99) (h5 : p5 <= 99) (h6 : p6 <= 99) (h7 : p7 <= 99)
(hv2 : v2.toNat = p0 + 256*p1 + 65536*p2 + 16777216*p3 +
4294967296*p4 + 1099511627776*p5 + 281474976710656*p6 +
72057594037927936*p7) :
(v2.extractLsb' 0 8).setWidth 64 = BitVec.ofNat 64 p0 ∧
((v2 >>> 16).extractLsb' 0 8).setWidth 64 = BitVec.ofNat 64 p2 ∧
(v2.extractLsb' 32 8).setWidth 64 = BitVec.ofNat 64 p4 ∧
((v2 >>> 16).extractLsb' 32 8).setWidth 64 = BitVec.ofNat 64 p6 := by
constructor
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
constructor
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
constructor
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
· apply BitVec.eq_of_toNat_eq
simp [BitVec.extractLsb'_toNat, hv2, Nat.shiftRight_eq_div_pow]
omega
packOrEqAdd (a b : Nat) (ha : a <= 99) :
(BitVec.ofNat 64 a ||| (BitVec.ofNat 64 b <<< 32)) =
BitVec.ofNat 64 a + (BitVec.ofNat 64 b <<< 32) := by
rw [BitVec.add_eq_or_of_and_eq_zero]
ext i hi
simp only [BitVec.getElem_and, BitVec.getElem_shiftLeft, BitVec.getElem_zero,
Bool.and_eq_false_imp]
intro hai
have hpow' := BitVec.two_pow_le_toNat_of_getElem_eq_true hi hai
have ha64 : a < 2 ^ 64 := by norm_num; omega
rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt ha64] at hpow'
interval_cases i <;> norm_num at hpow' ⊢ <;> omega
prodA (p0 p4 : Nat) (h0 : p0 <= 99) (_h4 : p4 <= 99) :
(BitVec.ofNat 64 p0 ||| (BitVec.ofNat 64 p4 <<< 32)) *
4294967296000100#64 =
BitVec.ofNat 64 (100*p0 + 4294967296*(1000000*p0 + 100*p4)) := by
rw [packOrEqAdd p0 p4 h0]
simp only [BitVec.shiftLeft_eq_mul_twoPow, BitVec.ofNat_add,
BitVec.ofNat_mul]
have hpow : BitVec.twoPow 64 32 = 4294967296#64 := by decide +kernel
rw [hpow]
have hc0 : 4294967296000100#64 =
100#64 + 4294967296#64 * 1000000#64 := by decide +kernel
have hsq : 4294967296#64 * 4294967296#64 = 0#64 := by decide +kernel
rw [hc0]
calc
_ = 100#64 * BitVec.ofNat 64 p0 +
4294967296#64 * (1000000#64 * BitVec.ofNat 64 p0 +
100#64 * BitVec.ofNat 64 p4) +
BitVec.ofNat 64 p4 *
(4294967296#64 * 4294967296#64) * 1000000#64 := by ring
_ = _ := by rw [hsq]; simp
prodB (p2 p6 : Nat) (h2 : p2 <= 99) (_h6 : p6 <= 99) :
(BitVec.ofNat 64 p2 ||| (BitVec.ofNat 64 p6 <<< 32)) *
42949672960001#64 =
BitVec.ofNat 64 (p2 + 4294967296*(10000*p2 + p6)) := by
rw [packOrEqAdd p2 p6 h2]
simp only [BitVec.shiftLeft_eq_mul_twoPow, BitVec.ofNat_add,
BitVec.ofNat_mul]
have hpow : BitVec.twoPow 64 32 = 4294967296#64 := by decide +kernel
rw [hpow]
have hc2 : 42949672960001#64 =
(1 : BitVec 64) + 4294967296#64 * 10000#64 := by decide +kernel
have hsq : 4294967296#64 * 4294967296#64 = 0#64 := by decide +kernel
rw [hc2]
calc
_ = BitVec.ofNat 64 p2 +
4294967296#64 * (10000#64 * BitVec.ofNat 64 p2 +
BitVec.ofNat 64 p6) +
BitVec.ofNat 64 p6 *
(4294967296#64 * 4294967296#64) * 10000#64 := by ring
_ = _ := by rw [hsq]; simp
combinePairs (d0 d1 d2 d3 d4 d5 d6 d7 : Nat)
(h0 : d0 <= 9) (h1 : d1 <= 9) (h2 : d2 <= 9) (h3 : d3 <= 9)
(h4 : d4 <= 9) (h5 : d5 <= 9) (h6 : d6 <= 9) (h7 : d7 <= 9) :
(((((BitVec.ofNat 64 (10*d0+d1) |||
(BitVec.ofNat 64 (10*d4+d5) <<< 32)) * 4294967296000100#64 +
(BitVec.ofNat 64 (10*d2+d3) |||
(BitVec.ofNat 64 (10*d6+d7) <<< 32)) * 42949672960001#64) >>> 32
).setWidth 32).setWidth 64) =
BitVec.ofNat 64 d0 * 10000000#64 +
BitVec.ofNat 64 d1 * 1000000#64 +
BitVec.ofNat 64 d2 * 100000#64 +
BitVec.ofNat 64 d3 * 10000#64 +
BitVec.ofNat 64 d4 * 1000#64 +
BitVec.ofNat 64 d5 * 100#64 +
BitVec.ofNat 64 d6 * 10#64 +
BitVec.ofNat 64 d7 := by
have hp0 : 10*d0+d1 <= 99 := by as_aux_lemma => omega
have hp2 : 10*d2+d3 <= 99 := by as_aux_lemma => omega
have hp4 : 10*d4+d5 <= 99 := by as_aux_lemma => omega
have hp6 : 10*d6+d7 <= 99 := by as_aux_lemma => omega
rw [prodA _ _ hp0 hp4, prodB _ _ hp2 hp6]
have hdecimal : d0*10000000 + d1*1000000 + d2*100000 + d3*10000 +
d4*1000 + d5*100 + d6*10 + d7 < 100000000 := by as_aux_lemma => omega
have hlow : 100*(10*d0+d1) + (10*d2+d3) < 4294967296 := by
as_aux_lemma => omega
have hform :
100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7))) =
(100*(10*d0+d1) + (10*d2+d3)) + 4294967296 *
(d0*10000000 + d1*1000000 + d2*100000 + d3*10000 +
d4*1000 + d5*100 + d6*10 + d7) := by ring
have htotal :
100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7))) <
18446744073709551616 := by as_aux_lemma =>
rw [hform]
omega
have hquot :
(100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7)))) /
4294967296 =
d0*10000000 + d1*1000000 + d2*100000 + d3*10000 +
d4*1000 + d5*100 + d6*10 + d7 := by as_aux_lemma =>
rw [hform, Nat.add_mul_div_left _ _ (by norm_num),
Nat.div_eq_of_lt hlow, Nat.zero_add]
have addOfNat (a b : Nat) : BitVec.ofNat 64 a + BitVec.ofNat 64 b =
BitVec.ofNat 64 (a+b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_add, Nat.add_mod]
have mulOfNat (a b : Nat) : BitVec.ofNat 64 a * BitVec.ofNat 64 b =
BitVec.ofNat 64 (a*b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_mul, Nat.mul_mod]
have hsum :
BitVec.ofNat 64 (100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5))) +
BitVec.ofNat 64 ((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7))) =
BitVec.ofNat 64 (100*(10*d0+d1) +
4294967296*(1000000*(10*d0+d1) + 100*(10*d4+d5)) +
((10*d2+d3) +
4294967296*(10000*(10*d2+d3) + (10*d6+d7)))) := by
apply addOfNat
have hright :
BitVec.ofNat 64 d0 * 10000000#64 +
BitVec.ofNat 64 d1 * 1000000#64 +
BitVec.ofNat 64 d2 * 100000#64 +
BitVec.ofNat 64 d3 * 10000#64 +
BitVec.ofNat 64 d4 * 1000#64 +
BitVec.ofNat 64 d5 * 100#64 +
BitVec.ofNat 64 d6 * 10#64 +
BitVec.ofNat 64 d7 =
BitVec.ofNat 64 (d0*10000000 + d1*1000000 + d2*100000 +
d3*10000 + d4*1000 + d5*100 + d6*10 + d7) := by
simp only [mulOfNat, addOfNat]
rw [hsum, hright]
apply BitVec.eq_of_toNat_eq
simp [Nat.shiftRight_eq_div_pow, Nat.mod_eq_of_lt htotal, hquot,
Nat.mod_eq_of_lt (show d0*10000000 + d1*1000000 + d2*100000 +
d3*10000 + d4*1000 + d5*100 + d6*10 + d7 < 4294967296 by omega),
Nat.mod_eq_of_lt (show d0*10000000 + d1*1000000 + d2*100000 +
d3*10000 + d4*1000 + d5*100 + d6*10 + d7 <
18446744073709551616 by omega)]
digitSubSetWidthToNat (b : BitVec 8)
(hlo : 48 <= b.toNat) (hhi : b.toNat <= 57) :
((b - 48#8).setWidth 64).toNat = b.toNat - 48 := by
simp only [BitVec.toNat_setWidth, BitVec.toNat_sub, BitVec.toNat_ofNat]
norm_num
omega
bitVec64OfNatMul (a b : Nat) :
(BitVec.ofNat 64 a) * (BitVec.ofNat 64 b) =
BitVec.ofNat 64 (a * b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_mul, Nat.mul_mod]
bitVec64OfNatAdd (a b : Nat) :
(BitVec.ofNat 64 a) + (BitVec.ofNat 64 b) =
BitVec.ofNat 64 (a + b) := by
apply BitVec.eq_of_toNat_eq
simp [BitVec.toNat_add, Nat.add_mod]
parse8Execution (w : Std.U64)
(h : num.imp.dec2flt.common.is_8digits w = ok true) :
num.imp.dec2flt.parse.parse_8digits w
⦃ q => q.bv =
let v1 := w.bv - 3472328296227680304#64
let v2 := v1 * 10#64 + (v1 >>> 8)
let a := (v2 &&& 1095216660735#64) * 4294967296000100#64
let b := ((v2 >>> 16) &&& 1095216660735#64) * 42949672960001#64
(((a + b) >>> 32).setWidth 32).setWidth 64 ⦄ := by
have h0 := NumberHelperEightDigitWord w h 0 (by omega)
have h1 := NumberHelperEightDigitWord w h 1 (by omega)
have hp2 : 12336 <= w.val % 65536 /\
w.val % 65536 <= 14649 := by omega
clear h0 h1
have h2 := NumberHelperEightDigitWord w h 2 (by omega)
have hp3 : 3158064 <= w.val % 16777216 /\
w.val % 16777216 <= 3750201 := by omega
clear hp2 h2
have h3 := NumberHelperEightDigitWord w h 3 (by omega)
have hp4 : 808464432 <= w.val % 4294967296 /\
w.val % 4294967296 <= 960051513 := by omega
clear hp3 h3
have h4 := NumberHelperEightDigitWord w h 4 (by omega)
have hp5 : 206966894640 <= w.val % 1099511627776 /\
w.val % 1099511627776 <= 245773187385 := by omega
clear hp4 h4
have h5 := NumberHelperEightDigitWord w h 5 (by omega)
have hp6 : 52983525027888 <= w.val % 281474976710656 /\
w.val % 281474976710656 <= 62917935970617 := by omega
clear hp5 h5
have h6 := NumberHelperEightDigitWord w h 6 (by omega)
have hp7 : 13563782407139376 <= w.val % 72057594037927936 /\
w.val % 72057594037927936 <= 16106991608478009 := by omega
clear hp6 h6
have h7 := NumberHelperEightDigitWord w h 7 (by omega)
have hw : w.val < 18446744073709551616 := by scalar_tac
have hv : 3472328296227680304 <= w.val /\
w.val <= 4123389851770370361 := by omega
unfold num.imp.dec2flt.parse.parse_8digits
step
step
step
have hi1le : i1.val <= v1.val := by
rw [i1_post1]
exact Nat.shiftRight_le _ _
have hmax : i.val + i1.val <= U64.max := by
rw [U64.max_eq]
omega
step with UScalar.add_spec
step
step
step
step
step
step
step
step
have hv1bv : v1.bv = w.bv - 3472328296227680304#64 := by
apply BitVec.eq_of_toNat_eq
simp [v1_post1, BitVec.toNat_sub]
omega
have hibv : i.bv = v1.bv * 10#64 := by
apply BitVec.eq_of_toNat_eq
simp [i_post, BitVec.toNat_mul]
have hiBound := UScalar.hrBounds i
simp [UScalar.rMax_eq_max, U64.max_eq, i_post] at hiBound
rw [Nat.mod_eq_of_lt]
omega
have hv2bv : v2.bv = i.bv + i1.bv := by
apply BitVec.eq_of_toNat_eq
simp [v2_post, BitVec.toNat_add]
rw [Nat.mod_eq_of_lt]
rw [U64.max_eq] at hmax
omega
rw [i7_post]
change (i6.bv.setWidth 32).setWidth 64 = _
congr 1
congr 1
apply Eq.trans i6_post2
rw [i5_post, v11_post, v21_post]
change ((i2.bv * num.imp.dec2flt.parse.parse_8digits.MUL1.bv) +
(i4.bv * num.imp.dec2flt.parse.parse_8digits.MUL2.bv)) >>> 32 = _
simp_rw [i4_post2, i3_post2, i2_post2]
rw [num.imp.dec2flt.parse.parse_8digits.MASK.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL1.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL2.eq_def]
simp_rw [hv2bv, hibv, i1_post2, hv1bv]
simp
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (49)
- parse_8digits · dec2flt/parse.rs:18 Program Rust
- is_8digits · dec2flt/common.rs:40 Program Rust
- MASK · dec2flt/parse.rs:19 Program Rust
More program dependencies (16)
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
Standard-library dependencies (30)
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
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
- Classical.choice
- Quot.sound
- propext
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": "NumberHelperParseEightDigitsExact",
"closure_version": "patch_c_v1",
"active_decl_hash": "87effdae280265d23209edd60e1e58a523c7bb68aa1a89317ed85c33945ef71b",
"active_statement_hash": "415934bf7025090787db9ee3b6100a37e06b3a42ba33dbf4b01bc45d593dc2be",
"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-137",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperEightDigitWord": "a61cba9606484373",
"num_imp_dec2flt_parse_parse_8digits": "5f4488c177675662",
"num_imp_dec2flt_parse_parse_8digits_MASK": "7ca2021b20f34521",
"num_imp_dec2flt_parse_parse_8digits_MUL1": "152948ead6b79a6c",
"num_imp_dec2flt_parse_parse_8digits_MUL2": "4e8db7500927acde"
},
"strict_definition_deps": {
"num_imp_dec2flt_common_is_8digits": "53e9de5212d69bf5",
"num_imp_dec2flt_parse_parse_8digits": "ae610d45d88851c6",
"num_imp_dec2flt_parse_parse_8digits_MASK": "00fd2cbc66eea03b",
"num_imp_dec2flt_parse_parse_8digits_MUL1": "14171ee9dc4177db",
"num_imp_dec2flt_parse_parse_8digits_MUL2": "52fae8265919fe4b"
}
}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:b673e2fd32a27b60a491f28ee4e05774ffabd03d8fb158ac835107ba3e3a253b",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}