author | paulson <lp15@cam.ac.uk> |
Thu, 26 Sep 2024 14:44:37 +0100 | |
changeset 80948 | 572970d15ab0 |
parent 80914 | d97fdabd9e2b |
child 81189 | 47a0dfee26ea |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Hoare/Pointers0.thy |
13771 | 2 |
Author: Tobias Nipkow |
3 |
Copyright 2002 TUM |
|
4 |
||
5 |
This is like Pointers.thy, but instead of a type constructor 'a ref |
|
6 |
that adjoins Null to a type, Null is simply a distinguished element of |
|
7 |
the address type. This avoids the Ref constructor and thus simplifies |
|
8 |
specifications (a bit). However, the proofs don't seem to get simpler |
|
9 |
- in fact in some case they appear to get (a bit) more complicated. |
|
10 |
*) |
|
11 |
||
72990 | 12 |
section \<open>Alternative pointers\<close> |
13 |
||
14 |
theory Pointers0 |
|
15 |
imports Hoare_Logic |
|
16 |
begin |
|
13771 | 17 |
|
18 |
subsection "References" |
|
19 |
||
35316
870dfea4f9c0
dropped axclass; dropped Id; session theory Hoare.thy
haftmann
parents:
35101
diff
changeset
|
20 |
class ref = |
870dfea4f9c0
dropped axclass; dropped Id; session theory Hoare.thy
haftmann
parents:
35101
diff
changeset
|
21 |
fixes Null :: 'a |
13771 | 22 |
|
23 |
subsection "Field access and update" |
|
24 |
||
25 |
syntax |
|
35101 | 26 |
"_fassign" :: "'a::ref => id => 'v => 's com" |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
72990
diff
changeset
|
27 |
(\<open>(2_^._ :=/ _)\<close> [70,1000,65] 61) |
35101 | 28 |
"_faccess" :: "'a::ref => ('a::ref \<Rightarrow> 'v) => 'v" |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
72990
diff
changeset
|
29 |
(\<open>_^._\<close> [65,1000] 65) |
13771 | 30 |
translations |
35101 | 31 |
"p^.f := e" => "f := CONST fun_upd f p e" |
13771 | 32 |
"p^.f" => "f p" |
33 |
||
34 |
||
35 |
text "An example due to Suzuki:" |
|
36 |
||
37 |
lemma "VARS v n |
|
38 |
{distinct[w,x,y,z]} |
|
39 |
w^.v := (1::int); w^.n := x; |
|
40 |
x^.v := 2; x^.n := y; |
|
41 |
y^.v := 3; y^.n := z; |
|
42 |
z^.v := 4; x^.n := z |
|
43 |
{w^.n^.n^.v = 4}" |
|
44 |
by vcg_simp |
|
45 |
||
46 |
||
72990 | 47 |
subsection "The heap" |
13771 | 48 |
|
72990 | 49 |
subsubsection "Paths in the heap" |
13771 | 50 |
|
38353 | 51 |
primrec Path :: "('a::ref \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a \<Rightarrow> bool" |
52 |
where |
|
53 |
"Path h x [] y = (x = y)" |
|
54 |
| "Path h x (a#as) y = (x \<noteq> Null \<and> x = a \<and> Path h (h a) as y)" |
|
13771 | 55 |
|
56 |
lemma [iff]: "Path h Null xs y = (xs = [] \<and> y = Null)" |
|
57 |
apply(case_tac xs) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
58 |
apply fastforce |
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
59 |
apply fastforce |
13771 | 60 |
done |
61 |
||
62 |
lemma [simp]: "a \<noteq> Null \<Longrightarrow> Path h a as z = |
|
63 |
(as = [] \<and> z = a \<or> (\<exists>bs. as = a#bs \<and> Path h (h a) bs z))" |
|
64 |
apply(case_tac as) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
65 |
apply fastforce |
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
66 |
apply fastforce |
13771 | 67 |
done |
68 |
||
69 |
lemma [simp]: "\<And>x. Path f x (as@bs) z = (\<exists>y. Path f x as y \<and> Path f y bs z)" |
|
70 |
by(induct as, simp+) |
|
71 |
||
72 |
lemma [simp]: "\<And>x. u \<notin> set as \<Longrightarrow> Path (f(u := v)) x as y = Path f x as y" |
|
73 |
by(induct as, simp, simp add:eq_sym_conv) |
|
74 |
||
72990 | 75 |
subsubsection "Lists on the heap" |
13771 | 76 |
|
72990 | 77 |
paragraph "Relational abstraction" |
13771 | 78 |
|
38353 | 79 |
definition List :: "('a::ref \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> bool" |
80 |
where "List h x as = Path h x as Null" |
|
13771 | 81 |
|
82 |
lemma [simp]: "List h x [] = (x = Null)" |
|
83 |
by(simp add:List_def) |
|
84 |
||
85 |
lemma [simp]: "List h x (a#as) = (x \<noteq> Null \<and> x = a \<and> List h (h a) as)" |
|
86 |
by(simp add:List_def) |
|
87 |
||
88 |
lemma [simp]: "List h Null as = (as = [])" |
|
89 |
by(case_tac as, simp_all) |
|
90 |
||
91 |
lemma List_Ref[simp]: |
|
92 |
"a \<noteq> Null \<Longrightarrow> List h a as = (\<exists>bs. as = a#bs \<and> List h (h a) bs)" |
|
93 |
by(case_tac as, simp_all, fast) |
|
94 |
||
95 |
theorem notin_List_update[simp]: |
|
96 |
"\<And>x. a \<notin> set as \<Longrightarrow> List (h(a := y)) x as = List h x as" |
|
97 |
apply(induct as) |
|
98 |
apply simp |
|
99 |
apply(clarsimp simp add:fun_upd_apply) |
|
100 |
done |
|
101 |
||
102 |
||
103 |
declare fun_upd_apply[simp del]fun_upd_same[simp] fun_upd_other[simp] |
|
104 |
||
105 |
lemma List_unique: "\<And>x bs. List h x as \<Longrightarrow> List h x bs \<Longrightarrow> as = bs" |
|
106 |
by(induct as, simp, clarsimp) |
|
107 |
||
108 |
lemma List_unique1: "List h p as \<Longrightarrow> \<exists>!as. List h p as" |
|
109 |
by(blast intro:List_unique) |
|
110 |
||
111 |
lemma List_app: "\<And>x. List h x (as@bs) = (\<exists>y. Path h x as y \<and> List h y bs)" |
|
112 |
by(induct as, simp, clarsimp) |
|
113 |
||
114 |
lemma List_hd_not_in_tl[simp]: "List h (h a) as \<Longrightarrow> a \<notin> set as" |
|
115 |
apply (clarsimp simp add:in_set_conv_decomp) |
|
116 |
apply(frule List_app[THEN iffD1]) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
117 |
apply(fastforce dest: List_unique) |
13771 | 118 |
done |
119 |
||
120 |
lemma List_distinct[simp]: "\<And>x. List h x as \<Longrightarrow> distinct as" |
|
121 |
apply(induct as, simp) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
122 |
apply(fastforce dest:List_hd_not_in_tl) |
13771 | 123 |
done |
124 |
||
72990 | 125 |
subsubsection "Functional abstraction" |
13771 | 126 |
|
38353 | 127 |
definition islist :: "('a::ref \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> bool" |
128 |
where "islist h p \<longleftrightarrow> (\<exists>as. List h p as)" |
|
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35316
diff
changeset
|
129 |
|
38353 | 130 |
definition list :: "('a::ref \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a list" |
131 |
where "list h p = (SOME as. List h p as)" |
|
13771 | 132 |
|
133 |
lemma List_conv_islist_list: "List h p as = (islist h p \<and> as = list h p)" |
|
134 |
apply(simp add:islist_def list_def) |
|
135 |
apply(rule iffI) |
|
136 |
apply(rule conjI) |
|
137 |
apply blast |
|
138 |
apply(subst some1_equality) |
|
139 |
apply(erule List_unique1) |
|
140 |
apply assumption |
|
141 |
apply(rule refl) |
|
142 |
apply simp |
|
143 |
apply(rule someI_ex) |
|
144 |
apply fast |
|
145 |
done |
|
146 |
||
147 |
lemma [simp]: "islist h Null" |
|
148 |
by(simp add:islist_def) |
|
149 |
||
150 |
lemma [simp]: "a \<noteq> Null \<Longrightarrow> islist h a = islist h (h a)" |
|
151 |
by(simp add:islist_def) |
|
152 |
||
153 |
lemma [simp]: "list h Null = []" |
|
154 |
by(simp add:list_def) |
|
155 |
||
156 |
lemma list_Ref_conv[simp]: |
|
157 |
"\<lbrakk> a \<noteq> Null; islist h (h a) \<rbrakk> \<Longrightarrow> list h a = a # list h (h a)" |
|
158 |
apply(insert List_Ref[of _ h]) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
159 |
apply(fastforce simp:List_conv_islist_list) |
13771 | 160 |
done |
161 |
||
162 |
lemma [simp]: "islist h (h a) \<Longrightarrow> a \<notin> set(list h (h a))" |
|
163 |
apply(insert List_hd_not_in_tl[of h]) |
|
164 |
apply(simp add:List_conv_islist_list) |
|
165 |
done |
|
166 |
||
167 |
lemma list_upd_conv[simp]: |
|
168 |
"islist h p \<Longrightarrow> y \<notin> set(list h p) \<Longrightarrow> list (h(y := q)) p = list h p" |
|
169 |
apply(drule notin_List_update[of _ _ h q p]) |
|
170 |
apply(simp add:List_conv_islist_list) |
|
171 |
done |
|
172 |
||
173 |
lemma islist_upd[simp]: |
|
174 |
"islist h p \<Longrightarrow> y \<notin> set(list h p) \<Longrightarrow> islist (h(y := q)) p" |
|
175 |
apply(frule notin_List_update[of _ _ h q p]) |
|
176 |
apply(simp add:List_conv_islist_list) |
|
177 |
done |
|
178 |
||
179 |
||
72990 | 180 |
subsection "Verifications" |
13771 | 181 |
|
72990 | 182 |
subsubsection "List reversal" |
13771 | 183 |
|
184 |
text "A short but unreadable proof:" |
|
185 |
||
186 |
lemma "VARS tl p q r |
|
187 |
{List tl p Ps \<and> List tl q Qs \<and> set Ps \<inter> set Qs = {}} |
|
188 |
WHILE p \<noteq> Null |
|
189 |
INV {\<exists>ps qs. List tl p ps \<and> List tl q qs \<and> set ps \<inter> set qs = {} \<and> |
|
190 |
rev ps @ qs = rev Ps @ Qs} |
|
191 |
DO r := p; p := p^.tl; r^.tl := q; q := r OD |
|
192 |
{List tl q (rev Ps @ Qs)}" |
|
193 |
apply vcg_simp |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
194 |
apply fastforce |
67444 | 195 |
apply(fastforce intro:notin_List_update[THEN iffD2]) |
196 |
\<comment> \<open>explicit:\<close> |
|
197 |
\<^cancel>\<open>apply clarify\<close> |
|
198 |
\<^cancel>\<open>apply(rename_tac ps qs)\<close> |
|
199 |
\<^cancel>\<open>apply clarsimp\<close> |
|
200 |
\<^cancel>\<open>apply(rename_tac ps')\<close> |
|
201 |
\<^cancel>\<open>apply(rule_tac x = ps' in exI)\<close> |
|
202 |
\<^cancel>\<open>apply simp\<close> |
|
203 |
\<^cancel>\<open>apply(rule_tac x = "p#qs" in exI)\<close> |
|
204 |
\<^cancel>\<open>apply simp\<close> |
|
205 |
done |
|
13771 | 206 |
|
207 |
||
208 |
text "A longer readable version:" |
|
209 |
||
210 |
lemma "VARS tl p q r |
|
211 |
{List tl p Ps \<and> List tl q Qs \<and> set Ps \<inter> set Qs = {}} |
|
212 |
WHILE p \<noteq> Null |
|
213 |
INV {\<exists>ps qs. List tl p ps \<and> List tl q qs \<and> set ps \<inter> set qs = {} \<and> |
|
214 |
rev ps @ qs = rev Ps @ Qs} |
|
215 |
DO r := p; p := p^.tl; r^.tl := q; q := r OD |
|
216 |
{List tl q (rev Ps @ Qs)}" |
|
217 |
proof vcg |
|
218 |
fix tl p q r |
|
219 |
assume "List tl p Ps \<and> List tl q Qs \<and> set Ps \<inter> set Qs = {}" |
|
220 |
thus "\<exists>ps qs. List tl p ps \<and> List tl q qs \<and> set ps \<inter> set qs = {} \<and> |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
221 |
rev ps @ qs = rev Ps @ Qs" by fastforce |
13771 | 222 |
next |
223 |
fix tl p q r |
|
224 |
assume "(\<exists>ps qs. List tl p ps \<and> List tl q qs \<and> set ps \<inter> set qs = {} \<and> |
|
225 |
rev ps @ qs = rev Ps @ Qs) \<and> p \<noteq> Null" |
|
226 |
(is "(\<exists>ps qs. ?I ps qs) \<and> _") |
|
227 |
then obtain ps qs where I: "?I ps qs \<and> p \<noteq> Null" by fast |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
228 |
then obtain ps' where "ps = p # ps'" by fastforce |
13771 | 229 |
hence "List (tl(p := q)) (p^.tl) ps' \<and> |
230 |
List (tl(p := q)) p (p#qs) \<and> |
|
231 |
set ps' \<inter> set (p#qs) = {} \<and> |
|
232 |
rev ps' @ (p#qs) = rev Ps @ Qs" |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
233 |
using I by fastforce |
13771 | 234 |
thus "\<exists>ps' qs'. List (tl(p := q)) (p^.tl) ps' \<and> |
235 |
List (tl(p := q)) p qs' \<and> |
|
236 |
set ps' \<inter> set qs' = {} \<and> |
|
237 |
rev ps' @ qs' = rev Ps @ Qs" by fast |
|
238 |
next |
|
239 |
fix tl p q r |
|
240 |
assume "(\<exists>ps qs. List tl p ps \<and> List tl q qs \<and> set ps \<inter> set qs = {} \<and> |
|
241 |
rev ps @ qs = rev Ps @ Qs) \<and> \<not> p \<noteq> Null" |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
242 |
thus "List tl q (rev Ps @ Qs)" by fastforce |
13771 | 243 |
qed |
244 |
||
245 |
||
62042 | 246 |
text\<open>Finaly, the functional version. A bit more verbose, but automatic!\<close> |
13771 | 247 |
|
248 |
lemma "VARS tl p q r |
|
249 |
{islist tl p \<and> islist tl q \<and> |
|
250 |
Ps = list tl p \<and> Qs = list tl q \<and> set Ps \<inter> set Qs = {}} |
|
251 |
WHILE p \<noteq> Null |
|
252 |
INV {islist tl p \<and> islist tl q \<and> |
|
253 |
set(list tl p) \<inter> set(list tl q) = {} \<and> |
|
254 |
rev(list tl p) @ (list tl q) = rev Ps @ Qs} |
|
255 |
DO r := p; p := p^.tl; r^.tl := q; q := r OD |
|
256 |
{islist tl q \<and> list tl q = rev Ps @ Qs}" |
|
257 |
apply vcg_simp |
|
258 |
apply clarsimp |
|
259 |
apply clarsimp |
|
260 |
done |
|
261 |
||
262 |
||
72990 | 263 |
subsubsection "Searching in a list" |
13771 | 264 |
|
62042 | 265 |
text\<open>What follows is a sequence of successively more intelligent proofs that |
13771 | 266 |
a simple loop finds an element in a linked list. |
267 |
||
69597 | 268 |
We start with a proof based on the \<^term>\<open>List\<close> predicate. This means it only |
62042 | 269 |
works for acyclic lists.\<close> |
13771 | 270 |
|
271 |
lemma "VARS tl p |
|
272 |
{List tl p Ps \<and> X \<in> set Ps} |
|
273 |
WHILE p \<noteq> Null \<and> p \<noteq> X |
|
274 |
INV {p \<noteq> Null \<and> (\<exists>ps. List tl p ps \<and> X \<in> set ps)} |
|
275 |
DO p := p^.tl OD |
|
276 |
{p = X}" |
|
277 |
apply vcg_simp |
|
278 |
apply(case_tac "p = Null") |
|
279 |
apply clarsimp |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
280 |
apply fastforce |
13771 | 281 |
apply clarsimp |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
282 |
apply fastforce |
13771 | 283 |
apply clarsimp |
284 |
done |
|
285 |
||
69597 | 286 |
text\<open>Using \<^term>\<open>Path\<close> instead of \<^term>\<open>List\<close> generalizes the correctness |
62042 | 287 |
statement to cyclic lists as well:\<close> |
13771 | 288 |
|
289 |
lemma "VARS tl p |
|
290 |
{Path tl p Ps X} |
|
291 |
WHILE p \<noteq> Null \<and> p \<noteq> X |
|
292 |
INV {\<exists>ps. Path tl p ps X} |
|
293 |
DO p := p^.tl OD |
|
294 |
{p = X}" |
|
295 |
apply vcg_simp |
|
296 |
apply blast |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
297 |
apply fastforce |
13771 | 298 |
apply clarsimp |
299 |
done |
|
300 |
||
62042 | 301 |
text\<open>Now it dawns on us that we do not need the list witness at all --- it |
302 |
suffices to talk about reachability, i.e.\ we can use relations directly.\<close> |
|
13771 | 303 |
|
304 |
lemma "VARS tl p |
|
67613 | 305 |
{(p,X) \<in> {(x,y). y = tl x & x \<noteq> Null}\<^sup>*} |
13771 | 306 |
WHILE p \<noteq> Null \<and> p \<noteq> X |
67613 | 307 |
INV {(p,X) \<in> {(x,y). y = tl x & x \<noteq> Null}\<^sup>*} |
13771 | 308 |
DO p := p^.tl OD |
309 |
{p = X}" |
|
310 |
apply vcg_simp |
|
311 |
apply clarsimp |
|
312 |
apply(erule converse_rtranclE) |
|
313 |
apply simp |
|
314 |
apply(simp) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
315 |
apply(fastforce elim:converse_rtranclE) |
13771 | 316 |
done |
317 |
||
318 |
||
72990 | 319 |
subsubsection "Merging two lists" |
13771 | 320 |
|
321 |
text"This is still a bit rough, especially the proof." |
|
322 |
||
35419 | 323 |
fun merge :: "'a list * 'a list * ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list" where |
13771 | 324 |
"merge(x#xs,y#ys,f) = (if f x y then x # merge(xs,y#ys,f) |
35419 | 325 |
else y # merge(x#xs,ys,f))" | |
326 |
"merge(x#xs,[],f) = x # merge(xs,[],f)" | |
|
327 |
"merge([],y#ys,f) = y # merge([],ys,f)" | |
|
13771 | 328 |
"merge([],[],f) = []" |
329 |
||
330 |
lemma imp_disjCL: "(P|Q \<longrightarrow> R) = ((P \<longrightarrow> R) \<and> (~P \<longrightarrow> Q \<longrightarrow> R))" |
|
331 |
by blast |
|
332 |
||
333 |
declare disj_not1[simp del] imp_disjL[simp del] imp_disjCL[simp] |
|
334 |
||
335 |
lemma "VARS hd tl p q r s |
|
336 |
{List tl p Ps \<and> List tl q Qs \<and> set Ps \<inter> set Qs = {} \<and> |
|
337 |
(p \<noteq> Null \<or> q \<noteq> Null)} |
|
338 |
IF if q = Null then True else p ~= Null & p^.hd \<le> q^.hd |
|
339 |
THEN r := p; p := p^.tl ELSE r := q; q := q^.tl FI; |
|
340 |
s := r; |
|
341 |
WHILE p \<noteq> Null \<or> q \<noteq> Null |
|
67613 | 342 |
INV {\<exists>rs ps qs. Path tl r rs s \<and> List tl p ps \<and> List tl q qs \<and> |
13771 | 343 |
distinct(s # ps @ qs @ rs) \<and> s \<noteq> Null \<and> |
344 |
merge(Ps,Qs,\<lambda>x y. hd x \<le> hd y) = |
|
345 |
rs @ s # merge(ps,qs,\<lambda>x y. hd x \<le> hd y) \<and> |
|
346 |
(tl s = p \<or> tl s = q)} |
|
347 |
DO IF if q = Null then True else p \<noteq> Null \<and> p^.hd \<le> q^.hd |
|
348 |
THEN s^.tl := p; p := p^.tl ELSE s^.tl := q; q := q^.tl FI; |
|
349 |
s := s^.tl |
|
350 |
OD |
|
351 |
{List tl r (merge(Ps,Qs,\<lambda>x y. hd x \<le> hd y))}" |
|
352 |
apply vcg_simp |
|
353 |
||
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
354 |
apply (fastforce) |
13771 | 355 |
|
356 |
apply clarsimp |
|
357 |
apply(rule conjI) |
|
358 |
apply clarsimp |
|
359 |
apply(simp add:eq_sym_conv) |
|
360 |
apply(rule_tac x = "rs @ [s]" in exI) |
|
361 |
apply simp |
|
362 |
apply(rule_tac x = "bs" in exI) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
41959
diff
changeset
|
363 |
apply (fastforce simp:eq_sym_conv) |
13771 | 364 |
|
365 |
apply clarsimp |
|
366 |
apply(rule conjI) |
|
367 |
apply clarsimp |
|
368 |
apply(rule_tac x = "rs @ [s]" in exI) |
|
369 |
apply simp |
|
370 |
apply(rule_tac x = "bsa" in exI) |
|
371 |
apply(rule conjI) |
|
372 |
apply (simp add:eq_sym_conv) |
|
373 |
apply(rule exI) |
|
374 |
apply(rule conjI) |
|
375 |
apply(rule_tac x = bs in exI) |
|
376 |
apply(rule conjI) |
|
377 |
apply(rule refl) |
|
378 |
apply (simp add:eq_sym_conv) |
|
379 |
apply (simp add:eq_sym_conv) |
|
380 |
||
381 |
apply(rule conjI) |
|
382 |
apply clarsimp |
|
383 |
apply(rule_tac x = "rs @ [s]" in exI) |
|
384 |
apply simp |
|
385 |
apply(rule_tac x = bs in exI) |
|
386 |
apply (simp add:eq_sym_conv) |
|
387 |
apply clarsimp |
|
388 |
apply(rule_tac x = "rs @ [s]" in exI) |
|
389 |
apply (simp add:eq_sym_conv) |
|
390 |
apply(rule exI) |
|
391 |
apply(rule conjI) |
|
392 |
apply(rule_tac x = bsa in exI) |
|
393 |
apply(rule conjI) |
|
394 |
apply(rule refl) |
|
395 |
apply (simp add:eq_sym_conv) |
|
396 |
apply(rule_tac x = bs in exI) |
|
397 |
apply (simp add:eq_sym_conv) |
|
398 |
||
399 |
apply(clarsimp simp add:List_app) |
|
400 |
done |
|
401 |
||
402 |
(* TODO: merging with islist/list instead of List: an improvement? |
|
403 |
needs (is)path, which is not so easy to prove either. *) |
|
404 |
||
72990 | 405 |
subsubsection "Storage allocation" |
13771 | 406 |
|
38353 | 407 |
definition new :: "'a set \<Rightarrow> 'a::ref" |
408 |
where "new A = (SOME a. a \<notin> A & a \<noteq> Null)" |
|
13771 | 409 |
|
410 |
||
411 |
lemma new_notin: |
|
412 |
"\<lbrakk> ~finite(UNIV::('a::ref)set); finite(A::'a set); B \<subseteq> A \<rbrakk> \<Longrightarrow> |
|
413 |
new (A) \<notin> B & new A \<noteq> Null" |
|
414 |
apply(unfold new_def) |
|
415 |
apply(rule someI2_ex) |
|
416 |
apply (fast dest:ex_new_if_finite[of "insert Null A"]) |
|
417 |
apply (fast) |
|
418 |
done |
|
419 |
||
420 |
lemma "~finite(UNIV::('a::ref)set) \<Longrightarrow> |
|
421 |
VARS xs elem next alloc p q |
|
422 |
{Xs = xs \<and> p = (Null::'a)} |
|
423 |
WHILE xs \<noteq> [] |
|
424 |
INV {islist next p \<and> set(list next p) \<subseteq> set alloc \<and> |
|
425 |
map elem (rev(list next p)) @ xs = Xs} |
|
426 |
DO q := new(set alloc); alloc := q#alloc; |
|
427 |
q^.next := p; q^.elem := hd xs; xs := tl xs; p := q |
|
428 |
OD |
|
429 |
{islist next p \<and> map elem (rev(list next p)) = Xs}" |
|
430 |
apply vcg_simp |
|
431 |
apply (clarsimp simp: subset_insert_iff neq_Nil_conv fun_upd_apply new_notin) |
|
432 |
done |
|
433 |
||
434 |
end |