Closure.thy
author urbanc
Thu, 02 Jun 2011 16:44:35 +0000
changeset 166 7743d2ad71d1
parent 162 e93760534354
permissions -rw-r--r--
updated theories and itp-paper
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
     1
(* Author: Christian Urban, Xingyuan Zhang, Chunhan Wu *)
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
     2
theory Closure
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
     3
imports Derivs
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
     4
begin
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
     5
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
     6
section {* Closure properties of regular languages *}
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
     7
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
     8
abbreviation
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
     9
  regular :: "lang \<Rightarrow> bool"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    10
where
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    11
  "regular A \<equiv> \<exists>r. A = L_rexp r"
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    12
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    13
subsection {* Closure under set operations *}
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    14
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    15
lemma closure_union[intro]:
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    16
  assumes "regular A" "regular B" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    17
  shows "regular (A \<union> B)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    18
proof -
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    19
  from assms obtain r1 r2::rexp where "L_rexp r1 = A" "L_rexp r2 = B" by auto
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    20
  then have "A \<union> B = L_rexp (ALT r1 r2)" by simp
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    21
  then show "regular (A \<union> B)" by blast
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    22
qed
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    23
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    24
lemma closure_seq[intro]:
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    25
  assumes "regular A" "regular B" 
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    26
  shows "regular (A \<cdot> B)"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    27
proof -
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    28
  from assms obtain r1 r2::rexp where "L_rexp r1 = A" "L_rexp r2 = B" by auto
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    29
  then have "A \<cdot> B = L_rexp (SEQ r1 r2)" by simp
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    30
  then show "regular (A \<cdot> B)" by blast
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    31
qed
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    32
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    33
lemma closure_star[intro]:
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    34
  assumes "regular A"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    35
  shows "regular (A\<star>)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    36
proof -
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    37
  from assms obtain r::rexp where "L_rexp r = A" by auto
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    38
  then have "A\<star> = L_rexp (STAR r)" by simp
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    39
  then show "regular (A\<star>)" by blast
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    40
qed
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    41
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    42
text {* Closure under complementation is proved via the 
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    43
  Myhill-Nerode theorem *}
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    44
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    45
lemma closure_complement[intro]:
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    46
  assumes "regular A"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    47
  shows "regular (- A)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    48
proof -
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    49
  from assms have "finite (UNIV // \<approx>A)" by (simp add: Myhill_Nerode)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    50
  then have "finite (UNIV // \<approx>(-A))" by (simp add: str_eq_rel_def)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    51
  then show "regular (- A)" by (simp add: Myhill_Nerode)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    52
qed
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    53
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    54
lemma closure_difference[intro]:
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    55
  assumes "regular A" "regular B" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    56
  shows "regular (A - B)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    57
proof -
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    58
  have "A - B = - (- A \<union> B)" by blast
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    59
  moreover
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    60
  have "regular (- (- A \<union> B))" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    61
    using assms by blast
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    62
  ultimately show "regular (A - B)" by simp
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    63
qed
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    64
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    65
lemma closure_intersection[intro]:
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    66
  assumes "regular A" "regular B" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    67
  shows "regular (A \<inter> B)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    68
proof -
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    69
  have "A \<inter> B = - (- A \<union> - B)" by blast
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    70
  moreover
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    71
  have "regular (- (- A \<union> - B))" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    72
    using assms by blast
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    73
  ultimately show "regular (A \<inter> B)" by simp
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    74
qed
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    75
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    76
subsection {* Closure under string reversal *}
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    77
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    78
fun
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    79
  Rev :: "rexp \<Rightarrow> rexp"
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    80
where
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    81
  "Rev NULL = NULL"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    82
| "Rev EMPTY = EMPTY"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    83
| "Rev (CHAR c) = CHAR c"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    84
| "Rev (ALT r1 r2) = ALT (Rev r1) (Rev r2)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    85
| "Rev (SEQ r1 r2) = SEQ (Rev r2) (Rev r1)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    86
| "Rev (STAR r) = STAR (Rev r)"
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    87
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    88
lemma rev_seq[simp]:
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    89
  shows "rev ` (B \<cdot> A) = (rev ` A) \<cdot> (rev ` B)"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    90
unfolding Seq_def image_def
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    91
by (auto) (metis rev_append)+
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    92
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    93
lemma rev_star1:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    94
  assumes a: "s \<in> (rev ` A)\<star>"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    95
  shows "s \<in> rev ` (A\<star>)"
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
    96
using a
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    97
proof(induct rule: star_induct)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    98
  case (step s1 s2)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
    99
  have inj: "inj (rev::string \<Rightarrow> string)" unfolding inj_on_def by auto
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   100
  have "s1 \<in> rev ` A" "s2 \<in> rev ` (A\<star>)" by fact+
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   101
  then obtain x1 x2 where "x1 \<in> A" "x2 \<in> A\<star>" and eqs: "s1 = rev x1" "s2 = rev x2" by auto
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   102
  then have "x1 \<in> A\<star>" "x2 \<in> A\<star>" by (auto intro: star_intro2)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   103
  then have "x2 @ x1 \<in> A\<star>" by (auto intro: star_intro1)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   104
  then have "rev (x2 @ x1) \<in> rev ` A\<star>" using inj by (simp only: inj_image_mem_iff)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   105
  then show "s1 @ s2 \<in>  rev ` A\<star>" using eqs by simp
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   106
qed (auto)
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
   107
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   108
lemma rev_star2:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   109
  assumes a: "s \<in> A\<star>"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   110
  shows "rev s \<in> (rev ` A)\<star>"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   111
using a
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   112
proof(induct rule: star_induct)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   113
  case (step s1 s2)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   114
  have inj: "inj (rev::string \<Rightarrow> string)" unfolding inj_on_def by auto
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   115
  have "s1 \<in> A"by fact
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   116
  then have "rev s1 \<in> rev ` A" using inj by (simp only: inj_image_mem_iff)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   117
  then have "rev s1 \<in> (rev ` A)\<star>" by (auto intro: star_intro2)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   118
  moreover
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   119
  have "rev s2 \<in> (rev ` A)\<star>" by fact
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   120
  ultimately show "rev (s1 @ s2) \<in>  (rev ` A)\<star>" by (auto intro: star_intro1)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   121
qed (auto)
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
   122
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   123
lemma rev_star[simp]:
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   124
  shows " rev ` (A\<star>) = (rev ` A)\<star>"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   125
using rev_star1 rev_star2 by auto
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   126
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   127
lemma rev_lang:
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   128
  shows "rev ` (L_rexp r) = L_rexp (Rev r)"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   129
by (induct r) (simp_all add: image_Un)
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   130
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   131
lemma closure_reversal[intro]:
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   132
  assumes "regular A"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   133
  shows "regular (rev ` A)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   134
proof -
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   135
  from assms obtain r::rexp where "A = L_rexp r" by auto
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   136
  then have "L_rexp (Rev r) = rev ` A" by (simp add: rev_lang)
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   137
  then show "regular (rev` A)" by blast
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
   138
qed
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
   139
  
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   140
subsection {* Closure under left-quotients *}
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   141
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   142
lemma closure_left_quotient:
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   143
  assumes "regular A"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   144
  shows "regular (Ders_set B A)"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   145
proof -
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   146
  from assms obtain r::rexp where eq: "L_rexp r = A" by auto
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   147
  have fin: "finite (pders_set B r)" by (rule finite_pders_set)
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   148
  
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   149
  have "Ders_set B (L_rexp r) = (\<Union> L_rexp ` (pders_set B r))"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   150
    by (simp add: Ders_set_pders_set)
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   151
  also have "\<dots> = L_rexp (\<Uplus>(pders_set B r))" using fin by simp
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   152
  finally have "Ders_set B A = L_rexp (\<Uplus>(pders_set B r))" using eq
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   153
    by simp
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   154
  then show "regular (Ders_set B A)" by auto
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   155
qed
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   156
5
074d9a4b2bc9 added a file about the easy closure properties of regular sets (the difficult parts, like complement, are missing)
urbanc
parents:
diff changeset
   157
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 5
diff changeset
   158
end