# HG changeset patch # User desharna # Date 1683699653 -7200 # Node ID 93f294ad42e6c558825864ac27afe6b41d408794 # Parent f5b67198b0194f504ddda8bd6e09f66f6743c136# Parent 24f0cd70790b1bd58c4af1f3a0ddbe2f6699b1e3 merged diff -r f5b67198b019 -r 93f294ad42e6 NEWS --- a/NEWS Tue May 09 23:56:40 2023 +0200 +++ b/NEWS Wed May 10 08:20:53 2023 +0200 @@ -81,7 +81,9 @@ Finite_Set.bex_greatest_element Finite_Set.bex_least_element Finite_Set.bex_max_element + Finite_Set.bex_max_element_with_property Finite_Set.bex_min_element + Finite_Set.bex_min_element_with_property is_max_element_in_set_iff is_min_element_in_set_iff diff -r f5b67198b019 -r 93f294ad42e6 src/HOL/Finite_Set.thy --- a/src/HOL/Finite_Set.thy Tue May 09 23:56:40 2023 +0200 +++ b/src/HOL/Finite_Set.thy Wed May 10 08:20:53 2023 +0200 @@ -2471,94 +2471,193 @@ context begin qualified lemma - assumes "finite A" and "A \ {}" and "transp_on A R" and "asymp_on A R" + assumes "finite A" and "asymp_on A R" and "transp_on A R" and "\x \ A. P x" shows - bex_min_element: "\m \ A. \x \ A. x \ m \ \ R x m" and - bex_max_element: "\m \ A. \x \ A. x \ m \ \ R m x" + bex_min_element_with_property: "\x \ A. P x \ (\y \ A. R y x \ \ P y)" and + bex_max_element_with_property: "\x \ A. P x \ (\y \ A. R x y \ \ P y)" unfolding atomize_conj using assms proof (induction A rule: finite_induct) case empty hence False - by simp + by simp_all thus ?case .. next - case (insert a A') + case (insert x F) + + from insert.prems have "asymp_on F R" + using asymp_on_subset by blast + + from insert.prems have "transp_on F R" + using transp_on_subset by blast + show ?case - proof (cases "A' = {}") + proof (cases "P x") case True show ?thesis - proof (intro conjI bexI) - show "\x\insert a A'. x \ a \ \ R x a" and "\x\insert a A'. x \ a \ \ R a x" - using True by blast+ - qed simp_all - next - case False - moreover have "transp_on A' R" - using insert.prems transp_on_subset by blast - moreover have "asymp_on A' R" - using insert.prems asymp_on_subset by blast - ultimately obtain min max where - "min \ A'" and "max \ A'" and - min_is_min: "\x\A'. x \ min \ \ R x min" and - max_is_max: "\x\A'. x \ max \ \ R max x" - using insert.IH by auto - - show ?thesis - proof (rule conjI) - show "\min\insert a A'. \x\insert a A'. x \ min \ \ R x min" - proof (cases "R a min") - case True - show ?thesis - proof (intro bexI ballI impI) - show "a \ insert a A'" - by simp + proof (cases "\a\F. P a") + case True + with insert.IH obtain min max where + "min \ F" and "P min" and "\z \ F. R z min \ \ P z" + "max \ F" and "P max" and "\z \ F. R max z \ \ P z" + using \asymp_on F R\ \transp_on F R\ by auto + + show ?thesis + proof (rule conjI) + show "\y \ insert x F. P y \ (\z \ insert x F. R y z \ \ P z)" + proof (cases "R max x") + case True + show ?thesis + proof (intro bexI conjI ballI impI) + show "x \ insert x F" + by simp + next + show "P x" + using \P x\ by simp + next + fix z assume "z \ insert x F" and "R x z" + hence "z = x \ z \ F" + by simp + thus "\ P z" + proof (rule disjE) + assume "z = x" + hence "R x x" + using \R x z\ by simp + moreover have "\ R x x" + using \asymp_on (insert x F) R\[THEN irreflp_on_if_asymp_on, THEN irreflp_onD] + by simp + ultimately have False + by simp + thus ?thesis .. + next + assume "z \ F" + moreover have "R max z" + using \R max x\ \R x z\ + using \transp_on (insert x F) R\[THEN transp_onD, of max x z] + using \max \ F\ \z \ F\ by simp + ultimately show ?thesis + using \\z \ F. R max z \ \ P z\ by simp + qed + qed next - fix x - show "x \ insert a A' \ x \ a \ \ R x a" - using True \min \ A'\ min_is_min[rule_format, of x] insert.prems(2,3) - by (auto dest: asymp_onD transp_onD) + case False + show ?thesis + proof (intro bexI conjI ballI impI) + show "max \ insert x F" + using \max \ F\ by simp + next + show "P max" + using \P max\ by simp + next + fix z assume "z \ insert x F" and "R max z" + hence "z = x \ z \ F" + by simp + thus "\ P z" + proof (rule disjE) + assume "z = x" + hence False + using \\ R max x\ \R max z\ by simp + thus ?thesis .. + next + assume "z \ F" + thus ?thesis + using \R max z\ \\z\F. R max z \ \ P z\ by simp + qed + qed qed next - case False - show ?thesis - proof (rule bexI) - show "min \ insert a A'" - using \min \ A'\ by auto + show "\y \ insert x F. P y \ (\z \ insert x F. R z y \ \ P z)" + proof (cases "R x min") + case True + show ?thesis + proof (intro bexI conjI ballI impI) + show "x \ insert x F" + by simp + next + show "P x" + using \P x\ by simp + next + fix z assume "z \ insert x F" and "R z x" + hence "z = x \ z \ F" + by simp + thus "\ P z" + proof (rule disjE) + assume "z = x" + hence "R x x" + using \R z x\ by simp + moreover have "\ R x x" + using \asymp_on (insert x F) R\[THEN irreflp_on_if_asymp_on, THEN irreflp_onD] + by simp + ultimately have False + by simp + thus ?thesis .. + next + assume "z \ F" + moreover have "R z min" + using \R z x\ \R x min\ + using \transp_on (insert x F) R\[THEN transp_onD, of z x min] + using \min \ F\ \z \ F\ by simp + ultimately show ?thesis + using \\z \ F. R z min \ \ P z\ by simp + qed + qed next - show "\x\insert a A'. x \ min \ \ R x min" - using False min_is_min by blast + case False + show ?thesis + proof (intro bexI conjI ballI impI) + show "min \ insert x F" + using \min \ F\ by simp + next + show "P min" + using \P min\ by simp + next + fix z assume "z \ insert x F" and "R z min" + hence "z = x \ z \ F" + by simp + thus "\ P z" + proof (rule disjE) + assume "z = x" + hence False + using \\ R x min\ \R z min\ by simp + thus ?thesis .. + next + assume "z \ F" + thus ?thesis + using \R z min\ \\z\F. R z min \ \ P z\ by simp + qed + qed qed qed next - show "\max\insert a A'. \x\insert a A'. x \ max \ \ R max x" - proof (cases "R max a") - case True - show ?thesis - proof (intro bexI ballI impI) - show "a \ insert a A'" - by simp - next - fix x - show "x \ insert a A' \ x \ a \ \ R a x" - using True \max \ A'\ max_is_max[rule_format, of x] insert.prems(2,3) - by (auto dest: asymp_onD transp_onD) - qed - next - case False - show ?thesis - proof (rule bexI) - show "max \ insert a A'" - using \max \ A'\ by auto - next - show "\x\insert a A'. x \ max \ \ R max x" - using False max_is_max by blast - qed - qed + case False + then show ?thesis + using \\a\insert x F. P a\ + using \asymp_on (insert x F) R\[THEN asymp_onD, of x] insert_iff[of _ x F] + by blast qed + next + case False + with insert.prems have "\x \ F. P x" + by simp + with insert.IH have + "\y \ F. P y \ (\z\F. R z y \ \ P z)" + "\y \ F. P y \ (\z\F. R y z \ \ P z)" + using \asymp_on F R\ \transp_on F R\ by auto + thus ?thesis + using False by auto qed qed +qualified lemma + assumes "finite A" and "asymp_on A R" and "transp_on A R" and "A \ {}" + shows + bex_min_element: "\m \ A. \x \ A. x \ m \ \ R x m" and + bex_max_element: "\m \ A. \x \ A. x \ m \ \ R m x" + using \A \ {}\ + bex_min_element_with_property[OF assms(1,2,3), of "\_. True", simplified] + bex_max_element_with_property[OF assms(1,2,3), of "\_. True", simplified] + by blast+ + end text \The following alternative form might sometimes be easier to work with.\ @@ -2679,7 +2778,7 @@ shows "\ m \ A. \ b \ A. m \ b \ m = b" proof - obtain m where "m \ A" and m_is_max: "\x\A. x \ m \ \ m < x" - using Finite_Set.bex_max_element[OF \finite A\ \A \ {}\, of "(<)"] by auto + using Finite_Set.bex_max_element[OF \finite A\ _ _ \A \ {}\, of "(<)"] by auto moreover have "\b \ A. m \ b \ m = b" using m_is_max by (auto simp: le_less) ultimately show ?thesis @@ -2695,7 +2794,7 @@ shows "\ m \ A. \ b \ A. b \ m \ m = b" proof - obtain m where "m \ A" and m_is_min: "\x\A. x \ m \ \ x < m" - using Finite_Set.bex_min_element[OF \finite A\ \A \ {}\, of "(<)"] by auto + using Finite_Set.bex_min_element[OF \finite A\ _ _ \A \ {}\, of "(<)"] by auto moreover have "\b \ A. b \ m \ m = b" using m_is_min by (auto simp: le_less) ultimately show ?thesis diff -r f5b67198b019 -r 93f294ad42e6 src/HOL/Library/Multiset_Order.thy --- a/src/HOL/Library/Multiset_Order.thy Tue May 09 23:56:40 2023 +0200 +++ b/src/HOL/Library/Multiset_Order.thy Wed May 10 08:20:53 2023 +0200 @@ -287,7 +287,7 @@ next case False hence "\m\#M1 - M2. \x\#M1 - M2. x \ m \ \ R m x" - using Finite_Set.bex_max_element[of "set_mset (M1 - M2)" R, OF finite_set_mset _ tran asym] + using Finite_Set.bex_max_element[of "set_mset (M1 - M2)" R, OF finite_set_mset asym tran] by simp with \transp_on A R\ B_sub_A have "\y\#M2 - M1. \x\#M1 - M2. \ R y x" using \multp\<^sub>H\<^sub>O R M1 M2\[THEN multp\<^sub>H\<^sub>O_implies_one_step_strong(2)]