progs/Matcher2.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 04 Oct 2016 12:00:23 +0100
changeset 440 e14cd32ad497
parent 397 cf3ca219c727
child 455 1dbf84ade62c
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
397
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
     1
theory Matcher2
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
  imports "Main" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
355
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
     5
lemma Suc_Union:
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
     6
  "(\<Union> x\<le>Suc m. B x) = (B (Suc m) \<union> (\<Union> x\<le>m. B x))"
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
     7
by (metis UN_insert atMost_Suc)
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
     8
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
     9
lemma Suc_reduce_Union:
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    10
  "(\<Union>x\<in>{Suc n..Suc m}. B x) = (\<Union>x\<in>{n..m}. B (Suc x))"
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    11
by (metis UN_extend_simps(10) image_Suc_atLeastAtMost)
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    12
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    13
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
section {* Regular Expressions *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
datatype rexp =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  NULL
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
| EMPTY
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
| CHAR char
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
| SEQ rexp rexp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
| ALT rexp rexp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
| STAR rexp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
| NOT rexp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
| PLUS rexp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
| OPT rexp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
| NTIMES rexp nat
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 361
diff changeset
    27
| NMTIMES rexp nat nat
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 361
diff changeset
    28
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 361
diff changeset
    29
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
section {* Sequential Composition of Sets *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
definition
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
  Seq :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
where 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  "A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
text {* Two Simple Properties about Sequential Composition *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
lemma seq_empty [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  shows "A ;; {[]} = A"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  and   "{[]} ;; A = A"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
by (simp_all add: Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
lemma seq_null [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  shows "A ;; {} = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  and   "{} ;; A = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
by (simp_all add: Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
lemma seq_union:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  shows "A ;; (B \<union> C) = A ;; B \<union> A ;; C"
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    51
  and   "(B \<union> C) ;; A = B ;; A \<union> C ;; A"
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
by (auto simp add: Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
lemma seq_Union:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  shows "A ;; (\<Union>x\<in>B. C x) = (\<Union>x\<in>B. A ;; C x)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
by (auto simp add: Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
lemma seq_empty_in [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  "[] \<in> A ;; B \<longleftrightarrow> ([] \<in> A \<and> [] \<in> B)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
by (simp add: Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    62
lemma seq_assoc: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    63
  shows "A ;; (B ;; C) = (A ;; B) ;; C" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    64
apply(auto simp add: Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    65
apply(metis append_assoc)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    66
apply(metis)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    67
done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    68
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    70
section {* Power for Sets *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    71
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    72
fun 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    73
  pow :: "string set \<Rightarrow> nat \<Rightarrow> string set" ("_ \<up> _" [101, 102] 101)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    74
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    75
   "A \<up> 0 = {[]}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    76
|  "A \<up> (Suc n) = A ;; (A \<up> n)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    78
lemma pow_empty [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    79
  shows "[] \<in> A \<up> n \<longleftrightarrow> (n = 0 \<or> [] \<in> A)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    80
by (induct n) (auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    81
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    82
lemma pow_plus:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    83
  "A \<up> (n + m) = A \<up> n ;; A \<up> m"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    84
by (induct n) (simp_all add: seq_assoc)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    85
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
section {* Kleene Star for Sets *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
inductive_set
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
  Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
  for A :: "string set"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
  start[intro]: "[] \<in> A\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
| step[intro]:  "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
text {* A Standard Property of Star *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
lemma star_decomp: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
  assumes a: "c # x \<in> A\<star>" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  shows "\<exists>a b. x = a @ b \<and> c # a \<in> A \<and> b \<in> A\<star>"
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   100
using a 
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
using a
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
by (induct x\<equiv>"c # x" rule: Star.induct) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
   (auto simp add: append_eq_Cons_conv)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   105
lemma star_cases:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   106
  shows "A\<star> = {[]} \<union> A ;; A\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   107
unfolding Seq_def 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   108
by (auto) (metis Star.simps)
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   110
lemma Star_in_Pow:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   111
  assumes a: "s \<in> A\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   112
  shows "\<exists>n. s \<in> A \<up> n"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   113
using a
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   114
apply(induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   115
apply(auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   116
apply(rule_tac x="Suc n" in exI)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   117
apply(auto simp add: Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   118
done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   119
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   120
lemma Pow_in_Star:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   121
  assumes a: "s \<in> A \<up> n"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   122
  shows "s \<in> A\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   123
using a
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   124
by (induct n arbitrary: s) (auto simp add: Seq_def)
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   127
lemma Star_def2: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   128
  shows "A\<star> = (\<Union>n. A \<up> n)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   129
using Star_in_Pow Pow_in_Star
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   130
by (auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   131
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
section {* Semantics of Regular Expressions *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
fun
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
  L :: "rexp \<Rightarrow> string set"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
  "L (NULL) = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
| "L (EMPTY) = {[]}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
| "L (CHAR c) = {[c]}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
| "L (SEQ r1 r2) = (L r1) ;; (L r2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
| "L (ALT r1 r2) = (L r1) \<union> (L r2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
| "L (STAR r) = (L r)\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
| "L (NOT r) = UNIV - (L r)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
| "L (PLUS r) = (L r) ;; ((L r)\<star>)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
| "L (OPT r) = (L r) \<union> {[]}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
| "L (NTIMES r n) = (L r) \<up> n"
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 361
diff changeset
   149
| "L (NMTIMES r n m) = (\<Union>i\<in> {n..m} . ((L r) \<up> i))" 
355
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   150
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
227
93bd75031ced added handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   152
lemma "L (NOT NULL) = UNIV"
93bd75031ced added handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   153
apply(simp)
93bd75031ced added handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   154
done
93bd75031ced added handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   155
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
section {* The Matcher *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
fun
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
 nullable :: "rexp \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
  "nullable (NULL) = False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
| "nullable (EMPTY) = True"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
| "nullable (CHAR c) = False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
| "nullable (STAR r) = True"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
| "nullable (NOT r) = (\<not>(nullable r))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
| "nullable (PLUS r) = (nullable r)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
| "nullable (OPT r) = True"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
| "nullable (NTIMES r n) = (if n = 0 then True else nullable r)"
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 361
diff changeset
   171
| "nullable (NMTIMES r n m) = (if m < n then False else (if n = 0 then True else nullable r))"
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
   172
397
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   173
fun M :: "rexp \<Rightarrow> nat"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   174
where
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   175
  "M (NULL) = 0"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   176
| "M (EMPTY) = 0"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   177
| "M (CHAR char) = 0"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   178
| "M (SEQ r1 r2) = Suc ((M r1) + (M r2))"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   179
| "M (ALT r1 r2) = Suc ((M r1) + (M r2))"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   180
| "M (STAR r) = Suc (M r)"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   181
| "M (NOT r) = Suc (M r)"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   182
| "M (PLUS r) = Suc (M r)"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   183
| "M (OPT r) = Suc (M r)"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   184
| "M (NTIMES r n) = Suc (M r) * 2 * (Suc n)"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   185
| "M (NMTIMES r n m) = Suc (Suc (M r)) * 2 * (Suc m) * (Suc (Suc m) - Suc n)"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   186
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   187
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
   188
function der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
  "der c (NULL) = NULL"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
| "der c (EMPTY) = NULL"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
| "der c (CHAR d) = (if c = d then EMPTY else NULL)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
| "der c (SEQ r1 r2) = ALT (SEQ (der c r1) r2) (if nullable r1 then der c r2 else NULL)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
| "der c (STAR r) = SEQ (der c r) (STAR r)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
| "der c (NOT r) = NOT(der c r)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
| "der c (PLUS r) = SEQ (der c r) (STAR r)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
| "der c (OPT r) = der c r"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
| "der c (NTIMES r 0) = NULL"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
| "der c (NTIMES r (Suc n)) = der c (SEQ r (NTIMES r n))"
363
0d6deecdb2eb updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   201
| "der c (NMTIMES r n m) = 
397
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   202
        (if m < n then NULL else 
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   203
        (if n = m then der c (NTIMES r n) else
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   204
                       ALT (der c (NTIMES r n)) (der c (NMTIMES r (Suc n) m))))"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   205
by pat_completeness auto
363
0d6deecdb2eb updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   206
397
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   207
lemma bigger1:
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   208
  "\<lbrakk>c < (d::nat); a < b; 0 < a; 0 < c\<rbrakk> \<Longrightarrow> c * a < d * b"
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   209
by (metis le0 mult_strict_mono')
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
termination der 
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
   212
apply(relation "measure (\<lambda>(c, r). M r)") 
397
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   213
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   214
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   215
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   216
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   217
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   218
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   219
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   220
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   221
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   222
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   223
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   224
apply(simp_all del: M.simps)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   225
apply(simp_all only: M.simps)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   226
defer
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   227
apply(subgoal_tac "Suc (Suc m) - Suc (Suc n) < Suc (Suc m) - Suc n")
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   228
prefer 2
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   229
apply(auto)[1]
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   230
apply (metis Suc_mult_less_cancel1 mult.assoc numeral_eq_Suc)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   231
apply(subgoal_tac "0 < (Suc (Suc m) - Suc n)")
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   232
prefer 2
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   233
apply(auto)[1]
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   234
apply(subgoal_tac "Suc n < Suc m")
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   235
prefer 2
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   236
apply(auto)[1]
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   237
apply(subgoal_tac "Suc (M r) * 2 * Suc n < Suc (Suc (M r)) * 2 * Suc m")
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   238
prefer 2
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   239
apply(subgoal_tac "Suc (M r) * 2 < Suc (Suc (M r)) * 2")
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   240
prefer 2
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   241
apply(auto)[1]
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   242
apply(rule bigger1)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   243
apply(assumption)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   244
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   245
apply (metis zero_less_Suc)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   246
apply (metis mult_is_0 neq0_conv old.nat.distinct(2))
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   247
apply(rotate_tac 4)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   248
apply(drule_tac a="1" and b="(Suc (Suc m) - Suc n)" in bigger1)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   249
prefer 4
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   250
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   251
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   252
apply (metis zero_less_one)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   253
apply(simp)
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   254
done
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
fun 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  "ders [] r = r"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
| "ders (c # s) r = ders s (der c r)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
fun
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
  matcher :: "rexp \<Rightarrow> string \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
  "matcher r s = nullable (ders s r)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
section {* Correctness Proof of the Matcher *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
lemma nullable_correctness:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
  shows "nullable r  \<longleftrightarrow> [] \<in> (L r)"
355
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   272
apply(induct r) 
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   273
apply(auto simp add: Seq_def) 
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   274
done
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
section {* Left-Quotient of a Set *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
definition
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
  Der :: "char \<Rightarrow> string set \<Rightarrow> string set"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
  "Der c A \<equiv> {s. [c] @ s \<in> A}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
lemma Der_null [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
  shows "Der c {} = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
unfolding Der_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
lemma Der_empty [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
  shows "Der c {[]} = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
unfolding Der_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
lemma Der_char [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
  shows "Der c {[d]} = (if c = d then {[]} else {})"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
unfolding Der_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
lemma Der_union [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
  shows "Der c (A \<union> B) = Der c A \<union> Der c B"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
unfolding Der_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
lemma Der_insert_nil [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
  shows "Der c (insert [] A) = Der c A"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
unfolding Der_def 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
by auto 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
lemma Der_seq [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
  shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
unfolding Der_def Seq_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
by (auto simp add: Cons_eq_append_conv)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
lemma Der_star [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
  shows "Der c (A\<star>) = (Der c A) ;; A\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
proof -    
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
  have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
    by (simp only: star_cases[symmetric])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
  also have "... = Der c (A ;; A\<star>)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
    by (simp only: Der_union Der_empty) (simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
  also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
    by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
  also have "... =  (Der c A) ;; A\<star>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
    unfolding Seq_def Der_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
    by (auto dest: star_decomp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
  finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
lemma Der_UNIV [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
  "Der c (UNIV - A) = UNIV - Der c A"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
unfolding Der_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
by (auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
lemma Der_pow [simp]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
  shows "Der c (A \<up> (Suc n)) = (Der c A) ;; (A \<up> n) \<union> (if [] \<in> A then Der c (A \<up> n) else {})"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
unfolding Der_def 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
by(auto simp add: Cons_eq_append_conv Seq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
lemma Der_UNION [simp]: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
  shows "Der c (\<Union>x\<in>A. B x) = (\<Union>x\<in>A. Der c (B x))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
by (auto simp add: Der_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
363
0d6deecdb2eb updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   342
lemma der_correctness:
0d6deecdb2eb updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   343
  shows "L (der c r) = Der c (L r)"
0d6deecdb2eb updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   344
apply(induct rule: der.induct) 
0d6deecdb2eb updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   345
apply(simp_all add: nullable_correctness 
0d6deecdb2eb updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   346
    Suc_Union Suc_reduce_Union seq_Union atLeast0AtMost)
397
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   347
apply(rule impI)+
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   348
apply(subgoal_tac "{n..m} = {n} \<union> {Suc n..m}")
355
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   349
apply(auto)
397
cf3ca219c727 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 385
diff changeset
   350
done
191
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
lemma matcher_correctness:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
  shows "matcher r s \<longleftrightarrow> s \<in> L r"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
by (induct s arbitrary: r)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
   (simp_all add: nullable_correctness der_correctness Der_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
end