src/HOL/Hoare_Parallel/Gar_Coll.thy
author nipkow
Sun Jan 03 10:01:23 2010 +0100 (2010-01-03)
changeset 34233 156c42518cfc
parent 32687 27530efec97a
child 35416 d8d7d1b785af
permissions -rw-r--r--
removed more asm_rl's - unfortunately slowdown of 1 min.
prensani@13020
     1
header {* \section{The Single Mutator Case} *}
prensani@13020
     2
haftmann@16417
     3
theory Gar_Coll imports Graph OG_Syntax begin
prensani@13020
     4
paulson@13624
     5
declare psubsetE [rule del]
paulson@13624
     6
prensani@13020
     7
text {* Declaration of variables: *}
prensani@13020
     8
prensani@13020
     9
record gar_coll_state =
prensani@13020
    10
  M :: nodes
prensani@13020
    11
  E :: edges
prensani@13020
    12
  bc :: "nat set"
prensani@13020
    13
  obc :: "nat set"
prensani@13020
    14
  Ma :: nodes
prensani@13020
    15
  ind :: nat 
prensani@13020
    16
  k :: nat
prensani@13020
    17
  z :: bool
prensani@13020
    18
prensani@13020
    19
subsection {* The Mutator *}
prensani@13020
    20
prensani@13020
    21
text {* The mutator first redirects an arbitrary edge @{text "R"} from
prensani@13020
    22
an arbitrary accessible node towards an arbitrary accessible node
prensani@13020
    23
@{text "T"}.  It then colors the new target @{text "T"} black. 
prensani@13020
    24
prensani@13020
    25
We declare the arbitrarily selected node and edge as constants:*}
prensani@13020
    26
prensani@13020
    27
consts R :: nat  T :: nat
prensani@13020
    28
prensani@13020
    29
text {* \noindent The following predicate states, given a list of
prensani@13020
    30
nodes @{text "m"} and a list of edges @{text "e"}, the conditions
prensani@13020
    31
under which the selected edge @{text "R"} and node @{text "T"} are
prensani@13020
    32
valid: *}
prensani@13020
    33
prensani@13020
    34
constdefs
prensani@13020
    35
  Mut_init :: "gar_coll_state \<Rightarrow> bool"
prensani@13020
    36
  "Mut_init \<equiv> \<guillemotleft> T \<in> Reach \<acute>E \<and> R < length \<acute>E \<and> T < length \<acute>M \<guillemotright>"
prensani@13020
    37
prensani@13020
    38
text {* \noindent For the mutator we
prensani@13020
    39
consider two modules, one for each action.  An auxiliary variable
prensani@13020
    40
@{text "\<acute>z"} is set to false if the mutator has already redirected an
prensani@13020
    41
edge but has not yet colored the new target.   *}
prensani@13020
    42
prensani@13020
    43
constdefs
prensani@13020
    44
  Redirect_Edge :: "gar_coll_state ann_com"
prensani@13020
    45
  "Redirect_Edge \<equiv> .{\<acute>Mut_init \<and> \<acute>z}. \<langle>\<acute>E:=\<acute>E[R:=(fst(\<acute>E!R), T)],, \<acute>z:= (\<not>\<acute>z)\<rangle>"
prensani@13020
    46
prensani@13020
    47
  Color_Target :: "gar_coll_state ann_com"
prensani@13020
    48
  "Color_Target \<equiv> .{\<acute>Mut_init \<and> \<not>\<acute>z}. \<langle>\<acute>M:=\<acute>M[T:=Black],, \<acute>z:= (\<not>\<acute>z)\<rangle>"
prensani@13020
    49
prensani@13020
    50
  Mutator :: "gar_coll_state ann_com"
prensani@13020
    51
  "Mutator \<equiv>
prensani@13020
    52
  .{\<acute>Mut_init \<and> \<acute>z}. 
prensani@13020
    53
  WHILE True INV .{\<acute>Mut_init \<and> \<acute>z}. 
prensani@13020
    54
  DO  Redirect_Edge ;; Color_Target  OD"
prensani@13020
    55
prensani@13020
    56
subsubsection {* Correctness of the mutator *}
prensani@13020
    57
prensani@13020
    58
lemmas mutator_defs = Mut_init_def Redirect_Edge_def Color_Target_def
prensani@13020
    59
prensani@13020
    60
lemma Redirect_Edge: 
prensani@13020
    61
  "\<turnstile> Redirect_Edge pre(Color_Target)"
prensani@13020
    62
apply (unfold mutator_defs)
prensani@13020
    63
apply annhoare
prensani@13020
    64
apply(simp_all)
prensani@13020
    65
apply(force elim:Graph2)
prensani@13020
    66
done
prensani@13020
    67
prensani@13020
    68
lemma Color_Target:
prensani@13020
    69
  "\<turnstile> Color_Target .{\<acute>Mut_init \<and> \<acute>z}."
prensani@13020
    70
apply (unfold mutator_defs)
prensani@13020
    71
apply annhoare
prensani@13020
    72
apply(simp_all)
prensani@13020
    73
done
prensani@13020
    74
prensani@13020
    75
lemma Mutator: 
prensani@13020
    76
 "\<turnstile> Mutator .{False}."
prensani@13020
    77
apply(unfold Mutator_def)
prensani@13020
    78
apply annhoare
prensani@13020
    79
apply(simp_all add:Redirect_Edge Color_Target)
prensani@13020
    80
apply(simp add:mutator_defs Redirect_Edge_def)
prensani@13020
    81
done
prensani@13020
    82
prensani@13020
    83
subsection {* The Collector *}
prensani@13020
    84
prensani@13020
    85
text {* \noindent A constant @{text "M_init"} is used to give @{text "\<acute>Ma"} a
prensani@13020
    86
suitable first value, defined as a list of nodes where only the @{text
prensani@13020
    87
"Roots"} are black. *}
prensani@13020
    88
prensani@13020
    89
consts  M_init :: nodes
prensani@13020
    90
prensani@13020
    91
constdefs
prensani@13020
    92
  Proper_M_init :: "gar_coll_state \<Rightarrow> bool"
prensani@13020
    93
  "Proper_M_init \<equiv>  \<guillemotleft> Blacks M_init=Roots \<and> length M_init=length \<acute>M \<guillemotright>"
prensani@13020
    94
 
prensani@13020
    95
  Proper :: "gar_coll_state \<Rightarrow> bool"
prensani@13020
    96
  "Proper \<equiv> \<guillemotleft> Proper_Roots \<acute>M \<and> Proper_Edges(\<acute>M, \<acute>E) \<and> \<acute>Proper_M_init \<guillemotright>"
prensani@13020
    97
prensani@13020
    98
  Safe :: "gar_coll_state \<Rightarrow> bool"
prensani@13020
    99
  "Safe \<equiv> \<guillemotleft> Reach \<acute>E \<subseteq> Blacks \<acute>M \<guillemotright>"
prensani@13020
   100
prensani@13020
   101
lemmas collector_defs = Proper_M_init_def Proper_def Safe_def
prensani@13020
   102
prensani@13020
   103
subsubsection {* Blackening the roots *}
prensani@13020
   104
prensani@13020
   105
constdefs
prensani@13020
   106
  Blacken_Roots :: " gar_coll_state ann_com"
prensani@13020
   107
  "Blacken_Roots \<equiv> 
prensani@13020
   108
  .{\<acute>Proper}.
prensani@13020
   109
  \<acute>ind:=0;;
prensani@13020
   110
  .{\<acute>Proper \<and> \<acute>ind=0}.
prensani@13020
   111
  WHILE \<acute>ind<length \<acute>M 
prensani@13020
   112
   INV .{\<acute>Proper \<and> (\<forall>i<\<acute>ind. i \<in> Roots \<longrightarrow> \<acute>M!i=Black) \<and> \<acute>ind\<le>length \<acute>M}.
prensani@13020
   113
  DO .{\<acute>Proper \<and> (\<forall>i<\<acute>ind. i \<in> Roots \<longrightarrow> \<acute>M!i=Black) \<and> \<acute>ind<length \<acute>M}.
prensani@13020
   114
   IF \<acute>ind\<in>Roots THEN 
prensani@13020
   115
   .{\<acute>Proper \<and> (\<forall>i<\<acute>ind. i \<in> Roots \<longrightarrow> \<acute>M!i=Black) \<and> \<acute>ind<length \<acute>M \<and> \<acute>ind\<in>Roots}. 
prensani@13020
   116
    \<acute>M:=\<acute>M[\<acute>ind:=Black] FI;;
prensani@13020
   117
   .{\<acute>Proper \<and> (\<forall>i<\<acute>ind+1. i \<in> Roots \<longrightarrow> \<acute>M!i=Black) \<and> \<acute>ind<length \<acute>M}.
prensani@13020
   118
    \<acute>ind:=\<acute>ind+1 
prensani@13020
   119
  OD"
prensani@13020
   120
prensani@13020
   121
lemma Blacken_Roots: 
prensani@13020
   122
 "\<turnstile> Blacken_Roots .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M}."
prensani@13020
   123
apply (unfold Blacken_Roots_def)
prensani@13020
   124
apply annhoare
prensani@13020
   125
apply(simp_all add:collector_defs Graph_defs)
prensani@13020
   126
apply safe
prensani@13020
   127
apply(simp_all add:nth_list_update)
prensani@13020
   128
  apply (erule less_SucE)
prensani@13020
   129
   apply simp+
prensani@13020
   130
 apply force
prensani@13020
   131
apply force
prensani@13020
   132
done
prensani@13020
   133
prensani@13020
   134
subsubsection {* Propagating black *}
prensani@13020
   135
prensani@13020
   136
constdefs
prensani@13020
   137
  PBInv :: "gar_coll_state \<Rightarrow> nat \<Rightarrow> bool"
prensani@13020
   138
  "PBInv \<equiv> \<guillemotleft> \<lambda>ind. \<acute>obc < Blacks \<acute>M \<or> (\<forall>i <ind. \<not>BtoW (\<acute>E!i, \<acute>M) \<or>
prensani@13020
   139
   (\<not>\<acute>z \<and> i=R \<and> (snd(\<acute>E!R)) = T \<and> (\<exists>r. ind \<le> r \<and> r < length \<acute>E \<and> BtoW(\<acute>E!r,\<acute>M))))\<guillemotright>"
prensani@13020
   140
prensani@13020
   141
constdefs  
prensani@13020
   142
  Propagate_Black_aux :: "gar_coll_state ann_com"
prensani@13020
   143
  "Propagate_Black_aux \<equiv>
prensani@13020
   144
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M}.
prensani@13020
   145
  \<acute>ind:=0;;
prensani@13020
   146
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M \<and> \<acute>ind=0}. 
prensani@13020
   147
  WHILE \<acute>ind<length \<acute>E 
prensani@13020
   148
   INV .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   149
         \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind\<le>length \<acute>E}.
prensani@13020
   150
  DO .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   151
       \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind<length \<acute>E}. 
prensani@13020
   152
   IF \<acute>M!(fst (\<acute>E!\<acute>ind)) = Black THEN 
prensani@13020
   153
    .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   154
       \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind<length \<acute>E \<and> \<acute>M!fst(\<acute>E!\<acute>ind)=Black}.
prensani@13020
   155
     \<acute>M:=\<acute>M[snd(\<acute>E!\<acute>ind):=Black];;
prensani@13020
   156
    .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   157
       \<and> \<acute>PBInv (\<acute>ind + 1) \<and> \<acute>ind<length \<acute>E}.
prensani@13020
   158
     \<acute>ind:=\<acute>ind+1
prensani@13020
   159
   FI
prensani@13020
   160
  OD"
prensani@13020
   161
prensani@13020
   162
lemma Propagate_Black_aux: 
prensani@13020
   163
  "\<turnstile>  Propagate_Black_aux
prensani@13020
   164
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   165
    \<and> ( \<acute>obc < Blacks \<acute>M \<or> \<acute>Safe)}."
prensani@13020
   166
apply (unfold Propagate_Black_aux_def  PBInv_def collector_defs)
prensani@13020
   167
apply annhoare
prensani@13020
   168
apply(simp_all add:Graph6 Graph7 Graph8 Graph12)
prensani@13020
   169
      apply force
prensani@13020
   170
     apply force
prensani@13020
   171
    apply force
prensani@13020
   172
--{* 4 subgoals left *}
prensani@13020
   173
apply clarify
prensani@13020
   174
apply(simp add:Proper_Edges_def Proper_Roots_def Graph6 Graph7 Graph8 Graph12)
prensani@13020
   175
apply (erule disjE)
prensani@13020
   176
 apply(rule disjI1)
prensani@13020
   177
 apply(erule Graph13)
prensani@13020
   178
 apply force
prensani@13020
   179
apply (case_tac "M x ! snd (E x ! ind x)=Black")
prensani@13020
   180
 apply (simp add: Graph10 BtoW_def)
prensani@13020
   181
 apply (rule disjI2)
prensani@13020
   182
 apply clarify
prensani@13020
   183
 apply (erule less_SucE)
prensani@13020
   184
  apply (erule_tac x=i in allE , erule (1) notE impE)
prensani@13020
   185
  apply simp
prensani@13020
   186
  apply clarify
wenzelm@26316
   187
  apply (drule_tac y = r in le_imp_less_or_eq)
prensani@13020
   188
  apply (erule disjE)
prensani@13020
   189
   apply (subgoal_tac "Suc (ind x)\<le>r")
prensani@13020
   190
    apply fast
prensani@13020
   191
   apply arith
prensani@13020
   192
  apply fast
prensani@13020
   193
 apply fast
prensani@13020
   194
apply(rule disjI1)
prensani@13020
   195
apply(erule subset_psubset_trans)
prensani@13020
   196
apply(erule Graph11)
prensani@13020
   197
apply fast
prensani@13020
   198
--{* 3 subgoals left *}
prensani@13020
   199
apply force
prensani@13020
   200
apply force
prensani@13020
   201
--{* last *}
prensani@13020
   202
apply clarify
prensani@13020
   203
apply simp
prensani@13020
   204
apply(subgoal_tac "ind x = length (E x)")
nipkow@34233
   205
 apply (simp)
prensani@13020
   206
 apply(drule Graph1)
prensani@13020
   207
   apply simp
nipkow@34233
   208
  apply clarify
nipkow@34233
   209
  apply(erule allE, erule impE, assumption)
prensani@13020
   210
  apply force
prensani@13020
   211
 apply force
prensani@13020
   212
apply arith
prensani@13020
   213
done
prensani@13020
   214
prensani@13020
   215
subsubsection {* Refining propagating black *}
prensani@13020
   216
prensani@13020
   217
constdefs
prensani@13020
   218
  Auxk :: "gar_coll_state \<Rightarrow> bool"
prensani@13020
   219
  "Auxk \<equiv> \<guillemotleft>\<acute>k<length \<acute>M \<and> (\<acute>M!\<acute>k\<noteq>Black \<or> \<not>BtoW(\<acute>E!\<acute>ind, \<acute>M) \<or> 
prensani@13020
   220
          \<acute>obc<Blacks \<acute>M \<or> (\<not>\<acute>z \<and> \<acute>ind=R \<and> snd(\<acute>E!R)=T  
prensani@13020
   221
          \<and> (\<exists>r. \<acute>ind<r \<and> r<length \<acute>E \<and> BtoW(\<acute>E!r, \<acute>M))))\<guillemotright>"
prensani@13020
   222
prensani@13020
   223
constdefs  
prensani@13020
   224
  Propagate_Black :: " gar_coll_state ann_com"
prensani@13020
   225
  "Propagate_Black \<equiv>
prensani@13020
   226
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M}.
prensani@13020
   227
  \<acute>ind:=0;;
prensani@13020
   228
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M \<and> \<acute>ind=0}.
prensani@13020
   229
  WHILE \<acute>ind<length \<acute>E 
prensani@13020
   230
   INV .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   231
         \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind\<le>length \<acute>E}.
prensani@13020
   232
  DO .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   233
       \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind<length \<acute>E}. 
prensani@13020
   234
   IF (\<acute>M!(fst (\<acute>E!\<acute>ind)))=Black THEN 
prensani@13020
   235
    .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   236
      \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind<length \<acute>E \<and> (\<acute>M!fst(\<acute>E!\<acute>ind))=Black}.
prensani@13020
   237
     \<acute>k:=(snd(\<acute>E!\<acute>ind));;
prensani@13020
   238
    .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   239
      \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind<length \<acute>E \<and> (\<acute>M!fst(\<acute>E!\<acute>ind))=Black 
prensani@13020
   240
      \<and> \<acute>Auxk}.
prensani@13020
   241
     \<langle>\<acute>M:=\<acute>M[\<acute>k:=Black],, \<acute>ind:=\<acute>ind+1\<rangle>
prensani@13020
   242
   ELSE .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   243
          \<and> \<acute>PBInv \<acute>ind \<and> \<acute>ind<length \<acute>E}. 
prensani@13020
   244
         \<langle>IF (\<acute>M!(fst (\<acute>E!\<acute>ind)))\<noteq>Black THEN \<acute>ind:=\<acute>ind+1 FI\<rangle> 
prensani@13020
   245
   FI
prensani@13020
   246
  OD"
prensani@13020
   247
prensani@13020
   248
lemma Propagate_Black: 
prensani@13020
   249
  "\<turnstile>  Propagate_Black
prensani@13020
   250
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   251
    \<and> ( \<acute>obc < Blacks \<acute>M \<or> \<acute>Safe)}."
prensani@13020
   252
apply (unfold Propagate_Black_def  PBInv_def Auxk_def collector_defs)
prensani@13020
   253
apply annhoare
haftmann@32687
   254
apply(simp_all add: Graph6 Graph7 Graph8 Graph12)
prensani@13020
   255
       apply force
prensani@13020
   256
      apply force
prensani@13020
   257
     apply force
prensani@13020
   258
--{* 5 subgoals left *}
prensani@13020
   259
apply clarify
prensani@13020
   260
apply(simp add:BtoW_def Proper_Edges_def)
prensani@13020
   261
--{* 4 subgoals left *}
prensani@13020
   262
apply clarify
prensani@13020
   263
apply(simp add:Proper_Edges_def Graph6 Graph7 Graph8 Graph12)
prensani@13020
   264
apply (erule disjE)
prensani@13020
   265
 apply (rule disjI1)
prensani@13020
   266
 apply (erule psubset_subset_trans)
prensani@13020
   267
 apply (erule Graph9)
prensani@13020
   268
apply (case_tac "M x!k x=Black")
prensani@13020
   269
 apply (case_tac "M x ! snd (E x ! ind x)=Black")
prensani@13020
   270
  apply (simp add: Graph10 BtoW_def)
prensani@13020
   271
  apply (rule disjI2)
prensani@13020
   272
  apply clarify
prensani@13020
   273
  apply (erule less_SucE)
prensani@13020
   274
   apply (erule_tac x=i in allE , erule (1) notE impE)
prensani@13020
   275
   apply simp
prensani@13020
   276
   apply clarify
wenzelm@26316
   277
   apply (drule_tac y = r in le_imp_less_or_eq)
prensani@13020
   278
   apply (erule disjE)
prensani@13020
   279
    apply (subgoal_tac "Suc (ind x)\<le>r")
prensani@13020
   280
     apply fast
prensani@13020
   281
    apply arith
prensani@13020
   282
   apply fast
prensani@13020
   283
  apply fast
prensani@13020
   284
 apply (simp add: Graph10 BtoW_def)
prensani@13020
   285
 apply (erule disjE)
prensani@13020
   286
  apply (erule disjI1)
prensani@13020
   287
 apply clarify
prensani@13020
   288
 apply (erule less_SucE)
prensani@13020
   289
  apply force
prensani@13020
   290
 apply simp
prensani@13020
   291
 apply (subgoal_tac "Suc R\<le>r")
prensani@13020
   292
  apply fast
prensani@13020
   293
 apply arith
prensani@13020
   294
apply(rule disjI1)
prensani@13020
   295
apply(erule subset_psubset_trans)
prensani@13020
   296
apply(erule Graph11)
prensani@13020
   297
apply fast
prensani@13020
   298
--{* 2 subgoals left *}
prensani@13020
   299
apply clarify
prensani@13020
   300
apply(simp add:Proper_Edges_def Graph6 Graph7 Graph8 Graph12)
prensani@13020
   301
apply (erule disjE)
prensani@13020
   302
 apply fast
prensani@13020
   303
apply clarify
prensani@13020
   304
apply (erule less_SucE)
prensani@13020
   305
 apply (erule_tac x=i in allE , erule (1) notE impE)
prensani@13020
   306
 apply simp
prensani@13020
   307
 apply clarify
wenzelm@26316
   308
 apply (drule_tac y = r in le_imp_less_or_eq)
prensani@13020
   309
 apply (erule disjE)
prensani@13020
   310
  apply (subgoal_tac "Suc (ind x)\<le>r")
prensani@13020
   311
   apply fast
prensani@13020
   312
  apply arith
prensani@13020
   313
 apply (simp add: BtoW_def)
prensani@13020
   314
apply (simp add: BtoW_def)
prensani@13020
   315
--{* last *}
prensani@13020
   316
apply clarify
prensani@13020
   317
apply simp
prensani@13020
   318
apply(subgoal_tac "ind x = length (E x)")
nipkow@34233
   319
 apply (simp)
prensani@13020
   320
 apply(drule Graph1)
prensani@13020
   321
   apply simp
prensani@13020
   322
  apply clarify  
nipkow@34233
   323
  apply(erule allE, erule impE, assumption)
prensani@13020
   324
  apply force
prensani@13020
   325
 apply force
prensani@13020
   326
apply arith
prensani@13020
   327
done
prensani@13020
   328
prensani@13020
   329
subsubsection {* Counting black nodes *}
prensani@13020
   330
prensani@13020
   331
constdefs
prensani@13020
   332
  CountInv :: "gar_coll_state \<Rightarrow> nat \<Rightarrow> bool"
prensani@13020
   333
  "CountInv \<equiv> \<guillemotleft> \<lambda>ind. {i. i<ind \<and> \<acute>Ma!i=Black}\<subseteq>\<acute>bc \<guillemotright>"
prensani@13020
   334
prensani@13020
   335
constdefs
prensani@13020
   336
  Count :: " gar_coll_state ann_com"
prensani@13020
   337
  "Count \<equiv>
prensani@13020
   338
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   339
    \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   340
    \<and> length \<acute>Ma=length \<acute>M \<and> (\<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe) \<and> \<acute>bc={}}.
prensani@13020
   341
  \<acute>ind:=0;;
prensani@13020
   342
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   343
    \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   344
   \<and> length \<acute>Ma=length \<acute>M \<and> (\<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe) \<and> \<acute>bc={} 
prensani@13020
   345
   \<and> \<acute>ind=0}.
prensani@13020
   346
   WHILE \<acute>ind<length \<acute>M 
prensani@13020
   347
     INV .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   348
           \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   349
           \<and> length \<acute>Ma=length \<acute>M \<and> \<acute>CountInv \<acute>ind
prensani@13020
   350
           \<and> ( \<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe) \<and> \<acute>ind\<le>length \<acute>M}.
prensani@13020
   351
   DO .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   352
         \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   353
         \<and> length \<acute>Ma=length \<acute>M \<and> \<acute>CountInv \<acute>ind 
prensani@13020
   354
         \<and> ( \<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe) \<and> \<acute>ind<length \<acute>M}. 
prensani@13020
   355
       IF \<acute>M!\<acute>ind=Black 
prensani@13020
   356
          THEN .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   357
                 \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   358
                 \<and> length \<acute>Ma=length \<acute>M \<and> \<acute>CountInv \<acute>ind
prensani@13020
   359
                 \<and> ( \<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe) \<and> \<acute>ind<length \<acute>M \<and> \<acute>M!\<acute>ind=Black}.
prensani@13020
   360
          \<acute>bc:=insert \<acute>ind \<acute>bc
prensani@13020
   361
       FI;;
prensani@13020
   362
      .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   363
        \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   364
        \<and> length \<acute>Ma=length \<acute>M \<and> \<acute>CountInv (\<acute>ind+1)
prensani@13020
   365
        \<and> ( \<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe) \<and> \<acute>ind<length \<acute>M}.
prensani@13020
   366
      \<acute>ind:=\<acute>ind+1
prensani@13020
   367
   OD"
prensani@13020
   368
prensani@13020
   369
lemma Count: 
prensani@13020
   370
  "\<turnstile> Count 
prensani@13020
   371
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   372
   \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>\<acute>bc \<and> \<acute>bc\<subseteq>Blacks \<acute>M \<and> length \<acute>Ma=length \<acute>M
prensani@13020
   373
   \<and> (\<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe)}."
prensani@13020
   374
apply(unfold Count_def)
prensani@13020
   375
apply annhoare
prensani@13020
   376
apply(simp_all add:CountInv_def Graph6 Graph7 Graph8 Graph12 Blacks_def collector_defs)
prensani@13020
   377
      apply force
prensani@13020
   378
     apply force
prensani@13020
   379
    apply force
prensani@13020
   380
   apply clarify
prensani@13020
   381
   apply simp
prensani@13020
   382
   apply(fast elim:less_SucE)
prensani@13020
   383
  apply clarify
prensani@13020
   384
  apply simp
prensani@13020
   385
  apply(fast elim:less_SucE)
prensani@13020
   386
 apply force
prensani@13020
   387
apply force
prensani@13020
   388
done
prensani@13020
   389
prensani@13020
   390
subsubsection {* Appending garbage nodes to the free list *}
prensani@13020
   391
prensani@13020
   392
consts Append_to_free :: "nat \<times> edges \<Rightarrow> edges"
prensani@13020
   393
prensani@13020
   394
axioms
prensani@13020
   395
  Append_to_free0: "length (Append_to_free (i, e)) = length e"
prensani@13020
   396
  Append_to_free1: "Proper_Edges (m, e) 
prensani@13020
   397
                   \<Longrightarrow> Proper_Edges (m, Append_to_free(i, e))"
prensani@13020
   398
  Append_to_free2: "i \<notin> Reach e 
prensani@13020
   399
     \<Longrightarrow> n \<in> Reach (Append_to_free(i, e)) = ( n = i \<or> n \<in> Reach e)"
prensani@13020
   400
prensani@13020
   401
constdefs
prensani@13020
   402
  AppendInv :: "gar_coll_state \<Rightarrow> nat \<Rightarrow> bool"
prensani@13020
   403
  "AppendInv \<equiv> \<guillemotleft>\<lambda>ind. \<forall>i<length \<acute>M. ind\<le>i \<longrightarrow> i\<in>Reach \<acute>E \<longrightarrow> \<acute>M!i=Black\<guillemotright>"
prensani@13020
   404
prensani@13020
   405
constdefs
prensani@13020
   406
  Append :: " gar_coll_state ann_com"
prensani@13020
   407
   "Append \<equiv>
prensani@13020
   408
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>Safe}.
prensani@13020
   409
  \<acute>ind:=0;;
prensani@13020
   410
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>Safe \<and> \<acute>ind=0}.
prensani@13020
   411
    WHILE \<acute>ind<length \<acute>M 
prensani@13020
   412
      INV .{\<acute>Proper \<and> \<acute>AppendInv \<acute>ind \<and> \<acute>ind\<le>length \<acute>M}.
prensani@13020
   413
    DO .{\<acute>Proper \<and> \<acute>AppendInv \<acute>ind \<and> \<acute>ind<length \<acute>M}.
prensani@13020
   414
       IF \<acute>M!\<acute>ind=Black THEN 
prensani@13020
   415
          .{\<acute>Proper \<and> \<acute>AppendInv \<acute>ind \<and> \<acute>ind<length \<acute>M \<and> \<acute>M!\<acute>ind=Black}. 
prensani@13020
   416
          \<acute>M:=\<acute>M[\<acute>ind:=White] 
prensani@13020
   417
       ELSE .{\<acute>Proper \<and> \<acute>AppendInv \<acute>ind \<and> \<acute>ind<length \<acute>M \<and> \<acute>ind\<notin>Reach \<acute>E}.
prensani@13020
   418
              \<acute>E:=Append_to_free(\<acute>ind,\<acute>E)
prensani@13020
   419
       FI;;
prensani@13020
   420
     .{\<acute>Proper \<and> \<acute>AppendInv (\<acute>ind+1) \<and> \<acute>ind<length \<acute>M}. 
prensani@13020
   421
       \<acute>ind:=\<acute>ind+1
prensani@13020
   422
    OD"
prensani@13020
   423
prensani@13020
   424
lemma Append: 
prensani@13020
   425
  "\<turnstile> Append .{\<acute>Proper}."
prensani@13020
   426
apply(unfold Append_def AppendInv_def)
prensani@13020
   427
apply annhoare
prensani@13020
   428
apply(simp_all add:collector_defs Graph6 Graph7 Graph8 Append_to_free0 Append_to_free1 Graph12)
prensani@13020
   429
       apply(force simp:Blacks_def nth_list_update)
prensani@13020
   430
      apply force
prensani@13020
   431
     apply force
prensani@13020
   432
    apply(force simp add:Graph_defs)
prensani@13020
   433
   apply force
prensani@13020
   434
  apply clarify
prensani@13020
   435
  apply simp
prensani@13020
   436
  apply(rule conjI)
prensani@13020
   437
   apply (erule Append_to_free1)
prensani@13020
   438
  apply clarify
prensani@13020
   439
  apply (drule_tac n = "i" in Append_to_free2)
prensani@13020
   440
  apply force
prensani@13020
   441
 apply force
prensani@13020
   442
apply force
prensani@13020
   443
done
prensani@13020
   444
prensani@13020
   445
subsubsection {* Correctness of the Collector *}
prensani@13020
   446
prensani@13020
   447
constdefs 
prensani@13020
   448
  Collector :: " gar_coll_state ann_com"
prensani@13020
   449
  "Collector \<equiv>
prensani@13020
   450
.{\<acute>Proper}.  
prensani@13020
   451
 WHILE True INV .{\<acute>Proper}. 
prensani@13020
   452
 DO  
prensani@13020
   453
  Blacken_Roots;; 
prensani@13020
   454
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M}.  
prensani@13020
   455
   \<acute>obc:={};; 
prensani@13020
   456
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc={}}. 
prensani@13020
   457
   \<acute>bc:=Roots;; 
prensani@13020
   458
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc={} \<and> \<acute>bc=Roots}. 
prensani@13020
   459
   \<acute>Ma:=M_init;;  
prensani@13020
   460
  .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc={} \<and> \<acute>bc=Roots \<and> \<acute>Ma=M_init}. 
prensani@13020
   461
   WHILE \<acute>obc\<noteq>\<acute>bc  
prensani@13020
   462
     INV .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M 
prensani@13020
   463
           \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma \<and> Blacks \<acute>Ma\<subseteq>\<acute>bc \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   464
           \<and> length \<acute>Ma=length \<acute>M \<and> (\<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe)}. 
prensani@13020
   465
   DO .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M}.
prensani@13020
   466
       \<acute>obc:=\<acute>bc;;
prensani@13020
   467
       Propagate_Black;; 
prensani@13020
   468
      .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M 
prensani@13020
   469
        \<and> (\<acute>obc < Blacks \<acute>M \<or> \<acute>Safe)}. 
prensani@13020
   470
       \<acute>Ma:=\<acute>M;;
prensani@13020
   471
      .{\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>Ma 
prensani@13020
   472
        \<and> Blacks \<acute>Ma\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M \<and> length \<acute>Ma=length \<acute>M 
prensani@13020
   473
        \<and> ( \<acute>obc < Blacks \<acute>Ma \<or> \<acute>Safe)}.
prensani@13020
   474
       \<acute>bc:={};;
prensani@13020
   475
       Count 
prensani@13020
   476
   OD;; 
prensani@13020
   477
  Append  
prensani@13020
   478
 OD"
prensani@13020
   479
prensani@13020
   480
lemma Collector: 
prensani@13020
   481
  "\<turnstile> Collector .{False}."
prensani@13020
   482
apply(unfold Collector_def)
prensani@13020
   483
apply annhoare
prensani@13020
   484
apply(simp_all add: Blacken_Roots Propagate_Black Count Append)
prensani@13020
   485
apply(simp_all add:Blacken_Roots_def Propagate_Black_def Count_def Append_def collector_defs)
prensani@13020
   486
   apply (force simp add: Proper_Roots_def)
prensani@13020
   487
  apply force
prensani@13020
   488
 apply force
prensani@13020
   489
apply clarify
prensani@13020
   490
apply (erule disjE)
prensani@13020
   491
apply(simp add:psubsetI)
prensani@13020
   492
 apply(force dest:subset_antisym)
prensani@13020
   493
done
prensani@13020
   494
prensani@13020
   495
subsection {* Interference Freedom *}
prensani@13020
   496
prensani@13020
   497
lemmas modules = Redirect_Edge_def Color_Target_def Blacken_Roots_def 
prensani@13020
   498
                 Propagate_Black_def Count_def Append_def
prensani@13020
   499
lemmas Invariants = PBInv_def Auxk_def CountInv_def AppendInv_def
prensani@13020
   500
lemmas abbrev = collector_defs mutator_defs Invariants
prensani@13020
   501
prensani@13020
   502
lemma interfree_Blacken_Roots_Redirect_Edge: 
prensani@13020
   503
 "interfree_aux (Some Blacken_Roots, {}, Some Redirect_Edge)"
prensani@13020
   504
apply (unfold modules)
prensani@13020
   505
apply interfree_aux
prensani@13020
   506
apply safe
prensani@13020
   507
apply (simp_all add:Graph6 Graph12 abbrev)
prensani@13020
   508
done
prensani@13020
   509
prensani@13020
   510
lemma interfree_Redirect_Edge_Blacken_Roots: 
prensani@13020
   511
  "interfree_aux (Some Redirect_Edge, {}, Some Blacken_Roots)"
prensani@13020
   512
apply (unfold modules)
prensani@13020
   513
apply interfree_aux
prensani@13020
   514
apply safe
prensani@13020
   515
apply(simp add:abbrev)+
prensani@13020
   516
done
prensani@13020
   517
prensani@13020
   518
lemma interfree_Blacken_Roots_Color_Target: 
prensani@13020
   519
  "interfree_aux (Some Blacken_Roots, {}, Some Color_Target)"
prensani@13020
   520
apply (unfold modules)
prensani@13020
   521
apply interfree_aux
prensani@13020
   522
apply safe
prensani@13020
   523
apply(simp_all add:Graph7 Graph8 nth_list_update abbrev)
prensani@13020
   524
done
prensani@13020
   525
prensani@13020
   526
lemma interfree_Color_Target_Blacken_Roots: 
prensani@13020
   527
  "interfree_aux (Some Color_Target, {}, Some Blacken_Roots)"
prensani@13020
   528
apply (unfold modules )
prensani@13020
   529
apply interfree_aux
prensani@13020
   530
apply safe
prensani@13020
   531
apply(simp add:abbrev)+
prensani@13020
   532
done
prensani@13020
   533
prensani@13020
   534
lemma interfree_Propagate_Black_Redirect_Edge: 
prensani@13020
   535
  "interfree_aux (Some Propagate_Black, {}, Some Redirect_Edge)"
prensani@13020
   536
apply (unfold modules )
prensani@13020
   537
apply interfree_aux
prensani@13020
   538
--{* 11 subgoals left *}
prensani@13020
   539
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   540
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   541
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   542
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   543
apply(erule conjE)+
prensani@13020
   544
apply(erule disjE, erule disjI1, rule disjI2, rule allI, (rule impI)+, case_tac "R=i", rule conjI, erule sym)
prensani@13020
   545
 apply(erule Graph4) 
prensani@13020
   546
   apply(simp)+
prensani@13020
   547
  apply (simp add:BtoW_def)
prensani@13020
   548
 apply (simp add:BtoW_def)
prensani@13020
   549
apply(rule conjI)
prensani@13020
   550
 apply (force simp add:BtoW_def)
prensani@13020
   551
apply(erule Graph4)
prensani@13020
   552
   apply simp+
prensani@13020
   553
--{* 7 subgoals left *}
prensani@13020
   554
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   555
apply(erule conjE)+
prensani@13020
   556
apply(erule disjE, erule disjI1, rule disjI2, rule allI, (rule impI)+, case_tac "R=i", rule conjI, erule sym)
prensani@13020
   557
 apply(erule Graph4) 
prensani@13020
   558
   apply(simp)+
prensani@13020
   559
  apply (simp add:BtoW_def)
prensani@13020
   560
 apply (simp add:BtoW_def)
prensani@13020
   561
apply(rule conjI)
prensani@13020
   562
 apply (force simp add:BtoW_def)
prensani@13020
   563
apply(erule Graph4)
prensani@13020
   564
   apply simp+
prensani@13020
   565
--{* 6 subgoals left *}
prensani@13020
   566
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   567
apply(erule conjE)+
prensani@13020
   568
apply(rule conjI)
prensani@13020
   569
 apply(erule disjE, erule disjI1, rule disjI2, rule allI, (rule impI)+, case_tac "R=i", rule conjI, erule sym)
prensani@13020
   570
  apply(erule Graph4) 
prensani@13020
   571
    apply(simp)+
prensani@13020
   572
   apply (simp add:BtoW_def)
prensani@13020
   573
  apply (simp add:BtoW_def)
prensani@13020
   574
 apply(rule conjI)
prensani@13020
   575
  apply (force simp add:BtoW_def)
prensani@13020
   576
 apply(erule Graph4)
prensani@13020
   577
    apply simp+
prensani@13020
   578
apply(simp add:BtoW_def nth_list_update) 
prensani@13020
   579
apply force
prensani@13020
   580
--{* 5 subgoals left *}
prensani@13020
   581
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   582
--{* 4 subgoals left *}
prensani@13020
   583
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   584
apply(rule conjI)
prensani@13020
   585
 apply(erule disjE, erule disjI1, rule disjI2, rule allI, (rule impI)+, case_tac "R=i", rule conjI, erule sym)
prensani@13020
   586
  apply(erule Graph4) 
prensani@13020
   587
    apply(simp)+
prensani@13020
   588
   apply (simp add:BtoW_def)
prensani@13020
   589
  apply (simp add:BtoW_def)
prensani@13020
   590
 apply(rule conjI)
prensani@13020
   591
  apply (force simp add:BtoW_def)
prensani@13020
   592
 apply(erule Graph4)
prensani@13020
   593
    apply simp+
prensani@13020
   594
apply(rule conjI)
prensani@13020
   595
 apply(simp add:nth_list_update)
prensani@13020
   596
 apply force
prensani@13020
   597
apply(rule impI, rule impI, erule disjE, erule disjI1, case_tac "R = (ind x)" ,case_tac "M x ! T = Black")
prensani@13020
   598
  apply(force simp add:BtoW_def)
prensani@13020
   599
 apply(case_tac "M x !snd (E x ! ind x)=Black")
prensani@13020
   600
  apply(rule disjI2)
prensani@13020
   601
  apply simp
prensani@13020
   602
  apply (erule Graph5)
prensani@13020
   603
  apply simp+
prensani@13020
   604
 apply(force simp add:BtoW_def)
prensani@13020
   605
apply(force simp add:BtoW_def)
prensani@13020
   606
--{* 3 subgoals left *}
prensani@13020
   607
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   608
--{* 2 subgoals left *}
prensani@13020
   609
apply(clarify, simp add:abbrev Graph6 Graph12)
prensani@13020
   610
apply(erule disjE, erule disjI1, rule disjI2, rule allI, (rule impI)+, case_tac "R=i", rule conjI, erule sym)
prensani@13020
   611
 apply clarify
prensani@13020
   612
 apply(erule Graph4) 
prensani@13020
   613
   apply(simp)+
prensani@13020
   614
  apply (simp add:BtoW_def)
prensani@13020
   615
 apply (simp add:BtoW_def)
prensani@13020
   616
apply(rule conjI)
prensani@13020
   617
 apply (force simp add:BtoW_def)
prensani@13020
   618
apply(erule Graph4)
prensani@13020
   619
   apply simp+
prensani@13020
   620
done
prensani@13020
   621
prensani@13020
   622
lemma interfree_Redirect_Edge_Propagate_Black: 
prensani@13020
   623
  "interfree_aux (Some Redirect_Edge, {}, Some Propagate_Black)"
prensani@13020
   624
apply (unfold modules )
prensani@13020
   625
apply interfree_aux
prensani@13020
   626
apply(clarify, simp add:abbrev)+
prensani@13020
   627
done
prensani@13020
   628
prensani@13020
   629
lemma interfree_Propagate_Black_Color_Target: 
prensani@13020
   630
  "interfree_aux (Some Propagate_Black, {}, Some Color_Target)"
prensani@13020
   631
apply (unfold modules )
prensani@13020
   632
apply interfree_aux
prensani@13020
   633
--{* 11 subgoals left *}
prensani@13020
   634
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)+
prensani@13020
   635
apply(erule conjE)+
prensani@13020
   636
apply(erule disjE,rule disjI1,erule psubset_subset_trans,erule Graph9, 
prensani@13020
   637
      case_tac "M x!T=Black", rule disjI2,rotate_tac -1, simp add: Graph10, clarify,
prensani@13020
   638
      erule allE, erule impE, assumption, erule impE, assumption, 
prensani@13020
   639
      simp add:BtoW_def, rule disjI1, erule subset_psubset_trans, erule Graph11, force) 
prensani@13020
   640
--{* 7 subgoals left *}
prensani@13020
   641
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   642
apply(erule conjE)+
prensani@13020
   643
apply(erule disjE,rule disjI1,erule psubset_subset_trans,erule Graph9, 
prensani@13020
   644
      case_tac "M x!T=Black", rule disjI2,rotate_tac -1, simp add: Graph10, clarify,
prensani@13020
   645
      erule allE, erule impE, assumption, erule impE, assumption, 
prensani@13020
   646
      simp add:BtoW_def, rule disjI1, erule subset_psubset_trans, erule Graph11, force) 
prensani@13020
   647
--{* 6 subgoals left *}
prensani@13020
   648
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   649
apply clarify
prensani@13020
   650
apply (rule conjI)
prensani@13020
   651
 apply(erule disjE,rule disjI1,erule psubset_subset_trans,erule Graph9, 
prensani@13020
   652
      case_tac "M x!T=Black", rule disjI2,rotate_tac -1, simp add: Graph10, clarify,
prensani@13020
   653
      erule allE, erule impE, assumption, erule impE, assumption, 
prensani@13020
   654
      simp add:BtoW_def, rule disjI1, erule subset_psubset_trans, erule Graph11, force) 
prensani@13020
   655
apply(simp add:nth_list_update)
prensani@13020
   656
--{* 5 subgoals left *}
prensani@13020
   657
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   658
--{* 4 subgoals left *}
prensani@13020
   659
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   660
apply (rule conjI)
prensani@13020
   661
 apply(erule disjE,rule disjI1,erule psubset_subset_trans,erule Graph9, 
prensani@13020
   662
      case_tac "M x!T=Black", rule disjI2,rotate_tac -1, simp add: Graph10, clarify,
prensani@13020
   663
      erule allE, erule impE, assumption, erule impE, assumption, 
prensani@13020
   664
      simp add:BtoW_def, rule disjI1, erule subset_psubset_trans, erule Graph11, force) 
prensani@13020
   665
apply(rule conjI)
prensani@13020
   666
apply(simp add:nth_list_update)
prensani@13020
   667
apply(rule impI,rule impI, case_tac "M x!T=Black",rotate_tac -1, force simp add: BtoW_def Graph10, 
prensani@13020
   668
      erule subset_psubset_trans, erule Graph11, force)
prensani@13020
   669
--{* 3 subgoals left *}
prensani@13020
   670
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   671
--{* 2 subgoals left *}
prensani@13020
   672
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   673
apply(erule disjE,rule disjI1,erule psubset_subset_trans,erule Graph9, 
prensani@13020
   674
      case_tac "M x!T=Black", rule disjI2,rotate_tac -1, simp add: Graph10, clarify,
prensani@13020
   675
      erule allE, erule impE, assumption, erule impE, assumption, 
prensani@13020
   676
      simp add:BtoW_def, rule disjI1, erule subset_psubset_trans, erule Graph11, force) 
prensani@13020
   677
--{* 3 subgoals left *}
prensani@13020
   678
apply(simp add:abbrev)
prensani@13020
   679
done
prensani@13020
   680
prensani@13020
   681
lemma interfree_Color_Target_Propagate_Black: 
prensani@13020
   682
  "interfree_aux (Some Color_Target, {}, Some Propagate_Black)"
prensani@13020
   683
apply (unfold modules )
prensani@13020
   684
apply interfree_aux
prensani@13020
   685
apply(clarify, simp add:abbrev)+
prensani@13020
   686
done
prensani@13020
   687
prensani@13020
   688
lemma interfree_Count_Redirect_Edge: 
prensani@13020
   689
  "interfree_aux (Some Count, {}, Some Redirect_Edge)"
prensani@13020
   690
apply (unfold modules)
prensani@13020
   691
apply interfree_aux
prensani@13020
   692
--{* 9 subgoals left *}
prensani@13020
   693
apply(simp_all add:abbrev Graph6 Graph12)
prensani@13020
   694
--{* 6 subgoals left *}
prensani@13020
   695
apply(clarify, simp add:abbrev Graph6 Graph12,
prensani@13020
   696
      erule disjE,erule disjI1,rule disjI2,rule subset_trans, erule Graph3,force,force)+
prensani@13020
   697
done
prensani@13020
   698
prensani@13020
   699
lemma interfree_Redirect_Edge_Count: 
prensani@13020
   700
  "interfree_aux (Some Redirect_Edge, {}, Some Count)"
prensani@13020
   701
apply (unfold modules )
prensani@13020
   702
apply interfree_aux
prensani@13020
   703
apply(clarify,simp add:abbrev)+
prensani@13020
   704
apply(simp add:abbrev)
prensani@13020
   705
done
prensani@13020
   706
prensani@13020
   707
lemma interfree_Count_Color_Target: 
prensani@13020
   708
  "interfree_aux (Some Count, {}, Some Color_Target)"
prensani@13020
   709
apply (unfold modules )
prensani@13020
   710
apply interfree_aux
prensani@13020
   711
--{* 9 subgoals left *}
prensani@13020
   712
apply(simp_all add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   713
--{* 6 subgoals left *}
prensani@13020
   714
apply(clarify,simp add:abbrev Graph7 Graph8 Graph12,
prensani@13020
   715
      erule disjE, erule disjI1, rule disjI2,erule subset_trans, erule Graph9)+
prensani@13020
   716
--{* 2 subgoals left *}
prensani@13020
   717
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12)
prensani@13020
   718
apply(rule conjI)
prensani@13020
   719
 apply(erule disjE, erule disjI1, rule disjI2,erule subset_trans, erule Graph9) 
prensani@13020
   720
apply(simp add:nth_list_update)
prensani@13022
   721
--{* 1 subgoal left *}
prensani@13020
   722
apply(clarify, simp add:abbrev Graph7 Graph8 Graph12,
prensani@13020
   723
      erule disjE, erule disjI1, rule disjI2,erule subset_trans, erule Graph9)
prensani@13020
   724
done
prensani@13020
   725
prensani@13020
   726
lemma interfree_Color_Target_Count: 
prensani@13020
   727
  "interfree_aux (Some Color_Target, {}, Some Count)"
prensani@13020
   728
apply (unfold modules )
prensani@13020
   729
apply interfree_aux
prensani@13020
   730
apply(clarify, simp add:abbrev)+
prensani@13020
   731
apply(simp add:abbrev)
prensani@13020
   732
done
prensani@13020
   733
prensani@13020
   734
lemma interfree_Append_Redirect_Edge: 
prensani@13020
   735
  "interfree_aux (Some Append, {}, Some Redirect_Edge)"
prensani@13020
   736
apply (unfold modules )
prensani@13020
   737
apply interfree_aux
prensani@13020
   738
apply( simp_all add:abbrev Graph6 Append_to_free0 Append_to_free1 Graph12)
prensani@13020
   739
apply(clarify, simp add:abbrev Graph6 Append_to_free0 Append_to_free1 Graph12, force dest:Graph3)+
prensani@13020
   740
done
prensani@13020
   741
prensani@13020
   742
lemma interfree_Redirect_Edge_Append: 
prensani@13020
   743
  "interfree_aux (Some Redirect_Edge, {}, Some Append)"
prensani@13020
   744
apply (unfold modules )
prensani@13020
   745
apply interfree_aux
prensani@13020
   746
apply(clarify, simp add:abbrev Append_to_free0)+
prensani@13020
   747
apply (force simp add: Append_to_free2)
prensani@13020
   748
apply(clarify, simp add:abbrev Append_to_free0)+
prensani@13020
   749
done
prensani@13020
   750
prensani@13020
   751
lemma interfree_Append_Color_Target: 
prensani@13020
   752
  "interfree_aux (Some Append, {}, Some Color_Target)"
prensani@13020
   753
apply (unfold modules )
prensani@13020
   754
apply interfree_aux
prensani@13020
   755
apply(clarify, simp add:abbrev Graph7 Graph8 Append_to_free0 Append_to_free1 Graph12 nth_list_update)+
prensani@13020
   756
apply(simp add:abbrev Graph7 Graph8 Append_to_free0 Append_to_free1 Graph12 nth_list_update)
prensani@13020
   757
done
prensani@13020
   758
prensani@13020
   759
lemma interfree_Color_Target_Append: 
prensani@13020
   760
  "interfree_aux (Some Color_Target, {}, Some Append)"
prensani@13020
   761
apply (unfold modules )
prensani@13020
   762
apply interfree_aux
prensani@13020
   763
apply(clarify, simp add:abbrev Append_to_free0)+
prensani@13020
   764
apply (force simp add: Append_to_free2)
prensani@13020
   765
apply(clarify,simp add:abbrev Append_to_free0)+
prensani@13020
   766
done
prensani@13020
   767
prensani@13020
   768
lemmas collector_mutator_interfree = 
prensani@13020
   769
 interfree_Blacken_Roots_Redirect_Edge interfree_Blacken_Roots_Color_Target 
prensani@13020
   770
 interfree_Propagate_Black_Redirect_Edge interfree_Propagate_Black_Color_Target  
prensani@13020
   771
 interfree_Count_Redirect_Edge interfree_Count_Color_Target 
prensani@13020
   772
 interfree_Append_Redirect_Edge interfree_Append_Color_Target 
prensani@13020
   773
 interfree_Redirect_Edge_Blacken_Roots interfree_Color_Target_Blacken_Roots 
prensani@13020
   774
 interfree_Redirect_Edge_Propagate_Black interfree_Color_Target_Propagate_Black  
prensani@13020
   775
 interfree_Redirect_Edge_Count interfree_Color_Target_Count 
prensani@13020
   776
 interfree_Redirect_Edge_Append interfree_Color_Target_Append
prensani@13020
   777
prensani@13020
   778
subsubsection {* Interference freedom Collector-Mutator *}
prensani@13020
   779
prensani@13020
   780
lemma interfree_Collector_Mutator:
prensani@13020
   781
 "interfree_aux (Some Collector, {}, Some Mutator)"
prensani@13020
   782
apply(unfold Collector_def Mutator_def)
prensani@13020
   783
apply interfree_aux
prensani@13020
   784
apply(simp_all add:collector_mutator_interfree)
prensani@13020
   785
apply(unfold modules collector_defs mutator_defs)
prensani@13020
   786
apply(tactic  {* TRYALL (interfree_aux_tac) *})
prensani@13020
   787
--{* 32 subgoals left *}
prensani@13020
   788
apply(simp_all add:Graph6 Graph7 Graph8 Append_to_free0 Append_to_free1 Graph12)
prensani@13020
   789
--{* 20 subgoals left *}
wenzelm@23894
   790
apply(tactic{* TRYALL (clarify_tac @{claset}) *})
prensani@13020
   791
apply(simp_all add:Graph6 Graph7 Graph8 Append_to_free0 Append_to_free1 Graph12)
prensani@13020
   792
apply(tactic {* TRYALL (etac disjE) *})
prensani@13020
   793
apply simp_all
wenzelm@26342
   794
apply(tactic {* TRYALL(EVERY'[rtac disjI2,rtac subset_trans,etac @{thm Graph3},force_tac @{clasimpset}, assume_tac]) *})
wenzelm@26342
   795
apply(tactic {* TRYALL(EVERY'[rtac disjI2,etac subset_trans,rtac @{thm Graph9},force_tac @{clasimpset}]) *})
wenzelm@26342
   796
apply(tactic {* TRYALL(EVERY'[rtac disjI1,etac @{thm psubset_subset_trans},rtac @{thm Graph9},force_tac @{clasimpset}]) *})
prensani@13020
   797
done
prensani@13020
   798
prensani@13020
   799
subsubsection {* Interference freedom Mutator-Collector *}
prensani@13020
   800
prensani@13020
   801
lemma interfree_Mutator_Collector:
prensani@13020
   802
 "interfree_aux (Some Mutator, {}, Some Collector)"
prensani@13020
   803
apply(unfold Collector_def Mutator_def)
prensani@13020
   804
apply interfree_aux
prensani@13020
   805
apply(simp_all add:collector_mutator_interfree)
prensani@13020
   806
apply(unfold modules collector_defs mutator_defs)
prensani@13020
   807
apply(tactic  {* TRYALL (interfree_aux_tac) *})
prensani@13020
   808
--{* 64 subgoals left *}
prensani@13020
   809
apply(simp_all add:nth_list_update Invariants Append_to_free0)+
wenzelm@23894
   810
apply(tactic{* TRYALL (clarify_tac @{claset}) *})
prensani@13020
   811
--{* 4 subgoals left *}
prensani@13020
   812
apply force
prensani@13020
   813
apply(simp add:Append_to_free2)
prensani@13020
   814
apply force
prensani@13020
   815
apply(simp add:Append_to_free2)
prensani@13020
   816
done
prensani@13020
   817
prensani@13020
   818
subsubsection {* The Garbage Collection algorithm *}
prensani@13020
   819
prensani@13020
   820
text {* In total there are 289 verification conditions.  *}
prensani@13020
   821
prensani@13020
   822
lemma Gar_Coll: 
prensani@13020
   823
  "\<parallel>- .{\<acute>Proper \<and> \<acute>Mut_init \<and> \<acute>z}.  
prensani@13020
   824
  COBEGIN  
prensani@13020
   825
   Collector
prensani@13020
   826
  .{False}.
prensani@13020
   827
 \<parallel>  
prensani@13020
   828
   Mutator
prensani@13020
   829
  .{False}. 
prensani@13020
   830
 COEND 
prensani@13020
   831
  .{False}."
prensani@13020
   832
apply oghoare
prensani@13020
   833
apply(force simp add: Mutator_def Collector_def modules)
prensani@13020
   834
apply(rule Collector)
prensani@13020
   835
apply(rule Mutator)
prensani@13020
   836
apply(simp add:interfree_Collector_Mutator)
prensani@13020
   837
apply(simp add:interfree_Mutator_Collector)
prensani@13020
   838
apply force
prensani@13020
   839
done
prensani@13020
   840
prensani@13020
   841
end