9448
|
1 |
(* Title: HOL/While
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow
|
|
4 |
Copyright 2000 TU Muenchen
|
|
5 |
|
|
6 |
Defines a while-combinator "while" and proves
|
|
7 |
a) an unrestricted unfolding law (even if while diverges!)
|
|
8 |
(I got this idea from Wolfgang Goerigk)
|
|
9 |
b) the invariant rule for reasoning about while
|
|
10 |
*)
|
|
11 |
|
|
12 |
While = Recdef +
|
|
13 |
|
|
14 |
consts while_aux :: "('a => bool) * ('a => 'a) * 'a => 'a"
|
|
15 |
recdef while_aux
|
|
16 |
"same_fst (%b. True) (%b. same_fst (%c. True) (%c.
|
|
17 |
{(t,s). b s & c s = t &
|
|
18 |
~(? f. f 0 = s & (!i. b(f i) & c(f i) = f(i+1)))}))"
|
|
19 |
"while_aux(b,c,s) =
|
|
20 |
(if (? f. f 0 = s & (!i. b(f i) & c(f i) = f(i+1)))
|
|
21 |
then arbitrary
|
|
22 |
else if b s then while_aux(b,c,c s) else s)"
|
|
23 |
|
|
24 |
constdefs
|
|
25 |
while :: "('a => bool) => ('a => 'a) => 'a => 'a"
|
|
26 |
"while b c s == while_aux(b,c,s)"
|
|
27 |
|
|
28 |
end
|