Predicate transformer semantics
Predicate transformer semantics were introduced by Edsger Dijkstra in his seminal paper "Guarded commands, nondeterminacy and formal derivation of programs". They define the semantics of an imperative programming paradigm by assigning to each statement in this language a corresponding predicate transformer: a total function between two predicates on the state space of the statement. In this sense, predicate transformer semantics are a kind of denotational semantics. Actually, in guarded commands, Dijkstra uses only one kind of predicate transformer: the well-known weakest preconditions (see below). Moreover, predicate transformer semantics are a reformulation of Floyd–Hoare logic. Whereas... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
Predicate transformer semantics were introduced by Edsger Dijkstra in his seminal paper "Guarded commands, nondeterminacy and formal derivation of programs". They define the semantics of an imperative programming paradigm by assigning to each statement in this language a corresponding predicate transformer: a total function between two predicates on the state space of the statement. In this sense, predicate transformer semantics are a kind of denotational semantics. Actually, in guarded commands, Dijkstra uses only one kind of predicate transformer: the well-known weakest preconditions (see below). Moreover, predicate transformer semantics are a reformulation of Floyd–Hoare logic. Whereas Hoare logic is presented as a deductive system, predicate transformer semantics (either by weakest-preconditions or by strongest-postconditions see below) are complete strategies to build valid deductions of Hoare logic. In other words, they provide an effective algorithm to reduce the problem of verifying a Hoare triple to the problem of proving a first-order formula. Technically, predicate transformer semantics perform a kind of symbolic execution of statements into predicates: execution runs backward in the case of weakest-preconditions, or runs forward in the case of strongest-postconditions. For a statement S and a postcondition R, a weakest precondition is a predicate Q such that for any precondition , \{ P \} S \{ R \} if and only if P \Rightarrow Q . In other words, it is the "loosest" or least restrictive requirement needed to guarantee that R holds after S. Uniqueness follows easily from the definition: If both Q and Q' are weakest preconditions, then by the definition \{ Q' \} S \{ R \} so Q' \Rightarrow Q and \{ Q \} S \{ R \} so Q \Rightarrow Q' , and thus Q=Q' . We often use wp(S, R) to denote the weakest precondition for statement S with respect to a postcondition R. We use T to denote the predicate that is everywhere true and F to denote the one that is everywhere false. We shouldn't at least conceptually confuse ourselves with a Boolean expression defined by some language syntax, which might also contain true and false as Boolean scalars. For such scalars we need to do a type coercion such that we have T = predicate(true) and F = predicate(false). Such a promotion is carried out often casually, so people tend to take T as true and F as false. wp(x := x - 5, x > 10) & = & x - 5 > 10 \\ & \Leftrightarrow & x > 15 \end{array} This means that, for the postcondition x > 10 to be true after the assignment, the precondition x > 15 must be true before the assignment. This is also the "weakest precondition", in that it is the "weakest" restriction on the value of x which makes x > 10 true after the assignment. \begin{array}[t]{rcl} wp(x:=x-5;x:=x*2\ ,\ x>20) & = & wp(x:=x-5,wp(x:=x*2, x > 20))\\ & = & wp(x:=x-5,x*2 > 20)\\ & = & (x-5)*2 > 20\\ & = & x > 15 \end{array} wp(\texttt{if}\ x x:l[x = l, x = l+1] Another example is a computation of a square root of an integer. x:l[x = l^2, x = l] The specification statement appears like a primitive in the sense that it does not contain other statements. However, it is very expressive, as pre and post are arbitrary predicates. Its weakest precondition is as follows. It combines Morgan's syntactic idea with the sharpness idea by Bijlsma, Matthews and Wiltink. The very advantage of this is its capability of defining wp of goto L and other jump statements. wp(do x > 0 → L: x := x-1 od; if x 0 → L: x := x-1 od, (x 0 → L: x := x-1 od, x 0 ∧ wp(L: x := x-1, Z) ∨ x 0 ∧ Z(x ← x-1) ∨ x 0 ∧ Z(x ← x-1) ∨ x sp(x := x - 5, x > 15)\ =\ \exists y, x = y - 5 \wedge y > 15 \ \Leftrightarrow \ x > 10 On sequence, it appears that sp runs forward (whereas wp runs backward): S\ =\ \texttt{if}\ \texttt{true} \rightarrow x:=0\ [\!]\ \texttt{true} \rightarrow x:=1\ \texttt{fi} Then, wp(S,R) reduces to the formula R[x \leftarrow 0] \wedge R[x \leftarrow 1] . Hence, wp(S,\ x=0 \vee x=1) reduces to the tautology (0=0 \vee 0=1) \wedge (1=0 \vee 1=1) Whereas, the formula wp(S, x=0) \vee wp(S,x=1) reduces to the wrong proposition (0=0 \wedge 1=0) \vee (1=0 \wedge 1=1) .
Cite this
"Predicate transformer semantics". 1789403931. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1374898040 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy