Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
feat: add simproc for optimizing constant multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX committed Jun 25, 2024
1 parent a9ebec3 commit 0f02d5c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LeanSAT/Reflect/Tactics/Normalize/BitVec.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import LeanSAT.Reflect.Tactics.Normalize.Canonicalize
namespace BVDecide
namespace Normalize

open Lean Meta

section Reduce

attribute [bv_normalize] BitVec.neg_eq_not_add
Expand Down Expand Up @@ -54,6 +56,18 @@ attribute [bv_normalize] BitVec.getLsb_concat_zero
attribute [bv_normalize] BitVec.mul_one
attribute [bv_normalize] BitVec.one_mul

/--
The bitblaster for multiplication introduces symbolic branches over the right hand side.
If we have an expression of the form `c * x` where `c` is constant we should change it to `x * c`
such that these symbolic branches get constant folded by the AIG framework.
-/
simproc [bv_normalize] mulConst ((_ : BitVec _) * (_ : BitVec _)) := fun e => do
let_expr HMul.hMul _ _ _ _ lhs rhs := e | return .continue
let some ⟨width, _⟩ ← Lean.Meta.getBitVecValue? lhs | return .continue
let new ← mkAppM ``HMul.hMul #[rhs, lhs]
let proof := mkApp3 (mkConst ``BitVec.mul_comm) (toExpr width) lhs rhs
return .done { expr := new, proof? := some proof }

end Constant

@[bv_normalize]
Expand Down

0 comments on commit 0f02d5c

Please sign in to comment.