Title: Proving program termination and liveness
1 Proving program termination and liveness Byron
Cook Cambridge theory mini-course Lecture I of
III October 15, 2007
TexPoint fonts used in EMF. Read the TexPoint
manual before you delete this box. A
2Introduction
- The halting problem (a.k.a. program termination
problem) - Given a computer program together with an
initial state, in a finite amount of time
determine whether the program will finish running
or will run forever
3Introduction
- Halting problem has troubled us since the
beginning of computing - One of the first problems proved undecidable
- The source of unsolved puzzles
- A matter of practical importance
- Is every call to AcquireLock() is followed by a
call to ReleaseLock()? - Does SerialPnpDispatch(..) always return control
back to its caller?
4Introduction
- Halting problem has troubled us since the
beginning of computing - One of the first problems proved undecidable
- The source of unsolved puzzles
- A matter of practical importance
- Is every call to AcquireLock() is followed by a
call to ReleaseLock()? - Does SerialPnpDispatch(..) always return control
back to its caller?
5Introduction
- Halting problem has troubled us since the
beginning of computing - One of the first problems proved undecidable
- The source of unsolved puzzles
- A matter of practical importance
- Is every call to AcquireLock() is followed by a
call to ReleaseLock()? - Does SerialPnpDispatch(..) always return control
back to its caller?
6Introduction
- Common wisdom
- Proving termination/liveness is impossible
- Thats the halting problem
- Truth
- Turing didnt prove that we cannot prove
termination - He did prove that theres at least one problem
that we cannot prove terminating
7Introduction
- Common wisdom
- Even if some termination proof tricks exist,
theyll never work for real code - Recent advances disprove this wisdom
- Rank function synthesis techniques
- Termination proof techniques for complex CFGs
- Termination analysis techniques developed
- Methods of refining termination arguments
- Terminator now being used to prove termination of
device driver dispatch routines through the
Windows SDV product
8Introduction
- This course
- Foundations of termination
- Methods of proving termination
- Proving liveness properties
- Proving concurrent programs terminating
9Outline
- Foundations
- Checking termination
- Termination analysis
- Refinement synthesis
- Liveness
- Heap
- Concurrency
10Outline
- Foundations
- Checking termination
- Termination analysis
- Refinement synthesis
- Liveness
- Heap
- Concurrency
11Outline
- Foundations
- Checking termination
- Termination analysis
- Refinement synthesis
- Liveness
- Heap
- Concurrency
12Halting problem
- The halting problem (a.k.a. program termination
problem) - Given a computer program together with an
initial state, in a finite amount of time
determine whether the program will finish running
or will run forever
13Halting problem
- Highlights of undecidability proof
- Assume we do have a procedure, call it h
- h program input -gt bool
- let c(p) if h(p,p) spin() else true
- Consider c(c)
- If it terminates, h(c,c) returned false, thus
c(c) shouldnt terminate - If it doesnt terminate, h(c,c) shouldnt have
returned true
14Well-founded relations
- The halting problem (a.k.a. program termination
problem) - The programs transition relation is well-founded
15Well-founded relations
- Notation
- Transition relation
- Initial states
- Reachable states
- Well-founded?
16Well-founded relations
17Well-founded relations
18Well-founded relations
19Well-founded relations
What are well-founded relations?
20Well-founded relations
What are well-founded relations?
21Well-founded relations
What are well-founded relations?
22Well-founded relations
What are well-founded relations?
23Well-founded relations
What are well-founded relations?
Well-founded relations do not permit infinite
sequences
24Well-founded relations
What are well-founded relations?
Well-founded relations do not permit infinite
sequences
25Well-founded relations
What are well-founded relations?
Well-founded relations do not permit infinite
sequences
26Well-founded relations
What are well-founded relations?
27Well-founded relations
What are well-founded relations?
28Well-founded relations
- Observation
- Subrelations of WF-relations are WF
- As an example application
29Next
Next Ranking functions and ranking relations
30Well-ordered sets
31Well-ordered sets
32Ranking functions and ranking relations
33Ranking functions and ranking relations
34Example
35Example
36Example
37Example
38Example
39Example
40Example
41Next
Next Prove a program terminating with tools
42Example
43Example
44Example
45Example
46Example
47Example
48Example
49Example
50Example
51Example
52Example
53Example
54Example
55Example
56Example
57Outline
- Foundations
- Checking termination
- Termination analysis
- Refinement synthesis
- Liveness
- Heap
- Concurrency
58Outline
- Foundations
- Checking termination
- Termination analysis
- Refinement synthesis
- Liveness
- Heap
- Concurrency
59Traces, paths, segments, etc
60Traces, paths, segments, etc
61Traces, paths, segments, etc
62Cutpoints
63Cutpoints
64Cutpoints
65Cutpoints
66Cutpoints
67Cutpoints
68Cutpoints
69Cutpoints
70Cutpoints
71Cutpoints
72Cutpoints
73Cutpoints
74Isolation
- Nesting of loops allows us to isolate pieces of
the program
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
75Isolation
- Nesting of loops allows us to isolate pieces of
the program
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
76Isolation
- Nesting of loops allows us to isolate pieces of
the program
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
77Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
78Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
79Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
80Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
81Cutpoints
82Combining ranking functions
- Combinations of ranking functions are the modern
method of arguing termination - Size-change approach (used by ACL2, APROVE)
- Disjunctive-WF (used by Terminator,
LinearRankTerm) - Polyranking principle (used by PolyRank)
- Idea use many simple ranking functions instead
of one big complex one - Makes finding/expressing termination argument
easier - Makes checking the subset inclusion harder
83Disjunctively well-founded termination arguments
84Disjunctively well-founded termination arguments
85Disjunctively well-founded termination arguments
while(xgt0 ygt0) if () x--
else y--
86Disjunctively well-founded termination arguments
while(xgt0 ygt0) if () x--
else y--
87Disjunctively well-founded termination arguments
while(xgt0 ygt0) if () x--
else y--
88Disjunctively well-founded termination arguments
while(xgt0 ygt0) if () x--
else y--
89Disjunctively well-founded termination arguments
while(xgt0 ygt0) if () x--
else y--
90Disjunctively well-founded termination arguments
while(xgt0 ygt0) if () x--
else y--
91Disjunctively well-founded termination arguments
92Disjunctively well-founded termination arguments
while(xlt0 xlt1000) if () x--
else x
93Disjunctively well-founded termination arguments
while(xlt0 xlt1000) if () x--
else x
94Disjunctively well-founded termination arguments
while(xlt0 xlt1000) if () x--
else x
95Disjunctively well-founded termination arguments
while(xlt0 xlt1000) if () x--
else x
96Nexy
Next Using cut-points with our new disjunctive
rule
97Cutpoints
98Cutpoints
99Cutpoints
100Cutpoints
101Cutpoints
102Isolation
- Nesting of loops allows us to isolate pieces of
the program
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
103Isolation
- Nesting of loops allows us to isolate pieces of
the program
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
104Isolation
- Nesting of loops allows us to isolate pieces of
the program
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
105Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
106Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
107Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
108Isolation
- When proving well-foundedness of cutpoints in
inner loops, we can ignore non-termination of the
enclosing loop - When proving well-foundedness of cutpoints in
outer loops, we can ignore non-termination of the
inner loop
- Nesting of loops allows us to isolate pieces of
the program
109Isolation
110Checking disjunctively well-founded arguments
- Cutpoints can be easily explained with
disjunctive well-foundedness
111Checking disjunctively well-founded arguments
- Cutpoints can be easily explained with
disjunctive well-foundedness
112Checking disjunctively well-founded arguments
- Cutpoints can be easily explained with
disjunctive well-foundedness
113Checking disjunctively well-founded arguments
- Cutpoints can be easily explained with
disjunctive well-foundedness
6
4
5
4
5
6
114Next
- Next
- Implementing the disjunctive rule in practice
with
115Checking disjunctively well-founded arguments
x f(x,y) g(y,x)
set 0 . . . if (!set)
if () old_x x
old_y y set 1
else assert(M1 M2 M3)
while(xlty)
set 0
116(No Transcript)
117(No Transcript)
118(No Transcript)
119(No Transcript)
120(No Transcript)
121Which programs terminate? And why?
122Which programs terminate? And why?
123Questions
- If R is well-founded, is RR?
-
124Questions
- If RR is well-founded, is R?
-
125Outline
- Foundations
- Checking termination
- Termination analysis
- Refinement synthesis
- Liveness
- Heap
- Concurrency