CpsG.thy
changeset 32 e861aff29655
parent 0 110247f9d47e
child 33 9b9f2117561f
equal deleted inserted replaced
31:8f026b608378 32:e861aff29655
   253 
   253 
   254 lemma children_def2:
   254 lemma children_def2:
   255   "children s th \<equiv> {th'. \<exists> cs. (Th th', Cs cs) \<in> depend s \<and> (Cs cs, Th th) \<in> depend s}"
   255   "children s th \<equiv> {th'. \<exists> cs. (Th th', Cs cs) \<in> depend s \<and> (Cs cs, Th th) \<in> depend s}"
   256 unfolding child_def children_def by simp
   256 unfolding child_def children_def by simp
   257 
   257 
   258 lemma children_dependents: "children s th \<subseteq> dependents (wq s) th"
   258 lemma children_dependants: "children s th \<subseteq> dependants (wq s) th"
   259   by (unfold children_def child_def cs_dependents_def, auto simp:eq_depend)
   259   by (unfold children_def child_def cs_dependants_def, auto simp:eq_depend)
   260 
   260 
   261 lemma child_unique:
   261 lemma child_unique:
   262   assumes vt: "vt s"
   262   assumes vt: "vt s"
   263   and ch1: "(Th th, Th th1) \<in> child s"
   263   and ch1: "(Th th, Th th1) \<in> child s"
   264   and ch2: "(Th th, Th th2) \<in> child s"
   264   and ch2: "(Th th, Th th2) \<in> child s"
   444 proof(rule unique_chain [OF _ dp1 dp2 neq])
   444 proof(rule unique_chain [OF _ dp1 dp2 neq])
   445   from unique_depend[OF vt]
   445   from unique_depend[OF vt]
   446   show "\<And>a b c. \<lbrakk>(a, b) \<in> depend s; (a, c) \<in> depend s\<rbrakk> \<Longrightarrow> b = c" by auto
   446   show "\<And>a b c. \<lbrakk>(a, b) \<in> depend s; (a, c) \<in> depend s\<rbrakk> \<Longrightarrow> b = c" by auto
   447 qed
   447 qed
   448 
   448 
   449 lemma dependents_child_unique:
   449 lemma dependants_child_unique:
   450   fixes s th th1 th2 th3
   450   fixes s th th1 th2 th3
   451   assumes vt: "vt s"
   451   assumes vt: "vt s"
   452   and ch1: "(Th th1, Th th) \<in> child s"
   452   and ch1: "(Th th1, Th th) \<in> child s"
   453   and ch2: "(Th th2, Th th) \<in> child s"
   453   and ch2: "(Th th2, Th th) \<in> child s"
   454   and dp1: "th3 \<in> dependents s th1"
   454   and dp1: "th3 \<in> dependants s th1"
   455   and dp2: "th3 \<in> dependents s th2"
   455   and dp2: "th3 \<in> dependants s th2"
   456 shows "th1 = th2"
   456 shows "th1 = th2"
   457 proof -
   457 proof -
   458   { assume neq: "th1 \<noteq> th2"
   458   { assume neq: "th1 \<noteq> th2"
   459     from dp1 have dp1: "(Th th3, Th th1) \<in> (depend s)^+" 
   459     from dp1 have dp1: "(Th th3, Th th1) \<in> (depend s)^+" 
   460       by (simp add:s_dependents_def eq_depend)
   460       by (simp add:s_dependants_def eq_depend)
   461     from dp2 have dp2: "(Th th3, Th th2) \<in> (depend s)^+" 
   461     from dp2 have dp2: "(Th th3, Th th2) \<in> (depend s)^+" 
   462       by (simp add:s_dependents_def eq_depend)
   462       by (simp add:s_dependants_def eq_depend)
   463     from unique_depend_p[OF vt dp1 dp2] and neq
   463     from unique_depend_p[OF vt dp1 dp2] and neq
   464     have "(Th th1, Th th2) \<in> (depend s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (depend s)\<^sup>+" by auto
   464     have "(Th th1, Th th2) \<in> (depend s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (depend s)\<^sup>+" by auto
   465     hence False
   465     hence False
   466     proof
   466     proof
   467       assume "(Th th1, Th th2) \<in> (depend s)\<^sup>+ "
   467       assume "(Th th1, Th th2) \<in> (depend s)\<^sup>+ "
   477   fixes s th
   477   fixes s th
   478   assumes vt: "vt s"
   478   assumes vt: "vt s"
   479   shows "cp s th = Max ({preced th s} \<union> (cp s ` children s th))"
   479   shows "cp s th = Max ({preced th s} \<union> (cp s ` children s th))"
   480 proof(unfold cp_eq_cpreced_f cpreced_def)
   480 proof(unfold cp_eq_cpreced_f cpreced_def)
   481   let ?f = "(\<lambda>th. preced th s)"
   481   let ?f = "(\<lambda>th. preced th s)"
   482   show "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th)) =
   482   show "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependants (wq s) th)) =
   483         Max ({preced th s} \<union> (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th))) ` children s th)"
   483         Max ({preced th s} \<union> (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependants (wq s) th))) ` children s th)"
   484   proof(cases " children s th = {}")
   484   proof(cases " children s th = {}")
   485     case False
   485     case False
   486     have "(\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th))) ` children s th = 
   486     have "(\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependants (wq s) th))) ` children s th = 
   487           {Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) | th' . th' \<in> children s th}"
   487           {Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) | th' . th' \<in> children s th}"
   488       (is "?L = ?R")
   488       (is "?L = ?R")
   489       by auto
   489       by auto
   490     also have "\<dots> = 
   490     also have "\<dots> = 
   491       Max ` {((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) | th' . th' \<in> children s th}"
   491       Max ` {((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) | th' . th' \<in> children s th}"
   492       (is "_ = Max ` ?C")
   492       (is "_ = Max ` ?C")
   493       by auto
   493       by auto
   494     finally have "Max ?L = Max (Max ` ?C)" by auto
   494     finally have "Max ?L = Max (Max ` ?C)" by auto
   495     also have "\<dots> = Max (\<Union> ?C)"
   495     also have "\<dots> = Max (\<Union> ?C)"
   496     proof(rule Max_Union[symmetric])
   496     proof(rule Max_Union[symmetric])
   497       from children_dependents[of s th] finite_threads[OF vt] and dependents_threads[OF vt, of th]
   497       from children_dependants[of s th] finite_threads[OF vt] and dependants_threads[OF vt, of th]
   498       show "finite {(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th}"
   498       show "finite {(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th}"
   499         by (auto simp:finite_subset)
   499         by (auto simp:finite_subset)
   500     next
   500     next
   501       from False
   501       from False
   502       show "{(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th} \<noteq> {}"
   502       show "{(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th} \<noteq> {}"
   503         by simp
   503         by simp
   504     next
   504     next
   505       show "\<And>A. A \<in> {(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th} \<Longrightarrow>
   505       show "\<And>A. A \<in> {(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th} \<Longrightarrow>
   506         finite A \<and> A \<noteq> {}"
   506         finite A \<and> A \<noteq> {}"
   507         apply (auto simp:finite_subset)
   507         apply (auto simp:finite_subset)
   508       proof -
   508       proof -
   509         fix th'
   509         fix th'
   510         from finite_threads[OF vt] and dependents_threads[OF vt, of th']
   510         from finite_threads[OF vt] and dependants_threads[OF vt, of th']
   511         show "finite ((\<lambda>th. preced th s) ` dependents (wq s) th')" by (auto simp:finite_subset)
   511         show "finite ((\<lambda>th. preced th s) ` dependants (wq s) th')" by (auto simp:finite_subset)
   512       qed
   512       qed
   513     qed
   513     qed
   514     also have "\<dots> = Max ((\<lambda>th. preced th s) ` dependents (wq s) th)"
   514     also have "\<dots> = Max ((\<lambda>th. preced th s) ` dependants (wq s) th)"
   515       (is "Max ?A = Max ?B")
   515       (is "Max ?A = Max ?B")
   516     proof -
   516     proof -
   517       have "?A = ?B"
   517       have "?A = ?B"
   518       proof
   518       proof
   519         show "\<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th}
   519         show "\<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th}
   520                     \<subseteq> (\<lambda>th. preced th s) ` dependents (wq s) th"
   520                     \<subseteq> (\<lambda>th. preced th s) ` dependants (wq s) th"
   521         proof
   521         proof
   522           fix x 
   522           fix x 
   523           assume "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th}"
   523           assume "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th}"
   524           then obtain th' where 
   524           then obtain th' where 
   525              th'_in: "th' \<in> children s th"
   525              th'_in: "th' \<in> children s th"
   526             and x_in: "x \<in> ?f ` ({th'} \<union> dependents (wq s) th')" by auto
   526             and x_in: "x \<in> ?f ` ({th'} \<union> dependants (wq s) th')" by auto
   527           hence "x = ?f th' \<or> x \<in> (?f ` dependents (wq s) th')" by auto
   527           hence "x = ?f th' \<or> x \<in> (?f ` dependants (wq s) th')" by auto
   528           thus "x \<in> ?f ` dependents (wq s) th"
   528           thus "x \<in> ?f ` dependants (wq s) th"
   529           proof
   529           proof
   530             assume "x = preced th' s"
   530             assume "x = preced th' s"
   531             with th'_in and children_dependents
   531             with th'_in and children_dependants
   532             show "x \<in> (\<lambda>th. preced th s) ` dependents (wq s) th" by auto
   532             show "x \<in> (\<lambda>th. preced th s) ` dependants (wq s) th" by auto
   533           next
   533           next
   534             assume "x \<in> (\<lambda>th. preced th s) ` dependents (wq s) th'"
   534             assume "x \<in> (\<lambda>th. preced th s) ` dependants (wq s) th'"
   535             moreover note th'_in
   535             moreover note th'_in
   536             ultimately show " x \<in> (\<lambda>th. preced th s) ` dependents (wq s) th"
   536             ultimately show " x \<in> (\<lambda>th. preced th s) ` dependants (wq s) th"
   537               by (unfold cs_dependents_def children_def child_def, auto simp:eq_depend)
   537               by (unfold cs_dependants_def children_def child_def, auto simp:eq_depend)
   538           qed
   538           qed
   539         qed
   539         qed
   540       next
   540       next
   541         show "?f ` dependents (wq s) th
   541         show "?f ` dependants (wq s) th
   542            \<subseteq> \<Union>{?f ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th}"
   542            \<subseteq> \<Union>{?f ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th}"
   543         proof
   543         proof
   544           fix x 
   544           fix x 
   545           assume x_in: "x \<in> (\<lambda>th. preced th s) ` dependents (wq s) th"
   545           assume x_in: "x \<in> (\<lambda>th. preced th s) ` dependants (wq s) th"
   546           then obtain th' where
   546           then obtain th' where
   547             eq_x: "x = ?f th'" and dp: "(Th th', Th th) \<in> (depend s)^+" 
   547             eq_x: "x = ?f th'" and dp: "(Th th', Th th) \<in> (depend s)^+" 
   548             by (auto simp:cs_dependents_def eq_depend)
   548             by (auto simp:cs_dependants_def eq_depend)
   549           from depend_children[OF dp]
   549           from depend_children[OF dp]
   550           have "th' \<in> children s th \<or> (\<exists>th3. th3 \<in> children s th \<and> (Th th', Th th3) \<in> (depend s)\<^sup>+)" .
   550           have "th' \<in> children s th \<or> (\<exists>th3. th3 \<in> children s th \<and> (Th th', Th th3) \<in> (depend s)\<^sup>+)" .
   551           thus "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th}"
   551           thus "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th}"
   552           proof
   552           proof
   553             assume "th' \<in> children s th"
   553             assume "th' \<in> children s th"
   554             with eq_x
   554             with eq_x
   555             show "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th}"
   555             show "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th}"
   556               by auto
   556               by auto
   557           next
   557           next
   558             assume "\<exists>th3. th3 \<in> children s th \<and> (Th th', Th th3) \<in> (depend s)\<^sup>+"
   558             assume "\<exists>th3. th3 \<in> children s th \<and> (Th th', Th th3) \<in> (depend s)\<^sup>+"
   559             then obtain th3 where th3_in: "th3 \<in> children s th"
   559             then obtain th3 where th3_in: "th3 \<in> children s th"
   560               and dp3: "(Th th', Th th3) \<in> (depend s)\<^sup>+" by auto
   560               and dp3: "(Th th', Th th3) \<in> (depend s)\<^sup>+" by auto
   561             show "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th') |th'. th' \<in> children s th}"
   561             show "x \<in> \<Union>{(\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th') |th'. th' \<in> children s th}"
   562             proof -
   562             proof -
   563               from dp3
   563               from dp3
   564               have "th' \<in> dependents (wq s) th3"
   564               have "th' \<in> dependants (wq s) th3"
   565                 by (auto simp:cs_dependents_def eq_depend)
   565                 by (auto simp:cs_dependants_def eq_depend)
   566               with eq_x th3_in show ?thesis by auto
   566               with eq_x th3_in show ?thesis by auto
   567             qed
   567             qed
   568           qed          
   568           qed          
   569         qed
   569         qed
   570       qed
   570       qed
   571       thus ?thesis by simp
   571       thus ?thesis by simp
   572     qed
   572     qed
   573     finally have "Max ((\<lambda>th. preced th s) ` dependents (wq s) th) = Max (?L)" 
   573     finally have "Max ((\<lambda>th. preced th s) ` dependants (wq s) th) = Max (?L)" 
   574       (is "?X = ?Y") by auto
   574       (is "?X = ?Y") by auto
   575     moreover have "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th)) = 
   575     moreover have "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependants (wq s) th)) = 
   576                    max (?f th) ?X" 
   576                    max (?f th) ?X" 
   577     proof -
   577     proof -
   578       have "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th)) = 
   578       have "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependants (wq s) th)) = 
   579             Max ({?f th} \<union> ?f ` (dependents (wq s) th))" by simp
   579             Max ({?f th} \<union> ?f ` (dependants (wq s) th))" by simp
   580       also have "\<dots> = max (Max {?f th}) (Max (?f ` (dependents (wq s) th)))"
   580       also have "\<dots> = max (Max {?f th}) (Max (?f ` (dependants (wq s) th)))"
   581       proof(rule Max_Un, auto)
   581       proof(rule Max_Un, auto)
   582         from finite_threads[OF vt] and dependents_threads[OF vt, of th]
   582         from finite_threads[OF vt] and dependants_threads[OF vt, of th]
   583         show "finite ((\<lambda>th. preced th s) ` dependents (wq s) th)" by (auto simp:finite_subset)
   583         show "finite ((\<lambda>th. preced th s) ` dependants (wq s) th)" by (auto simp:finite_subset)
   584       next
   584       next
   585         assume "dependents (wq s) th = {}"
   585         assume "dependants (wq s) th = {}"
   586         with False and children_dependents show False by auto
   586         with False and children_dependants show False by auto
   587       qed
   587       qed
   588       also have "\<dots> = max (?f th) ?X" by simp
   588       also have "\<dots> = max (?f th) ?X" by simp
   589       finally show ?thesis .
   589       finally show ?thesis .
   590     qed
   590     qed
   591     moreover have "Max ({preced th s} \<union> 
   591     moreover have "Max ({preced th s} \<union> 
   592                      (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th))) ` children s th) = 
   592                      (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependants (wq s) th))) ` children s th) = 
   593                    max (?f th) ?Y"
   593                    max (?f th) ?Y"
   594     proof -
   594     proof -
   595       have "Max ({preced th s} \<union> 
   595       have "Max ({preced th s} \<union> 
   596                      (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th))) ` children s th) = 
   596                      (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependants (wq s) th))) ` children s th) = 
   597             max (Max {preced th s}) ?Y"
   597             max (Max {preced th s}) ?Y"
   598       proof(rule Max_Un, auto)
   598       proof(rule Max_Un, auto)
   599         from finite_threads[OF vt] dependents_threads[OF vt, of th] children_dependents [of s th]
   599         from finite_threads[OF vt] dependants_threads[OF vt, of th] children_dependants [of s th]
   600         show "finite ((\<lambda>th. Max (insert (preced th s) ((\<lambda>th. preced th s) ` dependents (wq s) th))) ` 
   600         show "finite ((\<lambda>th. Max (insert (preced th s) ((\<lambda>th. preced th s) ` dependants (wq s) th))) ` 
   601                        children s th)" 
   601                        children s th)" 
   602           by (auto simp:finite_subset)
   602           by (auto simp:finite_subset)
   603       next
   603       next
   604         assume "children s th = {}"
   604         assume "children s th = {}"
   605         with False show False by auto
   605         with False show False by auto
   607       thus ?thesis by simp
   607       thus ?thesis by simp
   608     qed
   608     qed
   609     ultimately show ?thesis by auto
   609     ultimately show ?thesis by auto
   610   next
   610   next
   611     case True
   611     case True
   612     moreover have "dependents (wq s) th = {}"
   612     moreover have "dependants (wq s) th = {}"
   613     proof -
   613     proof -
   614       { fix th'
   614       { fix th'
   615         assume "th' \<in> dependents (wq s) th"
   615         assume "th' \<in> dependants (wq s) th"
   616         hence " (Th th', Th th) \<in> (depend s)\<^sup>+" by (simp add:cs_dependents_def eq_depend)
   616         hence " (Th th', Th th) \<in> (depend s)\<^sup>+" by (simp add:cs_dependants_def eq_depend)
   617         from depend_children[OF this] and True
   617         from depend_children[OF this] and True
   618         have "False" by auto
   618         have "False" by auto
   619       } thus ?thesis by auto
   619       } thus ?thesis by auto
   620     qed
   620     qed
   621     ultimately show ?thesis by auto
   621     ultimately show ?thesis by auto
   646   by (unfold s_def depend_set_unchanged, auto)
   646   by (unfold s_def depend_set_unchanged, auto)
   647 
   647 
   648 lemma eq_cp_pre:
   648 lemma eq_cp_pre:
   649   fixes th' 
   649   fixes th' 
   650   assumes neq_th: "th' \<noteq> th"
   650   assumes neq_th: "th' \<noteq> th"
   651   and nd: "th \<notin> dependents s th'"
   651   and nd: "th \<notin> dependants s th'"
   652   shows "cp s th' = cp s' th'"
   652   shows "cp s th' = cp s' th'"
   653   apply (unfold cp_eq_cpreced cpreced_def)
   653   apply (unfold cp_eq_cpreced cpreced_def)
   654 proof -
   654 proof -
   655   have eq_dp: "\<And> th. dependents (wq s) th = dependents (wq s') th"
   655   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
   656     by (unfold cs_dependents_def, auto simp:eq_dep eq_depend)
   656     by (unfold cs_dependants_def, auto simp:eq_dep eq_depend)
   657   moreover {
   657   moreover {
   658     fix th1 
   658     fix th1 
   659     assume "th1 \<in> {th'} \<union> dependents (wq s') th'"
   659     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
   660     hence "th1 = th' \<or> th1 \<in> dependents (wq s') th'" by auto
   660     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
   661     hence "preced th1 s = preced th1 s'"
   661     hence "preced th1 s = preced th1 s'"
   662     proof
   662     proof
   663       assume "th1 = th'"
   663       assume "th1 = th'"
   664       with eq_preced[OF neq_th]
   664       with eq_preced[OF neq_th]
   665       show "preced th1 s = preced th1 s'" by simp
   665       show "preced th1 s = preced th1 s'" by simp
   666     next
   666     next
   667       assume "th1 \<in> dependents (wq s') th'"
   667       assume "th1 \<in> dependants (wq s') th'"
   668       with nd and eq_dp have "th1 \<noteq> th"
   668       with nd and eq_dp have "th1 \<noteq> th"
   669         by (auto simp:eq_depend cs_dependents_def s_dependents_def eq_dep)
   669         by (auto simp:eq_depend cs_dependants_def s_dependants_def eq_dep)
   670       from eq_preced[OF this] show "preced th1 s = preced th1 s'" by simp
   670       from eq_preced[OF this] show "preced th1 s = preced th1 s'" by simp
   671     qed
   671     qed
   672   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) = 
   672   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
   673                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" 
   673                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
   674     by (auto simp:image_def)
   674     by (auto simp:image_def)
   675   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) =
   675   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
   676         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" by simp
   676         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
   677 qed
   677 qed
   678 
   678 
   679 lemma no_dependents:
   679 lemma no_dependants:
   680   assumes "th' \<noteq> th"
   680   assumes "th' \<noteq> th"
   681   shows "th \<notin> dependents s th'"
   681   shows "th \<notin> dependants s th'"
   682 proof
   682 proof
   683   assume h: "th \<in> dependents s th'"
   683   assume h: "th \<in> dependants s th'"
   684   from step_back_step [OF vt_s[unfolded s_def]]
   684   from step_back_step [OF vt_s[unfolded s_def]]
   685   have "step s' (Set th prio)" .
   685   have "step s' (Set th prio)" .
   686   hence "th \<in> runing s'" by (cases, simp)
   686   hence "th \<in> runing s'" by (cases, simp)
   687   hence rd_th: "th \<in> readys s'" 
   687   hence rd_th: "th \<in> readys s'" 
   688     by (simp add:readys_def runing_def)
   688     by (simp add:readys_def runing_def)
   689   from h have "(Th th, Th th') \<in> (depend s')\<^sup>+"
   689   from h have "(Th th, Th th') \<in> (depend s')\<^sup>+"
   690     by (unfold s_dependents_def, unfold eq_depend, unfold eq_dep, auto)
   690     by (unfold s_dependants_def, unfold eq_depend, unfold eq_dep, auto)
   691   from tranclD[OF this]
   691   from tranclD[OF this]
   692   obtain z where "(Th th, z) \<in> depend s'" by auto
   692   obtain z where "(Th th, z) \<in> depend s'" by auto
   693   with rd_th show "False"
   693   with rd_th show "False"
   694     apply (case_tac z, auto simp:readys_def s_waiting_def s_depend_def s_waiting_def cs_waiting_def)
   694     apply (case_tac z, auto simp:readys_def s_waiting_def s_depend_def s_waiting_def cs_waiting_def)
   695     by (fold wq_def, blast)
   695     by (fold wq_def, blast)
   699 lemma eq_cp:
   699 lemma eq_cp:
   700  fixes th' 
   700  fixes th' 
   701   assumes neq_th: "th' \<noteq> th"
   701   assumes neq_th: "th' \<noteq> th"
   702   shows "cp s th' = cp s' th'"
   702   shows "cp s th' = cp s' th'"
   703 proof(rule eq_cp_pre [OF neq_th])
   703 proof(rule eq_cp_pre [OF neq_th])
   704   from no_dependents[OF neq_th] 
   704   from no_dependants[OF neq_th] 
   705   show "th \<notin> dependents s th'" .
   705   show "th \<notin> dependants s th'" .
   706 qed
   706 qed
   707 
   707 
   708 lemma eq_up:
   708 lemma eq_up:
   709   fixes th' th''
   709   fixes th' th''
   710   assumes dp1: "th \<in> dependents s th'"
   710   assumes dp1: "th \<in> dependants s th'"
   711   and dp2: "th' \<in> dependents s th''"
   711   and dp2: "th' \<in> dependants s th''"
   712   and eq_cps: "cp s th' = cp s' th'"
   712   and eq_cps: "cp s th' = cp s' th'"
   713   shows "cp s th'' = cp s' th''"
   713   shows "cp s th'' = cp s' th''"
   714 proof -
   714 proof -
   715   from dp2
   715   from dp2
   716   have "(Th th', Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependents_def)
   716   have "(Th th', Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependants_def)
   717   from depend_child[OF vt_s this[unfolded eq_depend]]
   717   from depend_child[OF vt_s this[unfolded eq_depend]]
   718   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
   718   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
   719   moreover { fix n th''
   719   moreover { fix n th''
   720     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   720     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   721                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   721                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   724       assume y_ch: "(y, Th th'') \<in> child s"
   724       assume y_ch: "(y, Th th'') \<in> child s"
   725         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
   725         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
   726         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
   726         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
   727       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
   727       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
   728       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
   728       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
   729       from dp1 have "(Th th, Th th') \<in> (depend s)^+" by (auto simp:s_dependents_def eq_depend)
   729       from dp1 have "(Th th, Th th') \<in> (depend s)^+" by (auto simp:s_dependants_def eq_depend)
   730       moreover from child_depend_p[OF ch'] and eq_y
   730       moreover from child_depend_p[OF ch'] and eq_y
   731       have "(Th th', Th thy) \<in> (depend s)^+" by simp
   731       have "(Th th', Th thy) \<in> (depend s)^+" by simp
   732       ultimately have dp_thy: "(Th th, Th thy) \<in> (depend s)^+" by auto
   732       ultimately have dp_thy: "(Th th, Th thy) \<in> (depend s)^+" by auto
   733       show "cp s th'' = cp s' th''"
   733       show "cp s th'' = cp s' th''"
   734         apply (subst cp_rec[OF vt_s])
   734         apply (subst cp_rec[OF vt_s])
   759               assume eq_th1: "th1 = th"
   759               assume eq_th1: "th1 = th"
   760               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
   760               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
   761               from children_no_dep[OF vt_s _ _ this] and 
   761               from children_no_dep[OF vt_s _ _ this] and 
   762               th1_in y_ch eq_y show False by (auto simp:children_def)
   762               th1_in y_ch eq_y show False by (auto simp:children_def)
   763             qed
   763             qed
   764             have "th \<notin> dependents s th1"
   764             have "th \<notin> dependants s th1"
   765             proof
   765             proof
   766               assume h:"th \<in> dependents s th1"
   766               assume h:"th \<in> dependants s th1"
   767               from eq_y dp_thy have "th \<in> dependents s thy" by (auto simp:s_dependents_def eq_depend)
   767               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_depend)
   768               from dependents_child_unique[OF vt_s _ _ h this]
   768               from dependants_child_unique[OF vt_s _ _ h this]
   769               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   769               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   770               with False show False by auto
   770               with False show False by auto
   771             qed
   771             qed
   772             from eq_cp_pre[OF neq_th1 this]
   772             from eq_cp_pre[OF neq_th1 this]
   773             show ?thesis .
   773             show ?thesis .
   791           show "th'' \<noteq> th"
   791           show "th'' \<noteq> th"
   792           proof
   792           proof
   793             assume "th'' = th"
   793             assume "th'' = th"
   794             with dp1 dp'
   794             with dp1 dp'
   795             have "(Th th, Th th) \<in> (depend s)^+"
   795             have "(Th th, Th th) \<in> (depend s)^+"
   796               by (auto simp:child_def s_dependents_def eq_depend)
   796               by (auto simp:child_def s_dependants_def eq_depend)
   797             with wf_trancl[OF wf_depend[OF vt_s]] 
   797             with wf_trancl[OF wf_depend[OF vt_s]] 
   798             show False by auto
   798             show False by auto
   799           qed
   799           qed
   800         qed
   800         qed
   801         moreover { 
   801         moreover { 
   809             case False
   809             case False
   810             have neq_th1: "th1 \<noteq> th"
   810             have neq_th1: "th1 \<noteq> th"
   811             proof
   811             proof
   812               assume eq_th1: "th1 = th"
   812               assume eq_th1: "th1 = th"
   813               with dp1 have "(Th th1, Th th') \<in> (depend s)^+" 
   813               with dp1 have "(Th th1, Th th') \<in> (depend s)^+" 
   814                 by (auto simp:s_dependents_def eq_depend)
   814                 by (auto simp:s_dependants_def eq_depend)
   815               from children_no_dep[OF vt_s _ _ this]
   815               from children_no_dep[OF vt_s _ _ this]
   816               th1_in dp'
   816               th1_in dp'
   817               show False by (auto simp:children_def)
   817               show False by (auto simp:children_def)
   818             qed
   818             qed
   819             thus ?thesis
   819             thus ?thesis
   820             proof(rule eq_cp_pre)
   820             proof(rule eq_cp_pre)
   821               show "th \<notin> dependents s th1"
   821               show "th \<notin> dependants s th1"
   822               proof
   822               proof
   823                 assume "th \<in> dependents s th1"
   823                 assume "th \<in> dependants s th1"
   824                 from dependents_child_unique[OF vt_s _ _ this dp1]
   824                 from dependants_child_unique[OF vt_s _ _ this dp1]
   825                 th1_in dp' have "th1 = th'"
   825                 th1_in dp' have "th1 = th'"
   826                   by (auto simp:children_def)
   826                   by (auto simp:children_def)
   827                 with False show False by auto
   827                 with False show False by auto
   828               qed
   828               qed
   829             qed
   829             qed
   841   ultimately show ?thesis by auto
   841   ultimately show ?thesis by auto
   842 qed
   842 qed
   843 
   843 
   844 lemma eq_up_self:
   844 lemma eq_up_self:
   845   fixes th' th''
   845   fixes th' th''
   846   assumes dp: "th \<in> dependents s th''"
   846   assumes dp: "th \<in> dependants s th''"
   847   and eq_cps: "cp s th = cp s' th"
   847   and eq_cps: "cp s th = cp s' th"
   848   shows "cp s th'' = cp s' th''"
   848   shows "cp s th'' = cp s' th''"
   849 proof -
   849 proof -
   850   from dp
   850   from dp
   851   have "(Th th, Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependents_def)
   851   have "(Th th, Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependants_def)
   852   from depend_child[OF vt_s this[unfolded eq_depend]]
   852   from depend_child[OF vt_s this[unfolded eq_depend]]
   853   have ch_th': "(Th th, Th th'') \<in> (child s)\<^sup>+" .
   853   have ch_th': "(Th th, Th th'') \<in> (child s)\<^sup>+" .
   854   moreover { fix n th''
   854   moreover { fix n th''
   855     have "\<lbrakk>(Th th, n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   855     have "\<lbrakk>(Th th, n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
   856                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   856                    (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
   892               assume eq_th1: "th1 = th"
   892               assume eq_th1: "th1 = th"
   893               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
   893               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
   894               from children_no_dep[OF vt_s _ _ this] and 
   894               from children_no_dep[OF vt_s _ _ this] and 
   895               th1_in y_ch eq_y show False by (auto simp:children_def)
   895               th1_in y_ch eq_y show False by (auto simp:children_def)
   896             qed
   896             qed
   897             have "th \<notin> dependents s th1"
   897             have "th \<notin> dependants s th1"
   898             proof
   898             proof
   899               assume h:"th \<in> dependents s th1"
   899               assume h:"th \<in> dependants s th1"
   900               from eq_y dp_thy have "th \<in> dependents s thy" by (auto simp:s_dependents_def eq_depend)
   900               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_depend)
   901               from dependents_child_unique[OF vt_s _ _ h this]
   901               from dependants_child_unique[OF vt_s _ _ h this]
   902               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   902               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
   903               with False show False by auto
   903               with False show False by auto
   904             qed
   904             qed
   905             from eq_cp_pre[OF neq_th1 this]
   905             from eq_cp_pre[OF neq_th1 this]
   906             show ?thesis .
   906             show ?thesis .
   924           show "th'' \<noteq> th"
   924           show "th'' \<noteq> th"
   925           proof
   925           proof
   926             assume "th'' = th"
   926             assume "th'' = th"
   927             with dp dp'
   927             with dp dp'
   928             have "(Th th, Th th) \<in> (depend s)^+"
   928             have "(Th th, Th th) \<in> (depend s)^+"
   929               by (auto simp:child_def s_dependents_def eq_depend)
   929               by (auto simp:child_def s_dependants_def eq_depend)
   930             with wf_trancl[OF wf_depend[OF vt_s]] 
   930             with wf_trancl[OF wf_depend[OF vt_s]] 
   931             show False by auto
   931             show False by auto
   932           qed
   932           qed
   933         qed
   933         qed
   934         moreover { 
   934         moreover { 
   941           next
   941           next
   942             case False
   942             case False
   943             assume neq_th1: "th1 \<noteq> th"
   943             assume neq_th1: "th1 \<noteq> th"
   944             thus ?thesis
   944             thus ?thesis
   945             proof(rule eq_cp_pre)
   945             proof(rule eq_cp_pre)
   946               show "th \<notin> dependents s th1"
   946               show "th \<notin> dependants s th1"
   947               proof
   947               proof
   948                 assume "th \<in> dependents s th1"
   948                 assume "th \<in> dependants s th1"
   949                 hence "(Th th, Th th1) \<in> (depend s)^+" by (auto simp:s_dependents_def eq_depend)
   949                 hence "(Th th, Th th1) \<in> (depend s)^+" by (auto simp:s_dependants_def eq_depend)
   950                 from children_no_dep[OF vt_s _ _ this]
   950                 from children_no_dep[OF vt_s _ _ this]
   951                 and th1_in dp' show False
   951                 and th1_in dp' show False
   952                   by (auto simp:children_def)
   952                   by (auto simp:children_def)
   953               qed
   953               qed
   954             qed
   954             qed
  1044 proof -
  1044 proof -
  1045   from step_depend_v[OF vt_s[unfolded s_def], folded s_def]
  1045   from step_depend_v[OF vt_s[unfolded s_def], folded s_def]
  1046     and nt show ?thesis  by (auto intro:next_th_unique)
  1046     and nt show ?thesis  by (auto intro:next_th_unique)
  1047 qed
  1047 qed
  1048 
  1048 
  1049 lemma dependents_kept:
  1049 lemma dependants_kept:
  1050   fixes th''
  1050   fixes th''
  1051   assumes neq1: "th'' \<noteq> th"
  1051   assumes neq1: "th'' \<noteq> th"
  1052   and neq2: "th'' \<noteq> th'"
  1052   and neq2: "th'' \<noteq> th'"
  1053   shows "dependents (wq s) th'' = dependents (wq s') th''"
  1053   shows "dependants (wq s) th'' = dependants (wq s') th''"
  1054 proof(auto)
  1054 proof(auto)
  1055   fix x
  1055   fix x
  1056   assume "x \<in> dependents (wq s) th''"
  1056   assume "x \<in> dependants (wq s) th''"
  1057   hence dp: "(Th x, Th th'') \<in> (depend s)^+"
  1057   hence dp: "(Th x, Th th'') \<in> (depend s)^+"
  1058     by (auto simp:cs_dependents_def eq_depend)
  1058     by (auto simp:cs_dependants_def eq_depend)
  1059   { fix n
  1059   { fix n
  1060     have "(n, Th th'') \<in> (depend s)^+ \<Longrightarrow>  (n, Th th'') \<in> (depend s')^+"
  1060     have "(n, Th th'') \<in> (depend s)^+ \<Longrightarrow>  (n, Th th'') \<in> (depend s')^+"
  1061     proof(induct rule:converse_trancl_induct)
  1061     proof(induct rule:converse_trancl_induct)
  1062       fix y 
  1062       fix y 
  1063       assume "(y, Th th'') \<in> depend s"
  1063       assume "(y, Th th'') \<in> depend s"
  1118       with ztp'
  1118       with ztp'
  1119       show "(y, Th th'') \<in> (depend s')\<^sup>+" by auto
  1119       show "(y, Th th'') \<in> (depend s')\<^sup>+" by auto
  1120     qed    
  1120     qed    
  1121   }
  1121   }
  1122   from this[OF dp]
  1122   from this[OF dp]
  1123   show "x \<in> dependents (wq s') th''" 
  1123   show "x \<in> dependants (wq s') th''" 
  1124     by (auto simp:cs_dependents_def eq_depend)
  1124     by (auto simp:cs_dependants_def eq_depend)
  1125 next
  1125 next
  1126   fix x
  1126   fix x
  1127   assume "x \<in> dependents (wq s') th''"
  1127   assume "x \<in> dependants (wq s') th''"
  1128   hence dp: "(Th x, Th th'') \<in> (depend s')^+"
  1128   hence dp: "(Th x, Th th'') \<in> (depend s')^+"
  1129     by (auto simp:cs_dependents_def eq_depend)
  1129     by (auto simp:cs_dependants_def eq_depend)
  1130   { fix n
  1130   { fix n
  1131     have "(n, Th th'') \<in> (depend s')^+ \<Longrightarrow>  (n, Th th'') \<in> (depend s)^+"
  1131     have "(n, Th th'') \<in> (depend s')^+ \<Longrightarrow>  (n, Th th'') \<in> (depend s)^+"
  1132     proof(induct rule:converse_trancl_induct)
  1132     proof(induct rule:converse_trancl_induct)
  1133       fix y 
  1133       fix y 
  1134       assume "(y, Th th'') \<in> depend s'"
  1134       assume "(y, Th th'') \<in> depend s'"
  1207       with ztp'
  1207       with ztp'
  1208       show "(y, Th th'') \<in> (depend s)\<^sup>+" by auto
  1208       show "(y, Th th'') \<in> (depend s)\<^sup>+" by auto
  1209     qed    
  1209     qed    
  1210   }
  1210   }
  1211   from this[OF dp]
  1211   from this[OF dp]
  1212   show "x \<in> dependents (wq s) th''"
  1212   show "x \<in> dependants (wq s) th''"
  1213     by (auto simp:cs_dependents_def eq_depend)
  1213     by (auto simp:cs_dependants_def eq_depend)
  1214 qed
  1214 qed
  1215 
  1215 
  1216 lemma cp_kept:
  1216 lemma cp_kept:
  1217   fixes th''
  1217   fixes th''
  1218   assumes neq1: "th'' \<noteq> th"
  1218   assumes neq1: "th'' \<noteq> th"
  1219   and neq2: "th'' \<noteq> th'"
  1219   and neq2: "th'' \<noteq> th'"
  1220   shows "cp s th'' = cp s' th''"
  1220   shows "cp s th'' = cp s' th''"
  1221 proof -
  1221 proof -
  1222   from dependents_kept[OF neq1 neq2]
  1222   from dependants_kept[OF neq1 neq2]
  1223   have "dependents (wq s) th'' = dependents (wq s') th''" .
  1223   have "dependants (wq s) th'' = dependants (wq s') th''" .
  1224   moreover {
  1224   moreover {
  1225     fix th1
  1225     fix th1
  1226     assume "th1 \<in> dependents (wq s) th''"
  1226     assume "th1 \<in> dependants (wq s) th''"
  1227     have "preced th1 s = preced th1 s'" 
  1227     have "preced th1 s = preced th1 s'" 
  1228       by (unfold s_def, auto simp:preced_def)
  1228       by (unfold s_def, auto simp:preced_def)
  1229   }
  1229   }
  1230   moreover have "preced th'' s = preced th'' s'" 
  1230   moreover have "preced th'' s = preced th'' s'" 
  1231     by (unfold s_def, auto simp:preced_def)
  1231     by (unfold s_def, auto simp:preced_def)
  1232   ultimately have "((\<lambda>th. preced th s) ` ({th''} \<union> dependents (wq s) th'')) = 
  1232   ultimately have "((\<lambda>th. preced th s) ` ({th''} \<union> dependants (wq s) th'')) = 
  1233     ((\<lambda>th. preced th s') ` ({th''} \<union> dependents (wq s') th''))"
  1233     ((\<lambda>th. preced th s') ` ({th''} \<union> dependants (wq s') th''))"
  1234     by (auto simp:image_def)
  1234     by (auto simp:image_def)
  1235   thus ?thesis
  1235   thus ?thesis
  1236     by (unfold cp_eq_cpreced cpreced_def, simp)
  1236     by (unfold cp_eq_cpreced cpreced_def, simp)
  1237 qed
  1237 qed
  1238 
  1238 
  1350 lemma eq_cp:
  1350 lemma eq_cp:
  1351   fixes th' 
  1351   fixes th' 
  1352   shows "cp s th' = cp s' th'"
  1352   shows "cp s th' = cp s' th'"
  1353   apply (unfold cp_eq_cpreced cpreced_def)
  1353   apply (unfold cp_eq_cpreced cpreced_def)
  1354 proof -
  1354 proof -
  1355   have eq_dp: "\<And> th. dependents (wq s) th = dependents (wq s') th"
  1355   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1356     apply (unfold cs_dependents_def, unfold eq_depend)
  1356     apply (unfold cs_dependants_def, unfold eq_depend)
  1357   proof -
  1357   proof -
  1358     from eq_child
  1358     from eq_child
  1359     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1359     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1360       by simp
  1360       by simp
  1361     with child_depend_eq[OF vt_s] child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1361     with child_depend_eq[OF vt_s] child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1362     show "\<And>th. {th'. (Th th', Th th) \<in> (depend s)\<^sup>+} = {th'. (Th th', Th th) \<in> (depend s')\<^sup>+}"
  1362     show "\<And>th. {th'. (Th th', Th th) \<in> (depend s)\<^sup>+} = {th'. (Th th', Th th) \<in> (depend s')\<^sup>+}"
  1363       by simp
  1363       by simp
  1364   qed
  1364   qed
  1365   moreover {
  1365   moreover {
  1366     fix th1 
  1366     fix th1 
  1367     assume "th1 \<in> {th'} \<union> dependents (wq s') th'"
  1367     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1368     hence "th1 = th' \<or> th1 \<in> dependents (wq s') th'" by auto
  1368     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1369     hence "preced th1 s = preced th1 s'"
  1369     hence "preced th1 s = preced th1 s'"
  1370     proof
  1370     proof
  1371       assume "th1 = th'"
  1371       assume "th1 = th'"
  1372       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1372       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1373     next
  1373     next
  1374       assume "th1 \<in> dependents (wq s') th'"
  1374       assume "th1 \<in> dependants (wq s') th'"
  1375       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1375       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1376     qed
  1376     qed
  1377   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) = 
  1377   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1378                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" 
  1378                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1379     by (auto simp:image_def)
  1379     by (auto simp:image_def)
  1380   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) =
  1380   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
  1381         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" by simp
  1381         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
  1382 qed
  1382 qed
  1383 
  1383 
  1384 end
  1384 end
  1385 
  1385 
  1386 locale step_P_cps =
  1386 locale step_P_cps =
  1494 lemma eq_cp:
  1494 lemma eq_cp:
  1495   fixes th' 
  1495   fixes th' 
  1496   shows "cp s th' = cp s' th'"
  1496   shows "cp s th' = cp s' th'"
  1497   apply (unfold cp_eq_cpreced cpreced_def)
  1497   apply (unfold cp_eq_cpreced cpreced_def)
  1498 proof -
  1498 proof -
  1499   have eq_dp: "\<And> th. dependents (wq s) th = dependents (wq s') th"
  1499   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1500     apply (unfold cs_dependents_def, unfold eq_depend)
  1500     apply (unfold cs_dependants_def, unfold eq_depend)
  1501   proof -
  1501   proof -
  1502     from eq_child
  1502     from eq_child
  1503     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1503     have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
  1504       by auto
  1504       by auto
  1505     with child_depend_eq[OF vt_s] child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1505     with child_depend_eq[OF vt_s] child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1506     show "\<And>th. {th'. (Th th', Th th) \<in> (depend s)\<^sup>+} = {th'. (Th th', Th th) \<in> (depend s')\<^sup>+}"
  1506     show "\<And>th. {th'. (Th th', Th th) \<in> (depend s)\<^sup>+} = {th'. (Th th', Th th) \<in> (depend s')\<^sup>+}"
  1507       by simp
  1507       by simp
  1508   qed
  1508   qed
  1509   moreover {
  1509   moreover {
  1510     fix th1 
  1510     fix th1 
  1511     assume "th1 \<in> {th'} \<union> dependents (wq s') th'"
  1511     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1512     hence "th1 = th' \<or> th1 \<in> dependents (wq s') th'" by auto
  1512     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1513     hence "preced th1 s = preced th1 s'"
  1513     hence "preced th1 s = preced th1 s'"
  1514     proof
  1514     proof
  1515       assume "th1 = th'"
  1515       assume "th1 = th'"
  1516       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1516       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1517     next
  1517     next
  1518       assume "th1 \<in> dependents (wq s') th'"
  1518       assume "th1 \<in> dependants (wq s') th'"
  1519       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1519       show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1520     qed
  1520     qed
  1521   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) = 
  1521   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1522                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" 
  1522                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1523     by (auto simp:image_def)
  1523     by (auto simp:image_def)
  1524   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) =
  1524   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
  1525         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" by simp
  1525         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
  1526 qed
  1526 qed
  1527 
  1527 
  1528 end
  1528 end
  1529 
  1529 
  1530 context step_P_cps_ne
  1530 context step_P_cps_ne
  1595   shows "((n1, Th th') \<in> (child s)^+) = ((n1, Th th') \<in> (child s')^+)"
  1595   shows "((n1, Th th') \<in> (child s)^+) = ((n1, Th th') \<in> (child s')^+)"
  1596   by (insert eq_child_left[OF nd] eq_child_right, auto)
  1596   by (insert eq_child_left[OF nd] eq_child_right, auto)
  1597 
  1597 
  1598 lemma eq_cp:
  1598 lemma eq_cp:
  1599   fixes th' 
  1599   fixes th' 
  1600   assumes nd: "th \<notin> dependents s th'"
  1600   assumes nd: "th \<notin> dependants s th'"
  1601   shows "cp s th' = cp s' th'"
  1601   shows "cp s th' = cp s' th'"
  1602   apply (unfold cp_eq_cpreced cpreced_def)
  1602   apply (unfold cp_eq_cpreced cpreced_def)
  1603 proof -
  1603 proof -
  1604   have nd': "(Th th, Th th') \<notin> (child s)^+"
  1604   have nd': "(Th th, Th th') \<notin> (child s)^+"
  1605   proof
  1605   proof
  1606     assume "(Th th, Th th') \<in> (child s)\<^sup>+"
  1606     assume "(Th th, Th th') \<in> (child s)\<^sup>+"
  1607     with child_depend_eq[OF vt_s]
  1607     with child_depend_eq[OF vt_s]
  1608     have "(Th th, Th th') \<in> (depend s)\<^sup>+" by simp
  1608     have "(Th th, Th th') \<in> (depend s)\<^sup>+" by simp
  1609     with nd show False 
  1609     with nd show False 
  1610       by (simp add:s_dependents_def eq_depend)
  1610       by (simp add:s_dependants_def eq_depend)
  1611   qed
  1611   qed
  1612   have eq_dp: "dependents (wq s) th' = dependents (wq s') th'"
  1612   have eq_dp: "dependants (wq s) th' = dependants (wq s') th'"
  1613   proof(auto)
  1613   proof(auto)
  1614     fix x assume " x \<in> dependents (wq s) th'"
  1614     fix x assume " x \<in> dependants (wq s) th'"
  1615     thus "x \<in> dependents (wq s') th'"
  1615     thus "x \<in> dependants (wq s') th'"
  1616       apply (auto simp:cs_dependents_def eq_depend)
  1616       apply (auto simp:cs_dependants_def eq_depend)
  1617     proof -
  1617     proof -
  1618       assume "(Th x, Th th') \<in> (depend s)\<^sup>+"
  1618       assume "(Th x, Th th') \<in> (depend s)\<^sup>+"
  1619       with  child_depend_eq[OF vt_s] have "(Th x, Th th') \<in> (child s)\<^sup>+" by simp
  1619       with  child_depend_eq[OF vt_s] have "(Th x, Th th') \<in> (child s)\<^sup>+" by simp
  1620       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s')^+" by simp
  1620       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s')^+" by simp
  1621       with child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1621       with child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1622       show "(Th x, Th th') \<in> (depend s')\<^sup>+" by simp
  1622       show "(Th x, Th th') \<in> (depend s')\<^sup>+" by simp
  1623     qed
  1623     qed
  1624   next
  1624   next
  1625     fix x assume "x \<in> dependents (wq s') th'"
  1625     fix x assume "x \<in> dependants (wq s') th'"
  1626     thus "x \<in> dependents (wq s) th'"
  1626     thus "x \<in> dependants (wq s) th'"
  1627       apply (auto simp:cs_dependents_def eq_depend)
  1627       apply (auto simp:cs_dependants_def eq_depend)
  1628     proof -
  1628     proof -
  1629       assume "(Th x, Th th') \<in> (depend s')\<^sup>+"
  1629       assume "(Th x, Th th') \<in> (depend s')\<^sup>+"
  1630       with child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]] 
  1630       with child_depend_eq[OF step_back_vt[OF vt_s[unfolded s_def]]] 
  1631       have "(Th x, Th th') \<in> (child s')\<^sup>+" by simp
  1631       have "(Th x, Th th') \<in> (child s')\<^sup>+" by simp
  1632       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s)^+" by simp
  1632       with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s)^+" by simp
  1634       show "(Th x, Th th') \<in> (depend s)\<^sup>+" by simp
  1634       show "(Th x, Th th') \<in> (depend s)\<^sup>+" by simp
  1635     qed
  1635     qed
  1636   qed
  1636   qed
  1637   moreover {
  1637   moreover {
  1638     fix th1 have "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1638     fix th1 have "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
  1639   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) = 
  1639   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1640                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" 
  1640                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1641     by (auto simp:image_def)
  1641     by (auto simp:image_def)
  1642   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) =
  1642   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
  1643         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" by simp
  1643         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
  1644 qed
  1644 qed
  1645 
  1645 
  1646 lemma eq_up:
  1646 lemma eq_up:
  1647   fixes th' th''
  1647   fixes th' th''
  1648   assumes dp1: "th \<in> dependents s th'"
  1648   assumes dp1: "th \<in> dependants s th'"
  1649   and dp2: "th' \<in> dependents s th''"
  1649   and dp2: "th' \<in> dependants s th''"
  1650   and eq_cps: "cp s th' = cp s' th'"
  1650   and eq_cps: "cp s th' = cp s' th'"
  1651   shows "cp s th'' = cp s' th''"
  1651   shows "cp s th'' = cp s' th''"
  1652 proof -
  1652 proof -
  1653   from dp2
  1653   from dp2
  1654   have "(Th th', Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependents_def)
  1654   have "(Th th', Th th'') \<in> (depend (wq s))\<^sup>+" by (simp add:s_dependants_def)
  1655   from depend_child[OF vt_s this[unfolded eq_depend]]
  1655   from depend_child[OF vt_s this[unfolded eq_depend]]
  1656   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
  1656   have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
  1657   moreover {
  1657   moreover {
  1658     fix n th''
  1658     fix n th''
  1659     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
  1659     have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
  1663       assume y_ch: "(y, Th th'') \<in> child s"
  1663       assume y_ch: "(y, Th th'') \<in> child s"
  1664         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
  1664         and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
  1665         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
  1665         and ch': "(Th th', y) \<in> (child s)\<^sup>+"
  1666       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
  1666       from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
  1667       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
  1667       with ih have eq_cpy:"cp s thy = cp s' thy" by blast
  1668       from dp1 have "(Th th, Th th') \<in> (depend s)^+" by (auto simp:s_dependents_def eq_depend)
  1668       from dp1 have "(Th th, Th th') \<in> (depend s)^+" by (auto simp:s_dependants_def eq_depend)
  1669       moreover from child_depend_p[OF ch'] and eq_y
  1669       moreover from child_depend_p[OF ch'] and eq_y
  1670       have "(Th th', Th thy) \<in> (depend s)^+" by simp
  1670       have "(Th th', Th thy) \<in> (depend s)^+" by simp
  1671       ultimately have dp_thy: "(Th th, Th thy) \<in> (depend s)^+" by auto
  1671       ultimately have dp_thy: "(Th th, Th thy) \<in> (depend s)^+" by auto
  1672       show "cp s th'' = cp s' th''"
  1672       show "cp s th'' = cp s' th''"
  1673         apply (subst cp_rec[OF vt_s])
  1673         apply (subst cp_rec[OF vt_s])
  1688               assume eq_th1: "th1 = th"
  1688               assume eq_th1: "th1 = th"
  1689               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
  1689               with dp_thy have "(Th th1, Th thy) \<in> (depend s)^+" by simp
  1690               from children_no_dep[OF vt_s _ _ this] and 
  1690               from children_no_dep[OF vt_s _ _ this] and 
  1691               th1_in y_ch eq_y show False by (auto simp:children_def)
  1691               th1_in y_ch eq_y show False by (auto simp:children_def)
  1692             qed
  1692             qed
  1693             have "th \<notin> dependents s th1"
  1693             have "th \<notin> dependants s th1"
  1694             proof
  1694             proof
  1695               assume h:"th \<in> dependents s th1"
  1695               assume h:"th \<in> dependants s th1"
  1696               from eq_y dp_thy have "th \<in> dependents s thy" by (auto simp:s_dependents_def eq_depend)
  1696               from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_depend)
  1697               from dependents_child_unique[OF vt_s _ _ h this]
  1697               from dependants_child_unique[OF vt_s _ _ h this]
  1698               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
  1698               th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
  1699               with False show False by auto
  1699               with False show False by auto
  1700             qed
  1700             qed
  1701             from eq_cp[OF this]
  1701             from eq_cp[OF this]
  1702             show ?thesis .
  1702             show ?thesis .
  1709           apply (fold s_def, auto simp:depend_s)
  1709           apply (fold s_def, auto simp:depend_s)
  1710           proof -
  1710           proof -
  1711             assume "(Cs cs, Th th'') \<in> depend s'"
  1711             assume "(Cs cs, Th th'') \<in> depend s'"
  1712             with depend_s have cs_th': "(Cs cs, Th th'') \<in> depend s" by auto
  1712             with depend_s have cs_th': "(Cs cs, Th th'') \<in> depend s" by auto
  1713             from dp1 have "(Th th, Th th') \<in> (depend s)^+"
  1713             from dp1 have "(Th th, Th th') \<in> (depend s)^+"
  1714               by (auto simp:s_dependents_def eq_depend)
  1714               by (auto simp:s_dependants_def eq_depend)
  1715             from converse_tranclE[OF this]
  1715             from converse_tranclE[OF this]
  1716             obtain cs1 where h1: "(Th th, Cs cs1) \<in> depend s"
  1716             obtain cs1 where h1: "(Th th, Cs cs1) \<in> depend s"
  1717               and h2: "(Cs cs1 , Th th') \<in> (depend s)\<^sup>+"
  1717               and h2: "(Cs cs1 , Th th') \<in> (depend s)\<^sup>+"
  1718               by (auto simp:s_depend_def)
  1718               by (auto simp:s_depend_def)
  1719             have eq_cs: "cs1 = cs" 
  1719             have eq_cs: "cs1 = cs" 
  1770             case False
  1770             case False
  1771             have neq_th1: "th1 \<noteq> th"
  1771             have neq_th1: "th1 \<noteq> th"
  1772             proof
  1772             proof
  1773               assume eq_th1: "th1 = th"
  1773               assume eq_th1: "th1 = th"
  1774               with dp1 have "(Th th1, Th th') \<in> (depend s)^+" 
  1774               with dp1 have "(Th th1, Th th') \<in> (depend s)^+" 
  1775                 by (auto simp:s_dependents_def eq_depend)
  1775                 by (auto simp:s_dependants_def eq_depend)
  1776               from children_no_dep[OF vt_s _ _ this]
  1776               from children_no_dep[OF vt_s _ _ this]
  1777               th1_in dp'
  1777               th1_in dp'
  1778               show False by (auto simp:children_def)
  1778               show False by (auto simp:children_def)
  1779             qed
  1779             qed
  1780             show ?thesis
  1780             show ?thesis
  1781             proof(rule eq_cp)
  1781             proof(rule eq_cp)
  1782               show "th \<notin> dependents s th1"
  1782               show "th \<notin> dependants s th1"
  1783               proof
  1783               proof
  1784                 assume "th \<in> dependents s th1"
  1784                 assume "th \<in> dependants s th1"
  1785                 from dependents_child_unique[OF vt_s _ _ this dp1]
  1785                 from dependants_child_unique[OF vt_s _ _ this dp1]
  1786                 th1_in dp' have "th1 = th'"
  1786                 th1_in dp' have "th1 = th'"
  1787                   by (auto simp:children_def)
  1787                   by (auto simp:children_def)
  1788                 with False show False by auto
  1788                 with False show False by auto
  1789               qed
  1789               qed
  1790             qed
  1790             qed
  1797           apply (fold s_def, auto simp:depend_s)
  1797           apply (fold s_def, auto simp:depend_s)
  1798           proof -
  1798           proof -
  1799             assume "(Cs cs, Th th'') \<in> depend s'"
  1799             assume "(Cs cs, Th th'') \<in> depend s'"
  1800             with depend_s have cs_th': "(Cs cs, Th th'') \<in> depend s" by auto
  1800             with depend_s have cs_th': "(Cs cs, Th th'') \<in> depend s" by auto
  1801             from dp1 have "(Th th, Th th') \<in> (depend s)^+"
  1801             from dp1 have "(Th th, Th th') \<in> (depend s)^+"
  1802               by (auto simp:s_dependents_def eq_depend)
  1802               by (auto simp:s_dependants_def eq_depend)
  1803             from converse_tranclE[OF this]
  1803             from converse_tranclE[OF this]
  1804             obtain cs1 where h1: "(Th th, Cs cs1) \<in> depend s"
  1804             obtain cs1 where h1: "(Th th, Cs cs1) \<in> depend s"
  1805               and h2: "(Cs cs1 , Th th') \<in> (depend s)\<^sup>+"
  1805               and h2: "(Cs cs1 , Th th') \<in> (depend s)\<^sup>+"
  1806               by (auto simp:s_depend_def)
  1806               by (auto simp:s_depend_def)
  1807             have eq_cs: "cs1 = cs" 
  1807             have eq_cs: "cs1 = cs" 
  1861   fixes th' 
  1861   fixes th' 
  1862   assumes neq_th: "th' \<noteq> th"
  1862   assumes neq_th: "th' \<noteq> th"
  1863   shows "cp s th' = cp s' th'"
  1863   shows "cp s th' = cp s' th'"
  1864   apply (unfold cp_eq_cpreced cpreced_def)
  1864   apply (unfold cp_eq_cpreced cpreced_def)
  1865 proof -
  1865 proof -
  1866   have nd: "th \<notin> dependents s th'"
  1866   have nd: "th \<notin> dependants s th'"
  1867   proof
  1867   proof
  1868     assume "th \<in> dependents s th'"
  1868     assume "th \<in> dependants s th'"
  1869     hence "(Th th, Th th') \<in> (depend s)^+" by (simp add:s_dependents_def eq_depend)
  1869     hence "(Th th, Th th') \<in> (depend s)^+" by (simp add:s_dependants_def eq_depend)
  1870     with eq_dep have "(Th th, Th th') \<in> (depend s')^+" by simp
  1870     with eq_dep have "(Th th, Th th') \<in> (depend s')^+" by simp
  1871     from converse_tranclE[OF this]
  1871     from converse_tranclE[OF this]
  1872     obtain y where "(Th th, y) \<in> depend s'" by auto
  1872     obtain y where "(Th th, y) \<in> depend s'" by auto
  1873     with dm_depend_threads[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1873     with dm_depend_threads[OF step_back_vt[OF vt_s[unfolded s_def]]]
  1874     have in_th: "th \<in> threads s'" by auto
  1874     have in_th: "th \<in> threads s'" by auto
  1877     proof(cases)
  1877     proof(cases)
  1878       assume "th \<notin> threads s'" 
  1878       assume "th \<notin> threads s'" 
  1879       with in_th show ?thesis by simp
  1879       with in_th show ?thesis by simp
  1880     qed
  1880     qed
  1881   qed
  1881   qed
  1882   have eq_dp: "\<And> th. dependents (wq s) th = dependents (wq s') th"
  1882   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1883     by (unfold cs_dependents_def, auto simp:eq_dep eq_depend)
  1883     by (unfold cs_dependants_def, auto simp:eq_dep eq_depend)
  1884   moreover {
  1884   moreover {
  1885     fix th1 
  1885     fix th1 
  1886     assume "th1 \<in> {th'} \<union> dependents (wq s') th'"
  1886     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1887     hence "th1 = th' \<or> th1 \<in> dependents (wq s') th'" by auto
  1887     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1888     hence "preced th1 s = preced th1 s'"
  1888     hence "preced th1 s = preced th1 s'"
  1889     proof
  1889     proof
  1890       assume "th1 = th'"
  1890       assume "th1 = th'"
  1891       with neq_th
  1891       with neq_th
  1892       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1892       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1893     next
  1893     next
  1894       assume "th1 \<in> dependents (wq s') th'"
  1894       assume "th1 \<in> dependants (wq s') th'"
  1895       with nd and eq_dp have "th1 \<noteq> th"
  1895       with nd and eq_dp have "th1 \<noteq> th"
  1896         by (auto simp:eq_depend cs_dependents_def s_dependents_def eq_dep)
  1896         by (auto simp:eq_depend cs_dependants_def s_dependants_def eq_dep)
  1897       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1897       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1898     qed
  1898     qed
  1899   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) = 
  1899   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1900                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" 
  1900                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1901     by (auto simp:image_def)
  1901     by (auto simp:image_def)
  1902   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) =
  1902   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
  1903         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" by simp
  1903         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
  1904 qed
  1904 qed
  1905 
  1905 
  1906 lemma nil_dependents: "dependents s th = {}"
  1906 lemma nil_dependants: "dependants s th = {}"
  1907 proof -
  1907 proof -
  1908   from step_back_step[OF vt_s[unfolded s_def]]
  1908   from step_back_step[OF vt_s[unfolded s_def]]
  1909   show ?thesis
  1909   show ?thesis
  1910   proof(cases)
  1910   proof(cases)
  1911     assume "th \<notin> threads s'"
  1911     assume "th \<notin> threads s'"
  1912     from not_thread_holdents[OF step_back_vt[OF vt_s[unfolded s_def]] this]
  1912     from not_thread_holdents[OF step_back_vt[OF vt_s[unfolded s_def]] this]
  1913     have hdn: " holdents s' th = {}" .
  1913     have hdn: " holdents s' th = {}" .
  1914     have "dependents s' th = {}"
  1914     have "dependants s' th = {}"
  1915     proof -
  1915     proof -
  1916       { assume "dependents s' th \<noteq> {}"
  1916       { assume "dependants s' th \<noteq> {}"
  1917         then obtain th' where dp: "(Th th', Th th) \<in> (depend s')^+"
  1917         then obtain th' where dp: "(Th th', Th th) \<in> (depend s')^+"
  1918           by (auto simp:s_dependents_def eq_depend)
  1918           by (auto simp:s_dependants_def eq_depend)
  1919         from tranclE[OF this] obtain cs' where 
  1919         from tranclE[OF this] obtain cs' where 
  1920           "(Cs cs', Th th) \<in> depend s'" by (auto simp:s_depend_def)
  1920           "(Cs cs', Th th) \<in> depend s'" by (auto simp:s_depend_def)
  1921         with hdn
  1921         with hdn
  1922         have False by (auto simp:holdents_test)
  1922         have False by (auto simp:holdents_test)
  1923       } thus ?thesis by auto
  1923       } thus ?thesis by auto
  1924     qed
  1924     qed
  1925     thus ?thesis 
  1925     thus ?thesis 
  1926       by (unfold s_def s_dependents_def eq_depend depend_create_unchanged, simp)
  1926       by (unfold s_def s_dependants_def eq_depend depend_create_unchanged, simp)
  1927   qed
  1927   qed
  1928 qed
  1928 qed
  1929 
  1929 
  1930 lemma eq_cp_th: "cp s th = preced th s"
  1930 lemma eq_cp_th: "cp s th = preced th s"
  1931   apply (unfold cp_eq_cpreced cpreced_def)
  1931   apply (unfold cp_eq_cpreced cpreced_def)
  1932   by (insert nil_dependents, unfold s_dependents_def cs_dependents_def, auto)
  1932   by (insert nil_dependants, unfold s_dependants_def cs_dependants_def, auto)
  1933 
  1933 
  1934 end
  1934 end
  1935 
  1935 
  1936 
  1936 
  1937 locale step_exit_cps =
  1937 locale step_exit_cps =
  1949   fixes th' 
  1949   fixes th' 
  1950   assumes neq_th: "th' \<noteq> th"
  1950   assumes neq_th: "th' \<noteq> th"
  1951   shows "cp s th' = cp s' th'"
  1951   shows "cp s th' = cp s' th'"
  1952   apply (unfold cp_eq_cpreced cpreced_def)
  1952   apply (unfold cp_eq_cpreced cpreced_def)
  1953 proof -
  1953 proof -
  1954   have nd: "th \<notin> dependents s th'"
  1954   have nd: "th \<notin> dependants s th'"
  1955   proof
  1955   proof
  1956     assume "th \<in> dependents s th'"
  1956     assume "th \<in> dependants s th'"
  1957     hence "(Th th, Th th') \<in> (depend s)^+" by (simp add:s_dependents_def eq_depend)
  1957     hence "(Th th, Th th') \<in> (depend s)^+" by (simp add:s_dependants_def eq_depend)
  1958     with eq_dep have "(Th th, Th th') \<in> (depend s')^+" by simp
  1958     with eq_dep have "(Th th, Th th') \<in> (depend s')^+" by simp
  1959     from converse_tranclE[OF this]
  1959     from converse_tranclE[OF this]
  1960     obtain cs' where bk: "(Th th, Cs cs') \<in> depend s'"
  1960     obtain cs' where bk: "(Th th, Cs cs') \<in> depend s'"
  1961       by (auto simp:s_depend_def)
  1961       by (auto simp:s_depend_def)
  1962     from step_back_step[OF vt_s[unfolded s_def]]
  1962     from step_back_step[OF vt_s[unfolded s_def]]
  1966       with bk show ?thesis
  1966       with bk show ?thesis
  1967         apply (unfold runing_def readys_def s_waiting_def s_depend_def)
  1967         apply (unfold runing_def readys_def s_waiting_def s_depend_def)
  1968         by (auto simp:cs_waiting_def wq_def)
  1968         by (auto simp:cs_waiting_def wq_def)
  1969     qed
  1969     qed
  1970   qed
  1970   qed
  1971   have eq_dp: "\<And> th. dependents (wq s) th = dependents (wq s') th"
  1971   have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
  1972     by (unfold cs_dependents_def, auto simp:eq_dep eq_depend)
  1972     by (unfold cs_dependants_def, auto simp:eq_dep eq_depend)
  1973   moreover {
  1973   moreover {
  1974     fix th1 
  1974     fix th1 
  1975     assume "th1 \<in> {th'} \<union> dependents (wq s') th'"
  1975     assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
  1976     hence "th1 = th' \<or> th1 \<in> dependents (wq s') th'" by auto
  1976     hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
  1977     hence "preced th1 s = preced th1 s'"
  1977     hence "preced th1 s = preced th1 s'"
  1978     proof
  1978     proof
  1979       assume "th1 = th'"
  1979       assume "th1 = th'"
  1980       with neq_th
  1980       with neq_th
  1981       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1981       show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1982     next
  1982     next
  1983       assume "th1 \<in> dependents (wq s') th'"
  1983       assume "th1 \<in> dependants (wq s') th'"
  1984       with nd and eq_dp have "th1 \<noteq> th"
  1984       with nd and eq_dp have "th1 \<noteq> th"
  1985         by (auto simp:eq_depend cs_dependents_def s_dependents_def eq_dep)
  1985         by (auto simp:eq_depend cs_dependants_def s_dependants_def eq_dep)
  1986       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1986       thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
  1987     qed
  1987     qed
  1988   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) = 
  1988   } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
  1989                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" 
  1989                      ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
  1990     by (auto simp:image_def)
  1990     by (auto simp:image_def)
  1991   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')) =
  1991   thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
  1992         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependents (wq s') th'))" by simp
  1992         Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
  1993 qed
  1993 qed
  1994 
  1994 
  1995 end
  1995 end
  1996 end
  1996 end
  1997 
  1997