Axiomatic Semantics
CS 565
Lecture 6
2/04/09
Axiomatic Semantics
Operational semantics describes the meaning of
programs in terms of the execution steps taken by
an abstract machine.
Denotational semantics describes the meaning of
programs in terms of formal mathematical objects.
Axiomatic semantics describes the meaning of
programs in terms of properties (axioms) about
them.
Every language construct is described in terms
of a statement (in logic) about what the
construct accomplishes when it executes.
States
!
"
"
!
!
!
!
!
"
!
!
"
!
!
" !
"
Hoare Triples
!
"
!
!
"
"
!
!
!
Satisfiability
!
"
"
!
"
"
#
!
! !
! !
! !
! !
Examples
!
!
!
Partial correctness
!
!
"
"
"
Soundness
!
"
"
"
!
"
Proof Rules
Skip:
{ P } skip { P }
Assignment:
{ P[t/x] } x := t { P }
Example: Suppose t = x + 1
Then, { x+1 = 2 } x := x + 1 { x = 2 }
Sequencing:
{P} c0 {Q} {Q} c1 {Q}
{P} c0;c1 {Q}
Proof Rules (cont)
!
Example
Example
Prove the program:
z := 0;
n : = y;
while n > 0 do
z := z + x;
n := n 1
computes the product of x and y (assuming y
is not negative).
Invariants
Example
Example
Example