Myhill.thy
changeset 55 d71424eb5d0c
parent 49 59936c012add
child 56 b3898315e687
equal deleted inserted replaced
54:c19d2fc2cc69 55:d71424eb5d0c
    16   str_eq :: "string \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> bool" ("_ \<approx>_ _")
    16   str_eq :: "string \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> bool" ("_ \<approx>_ _")
    17 where
    17 where
    18   "x \<approx>Lang y \<equiv> (x, y) \<in> (\<approx>Lang)"
    18   "x \<approx>Lang y \<equiv> (x, y) \<in> (\<approx>Lang)"
    19 
    19 
    20 text {*
    20 text {*
    21   The basic idea to show the finiteness of the partition induced by relation @{text "\<approx>Lang"}
    21   The main lemma (@{text "rexp_imp_finite"}) is proved by a structural induction over regular expressions.
    22   is to attach a tag @{text "tag(x)"} to every string @{text "x"}, the set of tags are carfully 
    22   While base cases (cases for @{const "NULL"}, @{const "EMPTY"}, @{const "CHAR"}) are quite straight forward,
    23   choosen, so that the range of tagging function @{text "tag"} (denoted @{text "range(tag)"}) is finite. 
    23   the inductive cases are rather involved. What we have when starting to prove these inductive caes is that
    24   If strings with the same tag are equivlent with respect @{text "\<approx>Lang"},
    24   the partitions induced by the componet language are finite. The basic idea to show the finiteness of the 
    25   i.e. @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"} (this property is named `injectivity' in the following), 
    25   partition induced by the composite language is to attach a tag @{text "tag(x)"} to every string 
    26   then it can be proved that: the partition given rise by @{text "(\<approx>Lang)"} is finite. 
    26   @{text "x"}. The tags are made of equivalent classes from the component partitions. Let @{text "tag"}
    27   
    27   be the tagging function and @{text "Lang"} be the composite language, it can be proved that
    28   There are two arguments for this. The first goes as the following:
    28   if strings with the same tag are equivalent with respect to @{text "Lang"}, expressed as:
       
    29   \[
       
    30   @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"}
       
    31   \]
       
    32   then the partition induced by @{text "Lang"} must be finite. There are two arguments for this. 
       
    33   The first goes as the following:
    29   \begin{enumerate}
    34   \begin{enumerate}
    30     \item First, the tagging function @{text "tag"} induces an equivalent relation @{text "(=tag=)"} 
    35     \item First, the tagging function @{text "tag"} induces an equivalent relation @{text "(=tag=)"} 
    31           (defiintion of @{text "f_eq_rel"} and lemma @{text "equiv_f_eq_rel"}).
    36           (defiintion of @{text "f_eq_rel"} and lemma @{text "equiv_f_eq_rel"}).
    32     \item It is shown that: if the range of @{text "tag"} is finite, 
    37     \item It is shown that: if the range of @{text "tag"} (denoted @{text "range(tag)"}) is finite, 
    33            the partition given rise by @{text "(=tag=)"} is finite (lemma @{text "finite_eq_f_rel"}).
    38            the partition given rise by @{text "(=tag=)"} is finite (lemma @{text "finite_eq_f_rel"}).
       
    39            Since tags are made from equivalent classes from component partitions, and the inductive
       
    40            hypothesis ensures the finiteness of these partitions, it is not difficult to prove
       
    41            the finiteness of @{text "range(tag)"}.
    34     \item It is proved that if equivalent relation @{text "R1"} is more refined than @{text "R2"}
    42     \item It is proved that if equivalent relation @{text "R1"} is more refined than @{text "R2"}
    35            (expressed as @{text "R1 \<subseteq> R2"}),
    43            (expressed as @{text "R1 \<subseteq> R2"}),
    36            and the partition induced by @{text "R1"} is finite, then the partition induced by @{text "R2"}
    44            and the partition induced by @{text "R1"} is finite, then the partition induced by @{text "R2"}
    37            is finite as well (lemma @{text "refined_partition_finite"}).
    45            is finite as well (lemma @{text "refined_partition_finite"}).
    38     \item The injectivity assumption @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"} implies that
    46     \item The injectivity assumption @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"} implies that
   115     proof(rule finite_subset [of _ "Pow ?B"])
   123     proof(rule finite_subset [of _ "Pow ?B"])
   116       from fnt show "finite (Pow (A // R1))" by simp
   124       from fnt show "finite (Pow (A // R1))" by simp
   117     next
   125     next
   118       from eq2
   126       from eq2
   119       show " ?f ` A // R2 \<subseteq> Pow ?B"
   127       show " ?f ` A // R2 \<subseteq> Pow ?B"
   120         apply (unfold image_def Pow_def quotient_def, auto)
   128         unfolding image_def Pow_def quotient_def
       
   129         apply auto
   121         by (rule_tac x = xb in bexI, simp, 
   130         by (rule_tac x = xb in bexI, simp, 
   122                  unfold equiv_def sym_def refl_on_def, blast)
   131                  unfold equiv_def sym_def refl_on_def, blast)
   123     qed
   132     qed
   124   next
   133   next
   125     show "inj_on ?f ?A"
   134     show "inj_on ?f ?A"
   130         have "X = Y" using X_in
   139         have "X = Y" using X_in
   131         proof(rule quotientE)
   140         proof(rule quotientE)
   132           fix x
   141           fix x
   133           assume "X = R2 `` {x}" and "x \<in> A" with eq2
   142           assume "X = R2 `` {x}" and "x \<in> A" with eq2
   134           have x_in: "x \<in> X" 
   143           have x_in: "x \<in> X" 
   135             by (unfold equiv_def quotient_def refl_on_def, auto)
   144             unfolding equiv_def quotient_def refl_on_def by auto
   136           with eq_f have "R1 `` {x} \<in> ?R" by auto
   145           with eq_f have "R1 `` {x} \<in> ?R" by auto
   137           then obtain y where 
   146           then obtain y where 
   138             y_in: "y \<in> Y" and eq_r: "R1 `` {x} = R1 ``{y}" by auto
   147             y_in: "y \<in> Y" and eq_r: "R1 `` {x} = R1 ``{y}" by auto
   139           have "(x, y) \<in> R1"
   148           have "(x, y) \<in> R1"
   140           proof -
   149           proof -
   141             from x_in X_in y_in Y_in eq2
   150             from x_in X_in y_in Y_in eq2
   142             have "x \<in> A" and "y \<in> A" 
   151             have "x \<in> A" and "y \<in> A" 
   143               by (unfold equiv_def quotient_def refl_on_def, auto)
   152               unfolding equiv_def quotient_def refl_on_def by auto
   144             from eq_equiv_class_iff [OF eq1 this] and eq_r
   153             from eq_equiv_class_iff [OF eq1 this] and eq_r
   145             show ?thesis by simp
   154             show ?thesis by simp
   146           qed
   155           qed
   147           with refined have xy_r2: "(x, y) \<in> R2" by auto
   156           with refined have xy_r2: "(x, y) \<in> R2" by auto
   148           from quotient_eqI [OF eq2 X_in Y_in x_in y_in this]
   157           from quotient_eqI [OF eq2 X_in Y_in x_in y_in this]
   152     qed
   161     qed
   153   qed
   162   qed
   154 qed
   163 qed
   155 
   164 
   156 lemma equiv_lang_eq: "equiv UNIV (\<approx>Lang)"
   165 lemma equiv_lang_eq: "equiv UNIV (\<approx>Lang)"
   157   apply (unfold equiv_def str_eq_rel_def sym_def refl_on_def trans_def)
   166   unfolding equiv_def str_eq_rel_def sym_def refl_on_def trans_def
   158   by blast
   167   by blast
   159 
   168 
   160 lemma tag_finite_imageD:
   169 lemma tag_finite_imageD:
   161   fixes tag
   170   fixes tag
   162   assumes rng_fnt: "finite (range tag)" 
   171   assumes rng_fnt: "finite (range tag)" 
   243   qed
   252   qed
   244 qed
   253 qed
   245 
   254 
   246 subsection {* The proof*}
   255 subsection {* The proof*}
   247 
   256 
   248 subsubsection {* The case for @{const "NULL"} *}
   257 text {*
       
   258   Each case is given in a separate section, as well as the final main lemma. Detailed explainations accompanied by
       
   259   illustrations are given for non-trivial cases.
       
   260 
       
   261   
       
   262   For ever inductive case, there are two tasks, the easier one is to show the range finiteness of
       
   263   of the tagging function based on the finiteness of component partitions, the
       
   264   difficult one is to show that strings with the same tag are equivalent with respect to the 
       
   265   composite language. Suppose the composite language be @{text "Lang"}, tagging function be 
       
   266   @{text "tag"}, it amounts to show:
       
   267   \[
       
   268   @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"}
       
   269   \]
       
   270   expanding the definition of @{text "\<approx>Lang"}, it amounts to show:
       
   271   \[
       
   272   @{text "tag(x) = tag(y) \<Longrightarrow> (\<forall> z. x@z \<in> Lang \<longleftrightarrow> y@z \<in> Lang)"}
       
   273   \]
       
   274   Because the assumed tag equlity @{text "tag(x) = tag(y)"} is symmetric,
       
   275   it is suffcient to show just one direction:
       
   276   \[
       
   277   @{text "\<And> x y z. \<lbrakk>tag(x) = tag(y); x@z \<in> Lang\<rbrakk> \<Longrightarrow> y@z \<in> Lang"}
       
   278   \]
       
   279   This is the pattern followed by every inductive case.
       
   280   *}
       
   281 
       
   282 subsubsection {* The base case for @{const "NULL"} *}
   249 
   283 
   250 lemma quot_null_eq:
   284 lemma quot_null_eq:
   251   shows "(UNIV // \<approx>{}) = ({UNIV}::lang set)"
   285   shows "(UNIV // \<approx>{}) = ({UNIV}::lang set)"
   252   unfolding quotient_def Image_def str_eq_rel_def by auto
   286   unfolding quotient_def Image_def str_eq_rel_def by auto
   253 
   287 
   254 lemma quot_null_finiteI [intro]:
   288 lemma quot_null_finiteI [intro]:
   255   shows "finite ((UNIV // \<approx>{})::lang set)"
   289   shows "finite ((UNIV // \<approx>{})::lang set)"
   256 unfolding quot_null_eq by simp
   290 unfolding quot_null_eq by simp
   257 
   291 
   258 
   292 
   259 subsubsection {* The case for @{const "EMPTY"} *}
   293 subsubsection {* The base case for @{const "EMPTY"} *}
   260 
   294 
   261 
   295 
   262 lemma quot_empty_subset:
   296 lemma quot_empty_subset:
   263   "UNIV // (\<approx>{[]}) \<subseteq> {{[]}, UNIV - {[]}}"
   297   "UNIV // (\<approx>{[]}) \<subseteq> {{[]}, UNIV - {[]}}"
   264 proof
   298 proof
   281 lemma quot_empty_finiteI [intro]:
   315 lemma quot_empty_finiteI [intro]:
   282   shows "finite (UNIV // (\<approx>{[]}))"
   316   shows "finite (UNIV // (\<approx>{[]}))"
   283 by (rule finite_subset[OF quot_empty_subset]) (simp)
   317 by (rule finite_subset[OF quot_empty_subset]) (simp)
   284 
   318 
   285 
   319 
   286 subsubsection {* The case for @{const "CHAR"} *}
   320 subsubsection {* The base case for @{const "CHAR"} *}
   287 
   321 
   288 lemma quot_char_subset:
   322 lemma quot_char_subset:
   289   "UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}"
   323   "UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}"
   290 proof 
   324 proof 
   291   fix x 
   325   fix x 
   313 lemma quot_char_finiteI [intro]:
   347 lemma quot_char_finiteI [intro]:
   314   shows "finite (UNIV // (\<approx>{[c]}))"
   348   shows "finite (UNIV // (\<approx>{[c]}))"
   315 by (rule finite_subset[OF quot_char_subset]) (simp)
   349 by (rule finite_subset[OF quot_char_subset]) (simp)
   316 
   350 
   317 
   351 
   318 
   352 subsubsection {* The inductive case for @{const ALT} *}
   319 subsubsection {* The case for @{text "SEQ"}*}
       
   320 
       
   321 definition 
       
   322   tag_str_SEQ :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang set)"
       
   323 where
       
   324   "tag_str_SEQ L1 L2 = 
       
   325      (\<lambda>x. (\<approx>L1 `` {x}, {(\<approx>L2 `` {x - xa}) | xa.  xa \<le> x \<and> xa \<in> L1}))"
       
   326 
       
   327 
       
   328 lemma append_seq_elim:
       
   329   assumes "x @ y \<in> L\<^isub>1 ;; L\<^isub>2"
       
   330   shows "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2) \<or> 
       
   331           (\<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2)"
       
   332 proof-
       
   333   from assms obtain s\<^isub>1 s\<^isub>2 
       
   334     where "x @ y = s\<^isub>1 @ s\<^isub>2" 
       
   335     and in_seq: "s\<^isub>1 \<in> L\<^isub>1 \<and> s\<^isub>2 \<in> L\<^isub>2" 
       
   336     by (auto simp:Seq_def)
       
   337   hence "(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)"
       
   338     using app_eq_dest by auto
       
   339   moreover have "\<lbrakk>x \<le> s\<^isub>1; (s\<^isub>1 - x) @ s\<^isub>2 = y\<rbrakk> \<Longrightarrow> 
       
   340                        \<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2" 
       
   341     using in_seq by (rule_tac x = "s\<^isub>1 - x" in exI, auto elim:prefixE)
       
   342   moreover have "\<lbrakk>s\<^isub>1 \<le> x; (x - s\<^isub>1) @ y = s\<^isub>2\<rbrakk> \<Longrightarrow> 
       
   343                     \<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2" 
       
   344     using in_seq by (rule_tac x = s\<^isub>1 in exI, auto)
       
   345   ultimately show ?thesis by blast
       
   346 qed
       
   347 
       
   348 lemma tag_str_SEQ_injI:
       
   349   "tag_str_SEQ L\<^isub>1 L\<^isub>2 m = tag_str_SEQ L\<^isub>1 L\<^isub>2 n \<Longrightarrow> m \<approx>(L\<^isub>1 ;; L\<^isub>2) n"
       
   350 proof-
       
   351   { fix x y z
       
   352     assume xz_in_seq: "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"
       
   353     and tag_xy: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
       
   354     have"y @ z \<in> L\<^isub>1 ;; L\<^isub>2" 
       
   355     proof-
       
   356       have "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ z \<in> L\<^isub>2) \<or> 
       
   357                (\<exists> za \<le> z. (x @ za) \<in> L\<^isub>1 \<and> (z - za) \<in> L\<^isub>2)"
       
   358         using xz_in_seq append_seq_elim by simp
       
   359       moreover {
       
   360         fix xa
       
   361         assume h1: "xa \<le> x" and h2: "xa \<in> L\<^isub>1" and h3: "(x - xa) @ z \<in> L\<^isub>2"
       
   362         obtain ya where "ya \<le> y" and "ya \<in> L\<^isub>1" and "(y - ya) @ z \<in> L\<^isub>2" 
       
   363         proof -
       
   364           have "\<exists> ya.  ya \<le> y \<and> ya \<in> L\<^isub>1 \<and> (x - xa) \<approx>L\<^isub>2 (y - ya)"
       
   365           proof -
       
   366             have "{\<approx>L\<^isub>2 `` {x - xa} |xa. xa \<le> x \<and> xa \<in> L\<^isub>1} = 
       
   367                   {\<approx>L\<^isub>2 `` {y - xa} |xa. xa \<le> y \<and> xa \<in> L\<^isub>1}" 
       
   368                           (is "?Left = ?Right") 
       
   369               using h1 tag_xy by (auto simp:tag_str_SEQ_def)
       
   370             moreover have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Left" using h1 h2 by auto
       
   371             ultimately have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Right" by simp
       
   372             thus ?thesis by (auto simp:Image_def str_eq_rel_def str_eq_def)
       
   373           qed
       
   374           with prems show ?thesis by (auto simp:str_eq_rel_def str_eq_def)
       
   375         qed
       
   376         hence "y @ z \<in> L\<^isub>1 ;; L\<^isub>2" by (erule_tac prefixE, auto simp:Seq_def)          
       
   377       } moreover {
       
   378         fix za
       
   379         assume h1: "za \<le> z" and h2: "(x @ za) \<in> L\<^isub>1" and h3: "z - za \<in> L\<^isub>2"
       
   380         hence "y @ za \<in> L\<^isub>1"
       
   381         proof-
       
   382           have "\<approx>L\<^isub>1 `` {x} = \<approx>L\<^isub>1 `` {y}" 
       
   383             using h1 tag_xy by (auto simp:tag_str_SEQ_def)
       
   384           with h2 show ?thesis 
       
   385             by (auto simp:Image_def str_eq_rel_def str_eq_def) 
       
   386         qed
       
   387         with h1 h3 have "y @ z \<in> L\<^isub>1 ;; L\<^isub>2" 
       
   388           by (drule_tac A = L\<^isub>1 in seq_intro, auto elim:prefixE)
       
   389       }
       
   390       ultimately show ?thesis by blast
       
   391     qed
       
   392   } thus "tag_str_SEQ L\<^isub>1 L\<^isub>2 m = tag_str_SEQ L\<^isub>1 L\<^isub>2 n \<Longrightarrow> m \<approx>(L\<^isub>1 ;; L\<^isub>2) n" 
       
   393     by (auto simp add: str_eq_def str_eq_rel_def)
       
   394 qed 
       
   395 
       
   396 lemma quot_seq_finiteI [intro]:
       
   397   fixes L1 L2::"lang"
       
   398   assumes fin1: "finite (UNIV // \<approx>L1)" 
       
   399   and     fin2: "finite (UNIV // \<approx>L2)" 
       
   400   shows "finite (UNIV // \<approx>(L1 ;; L2))"
       
   401 proof (rule_tac tag = "tag_str_SEQ L1 L2" in tag_finite_imageD)
       
   402   show "\<And>x y. tag_str_SEQ L1 L2 x = tag_str_SEQ L1 L2 y \<Longrightarrow> x \<approx>(L1 ;; L2) y"
       
   403     by (rule tag_str_SEQ_injI)
       
   404 next
       
   405   have *: "finite ((UNIV // \<approx>L1) \<times> (Pow (UNIV // \<approx>L2)))" 
       
   406     using fin1 fin2 by auto
       
   407   show "finite (range (tag_str_SEQ L1 L2))" 
       
   408     unfolding tag_str_SEQ_def
       
   409     apply(rule finite_subset[OF _ *])
       
   410     unfolding quotient_def
       
   411     by auto
       
   412 qed
       
   413 
       
   414 subsubsection {* The case for @{const ALT} *}
       
   415 
   353 
   416 definition 
   354 definition 
   417   tag_str_ALT :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang)"
   355   tag_str_ALT :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang)"
   418 where
   356 where
   419   "tag_str_ALT L1 L2 = (\<lambda>x. (\<approx>L1 `` {x}, \<approx>L2 `` {x}))"
   357   "tag_str_ALT L1 L2 = (\<lambda>x. (\<approx>L1 `` {x}, \<approx>L2 `` {x}))"
   420 
       
   421 
   358 
   422 lemma quot_union_finiteI [intro]:
   359 lemma quot_union_finiteI [intro]:
   423   fixes L1 L2::"lang"
   360   fixes L1 L2::"lang"
   424   assumes finite1: "finite (UNIV // \<approx>L1)"
   361   assumes finite1: "finite (UNIV // \<approx>L1)"
   425   and     finite2: "finite (UNIV // \<approx>L2)"
   362   and     finite2: "finite (UNIV // \<approx>L2)"
   439     apply(rule finite_subset[OF _ *])
   376     apply(rule finite_subset[OF _ *])
   440     unfolding quotient_def
   377     unfolding quotient_def
   441     by auto
   378     by auto
   442 qed
   379 qed
   443 
   380 
   444 subsubsection {* The case for @{const "STAR"} *}
   381 subsubsection {* The inductive case for @{text "SEQ"}*}
       
   382 
       
   383 text {*
       
   384   For case @{const "SEQ"}, the language @{text "L"} is @{text "L\<^isub>1 ;; L\<^isub>2"}.
       
   385   Given @{text "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"}, according to the defintion of @{text " L\<^isub>1 ;; L\<^isub>2"},
       
   386   string @{text "x @ z"} can be splitted with the prefix in @{text "L\<^isub>1"} and suffix in @{text "L\<^isub>2"}.
       
   387   The split point can either be in @{text "x"} (as shown in Fig. \ref{seq_first_split}),
       
   388   or in @{text "z"} (as shown in Fig. \ref{seq_snd_split}). Whichever way it goes, the structure
       
   389   on @{text "x @ z"} cn be transfered faithfully onto @{text "y @ z"} 
       
   390   (as shown in Fig. \ref{seq_trans_first_split} and \ref{seq_trans_snd_split}) with the the help of the assumed 
       
   391   tag equality. The following tag function @{text "tag_str_SEQ"} is such designed to facilitate
       
   392   such transfers and lemma @{text "tag_str_SEQ_injI"} formalizes the informal argument above. The details 
       
   393   of structure transfer will be given their.
       
   394 \input{fig_seq}
       
   395 
       
   396   *}
       
   397 
       
   398 definition 
       
   399   tag_str_SEQ :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang set)"
       
   400 where
       
   401   "tag_str_SEQ L1 L2 = 
       
   402      (\<lambda>x. (\<approx>L1 `` {x}, {(\<approx>L2 `` {x - xa}) | xa.  xa \<le> x \<and> xa \<in> L1}))"
       
   403 
       
   404 text {* The following is a techical lemma which helps to split the @{text "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"} mentioned above.*}
       
   405 
       
   406 lemma append_seq_elim:
       
   407   assumes "x @ y \<in> L\<^isub>1 ;; L\<^isub>2"
       
   408   shows "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2) \<or> 
       
   409           (\<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2)"
       
   410 proof-
       
   411   from assms obtain s\<^isub>1 s\<^isub>2 
       
   412     where eq_xys: "x @ y = s\<^isub>1 @ s\<^isub>2" 
       
   413     and in_seq: "s\<^isub>1 \<in> L\<^isub>1 \<and> s\<^isub>2 \<in> L\<^isub>2" 
       
   414     by (auto simp:Seq_def)
       
   415   from app_eq_dest [OF eq_xys]
       
   416   have
       
   417     "(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)" 
       
   418                (is "?Split1 \<or> ?Split2") .
       
   419   moreover have "?Split1 \<Longrightarrow> \<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2" 
       
   420     using in_seq by (rule_tac x = "s\<^isub>1 - x" in exI, auto elim:prefixE)
       
   421   moreover have "?Split2 \<Longrightarrow> \<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2" 
       
   422     using in_seq by (rule_tac x = s\<^isub>1 in exI, auto)
       
   423   ultimately show ?thesis by blast
       
   424 qed
       
   425 
       
   426 
       
   427 lemma tag_str_SEQ_injI:
       
   428   fixes v w 
       
   429   assumes eq_tag: "tag_str_SEQ L\<^isub>1 L\<^isub>2 v = tag_str_SEQ L\<^isub>1 L\<^isub>2 w" 
       
   430   shows "v \<approx>(L\<^isub>1 ;; L\<^isub>2) w"
       
   431 proof-
       
   432     -- {* As explained before, a pattern for just one direction needs to be dealt with:*}
       
   433   { fix x y z
       
   434     assume xz_in_seq: "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"
       
   435     and tag_xy: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
       
   436     have"y @ z \<in> L\<^isub>1 ;; L\<^isub>2" 
       
   437     proof-
       
   438       -- {* There are two ways to split @{text "x@z"}: *}
       
   439       from append_seq_elim [OF xz_in_seq]
       
   440       have "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ z \<in> L\<^isub>2) \<or> 
       
   441                (\<exists> za \<le> z. (x @ za) \<in> L\<^isub>1 \<and> (z - za) \<in> L\<^isub>2)" .
       
   442       -- {* It can be shown that @{text "?thesis"} holds in either case: *}
       
   443       moreover {
       
   444         -- {* The case for the first split:*}
       
   445         fix xa
       
   446         assume h1: "xa \<le> x" and h2: "xa \<in> L\<^isub>1" and h3: "(x - xa) @ z \<in> L\<^isub>2"
       
   447         -- {* The following subgoal implements the structure transfer:*}
       
   448         obtain ya 
       
   449           where "ya \<le> y" 
       
   450           and "ya \<in> L\<^isub>1" 
       
   451           and "(y - ya) @ z \<in> L\<^isub>2"
       
   452         proof -
       
   453         -- {*
       
   454             \begin{minipage}{0.8\textwidth}
       
   455             By expanding the definition of 
       
   456             @{thm [display] "tag_xy"}
       
   457             and extracting the second compoent, we get:
       
   458             \end{minipage}
       
   459             *}
       
   460           have "{\<approx>L\<^isub>2 `` {x - xa} |xa. xa \<le> x \<and> xa \<in> L\<^isub>1} = 
       
   461                    {\<approx>L\<^isub>2 `` {y - ya} |ya. ya \<le> y \<and> ya \<in> L\<^isub>1}" (is "?Left = ?Right")
       
   462             using tag_xy unfolding tag_str_SEQ_def by simp
       
   463             -- {* Since @{thm "h1"} and @{thm "h2"} hold, it is not difficult to show: *}
       
   464           moreover have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Left" using h1 h2 by auto
       
   465             -- {* 
       
   466             \begin{minipage}{0.7\textwidth}
       
   467             Through tag equality, equivalent class @{term "\<approx>L\<^isub>2 `` {x - xa}"} also 
       
   468                   belongs to the @{text "?Right"}:
       
   469             \end{minipage}
       
   470             *}
       
   471           ultimately have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Right" by simp
       
   472             -- {* From this, the counterpart of @{text "xa"} in @{text "y"} is obtained:*}
       
   473           then obtain ya 
       
   474             where eq_xya: "\<approx>L\<^isub>2 `` {x - xa} = \<approx>L\<^isub>2 `` {y - ya}" 
       
   475             and pref_ya: "ya \<le> y" and ya_in: "ya \<in> L\<^isub>1"
       
   476             by simp blast
       
   477           -- {* It can be proved that @{text "ya"} has the desired property:*}
       
   478           have "(y - ya)@z \<in> L\<^isub>2" 
       
   479           proof -
       
   480             from eq_xya have "(x - xa)  \<approx>L\<^isub>2 (y - ya)" 
       
   481               unfolding Image_def str_eq_rel_def str_eq_def by auto
       
   482             with h3 show ?thesis unfolding str_eq_rel_def str_eq_def by simp
       
   483           qed
       
   484           -- {* Now, @{text "ya"} has all properties to be a qualified candidate:*}
       
   485           with pref_ya ya_in 
       
   486           show ?thesis using prems by blast
       
   487         qed
       
   488           -- {* From the properties of @{text "ya"}, @{text "y @ z \<in> L\<^isub>1 ;; L\<^isub>2"} is derived easily.*}
       
   489         hence "y @ z \<in> L\<^isub>1 ;; L\<^isub>2" by (erule_tac prefixE, auto simp:Seq_def)
       
   490       } moreover {
       
   491         -- {* The other case is even more simpler: *}
       
   492         fix za
       
   493         assume h1: "za \<le> z" and h2: "(x @ za) \<in> L\<^isub>1" and h3: "z - za \<in> L\<^isub>2"
       
   494         have "y @ za \<in> L\<^isub>1"
       
   495         proof-
       
   496           have "\<approx>L\<^isub>1 `` {x} = \<approx>L\<^isub>1 `` {y}" 
       
   497             using tag_xy unfolding tag_str_SEQ_def by simp
       
   498           with h2 show ?thesis
       
   499             unfolding Image_def str_eq_rel_def str_eq_def by auto
       
   500         qed
       
   501         with h1 h3 have "y @ z \<in> L\<^isub>1 ;; L\<^isub>2" 
       
   502           by (drule_tac A = L\<^isub>1 in seq_intro, auto elim:prefixE)
       
   503       }
       
   504       ultimately show ?thesis by blast
       
   505     qed
       
   506   } 
       
   507   -- {* 
       
   508       \begin{minipage}{0.8\textwidth}
       
   509       @{text "?thesis"} is proved by exploiting the symmetry of 
       
   510       @{thm [source] "eq_tag"}:
       
   511       \end{minipage}
       
   512       *}
       
   513   from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
       
   514     show ?thesis unfolding str_eq_def str_eq_rel_def by blast
       
   515 qed 
       
   516 
       
   517 lemma quot_seq_finiteI [intro]:
       
   518   fixes L1 L2::"lang"
       
   519   assumes fin1: "finite (UNIV // \<approx>L1)" 
       
   520   and     fin2: "finite (UNIV // \<approx>L2)" 
       
   521   shows "finite (UNIV // \<approx>(L1 ;; L2))"
       
   522 proof (rule_tac tag = "tag_str_SEQ L1 L2" in tag_finite_imageD)
       
   523   show "\<And>x y. tag_str_SEQ L1 L2 x = tag_str_SEQ L1 L2 y \<Longrightarrow> x \<approx>(L1 ;; L2) y"
       
   524     by (rule tag_str_SEQ_injI)
       
   525 next
       
   526   have *: "finite ((UNIV // \<approx>L1) \<times> (Pow (UNIV // \<approx>L2)))" 
       
   527     using fin1 fin2 by auto
       
   528   show "finite (range (tag_str_SEQ L1 L2))" 
       
   529     unfolding tag_str_SEQ_def
       
   530     apply(rule finite_subset[OF _ *])
       
   531     unfolding quotient_def
       
   532     by auto
       
   533 qed
       
   534 
       
   535 subsubsection {* The inductive case for @{const "STAR"} *}
   445 
   536 
   446 text {* 
   537 text {* 
   447   This turned out to be the trickiest case. The essential goal is 
   538   This turned out to be the trickiest case. The essential goal is 
   448   to proved @{text "y @ z \<in>  L\<^isub>1*"} under the assumptions that @{text "x @ z \<in>  L\<^isub>1*"}
   539   to proved @{text "y @ z \<in>  L\<^isub>1*"} under the assumptions that @{text "x @ z \<in>  L\<^isub>1*"}
   449   and that @{text "x"} and @{text "y"} have the same tag. The reasoning goes as the following:
   540   and that @{text "x"} and @{text "y"} have the same tag. The reasoning goes as the following:
   450   \begin{enumerate}
   541   \begin{enumerate}
   451     \item Since @{text "x @ z \<in>  L\<^isub>1*"} holds, a prefix @{text "xa"} of @{text "x"} can be found
   542     \item Since @{text "x @ z \<in>  L\<^isub>1*"} holds, a prefix @{text "xa"} of @{text "x"} can be found
   452           such that @{text "xa \<in> L\<^isub>1*"} and @{text "(x - xa)@z \<in> L\<^isub>1*"}, as shown in Fig. \ref{first_split}(a).
   543           such that @{text "xa \<in> L\<^isub>1*"} and @{text "(x - xa)@z \<in> L\<^isub>1*"}, as shown in Fig. \ref{first_split}.
   453           Such a prefix always exists, @{text "xa = []"}, for example, is one. 
   544           Such a prefix always exists, @{text "xa = []"}, for example, is one. 
   454     \item There could be many but fintie many of such @{text "xa"}, from which we can find the longest
   545     \item There could be many but fintie many of such @{text "xa"}, from which we can find the longest
   455           and name it @{text "xa_max"}, as shown in Fig. \ref{max_split}(b).
   546           and name it @{text "xa_max"}, as shown in Fig. \ref{max_split}.
   456     \item The next step is to split @{text "z"} into @{text "za"} and @{text "zb"} such that
   547     \item The next step is to split @{text "z"} into @{text "za"} and @{text "zb"} such that
   457            @{text "(x - xa_max) @ za \<in> L\<^isub>1"} and @{text "zb \<in> L\<^isub>1*"}  as shown in Fig. \ref{last_split}(d).
   548            @{text "(x - xa_max) @ za \<in> L\<^isub>1"} and @{text "zb \<in> L\<^isub>1*"}  as shown in Fig. \ref{last_split}.
   458           Such a split always exists because:
   549           Such a split always exists because:
   459           \begin{enumerate}
   550           \begin{enumerate}
   460             \item Because @{text "(x - x_max) @ z \<in> L\<^isub>1*"}, it can always be split into prefix @{text "a"}
   551             \item Because @{text "(x - x_max) @ z \<in> L\<^isub>1*"}, it can always be splitted into prefix @{text "a"}
   461               and suffix @{text "b"}, such that @{text "a \<in> L\<^isub>1"} and @{text "b \<in> L\<^isub>1*"},
   552               and suffix @{text "b"}, such that @{text "a \<in> L\<^isub>1"} and @{text "b \<in> L\<^isub>1*"},
   462               as shown in Fig. \ref{ab_split}(c).
   553               as shown in Fig. \ref{ab_split}.
   463             \item But the prefix @{text "a"} CANNOT be shorter than @{text "x - xa_max"}, otherwise
   554             \item But the prefix @{text "a"} CANNOT be shorter than @{text "x - xa_max"} 
   464                    @{text "xa_max"} is not the max in it's kind.
   555               (as shown in Fig. \ref{ab_split_wrong}), becasue otherwise,
   465             \item Now, @{text "za"} is just @{text "a - (x - xa_max)"} and @{text "zb"} is just @{text "b"}.
   556                    @{text "ma_max@a"} would be in the same kind as @{text "xa_max"} but with 
       
   557                    a larger size, conflicting with the fact that @{text "xa_max"} is the longest.
   466           \end{enumerate}
   558           \end{enumerate}
   467     \item  \label{tansfer_step} 
   559     \item  \label{tansfer_step} 
   468          By the assumption that @{text "x"} and @{text "y"} have the same tag, the structure on @{text "x @ z"}
   560          By the assumption that @{text "x"} and @{text "y"} have the same tag, the structure on @{text "x @ z"}
   469           can be transferred to @{text "y @ z"} as shown in Fig. \ref{trans_split}(e). The detailed steps are:
   561           can be transferred to @{text "y @ z"} as shown in Fig. \ref{trans_split}. The detailed steps are:
   470           \begin{enumerate}
   562           \begin{enumerate}
   471             \item A @{text "y"}-prefix @{text "ya"} corresponding to @{text "xa"} can be found, 
   563             \item A @{text "y"}-prefix @{text "ya"} corresponding to @{text "xa"} can be found, 
   472                   which satisfies conditions: @{text "ya \<in> L\<^isub>1*"} and @{text "(y - ya)@za \<in> L\<^isub>1"}.
   564                   which satisfies conditions: @{text "ya \<in> L\<^isub>1*"} and @{text "(y - ya)@za \<in> L\<^isub>1"}.
   473             \item Since we already know @{text "zb \<in> L\<^isub>1*"}, we get @{text "(y - ya)@za@zb \<in> L\<^isub>1*"},
   565             \item Since we already know @{text "zb \<in> L\<^isub>1*"}, we get @{text "(y - ya)@za@zb \<in> L\<^isub>1*"},
   474                   and this is just @{text "(y - ya)@z \<in> L\<^isub>1*"}.
   566                   and this is just @{text "(y - ya)@z \<in> L\<^isub>1*"}.
   476           \end{enumerate}
   568           \end{enumerate}
   477   \end{enumerate}
   569   \end{enumerate}
   478 
   570 
   479   The formal proof of lemma @{text "tag_str_STAR_injI"} faithfully follows this informal argument 
   571   The formal proof of lemma @{text "tag_str_STAR_injI"} faithfully follows this informal argument 
   480   while the tagging function @{text "tag_str_STAR"} is defined to make the transfer in step
   572   while the tagging function @{text "tag_str_STAR"} is defined to make the transfer in step
   481   \ref{transfer_step}4 feasible.
   573   \ref{ansfer_step} feasible.
   482 
   574 
   483    
   575   \input{fig_star}
   484 \begin{figure}[h!]
       
   485 \centering
       
   486 \subfigure[First split]{\label{first_split}
       
   487 \scalebox{0.9}{
       
   488 \begin{tikzpicture}
       
   489     \node[draw,minimum height=3.8ex] (xa) {$\hspace{2em}xa\hspace{2em}$};
       
   490     \node[draw,minimum height=3.8ex, right=-0.03em of xa] (xxa) { $\hspace{5em}x - xa\hspace{5em}$ };
       
   491     \node[draw,minimum height=3.8ex, right=-0.03em of xxa] (z) { $\hspace{21em}$ };
       
   492 
       
   493     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   494            (xa.north west) -- ($(xxa.north east)+(0em,0em)$)
       
   495                node[midway, above=0.5em]{$x$};
       
   496 
       
   497     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   498            (z.north west) -- ($(z.north east)+(0em,0em)$)
       
   499                node[midway, above=0.5em]{$z$};
       
   500 
       
   501     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   502            ($(xa.north west)+(0em,3ex)$) -- ($(z.north east)+(0em,3ex)$)
       
   503                node[midway, above=0.8em]{$x @ z \in L_1*$};
       
   504 
       
   505     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   506            ($(z.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$)
       
   507                node[midway, below=0.5em]{$(x - xa) @ z \in L_1*$};
       
   508 
       
   509     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   510            ($(xa.south east)+(0em,0ex)$) -- ($(xa.south west)+(0em,0ex)$)
       
   511                node[midway, below=0.5em]{$xa \in L_1*$};
       
   512 \end{tikzpicture}}}
       
   513 
       
   514 \subfigure[Max split]{\label{max_split}
       
   515 \scalebox{0.9}{
       
   516 \begin{tikzpicture}
       
   517     \node[draw,minimum height=3.8ex] (xa) { $\hspace{4em}xa\_max\hspace{4em}$ };
       
   518     \node[draw,minimum height=3.8ex, right=-0.03em of xa] (xxa) { $\hspace{0.5em}x - xa\_max\hspace{0.5em}$ };
       
   519     \node[draw,minimum height=3.8ex, right=-0.03em of xxa] (z) { $\hspace{21em}$ };
       
   520 
       
   521     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   522            (xa.north west) -- ($(xxa.north east)+(0em,0em)$)
       
   523                node[midway, above=0.5em]{$x$};
       
   524 
       
   525     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   526            (z.north west) -- ($(z.north east)+(0em,0em)$)
       
   527                node[midway, above=0.5em]{$z$};
       
   528 
       
   529     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   530            ($(xa.north west)+(0em,3ex)$) -- ($(z.north east)+(0em,3ex)$)
       
   531                node[midway, above=0.8em]{$x @ z \in L_1*$};
       
   532 
       
   533     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   534            ($(z.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$)
       
   535                node[midway, below=0.5em]{$(x - xa\_max) @ z \in L_1*$};
       
   536 
       
   537     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   538            ($(xa.south east)+(0em,0ex)$) -- ($(xa.south west)+(0em,0ex)$)
       
   539                node[midway, below=0.5em]{$xa \in L_1*$};
       
   540 \end{tikzpicture}}}
       
   541 
       
   542 \subfigure[Max split with $a$ and $b$]{\label{ab_split}
       
   543 \scalebox{0.9}{
       
   544 \begin{tikzpicture}
       
   545     \node[draw,minimum height=3.8ex] (xa) { $\hspace{4em}xa\_max\hspace{4em}$ };
       
   546     \node[draw,minimum height=3.8ex, right=-0.03em of xa] (xxa) { $\hspace{0.5em}x - xa\_max\hspace{0.5em}$ };
       
   547     \node[draw,minimum height=3.8ex, right=-0.03em of xxa] (z) { $\hspace{21em}$ };
       
   548 
       
   549     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   550            (xa.north west) -- ($(xxa.north east)+(0em,0em)$)
       
   551                node[midway, above=0.5em]{$x$};
       
   552 
       
   553     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   554            (z.north west) -- ($(z.north east)+(0em,0em)$)
       
   555                node[midway, above=0.5em]{$z$};
       
   556 
       
   557     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   558            ($(xa.north west)+(0em,3ex)$) -- ($(z.north east)+(0em,3ex)$)
       
   559                node[midway, above=0.8em]{$x @ z \in L_1*$};
       
   560 
       
   561     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   562            ($(z.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$)
       
   563                node[midway, below=0.5em]{$(x - xa\_max) @ z \in L_1*$};
       
   564 
       
   565     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   566            ($(xa.south east)+(0em,0ex)$) -- ($(xa.south west)+(0em,0ex)$)
       
   567                node[midway, below=0.5em]{$xa \in L_1*$};
       
   568 
       
   569     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   570            ($(xxa.south east)+(6em,-5ex)$) -- ($(xxa.south west)+(0em,-5ex)$)
       
   571                node[midway, below=0.5em]{$a \in L_1$};
       
   572 
       
   573     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   574            ($(z.south east)+(0em,-5ex)$) -- ($(xxa.south east)+(6em,-5ex)$)
       
   575                node[midway, below=0.5em]{$b \in L_1*$};
       
   576 
       
   577 \end{tikzpicture}}}
       
   578 
       
   579 \subfigure[Last split]{\label{last_split}
       
   580 \scalebox{0.9}{
       
   581 \begin{tikzpicture}
       
   582     \node[draw,minimum height=3.8ex] (xa) { $\hspace{4em}xa\_max\hspace{4em}$ };
       
   583     \node[draw,minimum height=3.8ex, right=-0.03em of xa] (xxa) { $\hspace{0.5em}x - xa\_max\hspace{0.5em}$ };
       
   584     \node[draw,minimum height=3.8ex, right=-0.03em of xxa] (za) { $\hspace{2em}za\hspace{2em}$ };
       
   585     \node[draw,minimum height=3.8ex, right=-0.03em of za] (zb) { $\hspace{7em}zb\hspace{7em}$ };
       
   586 
       
   587     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   588            (xa.north west) -- ($(xxa.north east)+(0em,0em)$)
       
   589                node[midway, above=0.5em]{$x$};
       
   590 
       
   591     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   592            (za.north west) -- ($(zb.north east)+(0em,0em)$)
       
   593                node[midway, above=0.5em]{$z$};
       
   594 
       
   595     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   596            ($(xa.north west)+(0em,3ex)$) -- ($(zb.north east)+(0em,3ex)$)
       
   597                node[midway, above=0.8em]{$x @ z \in L_1*$};
       
   598 
       
   599     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   600            ($(za.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$)
       
   601                node[midway, below=0.5em]{$(x - xa\_max) @ za \in L_1$};
       
   602 
       
   603     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   604            ($(xa.south east)+(0em,0ex)$) -- ($(xa.south west)+(0em,0ex)$)
       
   605                node[midway, below=0.5em]{$xa\_max \in L_1*$};
       
   606 
       
   607     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   608            ($(zb.south east)+(0em,0ex)$) -- ($(zb.south west)+(0em,0ex)$)
       
   609                node[midway, below=0.5em]{$zb \in L_1*$};
       
   610 
       
   611     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   612            ($(zb.south east)+(0em,-4ex)$) -- ($(xxa.south west)+(0em,-4ex)$)
       
   613                node[midway, below=0.5em]{$(x - xa\_max)@z \in L_1*$};
       
   614 \end{tikzpicture}}}
       
   615 
       
   616 
       
   617 \subfigure[Transferring to $y$]{\label{trans_split}
       
   618 \scalebox{0.9}{
       
   619 \begin{tikzpicture}
       
   620     \node[draw,minimum height=3.8ex] (xa) { $\hspace{5em}ya\hspace{5em}$ };
       
   621     \node[draw,minimum height=3.8ex, right=-0.03em of xa] (xxa) { $\hspace{2em}y - ya\hspace{2em}$ };
       
   622     \node[draw,minimum height=3.8ex, right=-0.03em of xxa] (za) { $\hspace{2em}za\hspace{2em}$ };
       
   623     \node[draw,minimum height=3.8ex, right=-0.03em of za] (zb) { $\hspace{7em}zb\hspace{7em}$ };
       
   624 
       
   625     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   626            (xa.north west) -- ($(xxa.north east)+(0em,0em)$)
       
   627                node[midway, above=0.5em]{$y$};
       
   628 
       
   629     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   630            (za.north west) -- ($(zb.north east)+(0em,0em)$)
       
   631                node[midway, above=0.5em]{$z$};
       
   632 
       
   633     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   634            ($(xa.north west)+(0em,3ex)$) -- ($(zb.north east)+(0em,3ex)$)
       
   635                node[midway, above=0.8em]{$y @ z \in L_1*$};
       
   636 
       
   637     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   638            ($(za.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$)
       
   639                node[midway, below=0.5em]{$(y - ya) @ za \in L_1$};
       
   640 
       
   641     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   642            ($(xa.south east)+(0em,0ex)$) -- ($(xa.south west)+(0em,0ex)$)
       
   643                node[midway, below=0.5em]{$ya \in L_1*$};
       
   644 
       
   645     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   646            ($(zb.south east)+(0em,0ex)$) -- ($(zb.south west)+(0em,0ex)$)
       
   647                node[midway, below=0.5em]{$zb \in L_1*$};
       
   648 
       
   649     \draw[decoration={brace,transform={yscale=3}},decorate]
       
   650            ($(zb.south east)+(0em,-4ex)$) -- ($(xxa.south west)+(0em,-4ex)$)
       
   651                node[midway, below=0.5em]{$(y - ya)@z \in L_1*$};
       
   652 \end{tikzpicture}}}
       
   653 
       
   654 \caption{The case for $STAR$}
       
   655 \end{figure}
       
   656 
       
   657 *} 
   576 *} 
   658 
   577 
   659 definition 
   578 definition 
   660   tag_str_STAR :: "lang \<Rightarrow> string \<Rightarrow> lang set"
   579   tag_str_STAR :: "lang \<Rightarrow> string \<Rightarrow> lang set"
   661 where
   580 where
   686     qed
   605     qed
   687   qed
   606   qed
   688 qed
   607 qed
   689 
   608 
   690 
   609 
   691 text {* Technical lemma. *}
   610 text {* The following is a technical lemma.which helps to show the range finiteness of tag function. *}
   692 lemma finite_strict_prefix_set: "finite {xa. xa < (x::string)}"
   611 lemma finite_strict_prefix_set: "finite {xa. xa < (x::string)}"
   693 apply (induct x rule:rev_induct, simp)
   612 apply (induct x rule:rev_induct, simp)
   694 apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \<union> {xs}")
   613 apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \<union> {xs}")
   695 by (auto simp:strict_prefix_def)
   614 by (auto simp:strict_prefix_def)
   696 
   615 
   698 lemma tag_str_STAR_injI:
   617 lemma tag_str_STAR_injI:
   699   fixes v w
   618   fixes v w
   700   assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
   619   assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
   701   shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
   620   shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
   702 proof-
   621 proof-
   703     -- {* 
   622     -- {* As explained before, a pattern for just one direction needs to be dealt with:*}
   704     \begin{minipage}{0.9\textwidth}
       
   705     According to the definition of @{text "\<approx>Lang"}, 
       
   706     proving @{text "v \<approx>(L\<^isub>1\<star>) w"} amounts to
       
   707     showing: for any string @{text "u"},
       
   708     if @{text "v @ u \<in> (L\<^isub>1\<star>)"} then @{text "w @ u \<in> (L\<^isub>1\<star>)"} and vice versa.
       
   709     The reasoning pattern for both directions are the same, as derived
       
   710     in the following:
       
   711     \end{minipage}
       
   712     *}
       
   713   { fix x y z
   623   { fix x y z
   714     assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>" 
   624     assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>" 
   715       and tag_xy: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y"
   625       and tag_xy: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y"
   716     have "y @ z \<in> L\<^isub>1\<star>"
   626     have "y @ z \<in> L\<^isub>1\<star>"
   717     proof(cases "x = []")
   627     proof(cases "x = []")
   721       case True
   631       case True
   722       with tag_xy have "y = []" 
   632       with tag_xy have "y = []" 
   723         by (auto simp:tag_str_STAR_def strict_prefix_def)
   633         by (auto simp:tag_str_STAR_def strict_prefix_def)
   724       thus ?thesis using xz_in_star True by simp
   634       thus ?thesis using xz_in_star True by simp
   725     next
   635     next
   726         -- {*
   636         -- {* The nontrival case:
   727         \begin{minipage}{0.9\textwidth}
       
   728         The case when @{text "x"} is not null, and
       
   729         @{text "x @ z"} is in @{text "L\<^isub>1\<star>"}, 
       
   730         \end{minipage}
       
   731         *}
   637         *}
   732       case False
   638       case False
   733       -- {* 
   639       -- {* 
   734         \begin{minipage}{0.9\textwidth}
   640         \begin{minipage}{0.8\textwidth}
   735         Since @{text "x @ z \<in> L\<^isub>1\<star>"}, @{text "x"} can always be splited
   641         Since @{text "x @ z \<in> L\<^isub>1\<star>"}, @{text "x"} can always be splitted
   736         by a prefix @{text "xa"} together with its suffix @{text "x - xa"}, such
   642         by a prefix @{text "xa"} together with its suffix @{text "x - xa"}, such
   737         that both @{text "xa"} and @{text "(x - xa) @ z"} are in @{text "L\<^isub>1\<star>"},
   643         that both @{text "xa"} and @{text "(x - xa) @ z"} are in @{text "L\<^isub>1\<star>"},
   738         and there could be many such splittings.Therefore, the following set @{text "?S"} 
   644         and there could be many such splittings.Therefore, the following set @{text "?S"} 
   739         is nonempty, and finite as well:
   645         is nonempty, and finite as well:
   740         \end{minipage}
   646         \end{minipage}
   743       have "finite ?S"
   649       have "finite ?S"
   744         by (rule_tac B = "{xa. xa < x}" in finite_subset, 
   650         by (rule_tac B = "{xa. xa < x}" in finite_subset, 
   745           auto simp:finite_strict_prefix_set)
   651           auto simp:finite_strict_prefix_set)
   746       moreover have "?S \<noteq> {}" using False xz_in_star
   652       moreover have "?S \<noteq> {}" using False xz_in_star
   747         by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
   653         by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
   748       -- {* Since @{text "?S"} is finite, we can always single out the longest
   654       -- {* \begin{minipage}{0.7\textwidth} 
   749           and name it @{text "xa_max"}:
   655             Since @{text "?S"} is finite, we can always single out the longest and name it @{text "xa_max"}: 
       
   656             \end{minipage}
   750           *}
   657           *}
   751       ultimately have "\<exists> xa_max \<in> ?S. \<forall> xa \<in> ?S. length xa \<le> length xa_max" 
   658       ultimately have "\<exists> xa_max \<in> ?S. \<forall> xa \<in> ?S. length xa \<le> length xa_max" 
   752         using finite_set_has_max by blast
   659         using finite_set_has_max by blast
   753       then obtain xa_max 
   660       then obtain xa_max 
   754         where h1: "xa_max < x" 
   661         where h1: "xa_max < x" 
   756         and h3: "(x - xa_max) @ z \<in> L\<^isub>1\<star>" 
   663         and h3: "(x - xa_max) @ z \<in> L\<^isub>1\<star>" 
   757         and h4:"\<forall> xa < x. xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>  
   664         and h4:"\<forall> xa < x. xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>  
   758                                      \<longrightarrow> length xa \<le> length xa_max"
   665                                      \<longrightarrow> length xa \<le> length xa_max"
   759         by blast
   666         by blast
   760       -- {*
   667       -- {*
   761           \begin{minipage}{0.9\textwidth}
   668           \begin{minipage}{0.8\textwidth}
   762           By the equality of tags, the counterpart of @{text "xa_max"} among 
   669           By the equality of tags, the counterpart of @{text "xa_max"} among 
   763           @{text "y"}-prefixes, named @{text "ya"}, can be found:
   670           @{text "y"}-prefixes, named @{text "ya"}, can be found:
   764           \end{minipage}
   671           \end{minipage}
   765           *}
   672           *}
   766       obtain ya 
   673       obtain ya 
   774         ultimately have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?right" by simp
   681         ultimately have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?right" by simp
   775         with prems show ?thesis apply 
   682         with prems show ?thesis apply 
   776           (simp add:Image_def str_eq_rel_def str_eq_def) by blast
   683           (simp add:Image_def str_eq_rel_def str_eq_def) by blast
   777       qed 
   684       qed 
   778       -- {*
   685       -- {*
   779           \begin{minipage}{0.9\textwidth}
   686           \begin{minipage}{0.8\textwidth}
   780           If the following proposition can be proved, then the @{text "?thesis"}:
   687           The @{text "?thesis"}, @{prop "y @ z \<in> L\<^isub>1\<star>"}, is a simple consequence
   781           @{text "y @ z \<in> L\<^isub>1\<star>"} is just a simple consequence.
   688           of the following proposition:
   782           \end{minipage}
   689           \end{minipage}
   783           *}
   690           *}
   784       have "(y - ya) @ z \<in> L\<^isub>1\<star>" 
   691       have "(y - ya) @ z \<in> L\<^isub>1\<star>" 
   785       proof-
   692       proof-
   786         -- {* The idea is to split the suffix @{text "z"} into @{text "za"} and @{text "zb"}, 
   693         -- {* The idea is to split the suffix @{text "z"} into @{text "za"} and @{text "zb"}, 
   787           such that: *}
   694           such that: *}
   788         obtain za zb where eq_zab: "z = za @ zb" 
   695         obtain za zb where eq_zab: "z = za @ zb" 
   789           and l_za: "(y - ya)@za \<in> L\<^isub>1" and ls_zb: "zb \<in> L\<^isub>1\<star>"
   696           and l_za: "(y - ya)@za \<in> L\<^isub>1" and ls_zb: "zb \<in> L\<^isub>1\<star>"
   790         proof -
   697         proof -
   791           -- {* 
   698           -- {* 
   792             \begin{minipage}{0.9\textwidth}
   699             \begin{minipage}{0.8\textwidth}
   793             Since @{text  "(x - xa_max) @ z"} is in @{text "L\<^isub>1\<star>"}, it can be split into
   700             Since @{thm "h1"}, @{text "x"} can be splitted into
   794             @{text "a"} and @{text "b"} such that:
   701             @{text "a"} and @{text "b"} such that:
   795             \end{minipage}
   702             \end{minipage}
   796             *}
   703             *}
   797           from h1 have "(x - xa_max) @ z \<noteq> []" 
   704           from h1 have "(x - xa_max) @ z \<noteq> []" 
   798             by (auto simp:strict_prefix_def elim:prefixE)
   705             by (auto simp:strict_prefix_def elim:prefixE)
   804           let ?za = "a - (x - xa_max)" and ?zb = "b"
   711           let ?za = "a - (x - xa_max)" and ?zb = "b"
   805           have pfx: "(x - xa_max) \<le> a" (is "?P1") 
   712           have pfx: "(x - xa_max) \<le> a" (is "?P1") 
   806             and eq_z: "z = ?za @ ?zb" (is "?P2")
   713             and eq_z: "z = ?za @ ?zb" (is "?P2")
   807           proof -
   714           proof -
   808             -- {* 
   715             -- {* 
   809               \begin{minipage}{0.9\textwidth}
   716               \begin{minipage}{0.8\textwidth}
   810               Since @{text "(x - xa_max) @ z = a @ b"}, the string @{text "(x - xa_max) @ z"}
   717               Since @{text "(x - xa_max) @ z = a @ b"}, string @{text "(x - xa_max) @ z"}
   811               could be splited in two ways:
   718               can be splitted in two ways:
   812               \end{minipage}
   719               \end{minipage}
   813               *}
   720               *}
   814             have "((x - xa_max) \<le> a \<and> (a - (x - xa_max)) @ b = z) \<or> 
   721             have "((x - xa_max) \<le> a \<and> (a - (x - xa_max)) @ b = z) \<or> 
   815               (a < (x - xa_max) \<and> ((x - xa_max) - a) @ z = b)" 
   722               (a < (x - xa_max) \<and> ((x - xa_max) - a) @ z = b)" 
   816               using app_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
   723               using app_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
   840             by (auto simp:str_eq_def str_eq_rel_def)
   747             by (auto simp:str_eq_def str_eq_rel_def)
   841            with eq_z and b_in prems
   748            with eq_z and b_in prems
   842           show ?thesis by blast
   749           show ?thesis by blast
   843         qed
   750         qed
   844         -- {* 
   751         -- {* 
   845             \begin{minipage}{0.9\textwidth}
   752            @{text "?thesis"} can easily be shown using properties of @{text "za"} and @{text "zb"}:
   846             From the properties of @{text "za"} and @{text "zb"} such obtained,
       
   847               @{text "?thesis"} can be shown easily. 
       
   848             \end{minipage}
       
   849             *}
   753             *}
   850         from step [OF l_za ls_zb]
   754         from step [OF l_za ls_zb]
   851         have "((y - ya) @ za) @ zb \<in> L\<^isub>1\<star>" .
   755         have "((y - ya) @ za) @ zb \<in> L\<^isub>1\<star>" .
   852         with eq_zab show ?thesis by simp
   756         with eq_zab show ?thesis by simp
   853       qed
   757       qed
   856     qed
   760     qed
   857   } 
   761   } 
   858   -- {* By instantiating the reasoning pattern just derived for both directions:*} 
   762   -- {* By instantiating the reasoning pattern just derived for both directions:*} 
   859   from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
   763   from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
   860   -- {* The thesis is proved as a trival consequence: *} 
   764   -- {* The thesis is proved as a trival consequence: *} 
   861     show  ?thesis by (unfold str_eq_def str_eq_rel_def, blast)
   765     show  ?thesis unfolding str_eq_def str_eq_rel_def by blast
   862 qed
   766 qed
   863 
   767 
   864 
   768 
   865 lemma -- {* The oringal version with a poor readability*}
   769 lemma -- {* The oringal version with less explicit details. *}
   866   fixes v w
   770   fixes v w
   867   assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
   771   assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
   868   shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
   772   shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
   869 proof-
   773 proof-
   870     -- {* 
   774     -- {* 
   871     \begin{minipage}{0.9\textwidth}
   775     \begin{minipage}{0.8\textwidth}
   872     According to the definition of @{text "\<approx>Lang"}, 
   776     According to the definition of @{text "\<approx>Lang"}, 
   873     proving @{text "v \<approx>(L\<^isub>1\<star>) w"} amounts to
   777     proving @{text "v \<approx>(L\<^isub>1\<star>) w"} amounts to
   874     showing: for any string @{text "u"},
   778     showing: for any string @{text "u"},
   875     if @{text "v @ u \<in> (L\<^isub>1\<star>)"} then @{text "w @ u \<in> (L\<^isub>1\<star>)"} and vice versa.
   779     if @{text "v @ u \<in> (L\<^isub>1\<star>)"} then @{text "w @ u \<in> (L\<^isub>1\<star>)"} and vice versa.
   876     The reasoning pattern for both directions are the same, as derived
   780     The reasoning pattern for both directions are the same, as derived
   889       with tag_xy have "y = []" 
   793       with tag_xy have "y = []" 
   890         by (auto simp:tag_str_STAR_def strict_prefix_def)
   794         by (auto simp:tag_str_STAR_def strict_prefix_def)
   891       thus ?thesis using xz_in_star True by simp
   795       thus ?thesis using xz_in_star True by simp
   892     next
   796     next
   893         -- {*
   797         -- {*
   894         \begin{minipage}{0.9\textwidth}
   798         \begin{minipage}{0.8\textwidth}
   895         The case when @{text "x"} is not null, and
   799         The case when @{text "x"} is not null, and
   896         @{text "x @ z"} is in @{text "L\<^isub>1\<star>"}, 
   800         @{text "x @ z"} is in @{text "L\<^isub>1\<star>"}, 
   897         \end{minipage}
   801         \end{minipage}
   898         *}
   802         *}
   899       case False
   803       case False
   965     qed
   869     qed
   966   } 
   870   } 
   967   -- {* By instantiating the reasoning pattern just derived for both directions:*} 
   871   -- {* By instantiating the reasoning pattern just derived for both directions:*} 
   968   from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
   872   from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
   969   -- {* The thesis is proved as a trival consequence: *} 
   873   -- {* The thesis is proved as a trival consequence: *} 
   970     show  ?thesis by (unfold str_eq_def str_eq_rel_def, blast)
   874     show  ?thesis unfolding str_eq_def str_eq_rel_def by blast
   971 qed
   875 qed
   972 
   876 
   973 lemma quot_star_finiteI [intro]:
   877 lemma quot_star_finiteI [intro]:
   974   fixes L1::"lang"
   878   fixes L1::"lang"
   975   assumes finite1: "finite (UNIV // \<approx>L1)"
   879   assumes finite1: "finite (UNIV // \<approx>L1)"