author | paulson |
Tue, 08 May 2001 16:01:28 +0200 | |
changeset 11289 | 65782388cf40 |
parent 9556 | dcdcfb0545e0 |
child 11701 | 3d51fbf81c17 |
permissions | -rw-r--r-- |
9243 | 1 |
(* Title: HOL/IMP/Examples.ML |
2 |
ID: $Id$ |
|
3 |
Author: David von Oheimb, TUM |
|
4 |
Copyright 2000 TUM |
|
5 |
*) |
|
6 |
||
7 |
Addsimps[update_def]; |
|
8 |
||
9556
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
9 |
section "An example due to Tony Hoare"; |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
10 |
|
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
11 |
Goal "[| !x. P x --> Q x; <w,s> -c-> t |] ==> \ |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
12 |
\ !c. w = While P c --> <While Q c,t> -c-> u --> <While Q c,s> -c-> u"; |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
13 |
by (etac evalc.induct 1); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
14 |
by (Auto_tac); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
15 |
val lemma1 = result() RS spec RS mp RS mp; |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
16 |
|
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
17 |
Goal "[| !x. P x --> Q x; <w,s> -c-> u |] ==> \ |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
18 |
\ !c. w = While Q c --> <While P c; While Q c,s> -c-> u"; |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
19 |
by (etac evalc.induct 1); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
20 |
by (ALLGOALS Asm_simp_tac); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
21 |
by (Blast_tac 1); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
22 |
by (case_tac "P s" 1); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
23 |
by (Auto_tac); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
24 |
val lemma2 = result() RS spec RS mp; |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
25 |
|
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
26 |
Goal "!x. P x --> Q x ==> \ |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
27 |
\ (<While P c; While Q c, s> -c-> t) = (<While Q c, s> -c-> t)"; |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
28 |
by (blast_tac (claset() addIs [lemma1,lemma2]) 1); |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
29 |
qed "Hoare_example"; |
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
30 |
|
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
31 |
|
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
32 |
section "Factorial"; |
9243 | 33 |
|
34 |
val step = resolve_tac evalc.intrs 1; |
|
35 |
val simp = Asm_simp_tac 1; |
|
36 |
Goalw [factorial_def] "a~=b ==> \ |
|
37 |
\ <factorial a b, Mem(a:=#3)> -c-> Mem(b:=#6,a:=#0)"; |
|
38 |
by (ftac not_sym 1); |
|
39 |
by step; |
|
40 |
by step; |
|
9556
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
41 |
by simp; |
9243 | 42 |
by step; |
43 |
by simp; |
|
44 |
by step; |
|
45 |
by step; |
|
9556
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
46 |
by simp; |
9243 | 47 |
by step; |
48 |
by simp; |
|
49 |
by step; |
|
50 |
by simp; |
|
51 |
by step; |
|
52 |
by step; |
|
9556
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
53 |
by simp; |
9243 | 54 |
by step; |
55 |
by simp; |
|
56 |
by step; |
|
57 |
by simp; |
|
58 |
by step; |
|
59 |
by step; |
|
9556
dcdcfb0545e0
moved Hoare_example to Examples; other minor improvements
oheimb
parents:
9339
diff
changeset
|
60 |
by simp; |
9243 | 61 |
by step; |
62 |
by simp; |
|
63 |
by step; |
|
64 |
by simp; |
|
65 |
qed "factorial_3"; |