If execution of is begun in a state satisfying , then it is guaranteed to terminate in a finite amount of time in a state satisfying .
Weakest Precondition
For any command and predicate , we define the weakest precondition of with respect to , denoted , as
the set of all states such that execution of begun in any one of them is guaranteed to terminate in a finite amount of time in a state satisfying .
Expression is equivalent to .
Law of the Excluded Miracle
Given any command , .
Distributivity of Conjunction
Given command and predicates and ,
Law of Monotonicity
Given command and predicates and , if , then .
Distributivity of Disjunction
Given command and predicates and ,
Strongest Postcondition
For any command and predicate , we define the strongest postcondition of with respect to , denoted , as
the state such that execution of begun in a state satisfying is guaranteed to terminate in after a finite amount of time.
Expression is equivalent to .
Commands
Skip
For any predicate , .
Abort
For any predicate , .
Sequential Composition
Sequential composition is one way of composing larger program segments from smaller segments. Let and be two commands. Then is defined as
Assignment
Simple
The assignment command has form , provided the types of and are the same. This command is read as " becomes " and is defined as
where is a predicate that describes the set of all states in which may be evaluated.
General
The multiple assignment command has form
where each is an identifier, each is a selector, and each expression has the same type as . We denote this assignment more compactly as . We define multiple assignment as
Alternative
The general form of the alternative command is:
Each is called a guarded command. To execute the alternative command, find one true guard and execute the corresponding command. Notice this is nondeterministic. We denote the alternative command as and define in terms of as:
Iterative
The general form of the iterative command is:
We denote the iterative command as and define in terms of as:
A bound function returns an upper bound on the number of iterations an iterative command may perform. On every iteration, it must evaluate to a smaller number than in the previous iteration. That is, for all . In this way, we guarantee the iterative command eventually terminates.
Understanding Loops
Consider loop . Suppose a predicate satisfies
for all .
Suppose further that an integer function satisfies the following, where is a fresh identifier: