MyhillNerode.thy
changeset 23 e31b733ace44
parent 19 48744a7f2661
equal deleted inserted replaced
22:0792821035b6 23:e31b733ace44
     1 theory MyhillNerode
     1 theory MyhillNerode
     2   imports "Main" 
     2   imports "Main" "List_Prefix"
     3 begin
     3 begin
     4 
     4 
     5 text {* sequential composition of languages *}
     5 text {* sequential composition of languages *}
     6 
     6 
     7 definition
     7 definition
   279 definition  
   279 definition  
   280   quot :: "string set \<Rightarrow> string set \<Rightarrow> (string set) set" ("_ Quo _" [100, 100] 100)
   280   quot :: "string set \<Rightarrow> string set \<Rightarrow> (string set) set" ("_ Quo _" [100, 100] 100)
   281 where
   281 where
   282   "L1 Quo L2 \<equiv> { \<lbrakk>x\<rbrakk>L2 | x. x \<in> L1}" 
   282   "L1 Quo L2 \<equiv> { \<lbrakk>x\<rbrakk>L2 | x. x \<in> L1}" 
   283 
   283 
       
   284 
   284 lemma lang_eqs_union_of_eqcls: 
   285 lemma lang_eqs_union_of_eqcls: 
   285   "Lang = (\<Union> {X. X \<in> (UNIV Quo Lang) \<and> (\<forall> x \<in> X. x \<in> Lang)})"
   286   "Lang = \<Union> {X. X \<in> (UNIV Quo Lang) \<and> (\<forall> x \<in> X. x \<in> Lang)}"
   286 proof
   287 proof
   287   show "Lang \<subseteq> \<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}"
   288   show "Lang \<subseteq> \<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}"
   288   proof
   289   proof
   289     fix x
   290     fix x
   290     assume "x \<in> Lang"
   291     assume "x \<in> Lang"
   302 next
   303 next
   303   show "\<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang} \<subseteq> Lang"
   304   show "\<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang} \<subseteq> Lang"
   304     by auto
   305     by auto
   305 qed
   306 qed
   306 
   307 
   307 
       
   308 lemma empty_notin_CS: "{} \<notin> UNIV Quo Lang"
   308 lemma empty_notin_CS: "{} \<notin> UNIV Quo Lang"
   309 apply (clarsimp simp:quot_def equiv_class_def)
   309 apply (clarsimp simp:quot_def equiv_class_def)
   310 by (rule_tac x = x in exI, auto simp:equiv_str_def)
   310 by (rule_tac x = x in exI, auto simp:equiv_str_def)
   311 
   311 
   312 lemma no_two_cls_inters:
   312 lemma no_two_cls_inters:
   315 
   315 
   316 text {* equiv_class transition *}
   316 text {* equiv_class transition *}
   317 definition 
   317 definition 
   318   CT :: "string set \<Rightarrow> char \<Rightarrow> string set \<Rightarrow> bool" ("_-_\<rightarrow>_" [99,99]99)
   318   CT :: "string set \<Rightarrow> char \<Rightarrow> string set \<Rightarrow> bool" ("_-_\<rightarrow>_" [99,99]99)
   319 where
   319 where
   320   "X-c\<rightarrow>Y \<equiv> ( X; {[c]} \<subseteq> Y)"
   320   "X-c\<rightarrow>Y \<equiv> ((X;{[c]}) \<subseteq> Y)"
   321 
   321 
   322 types t_equa_rhs = "(string set \<times> rexp) set"
   322 types t_equa_rhs = "(string set \<times> rexp) set"
   323 
   323 
   324 types t_equa = "(string set \<times> t_equa_rhs)"
   324 types t_equa = "(string set \<times> t_equa_rhs)"
   325 
   325 
   343 
   343 
   344 definition 
   344 definition 
   345   equation_rhs :: "(string set) set \<Rightarrow> string set \<Rightarrow> t_equa_rhs"
   345   equation_rhs :: "(string set) set \<Rightarrow> string set \<Rightarrow> t_equa_rhs"
   346 where
   346 where
   347   "equation_rhs CS X \<equiv> if (X = {[]}) then {({[]}, EMPTY)}
   347   "equation_rhs CS X \<equiv> if (X = {[]}) then {({[]}, EMPTY)}
   348     else {(S, folds ALT NULL {CHAR c| c. S-c\<rightarrow>X} )| S. S \<in> CS} \<union> empty_rhs X"
   348                          else {(S, folds ALT NULL {CHAR c| c. S-c\<rightarrow>X} )| S. S \<in> CS} \<union> empty_rhs X"
   349 
   349 
   350 definition 
   350 definition 
   351   equations :: "(string set) set \<Rightarrow> t_equas"
   351   equations :: "(string set) set \<Rightarrow> t_equas"
   352 where
   352 where
   353   "equations CS \<equiv> {(X, equation_rhs CS X) | X. X \<in> CS}"
   353   "equations CS \<equiv> {(X, equation_rhs CS X) | X. X \<in> CS}"
   496     qed
   496     qed
   497   qed
   497   qed
   498 qed
   498 qed
   499 
   499 
   500 text {* 
   500 text {* 
   501   merge_rhs {(X1, r1), (x2, r2}, (x4, r4), \<dots>} {(x1, r1'), (x3, r3'), \<dots>} = 
   501   merge_rhs {(x1, r1), (x2, r2}, (x4, r4), \<dots>} {(x1, r1'), (x3, r3'), \<dots>} = 
   502      {(x1, ALT r1 r1'}, (x2, r2), (x3, r3'), (x4, r4), \<dots>} *}  
   502      {(x1, ALT r1 r1'}, (x2, r2), (x3, r3'), (x4, r4), \<dots>} *}  
   503 definition 
   503 definition 
   504   merge_rhs :: "t_equa_rhs \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa_rhs"
   504   merge_rhs :: "t_equa_rhs \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa_rhs"
   505 where
   505 where
   506   "merge_rhs rhs rhs' \<equiv> {(X, r). (\<exists> r1 r2. ((X,r1) \<in> rhs \<and> (X, r2) \<in> rhs') \<and> r = ALT r1 r2)  \<or>
   506   "merge_rhs rhs rhs' \<equiv> {(X, r). (\<exists> r1 r2. ((X,r1) \<in> rhs \<and> (X, r2) \<in> rhs') \<and> r = ALT r1 r2)  \<or>
   507                                  (\<exists> r1. (X, r1) \<in> rhs \<and> (\<not> (\<exists> r2. (X, r2) \<in> rhs')) \<and> r = r1) \<or>
   507                                  (\<exists> r1. (X, r1) \<in> rhs \<and> (\<not> (\<exists> r2. (X, r2) \<in> rhs')) \<and> r = r1) \<or>
   508                                  (\<exists> r2. (X, r2) \<in> rhs' \<and> (\<not> (\<exists> r1. (X, r1) \<in> rhs)) \<and> r = r2)    }"   
   508                                  (\<exists> r2. (X, r2) \<in> rhs' \<and> (\<not> (\<exists> r1. (X, r1) \<in> rhs)) \<and> r = r2)    }"                                  
   509 
   509 
   510 
   510 
   511 text {* rhs_subst rhs X=xrhs r: substitude all occurence of X in rhs((X,r) \<in> rhs) with xrhs *}
   511 text {* rhs_subst rhs X=xrhs r: substitude all occurence of X in rhs((X,r) \<in> rhs) with xrhs *}
   512 definition 
   512 definition 
   513   rhs_subst :: "t_equa_rhs \<Rightarrow> string set \<Rightarrow> t_equa_rhs \<Rightarrow> rexp \<Rightarrow> t_equa_rhs"
   513   rhs_subst :: "t_equa_rhs \<Rightarrow> string set \<Rightarrow> t_equa_rhs \<Rightarrow> rexp \<Rightarrow> t_equa_rhs"
   629   Inv: Invairance of the equation-system, during the decrease of the equation-system, Inv holds.
   629   Inv: Invairance of the equation-system, during the decrease of the equation-system, Inv holds.
   630 *}
   630 *}
   631 definition Inv :: "string set \<Rightarrow> t_equas \<Rightarrow> bool"
   631 definition Inv :: "string set \<Rightarrow> t_equas \<Rightarrow> bool"
   632 where
   632 where
   633   "Inv X ES \<equiv> finite ES \<and> (\<exists> rhs. (X, rhs) \<in> ES) \<and> distinct_equas ES \<and> 
   633   "Inv X ES \<equiv> finite ES \<and> (\<exists> rhs. (X, rhs) \<in> ES) \<and> distinct_equas ES \<and> 
   634          (\<forall> X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs) \<and> X \<noteq> {} \<and> rhs_eq_cls xrhs 
   634             (\<forall> X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs) \<and> X \<noteq> {} \<and> rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls ES))"
   635               \<subseteq> insert {[]} (left_eq_cls ES))"
       
   636 
   635 
   637 text {*
   636 text {*
   638   TCon: Termination Condition of the equation-system decreasion.
   637   TCon: Termination Condition of the equation-system decreasion.
   639 *}
   638 *}
   640 definition TCon:: "'a set \<Rightarrow> bool"
   639 definition TCon:: "'a set \<Rightarrow> bool"
   642   "TCon ES \<equiv> card ES = 1"
   641   "TCon ES \<equiv> card ES = 1"
   643 
   642 
   644 
   643 
   645 text {* 
   644 text {* 
   646   The following is a iteration principle, and is the main framework for the proof:
   645   The following is a iteration principle, and is the main framework for the proof:
       
   646    1: We can form the initial equation-system using "equations" defined above, and prove it has invariance Inv by lemma "init_ES_satisfy_Inv";
       
   647    2: We can decrease the number of the equation-system using ardens_lemma_revised and substitution ("equas_subst", defined above), 
       
   648         and prove it holds the property "step" in "wf_iter" by lemma "iteration_step"
       
   649    and finally using property Inv and TCon to prove the myhill-nerode theorem
   647   
   650   
   648    1: We can form the initial equation-system using "equations" defined above, 
       
   649       and prove it has invariance Inv by lemma "init_ES_satisfy_Inv";
       
   650    
       
   651    2: We can decrease the number of the equation-system using ardens_lemma_revised 
       
   652       and substitution ("equas_subst", defined above), 
       
   653       and prove it holds the property "step" in "wf_iter" by lemma "iteration_step"
       
   654       and finally using property Inv and TCon to prove the myhill-nerode theorem
       
   655 *}
   651 *}
   656 lemma wf_iter [rule_format]: 
   652 lemma wf_iter [rule_format]: 
   657   fixes f
   653   fixes f
   658   assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and>  (f(e'), f(e)) \<in> less_than)"
   654   assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and>  (f(e'), f(e)) \<in> less_than)"
   659   shows pe:     "P e \<longrightarrow> (\<exists> e'. P e' \<and>  Q e')"
   655   shows pe:     "P e \<longrightarrow> (\<exists> e'. P e' \<and>  Q e')"
   804 
   800 
   805 lemma no_EMPTY_equations:
   801 lemma no_EMPTY_equations:
   806   "(X, xrhs) \<in> equations CS \<Longrightarrow> no_EMPTY_rhs xrhs"
   802   "(X, xrhs) \<in> equations CS \<Longrightarrow> no_EMPTY_rhs xrhs"
   807 apply (clarsimp simp add:equations_def equation_rhs_def)
   803 apply (clarsimp simp add:equations_def equation_rhs_def)
   808 apply (simp add:no_EMPTY_rhs_def empty_rhs_def, auto)
   804 apply (simp add:no_EMPTY_rhs_def empty_rhs_def, auto)
   809 apply (subgoal_tac "finite {CHAR c |c. Xa-c\<rightarrow>X}",
   805 apply (subgoal_tac "finite {CHAR c |c. Xa-c\<rightarrow>X}", drule_tac x = "[]" in fold_alt_null_eqs, clarsimp, rule finite_charset_rS)+
   810   drule_tac x = "[]" in fold_alt_null_eqs, clarsimp, rule finite_charset_rS)+
       
   811 done
   806 done
   812 
   807 
   813 lemma init_ES_satisfy_ardenable:
   808 lemma init_ES_satisfy_ardenable:
   814   "(X, xrhs) \<in> equations (UNIV Quo Lang)  \<Longrightarrow> ardenable (X, xrhs)"  
   809   "(X, xrhs) \<in> equations (UNIV Quo Lang)  \<Longrightarrow> ardenable (X, xrhs)"  
   815   unfolding ardenable_def
   810   unfolding ardenable_def
   892 by (auto simp:insert_absorb)
   887 by (auto simp:insert_absorb)
   893 
   888 
   894 lemma ardenable_prop:
   889 lemma ardenable_prop:
   895   assumes not_lambda: "Y \<noteq> {[]}"
   890   assumes not_lambda: "Y \<noteq> {[]}"
   896   and ardable: "ardenable (Y, yrhs)"
   891   and ardable: "ardenable (Y, yrhs)"
   897   shows "\<exists> yrhs'. Y = L yrhs' \<and> distinct_rhs yrhs' \<and> rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" 
   892   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'")
   898     (is "\<exists> yrhs'. ?P yrhs'")
       
   899 proof (cases "(\<exists> reg. (Y, reg) \<in> yrhs)")
   893 proof (cases "(\<exists> reg. (Y, reg) \<in> yrhs)")
   900   case True
   894   case True
   901   thus ?thesis 
   895   thus ?thesis 
   902   proof 
   896   proof 
   903     fix reg
   897     fix reg
  1310 qed 
  1304 qed 
  1311 
  1305 
  1312 
  1306 
  1313 text {* tests by Christian *}
  1307 text {* tests by Christian *}
  1314 
  1308 
  1315 lemma temp_set_ext[no_atp]: "(\<And>x. (x:A) = (x:B)) \<Longrightarrow> (A = B)"
  1309 (* Alternative definition for Quo *)
  1316 by(auto intro:set_eqI)
       
  1317 
       
  1318 fun
       
  1319   MNRel
       
  1320 where
       
  1321   "MNRel Lang (x, y) = (x \<equiv>Lang\<equiv> y)"
       
  1322 
       
  1323 lemma
       
  1324   "equiv UNIV (MNRel Lang)"
       
  1325 unfolding equiv_def
       
  1326 unfolding refl_on_def sym_def trans_def
       
  1327 apply(auto simp add: mem_def equiv_str_def)
       
  1328 done
       
  1329 
       
  1330 lemma
       
  1331   "(MNRel Lang)``{x} = \<lbrakk>x\<rbrakk>Lang"
       
  1332 unfolding equiv_class_def Image_def mem_def
       
  1333 by (simp)
       
  1334 
       
  1335 lemma tt: "\<lbrakk>A = B; C \<subseteq> B\<rbrakk> \<Longrightarrow> C \<subseteq> A" by simp 
       
  1336 
       
  1337 lemma
       
  1338   "UNIV//(MNRel (L1 \<union> L2)) \<subseteq> (UNIV//(MNRel L1)) \<union> (UNIV//(MNRel L2))"
       
  1339 unfolding quotient_def
       
  1340 unfolding UNION_eq_Union_image
       
  1341 apply(rule tt)
       
  1342 apply(rule Un_Union_image[symmetric])
       
  1343 apply(simp)
       
  1344 apply(rule UN_mono)
       
  1345 apply(simp)
       
  1346 apply(simp)
       
  1347 unfolding Image_def
       
  1348 unfolding mem_def
       
  1349 unfolding MNRel.simps
       
  1350 apply(simp)
       
  1351 oops
       
  1352 
       
  1353 
       
  1354 
       
  1355 text {* Alternative definition for Quo *}
       
  1356 definition 
  1310 definition 
  1357   QUOT :: "string set \<Rightarrow> (string set) set"  
  1311   QUOT :: "string set \<Rightarrow> (string set) set"  
  1358 where
  1312 where
  1359   "QUOT Lang \<equiv> (\<Union>x. {\<lbrakk>x\<rbrakk>Lang})"
  1313   "QUOT Lang \<equiv> (\<Union>x. {\<lbrakk>x\<rbrakk>Lang})"
  1360 
  1314 
  1361 lemma test_01:
  1315 lemma test: 
  1362   "Lang \<subseteq> (\<Union> QUOT Lang)"
  1316   "UNIV Quo Lang = QUOT Lang"
  1363 unfolding QUOT_def equiv_class_def equiv_str_def
  1317 by (auto simp add: quot_def QUOT_def)
  1364 by (blast)
  1318 
  1365 
  1319 lemma test1:
  1366 
  1320   assumes finite_CS: "finite (QUOT Lang)"
  1367 (* by chunhan *)
  1321   shows "reg Lang"
       
  1322 using finite_CS
       
  1323 unfolding test[symmetric]
       
  1324 by (auto dest: myhill_nerode)
       
  1325 
       
  1326 lemma cons_one: "x @ y \<in> {z} \<Longrightarrow> x @ y = z"
       
  1327 by simp
       
  1328 
  1368 lemma quot_lambda: "QUOT {[]} = {{[]}, UNIV - {[]}}"
  1329 lemma quot_lambda: "QUOT {[]} = {{[]}, UNIV - {[]}}"
  1369 proof 
  1330 proof 
  1370   show "QUOT {[]} \<subseteq> {{[]}, UNIV - {[]}}"
  1331   show "QUOT {[]} \<subseteq> {{[]}, UNIV - {[]}}"
  1371   proof 
  1332   proof 
  1372     fix x 
  1333     fix x 
  1444               by (auto simp add:equiv_str_def)
  1405               by (auto simp add:equiv_str_def)
  1445             moreover have "xa = [c] \<Longrightarrow> x = {[c]}"
  1406             moreover have "xa = [c] \<Longrightarrow> x = {[c]}"
  1446             proof -
  1407             proof -
  1447               have "xa = [c] \<Longrightarrow> {y. xa \<equiv>{[c]}\<equiv> y} = {[c]}" using in_eqiv
  1408               have "xa = [c] \<Longrightarrow> {y. xa \<equiv>{[c]}\<equiv> y} = {[c]}" using in_eqiv
  1448                 apply (simp add:equiv_str_def)
  1409                 apply (simp add:equiv_str_def)
  1449                 apply (rule temp_set_ext, rule iffI, simp)
  1410                 apply (rule set_ext, rule iffI, simp)
  1450                 apply (drule_tac x = "[]" in spec, auto)
  1411                 apply (drule_tac x = "[]" in spec, auto)
  1451                 done   
  1412                 done   
  1452               thus "xa = [c] \<Longrightarrow> x = {[c]}" using in_eqiv by simp 
  1413               thus "xa = [c] \<Longrightarrow> x = {[c]}" using in_eqiv by simp 
  1453             qed
  1414             qed
  1454             moreover have "\<lbrakk>xa \<noteq> []; xa \<noteq> [c]\<rbrakk> \<Longrightarrow> x = UNIV - {[],[c]}"
  1415             moreover have "\<lbrakk>xa \<noteq> []; xa \<noteq> [c]\<rbrakk> \<Longrightarrow> x = UNIV - {[],[c]}"
  1455             proof -
  1416             proof -
  1456               have "\<lbrakk>xa \<noteq> []; xa \<noteq> [c]\<rbrakk> \<Longrightarrow> {y. xa \<equiv>{[c]}\<equiv> y} = UNIV - {[],[c]}" 
  1417               have "\<lbrakk>xa \<noteq> []; xa \<noteq> [c]\<rbrakk> \<Longrightarrow> {y. xa \<equiv>{[c]}\<equiv> y} = UNIV - {[],[c]}" 
  1457                 apply (clarsimp simp add:equiv_str_def)
  1418                 apply (clarsimp simp add:equiv_str_def)
  1458                 apply (rule temp_set_ext, rule iffI, simp)
  1419                 apply (rule set_ext, rule iffI, simp)
  1459                 apply (rule conjI)
  1420                 apply (rule conjI)
  1460                 apply (drule_tac x = "[c]" in spec, simp)
  1421                 apply (drule_tac x = "[c]" in spec, simp)
  1461                 apply (drule_tac x = "[]" in spec, simp)
  1422                 apply (drule_tac x = "[]" in spec, simp)
  1462                 by (auto dest:quot_single_aux)
  1423                 by (auto dest:quot_single_aux)
  1463               thus "\<lbrakk>xa \<noteq> []; xa \<noteq> [c]\<rbrakk> \<Longrightarrow> x = UNIV - {[],[c]}" using in_eqiv by simp
  1424               thus "\<lbrakk>xa \<noteq> []; xa \<noteq> [c]\<rbrakk> \<Longrightarrow> x = UNIV - {[],[c]}" using in_eqiv by simp
  1479           apply (simp add:QUOT_def equiv_class_def equiv_str_def)
  1440           apply (simp add:QUOT_def equiv_class_def equiv_str_def)
  1480           by (rule_tac x = "[]" in exI, auto)
  1441           by (rule_tac x = "[]" in exI, auto)
  1481         moreover have "x = {[c]} \<Longrightarrow> x \<in> QUOT {[c]}"
  1442         moreover have "x = {[c]} \<Longrightarrow> x \<in> QUOT {[c]}"
  1482           apply (simp add:QUOT_def equiv_class_def equiv_str_def)
  1443           apply (simp add:QUOT_def equiv_class_def equiv_str_def)
  1483           apply (rule_tac x = "[c]" in exI, simp)
  1444           apply (rule_tac x = "[c]" in exI, simp)
  1484           apply (rule temp_set_ext, rule iffI, simp+)
  1445           apply (rule set_ext, rule iffI, simp+)
  1485           by (drule_tac x = "[]" in spec, simp)
  1446           by (drule_tac x = "[]" in spec, simp)
  1486         moreover have "x = UNIV - {[],[c]} \<Longrightarrow> x \<in> QUOT {[c]}"
  1447         moreover have "x = UNIV - {[],[c]} \<Longrightarrow> x \<in> QUOT {[c]}"
  1487           using exist_another
  1448           using exist_another
  1488           apply (clarsimp simp add:QUOT_def equiv_class_def equiv_str_def)        
  1449           apply (clarsimp simp add:QUOT_def equiv_class_def equiv_str_def)        
  1489           apply (rule_tac x = "[a]" in exI, simp)
  1450           apply (rule_tac x = "[a]" in exI, simp)
  1490           apply (rule temp_set_ext, rule iffI, simp)
  1451           apply (rule set_ext, rule iffI, simp)
  1491           apply (clarsimp simp:quot_single_aux, simp)
  1452           apply (clarsimp simp:quot_single_aux, simp)
  1492           apply (rule conjI)
  1453           apply (rule conjI)
  1493           apply (drule_tac x = "[c]" in spec, simp)
  1454           apply (drule_tac x = "[c]" in spec, simp)
  1494           by (drule_tac x = "[]" in spec, simp)     
  1455           by (drule_tac x = "[]" in spec, simp)     
  1495         ultimately show ?thesis using in_res by blast
  1456         ultimately show ?thesis using in_res by blast
  1496       qed
  1457       qed
  1497     qed
  1458     qed
  1498   qed
  1459   qed
  1499 qed
  1460 qed
  1500 
  1461 
  1501 lemma quot_seq: 
  1462 lemma eq_class_imp_eq_str:
  1502   assumes finite1: "finite (QUOT L\<^isub>1)"
  1463   "\<lbrakk>x\<rbrakk>lang = \<lbrakk>y\<rbrakk>lang \<Longrightarrow> x \<equiv>lang\<equiv> y"
  1503   and finite2: "finite (QUOT L\<^isub>2)"
  1464 by (auto simp:equiv_class_def equiv_str_def)
  1504   shows "finite (QUOT (L\<^isub>1;L\<^isub>2))"
       
  1505 apply (simp add:QUOT_def equiv_class_def equiv_str_def)
       
  1506 sorry
       
  1507  
       
  1508 
       
  1509 lemma a:
       
  1510   "\<lbrakk>x \<equiv>L1\<equiv> y \<and> x \<equiv>L2\<equiv> y\<rbrakk> \<Longrightarrow> x \<equiv>(L1 \<union> L2)\<equiv> y"
       
  1511 apply(simp add: equiv_str_def)
       
  1512 done
       
  1513 
       
  1514 
       
  1515 (*
       
  1516 lemma quot_star:  
       
  1517   assumes finite1: "finite (QUOT L\<^isub>1)"
       
  1518   shows "finite (QUOT (L\<^isub>1\<star>))"
       
  1519 sorry
       
  1520 
       
  1521 
       
  1522 lemma other_direction:
       
  1523   "Lang = L (r::rexp) \<Longrightarrow> finite (QUOT Lang)"
       
  1524 apply (induct arbitrary:Lang rule:rexp.induct)
       
  1525 apply (simp add:QUOT_def equiv_class_def equiv_str_def)
       
  1526 by (simp_all add:quot_lambda quot_single quot_seq quot_alt quot_star)  
       
  1527 
       
  1528 lemma test: 
       
  1529   "UNIV Quo Lang = QUOT Lang"
       
  1530 by (auto simp add: quot_def QUOT_def)
       
  1531 *)
       
  1532 
       
  1533 
       
  1534 (* by chunhan *)
       
  1535 
       
  1536 
  1465 
  1537 lemma finite_tag_image: 
  1466 lemma finite_tag_image: 
  1538   "finite (range tag) \<Longrightarrow> finite (((op `) tag) ` S)"
  1467   "finite (range tag) \<Longrightarrow> finite (((op `) tag) ` S)"
  1539 apply (rule_tac B = "Pow (tag ` UNIV)" in finite_subset)
  1468 apply (rule_tac B = "Pow (tag ` UNIV)" in finite_subset)
  1540 by (auto simp add:image_def Pow_def)
  1469 by (auto simp add:image_def Pow_def)
  1541 
  1470 
  1542 term image
       
  1543 term "(op `) tag"
       
  1544 
       
  1545 lemma str_inj_imps:
  1471 lemma str_inj_imps:
  1546   assumes str_inj: "\<And> m n. tag m = tag (n::string) \<Longrightarrow> m \<equiv>lang\<equiv> n"
  1472   assumes str_inj: "\<And> m n. tag m = tag (n::string) \<Longrightarrow> m \<equiv>lang\<equiv> n"
  1547   shows "inj_on (image tag) (QUOT lang)"
  1473   shows "inj_on ((op `) tag) (QUOT lang)"
  1548 proof (clarsimp simp add:inj_on_def QUOT_def)
  1474 proof (clarsimp simp add:inj_on_def QUOT_def)
  1549   fix x y
  1475   fix x y
  1550   assume eq_tag: "tag ` \<lbrakk>x\<rbrakk>lang = tag ` \<lbrakk>y\<rbrakk>lang"
  1476   assume eq_tag: "tag ` \<lbrakk>x\<rbrakk>lang = tag ` \<lbrakk>y\<rbrakk>lang"
  1551   show "\<lbrakk>x\<rbrakk>lang = \<lbrakk>y\<rbrakk>lang"
  1477   show "\<lbrakk>x\<rbrakk>lang = \<lbrakk>y\<rbrakk>lang"
  1552   proof -
  1478   proof -
  1561       apply (drule_tac str_inj, (drule_tac aux1)+)
  1487       apply (drule_tac str_inj, (drule_tac aux1)+)
  1562       by (simp add:equiv_str_def equiv_class_def)
  1488       by (simp add:equiv_str_def equiv_class_def)
  1563   qed
  1489   qed
  1564 qed
  1490 qed
  1565 
  1491 
  1566 definition 
  1492 definition tag_str_ALT :: "string set \<Rightarrow> string set \<Rightarrow> string \<Rightarrow> (string set \<times> string set)"
  1567   tag_str_ALT :: "string set \<Rightarrow> string set \<Rightarrow> string \<Rightarrow> (string set \<times> string set)"
       
  1568 where
  1493 where
  1569   "tag_str_ALT L\<^isub>1 L\<^isub>2 x \<equiv> (\<lbrakk>x\<rbrakk>L\<^isub>1, \<lbrakk>x\<rbrakk>L\<^isub>2)"
  1494   "tag_str_ALT L\<^isub>1 L\<^isub>2 x \<equiv> (\<lbrakk>x\<rbrakk>L\<^isub>1, \<lbrakk>x\<rbrakk>L\<^isub>2)"
  1570 
       
  1571 lemma
       
  1572   "{(\<lbrakk>x\<rbrakk>L\<^isub>1, \<lbrakk>x\<rbrakk>L\<^isub>2) | x. True} \<subseteq> (QUOT L\<^isub>1) \<times> (QUOT L\<^isub>2)"
       
  1573 unfolding QUOT_def
       
  1574 by (auto)
       
  1575 
  1495 
  1576 lemma tag_str_alt_range_finite:
  1496 lemma tag_str_alt_range_finite:
  1577   assumes finite1: "finite (QUOT L\<^isub>1)"
  1497   assumes finite1: "finite (QUOT L\<^isub>1)"
  1578   and finite2: "finite (QUOT L\<^isub>2)"
  1498   and finite2: "finite (QUOT L\<^isub>2)"
  1579   shows "finite (range (tag_str_ALT L\<^isub>1 L\<^isub>2))"
  1499   shows "finite (range (tag_str_ALT L\<^isub>1 L\<^isub>2))"
  1580 proof -
  1500 proof -
  1581   have "{y. \<exists>x. y = (\<lbrakk>x\<rbrakk>L\<^isub>1, \<lbrakk>x\<rbrakk>L\<^isub>2)} \<subseteq> (QUOT L\<^isub>1) \<times> (QUOT L\<^isub>2)"
  1501   have "{y. \<exists>x. y = (\<lbrakk>x\<rbrakk>L\<^isub>1, \<lbrakk>x\<rbrakk>L\<^isub>2)} \<subseteq> (QUOT L\<^isub>1) \<times> (QUOT L\<^isub>2)"
  1582     unfolding QUOT_def
  1502     by (auto simp:QUOT_def)
  1583     by auto
       
  1584   thus ?thesis using finite1 finite2
  1503   thus ?thesis using finite1 finite2
  1585     by (auto simp: image_def tag_str_ALT_def UNION_def 
  1504     by (auto simp: image_def tag_str_ALT_def UNION_def 
  1586             intro: finite_subset[where B = "(QUOT L\<^isub>1) \<times> (QUOT L\<^isub>2)"])
  1505             intro: finite_subset[where B = "(QUOT L\<^isub>1) \<times> (QUOT L\<^isub>2)"])
  1587 qed
  1506 qed
  1588 
  1507 
  1593   
  1512   
  1594 lemma quot_alt:
  1513 lemma quot_alt:
  1595   assumes finite1: "finite (QUOT L\<^isub>1)"
  1514   assumes finite1: "finite (QUOT L\<^isub>1)"
  1596   and finite2: "finite (QUOT L\<^isub>2)"
  1515   and finite2: "finite (QUOT L\<^isub>2)"
  1597   shows "finite (QUOT (L\<^isub>1 \<union> L\<^isub>2))"
  1516   shows "finite (QUOT (L\<^isub>1 \<union> L\<^isub>2))"
  1598 proof -
  1517 proof (rule_tac f = "(op `) (tag_str_ALT L\<^isub>1 L\<^isub>2)" in finite_imageD)
  1599   have "finite (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2) ` QUOT (L\<^isub>1 \<union> L\<^isub>2))"
  1518   show "finite (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2) ` QUOT (L\<^isub>1 \<union> L\<^isub>2))"
  1600     using finite_tag_image tag_str_alt_range_finite finite1 finite2
  1519     using finite_tag_image tag_str_alt_range_finite finite1 finite2
  1601     by auto
  1520     by auto
  1602   moreover 
  1521 next
  1603   have "inj_on (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2)) (QUOT (L\<^isub>1 \<union> L\<^isub>2))"
  1522   show "inj_on (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2)) (QUOT (L\<^isub>1 \<union> L\<^isub>2))"
  1604     apply (rule_tac str_inj_imps)
  1523     apply (rule_tac str_inj_imps)
  1605     by (erule_tac tag_str_alt_inj)
  1524     by (erule_tac tag_str_alt_inj)
  1606   ultimately 
  1525 qed
  1607   show "finite (QUOT (L\<^isub>1 \<union> L\<^isub>2))" by (rule finite_imageD)
       
  1608 qed
       
  1609 
       
  1610 
       
  1611 (*by cu *)
       
  1612 
       
  1613 
       
  1614 definition
       
  1615   str_eq ("_ \<approx>_ _")
       
  1616 where
       
  1617   "x \<approx>Lang y \<equiv> (\<forall>z. x @ z \<in> Lang \<longleftrightarrow> y @ z \<in> Lang)"
       
  1618 
       
  1619 definition
       
  1620   str_eq_rel ("\<approx>_")
       
  1621 where
       
  1622   "\<approx>Lang \<equiv> {(x, y). x \<approx>Lang y}"
       
  1623 
       
  1624 lemma [simp]:
       
  1625   "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y"
       
  1626 by simp
       
  1627 
       
  1628 lemma inj_image_lang:
       
  1629   fixes f::"string \<Rightarrow> 'a"
       
  1630   assumes str_inj: "\<And>x y. f x = f y \<Longrightarrow> x \<approx>Lang y"
       
  1631   shows "inj_on (image f) (UNIV // (\<approx>Lang))"
       
  1632 proof - 
       
  1633   { fix x y::string
       
  1634     assume eq_tag: "f ` {z. x \<approx>Lang z} = f ` {z. y \<approx>Lang z}"
       
  1635     moreover
       
  1636     have "{z. x \<approx>Lang z} \<noteq> {}" unfolding str_eq_def by auto
       
  1637     ultimately obtain a b where "x \<approx>Lang a" "y \<approx>Lang b" "f a = f b" by blast
       
  1638     then have "x \<approx>Lang a" "y \<approx>Lang b" "a \<approx>Lang b" using str_inj by auto
       
  1639     then have "x \<approx>Lang y" unfolding str_eq_def by simp 
       
  1640     then have "{z. x \<approx>Lang z} = {z. y \<approx>Lang z}" unfolding str_eq_def by simp
       
  1641   }
       
  1642   then have "\<forall>x\<in>UNIV // \<approx>Lang. \<forall>y\<in>UNIV // \<approx>Lang. f ` x = f ` y \<longrightarrow> x = y"
       
  1643     unfolding quotient_def Image_def str_eq_rel_def by simp
       
  1644   then show "inj_on (image f) (UNIV // (\<approx>Lang))"
       
  1645     unfolding inj_on_def by simp
       
  1646 qed
       
  1647 
       
  1648 
       
  1649 lemma finite_range_image: 
       
  1650   assumes fin: "finite (range f)"
       
  1651   shows "finite ((image f) ` X)"
       
  1652 proof -
       
  1653   from fin have "finite (Pow (f ` UNIV))" by auto
       
  1654   moreover
       
  1655   have "(image f) ` X \<subseteq> Pow (f ` UNIV)" by auto
       
  1656   ultimately show "finite ((image f) ` X)" using finite_subset by auto
       
  1657 qed
       
  1658 
       
  1659 definition 
       
  1660   tag1 :: "string set \<Rightarrow> string set \<Rightarrow> string \<Rightarrow> (string set \<times> string set)"
       
  1661 where
       
  1662   "tag1 L\<^isub>1 L\<^isub>2 \<equiv> \<lambda>x. ((\<approx>L\<^isub>1) `` {x}, (\<approx>L\<^isub>2) `` {x})"
       
  1663 
       
  1664 lemma tag1_range_finite:
       
  1665   assumes finite1: "finite (UNIV // \<approx>L\<^isub>1)"
       
  1666   and finite2: "finite (UNIV // \<approx>L\<^isub>2)"
       
  1667   shows "finite (range (tag1 L\<^isub>1 L\<^isub>2))"
       
  1668 proof -
       
  1669   have "finite (UNIV // \<approx>L\<^isub>1 \<times> UNIV // \<approx>L\<^isub>2)" using finite1 finite2 by auto
       
  1670   moreover
       
  1671   have "range (tag1 L\<^isub>1 L\<^isub>2) \<subseteq> (UNIV // \<approx>L\<^isub>1) \<times> (UNIV // \<approx>L\<^isub>2)"
       
  1672     unfolding tag1_def quotient_def by auto
       
  1673   ultimately show "finite (range (tag1 L\<^isub>1 L\<^isub>2))" 
       
  1674     using finite_subset by blast
       
  1675 qed
       
  1676 
       
  1677 lemma tag1_inj:
       
  1678   "tag1 L\<^isub>1 L\<^isub>2 x = tag1 L\<^isub>1 L\<^isub>2 y \<Longrightarrow> x \<approx>(L\<^isub>1 \<union> L\<^isub>2) y"
       
  1679 unfolding tag1_def Image_def str_eq_rel_def str_eq_def
       
  1680 by auto
       
  1681 
       
  1682 lemma quot_alt_cu:
       
  1683   fixes L\<^isub>1 L\<^isub>2::"string set"
       
  1684   assumes fin1: "finite (UNIV // \<approx>L\<^isub>1)"
       
  1685   and fin2: "finite (UNIV // \<approx>L\<^isub>2)"
       
  1686   shows "finite (UNIV // \<approx>(L\<^isub>1 \<union> L\<^isub>2))"
       
  1687 proof -
       
  1688   have "finite (range (tag1 L\<^isub>1 L\<^isub>2))" 
       
  1689     using fin1 fin2 tag1_range_finite by simp
       
  1690   then have "finite (image (tag1 L\<^isub>1 L\<^isub>2) ` (UNIV // \<approx>(L\<^isub>1 \<union> L\<^isub>2)))" 
       
  1691     using finite_range_image by blast
       
  1692   moreover 
       
  1693   have "\<And>x y. tag1 L\<^isub>1 L\<^isub>2 x = tag1 L\<^isub>1 L\<^isub>2 y \<Longrightarrow> x \<approx>(L\<^isub>1 \<union> L\<^isub>2) y" 
       
  1694     using tag1_inj by simp
       
  1695   then have "inj_on (image (tag1 L\<^isub>1 L\<^isub>2)) (UNIV // \<approx>(L\<^isub>1 \<union> L\<^isub>2))" 
       
  1696     using inj_image_lang by blast
       
  1697   ultimately 
       
  1698   show "finite (UNIV // \<approx>(L\<^isub>1 \<union> L\<^isub>2))" by (rule finite_imageD)
       
  1699 qed
       
  1700 
       
  1701 (* by chunhan *)
       
  1702 
  1526 
  1703 (* list_diff:: list substract, once different return tailer *)
  1527 (* list_diff:: list substract, once different return tailer *)
  1704 fun list_diff :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" (infix "-" 51)
  1528 fun list_diff :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" (infix "-" 51)
  1705 where
  1529 where
  1706   "list_diff []  xs = []" |
  1530   "list_diff []  xs = []" |
  1707   "list_diff (x#xs) [] = x#xs" |
  1531   "list_diff (x#xs) [] = x#xs" |
  1708   "list_diff (x#xs) (y#ys) = (if x = y then list_diff xs ys else (x#xs))"
  1532   "list_diff (x#xs) (y#ys) = (if x = y then list_diff xs ys else (x#xs))"
  1709 
  1533 
  1710 definition tag_str_SEQ:: "string set \<Rightarrow> string set \<Rightarrow> string \<Rightarrow> (string set) set"
  1534 lemma [simp]: "(x @ y) - x = y"
  1711 where
  1535 apply (induct x)
  1712   "tag_str_SEQ L\<^isub>1 L\<^isub>2 x \<equiv> if (\<exists> y. y \<le> x \<and> y \<in> L\<^isub>1)
  1536 by (case_tac y, simp+)
  1713                          then {(\<lbrakk>(x - y)\<rbrakk>L\<^isub>2) | y.  y \<le> x \<and> y \<in> L\<^isub>1}
  1537 
  1714                          else { \<lbrakk>x\<rbrakk>L\<^isub>1 }"
  1538 lemma [simp]: "x - x = []"
       
  1539 by (induct x, auto)
       
  1540 
       
  1541 lemma [simp]: "x = xa @ y \<Longrightarrow> x - xa = y "
       
  1542 by (induct x, auto)
       
  1543 
       
  1544 lemma [simp]: "x - [] = x"
       
  1545 by (induct x, auto)
       
  1546 
       
  1547 lemma [simp]: "xa \<le> x \<Longrightarrow> (x @ y) - xa = (x - xa) @ y"
       
  1548 by (auto elim:prefixE)
       
  1549 
       
  1550 definition tag_str_SEQ:: "string set \<Rightarrow> string set \<Rightarrow> string \<Rightarrow> (string set \<times> string set set)"
       
  1551 where
       
  1552   "tag_str_SEQ L\<^isub>1 L\<^isub>2 x \<equiv> if (\<exists> xa \<le> x. xa \<in> L\<^isub>1)
       
  1553                          then (\<lbrakk>x\<rbrakk>L\<^isub>1, {\<lbrakk>(x - xa)\<rbrakk>L\<^isub>2 | xa.  xa \<le> x \<and> xa \<in> L\<^isub>1})
       
  1554                          else (\<lbrakk>x\<rbrakk>L\<^isub>1, {})"
       
  1555 
       
  1556 lemma tag_seq_eq_E:
       
  1557   "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y \<Longrightarrow>
       
  1558    ((\<exists> xa \<le> x. xa \<in> L\<^isub>1) \<and> \<lbrakk>x\<rbrakk>L\<^isub>1 = \<lbrakk>y\<rbrakk>L\<^isub>1 \<and> 
       
  1559     {\<lbrakk>(x - xa)\<rbrakk>L\<^isub>2 | xa. xa \<le> x \<and> xa \<in> L\<^isub>1} = {\<lbrakk>(y - ya)\<rbrakk>L\<^isub>2 | ya. ya \<le> y \<and> ya \<in> L\<^isub>1} ) \<or>
       
  1560    ((\<forall> xa \<le> x. xa \<notin> L\<^isub>1) \<and> \<lbrakk>x\<rbrakk>L\<^isub>1 = \<lbrakk>y\<rbrakk>L\<^isub>1)"
       
  1561 by (simp add:tag_str_SEQ_def split:if_splits, blast)
  1715 
  1562 
  1716 lemma tag_str_seq_range_finite:
  1563 lemma tag_str_seq_range_finite:
  1717   assumes finite1: "finite (QUOT L\<^isub>1)"
  1564   assumes finite1: "finite (QUOT L\<^isub>1)"
  1718   and finite2: "finite (QUOT L\<^isub>2)"
  1565   and finite2: "finite (QUOT L\<^isub>2)"
  1719   shows "finite (range (tag_str_SEQ L\<^isub>1 L\<^isub>2))"
  1566   shows "finite (range (tag_str_SEQ L\<^isub>1 L\<^isub>2))"
  1720 proof -
  1567 proof -
  1721   have "(range (tag_str_SEQ L\<^isub>1 L\<^isub>2)) \<subseteq> Pow ((QUOT L\<^isub>1) \<union> (QUOT L\<^isub>2))"
  1568   have "(range (tag_str_SEQ L\<^isub>1 L\<^isub>2)) \<subseteq> (QUOT L\<^isub>1) \<times> (Pow (QUOT L\<^isub>2))"
  1722     by (auto simp:image_def tag_str_SEQ_def QUOT_def)
  1569     by (auto simp:image_def tag_str_SEQ_def QUOT_def)
  1723   thus ?thesis using finite1 finite2 
  1570   thus ?thesis using finite1 finite2 
  1724     by (rule_tac B = "Pow ((QUOT L\<^isub>1) \<union> (QUOT L\<^isub>2))" in finite_subset, auto)
  1571     by (rule_tac B = "(QUOT L\<^isub>1) \<times> (Pow (QUOT L\<^isub>2))" in finite_subset, auto)
  1725 qed
  1572 qed
  1726   
  1573   
       
  1574 lemma app_in_seq_decom[rule_format]:
       
  1575   "\<forall> x. x @ z \<in> L\<^isub>1 ; L\<^isub>2 \<longrightarrow> (\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ z \<in> L\<^isub>2) \<or> 
       
  1576                             (\<exists> za \<le> z. (x @ za) \<in> L\<^isub>1 \<and> (z - za) \<in> L\<^isub>2)"
       
  1577 apply (induct z)
       
  1578 apply (simp, rule allI, rule impI, rule disjI1)
       
  1579 apply (clarsimp simp add:lang_seq_def)
       
  1580 apply (rule_tac x = s1 in exI, simp)
       
  1581 apply (rule allI | rule impI)+
       
  1582 apply (drule_tac x = "x @ [a]" in spec, simp)
       
  1583 apply (erule exE | erule conjE | erule disjE)+
       
  1584 apply (rule disjI2, rule_tac x = "[a]" in exI, simp)
       
  1585 apply (rule disjI1, rule_tac x = xa in exI, simp) 
       
  1586 apply (erule exE | erule conjE)+
       
  1587 apply (rule disjI2, rule_tac x = "a # za" in exI, simp)
       
  1588 done
       
  1589 
  1727 lemma tag_str_seq_inj:
  1590 lemma tag_str_seq_inj:
  1728   assumes tag_eq: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
  1591   assumes tag_eq: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
  1729   shows "(x::string) \<equiv>(L\<^isub>1 ; L\<^isub>2)\<equiv> y"
  1592   shows "(x::string) \<equiv>(L\<^isub>1 ; L\<^isub>2)\<equiv> y"
  1730 proof (cases "\<exists> xa. xa \<le> x \<and> xa \<in> L\<^isub>1")
  1593 proof -
  1731   have equiv_str_sym: "\<And> x y lang. (x::string) \<equiv>lang\<equiv> y \<Longrightarrow> y \<equiv>lang\<equiv> x"
  1594   have aux: "\<And> x y z. \<lbrakk>tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y; x @ z \<in> L\<^isub>1 ; L\<^isub>2\<rbrakk> 
  1732     by (auto simp:equiv_str_def)
  1595                        \<Longrightarrow> y @ z \<in> L\<^isub>1 ; L\<^isub>2"
  1733   have set_equ_D: "\<And> A a B b. \<lbrakk>A = B; A \<noteq> {}\<rbrakk> \<Longrightarrow> \<exists> a b. a \<in> A \<and> b \<in> B \<and> a = b " by auto
  1596   proof (drule app_in_seq_decom, erule disjE)
  1734   have eqset_equ_D: "\<And> x y lang. {y. x \<equiv>lang\<equiv> y} = {ya. y \<equiv>lang\<equiv> ya} \<Longrightarrow> x \<equiv>lang\<equiv> y"
  1597     fix x y z
  1735     by (drule set_equ_D, auto simp:equiv_str_def)
  1598     assume tag_eq: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
  1736   assume  x_left_l1: "\<exists>xa\<le>x. xa \<in> L\<^isub>1"
  1599       and x_gets_l2: "\<exists>xa\<le>x. xa \<in> L\<^isub>1 \<and> (x - xa) @ z \<in> L\<^isub>2"
  1737   show "x \<equiv>L\<^isub>1 ; L\<^isub>2\<equiv> y"
  1600     from x_gets_l2 have "\<exists> xa \<le> x. xa \<in> L\<^isub>1" by blast
  1738   proof (cases "\<exists> ya. ya \<le> y \<and> ya \<in> L\<^isub>1")
  1601     hence xy_l2:"{\<lbrakk>(x - xa)\<rbrakk>L\<^isub>2 | xa. xa \<le> x \<and> xa \<in> L\<^isub>1} = {\<lbrakk>(y - ya)\<rbrakk>L\<^isub>2 | ya. ya \<le> y \<and> ya \<in> L\<^isub>1}"
  1739     assume y_left_l1: "\<exists>ya\<le>y. ya \<in> L\<^isub>1"
  1602       using tag_eq tag_seq_eq_E by blast
  1740     with tag_eq x_left_l1
  1603     from x_gets_l2 obtain xa where xa_le_x: "xa \<le> x"
  1741     show "x \<equiv>L\<^isub>1 ; L\<^isub>2\<equiv> y"
  1604                                and xa_in_l1: "xa \<in> L\<^isub>1"
  1742       apply (simp add:tag_str_SEQ_def)
  1605                                and rest_in_l2: "(x - xa) @ z \<in> L\<^isub>2" by blast
  1743       apply (drule set_equ_D)
  1606     hence "\<exists> ya. \<lbrakk>(x - xa)\<rbrakk>L\<^isub>2 = \<lbrakk>(y - ya)\<rbrakk>L\<^isub>2 \<and> ya \<le> y \<and> ya \<in> L\<^isub>1" using xy_l2 by auto
  1744       apply (auto simp:equiv_class_def equiv_str_def)[1]
  1607     then obtain ya where ya_le_x: "ya \<le> y"
  1745       apply (clarsimp simp:equiv_str_def)
  1608                      and ya_in_l1: "ya \<in> L\<^isub>1"
  1746       apply (rule iffI)
  1609                      and rest_eq: "\<lbrakk>(x - xa)\<rbrakk>L\<^isub>2 = \<lbrakk>(y - ya)\<rbrakk>L\<^isub>2" by blast
  1747       apply  
  1610     from rest_eq rest_in_l2 have "(y - ya) @ z \<in> L\<^isub>2" 
  1748       apply (
  1611       by (auto simp:equiv_class_def equiv_str_def)
       
  1612     hence "ya @ ((y - ya) @ z) \<in> L\<^isub>1 ; L\<^isub>2" using ya_in_l1
       
  1613       by (auto simp:lang_seq_def)
       
  1614     thus "y @ z \<in> L\<^isub>1 ; L\<^isub>2" using ya_le_x 
       
  1615       by (erule_tac prefixE, simp)
  1749   next
  1616   next
  1750     assume y_in_l1: "\<not> (\<exists>ya\<le>y. ya \<in> L\<^isub>1)"
  1617     fix x y z
  1751     show "x \<equiv>L\<^isub>1 ; L\<^isub>2\<equiv> y"
  1618     assume tag_eq: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
  1752       sorry
  1619       and x_gets_l1: "\<exists>za\<le>z. x @ za \<in> L\<^isub>1 \<and> z - za \<in> L\<^isub>2"
       
  1620     from tag_eq tag_seq_eq_E have x_y_eq: "\<lbrakk>x\<rbrakk>L\<^isub>1 = \<lbrakk>y\<rbrakk>L\<^isub>1" by blast
       
  1621     from x_gets_l1 obtain za where za_le_z: "za \<le> z"
       
  1622                                and x_za_in_l1: "(x @ za) \<in> L\<^isub>1"
       
  1623                                and rest_in_l2: "z - za \<in> L\<^isub>2" by blast
       
  1624     from x_y_eq x_za_in_l1 have y_za_in_l1: "y @ za \<in> L\<^isub>1"
       
  1625       by (auto simp:equiv_class_def equiv_str_def)
       
  1626     hence "(y @ za) @ (z - za) \<in> L\<^isub>1 ; L\<^isub>2" using rest_in_l2
       
  1627       apply (simp add:lang_seq_def)
       
  1628       by (rule_tac x = "y @ za" in exI, rule_tac x = "z - za" in exI, simp)
       
  1629     thus "y @ z \<in> L\<^isub>1 ; L\<^isub>2" using za_le_z
       
  1630       by (erule_tac prefixE, simp)
  1753   qed
  1631   qed
  1754 next
  1632   show ?thesis using tag_eq
  1755   assume x_in_l1: "\<not> (\<exists>xa\<le>x. xa \<in> L\<^isub>1)"
  1633     apply (simp add:equiv_str_def)
  1756   show "x \<equiv>L\<^isub>1 ; L\<^isub>2\<equiv> y"
  1634     by (auto intro:aux)
  1757   proof (cases "\<exists> ya. ya \<le> y \<and> ya \<in> L\<^isub>1")
  1635 qed
  1758     assume y_left_l1: "\<exists>ya\<le>y. ya \<in> L\<^isub>1"
       
  1759     show "x \<equiv>L\<^isub>1 ; L\<^isub>2\<equiv> y"
       
  1760       sorry
       
  1761   next
       
  1762     assume y_in_l1: "\<not> (\<exists>ya\<le>y. ya \<in> L\<^isub>1)"
       
  1763     with tag_eq x_in_l1
       
  1764     have "\<lbrakk>x\<rbrakk>(L\<^isub>1;L\<^isub>2) = \<lbrakk>y\<rbrakk>(L\<^isub>1;L\<^isub>2)"
       
  1765       sorry
       
  1766     thus "x \<equiv>L\<^isub>1 ; L\<^isub>2\<equiv> y"
       
  1767       by (auto simp:equiv_class_def equiv_str_def)
       
  1768   qed
       
  1769 qed
       
  1770   
       
  1771 apply (simp add:tag_str_SEQ_def split:if_splits)
       
  1772 prefer 4
       
  1773 apply (clarsimp simp add:equiv_str_def)
       
  1774 apply (rule iffI)
       
  1775 apply (simp add:lang_seq_def equiv_class_def equiv_str_def)
       
  1776 apply blast
       
  1777 apply (
       
  1778 sorry
       
  1779 
       
  1780 
  1636 
  1781 lemma quot_seq: 
  1637 lemma quot_seq: 
  1782   assumes finite1: "finite (QUOT L\<^isub>1)"
  1638   assumes finite1: "finite (QUOT L\<^isub>1)"
  1783   and finite2: "finite (QUOT L\<^isub>2)"
  1639   and finite2: "finite (QUOT L\<^isub>2)"
  1784   shows "finite (QUOT (L\<^isub>1;L\<^isub>2))"
  1640   shows "finite (QUOT (L\<^isub>1;L\<^isub>2))"
  1790   show "inj_on (op ` (tag_str_SEQ L\<^isub>1 L\<^isub>2)) (QUOT (L\<^isub>1 ; L\<^isub>2))"
  1646   show "inj_on (op ` (tag_str_SEQ L\<^isub>1 L\<^isub>2)) (QUOT (L\<^isub>1 ; L\<^isub>2))"
  1791     apply (rule_tac str_inj_imps)
  1647     apply (rule_tac str_inj_imps)
  1792     by (erule_tac tag_str_seq_inj)
  1648     by (erule_tac tag_str_seq_inj)
  1793 qed
  1649 qed
  1794 
  1650 
  1795 definition tag_str_STAR:: "string set \<Rightarrow> string \<Rightarrow> (string set) set"
  1651 (****************** the STAR case ************************)
  1796 where
  1652 
  1797   "tag_str_STAR L\<^isub>1 x = {\<lbrakk>y\<rbrakk>L\<^isub>1 | y. y \<le> x}"
  1653 lemma app_eq_elim[rule_format]:
       
  1654   "\<And> a. \<forall> b x y. a @ b = x @ y \<longrightarrow> (\<exists> aa ab. a = aa @ ab \<and> x = aa \<and> y = ab @ b) \<or>
       
  1655                                    (\<exists> ba bb. b = ba @ bb \<and> x = a @ ba \<and> y = bb \<and> ba \<noteq> [])"
       
  1656   apply (induct_tac a rule:List.induct, simp)
       
  1657   apply (rule allI | rule impI)+
       
  1658   by (case_tac x, auto)
       
  1659 
       
  1660 definition tag_str_STAR:: "string set \<Rightarrow> string \<Rightarrow> string set set"
       
  1661 where
       
  1662   "tag_str_STAR L\<^isub>1 x \<equiv> if (x = []) 
       
  1663                        then {}
       
  1664                        else {\<lbrakk>x\<^isub>2\<rbrakk>L\<^isub>1 | x\<^isub>1 x\<^isub>2. x =  x\<^isub>1 @ x\<^isub>2 \<and> x\<^isub>1 \<in> L\<^isub>1\<star> \<and> x\<^isub>2 \<noteq> []}"
  1798 
  1665 
  1799 lemma tag_str_star_range_finite:
  1666 lemma tag_str_star_range_finite:
  1800   assumes finite1: "finite (QUOT L\<^isub>1)"
  1667   assumes finite1: "finite (QUOT L\<^isub>1)"
  1801   shows "finite (range (tag_str_STAR L\<^isub>1))"
  1668   shows "finite (range (tag_str_STAR L\<^isub>1))"
  1802 proof -
  1669 proof -
  1804     by (auto simp:image_def tag_str_STAR_def QUOT_def)
  1671     by (auto simp:image_def tag_str_STAR_def QUOT_def)
  1805   thus ?thesis using finite1
  1672   thus ?thesis using finite1
  1806     by (rule_tac B = "Pow (QUOT L\<^isub>1)" in finite_subset, auto)
  1673     by (rule_tac B = "Pow (QUOT L\<^isub>1)" in finite_subset, auto)
  1807 qed
  1674 qed
  1808 
  1675 
       
  1676 lemma star_prop[rule_format]: "x \<in> lang\<star> \<Longrightarrow> \<forall> y. y \<in> lang\<star> \<longrightarrow> x @ y \<in> lang\<star>"
       
  1677 by (erule Star.induct, auto)
       
  1678 
       
  1679 lemma star_prop2: "y \<in> lang \<Longrightarrow> y \<in> lang\<star>"
       
  1680 by (drule step[of y lang "[]"], auto simp:start)
       
  1681 
       
  1682 lemma star_prop3[rule_format]: "x \<in> lang\<star> \<Longrightarrow> \<forall>y . y \<in> lang \<longrightarrow> x @ y \<in> lang\<star>"
       
  1683 by (erule Star.induct, auto intro:star_prop2)
       
  1684 
       
  1685 lemma postfix_prop: "y >>= (x @ y) \<Longrightarrow> x = []"
       
  1686 by (erule postfixE, induct x arbitrary:y, auto)
       
  1687 
       
  1688 lemma inj_aux:
       
  1689   "\<lbrakk>(m @ z) \<in> L\<^isub>1\<star>; m \<equiv>L\<^isub>1\<equiv> yb; xa @ m = x; xa \<in> L\<^isub>1\<star>; m \<noteq> [];
       
  1690     \<forall> xa xb. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star> \<longrightarrow> xb >>= m\<rbrakk> 
       
  1691   \<Longrightarrow> (yb @ z) \<in> L\<^isub>1\<star>"
       
  1692 proof- 
       
  1693   have "\<And>s. s \<in> L\<^isub>1\<star> \<Longrightarrow> \<forall> m z yb. (s = m @ z \<and> m \<equiv>L\<^isub>1\<equiv> yb \<and> x = xa @ m \<and> xa \<in> L\<^isub>1\<star> \<and> m \<noteq> [] \<and>  
       
  1694     (\<forall> xa xb. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star> \<longrightarrow> xb >>= m) \<longrightarrow> (yb @ z) \<in> L\<^isub>1\<star>)"    
       
  1695     apply (erule Star.induct, simp)
       
  1696     apply (rule allI | rule impI | erule conjE)+
       
  1697     apply (drule app_eq_elim)
       
  1698     apply (erule disjE | erule exE | erule conjE)+
       
  1699     apply simp
       
  1700     apply (simp (no_asm) only:append_assoc[THEN sym])
       
  1701     apply (rule step) 
       
  1702     apply (simp add:equiv_str_def)
       
  1703     apply simp
       
  1704 
       
  1705     apply (erule exE | erule conjE)+    
       
  1706     apply (rotate_tac 3)
       
  1707     apply (frule_tac x = "xa @ s1" in spec)
       
  1708     apply (rotate_tac 12)
       
  1709     apply (drule_tac x = ba in spec)
       
  1710     apply (erule impE)
       
  1711     apply ( simp add:star_prop3)
       
  1712     apply (simp)
       
  1713     apply (drule postfix_prop)
       
  1714     apply simp
       
  1715     done
       
  1716   thus "\<lbrakk>(m @ z) \<in> L\<^isub>1\<star>; m \<equiv>L\<^isub>1\<equiv> yb; xa @ m = x; xa \<in> L\<^isub>1\<star>; m \<noteq> [];
       
  1717          \<forall> xa xb. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star> \<longrightarrow> xb >>= m\<rbrakk> 
       
  1718         \<Longrightarrow> (yb @ z) \<in> L\<^isub>1\<star>" by blast
       
  1719 qed
       
  1720 
       
  1721 
       
  1722 lemma min_postfix_exists[rule_format]:
       
  1723   "finite A \<Longrightarrow> A \<noteq> {} \<and> (\<forall> a \<in> A. \<forall> b \<in> A. ((b >>= a) \<or> (a >>= b))) 
       
  1724                 \<longrightarrow> (\<exists> min. (min \<in> A \<and> (\<forall> a \<in> A. a >>= min)))"
       
  1725 apply (erule finite.induct)
       
  1726 apply simp
       
  1727 apply simp
       
  1728 apply (case_tac "A = {}")
       
  1729 apply simp
       
  1730 apply clarsimp
       
  1731 apply (case_tac "a >>= min")
       
  1732 apply (rule_tac x = min in exI, simp)
       
  1733 apply (rule_tac x = a in exI, simp)
       
  1734 apply clarify
       
  1735 apply (rotate_tac 5)
       
  1736 apply (erule_tac x = aa in ballE) defer apply simp
       
  1737 apply (erule_tac ys = min in postfix_trans)
       
  1738 apply (erule_tac x = min in ballE) 
       
  1739 by simp+
       
  1740 
  1809 lemma tag_str_star_inj:
  1741 lemma tag_str_star_inj:
  1810   "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 (y::string) \<Longrightarrow> x \<equiv>L\<^isub>1\<star>\<equiv> y"
  1742   "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 (y::string) \<Longrightarrow> x \<equiv>L\<^isub>1\<star>\<equiv> y"
  1811 proof -
  1743 proof -
  1812   have "\<forall> x lang. (x = []) = (tag_str_STAR lang x = {\<lbrakk>[]\<rbrakk>lang})"
  1744   have aux: "\<And> x y z. \<lbrakk>tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y; x @ z \<in> L\<^isub>1\<star>\<rbrakk> \<Longrightarrow> y @ z \<in> L\<^isub>1\<star>"
  1813   proof (rule_tac allI, rule_tac allI, rule_tac iffI)
  1745   proof-
  1814     fix x lang
  1746     fix x y z
  1815     show "x = [] \<Longrightarrow> tag_str_STAR lang x = {\<lbrakk>[]\<rbrakk>lang}" 
  1747     assume tag_eq: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y"
  1816       by (simp add:tag_str_STAR_def)
  1748       and x_z: "x @ z \<in> L\<^isub>1\<star>"
  1817   next    
  1749     show "y @ z \<in> L\<^isub>1\<star>"
  1818     fix x lang
  1750     proof (cases "x = []")
  1819     show "tag_str_STAR lang x = {\<lbrakk>[]\<rbrakk>lang} \<Longrightarrow> x = []"
  1751       case True
  1820       apply (simp add:tag_str_STAR_def)
  1752       with tag_eq have "y = []" by (simp add:tag_str_STAR_def split:if_splits, blast)
  1821       apply (drule equalityD1)
  1753       thus ?thesis using x_z True by simp
  1822       apply (case_tac x)
  1754     next
  1823       apply simp
  1755       case False
  1824       thm in_mono
  1756       hence not_empty: "{xb. \<exists> xa. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star>} \<noteq> {}" using x_z
  1825       apply (drule_tac x = "\<lbrakk>[a]\<rbrakk>lang" in in_mono)
  1757         by (simp, rule_tac x = x in exI, rule_tac x = "[]" in exI, simp add:start)
  1826       apply simp
  1758       have finite_set: "finite {xb. \<exists> xa. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star>}"
  1827       apply auto
  1759         apply (rule_tac B = "{xb. \<exists> xa. x = xa @ xb}" in finite_subset)
  1828       
  1760         apply auto
  1829       apply (erule subsetCE)
  1761         apply (induct x, simp)
  1830       
  1762         apply (subgoal_tac "{xb. \<exists>xa. a # x = xa @ xb} = insert (a # x) {xb. \<exists>xa. x = xa @ xb}")
  1831       apply (case_tac y)
  1763         apply auto
  1832       
  1764         by (case_tac xaa, simp+)
  1833       sorry
  1765       have comparable: "\<forall> a \<in> {xb. \<exists> xa. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star>}. 
  1834   next
  1766                         \<forall> b \<in> {xb. \<exists> xa. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star>}.
       
  1767                           ((b >>= a) \<or> (a >>= b))"
       
  1768         by (auto simp:postfix_def, drule app_eq_elim, blast)
       
  1769       hence "\<exists> min. min \<in> {xb. \<exists> xa. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star>} 
       
  1770                 \<and> (\<forall> xa xb. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star> \<longrightarrow> xb >>= min)"
       
  1771         using finite_set not_empty comparable
       
  1772         apply (drule_tac min_postfix_exists, simp)
       
  1773         by (erule exE, rule_tac x = min in exI, auto)
       
  1774       then obtain min xa where x_decom: "x = xa @ min \<and> xa \<in> L\<^isub>1\<star>"
       
  1775         and min_not_empty: "min \<noteq> []"
       
  1776         and min_z_in_star: "min @ z \<in> L\<^isub>1\<star>"
       
  1777         and is_min: "\<forall> xa xb. x = xa @ xb \<and> xa \<in> L\<^isub>1\<star> \<and> xb \<noteq> [] \<and> xb @ z \<in> L\<^isub>1\<star> \<longrightarrow> xb >>= min"  by blast
       
  1778       from x_decom min_not_empty have "\<lbrakk>min\<rbrakk>L\<^isub>1 \<in> tag_str_STAR L\<^isub>1 x"  by (auto simp:tag_str_STAR_def)
       
  1779       hence "\<exists> yb. \<lbrakk>yb\<rbrakk>L\<^isub>1 \<in> tag_str_STAR L\<^isub>1 y \<and> \<lbrakk>min\<rbrakk>L\<^isub>1 = \<lbrakk>yb\<rbrakk>L\<^isub>1" using tag_eq by auto
       
  1780       hence "\<exists> ya yb. y = ya @ yb \<and> ya \<in> L\<^isub>1\<star> \<and> min \<equiv>L\<^isub>1\<equiv> yb \<and> yb \<noteq> [] " 
       
  1781         by (simp add:tag_str_STAR_def equiv_class_def equiv_str_def split:if_splits, blast)        
       
  1782       then obtain ya yb where y_decom: "y = ya @ yb"
       
  1783                           and ya_in_star: "ya \<in> L\<^isub>1\<star>"
       
  1784                           and yb_not_empty: "yb \<noteq> []"
       
  1785                           and min_yb_eq: "min \<equiv>L\<^isub>1\<equiv> yb"  by blast
       
  1786       from min_z_in_star min_yb_eq min_not_empty is_min x_decom
       
  1787       have "yb @ z \<in> L\<^isub>1\<star>"
       
  1788         by (rule_tac x = x and xa = xa in inj_aux, simp+)
       
  1789       thus ?thesis using ya_in_star y_decom
       
  1790         by (auto dest:star_prop)        
       
  1791     qed
  1835   qed
  1792   qed
  1836     apply (simp add:tag_str_STAR_def equiv_class_def equiv_str_def)
  1793   show "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 (y::string) \<Longrightarrow> x \<equiv>L\<^isub>1\<star>\<equiv> y"
  1837     apply (rule iffI)
  1794     by (auto intro:aux simp:equiv_str_def)
  1838     
  1795 qed
  1839     apply (auto simp:tag_str_STAR_def equiv_class_def equiv_str_def)
       
  1840   have "\<And> x y z xstr. xstr \<in> L\<^isub>1\<star> \<Longrightarrow> 
       
  1841                       xstr = x @ z \<and> tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y \<longrightarrow> y @ z \<in> L\<^isub>1\<star> "
       
  1842   proof (erule Star.induct)
       
  1843     fix x y z xstr
       
  1844     show "[] = x @ z \<and> tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y \<longrightarrow> y @ z \<in> L\<^isub>1\<star>"
       
  1845     apply (clarsimp simp add:tag_str_STAR_def equiv_str_def equiv_class_def)
       
  1846     apply (blast)
       
  1847 apply (simp add:tag_str_STAR_def equiv_class_def QUOT_def)
       
  1848 apply (simp add:equiv_str_def)
       
  1849 apply (rule allI, rule_tac iffI)
       
  1850 apply (erule_tac star.induct)
       
  1851 apply blast
       
  1852 
       
  1853 sorry
       
  1854 
       
  1855 
  1796 
  1856 lemma quot_star:  
  1797 lemma quot_star:  
  1857   assumes finite1: "finite (QUOT L\<^isub>1)"
  1798   assumes finite1: "finite (QUOT L\<^isub>1)"
  1858   shows "finite (QUOT (L\<^isub>1\<star>))"
  1799   shows "finite (QUOT (L\<^isub>1\<star>))"
  1859 proof (rule_tac f = "(op `) (tag_str_STAR L\<^isub>1)" in finite_imageD)
  1800 proof (rule_tac f = "(op `) (tag_str_STAR L\<^isub>1)" in finite_imageD)
  1870   "Lang = L (r::rexp) \<Longrightarrow> finite (QUOT Lang)"
  1811   "Lang = L (r::rexp) \<Longrightarrow> finite (QUOT Lang)"
  1871 apply (induct arbitrary:Lang rule:rexp.induct)
  1812 apply (induct arbitrary:Lang rule:rexp.induct)
  1872 apply (simp add:QUOT_def equiv_class_def equiv_str_def)
  1813 apply (simp add:QUOT_def equiv_class_def equiv_str_def)
  1873 by (simp_all add:quot_lambda quot_single quot_seq quot_alt quot_star)  
  1814 by (simp_all add:quot_lambda quot_single quot_seq quot_alt quot_star)  
  1874 
  1815 
  1875 
  1816 end 
  1876 
       
  1877 
       
  1878 end