Axiomatic
Axiomatic
x=x+yXO
Computer Programming
y<r ~r +y X q = (r- y) + y X (1 + q )
The proof of the second of these is:
C. A. R. HOARE
The Queen's University of Belfast,* Northern Ireland A5 (r--y) + y X (l+q)
= (r--y)+ (yXl+yXq)
In this paper an attempt is made to explore the logical founda- A9 = ( r - - y) + (y + y X q)
tions of computer programming by use of techniques which
were first applied in the study of geometry and have later A3 = ((r--y)+y)+yXq
been extended to other branches of mathematics. This in- A6 = r + y X q providedy < r
volves the elucidation of sets of axioms and rules of inference
The axioms A1 to A9 are, of course, true of the tradi-
which can be used in proofs of the properties of computer
tional infinite set of integers in mathematics. However,
programs. Examples are given of such axioms and rules, and
a formal proof o f a simple theorem is displayed. Finally, it is
they are also true of the finite sets of "integers" which are
argued that important advantages, both theoretical and prac-
manipulated by computers provided that they are con-
tical, may follow from a pursuance of these topics.
fined to nonnegative numbers. Their truth is independent
of the size of the set; furthermore, it is largely independent
KEY WORDS AND PHRASES: axiomatic method, theory of programming' of the choice of technique applied in the event of "over-
proofs of programs, formal language definition, programming language
flow"; for example:
design, machine-independentprogramming, program documentation
CR CATEGORY: 4.0, 4.21,4.22, 5.20, 5.21,5.23, 5.24 (1) Strict interpretation: the result of an overflowing
operation does not exist; when overflow occurs, the offend-
ing program never completes its operation. Note that in
this case, the equalities of A1 to A9 are strict, in the sense
that both sides exist or fail to exist together.
(2) Firm boundary: the result of an overflowing opera-
tion is taken as the maximum value represented.
(3) Modulo arithmetic: the result of an overflowing
1. Introduction operation is computed modulo the size of the set of integers
represented.
Computer programming is an exact science in that all
These three techniques are illustrated in Table II by
the properties of a program and all the consequences of
addition and multiplication tables for a trivially small
executing it in any given environment can, in principle,
model in which 0, 1, 2, and 3 are the only integers repre-
be found out from the text of the program itself by means
sented.
of purely deductive reasoning. Deductive reasoning in-
I t is interesting to note that the different systems satisfy-
volves the application of valid rules of inference to sets of
ing axioms A1 to A9 may be rigorously distinguished from
valid axioms. I t is therefore desirable and interesting to
each other by choosing a particular one of a set of mutually
elucidate the axioms and rules of inference which underlie
exclusive supplementary axioms. For example, infinite
our reasoning about computer programs. The exact choice
arithmetic satisfies the axiom:
of axioms will to some extent depend on the choice of
programming language. For illustrative purposes, this A10z ~3xVy (y < x),
paper is confined to a very simple language, which is effec-
where all finite arithmetics satisfy:
tively a subset of all eurrent procedure-oriented languages.
A10~ Vx (x < max)
2. Computer Arithmetic
where "max" denotes the largest integer represented.
The first requirement in valid reasoning about a pro-
Similarly, the three treatments of overflow may be
gram is to know the properties of the elementary operations
distinguished by a choice of one of the following aMoms
which it invokes, for example, addition and multiplication
relating to the value of max + 1:
of integers. Unfortunately, in several respects computer
arithmetic is not the same as the arithmetic familiar to Alls ~ 3x (x = max + 1) (strict interpretation)
mathematicians, and it is necessary to exercise some care
in selecting an appropriate set of axioms. For example, the All, max + 1 = max (firm boundary)
axioms displayed in Table I are rather a small selection AllM max + 1 = 0 (modulo arithmetic)
of axioms relevant to integers. From this incomplete set
Having selected one of these axioms, it is possible to
* Depurtment of Computer Science use it in deducing the properties of programs; however,