-
Notifications
You must be signed in to change notification settings - Fork 0
/
RG.thy
299 lines (240 loc) · 10.8 KB
/
RG.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
(* *********************************************************************
Theory RG.thy is part of a framework for modelling,
verification and transformation of concurrent imperative
programs. Copyright (c) 2021 M. Bortin
The framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For more details see the license agreement (LICENSE) you should have
received along with the framework.
******************************************************************* *)
theory RG
imports Computations
begin
section "Extended Hoare-triples"
definition HoareTripleRG :: "(nat \<Rightarrow> 's LA) \<Rightarrow> 's staterel \<Rightarrow> 's set \<Rightarrow> 's LA \<Rightarrow>
's set \<Rightarrow> 's staterel \<Rightarrow> bool"
("_ \<Turnstile> {_ , _} _ {_ , _}" [40, 20, 20, 71, 20, 20] 71)
where "\<rho> \<Turnstile> {R, P} p {Q, G} =
(EnvCond \<rho> R \<inter> InitCond \<rho> P \<inter> \<lbrakk>p\<rbrakk>\<^sub>\<rho> \<subseteq> TermCond \<rho> Q \<inter> ProgCond \<rho> G)"
definition HoareTripleRG2 :: "(nat \<Rightarrow> 's LA) \<Rightarrow> 's staterel \<Rightarrow> 's staterel \<Rightarrow>
's LA \<Rightarrow>
's staterel \<Rightarrow> 's staterel \<Rightarrow> bool"
("_ \<Turnstile>\<^sub>2 {_ , _} _ {_ , _}" [40, 20, 20, 71, 20, 20] 71)
where "\<rho> \<Turnstile>\<^sub>2 {R, P} p {Q, G} = (\<forall>\<sigma>. \<rho> \<Turnstile> {R, P `` {\<sigma>}} p {Q `` {\<sigma>}, G})"
abbreviation HoareTripleRGjf :: "'s staterel \<Rightarrow> 's set \<Rightarrow> 's LA \<Rightarrow>
's set \<Rightarrow> 's staterel \<Rightarrow> bool"
(" \<Turnstile> {_ , _} _ {_ , _}" [20, 20, 71, 20, 20] 71)
where "\<Turnstile> {R, P} p {Q, G} \<equiv> (\<lambda>x. Skip) \<Turnstile> {R, P} p {Q, G}"
abbreviation HoareTripleRG2jf :: "'s staterel \<Rightarrow> 's staterel \<Rightarrow>
's LA \<Rightarrow>
's staterel \<Rightarrow> 's staterel \<Rightarrow> bool"
("\<Turnstile>\<^sub>2 {_ , _} _ {_ , _}" [20, 20, 71, 20, 20] 71)
where "\<Turnstile>\<^sub>2 {R, P} p {Q, G} \<equiv> (\<lambda>x. Skip) \<Turnstile>\<^sub>2 {R, P} p {Q, G}"
lemma HoareTripleRG_subset_eq :
"\<rho> \<Turnstile> {R, P} p {Q, G} =
(\<forall>P' \<subseteq> P. \<rho> \<Turnstile> {R, P'} p {Q, G})"
apply(rule iffI)
apply clarify
apply(subst HoareTripleRG_def)
apply clarify
apply(rename_tac sq)
apply(subst (asm) HoareTripleRG_def)
apply(erule subsetD, simp add: InitCond_def)
apply fastforce
apply(drule spec, drule mp, rule subset_refl)
by assumption
lemma HoareTripleRG_singleton_eq :
"\<rho> \<Turnstile> {R, P} p {Q, G} =
(\<forall>s \<in> P. \<rho> \<Turnstile> {R, {s}} p {Q, G})"
apply(rule iffI)
apply clarify
apply(subst (asm) HoareTripleRG_subset_eq)
apply(drule spec, erule mp, clarsimp)
apply(subst HoareTripleRG_def)
apply clarify
apply(rename_tac sq)
apply(clarsimp simp: InitCond_def)
apply(drule_tac x="s" in bspec)
apply(subst (asm) hd_conv_nth, erule pcs_noNil)
apply simp
apply(subst (asm) HoareTripleRG_def)
apply(drule_tac c=sq in subsetD, simp add: InitCond_def, erule exI)
apply clarsimp
done
subsection "Properties of finite and infinite computations"
definition HoareTripleRG_i :: "(nat \<Rightarrow> 's LA) \<Rightarrow> 's staterel \<Rightarrow> 's set \<Rightarrow> 's LA \<Rightarrow>
's set \<Rightarrow> 's staterel \<Rightarrow> bool"
("_ \<Turnstile>i {_ , _} _ {_ , _}" [40, 20, 20, 71, 20, 20] 71)
where "\<rho> \<Turnstile>i {R, P} p {Q, G} \<equiv>
(EnvCond \<rho> R \<inter> InitCond \<rho> P \<inter> \<lbrakk>p\<rbrakk>\<^sub>\<rho> \<subseteq> TermCond \<rho> Q \<inter> ProgCond \<rho> G) \<and>
(EnvCond_i \<rho> R \<inter> InitCond_i \<rho> P \<inter> iCOMP \<rho> \<inter> {sq. progOf(sq 0) = p} \<subseteq>
TermCond_i \<rho> Q \<inter> ProgCond_i \<rho> G)"
abbreviation HoareTripleRGjf_i :: "'s staterel \<Rightarrow> 's set \<Rightarrow> 's LA \<Rightarrow>
's set \<Rightarrow> 's staterel \<Rightarrow> bool"
("\<Turnstile>i {_ , _} _ {_ , _}" [20, 20, 71, 20, 20] 71)
where "\<Turnstile>i {R, P} p {Q, G} \<equiv> (\<lambda>x. Skip) \<Turnstile>i {R, P} p {Q, G}"
theorem HoareTripleRG_i :
"\<rho> \<Turnstile> {R, P} p {Q, G} \<Longrightarrow>
\<rho> \<Turnstile>i {R, P} p {Q, G}"
apply(subst HoareTripleRG_i_def)
apply(rule conjI)
apply(simp add: HoareTripleRG_def)
apply clarify
apply(rename_tac isq)
apply simp
apply(case_tac "isq 0", clarsimp)
apply(rename_tac s0 tk0)
apply(subgoal_tac "\<forall>j. fprefix isq (j+1) \<in> TermCond \<rho> Q \<inter> ProgCond \<rho> G")
apply(rule conjI)
apply(clarsimp simp: TermCond_i_def)
apply(drule_tac x=j in spec, clarify)
apply(drule TermCond_D)
apply(simp add: fprefix_length)
apply(drule_tac x=j in spec, clarsimp simp: fprefix_nth)
apply fast
apply(clarsimp simp: ProgCond_i_def cstep_cond_def)
apply(drule_tac x=i in spec, clarify)
apply(erule_tac i=i in ProgCond_D)
apply(simp add: fprefix_length)
apply assumption
apply(simp add: fprefix_nth)
apply(erule sym)
apply(simp add: fprefix_nth)
apply(rule allI)
apply(frule_tac n="j+1" in fprefix_COMP, simp)
apply(subst (asm) HoareTripleRG_def)
apply(drule_tac c="fprefix isq (j+1)" in subsetD)
apply simp
apply(rule conjI)
apply(simp add: EnvCond_def)
apply(rule conjI)
apply(rule_tac x="progOf(isq 0)" in exI, simp add: pcs_def)
apply(subst hd_conv_nth, erule COMP_noNil)
apply(simp add: fprefix_nth)
apply(clarsimp simp: fprefix_length fprefix_nth)
apply(clarsimp simp: EnvCond_i_def)
apply(rule conjI)
apply(simp add: InitCond_def)
apply(rule conjI)
apply(rule_tac x="progOf(isq 0)" in exI, simp add: pcs_def)
apply(subst hd_conv_nth, erule COMP_noNil)
apply(simp add: fprefix_nth)
apply(subst hd_conv_nth, erule COMP_noNil)
apply(simp add: fprefix_nth InitCond_i_def)
apply(simp add: pcs_def)
apply(subst hd_conv_nth, erule COMP_noNil)
apply(simp add: fprefix_nth)
by assumption
section "Syntactic sugaring"
syntax
"_rg" :: "(nat \<Rightarrow> 's LA) \<Rightarrow> 's LA \<Rightarrow> 's staterel \<Rightarrow> 's set \<Rightarrow> 's set \<Rightarrow>'s staterel \<Rightarrow> bool"
("(4_)/ \<Turnstile> _//RELY _//PRE _//POST _//GUAR _" [60,0,0,0,0] 45)
translations
"_rg \<rho> p R P Q G" \<rightharpoonup> "\<rho> \<Turnstile> {R, P} p {Q, G}"
ML \<open> val syntax_debug = false \<close>
print_translation \<open>
let
fun rg_tr (rho :: R :: P :: p :: Q :: G :: ts) =
let val _ = if syntax_debug then writeln "rg" else ()
in Syntax.const @{syntax_const "_rg"} $
rho $ p $ R $ P $ Q $ G
end
| rg_tr x = let val _ = writeln (@{make_string} {x = x})
in raise Match end;
in
[(@{const_syntax HoareTripleRG}, K rg_tr)]
end
\<close>
syntax
"_rgjf" :: "'s LA \<Rightarrow> 's staterel \<Rightarrow> 's set \<Rightarrow> 's set \<Rightarrow>'s staterel \<Rightarrow> bool"
("\<Turnstile> _//RELY _//PRE _//POST _//GUAR _" [0,0,0,0] 45)
translations
"_rgjf p R P Q G" \<rightharpoonup> "\<Turnstile> {R, P} p {Q, G}"
print_translation \<open>
let
fun rgjf_tr (R :: P :: p :: Q :: G :: ts) =
let val _ = if syntax_debug then writeln "rgjf" else ()
in Syntax.const @{syntax_const "_rgjf"} $
p $ R $ P $ Q $ G
end
| rgjf_tr x = let val _ = writeln (@{make_string} {x = x})
in raise Match end;
in
[(@{const_syntax HoareTripleRGjf}, K rgjf_tr)]
end
\<close>
syntax
"_rgi" :: "(nat \<Rightarrow> 's LA) \<Rightarrow> 's LA \<Rightarrow> 's staterel \<Rightarrow> 's set \<Rightarrow> 's set \<Rightarrow>'s staterel \<Rightarrow> bool"
("(4_)/ \<Turnstile>i _//RELY _//PRE _//POST _//GUAR _" [60,0,0,0,0] 45)
translations
"_rgi \<rho> p R P Q G" \<rightharpoonup> "\<rho> \<Turnstile>i {R, P} p {Q, G}"
print_translation \<open>
let
fun rgi_tr (rho :: R :: P :: p :: Q :: G :: ts) =
let val _ = if syntax_debug then writeln "rgi" else ()
in Syntax.const @{syntax_const "_rgi"} $
rho $ p $ R $ P $ Q $ G
end
| rgi_tr x = let val _ = writeln (@{make_string} {x = x})
in raise Match end;
in
[(@{const_syntax HoareTripleRG_i}, K rgi_tr)]
end
\<close>
syntax
"_rgijf" :: "'s LA \<Rightarrow> 's staterel \<Rightarrow> 's set \<Rightarrow> 's set \<Rightarrow>'s staterel \<Rightarrow> bool"
("\<Turnstile>i _//RELY _//PRE _//POST _//GUAR _" [0,0,0,0] 45)
translations
"_rgijf p R P Q G" \<rightharpoonup> "\<Turnstile>i {R, P} p {Q, G}"
print_translation \<open>
let
fun rgijf_tr (R :: P :: p :: Q :: G :: ts) =
let val _ = if syntax_debug then writeln "rgijf" else ()
in Syntax.const @{syntax_const "_rgijf"} $
p $ R $ P $ Q $ G
end
| rgijf_tr x = let val _ = writeln (@{make_string} {x = x})
in raise Match end;
in
[(@{const_syntax HoareTripleRGjf_i}, K rgijf_tr)]
end
\<close>
syntax
"_rg2" :: "(nat \<Rightarrow> 's LA) \<Rightarrow> 's LA \<Rightarrow> 's staterel \<Rightarrow>
's staterel \<Rightarrow> 's staterel \<Rightarrow> 's staterel \<Rightarrow> bool"
("(4_)/ \<Turnstile>\<^sub>2 _//RELY _//PRE _//POST _//GUAR _" [60,0,0,0,0] 45)
translations
"_rg2 \<rho> p R P Q G" \<rightharpoonup> "\<rho> \<Turnstile>\<^sub>2 {R, P} p {Q, G}"
ML \<open> val syntax_debug = false \<close>
print_translation \<open> let
fun rg2_tr (rho :: R :: P :: p :: Q :: G :: ts) =
let val _ = if syntax_debug then writeln "rg2" else ()
in Syntax.const @{syntax_const "_rg2"} $
rho $ p $ R $ P $ Q $ G
end
| rg2_tr x = let val _ = writeln (@{make_string} {x = x})
in raise Match end;
in
[(@{const_syntax HoareTripleRG2}, K rg2_tr)]
end
\<close>
syntax
"_rg2jf" :: "'s LA \<Rightarrow> 's staterel \<Rightarrow>
's staterel \<Rightarrow> 's staterel \<Rightarrow> 's staterel \<Rightarrow> bool"
("\<Turnstile>\<^sub>2 _//RELY _//PRE _//POST _//GUAR _" [0,0,0,0] 45)
translations
"_rg2jf p R P Q G" \<rightharpoonup> "\<Turnstile>\<^sub>2 {R, P} p {Q, G}"
print_translation \<open> let
fun rg2jf_tr (R :: P :: p :: Q :: G :: ts) =
let val _ = if syntax_debug then writeln "rg2jf" else ()
in Syntax.const @{syntax_const "_rg2jf"} $
p $ R $ P $ Q $ G
end
| rg2jf_tr x = let val _ = writeln (@{make_string} {x = x})
in raise Match end;
in
[(@{const_syntax HoareTripleRG2jf}, K rg2jf_tr)]
end
\<close>
end