Myhill_2.thy
author urbanc
Thu, 17 Feb 2011 21:30:26 +0000
changeset 112 62fdb4bf7239
parent 109 79b37ef9505f
child 113 ec774952190c
permissions -rw-r--r--
more on the conclusion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     1
theory Myhill_2
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 63
diff changeset
     2
  imports Myhill_1 List_Prefix Prefix_subtract
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     3
begin
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     4
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     5
section {* Direction @{text "regular language \<Rightarrow>finite partition"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     6
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     7
subsection {* The scheme*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     8
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
     9
text {* 
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 63
diff changeset
    10
  The following convenient notation @{text "x \<approx>A y"} means:
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    11
  string @{text "x"} and @{text "y"} are equivalent with respect to 
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 63
diff changeset
    12
  language @{text "A"}.
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    13
  *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    14
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    15
definition
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    16
  str_eq :: "string \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> bool" ("_ \<approx>_ _")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    17
where
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 63
diff changeset
    18
  "x \<approx>A y \<equiv> (x, y) \<in> (\<approx>A)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    19
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    20
text {*
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    21
  The main lemma (@{text "rexp_imp_finite"}) is proved by a structural
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    22
  induction over regular expressions.  where base cases (cases for @{const
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    23
  "NULL"}, @{const "EMPTY"}, @{const "CHAR"}) are quite straightforward to
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    24
  proof. Real difficulty lies in inductive cases.  By inductive hypothesis,
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    25
  languages defined by sub-expressions induce finite partitiions. Under such
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    26
  hypothsis, we need to prove that the language defined by the composite
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    27
  regular expression gives rise to finite partion.  The basic idea is to
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    28
  attach a tag @{text "tag(x)"} to every string @{text "x"}. The tagging
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    29
  fuction @{text "tag"} is carefully devised, which returns tags made of
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    30
  equivalent classes of the partitions induced by subexpressoins, and
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    31
  therefore has a finite range. Let @{text "Lang"} be the composite language,
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    32
  it is proved that:
99
54aa3b6dd71c More into the second direction
zhang
parents: 75
diff changeset
    33
  \begin{quote}
54aa3b6dd71c More into the second direction
zhang
parents: 75
diff changeset
    34
  If strings with the same tag are equivalent with respect to @{text "Lang"}, expressed as:
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    35
  \[
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    36
  @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    37
  \]
99
54aa3b6dd71c More into the second direction
zhang
parents: 75
diff changeset
    38
  then the partition induced by @{text "Lang"} must be finite.
54aa3b6dd71c More into the second direction
zhang
parents: 75
diff changeset
    39
  \end{quote}
54aa3b6dd71c More into the second direction
zhang
parents: 75
diff changeset
    40
  There are two arguments for this. The first goes as the following:
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    41
  \begin{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    42
    \item First, the tagging function @{text "tag"} induces an equivalent relation @{text "(=tag=)"} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    43
          (defiintion of @{text "f_eq_rel"} and lemma @{text "equiv_f_eq_rel"}).
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    44
    \item It is shown that: if the range of @{text "tag"} (denoted @{text "range(tag)"}) is finite, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    45
           the partition given rise by @{text "(=tag=)"} is finite (lemma @{text "finite_eq_f_rel"}).
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    46
           Since tags are made from equivalent classes from component partitions, and the inductive
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    47
           hypothesis ensures the finiteness of these partitions, it is not difficult to prove
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    48
           the finiteness of @{text "range(tag)"}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    49
    \item It is proved that if equivalent relation @{text "R1"} is more refined than @{text "R2"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    50
           (expressed as @{text "R1 \<subseteq> R2"}),
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    51
           and the partition induced by @{text "R1"} is finite, then the partition induced by @{text "R2"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    52
           is finite as well (lemma @{text "refined_partition_finite"}).
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    53
    \item The injectivity assumption @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"} implies that
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    54
            @{text "(=tag=)"} is more refined than @{text "(\<approx>Lang)"}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    55
    \item Combining the points above, we have: the partition induced by language @{text "Lang"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    56
          is finite (lemma @{text "tag_finite_imageD"}).
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    57
  \end{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    58
*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    59
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    60
definition 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    61
   f_eq_rel ("=_=")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    62
where
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    63
   "=f= \<equiv> {(x, y) | x y. f x = f y}"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    64
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    65
lemma equiv_f_eq_rel:"equiv UNIV (=f=)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    66
  by (auto simp:equiv_def f_eq_rel_def refl_on_def sym_def trans_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    67
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    68
lemma finite_range_image: 
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    69
  assumes "finite (range f)"
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    70
  shows "finite (f ` A)"
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    71
  using assms unfolding image_def
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    72
  by (rule_tac finite_subset) (auto)
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    73
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    74
lemma finite_eq_f_rel:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    75
  assumes rng_fnt: "finite (range tag)"
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    76
  shows "finite (UNIV // =tag=)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    77
proof -
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
    78
  let "?f" =  "op ` tag" and ?A = "(UNIV // =tag=)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    79
  show ?thesis
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    80
  proof (rule_tac f = "?f" and A = ?A in finite_imageD) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    81
    -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    82
      The finiteness of @{text "f"}-image is a simple consequence of assumption @{text "rng_fnt"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    83
      *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    84
    show "finite (?f ` ?A)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    85
    proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    86
      have "\<forall> X. ?f X \<in> (Pow (range tag))" by (auto simp:image_def Pow_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    87
      moreover from rng_fnt have "finite (Pow (range tag))" by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    88
      ultimately have "finite (range ?f)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    89
        by (auto simp only:image_def intro:finite_subset)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    90
      from finite_range_image [OF this] show ?thesis .
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    91
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    92
  next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    93
    -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    94
      The injectivity of @{text "f"}-image is a consequence of the definition of @{text "(=tag=)"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    95
      *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    96
    show "inj_on ?f ?A" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    97
    proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    98
      { fix X Y
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
    99
        assume X_in: "X \<in> ?A"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   100
          and  Y_in: "Y \<in> ?A"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   101
          and  tag_eq: "?f X = ?f Y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   102
        have "X = Y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   103
        proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   104
          from X_in Y_in tag_eq 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   105
          obtain x y 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   106
            where x_in: "x \<in> X" and y_in: "y \<in> Y" and eq_tg: "tag x = tag y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   107
            unfolding quotient_def Image_def str_eq_rel_def 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   108
                                   str_eq_def image_def f_eq_rel_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   109
            apply simp by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   110
          with X_in Y_in show ?thesis 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   111
            by (auto simp:quotient_def str_eq_rel_def str_eq_def f_eq_rel_def) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   112
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   113
      } thus ?thesis unfolding inj_on_def by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   114
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   115
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   116
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   117
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
   118
lemma finite_image_finite: 
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
   119
  "\<lbrakk>\<forall> x \<in> A. f x \<in> B; finite B\<rbrakk> \<Longrightarrow> finite (f ` A)"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   120
  by (rule finite_subset [of _ B], auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   121
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   122
lemma refined_partition_finite:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   123
  fixes R1 R2 A
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   124
  assumes fnt: "finite (A // R1)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   125
  and refined: "R1 \<subseteq> R2"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   126
  and eq1: "equiv A R1" and eq2: "equiv A R2"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   127
  shows "finite (A // R2)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   128
proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   129
  let ?f = "\<lambda> X. {R1 `` {x} | x. x \<in> X}" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   130
    and ?A = "(A // R2)" and ?B = "(A // R1)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   131
  show ?thesis
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   132
  proof(rule_tac f = ?f and A = ?A in finite_imageD)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   133
    show "finite (?f ` ?A)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   134
    proof(rule finite_subset [of _ "Pow ?B"])
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   135
      from fnt show "finite (Pow (A // R1))" by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   136
    next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   137
      from eq2
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   138
      show " ?f ` A // R2 \<subseteq> Pow ?B"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   139
        unfolding image_def Pow_def quotient_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   140
        apply auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   141
        by (rule_tac x = xb in bexI, simp, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   142
                 unfold equiv_def sym_def refl_on_def, blast)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   143
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   144
  next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   145
    show "inj_on ?f ?A"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   146
    proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   147
      { fix X Y
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   148
        assume X_in: "X \<in> ?A" and Y_in: "Y \<in> ?A" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   149
          and eq_f: "?f X = ?f Y" (is "?L = ?R")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   150
        have "X = Y" using X_in
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   151
        proof(rule quotientE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   152
          fix x
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   153
          assume "X = R2 `` {x}" and "x \<in> A" with eq2
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   154
          have x_in: "x \<in> X" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   155
            unfolding equiv_def quotient_def refl_on_def by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   156
          with eq_f have "R1 `` {x} \<in> ?R" by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   157
          then obtain y where 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   158
            y_in: "y \<in> Y" and eq_r: "R1 `` {x} = R1 ``{y}" by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   159
          have "(x, y) \<in> R1"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   160
          proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   161
            from x_in X_in y_in Y_in eq2
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   162
            have "x \<in> A" and "y \<in> A" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   163
              unfolding equiv_def quotient_def refl_on_def by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   164
            from eq_equiv_class_iff [OF eq1 this] and eq_r
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   165
            show ?thesis by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   166
          qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   167
          with refined have xy_r2: "(x, y) \<in> R2" by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   168
          from quotient_eqI [OF eq2 X_in Y_in x_in y_in this]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   169
          show ?thesis .
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   170
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   171
      } thus ?thesis by (auto simp:inj_on_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   172
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   173
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   174
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   175
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   176
lemma equiv_lang_eq: "equiv UNIV (\<approx>Lang)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   177
  unfolding equiv_def str_eq_rel_def sym_def refl_on_def trans_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   178
  by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   179
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   180
lemma tag_finite_imageD:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   181
  fixes tag
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   182
  assumes rng_fnt: "finite (range tag)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   183
  -- {* Suppose the rang of tagging fucntion @{text "tag"} is finite. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   184
  and same_tag_eqvt: "\<And> m n. tag m = tag (n::string) \<Longrightarrow> m \<approx>Lang n"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   185
  -- {* And strings with same tag are equivalent *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   186
  shows "finite (UNIV // (\<approx>Lang))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   187
proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   188
  let ?R1 = "(=tag=)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   189
  show ?thesis
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   190
  proof(rule_tac refined_partition_finite [of _ ?R1])
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   191
    from finite_eq_f_rel [OF rng_fnt]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   192
     show "finite (UNIV // =tag=)" . 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   193
   next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   194
     from same_tag_eqvt
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   195
     show "(=tag=) \<subseteq> (\<approx>Lang)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   196
       by (auto simp:f_eq_rel_def str_eq_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   197
   next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   198
     from equiv_f_eq_rel
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   199
     show "equiv UNIV (=tag=)" by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   200
   next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   201
     from equiv_lang_eq
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   202
     show "equiv UNIV (\<approx>Lang)" by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   203
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   204
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   205
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   206
text {*
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   207
  A more concise, but less intelligible argument for @{text "tag_finite_imageD"} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   208
  is given as the following. The basic idea is still using standard library 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   209
  lemma @{thm [source] "finite_imageD"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   210
  \[
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   211
  @{thm "finite_imageD" [no_vars]}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   212
  \]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   213
  which says: if the image of injective function @{text "f"} over set @{text "A"} is 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   214
  finite, then @{text "A"} must be finte, as we did in the lemmas above.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   215
  *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   216
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   217
lemma 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   218
  fixes tag
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   219
  assumes rng_fnt: "finite (range tag)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   220
  -- {* Suppose the rang of tagging fucntion @{text "tag"} is finite. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   221
  and same_tag_eqvt: "\<And> m n. tag m = tag (n::string) \<Longrightarrow> m \<approx>Lang n"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   222
  -- {* And strings with same tag are equivalent *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   223
  shows "finite (UNIV // (\<approx>Lang))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   224
  -- {* Then the partition generated by @{text "(\<approx>Lang)"} is finite. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   225
proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   226
  -- {* The particular @{text "f"} and @{text "A"} used in @{thm [source] "finite_imageD"} are:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   227
  let "?f" =  "op ` tag" and ?A = "(UNIV // \<approx>Lang)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   228
  show ?thesis
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   229
  proof (rule_tac f = "?f" and A = ?A in finite_imageD) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   230
    -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   231
      The finiteness of @{text "f"}-image is a simple consequence of assumption @{text "rng_fnt"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   232
      *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   233
    show "finite (?f ` ?A)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   234
    proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   235
      have "\<forall> X. ?f X \<in> (Pow (range tag))" by (auto simp:image_def Pow_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   236
      moreover from rng_fnt have "finite (Pow (range tag))" by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   237
      ultimately have "finite (range ?f)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   238
        by (auto simp only:image_def intro:finite_subset)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   239
      from finite_range_image [OF this] show ?thesis .
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   240
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   241
  next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   242
    -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   243
      The injectivity of @{text "f"} is the consequence of assumption @{text "same_tag_eqvt"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   244
      *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   245
    show "inj_on ?f ?A" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   246
    proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   247
      { fix X Y
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   248
        assume X_in: "X \<in> ?A"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   249
          and  Y_in: "Y \<in> ?A"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   250
          and  tag_eq: "?f X = ?f Y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   251
        have "X = Y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   252
        proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   253
          from X_in Y_in tag_eq 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   254
          obtain x y where x_in: "x \<in> X" and y_in: "y \<in> Y" and eq_tg: "tag x = tag y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   255
            unfolding quotient_def Image_def str_eq_rel_def str_eq_def image_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   256
            apply simp by blast 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   257
          from same_tag_eqvt [OF eq_tg] have "x \<approx>Lang y" .
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   258
          with X_in Y_in x_in y_in
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   259
          show ?thesis by (auto simp:quotient_def str_eq_rel_def str_eq_def) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   260
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   261
      } thus ?thesis unfolding inj_on_def by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   262
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   263
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   264
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   265
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   266
subsection {* The proof*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   267
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   268
text {*
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   269
  Each case is given in a separate section, as well as the final main lemma. Detailed explainations accompanied by
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   270
  illustrations are given for non-trivial cases.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   271
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   272
  For ever inductive case, there are two tasks, the easier one is to show the range finiteness of
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   273
  of the tagging function based on the finiteness of component partitions, the
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   274
  difficult one is to show that strings with the same tag are equivalent with respect to the 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   275
  composite language. Suppose the composite language be @{text "Lang"}, tagging function be 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   276
  @{text "tag"}, it amounts to show:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   277
  \[
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   278
  @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   279
  \]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   280
  expanding the definition of @{text "\<approx>Lang"}, it amounts to show:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   281
  \[
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   282
  @{text "tag(x) = tag(y) \<Longrightarrow> (\<forall> z. x@z \<in> Lang \<longleftrightarrow> y@z \<in> Lang)"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   283
  \]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   284
  Because the assumed tag equlity @{text "tag(x) = tag(y)"} is symmetric,
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   285
  it is suffcient to show just one direction:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   286
  \[
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   287
  @{text "\<And> x y z. \<lbrakk>tag(x) = tag(y); x@z \<in> Lang\<rbrakk> \<Longrightarrow> y@z \<in> Lang"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   288
  \]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   289
  This is the pattern followed by every inductive case.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   290
  *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   291
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   292
subsubsection {* The base case for @{const "NULL"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   293
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   294
lemma quot_null_eq:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   295
  shows "(UNIV // \<approx>{}) = ({UNIV}::lang set)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   296
  unfolding quotient_def Image_def str_eq_rel_def by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   297
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   298
lemma quot_null_finiteI [intro]:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   299
  shows "finite ((UNIV // \<approx>{})::lang set)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   300
unfolding quot_null_eq by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   301
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   302
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   303
subsubsection {* The base case for @{const "EMPTY"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   304
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   305
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   306
lemma quot_empty_subset:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   307
  "UNIV // (\<approx>{[]}) \<subseteq> {{[]}, UNIV - {[]}}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   308
proof
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   309
  fix x
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   310
  assume "x \<in> UNIV // \<approx>{[]}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   311
  then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[]}}" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   312
    unfolding quotient_def Image_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   313
  show "x \<in> {{[]}, UNIV - {[]}}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   314
  proof (cases "y = []")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   315
    case True with h
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   316
    have "x = {[]}" by (auto simp: str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   317
    thus ?thesis by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   318
  next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   319
    case False with h
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   320
    have "x = UNIV - {[]}" by (auto simp: str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   321
    thus ?thesis by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   322
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   323
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   324
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   325
lemma quot_empty_finiteI [intro]:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   326
  shows "finite (UNIV // (\<approx>{[]}))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   327
by (rule finite_subset[OF quot_empty_subset]) (simp)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   328
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   329
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   330
subsubsection {* The base case for @{const "CHAR"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   331
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   332
lemma quot_char_subset:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   333
  "UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   334
proof 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   335
  fix x 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   336
  assume "x \<in> UNIV // \<approx>{[c]}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   337
  then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[c]}}" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   338
    unfolding quotient_def Image_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   339
  show "x \<in> {{[]},{[c]}, UNIV - {[], [c]}}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   340
  proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   341
    { assume "y = []" hence "x = {[]}" using h 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   342
        by (auto simp:str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   343
    } moreover {
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   344
      assume "y = [c]" hence "x = {[c]}" using h 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   345
        by (auto dest!:spec[where x = "[]"] simp:str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   346
    } moreover {
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   347
      assume "y \<noteq> []" and "y \<noteq> [c]"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   348
      hence "\<forall> z. (y @ z) \<noteq> [c]" by (case_tac y, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   349
      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
   350
        by (case_tac p, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   351
      ultimately have "x = UNIV - {[],[c]}" using h
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   352
        by (auto simp add:str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   353
    } ultimately show ?thesis by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   354
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   355
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   356
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   357
lemma quot_char_finiteI [intro]:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   358
  shows "finite (UNIV // (\<approx>{[c]}))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   359
by (rule finite_subset[OF quot_char_subset]) (simp)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   360
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   361
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   362
subsubsection {* The inductive case for @{const ALT} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   363
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   364
definition 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   365
  tag_str_ALT :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   366
where
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
   367
  "tag_str_ALT L1 L2 \<equiv> (\<lambda>x. (\<approx>L1 `` {x}, \<approx>L2 `` {x}))"
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   368
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   369
lemma quot_union_finiteI [intro]:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   370
  fixes L1 L2::"lang"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   371
  assumes finite1: "finite (UNIV // \<approx>L1)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   372
  and     finite2: "finite (UNIV // \<approx>L2)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   373
  shows "finite (UNIV // \<approx>(L1 \<union> L2))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   374
proof (rule_tac tag = "tag_str_ALT L1 L2" in tag_finite_imageD)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   375
  show "\<And>x y. tag_str_ALT L1 L2 x = tag_str_ALT L1 L2 y \<Longrightarrow> x \<approx>(L1 \<union> L2) y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   376
    unfolding tag_str_ALT_def 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   377
    unfolding str_eq_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   378
    unfolding Image_def 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   379
    unfolding str_eq_rel_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   380
    by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   381
next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   382
  have *: "finite ((UNIV // \<approx>L1) \<times> (UNIV // \<approx>L2))" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   383
    using finite1 finite2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   384
  show "finite (range (tag_str_ALT L1 L2))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   385
    unfolding tag_str_ALT_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   386
    apply(rule finite_subset[OF _ *])
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   387
    unfolding quotient_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   388
    by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   389
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   390
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   391
subsubsection {* The inductive case for @{text "SEQ"}*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   392
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   393
text {*
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   394
  For case @{const "SEQ"}, the language @{text "L"} is @{text "L\<^isub>1 ;; L\<^isub>2"}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   395
  Given @{text "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"}, according to the defintion of @{text " L\<^isub>1 ;; L\<^isub>2"},
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   396
  string @{text "x @ z"} can be splitted with the prefix in @{text "L\<^isub>1"} and suffix in @{text "L\<^isub>2"}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   397
  The split point can either be in @{text "x"} (as shown in Fig. \ref{seq_first_split}),
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   398
  or in @{text "z"} (as shown in Fig. \ref{seq_snd_split}). Whichever way it goes, the structure
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   399
  on @{text "x @ z"} cn be transfered faithfully onto @{text "y @ z"} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   400
  (as shown in Fig. \ref{seq_trans_first_split} and \ref{seq_trans_snd_split}) with the the help of the assumed 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   401
  tag equality. The following tag function @{text "tag_str_SEQ"} is such designed to facilitate
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   402
  such transfers and lemma @{text "tag_str_SEQ_injI"} formalizes the informal argument above. The details 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   403
  of structure transfer will be given their.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   404
\input{fig_seq}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   405
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   406
  *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   407
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   408
definition 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   409
  tag_str_SEQ :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang set)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   410
where
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
   411
  "tag_str_SEQ L1 L2 \<equiv>
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   412
     (\<lambda>x. (\<approx>L1 `` {x}, {(\<approx>L2 `` {x - xa}) | xa.  xa \<le> x \<and> xa \<in> L1}))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   413
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   414
text {* The following is a techical lemma which helps to split the @{text "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"} mentioned above.*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   415
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   416
lemma append_seq_elim:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   417
  assumes "x @ y \<in> L\<^isub>1 ;; L\<^isub>2"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   418
  shows "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2) \<or> 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   419
          (\<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   420
proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   421
  from assms obtain s\<^isub>1 s\<^isub>2 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   422
    where eq_xys: "x @ y = s\<^isub>1 @ s\<^isub>2" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   423
    and in_seq: "s\<^isub>1 \<in> L\<^isub>1 \<and> s\<^isub>2 \<in> L\<^isub>2" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   424
    by (auto simp:Seq_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   425
  from app_eq_dest [OF eq_xys]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   426
  have
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   427
    "(x \<le> s\<^isub>1 \<and> (s\<^isub>1 - x) @ s\<^isub>2 = y) \<or> (s\<^isub>1 \<le> x \<and> (x - s\<^isub>1) @ y = s\<^isub>2)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   428
               (is "?Split1 \<or> ?Split2") .
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   429
  moreover have "?Split1 \<Longrightarrow> \<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   430
    using in_seq by (rule_tac x = "s\<^isub>1 - x" in exI, auto elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   431
  moreover have "?Split2 \<Longrightarrow> \<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   432
    using in_seq by (rule_tac x = s\<^isub>1 in exI, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   433
  ultimately show ?thesis by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   434
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   435
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   436
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   437
lemma tag_str_SEQ_injI:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   438
  fixes v w 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   439
  assumes eq_tag: "tag_str_SEQ L\<^isub>1 L\<^isub>2 v = tag_str_SEQ L\<^isub>1 L\<^isub>2 w" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   440
  shows "v \<approx>(L\<^isub>1 ;; L\<^isub>2) w"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   441
proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   442
    -- {* As explained before, a pattern for just one direction needs to be dealt with:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   443
  { fix x y z
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   444
    assume xz_in_seq: "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   445
    and tag_xy: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   446
    have"y @ z \<in> L\<^isub>1 ;; L\<^isub>2" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   447
    proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   448
      -- {* There are two ways to split @{text "x@z"}: *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   449
      from append_seq_elim [OF xz_in_seq]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   450
      have "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ z \<in> L\<^isub>2) \<or> 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   451
               (\<exists> za \<le> z. (x @ za) \<in> L\<^isub>1 \<and> (z - za) \<in> L\<^isub>2)" .
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   452
      -- {* It can be shown that @{text "?thesis"} holds in either case: *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   453
      moreover {
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   454
        -- {* The case for the first split:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   455
        fix xa
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   456
        assume h1: "xa \<le> x" and h2: "xa \<in> L\<^isub>1" and h3: "(x - xa) @ z \<in> L\<^isub>2"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   457
        -- {* The following subgoal implements the structure transfer:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   458
        obtain ya 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   459
          where "ya \<le> y" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   460
          and "ya \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   461
          and "(y - ya) @ z \<in> L\<^isub>2"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   462
        proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   463
        -- {*
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   464
            \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   465
            By expanding the definition of 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   466
            @{thm [display] "tag_xy"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   467
            and extracting the second compoent, we get:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   468
            \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   469
            *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   470
          have "{\<approx>L\<^isub>2 `` {x - xa} |xa. xa \<le> x \<and> xa \<in> L\<^isub>1} = 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   471
                   {\<approx>L\<^isub>2 `` {y - ya} |ya. ya \<le> y \<and> ya \<in> L\<^isub>1}" (is "?Left = ?Right")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   472
            using tag_xy unfolding tag_str_SEQ_def by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   473
            -- {* Since @{thm "h1"} and @{thm "h2"} hold, it is not difficult to show: *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   474
          moreover have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Left" using h1 h2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   475
            -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   476
            \begin{minipage}{0.7\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   477
            Through tag equality, equivalent class @{term "\<approx>L\<^isub>2 `` {x - xa}"} also 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   478
                  belongs to the @{text "?Right"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   479
            \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   480
            *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   481
          ultimately have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Right" by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   482
            -- {* From this, the counterpart of @{text "xa"} in @{text "y"} is obtained:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   483
          then obtain ya 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   484
            where eq_xya: "\<approx>L\<^isub>2 `` {x - xa} = \<approx>L\<^isub>2 `` {y - ya}" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   485
            and pref_ya: "ya \<le> y" and ya_in: "ya \<in> L\<^isub>1"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   486
            by simp blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   487
          -- {* It can be proved that @{text "ya"} has the desired property:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   488
          have "(y - ya)@z \<in> L\<^isub>2" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   489
          proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   490
            from eq_xya have "(x - xa)  \<approx>L\<^isub>2 (y - ya)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   491
              unfolding Image_def str_eq_rel_def str_eq_def by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   492
            with h3 show ?thesis unfolding str_eq_rel_def str_eq_def by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   493
          qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   494
          -- {* Now, @{text "ya"} has all properties to be a qualified candidate:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   495
          with pref_ya ya_in 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   496
          show ?thesis using that by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   497
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   498
          -- {* From the properties of @{text "ya"}, @{text "y @ z \<in> L\<^isub>1 ;; L\<^isub>2"} is derived easily.*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   499
        hence "y @ z \<in> L\<^isub>1 ;; L\<^isub>2" by (erule_tac prefixE, auto simp:Seq_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   500
      } moreover {
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   501
        -- {* The other case is even more simpler: *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   502
        fix za
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   503
        assume h1: "za \<le> z" and h2: "(x @ za) \<in> L\<^isub>1" and h3: "z - za \<in> L\<^isub>2"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   504
        have "y @ za \<in> L\<^isub>1"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   505
        proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   506
          have "\<approx>L\<^isub>1 `` {x} = \<approx>L\<^isub>1 `` {y}" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   507
            using tag_xy unfolding tag_str_SEQ_def by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   508
          with h2 show ?thesis
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   509
            unfolding Image_def str_eq_rel_def str_eq_def by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   510
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   511
        with h1 h3 have "y @ z \<in> L\<^isub>1 ;; L\<^isub>2" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   512
          by (drule_tac A = L\<^isub>1 in seq_intro, auto elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   513
      }
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   514
      ultimately show ?thesis by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   515
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   516
  } 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   517
  -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   518
      \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   519
      @{text "?thesis"} is proved by exploiting the symmetry of 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   520
      @{thm [source] "eq_tag"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   521
      \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   522
      *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   523
  from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   524
    show ?thesis unfolding str_eq_def str_eq_rel_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   525
qed 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   526
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   527
lemma quot_seq_finiteI [intro]:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   528
  fixes L1 L2::"lang"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   529
  assumes fin1: "finite (UNIV // \<approx>L1)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   530
  and     fin2: "finite (UNIV // \<approx>L2)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   531
  shows "finite (UNIV // \<approx>(L1 ;; L2))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   532
proof (rule_tac tag = "tag_str_SEQ L1 L2" in tag_finite_imageD)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   533
  show "\<And>x y. tag_str_SEQ L1 L2 x = tag_str_SEQ L1 L2 y \<Longrightarrow> x \<approx>(L1 ;; L2) y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   534
    by (rule tag_str_SEQ_injI)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   535
next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   536
  have *: "finite ((UNIV // \<approx>L1) \<times> (Pow (UNIV // \<approx>L2)))" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   537
    using fin1 fin2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   538
  show "finite (range (tag_str_SEQ L1 L2))" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   539
    unfolding tag_str_SEQ_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   540
    apply(rule finite_subset[OF _ *])
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   541
    unfolding quotient_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   542
    by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   543
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   544
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   545
subsubsection {* The inductive case for @{const "STAR"} *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   546
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   547
text {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   548
  This turned out to be the trickiest case. The essential goal is 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   549
  to proved @{text "y @ z \<in>  L\<^isub>1*"} under the assumptions that @{text "x @ z \<in>  L\<^isub>1*"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   550
  and that @{text "x"} and @{text "y"} have the same tag. The reasoning goes as the following:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   551
  \begin{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   552
    \item Since @{text "x @ z \<in>  L\<^isub>1*"} holds, a prefix @{text "xa"} of @{text "x"} can be found
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   553
          such that @{text "xa \<in> L\<^isub>1*"} and @{text "(x - xa)@z \<in> L\<^isub>1*"}, as shown in Fig. \ref{first_split}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   554
          Such a prefix always exists, @{text "xa = []"}, for example, is one. 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   555
    \item There could be many but fintie many of such @{text "xa"}, from which we can find the longest
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   556
          and name it @{text "xa_max"}, as shown in Fig. \ref{max_split}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   557
    \item The next step is to split @{text "z"} into @{text "za"} and @{text "zb"} such that
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   558
           @{text "(x - xa_max) @ za \<in> L\<^isub>1"} and @{text "zb \<in> L\<^isub>1*"}  as shown in Fig. \ref{last_split}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   559
          Such a split always exists because:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   560
          \begin{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   561
            \item Because @{text "(x - x_max) @ z \<in> L\<^isub>1*"}, it can always be splitted into prefix @{text "a"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   562
              and suffix @{text "b"}, such that @{text "a \<in> L\<^isub>1"} and @{text "b \<in> L\<^isub>1*"},
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   563
              as shown in Fig. \ref{ab_split}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   564
            \item But the prefix @{text "a"} CANNOT be shorter than @{text "x - xa_max"} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   565
              (as shown in Fig. \ref{ab_split_wrong}), becasue otherwise,
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   566
                   @{text "ma_max@a"} would be in the same kind as @{text "xa_max"} but with 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   567
                   a larger size, conflicting with the fact that @{text "xa_max"} is the longest.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   568
          \end{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   569
    \item  \label{tansfer_step} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   570
         By the assumption that @{text "x"} and @{text "y"} have the same tag, the structure on @{text "x @ z"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   571
          can be transferred to @{text "y @ z"} as shown in Fig. \ref{trans_split}. The detailed steps are:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   572
          \begin{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   573
            \item A @{text "y"}-prefix @{text "ya"} corresponding to @{text "xa"} can be found, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   574
                  which satisfies conditions: @{text "ya \<in> L\<^isub>1*"} and @{text "(y - ya)@za \<in> L\<^isub>1"}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   575
            \item Since we already know @{text "zb \<in> L\<^isub>1*"}, we get @{text "(y - ya)@za@zb \<in> L\<^isub>1*"},
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   576
                  and this is just @{text "(y - ya)@z \<in> L\<^isub>1*"}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   577
            \item With fact @{text "ya \<in> L\<^isub>1*"}, we finally get @{text "y@z \<in> L\<^isub>1*"}.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   578
          \end{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   579
  \end{enumerate}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   580
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   581
  The formal proof of lemma @{text "tag_str_STAR_injI"} faithfully follows this informal argument 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   582
  while the tagging function @{text "tag_str_STAR"} is defined to make the transfer in step
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   583
  \ref{ansfer_step} feasible.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   584
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   585
  \input{fig_star}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   586
*} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   587
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   588
definition 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   589
  tag_str_STAR :: "lang \<Rightarrow> string \<Rightarrow> lang set"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   590
where
109
79b37ef9505f minor updated
urbanc
parents: 99
diff changeset
   591
  "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
   592
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   593
text {* A technical lemma. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   594
lemma finite_set_has_max: "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   595
           (\<exists> max \<in> A. \<forall> a \<in> A. f a <= (f max :: nat))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   596
proof (induct rule:finite.induct)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   597
  case emptyI thus ?case by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   598
next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   599
  case (insertI A a)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   600
  show ?case
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   601
  proof (cases "A = {}")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   602
    case True thus ?thesis by (rule_tac x = a in bexI, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   603
  next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   604
    case False
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   605
    with insertI.hyps and False  
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   606
    obtain max 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   607
      where h1: "max \<in> A" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   608
      and h2: "\<forall>a\<in>A. f a \<le> f max" by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   609
    show ?thesis
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   610
    proof (cases "f a \<le> f max")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   611
      assume "f a \<le> f max"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   612
      with h1 h2 show ?thesis by (rule_tac x = max in bexI, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   613
    next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   614
      assume "\<not> (f a \<le> f max)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   615
      thus ?thesis using h2 by (rule_tac x = a in bexI, auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   616
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   617
  qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   618
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   619
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   620
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   621
text {* The following is a technical lemma.which helps to show the range finiteness of tag function. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   622
lemma finite_strict_prefix_set: "finite {xa. xa < (x::string)}"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   623
apply (induct x rule:rev_induct, simp)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   624
apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \<union> {xs}")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   625
by (auto simp:strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   626
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   627
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   628
lemma tag_str_STAR_injI:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   629
  fixes v w
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   630
  assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   631
  shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   632
proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   633
    -- {* As explained before, a pattern for just one direction needs to be dealt with:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   634
  { fix x y z
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   635
    assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   636
      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
   637
    have "y @ z \<in> L\<^isub>1\<star>"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   638
    proof(cases "x = []")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   639
      -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   640
        The degenerated case when @{text "x"} is a null string is easy to prove:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   641
        *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   642
      case True
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   643
      with tag_xy have "y = []" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   644
        by (auto simp add: tag_str_STAR_def strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   645
      thus ?thesis using xz_in_star True by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   646
    next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   647
        -- {* The nontrival case:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   648
        *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   649
      case False
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   650
      -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   651
        \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   652
        Since @{text "x @ z \<in> L\<^isub>1\<star>"}, @{text "x"} can always be splitted
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   653
        by a prefix @{text "xa"} together with its suffix @{text "x - xa"}, such
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   654
        that both @{text "xa"} and @{text "(x - xa) @ z"} are in @{text "L\<^isub>1\<star>"},
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   655
        and there could be many such splittings.Therefore, the following set @{text "?S"} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   656
        is nonempty, and finite as well:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   657
        \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   658
        *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   659
      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
   660
      have "finite ?S"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   661
        by (rule_tac B = "{xa. xa < x}" in finite_subset, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   662
          auto simp:finite_strict_prefix_set)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   663
      moreover have "?S \<noteq> {}" using False xz_in_star
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   664
        by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   665
      -- {* \begin{minipage}{0.7\textwidth} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   666
            Since @{text "?S"} is finite, we can always single out the longest and name it @{text "xa_max"}: 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   667
            \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   668
          *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   669
      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
   670
        using finite_set_has_max by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   671
      then obtain xa_max 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   672
        where h1: "xa_max < x" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   673
        and h2: "xa_max \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   674
        and h3: "(x - xa_max) @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   675
        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
   676
                                     \<longrightarrow> length xa \<le> length xa_max"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   677
        by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   678
      -- {*
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   679
          \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   680
          By the equality of tags, the counterpart of @{text "xa_max"} among 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   681
          @{text "y"}-prefixes, named @{text "ya"}, can be found:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   682
          \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   683
          *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   684
      obtain ya 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   685
        where h5: "ya < y" and h6: "ya \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   686
        and eq_xya: "(x - xa_max) \<approx>L\<^isub>1 (y - ya)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   687
      proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   688
        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
   689
          {\<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
   690
          by (auto simp:tag_str_STAR_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   691
        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
   692
        ultimately have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?right" by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   693
        thus ?thesis using that 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   694
          apply (simp add:Image_def str_eq_rel_def str_eq_def) by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   695
      qed 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   696
      -- {*
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   697
          \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   698
          The @{text "?thesis"}, @{prop "y @ z \<in> L\<^isub>1\<star>"}, is a simple consequence
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   699
          of the following proposition:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   700
          \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   701
          *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   702
      have "(y - ya) @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   703
      proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   704
        -- {* The idea is to split the suffix @{text "z"} into @{text "za"} and @{text "zb"}, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   705
          such that: *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   706
        obtain za zb where eq_zab: "z = za @ zb" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   707
          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
   708
        proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   709
          -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   710
            \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   711
            Since @{thm "h1"}, @{text "x"} can be splitted into
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   712
            @{text "a"} and @{text "b"} such that:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   713
            \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   714
            *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   715
          from h1 have "(x - xa_max) @ z \<noteq> []" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   716
            by (auto simp:strict_prefix_def elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   717
          from star_decom [OF h3 this]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   718
          obtain a b where a_in: "a \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   719
            and a_neq: "a \<noteq> []" and b_in: "b \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   720
            and ab_max: "(x - xa_max) @ z = a @ b" by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   721
          -- {* Now the candiates for @{text "za"} and @{text "zb"} are found:*}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   722
          let ?za = "a - (x - xa_max)" and ?zb = "b"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   723
          have pfx: "(x - xa_max) \<le> a" (is "?P1") 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   724
            and eq_z: "z = ?za @ ?zb" (is "?P2")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   725
          proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   726
            -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   727
              \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   728
              Since @{text "(x - xa_max) @ z = a @ b"}, string @{text "(x - xa_max) @ z"}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   729
              can be splitted in two ways:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   730
              \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   731
              *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   732
            have "((x - xa_max) \<le> a \<and> (a - (x - xa_max)) @ b = z) \<or> 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   733
              (a < (x - xa_max) \<and> ((x - xa_max) - a) @ z = b)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   734
              using app_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   735
            moreover {
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   736
              -- {* However, the undsired way can be refuted by absurdity: *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   737
              assume np: "a < (x - xa_max)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   738
                and b_eqs: "((x - xa_max) - a) @ z = b"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   739
              have "False"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   740
              proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   741
                let ?xa_max' = "xa_max @ a"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   742
                have "?xa_max' < x" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   743
                  using np h1 by (clarsimp simp:strict_prefix_def diff_prefix) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   744
                moreover have "?xa_max' \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   745
                  using a_in h2 by (simp add:star_intro3) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   746
                moreover have "(x - ?xa_max') @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   747
                  using b_eqs b_in np h1 by (simp add:diff_diff_appd)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   748
                moreover have "\<not> (length ?xa_max' \<le> length xa_max)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   749
                  using a_neq by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   750
                ultimately show ?thesis using h4 by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   751
              qed }
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   752
            -- {* Now it can be shown that the splitting goes the way we desired. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   753
            ultimately show ?P1 and ?P2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   754
          qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   755
          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
   756
          -- {* Now candidates @{text "?za"} and @{text "?zb"} have all the requred properteis. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   757
          with eq_xya have "(y - ya) @ ?za \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   758
            by (auto simp:str_eq_def str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   759
           with eq_z and b_in 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   760
          show ?thesis using that by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   761
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   762
        -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   763
           @{text "?thesis"} can easily be shown using properties of @{text "za"} and @{text "zb"}:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   764
            *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   765
        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
   766
        with eq_zab show ?thesis by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   767
      qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   768
      with h5 h6 show ?thesis 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   769
        by (drule_tac star_intro1, auto simp:strict_prefix_def elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   770
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   771
  } 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   772
  -- {* By instantiating the reasoning pattern just derived for both directions:*} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   773
  from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   774
  -- {* The thesis is proved as a trival consequence: *} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   775
    show  ?thesis unfolding str_eq_def str_eq_rel_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   776
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   777
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   778
lemma -- {* The oringal version with less explicit details. *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   779
  fixes v w
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   780
  assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   781
  shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   782
proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   783
    -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   784
    \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   785
    According to the definition of @{text "\<approx>Lang"}, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   786
    proving @{text "v \<approx>(L\<^isub>1\<star>) w"} amounts to
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   787
    showing: for any string @{text "u"},
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   788
    if @{text "v @ u \<in> (L\<^isub>1\<star>)"} then @{text "w @ u \<in> (L\<^isub>1\<star>)"} and vice versa.
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   789
    The reasoning pattern for both directions are the same, as derived
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   790
    in the following:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   791
    \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   792
    *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   793
  { fix x y z
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   794
    assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   795
      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
   796
    have "y @ z \<in> L\<^isub>1\<star>"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   797
    proof(cases "x = []")
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   798
      -- {* 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   799
        The degenerated case when @{text "x"} is a null string is easy to prove:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   800
        *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   801
      case True
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   802
      with tag_xy have "y = []" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   803
        by (auto simp:tag_str_STAR_def strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   804
      thus ?thesis using xz_in_star True by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   805
    next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   806
        -- {*
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   807
        \begin{minipage}{0.8\textwidth}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   808
        The case when @{text "x"} is not null, and
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   809
        @{text "x @ z"} is in @{text "L\<^isub>1\<star>"}, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   810
        \end{minipage}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   811
        *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   812
      case False
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   813
      obtain x_max 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   814
        where h1: "x_max < x" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   815
        and h2: "x_max \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   816
        and h3: "(x - x_max) @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   817
        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
   818
                                     \<longrightarrow> length xa \<le> length x_max"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   819
      proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   820
        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
   821
        have "finite ?S"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   822
          by (rule_tac B = "{xa. xa < x}" in finite_subset, 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   823
                                auto simp:finite_strict_prefix_set)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   824
        moreover have "?S \<noteq> {}" using False xz_in_star
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   825
          by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   826
        ultimately have "\<exists> max \<in> ?S. \<forall> a \<in> ?S. length a \<le> length max" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   827
          using finite_set_has_max by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   828
        thus ?thesis using that by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   829
      qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   830
      obtain ya 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   831
        where h5: "ya < y" and h6: "ya \<in> L\<^isub>1\<star>" and h7: "(x - x_max) \<approx>L\<^isub>1 (y - ya)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   832
      proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   833
        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
   834
          {\<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
   835
          by (auto simp:tag_str_STAR_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   836
        moreover have "\<approx>L\<^isub>1 `` {x - x_max} \<in> ?left" using h1 h2 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   837
        ultimately have "\<approx>L\<^isub>1 `` {x - x_max} \<in> ?right" by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   838
        with that show ?thesis apply 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   839
          (simp add:Image_def str_eq_rel_def str_eq_def) by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   840
      qed      
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   841
      have "(y - ya) @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   842
      proof-
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   843
        from h3 h1 obtain a b where a_in: "a \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   844
          and a_neq: "a \<noteq> []" and b_in: "b \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   845
          and ab_max: "(x - x_max) @ z = a @ b" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   846
          by (drule_tac star_decom, auto simp:strict_prefix_def elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   847
        have "(x - x_max) \<le> a \<and> (a - (x - x_max)) @ b = z" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   848
        proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   849
          have "((x - x_max) \<le> a \<and> (a - (x - x_max)) @ b = z) \<or> 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   850
                            (a < (x - x_max) \<and> ((x - x_max) - a) @ z = b)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   851
            using app_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   852
          moreover { 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   853
            assume np: "a < (x - x_max)" and b_eqs: " ((x - x_max) - a) @ z = b"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   854
            have "False"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   855
            proof -
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   856
              let ?x_max' = "x_max @ a"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   857
              have "?x_max' < x" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   858
                using np h1 by (clarsimp simp:strict_prefix_def diff_prefix) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   859
              moreover have "?x_max' \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   860
                using a_in h2 by (simp add:star_intro3) 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   861
              moreover have "(x - ?x_max') @ z \<in> L\<^isub>1\<star>" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   862
                using b_eqs b_in np h1 by (simp add:diff_diff_appd)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   863
              moreover have "\<not> (length ?x_max' \<le> length x_max)" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   864
                using a_neq by simp
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   865
              ultimately show ?thesis using h4 by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   866
            qed 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   867
          } ultimately show ?thesis by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   868
        qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   869
        then obtain za where z_decom: "z = za @ b" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   870
          and x_za: "(x - x_max) @ za \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   871
          using a_in by (auto elim:prefixE)        
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   872
        from x_za h7 have "(y - ya) @ za \<in> L\<^isub>1" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   873
          by (auto simp:str_eq_def str_eq_rel_def)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   874
	with b_in have "((y - ya) @ za) @ b \<in> L\<^isub>1\<star>" by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   875
        with z_decom show ?thesis by auto 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   876
      qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   877
      with h5 h6 show ?thesis 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   878
        by (drule_tac star_intro1, auto simp:strict_prefix_def elim:prefixE)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   879
    qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   880
  } 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   881
  -- {* By instantiating the reasoning pattern just derived for both directions:*} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   882
  from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   883
  -- {* The thesis is proved as a trival consequence: *} 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   884
    show  ?thesis unfolding str_eq_def str_eq_rel_def by blast
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   885
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   886
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   887
lemma quot_star_finiteI [intro]:
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   888
  fixes L1::"lang"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   889
  assumes finite1: "finite (UNIV // \<approx>L1)"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   890
  shows "finite (UNIV // \<approx>(L1\<star>))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   891
proof (rule_tac tag = "tag_str_STAR L1" in tag_finite_imageD)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   892
  show "\<And>x y. tag_str_STAR L1 x = tag_str_STAR L1 y \<Longrightarrow> x \<approx>(L1\<star>) y"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   893
    by (rule tag_str_STAR_injI)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   894
next
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   895
  have *: "finite (Pow (UNIV // \<approx>L1))" 
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   896
    using finite1 by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   897
  show "finite (range (tag_str_STAR L1))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   898
    unfolding tag_str_STAR_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   899
    apply(rule finite_subset[OF _ *])
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   900
    unfolding quotient_def
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   901
    by auto
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   902
qed
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   903
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   904
subsubsection{* The conclusion *}
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   905
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   906
lemma Myhill_Nerode2:
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   907
  fixes r::"rexp"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   908
  shows "finite (UNIV // \<approx>(L r))"
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   909
by (induct r) (auto)
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   910
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   911
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   912
section {* Closure properties *}
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   913
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   914
abbreviation
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   915
  reg :: "lang \<Rightarrow> bool"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   916
where
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   917
  "reg A \<equiv> \<exists>r::rexp. A = L r"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   918
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   919
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   920
theorem Myhill_Nerode:
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   921
  shows "reg A \<longleftrightarrow> finite (UNIV // \<approx>A)"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   922
using Myhill_Nerode1 Myhill_Nerode2 by auto
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   923
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   924
lemma closure_union[intro]:
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   925
  assumes "reg A" "reg B" 
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   926
  shows "reg (A \<union> B)"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   927
using assms
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   928
apply(auto)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   929
apply(rule_tac x="ALT r ra" in exI)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   930
apply(auto)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   931
done
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   932
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   933
lemma closure_seq[intro]:
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   934
  assumes "reg A" "reg B" 
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   935
  shows "reg (A ;; B)"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   936
using assms
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   937
apply(auto)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   938
apply(rule_tac x="SEQ r ra" in exI)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   939
apply(auto)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   940
done
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   941
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   942
lemma closure_star[intro]:
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   943
  assumes "reg A"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   944
  shows "reg (A\<star>)"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   945
using assms
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   946
apply(auto)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   947
apply(rule_tac x="STAR r" in exI)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   948
apply(auto)
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   949
done
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   950
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   951
lemma closure_complement[intro]:
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   952
  assumes "reg A"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   953
  shows "reg (- A)"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   954
using assms
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   955
unfolding Myhill_Nerode
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   956
unfolding str_eq_rel_def
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   957
by auto
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   958
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   959
lemma closure_difference[intro]:
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   960
  assumes "reg A" "reg B" 
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   961
  shows "reg (A - B)"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   962
proof -
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   963
  have "A - B = - ((- A) \<union> B)" by blast
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   964
  moreover
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   965
  have "reg (- ((- A) \<union> B))" 
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   966
    using assms by blast
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   967
  ultimately show "reg (A - B)" by simp
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   968
qed
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   969
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   970
lemma closure_intersection[intro]:
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   971
  assumes "reg A" "reg B" 
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   972
  shows "reg (A \<inter> B)"
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   973
proof -
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   974
  have "A \<inter> B = - ((- A) \<union> (- B))" by blast
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   975
  moreover
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   976
  have "reg (- ((- A) \<union> (- B)))" 
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   977
    using assms by blast
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   978
  ultimately show "reg (A \<inter> B)" by simp
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   979
qed
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   980
62fdb4bf7239 more on the conclusion
urbanc
parents: 109
diff changeset
   981
63
649ff0b8766d Myhill_2.thy added
zhang
parents:
diff changeset
   982
end