AVoCS 2007
Isabelle Theories for Machine Words
Jeremy Dawson1 ,2
Logic and Computation Program, NICTA and Automated Reasoning Group, Australian National University, Canberra, ACT 0200, Australia Abstract We describe a collection of Isabelle theories which facilitate reasoning about machine words. For each possible word length, the words of that length form a type, and most of our work consists of generic theorems which can be applied to any such type. We develop the relationships between these words and integers (signed and unsigned), lists of booleans and functions from index to value, noting how these relationships are similar to those between an abstract type and its representing set. We discuss how we used Isabelle’s bin type, before and after it was changed from a datatype to an abstract type, and the techniques we used to retain, as nearly as possible, the convenience of primitive recursive definitions. We describe other useful techniques, such as encoding the word length in the type. Keywords: machine words, twos-complement, mechanised reasoning
1 Introduction
In formally verifying machine hardware, we need to be able to deal with the prop- erties of machine words. These differ from ordinary numbers in that, for example, addition and multiplication can overflow, with overflow bits being lost, and there are bit-wise operations which are simply defined in a natural way. Wai Wong [8] developed HOL theories in which words are represented as lists of
- bits. The type is the set of all words of any length; words of a given length form a
- subset. Some theorems have the word length as an explicit condition. The theories
include some bit-wise operations but not the arithmetic operations. In [4] Fox descibes HOL theories modelling the architecture of the ARM instruc- tion set. There, the HOL datatype w32 = W32 of num is used, that is, the machine word type is isomorphic to the naturals, and the expression W32 n is to mean the
1 National ICT Australia is funded by the Australian Government’s Dept of Communications, Information
Technology and the Arts and the Australian Research Council through Backing Australia’s Ability and the ICT Centre of Excellence program.
2 http://users.rsise.anu.edu.au/∼jeremy/