Bitblasting of bitvectors #
This module provides theorems for showing the equivalence between BitVec operations using
the Fin 2^n
representation and Boolean vectors. It is still under development, but
intended to provide a path for converting SAT and SMT solver proofs about BitVectors
as vectors of bits into proofs about Lean BitVec
values.
The module is named for the bit-blasting operation in an SMT solver that converts bitvector expressions into expressions about individual bits in each vector.
Main results #
x + y : BitVec w
is(adc x y false).2
.
Future work #
All other operations are to be PR'ed later and are already proved in https://github.com/mhk119/lean-smt/blob/bitvec/Smt/Data/Bitwise.lean.
Preliminaries #
Addition #
carry i x y c returns true if the i
carry bit is true when computing x + y + c
.
Equations
- BitVec.carry i x y c = decide (BitVec.toNat x % 2 ^ i + BitVec.toNat y % 2 ^ i + Bool.toNat c ≥ 2 ^ i)
Instances For
Carry function for bitwise addition.
Equations
- BitVec.adcb x y c = (Bool.atLeastTwo x y c, Bool.xor x (Bool.xor y c))
Instances For
Bitwise addition implemented via a ripple carry adder.
Equations
- BitVec.adc x y = BitVec.iunfoldr fun (i : Fin w) (c : Bool) => BitVec.adcb (BitVec.getLsb x ↑i) (BitVec.getLsb y ↑i) c
Instances For
add #
Adding a bitvector to its own complement yields the all ones bitpattern
Subtracting x
from the all ones bitvector is equivalent to taking its complement