author | wenzelm |
Mon, 13 Mar 2000 13:21:39 +0100 | |
changeset 8434 | 5e4bba59bfaa |
parent 8355 | 04d0f732e24e |
permissions | -rw-r--r-- |
5111 | 1 |
(* Title: HOL/UNITY/Mutex |
4776 | 2 |
ID: $Id$ |
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1998 University of Cambridge |
|
5 |
||
6 |
Based on "A Family of 2-Process Mutual Exclusion Algorithms" by J Misra |
|
7 |
*) |
|
8 |
||
6565 | 9 |
Addsimps [Mutex_def RS def_prg_Init]; |
10 |
program_defs_ref := [Mutex_def]; |
|
4776 | 11 |
|
5426
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
paulson
parents:
5424
diff
changeset
|
12 |
Addsimps (map simp_of_act |
6565 | 13 |
[U0_def, U1_def, U2_def, U3_def, U4_def, |
14 |
V0_def, V1_def, V2_def, V3_def, V4_def]); |
|
4776 | 15 |
|
6570 | 16 |
Addsimps (map simp_of_set [IU_def, IV_def, bad_IU_def]); |
4776 | 17 |
|
5232 | 18 |
|
6570 | 19 |
Goal "Mutex : Always IU"; |
7403 | 20 |
by (always_tac 1); |
6570 | 21 |
qed "IU"; |
4776 | 22 |
|
6570 | 23 |
Goal "Mutex : Always IV"; |
7403 | 24 |
by (always_tac 1); |
6570 | 25 |
qed "IV"; |
4776 | 26 |
|
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
27 |
(*The safety property: mutual exclusion*) |
6570 | 28 |
Goal "Mutex : Always {s. ~ (m s = #3 & n s = #3)}"; |
8355 | 29 |
by (rtac ([IU, IV] MRS Always_Int_I RS Always_weaken) 1); |
4776 | 30 |
by Auto_tac; |
31 |
qed "mutual_exclusion"; |
|
32 |
||
33 |
||
6565 | 34 |
(*The bad invariant FAILS in V1*) |
6570 | 35 |
Goal "Mutex : Always bad_IU"; |
7403 | 36 |
by (always_tac 1); |
6615 | 37 |
by Auto_tac; |
4776 | 38 |
(*Resulting state: n=1, p=false, m=4, u=false. |
6565 | 39 |
Execution of V1 (the command of process v guarded by n=1) sets p:=true, |
4776 | 40 |
violating the invariant!*) |
41 |
(*Check that subgoals remain: proof failed.*) |
|
42 |
getgoal 1; |
|
43 |
||
44 |
||
6909 | 45 |
Goal "((#1::int) <= i & i <= #3) = (i = #1 | i = #2 | i = #3)"; |
6615 | 46 |
by (arith_tac 1); |
5596 | 47 |
qed "eq_123"; |
48 |
||
49 |
||
4776 | 50 |
(*** Progress for U ***) |
51 |
||
6565 | 52 |
Goalw [Unless_def] "Mutex : {s. m s=#2} Unless {s. m s=#3}"; |
5426
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
paulson
parents:
5424
diff
changeset
|
53 |
by (constrains_tac 1); |
4776 | 54 |
qed "U_F0"; |
55 |
||
6565 | 56 |
Goal "Mutex : {s. m s=#1} LeadsTo {s. p s = v s & m s = #2}"; |
57 |
by (ensures_tac "U1" 1); |
|
4776 | 58 |
qed "U_F1"; |
59 |
||
6565 | 60 |
Goal "Mutex : {s. ~ p s & m s = #2} LeadsTo {s. m s = #3}"; |
6570 | 61 |
by (cut_facts_tac [IU] 1); |
6565 | 62 |
by (ensures_tac "U2" 1); |
4776 | 63 |
qed "U_F2"; |
64 |
||
6565 | 65 |
Goal "Mutex : {s. m s = #3} LeadsTo {s. p s}"; |
66 |
by (res_inst_tac [("B", "{s. m s = #4}")] LeadsTo_Trans 1); |
|
67 |
by (ensures_tac "U4" 2); |
|
68 |
by (ensures_tac "U3" 1); |
|
4776 | 69 |
qed "U_F3"; |
70 |
||
6565 | 71 |
Goal "Mutex : {s. m s = #2} LeadsTo {s. p s}"; |
5340 | 72 |
by (rtac ([LeadsTo_weaken_L, Int_lower2 RS subset_imp_LeadsTo] |
4776 | 73 |
MRS LeadsTo_Diff) 1); |
74 |
by (rtac ([U_F2, U_F3] MRS LeadsTo_Trans) 1); |
|
75 |
by (auto_tac (claset() addSEs [less_SucE], simpset())); |
|
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
76 |
val U_lemma2 = result(); |
4776 | 77 |
|
6565 | 78 |
Goal "Mutex : {s. m s = #1} LeadsTo {s. p s}"; |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
79 |
by (rtac ([U_F1 RS LeadsTo_weaken_R, U_lemma2] MRS LeadsTo_Trans) 1); |
4776 | 80 |
by (Blast_tac 1); |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
81 |
val U_lemma1 = result(); |
4776 | 82 |
|
6565 | 83 |
Goal "Mutex : {s. #1 <= m s & m s <= #3} LeadsTo {s. p s}"; |
5596 | 84 |
by (simp_tac (simpset() addsimps [eq_123, Collect_disj_eq, LeadsTo_Un_distrib, |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
85 |
U_lemma1, U_lemma2, U_F3] ) 1); |
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
86 |
val U_lemma123 = result(); |
4776 | 87 |
|
88 |
(*Misra's F4*) |
|
6565 | 89 |
Goal "Mutex : {s. u s} LeadsTo {s. p s}"; |
6570 | 90 |
by (rtac ([IU, U_lemma123] MRS Always_LeadsTo_weaken) 1); |
4776 | 91 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
92 |
qed "u_Leadsto_p"; |
4776 | 93 |
|
94 |
||
95 |
(*** Progress for V ***) |
|
96 |
||
97 |
||
6565 | 98 |
Goalw [Unless_def] "Mutex : {s. n s=#2} Unless {s. n s=#3}"; |
5426
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
paulson
parents:
5424
diff
changeset
|
99 |
by (constrains_tac 1); |
4776 | 100 |
qed "V_F0"; |
101 |
||
6565 | 102 |
Goal "Mutex : {s. n s=#1} LeadsTo {s. p s = (~ u s) & n s = #2}"; |
103 |
by (ensures_tac "V1" 1); |
|
4776 | 104 |
qed "V_F1"; |
105 |
||
6565 | 106 |
Goal "Mutex : {s. p s & n s = #2} LeadsTo {s. n s = #3}"; |
6570 | 107 |
by (cut_facts_tac [IV] 1); |
6565 | 108 |
by (ensures_tac "V2" 1); |
4776 | 109 |
qed "V_F2"; |
110 |
||
6565 | 111 |
Goal "Mutex : {s. n s = #3} LeadsTo {s. ~ p s}"; |
112 |
by (res_inst_tac [("B", "{s. n s = #4}")] LeadsTo_Trans 1); |
|
113 |
by (ensures_tac "V4" 2); |
|
114 |
by (ensures_tac "V3" 1); |
|
4776 | 115 |
qed "V_F3"; |
116 |
||
6565 | 117 |
Goal "Mutex : {s. n s = #2} LeadsTo {s. ~ p s}"; |
5340 | 118 |
by (rtac ([LeadsTo_weaken_L, Int_lower2 RS subset_imp_LeadsTo] |
4776 | 119 |
MRS LeadsTo_Diff) 1); |
120 |
by (rtac ([V_F2, V_F3] MRS LeadsTo_Trans) 1); |
|
121 |
by (auto_tac (claset() addSEs [less_SucE], simpset())); |
|
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
122 |
val V_lemma2 = result(); |
4776 | 123 |
|
6565 | 124 |
Goal "Mutex : {s. n s = #1} LeadsTo {s. ~ p s}"; |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
125 |
by (rtac ([V_F1 RS LeadsTo_weaken_R, V_lemma2] MRS LeadsTo_Trans) 1); |
4776 | 126 |
by (Blast_tac 1); |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
127 |
val V_lemma1 = result(); |
4776 | 128 |
|
6565 | 129 |
Goal "Mutex : {s. #1 <= n s & n s <= #3} LeadsTo {s. ~ p s}"; |
5596 | 130 |
by (simp_tac (simpset() addsimps [eq_123, Collect_disj_eq, LeadsTo_Un_distrib, |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
131 |
V_lemma1, V_lemma2, V_F3] ) 1); |
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
132 |
val V_lemma123 = result(); |
4776 | 133 |
|
134 |
||
135 |
(*Misra's F4*) |
|
6565 | 136 |
Goal "Mutex : {s. v s} LeadsTo {s. ~ p s}"; |
6570 | 137 |
by (rtac ([IV, V_lemma123] MRS Always_LeadsTo_weaken) 1); |
4776 | 138 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
139 |
qed "v_Leadsto_not_p"; |
4776 | 140 |
|
141 |
||
142 |
(** Absence of starvation **) |
|
143 |
||
144 |
(*Misra's F6*) |
|
6565 | 145 |
Goal "Mutex : {s. m s = #1} LeadsTo {s. m s = #3}"; |
6615 | 146 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
4776 | 147 |
by (rtac U_F2 2); |
148 |
by (simp_tac (simpset() addsimps [Collect_conj_eq] ) 1); |
|
149 |
by (stac Un_commute 1); |
|
6615 | 150 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
151 |
by (rtac ([v_Leadsto_not_p, U_F0] MRS PSP_Unless) 2); |
|
4776 | 152 |
by (rtac (U_F1 RS LeadsTo_weaken_R) 1); |
6615 | 153 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
154 |
qed "m1_Leadsto_3"; |
4776 | 155 |
|
156 |
(*The same for V*) |
|
6565 | 157 |
Goal "Mutex : {s. n s = #1} LeadsTo {s. n s = #3}"; |
6615 | 158 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
4776 | 159 |
by (rtac V_F2 2); |
160 |
by (simp_tac (simpset() addsimps [Collect_conj_eq] ) 1); |
|
161 |
by (stac Un_commute 1); |
|
6615 | 162 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
163 |
by (rtac ([u_Leadsto_p, V_F0] MRS PSP_Unless) 2); |
|
4776 | 164 |
by (rtac (V_F1 RS LeadsTo_weaken_R) 1); |
6615 | 165 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
166 |
qed "n1_Leadsto_3"; |