4776
|
1 |
(* Title: HOL/UNITY/Token
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1998 University of Cambridge
|
|
5 |
|
|
6 |
The Token Ring.
|
|
7 |
|
|
8 |
From Misra, "A Logic for Concurrent Programming" (1994), sections 5.2 and 13.2.
|
|
9 |
*)
|
|
10 |
|
5232
|
11 |
val Token_defs = [HasTok_def, H_def, E_def, T_def];
|
4776
|
12 |
|
|
13 |
AddIffs [N_positive, skip];
|
|
14 |
|
5111
|
15 |
Goalw [HasTok_def] "[| s: HasTok i; s: HasTok j |] ==> i=j";
|
4776
|
16 |
by Auto_tac;
|
|
17 |
qed "HasToK_partition";
|
|
18 |
|
5232
|
19 |
Goalw Token_defs "(s ~: E i) = (s : H i | s : T i)";
|
4776
|
20 |
by (Simp_tac 1);
|
5232
|
21 |
by (exhaust_tac "proc s i" 1);
|
4776
|
22 |
by Auto_tac;
|
|
23 |
qed "not_E_eq";
|
|
24 |
|
|
25 |
(*This proof is in the "massaging" style and is much faster! *)
|
5253
|
26 |
Goalw [stable_def] "stable acts (Compl(E i) Un (HasTok i))";
|
4776
|
27 |
by (rtac constrains_weaken 1);
|
|
28 |
by (rtac ([[TR2, TR4] MRS constrains_Un, TR5] MRS constrains_Un) 1);
|
|
29 |
by (auto_tac (claset(), simpset() addsimps [not_E_eq]));
|
|
30 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [H_def, E_def, T_def])));
|
|
31 |
qed "token_stable";
|
|
32 |
|
|
33 |
|
|
34 |
(*** Progress under weak fairness ***)
|
|
35 |
|
5069
|
36 |
Goalw [nodeOrder_def] "wf(nodeOrder j)";
|
4776
|
37 |
by (rtac (wf_less_than RS wf_inv_image RS wf_subset) 1);
|
|
38 |
by (Blast_tac 1);
|
|
39 |
qed"wf_nodeOrder";
|
|
40 |
|
5111
|
41 |
Goal "[| m<n; Suc m ~= n |] ==> Suc(m) < n";
|
4776
|
42 |
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1);
|
|
43 |
by (blast_tac (claset() addEs [less_asym, less_SucE]) 1);
|
|
44 |
qed "Suc_lessI";
|
|
45 |
|
5069
|
46 |
Goalw [nodeOrder_def, next_def, inv_image_def]
|
5111
|
47 |
"[| i<N; j<N |] ==> ((next i, i) : nodeOrder j) = (i ~= j)";
|
4776
|
48 |
by (auto_tac (claset(),
|
|
49 |
simpset() addsimps [Suc_lessI, mod_Suc, mod_less, mod_geq]));
|
|
50 |
by (dtac sym 1);
|
|
51 |
(*The next two lines...**)
|
|
52 |
by (REPEAT (eres_inst_tac [("P", "?a<N")] rev_mp 1));
|
|
53 |
by (etac ssubst 1);
|
|
54 |
(*were with the previous version of asm_full_simp_tac...
|
|
55 |
by (rotate_tac ~1 1);
|
|
56 |
*)
|
|
57 |
by (asm_full_simp_tac (simpset() addsimps [eq_sym_conv, mod_Suc, mod_less]) 1);
|
|
58 |
by (subgoal_tac "(j + N - i) = Suc (j + N - Suc i)" 1);
|
|
59 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_Suc, less_imp_le, Suc_leI,
|
|
60 |
diff_add_assoc]) 2);
|
|
61 |
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1);
|
|
62 |
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq, mod_Suc]) 1);
|
|
63 |
(*including less_asym here would slow things down*)
|
|
64 |
by (auto_tac (claset() delrules [notI],
|
|
65 |
simpset() addsimps [diff_add_assoc2, Suc_leI,
|
|
66 |
less_imp_diff_less,
|
|
67 |
mod_less, mod_geq, nat_neq_iff]));
|
|
68 |
by (REPEAT (blast_tac (claset() addEs [less_asym]) 3));
|
|
69 |
by (asm_simp_tac (simpset() addsimps [less_imp_diff_less,
|
|
70 |
Suc_diff_n RS sym]) 1);
|
|
71 |
by (asm_simp_tac (simpset() addsimps [add_diff_less, mod_less]) 1);
|
|
72 |
by (etac subst 1);
|
|
73 |
by (asm_simp_tac (simpset() addsimps [add_diff_less]) 1);
|
|
74 |
qed "nodeOrder_eq";
|
|
75 |
|
|
76 |
|
|
77 |
(*From "A Logic for Concurrent Programming", but not used in Chapter 4.
|
|
78 |
Note the use of case_tac. Reasoning about leadsTo takes practice!*)
|
5232
|
79 |
Goal "[| i<N; j<N |] ==> \
|
5253
|
80 |
\ leadsTo acts (HasTok i) ({s. (token s, i) : nodeOrder j} Un HasTok j)";
|
4776
|
81 |
by (case_tac "i=j" 1);
|
|
82 |
by (blast_tac (claset() addIs [subset_imp_leadsTo]) 1);
|
|
83 |
by (rtac (TR7 RS leadsTo_weaken_R) 1);
|
|
84 |
by (Clarify_tac 1);
|
|
85 |
by (asm_full_simp_tac (simpset() addsimps [HasTok_def, nodeOrder_eq]) 1);
|
|
86 |
qed "TR7_nodeOrder";
|
|
87 |
|
|
88 |
|
|
89 |
(*Chapter 4 variant, the one actually used below.*)
|
5232
|
90 |
Goal "[| i<N; j<N; i~=j |] \
|
5253
|
91 |
\ ==> leadsTo acts (HasTok i) {s. (token s, i) : nodeOrder j}";
|
4776
|
92 |
by (rtac (TR7 RS leadsTo_weaken_R) 1);
|
|
93 |
by (Clarify_tac 1);
|
|
94 |
by (asm_full_simp_tac (simpset() addsimps [HasTok_def, nodeOrder_eq]) 1);
|
|
95 |
qed "TR7_aux";
|
|
96 |
|
5232
|
97 |
Goal "({s. token s < N} Int token -`` {m}) = \
|
|
98 |
\ (if m<N then token -`` {m} else {})";
|
4776
|
99 |
by Auto_tac;
|
5232
|
100 |
val token_lemma = result();
|
4776
|
101 |
|
|
102 |
|
|
103 |
(*Misra's TR9: the token reaches an arbitrary node*)
|
5253
|
104 |
Goal "j<N ==> leadsTo acts {s. token s < N} (HasTok j)";
|
4776
|
105 |
by (rtac leadsTo_weaken_R 1);
|
5232
|
106 |
by (res_inst_tac [("I", "Compl{j}"), ("f", "token"), ("B", "{}")]
|
4776
|
107 |
(wf_nodeOrder RS bounded_induct) 1);
|
5232
|
108 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [token_lemma, vimage_Diff,
|
4776
|
109 |
HasTok_def])));
|
|
110 |
by (Blast_tac 2);
|
|
111 |
by (Clarify_tac 1);
|
|
112 |
by (rtac (TR7_aux RS leadsTo_weaken) 1);
|
|
113 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [nodeOrder_def, HasTok_def])));
|
|
114 |
by (ALLGOALS Blast_tac);
|
|
115 |
qed "leadsTo_j";
|
|
116 |
|
|
117 |
(*Misra's TR8: a hungry process eventually eats*)
|
5253
|
118 |
Goal "j<N ==> leadsTo acts ({s. token s < N} Int H j) (E j)";
|
4776
|
119 |
by (rtac (leadsTo_cancel1 RS leadsTo_Un_duplicate) 1);
|
|
120 |
by (rtac TR6 2);
|
|
121 |
by (rtac leadsTo_weaken_R 1);
|
|
122 |
by (rtac ([leadsTo_j, TR3] MRS PSP) 1);
|
|
123 |
by (ALLGOALS Blast_tac);
|
5232
|
124 |
qed "token_progress";
|