author | Christian Urban <urbanc@in.tum.de> |
Mon, 24 Sep 2018 11:05:39 +0100 | |
changeset 558 | 447ed6c7cdad |
parent 495 | 7d9d86dc7aa0 |
child 882 | 5fcad75ade92 |
permissions | -rw-r--r-- |
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory Matcher |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports "Main" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
208
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
167
diff
changeset
|
5 |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
section {* Regular Expressions *} |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
datatype rexp = |
495 | 9 |
ZERO |
10 |
| ONE |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
| CHAR char |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
| SEQ rexp rexp |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
| ALT rexp rexp |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
| STAR rexp |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
section {* Sequential Composition of Sets *} |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
definition |
cfba674a8fdf
added matcher
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) |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
where |
cfba674a8fdf
added matcher
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}" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
text {* Two Simple Properties about Sequential Composition *} |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
lemma seq_empty [simp]: |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
shows "A ;; {[]} = A" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
and "{[]} ;; A = A" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
by (simp_all add: Seq_def) |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
lemma seq_null [simp]: |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
shows "A ;; {} = {}" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
and "{} ;; A = {}" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
by (simp_all add: Seq_def) |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
section {* Kleene Star for Sets *} |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
inductive_set |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102) |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
for A :: "string set" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
where |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
start[intro]: "[] \<in> A\<star>" |
cfba674a8fdf
added matcher
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>" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
text {* A Standard Property of Star *} |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
lemma star_cases: |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
shows "A\<star> = {[]} \<union> A ;; A\<star>" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
unfolding Seq_def |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
by (auto) (metis Star.simps) |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
lemma star_decomp: |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
assumes a: "c # x \<in> A\<star>" |
cfba674a8fdf
added matcher
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>" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
using a |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
by (induct x\<equiv>"c # x" rule: Star.induct) |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
(auto simp add: append_eq_Cons_conv) |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
section {* Semantics of Regular Expressions *} |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
fun |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
L :: "rexp \<Rightarrow> string set" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
where |
495 | 66 |
"L (ZERO) = {}" |
67 |
| "L (ONE) = {[]}" |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
| "L (CHAR c) = {[c]}" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
| "L (SEQ r1 r2) = (L r1) ;; (L r2)" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
| "L (ALT r1 r2) = (L r1) \<union> (L r2)" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
| "L (STAR r) = (L r)\<star>" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
section {* The Matcher *} |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
fun |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
nullable :: "rexp \<Rightarrow> bool" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
where |
495 | 78 |
"nullable (ZERO) = False" |
79 |
| "nullable (ONE) = True" |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
| "nullable (CHAR c) = False" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
| "nullable (STAR r) = True" |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
|
208
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
167
diff
changeset
|
85 |
|
495 | 86 |
section {* Correctness Proof for Nullable *} |
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
lemma nullable_correctness: |
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
shows "nullable r \<longleftrightarrow> [] \<in> (L r)" |
208
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
167
diff
changeset
|
90 |
apply(induct r) |
495 | 91 |
(* ZERO case *) |
92 |
apply(simp only: nullable.simps) |
|
93 |
apply(simp only: L.simps) |
|
94 |
apply(simp) |
|
95 |
(* ONE case *) |
|
96 |
apply(simp only: nullable.simps) |
|
97 |
apply(simp only: L.simps) |
|
98 |
apply(simp) |
|
99 |
(* CHAR case *) |
|
100 |
apply(simp only: nullable.simps) |
|
101 |
apply(simp only: L.simps) |
|
102 |
apply(simp) |
|
103 |
prefer 2 |
|
104 |
(* ALT case *) |
|
105 |
apply(simp (no_asm) only: nullable.simps) |
|
106 |
apply(simp only:) |
|
107 |
apply(simp only: L.simps) |
|
108 |
apply(simp) |
|
109 |
(* SEQ case *) |
|
110 |
oops |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
|
495 | 112 |
lemma nullable_correctness: |
113 |
shows "nullable r \<longleftrightarrow> [] \<in> (L r)" |
|
114 |
apply(induct r) |
|
115 |
apply(simp_all) |
|
116 |
(* all easy subgoals are proved except the last 2 *) |
|
117 |
(* where the definition of Seq needs to be unfolded. *) |
|
118 |
oops |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
|
495 | 120 |
lemma nullable_correctness: |
121 |
shows "nullable r \<longleftrightarrow> [] \<in> (L r)" |
|
122 |
apply(induct r) |
|
123 |
apply(simp_all add: Seq_def) |
|
124 |
(* except the star case every thing is proved *) |
|
125 |
(* we need to use the rule for Star.start *) |
|
126 |
oops |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
|
495 | 128 |
lemma nullable_correctness: |
129 |
shows "nullable r \<longleftrightarrow> [] \<in> (L r)" |
|
130 |
apply(induct r) |
|
131 |
apply(simp_all add: Seq_def Star.start) |
|
132 |
done |
|
167
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
133 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
|
cfba674a8fdf
added matcher
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
end |