Regular.thy
author urbanc
Tue, 31 May 2011 20:32:49 +0000
changeset 165 b04cc5e4e84c
permissions -rw-r--r--
added missing file
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
165
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     1
(* Author: Christian Urban, Xingyuan Zhang, Chunhan Wu *)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     2
theory Regular
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     3
imports Main Folds
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     4
begin
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     5
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     6
section {* Preliminary definitions *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     7
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     8
type_synonym lang = "string set"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
     9
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    10
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    11
text {*  Sequential composition of two languages *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    12
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    13
definition 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    14
  Seq :: "lang \<Rightarrow> lang \<Rightarrow> lang" (infixr "\<cdot>" 100)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    15
where 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    16
  "A \<cdot> B = {s\<^isub>1 @ s\<^isub>2 | s\<^isub>1 s\<^isub>2. s\<^isub>1 \<in> A \<and> s\<^isub>2 \<in> B}"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    17
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    18
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    19
text {* Some properties of operator @{text "\<cdot>"}. *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    20
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    21
lemma seq_add_left:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    22
  assumes a: "A = B"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    23
  shows "C \<cdot> A = C \<cdot> B"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    24
using a by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    25
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    26
lemma seq_union_distrib_right:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    27
  shows "(A \<union> B) \<cdot> C = (A \<cdot> C) \<union> (B \<cdot> C)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    28
unfolding Seq_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    29
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    30
lemma seq_union_distrib_left:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    31
  shows "C \<cdot> (A \<union> B) = (C \<cdot> A) \<union> (C \<cdot> B)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    32
unfolding Seq_def by  auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    33
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    34
lemma seq_intro:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    35
  assumes a: "x \<in> A" "y \<in> B"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    36
  shows "x @ y \<in> A \<cdot> B "
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    37
using a by (auto simp: Seq_def)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    38
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    39
lemma seq_assoc:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    40
  shows "(A \<cdot> B) \<cdot> C = A \<cdot> (B \<cdot> C)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    41
unfolding Seq_def
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    42
apply(auto)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    43
apply(blast)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    44
by (metis append_assoc)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    45
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    46
lemma seq_empty [simp]:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    47
  shows "A \<cdot> {[]} = A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    48
  and   "{[]} \<cdot> A = A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    49
by (simp_all add: Seq_def)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    50
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    51
lemma seq_null [simp]:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    52
  shows "A \<cdot> {} = {}"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    53
  and   "{} \<cdot> A = {}"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    54
by (simp_all add: Seq_def)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    55
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    56
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    57
text {* Power and Star of a language *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    58
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    59
fun 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    60
  pow :: "lang \<Rightarrow> nat \<Rightarrow> lang" (infixl "\<up>" 100)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    61
where
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    62
  "A \<up> 0 = {[]}"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    63
| "A \<up> (Suc n) =  A \<cdot> (A \<up> n)" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    64
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    65
definition
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    66
  Star :: "lang \<Rightarrow> lang" ("_\<star>" [101] 102)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    67
where
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    68
  "A\<star> \<equiv> (\<Union>n. A \<up> n)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    69
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    70
lemma star_start[intro]:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    71
  shows "[] \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    72
proof -
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    73
  have "[] \<in> A \<up> 0" by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    74
  then show "[] \<in> A\<star>" unfolding Star_def by blast
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    75
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    76
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    77
lemma star_step [intro]:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    78
  assumes a: "s1 \<in> A" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    79
  and     b: "s2 \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    80
  shows "s1 @ s2 \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    81
proof -
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    82
  from b obtain n where "s2 \<in> A \<up> n" unfolding Star_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    83
  then have "s1 @ s2 \<in> A \<up> (Suc n)" using a by (auto simp add: Seq_def)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    84
  then show "s1 @ s2 \<in> A\<star>" unfolding Star_def by blast
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    85
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    86
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    87
lemma star_induct[consumes 1, case_names start step]:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    88
  assumes a: "x \<in> A\<star>" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    89
  and     b: "P []"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    90
  and     c: "\<And>s1 s2. \<lbrakk>s1 \<in> A; s2 \<in> A\<star>; P s2\<rbrakk> \<Longrightarrow> P (s1 @ s2)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    91
  shows "P x"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    92
proof -
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    93
  from a obtain n where "x \<in> A \<up> n" unfolding Star_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    94
  then show "P x"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    95
    by (induct n arbitrary: x)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    96
       (auto intro!: b c simp add: Seq_def Star_def)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    97
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    98
    
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
    99
lemma star_intro1:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   100
  assumes a: "x \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   101
  and     b: "y \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   102
  shows "x @ y \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   103
using a b
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   104
by (induct rule: star_induct) (auto)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   105
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   106
lemma star_intro2: 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   107
  assumes a: "y \<in> A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   108
  shows "y \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   109
proof -
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   110
  from a have "y @ [] \<in> A\<star>" by blast
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   111
  then show "y \<in> A\<star>" by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   112
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   113
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   114
lemma star_intro3:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   115
  assumes a: "x \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   116
  and     b: "y \<in> A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   117
  shows "x @ y \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   118
using a b by (blast intro: star_intro1 star_intro2)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   119
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   120
lemma star_cases:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   121
  shows "A\<star> =  {[]} \<union> A \<cdot> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   122
proof
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   123
  { fix x
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   124
    have "x \<in> A\<star> \<Longrightarrow> x \<in> {[]} \<union> A \<cdot> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   125
      unfolding Seq_def
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   126
    by (induct rule: star_induct) (auto)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   127
  }
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   128
  then show "A\<star> \<subseteq> {[]} \<union> A \<cdot> A\<star>" by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   129
next
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   130
  show "{[]} \<union> A \<cdot> A\<star> \<subseteq> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   131
    unfolding Seq_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   132
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   133
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   134
lemma star_decom: 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   135
  assumes a: "x \<in> A\<star>" "x \<noteq> []"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   136
  shows "\<exists>a b. x = a @ b \<and> a \<noteq> [] \<and> a \<in> A \<and> b \<in> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   137
using a
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   138
by (induct rule: star_induct) (blast)+
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   139
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   140
lemma seq_Union_left: 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   141
  shows "B \<cdot> (\<Union>n. A \<up> n) = (\<Union>n. B \<cdot> (A \<up> n))"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   142
unfolding Seq_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   143
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   144
lemma seq_Union_right: 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   145
  shows "(\<Union>n. A \<up> n) \<cdot> B = (\<Union>n. (A \<up> n) \<cdot> B)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   146
unfolding Seq_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   147
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   148
lemma seq_pow_comm:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   149
  shows "A \<cdot> (A \<up> n) = (A \<up> n) \<cdot> A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   150
by (induct n) (simp_all add: seq_assoc[symmetric])
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   151
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   152
lemma seq_star_comm:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   153
  shows "A \<cdot> A\<star> = A\<star> \<cdot> A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   154
unfolding Star_def seq_Union_left
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   155
unfolding seq_pow_comm seq_Union_right 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   156
by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   157
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   158
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   159
text {* Two lemmas about the length of strings in @{text "A \<up> n"} *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   160
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   161
lemma pow_length:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   162
  assumes a: "[] \<notin> A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   163
  and     b: "s \<in> A \<up> Suc n"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   164
  shows "n < length s"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   165
using b
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   166
proof (induct n arbitrary: s)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   167
  case 0
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   168
  have "s \<in> A \<up> Suc 0" by fact
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   169
  with a have "s \<noteq> []" by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   170
  then show "0 < length s" by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   171
next
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   172
  case (Suc n)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   173
  have ih: "\<And>s. s \<in> A \<up> Suc n \<Longrightarrow> n < length s" by fact
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   174
  have "s \<in> A \<up> Suc (Suc n)" by fact
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   175
  then obtain s1 s2 where eq: "s = s1 @ s2" and *: "s1 \<in> A" and **: "s2 \<in> A \<up> Suc n"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   176
    by (auto simp add: Seq_def)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   177
  from ih ** have "n < length s2" by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   178
  moreover have "0 < length s1" using * a by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   179
  ultimately show "Suc n < length s" unfolding eq 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   180
    by (simp only: length_append)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   181
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   182
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   183
lemma seq_pow_length:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   184
  assumes a: "[] \<notin> A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   185
  and     b: "s \<in> B \<cdot> (A \<up> Suc n)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   186
  shows "n < length s"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   187
proof -
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   188
  from b obtain s1 s2 where eq: "s = s1 @ s2" and *: "s2 \<in> A \<up> Suc n"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   189
    unfolding Seq_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   190
  from * have " n < length s2" by (rule pow_length[OF a])
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   191
  then show "n < length s" using eq by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   192
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   193
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   194
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   195
section {* A modified version of Arden's lemma *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   196
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   197
text {*  A helper lemma for Arden *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   198
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   199
lemma arden_helper:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   200
  assumes eq: "X = X \<cdot> A \<union> B"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   201
  shows "X = X \<cdot> (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A \<up> m))"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   202
proof (induct n)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   203
  case 0 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   204
  show "X = X \<cdot> (A \<up> Suc 0) \<union> (\<Union>(m::nat)\<in>{0..0}. B \<cdot> (A \<up> m))"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   205
    using eq by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   206
next
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   207
  case (Suc n)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   208
  have ih: "X = X \<cdot> (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A \<up> m))" by fact
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   209
  also have "\<dots> = (X \<cdot> A \<union> B) \<cdot> (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A \<up> m))" using eq by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   210
  also have "\<dots> = X \<cdot> (A \<up> Suc (Suc n)) \<union> (B \<cdot> (A \<up> Suc n)) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A \<up> m))"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   211
    by (simp add: seq_union_distrib_right seq_assoc)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   212
  also have "\<dots> = X \<cdot> (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B \<cdot> (A \<up> m))"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   213
    by (auto simp add: le_Suc_eq)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   214
  finally show "X = X \<cdot> (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B \<cdot> (A \<up> m))" .
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   215
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   216
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   217
theorem arden:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   218
  assumes nemp: "[] \<notin> A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   219
  shows "X = X \<cdot> A \<union> B \<longleftrightarrow> X = B \<cdot> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   220
proof
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   221
  assume eq: "X = B \<cdot> A\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   222
  have "A\<star> = {[]} \<union> A\<star> \<cdot> A" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   223
    unfolding seq_star_comm[symmetric]
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   224
    by (rule star_cases)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   225
  then have "B \<cdot> A\<star> = B \<cdot> ({[]} \<union> A\<star> \<cdot> A)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   226
    by (rule seq_add_left)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   227
  also have "\<dots> = B \<union> B \<cdot> (A\<star> \<cdot> A)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   228
    unfolding seq_union_distrib_left by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   229
  also have "\<dots> = B \<union> (B \<cdot> A\<star>) \<cdot> A" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   230
    by (simp only: seq_assoc)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   231
  finally show "X = X \<cdot> A \<union> B" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   232
    using eq by blast 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   233
next
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   234
  assume eq: "X = X \<cdot> A \<union> B"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   235
  { fix n::nat
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   236
    have "B \<cdot> (A \<up> n) \<subseteq> X" using arden_helper[OF eq, of "n"] by auto }
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   237
  then have "B \<cdot> A\<star> \<subseteq> X" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   238
    unfolding Seq_def Star_def UNION_def by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   239
  moreover
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   240
  { fix s::string
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   241
    obtain k where "k = length s" by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   242
    then have not_in: "s \<notin> X \<cdot> (A \<up> Suc k)" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   243
      using seq_pow_length[OF nemp] by blast
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   244
    assume "s \<in> X"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   245
    then have "s \<in> X \<cdot> (A \<up> Suc k) \<union> (\<Union>m\<in>{0..k}. B \<cdot> (A \<up> m))"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   246
      using arden_helper[OF eq, of "k"] by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   247
    then have "s \<in> (\<Union>m\<in>{0..k}. B \<cdot> (A \<up> m))" using not_in by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   248
    moreover
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   249
    have "(\<Union>m\<in>{0..k}. B \<cdot> (A \<up> m)) \<subseteq> (\<Union>n. B \<cdot> (A \<up> n))" by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   250
    ultimately 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   251
    have "s \<in> B \<cdot> A\<star>" 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   252
      unfolding seq_Union_left Star_def by auto }
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   253
  then have "X \<subseteq> B \<cdot> A\<star>" by auto
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   254
  ultimately 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   255
  show "X = B \<cdot> A\<star>" by simp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   256
qed
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   257
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   258
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   259
section {* Regular Expressions *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   260
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   261
datatype rexp =
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   262
  NULL
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   263
| EMPTY
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   264
| CHAR char
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   265
| SEQ rexp rexp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   266
| ALT rexp rexp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   267
| STAR rexp
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   268
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   269
fun
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   270
  L_rexp :: "rexp \<Rightarrow> lang"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   271
where
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   272
    "L_rexp (NULL) = {}"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   273
  | "L_rexp (EMPTY) = {[]}"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   274
  | "L_rexp (CHAR c) = {[c]}"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   275
  | "L_rexp (SEQ r1 r2) = (L_rexp r1) \<cdot> (L_rexp r2)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   276
  | "L_rexp (ALT r1 r2) = (L_rexp r1) \<union> (L_rexp r2)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   277
  | "L_rexp (STAR r) = (L_rexp r)\<star>"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   278
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   279
text {* ALT-combination for a set of regular expressions *}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   280
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   281
abbreviation
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   282
  Setalt  ("\<Uplus>_" [1000] 999) 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   283
where
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   284
  "\<Uplus>A \<equiv> folds ALT NULL A"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   285
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   286
text {* 
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   287
  For finite sets, @{term Setalt} is preserved under @{term L_exp}.
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   288
*}
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   289
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   290
lemma folds_alt_simp [simp]:
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   291
  fixes rs::"rexp set"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   292
  assumes a: "finite rs"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   293
  shows "L_rexp (\<Uplus>rs) = \<Union> (L_rexp ` rs)"
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   294
unfolding folds_def
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   295
apply(rule set_eqI)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   296
apply(rule someI2_ex)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   297
apply(rule_tac finite_imp_fold_graph[OF a])
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   298
apply(erule fold_graph.induct)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   299
apply(auto)
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   300
done
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   301
b04cc5e4e84c added missing file
urbanc
parents:
diff changeset
   302
end