diff -r 1b73c3e17d9f -r 15a5e0922f45 src/HOL/Wellfounded.thy --- a/src/HOL/Wellfounded.thy Tue Mar 04 19:34:12 2025 +0100 +++ b/src/HOL/Wellfounded.thy Wed Mar 05 08:28:21 2025 +0100 @@ -417,34 +417,64 @@ subsubsection \Well-foundedness of transitive closure\ +lemma bex_rtrancl_min_element_if_wf_on: + assumes wf: "wf_on A r" and x_in: "x \ A" + shows "\y \ A. (y, x) \ r\<^sup>* \ \(\z \ A. (z, y) \ r)" + using wf +proof (induction x rule: wf_on_induct) + case in_set + thus ?case + using x_in . +next + case (less z) + show ?case + proof (cases "\y \ A. (y, z) \ r") + case True + then obtain y where "y \ A" and "(y, z) \ r" + by blast + then obtain x where "x \ A" and "(x, y) \ r\<^sup>*" and "\ (\w\A. (w, x) \ r)" + using less.IH by blast + show ?thesis + proof (intro bexI conjI) + show "(x, z) \ r\<^sup>*" + using rtrancl.rtrancl_into_rtrancl[of x y r z] + using \(x, y) \ r\<^sup>*\ \(y, z) \ r\ by blast + next + show "\ (\z\A. (z, x) \ r)" + using \\ (\w\A. (w, x) \ r)\ . + next + show "x \ A" + using \x \ A\ . + qed + next + case False + show ?thesis + proof (intro bexI conjI) + show "(z, z) \ r\<^sup>*" + using rtrancl.rtrancl_refl . + next + show "\ (\w\A. (w, z) \ r)" + using False . + next + show "z \ A" + using less.hyps . + qed + qed +qed + +lemma bex_rtransclp_min_element_if_wfp_on: "wfp_on A R \ x \ A \ \y\A. R\<^sup>*\<^sup>* y x \ \ (\z\A. R z y)" + by (rule bex_rtrancl_min_element_if_wf_on[to_pred]) + lemma ex_terminating_rtranclp_strong: assumes wf: "wfp_on {x'. R\<^sup>*\<^sup>* x x'} R\\" shows "\y. R\<^sup>*\<^sup>* x y \ (\z. R y z)" -proof (cases "\y. R x y") - case True - with wf show ?thesis - proof (induction rule: Wellfounded.wfp_on_induct) - case in_set - thus ?case - by simp - next - case (less y) - have "R\<^sup>*\<^sup>* x y" - using less.hyps mem_Collect_eq[of _ "R\<^sup>*\<^sup>* x"] by iprover +proof - + have x_in: "x \ {x'. R\<^sup>*\<^sup>* x x'}" + by simp - moreover obtain z where "R y z" - using less.prems by iprover - - ultimately have "R\<^sup>*\<^sup>* x z" - using rtranclp.rtrancl_into_rtrancl[of R x y z] by iprover - - show ?case - using \R y z\ \R\<^sup>*\<^sup>* x z\ less.IH[of z] rtranclp_trans[of R y z] by blast - qed -next - case False - thus ?thesis - by blast + show ?thesis + using bex_rtransclp_min_element_if_wfp_on[OF wf x_in] + using rtranclp.rtrancl_into_rtrancl[of R x] by blast qed lemma ex_terminating_rtranclp: