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