7 |
7 |
8 lemma wq_v_neq: |
8 lemma wq_v_neq: |
9 "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'" |
9 "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'" |
10 by (auto simp:wq_def Let_def cp_def split:list.splits) |
10 by (auto simp:wq_def Let_def cp_def split:list.splits) |
11 |
11 |
12 lemma wq_distinct: "vt step s \<Longrightarrow> distinct (wq s cs)" |
12 lemma wq_distinct: "vt s \<Longrightarrow> distinct (wq s cs)" |
13 proof(erule_tac vt.induct, simp add:wq_def) |
13 proof(erule_tac vt.induct, simp add:wq_def) |
14 fix s e |
14 fix s e |
15 assume h1: "step s e" |
15 assume h1: "step s e" |
16 and h2: "distinct (wq s cs)" |
16 and h2: "distinct (wq s cs)" |
17 thus "distinct (wq (e # s) cs)" |
17 thus "distinct (wq (e # s) cs)" |
42 thus "distinct q" by auto |
42 thus "distinct q" by auto |
43 qed |
43 qed |
44 qed |
44 qed |
45 qed |
45 qed |
46 |
46 |
47 lemma step_back_vt: "vt ccs (e#s) \<Longrightarrow> vt ccs s" |
47 lemma step_back_vt: "vt (e#s) \<Longrightarrow> vt s" |
48 by(ind_cases "vt ccs (e#s)", simp) |
48 by(ind_cases "vt (e#s)", simp) |
49 |
49 |
50 lemma step_back_step: "vt ccs (e#s) \<Longrightarrow> ccs s e" |
50 lemma step_back_step: "vt (e#s) \<Longrightarrow> step s e" |
51 by(ind_cases "vt ccs (e#s)", simp) |
51 by(ind_cases "vt (e#s)", simp) |
52 |
52 |
53 lemma block_pre: |
53 lemma block_pre: |
54 fixes thread cs s |
54 fixes thread cs s |
55 assumes vt_e: "vt step (e#s)" |
55 assumes vt_e: "vt (e#s)" |
56 and s_ni: "thread \<notin> set (wq s cs)" |
56 and s_ni: "thread \<notin> set (wq s cs)" |
57 and s_i: "thread \<in> set (wq (e#s) cs)" |
57 and s_i: "thread \<in> set (wq (e#s) cs)" |
58 shows "e = P thread cs" |
58 shows "e = P thread cs" |
59 proof - |
59 proof - |
60 show ?thesis |
60 show ?thesis |
82 proof - |
82 proof - |
83 fix q qs |
83 fix q qs |
84 assume h1: "thread \<notin> set (wq_fun (schs s) cs)" |
84 assume h1: "thread \<notin> set (wq_fun (schs s) cs)" |
85 and h2: "q # qs = wq_fun (schs s) cs" |
85 and h2: "q # qs = wq_fun (schs s) cs" |
86 and h3: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)" |
86 and h3: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)" |
87 and vt: "vt step (V th cs # s)" |
87 and vt: "vt (V th cs # s)" |
88 from h1 and h2[symmetric] have "thread \<notin> set (q # qs)" by simp |
88 from h1 and h2[symmetric] have "thread \<notin> set (q # qs)" by simp |
89 moreover have "thread \<in> set qs" |
89 moreover have "thread \<in> set qs" |
90 proof - |
90 proof - |
91 have "set (SOME q. distinct q \<and> set q = set qs) = set qs" |
91 have "set (SOME q. distinct q \<and> set q = set qs) = set qs" |
92 proof(rule someI2) |
92 proof(rule someI2) |
122 qed |
122 qed |
123 |
123 |
124 lemma q_head: "Q (hd es) \<Longrightarrow> hd es = hd [th\<leftarrow>es . Q th]" |
124 lemma q_head: "Q (hd es) \<Longrightarrow> hd es = hd [th\<leftarrow>es . Q th]" |
125 by (cases es, auto) |
125 by (cases es, auto) |
126 |
126 |
127 inductive_cases evt_cons: "vt cs (a#s)" |
127 inductive_cases evt_cons: "vt (a#s)" |
128 |
128 |
129 lemma abs2: |
129 lemma abs2: |
130 assumes vt: "vt step (e#s)" |
130 assumes vt: "vt (e#s)" |
131 and inq: "thread \<in> set (wq s cs)" |
131 and inq: "thread \<in> set (wq s cs)" |
132 and nh: "thread = hd (wq s cs)" |
132 and nh: "thread = hd (wq s cs)" |
133 and qt: "thread \<noteq> hd (wq (e#s) cs)" |
133 and qt: "thread \<noteq> hd (wq (e#s) cs)" |
134 and inq': "thread \<in> set (wq (e#s) cs)" |
134 and inq': "thread \<in> set (wq (e#s) cs)" |
135 shows "False" |
135 shows "False" |
139 apply ((simp split:if_splits add:Let_def wq_def)[1])+ |
139 apply ((simp split:if_splits add:Let_def wq_def)[1])+ |
140 apply (insert abs1, fast)[1] |
140 apply (insert abs1, fast)[1] |
141 apply (auto simp:wq_def simp:Let_def split:if_splits list.splits) |
141 apply (auto simp:wq_def simp:Let_def split:if_splits list.splits) |
142 proof - |
142 proof - |
143 fix th qs |
143 fix th qs |
144 assume vt: "vt step (V th cs # s)" |
144 assume vt: "vt (V th cs # s)" |
145 and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)" |
145 and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)" |
146 and eq_wq: "wq_fun (schs s) cs = thread # qs" |
146 and eq_wq: "wq_fun (schs s) cs = thread # qs" |
147 show "False" |
147 show "False" |
148 proof - |
148 proof - |
149 from wq_distinct[OF step_back_vt[OF vt], of cs] |
149 from wq_distinct[OF step_back_vt[OF vt], of cs] |
164 ultimately show ?thesis by auto |
164 ultimately show ?thesis by auto |
165 qed |
165 qed |
166 qed |
166 qed |
167 qed |
167 qed |
168 |
168 |
169 lemma vt_moment: "\<And> t. \<lbrakk>vt cs s; t \<le> length s\<rbrakk> \<Longrightarrow> vt cs (moment t s)" |
169 lemma vt_moment: "\<And> t. \<lbrakk>vt s; t \<le> length s\<rbrakk> \<Longrightarrow> vt (moment t s)" |
170 proof(induct s, simp) |
170 proof(induct s, simp) |
171 fix a s t |
171 fix a s t |
172 assume h: "\<And>t.\<lbrakk>vt cs s; t \<le> length s\<rbrakk> \<Longrightarrow> vt cs (moment t s)" |
172 assume h: "\<And>t.\<lbrakk>vt s; t \<le> length s\<rbrakk> \<Longrightarrow> vt (moment t s)" |
173 and vt_a: "vt cs (a # s)" |
173 and vt_a: "vt (a # s)" |
174 and le_t: "t \<le> length (a # s)" |
174 and le_t: "t \<le> length (a # s)" |
175 show "vt cs (moment t (a # s))" |
175 show "vt (moment t (a # s))" |
176 proof(cases "t = length (a#s)") |
176 proof(cases "t = length (a#s)") |
177 case True |
177 case True |
178 from True have "moment t (a#s) = a#s" by simp |
178 from True have "moment t (a#s) = a#s" by simp |
179 with vt_a show ?thesis by simp |
179 with vt_a show ?thesis by simp |
180 next |
180 next |
181 case False |
181 case False |
182 with le_t have le_t1: "t \<le> length s" by simp |
182 with le_t have le_t1: "t \<le> length s" by simp |
183 from vt_a have "vt cs s" |
183 from vt_a have "vt s" |
184 by (erule_tac evt_cons, simp) |
184 by (erule_tac evt_cons, simp) |
185 from h [OF this le_t1] have "vt cs (moment t s)" . |
185 from h [OF this le_t1] have "vt (moment t s)" . |
186 moreover have "moment t (a#s) = moment t s" |
186 moreover have "moment t (a#s) = moment t s" |
187 proof - |
187 proof - |
188 from moment_app [OF le_t1, of "[a]"] |
188 from moment_app [OF le_t1, of "[a]"] |
189 show ?thesis by simp |
189 show ?thesis by simp |
190 qed |
190 qed |
196 lemma \<lbrakk>thread \<in> set (wq_fun cs1 s); thread \<in> set (wq_fun cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2" |
196 lemma \<lbrakk>thread \<in> set (wq_fun cs1 s); thread \<in> set (wq_fun cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2" |
197 *) |
197 *) |
198 |
198 |
199 lemma waiting_unique_pre: |
199 lemma waiting_unique_pre: |
200 fixes cs1 cs2 s thread |
200 fixes cs1 cs2 s thread |
201 assumes vt: "vt step s" |
201 assumes vt: "vt s" |
202 and h11: "thread \<in> set (wq s cs1)" |
202 and h11: "thread \<in> set (wq s cs1)" |
203 and h12: "thread \<noteq> hd (wq s cs1)" |
203 and h12: "thread \<noteq> hd (wq s cs1)" |
204 assumes h21: "thread \<in> set (wq s cs2)" |
204 assumes h21: "thread \<in> set (wq s cs2)" |
205 and h22: "thread \<noteq> hd (wq s cs2)" |
205 and h22: "thread \<noteq> hd (wq s cs2)" |
206 and neq12: "cs1 \<noteq> cs2" |
206 and neq12: "cs1 \<noteq> cs2" |
233 obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto |
233 obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto |
234 have "t2 < ?t3" by simp |
234 have "t2 < ?t3" by simp |
235 from nn2 [rule_format, OF this] and eq_m |
235 from nn2 [rule_format, OF this] and eq_m |
236 have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and |
236 have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and |
237 h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto |
237 h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto |
238 have vt_e: "vt step (e#moment t2 s)" |
238 have vt_e: "vt (e#moment t2 s)" |
239 proof - |
239 proof - |
240 from vt_moment [OF vt le_t3] |
240 from vt_moment [OF vt le_t3] |
241 have "vt step (moment ?t3 s)" . |
241 have "vt (moment ?t3 s)" . |
242 with eq_m show ?thesis by simp |
242 with eq_m show ?thesis by simp |
243 qed |
243 qed |
244 have ?thesis |
244 have ?thesis |
245 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
245 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
246 case True |
246 case True |
250 show ?thesis by auto |
250 show ?thesis by auto |
251 next |
251 next |
252 case False |
252 case False |
253 from block_pre [OF vt_e False h1] |
253 from block_pre [OF vt_e False h1] |
254 have "e = P thread cs2" . |
254 have "e = P thread cs2" . |
255 with vt_e have "vt step ((P thread cs2)# moment t2 s)" by simp |
255 with vt_e have "vt ((P thread cs2)# moment t2 s)" by simp |
256 from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp |
256 from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp |
257 with runing_ready have "thread \<in> readys (moment t2 s)" by auto |
257 with runing_ready have "thread \<in> readys (moment t2 s)" by auto |
258 with nn1 [rule_format, OF lt12] |
258 with nn1 [rule_format, OF lt12] |
259 show ?thesis by (simp add:readys_def s_waiting_def, auto) |
259 show ?thesis by (simp add:readys_def wq_def s_waiting_def, auto) |
260 qed |
260 qed |
261 } moreover { |
261 } moreover { |
262 assume lt12: "t2 < t1" |
262 assume lt12: "t2 < t1" |
263 let ?t3 = "Suc t1" |
263 let ?t3 = "Suc t1" |
264 from lt1 have le_t3: "?t3 \<le> length s" by auto |
264 from lt1 have le_t3: "?t3 \<le> length s" by auto |
266 obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto |
266 obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto |
267 have lt_t3: "t1 < ?t3" by simp |
267 have lt_t3: "t1 < ?t3" by simp |
268 from nn1 [rule_format, OF this] and eq_m |
268 from nn1 [rule_format, OF this] and eq_m |
269 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
269 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
270 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
270 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
271 have vt_e: "vt step (e#moment t1 s)" |
271 have vt_e: "vt (e#moment t1 s)" |
272 proof - |
272 proof - |
273 from vt_moment [OF vt le_t3] |
273 from vt_moment [OF vt le_t3] |
274 have "vt step (moment ?t3 s)" . |
274 have "vt (moment ?t3 s)" . |
275 with eq_m show ?thesis by simp |
275 with eq_m show ?thesis by simp |
276 qed |
276 qed |
277 have ?thesis |
277 have ?thesis |
278 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
278 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
279 case True |
279 case True |
283 show ?thesis by auto |
283 show ?thesis by auto |
284 next |
284 next |
285 case False |
285 case False |
286 from block_pre [OF vt_e False h1] |
286 from block_pre [OF vt_e False h1] |
287 have "e = P thread cs1" . |
287 have "e = P thread cs1" . |
288 with vt_e have "vt step ((P thread cs1)# moment t1 s)" by simp |
288 with vt_e have "vt ((P thread cs1)# moment t1 s)" by simp |
289 from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp |
289 from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp |
290 with runing_ready have "thread \<in> readys (moment t1 s)" by auto |
290 with runing_ready have "thread \<in> readys (moment t1 s)" by auto |
291 with nn2 [rule_format, OF lt12] |
291 with nn2 [rule_format, OF lt12] |
292 show ?thesis by (simp add:readys_def s_waiting_def, auto) |
292 show ?thesis by (simp add:readys_def wq_def s_waiting_def, auto) |
293 qed |
293 qed |
294 } moreover { |
294 } moreover { |
295 assume eqt12: "t1 = t2" |
295 assume eqt12: "t1 = t2" |
296 let ?t3 = "Suc t1" |
296 let ?t3 = "Suc t1" |
297 from lt1 have le_t3: "?t3 \<le> length s" by auto |
297 from lt1 have le_t3: "?t3 \<le> length s" by auto |
299 obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto |
299 obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto |
300 have lt_t3: "t1 < ?t3" by simp |
300 have lt_t3: "t1 < ?t3" by simp |
301 from nn1 [rule_format, OF this] and eq_m |
301 from nn1 [rule_format, OF this] and eq_m |
302 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
302 have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and |
303 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
303 h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto |
304 have vt_e: "vt step (e#moment t1 s)" |
304 have vt_e: "vt (e#moment t1 s)" |
305 proof - |
305 proof - |
306 from vt_moment [OF vt le_t3] |
306 from vt_moment [OF vt le_t3] |
307 have "vt step (moment ?t3 s)" . |
307 have "vt (moment ?t3 s)" . |
308 with eq_m show ?thesis by simp |
308 with eq_m show ?thesis by simp |
309 qed |
309 qed |
310 have ?thesis |
310 have ?thesis |
311 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
311 proof(cases "thread \<in> set (wq (moment t1 s) cs1)") |
312 case True |
312 case True |
326 show ?thesis |
326 show ?thesis |
327 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
327 proof(cases "thread \<in> set (wq (moment t2 s) cs2)") |
328 case True |
328 case True |
329 from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)" |
329 from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)" |
330 by auto |
330 by auto |
331 from vt_e and eqt12 have "vt step (e#moment t2 s)" by simp |
331 from vt_e and eqt12 have "vt (e#moment t2 s)" by simp |
332 from abs2 [OF this True eq_th h2 h1] |
332 from abs2 [OF this True eq_th h2 h1] |
333 show ?thesis . |
333 show ?thesis . |
334 next |
334 next |
335 case False |
335 case False |
336 have vt_e: "vt step (e#moment t2 s)" |
336 have vt_e: "vt (e#moment t2 s)" |
337 proof - |
337 proof - |
338 from vt_moment [OF vt le_t3] eqt12 |
338 from vt_moment [OF vt le_t3] eqt12 |
339 have "vt step (moment (Suc t2) s)" by auto |
339 have "vt (moment (Suc t2) s)" by auto |
340 with eq_m eqt12 show ?thesis by simp |
340 with eq_m eqt12 show ?thesis by simp |
341 qed |
341 qed |
342 from block_pre [OF vt_e False h1] |
342 from block_pre [OF vt_e False h1] |
343 have "e = P thread cs2" . |
343 have "e = P thread cs2" . |
344 with eq_e1 neq12 show ?thesis by auto |
344 with eq_e1 neq12 show ?thesis by auto |
348 qed |
348 qed |
349 qed |
349 qed |
350 |
350 |
351 lemma waiting_unique: |
351 lemma waiting_unique: |
352 fixes s cs1 cs2 |
352 fixes s cs1 cs2 |
353 assumes "vt step s" |
353 assumes "vt s" |
354 and "waiting s th cs1" |
354 and "waiting s th cs1" |
355 and "waiting s th cs2" |
355 and "waiting s th cs2" |
356 shows "cs1 = cs2" |
356 shows "cs1 = cs2" |
357 proof - |
357 proof - |
358 from waiting_unique_pre and prems |
358 from waiting_unique_pre and prems |
359 show ?thesis |
359 show ?thesis |
360 by (auto simp add:s_waiting_def) |
360 by (auto simp add: wq_def s_waiting_def) |
361 qed |
361 qed |
362 |
362 |
363 lemma held_unique: |
363 lemma held_unique: |
364 assumes "vt step s" |
364 assumes "vt s" |
365 and "holding s th1 cs" |
365 and "holding s th1 cs" |
366 and "holding s th2 cs" |
366 and "holding s th2 cs" |
367 shows "th1 = th2" |
367 shows "th1 = th2" |
368 proof - |
368 proof - |
369 from prems show ?thesis |
369 from prems show ?thesis |
510 by (simp add:Let_def) |
510 by (simp add:Let_def) |
511 |
511 |
512 |
512 |
513 |
513 |
514 lemma step_v_hold_inv[elim_format]: |
514 lemma step_v_hold_inv[elim_format]: |
515 "\<And>c t. \<lbrakk>vt step (V th cs # s); |
515 "\<And>c t. \<lbrakk>vt (V th cs # s); |
516 \<not> holding (wq s) t c; holding (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> next_th s th cs t \<and> c = cs" |
516 \<not> holding (wq s) t c; holding (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> next_th s th cs t \<and> c = cs" |
517 proof - |
517 proof - |
518 fix c t |
518 fix c t |
519 assume vt: "vt step (V th cs # s)" |
519 assume vt: "vt (V th cs # s)" |
520 and nhd: "\<not> holding (wq s) t c" |
520 and nhd: "\<not> holding (wq s) t c" |
521 and hd: "holding (wq (V th cs # s)) t c" |
521 and hd: "holding (wq (V th cs # s)) t c" |
522 show "next_th s th cs t \<and> c = cs" |
522 show "next_th s th cs t \<and> c = cs" |
523 proof(cases "c = cs") |
523 proof(cases "c = cs") |
524 case False |
524 case False |
559 with True show ?thesis by auto |
559 with True show ?thesis by auto |
560 qed |
560 qed |
561 qed |
561 qed |
562 |
562 |
563 lemma step_v_wait_inv[elim_format]: |
563 lemma step_v_wait_inv[elim_format]: |
564 "\<And>t c. \<lbrakk>vt step (V th cs # s); \<not> waiting (wq (V th cs # s)) t c; waiting (wq s) t c |
564 "\<And>t c. \<lbrakk>vt (V th cs # s); \<not> waiting (wq (V th cs # s)) t c; waiting (wq s) t c |
565 \<rbrakk> |
565 \<rbrakk> |
566 \<Longrightarrow> (next_th s th cs t \<and> cs = c)" |
566 \<Longrightarrow> (next_th s th cs t \<and> cs = c)" |
567 proof - |
567 proof - |
568 fix t c |
568 fix t c |
569 assume vt: "vt step (V th cs # s)" |
569 assume vt: "vt (V th cs # s)" |
570 and nw: "\<not> waiting (wq (V th cs # s)) t c" |
570 and nw: "\<not> waiting (wq (V th cs # s)) t c" |
571 and wt: "waiting (wq s) t c" |
571 and wt: "waiting (wq s) t c" |
572 show "next_th s th cs t \<and> cs = c" |
572 show "next_th s th cs t \<and> cs = c" |
573 proof(cases "cs = c") |
573 proof(cases "cs = c") |
574 case False |
574 case False |
621 with True show ?thesis by simp |
621 with True show ?thesis by simp |
622 qed |
622 qed |
623 qed |
623 qed |
624 |
624 |
625 lemma step_v_not_wait[consumes 3]: |
625 lemma step_v_not_wait[consumes 3]: |
626 "\<lbrakk>vt step (V th cs # s); next_th s th cs t; waiting (wq (V th cs # s)) t cs\<rbrakk> \<Longrightarrow> False" |
626 "\<lbrakk>vt (V th cs # s); next_th s th cs t; waiting (wq (V th cs # s)) t cs\<rbrakk> \<Longrightarrow> False" |
627 by (unfold next_th_def cs_waiting_def wq_def, auto simp:Let_def) |
627 by (unfold next_th_def cs_waiting_def wq_def, auto simp:Let_def) |
628 |
628 |
629 lemma step_v_release: |
629 lemma step_v_release: |
630 "\<lbrakk>vt step (V th cs # s); holding (wq (V th cs # s)) th cs\<rbrakk> \<Longrightarrow> False" |
630 "\<lbrakk>vt (V th cs # s); holding (wq (V th cs # s)) th cs\<rbrakk> \<Longrightarrow> False" |
631 proof - |
631 proof - |
632 assume vt: "vt step (V th cs # s)" |
632 assume vt: "vt (V th cs # s)" |
633 and hd: "holding (wq (V th cs # s)) th cs" |
633 and hd: "holding (wq (V th cs # s)) th cs" |
634 from step_back_step [OF vt] and hd |
634 from step_back_step [OF vt] and hd |
635 show "False" |
635 show "False" |
636 proof(cases) |
636 proof(cases) |
637 assume "holding (wq (V th cs # s)) th cs" and "holding s th cs" |
637 assume "holding (wq (V th cs # s)) th cs" and "holding s th cs" |
662 qed |
662 qed |
663 qed |
663 qed |
664 qed |
664 qed |
665 |
665 |
666 lemma step_v_get_hold: |
666 lemma step_v_get_hold: |
667 "\<And>th'. \<lbrakk>vt step (V th cs # s); \<not> holding (wq (V th cs # s)) th' cs; next_th s th cs th'\<rbrakk> \<Longrightarrow> False" |
667 "\<And>th'. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) th' cs; next_th s th cs th'\<rbrakk> \<Longrightarrow> False" |
668 apply (unfold cs_holding_def next_th_def wq_def, |
668 apply (unfold cs_holding_def next_th_def wq_def, |
669 auto simp:Let_def) |
669 auto simp:Let_def) |
670 proof - |
670 proof - |
671 fix rest |
671 fix rest |
672 assume vt: "vt step (V th cs # s)" |
672 assume vt: "vt (V th cs # s)" |
673 and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest" |
673 and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest" |
674 and nrest: "rest \<noteq> []" |
674 and nrest: "rest \<noteq> []" |
675 and ni: "hd (SOME q. distinct q \<and> set q = set rest) |
675 and ni: "hd (SOME q. distinct q \<and> set q = set rest) |
676 \<notin> set (SOME q. distinct q \<and> set q = set rest)" |
676 \<notin> set (SOME q. distinct q \<and> set q = set rest)" |
677 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
677 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
686 qed |
686 qed |
687 with ni show "False" by auto |
687 with ni show "False" by auto |
688 qed |
688 qed |
689 |
689 |
690 lemma step_v_release_inv[elim_format]: |
690 lemma step_v_release_inv[elim_format]: |
691 "\<And>c t. \<lbrakk>vt step (V th cs # s); \<not> holding (wq (V th cs # s)) t c; holding (wq s) t c\<rbrakk> \<Longrightarrow> |
691 "\<And>c t. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) t c; holding (wq s) t c\<rbrakk> \<Longrightarrow> |
692 c = cs \<and> t = th" |
692 c = cs \<and> t = th" |
693 apply (unfold cs_holding_def wq_def, auto simp:Let_def split:if_splits list.splits) |
693 apply (unfold cs_holding_def wq_def, auto simp:Let_def split:if_splits list.splits) |
694 proof - |
694 proof - |
695 fix a list |
695 fix a list |
696 assume vt: "vt step (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list" |
696 assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list" |
697 from step_back_step [OF vt] show "a = th" |
697 from step_back_step [OF vt] show "a = th" |
698 proof(cases) |
698 proof(cases) |
699 assume "holding s th cs" with eq_wq |
699 assume "holding s th cs" with eq_wq |
700 show ?thesis |
700 show ?thesis |
701 by (unfold s_holding_def wq_def, auto) |
701 by (unfold s_holding_def wq_def, auto) |
702 qed |
702 qed |
703 next |
703 next |
704 fix a list |
704 fix a list |
705 assume vt: "vt step (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list" |
705 assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list" |
706 from step_back_step [OF vt] show "a = th" |
706 from step_back_step [OF vt] show "a = th" |
707 proof(cases) |
707 proof(cases) |
708 assume "holding s th cs" with eq_wq |
708 assume "holding s th cs" with eq_wq |
709 show ?thesis |
709 show ?thesis |
710 by (unfold s_holding_def wq_def, auto) |
710 by (unfold s_holding_def wq_def, auto) |
711 qed |
711 qed |
712 qed |
712 qed |
713 |
713 |
714 lemma step_v_waiting_mono: |
714 lemma step_v_waiting_mono: |
715 "\<And>t c. \<lbrakk>vt step (V th cs # s); waiting (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> waiting (wq s) t c" |
715 "\<And>t c. \<lbrakk>vt (V th cs # s); waiting (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> waiting (wq s) t c" |
716 proof - |
716 proof - |
717 fix t c |
717 fix t c |
718 let ?s' = "(V th cs # s)" |
718 let ?s' = "(V th cs # s)" |
719 assume vt: "vt step ?s'" |
719 assume vt: "vt ?s'" |
720 and wt: "waiting (wq ?s') t c" |
720 and wt: "waiting (wq ?s') t c" |
721 show "waiting (wq s) t c" |
721 show "waiting (wq s) t c" |
722 proof(cases "c = cs") |
722 proof(cases "c = cs") |
723 case False |
723 case False |
724 assume neq_cs: "c \<noteq> cs" |
724 assume neq_cs: "c \<noteq> cs" |
785 step_v_get_hold step_v_release_inv) |
785 step_v_get_hold step_v_release_inv) |
786 apply (erule_tac step_v_not_wait, auto) |
786 apply (erule_tac step_v_not_wait, auto) |
787 done |
787 done |
788 |
788 |
789 lemma step_depend_p: |
789 lemma step_depend_p: |
790 "vt step (P th cs#s) \<Longrightarrow> |
790 "vt (P th cs#s) \<Longrightarrow> |
791 depend (P th cs # s) = (if (wq s cs = []) then depend s \<union> {(Cs cs, Th th)} |
791 depend (P th cs # s) = (if (wq s cs = []) then depend s \<union> {(Cs cs, Th th)} |
792 else depend s \<union> {(Th th, Cs cs)})" |
792 else depend s \<union> {(Th th, Cs cs)})" |
793 apply(simp only: s_depend_def wq_def) |
793 apply(simp only: s_depend_def wq_def) |
794 apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def) |
794 apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def) |
795 apply(case_tac "csa = cs", auto) |
795 apply(case_tac "csa = cs", auto) |
814 lemma depend_target_th: "(Th th, x) \<in> depend (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs" |
814 lemma depend_target_th: "(Th th, x) \<in> depend (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs" |
815 by (unfold s_depend_def, auto) |
815 by (unfold s_depend_def, auto) |
816 |
816 |
817 lemma acyclic_depend: |
817 lemma acyclic_depend: |
818 fixes s |
818 fixes s |
819 assumes vt: "vt step s" |
819 assumes vt: "vt s" |
820 shows "acyclic (depend s)" |
820 shows "acyclic (depend s)" |
821 proof - |
821 proof - |
822 from vt show ?thesis |
822 from vt show ?thesis |
823 proof(induct) |
823 proof(induct) |
824 case (vt_cons s e) |
824 case (vt_cons s e) |
825 assume ih: "acyclic (depend s)" |
825 assume ih: "acyclic (depend s)" |
826 and stp: "step s e" |
826 and stp: "step s e" |
827 and vt: "vt step s" |
827 and vt: "vt s" |
828 show ?case |
828 show ?case |
829 proof(cases e) |
829 proof(cases e) |
830 case (Create th prio) |
830 case (Create th prio) |
831 with ih |
831 with ih |
832 show ?thesis by (simp add:depend_create_unchanged) |
832 show ?thesis by (simp add:depend_create_unchanged) |
833 next |
833 next |
834 case (Exit th) |
834 case (Exit th) |
835 with ih show ?thesis by (simp add:depend_exit_unchanged) |
835 with ih show ?thesis by (simp add:depend_exit_unchanged) |
836 next |
836 next |
837 case (V th cs) |
837 case (V th cs) |
838 from V vt stp have vtt: "vt step (V th cs#s)" by auto |
838 from V vt stp have vtt: "vt (V th cs#s)" by auto |
839 from step_depend_v [OF this] |
839 from step_depend_v [OF this] |
840 have eq_de: |
840 have eq_de: |
841 "depend (e # s) = |
841 "depend (e # s) = |
842 depend s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union> |
842 depend s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union> |
843 {(Cs cs, Th th') |th'. next_th s th cs th'}" |
843 {(Cs cs, Th th') |th'. next_th s th cs th'}" |
847 have "step s (V th cs)" . |
847 have "step s (V th cs)" . |
848 thus ?thesis |
848 thus ?thesis |
849 proof(cases) |
849 proof(cases) |
850 assume "holding s th cs" |
850 assume "holding s th cs" |
851 hence th_in: "th \<in> set (wq s cs)" and |
851 hence th_in: "th \<in> set (wq s cs)" and |
852 eq_hd: "th = hd (wq s cs)" by (unfold s_holding_def, auto) |
852 eq_hd: "th = hd (wq s cs)" unfolding s_holding_def wq_def by auto |
853 then obtain rest where |
853 then obtain rest where |
854 eq_wq: "wq s cs = th#rest" |
854 eq_wq: "wq s cs = th#rest" |
855 by (cases "wq s cs", auto) |
855 by (cases "wq s cs", auto) |
856 show ?thesis |
856 show ?thesis |
857 proof(cases "rest = []") |
857 proof(cases "rest = []") |
869 hence th_d: "(Th ?th', x) \<in> ?A" by simp |
869 hence th_d: "(Th ?th', x) \<in> ?A" by simp |
870 from depend_target_th [OF this] |
870 from depend_target_th [OF this] |
871 obtain cs' where eq_x: "x = Cs cs'" by auto |
871 obtain cs' where eq_x: "x = Cs cs'" by auto |
872 with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp |
872 with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp |
873 hence wt_th': "waiting s ?th' cs'" |
873 hence wt_th': "waiting s ?th' cs'" |
874 unfolding s_depend_def s_waiting_def cs_waiting_def by simp |
874 unfolding s_depend_def s_waiting_def cs_waiting_def wq_def by simp |
875 hence "cs' = cs" |
875 hence "cs' = cs" |
876 proof(rule waiting_unique [OF vt]) |
876 proof(rule waiting_unique [OF vt]) |
877 from eq_wq wq_distinct[OF vt, of cs] |
877 from eq_wq wq_distinct[OF vt, of cs] |
878 show "waiting s ?th' cs" |
878 show "waiting s ?th' cs" |
879 apply (unfold s_waiting_def, auto) |
879 apply (unfold s_waiting_def wq_def, auto) |
880 proof - |
880 proof - |
881 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
881 assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest" |
882 and eq_wq: "wq s cs = th # rest" |
882 and eq_wq: "wq_fun (schs s) cs = th # rest" |
883 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
883 have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []" |
884 proof(rule someI2) |
884 proof(rule someI2) |
885 from wq_distinct[OF vt, of cs] and eq_wq |
885 from wq_distinct[OF vt, of cs] and eq_wq |
886 show "distinct rest \<and> set rest = set rest" by auto |
886 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
887 next |
887 next |
888 fix x assume "distinct x \<and> set x = set rest" |
888 fix x assume "distinct x \<and> set x = set rest" |
889 with False show "x \<noteq> []" by auto |
889 with False show "x \<noteq> []" by auto |
890 qed |
890 qed |
891 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
891 hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> |
892 set (SOME q. distinct q \<and> set q = set rest)" by auto |
892 set (SOME q. distinct q \<and> set q = set rest)" by auto |
893 moreover have "\<dots> = set rest" |
893 moreover have "\<dots> = set rest" |
894 proof(rule someI2) |
894 proof(rule someI2) |
895 from wq_distinct[OF vt, of cs] and eq_wq |
895 from wq_distinct[OF vt, of cs] and eq_wq |
896 show "distinct rest \<and> set rest = set rest" by auto |
896 show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto |
897 next |
897 next |
898 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
898 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
899 qed |
899 qed |
900 moreover note hd_in |
900 moreover note hd_in |
901 ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto |
901 ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto |
990 qed |
990 qed |
991 qed |
991 qed |
992 |
992 |
993 lemma finite_depend: |
993 lemma finite_depend: |
994 fixes s |
994 fixes s |
995 assumes vt: "vt step s" |
995 assumes vt: "vt s" |
996 shows "finite (depend s)" |
996 shows "finite (depend s)" |
997 proof - |
997 proof - |
998 from vt show ?thesis |
998 from vt show ?thesis |
999 proof(induct) |
999 proof(induct) |
1000 case (vt_cons s e) |
1000 case (vt_cons s e) |
1001 assume ih: "finite (depend s)" |
1001 assume ih: "finite (depend s)" |
1002 and stp: "step s e" |
1002 and stp: "step s e" |
1003 and vt: "vt step s" |
1003 and vt: "vt s" |
1004 show ?case |
1004 show ?case |
1005 proof(cases e) |
1005 proof(cases e) |
1006 case (Create th prio) |
1006 case (Create th prio) |
1007 with ih |
1007 with ih |
1008 show ?thesis by (simp add:depend_create_unchanged) |
1008 show ?thesis by (simp add:depend_create_unchanged) |
1009 next |
1009 next |
1010 case (Exit th) |
1010 case (Exit th) |
1011 with ih show ?thesis by (simp add:depend_exit_unchanged) |
1011 with ih show ?thesis by (simp add:depend_exit_unchanged) |
1012 next |
1012 next |
1013 case (V th cs) |
1013 case (V th cs) |
1014 from V vt stp have vtt: "vt step (V th cs#s)" by auto |
1014 from V vt stp have vtt: "vt (V th cs#s)" by auto |
1015 from step_depend_v [OF this] |
1015 from step_depend_v [OF this] |
1016 have eq_de: "depend (e # s) = |
1016 have eq_de: "depend (e # s) = |
1017 depend s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union> |
1017 depend s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union> |
1018 {(Cs cs, Th th') |th'. next_th s th cs th'} |
1018 {(Cs cs, Th th') |th'. next_th s th cs th'} |
1019 " |
1019 " |
1085 lemma th_chasing: "(Th th, Cs cs) \<in> depend (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> depend s" |
1085 lemma th_chasing: "(Th th, Cs cs) \<in> depend (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> depend s" |
1086 by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1086 by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1087 |
1087 |
1088 lemma wq_threads: |
1088 lemma wq_threads: |
1089 fixes s cs |
1089 fixes s cs |
1090 assumes vt: "vt step s" |
1090 assumes vt: "vt s" |
1091 and h: "th \<in> set (wq s cs)" |
1091 and h: "th \<in> set (wq s cs)" |
1092 shows "th \<in> threads s" |
1092 shows "th \<in> threads s" |
1093 proof - |
1093 proof - |
1094 from vt and h show ?thesis |
1094 from vt and h show ?thesis |
1095 proof(induct arbitrary: th cs) |
1095 proof(induct arbitrary: th cs) |
1096 case (vt_cons s e) |
1096 case (vt_cons s e) |
1097 assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s" |
1097 assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s" |
1098 and stp: "step s e" |
1098 and stp: "step s e" |
1099 and vt: "vt step s" |
1099 and vt: "vt s" |
1100 and h: "th \<in> set (wq (e # s) cs)" |
1100 and h: "th \<in> set (wq (e # s) cs)" |
1101 show ?case |
1101 show ?case |
1102 proof(cases e) |
1102 proof(cases e) |
1103 case (Create th' prio) |
1103 case (Create th' prio) |
1104 with ih h show ?thesis |
1104 with ih h show ?thesis |
1185 case vt_nil |
1185 case vt_nil |
1186 thus ?case by (auto simp:wq_def) |
1186 thus ?case by (auto simp:wq_def) |
1187 qed |
1187 qed |
1188 qed |
1188 qed |
1189 |
1189 |
1190 lemma range_in: "\<lbrakk>vt step s; (Th th) \<in> Range (depend (s::state))\<rbrakk> \<Longrightarrow> th \<in> threads s" |
1190 lemma range_in: "\<lbrakk>vt s; (Th th) \<in> Range (depend (s::state))\<rbrakk> \<Longrightarrow> th \<in> threads s" |
1191 apply(unfold s_depend_def cs_waiting_def cs_holding_def) |
1191 apply(unfold s_depend_def cs_waiting_def cs_holding_def) |
1192 by (auto intro:wq_threads) |
1192 by (auto intro:wq_threads) |
1193 |
1193 |
1194 lemma readys_v_eq: |
1194 lemma readys_v_eq: |
1195 fixes th thread cs rest |
1195 fixes th thread cs rest |
1196 assumes vt: "vt step s" |
1196 assumes vt: "vt s" |
1197 and neq_th: "th \<noteq> thread" |
1197 and neq_th: "th \<noteq> thread" |
1198 and eq_wq: "wq s cs = thread#rest" |
1198 and eq_wq: "wq s cs = thread#rest" |
1199 and not_in: "th \<notin> set rest" |
1199 and not_in: "th \<notin> set rest" |
1200 shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)" |
1200 shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)" |
1201 proof - |
1201 proof - |
1202 from prems show ?thesis |
1202 from prems show ?thesis |
1203 apply (auto simp:readys_def) |
1203 apply (auto simp:readys_def) |
1204 apply (case_tac "cs = csa", simp add:s_waiting_def) |
1204 apply(simp add:s_waiting_def[folded wq_def]) |
1205 apply (erule_tac x = csa in allE) |
1205 apply (erule_tac x = csa in allE) |
1206 apply (simp add:s_waiting_def wq_def Let_def split:if_splits) |
1206 apply (simp add:s_waiting_def wq_def Let_def split:if_splits) |
1207 apply (case_tac "csa = cs", simp) |
1207 apply (case_tac "csa = cs", simp) |
1208 apply (erule_tac x = cs in allE) |
1208 apply (erule_tac x = cs in allE) |
|
1209 apply(auto simp add: s_waiting_def[folded wq_def] Let_def split: list.splits) |
|
1210 apply(auto simp add: wq_def) |
1209 apply (auto simp:s_waiting_def wq_def Let_def split:list.splits) |
1211 apply (auto simp:s_waiting_def wq_def Let_def split:list.splits) |
1210 proof - |
1212 proof - |
1211 assume th_nin: "th \<notin> set rest" |
1213 assume th_nin: "th \<notin> set rest" |
1212 and th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)" |
1214 and th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)" |
1213 and eq_wq: "wq_fun (schs s) cs = thread # rest" |
1215 and eq_wq: "wq_fun (schs s) cs = thread # rest" |
1214 have "set (SOME q. distinct q \<and> set q = set rest) = set rest" |
1216 have "set (SOME q. distinct q \<and> set q = set rest) = set rest" |
1215 proof(rule someI2) |
1217 proof(rule someI2) |
1216 from wq_distinct[OF vt, of cs] and eq_wq[folded wq_def] |
1218 from wq_distinct[OF vt, of cs, unfolded wq_def] and eq_wq[unfolded wq_def] |
1217 show "distinct rest \<and> set rest = set rest" by auto |
1219 show "distinct rest \<and> set rest = set rest" by auto |
1218 next |
1220 next |
1219 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
1221 show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto |
1220 qed |
1222 qed |
1221 with th_nin th_in show False by auto |
1223 with th_nin th_in show False by auto |
1222 qed |
1224 qed |
1223 qed |
1225 qed |
1224 |
1226 |
1225 lemma chain_building: |
1227 lemma chain_building: |
1226 assumes vt: "vt step s" |
1228 assumes vt: "vt s" |
1227 shows "node \<in> Domain (depend s) \<longrightarrow> (\<exists> th'. th' \<in> readys s \<and> (node, Th th') \<in> (depend s)^+)" |
1229 shows "node \<in> Domain (depend s) \<longrightarrow> (\<exists> th'. th' \<in> readys s \<and> (node, Th th') \<in> (depend s)^+)" |
1228 proof - |
1230 proof - |
1229 from wf_dep_converse [OF vt] |
1231 from wf_dep_converse [OF vt] |
1230 have h: "wf ((depend s)\<inverse>)" . |
1232 have h: "wf ((depend s)\<inverse>)" . |
1231 show ?thesis |
1233 show ?thesis |
1257 from True and th'_d show ?thesis by auto |
1259 from True and th'_d show ?thesis by auto |
1258 next |
1260 next |
1259 case False |
1261 case False |
1260 from th'_d and range_in [OF vt] have "th' \<in> threads s" by auto |
1262 from th'_d and range_in [OF vt] have "th' \<in> threads s" by auto |
1261 with False have "Th th' \<in> Domain (depend s)" |
1263 with False have "Th th' \<in> Domain (depend s)" |
1262 by (auto simp:readys_def s_waiting_def s_depend_def cs_waiting_def Domain_def) |
1264 by (auto simp:readys_def wq_def s_waiting_def s_depend_def cs_waiting_def Domain_def) |
1263 from ih [OF th'_d this] |
1265 from ih [OF th'_d this] |
1264 obtain th'' where |
1266 obtain th'' where |
1265 th''_r: "th'' \<in> readys s" and |
1267 th''_r: "th'' \<in> readys s" and |
1266 th''_in: "(Th th', Th th'') \<in> (depend s)\<^sup>+" by auto |
1268 th''_in: "(Th th', Th th'') \<in> (depend s)\<^sup>+" by auto |
1267 from th'_d and th''_in |
1269 from th'_d and th''_in |
1273 qed |
1275 qed |
1274 qed |
1276 qed |
1275 |
1277 |
1276 lemma th_chain_to_ready: |
1278 lemma th_chain_to_ready: |
1277 fixes s th |
1279 fixes s th |
1278 assumes vt: "vt step s" |
1280 assumes vt: "vt s" |
1279 and th_in: "th \<in> threads s" |
1281 and th_in: "th \<in> threads s" |
1280 shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (depend s)^+)" |
1282 shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (depend s)^+)" |
1281 proof(cases "th \<in> readys s") |
1283 proof(cases "th \<in> readys s") |
1282 case True |
1284 case True |
1283 thus ?thesis by auto |
1285 thus ?thesis by auto |
1284 next |
1286 next |
1285 case False |
1287 case False |
1286 from False and th_in have "Th th \<in> Domain (depend s)" |
1288 from False and th_in have "Th th \<in> Domain (depend s)" |
1287 by (auto simp:readys_def s_waiting_def s_depend_def cs_waiting_def Domain_def) |
1289 by (auto simp:readys_def s_waiting_def s_depend_def wq_def cs_waiting_def Domain_def) |
1288 from chain_building [rule_format, OF vt this] |
1290 from chain_building [rule_format, OF vt this] |
1289 show ?thesis by auto |
1291 show ?thesis by auto |
1290 qed |
1292 qed |
1291 |
1293 |
1292 lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs" |
1294 lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs" |
1293 by (unfold s_waiting_def cs_waiting_def, auto) |
1295 by (unfold s_waiting_def cs_waiting_def wq_def, auto) |
1294 |
1296 |
1295 lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs" |
1297 lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs" |
1296 by (unfold s_holding_def cs_holding_def, simp) |
1298 by (unfold s_holding_def wq_def cs_holding_def, simp) |
1297 |
1299 |
1298 lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2" |
1300 lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2" |
1299 by (unfold s_holding_def cs_holding_def, auto) |
1301 by (unfold s_holding_def cs_holding_def, auto) |
1300 |
1302 |
1301 lemma unique_depend: "\<lbrakk>vt step s; (n, n1) \<in> depend s; (n, n2) \<in> depend s\<rbrakk> \<Longrightarrow> n1 = n2" |
1303 lemma unique_depend: "\<lbrakk>vt s; (n, n1) \<in> depend s; (n, n2) \<in> depend s\<rbrakk> \<Longrightarrow> n1 = n2" |
1302 apply(unfold s_depend_def, auto, fold waiting_eq holding_eq) |
1304 apply(unfold s_depend_def, auto, fold waiting_eq holding_eq) |
1303 by(auto elim:waiting_unique holding_unique) |
1305 by(auto elim:waiting_unique holding_unique) |
1304 |
1306 |
1305 lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r" |
1307 lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r" |
1306 by (induct rule:trancl_induct, auto) |
1308 by (induct rule:trancl_induct, auto) |
1307 |
1309 |
1308 lemma dchain_unique: |
1310 lemma dchain_unique: |
1309 assumes vt: "vt step s" |
1311 assumes vt: "vt s" |
1310 and th1_d: "(n, Th th1) \<in> (depend s)^+" |
1312 and th1_d: "(n, Th th1) \<in> (depend s)^+" |
1311 and th1_r: "th1 \<in> readys s" |
1313 and th1_r: "th1 \<in> readys s" |
1312 and th2_d: "(n, Th th2) \<in> (depend s)^+" |
1314 and th2_d: "(n, Th th2) \<in> (depend s)^+" |
1313 and th2_r: "th2 \<in> readys s" |
1315 and th2_r: "th2 \<in> readys s" |
1314 shows "th1 = th2" |
1316 shows "th1 = th2" |
1323 from trancl_split [OF this] |
1325 from trancl_split [OF this] |
1324 obtain n where dd: "(Th th1, n) \<in> depend s" by auto |
1326 obtain n where dd: "(Th th1, n) \<in> depend s" by auto |
1325 then obtain cs where eq_n: "n = Cs cs" |
1327 then obtain cs where eq_n: "n = Cs cs" |
1326 by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1328 by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1327 from dd eq_n have "th1 \<notin> readys s" |
1329 from dd eq_n have "th1 \<notin> readys s" |
1328 by (auto simp:readys_def s_depend_def s_waiting_def cs_waiting_def) |
1330 by (auto simp:readys_def s_depend_def wq_def s_waiting_def cs_waiting_def) |
1329 with th1_r show ?thesis by auto |
1331 with th1_r show ?thesis by auto |
1330 next |
1332 next |
1331 assume "(Th th2, Th th1) \<in> (depend s)\<^sup>+" |
1333 assume "(Th th2, Th th1) \<in> (depend s)\<^sup>+" |
1332 from trancl_split [OF this] |
1334 from trancl_split [OF this] |
1333 obtain n where dd: "(Th th2, n) \<in> depend s" by auto |
1335 obtain n where dd: "(Th th2, n) \<in> depend s" by auto |
1334 then obtain cs where eq_n: "n = Cs cs" |
1336 then obtain cs where eq_n: "n = Cs cs" |
1335 by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1337 by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in) |
1336 from dd eq_n have "th2 \<notin> readys s" |
1338 from dd eq_n have "th2 \<notin> readys s" |
1337 by (auto simp:readys_def s_depend_def s_waiting_def cs_waiting_def) |
1339 by (auto simp:readys_def wq_def s_depend_def s_waiting_def cs_waiting_def) |
1338 with th2_r show ?thesis by auto |
1340 with th2_r show ?thesis by auto |
1339 qed |
1341 qed |
1340 } thus ?thesis by auto |
1342 } thus ?thesis by auto |
1341 qed |
1343 qed |
1342 |
1344 |
1343 |
1345 |
1344 lemma step_holdents_p_add: |
1346 lemma step_holdents_p_add: |
1345 fixes th cs s |
1347 fixes th cs s |
1346 assumes vt: "vt step (P th cs#s)" |
1348 assumes vt: "vt (P th cs#s)" |
1347 and "wq s cs = []" |
1349 and "wq s cs = []" |
1348 shows "holdents (P th cs#s) th = holdents s th \<union> {cs}" |
1350 shows "holdents (P th cs#s) th = holdents s th \<union> {cs}" |
1349 proof - |
1351 proof - |
1350 from prems show ?thesis |
1352 from prems show ?thesis |
1351 unfolding holdents_def step_depend_p[OF vt] by auto |
1353 unfolding holdents_def step_depend_p[OF vt] by auto |
1352 qed |
1354 qed |
1353 |
1355 |
1354 lemma step_holdents_p_eq: |
1356 lemma step_holdents_p_eq: |
1355 fixes th cs s |
1357 fixes th cs s |
1356 assumes vt: "vt step (P th cs#s)" |
1358 assumes vt: "vt (P th cs#s)" |
1357 and "wq s cs \<noteq> []" |
1359 and "wq s cs \<noteq> []" |
1358 shows "holdents (P th cs#s) th = holdents s th" |
1360 shows "holdents (P th cs#s) th = holdents s th" |
1359 proof - |
1361 proof - |
1360 from prems show ?thesis |
1362 from prems show ?thesis |
1361 unfolding holdents_def step_depend_p[OF vt] by auto |
1363 unfolding holdents_def step_depend_p[OF vt] by auto |
1362 qed |
1364 qed |
1363 |
1365 |
1364 |
1366 |
1365 lemma finite_holding: |
1367 lemma finite_holding: |
1366 fixes s th cs |
1368 fixes s th cs |
1367 assumes vt: "vt step s" |
1369 assumes vt: "vt s" |
1368 shows "finite (holdents s th)" |
1370 shows "finite (holdents s th)" |
1369 proof - |
1371 proof - |
1370 let ?F = "\<lambda> (x, y). the_cs x" |
1372 let ?F = "\<lambda> (x, y). the_cs x" |
1371 from finite_depend [OF vt] |
1373 from finite_depend [OF vt] |
1372 have "finite (depend s)" . |
1374 have "finite (depend s)" . |
1383 ultimately show ?thesis by (unfold holdents_def, auto intro:finite_subset) |
1385 ultimately show ?thesis by (unfold holdents_def, auto intro:finite_subset) |
1384 qed |
1386 qed |
1385 |
1387 |
1386 lemma cntCS_v_dec: |
1388 lemma cntCS_v_dec: |
1387 fixes s thread cs |
1389 fixes s thread cs |
1388 assumes vtv: "vt step (V thread cs#s)" |
1390 assumes vtv: "vt (V thread cs#s)" |
1389 shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread" |
1391 shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread" |
1390 proof - |
1392 proof - |
1391 from step_back_step[OF vtv] |
1393 from step_back_step[OF vtv] |
1392 have cs_in: "cs \<in> holdents s thread" |
1394 have cs_in: "cs \<in> holdents s thread" |
1393 apply (cases, unfold holdents_def s_depend_def, simp) |
1395 apply (cases, unfold holdents_def s_depend_def, simp) |
1394 by (unfold cs_holding_def s_holding_def, auto) |
1396 by (unfold cs_holding_def s_holding_def wq_def, auto) |
1395 moreover have cs_not_in: |
1397 moreover have cs_not_in: |
1396 "(holdents (V thread cs#s) thread) = holdents s thread - {cs}" |
1398 "(holdents (V thread cs#s) thread) = holdents s thread - {cs}" |
1397 apply (insert wq_distinct[OF step_back_vt[OF vtv], of cs]) |
1399 apply (insert wq_distinct[OF step_back_vt[OF vtv], of cs]) |
1398 apply (unfold holdents_def, unfold step_depend_v[OF vtv], |
1400 apply (unfold holdents_def, unfold step_depend_v[OF vtv], |
1399 auto simp:next_th_def) |
1401 auto simp:next_th_def) |
1456 ultimately show ?thesis by (simp add:cntCS_def) |
1458 ultimately show ?thesis by (simp add:cntCS_def) |
1457 qed |
1459 qed |
1458 |
1460 |
1459 lemma cnp_cnv_cncs: |
1461 lemma cnp_cnv_cncs: |
1460 fixes s th |
1462 fixes s th |
1461 assumes vt: "vt step s" |
1463 assumes vt: "vt s" |
1462 shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) |
1464 shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) |
1463 then cntCS s th else cntCS s th + 1)" |
1465 then cntCS s th else cntCS s th + 1)" |
1464 proof - |
1466 proof - |
1465 from vt show ?thesis |
1467 from vt show ?thesis |
1466 proof(induct arbitrary:th) |
1468 proof(induct arbitrary:th) |
1467 case (vt_cons s e) |
1469 case (vt_cons s e) |
1468 assume vt: "vt step s" |
1470 assume vt: "vt s" |
1469 and ih: "\<And>th. cntP s th = cntV s th + |
1471 and ih: "\<And>th. cntP s th = cntV s th + |
1470 (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)" |
1472 (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)" |
1471 and stp: "step s e" |
1473 and stp: "step s e" |
1472 from stp show ?case |
1474 from stp show ?case |
1473 proof(cases) |
1475 proof(cases) |
1517 with eq_e |
1519 with eq_e |
1518 have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = |
1520 have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = |
1519 (th \<in> readys (s) \<or> th \<notin> threads (s))" |
1521 (th \<in> readys (s) \<or> th \<notin> threads (s))" |
1520 apply (simp add:threads.simps readys_def) |
1522 apply (simp add:threads.simps readys_def) |
1521 apply (subst s_waiting_def) |
1523 apply (subst s_waiting_def) |
1522 apply (subst (1 2) wq_def) |
|
1523 apply (simp add:Let_def) |
1524 apply (simp add:Let_def) |
1524 apply (subst s_waiting_def, simp) |
1525 apply (subst s_waiting_def, simp) |
1525 by (fold wq_def, simp) |
1526 done |
1526 with eq_cnp eq_cnv eq_cncs ih |
1527 with eq_cnp eq_cnv eq_cncs ih |
1527 have ?thesis by simp |
1528 have ?thesis by simp |
1528 } moreover { |
1529 } moreover { |
1529 assume eq_th: "th = thread" |
1530 assume eq_th: "th = thread" |
1530 with ih is_runing have " cntP s th = cntV s th + cntCS s th" |
1531 with ih is_runing have " cntP s th = cntV s th + cntCS s th" |
1537 next |
1538 next |
1538 case (thread_P thread cs) |
1539 case (thread_P thread cs) |
1539 assume eq_e: "e = P thread cs" |
1540 assume eq_e: "e = P thread cs" |
1540 and is_runing: "thread \<in> runing s" |
1541 and is_runing: "thread \<in> runing s" |
1541 and no_dep: "(Cs cs, Th thread) \<notin> (depend s)\<^sup>+" |
1542 and no_dep: "(Cs cs, Th thread) \<notin> (depend s)\<^sup>+" |
1542 from prems have vtp: "vt step (P thread cs#s)" by auto |
1543 from prems have vtp: "vt (P thread cs#s)" by auto |
1543 show ?thesis |
1544 show ?thesis |
1544 proof - |
1545 proof - |
1545 { have hh: "\<And> A B C. (B = C) \<Longrightarrow> (A \<and> B) = (A \<and> C)" by blast |
1546 { have hh: "\<And> A B C. (B = C) \<Longrightarrow> (A \<and> B) = (A \<and> C)" by blast |
1546 assume neq_th: "th \<noteq> thread" |
1547 assume neq_th: "th \<noteq> thread" |
1547 with eq_e |
1548 with eq_e |
1619 proof |
1620 proof |
1620 assume "th \<in> readys (e#s)" |
1621 assume "th \<in> readys (e#s)" |
1621 hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def) |
1622 hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def) |
1622 from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" . |
1623 from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" . |
1623 hence "th \<in> set (wq (e#s) cs) \<Longrightarrow> th = hd (wq (e#s) cs)" |
1624 hence "th \<in> set (wq (e#s) cs) \<Longrightarrow> th = hd (wq (e#s) cs)" |
1624 by (simp add:s_waiting_def) |
1625 by (simp add:s_waiting_def wq_def) |
1625 moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto |
1626 moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto |
1626 ultimately have "th = hd (wq (e#s) cs)" by blast |
1627 ultimately have "th = hd (wq (e#s) cs)" by blast |
1627 with eq_wq have "th = hd (wq s cs @ [th])" by simp |
1628 with eq_wq have "th = hd (wq s cs @ [th])" by simp |
1628 hence "th = hd (wq s cs)" using False by auto |
1629 hence "th = hd (wq s cs)" using False by auto |
1629 with False eq_wq wq_distinct [OF vtp, of cs] |
1630 with False eq_wq wq_distinct [OF vtp, of cs] |
1642 qed |
1643 qed |
1643 } ultimately show ?thesis by blast |
1644 } ultimately show ?thesis by blast |
1644 qed |
1645 qed |
1645 next |
1646 next |
1646 case (thread_V thread cs) |
1647 case (thread_V thread cs) |
1647 from prems have vtv: "vt step (V thread cs # s)" by auto |
1648 from prems have vtv: "vt (V thread cs # s)" by auto |
1648 assume eq_e: "e = V thread cs" |
1649 assume eq_e: "e = V thread cs" |
1649 and is_runing: "thread \<in> runing s" |
1650 and is_runing: "thread \<in> runing s" |
1650 and hold: "holding s thread cs" |
1651 and hold: "holding s thread cs" |
1651 from hold obtain rest |
1652 from hold obtain rest |
1652 where eq_wq: "wq s cs = thread # rest" |
1653 where eq_wq: "wq s cs = thread # rest" |
1653 by (case_tac "wq s cs", auto simp:s_holding_def) |
1654 by (case_tac "wq s cs", auto simp: wq_def s_holding_def) |
1654 have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e) |
1655 have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e) |
1655 have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest" |
1656 have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest" |
1656 proof(rule someI2) |
1657 proof(rule someI2) |
1657 from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq |
1658 from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq |
1658 show "distinct rest \<and> set rest = set rest" by auto |
1659 show "distinct rest \<and> set rest = set rest" by auto |
1691 assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)" |
1692 assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)" |
1692 with eq_set have "thread \<in> set rest" by simp |
1693 with eq_set have "thread \<in> set rest" by simp |
1693 with wq_distinct[OF step_back_vt[OF vtv], of cs] |
1694 with wq_distinct[OF step_back_vt[OF vtv], of cs] |
1694 and eq_wq show False by auto |
1695 and eq_wq show False by auto |
1695 qed |
1696 qed |
1696 thus ?thesis by (simp add:s_waiting_def) |
1697 thus ?thesis by (simp add:wq_def s_waiting_def) |
1697 qed |
1698 qed |
1698 } moreover { |
1699 } moreover { |
1699 assume neq_cs: "cs1 \<noteq> cs" |
1700 assume neq_cs: "cs1 \<noteq> cs" |
1700 have "\<not> waiting (e # s) thread cs1" |
1701 have "\<not> waiting (e # s) thread cs1" |
1701 proof - |
1702 proof - |
1706 from runing_ready and is_runing |
1707 from runing_ready and is_runing |
1707 have "thread \<in> readys s" by auto |
1708 have "thread \<in> readys s" by auto |
1708 thus ?thesis by (simp add:readys_def) |
1709 thus ?thesis by (simp add:readys_def) |
1709 qed |
1710 qed |
1710 ultimately show ?thesis |
1711 ultimately show ?thesis |
1711 by (auto simp:s_waiting_def eq_e) |
1712 by (auto simp:wq_def s_waiting_def eq_e) |
1712 qed |
1713 qed |
1713 } ultimately show "\<not> waiting (e # s) thread cs1" by blast |
1714 } ultimately show "\<not> waiting (e # s) thread cs1" by blast |
1714 qed |
1715 qed |
1715 ultimately show ?thesis by (simp add:readys_def) |
1716 ultimately show ?thesis by (simp add:readys_def) |
1716 qed |
1717 qed |
1776 proof - |
1777 proof - |
1777 from eq_wq and th_in |
1778 from eq_wq and th_in |
1778 have "\<not> th \<in> readys s" |
1779 have "\<not> th \<in> readys s" |
1779 apply (auto simp:readys_def s_waiting_def) |
1780 apply (auto simp:readys_def s_waiting_def) |
1780 apply (rule_tac x = cs in exI, auto) |
1781 apply (rule_tac x = cs in exI, auto) |
1781 by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto) |
1782 by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto simp add: wq_def) |
1782 moreover |
1783 moreover |
1783 from eq_wq and th_in and neq_hd |
1784 from eq_wq and th_in and neq_hd |
1784 have "\<not> (th \<in> readys (e # s))" |
1785 have "\<not> (th \<in> readys (e # s))" |
1785 apply (auto simp:readys_def s_waiting_def eq_e wq_def Let_def split:list.splits) |
1786 apply (auto simp:readys_def s_waiting_def eq_e wq_def Let_def split:list.splits) |
1786 by (rule_tac x = cs in exI, auto simp:eq_set) |
1787 by (rule_tac x = cs in exI, auto simp:eq_set) |
1929 qed |
1930 qed |
1930 qed |
1931 qed |
1931 |
1932 |
1932 lemma not_thread_cncs: |
1933 lemma not_thread_cncs: |
1933 fixes th s |
1934 fixes th s |
1934 assumes vt: "vt step s" |
1935 assumes vt: "vt s" |
1935 and not_in: "th \<notin> threads s" |
1936 and not_in: "th \<notin> threads s" |
1936 shows "cntCS s th = 0" |
1937 shows "cntCS s th = 0" |
1937 proof - |
1938 proof - |
1938 from vt not_in show ?thesis |
1939 from vt not_in show ?thesis |
1939 proof(induct arbitrary:th) |
1940 proof(induct arbitrary:th) |
1940 case (vt_cons s e th) |
1941 case (vt_cons s e th) |
1941 assume vt: "vt step s" |
1942 assume vt: "vt s" |
1942 and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0" |
1943 and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0" |
1943 and stp: "step s e" |
1944 and stp: "step s e" |
1944 and not_in: "th \<notin> threads (e # s)" |
1945 and not_in: "th \<notin> threads (e # s)" |
1945 from stp show ?case |
1946 from stp show ?case |
1946 proof(cases) |
1947 proof(cases) |
1975 qed |
1976 qed |
1976 next |
1977 next |
1977 case (thread_P thread cs) |
1978 case (thread_P thread cs) |
1978 assume eq_e: "e = P thread cs" |
1979 assume eq_e: "e = P thread cs" |
1979 and is_runing: "thread \<in> runing s" |
1980 and is_runing: "thread \<in> runing s" |
1980 from prems have vtp: "vt step (P thread cs#s)" by auto |
1981 from prems have vtp: "vt (P thread cs#s)" by auto |
1981 have neq_th: "th \<noteq> thread" |
1982 have neq_th: "th \<noteq> thread" |
1982 proof - |
1983 proof - |
1983 from not_in eq_e have "th \<notin> threads s" by simp |
1984 from not_in eq_e have "th \<notin> threads s" by simp |
1984 moreover from is_runing have "thread \<in> threads s" |
1985 moreover from is_runing have "thread \<in> threads s" |
1985 by (simp add:runing_def readys_def) |
1986 by (simp add:runing_def readys_def) |
2003 from not_in eq_e have "th \<notin> threads s" by simp |
2004 from not_in eq_e have "th \<notin> threads s" by simp |
2004 moreover from is_runing have "thread \<in> threads s" |
2005 moreover from is_runing have "thread \<in> threads s" |
2005 by (simp add:runing_def readys_def) |
2006 by (simp add:runing_def readys_def) |
2006 ultimately show ?thesis by auto |
2007 ultimately show ?thesis by auto |
2007 qed |
2008 qed |
2008 from prems have vtv: "vt step (V thread cs#s)" by auto |
2009 from prems have vtv: "vt (V thread cs#s)" by auto |
2009 from hold obtain rest |
2010 from hold obtain rest |
2010 where eq_wq: "wq s cs = thread # rest" |
2011 where eq_wq: "wq s cs = thread # rest" |
2011 by (case_tac "wq s cs", auto simp:s_holding_def) |
2012 by (case_tac "wq s cs", auto simp: wq_def s_holding_def) |
2012 from not_in eq_e eq_wq |
2013 from not_in eq_e eq_wq |
2013 have "\<not> next_th s thread cs th" |
2014 have "\<not> next_th s thread cs th" |
2014 apply (auto simp:next_th_def) |
2015 apply (auto simp:next_th_def) |
2015 proof - |
2016 proof - |
2016 assume ne: "rest \<noteq> []" |
2017 assume ne: "rest \<noteq> []" |
2053 auto simp:count_def holdents_def s_depend_def wq_def cs_holding_def) |
2054 auto simp:count_def holdents_def s_depend_def wq_def cs_holding_def) |
2054 qed |
2055 qed |
2055 qed |
2056 qed |
2056 |
2057 |
2057 lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs" |
2058 lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs" |
2058 by (auto simp:s_waiting_def cs_waiting_def) |
2059 by (auto simp:s_waiting_def cs_waiting_def wq_def) |
2059 |
2060 |
2060 lemma dm_depend_threads: |
2061 lemma dm_depend_threads: |
2061 fixes th s |
2062 fixes th s |
2062 assumes vt: "vt step s" |
2063 assumes vt: "vt s" |
2063 and in_dom: "(Th th) \<in> Domain (depend s)" |
2064 and in_dom: "(Th th) \<in> Domain (depend s)" |
2064 shows "th \<in> threads s" |
2065 shows "th \<in> threads s" |
2065 proof - |
2066 proof - |
2066 from in_dom obtain n where "(Th th, n) \<in> depend s" by auto |
2067 from in_dom obtain n where "(Th th, n) \<in> depend s" by auto |
2067 moreover from depend_target_th[OF this] obtain cs where "n = Cs cs" by auto |
2068 moreover from depend_target_th[OF this] obtain cs where "n = Cs cs" by auto |
2350 by (auto simp:cntP_def cntV_def count_def) |
2351 by (auto simp:cntP_def cntV_def count_def) |
2351 next |
2352 next |
2352 case (thread_exit thread) |
2353 case (thread_exit thread) |
2353 assume eq_e: "e = Exit thread" |
2354 assume eq_e: "e = Exit thread" |
2354 and not_holding: "holdents s thread = {}" |
2355 and not_holding: "holdents s thread = {}" |
2355 have vt_s: "vt step s" by fact |
2356 have vt_s: "vt s" by fact |
2356 from finite_holding[OF vt_s] have "finite (holdents s thread)" . |
2357 from finite_holding[OF vt_s] have "finite (holdents s thread)" . |
2357 with not_holding have "cntCS s thread = 0" by (unfold cntCS_def, auto) |
2358 with not_holding have "cntCS s thread = 0" by (unfold cntCS_def, auto) |
2358 moreover have "thread \<in> readys s" using thread_exit by (auto simp:runing_def) |
2359 moreover have "thread \<in> readys s" using thread_exit by (auto simp:runing_def) |
2359 moreover note cnp_cnv_cncs[OF vt_s, of thread] |
2360 moreover note cnp_cnv_cncs[OF vt_s, of thread] |
2360 ultimately have eq_thread: "cntP s thread = cntV s thread" by auto |
2361 ultimately have eq_thread: "cntP s thread = cntV s thread" by auto |
2406 lemma eq_depend: |
2407 lemma eq_depend: |
2407 "depend (wq s) = depend s" |
2408 "depend (wq s) = depend s" |
2408 by (unfold cs_depend_def s_depend_def, auto) |
2409 by (unfold cs_depend_def s_depend_def, auto) |
2409 |
2410 |
2410 lemma count_eq_dependents: |
2411 lemma count_eq_dependents: |
2411 assumes vt: "vt step s" |
2412 assumes vt: "vt s" |
2412 and eq_pv: "cntP s th = cntV s th" |
2413 and eq_pv: "cntP s th = cntV s th" |
2413 shows "dependents (wq s) th = {}" |
2414 shows "dependents (wq s) th = {}" |
2414 proof - |
2415 proof - |
2415 from cnp_cnv_cncs[OF vt] and eq_pv |
2416 from cnp_cnv_cncs[OF vt] and eq_pv |
2416 have "cntCS s th = 0" |
2417 have "cntCS s th = 0" |
2463 by (unfold cs_dependents_def, simp) |
2464 by (unfold cs_dependents_def, simp) |
2464 from hh [OF this] show "th1 \<in> threads s" . |
2465 from hh [OF this] show "th1 \<in> threads s" . |
2465 qed |
2466 qed |
2466 |
2467 |
2467 lemma finite_threads: |
2468 lemma finite_threads: |
2468 assumes vt: "vt step s" |
2469 assumes vt: "vt s" |
2469 shows "finite (threads s)" |
2470 shows "finite (threads s)" |
2470 proof - |
2471 proof - |
2471 from vt show ?thesis |
2472 from vt show ?thesis |
2472 proof(induct) |
2473 proof(induct) |
2473 case (vt_cons s e) |
2474 case (vt_cons s e) |
2474 assume vt: "vt step s" |
2475 assume vt: "vt s" |
2475 and step: "step s e" |
2476 and step: "step s e" |
2476 and ih: "finite (threads s)" |
2477 and ih: "finite (threads s)" |
2477 from step |
2478 from step |
2478 show ?case |
2479 show ?case |
2479 proof(cases) |
2480 proof(cases) |
2516 next |
2517 next |
2517 from fnt and seq show "finite (f ` B)" by auto |
2518 from fnt and seq show "finite (f ` B)" by auto |
2518 qed |
2519 qed |
2519 |
2520 |
2520 lemma cp_le: |
2521 lemma cp_le: |
2521 assumes vt: "vt step s" |
2522 assumes vt: "vt s" |
2522 and th_in: "th \<in> threads s" |
2523 and th_in: "th \<in> threads s" |
2523 shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)" |
2524 shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)" |
2524 proof(unfold cp_eq_cpreced cpreced_def cs_dependents_def) |
2525 proof(unfold cp_eq_cpreced cpreced_def cs_dependents_def) |
2525 show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+})) |
2526 show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+})) |
2526 \<le> Max ((\<lambda>th. preced th s) ` threads s)" |
2527 \<le> Max ((\<lambda>th. preced th s) ` threads s)" |
2539 by (unfold cs_depend_def s_depend_def, auto simp:Domain_def) |
2540 by (unfold cs_depend_def s_depend_def, auto simp:Domain_def) |
2540 qed |
2541 qed |
2541 qed |
2542 qed |
2542 |
2543 |
2543 lemma le_cp: |
2544 lemma le_cp: |
2544 assumes vt: "vt step s" |
2545 assumes vt: "vt s" |
2545 shows "preced th s \<le> cp s th" |
2546 shows "preced th s \<le> cp s th" |
2546 proof(unfold cp_eq_cpreced preced_def cpreced_def, simp) |
2547 proof(unfold cp_eq_cpreced preced_def cpreced_def, simp) |
2547 show "Prc (original_priority th s) (birthtime th s) |
2548 show "Prc (original_priority th s) (birthtime th s) |
2548 \<le> Max (insert (Prc (original_priority th s) (birthtime th s)) |
2549 \<le> Max (insert (Prc (original_priority th s) (birthtime th s)) |
2549 ((\<lambda>th. Prc (original_priority th s) (birthtime th s)) ` dependents (wq s) th))" |
2550 ((\<lambda>th. Prc (original_priority th s) (birthtime th s)) ` dependents (wq s) th))" |