author | paulson |
Thu, 11 Nov 1999 10:25:17 +0100 | |
changeset 8005 | b64d86018785 |
parent 7543 | abefbd41bd3e |
child 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)}"; |
29 |
by (rtac Always_weaken 1); |
|
7543 | 30 |
by (rtac ([IU, IV] MRS Always_Int_I) 1); |
4776 | 31 |
by Auto_tac; |
32 |
qed "mutual_exclusion"; |
|
33 |
||
34 |
||
6565 | 35 |
(*The bad invariant FAILS in V1*) |
6570 | 36 |
Goal "Mutex : Always bad_IU"; |
7403 | 37 |
by (always_tac 1); |
6615 | 38 |
by Auto_tac; |
4776 | 39 |
(*Resulting state: n=1, p=false, m=4, u=false. |
6565 | 40 |
Execution of V1 (the command of process v guarded by n=1) sets p:=true, |
4776 | 41 |
violating the invariant!*) |
42 |
(*Check that subgoals remain: proof failed.*) |
|
43 |
getgoal 1; |
|
44 |
||
45 |
||
6909 | 46 |
Goal "((#1::int) <= i & i <= #3) = (i = #1 | i = #2 | i = #3)"; |
6615 | 47 |
by (arith_tac 1); |
5596 | 48 |
qed "eq_123"; |
49 |
||
50 |
||
4776 | 51 |
(*** Progress for U ***) |
52 |
||
6565 | 53 |
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
|
54 |
by (constrains_tac 1); |
4776 | 55 |
qed "U_F0"; |
56 |
||
6565 | 57 |
Goal "Mutex : {s. m s=#1} LeadsTo {s. p s = v s & m s = #2}"; |
58 |
by (ensures_tac "U1" 1); |
|
4776 | 59 |
qed "U_F1"; |
60 |
||
6565 | 61 |
Goal "Mutex : {s. ~ p s & m s = #2} LeadsTo {s. m s = #3}"; |
6570 | 62 |
by (cut_facts_tac [IU] 1); |
6565 | 63 |
by (ensures_tac "U2" 1); |
4776 | 64 |
qed "U_F2"; |
65 |
||
6565 | 66 |
Goal "Mutex : {s. m s = #3} LeadsTo {s. p s}"; |
67 |
by (res_inst_tac [("B", "{s. m s = #4}")] LeadsTo_Trans 1); |
|
68 |
by (ensures_tac "U4" 2); |
|
69 |
by (ensures_tac "U3" 1); |
|
4776 | 70 |
qed "U_F3"; |
71 |
||
6565 | 72 |
Goal "Mutex : {s. m s = #2} LeadsTo {s. p s}"; |
5340 | 73 |
by (rtac ([LeadsTo_weaken_L, Int_lower2 RS subset_imp_LeadsTo] |
4776 | 74 |
MRS LeadsTo_Diff) 1); |
75 |
by (rtac ([U_F2, U_F3] MRS LeadsTo_Trans) 1); |
|
76 |
by (auto_tac (claset() addSEs [less_SucE], simpset())); |
|
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
77 |
val U_lemma2 = result(); |
4776 | 78 |
|
6565 | 79 |
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
|
80 |
by (rtac ([U_F1 RS LeadsTo_weaken_R, U_lemma2] MRS LeadsTo_Trans) 1); |
4776 | 81 |
by (Blast_tac 1); |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
82 |
val U_lemma1 = result(); |
4776 | 83 |
|
6565 | 84 |
Goal "Mutex : {s. #1 <= m s & m s <= #3} LeadsTo {s. p s}"; |
5596 | 85 |
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
|
86 |
U_lemma1, U_lemma2, U_F3] ) 1); |
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
87 |
val U_lemma123 = result(); |
4776 | 88 |
|
89 |
(*Misra's F4*) |
|
6565 | 90 |
Goal "Mutex : {s. u s} LeadsTo {s. p s}"; |
6570 | 91 |
by (rtac ([IU, U_lemma123] MRS Always_LeadsTo_weaken) 1); |
4776 | 92 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
93 |
qed "u_Leadsto_p"; |
4776 | 94 |
|
95 |
||
96 |
(*** Progress for V ***) |
|
97 |
||
98 |
||
6565 | 99 |
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
|
100 |
by (constrains_tac 1); |
4776 | 101 |
qed "V_F0"; |
102 |
||
6565 | 103 |
Goal "Mutex : {s. n s=#1} LeadsTo {s. p s = (~ u s) & n s = #2}"; |
104 |
by (ensures_tac "V1" 1); |
|
4776 | 105 |
qed "V_F1"; |
106 |
||
6565 | 107 |
Goal "Mutex : {s. p s & n s = #2} LeadsTo {s. n s = #3}"; |
6570 | 108 |
by (cut_facts_tac [IV] 1); |
6565 | 109 |
by (ensures_tac "V2" 1); |
4776 | 110 |
qed "V_F2"; |
111 |
||
6565 | 112 |
Goal "Mutex : {s. n s = #3} LeadsTo {s. ~ p s}"; |
113 |
by (res_inst_tac [("B", "{s. n s = #4}")] LeadsTo_Trans 1); |
|
114 |
by (ensures_tac "V4" 2); |
|
115 |
by (ensures_tac "V3" 1); |
|
4776 | 116 |
qed "V_F3"; |
117 |
||
6565 | 118 |
Goal "Mutex : {s. n s = #2} LeadsTo {s. ~ p s}"; |
5340 | 119 |
by (rtac ([LeadsTo_weaken_L, Int_lower2 RS subset_imp_LeadsTo] |
4776 | 120 |
MRS LeadsTo_Diff) 1); |
121 |
by (rtac ([V_F2, V_F3] MRS LeadsTo_Trans) 1); |
|
122 |
by (auto_tac (claset() addSEs [less_SucE], simpset())); |
|
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
123 |
val V_lemma2 = result(); |
4776 | 124 |
|
6565 | 125 |
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
|
126 |
by (rtac ([V_F1 RS LeadsTo_weaken_R, V_lemma2] MRS LeadsTo_Trans) 1); |
4776 | 127 |
by (Blast_tac 1); |
5240
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
128 |
val V_lemma1 = result(); |
4776 | 129 |
|
6565 | 130 |
Goal "Mutex : {s. #1 <= n s & n s <= #3} LeadsTo {s. ~ p s}"; |
5596 | 131 |
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
|
132 |
V_lemma1, V_lemma2, V_F3] ) 1); |
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
paulson
parents:
5232
diff
changeset
|
133 |
val V_lemma123 = result(); |
4776 | 134 |
|
135 |
||
136 |
(*Misra's F4*) |
|
6565 | 137 |
Goal "Mutex : {s. v s} LeadsTo {s. ~ p s}"; |
6570 | 138 |
by (rtac ([IV, V_lemma123] MRS Always_LeadsTo_weaken) 1); |
4776 | 139 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
140 |
qed "v_Leadsto_not_p"; |
4776 | 141 |
|
142 |
||
143 |
(** Absence of starvation **) |
|
144 |
||
145 |
(*Misra's F6*) |
|
6565 | 146 |
Goal "Mutex : {s. m s = #1} LeadsTo {s. m s = #3}"; |
6615 | 147 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
4776 | 148 |
by (rtac U_F2 2); |
149 |
by (simp_tac (simpset() addsimps [Collect_conj_eq] ) 1); |
|
150 |
by (stac Un_commute 1); |
|
6615 | 151 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
152 |
by (rtac ([v_Leadsto_not_p, U_F0] MRS PSP_Unless) 2); |
|
4776 | 153 |
by (rtac (U_F1 RS LeadsTo_weaken_R) 1); |
6615 | 154 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
155 |
qed "m1_Leadsto_3"; |
4776 | 156 |
|
157 |
(*The same for V*) |
|
6565 | 158 |
Goal "Mutex : {s. n s = #1} LeadsTo {s. n s = #3}"; |
6615 | 159 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
4776 | 160 |
by (rtac V_F2 2); |
161 |
by (simp_tac (simpset() addsimps [Collect_conj_eq] ) 1); |
|
162 |
by (stac Un_commute 1); |
|
6615 | 163 |
by (rtac (LeadsTo_cancel2 RS LeadsTo_Un_duplicate) 1); |
164 |
by (rtac ([u_Leadsto_p, V_F0] MRS PSP_Unless) 2); |
|
4776 | 165 |
by (rtac (V_F1 RS LeadsTo_weaken_R) 1); |
6615 | 166 |
by Auto_tac; |
5313
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
paulson
parents:
5277
diff
changeset
|
167 |
qed "n1_Leadsto_3"; |