diff -r 9df291750cc0 -r dca9c237d108 src/HOL/Wellfounded.thy --- a/src/HOL/Wellfounded.thy Tue Mar 26 06:32:38 2024 +0100 +++ b/src/HOL/Wellfounded.thy Tue Mar 26 09:31:34 2024 +0100 @@ -961,20 +961,52 @@ by (clarsimp simp: inv_image_def wf_eq_minimal) qed +lemma wfp_on_inv_imagep: + assumes wf: "wfp_on (f ` A) R" + shows "wfp_on A (inv_imagep R f)" + unfolding wfp_on_iff_ex_minimal +proof (intro allI impI) + fix B assume "B \ A" and "B \ {}" + hence "\z\f ` B. \y. R y z \ y \ f ` B" + using wf[unfolded wfp_on_iff_ex_minimal, rule_format, of "f ` B"] by blast + thus "\z\B. \y. inv_imagep R f y z \ y \ B" + unfolding inv_imagep_def + by auto +qed + subsubsection \Conversion to a known well-founded relation\ +lemma wfp_on_if_convertible_to_wfp_on: + assumes + wf: "wfp_on (f ` A) Q" and + convertible: "(\x y. x \ A \ y \ A \ R x y \ Q (f x) (f y))" + shows "wfp_on A R" + unfolding wfp_on_iff_ex_minimal +proof (intro allI impI) + fix B assume "B \ A" and "B \ {}" + moreover from wf have "wfp_on A (inv_imagep Q f)" + by (rule wfp_on_inv_imagep) + ultimately obtain y where "y \ B" and "\z. Q (f z) (f y) \ z \ B" + unfolding wfp_on_iff_ex_minimal in_inv_imagep + by blast + thus "\z \ B. \y. R y z \ y \ B" + using \B \ A\ convertible by blast +qed + +lemma wf_on_if_convertible_to_wf_on: "wf_on (f ` A) Q \ (\x y. x \ A \ y \ A \ (x, y) \ R \ (f x, f y) \ Q) \ wf_on A R" + using wfp_on_if_convertible_to_wfp_on[to_set] . + lemma wf_if_convertible_to_wf: fixes r :: "'a rel" and s :: "'b rel" and f :: "'a \ 'b" assumes "wf s" and convertible: "\x y. (x, y) \ r \ (f x, f y) \ s" shows "wf r" -proof (rule wfI_min[of r]) - fix x :: 'a and Q :: "'a set" - assume "x \ Q" - then obtain y where "y \ Q" and "\z. (f z, f y) \ s \ z \ Q" - by (auto elim: wfE_min[OF wf_inv_image[of s f, OF \wf s\], unfolded in_inv_image]) - thus "\z \ Q. \y. (y, z) \ r \ y \ Q" - by (auto intro: convertible) +proof (rule wf_on_if_convertible_to_wf_on) + show "wf_on (range f) s" + using wf_on_subset[OF \wf s\ subset_UNIV] . +next + show "\x y. (x, y) \ r \ (f x, f y) \ s" + using convertible . qed lemma wfP_if_convertible_to_wfP: "wfP S \ (\x y. R x y \ S (f x) (f y)) \ wfP R"