CpsG.thy
changeset 35 92f61f6a0fe7
parent 33 9b9f2117561f
child 45 fc83f79009bd
equal deleted inserted replaced
34:313acffe63b6 35:92f61f6a0fe7
     1 
     1 
     2 theory CpsG
     2 theory CpsG
     3 imports PrioG 
     3 imports PrioG Max
     4 begin
     4 begin
     5 
     5 
     6 lemma not_thread_holdents:
     6 lemma not_thread_holdents:
     7   fixes th s
     7   fixes th s
     8   assumes vt: "vt s"
     8   assumes vt: "vt s"
    21       case (thread_create thread prio)
    21       case (thread_create thread prio)
    22       assume eq_e: "e = Create thread prio"
    22       assume eq_e: "e = Create thread prio"
    23         and not_in': "thread \<notin> threads s"
    23         and not_in': "thread \<notin> threads s"
    24       have "holdents (e # s) th = holdents s th"
    24       have "holdents (e # s) th = holdents s th"
    25         apply (unfold eq_e holdents_test)
    25         apply (unfold eq_e holdents_test)
    26         by (simp add:depend_create_unchanged)
    26         by (simp add:RAG_create_unchanged)
    27       moreover have "th \<notin> threads s" 
    27       moreover have "th \<notin> threads s" 
    28       proof -
    28       proof -
    29         from not_in eq_e show ?thesis by simp
    29         from not_in eq_e show ?thesis by simp
    30       qed
    30       qed
    31       moreover note ih ultimately show ?thesis by auto
    31       moreover note ih ultimately show ?thesis by auto
    36       show ?thesis
    36       show ?thesis
    37       proof(cases "th = thread")
    37       proof(cases "th = thread")
    38         case True
    38         case True
    39         with nh eq_e
    39         with nh eq_e
    40         show ?thesis 
    40         show ?thesis 
    41           by (auto simp:holdents_test depend_exit_unchanged)
    41           by (auto simp:holdents_test RAG_exit_unchanged)
    42       next
    42       next
    43         case False
    43         case False
    44         with not_in and eq_e
    44         with not_in and eq_e
    45         have "th \<notin> threads s" by simp
    45         have "th \<notin> threads s" by simp
    46         from ih[OF this] False eq_e show ?thesis 
    46         from ih[OF this] False eq_e show ?thesis 
    47           by (auto simp:holdents_test depend_exit_unchanged)
    47           by (auto simp:holdents_test RAG_exit_unchanged)
    48       qed
    48       qed
    49     next
    49     next
    50       case (thread_P thread cs)
    50       case (thread_P thread cs)
    51       assume eq_e: "e = P thread cs"
    51       assume eq_e: "e = P thread cs"
    52       and is_runing: "thread \<in> runing s"
    52       and is_runing: "thread \<in> runing s"
    58           by (simp add:runing_def readys_def)
    58           by (simp add:runing_def readys_def)
    59         ultimately show ?thesis by auto
    59         ultimately show ?thesis by auto
    60       qed
    60       qed
    61       hence "holdents (e # s) th  = holdents s th "
    61       hence "holdents (e # s) th  = holdents s th "
    62         apply (unfold cntCS_def holdents_test eq_e)
    62         apply (unfold cntCS_def holdents_test eq_e)
    63         by (unfold step_depend_p[OF vtp], auto)
    63         by (unfold step_RAG_p[OF vtp], auto)
    64       moreover have "holdents s th = {}"
    64       moreover have "holdents s th = {}"
    65       proof(rule ih)
    65       proof(rule ih)
    66         from not_in eq_e show "th \<notin> threads s" by simp
    66         from not_in eq_e show "th \<notin> threads s" by simp
    67       qed
    67       qed
    68       ultimately show ?thesis by simp
    68       ultimately show ?thesis by simp
   100         from wq_threads[OF step_back_vt[OF vtv], OF this] and ni
   100         from wq_threads[OF step_back_vt[OF vtv], OF this] and ni
   101         show False by auto
   101         show False by auto
   102       qed
   102       qed
   103       moreover note neq_th eq_wq
   103       moreover note neq_th eq_wq
   104       ultimately have "holdents (e # s) th  = holdents s th"
   104       ultimately have "holdents (e # s) th  = holdents s th"
   105         by (unfold eq_e cntCS_def holdents_test step_depend_v[OF vtv], auto)
   105         by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
   106       moreover have "holdents s th = {}"
   106       moreover have "holdents s th = {}"
   107       proof(rule ih)
   107       proof(rule ih)
   108         from not_in eq_e show "th \<notin> threads s" by simp
   108         from not_in eq_e show "th \<notin> threads s" by simp
   109       qed
   109       qed
   110       ultimately show ?thesis by simp
   110       ultimately show ?thesis by simp
   115         and is_runing: "thread \<in> runing s"
   115         and is_runing: "thread \<in> runing s"
   116       from not_in and eq_e have "th \<notin> threads s" by auto
   116       from not_in and eq_e have "th \<notin> threads s" by auto
   117       from ih [OF this] and eq_e
   117       from ih [OF this] and eq_e
   118       show ?thesis 
   118       show ?thesis 
   119         apply (unfold eq_e cntCS_def holdents_test)
   119         apply (unfold eq_e cntCS_def holdents_test)
   120         by (simp add:depend_set_unchanged)
   120         by (simp add:RAG_set_unchanged)
   121     qed
   121     qed
   122     next
   122     next
   123       case vt_nil
   123       case vt_nil
   124       show ?case
   124       show ?case
   125       by (auto simp:count_def holdents_test s_depend_def wq_def cs_holding_def)
   125       by (auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
   126   qed
   126   qed
   127 qed
   127 qed
   128 
   128 
   129 
   129 
   130 
   130 
   159   assumes nt1: "next_th s th cs th1"
   159   assumes nt1: "next_th s th cs th1"
   160   and nt2: "next_th s th cs th2"
   160   and nt2: "next_th s th cs th2"
   161   shows "th1 = th2"
   161   shows "th1 = th2"
   162 using assms by (unfold next_th_def, auto)
   162 using assms by (unfold next_th_def, auto)
   163 
   163 
   164 lemma wf_depend:
   164 lemma wf_RAG:
   165   assumes vt: "vt s"
   165   assumes vt: "vt s"
   166   shows "wf (depend s)"
   166   shows "wf (RAG s)"
   167 proof(rule finite_acyclic_wf)
   167 proof(rule finite_acyclic_wf)
   168   from finite_depend[OF vt] show "finite (depend s)" .
   168   from finite_RAG[OF vt] show "finite (RAG s)" .
   169 next
   169 next
   170   from acyclic_depend[OF vt] show "acyclic (depend s)" .
   170   from acyclic_RAG[OF vt] show "acyclic (RAG s)" .
   171 qed
   171 qed
   172 
   172 
   173 lemma Max_Union:
   173 
   174   assumes fc: "finite C"
       
   175   and ne: "C \<noteq> {}"
       
   176   and fa: "\<And> A. A \<in> C \<Longrightarrow> finite A \<and> A \<noteq> {}"
       
   177   shows "Max (\<Union> C) = Max (Max ` C)"
       
   178 proof -
       
   179   from fc ne fa show ?thesis
       
   180   proof(induct)
       
   181     case (insert x F)
       
   182     assume ih: "\<lbrakk>F \<noteq> {}; \<And>A. A \<in> F \<Longrightarrow> finite A \<and> A \<noteq> {}\<rbrakk> \<Longrightarrow> Max (\<Union>F) = Max (Max ` F)"
       
   183     and h: "\<And> A. A \<in> insert x F \<Longrightarrow> finite A \<and> A \<noteq> {}"
       
   184     show ?case (is "?L = ?R")
       
   185     proof(cases "F = {}")
       
   186       case False
       
   187       from Union_insert have "?L = Max (x \<union> (\<Union> F))" by simp
       
   188       also have "\<dots> = max (Max x) (Max(\<Union> F))"
       
   189       proof(rule Max_Un)
       
   190         from h[of x] show "finite x" by auto
       
   191       next
       
   192         from h[of x] show "x \<noteq> {}" by auto
       
   193       next
       
   194         show "finite (\<Union>F)"
       
   195         proof(rule finite_Union)
       
   196           show "finite F" by fact
       
   197         next
       
   198           from h show "\<And>M. M \<in> F \<Longrightarrow> finite M" by auto
       
   199         qed
       
   200       next
       
   201         from False and h show "\<Union>F \<noteq> {}" by auto
       
   202       qed
       
   203       also have "\<dots> = ?R"
       
   204       proof -
       
   205         have "?R = Max (Max ` ({x} \<union> F))" by simp
       
   206         also have "\<dots> = Max ({Max x} \<union> (Max ` F))" by simp
       
   207         also have "\<dots> = max (Max x) (Max (\<Union>F))"
       
   208         proof -
       
   209           have "Max ({Max x} \<union> Max ` F) = max (Max {Max x}) (Max (Max ` F))"
       
   210           proof(rule Max_Un)
       
   211             show "finite {Max x}" by simp
       
   212           next
       
   213             show "{Max x} \<noteq> {}" by simp
       
   214           next
       
   215             from insert show "finite (Max ` F)" by auto
       
   216           next
       
   217             from False show "Max ` F \<noteq> {}" by auto
       
   218           qed
       
   219           moreover have "Max {Max x} = Max x" by simp
       
   220           moreover have "Max (\<Union>F) = Max (Max ` F)"
       
   221           proof(rule ih)
       
   222             show "F \<noteq> {}" by fact
       
   223           next
       
   224             from h show "\<And>A. A \<in> F \<Longrightarrow> finite A \<and> A \<noteq> {}"
       
   225               by auto
       
   226           qed
       
   227           ultimately show ?thesis by auto
       
   228         qed
       
   229         finally show ?thesis by simp
       
   230       qed
       
   231       finally show ?thesis by simp
       
   232     next
       
   233       case True
       
   234       thus ?thesis by auto
       
   235     qed
       
   236   next
       
   237     case empty
       
   238     assume "{} \<noteq> {}" show ?case by auto
       
   239   qed
       
   240 qed
       
   241 
   174 
   242 definition child :: "state \<Rightarrow> (node \<times> node) set"
   175 definition child :: "state \<Rightarrow> (node \<times> node) set"
   243   where "child s \<equiv>
   176   where "child s \<equiv>
   244             {(Th th', Th th) | th th'. \<exists>cs. (Th th', Cs cs) \<in> depend s \<and> (Cs cs, Th th) \<in> depend s}"
   177             {(Th th', Th th) | th th'. \<exists>cs. (Th th', Cs cs) \<in> RAG s \<and> (Cs cs, Th th) \<in> RAG s}"
   245 
   178 
   246 definition children :: "state \<Rightarrow> thread \<Rightarrow> thread set"
   179 definition children :: "state \<Rightarrow> thread \<Rightarrow> thread set"
   247   where "children s th \<equiv> {th'. (Th th', Th th) \<in> child s}"
   180   where "children s th \<equiv> {th'. (Th th', Th th) \<in> child s}"
   248 
   181 
   249 lemma children_def2:
   182 lemma children_def2:
   250   "children s th \<equiv> {th'. \<exists> cs. (Th th', Cs cs) \<in> depend s \<and> (Cs cs, Th th) \<in> depend s}"
   183   "children s th \<equiv> {th'. \<exists> cs. (Th th', Cs cs) \<in> RAG s \<and> (Cs cs, Th th) \<in> RAG s}"
   251 unfolding child_def children_def by simp
   184 unfolding child_def children_def by simp
   252 
   185 
   253 lemma children_dependants: "children s th \<subseteq> dependants (wq s) th"
   186 lemma children_dependants: 
   254   by (unfold children_def child_def cs_dependants_def, auto simp:eq_depend)
   187   "children s th \<subseteq> dependants (wq s) th"
       
   188   unfolding children_def2
       
   189   unfolding cs_dependants_def
       
   190   by (auto simp add: eq_RAG)
   255 
   191 
   256 lemma child_unique:
   192 lemma child_unique:
   257   assumes vt: "vt s"
   193   assumes vt: "vt s"
   258   and ch1: "(Th th, Th th1) \<in> child s"
   194   and ch1: "(Th th, Th th1) \<in> child s"
   259   and ch2: "(Th th, Th th2) \<in> child s"
   195   and ch2: "(Th th, Th th2) \<in> child s"
   260   shows "th1 = th2"
   196   shows "th1 = th2"
   261 using ch1 ch2 
   197 using ch1 ch2 
   262 proof(unfold child_def, clarsimp)
   198 proof(unfold child_def, clarsimp)
   263   fix cs csa
   199   fix cs csa
   264   assume h1: "(Th th, Cs cs) \<in> depend s"
   200   assume h1: "(Th th, Cs cs) \<in> RAG s"
   265     and h2: "(Cs cs, Th th1) \<in> depend s"
   201     and h2: "(Cs cs, Th th1) \<in> RAG s"
   266     and h3: "(Th th, Cs csa) \<in> depend s"
   202     and h3: "(Th th, Cs csa) \<in> RAG s"
   267     and h4: "(Cs csa, Th th2) \<in> depend s"
   203     and h4: "(Cs csa, Th th2) \<in> RAG s"
   268   from unique_depend[OF vt h1 h3] have "cs = csa" by simp
   204   from unique_RAG[OF vt h1 h3] have "cs = csa" by simp
   269   with h4 have "(Cs cs, Th th2) \<in> depend s" by simp
   205   with h4 have "(Cs cs, Th th2) \<in> RAG s" by simp
   270   from unique_depend[OF vt h2 this]
   206   from unique_RAG[OF vt h2 this]
   271   show "th1 = th2" by simp
   207   show "th1 = th2" by simp
   272 qed 
   208 qed 
   273 
   209 
   274 lemma depend_children:
   210 lemma RAG_children:
   275   assumes h: "(Th th1, Th th2) \<in> (depend s)^+"
   211   assumes h: "(Th th1, Th th2) \<in> (RAG s)^+"
   276   shows "th1 \<in> children s th2 \<or> (\<exists> th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (depend s)^+)"
   212   shows "th1 \<in> children s th2 \<or> (\<exists> th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (RAG s)^+)"
   277 proof -
   213 proof -
   278   from h show ?thesis
   214   from h show ?thesis
   279   proof(induct rule: tranclE)
   215   proof(induct rule: tranclE)
   280     fix c th2
   216     fix c th2
   281     assume h1: "(Th th1, c) \<in> (depend s)\<^sup>+"
   217     assume h1: "(Th th1, c) \<in> (RAG s)\<^sup>+"
   282     and h2: "(c, Th th2) \<in> depend s"
   218     and h2: "(c, Th th2) \<in> RAG s"
   283     from h2 obtain cs where eq_c: "c = Cs cs"
   219     from h2 obtain cs where eq_c: "c = Cs cs"
   284       by (case_tac c, auto simp:s_depend_def)
   220       by (case_tac c, auto simp:s_RAG_def)
   285     show "th1 \<in> children s th2 \<or> (\<exists>th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (depend s)\<^sup>+)"
   221     show "th1 \<in> children s th2 \<or> (\<exists>th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (RAG s)\<^sup>+)"
   286     proof(rule tranclE[OF h1])
   222     proof(rule tranclE[OF h1])
   287       fix ca
   223       fix ca
   288       assume h3: "(Th th1, ca) \<in> (depend s)\<^sup>+"
   224       assume h3: "(Th th1, ca) \<in> (RAG s)\<^sup>+"
   289         and h4: "(ca, c) \<in> depend s"
   225         and h4: "(ca, c) \<in> RAG s"
   290       show "th1 \<in> children s th2 \<or> (\<exists>th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (depend s)\<^sup>+)"
   226       show "th1 \<in> children s th2 \<or> (\<exists>th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (RAG s)\<^sup>+)"
   291       proof -
   227       proof -
   292         from eq_c and h4 obtain th3 where eq_ca: "ca = Th th3"
   228         from eq_c and h4 obtain th3 where eq_ca: "ca = Th th3"
   293           by (case_tac ca, auto simp:s_depend_def)
   229           by (case_tac ca, auto simp:s_RAG_def)
   294         from eq_ca h4 h2 eq_c
   230         from eq_ca h4 h2 eq_c
   295         have "th3 \<in> children s th2" by (auto simp:children_def child_def)
   231         have "th3 \<in> children s th2" by (auto simp:children_def child_def)
   296         moreover from h3 eq_ca have "(Th th1, Th th3) \<in> (depend s)\<^sup>+" by simp
   232         moreover from h3 eq_ca have "(Th th1, Th th3) \<in> (RAG s)\<^sup>+" by simp
   297         ultimately show ?thesis by auto
   233         ultimately show ?thesis by auto
   298       qed
   234       qed
   299     next
   235     next
   300       assume "(Th th1, c) \<in> depend s"
   236       assume "(Th th1, c) \<in> RAG s"
   301       with h2 eq_c
   237       with h2 eq_c
   302       have "th1 \<in> children s th2"
   238       have "th1 \<in> children s th2"
   303         by (auto simp:children_def child_def)
   239         by (auto simp:children_def child_def)
   304       thus ?thesis by auto
   240       thus ?thesis by auto
   305     qed
   241     qed
   306   next
   242   next
   307     assume "(Th th1, Th th2) \<in> depend s"
   243     assume "(Th th1, Th th2) \<in> RAG s"
   308     thus ?thesis
   244     thus ?thesis
   309       by (auto simp:s_depend_def)
   245       by (auto simp:s_RAG_def)
   310   qed
   246   qed
   311 qed
   247 qed
   312 
   248 
   313 lemma sub_child: "child s \<subseteq> (depend s)^+"
   249 lemma sub_child: "child s \<subseteq> (RAG s)^+"
   314   by (unfold child_def, auto)
   250   by (unfold child_def, auto)
   315 
   251 
   316 lemma wf_child: 
   252 lemma wf_child: 
   317   assumes vt: "vt s"
   253   assumes vt: "vt s"
   318   shows "wf (child s)"
   254   shows "wf (child s)"
   319 apply(rule wf_subset)
   255 apply(rule wf_subset)
   320 apply(rule wf_trancl[OF wf_depend[OF vt]])
   256 apply(rule wf_trancl[OF wf_RAG[OF vt]])
   321 apply(rule sub_child)
   257 apply(rule sub_child)
   322 done
   258 done
   323 
   259 
   324 lemma depend_child_pre:
   260 lemma RAG_child_pre:
   325   assumes vt: "vt s"
   261   assumes vt: "vt s"
   326   shows
   262   shows
   327   "(Th th, n) \<in> (depend s)^+ \<longrightarrow> (\<forall> th'. n = (Th th') \<longrightarrow> (Th th, Th th') \<in> (child s)^+)" (is "?P n")
   263   "(Th th, n) \<in> (RAG s)^+ \<longrightarrow> (\<forall> th'. n = (Th th') \<longrightarrow> (Th th, Th th') \<in> (child s)^+)" (is "?P n")
   328 proof -
   264 proof -
   329   from wf_trancl[OF wf_depend[OF vt]]
   265   from wf_trancl[OF wf_RAG[OF vt]]
   330   have wf: "wf ((depend s)^+)" .
   266   have wf: "wf ((RAG s)^+)" .
   331   show ?thesis
   267   show ?thesis
   332   proof(rule wf_induct[OF wf, of ?P], clarsimp)
   268   proof(rule wf_induct[OF wf, of ?P], clarsimp)
   333     fix th'
   269     fix th'
   334     assume ih[rule_format]: "\<forall>y. (y, Th th') \<in> (depend s)\<^sup>+ \<longrightarrow>
   270     assume ih[rule_format]: "\<forall>y. (y, Th th') \<in> (RAG s)\<^sup>+ \<longrightarrow>
   335                (Th th, y) \<in> (depend s)\<^sup>+ \<longrightarrow> (\<forall>th'. y = Th th' \<longrightarrow> (Th th, Th th') \<in> (child s)\<^sup>+)"
   271                (Th th, y) \<in> (RAG s)\<^sup>+ \<longrightarrow> (\<forall>th'. y = Th th' \<longrightarrow> (Th th, Th th') \<in> (child s)\<^sup>+)"
   336     and h: "(Th th, Th th') \<in> (depend s)\<^sup>+"
   272     and h: "(Th th, Th th') \<in> (RAG s)\<^sup>+"
   337     show "(Th th, Th th') \<in> (child s)\<^sup>+"
   273     show "(Th th, Th th') \<in> (child s)\<^sup>+"
   338     proof -
   274     proof -
   339       from depend_children[OF h]
   275       from RAG_children[OF h]
   340       have "th \<in> children s th' \<or> (\<exists>th3. th3 \<in> children s th' \<and> (Th th, Th th3) \<in> (depend s)\<^sup>+)" .
   276       have "th \<in> children s th' \<or> (\<exists>th3. th3 \<in> children s th' \<and> (Th th, Th th3) \<in> (RAG s)\<^sup>+)" .
   341       thus ?thesis
   277       thus ?thesis
   342       proof
   278       proof
   343         assume "th \<in> children s th'"
   279         assume "th \<in> children s th'"
   344         thus "(Th th, Th th') \<in> (child s)\<^sup>+" by (auto simp:children_def)
   280         thus "(Th th, Th th') \<in> (child s)\<^sup>+" by (auto simp:children_def)
   345       next
   281       next
   346         assume "\<exists>th3. th3 \<in> children s th' \<and> (Th th, Th th3) \<in> (depend s)\<^sup>+"
   282         assume "\<exists>th3. th3 \<in> children s th' \<and> (Th th, Th th3) \<in> (RAG s)\<^sup>+"
   347         then obtain th3 where th3_in: "th3 \<in> children s th'" 
   283         then obtain th3 where th3_in: "th3 \<in> children s th'" 
   348           and th_dp: "(Th th, Th th3) \<in> (depend s)\<^sup>+" by auto
   284           and th_dp: "(Th th, Th th3) \<in> (RAG s)\<^sup>+" by auto
   349         from th3_in have "(Th th3, Th th') \<in> (depend s)^+" by (auto simp:children_def child_def)
   285         from th3_in have "(Th th3, Th th') \<in> (RAG s)^+" by (auto simp:children_def child_def)
   350         from ih[OF this th_dp, of th3] have "(Th th, Th th3) \<in> (child s)\<^sup>+" by simp
   286         from ih[OF this th_dp, of th3] have "(Th th, Th th3) \<in> (child s)\<^sup>+" by simp
   351         with th3_in show "(Th th, Th th') \<in> (child s)\<^sup>+" by (auto simp:children_def)
   287         with th3_in show "(Th th, Th th') \<in> (child s)\<^sup>+" by (auto simp:children_def)
   352       qed
   288       qed
   353     qed
   289     qed
   354   qed
   290   qed
   355 qed
   291 qed
   356 
   292 
   357 lemma depend_child: "\<lbrakk>vt s; (Th th, Th th') \<in> (depend s)^+\<rbrakk> \<Longrightarrow> (Th th, Th th') \<in> (child s)^+"
   293 lemma RAG_child: "\<lbrakk>vt s; (Th th, Th th') \<in> (RAG s)^+\<rbrakk> \<Longrightarrow> (Th th, Th th') \<in> (child s)^+"
   358   by (insert depend_child_pre, auto)
   294   by (insert RAG_child_pre, auto)
   359 
   295 
   360 lemma child_depend_p:
   296 lemma child_RAG_p:
   361   assumes "(n1, n2) \<in> (child s)^+"
   297   assumes "(n1, n2) \<in> (child s)^+"
   362   shows "(n1, n2) \<in> (depend s)^+"
   298   shows "(n1, n2) \<in> (RAG s)^+"
   363 proof -
   299 proof -
   364   from assms show ?thesis
   300   from assms show ?thesis
   365   proof(induct)
   301   proof(induct)
   366     case (base y)
   302     case (base y)
   367     with sub_child show ?case by auto
   303     with sub_child show ?case by auto
   368   next
   304   next
   369     case (step y z)
   305     case (step y z)
   370     assume "(y, z) \<in> child s"
   306     assume "(y, z) \<in> child s"
   371     with sub_child have "(y, z) \<in> (depend s)^+" by auto
   307     with sub_child have "(y, z) \<in> (RAG s)^+" by auto
   372     moreover have "(n1, y) \<in> (depend s)^+" by fact
   308     moreover have "(n1, y) \<in> (RAG s)^+" by fact
   373     ultimately show ?case by auto
   309     ultimately show ?case by auto
   374   qed
   310   qed
   375 qed
   311 qed
   376 
   312 
   377 lemma child_depend_eq: 
   313 lemma child_RAG_eq: 
   378   assumes vt: "vt s"
   314   assumes vt: "vt s"
   379   shows "(Th th1, Th th2) \<in> (child s)^+  \<longleftrightarrow> (Th th1, Th th2) \<in> (depend s)^+"
   315   shows "(Th th1, Th th2) \<in> (child s)^+  \<longleftrightarrow> (Th th1, Th th2) \<in> (RAG s)^+"
   380   by (auto intro: depend_child[OF vt] child_depend_p)
   316   by (auto intro: RAG_child[OF vt] child_RAG_p)
   381 
   317 
   382 lemma children_no_dep:
   318 lemma children_no_dep:
   383   fixes s th th1 th2 th3
   319   fixes s th th1 th2 th3
   384   assumes vt: "vt s"
   320   assumes vt: "vt s"
   385   and ch1: "(Th th1, Th th) \<in> child s"
   321   and ch1: "(Th th1, Th th) \<in> child s"
   386   and ch2: "(Th th2, Th th) \<in> child s"
   322   and ch2: "(Th th2, Th th) \<in> child s"
   387   and ch3: "(Th th1, Th th2) \<in> (depend s)^+"
   323   and ch3: "(Th th1, Th th2) \<in> (RAG s)^+"
   388   shows "False"
   324   shows "False"
   389 proof -
   325 proof -
   390   from depend_child[OF vt ch3]
   326   from RAG_child[OF vt ch3]
   391   have "(Th th1, Th th2) \<in> (child s)\<^sup>+" .
   327   have "(Th th1, Th th2) \<in> (child s)\<^sup>+" .
   392   thus ?thesis
   328   thus ?thesis
   393   proof(rule converse_tranclE)
   329   proof(rule converse_tranclE)
   394     assume "(Th th1, Th th2) \<in> child s"
   330     assume "(Th th1, Th th2) \<in> child s"
   395     from child_unique[OF vt ch1 this] have "th = th2" by simp
   331     from child_unique[OF vt ch1 this] have "th = th2" by simp
   410     qed
   346     qed
   411     ultimately show False by auto
   347     ultimately show False by auto
   412   qed
   348   qed
   413 qed
   349 qed
   414 
   350 
   415 lemma unique_depend_p:
   351 lemma unique_RAG_p:
   416   assumes vt: "vt s"
   352   assumes vt: "vt s"
   417   and dp1: "(n, n1) \<in> (depend s)^+"
   353   and dp1: "(n, n1) \<in> (RAG s)^+"
   418   and dp2: "(n, n2) \<in> (depend s)^+"
   354   and dp2: "(n, n2) \<in> (RAG s)^+"
   419   and neq: "n1 \<noteq> n2"
   355   and neq: "n1 \<noteq> n2"
   420   shows "(n1, n2) \<in> (depend s)^+ \<or> (n2, n1) \<in> (depend s)^+"
   356   shows "(n1, n2) \<in> (RAG s)^+ \<or> (n2, n1) \<in> (RAG s)^+"
   421 proof(rule unique_chain [OF _ dp1 dp2 neq])
   357 proof(rule unique_chain [OF _ dp1 dp2 neq])
   422   from unique_depend[OF vt]
   358   from unique_RAG[OF vt]
   423   show "\<And>a b c. \<lbrakk>(a, b) \<in> depend s; (a, c) \<in> depend s\<rbrakk> \<Longrightarrow> b = c" by auto
   359   show "\<And>a b c. \<lbrakk>(a, b) \<in> RAG s; (a, c) \<in> RAG s\<rbrakk> \<Longrightarrow> b = c" by auto
   424 qed
   360 qed
   425 
   361 
   426 lemma dependants_child_unique:
   362 lemma dependants_child_unique:
   427   fixes s th th1 th2 th3
   363   fixes s th th1 th2 th3
   428   assumes vt: "vt s"
   364   assumes vt: "vt s"
   431   and dp1: "th3 \<in> dependants s th1"
   367   and dp1: "th3 \<in> dependants s th1"
   432   and dp2: "th3 \<in> dependants s th2"
   368   and dp2: "th3 \<in> dependants s th2"
   433 shows "th1 = th2"
   369 shows "th1 = th2"
   434 proof -
   370 proof -
   435   { assume neq: "th1 \<noteq> th2"
   371   { assume neq: "th1 \<noteq> th2"
   436     from dp1 have dp1: "(Th th3, Th th1) \<in> (depend s)^+" 
   372     from dp1 have dp1: "(Th th3, Th th1) \<in> (RAG s)^+" 
   437       by (simp add:s_dependants_def eq_depend)
   373       by (simp add:s_dependants_def eq_RAG)
   438     from dp2 have dp2: "(Th th3, Th th2) \<in> (depend s)^+" 
   374     from dp2 have dp2: "(Th th3, Th th2) \<in> (RAG s)^+" 
   439       by (simp add:s_dependants_def eq_depend)
   375       by (simp add:s_dependants_def eq_RAG)
   440     from unique_depend_p[OF vt dp1 dp2] and neq
   376     from unique_RAG_p[OF vt dp1 dp2] and neq
   441     have "(Th th1, Th th2) \<in> (depend s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (depend s)\<^sup>+" by auto
   377     have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto
   442     hence False
   378     hence False
   443     proof
   379     proof
   444       assume "(Th th1, Th th2) \<in> (depend s)\<^sup>+ "
   380       assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ "
   445       from children_no_dep[OF vt ch1 ch2 this] show ?thesis .
   381       from children_no_dep[OF vt ch1 ch2 this] show ?thesis .
   446     next
   382     next
   447       assume " (Th th2, Th th1) \<in> (depend s)\<^sup>+"
   383       assume " (Th th2, Th th1) \<in> (RAG s)\<^sup>+"
   448       from children_no_dep[OF vt ch2 ch1 this] show ?thesis .
   384       from children_no_dep[OF vt ch2 ch1 this] show ?thesis .
   449     qed
   385     qed
   450   } thus ?thesis by auto
   386   } thus ?thesis by auto
   451 qed
   387 qed
   452 
   388 
   453 lemma depend_plus_elim:
   389 lemma RAG_plus_elim:
   454   assumes "vt s"
   390   assumes "vt s"
   455   fixes x
   391   fixes x
   456   assumes "(Th x, Th th) \<in> (depend (wq s))\<^sup>+"
   392   assumes "(Th x, Th th) \<in> (RAG (wq s))\<^sup>+"
   457   shows "\<exists>th'\<in>children s th. x = th' \<or> (Th x, Th th') \<in> (depend (wq s))\<^sup>+"
   393   shows "\<exists>th'\<in>children s th. x = th' \<or> (Th x, Th th') \<in> (RAG (wq s))\<^sup>+"
   458   using assms(2)[unfolded eq_depend, folded child_depend_eq[OF `vt s`]]
   394   using assms(2)[unfolded eq_RAG, folded child_RAG_eq[OF `vt s`]]
   459   apply (unfold children_def)
   395   apply (unfold children_def)
   460   by (metis assms(2) children_def depend_children eq_depend)
   396   by (metis assms(2) children_def RAG_children eq_RAG)
   461 
       
   462 lemma dependants_expand_pre: 
       
   463   assumes "vt s"
       
   464   shows "dependants (wq s) th = (\<Union> th' \<in> children s th. {th'} \<union> dependants (wq s) th')"
       
   465   apply (unfold cs_dependants_def)
       
   466   apply (auto elim!:depend_plus_elim[OF assms])
       
   467   apply (metis children_def eq_depend mem_Collect_eq set_mp sub_child)
       
   468   apply (unfold children_def, auto)
       
   469   apply (unfold eq_depend, fold  child_depend_eq[OF `vt s`])
       
   470   by (metis trancl.simps)
       
   471 
   397 
   472 lemma dependants_expand:
   398 lemma dependants_expand:
   473   assumes "vt s"
   399   assumes "vt s"
   474   shows "dependants (wq s) th = (\<Union> ((\<lambda> th. {th} \<union> dependants (wq s) th) ` (children s th)))"
   400   shows "dependants (wq s) th = (children s th) \<union> (\<Union>((dependants (wq s)) ` children s th))"
   475   apply (subst dependants_expand_pre[OF assms])
   401 apply(simp add: image_def)
   476   by simp
   402 unfolding cs_dependants_def
       
   403 apply(auto)
       
   404 apply (metis assms RAG_plus_elim mem_Collect_eq)
       
   405 apply (metis child_RAG_p children_def eq_RAG mem_Collect_eq r_into_trancl')
       
   406 by (metis assms child_RAG_eq children_def eq_RAG mem_Collect_eq trancl.trancl_into_trancl)
   477 
   407 
   478 lemma finite_children:
   408 lemma finite_children:
   479   assumes "vt s"
   409   assumes "vt s"
   480   shows "finite (children s th)"
   410   shows "finite (children s th)"
   481   using children_dependants dependants_threads[OF assms] finite_threads[OF assms]
   411   using children_dependants dependants_threads[OF assms] finite_threads[OF assms]
   485   assumes "vt s"
   415   assumes "vt s"
   486   shows "finite (dependants (wq s) th')"
   416   shows "finite (dependants (wq s) th')"
   487   using dependants_threads[OF assms] finite_threads[OF assms]
   417   using dependants_threads[OF assms] finite_threads[OF assms]
   488   by (metis rev_finite_subset)
   418   by (metis rev_finite_subset)
   489 
   419 
   490 lemma Max_insert:
       
   491   assumes "finite B"
       
   492   and  "B \<noteq> {}"
       
   493   shows "Max ({x} \<union> B) = max x (Max B)"
       
   494   by (metis Max_insert assms insert_is_Un)
       
   495 
       
   496 lemma dependands_expand2:
       
   497   assumes "vt s"
       
   498   shows "dependants (wq s) th = (children s th) \<union> (\<Union>((dependants (wq s)) ` children s th))"
       
   499   by (subst dependants_expand[OF assms]) (auto)
       
   500 
       
   501 abbreviation
   420 abbreviation
   502   "preceds s Ths \<equiv> {preced th s| th. th \<in> Ths}"
   421   "preceds s ths \<equiv> {preced th s| th. th \<in> ths}"
   503 
   422 
   504 lemma image_compr:
   423 abbreviation
   505   "f ` A = {f x | x. x \<in> A}"
   424   "cpreceds s ths \<equiv> (cp s) ` ths"
   506 by auto
       
   507 
   425 
   508 lemma Un_compr:
   426 lemma Un_compr:
   509   "{f th | th. R th \<or> Q th} = ({f th | th. R th} \<union> {f th' | th'. Q th'})"
   427   "{f th | th. R th \<or> Q th} = ({f th | th. R th} \<union> {f th' | th'. Q th'})"
   510 by auto
   428 by auto
   511 
   429 
   529 next
   447 next
   530   case False
   448   case False
   531   show ?thesis (is "?LHS = ?RHS")
   449   show ?thesis (is "?LHS = ?RHS")
   532   proof -
   450   proof -
   533     have eq_cp: "cp s = (\<lambda>th. Max (preceds s ({th} \<union> dependants (wq s) th)))"
   451     have eq_cp: "cp s = (\<lambda>th. Max (preceds s ({th} \<union> dependants (wq s) th)))"
   534       by (simp add: fun_eq_iff cp_eq_cpreced cpreced_def Un_compr image_compr[symmetric])
   452       by (simp add: fun_eq_iff cp_eq_cpreced cpreced_def Un_compr image_Collect[symmetric])
   535   
   453   
   536     have not_emptyness_facts[simp]: 
   454     have not_emptyness_facts[simp]: 
   537       "dependants (wq s) th \<noteq> {}" "children s th \<noteq> {}"
   455       "dependants (wq s) th \<noteq> {}" "children s th \<noteq> {}"
   538       using False dependands_expand2[OF assms] by(auto simp only: Un_empty)
   456       using False dependants_expand[OF assms] by(auto simp only: Un_empty)
   539 
   457 
   540     have finiteness_facts[simp]:
   458     have finiteness_facts[simp]:
   541       "\<And>th. finite (dependants (wq s) th)" "\<And>th. finite (children s th)"
   459       "\<And>th. finite (dependants (wq s) th)" "\<And>th. finite (children s th)"
   542       by (simp_all add: finite_dependants[OF `vt s`] finite_children[OF `vt s`])
   460       by (simp_all add: finite_dependants[OF `vt s`] finite_children[OF `vt s`])
   543 
   461 
   550       by (simp add: Max_Un)
   468       by (simp add: Max_Un)
   551 
   469 
   552     (* expanding dependants *)
   470     (* expanding dependants *)
   553     also have "\<dots> = max (Max {preced th s}) 
   471     also have "\<dots> = max (Max {preced th s}) 
   554       (Max (preceds s (children s th \<union> \<Union>(dependants (wq s) ` children s th))))"
   472       (Max (preceds s (children s th \<union> \<Union>(dependants (wq s) ` children s th))))"
   555       by (subst dependands_expand2[OF `vt s`]) (simp)
   473       by (subst dependants_expand[OF `vt s`]) (simp)
   556 
   474 
   557     (* moving out big Union *)
   475     (* moving out big Union *)
   558     also have "\<dots> = max (Max {preced th s})
   476     also have "\<dots> = max (Max {preced th s})
   559       (Max (preceds s (\<Union> ({children s th} \<union> (dependants (wq s) ` children s th)))))"  
   477       (Max (preceds s (\<Union> ({children s th} \<union> (dependants (wq s) ` children s th)))))"  
   560       by simp
   478       by simp
   600 proof -
   518 proof -
   601   from assms show ?thesis 
   519   from assms show ?thesis 
   602     by (unfold s_def, auto simp:preced_def)
   520     by (unfold s_def, auto simp:preced_def)
   603 qed
   521 qed
   604 
   522 
   605 lemma eq_dep: "depend s = depend s'"
   523 lemma eq_dep: "RAG s = RAG s'"
   606   by (unfold s_def depend_set_unchanged, auto)
   524   by (unfold s_def RAG_set_unchanged, auto)
   607 
   525 
   608 lemma eq_cp_pre:
   526 lemma eq_cp_pre:
   609   fixes th' 
   527   fixes th' 
   610   assumes neq_th: "th' \<noteq> th"
   528   assumes neq_th: "th' \<noteq> th"
   611   and nd: "th \<notin> dependants s th'"
   529   and nd: "th \<notin> dependants s th'"
   612   shows "cp s th' = cp s' th'"
   530   shows "cp s th' = cp s' th'"
   613   apply (unfold cp_eq_cpreced cpreced_def)
   531   apply (unfold cp_eq_cpreced cpreced_def)
   614 proof -
   532 proof -
   615   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
   533   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
   616     by (unfold cs_dependants_def, auto simp:eq_dep eq_depend)
   534     by (unfold cs_dependants_def, auto simp:eq_dep eq_RAG)
   617   moreover {
   535   moreover {
   618     fix th1 
   536     fix th1 
   619     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
   537     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
   620     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
   538     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
   621     hence "preced th1 s = preced th1 s'"
   539     hence "preced th1 s = preced th1 s'"
   624       with eq_preced[OF neq_th]
   542       with eq_preced[OF neq_th]
   625       show "preced th1 s = preced th1 s'" by simp
   543       show "preced th1 s = preced th1 s'" by simp
   626     next
   544     next
   627       assume "th1 \<in> dependants (wq s') th'"
   545       assume "th1 \<in> dependants (wq s') th'"
   628       with nd and eq_dp have "th1 \<noteq> th"
   546       with nd and eq_dp have "th1 \<noteq> th"
   629         by (auto simp:eq_depend cs_dependants_def s_dependants_def eq_dep)
   547         by (auto simp:eq_RAG cs_dependants_def s_dependants_def eq_dep)
   630       from eq_preced[OF this] show "preced th1 s = preced th1 s'" by simp
   548       from eq_preced[OF this] show "preced th1 s = preced th1 s'" by simp
   631     qed
   549     qed
   632   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
   550   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
   633                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
   551                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
   634     by (auto simp:image_def)
   552     by (auto simp:image_def)
   644   from step_back_step [OF vt_s[unfolded s_def]]
   562   from step_back_step [OF vt_s[unfolded s_def]]
   645   have "step s' (Set th prio)" .
   563   have "step s' (Set th prio)" .
   646   hence "th \<in> runing s'" by (cases, simp)
   564   hence "th \<in> runing s'" by (cases, simp)
   647   hence rd_th: "th \<in> readys s'" 
   565   hence rd_th: "th \<in> readys s'" 
   648     by (simp add:readys_def runing_def)
   566     by (simp add:readys_def runing_def)
   649   from h have "(Th th, Th th') \<in> (depend s')\<^sup>+"
   567   from h have "(Th th, Th th') \<in> (RAG s')\<^sup>+"
   650     by (unfold s_dependants_def, unfold eq_depend, unfold eq_dep, auto)
   568     by (unfold s_dependants_def, unfold eq_RAG, unfold eq_dep, auto)
   651   from tranclD[OF this]
   569   from tranclD[OF this]
   652   obtain z where "(Th th, z) \<in> depend s'" by auto
   570   obtain z where "(Th th, z) \<in> RAG s'" by auto
   653   with rd_th show "False"
   571   with rd_th show "False"
   654     apply (case_tac z, auto simp:readys_def s_waiting_def s_depend_def s_waiting_def cs_waiting_def)
   572     apply (case_tac z, auto simp:readys_def s_waiting_def s_RAG_def s_waiting_def cs_waiting_def)
   655     by (fold wq_def, blast)
   573     by (fold wq_def, blast)
   656 qed
   574 qed
   657 
   575 
   658 (* Result improved *)
   576 (* Result improved *)
   659 lemma eq_cp:
   577 lemma eq_cp:
   671   and dp2: "th' \<in> dependants s th''"
   589   and dp2: "th' \<in> dependants s th''"
   672   and eq_cps: "cp s th' = cp s' th'"
   590   and eq_cps: "cp s th' = cp s' th'"
   673   shows "cp s th'' = cp s' th''"
   591   shows "cp s th'' = cp s' th''"
   674 proof -
   592 proof -
   675   from dp2
   593   from dp2
   676   have "(Th th', Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependants_def)
   594   have "(Th th', Th th'') \<in> (RAG (wq s))\<^sup>+" by (simp add:s_dependants_def)
   677   from depend_child[OF vt_s this[unfolded eq_depend]]
   595   from RAG_child[OF vt_s this[unfolded eq_RAG]]
   678   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
   596   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
   679   moreover { fix n th''
   597   moreover { fix n th''
   680     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   598     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   681                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   599                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   682     proof(erule trancl_induct, auto)
   600     proof(erule trancl_induct, auto)
   684       assume y_ch: "(y, Th th'') \<in> child s"
   602       assume y_ch: "(y, Th th'') \<in> child s"
   685         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
   603         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
   686         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
   604         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
   687       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
   605       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
   688       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
   606       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
   689       from dp1 have "(Th th, Th th') \<in> (depend s)^+" by (auto simp:s_dependants_def eq_depend)
   607       from dp1 have "(Th th, Th th') \<in> (RAG s)^+" by (auto simp:s_dependants_def eq_RAG)
   690       moreover from child_depend_p[OF ch'] and eq_y
   608       moreover from child_RAG_p[OF ch'] and eq_y
   691       have "(Th th', Th thy) \<in> (depend s)^+" by simp
   609       have "(Th th', Th thy) \<in> (RAG s)^+" by simp
   692       ultimately have dp_thy: "(Th th, Th thy) \<in> (depend s)^+" by auto
   610       ultimately have dp_thy: "(Th th, Th thy) \<in> (RAG s)^+" by auto
   693       show "cp s th'' = cp s' th''"
   611       show "cp s th'' = cp s' th''"
   694         apply (subst cp_rec[OF vt_s])
   612         apply (subst cp_rec[OF vt_s])
   695       proof -
   613       proof -
   696         have "preced th'' s = preced th'' s'"
   614         have "preced th'' s = preced th'' s'"
   697         proof(rule eq_preced)
   615         proof(rule eq_preced)
   698           show "th'' \<noteq> th"
   616           show "th'' \<noteq> th"
   699           proof
   617           proof
   700             assume "th'' = th"
   618             assume "th'' = th"
   701             with dp_thy y_ch[unfolded eq_y] 
   619             with dp_thy y_ch[unfolded eq_y] 
   702             have "(Th th, Th th) \<in> (depend s)^+"
   620             have "(Th th, Th th) \<in> (RAG s)^+"
   703               by (auto simp:child_def)
   621               by (auto simp:child_def)
   704             with wf_trancl[OF wf_depend[OF vt_s]] 
   622             with wf_trancl[OF wf_RAG[OF vt_s]] 
   705             show False by auto
   623             show False by auto
   706           qed
   624           qed
   707         qed
   625         qed
   708         moreover { 
   626         moreover { 
   709           fix th1
   627           fix th1
   715           next
   633           next
   716             case False
   634             case False
   717             have neq_th1: "th1 \<noteq> th"
   635             have neq_th1: "th1 \<noteq> th"
   718             proof
   636             proof
   719               assume eq_th1: "th1 = th"
   637               assume eq_th1: "th1 = th"
   720               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
   638               with dp_thy have "(Th th1, Th thy) \<in> (RAG s)^+" by simp
   721               from children_no_dep[OF vt_s _ _ this] and 
   639               from children_no_dep[OF vt_s _ _ this] and 
   722               th1_in y_ch eq_y show False by (auto simp:children_def)
   640               th1_in y_ch eq_y show False by (auto simp:children_def)
   723             qed
   641             qed
   724             have "th \<notin> dependants s th1"
   642             have "th \<notin> dependants s th1"
   725             proof
   643             proof
   726               assume h:"th \<in> dependants s th1"
   644               assume h:"th \<in> dependants s th1"
   727               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_depend)
   645               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_RAG)
   728               from dependants_child_unique[OF vt_s _ _ h this]
   646               from dependants_child_unique[OF vt_s _ _ h this]
   729               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   647               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   730               with False show False by auto
   648               with False show False by auto
   731             qed
   649             qed
   732             from eq_cp_pre[OF neq_th1 this]
   650             from eq_cp_pre[OF neq_th1 this]
   734           qed
   652           qed
   735         }
   653         }
   736         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   654         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   737           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   655           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   738         moreover have "children s th'' = children s' th''"
   656         moreover have "children s th'' = children s' th''"
   739           by (unfold children_def child_def s_def depend_set_unchanged, simp)
   657           by (unfold children_def child_def s_def RAG_set_unchanged, simp)
   740         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   658         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   741           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   659           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   742       qed
   660       qed
   743     next
   661     next
   744       fix th''
   662       fix th''
   750         proof(rule eq_preced)
   668         proof(rule eq_preced)
   751           show "th'' \<noteq> th"
   669           show "th'' \<noteq> th"
   752           proof
   670           proof
   753             assume "th'' = th"
   671             assume "th'' = th"
   754             with dp1 dp'
   672             with dp1 dp'
   755             have "(Th th, Th th) \<in> (depend s)^+"
   673             have "(Th th, Th th) \<in> (RAG s)^+"
   756               by (auto simp:child_def s_dependants_def eq_depend)
   674               by (auto simp:child_def s_dependants_def eq_RAG)
   757             with wf_trancl[OF wf_depend[OF vt_s]] 
   675             with wf_trancl[OF wf_RAG[OF vt_s]] 
   758             show False by auto
   676             show False by auto
   759           qed
   677           qed
   760         qed
   678         qed
   761         moreover { 
   679         moreover { 
   762           fix th1
   680           fix th1
   768           next
   686           next
   769             case False
   687             case False
   770             have neq_th1: "th1 \<noteq> th"
   688             have neq_th1: "th1 \<noteq> th"
   771             proof
   689             proof
   772               assume eq_th1: "th1 = th"
   690               assume eq_th1: "th1 = th"
   773               with dp1 have "(Th th1, Th th') \<in> (depend s)^+" 
   691               with dp1 have "(Th th1, Th th') \<in> (RAG s)^+" 
   774                 by (auto simp:s_dependants_def eq_depend)
   692                 by (auto simp:s_dependants_def eq_RAG)
   775               from children_no_dep[OF vt_s _ _ this]
   693               from children_no_dep[OF vt_s _ _ this]
   776               th1_in dp'
   694               th1_in dp'
   777               show False by (auto simp:children_def)
   695               show False by (auto simp:children_def)
   778             qed
   696             qed
   779             thus ?thesis
   697             thus ?thesis
   790           qed
   708           qed
   791         }
   709         }
   792         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   710         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   793           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   711           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   794         moreover have "children s th'' = children s' th''"
   712         moreover have "children s th'' = children s' th''"
   795           by (unfold children_def child_def s_def depend_set_unchanged, simp)
   713           by (unfold children_def child_def s_def RAG_set_unchanged, simp)
   796         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   714         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   797           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   715           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   798       qed     
   716       qed     
   799     qed
   717     qed
   800   }
   718   }
   806   assumes dp: "th \<in> dependants s th''"
   724   assumes dp: "th \<in> dependants s th''"
   807   and eq_cps: "cp s th = cp s' th"
   725   and eq_cps: "cp s th = cp s' th"
   808   shows "cp s th'' = cp s' th''"
   726   shows "cp s th'' = cp s' th''"
   809 proof -
   727 proof -
   810   from dp
   728   from dp
   811   have "(Th th, Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependants_def)
   729   have "(Th th, Th th'') \<in> (RAG (wq s))\<^sup>+" by (simp add:s_dependants_def)
   812   from depend_child[OF vt_s this[unfolded eq_depend]]
   730   from RAG_child[OF vt_s this[unfolded eq_RAG]]
   813   have ch_th': "(Th th, Th th'') \<in> (child s)\<^sup>+" .
   731   have ch_th': "(Th th, Th th'') \<in> (child s)\<^sup>+" .
   814   moreover { fix n th''
   732   moreover { fix n th''
   815     have "\<lbrakk>(Th th, n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   733     have "\<lbrakk>(Th th, n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   816                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   734                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   817     proof(erule trancl_induct, auto)
   735     proof(erule trancl_induct, auto)
   819       assume y_ch: "(y, Th th'') \<in> child s"
   737       assume y_ch: "(y, Th th'') \<in> child s"
   820         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
   738         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
   821         and ch': "(Th th, y) \<in> (child s)\<^sup>+"
   739         and ch': "(Th th, y) \<in> (child s)\<^sup>+"
   822       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
   740       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
   823       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
   741       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
   824       from child_depend_p[OF ch'] and eq_y
   742       from child_RAG_p[OF ch'] and eq_y
   825       have dp_thy: "(Th th, Th thy) \<in> (depend s)^+" by simp
   743       have dp_thy: "(Th th, Th thy) \<in> (RAG s)^+" by simp
   826       show "cp s th'' = cp s' th''"
   744       show "cp s th'' = cp s' th''"
   827         apply (subst cp_rec[OF vt_s])
   745         apply (subst cp_rec[OF vt_s])
   828       proof -
   746       proof -
   829         have "preced th'' s = preced th'' s'"
   747         have "preced th'' s = preced th'' s'"
   830         proof(rule eq_preced)
   748         proof(rule eq_preced)
   831           show "th'' \<noteq> th"
   749           show "th'' \<noteq> th"
   832           proof
   750           proof
   833             assume "th'' = th"
   751             assume "th'' = th"
   834             with dp_thy y_ch[unfolded eq_y] 
   752             with dp_thy y_ch[unfolded eq_y] 
   835             have "(Th th, Th th) \<in> (depend s)^+"
   753             have "(Th th, Th th) \<in> (RAG s)^+"
   836               by (auto simp:child_def)
   754               by (auto simp:child_def)
   837             with wf_trancl[OF wf_depend[OF vt_s]] 
   755             with wf_trancl[OF wf_RAG[OF vt_s]] 
   838             show False by auto
   756             show False by auto
   839           qed
   757           qed
   840         qed
   758         qed
   841         moreover { 
   759         moreover { 
   842           fix th1
   760           fix th1
   848           next
   766           next
   849             case False
   767             case False
   850             have neq_th1: "th1 \<noteq> th"
   768             have neq_th1: "th1 \<noteq> th"
   851             proof
   769             proof
   852               assume eq_th1: "th1 = th"
   770               assume eq_th1: "th1 = th"
   853               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
   771               with dp_thy have "(Th th1, Th thy) \<in> (RAG s)^+" by simp
   854               from children_no_dep[OF vt_s _ _ this] and 
   772               from children_no_dep[OF vt_s _ _ this] and 
   855               th1_in y_ch eq_y show False by (auto simp:children_def)
   773               th1_in y_ch eq_y show False by (auto simp:children_def)
   856             qed
   774             qed
   857             have "th \<notin> dependants s th1"
   775             have "th \<notin> dependants s th1"
   858             proof
   776             proof
   859               assume h:"th \<in> dependants s th1"
   777               assume h:"th \<in> dependants s th1"
   860               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_depend)
   778               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_RAG)
   861               from dependants_child_unique[OF vt_s _ _ h this]
   779               from dependants_child_unique[OF vt_s _ _ h this]
   862               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   780               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   863               with False show False by auto
   781               with False show False by auto
   864             qed
   782             qed
   865             from eq_cp_pre[OF neq_th1 this]
   783             from eq_cp_pre[OF neq_th1 this]
   867           qed
   785           qed
   868         }
   786         }
   869         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   787         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   870           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   788           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   871         moreover have "children s th'' = children s' th''"
   789         moreover have "children s th'' = children s' th''"
   872           by (unfold children_def child_def s_def depend_set_unchanged, simp)
   790           by (unfold children_def child_def s_def RAG_set_unchanged, simp)
   873         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   791         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   874           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   792           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   875       qed
   793       qed
   876     next
   794     next
   877       fix th''
   795       fix th''
   883         proof(rule eq_preced)
   801         proof(rule eq_preced)
   884           show "th'' \<noteq> th"
   802           show "th'' \<noteq> th"
   885           proof
   803           proof
   886             assume "th'' = th"
   804             assume "th'' = th"
   887             with dp dp'
   805             with dp dp'
   888             have "(Th th, Th th) \<in> (depend s)^+"
   806             have "(Th th, Th th) \<in> (RAG s)^+"
   889               by (auto simp:child_def s_dependants_def eq_depend)
   807               by (auto simp:child_def s_dependants_def eq_RAG)
   890             with wf_trancl[OF wf_depend[OF vt_s]] 
   808             with wf_trancl[OF wf_RAG[OF vt_s]] 
   891             show False by auto
   809             show False by auto
   892           qed
   810           qed
   893         qed
   811         qed
   894         moreover { 
   812         moreover { 
   895           fix th1
   813           fix th1
   904             thus ?thesis
   822             thus ?thesis
   905             proof(rule eq_cp_pre)
   823             proof(rule eq_cp_pre)
   906               show "th \<notin> dependants s th1"
   824               show "th \<notin> dependants s th1"
   907               proof
   825               proof
   908                 assume "th \<in> dependants s th1"
   826                 assume "th \<in> dependants s th1"
   909                 hence "(Th th, Th th1) \<in> (depend s)^+" by (auto simp:s_dependants_def eq_depend)
   827                 hence "(Th th, Th th1) \<in> (RAG s)^+" by (auto simp:s_dependants_def eq_RAG)
   910                 from children_no_dep[OF vt_s _ _ this]
   828                 from children_no_dep[OF vt_s _ _ this]
   911                 and th1_in dp' show False
   829                 and th1_in dp' show False
   912                   by (auto simp:children_def)
   830                   by (auto simp:children_def)
   913               qed
   831               qed
   914             qed
   832             qed
   915           qed
   833           qed
   916         }
   834         }
   917         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   835         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
   918           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   836           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
   919         moreover have "children s th'' = children s' th''"
   837         moreover have "children s th'' = children s' th''"
   920           by (unfold children_def child_def s_def depend_set_unchanged, simp)
   838           by (unfold children_def child_def s_def RAG_set_unchanged, simp)
   921         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   839         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
   922           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   840           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
   923       qed     
   841       qed     
   924     qed
   842     qed
   925   }
   843   }
   996   assumes nt: "next_th s' th cs th'"
   914   assumes nt: "next_th s' th cs th'"
   997 
   915 
   998 context step_v_cps_nt
   916 context step_v_cps_nt
   999 begin
   917 begin
  1000 
   918 
  1001 lemma depend_s:
   919 lemma RAG_s:
  1002   "depend s = (depend s' - {(Cs cs, Th th), (Th th', Cs cs)}) \<union>
   920   "RAG s = (RAG s' - {(Cs cs, Th th), (Th th', Cs cs)}) \<union>
  1003                                          {(Cs cs, Th th')}"
   921                                          {(Cs cs, Th th')}"
  1004 proof -
   922 proof -
  1005   from step_depend_v[OF vt_s[unfolded s_def], folded s_def]
   923   from step_RAG_v[OF vt_s[unfolded s_def], folded s_def]
  1006     and nt show ?thesis  by (auto intro:next_th_unique)
   924     and nt show ?thesis  by (auto intro:next_th_unique)
  1007 qed
   925 qed
  1008 
   926 
  1009 lemma dependants_kept:
   927 lemma dependants_kept:
  1010   fixes th''
   928   fixes th''
  1012   and neq2: "th'' \<noteq> th'"
   930   and neq2: "th'' \<noteq> th'"
  1013   shows "dependants (wq s) th'' = dependants (wq s') th''"
   931   shows "dependants (wq s) th'' = dependants (wq s') th''"
  1014 proof(auto)
   932 proof(auto)
  1015   fix x
   933   fix x
  1016   assume "x \<in> dependants (wq s) th''"
   934   assume "x \<in> dependants (wq s) th''"
  1017   hence dp: "(Th x, Th th'') \<in> (depend s)^+"
   935   hence dp: "(Th x, Th th'') \<in> (RAG s)^+"
  1018     by (auto simp:cs_dependants_def eq_depend)
   936     by (auto simp:cs_dependants_def eq_RAG)
  1019   { fix n
   937   { fix n
  1020     have "(n, Th th'') \<in> (depend s)^+ \<Longrightarrow>  (n, Th th'') \<in> (depend s')^+"
   938     have "(n, Th th'') \<in> (RAG s)^+ \<Longrightarrow>  (n, Th th'') \<in> (RAG s')^+"
  1021     proof(induct rule:converse_trancl_induct)
   939     proof(induct rule:converse_trancl_induct)
  1022       fix y 
   940       fix y 
  1023       assume "(y, Th th'') \<in> depend s"
   941       assume "(y, Th th'') \<in> RAG s"
  1024       with depend_s neq1 neq2
   942       with RAG_s neq1 neq2
  1025       have "(y, Th th'') \<in> depend s'" by auto
   943       have "(y, Th th'') \<in> RAG s'" by auto
  1026       thus "(y, Th th'') \<in> (depend s')\<^sup>+" by auto
   944       thus "(y, Th th'') \<in> (RAG s')\<^sup>+" by auto
  1027     next
   945     next
  1028       fix y z 
   946       fix y z 
  1029       assume yz: "(y, z) \<in> depend s"
   947       assume yz: "(y, z) \<in> RAG s"
  1030         and ztp: "(z, Th th'') \<in> (depend s)\<^sup>+"
   948         and ztp: "(z, Th th'') \<in> (RAG s)\<^sup>+"
  1031         and ztp': "(z, Th th'') \<in> (depend s')\<^sup>+"
   949         and ztp': "(z, Th th'') \<in> (RAG s')\<^sup>+"
  1032       have "y \<noteq> Cs cs \<and> y \<noteq> Th th'"
   950       have "y \<noteq> Cs cs \<and> y \<noteq> Th th'"
  1033       proof
   951       proof
  1034         show "y \<noteq> Cs cs"
   952         show "y \<noteq> Cs cs"
  1035         proof
   953         proof
  1036           assume eq_y: "y = Cs cs"
   954           assume eq_y: "y = Cs cs"
  1037           with yz have dp_yz: "(Cs cs, z) \<in> depend s" by simp
   955           with yz have dp_yz: "(Cs cs, z) \<in> RAG s" by simp
  1038           from depend_s
   956           from RAG_s
  1039           have cst': "(Cs cs, Th th') \<in> depend s" by simp
   957           have cst': "(Cs cs, Th th') \<in> RAG s" by simp
  1040           from unique_depend[OF vt_s this dp_yz] 
   958           from unique_RAG[OF vt_s this dp_yz] 
  1041           have eq_z: "z = Th th'" by simp
   959           have eq_z: "z = Th th'" by simp
  1042           with ztp have "(Th th', Th th'') \<in> (depend s)^+" by simp
   960           with ztp have "(Th th', Th th'') \<in> (RAG s)^+" by simp
  1043           from converse_tranclE[OF this]
   961           from converse_tranclE[OF this]
  1044           obtain cs' where dp'': "(Th th', Cs cs') \<in> depend s"
   962           obtain cs' where dp'': "(Th th', Cs cs') \<in> RAG s"
  1045             by (auto simp:s_depend_def)
   963             by (auto simp:s_RAG_def)
  1046           with depend_s have dp': "(Th th', Cs cs') \<in> depend s'" by auto
   964           with RAG_s have dp': "(Th th', Cs cs') \<in> RAG s'" by auto
  1047           from dp'' eq_y yz eq_z have "(Cs cs, Cs cs') \<in> (depend s)^+" by auto
   965           from dp'' eq_y yz eq_z have "(Cs cs, Cs cs') \<in> (RAG s)^+" by auto
  1048           moreover have "cs' = cs"
   966           moreover have "cs' = cs"
  1049           proof -
   967           proof -
  1050             from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
   968             from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
  1051             have "(Th th', Cs cs) \<in> depend s'"
   969             have "(Th th', Cs cs) \<in> RAG s'"
  1052               by (auto simp:s_waiting_def wq_def s_depend_def cs_waiting_def)
   970               by (auto simp:s_waiting_def wq_def s_RAG_def cs_waiting_def)
  1053             from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this dp']
   971             from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] this dp']
  1054             show ?thesis by simp
   972             show ?thesis by simp
  1055           qed
   973           qed
  1056           ultimately have "(Cs cs, Cs cs) \<in> (depend s)^+" by simp
   974           ultimately have "(Cs cs, Cs cs) \<in> (RAG s)^+" by simp
  1057           moreover note wf_trancl[OF wf_depend[OF vt_s]]
   975           moreover note wf_trancl[OF wf_RAG[OF vt_s]]
  1058           ultimately show False by auto
   976           ultimately show False by auto
  1059         qed
   977         qed
  1060       next
   978       next
  1061         show "y \<noteq> Th th'"
   979         show "y \<noteq> Th th'"
  1062         proof
   980         proof
  1063           assume eq_y: "y = Th th'"
   981           assume eq_y: "y = Th th'"
  1064           with yz have dps: "(Th th', z) \<in> depend s" by simp
   982           with yz have dps: "(Th th', z) \<in> RAG s" by simp
  1065           with depend_s have dps': "(Th th', z) \<in> depend s'" by auto
   983           with RAG_s have dps': "(Th th', z) \<in> RAG s'" by auto
  1066           have "z = Cs cs"
   984           have "z = Cs cs"
  1067           proof -
   985           proof -
  1068             from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
   986             from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
  1069             have "(Th th', Cs cs) \<in> depend s'"
   987             have "(Th th', Cs cs) \<in> RAG s'"
  1070               by (auto simp:s_waiting_def wq_def s_depend_def cs_waiting_def)
   988               by (auto simp:s_waiting_def wq_def s_RAG_def cs_waiting_def)
  1071             from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] dps' this]
   989             from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] dps' this]
  1072             show ?thesis .
   990             show ?thesis .
  1073           qed
   991           qed
  1074           with dps depend_s show False by auto
   992           with dps RAG_s show False by auto
  1075         qed
   993         qed
  1076       qed
   994       qed
  1077       with depend_s yz have "(y, z) \<in> depend s'" by auto
   995       with RAG_s yz have "(y, z) \<in> RAG s'" by auto
  1078       with ztp'
   996       with ztp'
  1079       show "(y, Th th'') \<in> (depend s')\<^sup>+" by auto
   997       show "(y, Th th'') \<in> (RAG s')\<^sup>+" by auto
  1080     qed    
   998     qed    
  1081   }
   999   }
  1082   from this[OF dp]
  1000   from this[OF dp]
  1083   show "x \<in> dependants (wq s') th''" 
  1001   show "x \<in> dependants (wq s') th''" 
  1084     by (auto simp:cs_dependants_def eq_depend)
  1002     by (auto simp:cs_dependants_def eq_RAG)
  1085 next
  1003 next
  1086   fix x
  1004   fix x
  1087   assume "x \<in> dependants (wq s') th''"
  1005   assume "x \<in> dependants (wq s') th''"
  1088   hence dp: "(Th x, Th th'') \<in> (depend s')^+"
  1006   hence dp: "(Th x, Th th'') \<in> (RAG s')^+"
  1089     by (auto simp:cs_dependants_def eq_depend)
  1007     by (auto simp:cs_dependants_def eq_RAG)
  1090   { fix n
  1008   { fix n
  1091     have "(n, Th th'') \<in> (depend s')^+ \<Longrightarrow>  (n, Th th'') \<in> (depend s)^+"
  1009     have "(n, Th th'') \<in> (RAG s')^+ \<Longrightarrow>  (n, Th th'') \<in> (RAG s)^+"
  1092     proof(induct rule:converse_trancl_induct)
  1010     proof(induct rule:converse_trancl_induct)
  1093       fix y 
  1011       fix y 
  1094       assume "(y, Th th'') \<in> depend s'"
  1012       assume "(y, Th th'') \<in> RAG s'"
  1095       with depend_s neq1 neq2
  1013       with RAG_s neq1 neq2
  1096       have "(y, Th th'') \<in> depend s" by auto
  1014       have "(y, Th th'') \<in> RAG s" by auto
  1097       thus "(y, Th th'') \<in> (depend s)\<^sup>+" by auto
  1015       thus "(y, Th th'') \<in> (RAG s)\<^sup>+" by auto
  1098     next
  1016     next
  1099       fix y z 
  1017       fix y z 
  1100       assume yz: "(y, z) \<in> depend s'"
  1018       assume yz: "(y, z) \<in> RAG s'"
  1101         and ztp: "(z, Th th'') \<in> (depend s')\<^sup>+"
  1019         and ztp: "(z, Th th'') \<in> (RAG s')\<^sup>+"
  1102         and ztp': "(z, Th th'') \<in> (depend s)\<^sup>+"
  1020         and ztp': "(z, Th th'') \<in> (RAG s)\<^sup>+"
  1103       have "y \<noteq> Cs cs \<and> y \<noteq> Th th'"
  1021       have "y \<noteq> Cs cs \<and> y \<noteq> Th th'"
  1104       proof
  1022       proof
  1105         show "y \<noteq> Cs cs"
  1023         show "y \<noteq> Cs cs"
  1106         proof
  1024         proof
  1107           assume eq_y: "y = Cs cs"
  1025           assume eq_y: "y = Cs cs"
  1108           with yz have dp_yz: "(Cs cs, z) \<in> depend s'" by simp
  1026           with yz have dp_yz: "(Cs cs, z) \<in> RAG s'" by simp
  1109           from this have eq_z: "z = Th th"
  1027           from this have eq_z: "z = Th th"
  1110           proof -
  1028           proof -
  1111             from step_back_step[OF vt_s[unfolded s_def]]
  1029             from step_back_step[OF vt_s[unfolded s_def]]
  1112             have "(Cs cs, Th th) \<in> depend s'"
  1030             have "(Cs cs, Th th) \<in> RAG s'"
  1113               by(cases, auto simp: wq_def s_depend_def cs_holding_def s_holding_def)
  1031               by(cases, auto simp: wq_def s_RAG_def cs_holding_def s_holding_def)
  1114             from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this dp_yz]
  1032             from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] this dp_yz]
  1115             show ?thesis by simp
  1033             show ?thesis by simp
  1116           qed
  1034           qed
  1117           from converse_tranclE[OF ztp]
  1035           from converse_tranclE[OF ztp]
  1118           obtain u where "(z, u) \<in> depend s'" by auto
  1036           obtain u where "(z, u) \<in> RAG s'" by auto
  1119           moreover 
  1037           moreover 
  1120           from step_back_step[OF vt_s[unfolded s_def]]
  1038           from step_back_step[OF vt_s[unfolded s_def]]
  1121           have "th \<in> readys s'" by (cases, simp add:runing_def)
  1039           have "th \<in> readys s'" by (cases, simp add:runing_def)
  1122           moreover note eq_z
  1040           moreover note eq_z
  1123           ultimately show False 
  1041           ultimately show False 
  1124             by (auto simp:readys_def wq_def s_depend_def s_waiting_def cs_waiting_def)
  1042             by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
  1125         qed
  1043         qed
  1126       next
  1044       next
  1127         show "y \<noteq> Th th'"
  1045         show "y \<noteq> Th th'"
  1128         proof
  1046         proof
  1129           assume eq_y: "y = Th th'"
  1047           assume eq_y: "y = Th th'"
  1130           with yz have dps: "(Th th', z) \<in> depend s'" by simp
  1048           with yz have dps: "(Th th', z) \<in> RAG s'" by simp
  1131           have "z = Cs cs"
  1049           have "z = Cs cs"
  1132           proof -
  1050           proof -
  1133             from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
  1051             from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
  1134             have "(Th th', Cs cs) \<in> depend s'"
  1052             have "(Th th', Cs cs) \<in> RAG s'"
  1135               by (auto simp:s_waiting_def wq_def s_depend_def cs_waiting_def)
  1053               by (auto simp:s_waiting_def wq_def s_RAG_def cs_waiting_def)
  1136             from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] dps this]
  1054             from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] dps this]
  1137             show ?thesis .
  1055             show ?thesis .
  1138           qed
  1056           qed
  1139           with ztp have cs_i: "(Cs cs, Th th'') \<in>  (depend s')\<^sup>+" by simp
  1057           with ztp have cs_i: "(Cs cs, Th th'') \<in>  (RAG s')\<^sup>+" by simp
  1140           from step_back_step[OF vt_s[unfolded s_def]]
  1058           from step_back_step[OF vt_s[unfolded s_def]]
  1141           have cs_th: "(Cs cs, Th th) \<in> depend s'"
  1059           have cs_th: "(Cs cs, Th th) \<in> RAG s'"
  1142             by(cases, auto simp: s_depend_def wq_def cs_holding_def s_holding_def)
  1060             by(cases, auto simp: s_RAG_def wq_def cs_holding_def s_holding_def)
  1143           have "(Cs cs, Th th'') \<notin>  depend s'"
  1061           have "(Cs cs, Th th'') \<notin>  RAG s'"
  1144           proof
  1062           proof
  1145             assume "(Cs cs, Th th'') \<in> depend s'"
  1063             assume "(Cs cs, Th th'') \<in> RAG s'"
  1146             from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this cs_th]
  1064             from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] this cs_th]
  1147             and neq1 show "False" by simp
  1065             and neq1 show "False" by simp
  1148           qed
  1066           qed
  1149           with converse_tranclE[OF cs_i]
  1067           with converse_tranclE[OF cs_i]
  1150           obtain u where cu: "(Cs cs, u) \<in> depend s'"  
  1068           obtain u where cu: "(Cs cs, u) \<in> RAG s'"  
  1151             and u_t: "(u, Th th'') \<in> (depend s')\<^sup>+" by auto
  1069             and u_t: "(u, Th th'') \<in> (RAG s')\<^sup>+" by auto
  1152           have "u = Th th"
  1070           have "u = Th th"
  1153           proof -
  1071           proof -
  1154             from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] cu cs_th]
  1072             from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] cu cs_th]
  1155             show ?thesis .
  1073             show ?thesis .
  1156           qed
  1074           qed
  1157           with u_t have "(Th th, Th th'') \<in> (depend s')\<^sup>+" by simp
  1075           with u_t have "(Th th, Th th'') \<in> (RAG s')\<^sup>+" by simp
  1158           from converse_tranclE[OF this]
  1076           from converse_tranclE[OF this]
  1159           obtain v where "(Th th, v) \<in> (depend s')" by auto
  1077           obtain v where "(Th th, v) \<in> (RAG s')" by auto
  1160           moreover from step_back_step[OF vt_s[unfolded s_def]]
  1078           moreover from step_back_step[OF vt_s[unfolded s_def]]
  1161           have "th \<in> readys s'" by (cases, simp add:runing_def)
  1079           have "th \<in> readys s'" by (cases, simp add:runing_def)
  1162           ultimately show False 
  1080           ultimately show False 
  1163             by (auto simp:readys_def wq_def s_depend_def s_waiting_def cs_waiting_def)
  1081             by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
  1164         qed
  1082         qed
  1165       qed
  1083       qed
  1166       with depend_s yz have "(y, z) \<in> depend s" by auto
  1084       with RAG_s yz have "(y, z) \<in> RAG s" by auto
  1167       with ztp'
  1085       with ztp'
  1168       show "(y, Th th'') \<in> (depend s)\<^sup>+" by auto
  1086       show "(y, Th th'') \<in> (RAG s)\<^sup>+" by auto
  1169     qed    
  1087     qed    
  1170   }
  1088   }
  1171   from this[OF dp]
  1089   from this[OF dp]
  1172   show "x \<in> dependants (wq s) th''"
  1090   show "x \<in> dependants (wq s) th''"
  1173     by (auto simp:cs_dependants_def eq_depend)
  1091     by (auto simp:cs_dependants_def eq_RAG)
  1174 qed
  1092 qed
  1175 
  1093 
  1176 lemma cp_kept:
  1094 lemma cp_kept:
  1177   fixes th''
  1095   fixes th''
  1178   assumes neq1: "th'' \<noteq> th"
  1096   assumes neq1: "th'' \<noteq> th"
  1202   assumes nnt: "\<And> th'. (\<not> next_th s' th cs th')"
  1120   assumes nnt: "\<And> th'. (\<not> next_th s' th cs th')"
  1203 
  1121 
  1204 context step_v_cps_nnt
  1122 context step_v_cps_nnt
  1205 begin
  1123 begin
  1206 
  1124 
  1207 lemma nw_cs: "(Th th1, Cs cs) \<notin> depend s'"
  1125 lemma nw_cs: "(Th th1, Cs cs) \<notin> RAG s'"
  1208 proof
  1126 proof
  1209   assume "(Th th1, Cs cs) \<in> depend s'"
  1127   assume "(Th th1, Cs cs) \<in> RAG s'"
  1210   thus "False"
  1128   thus "False"
  1211     apply (auto simp:s_depend_def cs_waiting_def)
  1129     apply (auto simp:s_RAG_def cs_waiting_def)
  1212   proof -
  1130   proof -
  1213     assume h1: "th1 \<in> set (wq s' cs)"
  1131     assume h1: "th1 \<in> set (wq s' cs)"
  1214       and h2: "th1 \<noteq> hd (wq s' cs)"
  1132       and h2: "th1 \<noteq> hd (wq s' cs)"
  1215     from step_back_step[OF vt_s[unfolded s_def]]
  1133     from step_back_step[OF vt_s[unfolded s_def]]
  1216     show "False"
  1134     show "False"
  1227       with nnt show ?thesis by auto
  1145       with nnt show ?thesis by auto
  1228     qed
  1146     qed
  1229   qed
  1147   qed
  1230 qed
  1148 qed
  1231 
  1149 
  1232 lemma depend_s: "depend s = depend s' - {(Cs cs, Th th)}"
  1150 lemma RAG_s: "RAG s = RAG s' - {(Cs cs, Th th)}"
  1233 proof -
  1151 proof -
  1234   from nnt and  step_depend_v[OF vt_s[unfolded s_def], folded s_def]
  1152   from nnt and  step_RAG_v[OF vt_s[unfolded s_def], folded s_def]
  1235   show ?thesis by auto
  1153   show ?thesis by auto
  1236 qed
  1154 qed
  1237 
  1155 
  1238 lemma child_kept_left:
  1156 lemma child_kept_left:
  1239   assumes 
  1157   assumes 
  1242 proof -
  1160 proof -
  1243   from assms show ?thesis 
  1161   from assms show ?thesis 
  1244   proof(induct rule: converse_trancl_induct)
  1162   proof(induct rule: converse_trancl_induct)
  1245     case (base y)
  1163     case (base y)
  1246     from base obtain th1 cs1 th2
  1164     from base obtain th1 cs1 th2
  1247       where h1: "(Th th1, Cs cs1) \<in> depend s'"
  1165       where h1: "(Th th1, Cs cs1) \<in> RAG s'"
  1248       and h2: "(Cs cs1, Th th2) \<in> depend s'"
  1166       and h2: "(Cs cs1, Th th2) \<in> RAG s'"
  1249       and eq_y: "y = Th th1" and eq_n2: "n2 = Th th2"  by (auto simp:child_def)
  1167       and eq_y: "y = Th th1" and eq_n2: "n2 = Th th2"  by (auto simp:child_def)
  1250     have "cs1 \<noteq> cs"
  1168     have "cs1 \<noteq> cs"
  1251     proof
  1169     proof
  1252       assume eq_cs: "cs1 = cs"
  1170       assume eq_cs: "cs1 = cs"
  1253       with h1 have "(Th th1, Cs cs1) \<in> depend s'" by simp
  1171       with h1 have "(Th th1, Cs cs1) \<in> RAG s'" by simp
  1254       with nw_cs eq_cs show False by auto
  1172       with nw_cs eq_cs show False by auto
  1255     qed
  1173     qed
  1256     with h1 h2 depend_s have 
  1174     with h1 h2 RAG_s have 
  1257       h1': "(Th th1, Cs cs1) \<in> depend s" and
  1175       h1': "(Th th1, Cs cs1) \<in> RAG s" and
  1258       h2': "(Cs cs1, Th th2) \<in> depend s" by auto
  1176       h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
  1259     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1177     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1260     with eq_y eq_n2 have "(y, n2) \<in> child s" by simp
  1178     with eq_y eq_n2 have "(y, n2) \<in> child s" by simp
  1261     thus ?case by auto
  1179     thus ?case by auto
  1262   next
  1180   next
  1263     case (step y z)
  1181     case (step y z)
  1264     have "(y, z) \<in> child s'" by fact
  1182     have "(y, z) \<in> child s'" by fact
  1265     then obtain th1 cs1 th2
  1183     then obtain th1 cs1 th2
  1266       where h1: "(Th th1, Cs cs1) \<in> depend s'"
  1184       where h1: "(Th th1, Cs cs1) \<in> RAG s'"
  1267       and h2: "(Cs cs1, Th th2) \<in> depend s'"
  1185       and h2: "(Cs cs1, Th th2) \<in> RAG s'"
  1268       and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
  1186       and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
  1269     have "cs1 \<noteq> cs"
  1187     have "cs1 \<noteq> cs"
  1270     proof
  1188     proof
  1271       assume eq_cs: "cs1 = cs"
  1189       assume eq_cs: "cs1 = cs"
  1272       with h1 have "(Th th1, Cs cs1) \<in> depend s'" by simp
  1190       with h1 have "(Th th1, Cs cs1) \<in> RAG s'" by simp
  1273       with nw_cs eq_cs show False by auto
  1191       with nw_cs eq_cs show False by auto
  1274     qed
  1192     qed
  1275     with h1 h2 depend_s have 
  1193     with h1 h2 RAG_s have 
  1276       h1': "(Th th1, Cs cs1) \<in> depend s" and
  1194       h1': "(Th th1, Cs cs1) \<in> RAG s" and
  1277       h2': "(Cs cs1, Th th2) \<in> depend s" by auto
  1195       h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
  1278     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1196     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1279     with eq_y eq_z have "(y, z) \<in> child s" by simp
  1197     with eq_y eq_z have "(y, z) \<in> child s" by simp
  1280     moreover have "(z, n2) \<in> (child s)^+" by fact
  1198     moreover have "(z, n2) \<in> (child s)^+" by fact
  1281     ultimately show ?case by auto
  1199     ultimately show ?case by auto
  1282   qed
  1200   qed
  1288   shows "(n1, n2) \<in> (child s')^+"
  1206   shows "(n1, n2) \<in> (child s')^+"
  1289 proof -
  1207 proof -
  1290   from assms show ?thesis
  1208   from assms show ?thesis
  1291   proof(induct)
  1209   proof(induct)
  1292     case (base y)
  1210     case (base y)
  1293     from base and depend_s 
  1211     from base and RAG_s 
  1294     have "(n1, y) \<in> child s'"
  1212     have "(n1, y) \<in> child s'"
  1295       by (auto simp:child_def)
  1213       by (auto simp:child_def)
  1296     thus ?case by auto
  1214     thus ?case by auto
  1297   next
  1215   next
  1298     case (step y z)
  1216     case (step y z)
  1299     have "(y, z) \<in> child s" by fact
  1217     have "(y, z) \<in> child s" by fact
  1300     with depend_s have "(y, z) \<in> child s'"
  1218     with RAG_s have "(y, z) \<in> child s'"
  1301       by (auto simp:child_def)
  1219       by (auto simp:child_def)
  1302     moreover have "(n1, y) \<in> (child s')\<^sup>+" by fact
  1220     moreover have "(n1, y) \<in> (child s')\<^sup>+" by fact
  1303     ultimately show ?case by auto
  1221     ultimately show ?case by auto
  1304   qed
  1222   qed
  1305 qed
  1223 qed
  1311   fixes th' 
  1229   fixes th' 
  1312   shows "cp s th' = cp s' th'"
  1230   shows "cp s th' = cp s' th'"
  1313   apply (unfold cp_eq_cpreced cpreced_def)
  1231   apply (unfold cp_eq_cpreced cpreced_def)
  1314 proof -
  1232 proof -
  1315   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1233   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1316     apply (unfold cs_dependants_def, unfold eq_depend)
  1234     apply (unfold cs_dependants_def, unfold eq_RAG)
  1317   proof -
  1235   proof -
  1318     from eq_child
  1236     from eq_child
  1319     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1237     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1320       by simp
  1238       by simp
  1321     with child_depend_eq[OF vt_s] child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1239     with child_RAG_eq[OF vt_s] child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1322     show "\<And>th. {th'. (Th th', Th th) \<in> (depend s)\<^sup>+} = {th'. (Th th', Th th) \<in> (depend s')\<^sup>+}"
  1240     show "\<And>th. {th'. (Th th', Th th) \<in> (RAG s)\<^sup>+} = {th'. (Th th', Th th) \<in> (RAG s')\<^sup>+}"
  1323       by simp
  1241       by simp
  1324   qed
  1242   qed
  1325   moreover {
  1243   moreover {
  1326     fix th1 
  1244     fix th1 
  1327     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1245     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1355   assumes ee: "wq s' cs = []"
  1273   assumes ee: "wq s' cs = []"
  1356 
  1274 
  1357 context step_P_cps_e
  1275 context step_P_cps_e
  1358 begin
  1276 begin
  1359 
  1277 
  1360 lemma depend_s: "depend s = depend s' \<union> {(Cs cs, Th th)}"
  1278 lemma RAG_s: "RAG s = RAG s' \<union> {(Cs cs, Th th)}"
  1361 proof -
  1279 proof -
  1362   from ee and  step_depend_p[OF vt_s[unfolded s_def], folded s_def]
  1280   from ee and  step_RAG_p[OF vt_s[unfolded s_def], folded s_def]
  1363   show ?thesis by auto
  1281   show ?thesis by auto
  1364 qed
  1282 qed
  1365 
  1283 
  1366 lemma child_kept_left:
  1284 lemma child_kept_left:
  1367   assumes 
  1285   assumes 
  1370 proof -
  1288 proof -
  1371   from assms show ?thesis 
  1289   from assms show ?thesis 
  1372   proof(induct rule: converse_trancl_induct)
  1290   proof(induct rule: converse_trancl_induct)
  1373     case (base y)
  1291     case (base y)
  1374     from base obtain th1 cs1 th2
  1292     from base obtain th1 cs1 th2
  1375       where h1: "(Th th1, Cs cs1) \<in> depend s'"
  1293       where h1: "(Th th1, Cs cs1) \<in> RAG s'"
  1376       and h2: "(Cs cs1, Th th2) \<in> depend s'"
  1294       and h2: "(Cs cs1, Th th2) \<in> RAG s'"
  1377       and eq_y: "y = Th th1" and eq_n2: "n2 = Th th2"  by (auto simp:child_def)
  1295       and eq_y: "y = Th th1" and eq_n2: "n2 = Th th2"  by (auto simp:child_def)
  1378     have "cs1 \<noteq> cs"
  1296     have "cs1 \<noteq> cs"
  1379     proof
  1297     proof
  1380       assume eq_cs: "cs1 = cs"
  1298       assume eq_cs: "cs1 = cs"
  1381       with h1 have "(Th th1, Cs cs) \<in> depend s'" by simp
  1299       with h1 have "(Th th1, Cs cs) \<in> RAG s'" by simp
  1382       with ee show False
  1300       with ee show False
  1383         by (auto simp:s_depend_def cs_waiting_def)
  1301         by (auto simp:s_RAG_def cs_waiting_def)
  1384     qed
  1302     qed
  1385     with h1 h2 depend_s have 
  1303     with h1 h2 RAG_s have 
  1386       h1': "(Th th1, Cs cs1) \<in> depend s" and
  1304       h1': "(Th th1, Cs cs1) \<in> RAG s" and
  1387       h2': "(Cs cs1, Th th2) \<in> depend s" by auto
  1305       h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
  1388     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1306     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1389     with eq_y eq_n2 have "(y, n2) \<in> child s" by simp
  1307     with eq_y eq_n2 have "(y, n2) \<in> child s" by simp
  1390     thus ?case by auto
  1308     thus ?case by auto
  1391   next
  1309   next
  1392     case (step y z)
  1310     case (step y z)
  1393     have "(y, z) \<in> child s'" by fact
  1311     have "(y, z) \<in> child s'" by fact
  1394     then obtain th1 cs1 th2
  1312     then obtain th1 cs1 th2
  1395       where h1: "(Th th1, Cs cs1) \<in> depend s'"
  1313       where h1: "(Th th1, Cs cs1) \<in> RAG s'"
  1396       and h2: "(Cs cs1, Th th2) \<in> depend s'"
  1314       and h2: "(Cs cs1, Th th2) \<in> RAG s'"
  1397       and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
  1315       and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
  1398     have "cs1 \<noteq> cs"
  1316     have "cs1 \<noteq> cs"
  1399     proof
  1317     proof
  1400       assume eq_cs: "cs1 = cs"
  1318       assume eq_cs: "cs1 = cs"
  1401       with h1 have "(Th th1, Cs cs) \<in> depend s'" by simp
  1319       with h1 have "(Th th1, Cs cs) \<in> RAG s'" by simp
  1402       with ee show False 
  1320       with ee show False 
  1403         by (auto simp:s_depend_def cs_waiting_def)
  1321         by (auto simp:s_RAG_def cs_waiting_def)
  1404     qed
  1322     qed
  1405     with h1 h2 depend_s have 
  1323     with h1 h2 RAG_s have 
  1406       h1': "(Th th1, Cs cs1) \<in> depend s" and
  1324       h1': "(Th th1, Cs cs1) \<in> RAG s" and
  1407       h2': "(Cs cs1, Th th2) \<in> depend s" by auto
  1325       h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
  1408     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1326     hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
  1409     with eq_y eq_z have "(y, z) \<in> child s" by simp
  1327     with eq_y eq_z have "(y, z) \<in> child s" by simp
  1410     moreover have "(z, n2) \<in> (child s)^+" by fact
  1328     moreover have "(z, n2) \<in> (child s)^+" by fact
  1411     ultimately show ?case by auto
  1329     ultimately show ?case by auto
  1412   qed
  1330   qed
  1418   shows "(n1, n2) \<in> (child s')^+"
  1336   shows "(n1, n2) \<in> (child s')^+"
  1419 proof -
  1337 proof -
  1420   from assms show ?thesis
  1338   from assms show ?thesis
  1421   proof(induct)
  1339   proof(induct)
  1422     case (base y)
  1340     case (base y)
  1423     from base and depend_s
  1341     from base and RAG_s
  1424     have "(n1, y) \<in> child s'"
  1342     have "(n1, y) \<in> child s'"
  1425       apply (auto simp:child_def)
  1343       apply (auto simp:child_def)
  1426       proof -
  1344       proof -
  1427         fix th'
  1345         fix th'
  1428         assume "(Th th', Cs cs) \<in> depend s'"
  1346         assume "(Th th', Cs cs) \<in> RAG s'"
  1429         with ee have "False"
  1347         with ee have "False"
  1430           by (auto simp:s_depend_def cs_waiting_def)
  1348           by (auto simp:s_RAG_def cs_waiting_def)
  1431         thus "\<exists>cs. (Th th', Cs cs) \<in> depend s' \<and> (Cs cs, Th th) \<in> depend s'" by auto 
  1349         thus "\<exists>cs. (Th th', Cs cs) \<in> RAG s' \<and> (Cs cs, Th th) \<in> RAG s'" by auto 
  1432       qed
  1350       qed
  1433     thus ?case by auto
  1351     thus ?case by auto
  1434   next
  1352   next
  1435     case (step y z)
  1353     case (step y z)
  1436     have "(y, z) \<in> child s" by fact
  1354     have "(y, z) \<in> child s" by fact
  1437     with depend_s have "(y, z) \<in> child s'"
  1355     with RAG_s have "(y, z) \<in> child s'"
  1438       apply (auto simp:child_def)
  1356       apply (auto simp:child_def)
  1439       proof -
  1357       proof -
  1440         fix th'
  1358         fix th'
  1441         assume "(Th th', Cs cs) \<in> depend s'"
  1359         assume "(Th th', Cs cs) \<in> RAG s'"
  1442         with ee have "False"
  1360         with ee have "False"
  1443           by (auto simp:s_depend_def cs_waiting_def)
  1361           by (auto simp:s_RAG_def cs_waiting_def)
  1444         thus "\<exists>cs. (Th th', Cs cs) \<in> depend s' \<and> (Cs cs, Th th) \<in> depend s'" by auto 
  1362         thus "\<exists>cs. (Th th', Cs cs) \<in> RAG s' \<and> (Cs cs, Th th) \<in> RAG s'" by auto 
  1445       qed
  1363       qed
  1446     moreover have "(n1, y) \<in> (child s')\<^sup>+" by fact
  1364     moreover have "(n1, y) \<in> (child s')\<^sup>+" by fact
  1447     ultimately show ?case by auto
  1365     ultimately show ?case by auto
  1448   qed
  1366   qed
  1449 qed
  1367 qed
  1455   fixes th' 
  1373   fixes th' 
  1456   shows "cp s th' = cp s' th'"
  1374   shows "cp s th' = cp s' th'"
  1457   apply (unfold cp_eq_cpreced cpreced_def)
  1375   apply (unfold cp_eq_cpreced cpreced_def)
  1458 proof -
  1376 proof -
  1459   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1377   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1460     apply (unfold cs_dependants_def, unfold eq_depend)
  1378     apply (unfold cs_dependants_def, unfold eq_RAG)
  1461   proof -
  1379   proof -
  1462     from eq_child
  1380     from eq_child
  1463     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1381     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1464       by auto
  1382       by auto
  1465     with child_depend_eq[OF vt_s] child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1383     with child_RAG_eq[OF vt_s] child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1466     show "\<And>th. {th'. (Th th', Th th) \<in> (depend s)\<^sup>+} = {th'. (Th th', Th th) \<in> (depend s')\<^sup>+}"
  1384     show "\<And>th. {th'. (Th th', Th th) \<in> (RAG s)\<^sup>+} = {th'. (Th th', Th th) \<in> (RAG s')\<^sup>+}"
  1467       by simp
  1385       by simp
  1468   qed
  1386   qed
  1469   moreover {
  1387   moreover {
  1470     fix th1 
  1388     fix th1 
  1471     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1389     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1488 end
  1406 end
  1489 
  1407 
  1490 context step_P_cps_ne
  1408 context step_P_cps_ne
  1491 begin
  1409 begin
  1492 
  1410 
  1493 lemma depend_s: "depend s = depend s' \<union> {(Th th, Cs cs)}"
  1411 lemma RAG_s: "RAG s = RAG s' \<union> {(Th th, Cs cs)}"
  1494 proof -
  1412 proof -
  1495   from step_depend_p[OF vt_s[unfolded s_def]] and ne
  1413   from step_RAG_p[OF vt_s[unfolded s_def]] and ne
  1496   show ?thesis by (simp add:s_def)
  1414   show ?thesis by (simp add:s_def)
  1497 qed
  1415 qed
  1498 
  1416 
  1499 lemma eq_child_left:
  1417 lemma eq_child_left:
  1500   assumes nd: "(Th th, Th th') \<notin> (child s)^+"
  1418   assumes nd: "(Th th, Th th') \<notin> (child s)^+"
  1501   shows "(n1, Th th') \<in> (child s)^+ \<Longrightarrow> (n1, Th th') \<in> (child s')^+"
  1419   shows "(n1, Th th') \<in> (child s)^+ \<Longrightarrow> (n1, Th th') \<in> (child s')^+"
  1502 proof(induct rule:converse_trancl_induct)
  1420 proof(induct rule:converse_trancl_induct)
  1503   case (base y)
  1421   case (base y)
  1504   from base obtain th1 cs1
  1422   from base obtain th1 cs1
  1505     where h1: "(Th th1, Cs cs1) \<in> depend s"
  1423     where h1: "(Th th1, Cs cs1) \<in> RAG s"
  1506     and h2: "(Cs cs1, Th th') \<in> depend s"
  1424     and h2: "(Cs cs1, Th th') \<in> RAG s"
  1507     and eq_y: "y = Th th1"   by (auto simp:child_def)
  1425     and eq_y: "y = Th th1"   by (auto simp:child_def)
  1508   have "th1 \<noteq> th"
  1426   have "th1 \<noteq> th"
  1509   proof
  1427   proof
  1510     assume "th1 = th"
  1428     assume "th1 = th"
  1511     with base eq_y have "(Th th, Th th') \<in> child s" by simp
  1429     with base eq_y have "(Th th, Th th') \<in> child s" by simp
  1512     with nd show False by auto
  1430     with nd show False by auto
  1513   qed
  1431   qed
  1514   with h1 h2 depend_s 
  1432   with h1 h2 RAG_s 
  1515   have h1': "(Th th1, Cs cs1) \<in> depend s'" and 
  1433   have h1': "(Th th1, Cs cs1) \<in> RAG s'" and 
  1516        h2': "(Cs cs1, Th th') \<in> depend s'" by auto
  1434        h2': "(Cs cs1, Th th') \<in> RAG s'" by auto
  1517   with eq_y show ?case by (auto simp:child_def)
  1435   with eq_y show ?case by (auto simp:child_def)
  1518 next
  1436 next
  1519   case (step y z)
  1437   case (step y z)
  1520   have yz: "(y, z) \<in> child s" by fact
  1438   have yz: "(y, z) \<in> child s" by fact
  1521   then obtain th1 cs1 th2
  1439   then obtain th1 cs1 th2
  1522     where h1: "(Th th1, Cs cs1) \<in> depend s"
  1440     where h1: "(Th th1, Cs cs1) \<in> RAG s"
  1523     and h2: "(Cs cs1, Th th2) \<in> depend s"
  1441     and h2: "(Cs cs1, Th th2) \<in> RAG s"
  1524     and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
  1442     and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
  1525   have "th1 \<noteq> th"
  1443   have "th1 \<noteq> th"
  1526   proof
  1444   proof
  1527     assume "th1 = th"
  1445     assume "th1 = th"
  1528     with yz eq_y have "(Th th, z) \<in> child s" by simp
  1446     with yz eq_y have "(Th th, z) \<in> child s" by simp
  1529     moreover have "(z, Th th') \<in> (child s)^+" by fact
  1447     moreover have "(z, Th th') \<in> (child s)^+" by fact
  1530     ultimately have "(Th th, Th th') \<in> (child s)^+" by auto
  1448     ultimately have "(Th th, Th th') \<in> (child s)^+" by auto
  1531     with nd show False by auto
  1449     with nd show False by auto
  1532   qed
  1450   qed
  1533   with h1 h2 depend_s have h1': "(Th th1, Cs cs1) \<in> depend s'"
  1451   with h1 h2 RAG_s have h1': "(Th th1, Cs cs1) \<in> RAG s'"
  1534                        and h2': "(Cs cs1, Th th2) \<in> depend s'" by auto
  1452                        and h2': "(Cs cs1, Th th2) \<in> RAG s'" by auto
  1535   with eq_y eq_z have "(y, z) \<in> child s'" by (auto simp:child_def)
  1453   with eq_y eq_z have "(y, z) \<in> child s'" by (auto simp:child_def)
  1536   moreover have "(z, Th th') \<in> (child s')^+" by fact
  1454   moreover have "(z, Th th') \<in> (child s')^+" by fact
  1537   ultimately show ?case by auto
  1455   ultimately show ?case by auto
  1538 qed
  1456 qed
  1539 
  1457 
  1540 lemma eq_child_right:
  1458 lemma eq_child_right:
  1541   shows "(n1, Th th') \<in> (child s')^+ \<Longrightarrow> (n1, Th th') \<in> (child s)^+"
  1459   shows "(n1, Th th') \<in> (child s')^+ \<Longrightarrow> (n1, Th th') \<in> (child s)^+"
  1542 proof(induct rule:converse_trancl_induct)
  1460 proof(induct rule:converse_trancl_induct)
  1543   case (base y)
  1461   case (base y)
  1544   with depend_s show ?case by (auto simp:child_def)
  1462   with RAG_s show ?case by (auto simp:child_def)
  1545 next
  1463 next
  1546   case (step y z)
  1464   case (step y z)
  1547   have "(y, z) \<in> child s'" by fact
  1465   have "(y, z) \<in> child s'" by fact
  1548   with depend_s have "(y, z) \<in> child s" by (auto simp:child_def)
  1466   with RAG_s have "(y, z) \<in> child s" by (auto simp:child_def)
  1549   moreover have "(z, Th th') \<in> (child s)^+" by fact
  1467   moreover have "(z, Th th') \<in> (child s)^+" by fact
  1550   ultimately show ?case by auto
  1468   ultimately show ?case by auto
  1551 qed
  1469 qed
  1552 
  1470 
  1553 lemma eq_child:
  1471 lemma eq_child:
  1562   apply (unfold cp_eq_cpreced cpreced_def)
  1480   apply (unfold cp_eq_cpreced cpreced_def)
  1563 proof -
  1481 proof -
  1564   have nd': "(Th th, Th th') \<notin> (child s)^+"
  1482   have nd': "(Th th, Th th') \<notin> (child s)^+"
  1565   proof
  1483   proof
  1566     assume "(Th th, Th th') \<in> (child s)\<^sup>+"
  1484     assume "(Th th, Th th') \<in> (child s)\<^sup>+"
  1567     with child_depend_eq[OF vt_s]
  1485     with child_RAG_eq[OF vt_s]
  1568     have "(Th th, Th th') \<in> (depend s)\<^sup>+" by simp
  1486     have "(Th th, Th th') \<in> (RAG s)\<^sup>+" by simp
  1569     with nd show False 
  1487     with nd show False 
  1570       by (simp add:s_dependants_def eq_depend)
  1488       by (simp add:s_dependants_def eq_RAG)
  1571   qed
  1489   qed
  1572   have eq_dp: "dependants (wq s) th' = dependants (wq s') th'"
  1490   have eq_dp: "dependants (wq s) th' = dependants (wq s') th'"
  1573   proof(auto)
  1491   proof(auto)
  1574     fix x assume " x \<in> dependants (wq s) th'"
  1492     fix x assume " x \<in> dependants (wq s) th'"
  1575     thus "x \<in> dependants (wq s') th'"
  1493     thus "x \<in> dependants (wq s') th'"
  1576       apply (auto simp:cs_dependants_def eq_depend)
  1494       apply (auto simp:cs_dependants_def eq_RAG)
  1577     proof -
  1495     proof -
  1578       assume "(Th x, Th th') \<in> (depend s)\<^sup>+"
  1496       assume "(Th x, Th th') \<in> (RAG s)\<^sup>+"
  1579       with  child_depend_eq[OF vt_s] have "(Th x, Th th') \<in> (child s)\<^sup>+" by simp
  1497       with  child_RAG_eq[OF vt_s] have "(Th x, Th th') \<in> (child s)\<^sup>+" by simp
  1580       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s')^+" by simp
  1498       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s')^+" by simp
  1581       with child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1499       with child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1582       show "(Th x, Th th') \<in> (depend s')\<^sup>+" by simp
  1500       show "(Th x, Th th') \<in> (RAG s')\<^sup>+" by simp
  1583     qed
  1501     qed
  1584   next
  1502   next
  1585     fix x assume "x \<in> dependants (wq s') th'"
  1503     fix x assume "x \<in> dependants (wq s') th'"
  1586     thus "x \<in> dependants (wq s) th'"
  1504     thus "x \<in> dependants (wq s) th'"
  1587       apply (auto simp:cs_dependants_def eq_depend)
  1505       apply (auto simp:cs_dependants_def eq_RAG)
  1588     proof -
  1506     proof -
  1589       assume "(Th x, Th th') \<in> (depend s')\<^sup>+"
  1507       assume "(Th x, Th th') \<in> (RAG s')\<^sup>+"
  1590       with child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]] 
  1508       with child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]] 
  1591       have "(Th x, Th th') \<in> (child s')\<^sup>+" by simp
  1509       have "(Th x, Th th') \<in> (child s')\<^sup>+" by simp
  1592       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s)^+" by simp
  1510       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s)^+" by simp
  1593       with  child_depend_eq[OF vt_s]
  1511       with  child_RAG_eq[OF vt_s]
  1594       show "(Th x, Th th') \<in> (depend s)\<^sup>+" by simp
  1512       show "(Th x, Th th') \<in> (RAG s)\<^sup>+" by simp
  1595     qed
  1513     qed
  1596   qed
  1514   qed
  1597   moreover {
  1515   moreover {
  1598     fix th1 have "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1516     fix th1 have "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1599   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1517   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1609   and dp2: "th' \<in> dependants s th''"
  1527   and dp2: "th' \<in> dependants s th''"
  1610   and eq_cps: "cp s th' = cp s' th'"
  1528   and eq_cps: "cp s th' = cp s' th'"
  1611   shows "cp s th'' = cp s' th''"
  1529   shows "cp s th'' = cp s' th''"
  1612 proof -
  1530 proof -
  1613   from dp2
  1531   from dp2
  1614   have "(Th th', Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependants_def)
  1532   have "(Th th', Th th'') \<in> (RAG (wq s))\<^sup>+" by (simp add:s_dependants_def)
  1615   from depend_child[OF vt_s this[unfolded eq_depend]]
  1533   from RAG_child[OF vt_s this[unfolded eq_RAG]]
  1616   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
  1534   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
  1617   moreover {
  1535   moreover {
  1618     fix n th''
  1536     fix n th''
  1619     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
  1537     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
  1620                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
  1538                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
  1623       assume y_ch: "(y, Th th'') \<in> child s"
  1541       assume y_ch: "(y, Th th'') \<in> child s"
  1624         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
  1542         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
  1625         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
  1543         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
  1626       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
  1544       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
  1627       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
  1545       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
  1628       from dp1 have "(Th th, Th th') \<in> (depend s)^+" by (auto simp:s_dependants_def eq_depend)
  1546       from dp1 have "(Th th, Th th') \<in> (RAG s)^+" by (auto simp:s_dependants_def eq_RAG)
  1629       moreover from child_depend_p[OF ch'] and eq_y
  1547       moreover from child_RAG_p[OF ch'] and eq_y
  1630       have "(Th th', Th thy) \<in> (depend s)^+" by simp
  1548       have "(Th th', Th thy) \<in> (RAG s)^+" by simp
  1631       ultimately have dp_thy: "(Th th, Th thy) \<in> (depend s)^+" by auto
  1549       ultimately have dp_thy: "(Th th, Th thy) \<in> (RAG s)^+" by auto
  1632       show "cp s th'' = cp s' th''"
  1550       show "cp s th'' = cp s' th''"
  1633         apply (subst cp_rec[OF vt_s])
  1551         apply (subst cp_rec[OF vt_s])
  1634       proof -
  1552       proof -
  1635         have "preced th'' s = preced th'' s'"
  1553         have "preced th'' s = preced th'' s'"
  1636           by (simp add:s_def preced_def)
  1554           by (simp add:s_def preced_def)
  1644           next
  1562           next
  1645             case False
  1563             case False
  1646             have neq_th1: "th1 \<noteq> th"
  1564             have neq_th1: "th1 \<noteq> th"
  1647             proof
  1565             proof
  1648               assume eq_th1: "th1 = th"
  1566               assume eq_th1: "th1 = th"
  1649               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
  1567               with dp_thy have "(Th th1, Th thy) \<in> (RAG s)^+" by simp
  1650               from children_no_dep[OF vt_s _ _ this] and 
  1568               from children_no_dep[OF vt_s _ _ this] and 
  1651               th1_in y_ch eq_y show False by (auto simp:children_def)
  1569               th1_in y_ch eq_y show False by (auto simp:children_def)
  1652             qed
  1570             qed
  1653             have "th \<notin> dependants s th1"
  1571             have "th \<notin> dependants s th1"
  1654             proof
  1572             proof
  1655               assume h:"th \<in> dependants s th1"
  1573               assume h:"th \<in> dependants s th1"
  1656               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_depend)
  1574               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_RAG)
  1657               from dependants_child_unique[OF vt_s _ _ h this]
  1575               from dependants_child_unique[OF vt_s _ _ h this]
  1658               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
  1576               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
  1659               with False show False by auto
  1577               with False show False by auto
  1660             qed
  1578             qed
  1661             from eq_cp[OF this]
  1579             from eq_cp[OF this]
  1663           qed
  1581           qed
  1664         }
  1582         }
  1665         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
  1583         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
  1666           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
  1584           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
  1667         moreover have "children s th'' = children s' th''"
  1585         moreover have "children s th'' = children s' th''"
  1668           apply (unfold children_def child_def s_def depend_set_unchanged, simp)
  1586           apply (unfold children_def child_def s_def RAG_set_unchanged, simp)
  1669           apply (fold s_def, auto simp:depend_s)
  1587           apply (fold s_def, auto simp:RAG_s)
  1670           proof -
  1588           proof -
  1671             assume "(Cs cs, Th th'') \<in> depend s'"
  1589             assume "(Cs cs, Th th'') \<in> RAG s'"
  1672             with depend_s have cs_th': "(Cs cs, Th th'') \<in> depend s" by auto
  1590             with RAG_s have cs_th': "(Cs cs, Th th'') \<in> RAG s" by auto
  1673             from dp1 have "(Th th, Th th') \<in> (depend s)^+"
  1591             from dp1 have "(Th th, Th th') \<in> (RAG s)^+"
  1674               by (auto simp:s_dependants_def eq_depend)
  1592               by (auto simp:s_dependants_def eq_RAG)
  1675             from converse_tranclE[OF this]
  1593             from converse_tranclE[OF this]
  1676             obtain cs1 where h1: "(Th th, Cs cs1) \<in> depend s"
  1594             obtain cs1 where h1: "(Th th, Cs cs1) \<in> RAG s"
  1677               and h2: "(Cs cs1 , Th th') \<in> (depend s)\<^sup>+"
  1595               and h2: "(Cs cs1 , Th th') \<in> (RAG s)\<^sup>+"
  1678               by (auto simp:s_depend_def)
  1596               by (auto simp:s_RAG_def)
  1679             have eq_cs: "cs1 = cs" 
  1597             have eq_cs: "cs1 = cs" 
  1680             proof -
  1598             proof -
  1681               from depend_s have "(Th th, Cs cs) \<in> depend s" by simp
  1599               from RAG_s have "(Th th, Cs cs) \<in> RAG s" by simp
  1682               from unique_depend[OF vt_s this h1]
  1600               from unique_RAG[OF vt_s this h1]
  1683               show ?thesis by simp
  1601               show ?thesis by simp
  1684             qed
  1602             qed
  1685             have False
  1603             have False
  1686             proof(rule converse_tranclE[OF h2])
  1604             proof(rule converse_tranclE[OF h2])
  1687               assume "(Cs cs1, Th th') \<in> depend s"
  1605               assume "(Cs cs1, Th th') \<in> RAG s"
  1688               with eq_cs have "(Cs cs, Th th') \<in> depend s" by simp
  1606               with eq_cs have "(Cs cs, Th th') \<in> RAG s" by simp
  1689               from unique_depend[OF vt_s this cs_th']
  1607               from unique_RAG[OF vt_s this cs_th']
  1690               have "th' = th''" by simp
  1608               have "th' = th''" by simp
  1691               with ch' y_ch have "(Th th'', Th th'') \<in> (child s)^+" by auto
  1609               with ch' y_ch have "(Th th'', Th th'') \<in> (child s)^+" by auto
  1692               with wf_trancl[OF wf_child[OF vt_s]] 
  1610               with wf_trancl[OF wf_child[OF vt_s]] 
  1693               show False by auto
  1611               show False by auto
  1694             next
  1612             next
  1695               fix y
  1613               fix y
  1696               assume "(Cs cs1, y) \<in> depend s"
  1614               assume "(Cs cs1, y) \<in> RAG s"
  1697                 and ytd: " (y, Th th') \<in> (depend s)\<^sup>+"
  1615                 and ytd: " (y, Th th') \<in> (RAG s)\<^sup>+"
  1698               with eq_cs have csy: "(Cs cs, y) \<in> depend s" by simp
  1616               with eq_cs have csy: "(Cs cs, y) \<in> RAG s" by simp
  1699               from unique_depend[OF vt_s this cs_th']
  1617               from unique_RAG[OF vt_s this cs_th']
  1700               have "y = Th th''" .
  1618               have "y = Th th''" .
  1701               with ytd have "(Th th'', Th th') \<in> (depend s)^+" by simp
  1619               with ytd have "(Th th'', Th th') \<in> (RAG s)^+" by simp
  1702               from depend_child[OF vt_s this]
  1620               from RAG_child[OF vt_s this]
  1703               have "(Th th'', Th th') \<in> (child s)\<^sup>+" .
  1621               have "(Th th'', Th th') \<in> (child s)\<^sup>+" .
  1704               moreover from ch' y_ch have ch'': "(Th th', Th th'') \<in> (child s)^+" by auto
  1622               moreover from ch' y_ch have ch'': "(Th th', Th th'') \<in> (child s)^+" by auto
  1705               ultimately have "(Th th'', Th th'') \<in> (child s)^+" by auto 
  1623               ultimately have "(Th th'', Th th'') \<in> (child s)^+" by auto 
  1706               with wf_trancl[OF wf_child[OF vt_s]] 
  1624               with wf_trancl[OF wf_child[OF vt_s]] 
  1707               show False by auto
  1625               show False by auto
  1708             qed
  1626             qed
  1709             thus "\<exists>cs. (Th th, Cs cs) \<in> depend s' \<and> (Cs cs, Th th'') \<in> depend s'" by auto
  1627             thus "\<exists>cs. (Th th, Cs cs) \<in> RAG s' \<and> (Cs cs, Th th'') \<in> RAG s'" by auto
  1710           qed
  1628           qed
  1711           ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
  1629           ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
  1712           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
  1630           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
  1713       qed
  1631       qed
  1714     next
  1632     next
  1729           next
  1647           next
  1730             case False
  1648             case False
  1731             have neq_th1: "th1 \<noteq> th"
  1649             have neq_th1: "th1 \<noteq> th"
  1732             proof
  1650             proof
  1733               assume eq_th1: "th1 = th"
  1651               assume eq_th1: "th1 = th"
  1734               with dp1 have "(Th th1, Th th') \<in> (depend s)^+" 
  1652               with dp1 have "(Th th1, Th th') \<in> (RAG s)^+" 
  1735                 by (auto simp:s_dependants_def eq_depend)
  1653                 by (auto simp:s_dependants_def eq_RAG)
  1736               from children_no_dep[OF vt_s _ _ this]
  1654               from children_no_dep[OF vt_s _ _ this]
  1737               th1_in dp'
  1655               th1_in dp'
  1738               show False by (auto simp:children_def)
  1656               show False by (auto simp:children_def)
  1739             qed
  1657             qed
  1740             show ?thesis
  1658             show ?thesis
  1751           qed
  1669           qed
  1752         }
  1670         }
  1753         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
  1671         ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
  1754           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
  1672           {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
  1755         moreover have "children s th'' = children s' th''"
  1673         moreover have "children s th'' = children s' th''"
  1756           apply (unfold children_def child_def s_def depend_set_unchanged, simp)
  1674           apply (unfold children_def child_def s_def RAG_set_unchanged, simp)
  1757           apply (fold s_def, auto simp:depend_s)
  1675           apply (fold s_def, auto simp:RAG_s)
  1758           proof -
  1676           proof -
  1759             assume "(Cs cs, Th th'') \<in> depend s'"
  1677             assume "(Cs cs, Th th'') \<in> RAG s'"
  1760             with depend_s have cs_th': "(Cs cs, Th th'') \<in> depend s" by auto
  1678             with RAG_s have cs_th': "(Cs cs, Th th'') \<in> RAG s" by auto
  1761             from dp1 have "(Th th, Th th') \<in> (depend s)^+"
  1679             from dp1 have "(Th th, Th th') \<in> (RAG s)^+"
  1762               by (auto simp:s_dependants_def eq_depend)
  1680               by (auto simp:s_dependants_def eq_RAG)
  1763             from converse_tranclE[OF this]
  1681             from converse_tranclE[OF this]
  1764             obtain cs1 where h1: "(Th th, Cs cs1) \<in> depend s"
  1682             obtain cs1 where h1: "(Th th, Cs cs1) \<in> RAG s"
  1765               and h2: "(Cs cs1 , Th th') \<in> (depend s)\<^sup>+"
  1683               and h2: "(Cs cs1 , Th th') \<in> (RAG s)\<^sup>+"
  1766               by (auto simp:s_depend_def)
  1684               by (auto simp:s_RAG_def)
  1767             have eq_cs: "cs1 = cs" 
  1685             have eq_cs: "cs1 = cs" 
  1768             proof -
  1686             proof -
  1769               from depend_s have "(Th th, Cs cs) \<in> depend s" by simp
  1687               from RAG_s have "(Th th, Cs cs) \<in> RAG s" by simp
  1770               from unique_depend[OF vt_s this h1]
  1688               from unique_RAG[OF vt_s this h1]
  1771               show ?thesis by simp
  1689               show ?thesis by simp
  1772             qed
  1690             qed
  1773             have False
  1691             have False
  1774             proof(rule converse_tranclE[OF h2])
  1692             proof(rule converse_tranclE[OF h2])
  1775               assume "(Cs cs1, Th th') \<in> depend s"
  1693               assume "(Cs cs1, Th th') \<in> RAG s"
  1776               with eq_cs have "(Cs cs, Th th') \<in> depend s" by simp
  1694               with eq_cs have "(Cs cs, Th th') \<in> RAG s" by simp
  1777               from unique_depend[OF vt_s this cs_th']
  1695               from unique_RAG[OF vt_s this cs_th']
  1778               have "th' = th''" by simp
  1696               have "th' = th''" by simp
  1779               with dp' have "(Th th'', Th th'') \<in> (child s)^+" by auto
  1697               with dp' have "(Th th'', Th th'') \<in> (child s)^+" by auto
  1780               with wf_trancl[OF wf_child[OF vt_s]] 
  1698               with wf_trancl[OF wf_child[OF vt_s]] 
  1781               show False by auto
  1699               show False by auto
  1782             next
  1700             next
  1783               fix y
  1701               fix y
  1784               assume "(Cs cs1, y) \<in> depend s"
  1702               assume "(Cs cs1, y) \<in> RAG s"
  1785                 and ytd: " (y, Th th') \<in> (depend s)\<^sup>+"
  1703                 and ytd: " (y, Th th') \<in> (RAG s)\<^sup>+"
  1786               with eq_cs have csy: "(Cs cs, y) \<in> depend s" by simp
  1704               with eq_cs have csy: "(Cs cs, y) \<in> RAG s" by simp
  1787               from unique_depend[OF vt_s this cs_th']
  1705               from unique_RAG[OF vt_s this cs_th']
  1788               have "y = Th th''" .
  1706               have "y = Th th''" .
  1789               with ytd have "(Th th'', Th th') \<in> (depend s)^+" by simp
  1707               with ytd have "(Th th'', Th th') \<in> (RAG s)^+" by simp
  1790               from depend_child[OF vt_s this]
  1708               from RAG_child[OF vt_s this]
  1791               have "(Th th'', Th th') \<in> (child s)\<^sup>+" .
  1709               have "(Th th'', Th th') \<in> (child s)\<^sup>+" .
  1792               moreover from dp' have ch'': "(Th th', Th th'') \<in> (child s)^+" by auto
  1710               moreover from dp' have ch'': "(Th th', Th th'') \<in> (child s)^+" by auto
  1793               ultimately have "(Th th'', Th th'') \<in> (child s)^+" by auto 
  1711               ultimately have "(Th th'', Th th'') \<in> (child s)^+" by auto 
  1794               with wf_trancl[OF wf_child[OF vt_s]] 
  1712               with wf_trancl[OF wf_child[OF vt_s]] 
  1795               show False by auto
  1713               show False by auto
  1796             qed
  1714             qed
  1797             thus "\<exists>cs. (Th th, Cs cs) \<in> depend s' \<and> (Cs cs, Th th'') \<in> depend s'" by auto
  1715             thus "\<exists>cs. (Th th, Cs cs) \<in> RAG s' \<and> (Cs cs, Th th'') \<in> RAG s'" by auto
  1798           qed
  1716           qed
  1799         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
  1717         ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
  1800           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
  1718           by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
  1801       qed     
  1719       qed     
  1802     qed
  1720     qed
  1812   assumes vt_s: "vt s"
  1730   assumes vt_s: "vt s"
  1813 
  1731 
  1814 context step_create_cps
  1732 context step_create_cps
  1815 begin
  1733 begin
  1816 
  1734 
  1817 lemma eq_dep: "depend s = depend s'"
  1735 lemma eq_dep: "RAG s = RAG s'"
  1818   by (unfold s_def depend_create_unchanged, auto)
  1736   by (unfold s_def RAG_create_unchanged, auto)
  1819 
  1737 
  1820 lemma eq_cp:
  1738 lemma eq_cp:
  1821   fixes th' 
  1739   fixes th' 
  1822   assumes neq_th: "th' \<noteq> th"
  1740   assumes neq_th: "th' \<noteq> th"
  1823   shows "cp s th' = cp s' th'"
  1741   shows "cp s th' = cp s' th'"
  1824   apply (unfold cp_eq_cpreced cpreced_def)
  1742   apply (unfold cp_eq_cpreced cpreced_def)
  1825 proof -
  1743 proof -
  1826   have nd: "th \<notin> dependants s th'"
  1744   have nd: "th \<notin> dependants s th'"
  1827   proof
  1745   proof
  1828     assume "th \<in> dependants s th'"
  1746     assume "th \<in> dependants s th'"
  1829     hence "(Th th, Th th') \<in> (depend s)^+" by (simp add:s_dependants_def eq_depend)
  1747     hence "(Th th, Th th') \<in> (RAG s)^+" by (simp add:s_dependants_def eq_RAG)
  1830     with eq_dep have "(Th th, Th th') \<in> (depend s')^+" by simp
  1748     with eq_dep have "(Th th, Th th') \<in> (RAG s')^+" by simp
  1831     from converse_tranclE[OF this]
  1749     from converse_tranclE[OF this]
  1832     obtain y where "(Th th, y) \<in> depend s'" by auto
  1750     obtain y where "(Th th, y) \<in> RAG s'" by auto
  1833     with dm_depend_threads[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1751     with dm_RAG_threads[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1834     have in_th: "th \<in> threads s'" by auto
  1752     have in_th: "th \<in> threads s'" by auto
  1835     from step_back_step[OF vt_s[unfolded s_def]]
  1753     from step_back_step[OF vt_s[unfolded s_def]]
  1836     show False
  1754     show False
  1837     proof(cases)
  1755     proof(cases)
  1838       assume "th \<notin> threads s'" 
  1756       assume "th \<notin> threads s'" 
  1839       with in_th show ?thesis by simp
  1757       with in_th show ?thesis by simp
  1840     qed
  1758     qed
  1841   qed
  1759   qed
  1842   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1760   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1843     by (unfold cs_dependants_def, auto simp:eq_dep eq_depend)
  1761     by (unfold cs_dependants_def, auto simp:eq_dep eq_RAG)
  1844   moreover {
  1762   moreover {
  1845     fix th1 
  1763     fix th1 
  1846     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1764     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1847     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1765     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1848     hence "preced th1 s = preced th1 s'"
  1766     hence "preced th1 s = preced th1 s'"
  1851       with neq_th
  1769       with neq_th
  1852       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1770       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1853     next
  1771     next
  1854       assume "th1 \<in> dependants (wq s') th'"
  1772       assume "th1 \<in> dependants (wq s') th'"
  1855       with nd and eq_dp have "th1 \<noteq> th"
  1773       with nd and eq_dp have "th1 \<noteq> th"
  1856         by (auto simp:eq_depend cs_dependants_def s_dependants_def eq_dep)
  1774         by (auto simp:eq_RAG cs_dependants_def s_dependants_def eq_dep)
  1857       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1775       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1858     qed
  1776     qed
  1859   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1777   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1860                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1778                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1861     by (auto simp:image_def)
  1779     by (auto simp:image_def)
  1872     from not_thread_holdents[OF step_back_vt[OF vt_s[unfolded s_def]] this]
  1790     from not_thread_holdents[OF step_back_vt[OF vt_s[unfolded s_def]] this]
  1873     have hdn: " holdents s' th = {}" .
  1791     have hdn: " holdents s' th = {}" .
  1874     have "dependants s' th = {}"
  1792     have "dependants s' th = {}"
  1875     proof -
  1793     proof -
  1876       { assume "dependants s' th \<noteq> {}"
  1794       { assume "dependants s' th \<noteq> {}"
  1877         then obtain th' where dp: "(Th th', Th th) \<in> (depend s')^+"
  1795         then obtain th' where dp: "(Th th', Th th) \<in> (RAG s')^+"
  1878           by (auto simp:s_dependants_def eq_depend)
  1796           by (auto simp:s_dependants_def eq_RAG)
  1879         from tranclE[OF this] obtain cs' where 
  1797         from tranclE[OF this] obtain cs' where 
  1880           "(Cs cs', Th th) \<in> depend s'" by (auto simp:s_depend_def)
  1798           "(Cs cs', Th th) \<in> RAG s'" by (auto simp:s_RAG_def)
  1881         with hdn
  1799         with hdn
  1882         have False by (auto simp:holdents_test)
  1800         have False by (auto simp:holdents_test)
  1883       } thus ?thesis by auto
  1801       } thus ?thesis by auto
  1884     qed
  1802     qed
  1885     thus ?thesis 
  1803     thus ?thesis 
  1886       by (unfold s_def s_dependants_def eq_depend depend_create_unchanged, simp)
  1804       by (unfold s_def s_dependants_def eq_RAG RAG_create_unchanged, simp)
  1887   qed
  1805   qed
  1888 qed
  1806 qed
  1889 
  1807 
  1890 lemma eq_cp_th: "cp s th = preced th s"
  1808 lemma eq_cp_th: "cp s th = preced th s"
  1891   apply (unfold cp_eq_cpreced cpreced_def)
  1809   apply (unfold cp_eq_cpreced cpreced_def)
  1900   assumes vt_s: "vt s"
  1818   assumes vt_s: "vt s"
  1901 
  1819 
  1902 context step_exit_cps
  1820 context step_exit_cps
  1903 begin
  1821 begin
  1904 
  1822 
  1905 lemma eq_dep: "depend s = depend s'"
  1823 lemma eq_dep: "RAG s = RAG s'"
  1906   by (unfold s_def depend_exit_unchanged, auto)
  1824   by (unfold s_def RAG_exit_unchanged, auto)
  1907 
  1825 
  1908 lemma eq_cp:
  1826 lemma eq_cp:
  1909   fixes th' 
  1827   fixes th' 
  1910   assumes neq_th: "th' \<noteq> th"
  1828   assumes neq_th: "th' \<noteq> th"
  1911   shows "cp s th' = cp s' th'"
  1829   shows "cp s th' = cp s' th'"
  1912   apply (unfold cp_eq_cpreced cpreced_def)
  1830   apply (unfold cp_eq_cpreced cpreced_def)
  1913 proof -
  1831 proof -
  1914   have nd: "th \<notin> dependants s th'"
  1832   have nd: "th \<notin> dependants s th'"
  1915   proof
  1833   proof
  1916     assume "th \<in> dependants s th'"
  1834     assume "th \<in> dependants s th'"
  1917     hence "(Th th, Th th') \<in> (depend s)^+" by (simp add:s_dependants_def eq_depend)
  1835     hence "(Th th, Th th') \<in> (RAG s)^+" by (simp add:s_dependants_def eq_RAG)
  1918     with eq_dep have "(Th th, Th th') \<in> (depend s')^+" by simp
  1836     with eq_dep have "(Th th, Th th') \<in> (RAG s')^+" by simp
  1919     from converse_tranclE[OF this]
  1837     from converse_tranclE[OF this]
  1920     obtain cs' where bk: "(Th th, Cs cs') \<in> depend s'"
  1838     obtain cs' where bk: "(Th th, Cs cs') \<in> RAG s'"
  1921       by (auto simp:s_depend_def)
  1839       by (auto simp:s_RAG_def)
  1922     from step_back_step[OF vt_s[unfolded s_def]]
  1840     from step_back_step[OF vt_s[unfolded s_def]]
  1923     show False
  1841     show False
  1924     proof(cases)
  1842     proof(cases)
  1925       assume "th \<in> runing s'"
  1843       assume "th \<in> runing s'"
  1926       with bk show ?thesis
  1844       with bk show ?thesis
  1927         apply (unfold runing_def readys_def s_waiting_def s_depend_def)
  1845         apply (unfold runing_def readys_def s_waiting_def s_RAG_def)
  1928         by (auto simp:cs_waiting_def wq_def)
  1846         by (auto simp:cs_waiting_def wq_def)
  1929     qed
  1847     qed
  1930   qed
  1848   qed
  1931   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1849   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1932     by (unfold cs_dependants_def, auto simp:eq_dep eq_depend)
  1850     by (unfold cs_dependants_def, auto simp:eq_dep eq_RAG)
  1933   moreover {
  1851   moreover {
  1934     fix th1 
  1852     fix th1 
  1935     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1853     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1936     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1854     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1937     hence "preced th1 s = preced th1 s'"
  1855     hence "preced th1 s = preced th1 s'"
  1940       with neq_th
  1858       with neq_th
  1941       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1859       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1942     next
  1860     next
  1943       assume "th1 \<in> dependants (wq s') th'"
  1861       assume "th1 \<in> dependants (wq s') th'"
  1944       with nd and eq_dp have "th1 \<noteq> th"
  1862       with nd and eq_dp have "th1 \<noteq> th"
  1945         by (auto simp:eq_depend cs_dependants_def s_dependants_def eq_dep)
  1863         by (auto simp:eq_RAG cs_dependants_def s_dependants_def eq_dep)
  1946       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1864       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1947     qed
  1865     qed
  1948   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1866   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1949                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1867                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1950     by (auto simp:image_def)
  1868     by (auto simp:image_def)