896
|
1 |
(* $Id$ *)
|
|
2 |
|
244
|
3 |
Proves about loops and tail-recursive functions
|
|
4 |
===============================================
|
|
5 |
|
|
6 |
Problem A
|
|
7 |
|
|
8 |
P = while B1 do S od
|
|
9 |
Q = while B1 or B2 do S od
|
|
10 |
|
|
11 |
Prove P;Q = Q (provided B1, B2 have no side effects)
|
|
12 |
|
|
13 |
------
|
|
14 |
|
|
15 |
Looking at the denotational semantics of while, we get
|
|
16 |
|
|
17 |
Problem B
|
|
18 |
|
|
19 |
[|B1|]:State->Bool
|
|
20 |
[|B2|]:State->Bool
|
|
21 |
[|S |]:State->State
|
|
22 |
f :State->State
|
|
23 |
|
|
24 |
p = fix LAM f.LAM x. if [| B1 |] x then f([| S |] x) else x fi
|
|
25 |
q = fix LAM f.LAM x. if [| B1 |] x orelse [|b2 |] x then f([| S |] x) else x fi
|
|
26 |
|
|
27 |
Prove q o p = q rsp. ALL x.q(p(x))=q(x)
|
|
28 |
|
|
29 |
Remark: 1. Bool is the three-valued domain {UU,FF,TT} since tests B1 and B2 may
|
|
30 |
not terminate.
|
|
31 |
2. orelse is the sequential or like in ML
|
|
32 |
|
|
33 |
----------
|
|
34 |
|
|
35 |
If we abstract over the structure of stores we get
|
|
36 |
|
|
37 |
Problem C
|
|
38 |
|
|
39 |
b1:'a -> Bool
|
|
40 |
b2:'a -> Bool
|
|
41 |
g :'a ->'a
|
|
42 |
h :'a ->'a
|
|
43 |
|
|
44 |
p = fix LAM h.LAM x. if b1(x) then h(g(x)) else x fi
|
|
45 |
q = fix LAM h.LAM x. if b1(x) orelse b2(x) then h(g(x)) else x fi
|
|
46 |
|
|
47 |
where g is an abstraction of [| S |]
|
|
48 |
|
|
49 |
Prove q o p = q
|
|
50 |
|
|
51 |
Remark: there are no restrictions wrt. definedness or strictness for any of
|
|
52 |
the involved functions.
|
|
53 |
|
|
54 |
----------
|
|
55 |
|
|
56 |
In a functional programming language the problem reads as follows:
|
|
57 |
|
|
58 |
p(x) = if b1(x)
|
|
59 |
then p(g(x))
|
|
60 |
else x fi
|
|
61 |
|
|
62 |
q(x) = if b1(x) orelse b2(x)
|
|
63 |
then q(g(x))
|
|
64 |
else x fi
|
|
65 |
|
|
66 |
|
|
67 |
Prove: q o p = q
|
|
68 |
|
|
69 |
|
|
70 |
-------------
|
|
71 |
|
|
72 |
In you like to test the problem in ML (bad guy) you have to introduce
|
|
73 |
formal parameters for b1,b2 and g.
|
|
74 |
|
|
75 |
fun p b1 g x = if b1(x)
|
|
76 |
then p b1 g (g(x))
|
|
77 |
else x;
|
|
78 |
|
|
79 |
|
|
80 |
fun q b1 b2 g x = if b1(x) orelse b2(x)
|
|
81 |
then q b1 b2 g (g(x))
|
|
82 |
else x;
|
|
83 |
|
|
84 |
Prove: for all b1 b2 g .
|
|
85 |
(q b1 b2 g) o (p b1 g) = (q b1 b2 g)
|
|
86 |
|
|
87 |
===========
|
|
88 |
|
|
89 |
It took 4 person-days to formulate and prove the problem C in the
|
|
90 |
Isabelle logic HOLCF. The formalisation was done by conservative extension and
|
|
91 |
all proof principles where derived from pure HOLCF.
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|