1.1 --- a/src/HOL/Imperative_HOL/Ref.thy Tue Jul 06 09:21:13 2010 +0200
1.2 +++ b/src/HOL/Imperative_HOL/Ref.thy Tue Jul 06 09:21:15 2010 +0200
1.3 @@ -16,185 +16,175 @@
1.4
1.5 subsection {* Primitive layer *}
1.6
1.7 -definition
1.8 - ref_present :: "'a\<Colon>heap ref \<Rightarrow> heap \<Rightarrow> bool" where
1.9 - "ref_present r h \<longleftrightarrow> addr_of_ref r < lim h"
1.10 +definition present :: "heap \<Rightarrow> 'a\<Colon>heap ref \<Rightarrow> bool" where
1.11 + "present h r \<longleftrightarrow> addr_of_ref r < lim h"
1.12
1.13 -definition
1.14 - get_ref :: "'a\<Colon>heap ref \<Rightarrow> heap \<Rightarrow> 'a" where
1.15 - "get_ref r h = from_nat (refs h (TYPEREP('a)) (addr_of_ref r))"
1.16 +definition get :: "heap \<Rightarrow> 'a\<Colon>heap ref \<Rightarrow> 'a" where
1.17 + "get h = from_nat \<circ> refs h TYPEREP('a) \<circ> addr_of_ref"
1.18
1.19 -definition
1.20 - set_ref :: "'a\<Colon>heap ref \<Rightarrow> 'a \<Rightarrow> heap \<Rightarrow> heap" where
1.21 - "set_ref r x =
1.22 - refs_update (\<lambda>h. h(TYPEREP('a) := ((h (TYPEREP('a))) (addr_of_ref r:=to_nat x))))"
1.23 +definition set :: "'a\<Colon>heap ref \<Rightarrow> 'a \<Rightarrow> heap \<Rightarrow> heap" where
1.24 + "set r x = refs_update
1.25 + (\<lambda>h. h(TYPEREP('a) := ((h (TYPEREP('a))) (addr_of_ref r := to_nat x))))"
1.26
1.27 -definition ref :: "'a \<Rightarrow> heap \<Rightarrow> 'a\<Colon>heap ref \<times> heap" where
1.28 - "ref x h = (let
1.29 +definition alloc :: "'a \<Rightarrow> heap \<Rightarrow> 'a\<Colon>heap ref \<times> heap" where
1.30 + "alloc x h = (let
1.31 l = lim h;
1.32 - r = Ref l;
1.33 - h'' = set_ref r x (h\<lparr>lim := l + 1\<rparr>)
1.34 - in (r, h''))"
1.35 + r = Ref l
1.36 + in (r, set r x (h\<lparr>lim := l + 1\<rparr>)))"
1.37
1.38 -definition noteq_refs :: "('a\<Colon>heap) ref \<Rightarrow> ('b\<Colon>heap) ref \<Rightarrow> bool" (infix "=!=" 70) where
1.39 +definition noteq :: "'a\<Colon>heap ref \<Rightarrow> 'b\<Colon>heap ref \<Rightarrow> bool" (infix "=!=" 70) where
1.40 "r =!= s \<longleftrightarrow> TYPEREP('a) \<noteq> TYPEREP('b) \<or> addr_of_ref r \<noteq> addr_of_ref s"
1.41
1.42 -lemma noteq_refs_sym: "r =!= s \<Longrightarrow> s =!= r"
1.43 - and unequal_refs [simp]: "r \<noteq> r' \<longleftrightarrow> r =!= r'" -- "same types!"
1.44 - unfolding noteq_refs_def by auto
1.45 +lemma noteq_sym: "r =!= s \<Longrightarrow> s =!= r"
1.46 + and unequal [simp]: "r \<noteq> r' \<longleftrightarrow> r =!= r'" -- "same types!"
1.47 + by (auto simp add: noteq_def)
1.48
1.49 -lemma noteq_refs_irrefl: "r =!= r \<Longrightarrow> False"
1.50 - unfolding noteq_refs_def by auto
1.51 +lemma noteq_irrefl: "r =!= r \<Longrightarrow> False"
1.52 + by (auto simp add: noteq_def)
1.53
1.54 -lemma present_new_ref: "ref_present r h \<Longrightarrow> r =!= fst (ref v h)"
1.55 - by (simp add: ref_present_def ref_def Let_def noteq_refs_def)
1.56 +lemma present_alloc_neq: "present h r \<Longrightarrow> r =!= fst (alloc v h)"
1.57 + by (simp add: present_def alloc_def noteq_def Let_def)
1.58
1.59 -lemma next_ref_fresh [simp]:
1.60 - assumes "(r, h') = ref x h"
1.61 - shows "\<not> ref_present r h"
1.62 - using assms by (cases h) (auto simp add: ref_def ref_present_def Let_def)
1.63 +lemma next_fresh [simp]:
1.64 + assumes "(r, h') = alloc x h"
1.65 + shows "\<not> present h r"
1.66 + using assms by (cases h) (auto simp add: alloc_def present_def Let_def)
1.67
1.68 -lemma next_ref_present [simp]:
1.69 - assumes "(r, h') = ref x h"
1.70 - shows "ref_present r h'"
1.71 - using assms by (cases h) (auto simp add: ref_def set_ref_def ref_present_def Let_def)
1.72 +lemma next_present [simp]:
1.73 + assumes "(r, h') = alloc x h"
1.74 + shows "present h' r"
1.75 + using assms by (cases h) (auto simp add: alloc_def set_def present_def Let_def)
1.76
1.77 -lemma ref_get_set_eq [simp]: "get_ref r (set_ref r x h) = x"
1.78 - by (simp add: get_ref_def set_ref_def)
1.79 +lemma get_set_eq [simp]:
1.80 + "get (set r x h) r = x"
1.81 + by (simp add: get_def set_def)
1.82
1.83 -lemma ref_get_set_neq [simp]: "r =!= s \<Longrightarrow> get_ref r (set_ref s x h) = get_ref r h"
1.84 - by (simp add: noteq_refs_def get_ref_def set_ref_def)
1.85 +lemma get_set_neq [simp]:
1.86 + "r =!= s \<Longrightarrow> get (set s x h) r = get h r"
1.87 + by (simp add: noteq_def get_def set_def)
1.88
1.89 -(* FIXME: We need some infrastructure to infer that locally generated
1.90 - new refs (by new_ref(_no_init), new_array(')) are distinct
1.91 - from all existing refs.
1.92 -*)
1.93 +lemma set_same [simp]:
1.94 + "set r x (set r y h) = set r x h"
1.95 + by (simp add: set_def)
1.96
1.97 -lemma ref_set_get: "set_ref r (get_ref r h) h = h"
1.98 -apply (simp add: set_ref_def get_ref_def)
1.99 -oops
1.100 +lemma set_set_swap:
1.101 + "r =!= r' \<Longrightarrow> set r x (set r' x' h) = set r' x' (set r x h)"
1.102 + by (simp add: noteq_def set_def expand_fun_eq)
1.103
1.104 -lemma set_ref_same[simp]:
1.105 - "set_ref r x (set_ref r y h) = set_ref r x h"
1.106 - by (simp add: set_ref_def)
1.107 +lemma alloc_set:
1.108 + "fst (alloc x (set r x' h)) = fst (alloc x h)"
1.109 + by (simp add: alloc_def set_def Let_def)
1.110
1.111 -lemma ref_set_set_swap:
1.112 - "r =!= r' \<Longrightarrow> set_ref r x (set_ref r' x' h) = set_ref r' x' (set_ref r x h)"
1.113 - by (simp add: Let_def expand_fun_eq noteq_refs_def set_ref_def)
1.114 +lemma get_alloc [simp]:
1.115 + "get (snd (alloc x h)) (fst (alloc x' h)) = x"
1.116 + by (simp add: alloc_def Let_def)
1.117
1.118 -lemma ref_new_set: "fst (ref v (set_ref r v' h)) = fst (ref v h)"
1.119 - by (simp add: ref_def set_ref_def Let_def)
1.120 +lemma set_alloc [simp]:
1.121 + "set (fst (alloc v h)) v' (snd (alloc v h)) = snd (alloc v' h)"
1.122 + by (simp add: alloc_def Let_def)
1.123
1.124 -lemma ref_get_new [simp]:
1.125 - "get_ref (fst (ref v h)) (snd (ref v' h)) = v'"
1.126 - by (simp add: ref_def Let_def split_def)
1.127 +lemma get_alloc_neq: "r =!= fst (alloc v h) \<Longrightarrow>
1.128 + get (snd (alloc v h)) r = get h r"
1.129 + by (simp add: get_def set_def alloc_def Let_def noteq_def)
1.130
1.131 -lemma ref_set_new [simp]:
1.132 - "set_ref (fst (ref v h)) new_v (snd (ref v h)) = snd (ref new_v h)"
1.133 - by (simp add: ref_def Let_def split_def)
1.134 +lemma lim_set [simp]:
1.135 + "lim (set r v h) = lim h"
1.136 + by (simp add: set_def)
1.137
1.138 -lemma ref_get_new_neq: "r =!= (fst (ref v h)) \<Longrightarrow>
1.139 - get_ref r (snd (ref v h)) = get_ref r h"
1.140 - by (simp add: get_ref_def set_ref_def ref_def Let_def noteq_refs_def)
1.141 +lemma present_alloc [simp]:
1.142 + "present h r \<Longrightarrow> present (snd (alloc v h)) r"
1.143 + by (simp add: present_def alloc_def Let_def)
1.144
1.145 -lemma lim_set_ref [simp]:
1.146 - "lim (set_ref r v h) = lim h"
1.147 - by (simp add: set_ref_def)
1.148 +lemma present_set [simp]:
1.149 + "present (set r v h) = present h"
1.150 + by (simp add: present_def expand_fun_eq)
1.151
1.152 -lemma ref_present_new_ref [simp]:
1.153 - "ref_present r h \<Longrightarrow> ref_present r (snd (ref v h))"
1.154 - by (simp add: ref_present_def ref_def Let_def)
1.155 -
1.156 -lemma ref_present_set_ref [simp]:
1.157 - "ref_present r (set_ref r' v h) = ref_present r h"
1.158 - by (simp add: set_ref_def ref_present_def)
1.159 -
1.160 -lemma noteq_refsI: "\<lbrakk> ref_present r h; \<not>ref_present r' h \<rbrakk> \<Longrightarrow> r =!= r'"
1.161 - unfolding noteq_refs_def ref_present_def
1.162 - by auto
1.163 +lemma noteq_I:
1.164 + "present h r \<Longrightarrow> \<not> present h r' \<Longrightarrow> r =!= r'"
1.165 + by (auto simp add: noteq_def present_def)
1.166
1.167
1.168 subsection {* Primitives *}
1.169
1.170 -definition
1.171 - new :: "'a\<Colon>heap \<Rightarrow> 'a ref Heap" where
1.172 - [code del]: "new v = Heap_Monad.heap (Ref.ref v)"
1.173 +definition ref :: "'a\<Colon>heap \<Rightarrow> 'a ref Heap" where
1.174 + [code del]: "ref v = Heap_Monad.heap (alloc v)"
1.175
1.176 -definition
1.177 - lookup :: "'a\<Colon>heap ref \<Rightarrow> 'a Heap" ("!_" 61) where
1.178 - [code del]: "lookup r = Heap_Monad.heap (\<lambda>h. (get_ref r h, h))"
1.179 +definition lookup :: "'a\<Colon>heap ref \<Rightarrow> 'a Heap" ("!_" 61) where
1.180 + [code del]: "lookup r = Heap_Monad.heap (\<lambda>h. (get h r, h))"
1.181
1.182 -definition
1.183 - update :: "'a ref \<Rightarrow> ('a\<Colon>heap) \<Rightarrow> unit Heap" ("_ := _" 62) where
1.184 - [code del]: "update r e = Heap_Monad.heap (\<lambda>h. ((), set_ref r e h))"
1.185 +definition update :: "'a ref \<Rightarrow> 'a\<Colon>heap \<Rightarrow> unit Heap" ("_ := _" 62) where
1.186 + [code del]: "update r v = Heap_Monad.heap (\<lambda>h. ((), set r v h))"
1.187
1.188
1.189 subsection {* Derivates *}
1.190
1.191 -definition
1.192 - change :: "('a\<Colon>heap \<Rightarrow> 'a) \<Rightarrow> 'a ref \<Rightarrow> 'a Heap"
1.193 -where
1.194 - "change f r = (do x \<leftarrow> ! r;
1.195 - let y = f x;
1.196 - r := y;
1.197 - return y
1.198 - done)"
1.199 -
1.200 -hide_const (open) new lookup update change
1.201 +definition change :: "('a\<Colon>heap \<Rightarrow> 'a) \<Rightarrow> 'a ref \<Rightarrow> 'a Heap" where
1.202 + "change f r = (do
1.203 + x \<leftarrow> ! r;
1.204 + let y = f x;
1.205 + r := y;
1.206 + return y
1.207 + done)"
1.208
1.209
1.210 subsection {* Properties *}
1.211
1.212 lemma lookup_chain:
1.213 "(!r \<guillemotright> f) = f"
1.214 - by (cases f)
1.215 - (auto simp add: Let_def bindM_def lookup_def expand_fun_eq)
1.216 + by (rule Heap_eqI) (simp add: lookup_def)
1.217
1.218 lemma update_change [code]:
1.219 - "r := e = Ref.change (\<lambda>_. e) r \<guillemotright> return ()"
1.220 - by (auto simp add: change_def lookup_chain)
1.221 + "r := e = change (\<lambda>_. e) r \<guillemotright> return ()"
1.222 + by (rule Heap_eqI) (simp add: change_def lookup_chain)
1.223
1.224
1.225 text {* Non-interaction between imperative array and imperative references *}
1.226
1.227 -lemma get_array_set_ref [simp]: "get_array a (set_ref r v h) = get_array a h"
1.228 - by (simp add: get_array_def set_ref_def)
1.229 +lemma get_array_set [simp]:
1.230 + "get_array a (set r v h) = get_array a h"
1.231 + by (simp add: get_array_def set_def)
1.232
1.233 -lemma nth_set_ref [simp]: "get_array a (set_ref r v h) ! i = get_array a h ! i"
1.234 +lemma nth_set [simp]:
1.235 + "get_array a (set r v h) ! i = get_array a h ! i"
1.236 by simp
1.237
1.238 -lemma get_ref_upd [simp]: "get_ref r (Array.change a i v h) = get_ref r h"
1.239 - by (simp add: get_ref_def set_array_def Array.change_def)
1.240 +lemma get_change [simp]:
1.241 + "get (Array.change a i v h) r = get h r"
1.242 + by (simp add: get_def Array.change_def set_array_def)
1.243
1.244 -lemma new_ref_upd: "fst (ref v (Array.change a i v' h)) = fst (ref v h)"
1.245 - by (simp add: set_array_def get_array_def Let_def ref_new_set Array.change_def ref_def)
1.246 +lemma alloc_change:
1.247 + "fst (alloc v (Array.change a i v' h)) = fst (alloc v h)"
1.248 + by (simp add: Array.change_def get_array_def set_array_def alloc_def Let_def)
1.249
1.250 -lemma upd_set_ref_swap: "Array.change a i v (set_ref r v' h) = set_ref r v' (Array.change a i v h)"
1.251 - by (simp add: set_ref_def Array.change_def get_array_def set_array_def)
1.252 +lemma change_set_swap:
1.253 + "Array.change a i v (set r v' h) = set r v' (Array.change a i v h)"
1.254 + by (simp add: Array.change_def get_array_def set_array_def set_def)
1.255
1.256 -lemma length_new_ref[simp]:
1.257 - "length a (snd (ref v h)) = length a h"
1.258 - by (simp add: get_array_def set_ref_def length_def ref_def Let_def)
1.259 +lemma length_alloc [simp]:
1.260 + "Array.length a (snd (alloc v h)) = Array.length a h"
1.261 + by (simp add: Array.length_def get_array_def alloc_def set_def Let_def)
1.262
1.263 -lemma get_array_new_ref [simp]:
1.264 - "get_array a (snd (ref v h)) = get_array a h"
1.265 - by (simp add: ref_def set_ref_def get_array_def Let_def)
1.266 +lemma get_array_alloc [simp]:
1.267 + "get_array a (snd (alloc v h)) = get_array a h"
1.268 + by (simp add: get_array_def alloc_def set_def Let_def)
1.269
1.270 -lemma ref_present_upd [simp]:
1.271 - "ref_present r (Array.change a i v h) = ref_present r h"
1.272 - by (simp add: Array.change_def ref_present_def set_array_def get_array_def)
1.273 +lemma present_change [simp]:
1.274 + "present (Array.change a i v h) = present h"
1.275 + by (simp add: Array.change_def set_array_def expand_fun_eq present_def)
1.276
1.277 -lemma array_present_set_ref [simp]:
1.278 - "array_present a (set_ref r v h) = array_present a h"
1.279 - by (simp add: array_present_def set_ref_def)
1.280 +lemma array_present_set [simp]:
1.281 + "array_present a (set r v h) = array_present a h"
1.282 + by (simp add: array_present_def set_def)
1.283
1.284 -lemma array_present_new_ref [simp]:
1.285 - "array_present a h \<Longrightarrow> array_present a (snd (ref v h))"
1.286 - by (simp add: array_present_def ref_def Let_def)
1.287 +lemma array_present_alloc [simp]:
1.288 + "array_present a h \<Longrightarrow> array_present a (snd (alloc v h))"
1.289 + by (simp add: array_present_def alloc_def Let_def)
1.290
1.291 -lemma array_ref_set_set_swap:
1.292 - "set_array r x (set_ref r' x' h) = set_ref r' x' (set_array r x h)"
1.293 - by (simp add: Let_def expand_fun_eq set_array_def set_ref_def)
1.294 +lemma set_array_set_swap:
1.295 + "set_array a xs (set r x' h) = set r x' (set_array a xs h)"
1.296 + by (simp add: set_array_def set_def)
1.297 +
1.298 +hide_const (open) present get set alloc lookup update change
1.299
1.300
1.301 subsection {* Code generator setup *}
1.302 @@ -203,7 +193,7 @@
1.303
1.304 code_type ref (SML "_/ Unsynchronized.ref")
1.305 code_const Ref (SML "raise/ (Fail/ \"bare Ref\")")
1.306 -code_const Ref.new (SML "(fn/ ()/ =>/ Unsynchronized.ref/ _)")
1.307 +code_const ref (SML "(fn/ ()/ =>/ Unsynchronized.ref/ _)")
1.308 code_const Ref.lookup (SML "(fn/ ()/ =>/ !/ _)")
1.309 code_const Ref.update (SML "(fn/ ()/ =>/ _/ :=/ _)")
1.310
1.311 @@ -214,7 +204,7 @@
1.312
1.313 code_type ref (OCaml "_/ ref")
1.314 code_const Ref (OCaml "failwith/ \"bare Ref\")")
1.315 -code_const Ref.new (OCaml "(fn/ ()/ =>/ ref/ _)")
1.316 +code_const ref (OCaml "(fn/ ()/ =>/ ref/ _)")
1.317 code_const Ref.lookup (OCaml "(fn/ ()/ =>/ !/ _)")
1.318 code_const Ref.update (OCaml "(fn/ ()/ =>/ _/ :=/ _)")
1.319
1.320 @@ -225,7 +215,7 @@
1.321
1.322 code_type ref (Haskell "Heap.STRef/ Heap.RealWorld/ _")
1.323 code_const Ref (Haskell "error/ \"bare Ref\"")
1.324 -code_const Ref.new (Haskell "Heap.newSTRef")
1.325 +code_const ref (Haskell "Heap.newSTRef")
1.326 code_const Ref.lookup (Haskell "Heap.readSTRef")
1.327 code_const Ref.update (Haskell "Heap.writeSTRef")
1.328
2.1 --- a/src/HOL/Imperative_HOL/Relational.thy Tue Jul 06 09:21:13 2010 +0200
2.2 +++ b/src/HOL/Imperative_HOL/Relational.thy Tue Jul 06 09:21:15 2010 +0200
2.3 @@ -311,42 +311,42 @@
2.4 extends h' h x \<Longrightarrow> lim h' = Suc (lim h)
2.5 *)
2.6
2.7 -lemma crel_Ref_new:
2.8 - assumes "crel (Ref.new v) h h' x"
2.9 - obtains "get_ref x h' = v"
2.10 - and "\<not> ref_present x h"
2.11 - and "ref_present x h'"
2.12 - and "\<forall>y. ref_present y h \<longrightarrow> get_ref y h = get_ref y h'"
2.13 +lemma crel_ref:
2.14 + assumes "crel (ref v) h h' x"
2.15 + obtains "Ref.get h' x = v"
2.16 + and "\<not> Ref.present h x"
2.17 + and "Ref.present h' x"
2.18 + and "\<forall>y. Ref.present h y \<longrightarrow> Ref.get h y = Ref.get h' y"
2.19 (* and "lim h' = Suc (lim h)" *)
2.20 - and "\<forall>y. ref_present y h \<longrightarrow> ref_present y h'"
2.21 + and "\<forall>y. Ref.present h y \<longrightarrow> Ref.present h' y"
2.22 using assms
2.23 - unfolding Ref.new_def
2.24 + unfolding Ref.ref_def
2.25 apply (elim crel_heap)
2.26 - unfolding Ref.ref_def
2.27 + unfolding Ref.alloc_def
2.28 apply (simp add: Let_def)
2.29 - unfolding ref_present_def
2.30 + unfolding Ref.present_def
2.31 apply auto
2.32 - unfolding get_ref_def set_ref_def
2.33 + unfolding Ref.get_def Ref.set_def
2.34 apply auto
2.35 done
2.36
2.37 lemma crel_lookup:
2.38 assumes "crel (!r') h h' r"
2.39 - obtains "h = h'" "r = get_ref r' h"
2.40 + obtains "h = h'" "r = Ref.get h r'"
2.41 using assms
2.42 unfolding Ref.lookup_def
2.43 by (auto elim: crel_heap)
2.44
2.45 lemma crel_update:
2.46 assumes "crel (r' := v) h h' r"
2.47 - obtains "h' = set_ref r' v h" "r = ()"
2.48 + obtains "h' = Ref.set r' v h" "r = ()"
2.49 using assms
2.50 unfolding Ref.update_def
2.51 by (auto elim: crel_heap)
2.52
2.53 lemma crel_change:
2.54 assumes "crel (Ref.change f r') h h' r"
2.55 - obtains "h' = set_ref r' (f (get_ref r' h)) h" "r = f (get_ref r' h)"
2.56 + obtains "h' = Ref.set r' (f (Ref.get h r')) h" "r = f (Ref.get h r')"
2.57 using assms
2.58 unfolding Ref.change_def Let_def
2.59 by (auto elim!: crelE crel_lookup crel_update crel_return)
2.60 @@ -467,15 +467,15 @@
2.61 subsubsection {* Introduction rules for reference commands *}
2.62
2.63 lemma crel_lookupI:
2.64 - shows "crel (!r) h h (get_ref r h)"
2.65 + shows "crel (!r) h h (Ref.get h r)"
2.66 unfolding lookup_def by (auto intro!: crel_heapI')
2.67
2.68 lemma crel_updateI:
2.69 - shows "crel (r := v) h (set_ref r v h) ()"
2.70 + shows "crel (r := v) h (Ref.set r v h) ()"
2.71 unfolding update_def by (auto intro!: crel_heapI')
2.72
2.73 lemma crel_changeI:
2.74 - shows "crel (Ref.change f r) h (set_ref r (f (get_ref r h)) h) (f (get_ref r h))"
2.75 + shows "crel (Ref.change f r) h (Ref.set r (f (Ref.get h r)) h) (f (Ref.get h r))"
2.76 unfolding change_def Let_def by (auto intro!: crelI crel_returnI crel_lookupI crel_updateI)
2.77
2.78 subsubsection {* Introduction rules for the assert command *}
2.79 @@ -667,8 +667,8 @@
2.80 subsection {* Introduction rules for the reference commands *}
2.81
2.82 lemma noError_Ref_new:
2.83 - shows "noError (Ref.new v) h"
2.84 -unfolding Ref.new_def by (intro noError_heap)
2.85 + shows "noError (ref v) h"
2.86 + unfolding Ref.ref_def by (intro noError_heap)
2.87
2.88 lemma noError_lookup:
2.89 shows "noError (!r) h"
2.90 @@ -696,7 +696,7 @@
2.91 lemmas crel_elim_all =
2.92 crelE crelE' crel_return crel_raise crel_if crel_option_case
2.93 crel_length crel_new_weak crel_nth crel_upd crel_of_list_weak crel_map_entry crel_swap crel_make_weak crel_freeze crel_map_weak
2.94 - crel_Ref_new crel_lookup crel_update crel_change
2.95 + crel_ref crel_lookup crel_update crel_change
2.96 crel_assert
2.97
2.98 lemmas crel_intro_all =
3.1 --- a/src/HOL/Imperative_HOL/ex/Linked_Lists.thy Tue Jul 06 09:21:13 2010 +0200
3.2 +++ b/src/HOL/Imperative_HOL/ex/Linked_Lists.thy Tue Jul 06 09:21:15 2010 +0200
3.3 @@ -13,7 +13,7 @@
3.4 setup {* Sign.add_const_constraint (@{const_name Ref}, SOME @{typ "nat \<Rightarrow> 'a\<Colon>type ref"}) *}
3.5 datatype 'a node = Empty | Node 'a "('a node) ref"
3.6
3.7 -fun
3.8 +primrec
3.9 node_encode :: "'a\<Colon>countable node \<Rightarrow> nat"
3.10 where
3.11 "node_encode Empty = 0"
3.12 @@ -28,11 +28,11 @@
3.13
3.14 instance node :: (heap) heap ..
3.15
3.16 -fun make_llist :: "'a\<Colon>heap list \<Rightarrow> 'a node Heap"
3.17 +primrec make_llist :: "'a\<Colon>heap list \<Rightarrow> 'a node Heap"
3.18 where
3.19 [simp del]: "make_llist [] = return Empty"
3.20 | "make_llist (x#xs) = do tl \<leftarrow> make_llist xs;
3.21 - next \<leftarrow> Ref.new tl;
3.22 + next \<leftarrow> ref tl;
3.23 return (Node x next)
3.24 done"
3.25
3.26 @@ -63,24 +63,24 @@
3.27
3.28 subsection {* Definition of list_of, list_of', refs_of and refs_of' *}
3.29
3.30 -fun list_of :: "heap \<Rightarrow> ('a::heap) node \<Rightarrow> 'a list \<Rightarrow> bool"
3.31 +primrec list_of :: "heap \<Rightarrow> ('a::heap) node \<Rightarrow> 'a list \<Rightarrow> bool"
3.32 where
3.33 "list_of h r [] = (r = Empty)"
3.34 -| "list_of h r (a#as) = (case r of Empty \<Rightarrow> False | Node b bs \<Rightarrow> (a = b \<and> list_of h (get_ref bs h) as))"
3.35 +| "list_of h r (a#as) = (case r of Empty \<Rightarrow> False | Node b bs \<Rightarrow> (a = b \<and> list_of h (Ref.get h bs) as))"
3.36
3.37 definition list_of' :: "heap \<Rightarrow> ('a::heap) node ref \<Rightarrow> 'a list \<Rightarrow> bool"
3.38 where
3.39 - "list_of' h r xs = list_of h (get_ref r h) xs"
3.40 + "list_of' h r xs = list_of h (Ref.get h r) xs"
3.41
3.42 -fun refs_of :: "heap \<Rightarrow> ('a::heap) node \<Rightarrow> 'a node ref list \<Rightarrow> bool"
3.43 +primrec refs_of :: "heap \<Rightarrow> ('a::heap) node \<Rightarrow> 'a node ref list \<Rightarrow> bool"
3.44 where
3.45 "refs_of h r [] = (r = Empty)"
3.46 -| "refs_of h r (x#xs) = (case r of Empty \<Rightarrow> False | Node b bs \<Rightarrow> (x = bs) \<and> refs_of h (get_ref bs h) xs)"
3.47 +| "refs_of h r (x#xs) = (case r of Empty \<Rightarrow> False | Node b bs \<Rightarrow> (x = bs) \<and> refs_of h (Ref.get h bs) xs)"
3.48
3.49 -fun refs_of' :: "heap \<Rightarrow> ('a::heap) node ref \<Rightarrow> 'a node ref list \<Rightarrow> bool"
3.50 +primrec refs_of' :: "heap \<Rightarrow> ('a::heap) node ref \<Rightarrow> 'a node ref list \<Rightarrow> bool"
3.51 where
3.52 "refs_of' h r [] = False"
3.53 -| "refs_of' h r (x#xs) = ((x = r) \<and> refs_of h (get_ref x h) xs)"
3.54 +| "refs_of' h r (x#xs) = ((x = r) \<and> refs_of h (Ref.get h x) xs)"
3.55
3.56
3.57 subsection {* Properties of these definitions *}
3.58 @@ -88,35 +88,35 @@
3.59 lemma list_of_Empty[simp]: "list_of h Empty xs = (xs = [])"
3.60 by (cases xs, auto)
3.61
3.62 -lemma list_of_Node[simp]: "list_of h (Node x ps) xs = (\<exists>xs'. (xs = x # xs') \<and> list_of h (get_ref ps h) xs')"
3.63 +lemma list_of_Node[simp]: "list_of h (Node x ps) xs = (\<exists>xs'. (xs = x # xs') \<and> list_of h (Ref.get h ps) xs')"
3.64 by (cases xs, auto)
3.65
3.66 -lemma list_of'_Empty[simp]: "get_ref q h = Empty \<Longrightarrow> list_of' h q xs = (xs = [])"
3.67 +lemma list_of'_Empty[simp]: "Ref.get h q = Empty \<Longrightarrow> list_of' h q xs = (xs = [])"
3.68 unfolding list_of'_def by simp
3.69
3.70 -lemma list_of'_Node[simp]: "get_ref q h = Node x ps \<Longrightarrow> list_of' h q xs = (\<exists>xs'. (xs = x # xs') \<and> list_of' h ps xs')"
3.71 +lemma list_of'_Node[simp]: "Ref.get h q = Node x ps \<Longrightarrow> list_of' h q xs = (\<exists>xs'. (xs = x # xs') \<and> list_of' h ps xs')"
3.72 unfolding list_of'_def by simp
3.73
3.74 -lemma list_of'_Nil: "list_of' h q [] \<Longrightarrow> get_ref q h = Empty"
3.75 +lemma list_of'_Nil: "list_of' h q [] \<Longrightarrow> Ref.get h q = Empty"
3.76 unfolding list_of'_def by simp
3.77
3.78 lemma list_of'_Cons:
3.79 assumes "list_of' h q (x#xs)"
3.80 -obtains n where "get_ref q h = Node x n" and "list_of' h n xs"
3.81 +obtains n where "Ref.get h q = Node x n" and "list_of' h n xs"
3.82 using assms unfolding list_of'_def by (auto split: node.split_asm)
3.83
3.84 lemma refs_of_Empty[simp] : "refs_of h Empty xs = (xs = [])"
3.85 by (cases xs, auto)
3.86
3.87 -lemma refs_of_Node[simp]: "refs_of h (Node x ps) xs = (\<exists>prs. xs = ps # prs \<and> refs_of h (get_ref ps h) prs)"
3.88 +lemma refs_of_Node[simp]: "refs_of h (Node x ps) xs = (\<exists>prs. xs = ps # prs \<and> refs_of h (Ref.get h ps) prs)"
3.89 by (cases xs, auto)
3.90
3.91 -lemma refs_of'_def': "refs_of' h p ps = (\<exists>prs. (ps = (p # prs)) \<and> refs_of h (get_ref p h) prs)"
3.92 +lemma refs_of'_def': "refs_of' h p ps = (\<exists>prs. (ps = (p # prs)) \<and> refs_of h (Ref.get h p) prs)"
3.93 by (cases ps, auto)
3.94
3.95 lemma refs_of'_Node:
3.96 assumes "refs_of' h p xs"
3.97 - assumes "get_ref p h = Node x pn"
3.98 + assumes "Ref.get h p = Node x pn"
3.99 obtains pnrs
3.100 where "xs = p # pnrs" and "refs_of' h pn pnrs"
3.101 using assms
3.102 @@ -166,7 +166,7 @@
3.103 assumes "list_of' h r xs"
3.104 shows "\<exists>rs. refs_of' h r rs"
3.105 proof -
3.106 - from assms obtain rs' where "refs_of h (get_ref r h) rs'"
3.107 + from assms obtain rs' where "refs_of h (Ref.get h r) rs'"
3.108 unfolding list_of'_def by (rule list_of_refs_of)
3.109 thus ?thesis unfolding refs_of'_def' by auto
3.110 qed
3.111 @@ -238,7 +238,7 @@
3.112 done
3.113
3.114 lemma refs_of_next:
3.115 -assumes "refs_of h (get_ref p h) rs"
3.116 +assumes "refs_of h (Ref.get h p) rs"
3.117 shows "p \<notin> set rs"
3.118 proof (rule ccontr)
3.119 assume a: "\<not> (p \<notin> set rs)"
3.120 @@ -264,7 +264,7 @@
3.121
3.122 subsection {* Interaction of these predicates with our heap transitions *}
3.123
3.124 -lemma list_of_set_ref: "refs_of h q rs \<Longrightarrow> p \<notin> set rs \<Longrightarrow> list_of (set_ref p v h) q as = list_of h q as"
3.125 +lemma list_of_set_ref: "refs_of h q rs \<Longrightarrow> p \<notin> set rs \<Longrightarrow> list_of (Ref.set p v h) q as = list_of h q as"
3.126 using assms
3.127 proof (induct as arbitrary: q rs)
3.128 case Nil thus ?case by simp
3.129 @@ -275,15 +275,15 @@
3.130 case Empty thus ?thesis by auto
3.131 next
3.132 case (Node a ref)
3.133 - from Cons(2) Node obtain rs' where 1: "refs_of h (get_ref ref h) rs'" and rs_rs': "rs = ref # rs'" by auto
3.134 + from Cons(2) Node obtain rs' where 1: "refs_of h (Ref.get h ref) rs'" and rs_rs': "rs = ref # rs'" by auto
3.135 from Cons(3) rs_rs' have "ref \<noteq> p" by fastsimp
3.136 - hence ref_eq: "get_ref ref (set_ref p v h) = (get_ref ref h)" by (auto simp add: ref_get_set_neq)
3.137 + hence ref_eq: "Ref.get (Ref.set p v h) ref = (Ref.get h ref)" by (auto simp add: Ref.get_set_neq)
3.138 from rs_rs' Cons(3) have 2: "p \<notin> set rs'" by simp
3.139 from Cons.hyps[OF 1 2] Node ref_eq show ?thesis by simp
3.140 qed
3.141 qed
3.142
3.143 -lemma refs_of_set_ref: "refs_of h q rs \<Longrightarrow> p \<notin> set rs \<Longrightarrow> refs_of (set_ref p v h) q as = refs_of h q as"
3.144 +lemma refs_of_set_ref: "refs_of h q rs \<Longrightarrow> p \<notin> set rs \<Longrightarrow> refs_of (Ref.set p v h) q as = refs_of h q as"
3.145 proof (induct as arbitrary: q rs)
3.146 case Nil thus ?case by simp
3.147 next
3.148 @@ -293,15 +293,15 @@
3.149 case Empty thus ?thesis by auto
3.150 next
3.151 case (Node a ref)
3.152 - from Cons(2) Node obtain rs' where 1: "refs_of h (get_ref ref h) rs'" and rs_rs': "rs = ref # rs'" by auto
3.153 + from Cons(2) Node obtain rs' where 1: "refs_of h (Ref.get h ref) rs'" and rs_rs': "rs = ref # rs'" by auto
3.154 from Cons(3) rs_rs' have "ref \<noteq> p" by fastsimp
3.155 - hence ref_eq: "get_ref ref (set_ref p v h) = (get_ref ref h)" by (auto simp add: ref_get_set_neq)
3.156 + hence ref_eq: "Ref.get (Ref.set p v h) ref = (Ref.get h ref)" by (auto simp add: Ref.get_set_neq)
3.157 from rs_rs' Cons(3) have 2: "p \<notin> set rs'" by simp
3.158 from Cons.hyps[OF 1 2] Node ref_eq show ?thesis by auto
3.159 qed
3.160 qed
3.161
3.162 -lemma refs_of_set_ref2: "refs_of (set_ref p v h) q rs \<Longrightarrow> p \<notin> set rs \<Longrightarrow> refs_of (set_ref p v h) q rs = refs_of h q rs"
3.163 +lemma refs_of_set_ref2: "refs_of (Ref.set p v h) q rs \<Longrightarrow> p \<notin> set rs \<Longrightarrow> refs_of (Ref.set p v h) q rs = refs_of h q rs"
3.164 proof (induct rs arbitrary: q)
3.165 case Nil thus ?case by simp
3.166 next
3.167 @@ -311,9 +311,9 @@
3.168 case Empty thus ?thesis by auto
3.169 next
3.170 case (Node a ref)
3.171 - from Cons(2) Node have 1:"refs_of (set_ref p v h) (get_ref ref (set_ref p v h)) xs" and x_ref: "x = ref" by auto
3.172 + from Cons(2) Node have 1:"refs_of (Ref.set p v h) (Ref.get (Ref.set p v h) ref) xs" and x_ref: "x = ref" by auto
3.173 from Cons(3) this have "ref \<noteq> p" by fastsimp
3.174 - hence ref_eq: "get_ref ref (set_ref p v h) = (get_ref ref h)" by (auto simp add: ref_get_set_neq)
3.175 + hence ref_eq: "Ref.get (Ref.set p v h) ref = (Ref.get h ref)" by (auto simp add: Ref.get_set_neq)
3.176 from Cons(3) have 2: "p \<notin> set xs" by simp
3.177 with Cons.hyps 1 2 Node ref_eq show ?thesis
3.178 by simp
3.179 @@ -323,7 +323,7 @@
3.180 lemma list_of'_set_ref:
3.181 assumes "refs_of' h q rs"
3.182 assumes "p \<notin> set rs"
3.183 - shows "list_of' (set_ref p v h) q as = list_of' h q as"
3.184 + shows "list_of' (Ref.set p v h) q as = list_of' h q as"
3.185 proof -
3.186 from assms have "q \<noteq> p" by (auto simp only: dest!: refs_of'E)
3.187 with assms show ?thesis
3.188 @@ -333,18 +333,18 @@
3.189
3.190 lemma list_of'_set_next_ref_Node[simp]:
3.191 assumes "list_of' h r xs"
3.192 - assumes "get_ref p h = Node x r'"
3.193 + assumes "Ref.get h p = Node x r'"
3.194 assumes "refs_of' h r rs"
3.195 assumes "p \<notin> set rs"
3.196 - shows "list_of' (set_ref p (Node x r) h) p (x#xs) = list_of' h r xs"
3.197 + shows "list_of' (Ref.set p (Node x r) h) p (x#xs) = list_of' h r xs"
3.198 using assms
3.199 unfolding list_of'_def refs_of'_def'
3.200 -by (auto simp add: list_of_set_ref noteq_refs_sym)
3.201 +by (auto simp add: list_of_set_ref Ref.noteq_sym)
3.202
3.203 lemma refs_of'_set_ref:
3.204 assumes "refs_of' h q rs"
3.205 assumes "p \<notin> set rs"
3.206 - shows "refs_of' (set_ref p v h) q as = refs_of' h q as"
3.207 + shows "refs_of' (Ref.set p v h) q as = refs_of' h q as"
3.208 using assms
3.209 proof -
3.210 from assms have "q \<noteq> p" by (auto simp only: dest!: refs_of'E)
3.211 @@ -354,9 +354,9 @@
3.212 qed
3.213
3.214 lemma refs_of'_set_ref2:
3.215 - assumes "refs_of' (set_ref p v h) q rs"
3.216 + assumes "refs_of' (Ref.set p v h) q rs"
3.217 assumes "p \<notin> set rs"
3.218 - shows "refs_of' (set_ref p v h) q as = refs_of' h q as"
3.219 + shows "refs_of' (Ref.set p v h) q as = refs_of' h q as"
3.220 using assms
3.221 proof -
3.222 from assms have "q \<noteq> p" by (auto simp only: dest!: refs_of'E)
3.223 @@ -364,7 +364,7 @@
3.224 unfolding refs_of'_def'
3.225 apply auto
3.226 apply (subgoal_tac "prs = prsa")
3.227 - apply (insert refs_of_set_ref2[of p v h "get_ref q h"])
3.228 + apply (insert refs_of_set_ref2[of p v h "Ref.get h q"])
3.229 apply (erule_tac x="prs" in meta_allE)
3.230 apply auto
3.231 apply (auto dest: refs_of_is_fun)
3.232 @@ -372,15 +372,15 @@
3.233 qed
3.234
3.235 lemma refs_of'_set_next_ref:
3.236 -assumes "get_ref p h1 = Node x pn"
3.237 -assumes "refs_of' (set_ref p (Node x r1) h1) p rs"
3.238 +assumes "Ref.get h1 p = Node x pn"
3.239 +assumes "refs_of' (Ref.set p (Node x r1) h1) p rs"
3.240 obtains r1s where "rs = (p#r1s)" and "refs_of' h1 r1 r1s"
3.241 using assms
3.242 proof -
3.243 from assms refs_of'_distinct[OF assms(2)] have "\<exists> r1s. rs = (p # r1s) \<and> refs_of' h1 r1 r1s"
3.244 apply -
3.245 unfolding refs_of'_def'[of _ p]
3.246 - apply (auto, frule refs_of_set_ref2) by (auto dest: noteq_refs_sym)
3.247 + apply (auto, frule refs_of_set_ref2) by (auto dest: Ref.noteq_sym)
3.248 with prems show thesis by auto
3.249 qed
3.250
3.251 @@ -388,7 +388,7 @@
3.252
3.253 lemma refs_of_invariant:
3.254 assumes "refs_of h (r::('a::heap) node) xs"
3.255 - assumes "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>ref \<in> set refs. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h')"
3.256 + assumes "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>ref \<in> set refs. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref)"
3.257 shows "refs_of h' r xs"
3.258 using assms
3.259 proof (induct xs arbitrary: r)
3.260 @@ -396,28 +396,28 @@
3.261 next
3.262 case (Cons x xs')
3.263 from Cons(2) obtain v where Node: "r = Node v x" by (cases r, auto)
3.264 - from Cons(2) Node have refs_of_next: "refs_of h (get_ref x h) xs'" by simp
3.265 - from Cons(2-3) Node have ref_eq: "get_ref x h = get_ref x h'" by auto
3.266 - from ref_eq refs_of_next have 1: "refs_of h (get_ref x h') xs'" by simp
3.267 - from Cons(2) Cons(3) have "\<forall>ref \<in> set xs'. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h'"
3.268 + from Cons(2) Node have refs_of_next: "refs_of h (Ref.get h x) xs'" by simp
3.269 + from Cons(2-3) Node have ref_eq: "Ref.get h x = Ref.get h' x" by auto
3.270 + from ref_eq refs_of_next have 1: "refs_of h (Ref.get h' x) xs'" by simp
3.271 + from Cons(2) Cons(3) have "\<forall>ref \<in> set xs'. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref"
3.272 by fastsimp
3.273 - with Cons(3) 1 have 2: "\<forall>refs. refs_of h (get_ref x h') refs \<longrightarrow> (\<forall>ref \<in> set refs. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h')"
3.274 + with Cons(3) 1 have 2: "\<forall>refs. refs_of h (Ref.get h' x) refs \<longrightarrow> (\<forall>ref \<in> set refs. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref)"
3.275 by (fastsimp dest: refs_of_is_fun)
3.276 - from Cons.hyps[OF 1 2] have "refs_of h' (get_ref x h') xs'" .
3.277 + from Cons.hyps[OF 1 2] have "refs_of h' (Ref.get h' x) xs'" .
3.278 with Node show ?case by simp
3.279 qed
3.280
3.281 lemma refs_of'_invariant:
3.282 assumes "refs_of' h r xs"
3.283 - assumes "\<forall>refs. refs_of' h r refs \<longrightarrow> (\<forall>ref \<in> set refs. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h')"
3.284 + assumes "\<forall>refs. refs_of' h r refs \<longrightarrow> (\<forall>ref \<in> set refs. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref)"
3.285 shows "refs_of' h' r xs"
3.286 using assms
3.287 proof -
3.288 - from assms obtain prs where refs:"refs_of h (get_ref r h) prs" and xs_def: "xs = r # prs"
3.289 + from assms obtain prs where refs:"refs_of h (Ref.get h r) prs" and xs_def: "xs = r # prs"
3.290 unfolding refs_of'_def' by auto
3.291 - from xs_def assms have x_eq: "get_ref r h = get_ref r h'" by fastsimp
3.292 - from refs assms xs_def have 2: "\<forall>refs. refs_of h (get_ref r h) refs \<longrightarrow>
3.293 - (\<forall>ref\<in>set refs. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h')"
3.294 + from xs_def assms have x_eq: "Ref.get h r = Ref.get h' r" by fastsimp
3.295 + from refs assms xs_def have 2: "\<forall>refs. refs_of h (Ref.get h r) refs \<longrightarrow>
3.296 + (\<forall>ref\<in>set refs. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref)"
3.297 by (fastsimp dest: refs_of_is_fun)
3.298 from refs_of_invariant [OF refs 2] xs_def x_eq show ?thesis
3.299 unfolding refs_of'_def' by auto
3.300 @@ -425,7 +425,7 @@
3.301
3.302 lemma list_of_invariant:
3.303 assumes "list_of h (r::('a::heap) node) xs"
3.304 - assumes "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>ref \<in> set refs. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h')"
3.305 + assumes "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>ref \<in> set refs. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref)"
3.306 shows "list_of h' r xs"
3.307 using assms
3.308 proof (induct xs arbitrary: r)
3.309 @@ -437,16 +437,16 @@
3.310 by (cases r, auto)
3.311 from Cons(2) obtain rs where rs_def: "refs_of h r rs" by (rule list_of_refs_of)
3.312 from Node rs_def obtain rss where refs_of: "refs_of h r (ref#rss)" and rss_def: "rs = ref#rss" by auto
3.313 - from Cons(3) Node refs_of have ref_eq: "get_ref ref h = get_ref ref h'"
3.314 + from Cons(3) Node refs_of have ref_eq: "Ref.get h ref = Ref.get h' ref"
3.315 by auto
3.316 - from Cons(2) ref_eq Node have 1: "list_of h (get_ref ref h') xs'" by simp
3.317 - from refs_of Node ref_eq have refs_of_ref: "refs_of h (get_ref ref h') rss" by simp
3.318 - from Cons(3) rs_def have rs_heap_eq: "\<forall>ref\<in>set rs. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h'" by simp
3.319 - from refs_of_ref rs_heap_eq rss_def have 2: "\<forall>refs. refs_of h (get_ref ref h') refs \<longrightarrow>
3.320 - (\<forall>ref\<in>set refs. ref_present ref h \<and> ref_present ref h' \<and> get_ref ref h = get_ref ref h')"
3.321 + from Cons(2) ref_eq Node have 1: "list_of h (Ref.get h' ref) xs'" by simp
3.322 + from refs_of Node ref_eq have refs_of_ref: "refs_of h (Ref.get h' ref) rss" by simp
3.323 + from Cons(3) rs_def have rs_heap_eq: "\<forall>ref\<in>set rs. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref" by simp
3.324 + from refs_of_ref rs_heap_eq rss_def have 2: "\<forall>refs. refs_of h (Ref.get h' ref) refs \<longrightarrow>
3.325 + (\<forall>ref\<in>set refs. Ref.present h ref \<and> Ref.present h' ref \<and> Ref.get h ref = Ref.get h' ref)"
3.326 by (auto dest: refs_of_is_fun)
3.327 from Cons(1)[OF 1 2]
3.328 - have "list_of h' (get_ref ref h') xs'" .
3.329 + have "list_of h' (Ref.get h' ref) xs'" .
3.330 with Node show ?case
3.331 unfolding list_of'_def
3.332 by simp
3.333 @@ -454,29 +454,29 @@
3.334
3.335 lemma make_llist:
3.336 assumes "crel (make_llist xs) h h' r"
3.337 -shows "list_of h' r xs \<and> (\<forall>rs. refs_of h' r rs \<longrightarrow> (\<forall>ref \<in> (set rs). ref_present ref h'))"
3.338 +shows "list_of h' r xs \<and> (\<forall>rs. refs_of h' r rs \<longrightarrow> (\<forall>ref \<in> (set rs). Ref.present h' ref))"
3.339 using assms
3.340 proof (induct xs arbitrary: h h' r)
3.341 case Nil thus ?case by (auto elim: crel_return simp add: make_llist.simps)
3.342 next
3.343 case (Cons x xs')
3.344 from Cons.prems obtain h1 r1 r' where make_llist: "crel (make_llist xs') h h1 r1"
3.345 - and crel_refnew:"crel (Ref.new r1) h1 h' r'" and Node: "r = Node x r'"
3.346 + and crel_refnew:"crel (ref r1) h1 h' r'" and Node: "r = Node x r'"
3.347 unfolding make_llist.simps
3.348 by (auto elim!: crelE crel_return)
3.349 from Cons.hyps[OF make_llist] have list_of_h1: "list_of h1 r1 xs'" ..
3.350 from Cons.hyps[OF make_llist] obtain rs' where rs'_def: "refs_of h1 r1 rs'" by (auto intro: list_of_refs_of)
3.351 - from Cons.hyps[OF make_llist] rs'_def have refs_present: "\<forall>ref\<in>set rs'. ref_present ref h1" by simp
3.352 + from Cons.hyps[OF make_llist] rs'_def have refs_present: "\<forall>ref\<in>set rs'. Ref.present h1 ref" by simp
3.353 from crel_refnew rs'_def refs_present have refs_unchanged: "\<forall>refs. refs_of h1 r1 refs \<longrightarrow>
3.354 - (\<forall>ref\<in>set refs. ref_present ref h1 \<and> ref_present ref h' \<and> get_ref ref h1 = get_ref ref h')"
3.355 - by (auto elim!: crel_Ref_new dest: refs_of_is_fun)
3.356 + (\<forall>ref\<in>set refs. Ref.present h1 ref \<and> Ref.present h' ref \<and> Ref.get h1 ref = Ref.get h' ref)"
3.357 + by (auto elim!: crel_ref dest: refs_of_is_fun)
3.358 with list_of_invariant[OF list_of_h1 refs_unchanged] Node crel_refnew have fstgoal: "list_of h' r (x # xs')"
3.359 unfolding list_of.simps
3.360 - by (auto elim!: crel_Ref_new)
3.361 - from refs_unchanged rs'_def have refs_still_present: "\<forall>ref\<in>set rs'. ref_present ref h'" by auto
3.362 + by (auto elim!: crel_ref)
3.363 + from refs_unchanged rs'_def have refs_still_present: "\<forall>ref\<in>set rs'. Ref.present h' ref" by auto
3.364 from refs_of_invariant[OF rs'_def refs_unchanged] refs_unchanged Node crel_refnew refs_still_present
3.365 - have sndgoal: "\<forall>rs. refs_of h' r rs \<longrightarrow> (\<forall>ref\<in>set rs. ref_present ref h')"
3.366 - by (fastsimp elim!: crel_Ref_new dest: refs_of_is_fun)
3.367 + have sndgoal: "\<forall>rs. refs_of h' r rs \<longrightarrow> (\<forall>ref\<in>set rs. Ref.present h' ref)"
3.368 + by (fastsimp elim!: crel_ref dest: refs_of_is_fun)
3.369 from fstgoal sndgoal show ?case ..
3.370 qed
3.371
3.372 @@ -533,10 +533,10 @@
3.373 thm arg_cong2
3.374 by (auto simp add: expand_fun_eq intro: arg_cong2[where f = "op \<guillemotright>="] split: node.split)
3.375
3.376 -fun rev :: "('a:: heap) node \<Rightarrow> 'a node Heap"
3.377 +primrec rev :: "('a:: heap) node \<Rightarrow> 'a node Heap"
3.378 where
3.379 "rev Empty = return Empty"
3.380 -| "rev (Node x n) = (do q \<leftarrow> Ref.new Empty; p \<leftarrow> Ref.new (Node x n); v \<leftarrow> rev' (q, p); !v done)"
3.381 +| "rev (Node x n) = (do q \<leftarrow> ref Empty; p \<leftarrow> ref (Node x n); v \<leftarrow> rev' (q, p); !v done)"
3.382
3.383 subsection {* Correctness Proof *}
3.384
3.385 @@ -556,17 +556,17 @@
3.386 case (Cons x xs)
3.387 (*"LinkedList.list_of h' (get_ref v h') (List.rev xs @ x # qsa)"*)
3.388 from Cons(4) obtain ref where
3.389 - p_is_Node: "get_ref p h = Node x ref"
3.390 + p_is_Node: "Ref.get h p = Node x ref"
3.391 (*and "ref_present ref h"*)
3.392 and list_of'_ref: "list_of' h ref xs"
3.393 - unfolding list_of'_def by (cases "get_ref p h", auto)
3.394 - from p_is_Node Cons(2) have crel_rev': "crel (rev' (p, ref)) (set_ref p (Node x q) h) h' v"
3.395 + unfolding list_of'_def by (cases "Ref.get h p", auto)
3.396 + from p_is_Node Cons(2) have crel_rev': "crel (rev' (p, ref)) (Ref.set p (Node x q) h) h' v"
3.397 by (auto simp add: rev'_simps [of q p] elim!: crelE crel_lookup crel_update)
3.398 from Cons(3) obtain qrs where qrs_def: "refs_of' h q qrs" by (elim list_of'_refs_of')
3.399 from Cons(4) obtain prs where prs_def: "refs_of' h p prs" by (elim list_of'_refs_of')
3.400 from qrs_def prs_def Cons(5) have distinct_pointers: "set qrs \<inter> set prs = {}" by fastsimp
3.401 from qrs_def prs_def distinct_pointers refs_of'E have p_notin_qrs: "p \<notin> set qrs" by fastsimp
3.402 - from Cons(3) qrs_def this have 1: "list_of' (set_ref p (Node x q) h) p (x#qs)"
3.403 + from Cons(3) qrs_def this have 1: "list_of' (Ref.set p (Node x q) h) p (x#qs)"
3.404 unfolding list_of'_def
3.405 apply (simp)
3.406 unfolding list_of'_def[symmetric]
3.407 @@ -575,16 +575,16 @@
3.408 unfolding refs_of'_def' by auto
3.409 from prs_refs prs_def have p_not_in_refs: "p \<notin> set refs"
3.410 by (fastsimp dest!: refs_of'_distinct)
3.411 - with refs_def p_is_Node list_of'_ref have 2: "list_of' (set_ref p (Node x q) h) ref xs"
3.412 + with refs_def p_is_Node list_of'_ref have 2: "list_of' (Ref.set p (Node x q) h) ref xs"
3.413 by (auto simp add: list_of'_set_ref)
3.414 - from p_notin_qrs qrs_def have refs_of1: "refs_of' (set_ref p (Node x q) h) p (p#qrs)"
3.415 + from p_notin_qrs qrs_def have refs_of1: "refs_of' (Ref.set p (Node x q) h) p (p#qrs)"
3.416 unfolding refs_of'_def'
3.417 apply (simp)
3.418 unfolding refs_of'_def'[symmetric]
3.419 by (simp add: refs_of'_set_ref)
3.420 - from p_not_in_refs p_is_Node refs_def have refs_of2: "refs_of' (set_ref p (Node x q) h) ref refs"
3.421 + from p_not_in_refs p_is_Node refs_def have refs_of2: "refs_of' (Ref.set p (Node x q) h) ref refs"
3.422 by (simp add: refs_of'_set_ref)
3.423 - from p_not_in_refs refs_of1 refs_of2 distinct_pointers prs_refs have 3: "\<forall>qrs prs. refs_of' (set_ref p (Node x q) h) p qrs \<and> refs_of' (set_ref p (Node x q) h) ref prs \<longrightarrow> set prs \<inter> set qrs = {}"
3.424 + from p_not_in_refs refs_of1 refs_of2 distinct_pointers prs_refs have 3: "\<forall>qrs prs. refs_of' (Ref.set p (Node x q) h) p qrs \<and> refs_of' (Ref.set p (Node x q) h) ref prs \<longrightarrow> set prs \<inter> set qrs = {}"
3.425 apply - apply (rule allI)+ apply (rule impI) apply (erule conjE)
3.426 apply (drule refs_of'_is_fun) back back apply assumption
3.427 apply (drule refs_of'_is_fun) back back apply assumption
3.428 @@ -595,7 +595,7 @@
3.429
3.430 lemma rev_correctness:
3.431 assumes list_of_h: "list_of h r xs"
3.432 - assumes validHeap: "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>r \<in> set refs. ref_present r h)"
3.433 + assumes validHeap: "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>r \<in> set refs. Ref.present h r)"
3.434 assumes crel_rev: "crel (rev r) h h' r'"
3.435 shows "list_of h' r' (List.rev xs)"
3.436 using assms
3.437 @@ -606,39 +606,39 @@
3.438 next
3.439 case (Node x ps)
3.440 with crel_rev obtain p q h1 h2 h3 v where
3.441 - init: "crel (Ref.new Empty) h h1 q"
3.442 - "crel (Ref.new (Node x ps)) h1 h2 p"
3.443 + init: "crel (ref Empty) h h1 q"
3.444 + "crel (ref (Node x ps)) h1 h2 p"
3.445 and crel_rev':"crel (rev' (q, p)) h2 h3 v"
3.446 and lookup: "crel (!v) h3 h' r'"
3.447 using rev.simps
3.448 by (auto elim!: crelE)
3.449 from init have a1:"list_of' h2 q []"
3.450 unfolding list_of'_def
3.451 - by (auto elim!: crel_Ref_new)
3.452 + by (auto elim!: crel_ref)
3.453 from list_of_h obtain refs where refs_def: "refs_of h r refs" by (rule list_of_refs_of)
3.454 - from validHeap init refs_def have heap_eq: "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>ref\<in>set refs. ref_present ref h \<and> ref_present ref h2 \<and> get_ref ref h = get_ref ref h2)"
3.455 - by (fastsimp elim!: crel_Ref_new dest: refs_of_is_fun)
3.456 + from validHeap init refs_def have heap_eq: "\<forall>refs. refs_of h r refs \<longrightarrow> (\<forall>ref\<in>set refs. Ref.present h ref \<and> Ref.present h2 ref \<and> Ref.get h ref = Ref.get h2 ref)"
3.457 + by (fastsimp elim!: crel_ref dest: refs_of_is_fun)
3.458 from list_of_invariant[OF list_of_h heap_eq] have "list_of h2 r xs" .
3.459 from init this Node have a2: "list_of' h2 p xs"
3.460 apply -
3.461 unfolding list_of'_def
3.462 - apply (auto elim!: crel_Ref_new)
3.463 + apply (auto elim!: crel_ref)
3.464 done
3.465 from init have refs_of_q: "refs_of' h2 q [q]"
3.466 - by (auto elim!: crel_Ref_new)
3.467 + by (auto elim!: crel_ref)
3.468 from refs_def Node have refs_of'_ps: "refs_of' h ps refs"
3.469 by (auto simp add: refs_of'_def'[symmetric])
3.470 - from validHeap refs_def have all_ref_present: "\<forall>r\<in>set refs. ref_present r h" by simp
3.471 - from init refs_of'_ps Node this have heap_eq: "\<forall>refs. refs_of' h ps refs \<longrightarrow> (\<forall>ref\<in>set refs. ref_present ref h \<and> ref_present ref h2 \<and> get_ref ref h = get_ref ref h2)"
3.472 - by (fastsimp elim!: crel_Ref_new dest: refs_of'_is_fun)
3.473 + from validHeap refs_def have all_ref_present: "\<forall>r\<in>set refs. Ref.present h r" by simp
3.474 + from init refs_of'_ps Node this have heap_eq: "\<forall>refs. refs_of' h ps refs \<longrightarrow> (\<forall>ref\<in>set refs. Ref.present h ref \<and> Ref.present h2 ref \<and> Ref.get h ref = Ref.get h2 ref)"
3.475 + by (fastsimp elim!: crel_ref dest: refs_of'_is_fun)
3.476 from refs_of'_invariant[OF refs_of'_ps this] have "refs_of' h2 ps refs" .
3.477 with init have refs_of_p: "refs_of' h2 p (p#refs)"
3.478 - by (auto elim!: crel_Ref_new simp add: refs_of'_def')
3.479 + by (auto elim!: crel_ref simp add: refs_of'_def')
3.480 with init all_ref_present have q_is_new: "q \<notin> set (p#refs)"
3.481 - by (auto elim!: crel_Ref_new intro!: noteq_refsI)
3.482 + by (auto elim!: crel_ref intro!: Ref.noteq_I)
3.483 from refs_of_p refs_of_q q_is_new have a3: "\<forall>qrs prs. refs_of' h2 q qrs \<and> refs_of' h2 p prs \<longrightarrow> set prs \<inter> set qrs = {}"
3.484 by (fastsimp simp only: set.simps dest: refs_of'_is_fun)
3.485 - from rev'_invariant [OF crel_rev' a1 a2 a3] have "list_of h3 (get_ref v h3) (List.rev xs)"
3.486 + from rev'_invariant [OF crel_rev' a1 a2 a3] have "list_of h3 (Ref.get h3 v) (List.rev xs)"
3.487 unfolding list_of'_def by auto
3.488 with lookup show ?thesis
3.489 by (auto elim: crel_lookup)
3.490 @@ -734,32 +734,32 @@
3.491 lemma merge_induct2:
3.492 assumes "list_of' h (p::'a::{heap, ord} node ref) xs"
3.493 assumes "list_of' h q ys"
3.494 - assumes "\<And> ys p q. \<lbrakk> list_of' h p []; list_of' h q ys; get_ref p h = Empty \<rbrakk> \<Longrightarrow> P p q [] ys"
3.495 - assumes "\<And> x xs' p q pn. \<lbrakk> list_of' h p (x#xs'); list_of' h q []; get_ref p h = Node x pn; get_ref q h = Empty \<rbrakk> \<Longrightarrow> P p q (x#xs') []"
3.496 + assumes "\<And> ys p q. \<lbrakk> list_of' h p []; list_of' h q ys; Ref.get h p = Empty \<rbrakk> \<Longrightarrow> P p q [] ys"
3.497 + assumes "\<And> x xs' p q pn. \<lbrakk> list_of' h p (x#xs'); list_of' h q []; Ref.get h p = Node x pn; Ref.get h q = Empty \<rbrakk> \<Longrightarrow> P p q (x#xs') []"
3.498 assumes "\<And> x xs' y ys' p q pn qn.
3.499 - \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys'); get_ref p h = Node x pn; get_ref q h = Node y qn;
3.500 + \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys'); Ref.get h p = Node x pn; Ref.get h q = Node y qn;
3.501 x \<le> y; P pn q xs' (y#ys') \<rbrakk>
3.502 \<Longrightarrow> P p q (x#xs') (y#ys')"
3.503 assumes "\<And> x xs' y ys' p q pn qn.
3.504 - \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys'); get_ref p h = Node x pn; get_ref q h = Node y qn;
3.505 + \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys'); Ref.get h p = Node x pn; Ref.get h q = Node y qn;
3.506 \<not> x \<le> y; P p qn (x#xs') ys'\<rbrakk>
3.507 \<Longrightarrow> P p q (x#xs') (y#ys')"
3.508 shows "P p q xs ys"
3.509 using assms(1-2)
3.510 proof (induct xs ys arbitrary: p q rule: Lmerge.induct)
3.511 case (2 ys)
3.512 - from 2(1) have "get_ref p h = Empty" unfolding list_of'_def by simp
3.513 + from 2(1) have "Ref.get h p = Empty" unfolding list_of'_def by simp
3.514 with 2(1-2) assms(3) show ?case by blast
3.515 next
3.516 case (3 x xs')
3.517 - from 3(1) obtain pn where Node: "get_ref p h = Node x pn" by (rule list_of'_Cons)
3.518 - from 3(2) have "get_ref q h = Empty" unfolding list_of'_def by simp
3.519 + from 3(1) obtain pn where Node: "Ref.get h p = Node x pn" by (rule list_of'_Cons)
3.520 + from 3(2) have "Ref.get h q = Empty" unfolding list_of'_def by simp
3.521 with Node 3(1-2) assms(4) show ?case by blast
3.522 next
3.523 case (1 x xs' y ys')
3.524 - from 1(3) obtain pn where pNode:"get_ref p h = Node x pn"
3.525 + from 1(3) obtain pn where pNode:"Ref.get h p = Node x pn"
3.526 and list_of'_pn: "list_of' h pn xs'" by (rule list_of'_Cons)
3.527 - from 1(4) obtain qn where qNode:"get_ref q h = Node y qn"
3.528 + from 1(4) obtain qn where qNode:"Ref.get h q = Node y qn"
3.529 and list_of'_qn: "list_of' h qn ys'" by (rule list_of'_Cons)
3.530 show ?case
3.531 proof (cases "x \<le> y")
3.532 @@ -780,15 +780,15 @@
3.533 assumes "list_of' h p xs"
3.534 assumes "list_of' h q ys"
3.535 assumes "crel (merge p q) h h' r"
3.536 -assumes "\<And> ys p q. \<lbrakk> list_of' h p []; list_of' h q ys; get_ref p h = Empty \<rbrakk> \<Longrightarrow> P p q h h q [] ys"
3.537 -assumes "\<And> x xs' p q pn. \<lbrakk> list_of' h p (x#xs'); list_of' h q []; get_ref p h = Node x pn; get_ref q h = Empty \<rbrakk> \<Longrightarrow> P p q h h p (x#xs') []"
3.538 +assumes "\<And> ys p q. \<lbrakk> list_of' h p []; list_of' h q ys; Ref.get h p = Empty \<rbrakk> \<Longrightarrow> P p q h h q [] ys"
3.539 +assumes "\<And> x xs' p q pn. \<lbrakk> list_of' h p (x#xs'); list_of' h q []; Ref.get h p = Node x pn; Ref.get h q = Empty \<rbrakk> \<Longrightarrow> P p q h h p (x#xs') []"
3.540 assumes "\<And> x xs' y ys' p q pn qn h1 r1 h'.
3.541 - \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys');get_ref p h = Node x pn; get_ref q h = Node y qn;
3.542 - x \<le> y; crel (merge pn q) h h1 r1 ; P pn q h h1 r1 xs' (y#ys'); h' = set_ref p (Node x r1) h1 \<rbrakk>
3.543 + \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys');Ref.get h p = Node x pn; Ref.get h q = Node y qn;
3.544 + x \<le> y; crel (merge pn q) h h1 r1 ; P pn q h h1 r1 xs' (y#ys'); h' = Ref.set p (Node x r1) h1 \<rbrakk>
3.545 \<Longrightarrow> P p q h h' p (x#xs') (y#ys')"
3.546 assumes "\<And> x xs' y ys' p q pn qn h1 r1 h'.
3.547 - \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys'); get_ref p h = Node x pn; get_ref q h = Node y qn;
3.548 - \<not> x \<le> y; crel (merge p qn) h h1 r1; P p qn h h1 r1 (x#xs') ys'; h' = set_ref q (Node y r1) h1 \<rbrakk>
3.549 + \<lbrakk> list_of' h p (x#xs'); list_of' h q (y#ys'); Ref.get h p = Node x pn; Ref.get h q = Node y qn;
3.550 + \<not> x \<le> y; crel (merge p qn) h h1 r1; P p qn h h1 r1 (x#xs') ys'; h' = Ref.set q (Node y r1) h1 \<rbrakk>
3.551 \<Longrightarrow> P p q h h' q (x#xs') (y#ys')"
3.552 shows "P p q h h' r xs ys"
3.553 using assms(3)
3.554 @@ -808,7 +808,7 @@
3.555 case (3 x xs' y ys' p q pn qn)
3.556 from 3(3-5) 3(7) obtain h1 r1 where
3.557 1: "crel (merge pn q) h h1 r1"
3.558 - and 2: "h' = set_ref p (Node x r1) h1 \<and> r = p"
3.559 + and 2: "h' = Ref.set p (Node x r1) h1 \<and> r = p"
3.560 unfolding merge_simps[of p q]
3.561 by (auto elim!: crel_lookup crelE crel_return crel_if crel_update)
3.562 from 3(6)[OF 1] assms(6) [OF 3(1-5)] 1 2 show ?case by simp
3.563 @@ -816,7 +816,7 @@
3.564 case (4 x xs' y ys' p q pn qn)
3.565 from 4(3-5) 4(7) obtain h1 r1 where
3.566 1: "crel (merge p qn) h h1 r1"
3.567 - and 2: "h' = set_ref q (Node y r1) h1 \<and> r = q"
3.568 + and 2: "h' = Ref.set q (Node y r1) h1 \<and> r = q"
3.569 unfolding merge_simps[of p q]
3.570 by (auto elim!: crel_lookup crelE crel_return crel_if crel_update)
3.571 from 4(6)[OF 1] assms(7) [OF 4(1-5)] 1 2 show ?case by simp
3.572 @@ -834,7 +834,7 @@
3.573 assumes "crel (merge p q) h h' r'"
3.574 assumes "set xs \<inter> set ys = {}"
3.575 assumes "r \<notin> set xs \<union> set ys"
3.576 - shows "get_ref r h = get_ref r h'"
3.577 + shows "Ref.get h r = Ref.get h' r"
3.578 proof -
3.579 from assms(1) obtain ps where ps_def: "list_of' h p ps" by (rule refs_of'_list_of')
3.580 from assms(2) obtain qs where qs_def: "list_of' h q qs" by (rule refs_of'_list_of')
3.581 @@ -853,7 +853,8 @@
3.582 from pnrs_def 3(12) have "r \<noteq> p" by auto
3.583 with 3(11) 3(12) pnrs_def refs_of'_distinct[OF 3(9)] have p_in: "p \<notin> set pnrs \<union> set ys" by auto
3.584 from 3(11) pnrs_def have no_inter: "set pnrs \<inter> set ys = {}" by auto
3.585 - from 3(7)[OF refs_of'_pn 3(10) this p_in] 3(3) have p_is_Node: "get_ref p h1 = Node x pn" by simp
3.586 + from 3(7)[OF refs_of'_pn 3(10) this p_in] 3(3) have p_is_Node: "Ref.get h1 p = Node x pn"
3.587 + by simp
3.588 from 3(7)[OF refs_of'_pn 3(10) no_inter r_in] 3(8) `r \<noteq> p` show ?case
3.589 by simp
3.590 next
3.591 @@ -866,7 +867,7 @@
3.592 from qnrs_def 4(12) have "r \<noteq> q" by auto
3.593 with 4(11) 4(12) qnrs_def refs_of'_distinct[OF 4(10)] have q_in: "q \<notin> set xs \<union> set qnrs" by auto
3.594 from 4(11) qnrs_def have no_inter: "set xs \<inter> set qnrs = {}" by auto
3.595 - from 4(7)[OF 4(9) refs_of'_qn this q_in] 4(4) have q_is_Node: "get_ref q h1 = Node y qn" by simp
3.596 + from 4(7)[OF 4(9) refs_of'_qn this q_in] 4(4) have q_is_Node: "Ref.get h1 q = Node y qn" by simp
3.597 from 4(7)[OF 4(9) refs_of'_qn no_inter r_in] 4(8) `r \<noteq> q` show ?case
3.598 by simp
3.599 qed
3.600 @@ -899,7 +900,7 @@
3.601 by (rule refs_of'_Node)
3.602 from 3(10) 3(9) 3(11) pnrs_def refs_of'_distinct[OF 3(9)] have p_in: "p \<notin> set pnrs \<union> set ys" by auto
3.603 from 3(11) pnrs_def have no_inter: "set pnrs \<inter> set ys = {}" by auto
3.604 - from merge_unchanged[OF refs_of'_pn 3(10) 3(6) no_inter p_in] have p_stays: "get_ref p h1 = get_ref p h" ..
3.605 + from merge_unchanged[OF refs_of'_pn 3(10) 3(6) no_inter p_in] have p_stays: "Ref.get h1 p = Ref.get h p" ..
3.606 from 3 p_stays obtain r1s
3.607 where rs_def: "rs = p#r1s" and refs_of'_r1:"refs_of' h1 r1 r1s"
3.608 by (auto elim: refs_of'_set_next_ref)
3.609 @@ -912,7 +913,7 @@
3.610 by (rule refs_of'_Node)
3.611 from 4(10) 4(9) 4(11) qnrs_def refs_of'_distinct[OF 4(10)] have q_in: "q \<notin> set xs \<union> set qnrs" by auto
3.612 from 4(11) qnrs_def have no_inter: "set xs \<inter> set qnrs = {}" by auto
3.613 - from merge_unchanged[OF 4(9) refs_of'_qn 4(6) no_inter q_in] have q_stays: "get_ref q h1 = get_ref q h" ..
3.614 + from merge_unchanged[OF 4(9) refs_of'_qn 4(6) no_inter q_in] have q_stays: "Ref.get h1 q = Ref.get h q" ..
3.615 from 4 q_stays obtain r1s
3.616 where rs_def: "rs = q#r1s" and refs_of'_r1:"refs_of' h1 r1 r1s"
3.617 by (auto elim: refs_of'_set_next_ref)
3.618 @@ -945,7 +946,7 @@
3.619 from prs_def qrs_def 3(9) pnrs_def have no_inter: "set pnrs \<inter> set qrs = {}" by fastsimp
3.620 from no_inter refs_of'_pn qrs_def have no_inter2: "\<forall>qrs prs. refs_of' h q qrs \<and> refs_of' h pn prs \<longrightarrow> set prs \<inter> set qrs = {}"
3.621 by (fastsimp dest: refs_of'_is_fun)
3.622 - from merge_unchanged[OF refs_of'_pn qrs_def 3(6) no_inter p_in] have p_stays: "get_ref p h1 = get_ref p h" ..
3.623 + from merge_unchanged[OF refs_of'_pn qrs_def 3(6) no_inter p_in] have p_stays: "Ref.get h1 p = Ref.get h p" ..
3.624 from 3(7)[OF no_inter2] obtain rs where rs_def: "refs_of' h1 r1 rs" by (rule list_of'_refs_of')
3.625 from refs_of'_merge[OF refs_of'_pn qrs_def 3(6) no_inter this] p_in have p_rs: "p \<notin> set rs" by auto
3.626 with 3(7)[OF no_inter2] 3(1-5) 3(8) p_rs rs_def p_stays
3.627 @@ -962,7 +963,7 @@
3.628 from prs_def qrs_def 4(9) qnrs_def have no_inter: "set prs \<inter> set qnrs = {}" by fastsimp
3.629 from no_inter refs_of'_qn prs_def have no_inter2: "\<forall>qrs prs. refs_of' h qn qrs \<and> refs_of' h p prs \<longrightarrow> set prs \<inter> set qrs = {}"
3.630 by (fastsimp dest: refs_of'_is_fun)
3.631 - from merge_unchanged[OF prs_def refs_of'_qn 4(6) no_inter q_in] have q_stays: "get_ref q h1 = get_ref q h" ..
3.632 + from merge_unchanged[OF prs_def refs_of'_qn 4(6) no_inter q_in] have q_stays: "Ref.get h1 q = Ref.get h q" ..
3.633 from 4(7)[OF no_inter2] obtain rs where rs_def: "refs_of' h1 r1 rs" by (rule list_of'_refs_of')
3.634 from refs_of'_merge[OF prs_def refs_of'_qn 4(6) no_inter this] q_in have q_rs: "q \<notin> set rs" by auto
3.635 with 4(7)[OF no_inter2] 4(1-5) 4(8) q_rs rs_def q_stays
3.636 @@ -984,8 +985,8 @@
3.637 (do
3.638 ll_xs \<leftarrow> make_llist (filter (%n. n mod 2 = 0) [2..8]);
3.639 ll_ys \<leftarrow> make_llist (filter (%n. n mod 2 = 1) [5..11]);
3.640 - r \<leftarrow> Ref.new ll_xs;
3.641 - q \<leftarrow> Ref.new ll_ys;
3.642 + r \<leftarrow> ref ll_xs;
3.643 + q \<leftarrow> ref ll_ys;
3.644 p \<leftarrow> merge r q;
3.645 ll_zs \<leftarrow> !p;
3.646 zs \<leftarrow> traverse ll_zs;
3.647 @@ -998,4 +999,4 @@
3.648 ML {* @{code test_2} () *}
3.649 ML {* @{code test_3} () *}
3.650
3.651 -end
3.652 \ No newline at end of file
3.653 +end