Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add BitVec.(getElem_umod_of_lt, getElem_umod, getLsbD_umod, getMsbD_umod) #6795

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
27 changes: 27 additions & 0 deletions src/Init/Data/BitVec/Bitblast.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1230,4 +1230,31 @@ theorem shiftRight_eq_ushiftRightRec (x : BitVec w₁) (y : BitVec w₂) :
· simp [of_length_zero]
· simp [ushiftRightRec_eq]

/- ### umod -/

theorem getElem_umod {n d : BitVec w} (hi : i < w) :
(umod n d)[i] = if d = 0#w then n[i] else (divRec w {n, d} (DivModState.init w)).r[i] := by
by_cases hd : d = 0#w
· simp [hd]
· have := (BitVec.not_le (x := d) (y := 0#w)).mp
rw [← BitVec.umod_eq_divRec (by simp [hd, this])]
simp [hd]

theorem getLsbD_umod {n d : BitVec w}:
(umod n d).getLsbD i =
if d = 0#w then n.getLsbD i
else ((divRec w {n, d} (DivModState.init w)).r).getLsbD i := by
by_cases hi : i < w
· simp only [BitVec.getLsbD_eq_getElem hi, getElem_umod]
luisacicolini marked this conversation as resolved.
Show resolved Hide resolved
· simp [show w ≤ i by omega]

theorem getMsbD_umod {n d : BitVec w}:
(umod n d).getMsbD i =
if d = 0#w then n.getMsbD i
else (divRec w {n, d} (DivModState.init w)).r.getMsbD i := by
by_cases hi : i < w
· rw [BitVec.getMsbD_eq_getLsbD, getLsbD_umod]
simp [BitVec.getMsbD_eq_getLsbD, hi]
· simp [show w ≤ i by omega]

end BitVec
Loading