PIPBasics.thy
changeset 108 b769f43deb30
parent 107 30ed212f268a
child 109 4e59c0ce1511
equal deleted inserted replaced
107:30ed212f268a 108:b769f43deb30
     1 theory PIPBasics
     1 theory PIPBasics
     2 imports PIPDefs
     2 imports PIPDefs
     3 begin
     3 begin
     4 
     4 
     5 section {* Generic aulxiliary lemmas *}
     5 section {* Generic aulxiliary lemmas *}
       
     6 
       
     7 lemma rel_eqI:
       
     8   assumes "\<And> x y. (x,y) \<in> A \<Longrightarrow> (x,y) \<in> B"
       
     9   and "\<And> x y. (x,y) \<in> B \<Longrightarrow> (x, y) \<in> A"
       
    10   shows "A = B"
       
    11   using assms by auto
     6 
    12 
     7 lemma f_image_eq:
    13 lemma f_image_eq:
     8   assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
    14   assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
     9   shows "f ` A = g ` A"
    15   shows "f ` A = g ` A"
    10 proof
    16 proof
    84   also from assms have "... = ?L"
    90   also from assms have "... = ?L"
    85       by (subst Max.insert, simp+)
    91       by (subst Max.insert, simp+)
    86   finally show ?thesis by simp
    92   finally show ?thesis by simp
    87 qed
    93 qed
    88 
    94 
    89 lemma rel_eqI:
       
    90   assumes "\<And> x y. (x,y) \<in> A \<Longrightarrow> (x,y) \<in> B"
       
    91   and "\<And> x y. (x,y) \<in> B \<Longrightarrow> (x, y) \<in> A"
       
    92   shows "A = B"
       
    93   using assms by auto
       
    94 
       
    95 section {* Lemmas do not depend on trace validity *}
    95 section {* Lemmas do not depend on trace validity *}
       
    96 
       
    97 text {* The following lemma serves to proof @{text "preced_tm_lt"} *}
    96 
    98 
    97 lemma birth_time_lt:  
    99 lemma birth_time_lt:  
    98   assumes "s \<noteq> []"
   100   assumes "s \<noteq> []"
    99   shows "last_set th s < length s"
   101   shows "last_set th s < length s"
   100   using assms
   102   using assms
   110     show ?thesis using Cons(1)[OF True]
   112     show ?thesis using Cons(1)[OF True]
   111       by (cases a, auto)
   113       by (cases a, auto)
   112   qed
   114   qed
   113 qed simp
   115 qed simp
   114 
   116 
       
   117 text {* The following lemma also serves to proof @{text "preced_tm_lt"} *}
   115 lemma th_in_ne: "th \<in> threads s \<Longrightarrow> s \<noteq> []"
   118 lemma th_in_ne: "th \<in> threads s \<Longrightarrow> s \<noteq> []"
   116   by (induct s, auto)
   119   by (induct s, auto)
   117 
   120 
       
   121 text {* The following lemma is used in Correctness.thy *}
   118 lemma preced_tm_lt: "th \<in> threads s \<Longrightarrow> preced th s = Prc x y \<Longrightarrow> y < length s"
   122 lemma preced_tm_lt: "th \<in> threads s \<Longrightarrow> preced th s = Prc x y \<Longrightarrow> y < length s"
   119   by (drule_tac th_in_ne, unfold preced_def, auto intro: birth_time_lt)
   123   by (drule_tac th_in_ne, unfold preced_def, auto intro: birth_time_lt)
   120 
   124 
   121 lemma eq_RAG: 
   125 text {*
   122   "RAG (wq s) = RAG s"
   126   The follow lemma says if a resource is waited for, it must be held
   123   by (unfold cs_RAG_def s_RAG_def, auto)
   127   by someone else.
   124 
   128 *}
   125 lemma waiting_holding:
   129 lemma waiting_holding:
   126   assumes "waiting (s::state) th cs"
   130   assumes "waiting (s::state) th cs"
   127   obtains th' where "holding s th' cs"
   131   obtains th' where "holding s th' cs"
   128 proof -
   132 proof -
   129   from assms[unfolded s_waiting_def, folded wq_def]
   133   from assms[unfolded s_waiting_def, folded wq_def]
   132   hence "holding s th' cs" 
   136   hence "holding s th' cs" 
   133     by (unfold s_holding_def, fold wq_def, auto)
   137     by (unfold s_holding_def, fold wq_def, auto)
   134   from that[OF this] show ?thesis .
   138   from that[OF this] show ?thesis .
   135 qed
   139 qed
   136 
   140 
   137 lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th"
   141 text {* 
       
   142   The following four lemmas relate the @{term wq}
       
   143   and non-@{term wq} versions of @{term waiting}, @{term holding},
       
   144   @{term dependants} and @{term cp}.
       
   145 *}
       
   146 
       
   147 lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
       
   148   by  (unfold s_waiting_def cs_waiting_def wq_def, auto)
       
   149 
       
   150 lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
       
   151   by (unfold s_holding_def wq_def cs_holding_def, simp)
       
   152 
       
   153 lemma eq_dependants: "dependants (wq s) = dependants s"
       
   154   by (simp add: s_dependants_abv wq_def)
       
   155 
       
   156 lemma cp_eq: "cp s th = cpreced (wq s) s th"
   138 unfolding cp_def wq_def
   157 unfolding cp_def wq_def
   139 apply(induct s rule: schs.induct)
   158 apply(induct s rule: schs.induct)
   140 apply(simp add: Let_def cpreced_initial)
   159 apply(simp add: Let_def cpreced_initial)
   141 apply(simp add: Let_def)
   160 apply(simp add: Let_def)
   142 apply(simp add: Let_def)
   161 apply(simp add: Let_def)
   145 apply(simp add: Let_def)
   164 apply(simp add: Let_def)
   146 apply(subst (2) schs.simps)
   165 apply(subst (2) schs.simps)
   147 apply(simp add: Let_def)
   166 apply(simp add: Let_def)
   148 done
   167 done
   149 
   168 
       
   169 text {*
       
   170   The following lemmas is an alternative definition of @{term cp},
       
   171   which is based on the notion of subtrees in @{term RAG} and 
       
   172   is handy to use once the abstract theory of {\em relational graph}
       
   173   (and specifically {\em relational tree} and {\em relational forest})
       
   174   are in place.
       
   175 *}
   150 lemma cp_alt_def:
   176 lemma cp_alt_def:
   151   "cp s th =  
   177   "cp s th =  
   152            Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})"
   178            Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})"
   153 proof -
   179 proof -
   154   have "Max (the_preced s ` ({th} \<union> dependants (wq s) th)) =
   180   have "Max (the_preced s ` ({th} \<union> dependants (wq s) th)) =
   157   proof -
   183   proof -
   158     have "?L = ?R" 
   184     have "?L = ?R" 
   159     by (auto dest:rtranclD simp:cs_dependants_def cs_RAG_def s_RAG_def subtree_def)
   185     by (auto dest:rtranclD simp:cs_dependants_def cs_RAG_def s_RAG_def subtree_def)
   160     thus ?thesis by simp
   186     thus ?thesis by simp
   161   qed
   187   qed
   162   thus ?thesis by (unfold cp_eq_cpreced cpreced_def, fold the_preced_def, simp)
   188   thus ?thesis by (unfold cp_eq cpreced_def, fold the_preced_def, simp)
   163 qed
   189 qed
   164 
   190 
   165 lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs"
   191 text {*
   166   by (unfold s_RAG_def, auto)
   192   The following @{text "children_RAG_alt_def"} relates
   167 
   193   @{term children} in @{term RAG} to the notion of @{term holding}.
   168 lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
   194   It is a technical lemmas used to prove the two following lemmas.
   169   by  (unfold s_waiting_def cs_waiting_def wq_def, auto)
   195 *}
   170 
       
   171 lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
       
   172   by (unfold s_holding_def wq_def cs_holding_def, simp)
       
   173 
       
   174 lemma children_RAG_alt_def:
   196 lemma children_RAG_alt_def:
   175   "children (RAG (s::state)) (Th th) = Cs ` {cs. holding s th cs}"
   197   "children (RAG (s::state)) (Th th) = Cs ` {cs. holding s th cs}"
   176   by (unfold s_RAG_def, auto simp:children_def holding_eq)
   198   by (unfold s_RAG_def, auto simp:children_def holding_eq)
   177 
   199 
       
   200 text {*
       
   201   The following two lemmas relate @{term holdents} and @{term cntCS}
       
   202   to @{term children} in @{term RAG}, so that proofs about
       
   203   @{term holdents} and @{term cntCS} can be carried out under 
       
   204   the support of the abstract theory of {\em relational graph}
       
   205   (and specifically {\em relational tree} and {\em relational forest}).
       
   206 *}
   178 lemma holdents_alt_def:
   207 lemma holdents_alt_def:
   179   "holdents s th = the_cs ` (children (RAG (s::state)) (Th th))"
   208   "holdents s th = the_cs ` (children (RAG (s::state)) (Th th))"
   180   by (unfold children_RAG_alt_def holdents_def, simp add: image_image)
   209   by (unfold children_RAG_alt_def holdents_def, simp add: image_image)
   181 
   210 
   182 lemma cntCS_alt_def:
   211 lemma cntCS_alt_def:
   183   "cntCS s th = card (children (RAG s) (Th th))"
   212   "cntCS s th = card (children (RAG s) (Th th))"
   184   apply (unfold children_RAG_alt_def cntCS_def holdents_def)
   213   apply (unfold children_RAG_alt_def cntCS_def holdents_def)
   185   by (rule card_image[symmetric], auto simp:inj_on_def)
   214   by (rule card_image[symmetric], auto simp:inj_on_def)
   186 
   215 
       
   216 text {*
       
   217   The following two lemmas show the inclusion relations
       
   218   among three key sets, namely @{term runing}, @{term readys}
       
   219   and @{term threads}.
       
   220 *}
   187 lemma runing_ready: 
   221 lemma runing_ready: 
   188   shows "runing s \<subseteq> readys s"
   222   shows "runing s \<subseteq> readys s"
   189   unfolding runing_def readys_def
   223   unfolding runing_def readys_def
   190   by auto 
   224   by auto 
   191 
   225 
   192 lemma readys_threads:
   226 lemma readys_threads:
   193   shows "readys s \<subseteq> threads s"
   227   shows "readys s \<subseteq> threads s"
   194   unfolding readys_def
   228   unfolding readys_def
   195   by auto
   229   by auto
   196 
   230 
   197 lemma wq_v_neq [simp]:
   231 text {*
   198    "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'"
   232   The following lemma says that if a thread is running, 
   199   by (auto simp:wq_def Let_def cp_def split:list.splits)
   233   it must be the head of every waiting queue it is in. 
   200 
   234   In other words, a running thread must have got every 
   201 lemma runing_head:
   235   resource it has requested.
   202   assumes "th \<in> runing s"
   236 *}
   203   and "th \<in> set (wq_fun (schs s) cs)"
       
   204   shows "th = hd (wq_fun (schs s) cs)"
       
   205   using assms
       
   206   by (simp add:runing_def readys_def s_waiting_def wq_def)
       
   207 
       
   208 lemma runing_wqE:
   237 lemma runing_wqE:
   209   assumes "th \<in> runing s"
   238   assumes "th \<in> runing s"
   210   and "th \<in> set (wq s cs)"
   239   and "th \<in> set (wq s cs)"
   211   obtains rest where "wq s cs = th#rest"
   240   obtains rest where "wq s cs = th#rest"
   212 proof -
   241 proof -
   223       by (unfold runing_def readys_def, auto)
   252       by (unfold runing_def readys_def, auto)
   224   qed
   253   qed
   225   with eq_wq that show ?thesis by metis
   254   with eq_wq that show ?thesis by metis
   226 qed
   255 qed
   227 
   256 
   228 lemma isP_E:
       
   229   assumes "isP e"
       
   230   obtains cs where "e = P (actor e) cs"
       
   231   using assms by (cases e, auto)
       
   232 
       
   233 lemma isV_E:
       
   234   assumes "isV e"
       
   235   obtains cs where "e = V (actor e) cs"
       
   236   using assms by (cases e, auto) 
       
   237 
       
   238 
       
   239 text {*
   257 text {*
   240   Every thread can only be blocked on one critical resource, 
   258   Every thread can only be blocked on one critical resource, 
   241   symmetrically, every critical resource can only be held by one thread. 
   259   symmetrically, every critical resource can only be held by one thread. 
   242   This fact is much more easier according to our definition. 
   260   This fact is much more easier according to our definition. 
   243 *}
   261 *}
   245   assumes "holding (s::event list) th1 cs"
   263   assumes "holding (s::event list) th1 cs"
   246   and "holding s th2 cs"
   264   and "holding s th2 cs"
   247   shows "th1 = th2"
   265   shows "th1 = th2"
   248  by (insert assms, unfold s_holding_def, auto)
   266  by (insert assms, unfold s_holding_def, auto)
   249 
   267 
       
   268 text {*
       
   269   The following three lemmas establishes the uniqueness of
       
   270   precedence, a key property about precedence.
       
   271   The first two are just technical lemmas to assist the proof
       
   272   of the third.
       
   273 *}
   250 lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s"
   274 lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s"
   251   apply (induct s, auto)
   275   apply (induct s, auto)
   252   by (case_tac a, auto split:if_splits)
   276   by (case_tac a, auto split:if_splits)
   253 
   277 
   254 lemma last_set_unique: 
   278 lemma last_set_unique: 
   265 proof -
   289 proof -
   266   from pcd_eq have "last_set th1 s = last_set th2 s" by (simp add:preced_def)
   290   from pcd_eq have "last_set th1 s = last_set th2 s" by (simp add:preced_def)
   267   from last_set_unique [OF this th_in1 th_in2]
   291   from last_set_unique [OF this th_in1 th_in2]
   268   show ?thesis .
   292   show ?thesis .
   269 qed
   293 qed
   270                       
   294 
       
   295 text {*
       
   296   The following lemma shows that there exits a linear order
       
   297   on precedences, which is crucial for the notion of 
       
   298   @{term Max} to be applicable.
       
   299 *}
   271 lemma preced_linorder: 
   300 lemma preced_linorder: 
   272   assumes neq_12: "th1 \<noteq> th2"
   301   assumes neq_12: "th1 \<noteq> th2"
   273   and th_in1: "th1 \<in> threads s"
   302   and th_in1: "th1 \<in> threads s"
   274   and th_in2: " th2 \<in> threads s"
   303   and th_in2: " th2 \<in> threads s"
   275   shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
   304   shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
   277   from preced_unique [OF _ th_in1 th_in2] and neq_12 
   306   from preced_unique [OF _ th_in1 th_in2] and neq_12 
   278   have "preced th1 s \<noteq> preced th2 s" by auto
   307   have "preced th1 s \<noteq> preced th2 s" by auto
   279   thus ?thesis by auto
   308   thus ?thesis by auto
   280 qed
   309 qed
   281 
   310 
       
   311 text {*
       
   312   The following lemma case analysis the situations when
       
   313   two nodes are in @{term RAG}.
       
   314 *}
   282 lemma in_RAG_E:
   315 lemma in_RAG_E:
   283   assumes "(n1, n2) \<in> RAG (s::state)"
   316   assumes "(n1, n2) \<in> RAG (s::state)"
   284   obtains (waiting) th cs where "n1 = Th th" "n2 = Cs cs" "waiting s th cs"
   317   obtains (waiting) th cs where "n1 = Th th" "n2 = Cs cs" "waiting s th cs"
   285       | (holding) th cs where "n1 = Cs cs" "n2 = Th th" "holding s th cs"
   318       | (holding) th cs where "n1 = Cs cs" "n2 = Th th" "holding s th cs"
   286   using assms[unfolded s_RAG_def, folded waiting_eq holding_eq]
   319   using assms[unfolded s_RAG_def, folded waiting_eq holding_eq]
   287   by auto
   320   by auto
       
   321 
       
   322 text {*
       
   323   The following lemmas are the simplification rules 
       
   324   for @{term count}, @{term cntP}, @{term cntV}.
       
   325   It is a major technical in this development to use 
       
   326   the counter of @{term "P"} and @{term "V"} (* ccc *)
       
   327 *}
   288 
   328 
   289 lemma count_rec1 [simp]: 
   329 lemma count_rec1 [simp]: 
   290   assumes "Q e"
   330   assumes "Q e"
   291   shows "count Q (e#es) = Suc (count Q es)"
   331   shows "count Q (e#es) = Suc (count Q es)"
   292   using assms
   332   using assms
   351   case (V th' pty)
   391   case (V th' pty)
   352   show ?thesis
   392   show ?thesis
   353   by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", 
   393   by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", 
   354         insert assms V, auto simp:cntV_def)
   394         insert assms V, auto simp:cntV_def)
   355 qed (insert assms, auto simp:cntV_def)
   395 qed (insert assms, auto simp:cntV_def)
   356 
       
   357 lemma eq_dependants: "dependants (wq s) = dependants s"
       
   358   by (simp add: s_dependants_abv wq_def)
       
   359 
       
   360 lemma inj_the_preced: 
       
   361   "inj_on (the_preced s) (threads s)"
       
   362   by (metis inj_onI preced_unique the_preced_def)
       
   363 
       
   364 lemma holding_next_thI:
       
   365   assumes "holding s th cs"
       
   366   and "length (wq s cs) > 1"
       
   367   obtains th' where "next_th s th cs th'"
       
   368 proof -
       
   369   from assms(1)[folded holding_eq, unfolded cs_holding_def]
       
   370   have " th \<in> set (wq s cs) \<and> th = hd (wq s cs)" 
       
   371     by (unfold s_holding_def, fold wq_def, auto)
       
   372   then obtain rest where h1: "wq s cs = th#rest" 
       
   373     by (cases "wq s cs", auto)
       
   374   with assms(2) have h2: "rest \<noteq> []" by auto
       
   375   let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
       
   376   have "next_th s th cs ?th'" using  h1(1) h2 
       
   377     by (unfold next_th_def, auto)
       
   378   from that[OF this] show ?thesis .
       
   379 qed
       
   380 
   396 
   381 (* ccc *)
   397 (* ccc *)
   382 
   398 
   383 section {* Locales used to investigate the execution of PIP *}
   399 section {* Locales used to investigate the execution of PIP *}
   384 
   400 
   673   using vt_moment[of "Suc i", unfolded trace_e]
   689   using vt_moment[of "Suc i", unfolded trace_e]
   674   by (unfold_locales, simp)
   690   by (unfold_locales, simp)
   675 
   691 
   676 section {* Distinctiveness of waiting queues *}
   692 section {* Distinctiveness of waiting queues *}
   677 
   693 
       
   694 lemma (in valid_trace) finite_threads:
       
   695   shows "finite (threads s)"
       
   696   using vt by (induct) (auto elim: step.cases)
       
   697 
       
   698 lemma (in valid_trace) finite_readys [simp]: "finite (readys s)"
       
   699   using finite_threads readys_threads rev_finite_subset by blast
       
   700 
   678 context valid_trace_create
   701 context valid_trace_create
   679 begin
   702 begin
   680 
   703 
   681 lemma wq_kept [simp]:
   704 lemma wq_kept [simp]:
   682   shows "wq (e#s) cs' = wq s cs'"
   705   shows "wq (e#s) cs' = wq s cs'"
   808   using assms by simp
   831   using assms by simp
   809 end
   832 end
   810 
   833 
   811 context valid_trace
   834 context valid_trace
   812 begin
   835 begin
   813 
       
   814 lemma  finite_threads:
       
   815   shows "finite (threads s)"
       
   816   using vt by (induct) (auto elim: step.cases)
       
   817 
       
   818 lemma finite_readys [simp]: "finite (readys s)"
       
   819   using finite_threads readys_threads rev_finite_subset by blast
       
   820 
   836 
   821 lemma wq_distinct: "distinct (wq s cs)"
   837 lemma wq_distinct: "distinct (wq s cs)"
   822 proof(induct rule:ind)
   838 proof(induct rule:ind)
   823   case (Cons s e)
   839   case (Cons s e)
   824   interpret vt_e: valid_trace_e s e using Cons by simp
   840   interpret vt_e: valid_trace_e s e using Cons by simp
  1031 lemma  dm_RAG_threads:
  1047 lemma  dm_RAG_threads:
  1032   assumes in_dom: "(Th th) \<in> Domain (RAG s)"
  1048   assumes in_dom: "(Th th) \<in> Domain (RAG s)"
  1033   shows "th \<in> threads s"
  1049   shows "th \<in> threads s"
  1034 proof -
  1050 proof -
  1035   from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
  1051   from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
  1036   moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto
  1052   moreover then obtain cs where "n = Cs cs" by (unfold s_RAG_def, auto)
  1037   ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
  1053   ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
  1038   hence "th \<in> set (wq s cs)"
  1054   hence "th \<in> set (wq s cs)"
  1039     by (unfold s_RAG_def, auto simp:cs_waiting_def)
  1055     by (unfold s_RAG_def, auto simp:cs_waiting_def)
  1040   from wq_threads [OF this] show ?thesis .
  1056   from wq_threads [OF this] show ?thesis .
  1041 qed
  1057 qed
  1121     with wq_s_cs[folded otherwise] wq_distinct[of cs]
  1137     with wq_s_cs[folded otherwise] wq_distinct[of cs]
  1122     show ?thesis by simp
  1138     show ?thesis by simp
  1123   next
  1139   next
  1124     case False
  1140     case False
  1125     have "wq (e#s) c = wq s c" using False
  1141     have "wq (e#s) c = wq s c" using False
  1126         by (unfold is_v, simp)
  1142         by simp
  1127     hence "waiting s t c" using assms 
  1143     hence "waiting s t c" using assms 
  1128         by (simp add: cs_waiting_def waiting_eq)
  1144         by (simp add: cs_waiting_def waiting_eq)
  1129     hence "t \<notin> readys s" by (unfold readys_def, auto)
  1145     hence "t \<notin> readys s" by (unfold readys_def, auto)
  1130     hence "t \<notin> runing s" using runing_ready by auto 
  1146     hence "t \<notin> runing s" using runing_ready by auto 
  1131     with runing_th_s[folded otherwise] show ?thesis by auto 
  1147     with runing_th_s[folded otherwise] show ?thesis by auto 
  1136   assumes "waiting s t c"
  1152   assumes "waiting s t c"
  1137       and "c \<noteq> cs" 
  1153       and "c \<noteq> cs" 
  1138   shows "waiting (e#s) t c" 
  1154   shows "waiting (e#s) t c" 
  1139 proof -
  1155 proof -
  1140   have "wq (e#s) c = wq s c" 
  1156   have "wq (e#s) c = wq s c" 
  1141     using assms(2) is_v by auto
  1157     using assms(2) by auto
  1142   with assms(1) show ?thesis 
  1158   with assms(1) show ?thesis 
  1143     using cs_waiting_def waiting_eq by auto 
  1159     using cs_waiting_def waiting_eq by auto 
  1144 qed
  1160 qed
  1145 
  1161 
  1146 lemma holding_esI2:
  1162 lemma holding_esI2:
  1147   assumes "c \<noteq> cs" 
  1163   assumes "c \<noteq> cs" 
  1148   and "holding s t c"
  1164   and "holding s t c"
  1149   shows "holding (e#s) t c"
  1165   shows "holding (e#s) t c"
  1150 proof -
  1166 proof -
  1151   from assms(1) have "wq (e#s) c = wq s c" using is_v by auto
  1167   from assms(1) have "wq (e#s) c = wq s c"  by auto
  1152   from assms(2)[unfolded s_holding_def, folded wq_def, 
  1168   from assms(2)[unfolded s_holding_def, folded wq_def, 
  1153                 folded this, unfolded wq_def, folded s_holding_def]
  1169                 folded this, unfolded wq_def, folded s_holding_def]
  1154   show ?thesis .
  1170   show ?thesis .
  1155 qed
  1171 qed
  1156 
  1172 
  1241   assumes "waiting (e#s) t c" 
  1257   assumes "waiting (e#s) t c" 
  1242   obtains "c \<noteq> cs" "waiting s t c"
  1258   obtains "c \<noteq> cs" "waiting s t c"
  1243      |    "c = cs" "t \<noteq> taker" "waiting s t cs" "t \<in> set rest'"
  1259      |    "c = cs" "t \<noteq> taker" "waiting s t cs" "t \<in> set rest'"
  1244 proof(cases "c = cs")
  1260 proof(cases "c = cs")
  1245   case False
  1261   case False
  1246   hence "wq (e#s) c = wq s c" using is_v by auto
  1262   hence "wq (e#s) c = wq s c" by auto
  1247   with assms have "waiting s t c" using cs_waiting_def waiting_eq by auto 
  1263   with assms have "waiting s t c" using cs_waiting_def waiting_eq by auto 
  1248   from that(1)[OF False this] show ?thesis .
  1264   from that(1)[OF False this] show ?thesis .
  1249 next
  1265 next
  1250   case True
  1266   case True
  1251   from assms[unfolded s_waiting_def True, folded wq_def, unfolded wq_es_cs]
  1267   from assms[unfolded s_waiting_def True, folded wq_def, unfolded wq_es_cs]
  1275              folded wq_def, unfolded wq_es_cs]
  1291              folded wq_def, unfolded wq_es_cs]
  1276   have "t = taker" by (simp add: taker_def) 
  1292   have "t = taker" by (simp add: taker_def) 
  1277   from that(1)[OF True this] show ?thesis .
  1293   from that(1)[OF True this] show ?thesis .
  1278 next
  1294 next
  1279   case False
  1295   case False
  1280   hence "wq (e#s) c = wq s c" using is_v by auto
  1296   hence "wq (e#s) c = wq s c" by auto
  1281   from assms[unfolded s_holding_def, folded wq_def, 
  1297   from assms[unfolded s_holding_def, folded wq_def, 
  1282              unfolded this, unfolded wq_def, folded s_holding_def]
  1298              unfolded this, unfolded wq_def, folded s_holding_def]
  1283   have "holding s t c"  .
  1299   have "holding s t c"  .
  1284   from that(2)[OF False this] show ?thesis .
  1300   from that(2)[OF False this] show ?thesis .
  1285 qed
  1301 qed
  1326   have " wq (e # s) cs = []" .
  1342   have " wq (e # s) cs = []" .
  1327   from assms[unfolded s_holding_def, folded wq_def, unfolded this]
  1343   from assms[unfolded s_holding_def, folded wq_def, unfolded this]
  1328   show ?thesis by auto
  1344   show ?thesis by auto
  1329 qed
  1345 qed
  1330 
  1346 
  1331 lemma no_waiting:
  1347 lemma no_waiter_before: "\<not> waiting s t cs"
       
  1348 proof
       
  1349   assume otherwise: "waiting s t cs"
       
  1350   from this[unfolded s_waiting_def, folded wq_def, 
       
  1351             unfolded wq_s_cs rest_nil]
       
  1352   show False by simp
       
  1353 qed
       
  1354 
       
  1355 lemma no_waiter_after:
  1332   assumes "waiting (e#s) t cs"
  1356   assumes "waiting (e#s) t cs"
  1333   shows False
  1357   shows False
  1334 proof -
  1358 proof -
  1335   from wq_es_cs[unfolded nil_wq']
  1359   from wq_es_cs[unfolded nil_wq']
  1336   have " wq (e # s) cs = []" .
  1360   have " wq (e # s) cs = []" .
  1351 lemma waiting_esE:
  1375 lemma waiting_esE:
  1352   assumes "waiting (e#s) t c" 
  1376   assumes "waiting (e#s) t c" 
  1353   obtains "c \<noteq> cs" "waiting s t c"
  1377   obtains "c \<noteq> cs" "waiting s t c"
  1354 proof(cases "c = cs")
  1378 proof(cases "c = cs")
  1355   case False
  1379   case False
  1356   hence "wq (e#s) c = wq s c" using is_v by auto
  1380   hence "wq (e#s) c = wq s c"  by auto
  1357   with assms have "waiting s t c" using cs_waiting_def waiting_eq by auto 
  1381   with assms have "waiting s t c" using cs_waiting_def waiting_eq by auto 
  1358   from that(1)[OF False this] show ?thesis .
  1382   from that(1)[OF False this] show ?thesis .
  1359 next
  1383 next
  1360   case True
  1384   case True
  1361   from no_waiting[OF assms[unfolded True]]
  1385   from no_waiter_after[OF assms[unfolded True]]
  1362   show ?thesis by auto
  1386   show ?thesis by auto
  1363 qed
  1387 qed
  1364 
  1388 
  1365 lemma holding_esE:
  1389 lemma holding_esE:
  1366   assumes "holding (e#s) t c" 
  1390   assumes "holding (e#s) t c" 
  1369   case True
  1393   case True
  1370   from no_holding[OF assms[unfolded True]] 
  1394   from no_holding[OF assms[unfolded True]] 
  1371   show ?thesis by auto
  1395   show ?thesis by auto
  1372 next
  1396 next
  1373   case False
  1397   case False
  1374   hence "wq (e#s) c = wq s c" using is_v by auto
  1398   hence "wq (e#s) c = wq s c" by auto
  1375   from assms[unfolded s_holding_def, folded wq_def, 
  1399   from assms[unfolded s_holding_def, folded wq_def, 
  1376              unfolded this, unfolded wq_def, folded s_holding_def]
  1400              unfolded this, unfolded wq_def, folded s_holding_def]
  1377   have "holding s t c"  .
  1401   have "holding s t c"  .
  1378   from that[OF False this] show ?thesis .
  1402   from that[OF False this] show ?thesis .
  1379 qed
  1403 qed
  2687     qed
  2711     qed
  2688   qed
  2712   qed
  2689   finally show ?thesis .
  2713   finally show ?thesis .
  2690 qed
  2714 qed
  2691 
  2715 
       
  2716 lemma eq_RAG: 
       
  2717   "RAG (wq s) = RAG s"
       
  2718   by (unfold cs_RAG_def s_RAG_def, auto)
       
  2719 
  2692 lemma dependants_alt_def:
  2720 lemma dependants_alt_def:
  2693   "dependants s th = {th'. (Th th', Th th) \<in> (tRAG s)^+}"
  2721   "dependants s th = {th'. (Th th', Th th) \<in> (tRAG s)^+}"
  2694   by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
  2722   by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
  2695 
  2723 
  2696 lemma dependants_alt_def1:
  2724 lemma dependants_alt_def1: