Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
fa95a3e
local build fixed
luisacicolini Nov 17, 2025
491cd98
chore: wip
luisacicolini Nov 18, 2025
2b1b826
chore: popcount circuit
luisacicolini Nov 18, 2025
df19338
chore: tests
luisacicolini Nov 18, 2025
c01f209
chore: update header file
luisacicolini Nov 18, 2025
d1cfbb0
chore: wip
luisacicolini Nov 19, 2025
d0e3603
chore: wip proving pps on natlist
luisacicolini Nov 24, 2025
b14dce2
chore: popcount proof on nats
luisacicolini Nov 24, 2025
77562bf
chore: wip
luisacicolini Nov 25, 2025
b72bc62
chore: wip
luisacicolini Nov 26, 2025
08e7e41
chore: wip
luisacicolini Nov 27, 2025
ea03663
chore: case zero ind
luisacicolini Nov 27, 2025
602f9bb
chore: wip
luisacicolini Nov 27, 2025
679381e
chore: wip
luisacicolini Dec 2, 2025
277e7f3
chore: prove rec_add_eq_rec_add_iff
luisacicolini Dec 2, 2025
47828a2
chore: one to go
luisacicolini Dec 2, 2025
6e4a9ad
chore: locally builds
luisacicolini Dec 2, 2025
2bb1c5f
chore: local builds
luisacicolini Dec 2, 2025
e35e90d
chore: wip
luisacicolini Dec 2, 2025
b1cab23
chore: tailrec
luisacicolini Dec 3, 2025
22166ce
chore: wip
luisacicolini Dec 3, 2025
6337acf
chore: wip
luisacicolini Dec 3, 2025
4f94eaf
chore: sorry free circuit impl
luisacicolini Dec 3, 2025
aaae317
chore: proof
luisacicolini Dec 3, 2025
a69cbc4
chore: wip
luisacicolini Dec 3, 2025
ce08385
chore: correct circuit
luisacicolini Dec 3, 2025
a89ea13
chore: wip
luisacicolini Dec 4, 2025
b252670
chroe: wip
luisacicolini Dec 5, 2025
09c76d3
chore: prove denote_blastcpop
luisacicolini Dec 5, 2025
44ff6c2
chore: denotation proved. ugly but proved
luisacicolini Dec 7, 2025
20b2161
chore: the theorem was useless lol
luisacicolini Dec 7, 2025
63eedb3
chore: wip
luisacicolini Dec 8, 2025
0aaf47a
chore: wip
luisacicolini Dec 8, 2025
66e0d7d
chore: done.
luisacicolini Dec 8, 2025
ea2bfd4
chore; fix expr sorry
luisacicolini Dec 8, 2025
6869fd4
chore: polish simp
luisacicolini Dec 8, 2025
dfa139c
chore: fix unused hp
luisacicolini Dec 8, 2025
4f521bb
chore: fix tetst
luisacicolini Dec 8, 2025
0fa2663
chore: remove old defs
luisacicolini Dec 18, 2025
2d87358
chore: add back def
luisacicolini Dec 18, 2025
79fbeb4
chore: polish after rebasing
luisacicolini Dec 18, 2025
8e43f11
chore: cleanup
luisacicolini Dec 18, 2025
1856001
chore: remove sorrys;
luisacicolini Dec 18, 2025
984d05a
chore: remove redundant hp
luisacicolini Dec 18, 2025
818d4ba
chore: unused files
luisacicolini Dec 18, 2025
6732e65
chore: simplify post merging
luisacicolini Dec 19, 2025
a7de084
chore: remove subtype from eep
luisacicolini Jan 9, 2026
63e2ede
chore: extractandextendepopulateaux was cleaned
luisacicolini Jan 9, 2026
a1a4bac
chore: pps_layer subtyped and proved
luisacicolini Jan 9, 2026
0d11b99
chore: pps_layer rid of subtype
luisacicolini Jan 9, 2026
1f0b9a8
chore: removed subtype from pps
luisacicolini Jan 9, 2026
332c9c8
chore: cleaned and locally builds
luisacicolini Jan 9, 2026
30b31cc
chore: remove unused lemmas
luisacicolini Jan 9, 2026
921f8d5
chore: make things cuter
luisacicolini Jan 11, 2026
60d8976
chore: make things cuter
luisacicolini Jan 11, 2026
5ffe6ff
chore: naming and polishing
luisacicolini Jan 11, 2026
012e49c
chore: meh.
luisacicolini Jan 11, 2026
d65584e
chore: locally builds
luisacicolini Jan 12, 2026
d4a07b5
chore: instance is broken
luisacicolini Jan 12, 2026
6dfc513
chore: prove lawfulness
luisacicolini Jan 13, 2026
fe85697
chore: for unclear reasons this works
luisacicolini Jan 13, 2026
9bc060b
chore: circuit impl is sorry free
luisacicolini Jan 13, 2026
fd3a7bc
chore: flattenedAdd proof strategy draft
luisacicolini Jan 13, 2026
bbe5ca6
chore: fill all sorry in bitblast
luisacicolini Jan 13, 2026
7e55ede
chore: denote thm statements
luisacicolini Jan 13, 2026
8466bc0
chore: wip denotation proofs
luisacicolini Jan 13, 2026
7ee8116
chore: two cuties
luisacicolini Jan 14, 2026
981218e
chore: it works
luisacicolini Jan 14, 2026
13cfd91
chore: sorry free
luisacicolini Jan 14, 2026
ee8e94c
chore: remove eep lemmas
luisacicolini Jan 14, 2026
fdb2ac0
chore: hooked into bvdec
luisacicolini Jan 14, 2026
41080da
chore: finish hook
luisacicolini Jan 14, 2026
5542c70
chore: update name
luisacicolini Jan 14, 2026
1f972f5
chore: started refactoring
luisacicolini Jan 14, 2026
73d9b58
chore: cleanup
luisacicolini Jan 15, 2026
d116ec4
chore: wip
luisacicolini Jan 15, 2026
2bbb2b5
chore: just works
luisacicolini Jan 16, 2026
c7dcf52
chore: clean
luisacicolini Jan 16, 2026
1b347d7
chore: locally builds % sorry
luisacicolini Jan 20, 2026
ce3a2fc
chore: append proof
luisacicolini Jan 20, 2026
ee5a380
chore: unrelated change
luisacicolini Jan 20, 2026
abeca81
chore: space
luisacicolini Jan 22, 2026
96a818b
chore: better name
luisacicolini Feb 5, 2026
fbc3b9e
chore: some polishing
luisacicolini Feb 5, 2026
9481961
chore: significantly easier lemmas
luisacicolini Feb 6, 2026
6b3399e
chore: one more proof
luisacicolini Feb 6, 2026
ad566b6
chore: things
luisacicolini Feb 6, 2026
b019e83
chore
luisacicolini Feb 9, 2026
9658c32
chore
luisacicolini Feb 9, 2026
d669cb9
chore:
luisacicolini Feb 9, 2026
97209c5
chore:
luisacicolini Feb 9, 2026
fedc103
chore
luisacicolini Feb 9, 2026
aa37827
chore: unnec changes
luisacicolini Feb 9, 2026
4e28a2a
chore: wip;
luisacicolini Feb 10, 2026
c825103
chore: works
luisacicolini Feb 10, 2026
a717fcf
chore: finish circuit
luisacicolini Feb 10, 2026
13c141b
chore: local build
luisacicolini Feb 10, 2026
a58ffff
chore:
luisacicolini Feb 10, 2026
033a43d
chore: cleanup
luisacicolini Feb 10, 2026
8caa686
chore: bblast sorry free
luisacicolini Feb 10, 2026
1d0e78e
chore: all sorry free
luisacicolini Feb 10, 2026
cdc8dfe
chore: builds
luisacicolini Feb 11, 2026
3229aac
chore: you cant be for real
luisacicolini Feb 11, 2026
133b4bf
chore: polishing
luisacicolini Feb 11, 2026
953219e
chore: clean.
luisacicolini Feb 11, 2026
a3a6c40
chore: nit
luisacicolini Feb 11, 2026
57b63fc
chore: newlines
luisacicolini Feb 11, 2026
79913d1
chore: newlines
luisacicolini Feb 11, 2026
82659c2
chore: newlines
luisacicolini Feb 11, 2026
cdaa037
Apply suggestion from @luisacicolini
luisacicolini Feb 11, 2026
08ab4f4
Apply suggestion from @luisacicolini
luisacicolini Feb 11, 2026
bc4704f
chore: docstr
luisacicolini Feb 11, 2026
707890e
chore: test
luisacicolini Feb 11, 2026
b7adf43
chore: fix build
luisacicolini Feb 11, 2026
eec10e3
chore: comment
luisacicolini Feb 12, 2026
88dad09
chore: fix proof
luisacicolini Feb 13, 2026
9c8305d
chore: make thm private
luisacicolini Feb 13, 2026
a3c85fc
Apply suggestion from @luisacicolini
luisacicolini Feb 13, 2026
148b820
chore: fix test
luisacicolini Feb 13, 2026
cafb05f
chore: merge and address comments
luisacicolini Feb 13, 2026
440b5cb
chore: fix build
luisacicolini Feb 13, 2026
cd9ee04
chore: cleanup
luisacicolini Feb 13, 2026
b6716e9
chore: whitespace
luisacicolini Feb 13, 2026
0a2de90
chore: more cleanup
luisacicolini Feb 13, 2026
54d5ac5
chore: polish
luisacicolini Feb 17, 2026
8782d60
chore: cleanup finished
luisacicolini Feb 17, 2026
021a94e
chore: cleared proof
luisacicolini Feb 17, 2026
f6ef575
chore: mini nit and simp nonterm
luisacicolini Feb 18, 2026
b22085b
chore: mini nit and simp nonterm
luisacicolini Feb 18, 2026
df8b0c7
chore: cleanup
luisacicolini Feb 18, 2026
cf88a8f
chore: comments
luisacicolini Feb 18, 2026
a6fe2cf
chore: fix
luisacicolini Feb 18, 2026
01150c9
chore: wip
luisacicolini Feb 18, 2026
aec6cdd
chore: wip
luisacicolini Feb 18, 2026
2aa15e5
chore: fix
luisacicolini Feb 18, 2026
4eb4493
chore: fix
luisacicolini Feb 18, 2026
2c177a4
chore: fix
luisacicolini Feb 18, 2026
a3617df
chore: credit of this massive thing
luisacicolini Feb 19, 2026
c245b8f
chore: remove snakrcase
luisacicolini Feb 20, 2026
04babb2
chore: remove snakrcase
luisacicolini Feb 20, 2026
3e321f7
chore: remove snakrcase
luisacicolini Feb 20, 2026
77ce7ec
chore: remove snakrcase
luisacicolini Feb 20, 2026
787ec5d
chore: remove snakrcase
luisacicolini Feb 20, 2026
5c2a096
chore: remove snakrcase
luisacicolini Feb 20, 2026
bff0d8a
chore: fix indentation
luisacicolini Feb 20, 2026
f6a8a61
chore: fix var names
luisacicolini Feb 20, 2026
15ac642
chore: fix return type in cpopTree
luisacicolini Feb 20, 2026
27241ac
chore: simp nf in getLsbD_extractAndExtendBit
luisacicolini Feb 20, 2026
875b638
chore: simp nf in getLsbD_extractAndExtendBit
luisacicolini Feb 20, 2026
0cb426d
chore: 100c lim
luisacicolini Feb 20, 2026
e9640e0
chore: 100c lim
luisacicolini Feb 20, 2026
680dd30
chore: replace explicit hp w imp whenever possible
luisacicolini Feb 20, 2026
7f6e162
chore: simpnf in getLsbD_extractAndExtend
luisacicolini Feb 20, 2026
037991a
chore: remove simp tag from append_of_zero_width
luisacicolini Feb 20, 2026
bd4069a
chore: typo
luisacicolini Feb 20, 2026
3fca896
chore: whitespaces
luisacicolini Feb 20, 2026
545dcf5
chore: ite indentation
luisacicolini Feb 20, 2026
bdff514
chore: ite indentation
luisacicolini Feb 20, 2026
5a9b534
chore: modules
luisacicolini Feb 20, 2026
94a3ddd
Merge branch 'master' into popcount-clean-frfr
luisacicolini Feb 20, 2026
705372f
chore: fix merge
luisacicolini Feb 20, 2026
2d94898
Merge remote-tracking branch 'origin' into popcount-clean-frfr
luisacicolini Feb 25, 2026
8c5bebf
Merge remote-tracking branch 'origin' into popcount-clean-frfr
luisacicolini Feb 26, 2026
db7cbb2
chore: test
luisacicolini Feb 26, 2026
f27cdc1
chore: expected changes
luisacicolini Feb 26, 2026
c34fc49
chore: parenthesis
luisacicolini Feb 27, 2026
ed8da7c
chore: remove aig2
luisacicolini Feb 27, 2026
f135247
chore: address remainign comments
luisacicolini Feb 27, 2026
c965fcc
chore: copyrights
luisacicolini Feb 27, 2026
3ebcbde
chore: names
luisacicolini Feb 27, 2026
24627c1
chore: use go and instances
luisacicolini Feb 28, 2026
c573919
chore: comments
luisacicolini Feb 28, 2026
29b3697
chore: polish
luisacicolini Mar 2, 2026
0b68150
Apply suggestion from @hargoniX
hargoniX Mar 2, 2026
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
405 changes: 405 additions & 0 deletions src/Init/Data/BitVec/Bitblast.lean

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/Init/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,14 @@ theorem msb_append {x : BitVec w} {y : BitVec v} :
rw [getElem_append] -- Why does this not work with `simp [getElem_append]`?
simp

theorem append_of_zero_width (x : BitVec w) (y : BitVec v) (h : w = 0) :
(x ++ y) = y.cast (by simp [h]) := by
ext i ih
subst h
simp [← getLsbD_eq_getElem, getLsbD_append]
omega

set_option backward.isDefEq.respectTransparency false in
@[grind =]
theorem toInt_append {x : BitVec n} {y : BitVec m} :
(x ++ y).toInt = if n == 0 then y.toInt else (2 ^ m) * x.toInt + y.toNat := by
Expand Down Expand Up @@ -3012,6 +3020,34 @@ theorem extractLsb'_append_extractLsb'_eq_extractLsb' {x : BitVec w} (h : start
congr 1
omega

theorem append_extractLsb'_of_lt {x : BitVec (x_len * w)} :
(x.extractLsb' ((x_len - 1) * w) w ++ x.extractLsb' 0 ((x_len - 1) * w)).cast hcast = x := by
ext i hi
simp only [getElem_cast, getElem_append, getElem_extractLsb', Nat.zero_add, dite_eq_ite]
rw [← getLsbD_eq_getElem, ite_eq_left_iff, Nat.not_lt]
intros
simp only [show (x_len - 1) * w + (i - (x_len - 1) * w) = i by omega]


theorem extractLsb'_append_of_lt {x : BitVec (k * w)} {y : BitVec w} (hlt : i < k) :
extractLsb' (i * w) w (y ++ x) = extractLsb' (i * w) w x := by
ext j hj
simp only [← getLsbD_eq_getElem, getLsbD_extractLsb', hj, decide_true, getLsbD_append,
Bool.true_and, ite_eq_left_iff, Nat.not_lt]
intros h
by_cases hw0 : w = 0
· subst hw0
simp
· have : i * w ≤ (k - 1) * w := Nat.mul_le_mul_right w (by omega)
have h' : i * w + j < (k - 1 + 1) * w := by simp [Nat.add_mul]; omega
rw [Nat.sub_one_add_one (by omega)] at h'
omega

theorem extractLsb'_append_of_eq {x : BitVec (k * w)} {y : BitVec w} (heq : i = k) :
extractLsb' (i * w) w (y ++ x) = y := by
ext j hj
simp [← getLsbD_eq_getElem, getLsbD_append, hj, heq]

/-- Combine adjacent `~~~ (extractLsb _)'` operations into a single `~~~ (extractLsb _)'`. -/
theorem not_extractLsb'_append_not_extractLsb'_eq_not_extractLsb' {x : BitVec w} (h : start₂ = start₁ + len₁) :
(~~~ (x.extractLsb' start₂ len₂) ++ ~~~ (x.extractLsb' start₁ len₁)) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ instance : ToExpr BVUnOp where
| .arithShiftRightConst n => mkApp (mkConst ``BVUnOp.arithShiftRightConst) (toExpr n)
| .reverse => mkConst ``BVUnOp.reverse
| .clz => mkConst ``BVUnOp.clz
| .cpop => mkConst ``BVUnOp.cpop
toTypeExpr := mkConst ``BVUnOp

instance : ToExpr (BVExpr w) where
Expand Down
2 changes: 2 additions & 0 deletions src/Lean/Elab/Tactic/BVDecide/Frontend/BVDecide/Reify.lean
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ where
unaryReflection innerExpr .reverse ``Std.Tactic.BVDecide.Reflect.BitVec.reverse_congr origExpr
| BitVec.clz _ innerExpr =>
unaryReflection innerExpr .clz ``Std.Tactic.BVDecide.Reflect.BitVec.clz_congr origExpr
| BitVec.cpop _ innerExpr =>
unaryReflection innerExpr .cpop ``Std.Tactic.BVDecide.Reflect.BitVec.cpop_congr origExpr
| _ => return none

/--
Expand Down
2 changes: 2 additions & 0 deletions src/Lean/Meta/Tactic/Simp/BuiltinSimprocs/BitVec.lean
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ builtin_dsimproc [simp, seval] reduceGetLsb (getLsbD _ _) := reduceGetBit ``getL
builtin_dsimproc [simp, seval] reduceGetMsb (getMsbD _ _) := reduceGetBit ``getMsbD getMsbD
/-- Simplification procedure for `clz` (count leading zeros) on `BitVec`. -/
builtin_dsimproc [simp, seval] reduceClz (clz _) := reduceUnary ``BitVec.clz 2 BitVec.clz
/-- Simplification procedure for `cpop` (population count) on `BitVec`. -/
builtin_dsimproc [simp, seval] reduceCpop (cpop _) := reduceUnary ``BitVec.cpop 2 BitVec.cpop

/-- Simplification procedure for `getElem` on `BitVec`. -/
builtin_dsimproc [simp, seval] reduceGetElem ((_ : BitVec _)[_]) := fun e => do
Expand Down
8 changes: 8 additions & 0 deletions src/Std/Tactic/BVDecide/Bitblast/BVExpr/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ inductive BVUnOp where
Count leading zeros.
-/
| clz
/--
Population count.
-/
| cpop
deriving Hashable, DecidableEq

namespace BVUnOp
Expand All @@ -160,6 +164,7 @@ def toString : BVUnOp → String
| arithShiftRightConst n => s!">>a {n}"
| reverse => "rev"
| clz => "clz"
| cpop => "cpop"

instance : ToString BVUnOp := ⟨toString⟩

Expand All @@ -173,6 +178,7 @@ def eval : BVUnOp → (BitVec w → BitVec w)
| arithShiftRightConst n => (BitVec.sshiftRight · n)
| reverse => BitVec.reverse
| clz => BitVec.clz
| cpop => BitVec.cpop

@[simp] theorem eval_not : eval .not = ((~~~ ·) : BitVec w → BitVec w) := by rfl

Expand All @@ -192,6 +198,8 @@ theorem eval_arithShiftRightConst : eval (arithShiftRightConst n) = (BitVec.sshi

@[simp] theorem eval_clz : eval .clz = (BitVec.clz : BitVec w → BitVec w) := by rfl

@[simp] theorem eval_cpop : eval .cpop = (BitVec.cpop : BitVec w → BitVec w) := by rfl

end BVUnOp

/--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Mul
public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Umod
public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Reverse
public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Clz
public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Cpop
import Init.Data.Nat.Linear
import Init.Omega

Expand Down Expand Up @@ -232,6 +233,12 @@ where
apply AIG.LawfulVecOperator.le_size_of_le_aig_size (f := bitblast.blastClz)
omega
⟨⟨res, this⟩, cache.cast (AIG.LawfulVecOperator.le_size (f := bitblast.blastClz) ..)⟩
| .cpop =>
let res := bitblast.blastCpop eaig evec
have := by
apply AIG.LawfulVecOperator.le_size_of_le_aig_size (f := bitblast.blastCpop)
omega
⟨⟨res, this⟩, cache.cast (AIG.LawfulVecOperator.le_size (f := bitblast.blastCpop) ..)⟩
| .append lhs rhs h =>
let ⟨⟨⟨aig, lhs⟩, hlaig⟩, cache⟩ := goCache aig lhs cache
let ⟨⟨⟨aig, rhs⟩, hraig⟩, cache⟩ := goCache aig rhs cache
Expand Down Expand Up @@ -343,7 +350,7 @@ theorem go_decl_eq (aig : AIG BVBit) (expr : BVExpr w) (cache : Cache aig) :
· apply Nat.le_trans <;> assumption
next op expr =>
match op with
| .not | .rotateLeft .. | .rotateRight .. | .arithShiftRightConst .. | .reverse | .clz =>
| .not | .rotateLeft .. | .rotateRight .. | .arithShiftRightConst .. | .reverse | .clz | .cpop =>
rw [AIG.LawfulVecOperator.decl_eq]
rw [goCache_decl_eq]
have := (goCache aig expr cache).result.property
Expand Down
Loading
Loading