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