Checking Observational Purity of Procedures
Abstract
We provide two static analysis approaches(using theorem proving) that check if a given (recursive)
procedure behaves as if it were stateless, even when it maintains state in global variables.
In other words, we check if the given procedure behaves like a mathematical function. In order
to eliminate the need for manual annotations, we make use of an invariant that makes use of
uninterpreted function symbols. This invariant captures the set of reachable global states in all
runs of the procedure, if the procedure is observationally pure. If the procedure is not observationally
pure, this invariant has no semantics. Allowing function symbols makes it easier to
generate the invariant automatically. The two static analysis are an existential checker and an
impurity witness checker. The impurity witness checker outputs a formula whose unsatis fiability
implies that the procedure is observationally pure. Whereas, the existential checker outputs
a formula that constrains the de finition of the function that the given procedure may implement.
Satisfi ability of the formula generated by the existential checker implies that the given
procedure is observationally pure. The impurity witness approach works better (empirically)
with SMT solvers, whereas the existential approach is more precise on paper. We illustrate
our work on examples such as matrix chain multiplication. Examples such as these are not
addressable by related techniques in the literature. The closest work to our is by Barnett et
al.; this work cannot handle procedures with self recursion. We prove both our approaches to
be sound. We have implemented the two static analyses using the Boogie framework and the
Z3 SMT solver, and have evaluated our implementation on a number of examples