2 imports PrioG |
2 imports PrioG |
3 begin |
3 begin |
4 |
4 |
5 lemma not_thread_holdents: |
5 lemma not_thread_holdents: |
6 fixes th s |
6 fixes th s |
7 assumes vt: "vt step s" |
7 assumes vt: "vt s" |
8 and not_in: "th \<notin> threads s" |
8 and not_in: "th \<notin> threads s" |
9 shows "holdents s th = {}" |
9 shows "holdents s th = {}" |
10 proof - |
10 proof - |
11 from vt not_in show ?thesis |
11 from vt not_in show ?thesis |
12 proof(induct arbitrary:th) |
12 proof(induct arbitrary:th) |
13 case (vt_cons s e th) |
13 case (vt_cons s e th) |
14 assume vt: "vt step s" |
14 assume vt: "vt s" |
15 and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> holdents s th = {}" |
15 and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> holdents s th = {}" |
16 and stp: "step s e" |
16 and stp: "step s e" |
17 and not_in: "th \<notin> threads (e # s)" |
17 and not_in: "th \<notin> threads (e # s)" |
18 from stp show ?case |
18 from stp show ?case |
19 proof(cases) |
19 proof(cases) |
47 qed |
47 qed |
48 next |
48 next |
49 case (thread_P thread cs) |
49 case (thread_P thread cs) |
50 assume eq_e: "e = P thread cs" |
50 assume eq_e: "e = P thread cs" |
51 and is_runing: "thread \<in> runing s" |
51 and is_runing: "thread \<in> runing s" |
52 from prems have vtp: "vt step (P thread cs#s)" by auto |
52 from prems have vtp: "vt (P thread cs#s)" by auto |
53 have neq_th: "th \<noteq> thread" |
53 have neq_th: "th \<noteq> thread" |
54 proof - |
54 proof - |
55 from not_in eq_e have "th \<notin> threads s" by simp |
55 from not_in eq_e have "th \<notin> threads s" by simp |
56 moreover from is_runing have "thread \<in> threads s" |
56 moreover from is_runing have "thread \<in> threads s" |
57 by (simp add:runing_def readys_def) |
57 by (simp add:runing_def readys_def) |
75 from not_in eq_e have "th \<notin> threads s" by simp |
75 from not_in eq_e have "th \<notin> threads s" by simp |
76 moreover from is_runing have "thread \<in> threads s" |
76 moreover from is_runing have "thread \<in> threads s" |
77 by (simp add:runing_def readys_def) |
77 by (simp add:runing_def readys_def) |
78 ultimately show ?thesis by auto |
78 ultimately show ?thesis by auto |
79 qed |
79 qed |
80 from prems have vtv: "vt step (V thread cs#s)" by auto |
80 from prems have vtv: "vt (V thread cs#s)" by auto |
81 from hold obtain rest |
81 from hold obtain rest |
82 where eq_wq: "wq s cs = thread # rest" |
82 where eq_wq: "wq s cs = thread # rest" |
83 by (case_tac "wq s cs", auto simp:s_holding_def) |
83 by (case_tac "wq s cs", auto simp: wq_def s_holding_def) |
84 from not_in eq_e eq_wq |
84 from not_in eq_e eq_wq |
85 have "\<not> next_th s thread cs th" |
85 have "\<not> next_th s thread cs th" |
86 apply (auto simp:next_th_def) |
86 apply (auto simp:next_th_def) |
87 proof - |
87 proof - |
88 assume ne: "rest \<noteq> []" |
88 assume ne: "rest \<noteq> []" |
254 |
254 |
255 lemma children_dependents: "children s th \<subseteq> dependents (wq s) th" |
255 lemma children_dependents: "children s th \<subseteq> dependents (wq s) th" |
256 by (unfold children_def child_def cs_dependents_def, auto simp:eq_depend) |
256 by (unfold children_def child_def cs_dependents_def, auto simp:eq_depend) |
257 |
257 |
258 lemma child_unique: |
258 lemma child_unique: |
259 assumes vt: "vt step s" |
259 assumes vt: "vt s" |
260 and ch1: "(Th th, Th th1) \<in> child s" |
260 and ch1: "(Th th, Th th1) \<in> child s" |
261 and ch2: "(Th th, Th th2) \<in> child s" |
261 and ch2: "(Th th, Th th2) \<in> child s" |
262 shows "th1 = th2" |
262 shows "th1 = th2" |
263 proof - |
263 proof - |
264 from ch1 ch2 show ?thesis |
264 from ch1 ch2 show ?thesis |
327 |
327 |
328 lemma sub_child: "child s \<subseteq> (depend s)^+" |
328 lemma sub_child: "child s \<subseteq> (depend s)^+" |
329 by (unfold child_def, auto) |
329 by (unfold child_def, auto) |
330 |
330 |
331 lemma wf_child: |
331 lemma wf_child: |
332 assumes vt: "vt step s" |
332 assumes vt: "vt s" |
333 shows "wf (child s)" |
333 shows "wf (child s)" |
334 proof(rule wf_subset) |
334 proof(rule wf_subset) |
335 from wf_trancl[OF wf_depend[OF vt]] |
335 from wf_trancl[OF wf_depend[OF vt]] |
336 show "wf ((depend s)\<^sup>+)" . |
336 show "wf ((depend s)\<^sup>+)" . |
337 next |
337 next |
338 from sub_child show "child s \<subseteq> (depend s)\<^sup>+" . |
338 from sub_child show "child s \<subseteq> (depend s)\<^sup>+" . |
339 qed |
339 qed |
340 |
340 |
341 lemma depend_child_pre: |
341 lemma depend_child_pre: |
342 assumes vt: "vt step s" |
342 assumes vt: "vt s" |
343 shows |
343 shows |
344 "(Th th, n) \<in> (depend s)^+ \<longrightarrow> (\<forall> th'. n = (Th th') \<longrightarrow> (Th th, Th th') \<in> (child s)^+)" (is "?P n") |
344 "(Th th, n) \<in> (depend s)^+ \<longrightarrow> (\<forall> th'. n = (Th th') \<longrightarrow> (Th th, Th th') \<in> (child s)^+)" (is "?P n") |
345 proof - |
345 proof - |
346 from wf_trancl[OF wf_depend[OF vt]] |
346 from wf_trancl[OF wf_depend[OF vt]] |
347 have wf: "wf ((depend s)^+)" . |
347 have wf: "wf ((depend s)^+)" . |
369 qed |
369 qed |
370 qed |
370 qed |
371 qed |
371 qed |
372 qed |
372 qed |
373 |
373 |
374 lemma depend_child: "\<lbrakk>vt step s; (Th th, Th th') \<in> (depend s)^+\<rbrakk> \<Longrightarrow> (Th th, Th th') \<in> (child s)^+" |
374 lemma depend_child: "\<lbrakk>vt s; (Th th, Th th') \<in> (depend s)^+\<rbrakk> \<Longrightarrow> (Th th, Th th') \<in> (child s)^+" |
375 by (insert depend_child_pre, auto) |
375 by (insert depend_child_pre, auto) |
376 |
376 |
377 lemma child_depend_p: |
377 lemma child_depend_p: |
378 assumes "(n1, n2) \<in> (child s)^+" |
378 assumes "(n1, n2) \<in> (child s)^+" |
379 shows "(n1, n2) \<in> (depend s)^+" |
379 shows "(n1, n2) \<in> (depend s)^+" |
390 ultimately show ?case by auto |
390 ultimately show ?case by auto |
391 qed |
391 qed |
392 qed |
392 qed |
393 |
393 |
394 lemma child_depend_eq: |
394 lemma child_depend_eq: |
395 assumes vt: "vt step s" |
395 assumes vt: "vt s" |
396 shows |
396 shows |
397 "((Th th1, Th th2) \<in> (child s)^+) = |
397 "((Th th1, Th th2) \<in> (child s)^+) = |
398 ((Th th1, Th th2) \<in> (depend s)^+)" |
398 ((Th th1, Th th2) \<in> (depend s)^+)" |
399 by (auto intro: depend_child[OF vt] child_depend_p) |
399 by (auto intro: depend_child[OF vt] child_depend_p) |
400 |
400 |
401 lemma children_no_dep: |
401 lemma children_no_dep: |
402 fixes s th th1 th2 th3 |
402 fixes s th th1 th2 th3 |
403 assumes vt: "vt step s" |
403 assumes vt: "vt s" |
404 and ch1: "(Th th1, Th th) \<in> child s" |
404 and ch1: "(Th th1, Th th) \<in> child s" |
405 and ch2: "(Th th2, Th th) \<in> child s" |
405 and ch2: "(Th th2, Th th) \<in> child s" |
406 and ch3: "(Th th1, Th th2) \<in> (depend s)^+" |
406 and ch3: "(Th th1, Th th2) \<in> (depend s)^+" |
407 shows "False" |
407 shows "False" |
408 proof - |
408 proof - |
431 ultimately show False by auto |
431 ultimately show False by auto |
432 qed |
432 qed |
433 qed |
433 qed |
434 |
434 |
435 lemma unique_depend_p: |
435 lemma unique_depend_p: |
436 assumes vt: "vt step s" |
436 assumes vt: "vt s" |
437 and dp1: "(n, n1) \<in> (depend s)^+" |
437 and dp1: "(n, n1) \<in> (depend s)^+" |
438 and dp2: "(n, n2) \<in> (depend s)^+" |
438 and dp2: "(n, n2) \<in> (depend s)^+" |
439 and neq: "n1 \<noteq> n2" |
439 and neq: "n1 \<noteq> n2" |
440 shows "(n1, n2) \<in> (depend s)^+ \<or> (n2, n1) \<in> (depend s)^+" |
440 shows "(n1, n2) \<in> (depend s)^+ \<or> (n2, n1) \<in> (depend s)^+" |
441 proof(rule unique_chain [OF _ dp1 dp2 neq]) |
441 proof(rule unique_chain [OF _ dp1 dp2 neq]) |
443 show "\<And>a b c. \<lbrakk>(a, b) \<in> depend s; (a, c) \<in> depend s\<rbrakk> \<Longrightarrow> b = c" by auto |
443 show "\<And>a b c. \<lbrakk>(a, b) \<in> depend s; (a, c) \<in> depend s\<rbrakk> \<Longrightarrow> b = c" by auto |
444 qed |
444 qed |
445 |
445 |
446 lemma dependents_child_unique: |
446 lemma dependents_child_unique: |
447 fixes s th th1 th2 th3 |
447 fixes s th th1 th2 th3 |
448 assumes vt: "vt step s" |
448 assumes vt: "vt s" |
449 and ch1: "(Th th1, Th th) \<in> child s" |
449 and ch1: "(Th th1, Th th) \<in> child s" |
450 and ch2: "(Th th2, Th th) \<in> child s" |
450 and ch2: "(Th th2, Th th) \<in> child s" |
451 and dp1: "th3 \<in> dependents s th1" |
451 and dp1: "th3 \<in> dependents s th1" |
452 and dp2: "th3 \<in> dependents s th2" |
452 and dp2: "th3 \<in> dependents s th2" |
453 shows "th1 = th2" |
453 shows "th1 = th2" |
470 } thus ?thesis by auto |
470 } thus ?thesis by auto |
471 qed |
471 qed |
472 |
472 |
473 lemma cp_rec: |
473 lemma cp_rec: |
474 fixes s th |
474 fixes s th |
475 assumes vt: "vt step s" |
475 assumes vt: "vt s" |
476 shows "cp s th = Max ({preced th s} \<union> (cp s ` children s th))" |
476 shows "cp s th = Max ({preced th s} \<union> (cp s ` children s th))" |
477 proof(unfold cp_eq_cpreced_f cpreced_def) |
477 proof(unfold cp_eq_cpreced_f cpreced_def) |
478 let ?f = "(\<lambda>th. preced th s)" |
478 let ?f = "(\<lambda>th. preced th s)" |
479 show "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th)) = |
479 show "Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th)) = |
480 Max ({preced th s} \<union> (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th))) ` children s th)" |
480 Max ({preced th s} \<union> (\<lambda>th. Max ((\<lambda>th. preced th s) ` ({th} \<union> dependents (wq s) th))) ` children s th)" |
934 ultimately show ?thesis by auto |
934 ultimately show ?thesis by auto |
935 qed |
935 qed |
936 end |
936 end |
937 |
937 |
938 lemma next_waiting: |
938 lemma next_waiting: |
939 assumes vt: "vt step s" |
939 assumes vt: "vt s" |
940 and nxt: "next_th s th cs th'" |
940 and nxt: "next_th s th cs th'" |
941 shows "waiting s th' cs" |
941 shows "waiting s th' cs" |
942 proof - |
942 proof - |
943 from assms show ?thesis |
943 from assms show ?thesis |
944 apply (auto simp:next_th_def s_waiting_def) |
944 apply (auto simp:next_th_def s_waiting_def[folded wq_def]) |
945 proof - |
945 proof - |
946 fix rest |
946 fix rest |
947 assume ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
947 assume ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
948 and eq_wq: "wq s cs = th # rest" |
948 and eq_wq: "wq s cs = th # rest" |
949 and ne: "rest \<noteq> []" |
949 and ne: "rest \<noteq> []" |
1052 from dp'' eq_y yz eq_z have "(Cs cs, Cs cs') \<in> (depend s)^+" by auto |
1052 from dp'' eq_y yz eq_z have "(Cs cs, Cs cs') \<in> (depend s)^+" by auto |
1053 moreover have "cs' = cs" |
1053 moreover have "cs' = cs" |
1054 proof - |
1054 proof - |
1055 from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt] |
1055 from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt] |
1056 have "(Th th', Cs cs) \<in> depend s'" |
1056 have "(Th th', Cs cs) \<in> depend s'" |
1057 by (auto simp:s_waiting_def s_depend_def cs_waiting_def) |
1057 by (auto simp:s_waiting_def wq_def s_depend_def cs_waiting_def) |
1058 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this dp'] |
1058 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this dp'] |
1059 show ?thesis by simp |
1059 show ?thesis by simp |
1060 qed |
1060 qed |
1061 ultimately have "(Cs cs, Cs cs) \<in> (depend s)^+" by simp |
1061 ultimately have "(Cs cs, Cs cs) \<in> (depend s)^+" by simp |
1062 moreover note wf_trancl[OF wf_depend[OF vt_s]] |
1062 moreover note wf_trancl[OF wf_depend[OF vt_s]] |
1070 with depend_s have dps': "(Th th', z) \<in> depend s'" by auto |
1070 with depend_s have dps': "(Th th', z) \<in> depend s'" by auto |
1071 have "z = Cs cs" |
1071 have "z = Cs cs" |
1072 proof - |
1072 proof - |
1073 from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt] |
1073 from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt] |
1074 have "(Th th', Cs cs) \<in> depend s'" |
1074 have "(Th th', Cs cs) \<in> depend s'" |
1075 by (auto simp:s_waiting_def s_depend_def cs_waiting_def) |
1075 by (auto simp:s_waiting_def wq_def s_depend_def cs_waiting_def) |
1076 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] dps' this] |
1076 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] dps' this] |
1077 show ?thesis . |
1077 show ?thesis . |
1078 qed |
1078 qed |
1079 with dps depend_s show False by auto |
1079 with dps depend_s show False by auto |
1080 qed |
1080 qed |
1113 with yz have dp_yz: "(Cs cs, z) \<in> depend s'" by simp |
1113 with yz have dp_yz: "(Cs cs, z) \<in> depend s'" by simp |
1114 from this have eq_z: "z = Th th" |
1114 from this have eq_z: "z = Th th" |
1115 proof - |
1115 proof - |
1116 from step_back_step[OF vt_s[unfolded s_def]] |
1116 from step_back_step[OF vt_s[unfolded s_def]] |
1117 have "(Cs cs, Th th) \<in> depend s'" |
1117 have "(Cs cs, Th th) \<in> depend s'" |
1118 by(cases, auto simp: s_depend_def cs_holding_def s_holding_def) |
1118 by(cases, auto simp: wq_def s_depend_def cs_holding_def s_holding_def) |
1119 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this dp_yz] |
1119 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this dp_yz] |
1120 show ?thesis by simp |
1120 show ?thesis by simp |
1121 qed |
1121 qed |
1122 from converse_tranclE[OF ztp] |
1122 from converse_tranclE[OF ztp] |
1123 obtain u where "(z, u) \<in> depend s'" by auto |
1123 obtain u where "(z, u) \<in> depend s'" by auto |
1124 moreover |
1124 moreover |
1125 from step_back_step[OF vt_s[unfolded s_def]] |
1125 from step_back_step[OF vt_s[unfolded s_def]] |
1126 have "th \<in> readys s'" by (cases, simp add:runing_def) |
1126 have "th \<in> readys s'" by (cases, simp add:runing_def) |
1127 moreover note eq_z |
1127 moreover note eq_z |
1128 ultimately show False |
1128 ultimately show False |
1129 by (auto simp:readys_def s_depend_def s_waiting_def cs_waiting_def) |
1129 by (auto simp:readys_def wq_def s_depend_def s_waiting_def cs_waiting_def) |
1130 qed |
1130 qed |
1131 next |
1131 next |
1132 show "y \<noteq> Th th'" |
1132 show "y \<noteq> Th th'" |
1133 proof |
1133 proof |
1134 assume eq_y: "y = Th th'" |
1134 assume eq_y: "y = Th th'" |
1135 with yz have dps: "(Th th', z) \<in> depend s'" by simp |
1135 with yz have dps: "(Th th', z) \<in> depend s'" by simp |
1136 have "z = Cs cs" |
1136 have "z = Cs cs" |
1137 proof - |
1137 proof - |
1138 from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt] |
1138 from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt] |
1139 have "(Th th', Cs cs) \<in> depend s'" |
1139 have "(Th th', Cs cs) \<in> depend s'" |
1140 by (auto simp:s_waiting_def s_depend_def cs_waiting_def) |
1140 by (auto simp:s_waiting_def wq_def s_depend_def cs_waiting_def) |
1141 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] dps this] |
1141 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] dps this] |
1142 show ?thesis . |
1142 show ?thesis . |
1143 qed |
1143 qed |
1144 with ztp have cs_i: "(Cs cs, Th th'') \<in> (depend s')\<^sup>+" by simp |
1144 with ztp have cs_i: "(Cs cs, Th th'') \<in> (depend s')\<^sup>+" by simp |
1145 from step_back_step[OF vt_s[unfolded s_def]] |
1145 from step_back_step[OF vt_s[unfolded s_def]] |
1146 have cs_th: "(Cs cs, Th th) \<in> depend s'" |
1146 have cs_th: "(Cs cs, Th th) \<in> depend s'" |
1147 by(cases, auto simp: s_depend_def cs_holding_def s_holding_def) |
1147 by(cases, auto simp: s_depend_def wq_def cs_holding_def s_holding_def) |
1148 have "(Cs cs, Th th'') \<notin> depend s'" |
1148 have "(Cs cs, Th th'') \<notin> depend s'" |
1149 proof |
1149 proof |
1150 assume "(Cs cs, Th th'') \<in> depend s'" |
1150 assume "(Cs cs, Th th'') \<in> depend s'" |
1151 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this cs_th] |
1151 from unique_depend[OF step_back_vt[OF vt_s[unfolded s_def]] this cs_th] |
1152 and neq1 show "False" by simp |
1152 and neq1 show "False" by simp |
1163 from converse_tranclE[OF this] |
1163 from converse_tranclE[OF this] |
1164 obtain v where "(Th th, v) \<in> (depend s')" by auto |
1164 obtain v where "(Th th, v) \<in> (depend s')" by auto |
1165 moreover from step_back_step[OF vt_s[unfolded s_def]] |
1165 moreover from step_back_step[OF vt_s[unfolded s_def]] |
1166 have "th \<in> readys s'" by (cases, simp add:runing_def) |
1166 have "th \<in> readys s'" by (cases, simp add:runing_def) |
1167 ultimately show False |
1167 ultimately show False |
1168 by (auto simp:readys_def s_depend_def s_waiting_def cs_waiting_def) |
1168 by (auto simp:readys_def wq_def s_depend_def s_waiting_def cs_waiting_def) |
1169 qed |
1169 qed |
1170 qed |
1170 qed |
1171 with depend_s yz have "(y, z) \<in> depend s" by auto |
1171 with depend_s yz have "(y, z) \<in> depend s" by auto |
1172 with ztp' |
1172 with ztp' |
1173 show "(y, Th th'') \<in> (depend s)\<^sup>+" by auto |
1173 show "(y, Th th'') \<in> (depend s)\<^sup>+" by auto |
1221 show "False" |
1221 show "False" |
1222 proof(cases) |
1222 proof(cases) |
1223 assume "holding s' th cs" |
1223 assume "holding s' th cs" |
1224 then obtain rest where |
1224 then obtain rest where |
1225 eq_wq: "wq s' cs = th#rest" |
1225 eq_wq: "wq s' cs = th#rest" |
1226 apply (unfold s_holding_def) |
1226 apply (unfold s_holding_def wq_def[symmetric]) |
1227 by (case_tac "(wq s' cs)", auto) |
1227 by (case_tac "(wq s' cs)", auto) |
1228 with h1 h2 have ne: "rest \<noteq> []" by auto |
1228 with h1 h2 have ne: "rest \<noteq> []" by auto |
1229 with eq_wq |
1229 with eq_wq |
1230 have "next_th s' th cs (hd (SOME q. distinct q \<and> set q = set rest))" |
1230 have "next_th s' th cs (hd (SOME q. distinct q \<and> set q = set rest))" |
1231 by(unfold next_th_def, rule_tac x = "rest" in exI, auto) |
1231 by(unfold next_th_def, rule_tac x = "rest" in exI, auto) |