author | paulson |
Fri, 21 Jul 2000 18:01:36 +0200 | |
changeset 9403 | aad13b59b8d9 |
parent 9150 | b7642408aea3 |
child 10064 | 1a77667b21ef |
permissions | -rw-r--r-- |
9027 | 1 |
(* Title: HOL/UNITY/AllocImpl |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 2000 University of Cambridge |
|
5 |
||
6 |
Implementation of a multiple-client allocator from a single-client allocator |
|
7 |
*) |
|
8 |
||
9 |
AddIs [impOfSubs subset_preserves_o]; |
|
10 |
Addsimps [funPair_o_distrib]; |
|
11 |
Addsimps [Always_INT_distrib]; |
|
12 |
Delsimps [o_apply]; |
|
13 |
||
9110 | 14 |
(*Make a locale for M: merge_spec and G: preserves (funPair merge.Out iOut)?*) |
15 |
||
9027 | 16 |
Goalw [merge_spec_def,merge_eqOut_def] |
17 |
"[| M: merge_spec; G: preserves merge.Out; G: preserves merge.iOut |] \ |
|
18 |
\ ==> M Join G : Always {s. length (merge.Out s) = length (merge.iOut s)}"; |
|
19 |
by (force_tac (claset() addDs [guaranteesD], simpset()) 1); |
|
20 |
qed "Merge_Always_Out_eq_iOut"; |
|
21 |
||
9106
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
22 |
Goalw [merge_spec_def,merge_bounded_def] |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
23 |
"[| M: merge_spec; G: preserves merge.iOut |] \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
24 |
\ ==> M Join G : Always {s. ALL elt : set (merge.iOut s). elt < Nclients}"; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
25 |
by (force_tac (claset() addDs [guaranteesD], simpset()) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
26 |
qed "Merge_Bounded"; |
9091 | 27 |
|
9106
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
28 |
Goal "[| M : merge_spec; G : preserves (funPair merge.Out iOut) |] \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
29 |
\ ==> M Join G : Always \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
30 |
\ {s. setsum (%i. bag_of (sublist (merge.Out s) \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
31 |
\ {k. k < length (iOut s) & iOut s ! k = i})) \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
32 |
\ (lessThan Nclients) = \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
33 |
\ (bag_of o merge.Out) s}"; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
34 |
by (rtac ([[Merge_Always_Out_eq_iOut, Merge_Bounded] MRS Always_Int_I, |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
35 |
UNIV_AlwaysI] MRS (Always_Compl_Un_eq RS iffD1)) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
36 |
by Auto_tac; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
37 |
by (stac (bag_of_sublist_UN_disjoint RS sym) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
38 |
by (Simp_tac 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
39 |
by (Blast_tac 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
40 |
by (asm_full_simp_tac (simpset() addsimps [set_conv_nth]) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
41 |
by (subgoal_tac |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
42 |
"(UN i:lessThan Nclients. {k. k < length (iOut x) & iOut x ! k = i}) = \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
43 |
\ lessThan (length (iOut x))" 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
44 |
by (Blast_tac 2); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
45 |
by (asm_simp_tac (simpset() addsimps [o_def]) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
46 |
qed "Merge_Bag_Follows_lemma"; |
9027 | 47 |
|
48 |
Goal "M : merge_spec \ |
|
49 |
\ ==> M : (INT i: lessThan Nclients. Increasing (sub i o merge.In)) \ |
|
50 |
\ guarantees[funPair merge.Out merge.iOut] \ |
|
51 |
\ (bag_of o merge.Out) Fols \ |
|
52 |
\ (%s. setsum (%i. (bag_of o sub i o merge.In) s) \ |
|
53 |
\ (lessThan Nclients))"; |
|
9106
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
54 |
by (rtac (Merge_Bag_Follows_lemma RS Always_Follows1 RS guaranteesI) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
55 |
by Auto_tac; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
56 |
by (rtac Follows_setsum 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
57 |
by (auto_tac (claset(), |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
58 |
simpset() addsimps [merge_spec_def,merge_follows_def, o_def])); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
59 |
by (best_tac (claset() addIs [impOfSubs (mono_bag_of RS mono_Follows_apply)] |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
60 |
addDs [guaranteesD]) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
61 |
qed "Merge_Bag_Follows"; |
9091 | 62 |
|
63 |
||
9106
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
64 |
(** Distributor **) |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
65 |
|
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
66 |
Goalw [distr_follows_def] |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
67 |
"D : distr_follows \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
68 |
\ ==> D : Increasing distr.In Int Increasing distr.iIn Int \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
69 |
\ Always {s. ALL elt : set (distr.iIn s). elt < Nclients} \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
70 |
\ guarantees[distr.Out] \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
71 |
\ (INT i : lessThan Nclients. Increasing (sub i o distr.Out))"; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
72 |
by (blast_tac (claset() addIs [guaranteesI, Follows_Increasing1] |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
73 |
addDs [guaranteesD]) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
74 |
qed "Distr_Increasing_Out"; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
75 |
|
9027 | 76 |
|
9106
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
77 |
Goal "[| G : preserves distr.Out; \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
78 |
\ D Join G : Always {s. ALL elt: set (distr.iIn s). elt < Nclients} |] \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
79 |
\ ==> D Join G : Always \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
80 |
\ {s. setsum (%i. bag_of (sublist (distr.In s) \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
81 |
\ {k. k < length (iIn s) & iIn s ! k = i})) \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
82 |
\ (lessThan Nclients) = \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
83 |
\ bag_of (sublist (distr.In s) (lessThan (length (iIn s))))}"; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
84 |
by (etac ([asm_rl, UNIV_AlwaysI] MRS (Always_Compl_Un_eq RS iffD1)) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
85 |
by Auto_tac; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
86 |
by (stac (bag_of_sublist_UN_disjoint RS sym) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
87 |
by (Simp_tac 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
88 |
by (Blast_tac 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
89 |
by (asm_full_simp_tac (simpset() addsimps [set_conv_nth]) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
90 |
by (subgoal_tac |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
91 |
"(UN i:lessThan Nclients. {k. k < length (iIn x) & iIn x ! k = i}) = \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
92 |
\ lessThan (length (iIn x))" 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
93 |
by (Blast_tac 2); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
94 |
by (Asm_simp_tac 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
95 |
qed "Distr_Bag_Follows_lemma"; |
9027 | 96 |
|
97 |
||
9106
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
98 |
Goal "D : distr_follows \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
99 |
\ ==> D : Increasing distr.In Int Increasing distr.iIn Int \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
100 |
\ Always {s. ALL elt : set (distr.iIn s). elt < Nclients} \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
101 |
\ guarantees[distr.Out] \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
102 |
\ (INT i : lessThan Nclients. \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
103 |
\ (%s. setsum (%i. (bag_of o sub i o distr.Out) s) (lessThan Nclients)) \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
104 |
\ Fols \ |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
105 |
\ (%s. bag_of (sublist (distr.In s) (lessThan (length(distr.iIn s))))))"; |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
106 |
by (rtac guaranteesI 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
107 |
by (Clarify_tac 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
108 |
by (rtac (Distr_Bag_Follows_lemma RS Always_Follows2) 1); |
9027 | 109 |
by Auto_tac; |
9106
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
110 |
by (rtac Follows_setsum 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
111 |
by (auto_tac (claset(), |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
112 |
simpset() addsimps [distr_follows_def, o_def])); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
113 |
by (best_tac (claset() addIs [impOfSubs (mono_bag_of RS mono_Follows_apply)] |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
114 |
addDs [guaranteesD]) 1); |
0fe9200f64bd
working proofs of the basic merge and distributor properties
paulson
parents:
9091
diff
changeset
|
115 |
qed "Distr_Bag_Follows"; |
9027 | 116 |
|
9110 | 117 |
|
118 |
Goal "!!f::nat=>nat. (INT i:(lessThan n). {s. f i <= g i s}) \ |
|
119 |
\ <= {s. setsum f (lessThan n) <= setsum (%i. g i s) (lessThan n)}"; |
|
120 |
by (induct_tac "n" 1); |
|
121 |
by (auto_tac (claset(), simpset() addsimps [lessThan_Suc])); |
|
122 |
qed "alloc_refinement_lemma"; |
|
123 |
||
124 |
Goal |
|
125 |
"(INT i : lessThan Nclients. Increasing (sub i o allocAsk) Int \ |
|
126 |
\ Increasing (sub i o allocRel)) \ |
|
127 |
\ Int \ |
|
128 |
\ Always {s. ALL i. i<Nclients --> \ |
|
129 |
\ (ALL elt : set ((sub i o allocAsk) s). elt <= NbT)} \ |
|
130 |
\ Int \ |
|
131 |
\ (INT i : lessThan Nclients. \ |
|
132 |
\ INT h. {s. h <= (sub i o allocGiv)s & h pfixGe (sub i o allocAsk)s} \ |
|
133 |
\ LeadsTo {s. tokens h <= (tokens o sub i o allocRel)s}) \ |
|
9150 | 134 |
\ <= \ |
9110 | 135 |
\(INT i : lessThan Nclients. Increasing (sub i o allocAsk) Int \ |
136 |
\ Increasing (sub i o allocRel)) \ |
|
137 |
\ Int \ |
|
138 |
\ Always {s. ALL i. i<Nclients --> \ |
|
139 |
\ (ALL elt : set ((sub i o allocAsk) s). elt <= NbT)} \ |
|
140 |
\ Int \ |
|
141 |
\ (INT hf. (INT i : lessThan Nclients. \ |
|
142 |
\ {s. hf i <= (sub i o allocGiv)s & hf i pfixGe (sub i o allocAsk)s}) \ |
|
143 |
\ LeadsTo {s. setsum (%i. tokens (hf i)) (lessThan Nclients) <= \ |
|
144 |
\ setsum (%i. (tokens o sub i o allocRel)s) (lessThan Nclients) })"; |
|
145 |
by (auto_tac (claset(), simpset() addsimps [ball_conj_distrib])); |
|
146 |
by (rename_tac "F hf" 1); |
|
147 |
by (rtac ([Finite_stable_completion, alloc_refinement_lemma] |
|
148 |
MRS LeadsTo_weaken_R) 1); |
|
149 |
by (Blast_tac 1); |
|
150 |
by (Blast_tac 1); |
|
151 |
by (subgoal_tac "F : Increasing (tokens o (sub i o allocRel))" 1); |
|
152 |
by (blast_tac |
|
153 |
(claset() addIs [impOfSubs (mono_tokens RS mono_Increasing_o)]) 2); |
|
154 |
by (asm_full_simp_tac (simpset() addsimps [Increasing_def, o_assoc]) 1); |
|
155 |
qed "alloc_refinement"; |
|
156 |
||
157 |