|    758 text {* |    781 text {* | 
|    759   From this point until @{text "iteration_step"},  |    782   From this point until @{text "iteration_step"},  | 
|    760   the correctness of the iteration step @{text "iter X ES"} is proved. |    783   the correctness of the iteration step @{text "iter X ES"} is proved. | 
|    761 *} |    784 *} | 
|    762  |    785  | 
|    763 lemma arden_op_keeps_eq: |    786 lemma Arden_keeps_eq: | 
|    764   assumes l_eq_r: "X = L rhs" |    787   assumes l_eq_r: "X = L rhs" | 
|    765   and not_empty: "[] \<notin> L (\<Uplus>{r. Trn X r \<in> rhs})" |    788   and not_empty: "[] \<notin> L (\<Uplus>{r. Trn X r \<in> rhs})" | 
|    766   and finite: "finite rhs" |    789   and finite: "finite rhs" | 
|    767   shows "X = L (arden_op X rhs)" |    790   shows "X = L (Arden X rhs)" | 
|    768 proof - |    791 proof - | 
|    769   def A \<equiv> "L (\<Uplus>{r. Trn X r \<in> rhs})" |    792   def A \<equiv> "L (\<Uplus>{r. Trn X r \<in> rhs})" | 
|    770   def b \<equiv> "rhs - trns_of rhs X" |    793   def b \<equiv> "rhs - {Trn X r | r. Trn X r \<in> rhs}" | 
|    771   def B \<equiv> "L b"  |    794   def B \<equiv> "L b"  | 
|    772   have "X = B ;; A\<star>" |    795   have "X = B ;; A\<star>" | 
|    773   proof- |    796   proof- | 
|    774     have "L rhs = L(trns_of rhs X \<union> b)" by (auto simp: b_def trns_of_def) |    797     have "L rhs = L({Trn X r | r. Trn X r \<in> rhs} \<union> b)" by (auto simp: b_def) | 
|    775     also have "\<dots> = X ;; A \<union> B" |    798     also have "\<dots> = X ;; A \<union> B" | 
|    776       unfolding trns_of_def |         | 
|    777       unfolding L_rhs_union_distrib[symmetric] |    799       unfolding L_rhs_union_distrib[symmetric] | 
|    778       by (simp only: lang_of_rexp_of finite B_def A_def) |    800       by (simp only: lang_of_rexp_of finite B_def A_def) | 
|    779     finally show ?thesis |    801     finally show ?thesis | 
|    780       using l_eq_r not_empty |    802       using l_eq_r not_empty | 
|    781       apply(rule_tac arden[THEN iffD1]) |    803       apply(rule_tac arden[THEN iffD1]) | 
|    782       apply(simp add: A_def) |    804       apply(simp add: A_def) | 
|    783       apply(simp) |    805       apply(simp) | 
|    784       done |    806       done | 
|    785   qed |    807   qed | 
|    786   moreover have "L (arden_op X rhs) = (B ;; A\<star>)" |    808   moreover have "L (Arden X rhs) = B ;; A\<star>" | 
|    787     by (simp only:arden_op_def L_rhs_union_distrib lang_of_append_rhs  |    809     by (simp only:Arden_def L_rhs_union_distrib lang_of_append_rhs  | 
|    788                   B_def A_def b_def L_rexp.simps seq_union_distrib_left) |    810                   B_def A_def b_def L_rexp.simps seq_union_distrib_left) | 
|    789    ultimately show ?thesis by simp |    811    ultimately show ?thesis by simp | 
|    790 qed  |    812 qed  | 
|    791  |    813  | 
|    792 lemma append_keeps_finite: |    814 lemma append_keeps_finite: | 
|    793   "finite rhs \<Longrightarrow> finite (append_rhs_rexp rhs r)" |    815   "finite rhs \<Longrightarrow> finite (append_rhs_rexp rhs r)" | 
|    794 by (auto simp:append_rhs_rexp_def) |    816 by (auto simp:append_rhs_rexp_def) | 
|    795  |    817  | 
|    796 lemma arden_op_keeps_finite: |    818 lemma Arden_keeps_finite: | 
|    797   "finite rhs \<Longrightarrow> finite (arden_op X rhs)" |    819   "finite rhs \<Longrightarrow> finite (Arden X rhs)" | 
|    798 by (auto simp:arden_op_def append_keeps_finite) |    820 by (auto simp:Arden_def append_keeps_finite) | 
|    799  |    821  | 
|    800 lemma append_keeps_nonempty: |    822 lemma append_keeps_nonempty: | 
|    801   "rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (append_rhs_rexp rhs r)" |    823   "rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (append_rhs_rexp rhs r)" | 
|    802 apply (auto simp:rhs_nonempty_def append_rhs_rexp_def) |    824 apply (auto simp:rhs_nonempty_def append_rhs_rexp_def) | 
|    803 by (case_tac x, auto simp:Seq_def) |    825 by (case_tac x, auto simp:Seq_def) | 
|    808  |    830  | 
|    809 lemma nonempty_set_union: |    831 lemma nonempty_set_union: | 
|    810   "\<lbrakk>rhs_nonempty rhs; rhs_nonempty rhs'\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs \<union> rhs')" |    832   "\<lbrakk>rhs_nonempty rhs; rhs_nonempty rhs'\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs \<union> rhs')" | 
|    811 by (auto simp:rhs_nonempty_def) |    833 by (auto simp:rhs_nonempty_def) | 
|    812  |    834  | 
|    813 lemma arden_op_keeps_nonempty: |    835 lemma Arden_keeps_nonempty: | 
|    814   "rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (arden_op X rhs)" |    836   "rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (Arden X rhs)" | 
|    815 by (simp only:arden_op_def append_keeps_nonempty nonempty_set_sub) |    837 by (simp only:Arden_def append_keeps_nonempty nonempty_set_sub) | 
|    816  |    838  | 
|    817  |    839  | 
|    818 lemma subst_op_keeps_nonempty: |    840 lemma Subst_keeps_nonempty: | 
|    819   "\<lbrakk>rhs_nonempty rhs; rhs_nonempty xrhs\<rbrakk> \<Longrightarrow> rhs_nonempty (subst_op rhs X xrhs)" |    841   "\<lbrakk>rhs_nonempty rhs; rhs_nonempty xrhs\<rbrakk> \<Longrightarrow> rhs_nonempty (Subst rhs X xrhs)" | 
|    820 by (simp only:subst_op_def append_keeps_nonempty  nonempty_set_union nonempty_set_sub) |    842 by (simp only:Subst_def append_keeps_nonempty  nonempty_set_union nonempty_set_sub) | 
|    821  |    843  | 
|    822 lemma subst_op_keeps_eq: |    844 lemma Subst_keeps_eq: | 
|    823   assumes substor: "X = L xrhs" |    845   assumes substor: "X = L xrhs" | 
|    824   and finite: "finite rhs" |    846   and finite: "finite rhs" | 
|    825   shows "L (subst_op rhs X xrhs) = L rhs" (is "?Left = ?Right") |    847   shows "L (Subst rhs X xrhs) = L rhs" (is "?Left = ?Right") | 
|    826 proof- |    848 proof- | 
|    827   def A \<equiv> "L (rhs - trns_of rhs X)" |    849   def A \<equiv> "L (rhs - {Trn X r | r. Trn X r \<in> rhs})" | 
|    828   have "?Left = A \<union> L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs}))" |    850   have "?Left = A \<union> L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs}))" | 
|    829     unfolding subst_op_def |    851     unfolding Subst_def | 
|    830     unfolding L_rhs_union_distrib[symmetric] |    852     unfolding L_rhs_union_distrib[symmetric] | 
|    831     by (simp add: A_def) |    853     by (simp add: A_def) | 
|    832   moreover have "?Right = A \<union> L ({Trn X r | r. Trn X r \<in> rhs})" |    854   moreover have "?Right = A \<union> L ({Trn X r | r. Trn X r \<in> rhs})" | 
|    833   proof- |    855   proof- | 
|    834     have "rhs = (rhs - trns_of rhs X) \<union> (trns_of rhs X)" by (auto simp add: trns_of_def) |    856     have "rhs = (rhs - {Trn X r | r. Trn X r \<in> rhs}) \<union> ({Trn X r | r. Trn X r \<in> rhs})" by auto | 
|    835     thus ?thesis  |    857     thus ?thesis  | 
|    836       unfolding A_def |    858       unfolding A_def | 
|    837       unfolding L_rhs_union_distrib |    859       unfolding L_rhs_union_distrib | 
|    838       unfolding trns_of_def |         | 
|    839       by simp |    860       by simp | 
|    840   qed |    861   qed | 
|    841   moreover have "L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs})) = L ({Trn X r | r. Trn X r \<in> rhs})"  |    862   moreover have "L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs})) = L ({Trn X r | r. Trn X r \<in> rhs})"  | 
|    842     using finite substor  by (simp only:lang_of_append_rhs lang_of_rexp_of) |    863     using finite substor  by (simp only:lang_of_append_rhs lang_of_rexp_of) | 
|    843   ultimately show ?thesis by simp |    864   ultimately show ?thesis by simp | 
|    844 qed |    865 qed | 
|    845  |    866  | 
|    846 lemma subst_op_keeps_finite_rhs: |    867 lemma Subst_keeps_finite_rhs: | 
|    847   "\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (subst_op rhs Y yrhs)" |    868   "\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (Subst rhs Y yrhs)" | 
|    848 by (auto simp:subst_op_def append_keeps_finite) |    869 by (auto simp:Subst_def append_keeps_finite) | 
|    849  |    870  | 
|    850 lemma subst_op_all_keeps_finite: |    871 lemma Subst_all_keeps_finite: | 
|    851   assumes finite:"finite (ES:: (string set \<times> rhs_item set) set)" |    872   assumes finite:"finite (ES:: (string set \<times> rhs_item set) set)" | 
|    852   shows "finite (subst_op_all ES Y yrhs)" |    873   shows "finite (Subst_all ES Y yrhs)" | 
|    853 proof - |    874 proof - | 
|    854   have "finite {(Ya, subst_op yrhsa Y yrhs) |Ya yrhsa. (Ya, yrhsa) \<in> ES}"  |    875   have "finite {(Ya, Subst yrhsa Y yrhs) |Ya yrhsa. (Ya, yrhsa) \<in> ES}"  | 
|    855                                                                   (is "finite ?A") |    876                                                                   (is "finite ?A") | 
|    856   proof- |    877   proof- | 
|    857     def eqns' \<equiv> "{((Ya::string set), yrhsa)| Ya yrhsa. (Ya, yrhsa) \<in> ES}" |    878     def eqns' \<equiv> "{((Ya::string set), yrhsa)| Ya yrhsa. (Ya, yrhsa) \<in> ES}" | 
|    858     def h \<equiv> "\<lambda> ((Ya::string set), yrhsa). (Ya, subst_op yrhsa Y yrhs)" |    879     def h \<equiv> "\<lambda> ((Ya::string set), yrhsa). (Ya, Subst yrhsa Y yrhs)" | 
|    859     have "finite (h ` eqns')" using finite h_def eqns'_def by auto |    880     have "finite (h ` eqns')" using finite h_def eqns'_def by auto | 
|    860     moreover have "?A = h ` eqns'" by (auto simp:h_def eqns'_def) |    881     moreover have "?A = h ` eqns'" by (auto simp:h_def eqns'_def) | 
|    861     ultimately show ?thesis by auto       |    882     ultimately show ?thesis by auto       | 
|    862   qed |    883   qed | 
|    863   thus ?thesis by (simp add:subst_op_all_def) |    884   thus ?thesis by (simp add:Subst_all_def) | 
|    864 qed |    885 qed | 
|    865  |    886  | 
|    866 lemma subst_op_all_keeps_finite_rhs: |    887 lemma Subst_all_keeps_finite_rhs: | 
|    867   "\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (subst_op_all ES Y yrhs)" |    888   "\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (Subst_all ES Y yrhs)" | 
|    868 by (auto intro:subst_op_keeps_finite_rhs simp add:subst_op_all_def finite_rhs_def) |    889 by (auto intro:Subst_keeps_finite_rhs simp add:Subst_all_def finite_rhs_def) | 
|    869  |    890  | 
|    870 lemma append_rhs_keeps_cls: |    891 lemma append_rhs_keeps_cls: | 
|    871   "classes_of (append_rhs_rexp rhs r) = classes_of rhs" |    892   "classes_of (append_rhs_rexp rhs r) = classes_of rhs" | 
|    872 apply (auto simp:classes_of_def append_rhs_rexp_def) |    893 apply (auto simp:classes_of_def append_rhs_rexp_def) | 
|    873 apply (case_tac xa, auto simp:image_def) |    894 apply (case_tac xa, auto simp:image_def) | 
|    874 by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+) |    895 by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+) | 
|    875  |    896  | 
|    876 lemma arden_op_removes_cl: |    897 lemma Arden_removes_cl: | 
|    877   "classes_of (arden_op Y yrhs) = classes_of yrhs - {Y}" |    898   "classes_of (Arden Y yrhs) = classes_of yrhs - {Y}" | 
|    878 apply (simp add:arden_op_def append_rhs_keeps_cls trns_of_def) |    899 apply (simp add:Arden_def append_rhs_keeps_cls) | 
|    879 by (auto simp:classes_of_def) |    900 by (auto simp:classes_of_def) | 
|    880  |    901  | 
|    881 lemma lefts_of_keeps_cls: |    902 lemma lefts_of_keeps_cls: | 
|    882   "lefts_of (subst_op_all ES Y yrhs) = lefts_of ES" |    903   "lefts_of (Subst_all ES Y yrhs) = lefts_of ES" | 
|    883 by (auto simp:lefts_of_def subst_op_all_def) |    904 by (auto simp:lefts_of_def Subst_all_def) | 
|    884  |    905  | 
|    885 lemma subst_op_updates_cls: |    906 lemma Subst_updates_cls: | 
|    886   "X \<notin> classes_of xrhs \<Longrightarrow>  |    907   "X \<notin> classes_of xrhs \<Longrightarrow>  | 
|    887       classes_of (subst_op rhs X xrhs) = classes_of rhs \<union> classes_of xrhs - {X}" |    908       classes_of (Subst rhs X xrhs) = classes_of rhs \<union> classes_of xrhs - {X}" | 
|    888 apply (simp only:subst_op_def append_rhs_keeps_cls  |    909 apply (simp only:Subst_def append_rhs_keeps_cls  | 
|    889                               classes_of_union_distrib[THEN sym]) |    910                               classes_of_union_distrib[THEN sym]) | 
|    890 by (auto simp:classes_of_def trns_of_def) |    911 by (auto simp:classes_of_def) | 
|    891  |    912  | 
|    892 lemma subst_op_all_keeps_self_contained: |    913 lemma Subst_all_keeps_self_contained: | 
|    893   fixes Y |    914   fixes Y | 
|    894   assumes sc: "self_contained (ES \<union> {(Y, yrhs)})" (is "self_contained ?A") |    915   assumes sc: "self_contained (ES \<union> {(Y, yrhs)})" (is "self_contained ?A") | 
|    895   shows "self_contained (subst_op_all ES Y (arden_op Y yrhs))"  |    916   shows "self_contained (Subst_all ES Y (Arden Y yrhs))"  | 
|    896                                                    (is "self_contained ?B") |    917                                                    (is "self_contained ?B") | 
|    897 proof- |    918 proof- | 
|    898   { fix X xrhs' |    919   { fix X xrhs' | 
|    899     assume "(X, xrhs') \<in> ?B" |    920     assume "(X, xrhs') \<in> ?B" | 
|    900     then obtain xrhs  |    921     then obtain xrhs  | 
|    901       where xrhs_xrhs': "xrhs' = subst_op xrhs Y (arden_op Y yrhs)" |    922       where xrhs_xrhs': "xrhs' = Subst xrhs Y (Arden Y yrhs)" | 
|    902       and X_in: "(X, xrhs) \<in> ES" by (simp add:subst_op_all_def, blast)     |    923       and X_in: "(X, xrhs) \<in> ES" by (simp add:Subst_all_def, blast)     | 
|    903     have "classes_of xrhs' \<subseteq> lefts_of ?B" |    924     have "classes_of xrhs' \<subseteq> lefts_of ?B" | 
|    904     proof- |    925     proof- | 
|    905       have "lefts_of ?B = lefts_of ES" by (auto simp add:lefts_of_def subst_op_all_def) |    926       have "lefts_of ?B = lefts_of ES" by (auto simp add:lefts_of_def Subst_all_def) | 
|    906       moreover have "classes_of xrhs' \<subseteq> lefts_of ES" |    927       moreover have "classes_of xrhs' \<subseteq> lefts_of ES" | 
|    907       proof- |    928       proof- | 
|    908         have "classes_of xrhs' \<subseteq>  |    929         have "classes_of xrhs' \<subseteq>  | 
|    909                         classes_of xrhs \<union> classes_of (arden_op Y yrhs) - {Y}" |    930                         classes_of xrhs \<union> classes_of (Arden Y yrhs) - {Y}" | 
|    910         proof- |    931         proof- | 
|    911           have "Y \<notin> classes_of (arden_op Y yrhs)"  |    932           have "Y \<notin> classes_of (Arden Y yrhs)"  | 
|    912             using arden_op_removes_cl by simp |    933             using Arden_removes_cl by simp | 
|    913           thus ?thesis using xrhs_xrhs' by (auto simp:subst_op_updates_cls) |    934           thus ?thesis using xrhs_xrhs' by (auto simp:Subst_updates_cls) | 
|    914         qed |    935         qed | 
|    915         moreover have "classes_of xrhs \<subseteq> lefts_of ES \<union> {Y}" using X_in sc |    936         moreover have "classes_of xrhs \<subseteq> lefts_of ES \<union> {Y}" using X_in sc | 
|    916           apply (simp only:self_contained_def lefts_of_union_distrib[THEN sym]) |    937           apply (simp only:self_contained_def lefts_of_union_distrib[THEN sym]) | 
|    917           by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lefts_of_def) |    938           by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lefts_of_def) | 
|    918         moreover have "classes_of (arden_op Y yrhs) \<subseteq> lefts_of ES \<union> {Y}"  |    939         moreover have "classes_of (Arden Y yrhs) \<subseteq> lefts_of ES \<union> {Y}"  | 
|    919           using sc  |    940           using sc  | 
|    920           by (auto simp add:arden_op_removes_cl self_contained_def lefts_of_def) |    941           by (auto simp add:Arden_removes_cl self_contained_def lefts_of_def) | 
|    921         ultimately show ?thesis by auto |    942         ultimately show ?thesis by auto | 
|    922       qed |    943       qed | 
|    923       ultimately show ?thesis by simp |    944       ultimately show ?thesis by simp | 
|    924     qed |    945     qed | 
|    925   } thus ?thesis by (auto simp only:subst_op_all_def self_contained_def) |    946   } thus ?thesis by (auto simp only:Subst_all_def self_contained_def) | 
|    926 qed |    947 qed | 
|    927  |    948  | 
|    928 lemma subst_op_all_satisfy_invariant: |    949 lemma Subst_all_satisfy_invariant: | 
|    929   assumes invariant_ES: "invariant (ES \<union> {(Y, yrhs)})" |    950   assumes invariant_ES: "invariant (ES \<union> {(Y, yrhs)})" | 
|    930   shows "invariant (subst_op_all ES Y (arden_op Y yrhs))" |    951   shows "invariant (Subst_all ES Y (Arden Y yrhs))" | 
|    931 proof -   |    952 proof -   | 
|    932   have finite_yrhs: "finite yrhs"  |    953   have finite_yrhs: "finite yrhs"  | 
|    933     using invariant_ES by (auto simp:invariant_def finite_rhs_def) |    954     using invariant_ES by (auto simp:invariant_def finite_rhs_def) | 
|    934   have nonempty_yrhs: "rhs_nonempty yrhs"  |    955   have nonempty_yrhs: "rhs_nonempty yrhs"  | 
|    935     using invariant_ES by (auto simp:invariant_def ardenable_def) |    956     using invariant_ES by (auto simp:invariant_def ardenable_def) | 
|    936   have Y_eq_yrhs: "Y = L yrhs"  |    957   have Y_eq_yrhs: "Y = L yrhs"  | 
|    937     using invariant_ES by (simp only:invariant_def valid_eqns_def, blast) |    958     using invariant_ES by (simp only:invariant_def valid_eqns_def, blast) | 
|    938   have "distinct_equas (subst_op_all ES Y (arden_op Y yrhs))"  |    959   have "distinct_equas (Subst_all ES Y (Arden Y yrhs))"  | 
|    939     using invariant_ES |    960     using invariant_ES | 
|    940     by (auto simp:distinct_equas_def subst_op_all_def invariant_def) |    961     by (auto simp:distinct_equas_def Subst_all_def invariant_def) | 
|    941   moreover have "finite (subst_op_all ES Y (arden_op Y yrhs))"  |    962   moreover have "finite (Subst_all ES Y (Arden Y yrhs))"  | 
|    942     using invariant_ES by (simp add:invariant_def subst_op_all_keeps_finite) |    963     using invariant_ES by (simp add:invariant_def Subst_all_keeps_finite) | 
|    943   moreover have "finite_rhs (subst_op_all ES Y (arden_op Y yrhs))" |    964   moreover have "finite_rhs (Subst_all ES Y (Arden Y yrhs))" | 
|    944   proof- |    965   proof- | 
|    945     have "finite_rhs ES" using invariant_ES  |    966     have "finite_rhs ES" using invariant_ES  | 
|    946       by (simp add:invariant_def finite_rhs_def) |    967       by (simp add:invariant_def finite_rhs_def) | 
|    947     moreover have "finite (arden_op Y yrhs)" |    968     moreover have "finite (Arden Y yrhs)" | 
|    948     proof - |    969     proof - | 
|    949       have "finite yrhs" using invariant_ES  |    970       have "finite yrhs" using invariant_ES  | 
|    950         by (auto simp:invariant_def finite_rhs_def) |    971         by (auto simp:invariant_def finite_rhs_def) | 
|    951       thus ?thesis using arden_op_keeps_finite by simp |    972       thus ?thesis using Arden_keeps_finite by simp | 
|    952     qed |    973     qed | 
|    953     ultimately show ?thesis  |    974     ultimately show ?thesis  | 
|    954       by (simp add:subst_op_all_keeps_finite_rhs) |    975       by (simp add:Subst_all_keeps_finite_rhs) | 
|    955   qed |    976   qed | 
|    956   moreover have "ardenable (subst_op_all ES Y (arden_op Y yrhs))" |    977   moreover have "ardenable (Subst_all ES Y (Arden Y yrhs))" | 
|    957   proof -  |    978   proof -  | 
|    958     { fix X rhs |    979     { fix X rhs | 
|    959       assume "(X, rhs) \<in> ES" |    980       assume "(X, rhs) \<in> ES" | 
|    960       hence "rhs_nonempty rhs"  using prems invariant_ES   |    981       hence "rhs_nonempty rhs"  using prems invariant_ES   | 
|    961         by (simp add:invariant_def ardenable_def) |    982         by (simp add:invariant_def ardenable_def) | 
|    962       with nonempty_yrhs  |    983       with nonempty_yrhs  | 
|    963       have "rhs_nonempty (subst_op rhs Y (arden_op Y yrhs))" |    984       have "rhs_nonempty (Subst rhs Y (Arden Y yrhs))" | 
|    964         by (simp add:nonempty_yrhs  |    985         by (simp add:nonempty_yrhs  | 
|    965                subst_op_keeps_nonempty arden_op_keeps_nonempty) |    986                Subst_keeps_nonempty Arden_keeps_nonempty) | 
|    966     } thus ?thesis by (auto simp add:ardenable_def subst_op_all_def) |    987     } thus ?thesis by (auto simp add:ardenable_def Subst_all_def) | 
|    967   qed |    988   qed | 
|    968   moreover have "valid_eqns (subst_op_all ES Y (arden_op Y yrhs))" |    989   moreover have "valid_eqns (Subst_all ES Y (Arden Y yrhs))" | 
|    969   proof- |    990   proof- | 
|    970     have "Y = L (arden_op Y yrhs)"  |    991     have "Y = L (Arden Y yrhs)"  | 
|    971       using Y_eq_yrhs invariant_ES finite_yrhs nonempty_yrhs       |    992       using Y_eq_yrhs invariant_ES finite_yrhs nonempty_yrhs       | 
|    972       by (rule_tac arden_op_keeps_eq, (simp add:rexp_of_empty)+) |    993       by (rule_tac Arden_keeps_eq, (simp add:rexp_of_empty)+) | 
|    973     thus ?thesis using invariant_ES  |    994     thus ?thesis using invariant_ES  | 
|    974       by (clarsimp simp add:valid_eqns_def  |    995       by (clarsimp simp add:valid_eqns_def  | 
|    975               subst_op_all_def subst_op_keeps_eq invariant_def finite_rhs_def |    996               Subst_all_def Subst_keeps_eq invariant_def finite_rhs_def | 
|    976                    simp del:L_rhs.simps) |    997                    simp del:L_rhs.simps) | 
|    977   qed |    998   qed | 
|    978   moreover  |    999   moreover  | 
|    979   have self_subst: "self_contained (subst_op_all ES Y (arden_op Y yrhs))" |   1000   have self_subst: "self_contained (Subst_all ES Y (Arden Y yrhs))" | 
|    980     using invariant_ES subst_op_all_keeps_self_contained by (simp add:invariant_def) |   1001     using invariant_ES Subst_all_keeps_self_contained by (simp add:invariant_def) | 
|    981   ultimately show ?thesis using invariant_ES by (simp add:invariant_def) |   1002   ultimately show ?thesis using invariant_ES by (simp add:invariant_def) | 
|    982 qed |   1003 qed | 
|    983  |   1004  | 
|    984 lemma subst_op_all_card_le:  |   1005 lemma Subst_all_card_le:  | 
|    985   assumes finite: "finite (ES::(string set \<times> rhs_item set) set)" |   1006   assumes finite: "finite (ES::(string set \<times> rhs_item set) set)" | 
|    986   shows "card (subst_op_all ES Y yrhs) <= card ES" |   1007   shows "card (Subst_all ES Y yrhs) <= card ES" | 
|    987 proof- |   1008 proof- | 
|    988   def f \<equiv> "\<lambda> x. ((fst x)::string set, subst_op (snd x) Y yrhs)" |   1009   def f \<equiv> "\<lambda> x. ((fst x)::string set, Subst (snd x) Y yrhs)" | 
|    989   have "subst_op_all ES Y yrhs = f ` ES"  |   1010   have "Subst_all ES Y yrhs = f ` ES"  | 
|    990     apply (auto simp:subst_op_all_def f_def image_def) |   1011     apply (auto simp:Subst_all_def f_def image_def) | 
|    991     by (rule_tac x = "(Ya, yrhsa)" in bexI, simp+) |   1012     by (rule_tac x = "(Ya, yrhsa)" in bexI, simp+) | 
|    992   thus ?thesis using finite by (auto intro:card_image_le) |   1013   thus ?thesis using finite by (auto intro:card_image_le) | 
|    993 qed |   1014 qed | 
|    994  |   1015  | 
|    995 lemma subst_op_all_cls_remains:  |   1016 lemma Subst_all_cls_remains:  | 
|    996   "(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (subst_op_all ES Y yrhs)" |   1017   "(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (Subst_all ES Y yrhs)" | 
|    997 by (auto simp:subst_op_all_def) |   1018 by (auto simp:Subst_all_def) | 
|    998  |   1019  | 
|    999 lemma card_noteq_1_has_more: |   1020 lemma card_noteq_1_has_more: | 
|   1000   assumes card:"card S \<noteq> 1" |   1021   assumes card:"card S \<noteq> 1" | 
|   1001   and e_in: "e \<in> S" |   1022   and e_in: "e \<in> S" | 
|   1002   and finite: "finite S" |   1023   and finite: "finite S" | 
|   1029     from X_in_ES Y_in_ES and not_eq and Inv_ES |   1050     from X_in_ES Y_in_ES and not_eq and Inv_ES | 
|   1030     show "(Y, yrhs) \<in> ES \<and> X \<noteq> Y" |   1051     show "(Y, yrhs) \<in> ES \<and> X \<noteq> Y" | 
|   1031       by (auto simp: invariant_def distinct_equas_def) |   1052       by (auto simp: invariant_def distinct_equas_def) | 
|   1032   next |   1053   next | 
|   1033     fix x |   1054     fix x | 
|   1034     let ?ES' = "let (Y, yrhs) = x in subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)" |   1055     let ?ES' = "let (Y, yrhs) = x in Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)" | 
|   1035     assume prem: "case x of (Y, yrhs) \<Rightarrow> (Y, yrhs) \<in> ES \<and> (X \<noteq> Y)" |   1056     assume prem: "case x of (Y, yrhs) \<Rightarrow> (Y, yrhs) \<in> ES \<and> (X \<noteq> Y)" | 
|   1036     thus "invariant (?ES') \<and> (\<exists>xrhs'. (X, xrhs') \<in> ?ES') \<and> (?ES', ES) \<in> measure card" |   1057     thus "invariant (?ES') \<and> (\<exists>xrhs'. (X, xrhs') \<in> ?ES') \<and> (?ES', ES) \<in> measure card" | 
|   1037     proof(cases "x", simp) |   1058     proof(cases "x", simp) | 
|   1038       fix Y yrhs |   1059       fix Y yrhs | 
|   1039       assume h: "(Y, yrhs) \<in> ES \<and>  X \<noteq> Y"  |   1060       assume h: "(Y, yrhs) \<in> ES \<and>  X \<noteq> Y"  | 
|   1040       show "invariant (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) \<and> |   1061       show "invariant (Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)) \<and> | 
|   1041              (\<exists>xrhs'. (X, xrhs') \<in> subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) \<and> |   1062              (\<exists>xrhs'. (X, xrhs') \<in> Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)) \<and> | 
|   1042              card (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) < card ES" |   1063              card (Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)) < card ES" | 
|   1043       proof - |   1064       proof - | 
|   1044         have "invariant (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs))"  |   1065         have "invariant (Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs))"  | 
|   1045         proof(rule subst_op_all_satisfy_invariant) |   1066         proof(rule Subst_all_satisfy_invariant) | 
|   1046           from h have "(Y, yrhs) \<in> ES" by simp |   1067           from h have "(Y, yrhs) \<in> ES" by simp | 
|   1047           hence "ES - {(Y, yrhs)} \<union> {(Y, yrhs)} = ES" by auto |   1068           hence "ES - {(Y, yrhs)} \<union> {(Y, yrhs)} = ES" by auto | 
|   1048           with Inv_ES show "invariant (ES - {(Y, yrhs)} \<union> {(Y, yrhs)})" by auto |   1069           with Inv_ES show "invariant (ES - {(Y, yrhs)} \<union> {(Y, yrhs)})" by auto | 
|   1049         qed |   1070         qed | 
|   1050         moreover have  |   1071         moreover have  | 
|   1051           "(\<exists>xrhs'. (X, xrhs') \<in> subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs))" |   1072           "(\<exists>xrhs'. (X, xrhs') \<in> Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs))" | 
|   1052         proof(rule subst_op_all_cls_remains) |   1073         proof(rule Subst_all_cls_remains) | 
|   1053           from X_in_ES and h |   1074           from X_in_ES and h | 
|   1054           show "(X, xrhs) \<in> ES - {(Y, yrhs)}" by auto |   1075           show "(X, xrhs) \<in> ES - {(Y, yrhs)}" by auto | 
|   1055         qed |   1076         qed | 
|   1056         moreover have  |   1077         moreover have  | 
|   1057           "card (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) < card ES" |   1078           "card (Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)) < card ES" | 
|   1058         proof(rule le_less_trans) |   1079         proof(rule le_less_trans) | 
|   1059           show  |   1080           show  | 
|   1060             "card (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) \<le>  |   1081             "card (Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)) \<le>  | 
|   1061                                                                 card (ES - {(Y, yrhs)})" |   1082                                                                 card (ES - {(Y, yrhs)})" | 
|   1062           proof(rule subst_op_all_card_le) |   1083           proof(rule Subst_all_card_le) | 
|   1063             show "finite (ES - {(Y, yrhs)})" using finite_ES by auto |   1084             show "finite (ES - {(Y, yrhs)})" using finite_ES by auto | 
|   1064           qed |   1085           qed | 
|   1065         next |   1086         next | 
|   1066           show "card (ES - {(Y, yrhs)}) < card ES" using finite_ES h |   1087           show "card (ES - {(Y, yrhs)}) < card ES" using finite_ES h | 
|   1067             by (auto simp:card_gt_0_iff intro:diff_Suc_less) |   1088             by (auto simp:card_gt_0_iff intro:diff_Suc_less) | 
|   1068         qed |   1089         qed | 
|   1069         ultimately show ?thesis  |   1090         ultimately show ?thesis  | 
|   1070           by (auto dest: subst_op_all_card_le elim:le_less_trans) |   1091           by (auto dest: Subst_all_card_le elim:le_less_trans) | 
|   1071       qed |   1092       qed | 
|   1072     qed |   1093     qed | 
|   1073   qed |   1094   qed | 
|   1074 qed |   1095 qed | 
|   1075  |   1096  |