thys/RegLangs.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 24 Oct 2020 12:13:39 +0100
changeset 359 fedc16924b76
parent 314 20a57552d722
child 361 8bb064045b4e
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
   
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
     2
theory RegLangs
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     3
  imports Main "~~/src/HOL/Library/Sublist"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
section {* Sequential Composition of Languages *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
definition
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
where 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  "A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
text {* Two Simple Properties about Sequential Composition *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
lemma Sequ_empty_string [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  shows "A ;; {[]} = A"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  and   "{[]} ;; A = A"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
by (simp_all add: Sequ_def)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
lemma Sequ_empty [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  shows "A ;; {} = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  and   "{} ;; A = {}"
359
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    23
  by (simp_all add: Sequ_def)
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    24
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    25
lemma
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    26
  shows "(A \<union> B) ;; C = (A ;; C) \<union> (B ;; C)"
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    27
  apply(auto simp add: Sequ_def)  
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    28
  done
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
359
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    30
lemma
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    31
  shows "(A \<inter> B) ;; C \<subseteq> (A ;; C) \<inter> (B ;; C)"
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    32
  apply(auto simp add: Sequ_def) 
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    33
  done
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    34
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    35
lemma
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    36
  shows "(A ;; C) \<inter> (B ;; C) \<subseteq> (A \<inter> B) ;; C"
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    37
  apply(auto simp add: Sequ_def) 
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 314
diff changeset
    38
  oops
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
section {* Semantic Derivative (Left Quotient) of Languages *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
definition
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  Der :: "char \<Rightarrow> string set \<Rightarrow> string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  "Der c A \<equiv> {s. c # s \<in> A}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
definition
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  Ders :: "string \<Rightarrow> string set \<Rightarrow> string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  "Ders s A \<equiv> {s'. s @ s' \<in> A}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
lemma Der_null [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  shows "Der c {} = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
lemma Der_empty [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  shows "Der c {[]} = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
lemma Der_char [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  shows "Der c {[d]} = (if c = d then {[]} else {})"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
lemma Der_union [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  shows "Der c (A \<union> B) = Der c A \<union> Der c B"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
lemma Der_Sequ [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
unfolding Der_def Sequ_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
by (auto simp add: Cons_eq_append_conv)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
section {* Kleene Star for Languages *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
inductive_set
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  for A :: "string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  start[intro]: "[] \<in> A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
| step[intro]:  "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
(* Arden's lemma *)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
lemma Star_cases:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  shows "A\<star> = {[]} \<union> A ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
unfolding Sequ_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
by (auto) (metis Star.simps)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
lemma Star_decomp: 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  assumes "c # x \<in> A\<star>" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
using assms
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
by (induct x\<equiv>"c # x" rule: Star.induct) 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
   (auto simp add: append_eq_Cons_conv)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
lemma Star_Der_Sequ: 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  shows "Der c (A\<star>) \<subseteq> (Der c A) ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
unfolding Der_def Sequ_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
by(auto simp add: Star_decomp)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
lemma Der_star [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  shows "Der c (A\<star>) = (Der c A) ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
proof -    
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)"  
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
    by (simp only: Star_cases[symmetric])
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  also have "... = Der c (A ;; A\<star>)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
    by (simp only: Der_union Der_empty) (simp)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
    by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  also have "... =  (Der c A) ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
    using Star_Der_Sequ by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" .
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
qed
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   121
lemma Star_concat:
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   122
  assumes "\<forall>s \<in> set ss. s \<in> A"  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   123
  shows "concat ss \<in> A\<star>"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   124
using assms by (induct ss) (auto)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   125
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   126
lemma Star_split:
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   127
  assumes "s \<in> A\<star>"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   128
  shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   129
using assms
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   130
  apply(induct rule: Star.induct)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   131
  using concat.simps(1) apply fastforce
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   132
  apply(clarify)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   133
  by (metis append_Nil concat.simps(2) set_ConsD)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   134
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   135
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
section {* Regular Expressions *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
datatype rexp =
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  ZERO
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
| ONE
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
| CHAR char
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
| SEQ rexp rexp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
| ALT rexp rexp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
| STAR rexp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
section {* Semantics of Regular Expressions *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
fun
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  L :: "rexp \<Rightarrow> string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
  "L (ZERO) = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
| "L (ONE) = {[]}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
| "L (CHAR c) = {[c]}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
| "L (SEQ r1 r2) = (L r1) ;; (L r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
| "L (ALT r1 r2) = (L r1) \<union> (L r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
| "L (STAR r) = (L r)\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
section {* Nullable, Derivatives *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
fun
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
 nullable :: "rexp \<Rightarrow> bool"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  "nullable (ZERO) = False"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
| "nullable (ONE) = True"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
| "nullable (CHAR c) = False"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
| "nullable (STAR r) = True"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
fun
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  "der c (ZERO) = ZERO"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
| "der c (ONE) = ZERO"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
| "der c (CHAR d) = (if c = d then ONE else ZERO)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
| "der c (SEQ r1 r2) = 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
     (if nullable r1
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
      then ALT (SEQ (der c r1) r2) (der c r2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
      else SEQ (der c r1) r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
| "der c (STAR r) = SEQ (der c r) (STAR r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
fun 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  "ders [] r = r"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
| "ders (c # s) r = ders s (der c r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
lemma nullable_correctness:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  shows "nullable r  \<longleftrightarrow> [] \<in> (L r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
by (induct r) (auto simp add: Sequ_def) 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
lemma der_correctness:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  shows "L (der c r) = Der c (L r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
by (induct r) (simp_all add: nullable_correctness)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
lemma ders_correctness:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  shows "L (ders s r) = Ders s (L r)"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   203
  by (induct s arbitrary: r)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   204
     (simp_all add: Ders_def der_correctness Der_def)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   205
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   206
lemma ders_append:
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   207
  shows "ders (s1 @ s2) r = ders s2 (ders s1 r)"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   208
  by (induct s1 arbitrary: s2 r) (auto)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   209
314
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   210
lemma ders_snoc:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   211
  shows "ders (s @ [c]) r = der c (ders s r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   212
  by (simp add: ders_append)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   213
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
end