PIPBasics.thy
changeset 109 4e59c0ce1511
parent 108 b769f43deb30
child 110 4782d82c3ae9
equal deleted inserted replaced
108:b769f43deb30 109:4e59c0ce1511
   320   by auto
   320   by auto
   321 
   321 
   322 text {*
   322 text {*
   323   The following lemmas are the simplification rules 
   323   The following lemmas are the simplification rules 
   324   for @{term count}, @{term cntP}, @{term cntV}.
   324   for @{term count}, @{term cntP}, @{term cntV}.
   325   It is a major technical in this development to use 
   325   It is part of the scheme to use the counting 
   326   the counter of @{term "P"} and @{term "V"} (* ccc *)
   326   of @{term "P"} and @{term "V"} operations to reason about
       
   327   the number of resources occupied by one thread.
   327 *}
   328 *}
   328 
   329 
   329 lemma count_rec1 [simp]: 
   330 lemma count_rec1 [simp]: 
   330   assumes "Q e"
   331   assumes "Q e"
   331   shows "count Q (e#es) = Suc (count Q es)"
   332   shows "count Q (e#es) = Suc (count Q es)"
   372   assumes "\<not> isV e"
   373   assumes "\<not> isV e"
   373   shows "cntV (e#s) th' = cntV s th'"
   374   shows "cntV (e#s) th' = cntV s th'"
   374   using assms
   375   using assms
   375   by (unfold cntV_def, cases e, simp+)
   376   by (unfold cntV_def, cases e, simp+)
   376 
   377 
       
   378 text {*
       
   379   The following two lemmas show that only @{term P}
       
   380   and @{term V} operation can change the value 
       
   381   of @{term cntP} and @{term cntV}, which is true
       
   382   obviously.
       
   383 *}
   377 lemma cntP_diff_inv:
   384 lemma cntP_diff_inv:
   378   assumes "cntP (e#s) th \<noteq> cntP s th"
   385   assumes "cntP (e#s) th \<noteq> cntP s th"
   379   shows "isP e \<and> actor e = th"
   386   shows "isP e \<and> actor e = th"
   380 proof(cases e)
   387 proof(cases e)
   381   case (P th' pty)
   388   case (P th' pty)
   391   case (V th' pty)
   398   case (V th' pty)
   392   show ?thesis
   399   show ?thesis
   393   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)", 
   394         insert assms V, auto simp:cntV_def)
   401         insert assms V, auto simp:cntV_def)
   395 qed (insert assms, auto simp:cntV_def)
   402 qed (insert assms, auto simp:cntV_def)
   396 
       
   397 (* ccc *)
       
   398 
   403 
   399 section {* Locales used to investigate the execution of PIP *}
   404 section {* Locales used to investigate the execution of PIP *}
   400 
   405 
   401 text {* 
   406 text {* 
   402   The following locale @{text valid_trace} is used to constrain the 
   407   The following locale @{text valid_trace} is used to constrain the 
   687 
   692 
   688 sublocale valid_moment_e < vat_moment_e!: valid_trace_e "moment i s" "next_e"
   693 sublocale valid_moment_e < vat_moment_e!: valid_trace_e "moment i s" "next_e"
   689   using vt_moment[of "Suc i", unfolded trace_e]
   694   using vt_moment[of "Suc i", unfolded trace_e]
   690   by (unfold_locales, simp)
   695   by (unfold_locales, simp)
   691 
   696 
   692 section {* Distinctiveness of waiting queues *}
   697 section {* Waiting queues are distinct *}
   693 
   698 
   694 lemma (in valid_trace) finite_threads:
   699 text {*
   695   shows "finite (threads s)"
   700   This section proofs that every waiting queue in the system
   696   using vt by (induct) (auto elim: step.cases)
   701   is distinct, given in lemma @{text wq_distinct}.
   697 
   702 
   698 lemma (in valid_trace) finite_readys [simp]: "finite (readys s)"
   703   The proof is split into the locales for events (or operations),
   699   using finite_threads readys_threads rev_finite_subset by blast
   704   all contain a lemma named @{text "wq_distinct_kept"} to show that
       
   705   the distinctiveness is preserved by the respective operation. All lemmas
       
   706   before are to facilitate the proof of @{text "wq_distinct_kept"}.
       
   707 
       
   708   The proof also demonstrates the common pattern to prove
       
   709   invariant properties over valid traces, i.e. to spread the 
       
   710   invariant proof into locales and to assemble the results of all 
       
   711   locales to complete the final proof.
       
   712   
       
   713 *}
   700 
   714 
   701 context valid_trace_create
   715 context valid_trace_create
   702 begin
   716 begin
   703 
   717 
   704 lemma wq_kept [simp]:
   718 lemma wq_kept [simp]:
   758   proof(cases)
   772   proof(cases)
   759     case (thread_P)
   773     case (thread_P)
   760     with cs_th_RAG show ?thesis by auto
   774     with cs_th_RAG show ?thesis by auto
   761   qed
   775   qed
   762 qed
   776 qed
   763 
   777                   
   764 lemma wq_es_cs: 
   778 lemma wq_es_cs: 
   765   "wq (e#s) cs =  wq s cs @ [th]"
   779   "wq (e#s) cs =  wq s cs @ [th]"
   766   by (unfold is_p wq_def, auto simp:Let_def)
   780   by (unfold is_p wq_def, auto simp:Let_def)
   767 
   781 
   768 lemma wq_distinct_kept:
   782 lemma wq_distinct_kept:
   832 end
   846 end
   833 
   847 
   834 context valid_trace
   848 context valid_trace
   835 begin
   849 begin
   836 
   850 
       
   851 text {*
       
   852   The proof of @{text "wq_distinct"} shows how the results 
       
   853   proved in the foregoing locales are assembled in
       
   854   a overall structure of induction and case analysis
       
   855   to get the final conclusion. This scheme will be 
       
   856   used repeatedly in the following.
       
   857 *}
   837 lemma wq_distinct: "distinct (wq s cs)"
   858 lemma wq_distinct: "distinct (wq s cs)"
   838 proof(induct rule:ind)
   859 proof(induct rule:ind)
   839   case (Cons s e)
   860   case (Cons s e)
   840   interpret vt_e: valid_trace_e s e using Cons by simp
   861   interpret vt_e: valid_trace_e s e using Cons by simp
   841   show ?case 
   862   show ?case 
   867 
   888 
   868 end
   889 end
   869 
   890 
   870 section {* Waiting queues and threads *}
   891 section {* Waiting queues and threads *}
   871 
   892 
   872 context valid_trace_e
   893 text {*
   873 begin
   894   This section shows that all threads withing waiting queues are
   874 
   895   in the @{term threads}-set. In other words, @{term threads} covers
   875 lemma wq_out_inv: 
   896   all the threads in waiting queue.
   876   assumes s_in: "thread \<in> set (wq s cs)"
   897 
   877   and s_hd: "thread = hd (wq s cs)"
   898   The proof follows the same pattern as @{thm valid_trace.wq_distinct}.
   878   and s_i: "thread \<noteq> hd (wq (e#s) cs)"
   899   The desired property is shown to be kept by all operations (or events)
   879   shows "e = V thread cs"
   900   in their respective locales, and finally the main lemmas is 
   880 proof(cases e)
   901   derived by assembling the invariant keeping results of the locales. 
   881 -- {* There are only two non-trivial cases: *}
   902 *}
   882   case (V th cs1)
   903 
   883   show ?thesis
   904 context valid_trace_create
   884   proof(cases "cs1 = cs")
   905 begin
   885     case True
   906 
   886     have "PIP s (V th cs)" using pip_e[unfolded V[unfolded True]] .
   907 lemma 
   887     thus ?thesis
       
   888     proof(cases)
       
   889       case (thread_V)
       
   890       moreover have "th = thread" using thread_V(2) s_hd
       
   891           by (unfold s_holding_def wq_def, simp)
       
   892       ultimately show ?thesis using V True by simp
       
   893     qed
       
   894   qed (insert assms V, auto simp:wq_def Let_def split:if_splits)
       
   895 next
       
   896   case (P th cs1)
       
   897   show ?thesis
       
   898   proof(cases "cs1 = cs")
       
   899     case True
       
   900     with P have "wq (e#s) cs = wq_fun (schs s) cs @ [th]"
       
   901       by (auto simp:wq_def Let_def split:if_splits)
       
   902     with s_i s_hd s_in have False
       
   903       by (metis empty_iff hd_append2 list.set(1) wq_def) 
       
   904     thus ?thesis by simp
       
   905   qed (insert assms P, auto simp:wq_def Let_def split:if_splits)
       
   906 qed (insert assms, auto simp:wq_def Let_def split:if_splits)
       
   907 
       
   908 lemma wq_in_inv: 
       
   909   assumes s_ni: "thread \<notin> set (wq s cs)"
       
   910   and s_i: "thread \<in> set (wq (e#s) cs)"
       
   911   shows "e = P thread cs"
       
   912 proof(cases e)
       
   913   -- {* This is the only non-trivial case: *}
       
   914   case (V th cs1)
       
   915   have False
       
   916   proof(cases "cs1 = cs")
       
   917     case True
       
   918     show ?thesis
       
   919     proof(cases "(wq s cs1)")
       
   920       case (Cons w_hd w_tl)
       
   921       have "set (wq (e#s) cs) \<subseteq> set (wq s cs)"
       
   922       proof -
       
   923         have "(wq (e#s) cs) = (SOME q. distinct q \<and> set q = set w_tl)"
       
   924           using  Cons V by (auto simp:wq_def Let_def True split:if_splits)
       
   925         moreover have "set ... \<subseteq> set (wq s cs)"
       
   926         proof(rule someI2)
       
   927           show "distinct w_tl \<and> set w_tl = set w_tl"
       
   928             by (metis distinct.simps(2) local.Cons wq_distinct)
       
   929         qed (insert Cons True, auto)
       
   930         ultimately show ?thesis by simp
       
   931       qed
       
   932       with assms show ?thesis by auto
       
   933     qed (insert assms V True, auto simp:wq_def Let_def split:if_splits)
       
   934   qed (insert assms V, auto simp:wq_def Let_def split:if_splits)
       
   935   thus ?thesis by auto
       
   936 qed (insert assms, auto simp:wq_def Let_def split:if_splits)
       
   937 
       
   938 end
       
   939 
       
   940 lemma (in valid_trace_create)
       
   941   th_not_in_threads: "th \<notin> threads s"
   908   th_not_in_threads: "th \<notin> threads s"
   942 proof -
   909 proof -
   943   from pip_e[unfolded is_create]
   910   from pip_e[unfolded is_create]
   944   show ?thesis by (cases, simp)
   911   show ?thesis by (cases, simp)
   945 qed
   912 qed
   946 
   913 
   947 lemma (in valid_trace_create)
   914 lemma 
   948   threads_es [simp]: "threads (e#s) = threads s \<union> {th}"
   915   threads_es [simp]: "threads (e#s) = threads s \<union> {th}"
   949   by (unfold is_create, simp)
   916   by (unfold is_create, simp)
   950 
   917 
   951 lemma (in valid_trace_exit)
   918 lemma wq_threads_kept:
   952   threads_es [simp]: "threads (e#s) = threads s - {th}"
   919   assumes "\<And> th' cs'. th' \<in> set (wq s cs') \<Longrightarrow> th' \<in> threads s"
       
   920   and "th' \<in> set (wq (e#s) cs')"
       
   921   shows "th' \<in> threads (e#s)"
       
   922 proof -
       
   923   have "th' \<in> threads s"
       
   924   proof -
       
   925     from assms(2)[unfolded wq_kept]
       
   926     have "th' \<in> set (wq s cs')" .
       
   927     from assms(1)[OF this] show ?thesis .
       
   928   qed
       
   929   with threads_es show ?thesis by simp
       
   930 qed
       
   931 
       
   932 end
       
   933 
       
   934 context valid_trace_exit
       
   935 begin
       
   936 
       
   937 lemma threads_es [simp]: "threads (e#s) = threads s - {th}"
   953   by (unfold is_exit, simp)
   938   by (unfold is_exit, simp)
   954 
   939 
   955 lemma (in valid_trace_p)
   940 lemma 
   956   threads_es [simp]: "threads (e#s) = threads s"
   941   th_not_in_wq: "th \<notin> set (wq s cs)"
   957   by (unfold is_p, simp)
   942 proof -
   958 
   943   from pip_e[unfolded is_exit]
   959 lemma (in valid_trace_v)
   944   show ?thesis
       
   945   by (cases, unfold holdents_def s_holding_def, fold wq_def, 
       
   946              auto elim!:runing_wqE)
       
   947 qed
       
   948 
       
   949 lemma wq_threads_kept:
       
   950   assumes "\<And> th' cs'. th' \<in> set (wq s cs') \<Longrightarrow> th' \<in> threads s"
       
   951   and "th' \<in> set (wq (e#s) cs')"
       
   952   shows "th' \<in> threads (e#s)"
       
   953 proof -
       
   954   have "th' \<in> threads s"
       
   955   proof -
       
   956     from assms(2)[unfolded wq_kept]
       
   957     have "th' \<in> set (wq s cs')" .
       
   958     from assms(1)[OF this] show ?thesis .
       
   959   qed
       
   960   moreover have "th' \<noteq> th"
       
   961   proof
       
   962     assume otherwise: "th' = th"
       
   963     from assms(2)[unfolded wq_kept]
       
   964     have "th' \<in> set (wq s cs')" .
       
   965     with th_not_in_wq[folded otherwise]
       
   966     show False by simp
       
   967   qed
       
   968   ultimately show ?thesis
       
   969     by (unfold threads_es, simp)
       
   970 qed
       
   971 
       
   972 end
       
   973 
       
   974 context valid_trace_v
       
   975 begin
       
   976 
       
   977 lemma 
   960   threads_es [simp]: "threads (e#s) = threads s"
   978   threads_es [simp]: "threads (e#s) = threads s"
   961   by (unfold is_v, simp)
   979   by (unfold is_v, simp)
   962 
   980 
   963 lemma (in valid_trace_v)
   981 lemma 
   964   th_not_in_rest[simp]: "th \<notin> set rest"
   982   th_not_in_rest: "th \<notin> set rest"
   965 proof
   983 proof
   966   assume otherwise: "th \<in> set rest"
   984   assume otherwise: "th \<in> set rest"
   967   have "distinct (wq s cs)" by (simp add: wq_distinct)
   985   have "distinct (wq s cs)" by (simp add: wq_distinct)
   968   from this[unfolded wq_s_cs] and otherwise
   986   from this[unfolded wq_s_cs] and otherwise
   969   show False by auto
   987   show False by auto
   970 qed
   988 qed
   971 
   989 
   972 lemma (in valid_trace_v) distinct_rest: "distinct rest"
   990 lemma distinct_rest: "distinct rest"
   973   by (simp add: distinct_tl rest_def wq_distinct)
   991   by (simp add: distinct_tl rest_def wq_distinct)
   974 
   992 
   975 lemma (in valid_trace_v)
   993 lemma
   976   set_wq_es_cs [simp]: "set (wq (e#s) cs) = set (wq s cs) - {th}"
   994   set_wq_es_cs [simp]: "set (wq (e#s) cs) = set (wq s cs) - {th}"
   977 proof(unfold wq_es_cs wq'_def, rule someI2)
   995 proof(unfold wq_es_cs wq'_def, rule someI2)
   978   show "distinct rest \<and> set rest = set rest"
   996   show "distinct rest \<and> set rest = set rest"
   979     by (simp add: distinct_rest) 
   997     by (simp add: distinct_rest) 
   980 next
   998 next
   981   fix x
   999   fix x
   982   assume "distinct x \<and> set x = set rest"
  1000   assume "distinct x \<and> set x = set rest"
   983   thus "set x = set (wq s cs) - {th}" 
  1001   thus "set x = set (wq s cs) - {th}" 
   984       by (unfold wq_s_cs, simp)
  1002       by (unfold wq_s_cs, simp add:th_not_in_rest)
   985 qed
  1003 qed
   986 
  1004 
   987 lemma (in valid_trace_exit)
  1005 lemma wq_threads_kept:
   988   th_not_in_wq: "th \<notin> set (wq s cs)"
  1006   assumes "\<And> th' cs'. th' \<in> set (wq s cs') \<Longrightarrow> th' \<in> threads s"
   989 proof -
  1007   and "th' \<in> set (wq (e#s) cs')"
   990   from pip_e[unfolded is_exit]
  1008   shows "th' \<in> threads (e#s)"
   991   show ?thesis
  1009 proof(cases "cs' = cs")
   992   by (cases, unfold holdents_def s_holding_def, fold wq_def, 
  1010   case True
   993              auto elim!:runing_wqE)
  1011   have " th' \<in> threads s"
   994 qed
  1012   proof -
   995 
  1013     from assms(2)[unfolded True set_wq_es_cs]
       
  1014     have "th' \<in> set (wq s cs) - {th}" .
       
  1015     hence "th' \<in> set (wq s cs)" by simp
       
  1016     from assms(1)[OF this]
       
  1017     show ?thesis .
       
  1018   qed
       
  1019   with threads_es show ?thesis by simp
       
  1020 next
       
  1021     case False
       
  1022     have "th' \<in> threads s"
       
  1023     proof -
       
  1024       from wq_neq_simp[OF False]
       
  1025       have "wq (e # s) cs' = wq s cs'" .
       
  1026       from assms(2)[unfolded this]
       
  1027       have "th' \<in> set (wq s cs')" .
       
  1028       from assms(1)[OF this]
       
  1029       show ?thesis .
       
  1030     qed
       
  1031     with threads_es show ?thesis by simp
       
  1032 qed
       
  1033 end
       
  1034 
       
  1035 context valid_trace_p
       
  1036 begin
       
  1037 
       
  1038 lemma threads_es [simp]: "threads (e#s) = threads s"
       
  1039   by (unfold is_p, simp)
       
  1040 
       
  1041 lemma ready_th_s: "th \<in> readys s"
       
  1042   using runing_th_s
       
  1043   by (unfold runing_def, auto)
       
  1044 
       
  1045 lemma live_th_s: "th \<in> threads s"
       
  1046   using readys_threads ready_th_s by auto
       
  1047 
       
  1048 lemma wq_threads_kept:
       
  1049   assumes "\<And> th' cs'. th' \<in> set (wq s cs') \<Longrightarrow> th' \<in> threads s"
       
  1050   and "th' \<in> set (wq (e#s) cs')"
       
  1051   shows "th' \<in> threads (e#s)"
       
  1052 proof(cases "cs' = cs")
       
  1053     case True
       
  1054     from assms(2)[unfolded True wq_es_cs]
       
  1055     have "th' \<in> set (wq s cs) \<or> th' = th" by auto
       
  1056     thus ?thesis
       
  1057     proof
       
  1058       assume "th' \<in> set (wq s cs)"
       
  1059       from assms(1)[OF this] have "th' \<in> threads s" .
       
  1060       with threads_es
       
  1061       show ?thesis by simp
       
  1062     next
       
  1063       assume "th' = th"
       
  1064       with live_th_s have "th' \<in> threads s" by simp
       
  1065       with threads_es show ?thesis by simp
       
  1066     qed
       
  1067 next
       
  1068     case False
       
  1069     have "th' \<in> threads s"
       
  1070     proof -
       
  1071       from wq_neq_simp[OF False]
       
  1072       have "wq (e # s) cs' = wq s cs'" .
       
  1073       from assms(2)[unfolded this]
       
  1074       have "th' \<in> set (wq s cs')" .
       
  1075       from assms(1)[OF this]
       
  1076       show ?thesis .
       
  1077     qed
       
  1078     with threads_es show ?thesis by simp
       
  1079 qed
       
  1080 
       
  1081 end
       
  1082 
       
  1083 context valid_trace_set
       
  1084 begin
       
  1085 
       
  1086 lemma threads_kept[simp]:
       
  1087   "threads (e#s) = threads s"
       
  1088   by (unfold is_set, simp)
       
  1089 
       
  1090 lemma wq_threads_kept: 
       
  1091   assumes "\<And> th' cs'. th' \<in> set (wq s cs') \<Longrightarrow> th' \<in> threads s"
       
  1092   and "th' \<in> set (wq (e#s) cs')"
       
  1093   shows "th' \<in> threads (e#s)"
       
  1094 proof -
       
  1095   have "th' \<in> threads s"
       
  1096      using assms(1)[OF assms(2)[unfolded wq_kept]] .
       
  1097   with threads_kept show ?thesis by simp
       
  1098 qed
       
  1099 
       
  1100 end
       
  1101 
       
  1102 text {*
       
  1103   The is the main lemma of this section, which is derived
       
  1104   by induction, case analysis on event @{text e} and 
       
  1105   assembling the @{text "wq_threads_kept"}-results of 
       
  1106   all possible cases of @{text "e"}.
       
  1107 *}
   996 lemma (in valid_trace) wq_threads: 
  1108 lemma (in valid_trace) wq_threads: 
   997   assumes "th \<in> set (wq s cs)"
  1109   assumes "th \<in> set (wq s cs)"
   998   shows "th \<in> threads s"
  1110   shows "th \<in> threads s"
   999   using assms
  1111   using assms
  1000 proof(induct rule:ind)
  1112 proof(induct arbitrary:th cs rule:ind)
  1001   case (Nil)
  1113   case (Nil)
  1002   thus ?case by (auto simp:wq_def)
  1114   thus ?case by (auto simp:wq_def)
  1003 next
  1115 next
  1004   case (Cons s e)
  1116   case (Cons s e)
  1005   interpret vt_e: valid_trace_e s e using Cons by simp
  1117   interpret vt_e: valid_trace_e s e using Cons by simp
  1006   show ?case
  1118   show ?case
  1007   proof(cases e)
  1119   proof(cases e)
  1008     case (Create th' prio')
  1120     case (Create th' prio')
  1009     interpret vt: valid_trace_create s e th' prio'
  1121     interpret vt: valid_trace_create s e th' prio'
  1010       using Create by (unfold_locales, simp)
  1122       using Create by (unfold_locales, simp)
  1011     show ?thesis
  1123     show ?thesis using vt.wq_threads_kept Cons by auto
  1012       using Cons.hyps(2) Cons.prems by auto
       
  1013   next
  1124   next
  1014     case (Exit th')
  1125     case (Exit th')
  1015     interpret vt: valid_trace_exit s e th'
  1126     interpret vt: valid_trace_exit s e th'
  1016       using Exit by (unfold_locales, simp)
  1127       using Exit by (unfold_locales, simp)
  1017     show ?thesis
  1128     show ?thesis using vt.wq_threads_kept Cons by auto
  1018       using Cons.hyps(2) Cons.prems vt.th_not_in_wq by auto 
       
  1019   next
  1129   next
  1020     case (P th' cs')
  1130     case (P th' cs')
  1021     interpret vt: valid_trace_p s e th' cs'
  1131     interpret vt: valid_trace_p s e th' cs'
  1022       using P by (unfold_locales, simp)
  1132       using P by (unfold_locales, simp)
  1023     show ?thesis
  1133    show ?thesis using vt.wq_threads_kept Cons by auto
  1024       using Cons.hyps(2) Cons.prems readys_threads 
       
  1025         runing_ready vt.is_p vt.runing_th_s vt_e.wq_in_inv 
       
  1026         by fastforce 
       
  1027   next
  1134   next
  1028     case (V th' cs')
  1135     case (V th' cs')
  1029     interpret vt: valid_trace_v s e th' cs'
  1136     interpret vt: valid_trace_v s e th' cs'
  1030       using V by (unfold_locales, simp)
  1137       using V by (unfold_locales, simp)
  1031     show ?thesis using Cons
  1138    show ?thesis using vt.wq_threads_kept Cons by auto
  1032       using vt.is_v vt.threads_es vt_e.wq_in_inv by blast
       
  1033   next
  1139   next
  1034     case (Set th' prio)
  1140     case (Set th' prio)
  1035     interpret vt: valid_trace_set s e th' prio
  1141     interpret vt: valid_trace_set s e th' prio
  1036       using Set by (unfold_locales, simp)
  1142       using Set by (unfold_locales, simp)
  1037     show ?thesis using Cons.hyps(2) Cons.prems vt.is_set 
  1143    show ?thesis using vt.wq_threads_kept Cons by auto
  1038         by (auto simp:wq_def Let_def)
       
  1039   qed
  1144   qed
  1040 qed 
  1145 qed 
  1041 
  1146 
  1042 section {* RAG and threads *}
  1147 subsection {* RAG and threads *}
  1043 
  1148 
  1044 context valid_trace
  1149 context valid_trace
  1045 begin
  1150 begin
       
  1151 
       
  1152 text {*
       
  1153   As corollaries of @{thm wq_threads}, it is shown in this subsection
       
  1154   that the fields (including both domain
       
  1155   and range) of @{term RAG} are covered by @{term threads}.
       
  1156 *}
  1046 
  1157 
  1047 lemma  dm_RAG_threads:
  1158 lemma  dm_RAG_threads:
  1048   assumes in_dom: "(Th th) \<in> Domain (RAG s)"
  1159   assumes in_dom: "(Th th) \<in> Domain (RAG s)"
  1049   shows "th \<in> threads s"
  1160   shows "th \<in> threads s"
  1050 proof -
  1161 proof -
  1667 
  1778 
  1668 lemma waiting_esE:
  1779 lemma waiting_esE:
  1669   assumes "waiting (e#s) th' cs'"
  1780   assumes "waiting (e#s) th' cs'"
  1670   obtains "waiting s th' cs'"
  1781   obtains "waiting s th' cs'"
  1671   using assms
  1782   using assms
  1672   by (metis cs_waiting_def event.distinct(15) is_p list.sel(1) 
  1783   by (metis empty_iff list.sel(1) list.set(1) s_waiting_def 
  1673         set_ConsD waiting_eq we wq_es_cs' wq_neq_simp wq_out_inv)
  1784       set_ConsD wq_def wq_es_cs' wq_neq_simp)
  1674   
  1785   
  1675 lemma holding_esE:
  1786 lemma holding_esE:
  1676   assumes "holding (e#s) th' cs'"
  1787   assumes "holding (e#s) th' cs'"
  1677   obtains "cs' \<noteq> cs" "holding s th' cs'"
  1788   obtains "cs' \<noteq> cs" "holding s th' cs'"
  1678     | "cs' = cs" "th' = th"
  1789     | "cs' = cs" "th' = th"
  1769   with assms show ?thesis
  1880   with assms show ?thesis
  1770     using cs_holding_def holding_eq that by auto 
  1881     using cs_holding_def holding_eq that by auto 
  1771 next
  1882 next
  1772   case True
  1883   case True
  1773   with assms show ?thesis
  1884   with assms show ?thesis
  1774     using event.inject(3) holder_def is_p s_holding_def s_waiting_def that 
  1885     using s_holding_def that wq_def wq_es_cs' wq_s_cs by auto
  1775       waiting_es_th_cs wq_def wq_es_cs' wq_in_inv
       
  1776     by(force)
       
  1777 qed
  1886 qed
  1778 
  1887 
  1779 lemma waiting_esE:
  1888 lemma waiting_esE:
  1780   assumes "waiting (e#s) th' cs'"
  1889   assumes "waiting (e#s) th' cs'"
  1781   obtains "th' \<noteq> th" "waiting s th' cs'"
  1890   obtains "th' \<noteq> th" "waiting s th' cs'"
  1868   show ?thesis by (simp add: vt_p.RAG_es vt_p.wne) 
  1977   show ?thesis by (simp add: vt_p.RAG_es vt_p.wne) 
  1869 qed
  1978 qed
  1870 
  1979 
  1871 end
  1980 end
  1872 
  1981 
  1873 section {* Finiteness of RAG *}
  1982 section {* RAG is finite *}
  1874 
  1983 
  1875 context valid_trace
  1984 context valid_trace
  1876 begin
  1985 begin
  1877 
  1986 
  1878 lemma finite_RAG:
  1987 lemma finite_RAG:
  2950   next
  3059   next
  2951     show "preced th s \<in> the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)}"
  3060     show "preced th s \<in> the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)}"
  2952       by (simp add: subtree_def the_preced_def)   
  3061       by (simp add: subtree_def the_preced_def)   
  2953   qed
  3062   qed
  2954 
  3063 
       
  3064 lemma finite_threads:
       
  3065   shows "finite (threads s)"
       
  3066   using vt by (induct) (auto elim: step.cases)
  2955 
  3067 
  2956 lemma cp_le:
  3068 lemma cp_le:
  2957   assumes th_in: "th \<in> threads s"
  3069   assumes th_in: "th \<in> threads s"
  2958   shows "cp s th \<le> Max (the_preced s ` threads s)"
  3070   shows "cp s th \<le> Max (the_preced s ` threads s)"
  2959 proof(unfold cp_alt_def, rule Max_f_mono)
  3071 proof(unfold cp_alt_def, rule Max_f_mono)
  3014       show ?thesis .
  3126       show ?thesis .
  3015     qed
  3127     qed
  3016   } ultimately show ?thesis by auto
  3128   } ultimately show ?thesis by auto
  3017 qed
  3129 qed
  3018 
  3130 
       
  3131 lemma  finite_readys: "finite (readys s)"
       
  3132   using finite_threads readys_threads rev_finite_subset by blast
  3019 
  3133 
  3020 text {* (* ccc *) \noindent
  3134 text {* (* ccc *) \noindent
  3021   Since the current precedence of the threads in ready queue will always be boosted,
  3135   Since the current precedence of the threads in ready queue will always be boosted,
  3022   there must be one inside it has the maximum precedence of the whole system. 
  3136   there must be one inside it has the maximum precedence of the whole system. 
  3023 *}
  3137 *}
  3036     Max (Max ` (\<lambda>th. the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)}) ` readys s)" 
  3150     Max (Max ` (\<lambda>th. the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)}) ` readys s)" 
  3037   proof(rule Max_UNION)
  3151   proof(rule Max_UNION)
  3038     show "\<forall>M\<in>(\<lambda>x. the_preced s ` 
  3152     show "\<forall>M\<in>(\<lambda>x. the_preced s ` 
  3039                     {th'. Th th' \<in> subtree (RAG s) (Th x)}) ` readys s. finite M"
  3153                     {th'. Th th' \<in> subtree (RAG s) (Th x)}) ` readys s. finite M"
  3040                         using finite_subtree_threads by auto
  3154                         using finite_subtree_threads by auto
  3041   qed (auto simp:False subtree_def)
  3155   qed (auto simp:False subtree_def finite_readys)
  3042   also have "... =  
  3156   also have "... =  
  3043     Max ((Max \<circ> (\<lambda>th. the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})) ` readys s)" 
  3157     Max ((Max \<circ> (\<lambda>th. the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})) ` readys s)" 
  3044       by (unfold image_comp, simp)
  3158       by (unfold image_comp, simp)
  3045   also have "... = ?L" (is "Max (?f ` ?A) = Max (?g ` ?A)")
  3159   also have "... = ?L" (is "Max (?f ` ?A) = Max (?g ` ?A)")
  3046   proof -
  3160   proof -
  3130 
  3244 
  3131 lemma ready_th_s: "th \<in> readys s"
  3245 lemma ready_th_s: "th \<in> readys s"
  3132   using runing_th_s
  3246   using runing_th_s
  3133   by (unfold runing_def, auto)
  3247   by (unfold runing_def, auto)
  3134 
  3248 
  3135 lemma live_th_s: "th \<in> threads s"
       
  3136   using readys_threads ready_th_s by auto
       
  3137 
       
  3138 lemma live_th_es: "th \<in> threads (e#s)"
  3249 lemma live_th_es: "th \<in> threads (e#s)"
  3139   using live_th_s 
  3250   using live_th_s 
  3140   by (unfold is_p, simp)
  3251   by (unfold is_p, simp)
  3141 
  3252 
  3142 lemma waiting_neq_th: 
  3253 lemma waiting_neq_th: