@@ -3049,42 +3049,54 @@ theorem cpopNatRec_cons_eq_cpopNatRec_of_le {x : BitVec w} {b : Bool} (hn : n
30493049
30503050theorem getLsbD_extractAndExtendPopulate_add {x : BitVec w} (hk : k < w):
30513051 (x.extractAndExtendPopulate w).getLsbD (pos * w + k) = ((x.extractLsb' pos 1 ).zeroExtend w).getLsbD k := by
3052+
30523053 simp [← extractLsb'_extractAndExtendPopulate_eq (w := w) (len := w) (i := pos) (x := x)]
30533054 omega
30543055
3055- theorem getLsbD_extractAndExtendPopulate {x : BitVec w} (hw : 0 < w) (hk : k ≤ w * w):
3056- (x.extractAndExtendPopulate w).getLsbD k =
3057- let idx := k % w
3058- let pos := (k - idx)/w
3059- (x.extractLsb' pos 1 ).getLsbD idx := by
3060- simp
3061- let idx := k % w
3062- let pos := (k - idx) / w
3063- have hk : k = pos * w + idx := by
3064- subst pos idx
3065- have : (k = (k - k % w) / w * w + k % w) ↔ (k - k % w = (k - k % w) / w * w) := by
3066- sorry
3067- sorry
3068- have hidx : idx < w := by sorry
3069- rw [hk]
3070- rw [getLsbD_extractAndExtendPopulate_add (by omega)]
3071- simp
3072- by_cases hmod0 : idx = 0
3073- · simp [hmod0, hw]
3074- · simp [hmod0]
3075- intros hmod
3076- simp [hmod]
3077- rw [Nat.add_div hw]
3078- simp [hmod, show ¬ w = 0 by omega]
3079- rw [Nat.mul_div_cancel (H := by omega)]
3080- have : idx / w = 0 := by exact mod_div_self k w
3081- simp [this ]
3056+ theorem getLsbD_extractAndExtend_of_le_of_lt (w idx currIdx : Nat) (hw : 0 < w) (x : BitVec w)
3057+ (_hcurr : currIdx < w)
3058+ (hlt : idx < w * (currIdx + 1 )) (hle : w * currIdx ≤ idx) :
3059+ (BitVec.zeroExtend w (BitVec.extractLsb' currIdx 1 x)).getLsbD (idx - w * currIdx) =
3060+ (BitVec.extractAndExtendPopulate w x).getLsbD idx := by
3061+ unfold BitVec.extractAndExtendPopulate
3062+ have ⟨res, proof⟩ := BitVec.extractAndExtendPopulateAux 0 w x (BitVec.cast (by omega) 0 #0 ) (by omega) (by omega)
3063+ simp [Nat.mul_add] at hlt
3064+ simp [show idx - w * currIdx < w by omega]
3065+ by_cases h2 : idx - w * currIdx = 0
3066+ · have hidx : idx = currIdx * w := by rw [Nat.mul_comm]; omega
3067+ simp [h2]
3068+ simp [hidx]
3069+ specialize proof currIdx
3070+ have : res.getLsbD (currIdx * w) = (BitVec.extractLsb' (currIdx * w) w res)[0 ] := by
3071+ simp
3072+ simp [this , proof]
3073+ · have hidx : ∃ j, idx = currIdx * w + j := by
3074+ refine Nat.exists_eq_add_of_le (by rw [Nat.mul_comm]; omega)
3075+ obtain ⟨j, hj⟩ := hidx
3076+ simp [h2]
3077+ rw [hj]
3078+ specialize proof currIdx
3079+ have : res.getLsbD (currIdx * w + j) = (BitVec.extractLsb' (currIdx * w) w res).getLsbD j := by
3080+ simp
3081+ intros ht
3082+ by_cases hlt : j < w
3083+ · omega
3084+ · rw [Nat.mul_comm] at hj
3085+ omega
3086+ rw [this ]
3087+ rw [proof]
3088+ simp
3089+ intros hj' hj''
3090+ subst hj''
3091+ simp
3092+ rw [Nat.mul_comm] at hj
3093+ omega
30823094
3083- sorry
30843095
30853096theorem th3 :
30863097 (extractAndExtendPopulate w (setWidth n x)).addRecAux n 0 #w = (extractAndExtendPopulate w x).addRecAux n 0 #w := by
30873098 have : extractAndExtendPopulate w (setWidth n x) = (extractAndExtendPopulate w x).setWidth (n * w) := by
3099+ generalize hgen : extractAndExtendPopulate w x = gen
30883100
30893101 sorry
30903102
@@ -3150,7 +3162,6 @@ theorem thm1 {x : BitVec (w' + 1)} (hn : n ≤ w'):
31503162 apply eq_of_toNat_eq
31513163 simp
31523164
3153-
31543165 sorry
31553166 · simp [show n' = w' + 1 by omega]
31563167 have hext1 := extractLsb'_extractAndExtendPopulate_eq (w := w' + 1 ) (len := w' + 1 ) (i := w') (x := x)
0 commit comments