author | Christian Urban <christian.urban@kcl.ac.uk> |
Thu, 16 Feb 2023 23:23:22 +0000 | |
changeset 642 | 6c13f76c070b |
parent 598 | 2c9a3aba8ebc |
permissions | -rw-r--r-- |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
theory Blexer |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
3 |
imports "Lexer" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
begin |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
section \<open>Bit-Encodings\<close> |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
datatype bit = Z | S |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
fun code :: "val \<Rightarrow> bit list" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
"code Void = []" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
| "code (Char c) = []" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
| "code (Left v) = Z # (code v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
| "code (Right v) = S # (code v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
| "code (Seq v1 v2) = (code v1) @ (code v2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
| "code (Stars []) = [S]" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
| "code (Stars (v # vs)) = (Z # code v) @ code (Stars vs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
|
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
20 |
fun sz where |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
21 |
"sz ZERO = 0" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
22 |
| "sz ONE = 0" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
23 |
| "sz (CH _) = 0" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
24 |
| "sz (SEQ r1 r2) = 1 + sz r1 + sz r2" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
25 |
| "sz (ALT r1 r2) = 1 + sz r1 + sz r2" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
26 |
| "sz (STAR r) = 1 + sz r" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
27 |
| "sz (NTIMES r n) = 1 + (n + 1) + sz r" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
28 |
|
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
29 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
30 |
fun |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
Stars_add :: "val \<Rightarrow> val \<Rightarrow> val" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
"Stars_add v (Stars vs) = Stars (v # vs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
|
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
35 |
function (sequential) |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
"decode' bs ZERO = (undefined, bs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
39 |
| "decode' bs ONE = (Void, bs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
40 |
| "decode' bs (CH d) = (Char d, bs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
| "decode' [] (ALT r1 r2) = (Void, [])" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
| "decode' (Z # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r1 in (Left v, bs'))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
| "decode' (S # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r2 in (Right v, bs'))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
| "decode' bs (SEQ r1 r2) = (let (v1, bs') = decode' bs r1 in |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
let (v2, bs'') = decode' bs' r2 in (Seq v1 v2, bs''))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
| "decode' [] (STAR r) = (Void, [])" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
| "decode' (S # bs) (STAR r) = (Stars [], bs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
| "decode' (Z # bs) (STAR r) = (let (v, bs') = decode' bs r in |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
let (vs, bs'') = decode' bs' (STAR r) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
in (Stars_add v vs, bs''))" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
51 |
| "decode' bs (NTIMES r n) = decode' bs (STAR r)" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
by pat_completeness auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
lemma decode'_smaller: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
assumes "decode'_dom (bs, r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
shows "length (snd (decode' bs r)) \<le> length bs" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
apply(induct bs r) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
apply(auto simp add: decode'.psimps split: prod.split) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
using dual_order.trans apply blast |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
61 |
apply (meson dual_order.trans le_SucI) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
62 |
done |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
63 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
64 |
termination "decode'" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
65 |
apply(relation "inv_image (measure(%cs. sz cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
apply(auto dest!: decode'_smaller) |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
67 |
apply (metis less_Suc_eq_le snd_conv) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
68 |
done |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
69 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
70 |
definition |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
71 |
decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
72 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
73 |
"decode ds r \<equiv> (let (v, ds') = decode' ds r |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
74 |
in (if ds' = [] then Some v else None))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
75 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
76 |
lemma decode'_code_Stars: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
77 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
78 |
shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
79 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
80 |
apply(induct vs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
81 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
82 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
83 |
|
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
84 |
lemma decode'_code_NTIMES: |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
85 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x))" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
86 |
shows "decode' (code (Stars vs) @ ds) (NTIMES r n) = (Stars vs, ds)" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
87 |
using assms |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
88 |
apply(induct vs arbitrary: n r ds) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
89 |
apply(auto) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
90 |
done |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
91 |
|
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
92 |
|
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
93 |
lemma decode'_code: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
94 |
assumes "\<Turnstile> v : r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
95 |
shows "decode' ((code v) @ ds) r = (v, ds)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
96 |
using assms |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
97 |
apply(induct v r arbitrary: ds rule: Prf.induct) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
98 |
apply(auto)[6] |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
99 |
using decode'_code_Stars apply blast |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
100 |
apply(rule decode'_code_NTIMES) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
101 |
apply(simp) |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
102 |
apply(auto) |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
103 |
done |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
104 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
105 |
lemma decode_code: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
106 |
assumes "\<Turnstile> v : r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
107 |
shows "decode (code v) r = Some v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
108 |
using assms unfolding decode_def |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
109 |
by (smt append_Nil2 decode'_code old.prod.case) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
110 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
111 |
|
642 | 112 |
section \<open>Annotated Regular Expressions\<close> |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
113 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
114 |
datatype arexp = |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
115 |
AZERO |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
116 |
| AONE "bit list" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
117 |
| ACHAR "bit list" char |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
118 |
| ASEQ "bit list" arexp arexp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
119 |
| AALTs "bit list" "arexp list" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
120 |
| ASTAR "bit list" arexp |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
121 |
| ANTIMES "bit list" arexp nat |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
122 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
123 |
abbreviation |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
124 |
"AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
125 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
126 |
fun asize :: "arexp \<Rightarrow> nat" where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
127 |
"asize AZERO = 1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
128 |
| "asize (AONE cs) = 1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
129 |
| "asize (ACHAR cs c) = 1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
130 |
| "asize (AALTs cs rs) = Suc (sum_list (map asize rs))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
131 |
| "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
132 |
| "asize (ASTAR cs r) = Suc (asize r)" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
133 |
| "asize (ANTIMES cs r n) = Suc (asize r) + n" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
134 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
135 |
fun |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
136 |
erase :: "arexp \<Rightarrow> rexp" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
137 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
138 |
"erase AZERO = ZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
139 |
| "erase (AONE _) = ONE" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
140 |
| "erase (ACHAR _ c) = CH c" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
141 |
| "erase (AALTs _ []) = ZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
142 |
| "erase (AALTs _ [r]) = (erase r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
143 |
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
144 |
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
145 |
| "erase (ASTAR _ r) = STAR (erase r)" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
146 |
| "erase (ANTIMES _ r n) = NTIMES (erase r) n" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
147 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
148 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
149 |
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
150 |
"fuse bs AZERO = AZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
151 |
| "fuse bs (AONE cs) = AONE (bs @ cs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
152 |
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
153 |
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
154 |
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
155 |
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
156 |
| "fuse bs (ANTIMES cs r n) = ANTIMES (bs @ cs) r n" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
157 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
158 |
lemma fuse_append: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
159 |
shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
160 |
apply(induct r) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
161 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
162 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
163 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
164 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
165 |
fun intern :: "rexp \<Rightarrow> arexp" where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
166 |
"intern ZERO = AZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
167 |
| "intern ONE = AONE []" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
168 |
| "intern (CH c) = ACHAR [] c" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
169 |
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
170 |
(fuse [S] (intern r2))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
171 |
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
172 |
| "intern (STAR r) = ASTAR [] (intern r)" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
173 |
| "intern (NTIMES r n) = ANTIMES [] (intern r) n" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
174 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
175 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
176 |
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
177 |
"retrieve (AONE bs) Void = bs" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
178 |
| "retrieve (ACHAR bs c) (Char d) = bs" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
179 |
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
180 |
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
181 |
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
182 |
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
183 |
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
184 |
| "retrieve (ASTAR bs r) (Stars (v#vs)) = |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
185 |
bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
186 |
| "retrieve (ANTIMES bs r 0) (Stars []) = bs @ [S]" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
187 |
| "retrieve (ANTIMES bs r (Suc n)) (Stars (v#vs)) = |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
188 |
bs @ [Z] @ retrieve r v @ retrieve (ANTIMES [] r n) (Stars vs)" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
189 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
190 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
191 |
fun |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
192 |
bnullable :: "arexp \<Rightarrow> bool" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
193 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
194 |
"bnullable (AZERO) = False" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
195 |
| "bnullable (AONE bs) = True" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
196 |
| "bnullable (ACHAR bs c) = False" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
197 |
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
198 |
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
199 |
| "bnullable (ASTAR bs r) = True" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
200 |
| "bnullable (ANTIMES bs r n) = (if n = 0 then True else bnullable r)" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
201 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
202 |
abbreviation |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
203 |
bnullables :: "arexp list \<Rightarrow> bool" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
204 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
205 |
"bnullables rs \<equiv> (\<exists>r \<in> set rs. bnullable r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
206 |
|
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
207 |
function (sequential) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
208 |
bmkeps :: "arexp \<Rightarrow> bit list" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
209 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
210 |
"bmkeps(AONE bs) = bs" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
211 |
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
212 |
| "bmkeps(AALTs bs (r#rs)) = |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
213 |
(if bnullable(r) then (bs @ bmkeps r) else (bmkeps (AALTs bs rs)))" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
214 |
| "bmkeps(ASTAR bs r) = bs @ [S]" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
215 |
| "bmkeps(ANTIMES bs r n) = |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
216 |
(if n = 0 then bs @ [S] else bs @ [Z] @ (bmkeps r) @ bmkeps(ANTIMES [] r (n - 1)))" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
217 |
apply(pat_completeness) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
218 |
apply(auto) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
219 |
done |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
220 |
|
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
221 |
termination "bmkeps" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
222 |
apply(relation "measure asize") |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
223 |
apply(auto) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
224 |
using asize.elims by force |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
225 |
|
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
226 |
fun |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
227 |
bmkepss :: "arexp list \<Rightarrow> bit list" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
228 |
where |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
229 |
"bmkepss (r # rs) = (if bnullable(r) then (bmkeps r) else (bmkepss rs))" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
230 |
|
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
231 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
232 |
lemma bmkepss1: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
233 |
assumes "\<not> bnullables rs1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
234 |
shows "bmkepss (rs1 @ rs2) = bmkepss rs2" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
235 |
using assms |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
236 |
by(induct rs1) (auto) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
237 |
|
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
238 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
239 |
lemma bmkepss2: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
240 |
assumes "bnullables rs1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
241 |
shows "bmkepss (rs1 @ rs2) = bmkepss rs1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
242 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
243 |
by (induct rs1) (auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
244 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
245 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
246 |
fun |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
247 |
bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
248 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
249 |
"bder c (AZERO) = AZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
250 |
| "bder c (AONE bs) = AZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
251 |
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
252 |
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
253 |
| "bder c (ASEQ bs r1 r2) = |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
254 |
(if bnullable r1 |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
255 |
then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
256 |
else ASEQ bs (bder c r1) r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
257 |
| "bder c (ASTAR bs r) = ASEQ (bs @ [Z]) (bder c r) (ASTAR [] r)" |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
258 |
| "bder c (ANTIMES bs r n) = (if n = 0 then AZERO else ASEQ (bs @ [Z]) (bder c r) (ANTIMES [] r (n - 1)))" |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
259 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
260 |
fun |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
261 |
bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
262 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
263 |
"bders r [] = r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
264 |
| "bders r (c#s) = bders (bder c r) s" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
265 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
266 |
lemma bders_append: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
267 |
"bders c (s1 @ s2) = bders (bders c s1) s2" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
268 |
apply(induct s1 arbitrary: c s2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
269 |
apply(simp_all) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
270 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
271 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
272 |
lemma bnullable_correctness: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
273 |
shows "nullable (erase r) = bnullable r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
274 |
apply(induct r rule: erase.induct) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
275 |
apply(simp_all) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
276 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
277 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
278 |
lemma erase_fuse: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
279 |
shows "erase (fuse bs r) = erase r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
280 |
apply(induct r rule: erase.induct) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
281 |
apply(simp_all) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
282 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
283 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
284 |
lemma erase_intern [simp]: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
285 |
shows "erase (intern r) = r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
286 |
apply(induct r) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
287 |
apply(simp_all add: erase_fuse) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
288 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
289 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
290 |
lemma erase_bder [simp]: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
291 |
shows "erase (bder a r) = der a (erase r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
292 |
apply(induct r rule: erase.induct) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
293 |
apply(simp_all add: erase_fuse bnullable_correctness) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
294 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
295 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
296 |
lemma erase_bders [simp]: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
297 |
shows "erase (bders r s) = ders s (erase r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
298 |
apply(induct s arbitrary: r ) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
299 |
apply(simp_all) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
300 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
301 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
302 |
lemma bnullable_fuse: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
303 |
shows "bnullable (fuse bs r) = bnullable r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
304 |
apply(induct r arbitrary: bs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
305 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
306 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
307 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
308 |
lemma retrieve_encode_STARS: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
309 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
310 |
shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
311 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
312 |
apply(induct vs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
313 |
apply(simp_all) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
314 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
315 |
|
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
316 |
lemma retrieve_encode_NTIMES: |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
317 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v" "length vs = n" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
318 |
shows "code (Stars vs) = retrieve (ANTIMES [] (intern r) n) (Stars vs)" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
319 |
using assms |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
320 |
apply(induct vs arbitrary: n) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
321 |
apply(simp_all) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
322 |
by force |
583 | 323 |
|
324 |
||
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
325 |
lemma retrieve_fuse2: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
326 |
assumes "\<Turnstile> v : (erase r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
327 |
shows "retrieve (fuse bs r) v = bs @ retrieve r v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
328 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
329 |
apply(induct r arbitrary: v bs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
330 |
apply(auto elim: Prf_elims)[4] |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
331 |
apply(case_tac x2a) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
332 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
333 |
using Prf_elims(1) apply blast |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
334 |
apply(case_tac x2a) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
335 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
336 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
337 |
apply(case_tac list) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
338 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
339 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
340 |
apply (smt (verit, best) Prf_elims(3) append_assoc retrieve.simps(4) retrieve.simps(5)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
341 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
342 |
using retrieve_encode_STARS |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
343 |
apply(auto elim!: Prf_elims)[1] |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
344 |
apply(case_tac vs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
345 |
apply(simp) |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
346 |
apply(simp) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
347 |
(* NTIMES *) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
348 |
apply(auto elim!: Prf_elims)[1] |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
349 |
apply(case_tac vs1) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
350 |
apply(simp_all) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
351 |
apply(case_tac vs2) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
352 |
apply(simp_all) |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
353 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
354 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
355 |
lemma retrieve_fuse: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
356 |
assumes "\<Turnstile> v : r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
357 |
shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
358 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
359 |
by (simp_all add: retrieve_fuse2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
360 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
361 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
362 |
lemma retrieve_code: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
363 |
assumes "\<Turnstile> v : r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
364 |
shows "code v = retrieve (intern r) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
365 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
366 |
apply(induct v r ) |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
367 |
apply(simp_all add: retrieve_fuse retrieve_encode_STARS) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
368 |
apply(subst retrieve_encode_NTIMES) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
369 |
apply(auto) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
370 |
done |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
371 |
|
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
372 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
373 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
374 |
lemma retrieve_AALTs_bnullable1: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
375 |
assumes "bnullable r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
376 |
shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs)))) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
377 |
= bs @ retrieve r (mkeps (erase r))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
378 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
379 |
apply(case_tac rs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
380 |
apply(auto simp add: bnullable_correctness) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
381 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
382 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
383 |
lemma retrieve_AALTs_bnullable2: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
384 |
assumes "\<not>bnullable r" "bnullables rs" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
385 |
shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs)))) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
386 |
= retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
387 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
388 |
apply(induct rs arbitrary: r bs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
389 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
390 |
using bnullable_correctness apply blast |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
391 |
apply(case_tac rs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
392 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
393 |
using bnullable_correctness apply blast |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
394 |
apply(case_tac rs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
395 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
396 |
done |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
397 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
398 |
lemma bmkeps_retrieve_AALTs: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
399 |
assumes "\<forall>r \<in> set rs. bnullable r \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
400 |
"bnullables rs" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
401 |
shows "bs @ bmkepss rs = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
402 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
403 |
apply(induct rs arbitrary: bs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
404 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
405 |
using retrieve_AALTs_bnullable1 apply presburger |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
406 |
apply (metis retrieve_AALTs_bnullable2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
407 |
apply (simp add: retrieve_AALTs_bnullable1) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
408 |
by (metis retrieve_AALTs_bnullable2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
409 |
|
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
410 |
lemma bmkeps_retrieve_ANTIMES: |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
411 |
assumes "if n = 0 then True else bmkeps r = retrieve r (mkeps (erase r))" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
412 |
and "bnullable (ANTIMES bs r n)" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
413 |
shows "bmkeps (ANTIMES bs r n) = retrieve (ANTIMES bs r n) (Stars (replicate n (mkeps (erase r))))" |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
414 |
using assms |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
415 |
apply(induct n arbitrary: r bs) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
416 |
apply(auto)[1] |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
417 |
apply(simp) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
418 |
done |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
419 |
|
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
420 |
lemma bmkeps_retrieve: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
421 |
assumes "bnullable r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
422 |
shows "bmkeps r = retrieve r (mkeps (erase r))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
423 |
using assms |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
424 |
apply(induct r rule: bmkeps.induct) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
425 |
apply(auto) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
426 |
apply (simp add: retrieve_AALTs_bnullable1) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
427 |
using retrieve_AALTs_bnullable1 apply force |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
428 |
apply(metis retrieve_AALTs_bnullable2) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
429 |
by (metis Cons_eq_appendI One_nat_def Suc_diff_1 eq_Nil_appendI replicate_Suc retrieve.simps(10)) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
430 |
|
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
431 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
432 |
lemma bder_retrieve: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
433 |
assumes "\<Turnstile> v : der c (erase r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
434 |
shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
435 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
436 |
apply(induct r arbitrary: v rule: erase.induct) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
437 |
using Prf_elims(1) apply auto[1] |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
438 |
using Prf_elims(1) apply auto[1] |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
439 |
apply(auto)[1] |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
440 |
apply (metis Prf_elims(4) injval.simps(1) retrieve.simps(1) retrieve.simps(2)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
441 |
using Prf_elims(1) apply blast |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
442 |
(* AALTs case *) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
443 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
444 |
apply(erule Prf_elims) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
445 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
446 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
447 |
apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
448 |
apply(erule Prf_elims) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
449 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
450 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
451 |
apply(case_tac rs) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
452 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
453 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
454 |
using Prf_elims(3) apply fastforce |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
455 |
(* ASEQ case *) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
456 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
457 |
apply(case_tac "nullable (erase r1)") |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
458 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
459 |
apply(erule Prf_elims) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
460 |
using Prf_elims(2) bnullable_correctness apply force |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
461 |
apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
462 |
apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
463 |
using Prf_elims(2) apply force |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
464 |
(* ASTAR case *) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
465 |
apply(rename_tac bs r v) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
466 |
apply(simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
467 |
apply(erule Prf_elims) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
468 |
apply(clarify) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
469 |
apply(erule Prf_elims) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
470 |
apply(clarify) |
598
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
471 |
apply (simp add: retrieve_fuse2) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
472 |
(* ANTIMES case *) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
473 |
apply(auto) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
474 |
apply(erule Prf_elims) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
475 |
apply(erule Prf_elims) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
476 |
apply(clarify) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
477 |
apply(erule Prf_elims) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
478 |
apply(clarify) |
2c9a3aba8ebc
simplified the n-times case in decode_aux
Christian Urban <christian.urban@kcl.ac.uk>
parents:
583
diff
changeset
|
479 |
by (metis (full_types) Suc_pred append_assoc injval.simps(8) retrieve.simps(10) retrieve.simps(6)) |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
480 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
481 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
482 |
lemma MAIN_decode: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
483 |
assumes "\<Turnstile> v : ders s r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
484 |
shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
485 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
486 |
proof (induct s arbitrary: v rule: rev_induct) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
487 |
case Nil |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
488 |
have "\<Turnstile> v : ders [] r" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
489 |
then have "\<Turnstile> v : r" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
490 |
then have "Some v = decode (retrieve (intern r) v) r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
491 |
using decode_code retrieve_code by auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
492 |
then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
493 |
by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
494 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
495 |
case (snoc c s v) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
496 |
have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
497 |
Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
498 |
have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
499 |
then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
500 |
by (simp add: Prf_injval ders_append) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
501 |
have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
502 |
by (simp add: flex_append) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
503 |
also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
504 |
using asm2 IH by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
505 |
also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
506 |
using asm by (simp_all add: bder_retrieve ders_append) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
507 |
finally show "Some (flex r id (s @ [c]) v) = |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
508 |
decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
509 |
qed |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
510 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
511 |
definition blexer where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
512 |
"blexer r s \<equiv> if bnullable (bders (intern r) s) then |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
513 |
decode (bmkeps (bders (intern r) s)) r else None" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
514 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
515 |
lemma blexer_correctness: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
516 |
shows "blexer r s = lexer r s" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
517 |
proof - |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
518 |
{ define bds where "bds \<equiv> bders (intern r) s" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
519 |
define ds where "ds \<equiv> ders s r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
520 |
assume asm: "nullable ds" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
521 |
have era: "erase bds = ds" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
522 |
unfolding ds_def bds_def by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
523 |
have mke: "\<Turnstile> mkeps ds : ds" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
524 |
using asm by (simp add: mkeps_nullable) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
525 |
have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
526 |
using bmkeps_retrieve |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
527 |
using asm era |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
528 |
using bnullable_correctness by force |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
529 |
also have "... = Some (flex r id s (mkeps ds))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
530 |
using mke by (simp_all add: MAIN_decode ds_def bds_def) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
531 |
finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
532 |
unfolding bds_def ds_def . |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
533 |
} |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
534 |
then show "blexer r s = lexer r s" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
535 |
unfolding blexer_def lexer_flex |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
536 |
by (auto simp add: bnullable_correctness[symmetric]) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
537 |
qed |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
538 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
539 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
540 |
unused_thms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
541 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
542 |
end |