Myhill_2.thy
author zhang
Fri, 03 Jun 2011 13:54:14 +0000
changeset 168 c47efadcaee1
parent 166 7743d2ad71d1
child 170 b1258b7d2789
permissions -rw-r--r--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     1
theory Myhill_2
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
     2
  imports Myhill_1 Prefix_subtract
149
e122cb146ecc added the most current versions of the theories.
urbanc
parents: 132
diff changeset
     3
          "~~/src/HOL/Library/List_Prefix"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     4
begin
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     5
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
     6
section {* Direction @{text "regular language \<Rightarrow> finite partition"} *}
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     7
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     8
definition
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     9
  str_eq :: "string \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> bool" ("_ \<approx>_ _")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    10
where
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 63
diff changeset
    11
  "x \<approx>A y \<equiv> (x, y) \<in> (\<approx>A)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    12
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    13
lemma str_eq_def2:
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    14
  shows "\<approx>A = {(x, y) | x y. x \<approx>A y}"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    15
unfolding str_eq_def
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    16
by simp
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    17
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    18
definition 
117
22ba25b808c8 updated second direction
urbanc
parents: 113
diff changeset
    19
   tag_eq_rel :: "(string \<Rightarrow> 'b) \<Rightarrow> (string \<times> string) set" ("=_=")
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    20
where
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
    21
   "=tag= \<equiv> {(x, y). tag x = tag y}"
117
22ba25b808c8 updated second direction
urbanc
parents: 113
diff changeset
    22
22ba25b808c8 updated second direction
urbanc
parents: 113
diff changeset
    23
lemma finite_eq_tag_rel:
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    24
  assumes rng_fnt: "finite (range tag)"
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    25
  shows "finite (UNIV // =tag=)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    26
proof -
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    27
  let "?f" =  "\<lambda>X. tag ` X" and ?A = "(UNIV // =tag=)"
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    28
  have "finite (?f ` ?A)" 
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    29
  proof -
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    30
    have "range ?f \<subseteq> (Pow (range tag))" unfolding Pow_def by auto
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    31
    moreover 
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    32
    have "finite (Pow (range tag))" using rng_fnt by simp
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    33
    ultimately 
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    34
    have "finite (range ?f)" unfolding image_def by (blast intro: finite_subset)
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    35
    moreover
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    36
    have "?f ` ?A \<subseteq> range ?f" by auto
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    37
    ultimately show "finite (?f ` ?A)" by (rule rev_finite_subset) 
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    38
  qed
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    39
  moreover
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    40
  have "inj_on ?f ?A"
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    41
  proof -
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    42
    { fix X Y
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    43
      assume X_in: "X \<in> ?A"
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    44
        and  Y_in: "Y \<in> ?A"
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    45
        and  tag_eq: "?f X = ?f Y"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
    46
      then obtain x y 
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    47
        where "x \<in> X" "y \<in> Y" "tag x = tag y"
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    48
        unfolding quotient_def Image_def image_def tag_eq_rel_def
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    49
        by (simp) (blast)
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    50
      with X_in Y_in 
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    51
      have "X = Y"
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    52
	unfolding quotient_def tag_eq_rel_def by auto
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
    53
    } 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
    54
    then show "inj_on ?f ?A" unfolding inj_on_def by auto
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    55
  qed
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
    56
  ultimately show "finite (UNIV // =tag=)" by (rule finite_imageD)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    57
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    58
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    59
lemma refined_partition_finite:
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    60
  assumes fnt: "finite (UNIV // R1)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    61
  and refined: "R1 \<subseteq> R2"
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    62
  and eq1: "equiv UNIV R1" and eq2: "equiv UNIV R2"
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    63
  shows "finite (UNIV // R2)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    64
proof -
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    65
  let ?f = "\<lambda>X. {R1 `` {x} | x. x \<in> X}" 
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    66
    and ?A = "UNIV // R2" and ?B = "UNIV // R1"
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    67
  have "?f ` ?A \<subseteq> Pow ?B"
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    68
    unfolding image_def Pow_def quotient_def by auto
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    69
  moreover
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    70
  have "finite (Pow ?B)" using fnt by simp
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    71
  ultimately  
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    72
  have "finite (?f ` ?A)" by (rule finite_subset)
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    73
  moreover
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    74
  have "inj_on ?f ?A"
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    75
  proof -
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    76
    { fix X Y
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    77
      assume X_in: "X \<in> ?A" and Y_in: "Y \<in> ?A" and eq_f: "?f X = ?f Y"
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    78
      from quotientE [OF X_in]
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    79
      obtain x where "X = R2 `` {x}" by blast
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    80
      with equiv_class_self[OF eq2] have x_in: "x \<in> X" by simp
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    81
      then have "R1 ``{x} \<in> ?f X" by auto
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    82
      with eq_f have "R1 `` {x} \<in> ?f Y" by simp
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    83
      then obtain y 
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    84
        where y_in: "y \<in> Y" and eq_r1_xy: "R1 `` {x} = R1 `` {y}" by auto
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    85
      with eq_equiv_class[OF _ eq1] 
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    86
      have "(x, y) \<in> R1" by blast
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    87
      with refined have "(x, y) \<in> R2" by auto
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    88
      with quotient_eqI [OF eq2 X_in Y_in x_in y_in]
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    89
      have "X = Y" .
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    90
    } 
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    91
    then show "inj_on ?f ?A" unfolding inj_on_def by blast 
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    92
  qed
118
c3fa11ee776e first proof
urbanc
parents: 117
diff changeset
    93
  ultimately show "finite (UNIV // R2)" by (rule finite_imageD)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    94
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    95
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    96
lemma tag_finite_imageD:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    97
  assumes rng_fnt: "finite (range tag)" 
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
    98
  and same_tag_eqvt: "\<And>m n. tag m = tag n \<Longrightarrow> m \<approx>A n"
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
    99
  shows "finite (UNIV // \<approx>A)"
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   100
proof (rule_tac refined_partition_finite [of "=tag="])
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   101
  show "finite (UNIV // =tag=)" by (rule finite_eq_tag_rel[OF rng_fnt])
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   102
next
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   103
  from same_tag_eqvt
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   104
  show "=tag= \<subseteq> \<approx>A" unfolding tag_eq_rel_def str_eq_def
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   105
    by auto
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   106
next
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   107
  show "equiv UNIV =tag="
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   108
    unfolding equiv_def tag_eq_rel_def refl_on_def sym_def trans_def
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   109
    by auto
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   110
next
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   111
  show "equiv UNIV (\<approx>A)" 
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   112
    unfolding equiv_def str_eq_rel_def sym_def refl_on_def trans_def
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   113
    by blast
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   114
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   115
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   116
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   117
subsection {* The proof *}
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   118
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   119
subsubsection {* The base case for @{const "NULL"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   120
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   121
lemma quot_null_eq:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   122
  shows "UNIV // \<approx>{} = {UNIV}"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   123
unfolding quotient_def Image_def str_eq_rel_def by auto
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   124
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   125
lemma quot_null_finiteI [intro]:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   126
  shows "finite (UNIV // \<approx>{})"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   127
unfolding quot_null_eq by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   128
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   129
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   130
subsubsection {* The base case for @{const "EMPTY"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   131
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   132
lemma quot_empty_subset:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   133
  shows "UNIV // \<approx>{[]} \<subseteq> {{[]}, UNIV - {[]}}"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   134
proof
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   135
  fix x
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   136
  assume "x \<in> UNIV // \<approx>{[]}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   137
  then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[]}}" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   138
    unfolding quotient_def Image_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   139
  show "x \<in> {{[]}, UNIV - {[]}}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   140
  proof (cases "y = []")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   141
    case True with h
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   142
    have "x = {[]}" by (auto simp: str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   143
    thus ?thesis by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   144
  next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   145
    case False with h
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   146
    have "x = UNIV - {[]}" by (auto simp: str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   147
    thus ?thesis by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   148
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   149
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   150
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   151
lemma quot_empty_finiteI [intro]:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   152
  shows "finite (UNIV // \<approx>{[]})"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   153
by (rule finite_subset[OF quot_empty_subset]) (simp)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   154
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   155
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   156
subsubsection {* The base case for @{const "CHAR"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   157
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   158
lemma quot_char_subset:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   159
  "UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   160
proof 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   161
  fix x 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   162
  assume "x \<in> UNIV // \<approx>{[c]}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   163
  then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[c]}}" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   164
    unfolding quotient_def Image_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   165
  show "x \<in> {{[]},{[c]}, UNIV - {[], [c]}}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   166
  proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   167
    { assume "y = []" hence "x = {[]}" using h 
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   168
        by (auto simp:str_eq_rel_def) } 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   169
    moreover 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   170
    { assume "y = [c]" hence "x = {[c]}" using h 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   171
        by (auto dest!:spec[where x = "[]"] simp:str_eq_rel_def) } 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   172
    moreover 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   173
    { assume "y \<noteq> []" and "y \<noteq> [c]"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   174
      hence "\<forall> z. (y @ z) \<noteq> [c]" by (case_tac y, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   175
      moreover have "\<And> p. (p \<noteq> [] \<and> p \<noteq> [c]) = (\<forall> q. p @ q \<noteq> [c])" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   176
        by (case_tac p, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   177
      ultimately have "x = UNIV - {[],[c]}" using h
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   178
        by (auto simp add:str_eq_rel_def)
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   179
    } 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   180
    ultimately show ?thesis by blast
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   181
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   182
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   183
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   184
lemma quot_char_finiteI [intro]:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   185
  shows "finite (UNIV // \<approx>{[c]})"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   186
by (rule finite_subset[OF quot_char_subset]) (simp)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   187
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   188
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   189
subsubsection {* The inductive case for @{const ALT} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   190
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   191
definition 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   192
  tag_str_ALT :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   193
where
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   194
  "tag_str_ALT A B \<equiv> (\<lambda>x. (\<approx>A `` {x}, \<approx>B `` {x}))"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   195
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   196
lemma quot_union_finiteI [intro]:
119
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   197
  assumes finite1: "finite (UNIV // \<approx>A)"
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   198
  and     finite2: "finite (UNIV // \<approx>B)"
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   199
  shows "finite (UNIV // \<approx>(A \<union> B))"
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   200
proof (rule_tac tag = "tag_str_ALT A B" in tag_finite_imageD)
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   201
  have "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))" 
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   202
    using finite1 finite2 by auto
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   203
  then show "finite (range (tag_str_ALT A B))"
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   204
    unfolding tag_str_ALT_def quotient_def
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   205
    by (rule rev_finite_subset) (auto)
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   206
next
ece3f197b92b first two proofs in 2 direction
urbanc
parents: 118
diff changeset
   207
  show "\<And>x y. tag_str_ALT A B x = tag_str_ALT A B y \<Longrightarrow> x \<approx>(A \<union> B) y"
120
c1f596c7f59e ALT case done
urbanc
parents: 119
diff changeset
   208
    unfolding tag_str_ALT_def
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   209
    unfolding str_eq_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   210
    unfolding str_eq_rel_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   211
    by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   212
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   213
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   214
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   215
subsubsection {* The inductive case for @{text "SEQ"}*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   216
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   217
definition 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   218
  tag_str_SEQ :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang set)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   219
where
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
   220
  "tag_str_SEQ L1 L2 \<equiv>
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   221
     (\<lambda>x. (\<approx>L1 `` {x}, {(\<approx>L2 `` {x - xa}) | xa.  xa \<le> x \<and> xa \<in> L1}))"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   222
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   223
lemma Seq_in_cases:
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   224
  assumes "x @ z \<in> A \<cdot> B"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   225
  shows "(\<exists> x' \<le> x. x' \<in> A \<and> (x - x') @ z \<in> B) \<or> 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   226
         (\<exists> z' \<le> z. (x @ z') \<in> A \<and> (z - z') \<in> B)"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   227
using assms
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   228
unfolding Seq_def prefix_def
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   229
by (auto simp add: append_eq_append_conv2)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   230
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   231
lemma tag_str_SEQ_injI:
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   232
  assumes eq_tag: "tag_str_SEQ A B x = tag_str_SEQ A B y" 
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   233
  shows "x \<approx>(A \<cdot> B) y"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   234
proof -
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   235
  { fix x y z
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   236
    assume xz_in_seq: "x @ z \<in> A \<cdot> B"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   237
    and tag_xy: "tag_str_SEQ A B x = tag_str_SEQ A B y"
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   238
    have"y @ z \<in> A \<cdot> B" 
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   239
    proof -
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   240
      { (* first case with x' in A and (x - x') @ z in B *)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   241
        fix x'
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   242
        assume h1: "x' \<le> x" and h2: "x' \<in> A" and h3: "(x - x') @ z \<in> B"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   243
        obtain y' 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   244
          where "y' \<le> y" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   245
          and "y' \<in> A" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   246
          and "(y - y') @ z \<in> B"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   247
        proof -
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   248
          have "{\<approx>B `` {x - x'} |x'. x' \<le> x \<and> x' \<in> A} = 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   249
                {\<approx>B `` {y - y'} |y'. y' \<le> y \<and> y' \<in> A}" (is "?Left = ?Right")
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   250
            using tag_xy unfolding tag_str_SEQ_def by simp
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   251
          moreover 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   252
	  have "\<approx>B `` {x - x'} \<in> ?Left" using h1 h2 by auto
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   253
          ultimately 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   254
	  have "\<approx>B `` {x - x'} \<in> ?Right" by simp
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   255
          then obtain y' 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   256
            where eq_xy': "\<approx>B `` {x - x'} = \<approx>B `` {y - y'}" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   257
            and pref_y': "y' \<le> y" and y'_in: "y' \<in> A"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   258
            by simp blast
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   259
	  
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   260
	  have "(x - x')  \<approx>B (y - y')" using eq_xy'
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   261
            unfolding Image_def str_eq_rel_def str_eq_def by auto
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   262
          with h3 have "(y - y') @ z \<in> B" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   263
	    unfolding str_eq_rel_def str_eq_def by simp
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   264
          with pref_y' y'_in 
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   265
          show ?thesis using that by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   266
        qed
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   267
	then have "y @ z \<in> A \<cdot> B" by (erule_tac prefixE) (auto simp: Seq_def)
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   268
      } 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   269
      moreover 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   270
      { (* second case with x @ z' in A and z - z' in B *)
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   271
        fix z'
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   272
        assume h1: "z' \<le> z" and h2: "(x @ z') \<in> A" and h3: "z - z' \<in> B"
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   273
	 have "\<approx>A `` {x} = \<approx>A `` {y}" 
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   274
           using tag_xy unfolding tag_str_SEQ_def by simp
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   275
         with h2 have "y @ z' \<in> A"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   276
            unfolding Image_def str_eq_rel_def str_eq_def by auto
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   277
        with h1 h3 have "y @ z \<in> A \<cdot> B"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   278
	  unfolding prefix_def Seq_def
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   279
	  by (auto) (metis append_assoc)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   280
      }
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   281
      ultimately show "y @ z \<in> A \<cdot> B" 
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   282
	using Seq_in_cases [OF xz_in_seq] by blast
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   283
    qed
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   284
  }
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   285
  from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   286
    show "x \<approx>(A \<cdot> B) y" unfolding str_eq_def str_eq_rel_def by blast
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   287
qed 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   288
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   289
lemma quot_seq_finiteI [intro]:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   290
  fixes L1 L2::"lang"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   291
  assumes fin1: "finite (UNIV // \<approx>L1)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   292
  and     fin2: "finite (UNIV // \<approx>L2)" 
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   293
  shows "finite (UNIV // \<approx>(L1 \<cdot> L2))"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   294
proof (rule_tac tag = "tag_str_SEQ L1 L2" in tag_finite_imageD)
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   295
  show "\<And>x y. tag_str_SEQ L1 L2 x = tag_str_SEQ L1 L2 y \<Longrightarrow> x \<approx>(L1 \<cdot> L2) y"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   296
    by (rule tag_str_SEQ_injI)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   297
next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   298
  have *: "finite ((UNIV // \<approx>L1) \<times> (Pow (UNIV // \<approx>L2)))" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   299
    using fin1 fin2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   300
  show "finite (range (tag_str_SEQ L1 L2))" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   301
    unfolding tag_str_SEQ_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   302
    apply(rule finite_subset[OF _ *])
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   303
    unfolding quotient_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   304
    by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   305
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   306
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   307
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   308
subsubsection {* The inductive case for @{const "STAR"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   309
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   310
definition 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   311
  tag_str_STAR :: "lang \<Rightarrow> string \<Rightarrow> lang set"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   312
where
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   313
  "tag_str_STAR L1 \<equiv> (\<lambda>x. {\<approx>L1 `` {x - xa} | xa. xa < x \<and> xa \<in> L1\<star>})"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   314
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   315
text {* A technical lemma. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   316
lemma finite_set_has_max: "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   317
           (\<exists> max \<in> A. \<forall> a \<in> A. f a <= (f max :: nat))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   318
proof (induct rule:finite.induct)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   319
  case emptyI thus ?case by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   320
next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   321
  case (insertI A a)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   322
  show ?case
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   323
  proof (cases "A = {}")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   324
    case True thus ?thesis by (rule_tac x = a in bexI, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   325
  next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   326
    case False
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   327
    with insertI.hyps and False  
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   328
    obtain max 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   329
      where h1: "max \<in> A" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   330
      and h2: "\<forall>a\<in>A. f a \<le> f max" by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   331
    show ?thesis
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   332
    proof (cases "f a \<le> f max")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   333
      assume "f a \<le> f max"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   334
      with h1 h2 show ?thesis by (rule_tac x = max in bexI, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   335
    next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   336
      assume "\<not> (f a \<le> f max)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   337
      thus ?thesis using h2 by (rule_tac x = a in bexI, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   338
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   339
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   340
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   341
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   342
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   343
text {* The following is a technical lemma, which helps to show the range finiteness of tag function. *}
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   344
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   345
lemma finite_strict_prefix_set: "finite {xa. xa < (x::string)}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   346
apply (induct x rule:rev_induct, simp)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   347
apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \<union> {xs}")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   348
by (auto simp:strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   349
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   350
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   351
lemma tag_str_STAR_injI:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   352
  assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   353
  shows "v \<approx>(L\<^isub>1\<star>) w"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   354
proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   355
  { fix x y z
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   356
    assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   357
      and tag_xy: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   358
    have "y @ z \<in> L\<^isub>1\<star>"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   359
    proof(cases "x = []")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   360
      case True
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   361
      with tag_xy have "y = []" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   362
        by (auto simp add: tag_str_STAR_def strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   363
      thus ?thesis using xz_in_star True by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   364
    next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   365
      case False
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   366
      let ?S = "{xa. xa < x \<and> xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   367
      have "finite ?S"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   368
        by (rule_tac B = "{xa. xa < x}" in finite_subset, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   369
          auto simp:finite_strict_prefix_set)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   370
      moreover have "?S \<noteq> {}" using False xz_in_star
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   371
        by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   372
      ultimately have "\<exists> xa_max \<in> ?S. \<forall> xa \<in> ?S. length xa \<le> length xa_max" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   373
        using finite_set_has_max by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   374
      then obtain xa_max 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   375
        where h1: "xa_max < x" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   376
        and h2: "xa_max \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   377
        and h3: "(x - xa_max) @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   378
        and h4:"\<forall> xa < x. xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>  
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   379
                                     \<longrightarrow> length xa \<le> length xa_max"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   380
        by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   381
      obtain ya 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   382
        where h5: "ya < y" and h6: "ya \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   383
        and eq_xya: "(x - xa_max) \<approx>L\<^isub>1 (y - ya)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   384
      proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   385
        from tag_xy have "{\<approx>L\<^isub>1 `` {x - xa} |xa. xa < x \<and> xa \<in> L\<^isub>1\<star>} = 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   386
          {\<approx>L\<^isub>1 `` {y - xa} |xa. xa < y \<and> xa \<in> L\<^isub>1\<star>}" (is "?left = ?right")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   387
          by (auto simp:tag_str_STAR_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   388
        moreover have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?left" using h1 h2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   389
        ultimately have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?right" by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   390
        thus ?thesis using that 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   391
          apply (simp add:Image_def str_eq_rel_def str_eq_def) by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   392
      qed 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   393
      have "(y - ya) @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   394
      proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   395
        obtain za zb where eq_zab: "z = za @ zb" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   396
          and l_za: "(y - ya)@za \<in> L\<^isub>1" and ls_zb: "zb \<in> L\<^isub>1\<star>"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   397
        proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   398
          from h1 have "(x - xa_max) @ z \<noteq> []" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   399
            by (auto simp:strict_prefix_def elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   400
          from star_decom [OF h3 this]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   401
          obtain a b where a_in: "a \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   402
            and a_neq: "a \<noteq> []" and b_in: "b \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   403
            and ab_max: "(x - xa_max) @ z = a @ b" by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   404
          let ?za = "a - (x - xa_max)" and ?zb = "b"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   405
          have pfx: "(x - xa_max) \<le> a" (is "?P1") 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   406
            and eq_z: "z = ?za @ ?zb" (is "?P2")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   407
          proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   408
            have "((x - xa_max) \<le> a \<and> (a - (x - xa_max)) @ b = z) \<or> 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   409
              (a < (x - xa_max) \<and> ((x - xa_max) - a) @ z = b)" 
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   410
              using append_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   411
            moreover {
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   412
              assume np: "a < (x - xa_max)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   413
                and b_eqs: "((x - xa_max) - a) @ z = b"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   414
              have "False"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   415
              proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   416
                let ?xa_max' = "xa_max @ a"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   417
                have "?xa_max' < x" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   418
                  using np h1 by (clarsimp simp:strict_prefix_def diff_prefix) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   419
                moreover have "?xa_max' \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   420
                  using a_in h2 by (simp add:star_intro3) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   421
                moreover have "(x - ?xa_max') @ z \<in> L\<^isub>1\<star>" 
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   422
                  using b_eqs b_in np h1 by (simp add:diff_diff_append)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   423
                moreover have "\<not> (length ?xa_max' \<le> length xa_max)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   424
                  using a_neq by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   425
                ultimately show ?thesis using h4 by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   426
              qed }
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   427
            ultimately show ?P1 and ?P2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   428
          qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   429
          hence "(x - xa_max)@?za \<in> L\<^isub>1" using a_in by (auto elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   430
          with eq_xya have "(y - ya) @ ?za \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   431
            by (auto simp:str_eq_def str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   432
           with eq_z and b_in 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   433
          show ?thesis using that by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   434
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   435
        have "((y - ya) @ za) @ zb \<in> L\<^isub>1\<star>" using  l_za ls_zb by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   436
        with eq_zab show ?thesis by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   437
      qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   438
      with h5 h6 show ?thesis 
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   439
        by (drule_tac star_intro1) (auto simp:strict_prefix_def elim: prefixE)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   440
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   441
  } 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   442
  from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   443
    show  ?thesis unfolding str_eq_def str_eq_rel_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   444
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   445
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   446
lemma quot_star_finiteI [intro]:
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   447
  assumes finite1: "finite (UNIV // \<approx>A)"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   448
  shows "finite (UNIV // \<approx>(A\<star>))"
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   449
proof (rule_tac tag = "tag_str_STAR A" in tag_finite_imageD)
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   450
  show "\<And>x y. tag_str_STAR A x = tag_str_STAR A y \<Longrightarrow> x \<approx>(A\<star>) y"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   451
    by (rule tag_str_STAR_injI)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   452
next
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   453
  have *: "finite (Pow (UNIV // \<approx>A))" 
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   454
    using finite1 by auto
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   455
  show "finite (range (tag_str_STAR A))"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   456
    unfolding tag_str_STAR_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   457
    apply(rule finite_subset[OF _ *])
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   458
    unfolding quotient_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   459
    by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   460
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   461
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   462
subsubsection{* The conclusion *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   463
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   464
lemma Myhill_Nerode2:
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   465
  shows "finite (UNIV // \<approx>(L_rexp r))"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   466
by (induct r) (auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   467
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   468
132
f77a7138f791 comments by Xingyuan
urbanc
parents: 128
diff changeset
   469
theorem Myhill_Nerode:
166
7743d2ad71d1 updated theories and itp-paper
urbanc
parents: 162
diff changeset
   470
  shows "(\<exists>r. A = L_rexp r) \<longleftrightarrow> finite (UNIV // \<approx>A)"
162
e93760534354 added directory for journal version; took uptodate version of the theory files
urbanc
parents: 160
diff changeset
   471
using Myhill_Nerode1 Myhill_Nerode2 by auto
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   472
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   473
end