| author | wenzelm | 
| Mon, 14 Jul 2025 11:18:10 +0200 | |
| changeset 82864 | 2703f19d323e | 
| parent 81191 | 60f46822a22c | 
| permissions | -rw-r--r-- | 
| 41959 | 1  | 
(* Title: HOL/Hoare/Hoare_Logic_Abort.thy  | 
| 13857 | 2  | 
Author: Leonor Prensa Nieto & Tobias Nipkow  | 
3  | 
Copyright 2003 TUM  | 
|
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
4  | 
Author: Walter Guttmann (extension to total-correctness proofs)  | 
| 13857 | 5  | 
*)  | 
6  | 
||
| 
72987
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
7  | 
section \<open>Hoare Logic with an Abort statement for modelling run time errors\<close>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
8  | 
|
| 
35320
 
f80aee1ed475
dropped axclass; dropped Id; session theory Hoare.thy
 
haftmann 
parents: 
35113 
diff
changeset
 | 
9  | 
theory Hoare_Logic_Abort  | 
| 72990 | 10  | 
imports Hoare_Syntax Hoare_Tac  | 
| 
24470
 
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
 
wenzelm 
parents: 
21588 
diff
changeset
 | 
11  | 
begin  | 
| 13857 | 12  | 
|
| 42174 | 13  | 
type_synonym 'a bexp = "'a set"  | 
14  | 
type_synonym 'a assn = "'a set"  | 
|
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
15  | 
type_synonym 'a var = "'a \<Rightarrow> nat"  | 
| 13857 | 16  | 
|
| 58310 | 17  | 
datatype 'a com =  | 
| 
58305
 
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
 
blanchet 
parents: 
55660 
diff
changeset
 | 
18  | 
Basic "'a \<Rightarrow> 'a"  | 
| 
 
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
 
blanchet 
parents: 
55660 
diff
changeset
 | 
19  | 
| Abort  | 
| 
72987
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
20  | 
| Seq "'a com" "'a com"  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
21  | 
| Cond "'a bexp" "'a com" "'a com"  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
22  | 
| While "'a bexp" "'a com"  | 
| 35113 | 23  | 
|
| 
80914
 
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
 
wenzelm 
parents: 
74503 
diff
changeset
 | 
24  | 
abbreviation annskip (\<open>SKIP\<close>) where "SKIP == Basic id"  | 
| 13857 | 25  | 
|
| 42174 | 26  | 
type_synonym 'a sem = "'a option => 'a option => bool"  | 
| 13857 | 27  | 
|
| 36643 | 28  | 
inductive Sem :: "'a com \<Rightarrow> 'a sem"  | 
29  | 
where  | 
|
30  | 
"Sem (Basic f) None None"  | 
|
31  | 
| "Sem (Basic f) (Some s) (Some (f s))"  | 
|
32  | 
| "Sem Abort s None"  | 
|
| 
72987
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
33  | 
| "Sem c1 s s'' \<Longrightarrow> Sem c2 s'' s' \<Longrightarrow> Sem (Seq c1 c2) s s'"  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
34  | 
| "Sem (Cond b c1 c2) None None"  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
35  | 
| "s \<in> b \<Longrightarrow> Sem c1 (Some s) s' \<Longrightarrow> Sem (Cond b c1 c2) (Some s) s'"  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
36  | 
| "s \<notin> b \<Longrightarrow> Sem c2 (Some s) s' \<Longrightarrow> Sem (Cond b c1 c2) (Some s) s'"  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
37  | 
| "Sem (While b c) None None"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
38  | 
| "s \<notin> b \<Longrightarrow> Sem (While b c) (Some s) (Some s)"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
39  | 
| "s \<in> b \<Longrightarrow> Sem c (Some s) s'' \<Longrightarrow> Sem (While b c) s'' s' \<Longrightarrow>  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
40  | 
Sem (While b c) (Some s) s'"  | 
| 13857 | 41  | 
|
| 36643 | 42  | 
inductive_cases [elim!]:  | 
| 
72987
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
43  | 
"Sem (Basic f) s s'" "Sem (Seq c1 c2) s s'"  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
44  | 
"Sem (Cond b c1 c2) s s'"  | 
| 13857 | 45  | 
|
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
46  | 
lemma Sem_deterministic:  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
47  | 
assumes "Sem c s s1"  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
48  | 
and "Sem c s s2"  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
49  | 
shows "s1 = s2"  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
50  | 
proof -  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
51  | 
have "Sem c s s1 \<Longrightarrow> (\<forall>s2. Sem c s s2 \<longrightarrow> s1 = s2)"  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
52  | 
by (induct rule: Sem.induct) (subst Sem.simps, blast)+  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
53  | 
thus ?thesis  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
54  | 
using assms by simp  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
55  | 
qed  | 
| 13857 | 56  | 
|
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
57  | 
definition Valid :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a anno \<Rightarrow> 'a bexp \<Rightarrow> bool"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
58  | 
where "Valid p c a q \<equiv> \<forall>s s'. Sem c s s' \<longrightarrow> s \<in> Some ` p \<longrightarrow> s' \<in> Some ` q"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
59  | 
|
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
60  | 
definition ValidTC :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a anno \<Rightarrow> 'a bexp \<Rightarrow> bool"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
61  | 
where "ValidTC p c a q \<equiv> \<forall>s . s \<in> p \<longrightarrow> (\<exists>t . Sem c (Some s) (Some t) \<and> t \<in> q)"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
62  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
63  | 
lemma tc_implies_pc:  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
64  | 
"ValidTC p c a q \<Longrightarrow> Valid p c a q"  | 
| 
73655
 
26a1d66b9077
tuned proofs --- avoid z3, which is absent on arm64-linux;
 
wenzelm 
parents: 
72990 
diff
changeset
 | 
65  | 
by (smt (verit) Sem_deterministic ValidTC_def Valid_def image_iff)  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
66  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
67  | 
lemma tc_extract_function:  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
68  | 
"ValidTC p c a q \<Longrightarrow> \<exists>f . \<forall>s . s \<in> p \<longrightarrow> f s \<in> q"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
69  | 
by (meson ValidTC_def)  | 
| 13857 | 70  | 
|
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
71  | 
text \<open>The proof rules for partial correctness\<close>  | 
| 13857 | 72  | 
|
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
73  | 
lemma SkipRule: "p \<subseteq> q \<Longrightarrow> Valid p (Basic id) a q"  | 
| 13857 | 74  | 
by (auto simp:Valid_def)  | 
75  | 
||
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
76  | 
lemma BasicRule: "p \<subseteq> {s. f s \<in> q} \<Longrightarrow> Valid p (Basic f) a q"
 | 
| 13857 | 77  | 
by (auto simp:Valid_def)  | 
78  | 
||
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
79  | 
lemma SeqRule: "Valid P c1 a1 Q \<Longrightarrow> Valid Q c2 a2 R \<Longrightarrow> Valid P (Seq c1 c2) (Aseq a1 a2) R"  | 
| 13857 | 80  | 
by (auto simp:Valid_def)  | 
81  | 
||
82  | 
lemma CondRule:  | 
|
83  | 
 "p \<subseteq> {s. (s \<in> b \<longrightarrow> s \<in> w) \<and> (s \<notin> b \<longrightarrow> s \<in> w')}
 | 
|
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
84  | 
\<Longrightarrow> Valid w c1 a1 q \<Longrightarrow> Valid w' c2 a2 q \<Longrightarrow> Valid p (Cond b c1 c2) (Acond a1 a2) q"  | 
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42174 
diff
changeset
 | 
85  | 
by (fastforce simp:Valid_def image_def)  | 
| 13857 | 86  | 
|
| 36643 | 87  | 
lemma While_aux:  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
88  | 
assumes "Sem (While b c) s s'"  | 
| 36643 | 89  | 
shows "\<forall>s s'. Sem c s s' \<longrightarrow> s \<in> Some ` (I \<inter> b) \<longrightarrow> s' \<in> Some ` I \<Longrightarrow>  | 
90  | 
s \<in> Some ` I \<Longrightarrow> s' \<in> Some ` (I \<inter> -b)"  | 
|
91  | 
using assms  | 
|
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
92  | 
by (induct "While b c" s s') auto  | 
| 13857 | 93  | 
|
94  | 
lemma WhileRule:  | 
|
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
95  | 
"p \<subseteq> i \<Longrightarrow> Valid (i \<inter> b) c (A 0) i \<Longrightarrow> i \<inter> (-b) \<subseteq> q \<Longrightarrow> Valid p (While b c) (Awhile i v A) q"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
96  | 
apply (clarsimp simp:Valid_def)  | 
| 36643 | 97  | 
apply(drule While_aux)  | 
98  | 
apply assumption  | 
|
| 13857 | 99  | 
apply blast  | 
100  | 
apply blast  | 
|
101  | 
done  | 
|
102  | 
||
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
103  | 
lemma AbortRule: "p \<subseteq> {s. False} \<Longrightarrow> Valid p Abort a q"
 | 
| 13857 | 104  | 
by(auto simp:Valid_def)  | 
105  | 
||
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
106  | 
text \<open>The proof rules for total correctness\<close>  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
107  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
108  | 
lemma SkipRuleTC:  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
109  | 
assumes "p \<subseteq> q"  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
110  | 
shows "ValidTC p (Basic id) a q"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
111  | 
by (metis Sem.intros(2) ValidTC_def assms id_def subsetD)  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
112  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
113  | 
lemma BasicRuleTC:  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
114  | 
  assumes "p \<subseteq> {s. f s \<in> q}"
 | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
115  | 
shows "ValidTC p (Basic f) a q"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
116  | 
by (metis Ball_Collect Sem.intros(2) ValidTC_def assms)  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
117  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
118  | 
lemma SeqRuleTC:  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
119  | 
assumes "ValidTC p c1 a1 q"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
120  | 
and "ValidTC q c2 a2 r"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
121  | 
shows "ValidTC p (Seq c1 c2) (Aseq a1 a2) r"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
122  | 
by (meson assms Sem.intros(4) ValidTC_def)  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
123  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
124  | 
lemma CondRuleTC:  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
125  | 
 assumes "p \<subseteq> {s. (s \<in> b \<longrightarrow> s \<in> w) \<and> (s \<notin> b \<longrightarrow> s \<in> w')}"
 | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
126  | 
and "ValidTC w c1 a1 q"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
127  | 
and "ValidTC w' c2 a2 q"  | 
| 
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
128  | 
shows "ValidTC p (Cond b c1 c2) (Acons a1 a2) q"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
129  | 
proof (unfold ValidTC_def, rule allI)  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
130  | 
fix s  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
131  | 
show "s \<in> p \<longrightarrow> (\<exists>t . Sem (Cond b c1 c2) (Some s) (Some t) \<and> t \<in> q)"  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
132  | 
apply (cases "s \<in> b")  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
133  | 
apply (metis (mono_tags, lifting) Ball_Collect Sem.intros(6) ValidTC_def assms(1,2))  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
134  | 
by (metis (mono_tags, lifting) Ball_Collect Sem.intros(7) ValidTC_def assms(1,3))  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
135  | 
qed  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
136  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
137  | 
lemma WhileRuleTC:  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
138  | 
assumes "p \<subseteq> i"  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
139  | 
      and "\<And>n::nat . ValidTC (i \<inter> b \<inter> {s . v s = n}) c (A n) (i \<inter> {s . v s < n})"
 | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
140  | 
and "i \<inter> uminus b \<subseteq> q"  | 
| 
74503
 
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
 
nipkow 
parents: 
73655 
diff
changeset
 | 
141  | 
shows "ValidTC p (While b c) (Awhile i v A) q"  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
142  | 
proof -  | 
| 81191 | 143  | 
have "s \<in> i \<and> v s = n \<longrightarrow> (\<exists>t . Sem (While b c) (Some s) (Some t) \<and> t \<in> q)" for s n  | 
144  | 
proof (induction "n" arbitrary: s rule: less_induct)  | 
|
145  | 
fix n :: nat  | 
|
146  | 
fix s :: 'a  | 
|
147  | 
assume 1: "\<And>(m::nat) s::'a . m < n \<Longrightarrow> s \<in> i \<and> v s = m \<longrightarrow> (\<exists>t . Sem (While b c) (Some s) (Some t) \<and> t \<in> q)"  | 
|
148  | 
show "s \<in> i \<and> v s = n \<longrightarrow> (\<exists>t . Sem (While b c) (Some s) (Some t) \<and> t \<in> q)"  | 
|
149  | 
proof (rule impI, cases "s \<in> b")  | 
|
150  | 
assume 2: "s \<in> b" and "s \<in> i \<and> v s = n"  | 
|
151  | 
      hence "s \<in> i \<inter> b \<inter> {s . v s = n}"
 | 
|
152  | 
using assms(1) by auto  | 
|
153  | 
      hence "\<exists>t . Sem c (Some s) (Some t) \<and> t \<in> i \<inter> {s . v s < n}"
 | 
|
154  | 
by (metis assms(2) ValidTC_def)  | 
|
155  | 
      from this obtain t where 3: "Sem c (Some s) (Some t) \<and> t \<in> i \<inter> {s . v s < n}"
 | 
|
156  | 
by auto  | 
|
157  | 
hence "\<exists>u . Sem (While b c) (Some t) (Some u) \<and> u \<in> q"  | 
|
158  | 
using 1 by auto  | 
|
159  | 
thus "\<exists>t . Sem (While b c) (Some s) (Some t) \<and> t \<in> q"  | 
|
160  | 
using 2 3 Sem.intros(10) by force  | 
|
161  | 
next  | 
|
162  | 
assume "s \<notin> b" and "s \<in> i \<and> v s = n"  | 
|
163  | 
thus "\<exists>t . Sem (While b c) (Some s) (Some t) \<and> t \<in> q"  | 
|
164  | 
using Sem.intros(9) assms(3) by fastforce  | 
|
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
165  | 
qed  | 
| 81191 | 166  | 
qed  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
167  | 
thus ?thesis  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
168  | 
using assms(1) ValidTC_def by force  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
169  | 
qed  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
170  | 
|
| 
24470
 
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
 
wenzelm 
parents: 
21588 
diff
changeset
 | 
171  | 
|
| 
72987
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
172  | 
subsection \<open>Concrete syntax\<close>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
173  | 
|
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
174  | 
setup \<open>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
175  | 
Hoare_Syntax.setup  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
176  | 
   {Basic = \<^const_syntax>\<open>Basic\<close>,
 | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
177  | 
Skip = \<^const_syntax>\<open>annskip\<close>,  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
178  | 
Seq = \<^const_syntax>\<open>Seq\<close>,  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
179  | 
Cond = \<^const_syntax>\<open>Cond\<close>,  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
180  | 
While = \<^const_syntax>\<open>While\<close>,  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
181  | 
Valid = \<^const_syntax>\<open>Valid\<close>,  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
182  | 
ValidTC = \<^const_syntax>\<open>ValidTC\<close>}  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
183  | 
\<close>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
184  | 
|
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
185  | 
\<comment> \<open>Special syntax for guarded statements and guarded array updates:\<close>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
186  | 
syntax  | 
| 81189 | 187  | 
"_guarded_com" :: "bool \<Rightarrow> 'a com \<Rightarrow> 'a com"  | 
188  | 
(\<open>(\<open>indent=2 notation=\<open>mixfix Hoare guarded statement\<close>\<close>_ \<rightarrow>/ _)\<close> 71)  | 
|
189  | 
"_array_update" :: "'a list \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> 'a com"  | 
|
190  | 
(\<open>(\<open>indent=2 notation=\<open>mixfix Hoare array update\<close>\<close>_[_] :=/ _)\<close> [70, 65] 61)  | 
|
| 
72987
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
191  | 
translations  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
192  | 
"P \<rightarrow> c" \<rightleftharpoons> "IF P THEN c ELSE CONST Abort FI"  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
193  | 
"a[i] := v" \<rightharpoonup> "(i < CONST length a) \<rightarrow> (a := CONST list_update a i v)"  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
194  | 
\<comment> \<open>reverse translation not possible because of duplicate \<open>a\<close>\<close>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
195  | 
|
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
196  | 
text \<open>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
197  | 
Note: there is no special syntax for guarded array access. Thus  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
198  | 
you must write \<open>j < length a \<rightarrow> a[i] := a!j\<close>.  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
199  | 
\<close>  | 
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
200  | 
|
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
201  | 
|
| 
 
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72985 
diff
changeset
 | 
202  | 
subsection \<open>Proof methods: VCG\<close>  | 
| 
24470
 
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
 
wenzelm 
parents: 
21588 
diff
changeset
 | 
203  | 
|
| 
72985
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
204  | 
declare BasicRule [Hoare_Tac.BasicRule]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
205  | 
and SkipRule [Hoare_Tac.SkipRule]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
206  | 
and AbortRule [Hoare_Tac.AbortRule]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
207  | 
and SeqRule [Hoare_Tac.SeqRule]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
208  | 
and CondRule [Hoare_Tac.CondRule]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
209  | 
and WhileRule [Hoare_Tac.WhileRule]  | 
| 
24470
 
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
 
wenzelm 
parents: 
21588 
diff
changeset
 | 
210  | 
|
| 
72985
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
211  | 
declare BasicRuleTC [Hoare_Tac.BasicRuleTC]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
212  | 
and SkipRuleTC [Hoare_Tac.SkipRuleTC]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
213  | 
and SeqRuleTC [Hoare_Tac.SeqRuleTC]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
214  | 
and CondRuleTC [Hoare_Tac.CondRuleTC]  | 
| 
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
215  | 
and WhileRuleTC [Hoare_Tac.WhileRuleTC]  | 
| 13857 | 216  | 
|
| 62042 | 217  | 
method_setup vcg = \<open>  | 
| 
72985
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
218  | 
Scan.succeed (fn ctxt => SIMPLE_METHOD' (Hoare_Tac.hoare_tac ctxt (K all_tac)))\<close>  | 
| 13857 | 219  | 
"verification condition generator"  | 
220  | 
||
| 62042 | 221  | 
method_setup vcg_simp = \<open>  | 
| 30549 | 222  | 
Scan.succeed (fn ctxt =>  | 
| 
72985
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
223  | 
SIMPLE_METHOD' (Hoare_Tac.hoare_tac ctxt (asm_full_simp_tac ctxt)))\<close>  | 
| 13857 | 224  | 
"verification condition generator plus simplification"  | 
225  | 
||
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
226  | 
method_setup vcg_tc = \<open>  | 
| 
72985
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
227  | 
Scan.succeed (fn ctxt => SIMPLE_METHOD' (Hoare_Tac.hoare_tc_tac ctxt (K all_tac)))\<close>  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
228  | 
"verification condition generator"  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
229  | 
|
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
230  | 
method_setup vcg_tc_simp = \<open>  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
231  | 
Scan.succeed (fn ctxt =>  | 
| 
72985
 
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
 
wenzelm 
parents: 
72984 
diff
changeset
 | 
232  | 
SIMPLE_METHOD' (Hoare_Tac.hoare_tc_tac ctxt (asm_full_simp_tac ctxt)))\<close>  | 
| 
72806
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
233  | 
"verification condition generator plus simplification"  | 
| 
 
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
 
nipkow 
parents: 
69605 
diff
changeset
 | 
234  | 
|
| 13857 | 235  | 
end  |