-
Notifications
You must be signed in to change notification settings - Fork 717
feat: add leading zero counter BitVec.clz and bitblaster circuit/infrastructure
#8546
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
Merged
Merged
Changes from 107 commits
Commits
Show all changes
119 commits
Select commit
Hold shift + click to select a range
3e203f5
feat: theorems and defs
luisacicolini 763aa17
chore: a very broken .. something?
luisacicolini 0aa3594
chore: clz now lives within bitvecs, started polishing and rewriting …
luisacicolini 906ef10
chore: empty necessary files
luisacicolini ecdfb4f
chore: made theorems bitvec friendly
luisacicolini 9ace742
chore: first cleanup of simp onlys and some redundant hypotheses
luisacicolini 1035358
chore: first cleanup of simp onlys and some redundant hypotheses
luisacicolini c95b030
chore: populate bb files
luisacicolini 3e5da60
chore: builds locally modulo sorries
luisacicolini 0c00d5d
chore: wip
luisacicolini f212c0c
chore: wip
luisacicolini 0a69de0
chore: wip
luisacicolini 122b1c1
chore: first branch
luisacicolini ada14eb
chore: wip
luisacicolini 32f4a8e
chore: proof
luisacicolini 762bbaf
chore: a few sorry left
luisacicolini 9baccde
chore: wip
luisacicolini b31f356
chore: lookup
luisacicolini f52a9d0
chore: fix
luisacicolini 4b4bcfd
chore: wip
luisacicolini 607d8bd
chore: wip
luisacicolini 713ab35
chore: circuit
luisacicolini dfe04b4
chore: fix
luisacicolini e68b210
chore: wip
luisacicolini c353a68
chore: builds
luisacicolini 8adc1f7
chore: prove clzAuxRec_eq_iff
luisacicolini e3f0f0b
chore: prove clzAuxRec_le
luisacicolini 4624eec
chore: full of sorrys but almost complete
luisacicolini 59080fb
chore: clzAuxRec_succ_eq, clzAuxRec_zero_eq
luisacicolini 92298c8
chore: case 1/3 of double induction
luisacicolini 9f215ec
chroe: more stuff
luisacicolini f2101bb
chore: prove clzAuxRec_of_clzAux
luisacicolini fed118d
chore: prove correctness of clzRec def
luisacicolini 24b4155
chore: getLsbD_clzAuxRec
luisacicolini f62d954
chore: more stuff
luisacicolini 9118ca8
chore: prove go_zero_denote_eq
luisacicolini 1ddef92
chore: correct circuit
luisacicolini fa31ffd
chore: wip
luisacicolini 7d78371
chore: wip
luisacicolini e672697
chore: wip
luisacicolini dce3b2d
chore: I need to merge master
luisacicolini 2870e19
chore: clzAuxRec_eq_of_le
luisacicolini 1056e43
chore: one proof left
luisacicolini 419de01
chore: wip;
luisacicolini af2691d
chore: wip
luisacicolini 14cebf1
chore: only constants denotation is missing
luisacicolini 92f5210
chore: proved.
luisacicolini bfcd658
chore: almost there
luisacicolini 273ed67
chore: remove all sorrys
luisacicolini 573e422
chore: examples
luisacicolini 458843d
chore: examples
luisacicolini 83b6a40
chore: polish clz_eq_clzAuxRec_of_false
luisacicolini c9fdf4a
chore: polish clzAux_eq_iff_forall_of_clzAux_lt
luisacicolini 6478e12
chore: fix build
luisacicolini 3102e4d
chore: replace unfold with simp
luisacicolini 6804a58
chore: polish
luisacicolini 7bccae0
chore: polish
luisacicolini 8834dfc
chore: unwanted changes
luisacicolini 4228ed2
chore: fix
luisacicolini fa1684c
chore: comment
luisacicolini a5b7f02
chore: update name
luisacicolini 0197710
chore: correction
luisacicolini ea4cfe7
chore: space
luisacicolini c2c7507
chore: naming
luisacicolini 859796d
chore: whitespaces
luisacicolini c29309b
chore: docstring
luisacicolini 39743a1
chore: docs
luisacicolini 119bf45
chore: docs
luisacicolini ab05ace
chore: docstring
luisacicolini 75a0d1e
chore: de-line
luisacicolini 4345e47
chore: accept comment
luisacicolini c5de4ff
chore: accept
luisacicolini e74b7b7
chore: comment
luisacicolini ca38b4d
chore: docstring
luisacicolini 87373e3
chore: docstring
luisacicolini 289fede
chore: docstring
luisacicolini 3d7dbe2
chore: docstring
luisacicolini e538eb6
chore: fix
luisacicolini 40b15c2
chore: comment
luisacicolini 64b33b0
chore: doc
luisacicolini a24a504
chore: fix reduceite
luisacicolini e8a1c56
chore: redundant thm
luisacicolini d41f1ce
chore: nonterm simp
luisacicolini 0d13f9c
chore: nonterm simp
luisacicolini 221460a
chore: redundant name
luisacicolini 4570e26
chore: space
luisacicolini bf60b99
chore: arrow
luisacicolini 6e4d997
chore: arrow
luisacicolini 2ea4865
chore: arrow
luisacicolini 7023af4
chore: arrow
luisacicolini cb88897
chore: arrow
luisacicolini 1af48fb
chore: colf
luisacicolini d538b37
chore: golf
luisacicolini 9f2e855
chore: golf
luisacicolini ecc9065
chore: golf
luisacicolini eeaeea1
chore: golf
luisacicolini f1439cf
chore: final golf
luisacicolini fc426b4
Merge commit '46c3eaece9b8feee3f14cc5b8d9aaab66d091c63' into clz
luisacicolini 6cd5405
Merge commit 'ba39fd3ca85d9aa45958e0b1f0b549687e90dde3' into clz
luisacicolini cf9f927
Merge commit '548cc4e5552e786086e0b6e38dff4ef8bdb1bb53' into clz
luisacicolini d4b3c55
Merge remote-tracking branch 'origin' into clz
luisacicolini 41aa493
chore: fix build
luisacicolini 0743518
chore: redundant parentheses
luisacicolini f09246b
chore: comments
luisacicolini fc5ca89
Merge branch 'clz' of github.com:opencompl/lean4 into clz
luisacicolini adf1493
chore: spurious from mergine
luisacicolini 8be5f11
chore: spurious from merging
luisacicolini 05f738a
chore: spurious from merging
luisacicolini c1959af
feat: tailrec def
luisacicolini f46ade5
chore: builds now
luisacicolini 35e5354
chore: sorry-free
luisacicolini 22785f4
chore: address comment
luisacicolini 56dda91
chore: add BitVec.ofNat_sub_ofNat_of_le
luisacicolini 97b2c1a
chore: seval
luisacicolini 9e9aa2a
chore: alternative proof
luisacicolini 1137dcc
chore: aux lemmas
luisacicolini 663e550
chore: golf
luisacicolini 7149389
chore: golf proof
luisacicolini e0e7634
chore: whitespace
luisacicolini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Clz.lean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /- | ||
| Copyright (c) 2025 Lean FRO, LLC. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Luisa Cicolini, Siddharth Bhat, Henrik Böving | ||
| -/ | ||
| prelude | ||
| import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Const | ||
| import Std.Sat.AIG.If | ||
|
|
||
| /-! | ||
| This module contains the implementation of a bitblaster for `BitVec.clz`. | ||
| -/ | ||
|
|
||
| namespace Std.Tactic.BVDecide | ||
|
|
||
| open Std.Sat | ||
|
|
||
| variable [Hashable α] [DecidableEq α] | ||
|
|
||
| namespace BVExpr | ||
| namespace bitblast | ||
|
|
||
| def blastClz (aig : AIG α) (x : AIG.RefVec aig w) : | ||
| AIG.RefVecEntry α w := | ||
| let wconst := blastConst aig w | ||
| go aig x 0 wconst | ||
| where | ||
| go (aig : AIG α) (x : AIG.RefVec aig w) (curr : Nat) (acc : AIG.RefVec aig w) := | ||
| if hc : curr < w then | ||
| let lhs := blastConst aig (w := w) (w - 1 - curr) | ||
| let res := AIG.RefVec.ite aig ⟨x.get curr hc, lhs, acc⟩ | ||
| let aig := res.aig | ||
| let acc := res.vec | ||
| have := by apply AIG.LawfulVecOperator.le_size (f := AIG.RefVec.ite) | ||
luisacicolini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let x : AIG.RefVec aig w := x.cast this | ||
| go aig x (curr + 1) acc | ||
| else | ||
| ⟨aig, acc⟩ | ||
| termination_by w - curr | ||
|
|
||
| namespace blastClz | ||
|
|
||
| end blastClz | ||
|
|
||
| theorem blastClz.go_le_size (aig : AIG α) (curr : Nat) (acc : AIG.RefVec aig w) | ||
| (xc : AIG.RefVec aig w) : | ||
| aig.decls.size ≤ (go aig xc curr acc).aig.decls.size := by | ||
| unfold go | ||
| dsimp only | ||
| split | ||
| · refine Nat.le_trans ?_ (by apply go_le_size) | ||
| apply AIG.LawfulVecOperator.le_size (f := AIG.RefVec.ite) | ||
| · simp | ||
| termination_by w - curr | ||
|
|
||
| theorem blastClz.go_decl_eq (aig : AIG α) (curr : Nat) (acc : AIG.RefVec aig w) | ||
| (xc : AIG.RefVec aig w) : | ||
| ∀ (idx : Nat) h1 h2, | ||
| (go aig xc curr acc).aig.decls[idx]'h1 = aig.decls[idx]'h2 := by | ||
| generalize hgo : go aig xc curr acc = res | ||
| unfold go at hgo | ||
| dsimp only at hgo | ||
| split at hgo | ||
| · rw [← hgo] | ||
| intros | ||
| rw [blastClz.go_decl_eq, AIG.LawfulVecOperator.decl_eq (f := AIG.RefVec.ite)] | ||
| apply AIG.LawfulVecOperator.lt_size_of_lt_aig_size (f := AIG.RefVec.ite) | ||
| assumption | ||
| · simp [← hgo] | ||
| termination_by w - curr | ||
|
|
||
| instance : AIG.LawfulVecOperator α AIG.RefVec blastClz where | ||
| le_size := by | ||
| intros | ||
| unfold blastClz | ||
| dsimp only | ||
| apply blastClz.go_le_size | ||
| decl_eq := by | ||
| intros | ||
| unfold blastClz | ||
| dsimp only | ||
| apply blastClz.go_decl_eq | ||
|
|
||
| end bitblast | ||
| end BVExpr | ||
|
|
||
| end Std.Tactic.BVDecide | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.