author | oheimb |
Mon, 10 Sep 2001 18:31:24 +0200 | |
changeset 11560 | 46d0bde121ab |
parent 11559 | 65d98faa2182 |
child 11565 | ab004c0ecc63 |
permissions | -rw-r--r-- |
11376 | 1 |
(* Title: HOL/NanoJava/AxSem.thy |
2 |
ID: $Id$ |
|
3 |
Author: David von Oheimb |
|
4 |
Copyright 2001 Technische Universitaet Muenchen |
|
5 |
*) |
|
6 |
||
11560 | 7 |
header "Axiomatic Semantics" |
11376 | 8 |
|
9 |
theory AxSem = State: |
|
10 |
||
11 |
types assn = "state => bool" |
|
11486 | 12 |
vassn = "val => assn" |
11476 | 13 |
triple = "assn \<times> stmt \<times> assn" |
14 |
etriple = "assn \<times> expr \<times> vassn" |
|
11376 | 15 |
translations |
16 |
"assn" \<leftharpoondown> (type)"state => bool" |
|
11476 | 17 |
"vassn" \<leftharpoondown> (type)"val => assn" |
18 |
"triple" \<leftharpoondown> (type)"assn \<times> stmt \<times> assn" |
|
19 |
"etriple" \<leftharpoondown> (type)"assn \<times> expr \<times> vassn" |
|
11376 | 20 |
|
11476 | 21 |
consts hoare :: "(triple set \<times> triple set) set" |
22 |
consts ehoare :: "(triple set \<times> etriple ) set" |
|
11376 | 23 |
syntax (xsymbols) |
24 |
"@hoare" :: "[triple set, triple set ] => bool" ("_ |\<turnstile>/ _" [61,61] 60) |
|
25 |
"@hoare1" :: "[triple set, assn,stmt,assn] => bool" |
|
26 |
("_ \<turnstile>/ ({(1_)}/ (_)/ {(1_)})" [61,3,90,3]60) |
|
11486 | 27 |
"@ehoare" :: "[triple set, etriple ] => bool" ("_ |\<turnstile>\<^sub>e/ _"[61,61]60) |
11476 | 28 |
"@ehoare1" :: "[triple set, assn,expr,vassn]=> bool" |
11486 | 29 |
("_ \<turnstile>\<^sub>e/ ({(1_)}/ (_)/ {(1_)})" [61,3,90,3]60) |
11376 | 30 |
syntax |
31 |
"@hoare" :: "[triple set, triple set ] => bool" ("_ ||-/ _" [61,61] 60) |
|
32 |
"@hoare1" :: "[triple set, assn,stmt,assn] => bool" |
|
33 |
("_ |-/ ({(1_)}/ (_)/ {(1_)})" [61,3,90,3] 60) |
|
11476 | 34 |
"@ehoare" :: "[triple set, etriple ] => bool" ("_ ||-e/ _"[61,61] 60) |
35 |
"@ehoare1" :: "[triple set, assn,expr,vassn]=> bool" |
|
36 |
("_ |-e/ ({(1_)}/ (_)/ {(1_)})" [61,3,90,3] 60) |
|
11376 | 37 |
|
11476 | 38 |
translations "A |\<turnstile> C" \<rightleftharpoons> "(A,C) \<in> hoare" |
39 |
"A \<turnstile> {P}c{Q}" \<rightleftharpoons> "A |\<turnstile> {(P,c,Q)}" |
|
11486 | 40 |
"A |\<turnstile>\<^sub>e t" \<rightleftharpoons> "(A,t) \<in> ehoare" |
11558
6539627881e8
simplified vnam/vname, introduced fname, improved comments
oheimb
parents:
11508
diff
changeset
|
41 |
"A |\<turnstile>\<^sub>e (P,e,Q)" \<rightleftharpoons> "(A,P,e,Q) \<in> ehoare" (* shouldn't be necessary *) |
11486 | 42 |
"A \<turnstile>\<^sub>e {P}e{Q}" \<rightleftharpoons> "A |\<turnstile>\<^sub>e (P,e,Q)" |
11376 | 43 |
|
11476 | 44 |
|
11560 | 45 |
subsection "Hoare Logic Rules" |
46 |
||
11476 | 47 |
inductive hoare ehoare |
11376 | 48 |
intros |
49 |
||
50 |
Skip: "A |- {P} Skip {P}" |
|
51 |
||
52 |
Comp: "[| A |- {P} c1 {Q}; A |- {Q} c2 {R} |] ==> A |- {P} c1;;c2 {R}" |
|
53 |
||
11476 | 54 |
Cond: "[| A |-e {P} e {Q}; |
55 |
\<forall>v. A |- {Q v} (if v \<noteq> Null then c1 else c2) {R} |] ==> |
|
56 |
A |- {P} If(e) c1 Else c2 {R}" |
|
57 |
||
58 |
Loop: "A |- {\<lambda>s. P s \<and> s<x> \<noteq> Null} c {P} ==> |
|
59 |
A |- {P} While(x) c {\<lambda>s. P s \<and> s<x> = Null}" |
|
11376 | 60 |
|
11476 | 61 |
LAcc: "A |-e {\<lambda>s. P (s<x>) s} LAcc x {P}" |
11376 | 62 |
|
11476 | 63 |
LAss: "A |-e {P} e {\<lambda>v s. Q (lupd(x\<mapsto>v) s)} ==> |
64 |
A |- {P} x:==e {Q}" |
|
65 |
||
66 |
FAcc: "A |-e {P} e {\<lambda>v s. \<forall>a. v=Addr a --> Q (get_field s a f) s} ==> |
|
67 |
A |-e {P} e..f {Q}" |
|
11376 | 68 |
|
11476 | 69 |
FAss: "[| A |-e {P} e1 {\<lambda>v s. \<forall>a. v=Addr a --> Q a s}; |
70 |
\<forall>a. A |-e {Q a} e2 {\<lambda>v s. R (upd_obj a f v s)} |] ==> |
|
71 |
A |- {P} e1..f:==e2 {R}" |
|
11376 | 72 |
|
11476 | 73 |
NewC: "A |-e {\<lambda>s. \<forall>a. new_Addr s = Addr a --> P (Addr a) (new_obj a C s)} |
74 |
new C {P}" |
|
11376 | 75 |
|
11476 | 76 |
Cast: "A |-e {P} e {\<lambda>v s. (case v of Null => True |
77 |
| Addr a => obj_class s a <=C C) --> Q v s} ==> |
|
78 |
A |-e {P} Cast C e {Q}" |
|
11376 | 79 |
|
11476 | 80 |
Call: "[| A |-e {P} e1 {Q}; \<forall>a. A |-e {Q a} e2 {R a}; |
81 |
\<forall>a p l. A |- {\<lambda>s'. \<exists>s. R a p s \<and> l = s \<and> |
|
11558
6539627881e8
simplified vnam/vname, introduced fname, improved comments
oheimb
parents:
11508
diff
changeset
|
82 |
s' = lupd(This\<mapsto>a)(lupd(Par\<mapsto>p)(reset_locs s))} |
11507 | 83 |
Meth (C,m) {\<lambda>s. S (s<Res>) (set_locs l s)} |] ==> |
11476 | 84 |
A |-e {P} {C}e1..m(e2) {S}" |
11376 | 85 |
|
11497
0e66e0114d9a
corrected initialization of locals, streamlined Impl
oheimb
parents:
11486
diff
changeset
|
86 |
Meth: "\<forall>D. A |- {\<lambda>s'. \<exists>s a. s<This> = Addr a \<and> D = obj_class s a \<and> D <=C C \<and> |
0e66e0114d9a
corrected initialization of locals, streamlined Impl
oheimb
parents:
11486
diff
changeset
|
87 |
P s \<and> s' = init_locs D m s} |
0e66e0114d9a
corrected initialization of locals, streamlined Impl
oheimb
parents:
11486
diff
changeset
|
88 |
Impl (D,m) {Q} ==> |
11507 | 89 |
A |- {P} Meth (C,m) {Q}" |
11376 | 90 |
|
11560 | 91 |
--{* @{text "\<Union>z"} instead of @{text "\<forall>z"} in the conclusion and\\ |
11559 | 92 |
z restricted to type state due to limitations of the inductive package *} |
11508 | 93 |
Impl: "\<forall>z::state. A\<union> (\<Union>z. (\<lambda>Cm. (P z Cm, Impl Cm, Q z Cm))`Ms) ||- |
94 |
(\<lambda>Cm. (P z Cm, body Cm, Q z Cm))`Ms ==> |
|
95 |
A ||- (\<lambda>Cm. (P z Cm, Impl Cm, Q z Cm))`Ms" |
|
11376 | 96 |
|
11558
6539627881e8
simplified vnam/vname, introduced fname, improved comments
oheimb
parents:
11508
diff
changeset
|
97 |
--{* structural rules *} |
11376 | 98 |
|
11476 | 99 |
Asm: " a \<in> A ==> A ||- {a}" |
100 |
||
101 |
ConjI: " \<forall>c \<in> C. A ||- {c} ==> A ||- C" |
|
102 |
||
103 |
ConjE: "[|A ||- C; c \<in> C |] ==> A ||- {c}" |
|
104 |
||
11376 | 105 |
Conseq:"[| \<forall>z::state. A |- {P' z} c {Q' z}; |
11497
0e66e0114d9a
corrected initialization of locals, streamlined Impl
oheimb
parents:
11486
diff
changeset
|
106 |
\<forall>s t. (\<forall>z. P' z s --> Q' z t) --> (P s --> Q t) |] ==> |
11376 | 107 |
A |- {P} c {Q }" |
108 |
||
11558
6539627881e8
simplified vnam/vname, introduced fname, improved comments
oheimb
parents:
11508
diff
changeset
|
109 |
--{* z restricted to type state due to limitations of the inductive package *} |
11476 | 110 |
eConseq:"[| \<forall>z::state. A |-e {P' z} c {Q' z}; |
11497
0e66e0114d9a
corrected initialization of locals, streamlined Impl
oheimb
parents:
11486
diff
changeset
|
111 |
\<forall>s v t. (\<forall>z. P' z s --> Q' z v t) --> (P s --> Q v t) |] ==> |
11476 | 112 |
A |-e {P} c {Q }" |
11376 | 113 |
|
114 |
||
115 |
subsection "Derived Rules" |
|
116 |
||
117 |
lemma Conseq1: "\<lbrakk>A \<turnstile> {P'} c {Q}; \<forall>s. P s \<longrightarrow> P' s\<rbrakk> \<Longrightarrow> A \<turnstile> {P} c {Q}" |
|
11476 | 118 |
apply (rule hoare_ehoare.Conseq) |
119 |
apply (rule allI, assumption) |
|
120 |
apply fast |
|
121 |
done |
|
122 |
||
123 |
lemma Conseq2: "\<lbrakk>A \<turnstile> {P} c {Q'}; \<forall>t. Q' t \<longrightarrow> Q t\<rbrakk> \<Longrightarrow> A \<turnstile> {P} c {Q}" |
|
124 |
apply (rule hoare_ehoare.Conseq) |
|
125 |
apply (rule allI, assumption) |
|
126 |
apply fast |
|
127 |
done |
|
128 |
||
11486 | 129 |
lemma eConseq1: "\<lbrakk>A \<turnstile>\<^sub>e {P'} e {Q}; \<forall>s. P s \<longrightarrow> P' s\<rbrakk> \<Longrightarrow> A \<turnstile>\<^sub>e {P} e {Q}" |
11476 | 130 |
apply (rule hoare_ehoare.eConseq) |
131 |
apply (rule allI, assumption) |
|
132 |
apply fast |
|
133 |
done |
|
134 |
||
11486 | 135 |
lemma eConseq2: "\<lbrakk>A \<turnstile>\<^sub>e {P} e {Q'}; \<forall>v t. Q' v t \<longrightarrow> Q v t\<rbrakk> \<Longrightarrow> A \<turnstile>\<^sub>e {P} e {Q}" |
11476 | 136 |
apply (rule hoare_ehoare.eConseq) |
11376 | 137 |
apply (rule allI, assumption) |
138 |
apply fast |
|
139 |
done |
|
140 |
||
141 |
lemma Weaken: "\<lbrakk>A |\<turnstile> C'; C \<subseteq> C'\<rbrakk> \<Longrightarrow> A |\<turnstile> C" |
|
11476 | 142 |
apply (rule hoare_ehoare.ConjI) |
11376 | 143 |
apply clarify |
11476 | 144 |
apply (drule hoare_ehoare.ConjE) |
11376 | 145 |
apply fast |
146 |
apply assumption |
|
147 |
done |
|
148 |
||
149 |
lemma Union: "A |\<turnstile> (\<Union>z. C z) = (\<forall>z. A |\<turnstile> C z)" |
|
11476 | 150 |
by (auto intro: hoare_ehoare.ConjI hoare_ehoare.ConjE) |
11376 | 151 |
|
11497
0e66e0114d9a
corrected initialization of locals, streamlined Impl
oheimb
parents:
11486
diff
changeset
|
152 |
lemma Impl1: |
11508 | 153 |
"\<lbrakk>\<forall>z::state. A\<union> (\<Union>z. (\<lambda>Cm. (P z Cm, Impl Cm, Q z Cm))`Ms) |\<turnstile> |
154 |
(\<lambda>Cm. (P z Cm, body Cm, Q z Cm))`Ms; |
|
155 |
Cm \<in> Ms\<rbrakk> \<Longrightarrow> |
|
156 |
A \<turnstile> {P z Cm} Impl Cm {Q z Cm}" |
|
11476 | 157 |
apply (drule hoare_ehoare.Impl) |
11376 | 158 |
apply (erule Weaken) |
159 |
apply (auto del: image_eqI intro: rev_image_eqI) |
|
160 |
done |
|
161 |
||
162 |
end |