Title: Proving program termination and liveness
1 Proving program termination and liveness Byron
Cook Cambridge theory mini-course October 22nd,
2007 Lecture III of III
TexPoint fonts used in EMF. Read the TexPoint
manual before you delete this box. A
2Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
3Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
4Refinement
5Refinement
6Refinement
7Refinement
8Refinement
9Refinement
x x 1
assume(xgt0)
assume(xz)
assume(wgt0)
y 33 z
x x 1
x x 1
r r e
x x 1
assume(xgt0)
assume(rtrue)
y y 1
x x 1
w w - x
w 5 w
assume(wgtz)
z -z
x x 1
y 100
assume(k2gt0)
assume(glt100)
assume(tlt0)
assume(ggt0)
w w k
w g g
x x 1
x x 1
z w
p p3
k k / 3
y 3 y
10Refinement
x x 1
assume(xgt0)
assume(xz)
assume(wgt0)
y 33 z
x x 1
x x 1
r r e
x x 1
assume(xgt0)
assume(rtrue)
y y 1
x x 1
w w - x
w 5 w
assume(wgtz)
z -z
x x 1
y 100
assume(k2gt0)
assume(glt100)
assume(tlt0)
assume(ggt0)
w w k
w g g
x x 1
x x 1
z w
p p3
k k / 3
y 3 y
11Refinement
x x 1
assume(xgt0)
assume(xz)
assume(wgt0)
y 33 z
x x 1
x x 1
r r e
x x 1
assume(xgt0)
assume(rtrue)
y y 1
x x 1
w w - x
w 5 w
assume(wgtz)
z -z
x x 1
y 100
assume(k2gt0)
assume(glt100)
assume(tlt0)
assume(ggt0)
w w k
w g g
x x 1
x x 1
z w
p p3
k k / 3
y 3 y
12Refinement
x x 1
assume(xgt0)
assume(xz)
assume(wgt0)
y 33 z
x x 1
x x 1
r r e
x x 1
assume(xgt0)
assume(rtrue)
y y 1
x x 1
w w - x
w 5 w
assume(wgtz)
z -z
x x 1
y 100
assume(k2gt0)
assume(glt100)
assume(tlt0)
assume(ggt0)
w w k
w g g
x x 1
x x 1
z w
p p3
k k / 3
y 3 y
13(No Transcript)
14(No Transcript)
15(No Transcript)
16Refinement
17Refinement
18Refinement
19Tying the pieces together
20Tying the pieces together
21Tying the pieces together
22Tying the pieces together
23Tying the pieces together
24The bad news
25The bad news
26The bad news
27The bad news
28The bad news
29The bad news
30The bad news
31The bad news
32The bad news
33The bad news
34Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
35Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
36Proving liveness properties
- Myth Liveness can always be boiled down to
termination - Almost, but not quite!!
- Fact liveness can always be boiled down to fair
termination - Fair termination is standard termination with
fairness constraints on the executions - Weak fairness Buchi acceptance conditions
justice - Strong fairness Streett/Rabin acceptance
conditions compassion
37Proving liveness properties
- Myth Liveness can always be boiled down to
termination - Almost, but not quite!!
- Fact liveness can always be boiled down to fair
termination - Fair termination is standard termination with
fairness constraints on the executions - Weak fairness Buchi acceptance conditions
justice - Strong fairness Streett/Rabin acceptance
conditions compassion
38Proving liveness properties
- Fairness constraints remove classes of
counterexamples from consideration - The program doesnt terminate, but terminates if
certain paths are ignored - Fairness constraints describe those paths
39Strong fairness
40Strong fairness
41Strong fairness
42Strong fairness
43Strong fairness
44Strong fairness
45Strong fairness
fairness any 1 any qPENDING
void f() AcquireLock()
. .
. . . ReleaseLock()
. . void main()
void f() . AcquireLock() .
. . . . .
. . . . .
ReleaseLock() . . .
. . . . void main()
if (sNONE) if (nondet())
sPENDING if
(sPENDING) sMATCHED
sNONE
AcquireLock.entry if (sNONE) if
(nondet()) sPENDING
ReleaseLock.entry if (sPENDING)
sMATCHED main.entry sNONE
46Outline
47Outline
48Outline
49Strong fairness
50Strong fairness
51Strong fairness
52Strong fairness
53Strong fairness
x f(x,y) g(y,x)
set 0 . . . if (!set)
if () old_x x
old_y y set 1
else if (fair path segment)
assert(M1 M2 M3)
while(xlty)
54Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
in_S0 in_T0
55Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
(!S !in_S) T in_T
in_S0 in_T0
56Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
(!S !in_S) T in_T
in_S0 in_T0
- Also, add the following at each command in the
program - if (S) in_S1
- if (T) in_T1
57Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
if (S) in_S1 if (T) in_T1
(!S !in_S) T in_T
in_S0 in_T0
- Also, add the following at each command in the
program - if (S) in_S1
- if (T) in_T1
58Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
if (S) in_S1 if (T) in_T1
(!S !in_S) T in_T
in_S0 in_T0
- Also, add the following at each command in the
program - if (S) in_S1
- if (T) in_T1
59Liveness property library
60Liveness property library
61Liveness property library
62Liveness property library
63Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
64Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
65Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
66Introduction
67Introduction
68Introduction
69Introduction
70Introduction
71Concurrent programs
- Thread-modular algorithm finds an environment
model binary relation expressed as CNF formula - Implements iterative weakening strengthening
based on spurious counterexamples - Strengthening add conjuncts
- Weakening add disjuncts
- Nifty trick
- Iterative search considers potential
counterexamples to termination in isolation of
the other threads - Extremely weak rely/guarantee rule currently used
72Concurrent programs
- Thread-termination Thread T is thread
terminating in P if in each P-computation T makes
only finite many steps. - Important to note
- Were not ruling out deadlock
- Deadlock is a safety property that other tools
should rule out - Thus not proving that functions called in T
eventually return control back to their caller
73Concurrent programs
- Thread-modular algorithm finds an environment
model binary relation expressed as CNF formula - Implements iterative weakening strengthening
based on spurious counterexamples - Strengthening add conjuncts
- Weakening add disjuncts
- Nifty trick
- Iterative search considers potential
counterexamples to termination in isolation of
the other threads - Extremely weak rely/guarantee rule currently used
74Example
75Example
76Example
77Example
78Example
79Example
80Example
81Example
82Example
83Example
84Example
85Example
86Example
87Example
88Example
89Example
90Example
91Example
92Example
93Example
94Example
95Example
96Example
97Example
98Example
99Example
100Example
101Example
102Example
103Example
104Example
105Example
106Example
107Example
108Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency
109Outline
- Foundations
- Checking termination
- Rank function synthesis
- Termination analysis
- Counterexamples refinement
- Liveness
- Concurrency