Professional Documents
Culture Documents
Rajeev Gore
Australian National University
Semester 2, 2016
(Assignment)
2. {y = 4 y = 5} x:=y+1 {x = 5 y = 5}
(1. PreEq)
3. {False} x:=y+1 {x = 5 y = 5}
(2. PreEq)
i.e. if initial state is inconsistent and x:=y+1 terminates then final state
makes {x = 5 y = 5} true
Semantics
Calculus
FOL
N/A
= +
Arithmetic
N/A
:= ; while
if then else
N/A
{P}S{Q}
6 Inference
Rules
{Q(x)}
(backward driven)
{x = v}
x := e {x = e(v/x)}
x := x + 1 {x = (x + 1)(v/x)}
x := x + 1 {x = (v + 1)}
{x = 4} x := x + 1 {x = 5}
Note: does not solve the problem with pointers!
COMP 2600 Separation Logic
{Q(x)}
(backward driven)
{x = v}
x := e {x = e(v/x)}
{x = 1}
x := 1 {x = (1)(v/x)}
x := 1 {x = 1}
{x = x} x := 1 {x = 1}
Separation Logic: based on such forward reasoning zero-premise rules
COMP 2600 Separation Logic
http://www.cl.cam.ac.uk/~mjcg/HoareLogic/
Beware: he uses heavy duty logic and his notes are for a third year course!
Promise: I will tell the truth. I may not tell the whole truth, but I will not lie.
Name clash: Separation Logic is used for both the extension of Hoare Logic
and the extension of first-order logic upon which it is based!
Search: separation logic and you will get many technical papers, most of
which will be impenetrable, so beware!
Semantics
Calculus
FOL
N/A
= +
Arithmetic
N/A
:= ; while
if then else
{P}S{Q}
N/A
6 Inference
Rules
+ Floyd Axiom
Semantics
Calculus
SL
N/A
FOL
N/A
= +
Arithmetic
N/A
emp
:= ; while
if then else
[.]
dispose(.)
N/A
cons(.)
if initial state satisfies P
{P}S{Q}
COMP 2600 Separation Logic
and S terminates
More Inference
Rules
10
11
St(1) = 1
12
13
Semantics
Calculus
SL
N/A
FOL
N/A
= +
Arithmetic
N/A
emp
:= ; while
if then else
[.]
dispose(.)
N/A
cons(.)
if initial state satisfies P
{P}S{Q}
COMP 2600 Separation Logic
and S terminates
More Inference
Rules
14
St
x := [y + 1]
Hp
y = 20 20 21
1
St
Hp
y = 20 20 21
x=2
x := [y] + 1
15
St
[y + 1] := 5
Hp
y = 20 20 21
1
Hp
y = 20 20 21
Non-examples: [[x]] := 5
St
[x] + 1 := 5
16
(never faults)
Example: p := cons(3, 7)
St
p := cons(3, 7)
Hp
St
Hp
p = 10
10
11
Example: p := cons(q, q + 1)
St
Hp
q=5
p := cons(q, q + 1)
St
Hp
q=5
110
111
p = 110
17
St
Hp
q=5
110
p = 110
St
Hp
111
q=5
110
111
p = 110
St
Hp
dispose(q)
Example: dispose(p)
St
Hp
q=5
110
111
q=5
111
p = 110
p = 110
dispose(p)
18
19
Semantics
Calculus
SL
N/A
FOL
N/A
= +
Arithmetic
N/A
emp
:= ; while
if then else
[.]
dispose(.)
N/A
cons(.)
if initial state satisfies P
{P}S{Q}
COMP 2600 Separation Logic
and S terminates
More Inference
Rules
20
21
{Q(x)}
Floyd Axiom:
{x = v}
x := e {x = e(v/x)}
{x = v emp}
x := e {x = e(v/x) emp}
22
{x = v emp}
x := e {x = e(v/x) emp}
x := 1 {x = (1)(v/x) emp}
{x = x emp} x := 1 {x = 1 emp}
23
St
Hp
y = 20 20
1
x := [y]
St
Hp
y = 20 20
x=1
e is y: so
{(x = v1 ) (y 7 v2 )} x := [y] {(x = v2 ) (e(v1 /x) 7 v2 )}
v2 is 1: so
{(x = v1 ) (y 7 1)}
24
25
Semantics
Calculus
SL
N/A
FOL
N/A
= +
Arithmetic
N/A
emp
:= ; while
if then else
[.]
dispose(.)
N/A
cons(.)
if initial state satisfies P
{P}S{Q}
COMP 2600 Separation Logic
and S terminates
More Inference
Rules
26