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