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