812 next |
814 next |
813 case False then obtain a where "a \<in> A" by auto |
815 case False then obtain a where "a \<in> A" by auto |
814 with h have "A = {a}" by auto |
816 with h have "A = {a}" by auto |
815 thus ?thesis by simp |
817 thus ?thesis by simp |
816 qed |
818 qed |
|
819 *) |
817 |
820 |
818 lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs" |
821 lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs" |
819 by (unfold s_RAG_def, auto) |
822 by (unfold s_RAG_def, auto) |
820 |
823 |
821 lemma acyclic_RAG: |
824 lemma acyclic_RAG: |
822 fixes s |
825 fixes s |
823 assumes vt: "vt s" |
826 assumes vt: "vt s" |
824 shows "acyclic (RAG s)" |
827 shows "acyclic (RAG s)" |
825 proof - |
828 using assms |
826 from vt show ?thesis |
829 proof(induct) |
827 proof(induct) |
830 case (vt_cons s e) |
828 case (vt_cons s e) |
831 assume ih: "acyclic (RAG s)" |
829 assume ih: "acyclic (RAG s)" |
832 and stp: "step s e" |
830 and stp: "step s e" |
833 and vt: "vt s" |
831 and vt: "vt s" |
834 show ?case |
832 show ?case |
835 proof(cases e) |
833 proof(cases e) |
836 case (Create th prio) |
834 case (Create th prio) |
837 with ih |
835 with ih |
838 show ?thesis by (simp add:RAG_create_unchanged) |
836 show ?thesis by (simp add:RAG_create_unchanged) |
839 next |
837 next |
840 case (Exit th) |
838 case (Exit th) |
841 with ih show ?thesis by (simp add:RAG_exit_unchanged) |
839 with ih show ?thesis by (simp add:RAG_exit_unchanged) |
842 next |
840 next |
843 case (V th cs) |
841 case (V th cs) |
844 from V vt stp have vtt: "vt (V th cs#s)" by auto |
842 from V vt stp have vtt: "vt (V th cs#s)" by auto |
845 from step_RAG_v [OF this] |
843 from step_RAG_v [OF this] |
846 have eq_de: |
844 have eq_de: |
847 "RAG (e # s) = |
845 "RAG (e # s) = |
848 RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union> |
846 RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union> |
849 {(Cs cs, Th th') |th'. next_th s th cs th'}" |
847 {(Cs cs, Th th') |th'. next_th s th cs th'}" |
850 (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V) |
848 (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V) |
851 from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset) |
849 from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset) |
852 from step_back_step [OF vtt] |
850 from step_back_step [OF vtt] |
853 have "step s (V th cs)" . |
851 have "step s (V th cs)" . |
854 thus ?thesis |
852 thus ?thesis |
855 proof(cases) |
853 proof(cases) |
856 assume "holding s th cs" |
854 assume "holding s th cs" |
857 hence th_in: "th \<in> set (wq s cs)" and |
855 hence th_in: "th \<in> set (wq s cs)" and |
858 eq_hd: "th = hd (wq s cs)" unfolding s_holding_def wq_def by auto |
856 eq_hd: "th = hd (wq s cs)" unfolding s_holding_def wq_def by auto |
859 then obtain rest where |
857 then obtain rest where |
860 eq_wq: "wq s cs = th#rest" |
858 eq_wq: "wq s cs = th#rest" |
861 by (cases "wq s cs", auto) |
859 by (cases "wq s cs", auto) |
862 show ?thesis |
860 show ?thesis |
863 proof(cases "rest = []") |
861 proof(cases "rest = []") |
864 case False |
862 case False |
865 let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)" |
863 let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)" |
866 from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}" |
864 from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}" |
867 by (unfold next_th_def, auto) |
865 by (unfold next_th_def, auto) |
868 let ?E = "(?A - ?B - ?C)" |
866 let ?E = "(?A - ?B - ?C)" |
869 have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*" |
867 have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*" |
870 proof |
868 proof |
871 assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*" |
869 assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*" |
872 hence " (Th ?th', Cs cs) \<in> ?E\<^sup>+" by (simp add: rtrancl_eq_or_trancl) |
870 hence " (Th ?th', Cs cs) \<in> ?E\<^sup>+" by (simp add: rtrancl_eq_or_trancl) |
873 from tranclD [OF this] |
871 from tranclD [OF this] |
874 obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast |
872 obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast |
875 hence th_d: "(Th ?th', x) \<in> ?A" by simp |
873 hence th_d: "(Th ?th', x) \<in> ?A" by simp |
876 from RAG_target_th [OF this] |
874 from RAG_target_th [OF this] |
877 obtain cs' where eq_x: "x = Cs cs'" by auto |
875 obtain cs' where eq_x: "x = Cs cs'" by auto |
878 with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp |
876 with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp |
879 hence wt_th': "waiting s ?th' cs'" |
877 hence wt_th': "waiting s ?th' cs'" |
880 unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp |
878 unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp |
881 hence "cs' = cs" |
879 hence "cs' = cs" |
882 proof(rule waiting_unique [OF vt]) |
880 proof(rule waiting_unique [OF vt]) |
883 from eq_wq wq_distinct[OF vt, of cs] |
881 from eq_wq wq_distinct[OF vt, of cs] |
884 show "waiting s ?th' cs" |
882 show "waiting s ?th' cs" |
885 apply (unfold s_waiting_def wq_def, auto) |
883 apply (unfold s_waiting_def wq_def, auto) |
886 proof - |
884 proof - |
887 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
885 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
|
886 and eq_wq: "wq_fun (schs s) cs = th # rest" |
888 and eq_wq: "wq_fun (schs s) cs = th # rest" |
887 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
889 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
888 proof(rule someI2) |
890 proof(rule someI2) |
889 from wq_distinct[OF vt, of cs] and eq_wq |
891 from wq_distinct[OF vt, of cs] and eq_wq |
890 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
892 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
891 next |
|
892 fix x assume "distinct x \<and> set x = set rest" |
|
893 with False show "x \<noteq> []" by auto |
|
894 qed |
|
895 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
|
896 set (SOME q. distinct q \<and> set q = set rest)" by auto |
|
897 moreover have "\<dots> = set rest" |
|
898 proof(rule someI2) |
|
899 from wq_distinct[OF vt, of cs] and eq_wq |
|
900 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
|
901 next |
|
902 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
|
903 qed |
|
904 moreover note hd_in |
|
905 ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto |
|
906 next |
893 next |
907 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
894 fix x assume "distinct x \<and> set x = set rest" |
|
895 with False show "x \<noteq> []" by auto |
|
896 qed |
|
897 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
|
898 set (SOME q. distinct q \<and> set q = set rest)" by auto |
|
899 moreover have "\<dots> = set rest" |
|
900 proof(rule someI2) |
|
901 from wq_distinct[OF vt, of cs] and eq_wq |
|
902 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
|
903 next |
|
904 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
|
905 qed |
|
906 moreover note hd_in |
|
907 ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto |
|
908 next |
|
909 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
908 and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest" |
910 and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest" |
909 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
911 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
910 proof(rule someI2) |
912 proof(rule someI2) |
911 from wq_distinct[OF vt, of cs] and eq_wq |
913 from wq_distinct[OF vt, of cs] and eq_wq |
912 show "distinct rest \<and> set rest = set rest" by auto |
914 show "distinct rest \<and> set rest = set rest" by auto |
913 next |
915 next |
914 fix x assume "distinct x \<and> set x = set rest" |
916 fix x assume "distinct x \<and> set x = set rest" |
915 with False show "x \<noteq> []" by auto |
917 with False show "x \<noteq> []" by auto |
916 qed |
|
917 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
|
918 set (SOME q. distinct q \<and> set q = set rest)" by auto |
|
919 moreover have "\<dots> = set rest" |
|
920 proof(rule someI2) |
|
921 from wq_distinct[OF vt, of cs] and eq_wq |
|
922 show "distinct rest \<and> set rest = set rest" by auto |
|
923 next |
|
924 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
|
925 qed |
|
926 moreover note hd_in |
|
927 ultimately show False by auto |
|
928 qed |
918 qed |
|
919 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
|
920 set (SOME q. distinct q \<and> set q = set rest)" by auto |
|
921 moreover have "\<dots> = set rest" |
|
922 proof(rule someI2) |
|
923 from wq_distinct[OF vt, of cs] and eq_wq |
|
924 show "distinct rest \<and> set rest = set rest" by auto |
|
925 next |
|
926 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
|
927 qed |
|
928 moreover note hd_in |
|
929 ultimately show False by auto |
929 qed |
930 qed |
930 with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp |
|
931 with False |
|
932 show "False" by (auto simp: next_th_def eq_wq) |
|
933 qed |
931 qed |
934 with acyclic_insert[symmetric] and ac |
932 with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp |
935 and eq_de eq_D show ?thesis by auto |
933 with False |
936 next |
934 show "False" by (auto simp: next_th_def eq_wq) |
937 case True |
935 qed |
938 with eq_wq |
936 with acyclic_insert[symmetric] and ac |
939 have eq_D: "?D = {}" |
937 and eq_de eq_D show ?thesis by auto |
940 by (unfold next_th_def, auto) |
938 next |
941 with eq_de ac |
939 case True |
942 show ?thesis by auto |
940 with eq_wq |
943 qed |
941 have eq_D: "?D = {}" |
944 qed |
942 by (unfold next_th_def, auto) |
|
943 with eq_de ac |
|
944 show ?thesis by auto |
|
945 qed |
|
946 qed |
945 next |
947 next |
946 case (P th cs) |
948 case (P th cs) |
947 from P vt stp have vtt: "vt (P th cs#s)" by auto |
949 from P vt stp have vtt: "vt (P th cs#s)" by auto |
948 from step_RAG_p [OF this] P |
950 from step_RAG_p [OF this] P |
949 have "RAG (e # s) = |
951 have "RAG (e # s) = |