author | Christian Urban <christian.urban@kcl.ac.uk> |
Sat, 07 Nov 2020 00:07:28 +0000 | |
changeset 800 | 9eea6a801e10 |
parent 209 | ad9b08267fa4 |
permissions | -rw-r--r-- |
209
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory MatcherNot |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports "Main" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
section {* Regular Expressions *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
datatype rexp = |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
NULL |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
| EMPTY |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
| CHAR char |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
| SEQ rexp rexp |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
| ALT rexp rexp |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
| STAR rexp |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
| NOT rexp |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
section {* Sequential Composition of Sets *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
definition |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
Seq :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
"A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
text {* Two Simple Properties about Sequential Composition *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
lemma seq_empty [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
shows "A ;; {[]} = A" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
and "{[]} ;; A = A" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
by (simp_all add: Seq_def) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
lemma seq_null [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
shows "A ;; {} = {}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
and "{} ;; A = {}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
by (simp_all add: Seq_def) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
section {* Kleene Star for Sets *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
inductive_set |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
for A :: "string set" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
start[intro]: "[] \<in> A\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
| step[intro]: "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
text {* A Standard Property of Star *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
lemma star_cases: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
shows "A\<star> = {[]} \<union> A ;; A\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
unfolding Seq_def |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
by (auto) (metis Star.simps) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
lemma star_decomp: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
assumes a: "c # x \<in> A\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
shows "\<exists>a b. x = a @ b \<and> c # a \<in> A \<and> b \<in> A\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
using a |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
by (induct x\<equiv>"c # x" rule: Star.induct) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
(auto simp add: append_eq_Cons_conv) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
section {* Semantics of Regular Expressions *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
L :: "rexp \<Rightarrow> string set" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
"L (NULL) = {}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
| "L (EMPTY) = {[]}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
| "L (CHAR c) = {[c]}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
| "L (SEQ r1 r2) = (L r1) ;; (L r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
| "L (ALT r1 r2) = (L r1) \<union> (L r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
| "L (STAR r) = (L r)\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
| "L (NOT r) = UNIV - (L r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
section {* The Matcher *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
nullable :: "rexp \<Rightarrow> bool" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
"nullable (NULL) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
| "nullable (EMPTY) = True" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
| "nullable (CHAR c) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
| "nullable (STAR r) = True" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
85 |
| "nullable (NOT r) = (\<not> nullable r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
86 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
noccurs :: "rexp \<Rightarrow> bool" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
"noccurs (NULL) = True" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
| "noccurs (EMPTY) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
| "noccurs (CHAR c) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
| "noccurs (ALT r1 r2) = (noccurs r1 \<or> noccurs r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
| "noccurs (SEQ r1 r2) = (noccurs r1 \<or> noccurs r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
| "noccurs (STAR r) = (noccurs r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
| "noccurs (NOT r) = (\<not>noccurs r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
lemma |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
"L r = {} \<Longrightarrow> noccurs r" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
100 |
apply(induct r) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
apply(auto simp add: Seq_def) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
oops |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
lemma |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
"\<not> noccurs r \<Longrightarrow> L r \<noteq> {}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
apply(induct r) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
107 |
apply(auto simp add: Seq_def) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
oops |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
der :: "char \<Rightarrow> rexp \<Rightarrow> rexp" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
"der c (NULL) = NULL" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
| "der c (EMPTY) = NULL" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
| "der c (CHAR c') = (if c = c' then EMPTY else NULL)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
| "der c (SEQ r1 r2) = ALT (SEQ (der c r1) r2) (if nullable r1 then der c r2 else NULL)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
| "der c (STAR r) = SEQ (der c r) (STAR r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
| "der c (NOT r) = NOT (der c r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
"ders [] r = r" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
| "ders (c # s) r = ders s (der c r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
129 |
matcher :: "rexp \<Rightarrow> string \<Rightarrow> bool" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
130 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
131 |
"matcher r s = nullable (ders s r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
132 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
133 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
section {* Correctness Proof of the Matcher *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
lemma nullable_correctness: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
shows "nullable r \<longleftrightarrow> [] \<in> (L r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
138 |
by (induct r) (auto simp add: Seq_def) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
139 |
section {* Left-Quotient of a Set *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
140 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
141 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
142 |
zeroable :: "rexp \<Rightarrow> bool" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
"zeroable (NULL) = True" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
| "zeroable (EMPTY) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
146 |
| "zeroable (CHAR c) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
147 |
| "zeroable (ALT r1 r2) = (zeroable r1 \<and> zeroable r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
| "zeroable (SEQ r1 r2) = (zeroable r1 \<or> zeroable r2)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
| "zeroable (STAR r) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
150 |
| "zeroable (NOT r) = ((nullable r))" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
152 |
lemma zeroable_correctness: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
153 |
shows "zeroable r \<longleftrightarrow> (L r = {})" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
apply(induct r) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
155 |
apply(auto simp add: Seq_def)[6] |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
156 |
apply(simp add: nullable_correctness) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
157 |
apply(auto) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
158 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
by (induct r) (auto simp add: Seq_def) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
section {* Left-Quotient of a Set *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
162 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
definition |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
165 |
Der :: "char \<Rightarrow> string set \<Rightarrow> string set" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
167 |
"Der c A \<equiv> {s. [c] @ s \<in> A}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
168 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
lemma Der_null [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
170 |
shows "Der c {} = {}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
171 |
unfolding Der_def |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
172 |
by auto |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
173 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
lemma Der_empty [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
shows "Der c {[]} = {}" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
176 |
unfolding Der_def |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
by auto |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
179 |
lemma Der_char [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
180 |
shows "Der c {[d]} = (if c = d then {[]} else {})" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
unfolding Der_def |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
182 |
by auto |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
183 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
184 |
lemma Der_union [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
185 |
shows "Der c (A \<union> B) = Der c A \<union> Der c B" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
186 |
unfolding Der_def |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
187 |
by auto |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
188 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
189 |
lemma Der_seq [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
190 |
shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
191 |
unfolding Der_def Seq_def |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
192 |
by (auto simp add: Cons_eq_append_conv) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
193 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
194 |
lemma Der_star [simp]: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
195 |
shows "Der c (A\<star>) = (Der c A) ;; A\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
proof - |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
198 |
by (simp only: star_cases[symmetric]) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
also have "... = Der c (A ;; A\<star>)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
200 |
by (simp only: Der_union Der_empty) (simp) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
201 |
also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
202 |
by simp |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
also have "... = (Der c A) ;; A\<star>" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
204 |
unfolding Seq_def Der_def |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
205 |
by (auto dest: star_decomp) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
206 |
finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" . |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
207 |
qed |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
209 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
210 |
lemma der_correctness: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
211 |
shows "L (der c r) = Der c (L r)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
212 |
by (induct r) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
213 |
(simp_all add: nullable_correctness) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
214 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
215 |
lemma matcher_correctness: |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
216 |
shows "matcher r s \<longleftrightarrow> s \<in> L r" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
217 |
by (induct s arbitrary: r) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
218 |
(simp_all add: nullable_correctness der_correctness Der_def) |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
220 |
section {* Examples *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
definition |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
223 |
"CHRA \<equiv> CHAR (CHR ''a'')" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
225 |
definition |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
226 |
"ALT1 \<equiv> ALT CHRA EMPTY" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
227 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
228 |
definition |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
229 |
"SEQ3 \<equiv> SEQ (SEQ ALT1 ALT1) ALT1" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
230 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
value "matcher SEQ3 ''aaa''" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
232 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
233 |
value "matcher NULL []" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
234 |
value "matcher (CHAR (CHR ''a'')) [CHR ''a'']" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
235 |
value "matcher (CHAR a) [a,a]" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
236 |
value "matcher (STAR (CHAR a)) []" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
237 |
value "matcher (STAR (CHAR a)) [a,a]" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
238 |
value "matcher (SEQ (CHAR (CHR ''a'')) (SEQ (STAR (CHAR (CHR ''b''))) (CHAR (CHR ''c'')))) ''abbbbc''" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
239 |
value "matcher (SEQ (CHAR (CHR ''a'')) (SEQ (STAR (CHAR (CHR ''b''))) (CHAR (CHR ''c'')))) ''abbcbbc''" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
240 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
section {* Incorrect Matcher - fun-definition rejected *} |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
242 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
243 |
fun |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
match :: "rexp list \<Rightarrow> string \<Rightarrow> bool" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
245 |
where |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
246 |
"match [] [] = True" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
247 |
| "match [] (c # s) = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
248 |
| "match (NULL # rs) s = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
249 |
| "match (EMPTY # rs) s = match rs s" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
250 |
| "match (CHAR c # rs) [] = False" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
251 |
| "match (CHAR c # rs) (d # s) = (if c = d then match rs s else False)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
252 |
| "match (ALT r1 r2 # rs) s = (match (r1 # rs) s \<or> match (r2 # rs) s)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
253 |
| "match (SEQ r1 r2 # rs) s = match (r1 # r2 # rs) s" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
| "match (STAR r # rs) s = (match rs s \<or> match (r # (STAR r) # rs) s)" |
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
256 |
|
ad9b08267fa4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
257 |
end |