14.5.5.10.1. Bit Blasting
The standard library contains a number of helper implementations that are useful to implement bit blasting, which is the technique used by bv_decide
to encode propositions as Boolean satisfiability problems for external solvers.
🔗defBitVec.adcb (x y c : Bool) : Bool × Bool
Carry function for bitwise addition.
🔗defBitVec.carry {w : Nat} (i : Nat)
(x y : BitVec w) (c : Bool) : Bool
carry i x y c returns true if the i
carry bit is true when computing x + y + c
.
🔗defBitVec.mulRec {w : Nat} (x y : BitVec w)
(s : Nat) : BitVec w
A recurrence that describes multiplication as repeated addition.
Is useful for bitblasting multiplication.
🔗defBitVec.divRec {w : Nat} (m : Nat)
(args : BitVec.DivModArgs w)
(qr : BitVec.DivModState w) :
BitVec.DivModState w
A recursive definition of division for bitblasting, in terms of a shift-subtraction circuit.
🔗defBitVec.divSubtractShift {w : Nat}
(args : BitVec.DivModArgs w)
(qr : BitVec.DivModState w) :
BitVec.DivModState w
One round of the division algorithm, that tries to perform a subtract shift.
Note that this should only be called when r.msb = false
, so we will not overflow.
🔗defBitVec.shiftLeftRec {w₁ w₂ : Nat}
(x : BitVec w₁) (y : BitVec w₂) (n : Nat) :
BitVec w₁
shiftLeftRec x y n
shifts x
to the left by the first n
bits of y
.
The theorem shiftLeft_eq_shiftLeftRec
proves the equivalence of (x <<< y)
and shiftLeftRec
.
Together with equations shiftLeftRec_zero
, shiftLeftRec_succ
,
this allows us to unfold shiftLeft
into a circuit for bitblasting.
🔗defBitVec.sshiftRightRec {w₁ w₂ : Nat}
(x : BitVec w₁) (y : BitVec w₂) (n : Nat) :
BitVec w₁
sshiftRightRec x y n
shifts x
arithmetically/signed to the right by the first n
bits of y
.
The theorem sshiftRight_eq_sshiftRightRec
proves the equivalence of (x.sshiftRight y)
and sshiftRightRec
.
Together with equations sshiftRightRec_zero
, sshiftRightRec_succ
,
this allows us to unfold sshiftRight
into a circuit for bitblasting.
🔗defBitVec.ushiftRightRec {w₁ w₂ : Nat}
(x : BitVec w₁) (y : BitVec w₂) (n : Nat) :
BitVec w₁
ushiftRightRec x y n
shifts x
logically to the right by the first n
bits of y
.
The theorem shiftRight_eq_ushiftRightRec
proves the equivalence
of (x >>> y)
and ushiftRightRec
.
Together with equations ushiftRightRec_zero
, ushiftRightRec_succ
,
this allows us to unfold ushiftRight
into a circuit for bitblasting.
14.5.5.10.3. Simprocs
🔗defBitVec.reduceAbs : Lean.Meta.Simp.DSimproc
Simplification procedure for absolute value of BitVec
s.
🔗defBitVec.reduceAdd : Lean.Meta.Simp.DSimproc
Simplification procedure for addition of BitVec
s.
🔗defBitVec.reduceAllOnes : Lean.Meta.Simp.DSimproc
Simplification procedure for allOnes
🔗defBitVec.reduceAnd : Lean.Meta.Simp.DSimproc
Simplification procedure for bitwise and of BitVec
s.
🔗defBitVec.reduceAppend : Lean.Meta.Simp.DSimproc
Simplification procedure for append on BitVec
.
🔗defBitVec.reduceBEq : Lean.Meta.Simp.DSimproc
Simplification procedure for ==
on BitVec
s.
🔗defBitVec.reduceBNe : Lean.Meta.Simp.DSimproc
Simplification procedure for !=
on BitVec
s.
🔗defBitVec.reduceBin (declName : Lean.Name)
(arity : Nat)
(op :
{n : Nat} → BitVec n → BitVec n → BitVec n)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.DStep
Helper function for reducing homogeneous binary bitvector operators.
🔗defBitVec.reduceBinPred (declName : Lean.Name)
(arity : Nat)
(op : {n : Nat} → BitVec n → BitVec n → Bool)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.Step
Helper function for reducing bitvector predicates.
🔗defBitVec.reduceBitVecOfFin :
Lean.Meta.Simp.DSimproc
🔗defBitVec.reduceBitVecToFin :
Lean.Meta.Simp.DSimproc
🔗defBitVec.reduceBoolPred (declName : Lean.Name)
(arity : Nat)
(op : {n : Nat} → BitVec n → BitVec n → Bool)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.DStep
🔗defBitVec.reduceCast : Lean.Meta.Simp.DSimproc
Simplification procedure for casting BitVec
s along an equality of the size.
🔗defBitVec.reduceDiv : Lean.Meta.Simp.DSimproc
Simplification procedure for division of BitVec
s.
🔗defBitVec.reduceEq : Lean.Meta.Simp.Simproc
Simplification procedure for =
on BitVec
s.
🔗defBitVec.reduceExtend (declName : Lean.Name)
(op :
{n : Nat} → (m : Nat) → BitVec n → BitVec m)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.DStep
Simplification procedure for setWidth
, zeroExtend
and signExtend
on BitVec
s.
🔗defBitVec.reduceGE : Lean.Meta.Simp.Simproc
Simplification procedure for ≥
on BitVec
s.
🔗defBitVec.reduceGT : Lean.Meta.Simp.Simproc
Simplification procedure for >
on BitVec
s.
🔗defBitVec.reduceGetBit (declName : Lean.Name)
(op : {n : Nat} → BitVec n → Nat → Bool)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.DStep
Helper function for reducing bitvector functions such as getLsb
and getMsb
.
🔗defBitVec.reduceGetElem : Lean.Meta.Simp.DSimproc
Simplification procedure for getElem
on BitVec
.
🔗defBitVec.reduceGetLsb : Lean.Meta.Simp.DSimproc
Simplification procedure for getLsb
(lowest significant bit) on BitVec
.
🔗defBitVec.reduceGetMsb : Lean.Meta.Simp.DSimproc
Simplification procedure for getMsb
(most significant bit) on BitVec
.
🔗defBitVec.reduceHShiftLeft :
Lean.Meta.Simp.DSimproc
Simplification procedure for shift left on BitVec
.
🔗defBitVec.reduceHShiftLeft' :
Lean.Meta.Simp.DSimproc
Simplification procedure for converting a shift with a bit-vector literal into a natural number literal.
🔗defBitVec.reduceHShiftRight :
Lean.Meta.Simp.DSimproc
Simplification procedure for shift right on BitVec
.
🔗defBitVec.reduceHShiftRight' :
Lean.Meta.Simp.DSimproc
Simplification procedure for converting a shift with a bit-vector literal into a natural number literal.
🔗defBitVec.reduceLE : Lean.Meta.Simp.Simproc
Simplification procedure for ≤
on BitVec
s.
🔗defBitVec.reduceLT : Lean.Meta.Simp.Simproc
Simplification procedure for <
on BitVec
s.
🔗defBitVec.reduceMod : Lean.Meta.Simp.DSimproc
Simplification procedure for the modulo operation on BitVec
s.
🔗defBitVec.reduceMul : Lean.Meta.Simp.DSimproc
Simplification procedure for multiplication of BitVec
s.
🔗defBitVec.reduceNe : Lean.Meta.Simp.Simproc
Simplification procedure for ≠
on BitVec
s.
🔗defBitVec.reduceNeg : Lean.Meta.Simp.DSimproc
Simplification procedure for negation of BitVec
s.
🔗defBitVec.reduceNot : Lean.Meta.Simp.DSimproc
Simplification procedure for bitwise not of BitVec
s.
🔗defBitVec.reduceOfInt : Lean.Meta.Simp.DSimproc
Simplification procedure for BitVec.ofInt
.
🔗defBitVec.reduceOfNat : Lean.Meta.Simp.DSimproc
Simplification procedure for ensuring BitVec.ofNat
literals are normalized.
🔗defBitVec.reduceOr : Lean.Meta.Simp.DSimproc
Simplification procedure for bitwise or of BitVec
s.
🔗defBitVec.reduceReplicate : Lean.Meta.Simp.DSimproc
Simplification procedure for replicate
on BitVec
s.
🔗defBitVec.reduceRotateLeft :
Lean.Meta.Simp.DSimproc
Simplification procedure for rotate left on BitVec
.
🔗defBitVec.reduceRotateRight :
Lean.Meta.Simp.DSimproc
Simplification procedure for rotate right on BitVec
.
🔗defBitVec.reduceSDiv : Lean.Meta.Simp.DSimproc
Simplification procedure for signed t-division of BitVec
s.
🔗defBitVec.reduceSLE : Lean.Meta.Simp.DSimproc
Simplification procedure for signed less than or equal sle
on BitVec
s.
🔗defBitVec.reduceSLT : Lean.Meta.Simp.DSimproc
Simplification procedure for signed less than slt
on BitVec
s.
🔗defBitVec.reduceSMTSDiv : Lean.Meta.Simp.DSimproc
Simplification procedure for signed division of BitVec
s using the SMT-Lib conventions.
🔗defBitVec.reduceSMTUDiv : Lean.Meta.Simp.DSimproc
Simplification procedure for division of BitVec
s using the SMT-Lib conventions.
🔗defBitVec.reduceSMod : Lean.Meta.Simp.DSimproc
Simplification procedure for the signed modulo operation on BitVec
s.
🔗defBitVec.reduceSRem : Lean.Meta.Simp.DSimproc
Simplification procedure for signed remainder of BitVec
s.
🔗defBitVec.reduceSShiftRight :
Lean.Meta.Simp.DSimproc
Simplification procedure for signed shift right on BitVec
.
🔗defBitVec.reduceSetWidth : Lean.Meta.Simp.DSimproc
Simplification procedure for setWidth
on BitVec
s.
🔗defBitVec.reduceSetWidth' : Lean.Meta.Simp.DSimproc
Simplification procedure for setWidth'
on BitVec
s.
🔗defBitVec.reduceShift (declName : Lean.Name)
(arity : Nat)
(op : {n : Nat} → BitVec n → Nat → BitVec n)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.DStep
Helper function for reducing bitvector functions such as shiftLeft
and rotateRight
.
🔗defBitVec.reduceShiftLeft : Lean.Meta.Simp.DSimproc
Simplification procedure for shift left on BitVec
.
🔗defBitVec.reduceShiftLeftShiftLeft :
Lean.Meta.Simp.Simproc
🔗defBitVec.reduceShiftLeftZeroExtend :
Lean.Meta.Simp.DSimproc
Simplification procedure for shiftLeftZeroExtend
on BitVec
s.
🔗defBitVec.reduceShiftRightShiftRight :
Lean.Meta.Simp.Simproc
🔗defBitVec.reduceShiftShift
(declName thmName : Lean.Name)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.Step
Helper function for reducing (x <<< i) <<< j
(and (x >>> i) >>> j
) where i
and j
are
natural number literals.
🔗defBitVec.reduceShiftWithBitVecLit
(declName : Lean.Name) (e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.DStep
Helper function for reducing x <<< i
and x >>> i
where i
is a bitvector literal,
into one that is a natural number literal.
🔗defBitVec.reduceSignExtend :
Lean.Meta.Simp.DSimproc
Simplification procedure for signExtend
on BitVec
s.
🔗defBitVec.reduceSub : Lean.Meta.Simp.DSimproc
Simplification procedure for subtraction of BitVec
s.
🔗defBitVec.reduceToInt : Lean.Meta.Simp.DSimproc
Simplification procedure for BitVec.toInt
.
🔗defBitVec.reduceToNat : Lean.Meta.Simp.DSimproc
Simplification procedure for BitVec.toNat
.
🔗defBitVec.reduceUDiv : Lean.Meta.Simp.DSimproc
Simplification procedure for unsigned division of BitVec
s.
🔗defBitVec.reduceULE : Lean.Meta.Simp.DSimproc
Simplification procedure for unsigned less than or equal ule
on BitVec
s.
🔗defBitVec.reduceULT : Lean.Meta.Simp.DSimproc
Simplification procedure for unsigned less than ult
on BitVec
s.
🔗defBitVec.reduceUMod : Lean.Meta.Simp.DSimproc
Simplification procedure for the unsigned modulo operation on BitVec
s.
🔗defBitVec.reduceUShiftRight :
Lean.Meta.Simp.DSimproc
Simplification procedure for unsigned shift right on BitVec
.
🔗defBitVec.reduceUnary (declName : Lean.Name)
(arity : Nat)
(op : {n : Nat} → BitVec n → BitVec n)
(e : Lean.Expr) :
Lean.Meta.SimpM Lean.Meta.Simp.DStep
Helper function for reducing homogeneous unary bitvector operators.
🔗defBitVec.reduceXOr : Lean.Meta.Simp.DSimproc
Simplification procedure for bitwise xor of BitVec
s.
🔗defBitVec.reduceZeroExtend :
Lean.Meta.Simp.DSimproc
Simplification procedure for zeroExtend
on BitVec
s.