Skip to content

feat: add msb_neg_of_msb_false, msb_neg_of_msb_true, msb_neg_umod_neg_of_msb_true_of_msb_true, msg_neg_neg_mod_neg #8376

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

Draft
wants to merge 77 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
2cb11fe
feat: statement
luisacicolini May 7, 2025
8ab06cf
chore:wip
luisacicolini May 7, 2025
2da1672
chore: first case
luisacicolini May 7, 2025
f69d8cc
chore: progress
luisacicolini May 7, 2025
6d30b11
chore: first case solved
luisacicolini May 7, 2025
193c0de
chore: couple smaller cases
luisacicolini May 7, 2025
e13c792
chore: wip
luisacicolini May 7, 2025
5469f7d
chore: useless theorem
luisacicolini May 7, 2025
df4a406
reduce the proof a bit
tobiasgrosser May 12, 2025
d3d84a0
chore: case three converts to emod
luisacicolini May 12, 2025
96206b6
chore: case three subcase one
luisacicolini May 12, 2025
1a637c4
chore: progress
luisacicolini May 13, 2025
54d2a2d
chore: wip
luisacicolini May 13, 2025
6e460eb
chore: wip
luisacicolini May 13, 2025
c057e06
chore: wip
luisacicolini May 13, 2025
6f809ed
chore: add proof structure
tobiasgrosser May 14, 2025
1572cae
Clarify where to apply the bmod
tobiasgrosser May 14, 2025
2f5b90b
chore: first split case
luisacicolini May 14, 2025
4ef5a02
template for last case
tobiasgrosser May 14, 2025
6081d20
chore: push
luisacicolini May 14, 2025
b46492e
chore: case 1/4
luisacicolini May 14, 2025
1d8da7f
chore: case 2/4
luisacicolini May 14, 2025
86bf9f2
chore: case 3/4
luisacicolini May 14, 2025
aa22067
build up umod_msb theory
tobiasgrosser May 14, 2025
f3d0b00
chore: completed case 3
luisacicolini May 14, 2025
d5b6eac
more cleanup
tobiasgrosser May 14, 2025
35a0576
chore: case 2, pt 1
luisacicolini May 14, 2025
ac4b4b4
another msb_neg statement
tobiasgrosser May 14, 2025
707748a
chore: case 2
luisacicolini May 14, 2025
2b39e65
chore: case 2
luisacicolini May 14, 2025
01e0194
minore cleanup
tobiasgrosser May 14, 2025
12e964e
chore: cases
luisacicolini May 14, 2025
3b75037
chore: wip
luisacicolini May 14, 2025
eb01253
chore: wip
luisacicolini May 14, 2025
a7bce4c
chore: undo delete
luisacicolini May 14, 2025
1b225f5
revert to previous proof state
tobiasgrosser May 14, 2025
3f95c7d
move things around
tobiasgrosser May 14, 2025
bc2c647
WIP
tobiasgrosser May 14, 2025
e287df3
expose both proof attempts
tobiasgrosser May 14, 2025
12fd26a
drop redundant cases
tobiasgrosser May 14, 2025
58906f4
factor out common things
tobiasgrosser May 14, 2025
374e7b9
chore: one case missing
luisacicolini May 14, 2025
0473630
chore: wip
luisacicolini May 14, 2025
6cf3063
chore: wip
luisacicolini May 14, 2025
cc0e9b1
chore: one less case
luisacicolini May 14, 2025
101ca51
chore: wip
luisacicolini May 14, 2025
75e989c
chore: proof
luisacicolini May 14, 2025
2796fa8
chore: format
luisacicolini May 14, 2025
35be4c4
chore: cleanup: 1/?
luisacicolini May 14, 2025
ac8154f
chore: cleanup 2/?, all those norm_casts...
luisacicolini May 14, 2025
a3bae6f
chore: cleanup 1 and 2
luisacicolini May 15, 2025
35ec0b5
chore: cleanup 3/?
luisacicolini May 15, 2025
a487d51
chore: more cleanup 4/?
luisacicolini May 15, 2025
818503c
chore: cleanup first case 5/?
luisacicolini May 15, 2025
92749e1
chore: more cleanup, 5/?
luisacicolini May 15, 2025
72ac9c0
chore: cleanup 6/?
luisacicolini May 15, 2025
5aca481
chore: cleanup 7/? main theorem
luisacicolini May 15, 2025
3f9727d
chore: cleanup 8/?
luisacicolini May 15, 2025
fa23385
chore: simp only
luisacicolini May 15, 2025
37f24bb
Merge branch 'leanprover:master' into toInt-smod
luisacicolini May 15, 2025
858aae9
chore: remove unused theorem
luisacicolini May 15, 2025
2e896b3
shorten the proof
tobiasgrosser May 16, 2025
d9f5d78
shorten the proof
tobiasgrosser May 16, 2025
b22b9a7
drop unused statements
tobiasgrosser May 16, 2025
e46ac9b
clean further
tobiasgrosser May 16, 2025
456bb3a
Format toInt_smod better
tobiasgrosser May 16, 2025
98b14c6
Shorten further
tobiasgrosser May 16, 2025
fd95519
Shorten further
tobiasgrosser May 16, 2025
8179228
related mod and dvd
tobiasgrosser May 16, 2025
2bb786a
shorten further
tobiasgrosser May 16, 2025
13caeee
drop an unnecessary case
tobiasgrosser May 16, 2025
7540e67
clean
tobiasgrosser May 16, 2025
a66acc1
clean
tobiasgrosser May 16, 2025
e131348
chore: comments and naming
luisacicolini May 16, 2025
65ad40f
chore: unused theorems
luisacicolini May 16, 2025
d8c1b85
chore: move theorems from previous pr
luisacicolini May 16, 2025
4bf3b8a
chore: more theorems
luisacicolini May 17, 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
54 changes: 54 additions & 0 deletions src/Init/Data/BitVec/Bitblast.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,60 @@ theorem toInt_srem (x y : BitVec w) : (x.srem y).toInt = x.toInt.tmod y.toInt :=
((not_congr neg_eq_zero_iff).mpr hyz)]
exact neg_le_intMin_of_msb_eq_true h'

@[simp]
theorem msb_neg_of_msb_false {x : BitVec w} (hx : x.msb = false) :
(-x).msb = decide (x ≠ 0) := by
by_cases hw : w = 0; subst hw; decide +revert
have wpos : 0 < w := by omega
simp only [msb_neg, hx, bne_false]
simp only [bool_to_prop]
simp [hx, wpos]

@[simp]
theorem msb_neg_of_msb_true {x : BitVec w} (hx : x.msb = true) :
(-x).msb = decide (x = intMin w) := by
simp only [msb_neg, hx, bne_true, Bool.not_and]
simp only [bool_to_prop]
simp [hx]

theorem msb_neg_umod_neg_of_msb_true_of_msb_true
{x y : BitVec w} (hx : x.msb = true) (hy : y.msb = true) :
(-x % -y).msb = (decide (x = intMin w) && decide (-x < -y)) := by
simp only [msb_umod, msb_neg_of_msb_true, hx]
simp only [bool_to_prop]
simp [hy]

theorem msg_neg_neg_mod_neg {x y : BitVec w} (hx : x.msb = true) (hy : y.msb = true) :
(-(-x % -y)).msb = (-x % -y != 0#w && -x % -y != intMin w ^^ decide (x = intMin w) &&
decide (-x < -y)) := by
by_cases hw : w = 0; subst hw; decide +revert
have wpos : 0 < w := by omega
simp only [msb_neg]
simp only [msb_neg_umod_neg_of_msb_true_of_msb_true hx hy]

@[simp]
theorem lt_of_msb_true_of_msb_false {x y : BitVec w} (hx : x.msb = false) (hy : y.msb = true) :
x < y := by
simp only [LT.lt]
simp
have := toNat_ge_of_msb_true hy
have := toNat_lt_of_msb_false hx
omega

theorem toInt_dvd_iff_of_msb_false_msb_false {x y : BitVec w} (hx : x.msb = false) (hy : y.msb = false) :
y.toInt ∣ x.toInt ↔ x % y = 0#w := by
have := toInt_dvd_toInt_iff (x := x) (y := y)
simp [hx, hy] at this
exact this


theorem toInt_dvd_iff_of_msb_true_msb_true {x y : BitVec w} (hx : x.msb = true) (hy : y.msb = true) :
y.toInt ∣ x.toInt ↔ (-x) % (-y) = 0#w:= by
have := toInt_dvd_toInt_iff (x := x) (y := y)
simp [hx, hy] at this
exact this


/-! ### Lemmas that use bit blasting circuits -/

theorem add_sub_comm {x y : BitVec w} : x + y - z = x - z + y := by
Expand Down
Loading