1 theory PIPBasics |
1 theory PIPBasics |
2 imports PIPDefs |
2 imports PIPDefs |
3 begin |
3 begin |
4 |
4 |
5 text {* (* ddd *) |
5 text {* (* ddd *) |
|
6 |
6 Following the HOL convention of {\em definitional extension}, we have |
7 Following the HOL convention of {\em definitional extension}, we have |
7 given a concise and miniature model of PIP. To assure ourselves of |
8 given a concise and miniature model of PIP. To assure ourselves of the |
8 the correctness of this model, we are going to derive a series of |
9 correctness of this model, we are going to derive a series of expected |
9 expected properties out of it. |
10 properties out of it. |
10 |
11 |
11 This file contains the very basic properties, useful for self-assurance, |
12 This file contains the very basic properties, useful for self-assurance, |
12 as well as for deriving more advance properties concerning |
13 as well as for deriving more advance properties concerning the correctness |
13 the correctness and implementation of PIP. |
14 and implementation of PIP. *} |
14 *} |
|
15 |
15 |
16 |
16 |
17 section {* Generic auxiliary lemmas *} |
17 section {* Generic auxiliary lemmas *} |
18 |
18 |
19 lemma rel_eqI: |
19 lemma rel_eqI: |
133 text {* The following lemma is used in Correctness.thy *} |
133 text {* The following lemma is used in Correctness.thy *} |
134 lemma preced_tm_lt: "th \<in> threads s \<Longrightarrow> preced th s = Prc x y \<Longrightarrow> y < length s" |
134 lemma preced_tm_lt: "th \<in> threads s \<Longrightarrow> preced th s = Prc x y \<Longrightarrow> y < length s" |
135 by (drule_tac th_in_ne, unfold preced_def, auto intro: birth_time_lt) |
135 by (drule_tac th_in_ne, unfold preced_def, auto intro: birth_time_lt) |
136 |
136 |
137 text {* |
137 text {* |
138 The follow lemma says if a resource is waited for, it must be held |
138 |
139 by someone else. |
139 The following lemma says that if a resource is waited for, it must be held |
140 *} |
140 by someone else. *} |
|
141 |
141 lemma waiting_holding: |
142 lemma waiting_holding: |
142 assumes "waiting (s::state) th cs" |
143 assumes "waiting (s::state) th cs" |
143 obtains th' where "holding s th' cs" |
144 obtains th' where "holding s th' cs" |
144 proof - |
145 proof - |
145 from assms[unfolded s_waiting_def, folded wq_def] |
146 from assms[unfolded s_waiting_def, folded wq_def] |
148 hence "holding s th' cs" |
149 hence "holding s th' cs" |
149 by (unfold s_holding_def, fold wq_def, auto) |
150 by (unfold s_holding_def, fold wq_def, auto) |
150 from that[OF this] show ?thesis . |
151 from that[OF this] show ?thesis . |
151 qed |
152 qed |
152 |
153 |
153 text {* |
|
154 The following four lemmas relate the @{term wq} |
|
155 and non-@{term wq} versions of @{term waiting}, @{term holding}, |
|
156 @{term dependants} and @{term cp}. |
|
157 *} |
|
158 |
|
159 lemma waiting_eq: "waiting s th cs = waiting_raw (wq s) th cs" |
|
160 by (unfold s_waiting_def cs_waiting_raw wq_def, auto) |
|
161 |
|
162 lemma holding_eq: "holding (s::state) th cs = holding_raw (wq s) th cs" |
|
163 by (unfold s_holding_def wq_def cs_holding_raw, simp) |
|
164 |
|
165 lemma eq_dependants: "dependants_raw (wq s) = dependants s" |
|
166 by (simp add: s_dependants_abv wq_def) |
|
167 |
|
168 lemma cp_eq: "cp s th = cpreced (wq s) s th" |
|
169 unfolding cp_def wq_def |
|
170 apply(induct s rule: schs.induct) |
|
171 apply(simp add: Let_def cpreced_initial) |
|
172 apply(simp add: Let_def) |
|
173 apply(simp add: Let_def) |
|
174 apply(simp add: Let_def) |
|
175 apply(subst (2) schs.simps) |
|
176 apply(simp add: Let_def) |
|
177 apply(subst (2) schs.simps) |
|
178 apply(simp add: Let_def) |
|
179 done |
|
180 |
154 |
181 text {* |
155 text {* |
182 The following @{text "children_RAG_alt_def"} relates |
156 The following @{text "children_RAG_alt_def"} relates |
183 @{term children} in @{term RAG} to the notion of @{term holding}. |
157 @{term children} in @{term RAG} to the notion of @{term holding}. |
184 It is a technical lemmas used to prove the two following lemmas. |
158 It is a technical lemmas used to prove the two following lemmas. |
203 apply (unfold children_RAG_alt_def cntCS_def holdents_def) |
177 apply (unfold children_RAG_alt_def cntCS_def holdents_def) |
204 by (rule card_image[symmetric], auto simp:inj_on_def) |
178 by (rule card_image[symmetric], auto simp:inj_on_def) |
205 |
179 |
206 text {* |
180 text {* |
207 The following two lemmas show the inclusion relations |
181 The following two lemmas show the inclusion relations |
208 among three key sets, namely @{term runing}, @{term readys} |
182 among three key sets, namely @{term running}, @{term readys} |
209 and @{term threads}. |
183 and @{term threads}. |
210 *} |
184 *} |
211 lemma runing_ready: |
185 lemma running_ready: |
212 shows "runing s \<subseteq> readys s" |
186 shows "running s \<subseteq> readys s" |
213 unfolding runing_def readys_def |
187 unfolding running_def readys_def |
214 by auto |
188 by auto |
215 |
189 |
216 lemma readys_threads: |
190 lemma readys_threads: |
217 shows "readys s \<subseteq> threads s" |
191 shows "readys s \<subseteq> threads s" |
218 unfolding readys_def |
192 unfolding readys_def |
222 The following lemma says that if a thread is running, |
196 The following lemma says that if a thread is running, |
223 it must be the head of every waiting queue it is in. |
197 it must be the head of every waiting queue it is in. |
224 In other words, a running thread must have got every |
198 In other words, a running thread must have got every |
225 resource it has requested. |
199 resource it has requested. |
226 *} |
200 *} |
227 lemma runing_wqE: |
201 lemma running_wqE: |
228 assumes "th \<in> runing s" |
202 assumes "th \<in> running s" |
229 and "th \<in> set (wq s cs)" |
203 and "th \<in> set (wq s cs)" |
230 obtains rest where "wq s cs = th#rest" |
204 obtains rest where "wq s cs = th#rest" |
231 proof - |
205 proof - |
232 from assms(2) obtain th' rest where eq_wq: "wq s cs = th'#rest" |
206 from assms(2) obtain th' rest where eq_wq: "wq s cs = th'#rest" |
233 by (metis empty_iff list.exhaust list.set(1)) |
207 by (metis empty_iff list.exhaust list.set(1)) |
237 hence "th \<noteq> hd (wq s cs)" using eq_wq by auto |
211 hence "th \<noteq> hd (wq s cs)" using eq_wq by auto |
238 with assms(2) |
212 with assms(2) |
239 have "waiting s th cs" |
213 have "waiting s th cs" |
240 by (unfold s_waiting_def, fold wq_def, auto) |
214 by (unfold s_waiting_def, fold wq_def, auto) |
241 with assms show False |
215 with assms show False |
242 by (unfold runing_def readys_def, auto) |
216 by (unfold running_def readys_def, auto) |
243 qed |
217 qed |
244 with eq_wq that show ?thesis by metis |
218 with eq_wq that show ?thesis by metis |
245 qed |
219 qed |
246 |
220 |
247 text {* |
221 text {* |
389 show ?thesis using that |
363 show ?thesis using that |
390 by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", |
364 by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", |
391 insert assms V, auto simp:cntV_def) |
365 insert assms V, auto simp:cntV_def) |
392 qed (insert assms, auto simp:cntV_def) |
366 qed (insert assms, auto simp:cntV_def) |
393 |
367 |
394 lemma eq_RAG: |
|
395 "RAG_raw (wq s) = RAG s" |
|
396 by (unfold cs_RAG_raw s_RAG_def, auto) |
|
397 |
368 |
398 text {* |
369 text {* |
399 The following three lemmas shows the shape |
370 The following three lemmas shows the shape |
400 of nodes in @{term tRAG}. |
371 of nodes in @{term tRAG}. |
401 *} |
372 *} |
595 is handy to use once the abstract theory of {\em relational graph} |
566 is handy to use once the abstract theory of {\em relational graph} |
596 (and specifically {\em relational tree} and {\em relational forest}) |
567 (and specifically {\em relational tree} and {\em relational forest}) |
597 are in place. |
568 are in place. |
598 *} |
569 *} |
599 lemma cp_alt_def: |
570 lemma cp_alt_def: |
600 "cp s th = |
571 "cp s th = Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})" |
601 Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})" |
572 proof - |
602 proof - |
573 have "Max (the_preced s ` ({th} \<union> dependants s th)) = |
603 have "Max (the_preced s ` ({th} \<union> dependants_raw (wq s) th)) = |
|
604 Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})" |
574 Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})" |
605 (is "Max (_ ` ?L) = Max (_ ` ?R)") |
575 (is "Max (_ ` ?L) = Max (_ ` ?R)") |
606 proof - |
576 proof - |
607 have "?L = ?R" |
577 have "?L = ?R" |
608 by (auto dest:rtranclD simp:cs_dependants_def cs_RAG_raw s_RAG_def subtree_def) |
578 unfolding subtree_def |
|
579 apply(auto) |
|
580 apply (simp add: s_RAG_abv s_dependants_def wq_def) |
|
581 by (simp add: rtrancl_eq_or_trancl s_RAG_abv s_dependants_def wq_def) |
609 thus ?thesis by simp |
582 thus ?thesis by simp |
610 qed |
583 qed |
611 thus ?thesis by (unfold cp_eq cpreced_def, fold the_preced_def, simp) |
584 thus ?thesis |
|
585 by (metis (no_types, lifting) cp_eq cpreced_def eq_dependants |
|
586 f_image_eq the_preced_def) |
612 qed |
587 qed |
613 |
588 |
614 text {* |
589 text {* |
615 The following is another definition of @{term cp}. |
590 The following is another definition of @{term cp}. |
616 *} |
591 *} |
1058 assumes "cs' \<noteq> cs" |
1033 assumes "cs' \<noteq> cs" |
1059 shows "wq (e#s) cs' = wq s cs'" |
1034 shows "wq (e#s) cs' = wq s cs'" |
1060 using assms unfolding is_p wq_def |
1035 using assms unfolding is_p wq_def |
1061 by (auto simp:Let_def) |
1036 by (auto simp:Let_def) |
1062 |
1037 |
1063 lemma runing_th_s: |
1038 lemma running_th_s: |
1064 shows "th \<in> runing s" |
1039 shows "th \<in> running s" |
1065 proof - |
1040 proof - |
1066 from pip_e[unfolded is_p] |
1041 from pip_e[unfolded is_p] |
1067 show ?thesis by (cases, simp) |
1042 show ?thesis by (cases, simp) |
1068 qed |
1043 qed |
1069 |
1044 |
1070 lemma th_not_in_wq: |
1045 lemma th_not_in_wq: |
1071 shows "th \<notin> set (wq s cs)" |
1046 shows "th \<notin> set (wq s cs)" |
1072 proof |
1047 proof |
1073 assume otherwise: "th \<in> set (wq s cs)" |
1048 assume otherwise: "th \<in> set (wq s cs)" |
1074 from runing_wqE[OF runing_th_s this] |
1049 from running_wqE[OF running_th_s this] |
1075 obtain rest where eq_wq: "wq s cs = th#rest" by blast |
1050 obtain rest where eq_wq: "wq s cs = th#rest" by blast |
1076 with otherwise |
1051 with otherwise |
1077 have "holding s th cs" |
1052 have "holding s th cs" |
1078 by (unfold s_holding_def, fold wq_def, simp) |
1053 by (unfold s_holding_def, fold wq_def, simp) |
1079 hence cs_th_RAG: "(Cs cs, Th th) \<in> RAG s" |
1054 hence cs_th_RAG: "(Cs cs, Th th) \<in> RAG s" |
1252 th_not_in_wq: "th \<notin> set (wq s cs)" |
1227 th_not_in_wq: "th \<notin> set (wq s cs)" |
1253 proof - |
1228 proof - |
1254 from pip_e[unfolded is_exit] |
1229 from pip_e[unfolded is_exit] |
1255 show ?thesis |
1230 show ?thesis |
1256 by (cases, unfold holdents_def s_holding_def, fold wq_def, |
1231 by (cases, unfold holdents_def s_holding_def, fold wq_def, |
1257 auto elim!:runing_wqE) |
1232 auto elim!:running_wqE) |
1258 qed |
1233 qed |
1259 |
1234 |
1260 lemma wq_threads_kept: |
1235 lemma wq_threads_kept: |
1261 assumes "\<And> th' cs'. th' \<in> set (wq s cs') \<Longrightarrow> th' \<in> threads s" |
1236 assumes "\<And> th' cs'. th' \<in> set (wq s cs') \<Longrightarrow> th' \<in> threads s" |
1262 and "th' \<in> set (wq (e#s) cs')" |
1237 and "th' \<in> set (wq (e#s) cs')" |
1348 |
1323 |
1349 lemma threads_es [simp]: "threads (e#s) = threads s" |
1324 lemma threads_es [simp]: "threads (e#s) = threads s" |
1350 by (unfold is_p, simp) |
1325 by (unfold is_p, simp) |
1351 |
1326 |
1352 lemma ready_th_s: "th \<in> readys s" |
1327 lemma ready_th_s: "th \<in> readys s" |
1353 using runing_th_s |
1328 using running_th_s |
1354 by (unfold runing_def, auto) |
1329 by (unfold running_def, auto) |
1355 |
1330 |
1356 lemma live_th_s: "th \<in> threads s" |
1331 lemma live_th_s: "th \<in> threads s" |
1357 using readys_threads ready_th_s by auto |
1332 using readys_threads ready_th_s by auto |
1358 |
1333 |
1359 lemma wq_threads_kept: |
1334 lemma wq_threads_kept: |
1472 proof - |
1447 proof - |
1473 from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto |
1448 from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto |
1474 moreover then obtain cs where "n = Cs cs" by (unfold s_RAG_def, auto) |
1449 moreover then obtain cs where "n = Cs cs" by (unfold s_RAG_def, auto) |
1475 ultimately have "(Th th, Cs cs) \<in> RAG s" by simp |
1450 ultimately have "(Th th, Cs cs) \<in> RAG s" by simp |
1476 hence "th \<in> set (wq s cs)" |
1451 hence "th \<in> set (wq s cs)" |
1477 by (unfold s_RAG_def, auto simp:cs_waiting_raw) |
1452 by (unfold s_RAG_def, auto simp: waiting_raw_def) |
1478 from wq_threads [OF this] show ?thesis . |
1453 from wq_threads [OF this] show ?thesis . |
1479 qed |
1454 qed |
1480 |
1455 |
1481 lemma rg_RAG_threads: |
1456 lemma rg_RAG_threads: |
1482 assumes "(Th th) \<in> Range (RAG s)" |
1457 assumes "(Th th) \<in> Range (RAG s)" |
1483 shows "th \<in> threads s" |
1458 shows "th \<in> threads s" |
1484 using assms |
1459 using assms |
1485 by (unfold s_RAG_def cs_waiting_raw cs_holding_raw, |
1460 unfolding s_RAG_def waiting_raw_def holding_raw_def |
1486 auto intro:wq_threads) |
1461 using wq_threads by auto |
1487 |
1462 |
1488 lemma RAG_threads: |
1463 lemma RAG_threads: |
1489 assumes "(Th th) \<in> Field (RAG s)" |
1464 assumes "(Th th) \<in> Field (RAG s)" |
1490 shows "th \<in> threads s" |
1465 shows "th \<in> threads s" |
1491 using assms |
1466 using assms |
1591 lemma th'_in_inv: |
1566 lemma th'_in_inv: |
1592 assumes "th' \<in> set wq'" |
1567 assumes "th' \<in> set wq'" |
1593 shows "th' \<in> set rest" |
1568 shows "th' \<in> set rest" |
1594 using assms set_wq' by simp |
1569 using assms set_wq' by simp |
1595 |
1570 |
1596 lemma runing_th_s: |
1571 lemma running_th_s: |
1597 shows "th \<in> runing s" |
1572 shows "th \<in> running s" |
1598 proof - |
1573 proof - |
1599 from pip_e[unfolded is_v] |
1574 from pip_e[unfolded is_v] |
1600 show ?thesis by (cases, simp) |
1575 show ?thesis by (cases, simp) |
1601 qed |
1576 qed |
1602 |
1577 |
1617 next |
1592 next |
1618 case False |
1593 case False |
1619 have "wq (e#s) c = wq s c" using False |
1594 have "wq (e#s) c = wq s c" using False |
1620 by simp |
1595 by simp |
1621 hence "waiting s t c" using assms |
1596 hence "waiting s t c" using assms |
1622 by (simp add: cs_waiting_raw waiting_eq) |
1597 by (simp add: waiting_raw_def waiting_eq) |
1623 hence "t \<notin> readys s" by (unfold readys_def, auto) |
1598 hence "t \<notin> readys s" by (unfold readys_def, auto) |
1624 hence "t \<notin> runing s" using runing_ready by auto |
1599 hence "t \<notin> running s" using running_ready by auto |
1625 with runing_th_s[folded otherwise] show ?thesis by auto |
1600 with running_th_s[folded otherwise] show ?thesis by auto |
1626 qed |
1601 qed |
1627 qed |
1602 qed |
1628 |
1603 |
1629 lemma waiting_esI1: |
1604 lemma waiting_esI1: |
1630 assumes "waiting s t c" |
1605 assumes "waiting s t c" |
1632 shows "waiting (e#s) t c" |
1607 shows "waiting (e#s) t c" |
1633 proof - |
1608 proof - |
1634 have "wq (e#s) c = wq s c" |
1609 have "wq (e#s) c = wq s c" |
1635 using assms(2) by auto |
1610 using assms(2) by auto |
1636 with assms(1) show ?thesis |
1611 with assms(1) show ?thesis |
1637 unfolding cs_waiting_raw waiting_eq by auto |
1612 unfolding waiting_raw_def waiting_eq by auto |
1638 qed |
1613 qed |
1639 |
1614 |
1640 lemma holding_esI2: |
1615 lemma holding_esI2: |
1641 assumes "c \<noteq> cs" |
1616 assumes "c \<noteq> cs" |
1642 and "holding s t c" |
1617 and "holding s t c" |
1720 by (simp add: distinct_rest) |
1695 by (simp add: distinct_rest) |
1721 next |
1696 next |
1722 fix x |
1697 fix x |
1723 assume "distinct x \<and> set x = set rest" |
1698 assume "distinct x \<and> set x = set rest" |
1724 moreover have "t \<in> set rest" |
1699 moreover have "t \<in> set rest" |
1725 using assms(1) unfolding cs_waiting_raw waiting_eq wq_s_cs by auto |
1700 using assms(1) unfolding waiting_raw_def waiting_eq wq_s_cs by auto |
1726 ultimately show "t \<in> set x" by simp |
1701 ultimately show "t \<in> set x" by simp |
1727 qed |
1702 qed |
1728 moreover have "t \<noteq> hd wq'" |
1703 moreover have "t \<noteq> hd wq'" |
1729 using assms(2) taker_def by auto |
1704 using assms(2) taker_def by auto |
1730 ultimately show ?thesis |
1705 ultimately show ?thesis |
1736 obtains "c \<noteq> cs" "waiting s t c" |
1711 obtains "c \<noteq> cs" "waiting s t c" |
1737 | "c = cs" "t \<noteq> taker" "waiting s t cs" "t \<in> set rest'" |
1712 | "c = cs" "t \<noteq> taker" "waiting s t cs" "t \<in> set rest'" |
1738 proof(cases "c = cs") |
1713 proof(cases "c = cs") |
1739 case False |
1714 case False |
1740 hence "wq (e#s) c = wq s c" by auto |
1715 hence "wq (e#s) c = wq s c" by auto |
1741 with assms have "waiting s t c" unfolding cs_waiting_raw waiting_eq by auto |
1716 with assms have "waiting s t c" unfolding waiting_raw_def waiting_eq by auto |
1742 from that(1)[OF False this] show ?thesis . |
1717 from that(1)[OF False this] show ?thesis . |
1743 next |
1718 next |
1744 case True |
1719 case True |
1745 from assms[unfolded s_waiting_def True, folded wq_def, unfolded wq_es_cs] |
1720 from assms[unfolded s_waiting_def True, folded wq_def, unfolded wq_es_cs] |
1746 have "t \<noteq> hd wq'" "t \<in> set wq'" by auto |
1721 have "t \<noteq> hd wq'" "t \<in> set wq'" by auto |
1747 hence "t \<noteq> taker" by (simp add: taker_def) |
1722 hence "t \<noteq> taker" by (simp add: taker_def) |
1748 moreover hence "t \<noteq> th" using assms neq_t_th by blast |
1723 moreover hence "t \<noteq> th" using assms neq_t_th by blast |
1749 moreover have "t \<in> set rest" by (simp add: `t \<in> set wq'` th'_in_inv) |
1724 moreover have "t \<in> set rest" by (simp add: `t \<in> set wq'` th'_in_inv) |
1750 ultimately have "waiting s t cs" |
1725 ultimately have "waiting s t cs" |
1751 by (metis cs_waiting_raw insert_iff list.sel(1) s_waiting_abv set_simps(2) wq_def wq_s_cs) |
1726 by (metis waiting_raw_def insert_iff list.sel(1) s_waiting_abv set_simps(2) wq_def wq_s_cs) |
1752 show ?thesis using that(2) |
1727 show ?thesis using that(2) |
1753 using True `t \<in> set wq'` `t \<noteq> taker` `waiting s t cs` eq_wq' by auto |
1728 using True `t \<in> set wq'` `t \<noteq> taker` `waiting s t cs` eq_wq' by auto |
1754 qed |
1729 qed |
1755 |
1730 |
1756 lemma holding_esI1: |
1731 lemma holding_esI1: |
1843 lemma waiting_esI2: |
1818 lemma waiting_esI2: |
1844 assumes "waiting s t c" |
1819 assumes "waiting s t c" |
1845 shows "waiting (e#s) t c" |
1820 shows "waiting (e#s) t c" |
1846 proof - |
1821 proof - |
1847 have "c \<noteq> cs" using assms |
1822 have "c \<noteq> cs" using assms |
1848 using rest_nil wq_s_cs unfolding cs_waiting_raw waiting_eq by auto |
1823 using rest_nil wq_s_cs unfolding waiting_raw_def waiting_eq by auto |
1849 from waiting_esI1[OF assms this] |
1824 from waiting_esI1[OF assms this] |
1850 show ?thesis . |
1825 show ?thesis . |
1851 qed |
1826 qed |
1852 |
1827 |
1853 lemma waiting_esE: |
1828 lemma waiting_esE: |
1854 assumes "waiting (e#s) t c" |
1829 assumes "waiting (e#s) t c" |
1855 obtains "c \<noteq> cs" "waiting s t c" |
1830 obtains "c \<noteq> cs" "waiting s t c" |
1856 proof(cases "c = cs") |
1831 proof(cases "c = cs") |
1857 case False |
1832 case False |
1858 hence "wq (e#s) c = wq s c" by auto |
1833 hence "wq (e#s) c = wq s c" by auto |
1859 with assms have "waiting s t c" unfolding cs_waiting_raw waiting_eq by auto |
1834 with assms have "waiting s t c" unfolding waiting_raw_def waiting_eq by auto |
1860 from that(1)[OF False this] show ?thesis . |
1835 from that(1)[OF False this] show ?thesis . |
1861 next |
1836 next |
1862 case True |
1837 case True |
1863 from no_waiter_after[OF assms[unfolded True]] |
1838 from no_waiter_after[OF assms[unfolded True]] |
1864 show ?thesis by auto |
1839 show ?thesis by auto |
2075 |
2050 |
2076 lemma waiting_kept: |
2051 lemma waiting_kept: |
2077 assumes "waiting s th' cs'" |
2052 assumes "waiting s th' cs'" |
2078 shows "waiting (e#s) th' cs'" |
2053 shows "waiting (e#s) th' cs'" |
2079 using assms |
2054 using assms |
2080 unfolding th_not_in_wq waiting_eq cs_waiting_raw |
2055 unfolding th_not_in_wq waiting_eq waiting_raw_def |
2081 by (metis append_is_Nil_conv butlast_snoc hd_append2 in_set_butlastD |
2056 by (metis append_is_Nil_conv butlast_snoc hd_append2 in_set_butlastD |
2082 list.distinct(1) split_list wq_es_cs wq_neq_simp) |
2057 list.distinct(1) split_list wq_es_cs wq_neq_simp) |
2083 |
2058 |
2084 lemma holding_kept: |
2059 lemma holding_kept: |
2085 assumes "holding s th' cs'" |
2060 assumes "holding s th' cs'" |
2086 shows "holding (e#s) th' cs'" |
2061 shows "holding (e#s) th' cs'" |
2087 proof(cases "cs' = cs") |
2062 proof(cases "cs' = cs") |
2088 case False |
2063 case False |
2089 hence "wq (e#s) cs' = wq s cs'" by simp |
2064 hence "wq (e#s) cs' = wq s cs'" by simp |
2090 with assms show ?thesis unfolding cs_holding_raw holding_eq by auto |
2065 with assms show ?thesis unfolding holding_raw_def holding_eq by auto |
2091 next |
2066 next |
2092 case True |
2067 case True |
2093 from assms[unfolded s_holding_def, folded wq_def] |
2068 from assms[unfolded s_holding_def, folded wq_def] |
2094 obtain rest where eq_wq: "wq s cs' = th'#rest" |
2069 obtain rest where eq_wq: "wq s cs' = th'#rest" |
2095 by (metis empty_iff list.collapse list.set(1)) |
2070 by (metis empty_iff list.collapse list.set(1)) |
2096 hence "wq (e#s) cs' = th'#(rest@[th])" |
2071 hence "wq (e#s) cs' = th'#(rest@[th])" |
2097 by (simp add: True wq_es_cs) |
2072 by (simp add: True wq_es_cs) |
2098 thus ?thesis |
2073 thus ?thesis |
2099 by (simp add: cs_holding_raw holding_eq) |
2074 by (simp add: holding_raw_def holding_eq) |
2100 qed |
2075 qed |
2101 end |
2076 end |
2102 |
2077 |
2103 lemma (in valid_trace_p) th_not_waiting: "\<not> waiting s th c" |
2078 lemma (in valid_trace_p) th_not_waiting: "\<not> waiting s th c" |
2104 proof - |
2079 proof - |
2105 have "th \<in> readys s" |
2080 have "th \<in> readys s" |
2106 using runing_ready runing_th_s by blast |
2081 using running_ready running_th_s by blast |
2107 thus ?thesis |
2082 thus ?thesis |
2108 by (unfold readys_def, auto) |
2083 by (unfold readys_def, auto) |
2109 qed |
2084 qed |
2110 |
2085 |
2111 context valid_trace_p_h |
2086 context valid_trace_p_h |
2117 lemma holding_es_th_cs: |
2092 lemma holding_es_th_cs: |
2118 shows "holding (e#s) th cs" |
2093 shows "holding (e#s) th cs" |
2119 proof - |
2094 proof - |
2120 from wq_es_cs' |
2095 from wq_es_cs' |
2121 have "th \<in> set (wq (e#s) cs)" "th = hd (wq (e#s) cs)" by auto |
2096 have "th \<in> set (wq (e#s) cs)" "th = hd (wq (e#s) cs)" by auto |
2122 thus ?thesis unfolding cs_holding_raw holding_eq by blast |
2097 thus ?thesis unfolding holding_raw_def holding_eq by blast |
2123 qed |
2098 qed |
2124 |
2099 |
2125 lemma RAG_edge: "(Cs cs, Th th) \<in> RAG (e#s)" |
2100 lemma RAG_edge: "(Cs cs, Th th) \<in> RAG (e#s)" |
2126 by (unfold s_RAG_def, fold holding_eq, insert holding_es_th_cs, auto) |
2101 by (unfold s_RAG_def, fold holding_eq, insert holding_es_th_cs, auto) |
2127 |
2102 |
2142 have "th' = th" by simp |
2117 have "th' = th" by simp |
2143 from that(2)[OF True this] show ?thesis . |
2118 from that(2)[OF True this] show ?thesis . |
2144 next |
2119 next |
2145 case False |
2120 case False |
2146 have "holding s th' cs'" using assms |
2121 have "holding s th' cs'" using assms |
2147 using False unfolding cs_holding_raw holding_eq by auto |
2122 using False unfolding holding_raw_def holding_eq by auto |
2148 from that(1)[OF False this] show ?thesis . |
2123 from that(1)[OF False this] show ?thesis . |
2149 qed |
2124 qed |
2150 |
2125 |
2151 lemma RAG_es: "RAG (e # s) = RAG s \<union> {(Cs cs, Th th)}" (is "?L = ?R") |
2126 lemma RAG_es: "RAG (e # s) = RAG s \<union> {(Cs cs, Th th)}" (is "?L = ?R") |
2152 proof(rule rel_eqI) |
2127 proof(rule rel_eqI) |
2212 |
2187 |
2213 lemma wq_es_cs': "wq (e#s) cs = holder#waiters@[th]" |
2188 lemma wq_es_cs': "wq (e#s) cs = holder#waiters@[th]" |
2214 by (simp add: wq_es_cs wq_s_cs) |
2189 by (simp add: wq_es_cs wq_s_cs) |
2215 |
2190 |
2216 lemma waiting_es_th_cs: "waiting (e#s) th cs" |
2191 lemma waiting_es_th_cs: "waiting (e#s) th cs" |
2217 using th_not_in_wq waiting_eq wq_es_cs' wq_s_cs unfolding cs_waiting_raw by auto |
2192 using th_not_in_wq waiting_eq wq_es_cs' wq_s_cs unfolding waiting_raw_def by auto |
2218 |
2193 |
2219 lemma RAG_edge: "(Th th, Cs cs) \<in> RAG (e#s)" |
2194 lemma RAG_edge: "(Th th, Cs cs) \<in> RAG (e#s)" |
2220 by (unfold s_RAG_def, fold waiting_eq, insert waiting_es_th_cs, auto) |
2195 by (unfold s_RAG_def, fold waiting_eq, insert waiting_es_th_cs, auto) |
2221 |
2196 |
2222 lemma holding_esE: |
2197 lemma holding_esE: |
2225 using assms |
2200 using assms |
2226 proof(cases "cs' = cs") |
2201 proof(cases "cs' = cs") |
2227 case False |
2202 case False |
2228 hence "wq (e#s) cs' = wq s cs'" by simp |
2203 hence "wq (e#s) cs' = wq s cs'" by simp |
2229 with assms show ?thesis using that |
2204 with assms show ?thesis using that |
2230 unfolding cs_holding_raw holding_eq by auto |
2205 unfolding holding_raw_def holding_eq by auto |
2231 next |
2206 next |
2232 case True |
2207 case True |
2233 with assms show ?thesis |
2208 with assms show ?thesis |
2234 using s_holding_def that wq_def wq_es_cs' wq_s_cs by auto |
2209 using s_holding_def that wq_def wq_es_cs' wq_s_cs by auto |
2235 qed |
2210 qed |
2248 qed |
2223 qed |
2249 from that(1)[OF this True] show ?thesis . |
2224 from that(1)[OF this True] show ?thesis . |
2250 next |
2225 next |
2251 case False |
2226 case False |
2252 hence "th' = th \<and> cs' = cs" |
2227 hence "th' = th \<and> cs' = cs" |
2253 by (metis assms cs_waiting_raw holder_def list.sel(1) rotate1.simps(2) |
2228 by (metis assms waiting_raw_def holder_def list.sel(1) rotate1.simps(2) |
2254 set_ConsD set_rotate1 waiting_eq wq_es_cs wq_es_cs' wq_neq_simp) |
2229 set_ConsD set_rotate1 waiting_eq wq_es_cs wq_es_cs' wq_neq_simp) |
2255 with that(2) show ?thesis by metis |
2230 with that(2) show ?thesis by metis |
2256 qed |
2231 qed |
2257 |
2232 |
2258 lemma RAG_es: "RAG (e # s) = RAG s \<union> {(Th th, Cs cs)}" (is "?L = ?R") |
2233 lemma RAG_es: "RAG (e # s) = RAG s \<union> {(Th th, Cs cs)}" (is "?L = ?R") |
2359 lemma finite_RAG: |
2334 lemma finite_RAG: |
2360 shows "finite (RAG s)" |
2335 shows "finite (RAG s)" |
2361 proof(induct rule:ind) |
2336 proof(induct rule:ind) |
2362 case Nil |
2337 case Nil |
2363 show ?case |
2338 show ?case |
2364 by (auto simp: s_RAG_def cs_waiting_raw |
2339 by (auto simp: s_RAG_def waiting_raw_def |
2365 cs_holding_raw wq_def acyclic_def) |
2340 holding_raw_def wq_def acyclic_def) |
2366 next |
2341 next |
2367 case (Cons s e) |
2342 case (Cons s e) |
2368 interpret vt_e: valid_trace_e s e using Cons by simp |
2343 interpret vt_e: valid_trace_e s e using Cons by simp |
2369 show ?case |
2344 show ?case |
2370 proof(cases e) |
2345 proof(cases e) |
2792 lemma acyclic_RAG: |
2767 lemma acyclic_RAG: |
2793 shows "acyclic (RAG s)" |
2768 shows "acyclic (RAG s)" |
2794 proof(induct rule:ind) |
2769 proof(induct rule:ind) |
2795 case Nil |
2770 case Nil |
2796 show ?case |
2771 show ?case |
2797 by (auto simp: s_RAG_def cs_waiting_raw |
2772 by (auto simp: s_RAG_def waiting_raw_def |
2798 cs_holding_raw wq_def acyclic_def) |
2773 holding_raw_def wq_def acyclic_def) |
2799 next |
2774 next |
2800 case (Cons s e) |
2775 case (Cons s e) |
2801 interpret vt_e: valid_trace_e s e using Cons by simp |
2776 interpret vt_e: valid_trace_e s e using Cons by simp |
2802 show ?case |
2777 show ?case |
2803 proof(cases e) |
2778 proof(cases e) |
3082 case True |
3057 case True |
3083 thus ?thesis by auto |
3058 thus ?thesis by auto |
3084 next |
3059 next |
3085 case False |
3060 case False |
3086 from False and th_in have "Th th \<in> Domain (RAG s)" |
3061 from False and th_in have "Th th \<in> Domain (RAG s)" |
3087 by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_raw Domain_def) |
3062 by (auto simp: readys_def s_waiting_def s_RAG_def wq_def waiting_raw_def |
|
3063 Domain_def) |
3088 from chain_building [rule_format, OF this] |
3064 from chain_building [rule_format, OF this] |
3089 show ?thesis by auto |
3065 show ?thesis by auto |
3090 qed |
3066 qed |
3091 |
3067 |
3092 text {* |
3068 text {* |
3113 |
3089 |
3114 text {* |
3090 text {* |
3115 The following two lemmas shows there is at most one running thread |
3091 The following two lemmas shows there is at most one running thread |
3116 in the system. |
3092 in the system. |
3117 *} |
3093 *} |
3118 lemma runing_unique: |
3094 lemma running_unique: |
3119 assumes runing_1: "th1 \<in> runing s" |
3095 assumes running_1: "th1 \<in> running s" |
3120 and runing_2: "th2 \<in> runing s" |
3096 and running_2: "th2 \<in> running s" |
3121 shows "th1 = th2" |
3097 shows "th1 = th2" |
3122 proof - |
3098 proof - |
3123 from runing_1 and runing_2 have "cp s th1 = cp s th2" |
3099 from running_1 and running_2 have "cp s th1 = cp s th2" |
3124 unfolding runing_def by auto |
3100 unfolding running_def by auto |
3125 from this[unfolded cp_alt_def] |
3101 from this[unfolded cp_alt_def] |
3126 have eq_max: |
3102 have eq_max: |
3127 "Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th1)}) = |
3103 "Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th1)}) = |
3128 Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th2)})" |
3104 Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th2)})" |
3129 (is "Max ?L = Max ?R") . |
3105 (is "Max ?L = Max ?R") . |
3150 from h_1(1) |
3126 from h_1(1) |
3151 show "th1' \<in> threads s" |
3127 show "th1' \<in> threads s" |
3152 proof(cases rule:subtreeE) |
3128 proof(cases rule:subtreeE) |
3153 case 1 |
3129 case 1 |
3154 hence "th1' = th1" by simp |
3130 hence "th1' = th1" by simp |
3155 with runing_1 show ?thesis by (auto simp:runing_def readys_def) |
3131 with running_1 show ?thesis by (auto simp:running_def readys_def) |
3156 next |
3132 next |
3157 case 2 |
3133 case 2 |
3158 from this(2) |
3134 from this(2) |
3159 have "(Th th1', Th th1) \<in> (RAG s)^+" by (auto simp:ancestors_def) |
3135 have "(Th th1', Th th1) \<in> (RAG s)^+" by (auto simp:ancestors_def) |
3160 from tranclD[OF this] |
3136 from tranclD[OF this] |
3165 from h_2(1) |
3141 from h_2(1) |
3166 show "th2' \<in> threads s" |
3142 show "th2' \<in> threads s" |
3167 proof(cases rule:subtreeE) |
3143 proof(cases rule:subtreeE) |
3168 case 1 |
3144 case 1 |
3169 hence "th2' = th2" by simp |
3145 hence "th2' = th2" by simp |
3170 with runing_2 show ?thesis by (auto simp:runing_def readys_def) |
3146 with running_2 show ?thesis by (auto simp:running_def readys_def) |
3171 next |
3147 next |
3172 case 2 |
3148 case 2 |
3173 from this(2) |
3149 from this(2) |
3174 have "(Th th2', Th th2) \<in> (RAG s)^+" by (auto simp:ancestors_def) |
3150 have "(Th th2', Th th2) \<in> (RAG s)^+" by (auto simp:ancestors_def) |
3175 from tranclD[OF this] |
3151 from tranclD[OF this] |
3201 from rpath_plus[OF less_1(3) this] |
3177 from rpath_plus[OF less_1(3) this] |
3202 have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+" . |
3178 have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+" . |
3203 from tranclD[OF this] |
3179 from tranclD[OF this] |
3204 obtain cs where "waiting s th1 cs" |
3180 obtain cs where "waiting s th1 cs" |
3205 by (unfold s_RAG_def, fold waiting_eq, auto) |
3181 by (unfold s_RAG_def, fold waiting_eq, auto) |
3206 with runing_1 show False |
3182 with running_1 show False |
3207 by (unfold runing_def readys_def, auto) |
3183 by (unfold running_def readys_def, auto) |
3208 qed |
3184 qed |
3209 ultimately have "xs2 = xs1" by simp |
3185 ultimately have "xs2 = xs1" by simp |
3210 from rpath_dest_eq[OF rp1 rp2[unfolded this]] |
3186 from rpath_dest_eq[OF rp1 rp2[unfolded this]] |
3211 show ?thesis by simp |
3187 show ?thesis by simp |
3212 next |
3188 next |
3217 from rpath_plus[OF less_2(3) this] |
3193 from rpath_plus[OF less_2(3) this] |
3218 have "(Th th2, Th th1) \<in> (RAG s)\<^sup>+" . |
3194 have "(Th th2, Th th1) \<in> (RAG s)\<^sup>+" . |
3219 from tranclD[OF this] |
3195 from tranclD[OF this] |
3220 obtain cs where "waiting s th2 cs" |
3196 obtain cs where "waiting s th2 cs" |
3221 by (unfold s_RAG_def, fold waiting_eq, auto) |
3197 by (unfold s_RAG_def, fold waiting_eq, auto) |
3222 with runing_2 show False |
3198 with running_2 show False |
3223 by (unfold runing_def readys_def, auto) |
3199 by (unfold running_def readys_def, auto) |
3224 qed |
3200 qed |
3225 ultimately have "xs2 = xs1" by simp |
3201 ultimately have "xs2 = xs1" by simp |
3226 from rpath_dest_eq[OF rp1 rp2[unfolded this]] |
3202 from rpath_dest_eq[OF rp1 rp2[unfolded this]] |
3227 show ?thesis by simp |
3203 show ?thesis by simp |
3228 qed |
3204 qed |
3229 qed |
3205 qed |
3230 |
3206 |
3231 lemma card_runing: "card (runing s) \<le> 1" |
3207 lemma card_running: "card (running s) \<le> 1" |
3232 proof(cases "runing s = {}") |
3208 proof(cases "running s = {}") |
3233 case True |
3209 case True |
3234 thus ?thesis by auto |
3210 thus ?thesis by auto |
3235 next |
3211 next |
3236 case False |
3212 case False |
3237 then obtain th where [simp]: "th \<in> runing s" by auto |
3213 then obtain th where [simp]: "th \<in> running s" by auto |
3238 from runing_unique[OF this] |
3214 from running_unique[OF this] |
3239 have "runing s = {th}" by auto |
3215 have "running s = {th}" by auto |
3240 thus ?thesis by auto |
3216 thus ?thesis by auto |
3241 qed |
3217 qed |
3242 |
3218 |
3243 text {* |
3219 text {* |
3244 The following two lemmas show that the set of living threads |
3220 The following two lemmas show that the set of living threads |
3633 show False |
3609 show False |
3634 proof(cases) |
3610 proof(cases) |
3635 case (thread_P) |
3611 case (thread_P) |
3636 moreover have "(Cs cs, Th th) \<in> RAG s" |
3612 moreover have "(Cs cs, Th th) \<in> RAG s" |
3637 using otherwise th_not_in_wq |
3613 using otherwise th_not_in_wq |
3638 unfolding cs_holding_raw holding_eq by auto |
3614 unfolding holding_raw_def holding_eq by auto |
3639 ultimately show ?thesis by auto |
3615 ultimately show ?thesis by auto |
3640 qed |
3616 qed |
3641 qed |
3617 qed |
3642 |
3618 |
3643 lemma cntCS_es_th: "cntCS (e#s) th = cntCS s th + 1" |
3619 lemma cntCS_es_th: "cntCS (e#s) th = cntCS s th + 1" |
3817 lemma holding_th_cs_s: |
3793 lemma holding_th_cs_s: |
3818 "holding s th cs" |
3794 "holding s th cs" |
3819 by (unfold s_holding_def, fold wq_def, unfold wq_s_cs, auto) |
3795 by (unfold s_holding_def, fold wq_def, unfold wq_s_cs, auto) |
3820 |
3796 |
3821 lemma th_ready_s [simp]: "th \<in> readys s" |
3797 lemma th_ready_s [simp]: "th \<in> readys s" |
3822 using runing_th_s |
3798 using running_th_s |
3823 by (unfold runing_def readys_def, auto) |
3799 by (unfold running_def readys_def, auto) |
3824 |
3800 |
3825 lemma th_live_s [simp]: "th \<in> threads s" |
3801 lemma th_live_s [simp]: "th \<in> threads s" |
3826 using th_ready_s by (unfold readys_def, auto) |
3802 using th_ready_s by (unfold readys_def, auto) |
3827 |
3803 |
3828 lemma th_ready_es [simp]: "th \<in> readys (e#s)" |
3804 lemma th_ready_es [simp]: "th \<in> readys (e#s)" |
3829 using runing_th_s neq_t_th |
3805 using running_th_s neq_t_th |
3830 by (unfold is_v runing_def readys_def, auto) |
3806 by (unfold is_v running_def readys_def, auto) |
3831 |
3807 |
3832 lemma th_live_es [simp]: "th \<in> threads (e#s)" |
3808 lemma th_live_es [simp]: "th \<in> threads (e#s)" |
3833 using th_ready_es by (unfold readys_def, auto) |
3809 using th_ready_es by (unfold readys_def, auto) |
3834 |
3810 |
3835 lemma pvD_th_s[simp]: "pvD s th = 0" |
3811 lemma pvD_th_s[simp]: "pvD s th = 0" |
3856 |
3832 |
3857 lemma th_not_waiting: |
3833 lemma th_not_waiting: |
3858 "\<not> waiting s th c" |
3834 "\<not> waiting s th c" |
3859 proof - |
3835 proof - |
3860 have "th \<in> readys s" |
3836 have "th \<in> readys s" |
3861 using runing_ready runing_th_s by blast |
3837 using running_ready running_th_s by blast |
3862 thus ?thesis |
3838 thus ?thesis |
3863 by (unfold readys_def, auto) |
3839 by (unfold readys_def, auto) |
3864 qed |
3840 qed |
3865 |
3841 |
3866 lemma waiting_neq_th: |
3842 lemma waiting_neq_th: |
4476 |
4452 |
4477 lemma th_live_s [simp]: "th \<in> threads s" |
4453 lemma th_live_s [simp]: "th \<in> threads s" |
4478 proof - |
4454 proof - |
4479 from pip_e[unfolded is_exit] |
4455 from pip_e[unfolded is_exit] |
4480 show ?thesis |
4456 show ?thesis |
4481 by (cases, unfold runing_def readys_def, simp) |
4457 by (cases, unfold running_def readys_def, simp) |
4482 qed |
4458 qed |
4483 |
4459 |
4484 lemma th_ready_s [simp]: "th \<in> readys s" |
4460 lemma th_ready_s [simp]: "th \<in> readys s" |
4485 proof - |
4461 proof - |
4486 from pip_e[unfolded is_exit] |
4462 from pip_e[unfolded is_exit] |
4487 show ?thesis |
4463 show ?thesis |
4488 by (cases, unfold runing_def, simp) |
4464 by (cases, unfold running_def, simp) |
4489 qed |
4465 qed |
4490 |
4466 |
4491 lemma th_not_live_es [simp]: "th \<notin> threads (e#s)" |
4467 lemma th_not_live_es [simp]: "th \<notin> threads (e#s)" |
4492 by (unfold is_exit, simp) |
4468 by (unfold is_exit, simp) |
4493 |
4469 |
4623 |
4599 |
4624 lemma th_live_s [simp]: "th \<in> threads s" |
4600 lemma th_live_s [simp]: "th \<in> threads s" |
4625 proof - |
4601 proof - |
4626 from pip_e[unfolded is_set] |
4602 from pip_e[unfolded is_set] |
4627 show ?thesis |
4603 show ?thesis |
4628 by (cases, unfold runing_def readys_def, simp) |
4604 by (cases, unfold running_def readys_def, simp) |
4629 qed |
4605 qed |
4630 |
4606 |
4631 lemma th_ready_s [simp]: "th \<in> readys s" |
4607 lemma th_ready_s [simp]: "th \<in> readys s" |
4632 proof - |
4608 proof - |
4633 from pip_e[unfolded is_set] |
4609 from pip_e[unfolded is_set] |
4634 show ?thesis |
4610 show ?thesis |
4635 by (cases, unfold runing_def, simp) |
4611 by (cases, unfold running_def, simp) |
4636 qed |
4612 qed |
4637 |
4613 |
4638 lemma th_not_live_es [simp]: "th \<in> threads (e#s)" |
4614 lemma th_not_live_es [simp]: "th \<in> threads (e#s)" |
4639 by (unfold is_set, simp) |
4615 by (unfold is_set, simp) |
4640 |
4616 |
5140 proof(rule DomainE) |
5116 proof(rule DomainE) |
5141 fix b |
5117 fix b |
5142 assume "(Th th, b) \<in> RAG s" |
5118 assume "(Th th, b) \<in> RAG s" |
5143 with assms[unfolded readys_def s_waiting_def] |
5119 with assms[unfolded readys_def s_waiting_def] |
5144 show False |
5120 show False |
5145 by (cases b, auto simp:cs_RAG_raw s_RAG_abv cs_waiting_raw) |
5121 by (cases b, auto simp: RAG_raw_def s_RAG_abv waiting_raw_def) |
5146 qed |
5122 qed |
5147 qed |
5123 qed |
5148 |
5124 |
5149 lemma readys_holdents_detached: |
5125 lemma readys_holdents_detached: |
5150 assumes "th \<in> readys s" |
5126 assumes "th \<in> readys s" |