author | Christian Urban <urbanc@in.tum.de> |
Thu, 29 Jun 2017 17:57:41 +0100 | |
changeset 256 | 146b4817aebd |
parent 255 | 222ed43892ea |
child 286 | 804fbb227568 |
permissions | -rw-r--r-- |
148
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
theory Sulzmann |
254 | 3 |
imports "Positions" |
148
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
begin |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
section {* Sulzmann's "Ordering" of Values *} |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
|
255 | 9 |
inductive ValOrd :: "val \<Rightarrow> val \<Rightarrow> bool" ("_ \<prec> _" [100, 100] 100) |
10 |
where |
|
11 |
MY0: "length (flat v2) < length (flat v1) \<Longrightarrow> v1 \<prec> v2" |
|
12 |
| C2: "\<lbrakk>v1 \<prec> v1'; flat (Seq v1 v2) = flat (Seq v1' v2')\<rbrakk> \<Longrightarrow> (Seq v1 v2) \<prec> (Seq v1' v2')" |
|
13 |
| C1: "\<lbrakk>v2 \<prec> v2'; flat v2 = flat v2'\<rbrakk> \<Longrightarrow> (Seq v1 v2) \<prec> (Seq v1 v2')" |
|
14 |
| A2: "flat v1 = flat v2 \<Longrightarrow> (Left v1) \<prec> (Right v2)" |
|
15 |
| A3: "\<lbrakk>v2 \<prec> v2'; flat v2 = flat v2'\<rbrakk> \<Longrightarrow> (Right v2) \<prec> (Right v2')" |
|
16 |
| A4: "\<lbrakk>v1 \<prec> v1'; flat v1 = flat v1'\<rbrakk> \<Longrightarrow> (Left v1) \<prec> (Left v1')" |
|
17 |
| K1: "flat (Stars (v#vs)) = [] \<Longrightarrow> (Stars []) \<prec> (Stars (v#vs))" |
|
18 |
| K3: "\<lbrakk>v1 \<prec> v2; flat (Stars (v1#vs1)) = flat (Stars (v2#vs2))\<rbrakk> \<Longrightarrow> (Stars (v1#vs1)) \<prec> (Stars (v2#vs2))" |
|
19 |
| K4: "\<lbrakk>(Stars vs1) \<prec> (Stars vs2); flat (Stars vs1) = flat (Stars vs2)\<rbrakk> \<Longrightarrow> (Stars (v#vs1)) \<prec> (Stars (v#vs2))" |
|
20 |
||
21 |
||
22 |
(* |
|
245 | 23 |
inductive ValOrd :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<preceq>_ _" [100, 100, 100] 100) |
24 |
where |
|
25 |
C2: "v1 \<preceq>r1 v1' \<Longrightarrow> (Seq v1 v2) \<preceq>(SEQ r1 r2) (Seq v1' v2')" |
|
26 |
| C1: "v2 \<preceq>r2 v2' \<Longrightarrow> (Seq v1 v2) \<preceq>(SEQ r1 r2) (Seq v1 v2')" |
|
27 |
| A1: "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) \<preceq>(ALT r1 r2) (Left v1)" |
|
28 |
| A2: "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) \<preceq>(ALT r1 r2) (Right v2)" |
|
29 |
| A3: "v2 \<preceq>r2 v2' \<Longrightarrow> (Right v2) \<preceq>(ALT r1 r2) (Right v2')" |
|
30 |
| A4: "v1 \<preceq>r1 v1' \<Longrightarrow> (Left v1) \<preceq>(ALT r1 r2) (Left v1')" |
|
31 |
| K1: "flat (Stars (v # vs)) = [] \<Longrightarrow> (Stars []) \<preceq>(STAR r) (Stars (v # vs))" |
|
32 |
| K2: "flat (Stars (v # vs)) \<noteq> [] \<Longrightarrow> (Stars (v # vs)) \<preceq>(STAR r) (Stars [])" |
|
33 |
| K3: "v1 \<preceq>r v2 \<Longrightarrow> (Stars (v1 # vs1)) \<preceq>(STAR r) (Stars (v2 # vs2))" |
|
34 |
| K4: "(Stars vs1) \<preceq>(STAR r) (Stars vs2) \<Longrightarrow> (Stars (v # vs1)) \<preceq>(STAR r) (Stars (v # vs2))" |
|
255 | 35 |
*) |
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
36 |
(*| MY1: "Void \<preceq>ONE Void" |
245 | 37 |
| MY2: "(Char c) \<preceq>(CHAR c) (Char c)" |
38 |
| MY3: "(Stars []) \<preceq>(STAR r) (Stars [])" |
|
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
39 |
*) |
245 | 40 |
|
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
41 |
(* |
245 | 42 |
lemma ValOrd_refl: |
43 |
assumes "\<turnstile> v : r" |
|
44 |
shows "v \<preceq>r v" |
|
45 |
using assms |
|
46 |
apply(induct r rule: Prf.induct) |
|
47 |
apply(rule ValOrd.intros) |
|
48 |
apply(simp) |
|
49 |
apply(rule ValOrd.intros) |
|
50 |
apply(simp) |
|
51 |
apply(rule ValOrd.intros) |
|
52 |
apply(simp) |
|
53 |
apply(rule ValOrd.intros) |
|
54 |
apply(rule ValOrd.intros) |
|
55 |
apply(rule ValOrd.intros) |
|
56 |
apply(rule ValOrd.intros) |
|
57 |
apply(simp) |
|
58 |
done |
|
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
59 |
*) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
60 |
|
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
61 |
lemma ValOrd_irrefl: |
255 | 62 |
assumes "\<turnstile> v : r" "v \<prec> v" |
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
63 |
shows "False" |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
64 |
using assms |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
65 |
apply(induct v r rule: Prf.induct) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
66 |
apply(erule ValOrd.cases) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
67 |
apply(simp_all) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
68 |
apply(erule ValOrd.cases) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
69 |
apply(simp_all) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
70 |
apply(erule ValOrd.cases) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
71 |
apply(simp_all) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
72 |
apply(erule ValOrd.cases) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
73 |
apply(simp_all) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
74 |
apply(erule ValOrd.cases) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
75 |
apply(simp_all) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
76 |
apply(erule ValOrd.cases) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
77 |
apply(simp_all) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
78 |
apply(erule ValOrd.cases) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
79 |
apply(simp_all) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
80 |
done |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
81 |
|
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
82 |
lemma prefix_sprefix: |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
83 |
shows "xs \<sqsubseteq>pre ys \<longleftrightarrow> (xs = ys \<or> xs \<sqsubset>spre ys)" |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
84 |
apply(auto simp add: sprefix_list_def prefix_list_def) |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
85 |
done |
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
86 |
|
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
87 |
|
245 | 88 |
|
89 |
lemma Posix_CPT2: |
|
255 | 90 |
assumes "v1 \<prec> v2" |
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
91 |
shows "v1 :\<sqsubset>val v2" |
245 | 92 |
using assms |
255 | 93 |
apply(induct v1 v2 arbitrary: rule: ValOrd.induct) |
254 | 94 |
apply(rule val_ord_shorterI) |
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
95 |
apply(simp) |
254 | 96 |
apply(rule val_ord_SeqI1) |
248
b90ff5abb437
added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents:
247
diff
changeset
|
97 |
apply(simp) |
245 | 98 |
apply(simp) |
255 | 99 |
apply(rule val_ord_SeqI2) |
100 |
apply(simp) |
|
101 |
apply(simp) |
|
102 |
apply(simp add: val_ord_ex_def) |
|
103 |
apply(rule_tac x="[0]" in exI) |
|
104 |
apply(auto simp add: val_ord_def Pos_empty pflat_len_simps)[1] |
|
105 |
apply(smt inlen_bigger) |
|
106 |
apply(rule val_ord_RightI) |
|
107 |
apply(simp) |
|
108 |
apply(simp) |
|
109 |
apply(rule val_ord_LeftI) |
|
110 |
apply(simp) |
|
111 |
apply(simp) |
|
112 |
defer |
|
113 |
apply(rule val_ord_StarsI) |
|
114 |
apply(simp) |
|
115 |
apply(simp) |
|
116 |
apply(rule val_ord_StarsI2) |
|
117 |
apply(simp) |
|
118 |
apply(simp) |
|
119 |
oops |
|
120 |
||
256 | 121 |
lemma QQ: |
122 |
shows "x \<le> (y::nat) \<longleftrightarrow> x = y \<or> x < y" |
|
123 |
by auto |
|
124 |
||
255 | 125 |
lemma Posix_CPT2: |
126 |
assumes "v1 :\<sqsubset>val v2" "v1 \<in> CPTpre r s" "v2 \<in> CPTpre r s" |
|
127 |
shows "v1 \<prec> v2" |
|
128 |
using assms |
|
129 |
apply(induct r arbitrary: v1 v2 s) |
|
130 |
apply(auto simp add: CPTpre_def)[1] |
|
131 |
apply(erule CPrf.cases) |
|
132 |
apply(simp_all)[7] |
|
133 |
apply(auto simp add: CPTpre_def)[1] |
|
134 |
apply(erule CPrf.cases) |
|
135 |
apply(simp_all)[7] |
|
136 |
apply(auto simp add: CPTpre_def)[1] |
|
137 |
apply(erule CPrf.cases) |
|
138 |
apply(simp_all)[7] |
|
139 |
apply(simp add: val_ord_ex_def) |
|
140 |
apply(auto simp add: val_ord_def)[1] |
|
141 |
apply(auto simp add: CPTpre_def)[1] |
|
142 |
apply(erule CPrf.cases) |
|
143 |
apply(simp_all)[7] |
|
144 |
apply(erule CPrf.cases) |
|
145 |
apply(simp_all)[7] |
|
146 |
apply(auto simp add: val_ord_ex_def val_ord_def)[1] |
|
147 |
(* SEQ case *) |
|
148 |
apply(subst (asm) (5) CPTpre_def) |
|
149 |
apply(subst (asm) (5) CPTpre_def) |
|
150 |
apply(auto)[1] |
|
151 |
apply(erule CPrf.cases) |
|
152 |
apply(simp_all)[7] |
|
153 |
apply(erule CPrf.cases) |
|
154 |
apply(simp_all)[7] |
|
155 |
apply(clarify) |
|
256 | 156 |
apply(frule val_ord_shorterE) |
157 |
apply(subst (asm) QQ) |
|
158 |
apply(erule disjE) |
|
255 | 159 |
apply(drule val_ord_SeqE) |
160 |
apply(erule disjE) |
|
161 |
apply(drule_tac x="v1a" in meta_spec) |
|
256 | 162 |
apply(rotate_tac 8) |
255 | 163 |
apply(drule_tac x="v1b" in meta_spec) |
164 |
apply(drule_tac x="flat v1a @ flat v2a @ s'" in meta_spec) |
|
165 |
apply(simp) |
|
166 |
apply(drule meta_mp) |
|
167 |
apply(auto simp add: CPTpre_def)[1] |
|
168 |
apply(drule meta_mp) |
|
169 |
apply(auto simp add: CPTpre_def)[1] |
|
256 | 170 |
apply(rule ValOrd.intros(2)) |
171 |
apply(assumption) |
|
172 |
apply(frule val_ord_shorterE) |
|
173 |
apply(subst (asm) append_eq_append_conv_if) |
|
174 |
apply(simp) |
|
175 |
apply (metis append_assoc append_eq_append_conv_if length_append) |
|
176 |
||
177 |
||
178 |
thm le |
|
179 |
apply(clarify) |
|
255 | 180 |
apply(rule ValOrd.intros) |
256 | 181 |
apply(simp) |
182 |
||
255 | 183 |
apply(subst (asm) (3) CPTpre_def) |
184 |
apply(subst (asm) (3) CPTpre_def) |
|
185 |
apply(auto)[1] |
|
186 |
apply(drule_tac meta_mp) |
|
187 |
apply(auto simp add: CPTpre_def)[1] |
|
188 |
apply(erule CPrf.cases) |
|
189 |
apply(simp_all)[7] |
|
190 |
apply(erule CPrf.cases) |
|
191 |
apply(simp_all)[7] |
|
192 |
apply(clarify) |
|
193 |
apply(drule val_ord_SeqE) |
|
194 |
apply(erule disjE) |
|
195 |
apply(simp add: append_eq_append_conv2) |
|
196 |
apply(auto) |
|
197 |
prefer 2 |
|
198 |
apply(rule ValOrd.intros(2)) |
|
199 |
prefer 2 |
|
200 |
apply(simp) |
|
201 |
thm ValOrd.intros |
|
202 |
apply(case_tac "flat v1b = flat v1a") |
|
203 |
apply(rule ValOrd.intros) |
|
204 |
apply(simp) |
|
205 |
apply(simp) |
|
206 |
||
207 |
||
245 | 208 |
|
209 |
||
210 |
lemma Posix_CPT: |
|
211 |
assumes "v1 :\<sqsubset>val v2" "v1 \<in> CPT r s" "v2 \<in> CPT r s" |
|
212 |
shows "v1 \<preceq>r v2" |
|
213 |
using assms |
|
214 |
apply(induct r arbitrary: v1 v2 s rule: rexp.induct) |
|
215 |
apply(simp add: CPT_def) |
|
216 |
apply(clarify) |
|
217 |
apply(erule CPrf.cases) |
|
218 |
apply(simp_all) |
|
219 |
apply(simp add: CPT_def) |
|
220 |
apply(clarify) |
|
221 |
apply(erule CPrf.cases) |
|
222 |
apply(simp_all) |
|
223 |
apply(erule CPrf.cases) |
|
224 |
apply(simp_all) |
|
225 |
apply(rule ValOrd.intros) |
|
226 |
apply(simp add: CPT_def) |
|
227 |
apply(clarify) |
|
228 |
apply(erule CPrf.cases) |
|
229 |
apply(simp_all) |
|
230 |
apply(erule CPrf.cases) |
|
231 |
apply(simp_all) |
|
232 |
apply(rule ValOrd.intros) |
|
233 |
(*SEQ case *) |
|
234 |
apply(simp add: CPT_def) |
|
235 |
apply(clarify) |
|
236 |
apply(erule CPrf.cases) |
|
237 |
apply(simp_all) |
|
238 |
apply(clarify) |
|
239 |
apply(erule CPrf.cases) |
|
240 |
apply(simp_all) |
|
241 |
apply(clarify) |
|
242 |
thm val_ord_SEQ |
|
243 |
apply(drule_tac r="r1a" in val_ord_SEQ) |
|
244 |
apply(simp) |
|
245 |
using Prf_CPrf apply blast |
|
246 |
using Prf_CPrf apply blast |
|
247 |
apply(erule disjE) |
|
248 |
apply(rule C2) |
|
249 |
prefer 2 |
|
250 |
apply(simp) |
|
251 |
apply(rule C1) |
|
252 |
apply blast |
|
253 |
||
254 |
apply(simp add: append_eq_append_conv2) |
|
255 |
apply(clarify) |
|
256 |
apply(auto)[1] |
|
257 |
apply(drule_tac x="v1a" in meta_spec) |
|
258 |
apply(rotate_tac 8) |
|
259 |
apply(drule_tac x="v1b" in meta_spec) |
|
260 |
apply(rotate_tac 8) |
|
261 |
apply(simp) |
|
262 |
||
263 |
(* HERE *) |
|
264 |
apply(subst (asm) (3) val_ord_ex_def) |
|
265 |
apply(clarify) |
|
266 |
apply(subst (asm) val_ord_def) |
|
267 |
apply(clarify) |
|
268 |
apply(rule ValOrd.intros) |
|
269 |
||
270 |
||
271 |
apply(simp add: val_ord_ex_def) |
|
272 |
oops |
|
273 |
||
274 |
||
275 |
lemma ValOrd_trans: |
|
276 |
assumes "x \<preceq>r y" "y \<preceq>r z" |
|
277 |
and "x \<in> CPT r s" "y \<in> CPT r s" "z \<in> CPT r s" |
|
278 |
shows "x \<preceq>r z" |
|
279 |
using assms |
|
280 |
apply(induct x r y arbitrary: s z rule: ValOrd.induct) |
|
281 |
apply(rotate_tac 2) |
|
282 |
apply(erule ValOrd.cases) |
|
283 |
apply(simp_all)[13] |
|
284 |
apply(rule ValOrd.intros) |
|
285 |
apply(drule_tac x="s" in meta_spec) |
|
286 |
apply(drule_tac x="v1'a" in meta_spec) |
|
287 |
apply(drule_tac meta_mp) |
|
288 |
apply(simp) |
|
289 |
apply(drule_tac meta_mp) |
|
290 |
apply(simp add: CPT_def) |
|
291 |
oops |
|
292 |
||
293 |
lemma ValOrd_preorder: |
|
294 |
"preorder_on (CPT r s) {(v1, v2). v1 \<preceq>r v2 \<and> v1 \<in> (CPT r s) \<and> v2 \<in> (CPT r s)}" |
|
295 |
apply(simp add: preorder_on_def) |
|
296 |
apply(rule conjI) |
|
297 |
apply(simp add: refl_on_def) |
|
298 |
apply(auto) |
|
299 |
apply(rule ValOrd_refl) |
|
300 |
apply(simp add: CPT_def) |
|
301 |
apply(rule Prf_CPrf) |
|
302 |
apply(auto)[1] |
|
303 |
apply(simp add: trans_def) |
|
304 |
apply(auto) |
|
148
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
305 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
306 |
definition ValOrdEq :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<ge>_ _" [100, 100, 100] 100) |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
307 |
where |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
308 |
"v\<^sub>1 \<ge>r v\<^sub>2 \<equiv> v\<^sub>1 = v\<^sub>2 \<or> (v\<^sub>1 >r v\<^sub>2 \<and> flat v\<^sub>1 = flat v\<^sub>2)" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
309 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
310 |
(* |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
312 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
313 |
inductive ValOrd :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<succ>_ _" [100, 100, 100] 100) |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
314 |
where |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
"v2 \<succ>r2 v2' \<Longrightarrow> (Seq v1 v2) \<succ>(SEQ r1 r2) (Seq v1 v2')" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
316 |
| "\<lbrakk>v1 \<succ>r1 v1'; v1 \<noteq> v1'\<rbrakk> \<Longrightarrow> (Seq v1 v2) \<succ>(SEQ r1 r2) (Seq v1' v2')" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
317 |
| "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) \<succ>(ALT r1 r2) (Right v2)" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
318 |
| "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) \<succ>(ALT r1 r2) (Left v1)" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
319 |
| "v2 \<succ>r2 v2' \<Longrightarrow> (Right v2) \<succ>(ALT r1 r2) (Right v2')" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
320 |
| "v1 \<succ>r1 v1' \<Longrightarrow> (Left v1) \<succ>(ALT r1 r2) (Left v1')" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
321 |
| "Void \<succ>EMPTY Void" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
322 |
| "(Char c) \<succ>(CHAR c) (Char c)" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
323 |
| "flat (Stars (v # vs)) = [] \<Longrightarrow> (Stars []) \<succ>(STAR r) (Stars (v # vs))" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
324 |
| "flat (Stars (v # vs)) \<noteq> [] \<Longrightarrow> (Stars (v # vs)) \<succ>(STAR r) (Stars [])" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
325 |
| "\<lbrakk>v1 \<succ>r v2; v1 \<noteq> v2\<rbrakk> \<Longrightarrow> (Stars (v1 # vs1)) \<succ>(STAR r) (Stars (v2 # vs2))" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
326 |
| "(Stars vs1) \<succ>(STAR r) (Stars vs2) \<Longrightarrow> (Stars (v # vs1)) \<succ>(STAR r) (Stars (v # vs2))" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
327 |
| "(Stars []) \<succ>(STAR r) (Stars [])" |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
328 |
*) |
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
329 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
330 |
|
154
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
331 |
section {* Bit-Encodings *} |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
332 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
333 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
334 |
fun |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
335 |
code :: "val \<Rightarrow> rexp \<Rightarrow> bool list" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
336 |
where |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
337 |
"code Void ONE = []" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
338 |
| "code (Char c) (CHAR d) = []" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
339 |
| "code (Left v) (ALT r1 r2) = False # (code v r1)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
340 |
| "code (Right v) (ALT r1 r2) = True # (code v r2)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
341 |
| "code (Seq v1 v2) (SEQ r1 r2) = (code v1 r1) @ (code v2 r2)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
342 |
| "code (Stars []) (STAR r) = [True]" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
343 |
| "code (Stars (v # vs)) (STAR r) = False # (code v r) @ code (Stars vs) (STAR r)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
344 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
345 |
fun |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
346 |
Stars_add :: "val \<Rightarrow> val \<Rightarrow> val" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
347 |
where |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
348 |
"Stars_add v (Stars vs) = Stars (v # vs)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
349 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
350 |
function |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
351 |
decode' :: "bool list \<Rightarrow> rexp \<Rightarrow> (val * bool list)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
352 |
where |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
353 |
"decode' ds ZERO = (Void, [])" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
354 |
| "decode' ds ONE = (Void, ds)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
355 |
| "decode' ds (CHAR d) = (Char d, ds)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
356 |
| "decode' [] (ALT r1 r2) = (Void, [])" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
357 |
| "decode' (False # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
358 |
| "decode' (True # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
359 |
| "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
360 |
let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
361 |
| "decode' [] (STAR r) = (Void, [])" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
362 |
| "decode' (True # ds) (STAR r) = (Stars [], ds)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
363 |
| "decode' (False # ds) (STAR r) = (let (v, ds') = decode' ds r in |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
364 |
let (vs, ds'') = decode' ds' (STAR r) |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
365 |
in (Stars_add v vs, ds''))" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
366 |
by pat_completeness auto |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
367 |
|
204
cd9e40280784
added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
368 |
termination |
cd9e40280784
added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
369 |
apply(size_change) |
cd9e40280784
added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
370 |
oops |
cd9e40280784
added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
371 |
|
154
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
372 |
term "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
373 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
374 |
lemma decode'_smaller: |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
375 |
assumes "decode'_dom (ds, r)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
376 |
shows "length (snd (decode' ds r)) \<le> length ds" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
377 |
using assms |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
378 |
apply(induct ds r) |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
379 |
apply(auto simp add: decode'.psimps split: prod.split) |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
380 |
using dual_order.trans apply blast |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
381 |
by (meson dual_order.trans le_SucI) |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
382 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
383 |
termination "decode'" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
384 |
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
385 |
apply(auto dest!: decode'_smaller) |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
386 |
by (metis less_Suc_eq_le snd_conv) |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
387 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
388 |
fun |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
389 |
decode :: "bool list \<Rightarrow> rexp \<Rightarrow> val option" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
390 |
where |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
391 |
"decode ds r = (let (v, ds') = decode' ds r |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
392 |
in (if ds' = [] then Some v else None))" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
393 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
394 |
lemma decode'_code: |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
395 |
assumes "\<turnstile> v : r" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
396 |
shows "decode' ((code v r) @ ds) r = (v, ds)" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
397 |
using assms |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
398 |
by (induct v r arbitrary: ds) (auto) |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
399 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
400 |
|
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
401 |
lemma decode_code: |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
402 |
assumes "\<turnstile> v : r" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
403 |
shows "decode (code v r) r = Some v" |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
404 |
using assms decode'_code[of _ _ "[]"] |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
405 |
by auto |
2de3cf684ba0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
148
diff
changeset
|
406 |
|
159
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
407 |
datatype arexp = |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
408 |
AZERO |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
409 |
| AONE "bool list" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
410 |
| ACHAR "bool list" char |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
411 |
| ASEQ "bool list" arexp arexp |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
412 |
| AALT "bool list" arexp arexp |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
413 |
| ASTAR "bool list" arexp |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
414 |
|
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
415 |
fun fuse :: "bool list \<Rightarrow> arexp \<Rightarrow> arexp" where |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
416 |
"fuse bs AZERO = AZERO" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
417 |
| "fuse bs (AONE cs) = AONE (bs @ cs)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
418 |
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
419 |
| "fuse bs (AALT cs r1 r2) = AALT (bs @ cs) r1 r2" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
420 |
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
421 |
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
422 |
|
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
423 |
fun internalise :: "rexp \<Rightarrow> arexp" where |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
424 |
"internalise ZERO = AZERO" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
425 |
| "internalise ONE = AONE []" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
426 |
| "internalise (CHAR c) = ACHAR [] c" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
427 |
| "internalise (ALT r1 r2) = AALT [] (fuse [False] (internalise r1)) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
428 |
(fuse [True] (internalise r2))" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
429 |
| "internalise (SEQ r1 r2) = ASEQ [] (internalise r1) (internalise r2)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
430 |
| "internalise (STAR r) = ASTAR [] (internalise r)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
431 |
|
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
432 |
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bool list" where |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
433 |
"retrieve (AONE bs) Void = bs" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
434 |
| "retrieve (ACHAR bs c) (Char d) = bs" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
435 |
| "retrieve (AALT bs r1 r2) (Left v) = bs @ retrieve r1 v" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
436 |
| "retrieve (AALT bs r1 r2) (Right v) = bs @ retrieve r2 v" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
437 |
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
438 |
| "retrieve (ASTAR bs r) (Stars []) = bs @ [True]" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
439 |
| "retrieve (ASTAR bs r) (Stars (v#vs)) = |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
440 |
bs @ [False] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
441 |
|
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
442 |
fun |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
443 |
anullable :: "arexp \<Rightarrow> bool" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
444 |
where |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
445 |
"anullable (AZERO) = False" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
446 |
| "anullable (AONE bs) = True" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
447 |
| "anullable (ACHAR bs c) = False" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
448 |
| "anullable (AALT bs r1 r2) = (anullable r1 \<or> anullable r2)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
449 |
| "anullable (ASEQ bs r1 r2) = (anullable r1 \<and> anullable r2)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
450 |
| "anullable (ASTAR bs r) = True" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
451 |
|
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
452 |
fun |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
453 |
amkeps :: "arexp \<Rightarrow> bool list" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
454 |
where |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
455 |
"amkeps(AONE bs) = bs" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
456 |
| "amkeps(ASEQ bs r1 r2) = bs @ (amkeps r1) @ (amkeps r2)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
457 |
| "amkeps(AALT bs r1 r2) = (if anullable(r1) then bs @ (amkeps r1) else bs @ (amkeps r2))" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
458 |
| "amkeps(ASTAR bs r) = bs @ [True]" |
148
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
459 |
|
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
460 |
|
159
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
461 |
fun |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
462 |
ader :: "char \<Rightarrow> arexp \<Rightarrow> arexp" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
463 |
where |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
464 |
"ader c (AZERO) = AZERO" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
465 |
| "ader c (AONE bs) = AZERO" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
466 |
| "ader c (ACHAR bs d) = (if c = d then AONE bs else AZERO)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
467 |
| "ader c (AALT bs r1 r2) = AALT bs (ader c r1) (ader c r2)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
468 |
| "ader c (ASEQ bs r1 r2) = |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
469 |
(if anullable r1 |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
470 |
then AALT bs (ASEQ [] (ader c r1) r2) (fuse (amkeps r1) (ader c r2)) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
471 |
else ASEQ bs (ader c r1) r2)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
472 |
| "ader c (ASTAR bs r) = ASEQ bs (fuse [False] (ader c r)) (ASTAR [] r)" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
473 |
|
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
474 |
lemma |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
475 |
assumes "\<turnstile> v : der c r" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
476 |
shows "Some (injval r c v) = decode (retrieve (ader c (internalise r)) v) r" |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
477 |
using assms |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
478 |
apply(induct c r arbitrary: v rule: der.induct) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
479 |
apply(simp_all) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
480 |
apply(erule Prf_elims) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
481 |
apply(erule Prf_elims) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
482 |
apply(case_tac "c = d") |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
483 |
apply(simp) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
484 |
apply(erule Prf_elims) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
485 |
apply(simp) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
486 |
apply(simp) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
487 |
apply(erule Prf_elims) |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
488 |
apply(auto split: prod.splits)[1] |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
489 |
oops |
940530087f30
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
154
diff
changeset
|
490 |
|
148
702ed601349b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
491 |
end |