PIPBasics.thy
changeset 113 ce85c3c4e5bf
parent 112 b3795b1f030b
child 114 81c6ede5cd11
equal deleted inserted replaced
112:b3795b1f030b 113:ce85c3c4e5bf
   398   case (V th' pty)
   398   case (V th' pty)
   399   show ?thesis
   399   show ?thesis
   400   by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", 
   400   by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", 
   401         insert assms V, auto simp:cntV_def)
   401         insert assms V, auto simp:cntV_def)
   402 qed (insert assms, auto simp:cntV_def)
   402 qed (insert assms, auto simp:cntV_def)
       
   403 
       
   404 lemma eq_RAG: 
       
   405   "RAG (wq s) = RAG s"
       
   406   by (unfold cs_RAG_def s_RAG_def, auto)
       
   407 
       
   408 text {* 
       
   409   The following three lemmas shows the shape
       
   410   of nodes in @{term tRAG}.
       
   411 *}
       
   412 lemma tRAG_nodeE:
       
   413   assumes "(n1, n2) \<in> tRAG s"
       
   414   obtains th1 th2 where "n1 = Th th1" "n2 = Th th2"
       
   415   using assms
       
   416   by (auto simp: tRAG_def wRAG_def hRAG_def)
       
   417 
       
   418 lemma tRAG_ancestorsE:
       
   419   assumes "x \<in> ancestors (tRAG s) u"
       
   420   obtains th where "x = Th th"
       
   421 proof -
       
   422   from assms have "(u, x) \<in> (tRAG s)^+" 
       
   423       by (unfold ancestors_def, auto)
       
   424   from tranclE[OF this] obtain c where "(c, x) \<in> tRAG s" by auto
       
   425   then obtain th where "x = Th th"
       
   426     by (unfold tRAG_alt_def, auto)
       
   427   from that[OF this] show ?thesis .
       
   428 qed
       
   429 
       
   430 lemma subtree_nodeE:
       
   431   assumes "n \<in> subtree (tRAG s) (Th th)"
       
   432   obtains th1 where "n = Th th1"
       
   433 proof -
       
   434   show ?thesis
       
   435   proof(rule subtreeE[OF assms])
       
   436     assume "n = Th th"
       
   437     from that[OF this] show ?thesis .
       
   438   next
       
   439     assume "Th th \<in> ancestors (tRAG s) n"
       
   440     hence "(n, Th th) \<in> (tRAG s)^+" by (auto simp:ancestors_def)
       
   441     hence "\<exists> th1. n = Th th1"
       
   442     proof(induct)
       
   443       case (base y)
       
   444       from tRAG_nodeE[OF this] show ?case by metis
       
   445     next
       
   446       case (step y z)
       
   447       thus ?case by auto
       
   448     qed
       
   449     with that show ?thesis by auto
       
   450   qed
       
   451 qed
       
   452 
       
   453 text {*
       
   454   The following lemmas relate @{term tRAG} with 
       
   455   @{term RAG} from different perspectives. 
       
   456 *}
       
   457 
       
   458 lemma tRAG_star_RAG: "(tRAG s)^* \<subseteq> (RAG s)^*"
       
   459 proof -
       
   460   have "(wRAG s O hRAG s)^* \<subseteq> (RAG s O RAG s)^*" 
       
   461     by (rule rtrancl_mono, auto simp:RAG_split)
       
   462   also have "... \<subseteq> ((RAG s)^*)^*"
       
   463     by (rule rtrancl_mono, auto)
       
   464   also have "... = (RAG s)^*" by simp
       
   465   finally show ?thesis by (unfold tRAG_def, simp)
       
   466 qed
       
   467 
       
   468 lemma tRAG_subtree_RAG: "subtree (tRAG s) x \<subseteq> subtree (RAG s) x"
       
   469 proof -
       
   470   { fix a
       
   471     assume "a \<in> subtree (tRAG s) x"
       
   472     hence "(a, x) \<in> (tRAG s)^*" by (auto simp:subtree_def)
       
   473     with tRAG_star_RAG
       
   474     have "(a, x) \<in> (RAG s)^*" by auto
       
   475     hence "a \<in> subtree (RAG s) x" by (auto simp:subtree_def)
       
   476   } thus ?thesis by auto
       
   477 qed
       
   478 
       
   479 lemma tRAG_trancl_eq:
       
   480    "{th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
       
   481     {th'. (Th th', Th th)  \<in> (RAG s)^+}"
       
   482    (is "?L = ?R")
       
   483 proof -
       
   484   { fix th'
       
   485     assume "th' \<in> ?L"
       
   486     hence "(Th th', Th th) \<in> (tRAG s)^+" by auto
       
   487     from tranclD[OF this]
       
   488     obtain z where h: "(Th th', z) \<in> tRAG s" "(z, Th th) \<in> (tRAG s)\<^sup>*" by auto
       
   489     from tRAG_subtree_RAG and this(2)
       
   490     have "(z, Th th) \<in> (RAG s)^*" by (meson subsetCE tRAG_star_RAG) 
       
   491     moreover from h(1) have "(Th th', z) \<in> (RAG s)^+" using tRAG_alt_def by auto 
       
   492     ultimately have "th' \<in> ?R"  by auto 
       
   493   } moreover 
       
   494   { fix th'
       
   495     assume "th' \<in> ?R"
       
   496     hence "(Th th', Th th) \<in> (RAG s)^+" by (auto)
       
   497     from plus_rpath[OF this]
       
   498     obtain xs where rp: "rpath (RAG s) (Th th') xs (Th th)" "xs \<noteq> []" by auto
       
   499     hence "(Th th', Th th) \<in> (tRAG s)^+"
       
   500     proof(induct xs arbitrary:th' th rule:length_induct)
       
   501       case (1 xs th' th)
       
   502       then obtain x1 xs1 where Cons1: "xs = x1#xs1" by (cases xs, auto)
       
   503       show ?case
       
   504       proof(cases "xs1")
       
   505         case Nil
       
   506         from 1(2)[unfolded Cons1 Nil]
       
   507         have rp: "rpath (RAG s) (Th th') [x1] (Th th)" .
       
   508         hence "(Th th', x1) \<in> (RAG s)" 
       
   509           by (cases, auto)
       
   510         then obtain cs where "x1 = Cs cs" 
       
   511               by (unfold s_RAG_def, auto)
       
   512         from rpath_nnl_lastE[OF rp[unfolded this]]
       
   513         show ?thesis by auto
       
   514       next
       
   515         case (Cons x2 xs2)
       
   516         from 1(2)[unfolded Cons1[unfolded this]]
       
   517         have rp: "rpath (RAG s) (Th th') (x1 # x2 # xs2) (Th th)" .
       
   518         from rpath_edges_on[OF this]
       
   519         have eds: "edges_on (Th th' # x1 # x2 # xs2) \<subseteq> RAG s" .
       
   520         have "(Th th', x1) \<in> edges_on (Th th' # x1 # x2 # xs2)"
       
   521             by (simp add: edges_on_unfold)
       
   522         with eds have rg1: "(Th th', x1) \<in> RAG s" by auto
       
   523         then obtain cs1 where eq_x1: "x1 = Cs cs1" by (unfold s_RAG_def, auto)
       
   524         have "(x1, x2) \<in> edges_on (Th th' # x1 # x2 # xs2)"
       
   525             by (simp add: edges_on_unfold)
       
   526         from this eds
       
   527         have rg2: "(x1, x2) \<in> RAG s" by auto
       
   528         from this[unfolded eq_x1] 
       
   529         obtain th1 where eq_x2: "x2 = Th th1" by (unfold s_RAG_def, auto)
       
   530         from rg1[unfolded eq_x1] rg2[unfolded eq_x1 eq_x2]
       
   531         have rt1: "(Th th', Th th1) \<in> tRAG s" by (unfold tRAG_alt_def, auto)
       
   532         from rp have "rpath (RAG s) x2 xs2 (Th th)"
       
   533            by  (elim rpath_ConsE, simp)
       
   534         from this[unfolded eq_x2] have rp': "rpath (RAG s) (Th th1) xs2 (Th th)" .
       
   535         show ?thesis
       
   536         proof(cases "xs2 = []")
       
   537           case True
       
   538           from rpath_nilE[OF rp'[unfolded this]]
       
   539           have "th1 = th" by auto
       
   540           from rt1[unfolded this] show ?thesis by auto
       
   541         next
       
   542           case False
       
   543           from 1(1)[rule_format, OF _ rp' this, unfolded Cons1 Cons]
       
   544           have "(Th th1, Th th) \<in> (tRAG s)\<^sup>+" by simp
       
   545           with rt1 show ?thesis by auto
       
   546         qed
       
   547       qed
       
   548     qed
       
   549     hence "th' \<in> ?L" by auto
       
   550   } ultimately show ?thesis by blast
       
   551 qed
       
   552 
       
   553 lemma tRAG_trancl_eq_Th:
       
   554    "{Th th' | th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
       
   555     {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}"
       
   556     using tRAG_trancl_eq by auto
       
   557 
       
   558 lemma tRAG_Field:
       
   559   "Field (tRAG s) \<subseteq> Field (RAG s)"
       
   560   by (unfold tRAG_alt_def Field_def, auto)
       
   561 
       
   562 lemma tRAG_mono:
       
   563   assumes "RAG s' \<subseteq> RAG s"
       
   564   shows "tRAG s' \<subseteq> tRAG s"
       
   565   using assms 
       
   566   by (unfold tRAG_alt_def, auto)
       
   567 
       
   568 lemma tRAG_subtree_eq: 
       
   569    "(subtree (tRAG s) (Th th)) = {Th th' | th'. Th th'  \<in> (subtree (RAG s) (Th th))}"
       
   570    (is "?L = ?R")
       
   571 proof -
       
   572   { fix n 
       
   573     assume h: "n \<in> ?L"
       
   574     hence "n \<in> ?R"
       
   575     by (smt mem_Collect_eq subsetCE subtree_def subtree_nodeE tRAG_subtree_RAG) 
       
   576   } moreover {
       
   577     fix n
       
   578     assume "n \<in> ?R"
       
   579     then obtain th' where h: "n = Th th'" "(Th th', Th th) \<in> (RAG s)^*"
       
   580       by (auto simp:subtree_def)
       
   581     from rtranclD[OF this(2)]
       
   582     have "n \<in> ?L"
       
   583     proof
       
   584       assume "Th th' \<noteq> Th th \<and> (Th th', Th th) \<in> (RAG s)\<^sup>+"
       
   585       with h have "n \<in> {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}" by auto
       
   586       thus ?thesis using subtree_def tRAG_trancl_eq by fastforce
       
   587     qed (insert h, auto simp:subtree_def)
       
   588   } ultimately show ?thesis by auto
       
   589 qed
       
   590 
       
   591 lemma threads_set_eq: 
       
   592    "the_thread ` (subtree (tRAG s) (Th th)) = 
       
   593                   {th'. Th th' \<in> (subtree (RAG s) (Th th))}" (is "?L = ?R")
       
   594    by (auto intro:rev_image_eqI simp:tRAG_subtree_eq)
       
   595 
       
   596 lemma RAG_tRAG_transfer:
       
   597   assumes  "RAG s' = RAG s \<union> {(Th th, Cs cs)}"
       
   598   and "(Cs cs, Th th'') \<in> RAG s"
       
   599   shows "tRAG s' = tRAG s \<union> {(Th th, Th th'')}" (is "?L = ?R")
       
   600 proof -
       
   601   { fix n1 n2
       
   602     assume "(n1, n2) \<in> ?L"
       
   603     from this[unfolded tRAG_alt_def]
       
   604     obtain th1 th2 cs' where 
       
   605       h: "n1 = Th th1" "n2 = Th th2" 
       
   606          "(Th th1, Cs cs') \<in> RAG s'"
       
   607          "(Cs cs', Th th2) \<in> RAG s'" by auto
       
   608     from h(4) and assms(1) have cs_in: "(Cs cs', Th th2) \<in> RAG s" by auto
       
   609     from h(3) and assms(1) 
       
   610     have "(Th th1, Cs cs') = (Th th, Cs cs) \<or> 
       
   611           (Th th1, Cs cs') \<in> RAG s" by auto
       
   612     hence "(n1, n2) \<in> ?R"
       
   613     proof
       
   614       assume h1: "(Th th1, Cs cs') = (Th th, Cs cs)"
       
   615       with assms(1) have "(Th th1, Cs cs) \<in> RAG s'" by auto
       
   616       moreover have "th2 = th''"
       
   617       proof -
       
   618         from h1 have "cs' = cs" by simp
       
   619         from assms(2) cs_in[unfolded this]
       
   620         have "holding s th'' cs" "holding s th2 cs"
       
   621           by (unfold s_RAG_def, fold holding_eq, auto)
       
   622         from held_unique[OF this]
       
   623         show ?thesis by simp 
       
   624       qed
       
   625       ultimately show ?thesis using h(1,2) h1 by auto
       
   626     next
       
   627       assume "(Th th1, Cs cs') \<in> RAG s"
       
   628       with cs_in have "(Th th1, Th th2) \<in> tRAG s"
       
   629         by (unfold tRAG_alt_def, auto)
       
   630       from this[folded h(1, 2)] show ?thesis by auto
       
   631     qed
       
   632   } moreover {
       
   633     fix n1 n2
       
   634     assume "(n1, n2) \<in> ?R"
       
   635     hence "(n1, n2) \<in>tRAG s \<or> (n1, n2) = (Th th, Th th'')" by auto
       
   636     hence "(n1, n2) \<in> ?L" 
       
   637     proof
       
   638       assume "(n1, n2) \<in> tRAG s"
       
   639       moreover have "... \<subseteq> ?L"
       
   640       proof(rule tRAG_mono)
       
   641         show "RAG s \<subseteq> RAG s'" by (unfold assms(1), auto)
       
   642       qed
       
   643       ultimately show ?thesis by auto
       
   644     next
       
   645       assume eq_n: "(n1, n2) = (Th th, Th th'')"
       
   646       from assms(1, 2) have "(Cs cs, Th th'') \<in> RAG s'" by auto
       
   647       moreover have "(Th th, Cs cs) \<in> RAG s'" using assms(1) by auto
       
   648       ultimately show ?thesis 
       
   649         by (unfold eq_n tRAG_alt_def, auto)
       
   650     qed
       
   651   } ultimately show ?thesis by auto
       
   652 qed
       
   653 
       
   654 text {* 
       
   655   The following lemmas gives an alternative definition @{term dependants}
       
   656   in terms of @{term tRAG}.
       
   657 *}
       
   658 
       
   659 lemma dependants_alt_def:
       
   660   "dependants s th = {th'. (Th th', Th th) \<in> (tRAG s)^+}"
       
   661   by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
       
   662 
       
   663 text {* 
       
   664   The following lemmas gives another alternative definition @{term dependants}
       
   665   in terms of @{term RAG}.
       
   666 *}
       
   667 
       
   668 lemma dependants_alt_def1:
       
   669   "dependants (s::state) th = {th'. (Th th', Th th) \<in> (RAG s)^+}"
       
   670   using dependants_alt_def tRAG_trancl_eq by auto
   403 
   671 
   404 section {* Locales used to investigate the execution of PIP *}
   672 section {* Locales used to investigate the execution of PIP *}
   405 
   673 
   406 text {* 
   674 text {* 
   407   The following locale @{text valid_trace} is used to constrain the 
   675   The following locale @{text valid_trace} is used to constrain the 
  1177 lemma RAG_threads:
  1445 lemma RAG_threads:
  1178   assumes "(Th th) \<in> Field (RAG s)"
  1446   assumes "(Th th) \<in> Field (RAG s)"
  1179   shows "th \<in> threads s"
  1447   shows "th \<in> threads s"
  1180   using assms
  1448   using assms
  1181   by (metis Field_def UnE dm_RAG_threads rg_RAG_threads)
  1449   by (metis Field_def UnE dm_RAG_threads rg_RAG_threads)
       
  1450 
       
  1451 text {*
       
  1452   As a corollary, this lemma shows that @{term tRAG}
       
  1453   is also covered by the @{term threads}-set.
       
  1454 *}
       
  1455 lemma subtree_tRAG_thread:
       
  1456   assumes "th \<in> threads s"
       
  1457   shows "subtree (tRAG s) (Th th) \<subseteq> Th ` threads s" (is "?L \<subseteq> ?R")
       
  1458 proof -
       
  1459   have "?L = {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
       
  1460     by (unfold tRAG_subtree_eq, simp)
       
  1461   also have "... \<subseteq> ?R"
       
  1462   proof
       
  1463     fix x
       
  1464     assume "x \<in> {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
       
  1465     then obtain th' where h: "x = Th th'" "Th th' \<in> subtree (RAG s) (Th th)" by auto
       
  1466     from this(2)
       
  1467     show "x \<in> ?R"
       
  1468     proof(cases rule:subtreeE)
       
  1469       case 1
       
  1470       thus ?thesis by (simp add: assms h(1)) 
       
  1471     next
       
  1472       case 2
       
  1473       thus ?thesis by (metis ancestors_Field dm_RAG_threads h(1) image_eqI) 
       
  1474     qed
       
  1475   qed
       
  1476   finally show ?thesis .
       
  1477 qed
  1182 
  1478 
  1183 end
  1479 end
  1184 
  1480 
  1185 section {* The change of @{term RAG} *}
  1481 section {* The change of @{term RAG} *}
  1186 
  1482 
  2155   and "waiting (e#s) th' cs'"
  2451   and "waiting (e#s) th' cs'"
  2156   shows "e = P th' cs'"
  2452   shows "e = P th' cs'"
  2157 proof -
  2453 proof -
  2158   from assms(2)
  2454   from assms(2)
  2159   show ?thesis
  2455   show ?thesis
  2160   by (cases rule:waiting_esE, insert assms, auto) (* ccc *)
  2456   by (cases rule:waiting_esE, insert assms, auto)
  2161 qed
  2457 qed
  2162 
  2458 
  2163 end
  2459 end
  2164 
  2460 
  2165 context valid_trace_v_e
  2461 context valid_trace_v_e
  2517 
  2813 
  2518 end
  2814 end
  2519 
  2815 
  2520 section {* RAG is well-founded *}
  2816 section {* RAG is well-founded *}
  2521 
  2817 
       
  2818 text {*
       
  2819   In this section, it is proved that both @{term RAG} and 
       
  2820   its converse @{term "(RAG s)^-1"} are well-founded.
       
  2821   The proof is very simple with the help of
       
  2822   already proved fact that @{term RAG} is finite.
       
  2823 *}
       
  2824 
  2522 context valid_trace
  2825 context valid_trace
  2523 begin
  2826 begin
  2524 
  2827 
  2525 lemma wf_RAG: "wf (RAG s)"
  2828 lemma wf_RAG: "wf (RAG s)"
  2526 proof(rule finite_acyclic_wf)
  2829 proof(rule finite_acyclic_wf)
  2539   show "acyclic (RAG s)" .
  2842   show "acyclic (RAG s)" .
  2540 qed
  2843 qed
  2541 
  2844 
  2542 end
  2845 end
  2543 
  2846 
  2544 section {* RAG forms a forest (or tree) *}
  2847 section {* RAG forms a finite-branching forest (or tree) *}
       
  2848 
       
  2849 text {*
       
  2850   With all the well-formedness proofs about @{term RAG} in place, 
       
  2851   it is easy to show.
       
  2852 *}
  2545 
  2853 
  2546 context valid_trace
  2854 context valid_trace
  2547 begin
  2855 begin
  2548 
  2856 
  2549 lemma rtree_RAG: "rtree (RAG s)"
  2857 lemma rtree_RAG: "rtree (RAG s)"
  2567     qed
  2875     qed
  2568   qed
  2876   qed
  2569 qed
  2877 qed
  2570 
  2878 
  2571 
  2879 
  2572 section {* Derived properties for parts of RAG *}
  2880 section {* Derived properties for sub-graphs of RAG *}
  2573 
  2881 
  2574 context valid_trace
  2882 context valid_trace
  2575 begin
  2883 begin
  2576 
  2884 
  2577 lemma acyclic_tRAG: "acyclic (tRAG s)"
  2885 lemma acyclic_tRAG: "acyclic (tRAG s)"
  2594 lemma sgv_tRAG: "single_valued (tRAG s)"
  2902 lemma sgv_tRAG: "single_valued (tRAG s)"
  2595   by (unfold tRAG_def, rule single_valued_relcomp, 
  2903   by (unfold tRAG_def, rule single_valued_relcomp, 
  2596               insert sgv_wRAG sgv_hRAG, auto)
  2904               insert sgv_wRAG sgv_hRAG, auto)
  2597 
  2905 
  2598 end
  2906 end
       
  2907 
       
  2908 text {*
       
  2909   It can be shown that @{term tRAG} is also a 
       
  2910   finite-branch relational tree (or forest):  
       
  2911 *}
  2599 
  2912 
  2600 sublocale valid_trace < rtree_s: rtree "tRAG s"
  2913 sublocale valid_trace < rtree_s: rtree "tRAG s"
  2601 proof(unfold_locales)
  2914 proof(unfold_locales)
  2602   from sgv_tRAG show "single_valued (tRAG s)" .
  2915   from sgv_tRAG show "single_valued (tRAG s)" .
  2603 next
  2916 next
  2633     ultimately show ?thesis
  2946     ultimately show ?thesis
  2634       by (unfold fsubtree_def fsubtree_axioms_def,auto)
  2947       by (unfold fsubtree_def fsubtree_axioms_def,auto)
  2635   qed
  2948   qed
  2636   from this[folded tRAG_def] show "fsubtree (tRAG s)" .
  2949   from this[folded tRAG_def] show "fsubtree (tRAG s)" .
  2637 qed
  2950 qed
  2638 
       
  2639 lemma tRAG_nodeE:
       
  2640   assumes "(n1, n2) \<in> tRAG s"
       
  2641   obtains th1 th2 where "n1 = Th th1" "n2 = Th th2"
       
  2642   using assms
       
  2643   by (auto simp: tRAG_def wRAG_def hRAG_def)
       
  2644 
       
  2645 lemma tRAG_ancestorsE:
       
  2646   assumes "x \<in> ancestors (tRAG s) u"
       
  2647   obtains th where "x = Th th"
       
  2648 proof -
       
  2649   from assms have "(u, x) \<in> (tRAG s)^+" 
       
  2650       by (unfold ancestors_def, auto)
       
  2651   from tranclE[OF this] obtain c where "(c, x) \<in> tRAG s" by auto
       
  2652   then obtain th where "x = Th th"
       
  2653     by (unfold tRAG_alt_def, auto)
       
  2654   from that[OF this] show ?thesis .
       
  2655 qed
       
  2656                    
       
  2657 lemma subtree_nodeE:
       
  2658   assumes "n \<in> subtree (tRAG s) (Th th)"
       
  2659   obtains th1 where "n = Th th1"
       
  2660 proof -
       
  2661   show ?thesis
       
  2662   proof(rule subtreeE[OF assms])
       
  2663     assume "n = Th th"
       
  2664     from that[OF this] show ?thesis .
       
  2665   next
       
  2666     assume "Th th \<in> ancestors (tRAG s) n"
       
  2667     hence "(n, Th th) \<in> (tRAG s)^+" by (auto simp:ancestors_def)
       
  2668     hence "\<exists> th1. n = Th th1"
       
  2669     proof(induct)
       
  2670       case (base y)
       
  2671       from tRAG_nodeE[OF this] show ?case by metis
       
  2672     next
       
  2673       case (step y z)
       
  2674       thus ?case by auto
       
  2675     qed
       
  2676     with that show ?thesis by auto
       
  2677   qed
       
  2678 qed
       
  2679 
       
  2680 lemma tRAG_star_RAG: "(tRAG s)^* \<subseteq> (RAG s)^*"
       
  2681 proof -
       
  2682   have "(wRAG s O hRAG s)^* \<subseteq> (RAG s O RAG s)^*" 
       
  2683     by (rule rtrancl_mono, auto simp:RAG_split)
       
  2684   also have "... \<subseteq> ((RAG s)^*)^*"
       
  2685     by (rule rtrancl_mono, auto)
       
  2686   also have "... = (RAG s)^*" by simp
       
  2687   finally show ?thesis by (unfold tRAG_def, simp)
       
  2688 qed
       
  2689 
       
  2690 lemma tRAG_subtree_RAG: "subtree (tRAG s) x \<subseteq> subtree (RAG s) x"
       
  2691 proof -
       
  2692   { fix a
       
  2693     assume "a \<in> subtree (tRAG s) x"
       
  2694     hence "(a, x) \<in> (tRAG s)^*" by (auto simp:subtree_def)
       
  2695     with tRAG_star_RAG
       
  2696     have "(a, x) \<in> (RAG s)^*" by auto
       
  2697     hence "a \<in> subtree (RAG s) x" by (auto simp:subtree_def)
       
  2698   } thus ?thesis by auto
       
  2699 qed
       
  2700 
       
  2701 lemma tRAG_trancl_eq:
       
  2702    "{th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
       
  2703     {th'. (Th th', Th th)  \<in> (RAG s)^+}"
       
  2704    (is "?L = ?R")
       
  2705 proof -
       
  2706   { fix th'
       
  2707     assume "th' \<in> ?L"
       
  2708     hence "(Th th', Th th) \<in> (tRAG s)^+" by auto
       
  2709     from tranclD[OF this]
       
  2710     obtain z where h: "(Th th', z) \<in> tRAG s" "(z, Th th) \<in> (tRAG s)\<^sup>*" by auto
       
  2711     from tRAG_subtree_RAG and this(2)
       
  2712     have "(z, Th th) \<in> (RAG s)^*" by (meson subsetCE tRAG_star_RAG) 
       
  2713     moreover from h(1) have "(Th th', z) \<in> (RAG s)^+" using tRAG_alt_def by auto 
       
  2714     ultimately have "th' \<in> ?R"  by auto 
       
  2715   } moreover 
       
  2716   { fix th'
       
  2717     assume "th' \<in> ?R"
       
  2718     hence "(Th th', Th th) \<in> (RAG s)^+" by (auto)
       
  2719     from plus_rpath[OF this]
       
  2720     obtain xs where rp: "rpath (RAG s) (Th th') xs (Th th)" "xs \<noteq> []" by auto
       
  2721     hence "(Th th', Th th) \<in> (tRAG s)^+"
       
  2722     proof(induct xs arbitrary:th' th rule:length_induct)
       
  2723       case (1 xs th' th)
       
  2724       then obtain x1 xs1 where Cons1: "xs = x1#xs1" by (cases xs, auto)
       
  2725       show ?case
       
  2726       proof(cases "xs1")
       
  2727         case Nil
       
  2728         from 1(2)[unfolded Cons1 Nil]
       
  2729         have rp: "rpath (RAG s) (Th th') [x1] (Th th)" .
       
  2730         hence "(Th th', x1) \<in> (RAG s)" 
       
  2731           by (cases, auto)
       
  2732         then obtain cs where "x1 = Cs cs" 
       
  2733               by (unfold s_RAG_def, auto)
       
  2734         from rpath_nnl_lastE[OF rp[unfolded this]]
       
  2735         show ?thesis by auto
       
  2736       next
       
  2737         case (Cons x2 xs2)
       
  2738         from 1(2)[unfolded Cons1[unfolded this]]
       
  2739         have rp: "rpath (RAG s) (Th th') (x1 # x2 # xs2) (Th th)" .
       
  2740         from rpath_edges_on[OF this]
       
  2741         have eds: "edges_on (Th th' # x1 # x2 # xs2) \<subseteq> RAG s" .
       
  2742         have "(Th th', x1) \<in> edges_on (Th th' # x1 # x2 # xs2)"
       
  2743             by (simp add: edges_on_unfold)
       
  2744         with eds have rg1: "(Th th', x1) \<in> RAG s" by auto
       
  2745         then obtain cs1 where eq_x1: "x1 = Cs cs1" by (unfold s_RAG_def, auto)
       
  2746         have "(x1, x2) \<in> edges_on (Th th' # x1 # x2 # xs2)"
       
  2747             by (simp add: edges_on_unfold)
       
  2748         from this eds
       
  2749         have rg2: "(x1, x2) \<in> RAG s" by auto
       
  2750         from this[unfolded eq_x1] 
       
  2751         obtain th1 where eq_x2: "x2 = Th th1" by (unfold s_RAG_def, auto)
       
  2752         from rg1[unfolded eq_x1] rg2[unfolded eq_x1 eq_x2]
       
  2753         have rt1: "(Th th', Th th1) \<in> tRAG s" by (unfold tRAG_alt_def, auto)
       
  2754         from rp have "rpath (RAG s) x2 xs2 (Th th)"
       
  2755            by  (elim rpath_ConsE, simp)
       
  2756         from this[unfolded eq_x2] have rp': "rpath (RAG s) (Th th1) xs2 (Th th)" .
       
  2757         show ?thesis
       
  2758         proof(cases "xs2 = []")
       
  2759           case True
       
  2760           from rpath_nilE[OF rp'[unfolded this]]
       
  2761           have "th1 = th" by auto
       
  2762           from rt1[unfolded this] show ?thesis by auto
       
  2763         next
       
  2764           case False
       
  2765           from 1(1)[rule_format, OF _ rp' this, unfolded Cons1 Cons]
       
  2766           have "(Th th1, Th th) \<in> (tRAG s)\<^sup>+" by simp
       
  2767           with rt1 show ?thesis by auto
       
  2768         qed
       
  2769       qed
       
  2770     qed
       
  2771     hence "th' \<in> ?L" by auto
       
  2772   } ultimately show ?thesis by blast
       
  2773 qed
       
  2774 
       
  2775 lemma tRAG_trancl_eq_Th:
       
  2776    "{Th th' | th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
       
  2777     {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}"
       
  2778     using tRAG_trancl_eq by auto
       
  2779 
       
  2780 
       
  2781 lemma tRAG_Field:
       
  2782   "Field (tRAG s) \<subseteq> Field (RAG s)"
       
  2783   by (unfold tRAG_alt_def Field_def, auto)
       
  2784 
       
  2785 lemma tRAG_mono:
       
  2786   assumes "RAG s' \<subseteq> RAG s"
       
  2787   shows "tRAG s' \<subseteq> tRAG s"
       
  2788   using assms 
       
  2789   by (unfold tRAG_alt_def, auto)
       
  2790 
       
  2791 lemma tRAG_subtree_eq: 
       
  2792    "(subtree (tRAG s) (Th th)) = {Th th' | th'. Th th'  \<in> (subtree (RAG s) (Th th))}"
       
  2793    (is "?L = ?R")
       
  2794 proof -
       
  2795   { fix n 
       
  2796     assume h: "n \<in> ?L"
       
  2797     hence "n \<in> ?R"
       
  2798     by (smt mem_Collect_eq subsetCE subtree_def subtree_nodeE tRAG_subtree_RAG) 
       
  2799   } moreover {
       
  2800     fix n
       
  2801     assume "n \<in> ?R"
       
  2802     then obtain th' where h: "n = Th th'" "(Th th', Th th) \<in> (RAG s)^*"
       
  2803       by (auto simp:subtree_def)
       
  2804     from rtranclD[OF this(2)]
       
  2805     have "n \<in> ?L"
       
  2806     proof
       
  2807       assume "Th th' \<noteq> Th th \<and> (Th th', Th th) \<in> (RAG s)\<^sup>+"
       
  2808       with h have "n \<in> {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}" by auto
       
  2809       thus ?thesis using subtree_def tRAG_trancl_eq by fastforce
       
  2810     qed (insert h, auto simp:subtree_def)
       
  2811   } ultimately show ?thesis by auto
       
  2812 qed
       
  2813 
       
  2814 lemma threads_set_eq: 
       
  2815    "the_thread ` (subtree (tRAG s) (Th th)) = 
       
  2816                   {th'. Th th' \<in> (subtree (RAG s) (Th th))}" (is "?L = ?R")
       
  2817    by (auto intro:rev_image_eqI simp:tRAG_subtree_eq)
       
  2818 
       
  2819 context valid_trace
       
  2820 begin
       
  2821 
       
  2822 lemma RAG_tRAG_transfer:
       
  2823   assumes  "RAG s' = RAG s \<union> {(Th th, Cs cs)}"
       
  2824   and "(Cs cs, Th th'') \<in> RAG s"
       
  2825   shows "tRAG s' = tRAG s \<union> {(Th th, Th th'')}" (is "?L = ?R")
       
  2826 proof -
       
  2827   { fix n1 n2
       
  2828     assume "(n1, n2) \<in> ?L"
       
  2829     from this[unfolded tRAG_alt_def]
       
  2830     obtain th1 th2 cs' where 
       
  2831       h: "n1 = Th th1" "n2 = Th th2" 
       
  2832          "(Th th1, Cs cs') \<in> RAG s'"
       
  2833          "(Cs cs', Th th2) \<in> RAG s'" by auto
       
  2834     from h(4) and assms(1) have cs_in: "(Cs cs', Th th2) \<in> RAG s" by auto
       
  2835     from h(3) and assms(1) 
       
  2836     have "(Th th1, Cs cs') = (Th th, Cs cs) \<or> 
       
  2837           (Th th1, Cs cs') \<in> RAG s" by auto
       
  2838     hence "(n1, n2) \<in> ?R"
       
  2839     proof
       
  2840       assume h1: "(Th th1, Cs cs') = (Th th, Cs cs)"
       
  2841       hence eq_th1: "th1 = th" by simp
       
  2842       moreover have "th2 = th''"
       
  2843       proof -
       
  2844         from h1 have "cs' = cs" by simp
       
  2845         from assms(2) cs_in[unfolded this]
       
  2846         show ?thesis using unique_RAG by auto 
       
  2847       qed
       
  2848       ultimately show ?thesis using h(1,2) by auto
       
  2849     next
       
  2850       assume "(Th th1, Cs cs') \<in> RAG s"
       
  2851       with cs_in have "(Th th1, Th th2) \<in> tRAG s"
       
  2852         by (unfold tRAG_alt_def, auto)
       
  2853       from this[folded h(1, 2)] show ?thesis by auto
       
  2854     qed
       
  2855   } moreover {
       
  2856     fix n1 n2
       
  2857     assume "(n1, n2) \<in> ?R"
       
  2858     hence "(n1, n2) \<in>tRAG s \<or> (n1, n2) = (Th th, Th th'')" by auto
       
  2859     hence "(n1, n2) \<in> ?L" 
       
  2860     proof
       
  2861       assume "(n1, n2) \<in> tRAG s"
       
  2862       moreover have "... \<subseteq> ?L"
       
  2863       proof(rule tRAG_mono)
       
  2864         show "RAG s \<subseteq> RAG s'" by (unfold assms(1), auto)
       
  2865       qed
       
  2866       ultimately show ?thesis by auto
       
  2867     next
       
  2868       assume eq_n: "(n1, n2) = (Th th, Th th'')"
       
  2869       from assms(1, 2) have "(Cs cs, Th th'') \<in> RAG s'" by auto
       
  2870       moreover have "(Th th, Cs cs) \<in> RAG s'" using assms(1) by auto
       
  2871       ultimately show ?thesis 
       
  2872         by (unfold eq_n tRAG_alt_def, auto)
       
  2873     qed
       
  2874   } ultimately show ?thesis by auto
       
  2875 qed
       
  2876 
       
  2877 lemma subtree_tRAG_thread:
       
  2878   assumes "th \<in> threads s"
       
  2879   shows "subtree (tRAG s) (Th th) \<subseteq> Th ` threads s" (is "?L \<subseteq> ?R")
       
  2880 proof -
       
  2881   have "?L = {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
       
  2882     by (unfold tRAG_subtree_eq, simp)
       
  2883   also have "... \<subseteq> ?R"
       
  2884   proof
       
  2885     fix x
       
  2886     assume "x \<in> {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
       
  2887     then obtain th' where h: "x = Th th'" "Th th' \<in> subtree (RAG s) (Th th)" by auto
       
  2888     from this(2)
       
  2889     show "x \<in> ?R"
       
  2890     proof(cases rule:subtreeE)
       
  2891       case 1
       
  2892       thus ?thesis by (simp add: assms h(1)) 
       
  2893     next
       
  2894       case 2
       
  2895       thus ?thesis by (metis ancestors_Field dm_RAG_threads h(1) image_eqI) 
       
  2896     qed
       
  2897   qed
       
  2898   finally show ?thesis .
       
  2899 qed
       
  2900 
       
  2901 lemma eq_RAG: 
       
  2902   "RAG (wq s) = RAG s"
       
  2903   by (unfold cs_RAG_def s_RAG_def, auto)
       
  2904 
       
  2905 lemma dependants_alt_def:
       
  2906   "dependants s th = {th'. (Th th', Th th) \<in> (tRAG s)^+}"
       
  2907   by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
       
  2908 
       
  2909 lemma dependants_alt_def1:
       
  2910   "dependants (s::state) th = {th'. (Th th', Th th) \<in> (RAG s)^+}"
       
  2911   using dependants_alt_def tRAG_trancl_eq by auto
       
  2912 
       
  2913 end
       
  2914 
  2951 
  2915 section {* Chain to readys *}
  2952 section {* Chain to readys *}
  2916 
  2953 
  2917 context valid_trace
  2954 context valid_trace
  2918 begin
  2955 begin
  2959     using h_b(1)[unfolded trancl_converse] eq_b by auto
  2996     using h_b(1)[unfolded trancl_converse] eq_b by auto
  2960   ultimately show ?thesis using that by metis
  2997   ultimately show ?thesis using that by metis
  2961 qed
  2998 qed
  2962 
  2999 
  2963 text {* \noindent
  3000 text {* \noindent
  2964   The following is just an instance of @{text "chain_building"}.
  3001   The following lemma is proved easily by instantiating @{thm "chain_building"}.
  2965 *}                    
  3002 *}                    
  2966 lemma th_chain_to_ready:
  3003 lemma th_chain_to_ready:
  2967   assumes th_in: "th \<in> threads s"
  3004   assumes th_in: "th \<in> threads s"
  2968   shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)"
  3005   shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)"
  2969 proof(cases "th \<in> readys s")
  3006 proof(cases "th \<in> readys s")