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