Overview
Define as the predicate:
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 ,
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 wp(''\bar{x} \coloneqq \bar{e}'', R) = domain(\bar{e}) \textbf{ cand } R_{\bar{e}}^\bar{x}
Alternative
The general form of the alternative command is: \begin{align*} \textbf{if } & B_1 \rightarrow S_1 \\ \textbf{ | } & B_2 \rightarrow S_2 \\ & \quad\cdots \\ \textbf{ | } & B_n \rightarrow S_n \\ \textbf{fi } & \end{align*}
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: \begin{align*} wp(\text{IF}, R) = \;& (\forall i, 1 \leq i \leq n \Rightarrow domain(B_i)) \;\land \\ & (\exists i, 1 \leq i \leq n \land B_i) \;\land \\ & (\forall i, 1 \leq i \leq n \Rightarrow (B_i \Rightarrow wp(S_i, R))) \end{align*}
Bibliography
- Gries, David. The Science of Programming. Texts and Monographs in Computer Science. New York: Springer-Verlag, 1981.