# HG changeset patch # User paulson # Date 1635261723 -3600 # Node ID a0ab0dc28d3c19029fa8b7c89ed4a71df8dcc2a5 # Parent ee92a47b47cbf214c319128bb14e472491712f7c# Parent 00ffae972fc0625bdd9939399254751b02367824 merged diff -r ee92a47b47cb -r a0ab0dc28d3c src/HOL/Equiv_Relations.thy --- a/src/HOL/Equiv_Relations.thy Tue Oct 26 15:11:40 2021 +0200 +++ b/src/HOL/Equiv_Relations.thy Tue Oct 26 16:22:03 2021 +0100 @@ -82,6 +82,9 @@ lemma eq_equiv_class_iff: "equiv A r \ x \ A \ y \ A \ r``{x} = r``{y} \ (x, y) \ r" by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type) +lemma disjnt_equiv_class: "equiv A r \ disjnt (r``{a}) (r``{b}) \ (a, b) \ r" + by (auto dest: equiv_class_self simp: equiv_class_eq_iff disjnt_def) + subsection \Quotients\ diff -r ee92a47b47cb -r a0ab0dc28d3c src/HOL/Library/Disjoint_Sets.thy --- a/src/HOL/Library/Disjoint_Sets.thy Tue Oct 26 15:11:40 2021 +0200 +++ b/src/HOL/Library/Disjoint_Sets.thy Tue Oct 26 16:22:03 2021 +0100 @@ -4,24 +4,12 @@ section \Partitions and Disjoint Sets\ theory Disjoint_Sets - imports Main + imports FuncSet begin -lemma range_subsetD: "range f \ B \ f i \ B" - by blast - -lemma Int_Diff_disjoint: "A \ B \ (A - B) = {}" - by blast - -lemma Int_Diff_Un: "A \ B \ (A - B) = A" - by blast - -lemma mono_Un: "mono A \ (\i\n. A i) = A n" +lemma mono_imp_UN_eq_last: "mono A \ (\i\n. A i) = A n" unfolding mono_def by auto -lemma disjnt_equiv_class: "equiv A r \ disjnt (r``{a}) (r``{b}) \ (a, b) \ r" - by (auto dest: equiv_class_self simp: equiv_class_eq_iff disjnt_def) - subsection \Set of Disjoint Sets\ abbreviation disjoint :: "'a set set \ bool" where "disjoint \ pairwise disjnt" @@ -304,7 +292,7 @@ by (simp add: disjointed_def) lemma disjointed_mono: "mono A \ disjointed A (Suc n) = A (Suc n) - A n" - using mono_Un[of A] by (simp add: disjointed_def atLeastLessThanSuc_atLeastAtMost atLeast0AtMost) + using mono_imp_UN_eq_last[of A] by (simp add: disjointed_def atLeastLessThanSuc_atLeastAtMost atLeast0AtMost) subsection \Partitions\ @@ -496,4 +484,115 @@ using assms by (auto simp: refines_def disjoint_def partition_on_def) qed +subsection \The coarsest common refinement of a set of partitions\ + +definition common_refinement :: "'a set set set \ 'a set set" + where "common_refinement \

\ (\f \ (\\<^sub>E P\\

. P). {\ (f ` \

)}) - {{}}" + +text \With non-extensional function space\ +lemma common_refinement: "common_refinement \

= (\f \ (\ P\\

. P). {\ (f ` \

)}) - {{}}" + (is "?lhs = ?rhs") +proof + show "?rhs \ ?lhs" + apply (clarsimp simp add: common_refinement_def PiE_def Ball_def) + by (metis restrict_Pi_cancel image_restrict_eq restrict_extensional) +qed (auto simp add: common_refinement_def PiE_def) + +lemma common_refinement_exists: "\X \ common_refinement \

; P \ \

\ \ \R\P. X \ R" + by (auto simp add: common_refinement) + +lemma Union_common_refinement: "\ (common_refinement \

) = (\ P\\

. \P)" +proof + show "(\ P\\

. \P) \ \ (common_refinement \

)" + proof (clarsimp simp: common_refinement) + fix x + assume "\P\\

. \X\P. x \ X" + then obtain F where F: "\P. P\\

\ F P \ P \ x \ F P" + by metis + then have "x \ \ (F ` \

)" + by force + with F show "\X\(\x\\ P\\

. P. {\ (x ` \

)}) - {{}}. x \ X" + by (auto simp add: Pi_iff Bex_def) + qed +qed (auto simp: common_refinement_def) + +lemma partition_on_common_refinement: + assumes A: "\P. P \ \

\ partition_on A P" and "\

\ {}" + shows "partition_on A (common_refinement \

)" +proof (rule partition_onI) + show "\ (common_refinement \

) = A" + using assms by (simp add: partition_on_def Union_common_refinement) + fix P Q + assume "P \ common_refinement \

" and "Q \ common_refinement \

" and "P \ Q" + then obtain f g where f: "f \ (\\<^sub>E P\\

. P)" and P: "P = \ (f ` \

)" and "P \ {}" + and g: "g \ (\\<^sub>E P\\

. P)" and Q: "Q = \ (g ` \

)" and "Q \ {}" + by (auto simp add: common_refinement_def) + have "f=g" if "x \ P" "x \ Q" for x + proof (rule extensionalityI [of _ \

]) + fix R + assume "R \ \

" + with that P Q f g A [unfolded partition_on_def, OF \R \ \

\] + show "f R = g R" + by (metis INT_E Int_iff PiE_iff disjointD emptyE) + qed (use PiE_iff f g in auto) + then show "disjnt P Q" + by (metis P Q \P \ Q\ disjnt_iff) +qed (simp add: common_refinement_def) + +lemma refines_common_refinement: + assumes "\P. P \ \

\ partition_on A P" "P \ \

" + shows "refines A (common_refinement \

) P" + unfolding refines_def +proof (intro conjI strip) + fix X + assume "X \ common_refinement \

" + with assms show "\Y\P. X \ Y" + by (auto simp: common_refinement_def) +qed (use assms partition_on_common_refinement in auto) + +text \The common refinement is itself refined by any other\ +lemma common_refinement_coarsest: + assumes "\P. P \ \

\ partition_on A P" "partition_on A R" "\P. P \ \

\ refines A R P" "\

\ {}" + shows "refines A R (common_refinement \

)" + unfolding refines_def +proof (intro conjI ballI partition_on_common_refinement) + fix X + assume "X \ R" + have "\p \ P. X \ p" if "P \ \

" for P + by (meson \X \ R\ assms(3) refines_def that) + then obtain F where f: "\P. P \ \

\ F P \ P \ X \ F P" + by metis + with \partition_on A R\ \X \ R\ \\

\ {}\ + have "\ (F ` \

) \ common_refinement \

" + apply (simp add: partition_on_def common_refinement Pi_iff Bex_def) + by (metis (no_types, lifting) cINF_greatest subset_empty) + with f show "\Y\common_refinement \

. X \ Y" + by (metis \\

\ {}\ cINF_greatest) +qed (use assms in auto) + +lemma finite_common_refinement: + assumes "finite \

" "\P. P \ \

\ finite P" + shows "finite (common_refinement \

)" +proof - + have "finite (\\<^sub>E P\\

. P)" + by (simp add: assms finite_PiE) + then show ?thesis + by (auto simp: common_refinement_def) +qed + +lemma card_common_refinement: + assumes "finite \

" "\P. P \ \

\ finite P" + shows "card (common_refinement \

) \ (\P \ \

. card P)" +proof - + have "card (common_refinement \

) \ card (\f \ (\\<^sub>E P\\

. P). {\ (f ` \

)})" + unfolding common_refinement_def by (meson card_Diff1_le) + also have "\ \ (\f\(\\<^sub>E P\\

. P). card{\ (f ` \

)})" + by (metis assms finite_PiE card_UN_le) + also have "\ = card(\\<^sub>E P\\

. P)" + by simp + also have "\ = (\P \ \

. card P)" + by (simp add: assms(1) card_PiE dual_order.eq_iff) + finally show ?thesis . +qed + end diff -r ee92a47b47cb -r a0ab0dc28d3c src/HOL/Set.thy --- a/src/HOL/Set.thy Tue Oct 26 15:11:40 2021 +0200 +++ b/src/HOL/Set.thy Tue Oct 26 16:22:03 2021 +0100 @@ -973,6 +973,9 @@ lemma rangeE [elim?]: "b \ range (\x. f x) \ (\x. b = f x \ P) \ P" by (rule imageE) +lemma range_subsetD: "range f \ B \ f i \ B" + by blast + lemma full_SetCompr_eq: "{u. \x. u = f x} = range f" by auto @@ -1570,6 +1573,12 @@ text \\<^medskip> Miscellany.\ +lemma Int_Diff_disjoint: "A \ B \ (A - B) = {}" + by blast + +lemma Int_Diff_Un: "A \ B \ (A - B) = A" + by blast + lemma set_eq_subset: "A = B \ A \ B \ B \ A" by blast