theory Commutation imports "$AFP/Abstract-Rewriting/Abstract_Rewriting" begin text \@{theory Abstract_Rewriting} defines commutation as follows\ lemma "commute r s \ ((r\)\<^sup>* O s\<^sup>*) \ (s\<^sup>* O (r\)\<^sup>*)" by (rule commute_def) text \To use this definition the following introduction rule turns out to be useful\ lemma commuteI [intro]: "(\x y\<^sub>1 y\<^sub>2. (x, y\<^sub>1) \ r\<^sub>1\<^sup>* \ (x, y\<^sub>2) \ r\<^sub>2\<^sup>* \ \z. (y\<^sub>1, z) \ r\<^sub>2\<^sup>* \ (y\<^sub>2, z) \ r\<^sub>1\<^sup>*) \ commute r\<^sub>1 r\<^sub>2" unfolding commute_def by auto (metis converse_converse relcomp.simps rtrancl_converseD) text \We now define strong commutation\ definition strongly_commute :: "'a rel \ 'a rel \ bool" where "strongly_commute r\<^sub>1 r\<^sub>2 \ (\x y\<^sub>1 y\<^sub>2. (x, y\<^sub>1) \ r\<^sub>1 \ (x, y\<^sub>2) \ r\<^sub>2 \ (\z. (y\<^sub>1, z) \ r\<^sub>2\<^sup>= \ (y\<^sub>2, z) \ r\<^sub>1\<^sup>*))" text \Exercise: prove that strong commutation implies commutation\ lemma strongly_commute_imp_commute: assumes "strongly_commute r s" shows "commute r s" oops text \Here's a possible Solution\ definition semi_commute :: "'a rel \ 'a rel \ bool" where "semi_commute r\<^sub>1 r\<^sub>2 \ (\x y\<^sub>1 y\<^sub>2. (x, y\<^sub>1) \ r\<^sub>1 \ (x, y\<^sub>2) \ r\<^sub>2\<^sup>* \ (\z. (y\<^sub>1, z) \ r\<^sub>2\<^sup>* \ (y\<^sub>2, z) \ r\<^sub>1\<^sup>*))" lemma semi_commute_imp_commute: "semi_commute r\<^sub>1 r\<^sub>2 \ commute r\<^sub>1 r\<^sub>2" proof fix x y\<^sub>1 y\<^sub>2 assume *:"semi_commute r\<^sub>1 r\<^sub>2" and "(x, y\<^sub>1) \ r\<^sub>1\<^sup>*" and 2:"(x, y\<^sub>2) \ r\<^sub>2\<^sup>*" then obtain n where "(x, y\<^sub>1) \ r\<^sub>1 ^^ n" by auto then show "\z. (y\<^sub>1, z) \ r\<^sub>2\<^sup>* \ (y\<^sub>2, z) \ r\<^sub>1\<^sup>*" proof (induct n arbitrary: y\<^sub>1) case 0 then show ?case using 2 by auto next case (Suc n) then obtain y\<^sub>n where "(x, y\<^sub>n) \ r\<^sub>1 ^^ n" and 1:"(y\<^sub>n, y\<^sub>1) \ r\<^sub>1" by auto then obtain z where "(y\<^sub>n, z) \ r\<^sub>2\<^sup>* \ (y\<^sub>2, z) \ r\<^sub>1\<^sup>*" using Suc by auto then show ?case using rtrancl_trans 1 2 * unfolding semi_commute_def by metis qed qed lemma strongly_commute_D1n: assumes "strongly_commute r\<^sub>1 r\<^sub>2" shows "(x, y) \ r\<^sub>2 \ (x, z) \ r\<^sub>1 ^^ n \ \u. (y, u) \ r\<^sub>1\<^sup>* \ (z, u) \ r\<^sub>2\<^sup>=" proof (induct n arbitrary: x y z) case (Suc m) from Suc(3) obtain w where xw: "(x, w) \ r\<^sub>1 ^^ m" and wz: "(w, z) \ r\<^sub>1" by auto with Suc obtain u where yu: "(y, u) \ r\<^sub>1\<^sup>*" and wu: "(w, u) \ r\<^sub>2\<^sup>=" by blast then have "w = u \ (w, u) \ r\<^sub>2" by auto then show ?case proof (rule disjE) assume "w = u" then have "(y, z) \ r\<^sub>1\<^sup>*" using yu wz by auto then show ?thesis by blast next assume "(w, u) \ r\<^sub>2" then obtain t where "\ua. (u, t) \ r\<^sub>1\<^sup>* \ (z, t) \ r\<^sub>2\<^sup>=" using assms wz unfolding strongly_commute_def by blast then show ?thesis using rtrancl_trans yu by metis qed qed auto lemma strongly_commute_imp_commute: assumes "strongly_commute r\<^sub>1 r\<^sub>2" shows "commute r\<^sub>1 r\<^sub>2" proof (rule semi_commute_imp_commute) show "semi_commute r\<^sub>1 r\<^sub>2" unfolding semi_commute_def proof (intro allI impI) fix x y\<^sub>1 y\<^sub>2 assume "(x, y\<^sub>1) \ r\<^sub>1 \ (x, y\<^sub>2) \ r\<^sub>2\<^sup>*" then obtain n where "(x, y\<^sub>2) \ r\<^sub>2 ^^ n" and "(x, y\<^sub>1) \ r\<^sub>1" by auto then show "\z. (y\<^sub>1, z) \ r\<^sub>2\<^sup>* \ (y\<^sub>2, z) \ r\<^sub>1\<^sup>*" proof (induct n arbitrary: y\<^sub>2) case (Suc n) then obtain y where "(x, y) \ r\<^sub>2 ^^ n" and "(y, y\<^sub>2) \ r\<^sub>2" by auto with Suc obtain z where y\<^sub>1z:"(y\<^sub>1, z) \ r\<^sub>2\<^sup>*" and "(y, z) \ r\<^sub>1\<^sup>* " by auto then obtain u where u: "(y\<^sub>2, u) \ r\<^sub>1\<^sup>* \ (z, u) \ r\<^sub>2\<^sup>=" using assms \(y, y\<^sub>2) \ r\<^sub>2\ by (auto dest: strongly_commute_D1n) moreover have "(y\<^sub>1, u) \ r\<^sub>2\<^sup>*" using y\<^sub>1z u by auto ultimately show ?case by auto qed auto qed qed end