| author | wenzelm | 
| Wed, 03 Sep 2008 11:44:52 +0200 | |
| changeset 28108 | 1b08ed83b79e | 
| parent 26316 | 9e9e67e33557 | 
| child 31082 | 54a442b2d727 | 
| permissions | -rw-r--r-- | 
| 13020 | 1 | header {* \chapter{Case Study: Single and Multi-Mutator Garbage Collection Algorithms}
 | 
| 2 | ||
| 3 | \section {Formalization of the Memory} *}
 | |
| 4 | ||
| 16417 | 5 | theory Graph imports Main begin | 
| 13020 | 6 | |
| 7 | datatype node = Black | White | |
| 8 | ||
| 9 | types | |
| 10 | nodes = "node list" | |
| 11 | edge = "nat \<times> nat" | |
| 12 | edges = "edge list" | |
| 13 | ||
| 14 | consts Roots :: "nat set" | |
| 15 | ||
| 16 | constdefs | |
| 17 | Proper_Roots :: "nodes \<Rightarrow> bool" | |
| 18 |   "Proper_Roots M \<equiv> Roots\<noteq>{} \<and> Roots \<subseteq> {i. i<length M}"
 | |
| 19 | ||
| 20 | Proper_Edges :: "(nodes \<times> edges) \<Rightarrow> bool" | |
| 21 | "Proper_Edges \<equiv> (\<lambda>(M,E). \<forall>i<length E. fst(E!i)<length M \<and> snd(E!i)<length M)" | |
| 22 | ||
| 23 | BtoW :: "(edge \<times> nodes) \<Rightarrow> bool" | |
| 24 | "BtoW \<equiv> (\<lambda>(e,M). (M!fst e)=Black \<and> (M!snd e)\<noteq>Black)" | |
| 25 | ||
| 26 | Blacks :: "nodes \<Rightarrow> nat set" | |
| 27 |   "Blacks M \<equiv> {i. i<length M \<and> M!i=Black}"
 | |
| 28 | ||
| 29 | Reach :: "edges \<Rightarrow> nat set" | |
| 30 |   "Reach E \<equiv> {x. (\<exists>path. 1<length path \<and> path!(length path - 1)\<in>Roots \<and> x=path!0
 | |
| 31 | \<and> (\<forall>i<length path - 1. (\<exists>j<length E. E!j=(path!(i+1), path!i)))) | |
| 32 | \<or> x\<in>Roots}" | |
| 33 | ||
| 34 | text{* Reach: the set of reachable nodes is the set of Roots together with the
 | |
| 35 | nodes reachable from some Root by a path represented by a list of | |
| 36 | nodes (at least two since we traverse at least one edge), where two | |
| 37 | consecutive nodes correspond to an edge in E. *} | |
| 38 | ||
| 39 | subsection {* Proofs about Graphs *}
 | |
| 40 | ||
| 41 | lemmas Graph_defs= Blacks_def Proper_Roots_def Proper_Edges_def BtoW_def | |
| 42 | declare Graph_defs [simp] | |
| 43 | ||
| 13022 
b115b305612f
New order in the loading of theories (Quote-antiquote right before the OG_Syntax and RG_Syntax respectively)
 prensani parents: 
13020diff
changeset | 44 | subsubsection{* Graph 1 *}
 | 
| 13020 | 45 | |
| 46 | lemma Graph1_aux [rule_format]: | |
| 47 | "\<lbrakk> Roots\<subseteq>Blacks M; \<forall>i<length E. \<not>BtoW(E!i,M)\<rbrakk> | |
| 48 | \<Longrightarrow> 1< length path \<longrightarrow> (path!(length path - 1))\<in>Roots \<longrightarrow> | |
| 49 | (\<forall>i<length path - 1. (\<exists>j. j < length E \<and> E!j=(path!(Suc i), path!i))) | |
| 50 | \<longrightarrow> M!(path!0) = Black" | |
| 51 | apply(induct_tac "path") | |
| 52 | apply force | |
| 53 | apply clarify | |
| 54 | apply simp | |
| 55 | apply(case_tac "list") | |
| 56 | apply force | |
| 57 | apply simp | |
| 13601 | 58 | apply(rotate_tac -2) | 
| 13020 | 59 | apply(erule_tac x = "0" in all_dupE) | 
| 60 | apply simp | |
| 61 | apply clarify | |
| 62 | apply(erule allE , erule (1) notE impE) | |
| 63 | apply simp | |
| 64 | apply(erule mp) | |
| 65 | apply(case_tac "lista") | |
| 66 | apply force | |
| 67 | apply simp | |
| 68 | apply(erule mp) | |
| 69 | apply clarify | |
| 70 | apply(erule_tac x = "Suc i" in allE) | |
| 71 | apply force | |
| 72 | done | |
| 73 | ||
| 74 | lemma Graph1: | |
| 75 | "\<lbrakk>Roots\<subseteq>Blacks M; Proper_Edges(M, E); \<forall>i<length E. \<not>BtoW(E!i,M) \<rbrakk> | |
| 76 | \<Longrightarrow> Reach E\<subseteq>Blacks M" | |
| 77 | apply (unfold Reach_def) | |
| 78 | apply simp | |
| 79 | apply clarify | |
| 80 | apply(erule disjE) | |
| 81 | apply clarify | |
| 82 | apply(rule conjI) | |
| 83 | apply(subgoal_tac "0< length path - Suc 0") | |
| 84 | apply(erule allE , erule (1) notE impE) | |
| 85 | apply force | |
| 86 | apply simp | |
| 87 | apply(rule Graph1_aux) | |
| 88 | apply auto | |
| 89 | done | |
| 90 | ||
| 13022 
b115b305612f
New order in the loading of theories (Quote-antiquote right before the OG_Syntax and RG_Syntax respectively)
 prensani parents: 
13020diff
changeset | 91 | subsubsection{* Graph 2 *}
 | 
| 13020 | 92 | |
| 93 | lemma Ex_first_occurrence [rule_format]: | |
| 94 | "P (n::nat) \<longrightarrow> (\<exists>m. P m \<and> (\<forall>i. i<m \<longrightarrow> \<not> P i))"; | |
| 95 | apply(rule nat_less_induct) | |
| 96 | apply clarify | |
| 97 | apply(case_tac "\<forall>m. m<n \<longrightarrow> \<not> P m") | |
| 98 | apply auto | |
| 99 | done | |
| 100 | ||
| 101 | lemma Compl_lemma: "(n::nat)\<le>l \<Longrightarrow> (\<exists>m. m\<le>l \<and> n=l - m)" | |
| 102 | apply(rule_tac x = "l - n" in exI) | |
| 103 | apply arith | |
| 104 | done | |
| 105 | ||
| 106 | lemma Ex_last_occurrence: | |
| 107 | "\<lbrakk>P (n::nat); n\<le>l\<rbrakk> \<Longrightarrow> (\<exists>m. P (l - m) \<and> (\<forall>i. i<m \<longrightarrow> \<not>P (l - i)))" | |
| 108 | apply(drule Compl_lemma) | |
| 109 | apply clarify | |
| 110 | apply(erule Ex_first_occurrence) | |
| 111 | done | |
| 112 | ||
| 113 | lemma Graph2: | |
| 114 | "\<lbrakk>T \<in> Reach E; R<length E\<rbrakk> \<Longrightarrow> T \<in> Reach (E[R:=(fst(E!R), T)])" | |
| 115 | apply (unfold Reach_def) | |
| 116 | apply clarify | |
| 117 | apply simp | |
| 118 | apply(case_tac "\<forall>z<length path. fst(E!R)\<noteq>path!z") | |
| 119 | apply(rule_tac x = "path" in exI) | |
| 120 | apply simp | |
| 121 | apply clarify | |
| 122 | apply(erule allE , erule (1) notE impE) | |
| 123 | apply clarify | |
| 124 | apply(rule_tac x = "j" in exI) | |
| 125 | apply(case_tac "j=R") | |
| 126 | apply(erule_tac x = "Suc i" in allE) | |
| 127 | apply simp | |
| 128 | apply (force simp add:nth_list_update) | |
| 129 | apply simp | |
| 130 | apply(erule exE) | |
| 131 | apply(subgoal_tac "z \<le> length path - Suc 0") | |
| 132 | prefer 2 apply arith | |
| 133 | apply(drule_tac P = "\<lambda>m. m<length path \<and> fst(E!R)=path!m" in Ex_last_occurrence) | |
| 134 | apply assumption | |
| 135 | apply clarify | |
| 136 | apply simp | |
| 137 | apply(rule_tac x = "(path!0)#(drop (length path - Suc m) path)" in exI) | |
| 138 | apply simp | |
| 139 | apply(case_tac "length path - (length path - Suc m)") | |
| 140 | apply arith | |
| 141 | apply simp | |
| 142 | apply(subgoal_tac "(length path - Suc m) + nat \<le> length path") | |
| 143 | prefer 2 apply arith | |
| 144 | apply(drule nth_drop) | |
| 145 | apply simp | |
| 146 | apply(subgoal_tac "length path - Suc m + nat = length path - Suc 0") | |
| 147 | prefer 2 apply arith | |
| 148 | apply simp | |
| 149 | apply clarify | |
| 150 | apply(case_tac "i") | |
| 151 | apply(force simp add: nth_list_update) | |
| 152 | apply simp | |
| 153 | apply(subgoal_tac "(length path - Suc m) + nata \<le> length path") | |
| 154 | prefer 2 apply arith | |
| 155 | apply(subgoal_tac "(length path - Suc m) + (Suc nata) \<le> length path") | |
| 156 | prefer 2 apply arith | |
| 157 | apply simp | |
| 158 | apply(erule_tac x = "length path - Suc m + nata" in allE) | |
| 159 | apply simp | |
| 160 | apply clarify | |
| 161 | apply(rule_tac x = "j" in exI) | |
| 162 | apply(case_tac "R=j") | |
| 163 | prefer 2 apply force | |
| 164 | apply simp | |
| 165 | apply(drule_tac t = "path ! (length path - Suc m)" in sym) | |
| 166 | apply simp | |
| 167 | apply(case_tac " length path - Suc 0 < m") | |
| 168 | apply(subgoal_tac "(length path - Suc m)=0") | |
| 169 | prefer 2 apply arith | |
| 170 | apply(simp del: diff_is_0_eq) | |
| 171 | apply(subgoal_tac "Suc nata\<le>nat") | |
| 172 | prefer 2 apply arith | |
| 173 | apply(drule_tac n = "Suc nata" in Compl_lemma) | |
| 174 | apply clarify | |
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24078diff
changeset | 175 | using [[fast_arith_split_limit = 0]] | 
| 13020 | 176 | apply force | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24078diff
changeset | 177 | using [[fast_arith_split_limit = 9]] | 
| 13020 | 178 | apply(drule leI) | 
| 179 | apply(subgoal_tac "Suc (length path - Suc m + nata)=(length path - Suc 0) - (m - Suc nata)") | |
| 180 | apply(erule_tac x = "m - (Suc nata)" in allE) | |
| 181 | apply(case_tac "m") | |
| 182 | apply simp | |
| 183 | apply simp | |
| 13601 | 184 | apply simp | 
| 13020 | 185 | done | 
| 186 | ||
| 20432 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 webertj parents: 
20279diff
changeset | 187 | |
| 13022 
b115b305612f
New order in the loading of theories (Quote-antiquote right before the OG_Syntax and RG_Syntax respectively)
 prensani parents: 
13020diff
changeset | 188 | subsubsection{* Graph 3 *}
 | 
| 13020 | 189 | |
| 190 | lemma Graph3: | |
| 191 | "\<lbrakk> T\<in>Reach E; R<length E \<rbrakk> \<Longrightarrow> Reach(E[R:=(fst(E!R),T)]) \<subseteq> Reach E" | |
| 192 | apply (unfold Reach_def) | |
| 193 | apply clarify | |
| 194 | apply simp | |
| 195 | apply(case_tac "\<exists>i<length path - 1. (fst(E!R),T)=(path!(Suc i),path!i)") | |
| 196 | --{* the changed edge is part of the path *}
 | |
| 197 | apply(erule exE) | |
| 198 | apply(drule_tac P = "\<lambda>i. i<length path - 1 \<and> (fst(E!R),T)=(path!Suc i,path!i)" in Ex_first_occurrence) | |
| 199 | apply clarify | |
| 200 | apply(erule disjE) | |
| 201 | --{* T is NOT a root *}
 | |
| 202 | apply clarify | |
| 203 | apply(rule_tac x = "(take m path)@patha" in exI) | |
| 204 | apply(subgoal_tac "\<not>(length path\<le>m)") | |
| 205 | prefer 2 apply arith | |
| 206 | apply(simp add: min_def) | |
| 207 | apply(rule conjI) | |
| 208 | apply(subgoal_tac "\<not>(m + length patha - 1 < m)") | |
| 209 | prefer 2 apply arith | |
| 210 | apply(simp add: nth_append min_def) | |
| 211 | apply(rule conjI) | |
| 212 | apply(case_tac "m") | |
| 213 | apply force | |
| 214 | apply(case_tac "path") | |
| 215 | apply force | |
| 216 | apply force | |
| 217 | apply clarify | |
| 218 | apply(case_tac "Suc i\<le>m") | |
| 219 | apply(erule_tac x = "i" in allE) | |
| 220 | apply simp | |
| 221 | apply clarify | |
| 222 | apply(rule_tac x = "j" in exI) | |
| 223 | apply(case_tac "Suc i<m") | |
| 22230 | 224 | apply(simp add: nth_append) | 
| 13020 | 225 | apply(case_tac "R=j") | 
| 226 | apply(simp add: nth_list_update) | |
| 227 | apply(case_tac "i=m") | |
| 228 | apply force | |
| 229 | apply(erule_tac x = "i" in allE) | |
| 230 | apply force | |
| 231 | apply(force simp add: nth_list_update) | |
| 22230 | 232 | apply(simp add: nth_append) | 
| 13020 | 233 | apply(subgoal_tac "i=m - 1") | 
| 234 | prefer 2 apply arith | |
| 235 | apply(case_tac "R=j") | |
| 236 | apply(erule_tac x = "m - 1" in allE) | |
| 237 | apply(simp add: nth_list_update) | |
| 238 | apply(force simp add: nth_list_update) | |
| 239 | apply(simp add: nth_append min_def) | |
| 240 | apply(rotate_tac -4) | |
| 241 | apply(erule_tac x = "i - m" in allE) | |
| 242 | apply(subgoal_tac "Suc (i - m)=(Suc i - m)" ) | |
| 243 | prefer 2 apply arith | |
| 244 | apply simp | |
| 245 | --{* T is a root *}
 | |
| 246 | apply(case_tac "m=0") | |
| 247 | apply force | |
| 248 | apply(rule_tac x = "take (Suc m) path" in exI) | |
| 249 | apply(subgoal_tac "\<not>(length path\<le>Suc m)" ) | |
| 250 | prefer 2 apply arith | |
| 251 | apply(simp add: min_def) | |
| 252 | apply clarify | |
| 253 | apply(erule_tac x = "i" in allE) | |
| 254 | apply simp | |
| 255 | apply clarify | |
| 256 | apply(case_tac "R=j") | |
| 257 | apply(force simp add: nth_list_update) | |
| 258 | apply(force simp add: nth_list_update) | |
| 259 | --{* the changed edge is not part of the path *}
 | |
| 260 | apply(rule_tac x = "path" in exI) | |
| 261 | apply simp | |
| 262 | apply clarify | |
| 263 | apply(erule_tac x = "i" in allE) | |
| 264 | apply clarify | |
| 265 | apply(case_tac "R=j") | |
| 266 | apply(erule_tac x = "i" in allE) | |
| 267 | apply simp | |
| 268 | apply(force simp add: nth_list_update) | |
| 269 | done | |
| 270 | ||
| 13022 
b115b305612f
New order in the loading of theories (Quote-antiquote right before the OG_Syntax and RG_Syntax respectively)
 prensani parents: 
13020diff
changeset | 271 | subsubsection{* Graph 4 *}
 | 
| 13020 | 272 | |
| 273 | lemma Graph4: | |
| 274 | "\<lbrakk>T \<in> Reach E; Roots\<subseteq>Blacks M; I\<le>length E; T<length M; R<length E; | |
| 275 | \<forall>i<I. \<not>BtoW(E!i,M); R<I; M!fst(E!R)=Black; M!T\<noteq>Black\<rbrakk> \<Longrightarrow> | |
| 276 | (\<exists>r. I\<le>r \<and> r<length E \<and> BtoW(E[R:=(fst(E!R),T)]!r,M))" | |
| 277 | apply (unfold Reach_def) | |
| 278 | apply simp | |
| 279 | apply(erule disjE) | |
| 280 | prefer 2 apply force | |
| 281 | apply clarify | |
| 282 | --{* there exist a black node in the path to T *}
 | |
| 283 | apply(case_tac "\<exists>m<length path. M!(path!m)=Black") | |
| 284 | apply(erule exE) | |
| 285 | apply(drule_tac P = "\<lambda>m. m<length path \<and> M!(path!m)=Black" in Ex_first_occurrence) | |
| 286 | apply clarify | |
| 287 | apply(case_tac "ma") | |
| 288 | apply force | |
| 289 | apply simp | |
| 290 | apply(case_tac "length path") | |
| 291 | apply force | |
| 292 | apply simp | |
| 13601 | 293 | apply(erule_tac P = "\<lambda>i. i < nata \<longrightarrow> ?P i" and x = "nat" in allE) | 
| 13020 | 294 | apply simp | 
| 295 | apply clarify | |
| 13601 | 296 | apply(erule_tac P = "\<lambda>i. i < Suc nat \<longrightarrow> ?P i" and x = "nat" in allE) | 
| 13020 | 297 | apply simp | 
| 298 | apply(case_tac "j<I") | |
| 299 | apply(erule_tac x = "j" in allE) | |
| 300 | apply force | |
| 301 | apply(rule_tac x = "j" in exI) | |
| 302 | apply(force simp add: nth_list_update) | |
| 303 | apply simp | |
| 304 | apply(rotate_tac -1) | |
| 305 | apply(erule_tac x = "length path - 1" in allE) | |
| 306 | apply(case_tac "length path") | |
| 307 | apply force | |
| 308 | apply force | |
| 309 | done | |
| 310 | ||
| 13022 
b115b305612f
New order in the loading of theories (Quote-antiquote right before the OG_Syntax and RG_Syntax respectively)
 prensani parents: 
13020diff
changeset | 311 | subsubsection {* Graph 5 *}
 | 
| 13020 | 312 | |
| 313 | lemma Graph5: | |
| 314 | "\<lbrakk> T \<in> Reach E ; Roots \<subseteq> Blacks M; \<forall>i<R. \<not>BtoW(E!i,M); T<length M; | |
| 315 | R<length E; M!fst(E!R)=Black; M!snd(E!R)=Black; M!T \<noteq> Black\<rbrakk> | |
| 316 | \<Longrightarrow> (\<exists>r. R<r \<and> r<length E \<and> BtoW(E[R:=(fst(E!R),T)]!r,M))" | |
| 317 | apply (unfold Reach_def) | |
| 318 | apply simp | |
| 319 | apply(erule disjE) | |
| 320 | prefer 2 apply force | |
| 321 | apply clarify | |
| 322 | --{* there exist a black node in the path to T*}
 | |
| 323 | apply(case_tac "\<exists>m<length path. M!(path!m)=Black") | |
| 324 | apply(erule exE) | |
| 325 | apply(drule_tac P = "\<lambda>m. m<length path \<and> M!(path!m)=Black" in Ex_first_occurrence) | |
| 326 | apply clarify | |
| 327 | apply(case_tac "ma") | |
| 328 | apply force | |
| 329 | apply simp | |
| 330 | apply(case_tac "length path") | |
| 331 | apply force | |
| 332 | apply simp | |
| 13601 | 333 | apply(erule_tac P = "\<lambda>i. i < nata \<longrightarrow> ?P i" and x = "nat" in allE) | 
| 13020 | 334 | apply simp | 
| 335 | apply clarify | |
| 13601 | 336 | apply(erule_tac P = "\<lambda>i. i < Suc nat \<longrightarrow> ?P i" and x = "nat" in allE) | 
| 13020 | 337 | apply simp | 
| 338 | apply(case_tac "j\<le>R") | |
| 26316 
9e9e67e33557
removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
 wenzelm parents: 
24742diff
changeset | 339 | apply(drule le_imp_less_or_eq [of _ R]) | 
| 13020 | 340 | apply(erule disjE) | 
| 341 | apply(erule allE , erule (1) notE impE) | |
| 342 | apply force | |
| 343 | apply force | |
| 344 | apply(rule_tac x = "j" in exI) | |
| 345 | apply(force simp add: nth_list_update) | |
| 346 | apply simp | |
| 347 | apply(rotate_tac -1) | |
| 348 | apply(erule_tac x = "length path - 1" in allE) | |
| 349 | apply(case_tac "length path") | |
| 350 | apply force | |
| 351 | apply force | |
| 352 | done | |
| 353 | ||
| 13022 
b115b305612f
New order in the loading of theories (Quote-antiquote right before the OG_Syntax and RG_Syntax respectively)
 prensani parents: 
13020diff
changeset | 354 | subsubsection {* Other lemmas about graphs *}
 | 
| 13020 | 355 | |
| 356 | lemma Graph6: | |
| 357 | "\<lbrakk>Proper_Edges(M,E); R<length E ; T<length M\<rbrakk> \<Longrightarrow> Proper_Edges(M,E[R:=(fst(E!R),T)])" | |
| 358 | apply (unfold Proper_Edges_def) | |
| 359 | apply(force simp add: nth_list_update) | |
| 360 | done | |
| 361 | ||
| 362 | lemma Graph7: | |
| 363 | "\<lbrakk>Proper_Edges(M,E)\<rbrakk> \<Longrightarrow> Proper_Edges(M[T:=a],E)" | |
| 364 | apply (unfold Proper_Edges_def) | |
| 365 | apply force | |
| 366 | done | |
| 367 | ||
| 368 | lemma Graph8: | |
| 369 | "\<lbrakk>Proper_Roots(M)\<rbrakk> \<Longrightarrow> Proper_Roots(M[T:=a])" | |
| 370 | apply (unfold Proper_Roots_def) | |
| 371 | apply force | |
| 372 | done | |
| 373 | ||
| 374 | text{* Some specific lemmata for the verification of garbage collection algorithms. *}
 | |
| 375 | ||
| 376 | lemma Graph9: "j<length M \<Longrightarrow> Blacks M\<subseteq>Blacks (M[j := Black])" | |
| 377 | apply (unfold Blacks_def) | |
| 378 | apply(force simp add: nth_list_update) | |
| 379 | done | |
| 380 | ||
| 381 | lemma Graph10 [rule_format (no_asm)]: "\<forall>i. M!i=a \<longrightarrow>M[i:=a]=M" | |
| 382 | apply(induct_tac "M") | |
| 383 | apply auto | |
| 384 | apply(case_tac "i") | |
| 385 | apply auto | |
| 386 | done | |
| 387 | ||
| 388 | lemma Graph11 [rule_format (no_asm)]: | |
| 389 | "\<lbrakk> M!j\<noteq>Black;j<length M\<rbrakk> \<Longrightarrow> Blacks M \<subset> Blacks (M[j := Black])" | |
| 390 | apply (unfold Blacks_def) | |
| 391 | apply(rule psubsetI) | |
| 392 | apply(force simp add: nth_list_update) | |
| 393 | apply safe | |
| 394 | apply(erule_tac c = "j" in equalityCE) | |
| 395 | apply auto | |
| 396 | done | |
| 397 | ||
| 398 | lemma Graph12: "\<lbrakk>a\<subseteq>Blacks M;j<length M\<rbrakk> \<Longrightarrow> a\<subseteq>Blacks (M[j := Black])" | |
| 399 | apply (unfold Blacks_def) | |
| 400 | apply(force simp add: nth_list_update) | |
| 401 | done | |
| 402 | ||
| 403 | lemma Graph13: "\<lbrakk>a\<subset> Blacks M;j<length M\<rbrakk> \<Longrightarrow> a \<subset> Blacks (M[j := Black])" | |
| 404 | apply (unfold Blacks_def) | |
| 405 | apply(erule psubset_subset_trans) | |
| 406 | apply(force simp add: nth_list_update) | |
| 407 | done | |
| 408 | ||
| 409 | declare Graph_defs [simp del] | |
| 410 | ||
| 411 | end |