Skip to content
Snippets Groups Projects

Add some bitvector rules

Merged Hans-Jörg requested to merge devel/bb2024 into master
1 file
+ 37
0
Compare changes
  • Side-by-side
  • Inline
+ 88
0
@@ -73,6 +73,7 @@
\newcommand\lsymb[1]{\mathbf{#1}}
\DeclareMathOperator*{\subst}{subst}
\DeclareMathOperator*{\reify}{reify}
\DeclareMathOperator*{\bvexplode}{bvexplode}
\newcommand\groundbox[1]{\boxed{#1}}
% Proofs
@@ -1688,6 +1689,88 @@ is functional congruence, and \proofRule{sko_forall} works like
\end{AletheS}
\end{example}
\subsection{Bitvector Reasoning with Bitblasting}
A standard approach to handle bitvector reasoning in SMT solvers
is bitblasting. Bitblasting\index{bitblasting} works by translating
bitvector\index{bitvector} functions to propositional formulas that
model the logical circuit of the bitvector function.
To express bitblasting in Alethe proof rules, the the Alethe calculus uses
multiple families of helper functions: $\lsymb{bbT}$, $\lsymb{bitOf}_m$,
$\lsymb{bvsize}$, and $\lsymb{bv}_n^i$. Functions in the families are
distinguished either by overloading ($\lsymb{bbT}$ and $\lsymb{bvsize}$)
or by explicit indexing ($\lsymb{bitOf}_m$ and $\lsymb{bv}_n^i$).
To avoid name clashes with user defined
functions, $\lsymb{bbT}$ is written as \inlineAlethe{@bbT}, $\lsymb{bitOf}$
as \inlineAlethe{@bitOf}, $\lsymb{bvsize}$ as \inlineAlethe{@bvsize}, and
$\lsymb{bv}$ as \inlineAlethe{@bv}. The SMT-LIB standard specifies
that simple symbols starting with ``\inlineAlethe{@}'' are reserved for
solver generated functions.
The family $\lsymb{bbT}$ consists of one function for each bitvector sort
$(\lsymb{BitVec}\;n)$.
\[
\lsymb{bbT}\,:\,\underbrace{\lsymb{Bool}\,\dots\,\lsymb{Bool}}_n\;(\lsymb{BitVec}\;n).
\]
\noindent
Intuitively, the function $\lsymb{bbT}$ takes a list of boolean arguments and
packs them into a bitvector.
Let $\langle u_1, \dots, u_n\rangle$ denote a bitvector of sort $(\lsymb{BitVec}\;n)$
where $u_i = \top$ if the bit at position $i$ is $1$, and $u_i = \bot$ otherwise.
The bit $u_n$ is the least significant bit. Then
\[
\lsymb{bbT}\; v_1 \dots v_n = \langle v_1, \dots, v_n\rangle .
\]
\noindent
The $\lsymb{bbT}$ functions could be defined in terms of standard SMT-LIB functions.
\begin{align*}
\lsymb{bbT}\;v_1 \dots v_n :=\;
&\lsymb{concat}\,(\lsymb{concat}\,(\dots \\
&(\lsymb{concat}\,(\lsymb{ite}\,v_1\,\langle\top\rangle\,\langle\bot\rangle)\,(\lsymb{ite}\,v_2\,\langle\top\rangle\,\langle\bot\rangle))\\
& \dots \\
& (\lsymb{ite}\,v_{n-1}\,\langle\top\rangle\,\langle\bot\rangle)) \\
& (\lsymb{ite}\,v_n\,\langle\top\rangle\,\langle\bot\rangle)) \\
\end{align*}
\noindent
The functions $\lsymb{bitOf}_m$ are the inverse of $\lsymb{bbT}$. They extract
a bit of a bitvector as a boolean. Just as the built in $\lsymb{extract}$
symbol, $\lsymb{bitOf}_m$ is used as an indexed symbol. Hence, for $m \leq n$, we
write \inlineAlethe{(_ @bitOf} $m$ \inlineAlethe{)}, to denote functions
\[
\lsymb{bitOf}_m : (\lsymb{BitVec}\;n) \to \lsymb{Bool}.
\]
These functions are defined as
\[
\lsymb{bitOf}_m \langle u_1, \dots, u_n \rangle := u_m.
\]
\noindent
The functions $\lsymb{bvsize}$ return the size of a bitvector. Formally, there
is one $\lsymb{bvsize}$ for for each bitvector sort $(\lsymb{BitVec}\;n)$. Each
$\lsymb{bvsize}$ is a constant function that returns $n$. Using notation:
\begin{align*}
\lsymb{bvsize}& : (\lsymb{BitVec}\;n) \to \mathbb{N}\\
\lsymb{bvsize}&\;b := n
\end{align*}
\noindent
Finally, $\lsymb{bv}_n^i$ is a family of constants indexed by two parameters:
a bitvector length $n$, and a natural number $i$. We
write \inlineAlethe{(_ @bv}$n$ $i$ \inlineAlethe{)} for $\lsymb{bv}_n^i$.
The space before $n$ is omitted for historical reasons.
Each $\lsymb{bv}_n^i$ is the bitvector constant that represents the bitvector
of length $n$ that encodes the integer $i$. Formally, it corresponds
to \inlineAlethe{nat2bv[n](i)}, where \inlineAlethe{nat2bv} is defined
as in the SMT-LIB
standard.\footnote{See \url{https://smt-lib.github.io/theories-FixedSizeBitVectors.shtml}.}
\section{The Alethe Rules}
\label{apx:rules}
\input{rule_list}
@@ -1707,3 +1790,8 @@ is functional congruence, and \proofRule{sko_forall} works like
\bibliography{publications}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
Loading