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.(getMsbD, msb)_replicate, replicate_one #6326

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eb1d9ee
feat: getMsbD_replicate
luisacicolini Jan 21, 2025
3227ec0
chore: getMsbD_rotateLeft_of_lt undo change
luisacicolini Jan 21, 2025
8f708f3
chore: remove append_assoc_left
luisacicolini Jan 21, 2025
96233b3
chore: restart proof with replicate
luisacicolini Jan 21, 2025
b62806e
chore: fix getMsbD_rotateLeft_of_lt proof
luisacicolini Jan 21, 2025
648cd67
chore: reordeering
luisacicolini Jan 21, 2025
6e74763
chore: fix proofs
luisacicolini Jan 21, 2025
3fd39c3
chore: msb_replicare better proof
luisacicolini Jan 21, 2025
167062c
chore: simple order
luisacicolini Jan 21, 2025
1ad467b
chore: fix simp only
luisacicolini Jan 21, 2025
72ea87b
chore: format
luisacicolini Jan 21, 2025
4bd9cfb
chore: remove mul_one
luisacicolini Jan 21, 2025
0c73020
chore: remove useless var spec
luisacicolini Jan 21, 2025
f794c9e
chore: format of proof
luisacicolini Jan 21, 2025
4481757
chore: replace omega with proper theorem
luisacicolini Jan 21, 2025
ded2cce
chore: fix msb_replicate format
luisacicolini Jan 21, 2025
cfd4639
chore: fix ypothesis
luisacicolini Jan 21, 2025
19c426d
chore: restore unneeded change
luisacicolini Jan 21, 2025
80c622a
chore: nonretm simp
luisacicolini Jan 21, 2025
751f74f
chore: cases instead of by_cases
luisacicolini Jan 21, 2025
f8f584f
chore: simpler getElem proof
luisacicolini Jan 21, 2025
73dece4
chore: inline redundant omega
luisacicolini Jan 22, 2025
174dbc5
chore: undo reordering
luisacicolini Jan 22, 2025
8beb7f9
chore: undo reordering
luisacicolini Jan 22, 2025
6ac9a4e
chore: reordering
luisacicolini Jan 22, 2025
b8c1211
chore: reduce formatting diff
luisacicolini Jan 22, 2025
f34d8f9
chore: remove rewrite in replicate_one
luisacicolini Jan 22, 2025
0b4fed1
chore: format
luisacicolini Jan 22, 2025
6803da6
chore: inline redundand hypothesis
luisacicolini Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/Init/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3402,14 +3402,19 @@ theorem and_one_eq_setWidth_ofBool_getLsbD {x : BitVec w} :
theorem replicate_zero {x : BitVec w} : x.replicate 0 = 0#0 := by
simp [replicate]

@[simp]
theorem replicate_one {w : Nat} {x : BitVec w} (h : w = w * 1 := Eq.symm (Nat.mul_one _)) :
luisacicolini marked this conversation as resolved.
Show resolved Hide resolved
(x.replicate 1) = x.cast h := by
simp [replicate, h]

@[simp]
theorem replicate_succ {x : BitVec w} :
x.replicate (n + 1) =
(x ++ replicate n x).cast (by rw [Nat.mul_succ]; omega) := by
simp [replicate]

@[simp]
theorem getLsbD_replicate {n w : Nat} (x : BitVec w) :
theorem getLsbD_replicate {n w : Nat} {x : BitVec w} :
(x.replicate n).getLsbD i =
(decide (i < w * n) && x.getLsbD (i % w)) := by
induction n generalizing x
Expand All @@ -3420,17 +3425,17 @@ theorem getLsbD_replicate {n w : Nat} (x : BitVec w) :
· simp only [hi, decide_true, Bool.true_and]
by_cases hi' : i < w * n
· simp [hi', ih]
· simp [hi', decide_false]
rw [Nat.sub_mul_eq_mod_of_lt_of_le] <;> omega
· simp only [hi', ↓reduceIte]
rw [Nat.sub_mul_eq_mod_of_lt_of_le (by omega) (by omega)]
· rw [Nat.mul_succ] at hi ⊢
simp only [show ¬i < w * n by omega, decide_false, cond_false, hi, Bool.false_and]
apply BitVec.getLsbD_ge (x := x) (i := i - w * n) (ge := by omega)

@[simp]
theorem getElem_replicate {n w : Nat} (x : BitVec w) (h : i < w * n) :
theorem getElem_replicate {n w : Nat} {x : BitVec w} (h : i < w * n) :
(x.replicate n)[i] = if h' : w = 0 then false else x[i % w]'(@Nat.mod_lt i w (by omega)) := by
simp only [← getLsbD_eq_getElem, getLsbD_replicate]
by_cases h' : w = 0 <;> simp [h'] <;> omega
cases w <;> simp; omega

luisacicolini marked this conversation as resolved.
Show resolved Hide resolved
theorem append_assoc {x₁ : BitVec w₁} {x₂ : BitVec w₂} {x₃ : BitVec w₃} :
(x₁ ++ x₂) ++ x₃ = (x₁ ++ (x₂ ++ x₃)).cast (by omega) := by
Expand Down Expand Up @@ -3796,6 +3801,17 @@ theorem reverse_replicate {n : Nat} {x : BitVec w} :
conv => lhs; simp only [replicate_succ']
simp [reverse_append, ih]

@[simp]
theorem getMsbD_replicate {n w : Nat} {x : BitVec w} :
(x.replicate n).getMsbD i = (decide (i < w * n) && x.getMsbD (i % w)) := by
rw [← getLsbD_reverse, reverse_replicate, getLsbD_replicate, getLsbD_reverse]

@[simp]
theorem msb_replicate {n w : Nat} {x : BitVec w} :
(x.replicate n).msb = (decide (0 < n) && x.msb) := by
simp only [BitVec.msb, getMsbD_replicate, Nat.zero_mod]
cases n <;> cases w <;> simp

/-! ### Decidable quantifiers -/

theorem forall_zero_iff {P : BitVec 0 → Prop} :
Expand Down
Loading