# Unifying Theories of Programming

(Redirected from Unifying theories of programming)

Unifying Theories of Programming (UTP) deals with program semantics. It shows how denotational semantics, operational semantics and algebraic semantics can be combined in a unified framework for the formal specification, design and implementation of programs and computer systems.

The book of this title by C.A.R. Hoare and He Jifeng was published in the Prentice Hall International Series in Computer Science in 1998.[1]

## Theories

The semantic foundation of the UTP is the first-order predicate calculus, augmented with fixed point constructs from second-order logic. Following the tradition of Eric Hehner, programs are predicates in the UTP, and there is no distinction between programs and specifications at the semantic level. In the words of Hoare:

A computer program is identified with the strongest predicate describing every relevant observation that can be made of the behaviour of a computer executing that program.[2]

In UTP parlance, a theory is a model of a particular programming paradigm. A UTP theory is composed of three ingredients:

• an alphabet, which is a set of variable names denoting the attributes of the paradigm that can be observed by an external entity;
• a signature, which is the set of programming language constructs intrinsic to the paradigm; and
• a collection of healthiness conditions, which define the space of programs that fit within the paradigm. These healthiness conditions are typically expressed as monotonic idempotent predicate transformers.

Program refinement is an important concept in the UTP. A program $P_{1}$ is refined by $P_{2}$ if and only if every observation that can be made of $P_{2}$ is also an observation of $P_{1}$. The definition of refinement is common across UTP theories:

$P_{1}\sqsubseteq P_{2}\quad {\text{if and only if}}\quad \left[P_{2}\Rightarrow P_{1}\right]$

where $\left[X\right]$ denotes[3] the universal closure of all variables in the alphabet.

## Relations

The most basic UTP theory is the alphabetised predicate calculus, which has no alphabet restrictions or healthiness conditions. The theory of relations is slightly more specialised, since a relation's alphabet may consist of only:

• undecorated variables ($v$), modelling an observation of the program at the start of its execution; and
• primed variables ($v'$), modelling an observation of the program at a later stage of its execution.

Some common language constructs can be defined in the theory of relations as follows:

• The skip statement, which does not alter the program state in any way, is modelled as the relational identity:

${\mathbf {skip}}\equiv v'=v$

• The assignment of value $E$ to a variable $a$ is modelled as setting $a'$ to $E$ and keeping all other variables (denoted by $u$) constant:

$a:=E\equiv a'=E\land u'=u$

$P_{1};P_{2}\equiv \exists v_{0}\bullet P_{1}[v_{0}/v']\land P_{2}[v_{0}/v]$

• Non-deterministic choice between programs is their greatest lower bound:

$P_{1}\sqcap P_{2}\equiv P_{1}\lor P_{2}$

$P_{1}\triangleleft C\triangleright P_{2}\equiv (C\land P_{1})\lor (\lnot C\land P_{2})$

• A semantics for recursion is given by the least fixed point $\mu {\mathbf {F}}$ of a monotonic predicate transformer ${\mathbf {F}}$:

$\mu X\bullet {\mathbf {F}}(X)\equiv \sqcap \left\{X\mid {\mathbf {F}}(X)\sqsubseteq X\right\}$

## References

1. ^ C.A.R. Hoare and He Jifeng, Unifying Theories of Programming, Prentice Hall International Series in Computer Science, 1998. ISBN 0-13-458761-8.
2. ^ C.A.R. Hoare, Programming: Sorcery or science? IEEE Software, 1(2): 5–16, April 1984. ISSN 0740-7459. doi: 10.1109/MS.1984.234042.
3. ^ Edsger W. Dijkstra and Carel S. Scholten. Predicate calculus and program semantics. Texts and Monographs in Computer Science. Springer-Verlag New York, Inc., New York, NY, USA, 1990. ISBN 0-387-96957-8.