14 |
28 |
15 lemma wq_v_neq: |
29 lemma wq_v_neq: |
16 "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'" |
30 "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'" |
17 by (auto simp:wq_def Let_def cp_def split:list.splits) |
31 by (auto simp:wq_def Let_def cp_def split:list.splits) |
18 |
32 |
19 lemma wq_distinct: "vt s \<Longrightarrow> distinct (wq s cs)" |
33 context valid_trace |
20 proof(erule_tac vt.induct, simp add:wq_def) |
34 begin |
|
35 |
|
36 lemma ind [consumes 0, case_names Nil Cons, induct type]: |
|
37 assumes "PP []" |
|
38 and "(\<And>s e. valid_trace s \<Longrightarrow> valid_trace (e#s) \<Longrightarrow> |
|
39 PP s \<Longrightarrow> PIP s e \<Longrightarrow> PP (e # s))" |
|
40 shows "PP s" |
|
41 proof(rule vt.induct[OF vt]) |
|
42 from assms(1) show "PP []" . |
|
43 next |
|
44 fix s e |
|
45 assume h: "vt s" "PP s" "PIP s e" |
|
46 show "PP (e # s)" |
|
47 proof(cases rule:assms(2)) |
|
48 from h(1) show v1: "valid_trace s" by (unfold_locales, simp) |
|
49 next |
|
50 from h(1,3) have "vt (e#s)" by auto |
|
51 thus "valid_trace (e # s)" by (unfold_locales, simp) |
|
52 qed (insert h, auto) |
|
53 qed |
|
54 |
|
55 lemma wq_distinct: "distinct (wq s cs)" |
|
56 proof(rule ind, simp add:wq_def) |
21 fix s e |
57 fix s e |
22 assume h1: "step s e" |
58 assume h1: "step s e" |
23 and h2: "distinct (wq s cs)" |
59 and h2: "distinct (wq s cs)" |
24 thus "distinct (wq (e # s) cs)" |
60 thus "distinct (wq (e # s) cs)" |
25 proof(induct rule:step.induct, auto simp: wq_def Let_def split:list.splits) |
61 proof(induct rule:step.induct, auto simp: wq_def Let_def split:list.splits) |
159 assume vt: "vt (V th cs # s)" |
202 assume vt: "vt (V th cs # s)" |
160 and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)" |
203 and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)" |
161 and eq_wq: "wq_fun (schs s) cs = thread # qs" |
204 and eq_wq: "wq_fun (schs s) cs = thread # qs" |
162 show "False" |
205 show "False" |
163 proof - |
206 proof - |
164 from wq_distinct[OF step_back_vt[OF vt], of cs] |
207 from wq_distinct[of cs] |
165 and eq_wq[folded wq_def] have "distinct (thread#qs)" by simp |
208 and eq_wq[folded wq_def] have "distinct (thread#qs)" by simp |
166 moreover have "thread \<in> set qs" |
209 moreover have "thread \<in> set qs" |
167 proof - |
210 proof - |
168 have "set (SOME q. distinct q \<and> set q = set qs) = set qs" |
211 have "set (SOME q. distinct q \<and> set q = set qs) = set qs" |
169 proof(rule someI2) |
212 proof(rule someI2) |
170 from wq_distinct [OF step_back_vt[OF vt], of cs] |
213 from wq_distinct [of cs] |
171 and eq_wq [folded wq_def] |
214 and eq_wq [folded wq_def] |
172 show "distinct qs \<and> set qs = set qs" by auto |
215 show "distinct qs \<and> set qs = set qs" by auto |
173 next |
216 next |
174 fix x assume "distinct x \<and> set x = set qs" |
217 fix x assume "distinct x \<and> set x = set qs" |
175 thus "set x = set qs" by auto |
218 thus "set x = set qs" by auto |
179 ultimately show ?thesis by auto |
222 ultimately show ?thesis by auto |
180 qed |
223 qed |
181 qed |
224 qed |
182 qed |
225 qed |
183 |
226 |
184 lemma vt_moment: "\<And> t. \<lbrakk>vt s\<rbrakk> \<Longrightarrow> vt (moment t s)" |
227 end |
185 proof(induct s, simp) |
228 |
186 fix a s t |
229 context valid_trace |
187 assume h: "\<And>t.\<lbrakk>vt s\<rbrakk> \<Longrightarrow> vt (moment t s)" |
230 begin |
188 and vt_a: "vt (a # s)" |
231 |
189 show "vt (moment t (a # s))" |
232 lemma vt_moment: "\<And> t. vt (moment t s)" |
190 proof(cases "t \<ge> length (a#s)") |
233 proof(induct rule:ind) |
|
234 case Nil |
|
235 thus ?case by (simp add:vt_nil) |
|
236 next |
|
237 case (Cons s e t) |
|
238 show ?case |
|
239 proof(cases "t \<ge> length (e#s)") |
191 case True |
240 case True |
192 from True have "moment t (a#s) = a#s" by simp |
241 from True have "moment t (e#s) = e#s" by simp |
193 with vt_a show ?thesis by simp |
242 thus ?thesis using Cons |
|
243 by (simp add:valid_trace_def) |
194 next |
244 next |
195 case False |
245 case False |
196 hence le_t1: "t \<le> length s" by simp |
246 from Cons have "vt (moment t s)" by simp |
197 from vt_a have "vt s" |
247 moreover have "moment t (e#s) = moment t s" |
198 by (erule_tac evt_cons, simp) |
|
199 from h [OF this] have "vt (moment t s)" . |
|
200 moreover have "moment t (a#s) = moment t s" |
|
201 proof - |
248 proof - |
202 from moment_app [OF le_t1, of "[a]"] |
249 from False have "t \<le> length s" by simp |
|
250 from moment_app [OF this, of "[e]"] |
203 show ?thesis by simp |
251 show ?thesis by simp |
204 qed |
252 qed |
205 ultimately show ?thesis by auto |
253 ultimately show ?thesis by simp |
206 qed |
254 qed |
207 qed |
255 qed |
208 |
256 |
209 (* Wrong: |
257 (* Wrong: |
210 lemma \<lbrakk>thread \<in> set (wq_fun cs1 s); thread \<in> set (wq_fun cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2" |
258 lemma \<lbrakk>thread \<in> set (wq_fun cs1 s); thread \<in> set (wq_fun cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2" |
280 obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto |
326 obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto |
281 have "t2 < ?t3" by simp |
327 have "t2 < ?t3" by simp |
282 from nn2 [rule_format, OF this] and eq_m |
328 from nn2 [rule_format, OF this] and eq_m |
283 have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and |
329 have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and |
284 h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto |
330 h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto |
285 have vt_e: "vt (e#moment t2 s)" |
331 have "vt (e#moment t2 s)" |
286 proof - |
332 proof - |
287 from vt_moment [OF vt] |
333 from vt_moment |
288 have "vt (moment ?t3 s)" . |
334 have "vt (moment ?t3 s)" . |
289 with eq_m show ?thesis by simp |
335 with eq_m show ?thesis by simp |
290 qed |
336 qed |
|
337 then interpret vt_e: valid_trace_e "moment t2 s" "e" |
|
338 by (unfold_locales, auto, cases, simp) |
291 have ?thesis |
339 have ?thesis |
292 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
340 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
293 case True |
341 case True |
294 from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)" |
342 from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)" |
295 by auto |
343 by auto |
296 thm abs2 |
344 from vt_e.abs2 [OF True eq_th h2 h1] |
297 from abs2 [OF vt_e True eq_th h2 h1] |
|
298 show ?thesis by auto |
345 show ?thesis by auto |
299 next |
346 next |
300 case False |
347 case False |
301 from block_pre [OF vt_e False h1] |
348 from vt_e.block_pre[OF False h1] |
302 have "e = P thread cs2" . |
349 have "e = P thread cs2" . |
303 with vt_e have "vt ((P thread cs2)# moment t2 s)" by simp |
350 with vt_e.vt_e have "vt ((P thread cs2)# moment t2 s)" by simp |
304 from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp |
351 from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp |
305 with runing_ready have "thread \<in> readys (moment t2 s)" by auto |
352 with runing_ready have "thread \<in> readys (moment t2 s)" by auto |
306 with nn1 [rule_format, OF lt12] |
353 with nn1 [rule_format, OF lt12] |
307 show ?thesis by (simp add:readys_def wq_def s_waiting_def, auto) |
354 show ?thesis by (simp add:readys_def wq_def s_waiting_def, auto) |
308 qed |
355 qed |
314 obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto |
361 obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto |
315 have lt_t3: "t1 < ?t3" by simp |
362 have lt_t3: "t1 < ?t3" by simp |
316 from nn1 [rule_format, OF this] and eq_m |
363 from nn1 [rule_format, OF this] and eq_m |
317 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
364 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
318 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
365 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
319 have vt_e: "vt (e#moment t1 s)" |
366 have "vt (e#moment t1 s)" |
320 proof - |
367 proof - |
321 from vt_moment [OF vt] |
368 from vt_moment |
322 have "vt (moment ?t3 s)" . |
369 have "vt (moment ?t3 s)" . |
323 with eq_m show ?thesis by simp |
370 with eq_m show ?thesis by simp |
324 qed |
371 qed |
|
372 then interpret vt_e: valid_trace_e "moment t1 s" e |
|
373 by (unfold_locales, auto, cases, auto) |
325 have ?thesis |
374 have ?thesis |
326 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
375 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
327 case True |
376 case True |
328 from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)" |
377 from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)" |
329 by auto |
378 by auto |
330 from abs2 [OF vt_e True eq_th h2 h1] |
379 from vt_e.abs2 True eq_th h2 h1 |
331 show ?thesis by auto |
380 show ?thesis by auto |
332 next |
381 next |
333 case False |
382 case False |
334 from block_pre [OF vt_e False h1] |
383 from vt_e.block_pre [OF False h1] |
335 have "e = P thread cs1" . |
384 have "e = P thread cs1" . |
336 with vt_e have "vt ((P thread cs1)# moment t1 s)" by simp |
385 with vt_e.vt_e have "vt ((P thread cs1)# moment t1 s)" by simp |
337 from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp |
386 from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp |
338 with runing_ready have "thread \<in> readys (moment t1 s)" by auto |
387 with runing_ready have "thread \<in> readys (moment t1 s)" by auto |
339 with nn2 [rule_format, OF lt12] |
388 with nn2 [rule_format, OF lt12] |
340 show ?thesis by (simp add:readys_def wq_def s_waiting_def, auto) |
389 show ?thesis by (simp add:readys_def wq_def s_waiting_def, auto) |
341 qed |
390 qed |
349 from nn1 [rule_format, OF this] and eq_m |
398 from nn1 [rule_format, OF this] and eq_m |
350 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
399 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
351 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
400 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
352 have vt_e: "vt (e#moment t1 s)" |
401 have vt_e: "vt (e#moment t1 s)" |
353 proof - |
402 proof - |
354 from vt_moment [OF vt] |
403 from vt_moment |
355 have "vt (moment ?t3 s)" . |
404 have "vt (moment ?t3 s)" . |
356 with eq_m show ?thesis by simp |
405 with eq_m show ?thesis by simp |
357 qed |
406 qed |
|
407 then interpret vt_e: valid_trace_e "moment t1 s" e |
|
408 by (unfold_locales, auto, cases, auto) |
358 have ?thesis |
409 have ?thesis |
359 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
410 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
360 case True |
411 case True |
361 from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)" |
412 from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)" |
362 by auto |
413 by auto |
363 from abs2 [OF vt_e True eq_th h2 h1] |
414 from vt_e.abs2 [OF True eq_th h2 h1] |
364 show ?thesis by auto |
415 show ?thesis by auto |
365 next |
416 next |
366 case False |
417 case False |
367 from block_pre [OF vt_e False h1] |
418 from vt_e.block_pre [OF False h1] |
368 have eq_e1: "e = P thread cs1" . |
419 have eq_e1: "e = P thread cs1" . |
369 have lt_t3: "t1 < ?t3" by simp |
420 have lt_t3: "t1 < ?t3" by simp |
370 with eqt12 have "t2 < ?t3" by simp |
421 with eqt12 have "t2 < ?t3" by simp |
371 from nn2 [rule_format, OF this] and eq_m and eqt12 |
422 from nn2 [rule_format, OF this] and eq_m and eqt12 |
372 have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and |
423 have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and |
375 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
426 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
376 case True |
427 case True |
377 from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)" |
428 from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)" |
378 by auto |
429 by auto |
379 from vt_e and eqt12 have "vt (e#moment t2 s)" by simp |
430 from vt_e and eqt12 have "vt (e#moment t2 s)" by simp |
380 from abs2 [OF this True eq_th h2 h1] |
431 then interpret vt_e2: valid_trace_e "moment t2 s" e |
|
432 by (unfold_locales, auto, cases, auto) |
|
433 from vt_e2.abs2 [OF True eq_th h2 h1] |
381 show ?thesis . |
434 show ?thesis . |
382 next |
435 next |
383 case False |
436 case False |
384 have vt_e: "vt (e#moment t2 s)" |
437 have "vt (e#moment t2 s)" |
385 proof - |
438 proof - |
386 from vt_moment [OF vt] eqt12 |
439 from vt_moment eqt12 |
387 have "vt (moment (Suc t2) s)" by auto |
440 have "vt (moment (Suc t2) s)" by auto |
388 with eq_m eqt12 show ?thesis by simp |
441 with eq_m eqt12 show ?thesis by simp |
389 qed |
442 qed |
390 from block_pre [OF vt_e False h1] |
443 then interpret vt_e2: valid_trace_e "moment t2 s" e |
|
444 by (unfold_locales, auto, cases, auto) |
|
445 from vt_e2.block_pre [OF False h1] |
391 have "e = P thread cs2" . |
446 have "e = P thread cs2" . |
392 with eq_e1 neq12 show ?thesis by auto |
447 with eq_e1 neq12 show ?thesis by auto |
393 qed |
448 qed |
394 qed |
449 qed |
395 } ultimately show ?thesis by arith |
450 } ultimately show ?thesis by arith |
399 text {* |
454 text {* |
400 This lemma is a simple corrolary of @{text "waiting_unique_pre"}. |
455 This lemma is a simple corrolary of @{text "waiting_unique_pre"}. |
401 *} |
456 *} |
402 |
457 |
403 lemma waiting_unique: |
458 lemma waiting_unique: |
404 fixes s cs1 cs2 |
459 assumes "waiting s th cs1" |
405 assumes "vt s" |
|
406 and "waiting s th cs1" |
|
407 and "waiting s th cs2" |
460 and "waiting s th cs2" |
408 shows "cs1 = cs2" |
461 shows "cs1 = cs2" |
409 using waiting_unique_pre assms |
462 using waiting_unique_pre assms |
410 unfolding wq_def s_waiting_def |
463 unfolding wq_def s_waiting_def |
411 by auto |
464 by auto |
|
465 |
|
466 end |
412 |
467 |
413 (* not used *) |
468 (* not used *) |
414 text {* |
469 text {* |
415 Every thread can only be blocked on one critical resource, |
470 Every thread can only be blocked on one critical resource, |
416 symmetrically, every critical resource can only be held by one thread. |
471 symmetrically, every critical resource can only be held by one thread. |
417 This fact is much more easier according to our definition. |
472 This fact is much more easier according to our definition. |
418 *} |
473 *} |
419 lemma held_unique: |
474 lemma held_unique: |
420 fixes s::"state" |
475 assumes "holding (s::event list) th1 cs" |
421 assumes "holding s th1 cs" |
|
422 and "holding s th2 cs" |
476 and "holding s th2 cs" |
423 shows "th1 = th2" |
477 shows "th1 = th2" |
424 using assms |
478 by (insert assms, unfold s_holding_def, auto) |
425 unfolding s_holding_def |
|
426 by auto |
|
427 |
479 |
428 |
480 |
429 lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s" |
481 lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s" |
430 apply (induct s, auto) |
482 apply (induct s, auto) |
431 by (case_tac a, auto split:if_splits) |
483 by (case_tac a, auto split:if_splits) |
717 "wq_fun (schs s) cs = hd (SOME q. distinct q \<and> set q = set list) # list" |
773 "wq_fun (schs s) cs = hd (SOME q. distinct q \<and> set q = set list) # list" |
718 and hd_in: "hd (SOME q. distinct q \<and> set q = set list) |
774 and hd_in: "hd (SOME q. distinct q \<and> set q = set list) |
719 \<in> set (SOME q. distinct q \<and> set q = set list)" |
775 \<in> set (SOME q. distinct q \<and> set q = set list)" |
720 have "set (SOME q. distinct q \<and> set q = set list) = set list" |
776 have "set (SOME q. distinct q \<and> set q = set list) = set list" |
721 proof(rule someI2) |
777 proof(rule someI2) |
722 from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq |
778 from vt_v.wq_distinct[of cs] and eq_wq |
723 show "distinct list \<and> set list = set list" by auto |
779 show "distinct list \<and> set list = set list" by auto |
724 next |
780 next |
725 show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list" |
781 show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list" |
726 by auto |
782 by auto |
727 qed |
783 qed |
728 moreover have "distinct (hd (SOME q. distinct q \<and> set q = set list) # list)" |
784 moreover have "distinct (hd (SOME q. distinct q \<and> set q = set list) # list)" |
729 proof - |
785 proof - |
730 from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq |
786 from vt_v.wq_distinct[of cs] and eq_wq |
731 show ?thesis by auto |
787 show ?thesis by auto |
732 qed |
788 qed |
733 moreover note eq_wq and hd_in |
789 moreover note eq_wq and hd_in |
734 ultimately show "False" by auto |
790 ultimately show "False" by auto |
735 qed |
791 qed |
745 assume vt: "vt (V th cs # s)" |
801 assume vt: "vt (V th cs # s)" |
746 and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest" |
802 and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest" |
747 and nrest: "rest \<noteq> []" |
803 and nrest: "rest \<noteq> []" |
748 and ni: "hd (SOME q. distinct q \<and> set q = set rest) |
804 and ni: "hd (SOME q. distinct q \<and> set q = set rest) |
749 \<notin> set (SOME q. distinct q \<and> set q = set rest)" |
805 \<notin> set (SOME q. distinct q \<and> set q = set rest)" |
|
806 from vt interpret vt_v: valid_trace_e s "V th cs" |
|
807 by (cases, unfold_locales, simp+) |
750 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
808 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
751 proof(rule someI2) |
809 proof(rule someI2) |
752 from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq |
810 from vt_v.wq_distinct[of cs] and eq_wq |
753 show "distinct rest \<and> set rest = set rest" by auto |
811 show "distinct rest \<and> set rest = set rest" by auto |
754 next |
812 next |
755 fix x assume "distinct x \<and> set x = set rest" |
813 fix x assume "distinct x \<and> set x = set rest" |
756 hence "set x = set rest" by auto |
814 hence "set x = set rest" by auto |
757 with nrest |
815 with nrest |
947 obtain cs' where eq_x: "x = Cs cs'" by auto |
1010 obtain cs' where eq_x: "x = Cs cs'" by auto |
948 with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp |
1011 with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp |
949 hence wt_th': "waiting s ?th' cs'" |
1012 hence wt_th': "waiting s ?th' cs'" |
950 unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp |
1013 unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp |
951 hence "cs' = cs" |
1014 hence "cs' = cs" |
952 proof(rule waiting_unique [OF vt]) |
1015 proof(rule vt_s.waiting_unique) |
953 from eq_wq wq_distinct[OF vt, of cs] |
1016 from eq_wq vt_s.wq_distinct[of cs] |
954 show "waiting s ?th' cs" |
1017 show "waiting s ?th' cs" |
955 apply (unfold s_waiting_def wq_def, auto) |
1018 apply (unfold s_waiting_def wq_def, auto) |
956 proof - |
1019 proof - |
957 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
1020 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
958 and eq_wq: "wq_fun (schs s) cs = th # rest" |
1021 and eq_wq: "wq_fun (schs s) cs = th # rest" |
959 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
1022 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
960 proof(rule someI2) |
1023 proof(rule someI2) |
961 from wq_distinct[OF vt, of cs] and eq_wq |
1024 from vt_s.wq_distinct[of cs] and eq_wq |
962 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
1025 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
963 next |
1026 next |
964 fix x assume "distinct x \<and> set x = set rest" |
1027 fix x assume "distinct x \<and> set x = set rest" |
965 with False show "x \<noteq> []" by auto |
1028 with False show "x \<noteq> []" by auto |
966 qed |
1029 qed |
967 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
1030 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
968 set (SOME q. distinct q \<and> set q = set rest)" by auto |
1031 set (SOME q. distinct q \<and> set q = set rest)" by auto |
969 moreover have "\<dots> = set rest" |
1032 moreover have "\<dots> = set rest" |
970 proof(rule someI2) |
1033 proof(rule someI2) |
971 from wq_distinct[OF vt, of cs] and eq_wq |
1034 from vt_s.wq_distinct[of cs] and eq_wq |
972 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
1035 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
973 next |
1036 next |
974 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
1037 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
975 qed |
1038 qed |
976 moreover note hd_in |
1039 moreover note hd_in |
978 next |
1041 next |
979 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
1042 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
980 and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest" |
1043 and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest" |
981 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
1044 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
982 proof(rule someI2) |
1045 proof(rule someI2) |
983 from wq_distinct[OF vt, of cs] and eq_wq |
1046 from vt_s.wq_distinct[of cs] and eq_wq |
984 show "distinct rest \<and> set rest = set rest" by auto |
1047 show "distinct rest \<and> set rest = set rest" by auto |
985 next |
1048 next |
986 fix x assume "distinct x \<and> set x = set rest" |
1049 fix x assume "distinct x \<and> set x = set rest" |
987 with False show "x \<noteq> []" by auto |
1050 with False show "x \<noteq> []" by auto |
988 qed |
1051 qed |
989 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
1052 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
990 set (SOME q. distinct q \<and> set q = set rest)" by auto |
1053 set (SOME q. distinct q \<and> set q = set rest)" by auto |
991 moreover have "\<dots> = set rest" |
1054 moreover have "\<dots> = set rest" |
992 proof(rule someI2) |
1055 proof(rule someI2) |
993 from wq_distinct[OF vt, of cs] and eq_wq |
1056 from vt_s.wq_distinct[of cs] and eq_wq |
994 show "distinct rest \<and> set rest = set rest" by auto |
1057 show "distinct rest \<and> set rest = set rest" by auto |
995 next |
1058 next |
996 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
1059 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
997 qed |
1060 qed |
998 moreover note hd_in |
1061 moreover note hd_in |
1143 qed |
1206 qed |
1144 |
1207 |
1145 text {* Several useful lemmas *} |
1208 text {* Several useful lemmas *} |
1146 |
1209 |
1147 lemma wf_dep_converse: |
1210 lemma wf_dep_converse: |
1148 fixes s |
|
1149 assumes vt: "vt s" |
|
1150 shows "wf ((RAG s)^-1)" |
1211 shows "wf ((RAG s)^-1)" |
1151 proof(rule finite_acyclic_wf_converse) |
1212 proof(rule finite_acyclic_wf_converse) |
1152 from finite_RAG [OF vt] |
1213 from finite_RAG |
1153 show "finite (RAG s)" . |
1214 show "finite (RAG s)" . |
1154 next |
1215 next |
1155 from acyclic_RAG[OF vt] |
1216 from acyclic_RAG |
1156 show "acyclic (RAG s)" . |
1217 show "acyclic (RAG s)" . |
1157 qed |
1218 qed |
1158 |
1219 |
|
1220 end |
|
1221 |
1159 lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l" |
1222 lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l" |
1160 by (induct l, auto) |
1223 by (induct l, auto) |
1161 |
1224 |
1162 lemma th_chasing: "(Th th, Cs cs) \<in> RAG (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> RAG s" |
1225 lemma th_chasing: "(Th th, Cs cs) \<in> RAG (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> RAG s" |
1163 by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1226 by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1164 |
1227 |
|
1228 context valid_trace |
|
1229 begin |
|
1230 |
1165 lemma wq_threads: |
1231 lemma wq_threads: |
1166 fixes s cs |
1232 assumes h: "th \<in> set (wq s cs)" |
1167 assumes vt: "vt s" |
|
1168 and h: "th \<in> set (wq s cs)" |
|
1169 shows "th \<in> threads s" |
1233 shows "th \<in> threads s" |
1170 proof - |
1234 proof - |
1171 from vt and h show ?thesis |
1235 from vt and h show ?thesis |
1172 proof(induct arbitrary: th cs) |
1236 proof(induct arbitrary: th cs) |
1173 case (vt_cons s e) |
1237 case (vt_cons s e) |
|
1238 interpret vt_s: valid_trace s |
|
1239 using vt_cons(1) by (unfold_locales, auto) |
1174 assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s" |
1240 assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s" |
1175 and stp: "step s e" |
1241 and stp: "step s e" |
1176 and vt: "vt s" |
1242 and vt: "vt s" |
1177 and h: "th \<in> set (wq (e # s) cs)" |
1243 and h: "th \<in> set (wq (e # s) cs)" |
1178 show ?case |
1244 show ?case |
1360 |
1424 |
1361 text {* \noindent |
1425 text {* \noindent |
1362 The following is just an instance of @{text "chain_building"}. |
1426 The following is just an instance of @{text "chain_building"}. |
1363 *} |
1427 *} |
1364 lemma th_chain_to_ready: |
1428 lemma th_chain_to_ready: |
1365 fixes s th |
1429 assumes th_in: "th \<in> threads s" |
1366 assumes vt: "vt s" |
|
1367 and th_in: "th \<in> threads s" |
|
1368 shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)" |
1430 shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)" |
1369 proof(cases "th \<in> readys s") |
1431 proof(cases "th \<in> readys s") |
1370 case True |
1432 case True |
1371 thus ?thesis by auto |
1433 thus ?thesis by auto |
1372 next |
1434 next |
1373 case False |
1435 case False |
1374 from False and th_in have "Th th \<in> Domain (RAG s)" |
1436 from False and th_in have "Th th \<in> Domain (RAG s)" |
1375 by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_def Domain_def) |
1437 by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_def Domain_def) |
1376 from chain_building [rule_format, OF vt this] |
1438 from chain_building [rule_format, OF this] |
1377 show ?thesis by auto |
1439 show ?thesis by auto |
1378 qed |
1440 qed |
|
1441 |
|
1442 end |
1379 |
1443 |
1380 lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs" |
1444 lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs" |
1381 by (unfold s_waiting_def cs_waiting_def wq_def, auto) |
1445 by (unfold s_waiting_def cs_waiting_def wq_def, auto) |
1382 |
1446 |
1383 lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs" |
1447 lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs" |
1384 by (unfold s_holding_def wq_def cs_holding_def, simp) |
1448 by (unfold s_holding_def wq_def cs_holding_def, simp) |
1385 |
1449 |
1386 lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2" |
1450 lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2" |
1387 by (unfold s_holding_def cs_holding_def, auto) |
1451 by (unfold s_holding_def cs_holding_def, auto) |
1388 |
1452 |
1389 lemma unique_RAG: "\<lbrakk>vt s; (n, n1) \<in> RAG s; (n, n2) \<in> RAG s\<rbrakk> \<Longrightarrow> n1 = n2" |
1453 context valid_trace |
|
1454 begin |
|
1455 |
|
1456 lemma unique_RAG: "\<lbrakk>(n, n1) \<in> RAG s; (n, n2) \<in> RAG s\<rbrakk> \<Longrightarrow> n1 = n2" |
1390 apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq) |
1457 apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq) |
1391 by(auto elim:waiting_unique holding_unique) |
1458 by(auto elim:waiting_unique holding_unique) |
1392 |
1459 |
|
1460 end |
|
1461 |
|
1462 |
1393 lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r" |
1463 lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r" |
1394 by (induct rule:trancl_induct, auto) |
1464 by (induct rule:trancl_induct, auto) |
1395 |
1465 |
|
1466 context valid_trace |
|
1467 begin |
|
1468 |
1396 lemma dchain_unique: |
1469 lemma dchain_unique: |
1397 assumes vt: "vt s" |
1470 assumes th1_d: "(n, Th th1) \<in> (RAG s)^+" |
1398 and th1_d: "(n, Th th1) \<in> (RAG s)^+" |
|
1399 and th1_r: "th1 \<in> readys s" |
1471 and th1_r: "th1 \<in> readys s" |
1400 and th2_d: "(n, Th th2) \<in> (RAG s)^+" |
1472 and th2_d: "(n, Th th2) \<in> (RAG s)^+" |
1401 and th2_r: "th2 \<in> readys s" |
1473 and th2_r: "th2 \<in> readys s" |
1402 shows "th1 = th2" |
1474 shows "th1 = th2" |
1403 proof - |
1475 proof - |
1404 { assume neq: "th1 \<noteq> th2" |
1476 { assume neq: "th1 \<noteq> th2" |
1405 hence "Th th1 \<noteq> Th th2" by simp |
1477 hence "Th th1 \<noteq> Th th2" by simp |
1406 from unique_chain [OF _ th1_d th2_d this] and unique_RAG [OF vt] |
1478 from unique_chain [OF _ th1_d th2_d this] and unique_RAG |
1407 have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto |
1479 have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto |
1408 hence "False" |
1480 hence "False" |
1409 proof |
1481 proof |
1410 assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+" |
1482 assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+" |
1411 from trancl_split [OF this] |
1483 from trancl_split [OF this] |
1474 lemma cntCS_v_dec: |
1546 lemma cntCS_v_dec: |
1475 fixes s thread cs |
1547 fixes s thread cs |
1476 assumes vtv: "vt (V thread cs#s)" |
1548 assumes vtv: "vt (V thread cs#s)" |
1477 shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread" |
1549 shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread" |
1478 proof - |
1550 proof - |
|
1551 from vtv interpret vt_s: valid_trace s |
|
1552 by (cases, unfold_locales, simp) |
|
1553 from vtv interpret vt_v: valid_trace "V thread cs#s" |
|
1554 by (unfold_locales, simp) |
1479 from step_back_step[OF vtv] |
1555 from step_back_step[OF vtv] |
1480 have cs_in: "cs \<in> holdents s thread" |
1556 have cs_in: "cs \<in> holdents s thread" |
1481 apply (cases, unfold holdents_test s_RAG_def, simp) |
1557 apply (cases, unfold holdents_test s_RAG_def, simp) |
1482 by (unfold cs_holding_def s_holding_def wq_def, auto) |
1558 by (unfold cs_holding_def s_holding_def wq_def, auto) |
1483 moreover have cs_not_in: |
1559 moreover have cs_not_in: |
1484 "(holdents (V thread cs#s) thread) = holdents s thread - {cs}" |
1560 "(holdents (V thread cs#s) thread) = holdents s thread - {cs}" |
1485 apply (insert wq_distinct[OF step_back_vt[OF vtv], of cs]) |
1561 apply (insert vt_s.wq_distinct[of cs]) |
1486 apply (unfold holdents_test, unfold step_RAG_v[OF vtv], |
1562 apply (unfold holdents_test, unfold step_RAG_v[OF vtv], |
1487 auto simp:next_th_def) |
1563 auto simp:next_th_def) |
1488 proof - |
1564 proof - |
1489 fix rest |
1565 fix rest |
1490 assume dst: "distinct (rest::thread list)" |
1566 assume dst: "distinct (rest::thread list)" |
1534 have "holdents s thread = insert cs (holdents (V thread cs#s) thread)" |
1610 have "holdents s thread = insert cs (holdents (V thread cs#s) thread)" |
1535 by auto |
1611 by auto |
1536 moreover have "card \<dots> = |
1612 moreover have "card \<dots> = |
1537 Suc (card ((holdents (V thread cs#s) thread) - {cs}))" |
1613 Suc (card ((holdents (V thread cs#s) thread) - {cs}))" |
1538 proof(rule card_insert) |
1614 proof(rule card_insert) |
1539 from finite_holding [OF vtv] |
1615 from vt_v.finite_holding |
1540 show " finite (holdents (V thread cs # s) thread)" . |
1616 show " finite (holdents (V thread cs # s) thread)" . |
1541 qed |
1617 qed |
1542 moreover from cs_not_in |
1618 moreover from cs_not_in |
1543 have "cs \<notin> (holdents (V thread cs#s) thread)" by auto |
1619 have "cs \<notin> (holdents (V thread cs#s) thread)" by auto |
1544 ultimately show ?thesis by (simp add:cntCS_def) |
1620 ultimately show ?thesis by (simp add:cntCS_def) |
1545 qed |
1621 qed |
1546 |
1622 |
|
1623 context valid_trace |
|
1624 begin |
|
1625 |
1547 text {* (* ddd *) \noindent |
1626 text {* (* ddd *) \noindent |
1548 The relationship between @{text "cntP"}, @{text "cntV"} and @{text "cntCS"} |
1627 The relationship between @{text "cntP"}, @{text "cntV"} and @{text "cntCS"} |
1549 of one particular thread. |
1628 of one particular thread. |
1550 *} |
1629 *} |
1551 |
1630 |
1552 lemma cnp_cnv_cncs: |
1631 lemma cnp_cnv_cncs: |
1553 fixes s th |
|
1554 assumes vt: "vt s" |
|
1555 shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) |
1632 shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) |
1556 then cntCS s th else cntCS s th + 1)" |
1633 then cntCS s th else cntCS s th + 1)" |
1557 proof - |
1634 proof - |
1558 from vt show ?thesis |
1635 from vt show ?thesis |
1559 proof(induct arbitrary:th) |
1636 proof(induct arbitrary:th) |
1560 case (vt_cons s e) |
1637 case (vt_cons s e) |
|
1638 interpret vt_s: valid_trace s using vt_cons(1) by (unfold_locales, simp) |
1561 assume vt: "vt s" |
1639 assume vt: "vt s" |
1562 and ih: "\<And>th. cntP s th = cntV s th + |
1640 and ih: "\<And>th. cntP s th = cntV s th + |
1563 (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)" |
1641 (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)" |
1564 and stp: "step s e" |
1642 and stp: "step s e" |
1565 from stp show ?case |
1643 from stp show ?case |
1735 } ultimately show ?thesis by blast |
1815 } ultimately show ?thesis by blast |
1736 qed |
1816 qed |
1737 next |
1817 next |
1738 case (thread_V thread cs) |
1818 case (thread_V thread cs) |
1739 from assms vt stp ih thread_V have vtv: "vt (V thread cs # s)" by auto |
1819 from assms vt stp ih thread_V have vtv: "vt (V thread cs # s)" by auto |
|
1820 then interpret vt_v: valid_trace "(V thread cs # s)" by (unfold_locales, simp) |
1740 assume eq_e: "e = V thread cs" |
1821 assume eq_e: "e = V thread cs" |
1741 and is_runing: "thread \<in> runing s" |
1822 and is_runing: "thread \<in> runing s" |
1742 and hold: "holding s thread cs" |
1823 and hold: "holding s thread cs" |
1743 from hold obtain rest |
1824 from hold obtain rest |
1744 where eq_wq: "wq s cs = thread # rest" |
1825 where eq_wq: "wq s cs = thread # rest" |
1745 by (case_tac "wq s cs", auto simp: wq_def s_holding_def) |
1826 by (case_tac "wq s cs", auto simp: wq_def s_holding_def) |
1746 have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e) |
1827 have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e) |
1747 have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest" |
1828 have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest" |
1748 proof(rule someI2) |
1829 proof(rule someI2) |
1749 from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq |
1830 from vt_v.wq_distinct[of cs] and eq_wq |
1750 show "distinct rest \<and> set rest = set rest" by auto |
1831 show "distinct rest \<and> set rest = set rest" |
|
1832 by (metis distinct.simps(2) vt_s.wq_distinct) |
1751 next |
1833 next |
1752 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" |
1834 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" |
1753 by auto |
1835 by auto |
1754 qed |
1836 qed |
1755 show ?thesis |
1837 show ?thesis |
1913 and neq_cs: "csa \<noteq> cs" |
1996 and neq_cs: "csa \<noteq> cs" |
1914 and t_in': "?t \<in> set (wq_fun (schs s) csa)" |
1997 and t_in': "?t \<in> set (wq_fun (schs s) csa)" |
1915 show "?t = hd (wq_fun (schs s) csa)" |
1998 show "?t = hd (wq_fun (schs s) csa)" |
1916 proof - |
1999 proof - |
1917 { assume neq_hd': "?t \<noteq> hd (wq_fun (schs s) csa)" |
2000 { assume neq_hd': "?t \<noteq> hd (wq_fun (schs s) csa)" |
1918 from wq_distinct[OF step_back_vt[OF vtv], of cs] and |
2001 from vt_s.wq_distinct[of cs] and |
1919 eq_wq[folded wq_def] and t_in eq_wq |
2002 eq_wq[folded wq_def] and t_in eq_wq |
1920 have "?t \<noteq> thread" by auto |
2003 have "?t \<noteq> thread" by auto |
1921 with eq_wq and t_in |
2004 with eq_wq and t_in |
1922 have w1: "waiting s ?t cs" |
2005 have w1: "waiting s ?t cs" |
1923 by (auto simp:s_waiting_def wq_def) |
2006 by (auto simp:s_waiting_def wq_def) |
1924 from t_in' neq_hd' |
2007 from t_in' neq_hd' |
1925 have w2: "waiting s ?t csa" |
2008 have w2: "waiting s ?t csa" |
1926 by (auto simp:s_waiting_def wq_def) |
2009 by (auto simp:s_waiting_def wq_def) |
1927 from waiting_unique[OF step_back_vt[OF vtv] w1 w2] |
2010 from vt_s.waiting_unique[OF w1 w2] |
1928 and neq_cs have "False" by auto |
2011 and neq_cs have "False" by auto |
1929 } thus ?thesis by auto |
2012 } thus ?thesis by auto |
1930 qed |
2013 qed |
1931 qed |
2014 qed |
1932 moreover have "cntP s th = cntV s th + cntCS s th + 1" |
2015 moreover have "cntP s th = cntV s th + cntCS s th + 1" |
2095 from not_in eq_e have "th \<notin> threads s" by simp |
2178 from not_in eq_e have "th \<notin> threads s" by simp |
2096 moreover from is_runing have "thread \<in> threads s" |
2179 moreover from is_runing have "thread \<in> threads s" |
2097 by (simp add:runing_def readys_def) |
2180 by (simp add:runing_def readys_def) |
2098 ultimately show ?thesis by auto |
2181 ultimately show ?thesis by auto |
2099 qed |
2182 qed |
2100 from assms thread_V vt stp ih have vtv: "vt (V thread cs#s)" by auto |
2183 from assms thread_V vt stp ih |
|
2184 have vtv: "vt (V thread cs#s)" by auto |
|
2185 then interpret vt_v: valid_trace "(V thread cs#s)" |
|
2186 by (unfold_locales, simp) |
2101 from hold obtain rest |
2187 from hold obtain rest |
2102 where eq_wq: "wq s cs = thread # rest" |
2188 where eq_wq: "wq s cs = thread # rest" |
2103 by (case_tac "wq s cs", auto simp: wq_def s_holding_def) |
2189 by (case_tac "wq s cs", auto simp: wq_def s_holding_def) |
2104 from not_in eq_e eq_wq |
2190 from not_in eq_e eq_wq |
2105 have "\<not> next_th s thread cs th" |
2191 have "\<not> next_th s thread cs th" |
2107 proof - |
2193 proof - |
2108 assume ne: "rest \<noteq> []" |
2194 assume ne: "rest \<noteq> []" |
2109 and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s") |
2195 and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s") |
2110 have "?t \<in> set rest" |
2196 have "?t \<in> set rest" |
2111 proof(rule someI2) |
2197 proof(rule someI2) |
2112 from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq |
2198 from vt_v.wq_distinct[of cs] and eq_wq |
2113 show "distinct rest \<and> set rest = set rest" by auto |
2199 show "distinct rest \<and> set rest = set rest" |
|
2200 by (metis distinct.simps(2) vt_s.wq_distinct) |
2114 next |
2201 next |
2115 fix x assume "distinct x \<and> set x = set rest" with ne |
2202 fix x assume "distinct x \<and> set x = set rest" with ne |
2116 show "hd x \<in> set rest" by (cases x, auto) |
2203 show "hd x \<in> set rest" by (cases x, auto) |
2117 qed |
2204 qed |
2118 with eq_wq have "?t \<in> set (wq s cs)" by simp |
2205 with eq_wq have "?t \<in> set (wq s cs)" by simp |
2119 from wq_threads[OF step_back_vt[OF vtv], OF this] and ni |
2206 from vt_s.wq_threads[OF this] and ni |
2120 show False by auto |
2207 show False |
|
2208 using `hd (SOME q. distinct q \<and> set q = set rest) \<in> set (wq s cs)` |
|
2209 ni vt_s.wq_threads by blast |
2121 qed |
2210 qed |
2122 moreover note neq_th eq_wq |
2211 moreover note neq_th eq_wq |
2123 ultimately have "cntCS (e # s) th = cntCS s th" |
2212 ultimately have "cntCS (e # s) th = cntCS s th" |
2124 by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto) |
2213 by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto) |
2125 moreover have "cntCS s th = 0" |
2214 moreover have "cntCS s th = 0" |
2144 by (unfold cntCS_def, |
2233 by (unfold cntCS_def, |
2145 auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def) |
2234 auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def) |
2146 qed |
2235 qed |
2147 qed |
2236 qed |
2148 |
2237 |
|
2238 end |
|
2239 |
2149 lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs" |
2240 lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs" |
2150 by (auto simp:s_waiting_def cs_waiting_def wq_def) |
2241 by (auto simp:s_waiting_def cs_waiting_def wq_def) |
2151 |
2242 |
|
2243 context valid_trace |
|
2244 begin |
|
2245 |
2152 lemma dm_RAG_threads: |
2246 lemma dm_RAG_threads: |
2153 fixes th s |
2247 assumes in_dom: "(Th th) \<in> Domain (RAG s)" |
2154 assumes vt: "vt s" |
|
2155 and in_dom: "(Th th) \<in> Domain (RAG s)" |
|
2156 shows "th \<in> threads s" |
2248 shows "th \<in> threads s" |
2157 proof - |
2249 proof - |
2158 from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto |
2250 from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto |
2159 moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto |
2251 moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto |
2160 ultimately have "(Th th, Cs cs) \<in> RAG s" by simp |
2252 ultimately have "(Th th, Cs cs) \<in> RAG s" by simp |
2161 hence "th \<in> set (wq s cs)" |
2253 hence "th \<in> set (wq s cs)" |
2162 by (unfold s_RAG_def, auto simp:cs_waiting_def) |
2254 by (unfold s_RAG_def, auto simp:cs_waiting_def) |
2163 from wq_threads [OF vt this] show ?thesis . |
2255 from wq_threads [OF this] show ?thesis . |
2164 qed |
2256 qed |
|
2257 |
|
2258 end |
2165 |
2259 |
2166 lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th" |
2260 lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th" |
2167 unfolding cp_def wq_def |
2261 unfolding cp_def wq_def |
2168 apply(induct s rule: schs.induct) |
2262 apply(induct s rule: schs.induct) |
2169 thm cpreced_initial |
2263 thm cpreced_initial |
2364 hence h1: "(Th th1', Th th2) \<in> (RAG s)^+" |
2458 hence h1: "(Th th1', Th th2) \<in> (RAG s)^+" |
2365 by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp) |
2459 by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp) |
2366 from th1'_in have h2: "(Th th1', Th th1) \<in> (RAG s)^+" |
2460 from th1'_in have h2: "(Th th1', Th th1) \<in> (RAG s)^+" |
2367 by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp) |
2461 by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp) |
2368 show ?thesis |
2462 show ?thesis |
2369 proof(rule dchain_unique[OF vt h1 _ h2, symmetric]) |
2463 proof(rule dchain_unique[OF h1 _ h2, symmetric]) |
2370 from runing_1 show "th1 \<in> readys s" by (simp add:runing_def) |
2464 from runing_1 show "th1 \<in> readys s" by (simp add:runing_def) |
2371 from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) |
2465 from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) |
2372 qed |
2466 qed |
2373 qed |
2467 qed |
2374 qed |
2468 qed |
2375 qed |
2469 qed |
2376 |
2470 |
2377 |
2471 |
2378 lemma "vt s \<Longrightarrow> card (runing s) \<le> 1" |
2472 lemma "card (runing s) \<le> 1" |
2379 apply(subgoal_tac "finite (runing s)") |
2473 apply(subgoal_tac "finite (runing s)") |
2380 prefer 2 |
2474 prefer 2 |
2381 apply (metis finite_nat_set_iff_bounded lessI runing_unique) |
2475 apply (metis finite_nat_set_iff_bounded lessI runing_unique) |
2382 apply(rule ccontr) |
2476 apply(rule ccontr) |
2383 apply(simp) |
2477 apply(simp) |
2445 ultimately have eq_me: "moment (Suc i) t = e#(moment i t)" |
2542 ultimately have eq_me: "moment (Suc i) t = e#(moment i t)" |
2446 by (auto simp:down_to_moment) |
2543 by (auto simp:down_to_moment) |
2447 from that [OF this] show ?thesis . |
2544 from that [OF this] show ?thesis . |
2448 qed |
2545 qed |
2449 |
2546 |
|
2547 context valid_trace |
|
2548 begin |
|
2549 |
2450 lemma cnp_cnv_eq: |
2550 lemma cnp_cnv_eq: |
2451 fixes th s |
2551 assumes "th \<notin> threads s" |
2452 assumes "vt s" |
|
2453 and "th \<notin> threads s" |
|
2454 shows "cntP s th = cntV s th" |
2552 shows "cntP s th = cntV s th" |
2455 by (simp add: assms(1) assms(2) cnp_cnv_cncs not_thread_cncs) |
2553 using assms |
|
2554 using cnp_cnv_cncs not_thread_cncs by auto |
|
2555 |
|
2556 end |
|
2557 |
2456 |
2558 |
2457 lemma eq_RAG: |
2559 lemma eq_RAG: |
2458 "RAG (wq s) = RAG s" |
2560 "RAG (wq s) = RAG s" |
2459 by (unfold cs_RAG_def s_RAG_def, auto) |
2561 by (unfold cs_RAG_def s_RAG_def, auto) |
2460 |
2562 |
|
2563 context valid_trace |
|
2564 begin |
|
2565 |
2461 lemma count_eq_dependants: |
2566 lemma count_eq_dependants: |
2462 assumes vt: "vt s" |
2567 assumes eq_pv: "cntP s th = cntV s th" |
2463 and eq_pv: "cntP s th = cntV s th" |
|
2464 shows "dependants (wq s) th = {}" |
2568 shows "dependants (wq s) th = {}" |
2465 proof - |
2569 proof - |
2466 from cnp_cnv_cncs[OF vt] and eq_pv |
2570 from cnp_cnv_cncs and eq_pv |
2467 have "cntCS s th = 0" |
2571 have "cntCS s th = 0" |
2468 by (auto split:if_splits) |
2572 by (auto split:if_splits) |
2469 moreover have "finite {cs. (Cs cs, Th th) \<in> RAG s}" |
2573 moreover have "finite {cs. (Cs cs, Th th) \<in> RAG s}" |
2470 proof - |
2574 proof - |
2471 from finite_holding[OF vt, of th] show ?thesis |
2575 from finite_holding[of th] show ?thesis |
2472 by (simp add:holdents_test) |
2576 by (simp add:holdents_test) |
2473 qed |
2577 qed |
2474 ultimately have h: "{cs. (Cs cs, Th th) \<in> RAG s} = {}" |
2578 ultimately have h: "{cs. (Cs cs, Th th) \<in> RAG s} = {}" |
2475 by (unfold cntCS_def holdents_test cs_dependants_def, auto) |
2579 by (unfold cntCS_def holdents_test cs_dependants_def, auto) |
2476 show ?thesis |
2580 show ?thesis |
2503 from h obtain th' where "(Th th, Th th') \<in> (RAG (wq s))\<^sup>+" by auto |
2605 from h obtain th' where "(Th th, Th th') \<in> (RAG (wq s))\<^sup>+" by auto |
2504 hence "(Th th) \<in> Domain ( (RAG (wq s))\<^sup>+)" by (auto simp:Domain_def) |
2606 hence "(Th th) \<in> Domain ( (RAG (wq s))\<^sup>+)" by (auto simp:Domain_def) |
2505 with trancl_domain have "(Th th) \<in> Domain (RAG (wq s))" by simp |
2607 with trancl_domain have "(Th th) \<in> Domain (RAG (wq s))" by simp |
2506 thus ?thesis using eq_RAG by simp |
2608 thus ?thesis using eq_RAG by simp |
2507 qed |
2609 qed |
2508 from dm_RAG_threads[OF vt this] |
2610 from dm_RAG_threads[OF this] |
2509 have "th \<in> threads s" . |
2611 have "th \<in> threads s" . |
2510 } note hh = this |
2612 } note hh = this |
2511 fix th1 |
2613 fix th1 |
2512 assume "th1 \<in> dependants (wq s) th" |
2614 assume "th1 \<in> dependants (wq s) th" |
2513 hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (RAG (wq s))\<^sup>+}" |
2615 hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (RAG (wq s))\<^sup>+}" |
2514 by (unfold cs_dependants_def, simp) |
2616 by (unfold cs_dependants_def, simp) |
2515 from hh [OF this] show "th1 \<in> threads s" . |
2617 from hh [OF this] show "th1 \<in> threads s" . |
2516 qed |
2618 qed |
2517 |
2619 |
2518 lemma finite_threads: |
2620 lemma finite_threads: |
2519 assumes vt: "vt s" |
|
2520 shows "finite (threads s)" |
2621 shows "finite (threads s)" |
2521 using vt |
2622 using vt by (induct) (auto elim: step.cases) |
2522 by (induct) (auto elim: step.cases) |
2623 |
|
2624 end |
2523 |
2625 |
2524 lemma Max_f_mono: |
2626 lemma Max_f_mono: |
2525 assumes seq: "A \<subseteq> B" |
2627 assumes seq: "A \<subseteq> B" |
2526 and np: "A \<noteq> {}" |
2628 and np: "A \<noteq> {}" |
2527 and fnt: "finite B" |
2629 and fnt: "finite B" |
2532 from np show "f ` A \<noteq> {}" by auto |
2634 from np show "f ` A \<noteq> {}" by auto |
2533 next |
2635 next |
2534 from fnt and seq show "finite (f ` B)" by auto |
2636 from fnt and seq show "finite (f ` B)" by auto |
2535 qed |
2637 qed |
2536 |
2638 |
|
2639 context valid_trace |
|
2640 begin |
|
2641 |
2537 lemma cp_le: |
2642 lemma cp_le: |
2538 assumes vt: "vt s" |
2643 assumes th_in: "th \<in> threads s" |
2539 and th_in: "th \<in> threads s" |
|
2540 shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)" |
2644 shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)" |
2541 proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def) |
2645 proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def) |
2542 show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+})) |
2646 show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+})) |
2543 \<le> Max ((\<lambda>th. preced th s) ` threads s)" |
2647 \<le> Max ((\<lambda>th. preced th s) ` threads s)" |
2544 (is "Max (?f ` ?A) \<le> Max (?f ` ?B)") |
2648 (is "Max (?f ` ?A) \<le> Max (?f ` ?B)") |
2545 proof(rule Max_f_mono) |
2649 proof(rule Max_f_mono) |
2546 show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}" by simp |
2650 show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}" by simp |
2547 next |
2651 next |
2548 from finite_threads [OF vt] |
2652 from finite_threads |
2549 show "finite (threads s)" . |
2653 show "finite (threads s)" . |
2550 next |
2654 next |
2551 from th_in |
2655 from th_in |
2552 show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> threads s" |
2656 show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> threads s" |
2553 apply (auto simp:Domain_def) |
2657 apply (auto simp:Domain_def) |
2554 apply (rule_tac dm_RAG_threads[OF vt]) |
2658 apply (rule_tac dm_RAG_threads) |
2555 apply (unfold trancl_domain [of "RAG s", symmetric]) |
2659 apply (unfold trancl_domain [of "RAG s", symmetric]) |
2556 by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def) |
2660 by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def) |
2557 qed |
2661 qed |
2558 qed |
2662 qed |
2559 |
2663 |
2560 lemma le_cp: |
2664 lemma le_cp: |
2561 assumes vt: "vt s" |
|
2562 shows "preced th s \<le> cp s th" |
2665 shows "preced th s \<le> cp s th" |
2563 proof(unfold cp_eq_cpreced preced_def cpreced_def, simp) |
2666 proof(unfold cp_eq_cpreced preced_def cpreced_def, simp) |
2564 show "Prc (priority th s) (last_set th s) |
2667 show "Prc (priority th s) (last_set th s) |
2565 \<le> Max (insert (Prc (priority th s) (last_set th s)) |
2668 \<le> Max (insert (Prc (priority th s) (last_set th s)) |
2566 ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))" |
2669 ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))" |
2597 thus ?thesis by auto |
2700 thus ?thesis by auto |
2598 qed |
2701 qed |
2599 qed |
2702 qed |
2600 |
2703 |
2601 lemma max_cp_eq: |
2704 lemma max_cp_eq: |
2602 assumes vt: "vt s" |
|
2603 shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)" |
2705 shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)" |
2604 (is "?l = ?r") |
2706 (is "?l = ?r") |
2605 proof(cases "threads s = {}") |
2707 proof(cases "threads s = {}") |
2606 case True |
2708 case True |
2607 thus ?thesis by auto |
2709 thus ?thesis by auto |
2608 next |
2710 next |
2609 case False |
2711 case False |
2610 have "?l \<in> ((cp s) ` threads s)" |
2712 have "?l \<in> ((cp s) ` threads s)" |
2611 proof(rule Max_in) |
2713 proof(rule Max_in) |
2612 from finite_threads[OF vt] |
2714 from finite_threads |
2613 show "finite (cp s ` threads s)" by auto |
2715 show "finite (cp s ` threads s)" by auto |
2614 next |
2716 next |
2615 from False show "cp s ` threads s \<noteq> {}" by auto |
2717 from False show "cp s ` threads s \<noteq> {}" by auto |
2616 qed |
2718 qed |
2617 then obtain th |
2719 then obtain th |
2618 where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto |
2720 where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto |
2619 have "\<dots> \<le> ?r" by (rule cp_le[OF vt th_in]) |
2721 have "\<dots> \<le> ?r" by (rule cp_le[OF th_in]) |
2620 moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th") |
2722 moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th") |
2621 proof - |
2723 proof - |
2622 have "?r \<in> (?f ` ?A)" |
2724 have "?r \<in> (?f ` ?A)" |
2623 proof(rule Max_in) |
2725 proof(rule Max_in) |
2624 from finite_threads[OF vt] |
2726 from finite_threads |
2625 show " finite ((\<lambda>th. preced th s) ` threads s)" by auto |
2727 show " finite ((\<lambda>th. preced th s) ` threads s)" by auto |
2626 next |
2728 next |
2627 from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto |
2729 from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto |
2628 qed |
2730 qed |
2629 then obtain th' where |
2731 then obtain th' where |
2630 th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto |
2732 th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto |
2631 from le_cp [OF vt, of th'] eq_r |
2733 from le_cp [of th'] eq_r |
2632 have "?r \<le> cp s th'" by auto |
2734 have "?r \<le> cp s th'" by auto |
2633 moreover have "\<dots> \<le> cp s th" |
2735 moreover have "\<dots> \<le> cp s th" |
2634 proof(fold eq_l) |
2736 proof(fold eq_l) |
2635 show " cp s th' \<le> Max (cp s ` threads s)" |
2737 show " cp s th' \<le> Max (cp s ` threads s)" |
2636 proof(rule Max_ge) |
2738 proof(rule Max_ge) |
2637 from th_in' show "cp s th' \<in> cp s ` threads s" |
2739 from th_in' show "cp s th' \<in> cp s ` threads s" |
2638 by auto |
2740 by auto |
2639 next |
2741 next |
2640 from finite_threads[OF vt] |
2742 from finite_threads |
2641 show "finite (cp s ` threads s)" by auto |
2743 show "finite (cp s ` threads s)" by auto |
2642 qed |
2744 qed |
2643 qed |
2745 qed |
2644 ultimately show ?thesis by auto |
2746 ultimately show ?thesis by auto |
2645 qed |
2747 qed |
2646 ultimately show ?thesis using eq_l by auto |
2748 ultimately show ?thesis using eq_l by auto |
2647 qed |
2749 qed |
2648 |
2750 |
2649 lemma max_cp_readys_threads_pre: |
2751 lemma max_cp_readys_threads_pre: |
2650 assumes vt: "vt s" |
2752 assumes np: "threads s \<noteq> {}" |
2651 and np: "threads s \<noteq> {}" |
|
2652 shows "Max (cp s ` readys s) = Max (cp s ` threads s)" |
2753 shows "Max (cp s ` readys s) = Max (cp s ` threads s)" |
2653 proof(unfold max_cp_eq[OF vt]) |
2754 proof(unfold max_cp_eq) |
2654 show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)" |
2755 show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)" |
2655 proof - |
2756 proof - |
2656 let ?p = "Max ((\<lambda>th. preced th s) ` threads s)" |
2757 let ?p = "Max ((\<lambda>th. preced th s) ` threads s)" |
2657 let ?f = "(\<lambda>th. preced th s)" |
2758 let ?f = "(\<lambda>th. preced th s)" |
2658 have "?p \<in> ((\<lambda>th. preced th s) ` threads s)" |
2759 have "?p \<in> ((\<lambda>th. preced th s) ` threads s)" |
2659 proof(rule Max_in) |
2760 proof(rule Max_in) |
2660 from finite_threads[OF vt] show "finite (?f ` threads s)" by simp |
2761 from finite_threads show "finite (?f ` threads s)" by simp |
2661 next |
2762 next |
2662 from np show "?f ` threads s \<noteq> {}" by simp |
2763 from np show "?f ` threads s \<noteq> {}" by simp |
2663 qed |
2764 qed |
2664 then obtain tm where tm_max: "?f tm = ?p" and tm_in: "tm \<in> threads s" |
2765 then obtain tm where tm_max: "?f tm = ?p" and tm_in: "tm \<in> threads s" |
2665 by (auto simp:Image_def) |
2766 by (auto simp:Image_def) |
2666 from th_chain_to_ready [OF vt tm_in] |
2767 from th_chain_to_ready [OF tm_in] |
2667 have "tm \<in> readys s \<or> (\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+)" . |
2768 have "tm \<in> readys s \<or> (\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+)" . |
2668 thus ?thesis |
2769 thus ?thesis |
2669 proof |
2770 proof |
2670 assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+ " |
2771 assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+ " |
2671 then obtain th' where th'_in: "th' \<in> readys s" |
2772 then obtain th' where th'_in: "th' \<in> readys s" |
2672 and tm_chain:"(Th tm, Th th') \<in> (RAG s)\<^sup>+" by auto |
2773 and tm_chain:"(Th tm, Th th') \<in> (RAG s)\<^sup>+" by auto |
2673 have "cp s th' = ?f tm" |
2774 have "cp s th' = ?f tm" |
2674 proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI) |
2775 proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI) |
2675 from dependants_threads[OF vt] finite_threads[OF vt] |
2776 from dependants_threads finite_threads |
2676 show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" |
2777 show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" |
2677 by (auto intro:finite_subset) |
2778 by (auto intro:finite_subset) |
2678 next |
2779 next |
2679 fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')" |
2780 fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')" |
2680 from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" . |
2781 from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" . |
2681 moreover have "p \<le> \<dots>" |
2782 moreover have "p \<le> \<dots>" |
2682 proof(rule Max_ge) |
2783 proof(rule Max_ge) |
2683 from finite_threads[OF vt] |
2784 from finite_threads |
2684 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2785 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2685 next |
2786 next |
2686 from p_in and th'_in and dependants_threads[OF vt, of th'] |
2787 from p_in and th'_in and dependants_threads[of th'] |
2687 show "p \<in> (\<lambda>th. preced th s) ` threads s" |
2788 show "p \<in> (\<lambda>th. preced th s) ` threads s" |
2688 by (auto simp:readys_def) |
2789 by (auto simp:readys_def) |
2689 qed |
2790 qed |
2690 ultimately show "p \<le> preced tm s" by auto |
2791 ultimately show "p \<le> preced tm s" by auto |
2691 next |
2792 next |
2708 show "q \<le> cp s th'" |
2809 show "q \<le> cp s th'" |
2709 apply (unfold h eq_q) |
2810 apply (unfold h eq_q) |
2710 apply (unfold cp_eq_cpreced cpreced_def) |
2811 apply (unfold cp_eq_cpreced cpreced_def) |
2711 apply (rule Max_mono) |
2812 apply (rule Max_mono) |
2712 proof - |
2813 proof - |
2713 from dependants_threads [OF vt, of th1] th1_in |
2814 from dependants_threads [of th1] th1_in |
2714 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> |
2815 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> |
2715 (\<lambda>th. preced th s) ` threads s" |
2816 (\<lambda>th. preced th s) ` threads s" |
2716 by (auto simp:readys_def) |
2817 by (auto simp:readys_def) |
2717 next |
2818 next |
2718 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" by simp |
2819 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" by simp |
2719 next |
2820 next |
2720 from finite_threads[OF vt] |
2821 from finite_threads |
2721 show " finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2822 show " finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2722 qed |
2823 qed |
2723 next |
2824 next |
2724 from finite_threads[OF vt] |
2825 from finite_threads |
2725 show "finite (cp s ` readys s)" by (auto simp:readys_def) |
2826 show "finite (cp s ` readys s)" by (auto simp:readys_def) |
2726 next |
2827 next |
2727 from th'_in |
2828 from th'_in |
2728 show "cp s th' \<in> cp s ` readys s" by simp |
2829 show "cp s th' \<in> cp s ` readys s" by simp |
2729 qed |
2830 qed |
2739 proof - |
2840 proof - |
2740 { fix y' |
2841 { fix y' |
2741 assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)" |
2842 assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)" |
2742 have "y' \<le> preced tm s" |
2843 have "y' \<le> preced tm s" |
2743 proof(unfold tm_max, rule Max_ge) |
2844 proof(unfold tm_max, rule Max_ge) |
2744 from hy' dependants_threads[OF vt, of tm] |
2845 from hy' dependants_threads[of tm] |
2745 show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto |
2846 show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto |
2746 next |
2847 next |
2747 from finite_threads[OF vt] |
2848 from finite_threads |
2748 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2849 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2749 qed |
2850 qed |
2750 } with hy show ?thesis by auto |
2851 } with hy show ?thesis by auto |
2751 qed |
2852 qed |
2752 next |
2853 next |
2753 from dependants_threads[OF vt, of tm] finite_threads[OF vt] |
2854 from dependants_threads[of tm] finite_threads |
2754 show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))" |
2855 show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))" |
2755 by (auto intro:finite_subset) |
2856 by (auto intro:finite_subset) |
2756 next |
2857 next |
2757 show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)" |
2858 show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)" |
2758 by simp |
2859 by simp |
2759 qed |
2860 qed |
2760 moreover have "Max (cp s ` readys s) = cp s tm" |
2861 moreover have "Max (cp s ` readys s) = cp s tm" |
2761 proof(rule Max_eqI) |
2862 proof(rule Max_eqI) |
2762 from tm_ready show "cp s tm \<in> cp s ` readys s" by simp |
2863 from tm_ready show "cp s tm \<in> cp s ` readys s" by simp |
2763 next |
2864 next |
2764 from finite_threads[OF vt] |
2865 from finite_threads |
2765 show "finite (cp s ` readys s)" by (auto simp:readys_def) |
2866 show "finite (cp s ` readys s)" by (auto simp:readys_def) |
2766 next |
2867 next |
2767 fix y assume "y \<in> cp s ` readys s" |
2868 fix y assume "y \<in> cp s ` readys s" |
2768 then obtain th1 where th1_readys: "th1 \<in> readys s" |
2869 then obtain th1 where th1_readys: "th1 \<in> readys s" |
2769 and h: "y = cp s th1" by auto |
2870 and h: "y = cp s th1" by auto |
2770 show "y \<le> cp s tm" |
2871 show "y \<le> cp s tm" |
2771 apply(unfold cp_eq_p h) |
2872 apply(unfold cp_eq_p h) |
2772 apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono) |
2873 apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono) |
2773 proof - |
2874 proof - |
2774 from finite_threads[OF vt] |
2875 from finite_threads |
2775 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2876 show "finite ((\<lambda>th. preced th s) ` threads s)" by simp |
2776 next |
2877 next |
2777 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" |
2878 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" |
2778 by simp |
2879 by simp |
2779 next |
2880 next |
2780 from dependants_threads[OF vt, of th1] th1_readys |
2881 from dependants_threads[of th1] th1_readys |
2781 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) |
2882 show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) |
2782 \<subseteq> (\<lambda>th. preced th s) ` threads s" |
2883 \<subseteq> (\<lambda>th. preced th s) ` threads s" |
2783 by (auto simp:readys_def) |
2884 by (auto simp:readys_def) |
2784 qed |
2885 qed |
2785 qed |
2886 qed |
2834 apply(simp add: Domain_iff Range_iff) |
2935 apply(simp add: Domain_iff Range_iff) |
2835 apply(simp add: wq_def) |
2936 apply(simp add: wq_def) |
2836 apply(auto) |
2937 apply(auto) |
2837 done |
2938 done |
2838 |
2939 |
|
2940 context valid_trace |
|
2941 begin |
|
2942 |
2839 lemma detached_intro: |
2943 lemma detached_intro: |
2840 fixes s th |
2944 assumes eq_pv: "cntP s th = cntV s th" |
2841 assumes vt: "vt s" |
|
2842 and eq_pv: "cntP s th = cntV s th" |
|
2843 shows "detached s th" |
2945 shows "detached s th" |
2844 proof - |
2946 proof - |
2845 from cnp_cnv_cncs[OF vt] |
2947 from cnp_cnv_cncs |
2846 have eq_cnt: "cntP s th = |
2948 have eq_cnt: "cntP s th = |
2847 cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" . |
2949 cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" . |
2848 hence cncs_zero: "cntCS s th = 0" |
2950 hence cncs_zero: "cntCS s th = 0" |
2849 by (auto simp:eq_pv split:if_splits) |
2951 by (auto simp:eq_pv split:if_splits) |
2850 with eq_cnt |
2952 with eq_cnt |
2851 have "th \<in> readys s \<or> th \<notin> threads s" by (auto simp:eq_pv) |
2953 have "th \<in> readys s \<or> th \<notin> threads s" by (auto simp:eq_pv) |
2852 thus ?thesis |
2954 thus ?thesis |
2853 proof |
2955 proof |
2854 assume "th \<notin> threads s" |
2956 assume "th \<notin> threads s" |
2855 with range_in[OF vt] dm_RAG_threads[OF vt] |
2957 with range_in dm_RAG_threads |
2856 show ?thesis |
2958 show ?thesis |
2857 by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def Domain_iff Range_iff) |
2959 by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def Domain_iff Range_iff) |
2858 next |
2960 next |
2859 assume "th \<in> readys s" |
2961 assume "th \<in> readys s" |
2860 moreover have "Th th \<notin> Range (RAG s)" |
2962 moreover have "Th th \<notin> Range (RAG s)" |
2861 proof - |
2963 proof - |
2862 from card_0_eq [OF finite_holding [OF vt]] and cncs_zero |
2964 from card_0_eq [OF finite_holding] and cncs_zero |
2863 have "holdents s th = {}" |
2965 have "holdents s th = {}" |
2864 by (simp add:cntCS_def) |
2966 by (simp add:cntCS_def) |
2865 thus ?thesis |
2967 thus ?thesis |
2866 apply(auto simp:holdents_test) |
2968 apply(auto simp:holdents_test) |
2867 apply(case_tac a) |
2969 apply(case_tac a) |