author | hoelzl |
Mon, 03 Dec 2012 18:19:08 +0100 | |
changeset 50328 | 25b1e8686ce0 |
parent 48891 | c0eafbd55de3 |
child 51717 | 9e7d1c139569 |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Hoare/Hoare_Logic.thy |
5646 | 2 |
Author: Leonor Prensa Nieto & Tobias Nipkow |
3 |
Copyright 1998 TUM |
|
1335 | 4 |
|
5 |
Sugared semantic embedding of Hoare logic. |
|
5646 | 6 |
Strictly speaking a shallow embedding (as implemented by Norbert Galm |
7 |
following Mike Gordon) would suffice. Maybe the datatype com comes in useful |
|
8 |
later. |
|
1335 | 9 |
*) |
10 |
||
35316
870dfea4f9c0
dropped axclass; dropped Id; session theory Hoare.thy
haftmann
parents:
35113
diff
changeset
|
11 |
theory Hoare_Logic |
28457
25669513fd4c
major cleanup of hoare_tac.ML: just one copy for Hoare.thy and HoareAbort.thy (only 1 line different), refrain from inspecting the main goal, proper context;
wenzelm
parents:
24472
diff
changeset
|
12 |
imports Main |
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
|
13 |
begin |
1335 | 14 |
|
42174 | 15 |
type_synonym 'a bexp = "'a set" |
16 |
type_synonym 'a assn = "'a set" |
|
5646 | 17 |
|
18 |
datatype |
|
35113 | 19 |
'a com = Basic "'a \<Rightarrow> 'a" |
13682 | 20 |
| Seq "'a com" "'a com" ("(_;/ _)" [61,60] 60) |
21 |
| Cond "'a bexp" "'a com" "'a com" ("(1IF _/ THEN _ / ELSE _/ FI)" [0,0,0] 61) |
|
22 |
| While "'a bexp" "'a assn" "'a com" ("(1WHILE _/ INV {_} //DO _ /OD)" [0,0,0] 61) |
|
35113 | 23 |
|
35054 | 24 |
abbreviation annskip ("SKIP") where "SKIP == Basic id" |
5646 | 25 |
|
42174 | 26 |
type_synonym 'a sem = "'a => 'a => bool" |
5646 | 27 |
|
36643 | 28 |
inductive Sem :: "'a com \<Rightarrow> 'a sem" |
29 |
where |
|
30 |
"Sem (Basic f) s (f s)" |
|
31 |
| "Sem c1 s s'' \<Longrightarrow> Sem c2 s'' s' \<Longrightarrow> Sem (c1;c2) s s'" |
|
32 |
| "s \<in> b \<Longrightarrow> Sem c1 s s' \<Longrightarrow> Sem (IF b THEN c1 ELSE c2 FI) s s'" |
|
33 |
| "s \<notin> b \<Longrightarrow> Sem c2 s s' \<Longrightarrow> Sem (IF b THEN c1 ELSE c2 FI) s s'" |
|
34 |
| "s \<notin> b \<Longrightarrow> Sem (While b x c) s s" |
|
35 |
| "s \<in> b \<Longrightarrow> Sem c s s'' \<Longrightarrow> Sem (While b x c) s'' s' \<Longrightarrow> |
|
36 |
Sem (While b x c) s s'" |
|
5646 | 37 |
|
36643 | 38 |
inductive_cases [elim!]: |
39 |
"Sem (Basic f) s s'" "Sem (c1;c2) s s'" |
|
40 |
"Sem (IF b THEN c1 ELSE c2 FI) s s'" |
|
5646 | 41 |
|
38353 | 42 |
definition Valid :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a bexp \<Rightarrow> bool" |
43 |
where "Valid p c q \<longleftrightarrow> (!s s'. Sem c s s' --> s : p --> s' : q)" |
|
5007 | 44 |
|
45 |
||
35054 | 46 |
syntax |
42152
6c17259724b2
Hoare syntax: standard abstraction syntax admits source positions;
wenzelm
parents:
42054
diff
changeset
|
47 |
"_assign" :: "idt => 'b => 'a com" ("(2_ :=/ _)" [70, 65] 61) |
35054 | 48 |
|
49 |
syntax |
|
50 |
"_hoare_vars" :: "[idts, 'a assn,'a com,'a assn] => bool" |
|
51 |
("VARS _// {_} // _ // {_}" [0,0,55,0] 50) |
|
52 |
syntax ("" output) |
|
53 |
"_hoare" :: "['a assn,'a com,'a assn] => bool" |
|
54 |
("{_} // _ // {_}" [0,55,0] 50) |
|
13764 | 55 |
|
48891 | 56 |
ML_file "hoare_syntax.ML" |
42153 | 57 |
parse_translation {* [(@{syntax_const "_hoare_vars"}, Hoare_Syntax.hoare_vars_tr)] *} |
58 |
print_translation {* [(@{const_syntax Valid}, Hoare_Syntax.spec_tr' @{syntax_const "_hoare"})] *} |
|
1335 | 59 |
|
13682 | 60 |
|
13857 | 61 |
lemma SkipRule: "p \<subseteq> q \<Longrightarrow> Valid p (Basic id) q" |
62 |
by (auto simp:Valid_def) |
|
63 |
||
64 |
lemma BasicRule: "p \<subseteq> {s. f s \<in> q} \<Longrightarrow> Valid p (Basic f) q" |
|
65 |
by (auto simp:Valid_def) |
|
66 |
||
67 |
lemma SeqRule: "Valid P c1 Q \<Longrightarrow> Valid Q c2 R \<Longrightarrow> Valid P (c1;c2) R" |
|
68 |
by (auto simp:Valid_def) |
|
69 |
||
70 |
lemma CondRule: |
|
71 |
"p \<subseteq> {s. (s \<in> b \<longrightarrow> s \<in> w) \<and> (s \<notin> b \<longrightarrow> s \<in> w')} |
|
72 |
\<Longrightarrow> Valid w c1 q \<Longrightarrow> Valid w' c2 q \<Longrightarrow> Valid p (Cond b c1 c2) q" |
|
73 |
by (auto simp:Valid_def) |
|
74 |
||
36643 | 75 |
lemma While_aux: |
76 |
assumes "Sem (WHILE b INV {i} DO c OD) s s'" |
|
77 |
shows "\<forall>s s'. Sem c s s' \<longrightarrow> s \<in> I \<and> s \<in> b \<longrightarrow> s' \<in> I \<Longrightarrow> |
|
78 |
s \<in> I \<Longrightarrow> s' \<in> I \<and> s' \<notin> b" |
|
79 |
using assms |
|
80 |
by (induct "WHILE b INV {i} DO c OD" s s') auto |
|
13857 | 81 |
|
82 |
lemma WhileRule: |
|
83 |
"p \<subseteq> i \<Longrightarrow> Valid (i \<inter> b) c i \<Longrightarrow> i \<inter> (-b) \<subseteq> q \<Longrightarrow> Valid p (While b i c) q" |
|
84 |
apply (clarsimp simp:Valid_def) |
|
36643 | 85 |
apply(drule While_aux) |
86 |
apply assumption |
|
13857 | 87 |
apply blast |
88 |
apply blast |
|
89 |
done |
|
90 |
||
91 |
||
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
|
92 |
lemma Compl_Collect: "-(Collect b) = {x. ~(b x)}" |
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
|
93 |
by blast |
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
|
94 |
|
28457
25669513fd4c
major cleanup of hoare_tac.ML: just one copy for Hoare.thy and HoareAbort.thy (only 1 line different), refrain from inspecting the main goal, proper context;
wenzelm
parents:
24472
diff
changeset
|
95 |
lemmas AbortRule = SkipRule -- "dummy version" |
48891 | 96 |
ML_file "hoare_tac.ML" |
13682 | 97 |
|
98 |
method_setup vcg = {* |
|
30549 | 99 |
Scan.succeed (fn ctxt => SIMPLE_METHOD' (hoare_tac ctxt (K all_tac))) *} |
13682 | 100 |
"verification condition generator" |
101 |
||
102 |
method_setup vcg_simp = {* |
|
30549 | 103 |
Scan.succeed (fn ctxt => |
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
32134
diff
changeset
|
104 |
SIMPLE_METHOD' (hoare_tac ctxt (asm_full_simp_tac (simpset_of ctxt)))) *} |
13682 | 105 |
"verification condition generator plus simplification" |
106 |
||
107 |
end |