PrioG.thy
changeset 32 e861aff29655
parent 3 51019d035a79
child 35 92f61f6a0fe7
equal deleted inserted replaced
31:8f026b608378 32:e861aff29655
   373 using assms
   373 using assms
   374 unfolding s_holding_def
   374 unfolding s_holding_def
   375 by auto
   375 by auto
   376 
   376 
   377 
   377 
   378 lemma birthtime_lt: "th \<in> threads s \<Longrightarrow> birthtime th s < length s"
   378 lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s"
   379   apply (induct s, auto)
   379   apply (induct s, auto)
   380   by (case_tac a, auto split:if_splits)
   380   by (case_tac a, auto split:if_splits)
   381 
   381 
   382 lemma birthtime_unique: 
   382 lemma last_set_unique: 
   383   "\<lbrakk>birthtime th1 s = birthtime th2 s; th1 \<in> threads s; th2 \<in> threads s\<rbrakk>
   383   "\<lbrakk>last_set th1 s = last_set th2 s; th1 \<in> threads s; th2 \<in> threads s\<rbrakk>
   384           \<Longrightarrow> th1 = th2"
   384           \<Longrightarrow> th1 = th2"
   385   apply (induct s, auto)
   385   apply (induct s, auto)
   386   by (case_tac a, auto split:if_splits dest:birthtime_lt)
   386   by (case_tac a, auto split:if_splits dest:last_set_lt)
   387 
   387 
   388 lemma preced_unique : 
   388 lemma preced_unique : 
   389   assumes pcd_eq: "preced th1 s = preced th2 s"
   389   assumes pcd_eq: "preced th1 s = preced th2 s"
   390   and th_in1: "th1 \<in> threads s"
   390   and th_in1: "th1 \<in> threads s"
   391   and th_in2: " th2 \<in> threads s"
   391   and th_in2: " th2 \<in> threads s"
   392   shows "th1 = th2"
   392   shows "th1 = th2"
   393 proof -
   393 proof -
   394   from pcd_eq have "birthtime th1 s = birthtime th2 s" by (simp add:preced_def)
   394   from pcd_eq have "last_set th1 s = last_set th2 s" by (simp add:preced_def)
   395   from birthtime_unique [OF this th_in1 th_in2]
   395   from last_set_unique [OF this th_in1 th_in2]
   396   show ?thesis .
   396   show ?thesis .
   397 qed
   397 qed
   398 
   398 
   399 lemma preced_linorder: 
   399 lemma preced_linorder: 
   400   assumes neq_12: "th1 \<noteq> th2"
   400   assumes neq_12: "th1 \<noteq> th2"
  2098   and runing_2: "th2 \<in> runing s"
  2098   and runing_2: "th2 \<in> runing s"
  2099   shows "th1 = th2"
  2099   shows "th1 = th2"
  2100 proof -
  2100 proof -
  2101   from runing_1 and runing_2 have "cp s th1 = cp s th2"
  2101   from runing_1 and runing_2 have "cp s th1 = cp s th2"
  2102     by (unfold runing_def, simp)
  2102     by (unfold runing_def, simp)
  2103   hence eq_max: "Max ((\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1)) =
  2103   hence eq_max: "Max ((\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1)) =
  2104                  Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependents (wq s) th2))"
  2104                  Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependants (wq s) th2))"
  2105     (is "Max (?f ` ?A) = Max (?f ` ?B)")
  2105     (is "Max (?f ` ?A) = Max (?f ` ?B)")
  2106     by (unfold cp_eq_cpreced cpreced_def)
  2106     by (unfold cp_eq_cpreced cpreced_def)
  2107   obtain th1' where th1_in: "th1' \<in> ?A" and eq_f_th1: "?f th1' = Max (?f ` ?A)"
  2107   obtain th1' where th1_in: "th1' \<in> ?A" and eq_f_th1: "?f th1' = Max (?f ` ?A)"
  2108   proof -
  2108   proof -
  2109     have h1: "finite (?f ` ?A)"
  2109     have h1: "finite (?f ` ?A)"
  2110     proof -
  2110     proof -
  2111       have "finite ?A" 
  2111       have "finite ?A" 
  2112       proof -
  2112       proof -
  2113         have "finite (dependents (wq s) th1)"
  2113         have "finite (dependants (wq s) th1)"
  2114         proof-
  2114         proof-
  2115           have "finite {th'. (Th th', Th th1) \<in> (depend (wq s))\<^sup>+}"
  2115           have "finite {th'. (Th th', Th th1) \<in> (depend (wq s))\<^sup>+}"
  2116           proof -
  2116           proof -
  2117             let ?F = "\<lambda> (x, y). the_th x"
  2117             let ?F = "\<lambda> (x, y). the_th x"
  2118             have "{th'. (Th th', Th th1) \<in> (depend (wq s))\<^sup>+} \<subseteq> ?F ` ((depend (wq s))\<^sup>+)"
  2118             have "{th'. (Th th', Th th1) \<in> (depend (wq s))\<^sup>+} \<subseteq> ?F ` ((depend (wq s))\<^sup>+)"
  2126                 by (auto simp: s_depend_def cs_depend_def wq_def)
  2126                 by (auto simp: s_depend_def cs_depend_def wq_def)
  2127               thus ?thesis by auto
  2127               thus ?thesis by auto
  2128             qed
  2128             qed
  2129             ultimately show ?thesis by (auto intro:finite_subset)
  2129             ultimately show ?thesis by (auto intro:finite_subset)
  2130           qed
  2130           qed
  2131           thus ?thesis by (simp add:cs_dependents_def)
  2131           thus ?thesis by (simp add:cs_dependants_def)
  2132         qed
  2132         qed
  2133         thus ?thesis by simp
  2133         thus ?thesis by simp
  2134       qed
  2134       qed
  2135       thus ?thesis by auto
  2135       thus ?thesis by auto
  2136     qed
  2136     qed
  2147   proof -
  2147   proof -
  2148     have h1: "finite (?f ` ?B)"
  2148     have h1: "finite (?f ` ?B)"
  2149     proof -
  2149     proof -
  2150       have "finite ?B" 
  2150       have "finite ?B" 
  2151       proof -
  2151       proof -
  2152         have "finite (dependents (wq s) th2)"
  2152         have "finite (dependants (wq s) th2)"
  2153         proof-
  2153         proof-
  2154           have "finite {th'. (Th th', Th th2) \<in> (depend (wq s))\<^sup>+}"
  2154           have "finite {th'. (Th th', Th th2) \<in> (depend (wq s))\<^sup>+}"
  2155           proof -
  2155           proof -
  2156             let ?F = "\<lambda> (x, y). the_th x"
  2156             let ?F = "\<lambda> (x, y). the_th x"
  2157             have "{th'. (Th th', Th th2) \<in> (depend (wq s))\<^sup>+} \<subseteq> ?F ` ((depend (wq s))\<^sup>+)"
  2157             have "{th'. (Th th', Th th2) \<in> (depend (wq s))\<^sup>+} \<subseteq> ?F ` ((depend (wq s))\<^sup>+)"
  2165                 by (auto simp: s_depend_def cs_depend_def wq_def)
  2165                 by (auto simp: s_depend_def cs_depend_def wq_def)
  2166               thus ?thesis by auto
  2166               thus ?thesis by auto
  2167             qed
  2167             qed
  2168             ultimately show ?thesis by (auto intro:finite_subset)
  2168             ultimately show ?thesis by (auto intro:finite_subset)
  2169           qed
  2169           qed
  2170           thus ?thesis by (simp add:cs_dependents_def)
  2170           thus ?thesis by (simp add:cs_dependants_def)
  2171         qed
  2171         qed
  2172         thus ?thesis by simp
  2172         thus ?thesis by simp
  2173       qed
  2173       qed
  2174       thus ?thesis by auto
  2174       thus ?thesis by auto
  2175     qed
  2175     qed
  2184   qed
  2184   qed
  2185   from eq_f_th1 eq_f_th2 eq_max 
  2185   from eq_f_th1 eq_f_th2 eq_max 
  2186   have eq_preced: "preced th1' s = preced th2' s" by auto
  2186   have eq_preced: "preced th1' s = preced th2' s" by auto
  2187   hence eq_th12: "th1' = th2'"
  2187   hence eq_th12: "th1' = th2'"
  2188   proof (rule preced_unique)
  2188   proof (rule preced_unique)
  2189     from th1_in have "th1' = th1 \<or> (th1' \<in> dependents (wq s) th1)" by simp
  2189     from th1_in have "th1' = th1 \<or> (th1' \<in> dependants (wq s) th1)" by simp
  2190     thus "th1' \<in> threads s"
  2190     thus "th1' \<in> threads s"
  2191     proof
  2191     proof
  2192       assume "th1' \<in> dependents (wq s) th1"
  2192       assume "th1' \<in> dependants (wq s) th1"
  2193       hence "(Th th1') \<in> Domain ((depend s)^+)"
  2193       hence "(Th th1') \<in> Domain ((depend s)^+)"
  2194         apply (unfold cs_dependents_def cs_depend_def s_depend_def)
  2194         apply (unfold cs_dependants_def cs_depend_def s_depend_def)
  2195         by (auto simp:Domain_def)
  2195         by (auto simp:Domain_def)
  2196       hence "(Th th1') \<in> Domain (depend s)" by (simp add:trancl_domain)
  2196       hence "(Th th1') \<in> Domain (depend s)" by (simp add:trancl_domain)
  2197       from dm_depend_threads[OF vt this] show ?thesis .
  2197       from dm_depend_threads[OF vt this] show ?thesis .
  2198     next
  2198     next
  2199       assume "th1' = th1"
  2199       assume "th1' = th1"
  2200       with runing_1 show ?thesis
  2200       with runing_1 show ?thesis
  2201         by (unfold runing_def readys_def, auto)
  2201         by (unfold runing_def readys_def, auto)
  2202     qed
  2202     qed
  2203   next
  2203   next
  2204     from th2_in have "th2' = th2 \<or> (th2' \<in> dependents (wq s) th2)" by simp
  2204     from th2_in have "th2' = th2 \<or> (th2' \<in> dependants (wq s) th2)" by simp
  2205     thus "th2' \<in> threads s"
  2205     thus "th2' \<in> threads s"
  2206     proof
  2206     proof
  2207       assume "th2' \<in> dependents (wq s) th2"
  2207       assume "th2' \<in> dependants (wq s) th2"
  2208       hence "(Th th2') \<in> Domain ((depend s)^+)"
  2208       hence "(Th th2') \<in> Domain ((depend s)^+)"
  2209         apply (unfold cs_dependents_def cs_depend_def s_depend_def)
  2209         apply (unfold cs_dependants_def cs_depend_def s_depend_def)
  2210         by (auto simp:Domain_def)
  2210         by (auto simp:Domain_def)
  2211       hence "(Th th2') \<in> Domain (depend s)" by (simp add:trancl_domain)
  2211       hence "(Th th2') \<in> Domain (depend s)" by (simp add:trancl_domain)
  2212       from dm_depend_threads[OF vt this] show ?thesis .
  2212       from dm_depend_threads[OF vt this] show ?thesis .
  2213     next
  2213     next
  2214       assume "th2' = th2"
  2214       assume "th2' = th2"
  2215       with runing_2 show ?thesis
  2215       with runing_2 show ?thesis
  2216         by (unfold runing_def readys_def, auto)
  2216         by (unfold runing_def readys_def, auto)
  2217     qed
  2217     qed
  2218   qed
  2218   qed
  2219   from th1_in have "th1' = th1 \<or> th1' \<in> dependents (wq s) th1" by simp
  2219   from th1_in have "th1' = th1 \<or> th1' \<in> dependants (wq s) th1" by simp
  2220   thus ?thesis
  2220   thus ?thesis
  2221   proof
  2221   proof
  2222     assume eq_th': "th1' = th1"
  2222     assume eq_th': "th1' = th1"
  2223     from th2_in have "th2' = th2 \<or> th2' \<in> dependents (wq s) th2" by simp
  2223     from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
  2224     thus ?thesis
  2224     thus ?thesis
  2225     proof
  2225     proof
  2226       assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
  2226       assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
  2227     next
  2227     next
  2228       assume "th2' \<in> dependents (wq s) th2"
  2228       assume "th2' \<in> dependants (wq s) th2"
  2229       with eq_th12 eq_th' have "th1 \<in> dependents (wq s) th2" by simp
  2229       with eq_th12 eq_th' have "th1 \<in> dependants (wq s) th2" by simp
  2230       hence "(Th th1, Th th2) \<in> (depend s)^+"
  2230       hence "(Th th1, Th th2) \<in> (depend s)^+"
  2231         by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
  2231         by (unfold cs_dependants_def s_depend_def cs_depend_def, simp)
  2232       hence "Th th1 \<in> Domain ((depend s)^+)" 
  2232       hence "Th th1 \<in> Domain ((depend s)^+)" 
  2233         apply (unfold cs_dependents_def cs_depend_def s_depend_def)
  2233         apply (unfold cs_dependants_def cs_depend_def s_depend_def)
  2234         by (auto simp:Domain_def)
  2234         by (auto simp:Domain_def)
  2235       hence "Th th1 \<in> Domain (depend s)" by (simp add:trancl_domain)
  2235       hence "Th th1 \<in> Domain (depend s)" by (simp add:trancl_domain)
  2236       then obtain n where d: "(Th th1, n) \<in> depend s" by (auto simp:Domain_def)
  2236       then obtain n where d: "(Th th1, n) \<in> depend s" by (auto simp:Domain_def)
  2237       from depend_target_th [OF this]
  2237       from depend_target_th [OF this]
  2238       obtain cs' where "n = Cs cs'" by auto
  2238       obtain cs' where "n = Cs cs'" by auto
  2241         apply (unfold runing_def readys_def s_depend_def)
  2241         apply (unfold runing_def readys_def s_depend_def)
  2242         by (auto simp:eq_waiting)
  2242         by (auto simp:eq_waiting)
  2243       thus ?thesis by simp
  2243       thus ?thesis by simp
  2244     qed
  2244     qed
  2245   next
  2245   next
  2246     assume th1'_in: "th1' \<in> dependents (wq s) th1"
  2246     assume th1'_in: "th1' \<in> dependants (wq s) th1"
  2247     from th2_in have "th2' = th2 \<or> th2' \<in> dependents (wq s) th2" by simp
  2247     from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
  2248     thus ?thesis 
  2248     thus ?thesis 
  2249     proof
  2249     proof
  2250       assume "th2' = th2"
  2250       assume "th2' = th2"
  2251       with th1'_in eq_th12 have "th2 \<in> dependents (wq s) th1" by simp
  2251       with th1'_in eq_th12 have "th2 \<in> dependants (wq s) th1" by simp
  2252       hence "(Th th2, Th th1) \<in> (depend s)^+"
  2252       hence "(Th th2, Th th1) \<in> (depend s)^+"
  2253         by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
  2253         by (unfold cs_dependants_def s_depend_def cs_depend_def, simp)
  2254       hence "Th th2 \<in> Domain ((depend s)^+)" 
  2254       hence "Th th2 \<in> Domain ((depend s)^+)" 
  2255         apply (unfold cs_dependents_def cs_depend_def s_depend_def)
  2255         apply (unfold cs_dependants_def cs_depend_def s_depend_def)
  2256         by (auto simp:Domain_def)
  2256         by (auto simp:Domain_def)
  2257       hence "Th th2 \<in> Domain (depend s)" by (simp add:trancl_domain)
  2257       hence "Th th2 \<in> Domain (depend s)" by (simp add:trancl_domain)
  2258       then obtain n where d: "(Th th2, n) \<in> depend s" by (auto simp:Domain_def)
  2258       then obtain n where d: "(Th th2, n) \<in> depend s" by (auto simp:Domain_def)
  2259       from depend_target_th [OF this]
  2259       from depend_target_th [OF this]
  2260       obtain cs' where "n = Cs cs'" by auto
  2260       obtain cs' where "n = Cs cs'" by auto
  2262       with runing_2 have "False"
  2262       with runing_2 have "False"
  2263         apply (unfold runing_def readys_def s_depend_def)
  2263         apply (unfold runing_def readys_def s_depend_def)
  2264         by (auto simp:eq_waiting)
  2264         by (auto simp:eq_waiting)
  2265       thus ?thesis by simp
  2265       thus ?thesis by simp
  2266     next
  2266     next
  2267       assume "th2' \<in> dependents (wq s) th2"
  2267       assume "th2' \<in> dependants (wq s) th2"
  2268       with eq_th12 have "th1' \<in> dependents (wq s) th2" by simp
  2268       with eq_th12 have "th1' \<in> dependants (wq s) th2" by simp
  2269       hence h1: "(Th th1', Th th2) \<in> (depend s)^+"
  2269       hence h1: "(Th th1', Th th2) \<in> (depend s)^+"
  2270         by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
  2270         by (unfold cs_dependants_def s_depend_def cs_depend_def, simp)
  2271       from th1'_in have h2: "(Th th1', Th th1) \<in> (depend s)^+"
  2271       from th1'_in have h2: "(Th th1', Th th1) \<in> (depend s)^+"
  2272         by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
  2272         by (unfold cs_dependants_def s_depend_def cs_depend_def, simp)
  2273       show ?thesis
  2273       show ?thesis
  2274       proof(rule dchain_unique[OF vt h1 _ h2, symmetric])
  2274       proof(rule dchain_unique[OF vt h1 _ h2, symmetric])
  2275         from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
  2275         from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
  2276         from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) 
  2276         from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) 
  2277       qed
  2277       qed
  2413 
  2413 
  2414 lemma eq_depend: 
  2414 lemma eq_depend: 
  2415   "depend (wq s) = depend s"
  2415   "depend (wq s) = depend s"
  2416 by (unfold cs_depend_def s_depend_def, auto)
  2416 by (unfold cs_depend_def s_depend_def, auto)
  2417 
  2417 
  2418 lemma count_eq_dependents:
  2418 lemma count_eq_dependants:
  2419   assumes vt: "vt s"
  2419   assumes vt: "vt s"
  2420   and eq_pv: "cntP s th = cntV s th"
  2420   and eq_pv: "cntP s th = cntV s th"
  2421   shows "dependents (wq s) th = {}"
  2421   shows "dependants (wq s) th = {}"
  2422 proof -
  2422 proof -
  2423   from cnp_cnv_cncs[OF vt] and eq_pv
  2423   from cnp_cnv_cncs[OF vt] and eq_pv
  2424   have "cntCS s th = 0" 
  2424   have "cntCS s th = 0" 
  2425     by (auto split:if_splits)
  2425     by (auto split:if_splits)
  2426   moreover have "finite {cs. (Cs cs, Th th) \<in> depend s}"
  2426   moreover have "finite {cs. (Cs cs, Th th) \<in> depend s}"
  2427   proof -
  2427   proof -
  2428     from finite_holding[OF vt, of th] show ?thesis
  2428     from finite_holding[OF vt, of th] show ?thesis
  2429       by (simp add:holdents_test)
  2429       by (simp add:holdents_test)
  2430   qed
  2430   qed
  2431   ultimately have h: "{cs. (Cs cs, Th th) \<in> depend s} = {}"
  2431   ultimately have h: "{cs. (Cs cs, Th th) \<in> depend s} = {}"
  2432     by (unfold cntCS_def holdents_test cs_dependents_def, auto)
  2432     by (unfold cntCS_def holdents_test cs_dependants_def, auto)
  2433   show ?thesis
  2433   show ?thesis
  2434   proof(unfold cs_dependents_def)
  2434   proof(unfold cs_dependants_def)
  2435     { assume "{th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<noteq> {}"
  2435     { assume "{th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<noteq> {}"
  2436       then obtain th' where "(Th th', Th th) \<in> (depend (wq s))\<^sup>+" by auto
  2436       then obtain th' where "(Th th', Th th) \<in> (depend (wq s))\<^sup>+" by auto
  2437       hence "False"
  2437       hence "False"
  2438       proof(cases)
  2438       proof(cases)
  2439         assume "(Th th', Th th) \<in> depend (wq s)"
  2439         assume "(Th th', Th th) \<in> depend (wq s)"
  2446       qed
  2446       qed
  2447     } thus "{th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} = {}" by auto
  2447     } thus "{th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} = {}" by auto
  2448   qed
  2448   qed
  2449 qed
  2449 qed
  2450 
  2450 
  2451 lemma dependents_threads:
  2451 lemma dependants_threads:
  2452   fixes s th
  2452   fixes s th
  2453   assumes vt: "vt s"
  2453   assumes vt: "vt s"
  2454   shows "dependents (wq s) th \<subseteq> threads s"
  2454   shows "dependants (wq s) th \<subseteq> threads s"
  2455 proof
  2455 proof
  2456   { fix th th'
  2456   { fix th th'
  2457     assume h: "th \<in> {th'a. (Th th'a, Th th') \<in> (depend (wq s))\<^sup>+}"
  2457     assume h: "th \<in> {th'a. (Th th'a, Th th') \<in> (depend (wq s))\<^sup>+}"
  2458     have "Th th \<in> Domain (depend s)"
  2458     have "Th th \<in> Domain (depend s)"
  2459     proof -
  2459     proof -
  2464     qed
  2464     qed
  2465     from dm_depend_threads[OF vt this]
  2465     from dm_depend_threads[OF vt this]
  2466     have "th \<in> threads s" .
  2466     have "th \<in> threads s" .
  2467   } note hh = this
  2467   } note hh = this
  2468   fix th1 
  2468   fix th1 
  2469   assume "th1 \<in> dependents (wq s) th"
  2469   assume "th1 \<in> dependants (wq s) th"
  2470   hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (depend (wq s))\<^sup>+}"
  2470   hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (depend (wq s))\<^sup>+}"
  2471     by (unfold cs_dependents_def, simp)
  2471     by (unfold cs_dependants_def, simp)
  2472   from hh [OF this] show "th1 \<in> threads s" .
  2472   from hh [OF this] show "th1 \<in> threads s" .
  2473 qed
  2473 qed
  2474 
  2474 
  2475 lemma finite_threads:
  2475 lemma finite_threads:
  2476   assumes vt: "vt s"
  2476   assumes vt: "vt s"
  2493 
  2493 
  2494 lemma cp_le:
  2494 lemma cp_le:
  2495   assumes vt: "vt s"
  2495   assumes vt: "vt s"
  2496   and th_in: "th \<in> threads s"
  2496   and th_in: "th \<in> threads s"
  2497   shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
  2497   shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
  2498 proof(unfold cp_eq_cpreced cpreced_def cs_dependents_def)
  2498 proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def)
  2499   show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+}))
  2499   show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+}))
  2500          \<le> Max ((\<lambda>th. preced th s) ` threads s)"
  2500          \<le> Max ((\<lambda>th. preced th s) ` threads s)"
  2501     (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
  2501     (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
  2502   proof(rule Max_f_mono)
  2502   proof(rule Max_f_mono)
  2503     show "{th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<noteq> {}" by simp
  2503     show "{th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<noteq> {}" by simp
  2516 
  2516 
  2517 lemma le_cp:
  2517 lemma le_cp:
  2518   assumes vt: "vt s"
  2518   assumes vt: "vt s"
  2519   shows "preced th s \<le> cp s th"
  2519   shows "preced th s \<le> cp s th"
  2520 proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
  2520 proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
  2521   show "Prc (original_priority th s) (birthtime th s)
  2521   show "Prc (priority th s) (last_set th s)
  2522     \<le> Max (insert (Prc (original_priority th s) (birthtime th s))
  2522     \<le> Max (insert (Prc (priority th s) (last_set th s))
  2523             ((\<lambda>th. Prc (original_priority th s) (birthtime th s)) ` dependents (wq s) th))"
  2523             ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))"
  2524     (is "?l \<le> Max (insert ?l ?A)")
  2524     (is "?l \<le> Max (insert ?l ?A)")
  2525   proof(cases "?A = {}")
  2525   proof(cases "?A = {}")
  2526     case False
  2526     case False
  2527     have "finite ?A" (is "finite (?f ` ?B)")
  2527     have "finite ?A" (is "finite (?f ` ?B)")
  2528     proof -
  2528     proof -
  2542               by (auto simp: s_depend_def cs_depend_def wq_def)
  2542               by (auto simp: s_depend_def cs_depend_def wq_def)
  2543             thus ?thesis by auto
  2543             thus ?thesis by auto
  2544           qed
  2544           qed
  2545           ultimately show ?thesis by (auto intro:finite_subset)
  2545           ultimately show ?thesis by (auto intro:finite_subset)
  2546         qed
  2546         qed
  2547         thus ?thesis by (simp add:cs_dependents_def)
  2547         thus ?thesis by (simp add:cs_dependants_def)
  2548       qed
  2548       qed
  2549       thus ?thesis by simp
  2549       thus ?thesis by simp
  2550     qed
  2550     qed
  2551     from Max_insert [OF this False, of ?l] show ?thesis by auto
  2551     from Max_insert [OF this False, of ?l] show ?thesis by auto
  2552   next
  2552   next
  2627       assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (depend s)\<^sup>+ "
  2627       assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (depend s)\<^sup>+ "
  2628       then obtain th' where th'_in: "th' \<in> readys s" 
  2628       then obtain th' where th'_in: "th' \<in> readys s" 
  2629         and tm_chain:"(Th tm, Th th') \<in> (depend s)\<^sup>+" by auto
  2629         and tm_chain:"(Th tm, Th th') \<in> (depend s)\<^sup>+" by auto
  2630       have "cp s th' = ?f tm"
  2630       have "cp s th' = ?f tm"
  2631       proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
  2631       proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
  2632         from dependents_threads[OF vt] finite_threads[OF vt]
  2632         from dependants_threads[OF vt] finite_threads[OF vt]
  2633         show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th'))" 
  2633         show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" 
  2634           by (auto intro:finite_subset)
  2634           by (auto intro:finite_subset)
  2635       next
  2635       next
  2636         fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')"
  2636         fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
  2637         from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" .
  2637         from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" .
  2638         moreover have "p \<le> \<dots>"
  2638         moreover have "p \<le> \<dots>"
  2639         proof(rule Max_ge)
  2639         proof(rule Max_ge)
  2640           from finite_threads[OF vt]
  2640           from finite_threads[OF vt]
  2641           show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2641           show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2642         next
  2642         next
  2643           from p_in and th'_in and dependents_threads[OF vt, of th']
  2643           from p_in and th'_in and dependants_threads[OF vt, of th']
  2644           show "p \<in> (\<lambda>th. preced th s) ` threads s"
  2644           show "p \<in> (\<lambda>th. preced th s) ` threads s"
  2645             by (auto simp:readys_def)
  2645             by (auto simp:readys_def)
  2646         qed
  2646         qed
  2647         ultimately show "p \<le> preced tm s" by auto
  2647         ultimately show "p \<le> preced tm s" by auto
  2648       next
  2648       next
  2649         show "preced tm s \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')"
  2649         show "preced tm s \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
  2650         proof -
  2650         proof -
  2651           from tm_chain
  2651           from tm_chain
  2652           have "tm \<in> dependents (wq s) th'"
  2652           have "tm \<in> dependants (wq s) th'"
  2653             by (unfold cs_dependents_def s_depend_def cs_depend_def, auto)
  2653             by (unfold cs_dependants_def s_depend_def cs_depend_def, auto)
  2654           thus ?thesis by auto
  2654           thus ?thesis by auto
  2655         qed
  2655         qed
  2656       qed
  2656       qed
  2657       with tm_max
  2657       with tm_max
  2658       have h: "cp s th' = Max ((\<lambda>th. preced th s) ` threads s)" by simp
  2658       have h: "cp s th' = Max ((\<lambda>th. preced th s) ` threads s)" by simp
  2665         show "q \<le> cp s th'"
  2665         show "q \<le> cp s th'"
  2666           apply (unfold h eq_q)
  2666           apply (unfold h eq_q)
  2667           apply (unfold cp_eq_cpreced cpreced_def)
  2667           apply (unfold cp_eq_cpreced cpreced_def)
  2668           apply (rule Max_mono)
  2668           apply (rule Max_mono)
  2669         proof -
  2669         proof -
  2670           from dependents_threads [OF vt, of th1] th1_in
  2670           from dependants_threads [OF vt, of th1] th1_in
  2671           show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1) \<subseteq> 
  2671           show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> 
  2672                  (\<lambda>th. preced th s) ` threads s"
  2672                  (\<lambda>th. preced th s) ` threads s"
  2673             by (auto simp:readys_def)
  2673             by (auto simp:readys_def)
  2674         next
  2674         next
  2675           show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1) \<noteq> {}" by simp
  2675           show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" by simp
  2676         next
  2676         next
  2677           from finite_threads[OF vt] 
  2677           from finite_threads[OF vt] 
  2678           show " finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2678           show " finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2679         qed
  2679         qed
  2680       next
  2680       next
  2689       show ?thesis
  2689       show ?thesis
  2690       proof(fold tm_max)
  2690       proof(fold tm_max)
  2691         have cp_eq_p: "cp s tm = preced tm s"
  2691         have cp_eq_p: "cp s tm = preced tm s"
  2692         proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
  2692         proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
  2693           fix y 
  2693           fix y 
  2694           assume hy: "y \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependents (wq s) tm)"
  2694           assume hy: "y \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
  2695           show "y \<le> preced tm s"
  2695           show "y \<le> preced tm s"
  2696           proof -
  2696           proof -
  2697             { fix y'
  2697             { fix y'
  2698               assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependents (wq s) tm)"
  2698               assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)"
  2699               have "y' \<le> preced tm s"
  2699               have "y' \<le> preced tm s"
  2700               proof(unfold tm_max, rule Max_ge)
  2700               proof(unfold tm_max, rule Max_ge)
  2701                 from hy' dependents_threads[OF vt, of tm]
  2701                 from hy' dependants_threads[OF vt, of tm]
  2702                 show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
  2702                 show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
  2703               next
  2703               next
  2704                 from finite_threads[OF vt] 
  2704                 from finite_threads[OF vt] 
  2705                 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2705                 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2706               qed
  2706               qed
  2707             } with hy show ?thesis by auto
  2707             } with hy show ?thesis by auto
  2708           qed
  2708           qed
  2709         next
  2709         next
  2710           from dependents_threads[OF vt, of tm] finite_threads[OF vt]
  2710           from dependants_threads[OF vt, of tm] finite_threads[OF vt]
  2711           show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependents (wq s) tm))"
  2711           show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))"
  2712             by (auto intro:finite_subset)
  2712             by (auto intro:finite_subset)
  2713         next
  2713         next
  2714           show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependents (wq s) tm)"
  2714           show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
  2715             by simp
  2715             by simp
  2716         qed 
  2716         qed 
  2717         moreover have "Max (cp s ` readys s) = cp s tm"
  2717         moreover have "Max (cp s ` readys s) = cp s tm"
  2718         proof(rule Max_eqI)
  2718         proof(rule Max_eqI)
  2719           from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
  2719           from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
  2729             apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
  2729             apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
  2730           proof -
  2730           proof -
  2731             from finite_threads[OF vt]
  2731             from finite_threads[OF vt]
  2732             show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2732             show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
  2733           next
  2733           next
  2734             show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1) \<noteq> {}"
  2734             show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}"
  2735               by simp
  2735               by simp
  2736           next
  2736           next
  2737             from dependents_threads[OF vt, of th1] th1_readys
  2737             from dependants_threads[OF vt, of th1] th1_readys
  2738             show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1) 
  2738             show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) 
  2739                     \<subseteq> (\<lambda>th. preced th s) ` threads s"
  2739                     \<subseteq> (\<lambda>th. preced th s) ` threads s"
  2740               by (auto simp:readys_def)
  2740               by (auto simp:readys_def)
  2741           qed
  2741           qed
  2742         qed
  2742         qed
  2743         ultimately show " Max (cp s ` readys s) = preced tm s" by simp
  2743         ultimately show " Max (cp s ` readys s) = preced tm s" by simp