author | wenzelm |
Sat, 28 Jun 2008 21:21:13 +0200 | |
changeset 27381 | 19ae7064f00f |
parent 24893 | b8ef7afe3a6b |
child 32960 | 69916a850301 |
permissions | -rw-r--r-- |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
1 |
(* Title: ZF/UNITY/Merge |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
2 |
ID: $Id$ |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
3 |
Author: Sidi O Ehmety, Cambridge University Computer Laboratory |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
4 |
Copyright 2002 University of Cambridge |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
5 |
|
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
6 |
A multiple-client allocator from a single-client allocator: |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
7 |
Merge specification |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
8 |
*) |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
9 |
|
16417 | 10 |
theory Merge imports AllocBase Follows Guar GenPrefix begin |
14073 | 11 |
|
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
12 |
(** Merge specification (the number of inputs is Nclients) ***) |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
13 |
(** Parameter A represents the type of items to Merge **) |
14073 | 14 |
|
24893 | 15 |
definition |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
16 |
(*spec (10)*) |
24893 | 17 |
merge_increasing :: "[i, i, i] =>i" where |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
18 |
"merge_increasing(A, Out, iOut) == program guarantees |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
19 |
(lift(Out) IncreasingWrt prefix(A)/list(A)) Int |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
20 |
(lift(iOut) IncreasingWrt prefix(nat)/list(nat))" |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
21 |
|
24893 | 22 |
definition |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
23 |
(*spec (11)*) |
24893 | 24 |
merge_eq_Out :: "[i, i] =>i" where |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
25 |
"merge_eq_Out(Out, iOut) == program guarantees |
14073 | 26 |
Always({s \<in> state. length(s`Out) = length(s`iOut)})" |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
27 |
|
24893 | 28 |
definition |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
29 |
(*spec (12)*) |
24893 | 30 |
merge_bounded :: "i=>i" where |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
31 |
"merge_bounded(iOut) == program guarantees |
14073 | 32 |
Always({s \<in> state. \<forall>elt \<in> set_of_list(s`iOut). elt<Nclients})" |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
33 |
|
24893 | 34 |
definition |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
35 |
(*spec (13)*) |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
36 |
(* Parameter A represents the type of tokens *) |
24893 | 37 |
merge_follows :: "[i, i=>i, i, i] =>i" where |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
38 |
"merge_follows(A, In, Out, iOut) == |
14073 | 39 |
(\<Inter>n \<in> Nclients. lift(In(n)) IncreasingWrt prefix(A)/list(A)) |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
40 |
guarantees |
14073 | 41 |
(\<Inter>n \<in> Nclients. |
42 |
(%s. sublist(s`Out, {k \<in> nat. k < length(s`iOut) & |
|
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
43 |
nth(k, s`iOut) = n})) Fols lift(In(n)) |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
44 |
Wrt prefix(A)/list(A))" |
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
45 |
|
24893 | 46 |
definition |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
47 |
(*spec: preserves part*) |
24893 | 48 |
merge_preserves :: "[i=>i] =>i" where |
14073 | 49 |
"merge_preserves(In) == \<Inter>n \<in> nat. preserves(lift(In(n)))" |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
50 |
|
24893 | 51 |
definition |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
52 |
(* environmental constraints*) |
24893 | 53 |
merge_allowed_acts :: "[i, i] =>i" where |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
54 |
"merge_allowed_acts(Out, iOut) == |
14073 | 55 |
{F \<in> program. AllowedActs(F) = |
56 |
cons(id(state), (\<Union>G \<in> preserves(lift(Out)) \<inter> |
|
14057 | 57 |
preserves(lift(iOut)). Acts(G)))}" |
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
58 |
|
24893 | 59 |
definition |
60 |
merge_spec :: "[i, i =>i, i, i]=>i" where |
|
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
61 |
"merge_spec(A, In, Out, iOut) == |
14073 | 62 |
merge_increasing(A, Out, iOut) \<inter> merge_eq_Out(Out, iOut) \<inter> |
63 |
merge_bounded(iOut) \<inter> merge_follows(A, In, Out, iOut) |
|
64 |
\<inter> merge_allowed_acts(Out, iOut) \<inter> merge_preserves(In)" |
|
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
65 |
|
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
66 |
(** State definitions. OUTPUT variables are locals **) |
14073 | 67 |
locale merge = |
68 |
fixes In --{*merge's INPUT histories: streams to merge*} |
|
69 |
and Out --{*merge's OUTPUT history: merged items*} |
|
70 |
and iOut --{*merge's OUTPUT history: origins of merged items*} |
|
71 |
and A --{*the type of items being merged *} |
|
72 |
and M |
|
73 |
assumes var_assumes [simp]: |
|
74 |
"(\<forall>n. In(n):var) & Out \<in> var & iOut \<in> var" |
|
75 |
and all_distinct_vars: |
|
76 |
"\<forall>n. all_distinct([In(n), Out, iOut])" |
|
77 |
and type_assumes [simp]: |
|
78 |
"(\<forall>n. type_of(In(n))=list(A)) & |
|
79 |
type_of(Out)=list(A) & |
|
80 |
type_of(iOut)=list(nat)" |
|
81 |
and default_val_assumes [simp]: |
|
82 |
"(\<forall>n. default_val(In(n))=Nil) & |
|
83 |
default_val(Out)=Nil & |
|
84 |
default_val(iOut)=Nil" |
|
85 |
and merge_spec: "M \<in> merge_spec(A, In, Out, iOut)" |
|
86 |
||
87 |
||
88 |
lemma (in merge) In_value_type [TC,simp]: "s \<in> state ==> s`In(n) \<in> list(A)" |
|
89 |
apply (unfold state_def) |
|
90 |
apply (drule_tac a = "In (n)" in apply_type) |
|
91 |
apply auto |
|
92 |
done |
|
93 |
||
94 |
lemma (in merge) Out_value_type [TC,simp]: "s \<in> state ==> s`Out \<in> list(A)" |
|
95 |
apply (unfold state_def) |
|
14076 | 96 |
apply (drule_tac a = Out in apply_type, auto) |
14073 | 97 |
done |
98 |
||
99 |
lemma (in merge) iOut_value_type [TC,simp]: "s \<in> state ==> s`iOut \<in> list(nat)" |
|
100 |
apply (unfold state_def) |
|
14076 | 101 |
apply (drule_tac a = iOut in apply_type, auto) |
14073 | 102 |
done |
103 |
||
104 |
lemma (in merge) M_in_program [intro,simp]: "M \<in> program" |
|
105 |
apply (cut_tac merge_spec) |
|
106 |
apply (auto dest: guarantees_type [THEN subsetD] |
|
107 |
simp add: merge_spec_def merge_increasing_def) |
|
108 |
done |
|
109 |
||
110 |
lemma (in merge) merge_Allowed: |
|
111 |
"Allowed(M) = (preserves(lift(Out)) Int preserves(lift(iOut)))" |
|
112 |
apply (insert merge_spec preserves_type [of "lift (Out)"]) |
|
113 |
apply (auto simp add: merge_spec_def merge_allowed_acts_def Allowed_def safety_prop_Acts_iff) |
|
114 |
done |
|
115 |
||
116 |
lemma (in merge) M_ok_iff: |
|
117 |
"G \<in> program ==> |
|
118 |
M ok G <-> (G \<in> preserves(lift(Out)) & |
|
119 |
G \<in> preserves(lift(iOut)) & M \<in> Allowed(G))" |
|
120 |
apply (cut_tac merge_spec) |
|
121 |
apply (auto simp add: merge_Allowed ok_iff_Allowed) |
|
122 |
done |
|
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
123 |
|
14073 | 124 |
lemma (in merge) merge_Always_Out_eq_iOut: |
125 |
"[| G \<in> preserves(lift(Out)); G \<in> preserves(lift(iOut)); |
|
126 |
M \<in> Allowed(G) |] |
|
127 |
==> M \<squnion> G \<in> Always({s \<in> state. length(s`Out)=length(s`iOut)})" |
|
128 |
apply (frule preserves_type [THEN subsetD]) |
|
129 |
apply (subgoal_tac "G \<in> program") |
|
14076 | 130 |
prefer 2 apply assumption |
14073 | 131 |
apply (frule M_ok_iff) |
132 |
apply (cut_tac merge_spec) |
|
133 |
apply (force dest: guaranteesD simp add: merge_spec_def merge_eq_Out_def) |
|
134 |
done |
|
135 |
||
136 |
lemma (in merge) merge_Bounded: |
|
137 |
"[| G \<in> preserves(lift(iOut)); G \<in> preserves(lift(Out)); |
|
138 |
M \<in> Allowed(G) |] ==> |
|
139 |
M \<squnion> G: Always({s \<in> state. \<forall>elt \<in> set_of_list(s`iOut). elt<Nclients})" |
|
140 |
apply (frule preserves_type [THEN subsetD]) |
|
141 |
apply (frule M_ok_iff) |
|
142 |
apply (cut_tac merge_spec) |
|
143 |
apply (force dest: guaranteesD simp add: merge_spec_def merge_bounded_def) |
|
144 |
done |
|
145 |
||
146 |
lemma (in merge) merge_bag_Follows_lemma: |
|
147 |
"[| G \<in> preserves(lift(iOut)); |
|
148 |
G: preserves(lift(Out)); M \<in> Allowed(G) |] |
|
149 |
==> M \<squnion> G \<in> Always |
|
150 |
({s \<in> state. msetsum(%i. bag_of(sublist(s`Out, |
|
151 |
{k \<in> nat. k < length(s`iOut) & nth(k, s`iOut)=i})), |
|
152 |
Nclients, A) = bag_of(s`Out)})" |
|
153 |
apply (rule Always_Diff_Un_eq [THEN iffD1]) |
|
154 |
apply (rule_tac [2] state_AlwaysI [THEN Always_weaken]) |
|
14076 | 155 |
apply (rule Always_Int_I [OF merge_Always_Out_eq_iOut merge_Bounded], auto) |
14073 | 156 |
apply (subst bag_of_sublist_UN_disjoint [symmetric]) |
157 |
apply (auto simp add: nat_into_Finite set_of_list_conv_nth [OF iOut_value_type]) |
|
158 |
apply (subgoal_tac " (\<Union>i \<in> Nclients. {k \<in> nat. k < length (x`iOut) & nth (k, x`iOut) = i}) = length (x`iOut) ") |
|
159 |
apply (auto simp add: sublist_upt_eq_take [OF Out_value_type] |
|
160 |
length_type [OF iOut_value_type] |
|
161 |
take_all [OF _ Out_value_type] |
|
162 |
length_type [OF iOut_value_type]) |
|
163 |
apply (rule equalityI) |
|
14076 | 164 |
apply (blast dest: ltD, clarify) |
14073 | 165 |
apply (subgoal_tac "length (x ` iOut) \<in> nat") |
14076 | 166 |
prefer 2 apply (simp add: length_type [OF iOut_value_type]) |
14073 | 167 |
apply (subgoal_tac "xa \<in> nat") |
168 |
apply (simp_all add: Ord_mem_iff_lt) |
|
169 |
prefer 2 apply (blast intro: lt_trans) |
|
170 |
apply (drule_tac x = "nth (xa, x`iOut)" and P = "%elt. ?X (elt) --> elt<Nclients" in bspec) |
|
171 |
apply (simp add: ltI nat_into_Ord) |
|
172 |
apply (blast dest: ltD) |
|
173 |
done |
|
174 |
||
175 |
theorem (in merge) merge_bag_Follows: |
|
176 |
"M \<in> (\<Inter>n \<in> Nclients. lift(In(n)) IncreasingWrt prefix(A)/list(A)) |
|
177 |
guarantees |
|
178 |
(%s. bag_of(s`Out)) Fols |
|
179 |
(%s. msetsum(%i. bag_of(s`In(i)),Nclients, A)) Wrt MultLe(A, r)/Mult(A)" |
|
180 |
apply (cut_tac merge_spec) |
|
181 |
apply (rule merge_bag_Follows_lemma [THEN Always_Follows1, THEN guaranteesI]) |
|
14076 | 182 |
apply (simp_all add: M_ok_iff, clarify) |
14073 | 183 |
apply (rule Follows_state_ofD1 [OF Follows_msetsum_UN]) |
184 |
apply (simp_all add: nat_into_Finite bag_of_multiset [of _ A]) |
|
14076 | 185 |
apply (simp add: INT_iff merge_spec_def merge_follows_def, clarify) |
14073 | 186 |
apply (cut_tac merge_spec) |
187 |
apply (subgoal_tac "M ok G") |
|
188 |
prefer 2 apply (force intro: M_ok_iff [THEN iffD2]) |
|
14076 | 189 |
apply (drule guaranteesD, assumption) |
190 |
apply (simp add: merge_spec_def merge_follows_def, blast) |
|
14073 | 191 |
apply (simp cong add: Follows_cong |
14077 | 192 |
add: refl_prefix |
193 |
mono_bag_of [THEN subset_Follows_comp, THEN subsetD, |
|
194 |
unfolded metacomp_def]) |
|
14073 | 195 |
done |
196 |
||
14053
4daa384f4fd7
Introduction of the theories UNITY/Merge, UNITY/ClientImpl
paulson
parents:
diff
changeset
|
197 |
end |