author | wenzelm |
Wed, 23 Dec 2020 17:16:05 +0100 | |
changeset 72985 | 9cc431444435 |
parent 72984 | 8e99246f89c0 |
child 72987 | b1be35908165 |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Hoare/Hoare_Logic.thy |
5646 | 2 |
Author: Leonor Prensa Nieto & Tobias Nipkow |
3 |
Copyright 1998 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) |
1335 | 5 |
|
6 |
Sugared semantic embedding of Hoare logic. |
|
5646 | 7 |
Strictly speaking a shallow embedding (as implemented by Norbert Galm |
8 |
following Mike Gordon) would suffice. Maybe the datatype com comes in useful |
|
9 |
later. |
|
1335 | 10 |
*) |
11 |
||
35316
870dfea4f9c0
dropped axclass; dropped Id; session theory Hoare.thy
haftmann
parents:
35113
diff
changeset
|
12 |
theory Hoare_Logic |
72985
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
13 |
imports 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
|
14 |
begin |
1335 | 15 |
|
42174 | 16 |
type_synonym 'a bexp = "'a set" |
17 |
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
|
18 |
type_synonym 'a var = "'a \<Rightarrow> nat" |
5646 | 19 |
|
58310 | 20 |
datatype 'a com = |
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
55660
diff
changeset
|
21 |
Basic "'a \<Rightarrow> 'a" |
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
55660
diff
changeset
|
22 |
| Seq "'a com" "'a com" ("(_;/ _)" [61,60] 60) |
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
55660
diff
changeset
|
23 |
| Cond "'a bexp" "'a com" "'a com" ("(1IF _/ THEN _ / ELSE _/ FI)" [0,0,0] 61) |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
24 |
| While "'a bexp" "'a assn" "'a var" "'a com" ("(1WHILE _/ INV {_} / VAR {_} //DO _ /OD)" [0,0,0,0] 61) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
25 |
|
72984
8e99246f89c0
clarified syntax modes, avoid obsolete "xsymbols";
wenzelm
parents:
72806
diff
changeset
|
26 |
syntax |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
27 |
"_whilePC" :: "'a bexp \<Rightarrow> 'a assn \<Rightarrow> 'a com \<Rightarrow> 'a com" ("(1WHILE _/ INV {_} //DO _ /OD)" [0,0,0] 61) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
28 |
translations |
72984
8e99246f89c0
clarified syntax modes, avoid obsolete "xsymbols";
wenzelm
parents:
72806
diff
changeset
|
29 |
"WHILE b INV {x} DO c OD" \<rightharpoonup> "WHILE b INV {x} VAR {0} DO c OD" |
35113 | 30 |
|
35054 | 31 |
abbreviation annskip ("SKIP") where "SKIP == Basic id" |
5646 | 32 |
|
42174 | 33 |
type_synonym 'a sem = "'a => 'a => bool" |
5646 | 34 |
|
36643 | 35 |
inductive Sem :: "'a com \<Rightarrow> 'a sem" |
36 |
where |
|
37 |
"Sem (Basic f) s (f s)" |
|
38 |
| "Sem c1 s s'' \<Longrightarrow> Sem c2 s'' s' \<Longrightarrow> Sem (c1;c2) s s'" |
|
39 |
| "s \<in> b \<Longrightarrow> Sem c1 s s' \<Longrightarrow> Sem (IF b THEN c1 ELSE c2 FI) s s'" |
|
40 |
| "s \<notin> b \<Longrightarrow> Sem c2 s s' \<Longrightarrow> Sem (IF b THEN c1 ELSE c2 FI) s s'" |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
41 |
| "s \<notin> b \<Longrightarrow> Sem (While b x y c) s s" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
42 |
| "s \<in> b \<Longrightarrow> Sem c s s'' \<Longrightarrow> Sem (While b x y c) s'' s' \<Longrightarrow> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
43 |
Sem (While b x y c) s s'" |
5646 | 44 |
|
36643 | 45 |
inductive_cases [elim!]: |
46 |
"Sem (Basic f) s s'" "Sem (c1;c2) s s'" |
|
47 |
"Sem (IF b THEN c1 ELSE c2 FI) s s'" |
|
5646 | 48 |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
49 |
lemma Sem_deterministic: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
50 |
assumes "Sem c s s1" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
51 |
and "Sem c s s2" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
52 |
shows "s1 = s2" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
53 |
proof - |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
thus ?thesis |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
57 |
using assms by simp |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
58 |
qed |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
59 |
|
38353 | 60 |
definition Valid :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a bexp \<Rightarrow> bool" |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
61 |
where "Valid p c q \<equiv> \<forall>s s'. Sem c s s' \<longrightarrow> s \<in> p \<longrightarrow> s' \<in> q" |
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 |
definition ValidTC :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a bexp \<Rightarrow> bool" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
64 |
where "ValidTC p c q \<equiv> \<forall>s . s \<in> p \<longrightarrow> (\<exists>t . Sem c s t \<and> t \<in> q)" |
5007 | 65 |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
66 |
lemma tc_implies_pc: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
67 |
"ValidTC p c q \<Longrightarrow> Valid p c q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
68 |
by (metis Sem_deterministic Valid_def ValidTC_def) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
69 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
70 |
lemma tc_extract_function: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
71 |
"ValidTC p c q \<Longrightarrow> \<exists>f . \<forall>s . s \<in> p \<longrightarrow> f s \<in> q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
72 |
by (metis ValidTC_def) |
5007 | 73 |
|
35054 | 74 |
syntax |
42152
6c17259724b2
Hoare syntax: standard abstraction syntax admits source positions;
wenzelm
parents:
42054
diff
changeset
|
75 |
"_assign" :: "idt => 'b => 'a com" ("(2_ :=/ _)" [70, 65] 61) |
35054 | 76 |
|
77 |
syntax |
|
78 |
"_hoare_vars" :: "[idts, 'a assn,'a com,'a assn] => bool" |
|
79 |
("VARS _// {_} // _ // {_}" [0,0,55,0] 50) |
|
72984
8e99246f89c0
clarified syntax modes, avoid obsolete "xsymbols";
wenzelm
parents:
72806
diff
changeset
|
80 |
syntax (output) |
35054 | 81 |
"_hoare" :: "['a assn,'a com,'a assn] => bool" |
82 |
("{_} // _ // {_}" [0,55,0] 50) |
|
13764 | 83 |
|
69605 | 84 |
ML_file \<open>hoare_syntax.ML\<close> |
69597 | 85 |
parse_translation \<open>[(\<^syntax_const>\<open>_hoare_vars\<close>, K Hoare_Syntax.hoare_vars_tr)]\<close> |
86 |
print_translation \<open>[(\<^const_syntax>\<open>Valid\<close>, K (Hoare_Syntax.spec_tr' \<^syntax_const>\<open>_hoare\<close>))]\<close> |
|
1335 | 87 |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
88 |
syntax |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
89 |
"_hoare_tc_vars" :: "[idts, 'a assn,'a com,'a assn] => bool" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
90 |
("VARS _// [_] // _ // [_]" [0,0,55,0] 50) |
72984
8e99246f89c0
clarified syntax modes, avoid obsolete "xsymbols";
wenzelm
parents:
72806
diff
changeset
|
91 |
syntax (output) |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
92 |
"_hoare_tc" :: "['a assn,'a com,'a assn] => bool" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
93 |
("[_] // _ // [_]" [0,55,0] 50) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
94 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
95 |
parse_translation \<open>[(\<^syntax_const>\<open>_hoare_tc_vars\<close>, K Hoare_Syntax.hoare_tc_vars_tr)]\<close> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
96 |
print_translation \<open>[(\<^const_syntax>\<open>ValidTC\<close>, K (Hoare_Syntax.spec_tr' \<^syntax_const>\<open>_hoare_tc\<close>))]\<close> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
97 |
|
13682 | 98 |
|
13857 | 99 |
lemma SkipRule: "p \<subseteq> q \<Longrightarrow> Valid p (Basic id) q" |
100 |
by (auto simp:Valid_def) |
|
101 |
||
102 |
lemma BasicRule: "p \<subseteq> {s. f s \<in> q} \<Longrightarrow> Valid p (Basic f) q" |
|
103 |
by (auto simp:Valid_def) |
|
104 |
||
105 |
lemma SeqRule: "Valid P c1 Q \<Longrightarrow> Valid Q c2 R \<Longrightarrow> Valid P (c1;c2) R" |
|
106 |
by (auto simp:Valid_def) |
|
107 |
||
108 |
lemma CondRule: |
|
109 |
"p \<subseteq> {s. (s \<in> b \<longrightarrow> s \<in> w) \<and> (s \<notin> b \<longrightarrow> s \<in> w')} |
|
110 |
\<Longrightarrow> Valid w c1 q \<Longrightarrow> Valid w' c2 q \<Longrightarrow> Valid p (Cond b c1 c2) q" |
|
111 |
by (auto simp:Valid_def) |
|
112 |
||
36643 | 113 |
lemma While_aux: |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
114 |
assumes "Sem (WHILE b INV {i} VAR {v} DO c OD) s s'" |
36643 | 115 |
shows "\<forall>s s'. Sem c s s' \<longrightarrow> s \<in> I \<and> s \<in> b \<longrightarrow> s' \<in> I \<Longrightarrow> |
116 |
s \<in> I \<Longrightarrow> s' \<in> I \<and> s' \<notin> b" |
|
117 |
using assms |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
118 |
by (induct "WHILE b INV {i} VAR {v} DO c OD" s s') auto |
13857 | 119 |
|
120 |
lemma WhileRule: |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
121 |
"p \<subseteq> i \<Longrightarrow> Valid (i \<inter> b) c i \<Longrightarrow> i \<inter> (-b) \<subseteq> q \<Longrightarrow> Valid p (While b i v c) q" |
13857 | 122 |
apply (clarsimp simp:Valid_def) |
36643 | 123 |
apply(drule While_aux) |
124 |
apply assumption |
|
13857 | 125 |
apply blast |
126 |
apply blast |
|
127 |
done |
|
128 |
||
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
129 |
lemma SkipRuleTC: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
130 |
assumes "p \<subseteq> q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
131 |
shows "ValidTC p (Basic id) q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
132 |
by (metis assms Sem.intros(1) ValidTC_def id_apply subsetD) |
13857 | 133 |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
134 |
lemma BasicRuleTC: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
135 |
assumes "p \<subseteq> {s. f s \<in> q}" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
136 |
shows "ValidTC p (Basic f) q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
137 |
by (metis assms Ball_Collect Sem.intros(1) ValidTC_def) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
138 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
139 |
lemma SeqRuleTC: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
140 |
assumes "ValidTC p c1 q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
141 |
and "ValidTC q c2 r" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
142 |
shows "ValidTC p (c1;c2) r" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
143 |
by (meson assms Sem.intros(2) ValidTC_def) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
144 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
145 |
lemma CondRuleTC: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
146 |
assumes "p \<subseteq> {s. (s \<in> b \<longrightarrow> s \<in> w) \<and> (s \<notin> b \<longrightarrow> s \<in> w')}" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
147 |
and "ValidTC w c1 q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
148 |
and "ValidTC w' c2 q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
149 |
shows "ValidTC p (Cond b c1 c2) q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
150 |
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
|
151 |
fix s |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
152 |
show "s \<in> p \<longrightarrow> (\<exists>t . Sem (Cond b c1 c2) s t \<and> t \<in> q)" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
153 |
apply (cases "s \<in> b") |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
154 |
apply (metis (mono_tags, lifting) assms(1,2) Ball_Collect Sem.intros(3) ValidTC_def) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
155 |
by (metis (mono_tags, lifting) assms(1,3) Ball_Collect Sem.intros(4) ValidTC_def) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
156 |
qed |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
157 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
158 |
lemma WhileRuleTC: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
159 |
assumes "p \<subseteq> i" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
160 |
and "\<And>n::nat . ValidTC (i \<inter> b \<inter> {s . v s = n}) c (i \<inter> {s . v s < n})" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
161 |
and "i \<inter> uminus b \<subseteq> q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
162 |
shows "ValidTC p (While b i v c) q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
163 |
proof - |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
164 |
{ |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
165 |
fix s n |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
166 |
have "s \<in> i \<and> v s = n \<longrightarrow> (\<exists>t . Sem (While b i v c) s t \<and> t \<in> q)" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
167 |
proof (induction "n" arbitrary: s rule: less_induct) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
168 |
fix n :: nat |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
169 |
fix s :: 'a |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
170 |
assume 1: "\<And>(m::nat) s::'a . m < n \<Longrightarrow> s \<in> i \<and> v s = m \<longrightarrow> (\<exists>t . Sem (While b i v c) s t \<and> t \<in> q)" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
171 |
show "s \<in> i \<and> v s = n \<longrightarrow> (\<exists>t . Sem (While b i v c) s t \<and> t \<in> q)" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
172 |
proof (rule impI, cases "s \<in> b") |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
173 |
assume 2: "s \<in> b" and "s \<in> i \<and> v s = n" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
174 |
hence "s \<in> i \<inter> b \<inter> {s . v s = n}" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
175 |
using assms(1) by auto |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
176 |
hence "\<exists>t . Sem c s t \<and> t \<in> i \<inter> {s . v s < n}" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
177 |
by (metis assms(2) ValidTC_def) |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
178 |
from this obtain t where 3: "Sem c s t \<and> t \<in> i \<inter> {s . v s < n}" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
179 |
by auto |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
180 |
hence "\<exists>u . Sem (While b i v c) t u \<and> u \<in> q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
181 |
using 1 by auto |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
182 |
thus "\<exists>t . Sem (While b i v c) s t \<and> t \<in> q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
183 |
using 2 3 Sem.intros(6) by force |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
184 |
next |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
185 |
assume "s \<notin> b" and "s \<in> i \<and> v s = n" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
186 |
thus "\<exists>t . Sem (While b i v c) s t \<and> t \<in> q" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
187 |
using Sem.intros(5) assms(3) by fastforce |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
188 |
qed |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
189 |
qed |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
190 |
} |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
191 |
thus ?thesis |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
192 |
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
|
193 |
qed |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
194 |
|
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
|
195 |
|
72985
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
196 |
declare BasicRule [Hoare_Tac.BasicRule] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
197 |
and SkipRule [Hoare_Tac.SkipRule] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
198 |
and SeqRule [Hoare_Tac.SeqRule] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
199 |
and CondRule [Hoare_Tac.CondRule] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
200 |
and WhileRule [Hoare_Tac.WhileRule] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
201 |
|
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
202 |
declare BasicRuleTC [Hoare_Tac.BasicRuleTC] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
203 |
and SkipRuleTC [Hoare_Tac.SkipRuleTC] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
204 |
and SeqRuleTC [Hoare_Tac.SeqRuleTC] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
205 |
and CondRuleTC [Hoare_Tac.CondRuleTC] |
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
206 |
and WhileRuleTC [Hoare_Tac.WhileRuleTC] |
13682 | 207 |
|
62042 | 208 |
method_setup vcg = \<open> |
72985
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
209 |
Scan.succeed (fn ctxt => SIMPLE_METHOD' (Hoare_Tac.hoare_tac ctxt (K all_tac)))\<close> |
13682 | 210 |
"verification condition generator" |
211 |
||
62042 | 212 |
method_setup vcg_simp = \<open> |
30549 | 213 |
Scan.succeed (fn ctxt => |
72985
9cc431444435
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72984
diff
changeset
|
214 |
SIMPLE_METHOD' (Hoare_Tac.hoare_tac ctxt (asm_full_simp_tac ctxt)))\<close> |
13682 | 215 |
"verification condition generator plus simplification" |
216 |
||
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
217 |
method_setup vcg_tc = \<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_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
|
219 |
"verification condition generator" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
220 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
221 |
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
|
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_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
|
224 |
"verification condition generator plus simplification" |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69605
diff
changeset
|
225 |
|
13682 | 226 |
end |