Myhill.thy
changeset 28 cef2893f353b
parent 27 90a57a533b0c
child 29 c64241fa4dff
equal deleted inserted replaced
27:90a57a533b0c 28:cef2893f353b
    12   Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
    12   Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
    13   for L :: "string set"
    13   for L :: "string set"
    14 where
    14 where
    15   start[intro]: "[] \<in> L\<star>"
    15   start[intro]: "[] \<in> L\<star>"
    16 | step[intro]:  "\<lbrakk>s1 \<in> L; s2 \<in> L\<star>\<rbrakk> \<Longrightarrow> s1@s2 \<in> L\<star>" 
    16 | step[intro]:  "\<lbrakk>s1 \<in> L; s2 \<in> L\<star>\<rbrakk> \<Longrightarrow> s1@s2 \<in> L\<star>" 
       
    17 
       
    18 lemma seq_union_distrib:
       
    19   "(A \<union> B) ;; C = (A ;; C) \<union> (B ;; C)"
       
    20 by (auto simp:Seq_def)
       
    21 
       
    22 lemma seq_assoc:
       
    23   "(A ;; B) ;; C = A ;; (B ;; C)"
       
    24 unfolding Seq_def
       
    25 apply(auto)
       
    26 apply(metis)
       
    27 by (metis append_assoc)
       
    28 
       
    29 lemma union_seq:
       
    30   "\<Union> {f x y ;; z| x y. P x y } = (\<Union> {f x y|x y. P x y });; z"
       
    31 apply (auto simp add:Seq_def)
       
    32 apply metis
       
    33 done
    17 
    34 
    18 theorem ardens_revised:
    35 theorem ardens_revised:
    19   assumes nemp: "[] \<notin> A"
    36   assumes nemp: "[] \<notin> A"
    20   shows "(X = X ;; A \<union> B) \<longleftrightarrow> (X = B ;; A\<star>)"
    37   shows "(X = X ;; A \<union> B) \<longleftrightarrow> (X = B ;; A\<star>)"
    21 proof
    38 proof
    59 definition 
    76 definition 
    60   folds :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b"
    77   folds :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b"
    61 where
    78 where
    62   "folds f z S \<equiv> SOME x. fold_graph f z S x"
    79   "folds f z S \<equiv> SOME x. fold_graph f z S x"
    63 
    80 
    64 lemma folds_simp_null [simp]:
    81 lemma folds_alt_simp [simp]:
    65   "finite rs \<Longrightarrow> x \<in> L (folds ALT NULL rs) \<longleftrightarrow> (\<exists>r \<in> rs. x \<in> L r)"
    82   "finite rs \<Longrightarrow> L (folds ALT NULL rs) = \<Union> (L ` rs)"
    66 apply (simp add: folds_def)
    83 apply (rule set_ext, simp add:folds_def)
    67 apply (rule someI2_ex)
    84 apply (rule someI2_ex, erule finite_imp_fold_graph)
    68 apply (erule finite_imp_fold_graph)
    85 by (erule fold_graph.induct, auto)
    69 apply (erule fold_graph.induct)
       
    70 apply (auto)
       
    71 done
       
    72 
    86 
    73 lemma [simp]:
    87 lemma [simp]:
    74   shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y"
    88   shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y"
    75 by simp
    89 by simp
    76 
    90 
    82 definition
    96 definition
    83   str_eq_rel ("\<approx>_")
    97   str_eq_rel ("\<approx>_")
    84 where
    98 where
    85   "\<approx>Lang \<equiv> {(x, y). x \<approx>Lang y}"
    99   "\<approx>Lang \<equiv> {(x, y). x \<approx>Lang y}"
    86 
   100 
    87 
   101 definition
       
   102   final :: "string set \<Rightarrow> string set \<Rightarrow> bool"
       
   103 where
       
   104   "final X Lang \<equiv> (X \<in> UNIV // \<approx>Lang) \<and> (\<forall>s \<in> X. s \<in> Lang)"
       
   105 
       
   106 lemma lang_is_union_of_finals: 
       
   107   "Lang = \<Union> {X. final X Lang}"
       
   108 proof 
       
   109   show "Lang \<subseteq> \<Union> {X. final X Lang}"
       
   110   proof
       
   111     fix x
       
   112     assume "x \<in> Lang"   
       
   113     thus "x \<in> \<Union> {X. final X Lang}"
       
   114       apply (simp, rule_tac x = "(\<approx>Lang) `` {x}" in exI)      
       
   115       apply (auto simp:final_def quotient_def Image_def str_eq_rel_def str_eq_def)
       
   116       by (drule_tac x = "[]" in spec, simp)
       
   117   qed
       
   118 next
       
   119   show "\<Union>{X. final X Lang} \<subseteq> Lang"
       
   120     by (auto simp:final_def)
       
   121 qed
    88 
   122 
    89 section {* finite \<Rightarrow> regular *}
   123 section {* finite \<Rightarrow> regular *}
    90 
   124 
       
   125 datatype rhs_item = 
       
   126    Lam "rexp"                           (* Lambda *)
       
   127  | Trn "string set" "rexp"              (* Transition *)
       
   128 
       
   129 fun the_Trn:: "rhs_item \<Rightarrow> (string set \<times> rexp)"
       
   130 where "the_Trn (Trn Y r) = (Y, r)"
       
   131 
       
   132 fun the_r :: "rhs_item \<Rightarrow> rexp"
       
   133 where "the_r (Lam r) = r"
       
   134 
       
   135 overloading L_rhs_e \<equiv> "L:: rhs_item \<Rightarrow> string set"
       
   136 begin
       
   137 fun L_rhs_e:: "rhs_item \<Rightarrow> string set"
       
   138 where
       
   139   "L_rhs_e (Lam r) = L r" |
       
   140   "L_rhs_e (Trn X r) = X ;; L r"
       
   141 end
       
   142 
       
   143 overloading L_rhs \<equiv> "L:: rhs_item set \<Rightarrow> string set"
       
   144 begin
       
   145 fun L_rhs:: "rhs_item set \<Rightarrow> string set"
       
   146 where
       
   147   "L_rhs rhs = \<Union> (L ` rhs)"
       
   148 end
       
   149 
    91 definition
   150 definition
    92   transitions :: "string set \<Rightarrow> string set \<Rightarrow> rexp set" ("_\<Turnstile>\<Rightarrow>_")
   151   "init_rhs CS X \<equiv>  if ([] \<in> X)
       
   152                     then {Lam EMPTY} \<union> {Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}
       
   153                     else {Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}"
       
   154 
       
   155 definition
       
   156   "eqs CS \<equiv> {(X, init_rhs CS X)|X.  X \<in> CS}"
       
   157 
       
   158 (************ arden's lemma variation ********************)
       
   159 
       
   160 definition
       
   161   "items_of rhs X \<equiv> {Trn X r | r. (Trn X r) \<in> rhs}"
       
   162 
       
   163 definition
       
   164   "lam_of rhs \<equiv> {Lam r | r. Lam r \<in> rhs}"
       
   165 
       
   166 definition 
       
   167   "rexp_of rhs X \<equiv> folds ALT NULL ((snd o the_Trn) ` items_of rhs X)"
       
   168 
       
   169 definition
       
   170   "rexp_of_lam rhs \<equiv> folds ALT NULL (the_r ` lam_of rhs)"
       
   171 
       
   172 fun attach_rexp :: "rexp \<Rightarrow> rhs_item \<Rightarrow> rhs_item"
    93 where
   173 where
    94   "Y \<Turnstile>\<Rightarrow> X \<equiv> {CHAR c | c. Y ;; {[c]} \<subseteq> X}"
   174   "attach_rexp r' (Lam r)   = Lam (SEQ r r')"
       
   175 | "attach_rexp r' (Trn X r) = Trn X (SEQ r r')"
    95 
   176 
    96 definition
   177 definition
    97   transitions_rexp ("_ \<turnstile>\<rightarrow> _")
   178   "append_rhs_rexp rhs r \<equiv> (attach_rexp r) ` rhs"
    98 where
   179 
    99   "Y \<turnstile>\<rightarrow> X \<equiv> folds ALT NULL (Y \<Turnstile>\<Rightarrow>X)"
       
   100 
       
   101 definition
       
   102   "init_rhs CS X \<equiv> if X = {[]} 
       
   103                    then {({[]}, EMPTY)} 
       
   104                    else if ([] \<in> X)
       
   105                         then insert ({[]}, EMPTY) {(Y, Y \<turnstile>\<rightarrow>X) | Y. Y \<in> CS}
       
   106                         else {(Y, Y \<turnstile>\<rightarrow>X) | Y. Y \<in> CS}"
       
   107 
       
   108 overloading L_rhs \<equiv> "L:: (string set \<times> rexp) set \<Rightarrow> string set"
       
   109 begin
       
   110 fun L_rhs:: "(string set \<times> rexp) set \<Rightarrow> string set"
       
   111 where
       
   112   "L_rhs rhs = \<Union> {(Y;; L r) | Y r . (Y, r) \<in> rhs}"
       
   113 end
       
   114 
       
   115 definition
       
   116   "eqs CS \<equiv> (\<Union>X \<in> CS. {(X, init_rhs CS X)})"
       
   117 
       
   118 lemma [simp]:
       
   119   shows "finite (Y \<Turnstile>\<Rightarrow> X)"
       
   120 unfolding transitions_def
       
   121 by auto
       
   122 
       
   123 lemma defined_by_str:
       
   124   assumes "s \<in> X" 
       
   125   and "X \<in> UNIV // (\<approx>Lang)"
       
   126   shows "X = (\<approx>Lang) `` {s}"
       
   127 using assms
       
   128 unfolding quotient_def Image_def
       
   129 unfolding str_eq_rel_def str_eq_def
       
   130 by auto
       
   131 
       
   132 
       
   133 
       
   134 (************ arden's lemma variation ********************)
       
   135 definition 
   180 definition 
   136   "rexp_of rhs X \<equiv> folds ALT NULL {r. (X, r) \<in> rhs}"
   181   "arden_variate X rhs \<equiv> append_rhs_rexp (rhs - items_of rhs X) (STAR (rexp_of rhs X))"
   137 
   182 
   138 definition 
       
   139   "arden_variate X rhs \<equiv> {(Y, SEQ r (STAR (rexp_of rhs X)))| Y r. (Y, r) \<in> rhs \<and> Y \<noteq> X}"
       
   140 
       
   141 (************* rhs/equations property **************)
       
   142 
       
   143 definition 
       
   144   "distinct_equas ES \<equiv> \<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'"
       
   145 
   183 
   146 (*********** substitution of ES *************)
   184 (*********** substitution of ES *************)
   147 
   185 
   148 text {* rhs_subst rhs X xrhs: substitude all occurence of X in rhs with xrhs *}
   186 text {* rhs_subst rhs X xrhs: substitude all occurence of X in rhs with xrhs *}
   149 definition 
   187 definition 
   150   "rhs_subst rhs X xrhs \<equiv> {(Y, r) | Y r. Y \<noteq> X \<and> (Y, r) \<in> rhs} \<union> 
   188   "rhs_subst rhs X xrhs \<equiv> (rhs - (items_of rhs X)) \<union> (append_rhs_rexp xrhs (rexp_of rhs X))"
   151                           {(X, SEQ r\<^isub>1 r\<^isub>2 ) | r\<^isub>1 r\<^isub>2. (X, r\<^isub>1) \<in> xrhs \<and> (X, r\<^isub>2) \<in> rhs}"
       
   152 
   189 
   153 definition
   190 definition
   154   "eqs_subst ES X xrhs \<equiv> {(Y, rhs_subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}"
   191   "eqs_subst ES X xrhs \<equiv> {(Y, rhs_subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}"
   155 
   192 
   156 text {*
   193 text {*
   157   Inv: Invairance of the equation-system, during the decrease of the equation-system, Inv holds.
   194   Inv: Invairance of the equation-system, during the decrease of the equation-system, Inv holds.
   158 *}
   195 *}
   159 
   196 
   160 definition 
   197 definition 
   161   "ardenable ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> ([] \<notin> L (rexp_of rhs X)) \<and> X = L rhs"
   198   "distinct_equas ES \<equiv> \<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'"
       
   199 
       
   200 definition 
       
   201   "valid_eqns ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> (X = L rhs)"
       
   202 
       
   203 definition 
       
   204   "rhs_nonempty rhs \<equiv> (\<forall> Y r. Trn Y r \<in> rhs \<longrightarrow> [] \<notin> L r)"
       
   205 
       
   206 definition 
       
   207   "ardenable ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> rhs_nonempty rhs"
   162 
   208 
   163 definition 
   209 definition 
   164   "non_empty ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> X \<noteq> {}"
   210   "non_empty ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> X \<noteq> {}"
   165 
   211 
       
   212 definition
       
   213   "finite_rhs ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> finite rhs"
       
   214 
   166 definition 
   215 definition 
   167   "self_contained ES \<equiv> \<forall> X xrhs. (X, xrhs) \<in> ES 
   216   "classes_of rhs \<equiv> {X. \<exists> r. Trn X r \<in> rhs}"
   168                              \<longrightarrow> (\<forall> Y r.(Y, r) \<in> xrhs \<and> Y \<noteq> {[]} \<longrightarrow> (\<exists> yrhs. (Y, yrhs) \<in> ES))"
   217 
       
   218 definition
       
   219   "lefts_of ES \<equiv> {Y | Y yrhs. (Y, yrhs) \<in> ES}"
   169 
   220 
   170 definition 
   221 definition 
   171   "Inv ES \<equiv> finite ES \<and> distinct_equas ES \<and> ardenable ES \<and> non_empty ES \<and> self_contained ES"
   222   "self_contained ES \<equiv> \<forall> (X, xrhs) \<in> ES. classes_of xrhs \<subseteq> lefts_of ES"
       
   223 
       
   224 definition 
       
   225   "Inv ES \<equiv> valid_eqns ES \<and> finite ES \<and> distinct_equas ES \<and> ardenable ES \<and> 
       
   226             non_empty ES \<and> finite_rhs ES \<and> self_contained ES"
   172 
   227 
   173 lemma wf_iter [rule_format]: 
   228 lemma wf_iter [rule_format]: 
   174   fixes f
   229   fixes f
   175   assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and>  (f(e'), f(e)) \<in> less_than)"
   230   assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and>  (f(e'), f(e)) \<in> less_than)"
   176   shows pe:     "P e \<longrightarrow> (\<exists> e'. P e' \<and>  Q e')"
   231   shows pe:     "P e \<longrightarrow> (\<exists> e'. P e' \<and>  Q e')"
   195       from pe' show "P e'" .
   250       from pe' show "P e'" .
   196     qed
   251     qed
   197   qed
   252   qed
   198 qed
   253 qed
   199 
   254 
       
   255 text {* ************* basic properties of definitions above ************************ *}
       
   256 
       
   257 lemma L_rhs_union_distrib:
       
   258   " L (A::rhs_item set) \<union> L B = L (A \<union> B)"
       
   259 by simp
       
   260 
       
   261 lemma finite_snd_Trn:
       
   262   assumes finite:"finite rhs"
       
   263   shows "finite {r\<^isub>2. Trn Y r\<^isub>2 \<in> rhs}" (is "finite ?B")
       
   264 proof-
       
   265   def rhs' \<equiv> "{e \<in> rhs. \<exists> r. e = Trn Y r}"
       
   266   have "?B = (snd o the_Trn) ` rhs'" using rhs'_def by (auto simp:image_def)
       
   267   moreover have "finite rhs'" using finite rhs'_def by auto
       
   268   ultimately show ?thesis by simp
       
   269 qed
       
   270 
       
   271 lemma rexp_of_empty:
       
   272   assumes finite:"finite rhs"
       
   273   and nonempty:"rhs_nonempty rhs"
       
   274   shows "[] \<notin> L (rexp_of rhs X)"
       
   275 using finite nonempty rhs_nonempty_def
       
   276 by (drule_tac finite_snd_Trn[where Y = X], auto simp:rexp_of_def items_of_def)
       
   277 
       
   278 lemma [intro!]:
       
   279   "P (Trn X r) \<Longrightarrow> (\<exists>a. (\<exists>r. a = Trn X r \<and> P a))" by auto
       
   280 
       
   281 lemma finite_items_of:
       
   282   "finite rhs \<Longrightarrow> finite (items_of rhs X)"
       
   283 by (auto simp:items_of_def intro:finite_subset)
       
   284 
       
   285 lemma lang_of_rexp_of:
       
   286   assumes finite:"finite rhs"
       
   287   shows "L (items_of rhs X) = X ;; (L (rexp_of rhs X))"
       
   288 proof -
       
   289   have "finite ((snd \<circ> the_Trn) ` items_of rhs X)" using finite_items_of[OF finite] by auto
       
   290   thus ?thesis
       
   291     apply (auto simp:rexp_of_def Seq_def items_of_def)
       
   292     apply (rule_tac x = s1 in exI, rule_tac x = s2 in exI, auto)
       
   293     by (rule_tac x= "Trn X r" in exI, auto simp:Seq_def)
       
   294 qed
       
   295 
       
   296 lemma rexp_of_lam_eq_lam_set:
       
   297   assumes finite: "finite rhs"
       
   298   shows "L (rexp_of_lam rhs) = L (lam_of rhs)"
       
   299 proof -
       
   300   have "finite (the_r ` {Lam r |r. Lam r \<in> rhs})" using finite
       
   301     by (rule_tac finite_imageI, auto intro:finite_subset)
       
   302   thus ?thesis by (auto simp:rexp_of_lam_def lam_of_def)
       
   303 qed
       
   304 
       
   305 lemma [simp]:
       
   306   " L (attach_rexp r xb) = L xb ;; L r"
       
   307 apply (cases xb, auto simp:Seq_def)
       
   308 by (rule_tac x = "s1 @ s1a" in exI, rule_tac x = s2a in exI,auto simp:Seq_def)
       
   309 
       
   310 lemma lang_of_append_rhs:
       
   311   "L (append_rhs_rexp rhs r) = L rhs ;; L r"
       
   312 apply (auto simp:append_rhs_rexp_def image_def)
       
   313 apply (auto simp:Seq_def)
       
   314 apply (rule_tac x = "L xb ;; L r" in exI, auto simp add:Seq_def)
       
   315 by (rule_tac x = "attach_rexp r xb" in exI, auto simp:Seq_def)
       
   316 
       
   317 lemma classes_of_union_distrib:
       
   318   "classes_of A \<union> classes_of B = classes_of (A \<union> B)"
       
   319 by (auto simp add:classes_of_def)
       
   320 
       
   321 lemma lefts_of_union_distrib:
       
   322   "lefts_of A \<union> lefts_of B = lefts_of (A \<union> B)"
       
   323 by (auto simp:lefts_of_def)
       
   324 
       
   325 
   200 text {* ******BEGIN: proving the initial equation-system satisfies Inv ****** *}
   326 text {* ******BEGIN: proving the initial equation-system satisfies Inv ****** *}
       
   327 
       
   328 lemma defined_by_str:
       
   329   "\<lbrakk>s \<in> X; X \<in> UNIV // (\<approx>Lang)\<rbrakk> \<Longrightarrow> X = (\<approx>Lang) `` {s}"
       
   330 by (auto simp:quotient_def Image_def str_eq_rel_def str_eq_def)
       
   331 
       
   332 lemma every_eqclass_has_transition:
       
   333   assumes has_str: "s @ [c] \<in> X"
       
   334   and     in_CS:   "X \<in> UNIV // (\<approx>Lang)"
       
   335   obtains Y where "Y \<in> UNIV // (\<approx>Lang)" and "Y ;; {[c]} \<subseteq> X" and "s \<in> Y"
       
   336 proof -
       
   337   def Y \<equiv> "(\<approx>Lang) `` {s}"
       
   338   have "Y \<in> UNIV // (\<approx>Lang)" 
       
   339     unfolding Y_def quotient_def by auto
       
   340   moreover
       
   341   have "X = (\<approx>Lang) `` {s @ [c]}" 
       
   342     using has_str in_CS defined_by_str by blast
       
   343   then have "Y ;; {[c]} \<subseteq> X" 
       
   344     unfolding Y_def Image_def Seq_def
       
   345     unfolding str_eq_rel_def
       
   346     by (auto) (simp add: str_eq_def)
       
   347   moreover
       
   348   have "s \<in> Y" unfolding Y_def 
       
   349     unfolding Image_def str_eq_rel_def str_eq_def by simp
       
   350   ultimately show thesis by (blast intro: that)
       
   351 qed
       
   352 
       
   353 lemma l_eq_r_in_eqs:
       
   354   assumes X_in_eqs: "(X, xrhs) \<in> (eqs (UNIV // (\<approx>Lang)))"
       
   355   shows "X = L xrhs"
       
   356 proof 
       
   357   show "X \<subseteq> L xrhs"
       
   358   proof
       
   359     fix x
       
   360     assume "(1)": "x \<in> X"
       
   361     show "x \<in> L xrhs"          
       
   362     proof (cases "x = []")
       
   363       assume empty: "x = []"
       
   364       thus ?thesis using X_in_eqs "(1)"
       
   365         by (auto simp:eqs_def init_rhs_def)
       
   366     next
       
   367       assume not_empty: "x \<noteq> []"
       
   368       then obtain clist c where decom: "x = clist @ [c]"
       
   369         by (case_tac x rule:rev_cases, auto)
       
   370       have "X \<in> UNIV // (\<approx>Lang)" using X_in_eqs by (auto simp:eqs_def)
       
   371       then obtain Y 
       
   372         where "Y \<in> UNIV // (\<approx>Lang)" 
       
   373         and "Y ;; {[c]} \<subseteq> X"
       
   374         and "clist \<in> Y"
       
   375         using decom "(1)" every_eqclass_has_transition by blast
       
   376       hence "x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // (\<approx>Lang) \<and> Y ;; {[c]} \<subseteq> X}"
       
   377         using "(1)" decom
       
   378         by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def)
       
   379       thus ?thesis using X_in_eqs "(1)"
       
   380         by (simp add:eqs_def init_rhs_def)
       
   381     qed
       
   382   qed
       
   383 next
       
   384   show "L xrhs \<subseteq> X" using X_in_eqs
       
   385     by (auto simp:eqs_def init_rhs_def) 
       
   386 qed
       
   387 
       
   388 lemma finite_init_rhs: 
       
   389   assumes finite: "finite CS"
       
   390   shows "finite (init_rhs CS X)"
       
   391 proof-
       
   392   have "finite {Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" (is "finite ?A")
       
   393   proof -
       
   394     def S \<equiv> "{(Y, c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" 
       
   395     def h \<equiv> "\<lambda> (Y, c). Trn Y (CHAR c)"
       
   396     have "finite (CS \<times> (UNIV::char set))" using finite by auto
       
   397     hence "finite S" using S_def 
       
   398       by (rule_tac B = "CS \<times> UNIV" in finite_subset, auto)
       
   399     moreover have "?A = h ` S" by (auto simp: S_def h_def image_def)
       
   400     ultimately show ?thesis 
       
   401       by auto
       
   402   qed
       
   403   thus ?thesis by (simp add:init_rhs_def)
       
   404 qed
   201 
   405 
   202 lemma init_ES_satisfy_Inv:
   406 lemma init_ES_satisfy_Inv:
   203   assumes finite_CS: "finite (UNIV // (\<approx>Lang))"
   407   assumes finite_CS: "finite (UNIV // (\<approx>Lang))"
   204   and X_in_eq_cls: "X \<in> (UNIV // (\<approx>Lang))"
       
   205   shows "Inv (eqs (UNIV // (\<approx>Lang)))"
   408   shows "Inv (eqs (UNIV // (\<approx>Lang)))"
   206 proof -
   409 proof -
   207   have "finite (eqs (UNIV // (\<approx>Lang)))" using finite_CS
   410   have "finite (eqs (UNIV // (\<approx>Lang)))" using finite_CS
   208     by (auto simp add:eqs_def)
   411     by (simp add:eqs_def)
   209   moreover have "distinct_equas (eqs (UNIV // (\<approx>Lang)))"     
   412   moreover have "distinct_equas (eqs (UNIV // (\<approx>Lang)))"     
   210     by (auto simp:distinct_equas_def eqs_def)
   413     by (simp add:distinct_equas_def eqs_def)
   211   moreover have "ardenable (eqs (UNIV // (\<approx>Lang)))"
   414   moreover have "ardenable (eqs (UNIV // (\<approx>Lang)))"
   212   proof-
   415     by (auto simp add:ardenable_def eqs_def init_rhs_def rhs_nonempty_def del:L_rhs.simps)
   213     have "\<And> X rhs. (X, rhs) \<in> (eqs (UNIV // (\<approx>Lang))) \<Longrightarrow> ([] \<notin> L (rexp_of rhs X))"
   416   moreover have "valid_eqns (eqs (UNIV // (\<approx>Lang)))"
   214     proof 
   417     using l_eq_r_in_eqs by (simp add:valid_eqns_def)
   215       apply (auto simp:eqs_def rexp_of_def)
       
   216       sorry
       
   217     moreover have "\<forall> X rhs. (X, rhs) \<in> (eqs (UNIV // (\<approx>Lang))) \<longrightarrow> X = L rhs"
       
   218       sorry
       
   219     ultimately show ?thesis by (simp add:ardenable_def)
       
   220   qed
       
   221   moreover have "non_empty (eqs (UNIV // (\<approx>Lang)))"
   418   moreover have "non_empty (eqs (UNIV // (\<approx>Lang)))"
   222     by (auto simp:non_empty_def eqs_def quotient_def Image_def str_eq_rel_def str_eq_def)
   419     by (auto simp:non_empty_def eqs_def quotient_def Image_def str_eq_rel_def str_eq_def)
       
   420   moreover have "finite_rhs (eqs (UNIV // (\<approx>Lang)))"
       
   421     using finite_init_rhs[OF finite_CS] 
       
   422     by (auto simp:finite_rhs_def eqs_def)
   223   moreover have "self_contained (eqs (UNIV // (\<approx>Lang)))"
   423   moreover have "self_contained (eqs (UNIV // (\<approx>Lang)))"
   224     by (auto simp:self_contained_def eqs_def init_rhs_def)
   424     by (auto simp:self_contained_def eqs_def init_rhs_def classes_of_def lefts_of_def)
   225   ultimately show ?thesis by (simp add:Inv_def)
   425   ultimately show ?thesis by (simp add:Inv_def)
   226 qed
   426 qed
   227 
   427 
   228 
       
   229 text {* ****** BEGIN: proving every equation-system's iteration step satisfies Inv ***** *}
   428 text {* ****** BEGIN: proving every equation-system's iteration step satisfies Inv ***** *}
       
   429 
       
   430 lemma arden_variate_keeps_eq:
       
   431   assumes l_eq_r: "X = L rhs"
       
   432   and not_empty: "[] \<notin> L (rexp_of rhs X)"
       
   433   and finite: "finite rhs"
       
   434   shows "X = L (arden_variate X rhs)"
       
   435 proof -
       
   436   def A \<equiv> "L (rexp_of rhs X)"
       
   437   def b \<equiv> "rhs - items_of rhs X"
       
   438   def B \<equiv> "L b" 
       
   439   have "X = B ;; A\<star>"
       
   440   proof-
       
   441     have "rhs = items_of rhs X \<union> b" by (auto simp:b_def items_of_def)
       
   442     hence "L rhs = L(items_of rhs X \<union> b)" by simp
       
   443     hence "L rhs = L(items_of rhs X) \<union> B" by (simp only:L_rhs_union_distrib B_def)
       
   444     with lang_of_rexp_of
       
   445     have "L rhs = X ;; A \<union> B " using finite by (simp only:B_def b_def A_def)
       
   446     thus ?thesis
       
   447       using l_eq_r not_empty
       
   448       apply (drule_tac B = B and X = X in ardens_revised)
       
   449       by (auto simp:A_def simp del:L_rhs.simps)
       
   450   qed
       
   451   moreover have "L (arden_variate X rhs) = (B ;; A\<star>)" (is "?L = ?R")
       
   452     by (simp only:arden_variate_def L_rhs_union_distrib lang_of_append_rhs 
       
   453                   B_def A_def b_def L_rexp.simps seq_union_distrib)
       
   454    ultimately show ?thesis by simp
       
   455 qed 
       
   456 
       
   457 lemma append_keeps_finite:
       
   458   "finite rhs \<Longrightarrow> finite (append_rhs_rexp rhs r)"
       
   459 by (auto simp:append_rhs_rexp_def)
       
   460 
       
   461 lemma arden_variate_keeps_finite:
       
   462   "finite rhs \<Longrightarrow> finite (arden_variate X rhs)"
       
   463 by (auto simp:arden_variate_def append_keeps_finite)
       
   464 
       
   465 lemma append_keeps_nonempty:
       
   466   "rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (append_rhs_rexp rhs r)"
       
   467 apply (auto simp:rhs_nonempty_def append_rhs_rexp_def)
       
   468 by (case_tac x, auto simp:Seq_def)
       
   469 
       
   470 lemma nonempty_set_sub:
       
   471   "rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (rhs - A)"
       
   472 by (auto simp:rhs_nonempty_def)
       
   473 
       
   474 lemma nonempty_set_union:
       
   475   "\<lbrakk>rhs_nonempty rhs; rhs_nonempty rhs'\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs \<union> rhs')"
       
   476 by (auto simp:rhs_nonempty_def)
       
   477 
       
   478 lemma arden_variate_keeps_nonempty:
       
   479   "rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (arden_variate X rhs)"
       
   480 by (simp only:arden_variate_def append_keeps_nonempty nonempty_set_sub)
       
   481 
       
   482 
       
   483 lemma rhs_subst_keeps_nonempty:
       
   484   "\<lbrakk>rhs_nonempty rhs; rhs_nonempty xrhs\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs_subst rhs X xrhs)"
       
   485 by (simp only:rhs_subst_def append_keeps_nonempty  nonempty_set_union nonempty_set_sub)
       
   486 
       
   487 lemma rhs_subst_keeps_eq:
       
   488   assumes substor: "X = L xrhs"
       
   489   and finite: "finite rhs"
       
   490   shows "L (rhs_subst rhs X xrhs) = L rhs" (is "?Left = ?Right")
       
   491 proof-
       
   492   def A \<equiv> "L (rhs - items_of rhs X)"
       
   493   have "?Left = A \<union> L (append_rhs_rexp xrhs (rexp_of rhs X))"
       
   494     by (simp only:rhs_subst_def L_rhs_union_distrib A_def)
       
   495   moreover have "?Right = A \<union> L (items_of rhs X)"
       
   496   proof-
       
   497     have "rhs = (rhs - items_of rhs X) \<union> (items_of rhs X)" by (auto simp:items_of_def)
       
   498     thus ?thesis by (simp only:L_rhs_union_distrib A_def)
       
   499   qed
       
   500   moreover have "L (append_rhs_rexp xrhs (rexp_of rhs X)) = L (items_of rhs X)" 
       
   501     using finite substor  by (simp only:lang_of_append_rhs lang_of_rexp_of)
       
   502   ultimately show ?thesis by simp
       
   503 qed
       
   504 
       
   505 lemma rhs_subst_keeps_finite_rhs:
       
   506   "\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (rhs_subst rhs Y yrhs)"
       
   507 by (auto simp:rhs_subst_def append_keeps_finite)
       
   508 
       
   509 lemma eqs_subst_keeps_finite:
       
   510   assumes finite:"finite (ES:: (string set \<times> rhs_item set) set)"
       
   511   shows "finite (eqs_subst ES Y yrhs)"
       
   512 proof -
       
   513   have "finite {(Ya, rhs_subst yrhsa Y yrhs) |Ya yrhsa. (Ya, yrhsa) \<in> ES}" (is "finite ?A")
       
   514   proof-
       
   515     def eqns' \<equiv> "{((Ya::string set), yrhsa)| Ya yrhsa. (Ya, yrhsa) \<in> ES}"
       
   516     def h \<equiv> "\<lambda> ((Ya::string set), yrhsa). (Ya, rhs_subst yrhsa Y yrhs)"
       
   517     have "finite (h ` eqns')" using finite h_def eqns'_def by auto
       
   518     moreover have "?A = h ` eqns'" by (auto simp:h_def eqns'_def)
       
   519     ultimately show ?thesis by auto      
       
   520   qed
       
   521   thus ?thesis by (simp add:eqs_subst_def)
       
   522 qed
       
   523 
       
   524 lemma eqs_subst_keeps_finite_rhs:
       
   525   "\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (eqs_subst ES Y yrhs)"
       
   526 by (auto intro:rhs_subst_keeps_finite_rhs simp add:eqs_subst_def finite_rhs_def)
       
   527 
       
   528 lemma append_rhs_keeps_cls:
       
   529   "classes_of (append_rhs_rexp rhs r) = classes_of rhs"
       
   530 apply (auto simp:classes_of_def append_rhs_rexp_def)
       
   531 apply (case_tac xa, auto simp:image_def)
       
   532 by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+)
       
   533 
       
   534 lemma arden_variate_removes_cl:
       
   535   "classes_of (arden_variate Y yrhs) = classes_of yrhs - {Y}"
       
   536 apply (simp add:arden_variate_def append_rhs_keeps_cls items_of_def)
       
   537 by (auto simp:classes_of_def)
       
   538 
       
   539 lemma lefts_of_keeps_cls:
       
   540   "lefts_of (eqs_subst ES Y yrhs) = lefts_of ES"
       
   541 by (auto simp:lefts_of_def eqs_subst_def)
       
   542 
       
   543 lemma rhs_subst_updates_cls:
       
   544   "X \<notin> classes_of xrhs \<Longrightarrow> classes_of (rhs_subst rhs X xrhs) = classes_of rhs \<union> classes_of xrhs - {X}"
       
   545 apply (simp only:rhs_subst_def append_rhs_keeps_cls classes_of_union_distrib[THEN sym])
       
   546 by (auto simp:classes_of_def items_of_def)
       
   547 
       
   548 lemma eqs_subst_keeps_self_contained:
       
   549   fixes Y
       
   550   assumes sc: "self_contained (ES \<union> {(Y, yrhs)})" (is "self_contained ?A")
       
   551   shows "self_contained (eqs_subst ES Y (arden_variate Y yrhs))" (is "self_contained ?B")
       
   552 proof-
       
   553   { fix X xrhs'
       
   554     assume "(X, xrhs') \<in> ?B"
       
   555     then obtain xrhs 
       
   556       where xrhs_xrhs': "xrhs' = rhs_subst xrhs Y (arden_variate Y yrhs)"
       
   557       and X_in: "(X, xrhs) \<in> ES" by (simp add:eqs_subst_def, blast)    
       
   558     have "classes_of xrhs' \<subseteq> lefts_of ?B"
       
   559     proof-
       
   560       have "lefts_of ?B = lefts_of ES" by (auto simp add:lefts_of_def eqs_subst_def)
       
   561       moreover have "classes_of xrhs' \<subseteq> lefts_of ES"
       
   562       proof-
       
   563         have "classes_of xrhs' \<subseteq> classes_of xrhs \<union> classes_of (arden_variate Y yrhs) - {Y}"
       
   564         proof-
       
   565           have "Y \<notin> classes_of (arden_variate Y yrhs)" using arden_variate_removes_cl by simp
       
   566           thus ?thesis using xrhs_xrhs' by (auto simp:rhs_subst_updates_cls)
       
   567         qed
       
   568         moreover have "classes_of xrhs \<subseteq> lefts_of ES \<union> {Y}" using X_in sc
       
   569           apply (simp only:self_contained_def lefts_of_union_distrib[THEN sym])
       
   570           by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lefts_of_def)
       
   571         moreover have "classes_of (arden_variate Y yrhs) \<subseteq> lefts_of ES \<union> {Y}" using sc
       
   572           by (auto simp add:arden_variate_removes_cl self_contained_def lefts_of_def)
       
   573         ultimately show ?thesis by auto
       
   574       qed
       
   575       ultimately show ?thesis by simp
       
   576     qed
       
   577   } thus ?thesis by (auto simp only:eqs_subst_def self_contained_def)
       
   578 qed
       
   579 
       
   580 lemma eqs_subst_satisfy_Inv:
       
   581   assumes Inv_ES: "Inv (ES \<union> {(Y, yrhs)})"
       
   582   shows "Inv (eqs_subst ES Y (arden_variate Y yrhs))"
       
   583 proof -  
       
   584   have finite_yrhs: "finite yrhs" using Inv_ES by (auto simp:Inv_def finite_rhs_def)
       
   585   have nonempty_yrhs: "rhs_nonempty yrhs" using Inv_ES by (auto simp:Inv_def ardenable_def)
       
   586   have Y_eq_yrhs: "Y = L yrhs" using Inv_ES by (simp only:Inv_def valid_eqns_def, blast)
       
   587 
       
   588   have "distinct_equas (eqs_subst ES Y (arden_variate Y yrhs))" using Inv_ES
       
   589     by (auto simp:distinct_equas_def eqs_subst_def Inv_def)
       
   590   moreover have "finite (eqs_subst ES Y (arden_variate Y yrhs))" using Inv_ES 
       
   591     by (simp add:Inv_def eqs_subst_keeps_finite)
       
   592   moreover have "finite_rhs (eqs_subst ES Y (arden_variate Y yrhs))"
       
   593   proof-
       
   594     have "finite_rhs ES" using Inv_ES by (simp add:Inv_def finite_rhs_def)
       
   595     moreover have "finite (arden_variate Y yrhs)"
       
   596     proof -
       
   597       have "finite yrhs" using Inv_ES by (auto simp:Inv_def finite_rhs_def)
       
   598       thus ?thesis using arden_variate_keeps_finite by simp
       
   599     qed
       
   600     ultimately show ?thesis by (simp add:eqs_subst_keeps_finite_rhs)
       
   601   qed
       
   602   moreover have "ardenable (eqs_subst ES Y (arden_variate Y yrhs))"
       
   603   proof - 
       
   604     { fix X rhs
       
   605       assume "(X, rhs) \<in> ES"
       
   606       hence "rhs_nonempty rhs"  using prems Inv_ES  by (simp add:Inv_def ardenable_def)
       
   607       with nonempty_yrhs have "rhs_nonempty (rhs_subst rhs Y (arden_variate Y yrhs))"
       
   608         by (simp add:nonempty_yrhs rhs_subst_keeps_nonempty arden_variate_keeps_nonempty)
       
   609     } thus ?thesis by (auto simp add:ardenable_def eqs_subst_def)
       
   610   qed
       
   611   moreover have "valid_eqns (eqs_subst ES Y (arden_variate Y yrhs))"
       
   612   proof-
       
   613     have "Y = L (arden_variate Y yrhs)" using Y_eq_yrhs Inv_ES finite_yrhs nonempty_yrhs      
       
   614         by (rule_tac arden_variate_keeps_eq, (simp add:rexp_of_empty)+)
       
   615     thus ?thesis using Inv_ES 
       
   616       by (clarsimp simp add:valid_eqns_def eqs_subst_def rhs_subst_keeps_eq Inv_def finite_rhs_def
       
   617                    simp del:L_rhs.simps)
       
   618   qed
       
   619   moreover have non_empty_subst: "non_empty (eqs_subst ES Y (arden_variate Y yrhs))"
       
   620     using Inv_ES by (auto simp:Inv_def non_empty_def eqs_subst_def)
       
   621   moreover have self_subst: "self_contained (eqs_subst ES Y (arden_variate Y yrhs))"
       
   622     using Inv_ES eqs_subst_keeps_self_contained by (simp add:Inv_def)
       
   623   ultimately show ?thesis using Inv_ES by (simp add:Inv_def)
       
   624 qed
       
   625 
       
   626 lemma eqs_subst_card_le: 
       
   627   assumes finite: "finite (ES::(string set \<times> rhs_item set) set)"
       
   628   shows "card (eqs_subst ES Y yrhs) <= card ES"
       
   629 proof-
       
   630   def f \<equiv> "\<lambda> x. ((fst x)::string set, rhs_subst (snd x) Y yrhs)"
       
   631   have "eqs_subst ES Y yrhs = f ` ES" 
       
   632     apply (auto simp:eqs_subst_def f_def image_def)
       
   633     by (rule_tac x = "(Ya, yrhsa)" in bexI, simp+)
       
   634   thus ?thesis using finite by (auto intro:card_image_le)
       
   635 qed
       
   636 
       
   637 lemma eqs_subst_cls_remains: 
       
   638   "(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (eqs_subst ES Y yrhs)"
       
   639 by (auto simp:eqs_subst_def)
       
   640 
       
   641 lemma card_noteq_1_has_more:
       
   642   assumes card:"card S \<noteq> 1"
       
   643   and e_in: "e \<in> S"
       
   644   and finite: "finite S"
       
   645   obtains e' where "e' \<in> S \<and> e \<noteq> e'" 
       
   646 proof-
       
   647   have "card (S - {e}) > 0"
       
   648   proof -
       
   649     have "card S > 1" using card e_in finite  by (case_tac "card S", auto) 
       
   650     thus ?thesis using finite e_in by auto
       
   651   qed
       
   652   hence "S - {e} \<noteq> {}" using finite by (rule_tac notI, simp)
       
   653   thus "(\<And>e'. e' \<in> S \<and> e \<noteq> e' \<Longrightarrow> thesis) \<Longrightarrow> thesis" by auto
       
   654 qed
   230 
   655 
   231 lemma iteration_step: 
   656 lemma iteration_step: 
   232   assumes Inv_ES: "Inv ES"
   657   assumes Inv_ES: "Inv ES"
       
   658   and    X_in_ES: "(X, xrhs) \<in> ES"
       
   659   and    not_T: "card ES \<noteq> 1"
       
   660   shows "\<exists> ES'. (Inv ES' \<and> (\<exists> xrhs'.(X, xrhs') \<in> ES')) \<and> (card ES', card ES) \<in> less_than" (is "\<exists> ES'. ?P ES'")
       
   661 proof -
       
   662   have finite_ES: "finite ES" using Inv_ES by (simp add:Inv_def)
       
   663   then obtain Y yrhs where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" 
       
   664     using not_T X_in_ES by (drule_tac card_noteq_1_has_more, auto)
       
   665   def ES' == "ES - {(Y, yrhs)}"
       
   666   let ?ES'' = "eqs_subst ES' Y (arden_variate Y yrhs)"
       
   667   have "?P ?ES''"
       
   668   proof -
       
   669     have "Inv ?ES''" using Y_in_ES Inv_ES
       
   670       by (rule_tac eqs_subst_satisfy_Inv, simp add:ES'_def insert_absorb)
       
   671     moreover have "\<exists>xrhs'. (X, xrhs') \<in> ?ES''"  using not_eq X_in_ES
       
   672       by (rule_tac ES = ES' in eqs_subst_cls_remains, auto simp add:ES'_def)
       
   673     moreover have "(card ?ES'', card ES) \<in> less_than" 
       
   674     proof -
       
   675       have "finite ES'" using finite_ES ES'_def by auto
       
   676       moreover have "card ES' < card ES" using finite_ES Y_in_ES
       
   677         by (auto simp:ES'_def card_gt_0_iff intro:diff_Suc_less)
       
   678       ultimately show ?thesis 
       
   679         by (auto dest:eqs_subst_card_le elim:le_less_trans)
       
   680     qed
       
   681     ultimately show ?thesis by simp
       
   682   qed
       
   683   thus ?thesis by blast
       
   684 qed
       
   685 
       
   686 text {* ***** END: proving every equation-system's iteration step satisfies Inv ************** *}
       
   687 
       
   688 lemma iteration_conc: 
       
   689   assumes history: "Inv ES"
   233   and    X_in_ES: "\<exists> xrhs. (X, xrhs) \<in> ES"
   690   and    X_in_ES: "\<exists> xrhs. (X, xrhs) \<in> ES"
   234   and    not_T: "card ES > 1"
   691   shows "\<exists> ES'. (Inv ES' \<and> (\<exists> xrhs'. (X, xrhs') \<in> ES')) \<and> card ES' = 1" (is "\<exists> ES'. ?P ES'")
   235   shows "(\<exists> ES' xrhs'. Inv ES' \<and> (card ES', card ES) \<in> less_than \<and> (X, xrhs') \<in> ES')" 
   692 proof (cases "card ES = 1")
   236 proof -
       
   237 
       
   238  
       
   239 
       
   240 
       
   241 
       
   242  
       
   243 
       
   244 
       
   245 
       
   246   
       
   247 
       
   248 
       
   249 
       
   250 
       
   251 
       
   252 
       
   253 
       
   254 
       
   255 
       
   256 
       
   257 
       
   258 
       
   259 
       
   260 
       
   261 
       
   262 
       
   263 
       
   264 
       
   265 
       
   266 
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 lemma distinct_rhs_equations:
       
   275   "(X, xrhs) \<in> equations (UNIV Quo Lang) \<Longrightarrow> distinct_rhs xrhs"
       
   276 by (auto simp: equations_def equation_rhs_def distinct_rhs_def empty_rhs_def dest:no_two_cls_inters)
       
   277 
       
   278 lemma every_nonempty_eqclass_has_strings:
       
   279   "\<lbrakk>X \<in> (UNIV Quo Lang); X \<noteq> {[]}\<rbrakk> \<Longrightarrow> \<exists> clist. clist \<in> X \<and> clist \<noteq> []"
       
   280 by (auto simp:quot_def equiv_class_def equiv_str_def)
       
   281 
       
   282 lemma every_eqclass_is_derived_from_empty:
       
   283   assumes not_empty: "X \<noteq> {[]}"
       
   284   shows "X \<in> (UNIV Quo Lang) \<Longrightarrow> \<exists> clist. {[]};{clist} \<subseteq> X \<and> clist \<noteq> []"
       
   285 using not_empty
       
   286 apply (drule_tac every_nonempty_eqclass_has_strings, simp)
       
   287 by (auto intro:exI[where x = clist] simp:lang_seq_def)
       
   288 
       
   289 lemma equiv_str_in_CS:
       
   290   "\<lbrakk>clist\<rbrakk>Lang \<in> (UNIV Quo Lang)"
       
   291 by (auto simp:quot_def)
       
   292 
       
   293 lemma has_str_imp_defined_by_str:
       
   294   "\<lbrakk>str \<in> X; X \<in> UNIV Quo Lang\<rbrakk> \<Longrightarrow> X = \<lbrakk>str\<rbrakk>Lang"
       
   295 by (auto simp:quot_def equiv_class_def equiv_str_def)
       
   296 
       
   297 lemma every_eqclass_has_ascendent:
       
   298   assumes has_str: "clist @ [c] \<in> X"
       
   299   and     in_CS:   "X \<in> UNIV Quo Lang"
       
   300   shows "\<exists> Y. Y \<in> UNIV Quo Lang \<and> Y-c\<rightarrow>X \<and> clist \<in> Y" (is "\<exists> Y. ?P Y")
       
   301 proof -
       
   302   have "?P (\<lbrakk>clist\<rbrakk>Lang)" 
       
   303   proof -
       
   304     have "\<lbrakk>clist\<rbrakk>Lang \<in> UNIV Quo Lang"       
       
   305       by (simp add:quot_def, rule_tac x = clist in exI, simp)
       
   306     moreover have "\<lbrakk>clist\<rbrakk>Lang-c\<rightarrow>X" 
       
   307     proof -
       
   308       have "X = \<lbrakk>(clist @ [c])\<rbrakk>Lang" using has_str in_CS
       
   309         by (auto intro!:has_str_imp_defined_by_str)
       
   310       moreover have "\<forall> sl. sl \<in> \<lbrakk>clist\<rbrakk>Lang \<longrightarrow> sl @ [c] \<in> \<lbrakk>(clist @ [c])\<rbrakk>Lang"
       
   311         by (auto simp:equiv_class_def equiv_str_def)
       
   312       ultimately show ?thesis unfolding CT_def lang_seq_def
       
   313         by auto
       
   314     qed
       
   315     moreover have "clist \<in> \<lbrakk>clist\<rbrakk>Lang" 
       
   316       by (auto simp:equiv_str_def equiv_class_def)
       
   317     ultimately show "?P (\<lbrakk>clist\<rbrakk>Lang)" by simp
       
   318   qed
       
   319   thus ?thesis by blast
       
   320 qed
       
   321 
       
   322 lemma finite_charset_rS:
       
   323   "finite {CHAR c |c. Y-c\<rightarrow>X}"
       
   324 by (rule_tac A = UNIV and f = CHAR in finite_surj, auto)
       
   325 
       
   326 lemma l_eq_r_in_equations:
       
   327   assumes X_in_equas: "(X, xrhs) \<in> equations (UNIV Quo Lang)"
       
   328   shows "X = L xrhs"    
       
   329 proof (cases "X = {[]}")
       
   330   case True
   693   case True
   331   thus ?thesis using X_in_equas 
   694   thus ?thesis using history X_in_ES
   332     by (simp add:equations_def equation_rhs_def lang_seq_def)
   695     by blast
   333 next
       
   334   case False 
       
   335   show ?thesis
       
   336   proof 
       
   337     show "X \<subseteq> L xrhs"
       
   338     proof
       
   339       fix x
       
   340       assume "(1)": "x \<in> X"
       
   341       show "x \<in> L xrhs"          
       
   342       proof (cases "x = []")
       
   343         assume empty: "x = []"
       
   344         hence "x \<in> L (empty_rhs X)" using "(1)"
       
   345           by (auto simp:empty_rhs_def lang_seq_def)
       
   346         thus ?thesis using X_in_equas False empty "(1)" 
       
   347           unfolding equations_def equation_rhs_def by auto
       
   348       next
       
   349         assume not_empty: "x \<noteq> []"
       
   350         hence "\<exists> clist c. x = clist @ [c]" by (case_tac x rule:rev_cases, auto)
       
   351         then obtain clist c where decom: "x = clist @ [c]" by blast
       
   352         moreover have "\<And> Y. \<lbrakk>Y \<in> UNIV Quo Lang; Y-c\<rightarrow>X; clist \<in> Y\<rbrakk>
       
   353           \<Longrightarrow> [c] \<in> L (folds ALT NULL {CHAR c |c. Y-c\<rightarrow>X})"
       
   354         proof -
       
   355           fix Y
       
   356           assume Y_is_eq_cl: "Y \<in> UNIV Quo Lang"
       
   357             and Y_CT_X: "Y-c\<rightarrow>X"
       
   358             and clist_in_Y: "clist \<in> Y"
       
   359           with finite_charset_rS 
       
   360           show "[c] \<in> L (folds ALT NULL {CHAR c |c. Y-c\<rightarrow>X})"
       
   361             by (auto simp :fold_alt_null_eqs)
       
   362         qed
       
   363         hence "\<exists>Xa. Xa \<in> UNIV Quo Lang \<and> clist @ [c] \<in> Xa ; L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})" 
       
   364           using X_in_equas False not_empty "(1)" decom
       
   365           by (auto dest!:every_eqclass_has_ascendent simp:equations_def equation_rhs_def lang_seq_def)
       
   366         then obtain Xa where 
       
   367           "Xa \<in> UNIV Quo Lang \<and> clist @ [c] \<in> Xa ; L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})" by blast
       
   368         hence "x \<in> L {(S, folds ALT NULL {CHAR c |c. S-c\<rightarrow>X}) |S. S \<in> UNIV Quo Lang}" 
       
   369           using X_in_equas "(1)" decom
       
   370           by (auto simp add:equations_def equation_rhs_def intro!:exI[where x = Xa])
       
   371         thus "x \<in> L xrhs" using X_in_equas False not_empty unfolding equations_def equation_rhs_def
       
   372           by auto
       
   373       qed
       
   374     qed
       
   375   next
       
   376     show "L xrhs \<subseteq> X"
       
   377     proof
       
   378       fix x 
       
   379       assume "(2)": "x \<in> L xrhs"
       
   380       have "(2_1)": "\<And> s1 s2 r Xa. \<lbrakk>s1 \<in> Xa; s2 \<in> L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> X"
       
   381         using finite_charset_rS
       
   382         by (auto simp:CT_def lang_seq_def fold_alt_null_eqs)
       
   383       have "(2_2)": "\<And> s1 s2 Xa r.\<lbrakk>s1 \<in> Xa; s2 \<in> L r; (Xa, r) \<in> empty_rhs X\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> X"
       
   384         by (simp add:empty_rhs_def split:if_splits)
       
   385       show "x \<in> X" using X_in_equas False "(2)"         
       
   386         by (auto intro:"(2_1)" "(2_2)" simp:equations_def equation_rhs_def lang_seq_def)
       
   387     qed
       
   388   qed
       
   389 qed
       
   390 
       
   391 
       
   392 
       
   393 lemma no_EMPTY_equations:
       
   394   "(X, xrhs) \<in> equations CS \<Longrightarrow> no_EMPTY_rhs xrhs"
       
   395 apply (clarsimp simp add:equations_def equation_rhs_def)
       
   396 apply (simp add:no_EMPTY_rhs_def empty_rhs_def, auto)
       
   397 apply (subgoal_tac "finite {CHAR c |c. Xa-c\<rightarrow>X}", drule_tac x = "[]" in fold_alt_null_eqs, clarsimp, rule finite_charset_rS)+
       
   398 done
       
   399 
       
   400 lemma init_ES_satisfy_ardenable:
       
   401   "(X, xrhs) \<in> equations (UNIV Quo Lang)  \<Longrightarrow> ardenable (X, xrhs)"  
       
   402   unfolding ardenable_def
       
   403   by (auto intro:distinct_rhs_equations no_EMPTY_equations simp:l_eq_r_in_equations simp del:L_rhs.simps)
       
   404 
       
   405 lemma init_ES_satisfy_Inv:
       
   406   assumes finite_CS: "finite (UNIV Quo Lang)"
       
   407   and X_in_eq_cls: "X \<in> UNIV Quo Lang"
       
   408   shows "Inv X (equations (UNIV Quo Lang))"
       
   409 proof -
       
   410   have "finite (equations (UNIV Quo Lang))" using finite_CS
       
   411     by (auto simp:equations_def)    
       
   412   moreover have "\<exists>rhs. (X, rhs) \<in> equations (UNIV Quo Lang)" using X_in_eq_cls 
       
   413     by (simp add:equations_def)
       
   414   moreover have "distinct_equas (equations (UNIV Quo Lang))" 
       
   415     by (auto simp:distinct_equas_def equations_def)
       
   416   moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow>
       
   417                  rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equations (UNIV Quo Lang)))" 
       
   418     apply (simp add:left_eq_cls_def equations_def rhs_eq_cls_def equation_rhs_def)
       
   419     by (auto simp:empty_rhs_def split:if_splits)
       
   420   moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow> X \<noteq> {}"
       
   421     by (clarsimp simp:equations_def empty_notin_CS intro:classical)
       
   422   moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow> ardenable (X, xrhs)"
       
   423     by (auto intro!:init_ES_satisfy_ardenable)
       
   424   ultimately show ?thesis by (simp add:Inv_def)
       
   425 qed
       
   426 
       
   427 
       
   428 text {* *********** END: proving the initial equation-system satisfies Inv ******* *}
       
   429 
       
   430 
       
   431 
       
   432 
       
   433 
       
   434 
       
   435 
       
   436 
       
   437 
       
   438 
       
   439 
       
   440 
       
   441 
       
   442 
       
   443 
       
   444 text {* ****** BEGIN: proving every equation-system's iteration step satisfies Inv ***** *}
       
   445 
       
   446 lemma not_T_aux: "\<lbrakk>\<not> TCon (insert a A); x = a\<rbrakk>
       
   447        \<Longrightarrow> \<exists>y. x \<noteq> y \<and> y \<in> insert a A "
       
   448 apply (case_tac "insert a A = {a}")
       
   449 by (auto simp:TCon_def)
       
   450 
       
   451 lemma not_T_atleast_2[rule_format]:
       
   452   "finite S \<Longrightarrow> \<forall> x. x \<in> S \<and> (\<not> TCon S)\<longrightarrow> (\<exists> y. x \<noteq> y \<and> y \<in> S)"
       
   453 apply (erule finite.induct, simp)
       
   454 apply (clarify, case_tac "x = a")
       
   455 by (erule not_T_aux, auto)
       
   456 
       
   457 lemma exist_another_equa: 
       
   458   "\<lbrakk>\<not> TCon ES; finite ES; distinct_equas ES; (X, rhl) \<in> ES\<rbrakk> \<Longrightarrow> \<exists> Y yrhl. (Y, yrhl) \<in> ES \<and> X \<noteq> Y"
       
   459 apply (drule not_T_atleast_2, simp)
       
   460 apply (clarsimp simp:distinct_equas_def)
       
   461 apply (drule_tac x= X in spec, drule_tac x = rhl in spec, drule_tac x = b in spec)
       
   462 by auto
       
   463 
       
   464 lemma Inv_mono_with_lambda:
       
   465   assumes Inv_ES: "Inv X ES"
       
   466   and X_noteq_Y:  "X \<noteq> {[]}"
       
   467   shows "Inv X (ES - {({[]}, yrhs)})"
       
   468 proof -
       
   469   have "finite (ES - {({[]}, yrhs)})" using Inv_ES
       
   470     by (simp add:Inv_def)
       
   471   moreover have "\<exists>rhs. (X, rhs) \<in> ES - {({[]}, yrhs)}" using Inv_ES X_noteq_Y
       
   472     by (simp add:Inv_def)
       
   473   moreover have "distinct_equas (ES - {({[]}, yrhs)})" using Inv_ES X_noteq_Y
       
   474     apply (clarsimp simp:Inv_def distinct_equas_def)
       
   475     by (drule_tac x = Xa in spec, simp)    
       
   476   moreover have "\<forall>X xrhs.(X, xrhs) \<in> ES - {({[]}, yrhs)} \<longrightarrow>
       
   477                           ardenable (X, xrhs) \<and> X \<noteq> {}" using Inv_ES
       
   478     by (clarify, simp add:Inv_def)
       
   479   moreover 
       
   480   have "insert {[]} (left_eq_cls (ES - {({[]}, yrhs)})) = insert {[]} (left_eq_cls ES)"
       
   481     by (auto simp:left_eq_cls_def)
       
   482   hence "\<forall>X xrhs.(X, xrhs) \<in> ES - {({[]}, yrhs)} \<longrightarrow>
       
   483                           rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (ES - {({[]}, yrhs)}))"
       
   484     using Inv_ES by (auto simp:Inv_def)
       
   485   ultimately show ?thesis by (simp add:Inv_def)
       
   486 qed
       
   487 
       
   488 lemma non_empty_card_prop:
       
   489   "finite ES \<Longrightarrow> \<forall>e. e \<in> ES \<longrightarrow> card ES - Suc 0 < card ES"
       
   490 apply (erule finite.induct, simp)
       
   491 apply (case_tac[!] "a \<in> A")
       
   492 by (auto simp:insert_absorb)
       
   493 
       
   494 lemma ardenable_prop:
       
   495   assumes not_lambda: "Y \<noteq> {[]}"
       
   496   and ardable: "ardenable (Y, yrhs)"
       
   497   shows "\<exists> yrhs'. Y = L yrhs' \<and> distinct_rhs yrhs' \<and> rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" (is "\<exists> yrhs'. ?P yrhs'")
       
   498 proof (cases "(\<exists> reg. (Y, reg) \<in> yrhs)")
       
   499   case True
       
   500   thus ?thesis 
       
   501   proof 
       
   502     fix reg
       
   503     assume self_contained: "(Y, reg) \<in> yrhs"
       
   504     show ?thesis 
       
   505     proof -
       
   506       have "?P (arden_variate Y reg yrhs)"
       
   507       proof -
       
   508         have "Y = L (arden_variate Y reg yrhs)" 
       
   509           using self_contained not_lambda ardable
       
   510           by (rule_tac arden_variate_valid, simp_all add:ardenable_def)
       
   511         moreover have "distinct_rhs (arden_variate Y reg yrhs)" 
       
   512           using ardable 
       
   513           by (auto simp:distinct_rhs_def arden_variate_def seq_rhs_r_def del_x_paired_def ardenable_def)
       
   514         moreover have "rhs_eq_cls (arden_variate Y reg yrhs) = rhs_eq_cls yrhs - {Y}"
       
   515         proof -
       
   516           have "\<And> rhs r. rhs_eq_cls (seq_rhs_r rhs r) = rhs_eq_cls rhs"
       
   517             apply (auto simp:rhs_eq_cls_def seq_rhs_r_def image_def)
       
   518             by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "(x, ra)" in bexI, simp+)
       
   519           moreover have "\<And> rhs X. rhs_eq_cls (del_x_paired rhs X) = rhs_eq_cls rhs - {X}"
       
   520             by (auto simp:rhs_eq_cls_def del_x_paired_def)
       
   521           ultimately show ?thesis by (simp add:arden_variate_def)
       
   522         qed
       
   523         ultimately show ?thesis by simp
       
   524       qed
       
   525       thus ?thesis by (rule_tac x= "arden_variate Y reg yrhs" in exI, simp)
       
   526     qed
       
   527   qed
       
   528 next
       
   529   case False
       
   530   hence "(2)": "rhs_eq_cls yrhs - {Y} = rhs_eq_cls yrhs"
       
   531     by (auto simp:rhs_eq_cls_def)
       
   532   show ?thesis 
       
   533   proof -
       
   534     have "?P yrhs" using False ardable "(2)" 
       
   535       by (simp add:ardenable_def)      
       
   536     thus ?thesis by blast
       
   537   qed
       
   538 qed
       
   539 
       
   540 lemma equas_subst_f_del_no_other:
       
   541   assumes self_contained: "(Y, rhs) \<in> ES"
       
   542   shows "\<exists> rhs'. (Y, rhs') \<in> (equas_subst_f X xrhs ` ES)" (is "\<exists> rhs'. ?P rhs'")
       
   543 proof -
       
   544   have "\<exists> rhs'. equas_subst_f X xrhs (Y, rhs) = (Y, rhs')"
       
   545     by (auto simp:equas_subst_f_def)
       
   546   then obtain rhs' where "equas_subst_f X xrhs (Y, rhs) = (Y, rhs')" by blast
       
   547   hence "?P rhs'" unfolding image_def using self_contained
       
   548     by (auto intro:bexI[where x = "(Y, rhs)"])
       
   549   thus ?thesis by blast
       
   550 qed
       
   551 
       
   552 lemma del_x_paired_del_only_x: 
       
   553   "\<lbrakk>X \<noteq> Y; (X, rhs) \<in> ES\<rbrakk> \<Longrightarrow> (X, rhs) \<in> del_x_paired ES Y"
       
   554 by (auto simp:del_x_paired_def)
       
   555 
       
   556 lemma equas_subst_del_no_other:
       
   557  "\<lbrakk>(X, rhs) \<in> ES; X \<noteq> Y\<rbrakk> \<Longrightarrow> (\<exists>rhs. (X, rhs) \<in> equas_subst ES Y rhs')"
       
   558 unfolding equas_subst_def
       
   559 apply (drule_tac X = Y and xrhs = rhs' in equas_subst_f_del_no_other)
       
   560 by (erule exE, drule del_x_paired_del_only_x, auto)
       
   561 
       
   562 lemma equas_subst_holds_distinct:
       
   563   "distinct_equas ES \<Longrightarrow> distinct_equas (equas_subst ES Y rhs')"
       
   564 apply (clarsimp simp add:equas_subst_def distinct_equas_def del_x_paired_def equas_subst_f_def)
       
   565 by (auto split:if_splits)
       
   566 
       
   567 lemma del_x_paired_dels: 
       
   568   "(X, rhs) \<in> ES \<Longrightarrow> {Y. Y \<in> ES \<and> fst Y = X} \<inter> ES \<noteq> {}"
       
   569 by (auto)
       
   570 
       
   571 lemma del_x_paired_subset:
       
   572   "(X, rhs) \<in> ES \<Longrightarrow> ES - {Y. Y \<in> ES \<and> fst Y = X} \<subset> ES"
       
   573 apply (drule del_x_paired_dels)
       
   574 by auto
       
   575 
       
   576 lemma del_x_paired_card_less: 
       
   577   "\<lbrakk>finite ES; (X, rhs) \<in> ES\<rbrakk> \<Longrightarrow> card (del_x_paired ES X) < card ES"
       
   578 apply (simp add:del_x_paired_def)
       
   579 apply (drule del_x_paired_subset)
       
   580 by (auto intro:psubset_card_mono)
       
   581 
       
   582 lemma equas_subst_card_less:
       
   583   "\<lbrakk>finite ES; (Y, yrhs) \<in> ES\<rbrakk> \<Longrightarrow> card (equas_subst ES Y rhs') < card ES"
       
   584 apply (simp add:equas_subst_def)
       
   585 apply (frule_tac h = "equas_subst_f Y rhs'" in finite_imageI)
       
   586 apply (drule_tac f = "equas_subst_f Y rhs'" in Finite_Set.card_image_le)
       
   587 apply (drule_tac X = Y and xrhs = rhs' in equas_subst_f_del_no_other,erule exE)
       
   588 by (drule del_x_paired_card_less, auto)
       
   589 
       
   590 lemma equas_subst_holds_distinct_rhs:
       
   591   assumes   dist': "distinct_rhs yrhs'"
       
   592   and     history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
       
   593   and     X_in :  "(X, xrhs) \<in> equas_subst ES Y yrhs'"
       
   594   shows "distinct_rhs xrhs"
       
   595 using X_in history
       
   596 apply (clarsimp simp:equas_subst_def del_x_paired_def)
       
   597 apply (drule_tac x = a in spec, drule_tac x = b in spec)
       
   598 apply (simp add:ardenable_def equas_subst_f_def)
       
   599 by (auto intro:rhs_subst_holds_distinct_rhs simp:dist' split:if_splits)
       
   600 
       
   601 lemma r_no_EMPTY_imp_seq_rhs_r_no_EMPTY:
       
   602   "[] \<notin> L r \<Longrightarrow> no_EMPTY_rhs (seq_rhs_r rhs r)"
       
   603 by (auto simp:no_EMPTY_rhs_def seq_rhs_r_def lang_seq_def)
       
   604 
       
   605 lemma del_x_paired_holds_no_EMPTY:
       
   606   "no_EMPTY_rhs yrhs \<Longrightarrow> no_EMPTY_rhs (del_x_paired yrhs Y)"
       
   607 by (auto simp:no_EMPTY_rhs_def del_x_paired_def)
       
   608 
       
   609 lemma rhs_subst_holds_no_EMPTY:
       
   610   "\<lbrakk>no_EMPTY_rhs yrhs; (Y, r) \<in> yrhs; Y \<noteq> {[]}\<rbrakk> \<Longrightarrow> no_EMPTY_rhs (rhs_subst yrhs Y rhs' r)"
       
   611 apply (auto simp:rhs_subst_def intro!:no_EMPTY_rhss_imp_merge_no_EMPTY r_no_EMPTY_imp_seq_rhs_r_no_EMPTY del_x_paired_holds_no_EMPTY)
       
   612 by (auto simp:no_EMPTY_rhs_def)
       
   613 
       
   614 lemma equas_subst_holds_no_EMPTY:
       
   615   assumes substor: "Y \<noteq> {[]}"
       
   616   and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
       
   617   and X_in:"(X, xrhs) \<in> equas_subst ES Y yrhs'"
       
   618   shows "no_EMPTY_rhs xrhs"
       
   619 proof-
       
   620   from X_in have "\<exists> (Z, zrhs) \<in> ES. (X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)"
       
   621     by (auto simp add:equas_subst_def del_x_paired_def)
       
   622   then obtain Z zrhs where Z_in: "(Z, zrhs) \<in> ES"
       
   623                        and X_Z: "(X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" by blast
       
   624   hence dist_zrhs: "distinct_rhs zrhs" using history
       
   625     by (auto simp:ardenable_def)
       
   626   show ?thesis
       
   627   proof (cases "\<exists> r. (Y, r) \<in> zrhs")
       
   628     case True
       
   629     then obtain r where Y_in_zrhs: "(Y, r) \<in> zrhs" ..
       
   630     hence some: "(SOME r. (Y, r) \<in> zrhs) = r" using Z_in dist_zrhs
       
   631       by (auto simp:distinct_rhs_def)
       
   632     hence "no_EMPTY_rhs (rhs_subst zrhs Y yrhs' r)"
       
   633       using substor Y_in_zrhs history Z_in
       
   634       by (rule_tac rhs_subst_holds_no_EMPTY, auto simp:ardenable_def)
       
   635     thus ?thesis using X_Z True some
       
   636       by (simp add:equas_subst_def equas_subst_f_def)
       
   637   next
       
   638     case False
       
   639     hence "(X, xrhs) = (Z, zrhs)" using Z_in X_Z
       
   640       by (simp add:equas_subst_f_def)
       
   641     thus ?thesis using history Z_in
       
   642       by (auto simp:ardenable_def)
       
   643   qed
       
   644 qed
       
   645 
       
   646 lemma equas_subst_f_holds_left_eq_right:
       
   647   assumes substor: "Y = L rhs'"
       
   648   and     history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> distinct_rhs xrhs \<and> X = L xrhs"
       
   649   and       subst: "(X, xrhs) = equas_subst_f Y rhs' (Z, zrhs)"
       
   650   and     self_contained: "(Z, zrhs) \<in> ES"
       
   651   shows "X = L xrhs"
       
   652 proof (cases "\<exists> r. (Y, r) \<in> zrhs")
       
   653   case True
       
   654   from True obtain r where "(1)":"(Y, r) \<in> zrhs" ..
       
   655   show ?thesis
       
   656   proof -
       
   657     from history self_contained
       
   658     have dist: "distinct_rhs zrhs" by auto
       
   659     hence "(SOME r. (Y, r) \<in> zrhs) = r" using self_contained "(1)"
       
   660       using distinct_rhs_def by (auto intro:some_equality)
       
   661     moreover have "L zrhs = L (rhs_subst zrhs Y rhs' r)" using substor dist "(1)" self_contained
       
   662       by (rule_tac rhs_subst_prop1, auto simp:distinct_equas_rhs_def)
       
   663     ultimately show ?thesis using subst history self_contained
       
   664       by (auto simp:equas_subst_f_def split:if_splits)
       
   665   qed
       
   666 next
       
   667   case False
       
   668   thus ?thesis using history subst self_contained
       
   669     by (auto simp:equas_subst_f_def)
       
   670 qed
       
   671 
       
   672 lemma equas_subst_holds_left_eq_right:
       
   673   assumes history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
       
   674   and     substor: "Y = L rhs'"
       
   675   and     X_in :  "(X, xrhs) \<in> equas_subst ES Y yrhs'"
       
   676   shows "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y rhs' \<longrightarrow> X = L xrhs"
       
   677 apply (clarsimp simp add:equas_subst_def del_x_paired_def)
       
   678 using substor
       
   679 apply (drule_tac equas_subst_f_holds_left_eq_right)
       
   680 using history
       
   681 by (auto simp:ardenable_def)
       
   682 
       
   683 lemma equas_subst_holds_ardenable:
       
   684   assumes substor: "Y = L yrhs'"
       
   685   and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
       
   686   and X_in:"(X, xrhs) \<in> equas_subst ES Y yrhs'"
       
   687   and dist': "distinct_rhs yrhs'"
       
   688   and not_lambda: "Y \<noteq> {[]}"
       
   689   shows "ardenable (X, xrhs)"
       
   690 proof -
       
   691   have "distinct_rhs xrhs" using history X_in dist' 
       
   692     by (auto dest:equas_subst_holds_distinct_rhs)
       
   693   moreover have "no_EMPTY_rhs xrhs" using history X_in not_lambda
       
   694     by (auto intro:equas_subst_holds_no_EMPTY)
       
   695   moreover have "X = L xrhs" using history substor X_in
       
   696   by (auto dest: equas_subst_holds_left_eq_right simp del:L_rhs.simps)
       
   697   ultimately show ?thesis using ardenable_def by simp
       
   698 qed
       
   699 
       
   700 lemma equas_subst_holds_cls_defined:
       
   701   assumes         X_in: "(X, xrhs) \<in> equas_subst ES Y yrhs'"
       
   702   and           Inv_ES: "Inv X' ES"
       
   703   and            subst: "(Y, yrhs) \<in> ES"
       
   704   and  cls_holds_but_Y: "rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}"
       
   705   shows "rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equas_subst ES Y yrhs'))"
       
   706 proof-
       
   707   have tac: "\<lbrakk> A \<subseteq> B; C \<subseteq> D; E \<subseteq> A \<union> B\<rbrakk> \<Longrightarrow> E \<subseteq> B \<union> D" by auto
       
   708   from X_in have "\<exists> (Z, zrhs) \<in> ES. (X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)"
       
   709     by (auto simp add:equas_subst_def del_x_paired_def)
       
   710   then obtain Z zrhs where Z_in: "(Z, zrhs) \<in> ES"
       
   711                        and X_Z: "(X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" by blast
       
   712   hence "rhs_eq_cls zrhs \<subseteq> insert {[]} (left_eq_cls ES)" using Inv_ES
       
   713     by (auto simp:Inv_def)
       
   714   moreover have "rhs_eq_cls yrhs' \<subseteq> insert {[]} (left_eq_cls ES) - {Y}" 
       
   715     using Inv_ES subst cls_holds_but_Y
       
   716     by (auto simp:Inv_def)
       
   717   moreover have "rhs_eq_cls xrhs \<subseteq> rhs_eq_cls zrhs \<union> rhs_eq_cls yrhs' - {Y}"
       
   718     using X_Z cls_holds_but_Y
       
   719     apply (clarsimp simp add:equas_subst_f_def rhs_subst_def split:if_splits)
       
   720     by (auto simp:rhs_eq_cls_def merge_rhs_def del_x_paired_def seq_rhs_r_def)
       
   721   moreover have "left_eq_cls (equas_subst ES Y yrhs') = left_eq_cls ES - {Y}" using subst
       
   722     by (auto simp: left_eq_cls_def equas_subst_def del_x_paired_def equas_subst_f_def
       
   723              dest: equas_subst_f_del_no_other
       
   724              split: if_splits)
       
   725   ultimately show ?thesis by blast
       
   726 qed
       
   727 
       
   728 lemma iteration_step: 
       
   729   assumes Inv_ES: "Inv X ES"
       
   730   and    not_T: "\<not> TCon ES"
       
   731   shows "(\<exists> ES'. Inv X ES' \<and> (card ES', card ES) \<in> less_than)" 
       
   732 proof -
       
   733   from Inv_ES not_T have another: "\<exists>Y yrhs. (Y, yrhs) \<in> ES \<and> X \<noteq> Y" unfolding Inv_def
       
   734     by (clarify, rule_tac exist_another_equa[where X = X], auto)
       
   735   then obtain Y yrhs where subst: "(Y, yrhs) \<in> ES" and not_X: " X \<noteq> Y" by blast
       
   736   show ?thesis (is "\<exists> ES'. ?P ES'")
       
   737   proof (cases "Y = {[]}") 
       
   738     case True
       
   739       --"in this situation, we pick a \"\<lambda>\" equation, thus directly remove it from the equation-system"
       
   740     have "?P (ES - {(Y, yrhs)})" 
       
   741     proof 
       
   742       show "Inv X (ES - {(Y, yrhs)})" using True not_X
       
   743         by (simp add:Inv_ES Inv_mono_with_lambda)
       
   744     next 
       
   745       show "(card (ES - {(Y, yrhs)}), card ES) \<in> less_than" using Inv_ES subst
       
   746         by (auto elim:non_empty_card_prop[rule_format] simp:Inv_def)
       
   747     qed
       
   748     thus ?thesis by blast
       
   749   next
       
   750     case False
       
   751       --"in this situation, we pick a equation and using ardenable to get a 
       
   752         rhs without itself in it, then use equas_subst to form a new equation-system"
       
   753     hence "\<exists> yrhs'. Y = L yrhs' \<and> distinct_rhs yrhs' \<and> rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" 
       
   754       using subst Inv_ES
       
   755       by (auto intro:ardenable_prop simp add:Inv_def simp del:L_rhs.simps)
       
   756     then obtain yrhs' where Y'_l_eq_r: "Y = L yrhs'"
       
   757       and dist_Y': "distinct_rhs yrhs'"
       
   758       and cls_holds_but_Y: "rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" by blast
       
   759     hence "?P (equas_subst ES Y yrhs')"
       
   760     proof -
       
   761       have finite_del: "\<And> S x. finite S \<Longrightarrow> finite (del_x_paired S x)" 
       
   762         apply (rule_tac A = "del_x_paired S x" in finite_subset)
       
   763         by (auto simp:del_x_paired_def)
       
   764       have "finite (equas_subst ES Y yrhs')" using Inv_ES 
       
   765         by (auto intro!:finite_del simp:equas_subst_def Inv_def)
       
   766       moreover have "\<exists>rhs. (X, rhs) \<in> equas_subst ES Y yrhs'" using Inv_ES not_X
       
   767         by (auto intro:equas_subst_del_no_other simp:Inv_def)
       
   768       moreover have "distinct_equas (equas_subst ES Y yrhs')" using Inv_ES
       
   769         by (auto intro:equas_subst_holds_distinct simp:Inv_def)
       
   770       moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow> ardenable (X, xrhs)"
       
   771         using Inv_ES dist_Y' False Y'_l_eq_r
       
   772         apply (clarsimp simp:Inv_def)
       
   773         by (rule equas_subst_holds_ardenable, simp_all)
       
   774       moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow> X \<noteq> {}" using Inv_ES
       
   775         by (clarsimp simp:equas_subst_def Inv_def del_x_paired_def equas_subst_f_def split:if_splits, auto)
       
   776       moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow>
       
   777                                rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equas_subst ES Y yrhs'))"
       
   778         using Inv_ES subst cls_holds_but_Y
       
   779         apply (rule_tac impI | rule_tac allI)+
       
   780         by (erule equas_subst_holds_cls_defined, auto)
       
   781       moreover have "(card (equas_subst ES Y yrhs'), card ES) \<in> less_than"using Inv_ES subst
       
   782         by (simp add:equas_subst_card_less Inv_def)
       
   783       ultimately show "?P (equas_subst ES Y yrhs')" by (auto simp:Inv_def)      
       
   784     qed
       
   785     thus ?thesis by blast
       
   786   qed
       
   787 qed
       
   788 
       
   789 text {* ***** END: proving every equation-system's iteration step satisfies Inv ************** *}
       
   790 
       
   791 lemma iteration_conc: 
       
   792   assumes history: "Inv X ES"
       
   793   shows "\<exists> ES'. Inv X ES' \<and> TCon ES'" (is "\<exists> ES'. ?P ES'")
       
   794 proof (cases "TCon ES")
       
   795   case True
       
   796   hence "?P ES" using history by simp
       
   797   thus ?thesis by blast
       
   798 next
   696 next
   799   case False  
   697   case False  
   800   thus ?thesis using history iteration_step
   698   thus ?thesis using history iteration_step X_in_ES
   801     by (rule_tac f = card in wf_iter, simp_all)
   699     by (rule_tac f = card in wf_iter, auto)
   802 qed
   700 qed
   803 
   701   
   804 lemma eqset_imp_iff': "A = B \<Longrightarrow> \<forall> x. x \<in> A \<longleftrightarrow> x \<in> B"
   702 lemma last_cl_exists_rexp:
   805 apply (auto simp:mem_def)
   703   assumes ES_single: "ES = {(X, xrhs)}" 
   806 done
   704   and Inv_ES: "Inv ES"
   807 
   705   shows "\<exists> (r::rexp). L r = X" (is "\<exists> r. ?P r")
   808 lemma set_cases2:
   706 proof-
   809   "\<lbrakk>(A = {} \<Longrightarrow> R A); \<And> x. (A = {x}) \<Longrightarrow> R A; \<And> x y. \<lbrakk>x \<noteq> y; x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> R A\<rbrakk> \<Longrightarrow> R A"
   707   let ?A = "arden_variate X xrhs"
   810 apply (case_tac "A = {}", simp)
   708   have "?P (rexp_of_lam ?A)"
   811 by (case_tac "\<exists> x. A = {x}", clarsimp, blast)
   709   proof -
   812 
   710     have "L (rexp_of_lam ?A) = L (lam_of ?A)"
   813 lemma rhs_aux:"\<lbrakk>distinct_rhs rhs; {Y. \<exists>r. (Y, r) \<in> rhs} = {X}\<rbrakk> \<Longrightarrow> (\<exists>r. rhs = {(X, r)})"
   711     proof(rule rexp_of_lam_eq_lam_set)
   814 apply (rule_tac A = rhs in set_cases2, simp)
   712       show "finite (arden_variate X xrhs)" using Inv_ES ES_single 
   815 apply (drule_tac x = X in eqset_imp_iff, clarsimp)
   713         by (rule_tac arden_variate_keeps_finite, auto simp add:Inv_def finite_rhs_def)
   816 apply (drule eqset_imp_iff',clarsimp)
   714     qed
   817 apply (frule_tac x = a in spec, drule_tac x = aa in spec)
   715     also have "\<dots> = L ?A"
   818 by (auto simp:distinct_rhs_def)
   716     proof-
   819 
   717       have "lam_of ?A = ?A"
       
   718       proof-
       
   719         have "classes_of ?A = {}" using Inv_ES ES_single
       
   720           by (simp add:arden_variate_removes_cl self_contained_def Inv_def lefts_of_def) 
       
   721         thus ?thesis by (auto simp only:lam_of_def classes_of_def, case_tac x, auto)
       
   722       qed
       
   723       thus ?thesis by simp
       
   724     qed
       
   725     also have "\<dots> = X"
       
   726     proof(rule arden_variate_keeps_eq [THEN sym])
       
   727       show "X = L xrhs" using Inv_ES ES_single by (auto simp only:Inv_def valid_eqns_def)  
       
   728     next
       
   729       from Inv_ES ES_single show "[] \<notin> L (rexp_of xrhs X)"
       
   730         by(simp add:Inv_def ardenable_def rexp_of_empty finite_rhs_def)
       
   731     next
       
   732       from Inv_ES ES_single show "finite xrhs" by (simp add:Inv_def finite_rhs_def)
       
   733     qed
       
   734     finally show ?thesis by simp
       
   735   qed
       
   736   thus ?thesis by auto
       
   737 qed
       
   738    
   820 lemma every_eqcl_has_reg: 
   739 lemma every_eqcl_has_reg: 
   821   assumes finite_CS: "finite (UNIV Quo Lang)"
   740   assumes finite_CS: "finite (UNIV // (\<approx>Lang))"
   822   and X_in_CS: "X \<in> (UNIV Quo Lang)"
   741   and X_in_CS: "X \<in> (UNIV // (\<approx>Lang))"
   823   shows "\<exists> (reg::rexp). L reg = X" (is "\<exists> r. ?E r")
   742   shows "\<exists> (reg::rexp). L reg = X" (is "\<exists> r. ?E r")
   824 proof-
   743 proof -
   825   have "\<exists>ES'. Inv X ES' \<and> TCon ES'" using finite_CS X_in_CS
   744   from X_in_CS have "\<exists> xrhs. (X, xrhs) \<in> (eqs (UNIV  // (\<approx>Lang)))"
   826     by (auto intro:init_ES_satisfy_Inv iteration_conc)
   745     by (auto simp:eqs_def init_rhs_def)
   827   then obtain ES' where Inv_ES': "Inv X ES'" 
   746   then obtain ES xrhs where Inv_ES: "Inv ES" 
   828                    and  TCon_ES': "TCon ES'" by blast
   747     and X_in_ES: "(X, xrhs) \<in> ES"
   829   from Inv_ES' TCon_ES' 
   748     and card_ES: "card ES = 1"
   830   have "\<exists> rhs. ES' = {(X, rhs)}"
   749     using finite_CS X_in_CS init_ES_satisfy_Inv iteration_conc
   831     apply (clarsimp simp:Inv_def TCon_def)
   750     by blast
   832     apply (rule_tac x = rhs in exI)
   751   hence ES_single_equa: "ES = {(X, xrhs)}" 
   833     by (auto dest!:card_Suc_Diff1 simp:card_eq_0_iff)  
   752     by (auto simp:Inv_def dest!:card_Suc_Diff1 simp:card_eq_0_iff) 
   834   then obtain rhs where ES'_single_equa: "ES' = {(X, rhs)}" ..
   753   thus ?thesis using Inv_ES
   835   hence X_ardenable: "ardenable (X, rhs)" using Inv_ES'
   754     by (rule last_cl_exists_rexp)
   836     by (simp add:Inv_def)
   755 qed
       
   756 
       
   757 theorem hard_direction: 
       
   758   assumes finite_CS: "finite (UNIV // (\<approx>Lang))"
       
   759   shows   "\<exists> (reg::rexp). Lang = L reg"
       
   760 proof -
       
   761   have "\<forall> X \<in> (UNIV // (\<approx>Lang)). \<exists> (reg::rexp). X = L reg" 
       
   762     using finite_CS every_eqcl_has_reg by blast
       
   763   then obtain f where f_prop: "\<forall> X \<in> (UNIV // (\<approx>Lang)). X = L ((f X)::rexp)" 
       
   764     by (auto dest:bchoice)
       
   765   def rs \<equiv> "f ` {X. final X Lang}"  
       
   766   have "Lang = \<Union> {X. final X Lang}" using lang_is_union_of_finals by simp
       
   767   also have "\<dots> = L (folds ALT NULL rs)" 
       
   768   proof -
       
   769     have "finite {X. final X Lang}" using finite_CS by (auto simp:final_def)
       
   770     thus ?thesis  using f_prop by (auto simp:rs_def final_def)
       
   771   qed
       
   772   finally show ?thesis by blast
       
   773 qed 
       
   774 
       
   775 section {* regular \<Rightarrow> finite*}
       
   776 
       
   777 lemma quot_empty_subset:
       
   778   "UNIV // (\<approx>{[]}) \<subseteq> {{[]}, UNIV - {[]}}"
       
   779 proof
       
   780   fix x
       
   781   assume h: "x \<in> UNIV // \<approx>{[]}"
       
   782   show "x \<in> {{[]}, UNIV - {[]}}"
       
   783     
       
   784  
       
   785   have "\<And> s. s \<approx>{[]} [] \<Longrightarrow> s = []"
       
   786     apply (auto simp add:str_eq_def)
       
   787     apply blast
   837   
   788   
   838   from X_ardenable have X_l_eq_r: "X = L rhs"
   789   hence "False"
   839     by (simp add:ardenable_def)
   790     apply (simp add:quotient_def)
   840   hence rhs_not_empty: "rhs \<noteq> {}" using Inv_ES' ES'_single_equa
   791 
   841     by (auto simp:Inv_def ardenable_def)
   792 
   842   have rhs_eq_cls: "rhs_eq_cls rhs \<subseteq> {X, {[]}}"
   793 lemma other_direction:
   843     using Inv_ES' ES'_single_equa
   794   "Lang = L (r::rexp) \<Longrightarrow> finite (UNIV // (\<approx>Lang))"
   844     by (auto simp:Inv_def ardenable_def left_eq_cls_def)
   795 proof (induct arbitrary:Lang rule:rexp.induct)
   845   have X_not_empty: "X \<noteq> {}" using Inv_ES' ES'_single_equa
   796   case NULL
   846     by (auto simp:Inv_def)    
   797   have "UNIV // (\<approx>{}) \<subseteq> {UNIV} "
   847   show ?thesis
   798     by (auto simp:quotient_def str_eq_rel_def str_eq_def)
   848   proof (cases "X = {[]}")
   799   with prems show "?case" by (auto intro:finite_subset)
   849     case True
   800 next
   850     hence "?E EMPTY" by (simp)
   801   case EMPTY
   851     thus ?thesis by blast
   802   have "UNIV // (\<approx>{[]}) \<subseteq> {{[]}, UNIV - {[]}}"
   852   next
   803     sorry
   853     case False with  X_ardenable
   804   with prems show ?case by (auto intro:finite_subset)
   854     have "\<exists> rhs'. X = L rhs' \<and> rhs_eq_cls rhs' = rhs_eq_cls rhs - {X} \<and> distinct_rhs rhs'"
   805 next
   855       by (drule_tac ardenable_prop, auto)
   806   case (CHAR c)
   856     then obtain rhs' where X_eq_rhs': "X = L rhs'"
   807   have "UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}"
   857       and rhs'_eq_cls: "rhs_eq_cls rhs' = rhs_eq_cls rhs - {X}" 
   808     sorry
   858       and rhs'_dist : "distinct_rhs rhs'" by blast
   809   with prems show ?case by (auto intro:finite_subset)
   859     have "rhs_eq_cls rhs' \<subseteq> {{[]}}" using rhs_eq_cls False rhs'_eq_cls rhs_not_empty 
   810 next
   860       by blast
   811   case (SEQ r1 r2)
   861     hence "rhs_eq_cls rhs' = {{[]}}" using X_not_empty X_eq_rhs'
   812   show ?case sorry
   862       by (auto simp:rhs_eq_cls_def)
   813 next
   863     hence "\<exists> r. rhs' = {({[]}, r)}" using rhs'_dist
   814   case (ALT r1 r1)
   864       by (auto intro:rhs_aux simp:rhs_eq_cls_def)
   815   show ?case sorry
   865     then obtain r where "rhs' = {({[]}, r)}" ..
   816 next
   866     hence "?E r" using X_eq_rhs' by (auto simp add:lang_seq_def)
   817   case (STAR r)
   867     thus ?thesis by blast     
   818   show ?case sorry
   868   qed
   819 qed
   869 qed
   820     
   870 
   821 
   871 text {* definition of a regular language *}
   822       
   872 
   823 
   873 abbreviation
   824 
   874   reg :: "string set => bool"
   825 
   875 where
   826 
   876   "reg L1 \<equiv> (\<exists>r::rexp. L r = L1)"
   827 
   877 
   828 
   878 theorem myhill_nerode: 
   829 
   879   assumes finite_CS: "finite (UNIV Quo Lang)"
   830 
   880   shows   "\<exists> (reg::rexp). Lang = L reg" (is "\<exists> r. ?P r")
   831 
   881 proof -
   832 
   882   have has_r_each: "\<forall>C\<in>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists>(r::rexp). C = L r" using finite_CS
   833 
   883     by (auto dest:every_eqcl_has_reg)  
   834 
   884   have "\<exists> (rS::rexp set). finite rS \<and> 
   835 
   885                           (\<forall> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists> r \<in> rS. C = L r) \<and> 
   836 
   886                           (\<forall> r \<in> rS. \<exists> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. C = L r)" 
   837 
   887        (is "\<exists> rS. ?Q rS")
   838 
   888   proof-
   839 
   889     have "\<And> C. C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang} \<Longrightarrow> C = L (SOME (ra::rexp). C = L ra)"
   840 apply (induct arbitrary:Lang rule:rexp.induct)
   890       using has_r_each
   841 apply (simp add:QUOT_def equiv_class_def equiv_str_def)
   891       apply (erule_tac x = C in ballE, erule_tac exE)
   842 by (simp_all add:quot_lambda quot_single quot_seq quot_alt quot_star)  
   892       by (rule_tac a = r in someI2, simp+)
       
   893     hence "?Q ((\<lambda> C. SOME r. C = L r) ` {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang})" using has_r_each
       
   894       using finite_CS by auto
       
   895     thus ?thesis by blast    
       
   896   qed
       
   897   then obtain rS where finite_rS : "finite rS"
       
   898     and has_r_each': "\<forall> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists> r \<in> (rS::rexp set). C = L r"
       
   899     and has_cl_each: "\<forall> r \<in> (rS::rexp set). \<exists> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. C = L r" by blast
       
   900   have "?P (folds ALT NULL rS)"
       
   901   proof
       
   902     show "Lang \<subseteq> L (folds ALT NULL rS)" using finite_rS lang_eqs_union_of_eqcls[of Lang] has_r_each'
       
   903       apply (clarsimp simp:fold_alt_null_eqs) by blast
       
   904   next 
       
   905     show "L (folds ALT NULL rS) \<subseteq> Lang" using finite_rS lang_eqs_union_of_eqcls[of Lang] has_cl_each
       
   906       by (clarsimp simp:fold_alt_null_eqs)
       
   907   qed
       
   908   thus ?thesis by blast
       
   909 qed 
       
   910 
       
   911 
       
   912 text {* tests by Christian *}
       
   913 
   843 
   914 (* Alternative definition for Quo *)
   844 (* Alternative definition for Quo *)
   915 definition 
   845 definition 
   916   QUOT :: "string set \<Rightarrow> (string set) set"  
   846   QUOT :: "string set \<Rightarrow> (string set) set"  
   917 where
   847 where