author | Chengsong |
Mon, 04 Jul 2022 12:27:13 +0100 | |
changeset 558 | 671a83abccf3 |
parent 495 | f9cdc295ccf7 |
child 642 | 6c13f76c070b |
permissions | -rw-r--r-- |
495
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
theory LexerSimp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
imports "Lexer" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
begin |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
section {* Lexer including some simplifications *} |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
|
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 |
fun F_RIGHT where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
"F_RIGHT f v = Right (f v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
fun F_LEFT where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
"F_LEFT f v = Left (f v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
fun F_ALT where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
"F_ALT f\<^sub>1 f\<^sub>2 (Right v) = Right (f\<^sub>2 v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
| "F_ALT f\<^sub>1 f\<^sub>2 (Left v) = Left (f\<^sub>1 v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
| "F_ALT f1 f2 v = v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
fun F_SEQ1 where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
"F_SEQ1 f\<^sub>1 f\<^sub>2 v = Seq (f\<^sub>1 Void) (f\<^sub>2 v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
fun F_SEQ2 where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
"F_SEQ2 f\<^sub>1 f\<^sub>2 v = Seq (f\<^sub>1 v) (f\<^sub>2 Void)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
25 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
fun F_SEQ where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
"F_SEQ f\<^sub>1 f\<^sub>2 (Seq v\<^sub>1 v\<^sub>2) = Seq (f\<^sub>1 v\<^sub>1) (f\<^sub>2 v\<^sub>2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
| "F_SEQ f1 f2 v = v" |
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 simp_ALT where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
"simp_ALT (ZERO, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (r\<^sub>2, F_RIGHT f\<^sub>2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
| "simp_ALT (r\<^sub>1, f\<^sub>1) (ZERO, f\<^sub>2) = (r\<^sub>1, F_LEFT f\<^sub>1)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
| "simp_ALT (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (ALT r\<^sub>1 r\<^sub>2, F_ALT f\<^sub>1 f\<^sub>2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
35 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
fun simp_SEQ where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
"simp_SEQ (ONE, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (r\<^sub>2, F_SEQ1 f\<^sub>1 f\<^sub>2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
| "simp_SEQ (r\<^sub>1, f\<^sub>1) (ONE, f\<^sub>2) = (r\<^sub>1, F_SEQ2 f\<^sub>1 f\<^sub>2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
39 |
| "simp_SEQ (ZERO, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (ZERO, undefined)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
40 |
| "simp_SEQ (r\<^sub>1, f\<^sub>1) (ZERO, f\<^sub>2) = (ZERO, undefined)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
| "simp_SEQ (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (SEQ r\<^sub>1 r\<^sub>2, F_SEQ f\<^sub>1 f\<^sub>2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
lemma simp_SEQ_simps[simp]: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
"simp_SEQ p1 p2 = (if (fst p1 = ONE) then (fst p2, F_SEQ1 (snd p1) (snd p2)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
else (if (fst p2 = ONE) then (fst p1, F_SEQ2 (snd p1) (snd p2)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
else (if (fst p1 = ZERO) then (ZERO, undefined) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
else (if (fst p2 = ZERO) then (ZERO, undefined) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
else (SEQ (fst p1) (fst p2), F_SEQ (snd p1) (snd p2))))))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
by (induct p1 p2 rule: simp_SEQ.induct) (auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
51 |
lemma simp_ALT_simps[simp]: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
"simp_ALT p1 p2 = (if (fst p1 = ZERO) then (fst p2, F_RIGHT (snd p2)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
else (if (fst p2 = ZERO) then (fst p1, F_LEFT (snd p1)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
else (ALT (fst p1) (fst p2), F_ALT (snd p1) (snd p2))))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
by (induct p1 p2 rule: simp_ALT.induct) (auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
fun |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
simp :: "rexp \<Rightarrow> rexp * (val \<Rightarrow> val)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
"simp (ALT r1 r2) = simp_ALT (simp r1) (simp r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
61 |
| "simp (SEQ r1 r2) = simp_SEQ (simp r1) (simp r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
62 |
| "simp r = (r, id)" |
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 |
fun |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
65 |
slexer :: "rexp \<Rightarrow> string \<Rightarrow> val option" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
where |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
67 |
"slexer r [] = (if nullable r then Some(mkeps r) else None)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
68 |
| "slexer r (c#s) = (let (rs, fr) = simp (der c r) in |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
69 |
(case (slexer rs s) of |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
70 |
None \<Rightarrow> None |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
71 |
| Some(v) \<Rightarrow> Some(injval r c (fr v))))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
72 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
73 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
74 |
lemma slexer_better_simp: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
75 |
"slexer r (c#s) = (case (slexer (fst (simp (der c r))) s) of |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
76 |
None \<Rightarrow> None |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
77 |
| Some(v) \<Rightarrow> Some(injval r c ((snd (simp (der c r))) v)))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
78 |
by (auto split: prod.split option.split) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
79 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
80 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
81 |
lemma L_fst_simp: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
82 |
shows "L(r) = L(fst (simp r))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
83 |
by (induct r) (auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
84 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
85 |
lemma Posix_simp: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
86 |
assumes "s \<in> (fst (simp r)) \<rightarrow> v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
87 |
shows "s \<in> r \<rightarrow> ((snd (simp r)) v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
88 |
using assms |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
89 |
proof(induct r arbitrary: s v rule: rexp.induct) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
90 |
case (ALT r1 r2 s v) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
91 |
have IH1: "\<And>s v. s \<in> fst (simp r1) \<rightarrow> v \<Longrightarrow> s \<in> r1 \<rightarrow> snd (simp r1) v" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
92 |
have IH2: "\<And>s v. s \<in> fst (simp r2) \<rightarrow> v \<Longrightarrow> s \<in> r2 \<rightarrow> snd (simp r2) v" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
93 |
have as: "s \<in> fst (simp (ALT r1 r2)) \<rightarrow> v" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
94 |
consider (ZERO_ZERO) "fst (simp r1) = ZERO" "fst (simp r2) = ZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
95 |
| (ZERO_NZERO) "fst (simp r1) = ZERO" "fst (simp r2) \<noteq> ZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
96 |
| (NZERO_ZERO) "fst (simp r1) \<noteq> ZERO" "fst (simp r2) = ZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
97 |
| (NZERO_NZERO) "fst (simp r1) \<noteq> ZERO" "fst (simp r2) \<noteq> ZERO" by auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
98 |
then show "s \<in> ALT r1 r2 \<rightarrow> snd (simp (ALT r1 r2)) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
99 |
proof(cases) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
100 |
case (ZERO_ZERO) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
101 |
with as have "s \<in> ZERO \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
102 |
then show "s \<in> ALT r1 r2 \<rightarrow> snd (simp (ALT r1 r2)) v" by (rule Posix_elims(1)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
103 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
104 |
case (ZERO_NZERO) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
105 |
with as have "s \<in> fst (simp r2) \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
106 |
with IH2 have "s \<in> r2 \<rightarrow> snd (simp r2) v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
107 |
moreover |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
108 |
from ZERO_NZERO have "fst (simp r1) = ZERO" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
109 |
then have "L (fst (simp r1)) = {}" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
110 |
then have "L r1 = {}" using L_fst_simp by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
111 |
then have "s \<notin> L r1" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
112 |
ultimately have "s \<in> ALT r1 r2 \<rightarrow> Right (snd (simp r2) v)" by (rule Posix_ALT2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
113 |
then show "s \<in> ALT r1 r2 \<rightarrow> snd (simp (ALT r1 r2)) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
114 |
using ZERO_NZERO by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
115 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
116 |
case (NZERO_ZERO) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
117 |
with as have "s \<in> fst (simp r1) \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
118 |
with IH1 have "s \<in> r1 \<rightarrow> snd (simp r1) v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
119 |
then have "s \<in> ALT r1 r2 \<rightarrow> Left (snd (simp r1) v)" by (rule Posix_ALT1) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
120 |
then show "s \<in> ALT r1 r2 \<rightarrow> snd (simp (ALT r1 r2)) v" using NZERO_ZERO by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
121 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
122 |
case (NZERO_NZERO) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
123 |
with as have "s \<in> ALT (fst (simp r1)) (fst (simp r2)) \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
124 |
then consider (Left) v1 where "v = Left v1" "s \<in> (fst (simp r1)) \<rightarrow> v1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
125 |
| (Right) v2 where "v = Right v2" "s \<in> (fst (simp r2)) \<rightarrow> v2" "s \<notin> L (fst (simp r1))" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
126 |
by (erule_tac Posix_elims(4)) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
127 |
then show "s \<in> ALT r1 r2 \<rightarrow> snd (simp (ALT r1 r2)) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
128 |
proof(cases) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
129 |
case (Left) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
130 |
then have "v = Left v1" "s \<in> r1 \<rightarrow> (snd (simp r1) v1)" using IH1 by simp_all |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
131 |
then show "s \<in> ALT r1 r2 \<rightarrow> snd (simp (ALT r1 r2)) v" using NZERO_NZERO |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
132 |
by (simp_all add: Posix_ALT1) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
133 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
134 |
case (Right) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
135 |
then have "v = Right v2" "s \<in> r2 \<rightarrow> (snd (simp r2) v2)" "s \<notin> L r1" using IH2 L_fst_simp by simp_all |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
136 |
then show "s \<in> ALT r1 r2 \<rightarrow> snd (simp (ALT r1 r2)) v" using NZERO_NZERO |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
137 |
by (simp_all add: Posix_ALT2) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
138 |
qed |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
139 |
qed |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
140 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
141 |
case (SEQ r1 r2 s v) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
142 |
have IH1: "\<And>s v. s \<in> fst (simp r1) \<rightarrow> v \<Longrightarrow> s \<in> r1 \<rightarrow> snd (simp r1) v" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
143 |
have IH2: "\<And>s v. s \<in> fst (simp r2) \<rightarrow> v \<Longrightarrow> s \<in> r2 \<rightarrow> snd (simp r2) v" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
144 |
have as: "s \<in> fst (simp (SEQ r1 r2)) \<rightarrow> v" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
145 |
consider (ONE_ONE) "fst (simp r1) = ONE" "fst (simp r2) = ONE" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
146 |
| (ONE_NONE) "fst (simp r1) = ONE" "fst (simp r2) \<noteq> ONE" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
147 |
| (NONE_ONE) "fst (simp r1) \<noteq> ONE" "fst (simp r2) = ONE" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
148 |
| (NONE_NONE) "fst (simp r1) \<noteq> ONE" "fst (simp r2) \<noteq> ONE" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
149 |
by auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
150 |
then show "s \<in> SEQ r1 r2 \<rightarrow> snd (simp (SEQ r1 r2)) v" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
151 |
proof(cases) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
152 |
case (ONE_ONE) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
153 |
with as have b: "s \<in> ONE \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
154 |
from b have "s \<in> r1 \<rightarrow> snd (simp r1) v" using IH1 ONE_ONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
155 |
moreover |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
156 |
from b have c: "s = []" "v = Void" using Posix_elims(2) by auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
157 |
moreover |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
158 |
have "[] \<in> ONE \<rightarrow> Void" by (simp add: Posix_ONE) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
159 |
then have "[] \<in> fst (simp r2) \<rightarrow> Void" using ONE_ONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
160 |
then have "[] \<in> r2 \<rightarrow> snd (simp r2) Void" using IH2 by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
161 |
ultimately have "([] @ []) \<in> SEQ r1 r2 \<rightarrow> Seq (snd (simp r1) Void) (snd (simp r2) Void)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
162 |
using Posix_SEQ by blast |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
163 |
then show "s \<in> SEQ r1 r2 \<rightarrow> snd (simp (SEQ r1 r2)) v" using c ONE_ONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
164 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
165 |
case (ONE_NONE) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
166 |
with as have b: "s \<in> fst (simp r2) \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
167 |
from b have "s \<in> r2 \<rightarrow> snd (simp r2) v" using IH2 ONE_NONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
168 |
moreover |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
169 |
have "[] \<in> ONE \<rightarrow> Void" by (simp add: Posix_ONE) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
170 |
then have "[] \<in> fst (simp r1) \<rightarrow> Void" using ONE_NONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
171 |
then have "[] \<in> r1 \<rightarrow> snd (simp r1) Void" using IH1 by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
172 |
moreover |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
173 |
from ONE_NONE(1) have "L (fst (simp r1)) = {[]}" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
174 |
then have "L r1 = {[]}" by (simp add: L_fst_simp[symmetric]) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
175 |
ultimately have "([] @ s) \<in> SEQ r1 r2 \<rightarrow> Seq (snd (simp r1) Void) (snd (simp r2) v)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
176 |
by(rule_tac Posix_SEQ) auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
177 |
then show "s \<in> SEQ r1 r2 \<rightarrow> snd (simp (SEQ r1 r2)) v" using ONE_NONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
178 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
179 |
case (NONE_ONE) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
180 |
with as have "s \<in> fst (simp r1) \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
181 |
with IH1 have "s \<in> r1 \<rightarrow> snd (simp r1) v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
182 |
moreover |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
183 |
have "[] \<in> ONE \<rightarrow> Void" by (simp add: Posix_ONE) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
184 |
then have "[] \<in> fst (simp r2) \<rightarrow> Void" using NONE_ONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
185 |
then have "[] \<in> r2 \<rightarrow> snd (simp r2) Void" using IH2 by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
186 |
ultimately have "(s @ []) \<in> SEQ r1 r2 \<rightarrow> Seq (snd (simp r1) v) (snd (simp r2) Void)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
187 |
by(rule_tac Posix_SEQ) auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
188 |
then show "s \<in> SEQ r1 r2 \<rightarrow> snd (simp (SEQ r1 r2)) v" using NONE_ONE by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
189 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
190 |
case (NONE_NONE) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
191 |
from as have 00: "fst (simp r1) \<noteq> ZERO" "fst (simp r2) \<noteq> ZERO" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
192 |
apply(auto) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
193 |
apply(smt Posix_elims(1) fst_conv) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
194 |
by (smt NONE_NONE(2) Posix_elims(1) fstI) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
195 |
with NONE_NONE as have "s \<in> SEQ (fst (simp r1)) (fst (simp r2)) \<rightarrow> v" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
196 |
then obtain s1 s2 v1 v2 where eqs: "s = s1 @ s2" "v = Seq v1 v2" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
197 |
"s1 \<in> (fst (simp r1)) \<rightarrow> v1" "s2 \<in> (fst (simp r2)) \<rightarrow> v2" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
198 |
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
199 |
by (erule_tac Posix_elims(5)) (auto simp add: L_fst_simp[symmetric]) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
200 |
then have "s1 \<in> r1 \<rightarrow> (snd (simp r1) v1)" "s2 \<in> r2 \<rightarrow> (snd (simp r2) v2)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
201 |
using IH1 IH2 by auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
202 |
then show "s \<in> SEQ r1 r2 \<rightarrow> snd (simp (SEQ r1 r2)) v" using eqs NONE_NONE 00 |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
203 |
by(auto intro: Posix_SEQ) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
204 |
qed |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
205 |
qed (simp_all) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
206 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
207 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
208 |
lemma slexer_correctness: |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
209 |
shows "slexer r s = lexer r s" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
210 |
proof(induct s arbitrary: r) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
211 |
case Nil |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
212 |
show "slexer r [] = lexer r []" by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
213 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
214 |
case (Cons c s r) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
215 |
have IH: "\<And>r. slexer r s = lexer r s" by fact |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
216 |
show "slexer r (c # s) = lexer r (c # s)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
217 |
proof (cases "s \<in> L (der c r)") |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
218 |
case True |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
219 |
assume a1: "s \<in> L (der c r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
220 |
then obtain v1 where a2: "lexer (der c r) s = Some v1" "s \<in> der c r \<rightarrow> v1" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
221 |
using lexer_correct_Some by auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
222 |
from a1 have "s \<in> L (fst (simp (der c r)))" using L_fst_simp[symmetric] by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
223 |
then obtain v2 where a3: "lexer (fst (simp (der c r))) s = Some v2" "s \<in> (fst (simp (der c r))) \<rightarrow> v2" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
224 |
using lexer_correct_Some by auto |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
225 |
then have a4: "slexer (fst (simp (der c r))) s = Some v2" using IH by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
226 |
from a3(2) have "s \<in> der c r \<rightarrow> (snd (simp (der c r))) v2" using Posix_simp by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
227 |
with a2(2) have "v1 = (snd (simp (der c r))) v2" using Posix_determ by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
228 |
with a2(1) a4 show "slexer r (c # s) = lexer r (c # s)" by (auto split: prod.split) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
229 |
next |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
230 |
case False |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
231 |
assume b1: "s \<notin> L (der c r)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
232 |
then have "lexer (der c r) s = None" using lexer_correct_None by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
233 |
moreover |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
234 |
from b1 have "s \<notin> L (fst (simp (der c r)))" using L_fst_simp[symmetric] by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
235 |
then have "lexer (fst (simp (der c r))) s = None" using lexer_correct_None by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
236 |
then have "slexer (fst (simp (der c r))) s = None" using IH by simp |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
237 |
ultimately show "slexer r (c # s) = lexer r (c # s)" |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
238 |
by (simp del: slexer.simps add: slexer_better_simp) |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
239 |
qed |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
240 |
qed |
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
241 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
242 |
|
f9cdc295ccf7
a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
243 |
unused_thms |
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 |
end |