src/HOL/Finite_Set.thy
changeset 13490 44bdc150211b
parent 13421 8fcdf4a26468
child 13571 d76a798281f4
equal deleted inserted replaced
13489:79d117a158bd 13490:44bdc150211b
   114   apply (subst insert_is_Un)
   114   apply (subst insert_is_Un)
   115   apply (simp only: finite_Un)
   115   apply (simp only: finite_Un)
   116   apply blast
   116   apply blast
   117   done
   117   done
   118 
   118 
   119 lemma finite_imageI: "finite F ==> finite (h ` F)"
   119 lemma finite_imageI[simp]: "finite F ==> finite (h ` F)"
   120   -- {* The image of a finite set is finite. *}
   120   -- {* The image of a finite set is finite. *}
   121   by (induct set: Finites) simp_all
   121   by (induct set: Finites) simp_all
   122 
   122 
   123 lemma finite_range_imageI:
   123 lemma finite_range_imageI:
   124     "finite (range g) ==> finite (range (%x. f (g x)))"
   124     "finite (range g) ==> finite (range (%x. f (g x)))"
   880   apply (drule spec)
   880   apply (drule spec)
   881   apply (erule (1) notE impE)
   881   apply (erule (1) notE impE)
   882   apply (simp add: Ball_def)
   882   apply (simp add: Ball_def)
   883   done
   883   done
   884 
   884 
       
   885 subsubsection{* Min and Max of finite linearly ordered sets *}
       
   886 
       
   887 text{* Seemed easier to define directly than via fold. *}
       
   888 
       
   889 lemma ex_Max: fixes S :: "('a::linorder)set"
       
   890   assumes fin: "finite S" shows "S \<noteq> {} \<Longrightarrow> \<exists>m\<in>S. \<forall>s \<in> S. s \<le> m"
       
   891 using fin
       
   892 proof (induct)
       
   893   case empty thus ?case by simp
       
   894 next
       
   895   case (insert S x)
       
   896   show ?case
       
   897   proof (cases)
       
   898     assume "S = {}" thus ?thesis by simp
       
   899   next
       
   900     assume nonempty: "S \<noteq> {}"
       
   901     then obtain m where m: "m\<in>S" "\<forall>s\<in>S. s \<le> m" using insert by blast
       
   902     show ?thesis
       
   903     proof (cases)
       
   904       assume "x \<le> m" thus ?thesis using m by blast
       
   905     next
       
   906       assume "\<not> x \<le> m" thus ?thesis using m
       
   907 	by(simp add:linorder_not_le order_less_le)(blast intro: order_trans)
       
   908     qed
       
   909   qed
       
   910 qed
       
   911 
       
   912 lemma ex_Min: fixes S :: "('a::linorder)set"
       
   913   assumes fin: "finite S" shows "S \<noteq> {} \<Longrightarrow> \<exists>m\<in>S. \<forall>s \<in> S. m \<le> s"
       
   914 using fin
       
   915 proof (induct)
       
   916   case empty thus ?case by simp
       
   917 next
       
   918   case (insert S x)
       
   919   show ?case
       
   920   proof (cases)
       
   921     assume "S = {}" thus ?thesis by simp
       
   922   next
       
   923     assume nonempty: "S \<noteq> {}"
       
   924     then obtain m where m: "m\<in>S" "\<forall>s\<in>S. m \<le> s" using insert by blast
       
   925     show ?thesis
       
   926     proof (cases)
       
   927       assume "m \<le> x" thus ?thesis using m by blast
       
   928     next
       
   929       assume "\<not> m \<le> x" thus ?thesis using m
       
   930 	by(simp add:linorder_not_le order_less_le)(blast intro: order_trans)
       
   931     qed
       
   932   qed
       
   933 qed
       
   934 
       
   935 constdefs
       
   936  Min :: "('a::linorder)set \<Rightarrow> 'a"
       
   937 "Min S  \<equiv>  THE m. m \<in> S \<and> (\<forall>s \<in> S. m \<le> s)"
       
   938 
       
   939  Max :: "('a::linorder)set \<Rightarrow> 'a"
       
   940 "Max S  \<equiv>  THE m. m \<in> S \<and> (\<forall>s \<in> S. s \<le> m)"
       
   941 
       
   942 lemma Min[simp]: assumes a: "finite S" "S \<noteq> {}"
       
   943                  shows "Min S \<in> S \<and> (\<forall>s \<in> S. Min S \<le> s)" (is "?P(Min S)")
       
   944 proof (unfold Min_def, rule theI')
       
   945   show "\<exists>!m. ?P m"
       
   946   proof (rule ex_ex1I)
       
   947     show "\<exists>m. ?P m" using ex_Min[OF a] by blast
       
   948   next
       
   949     fix m1 m2 assume "?P m1" "?P m2"
       
   950     thus "m1 = m2" by (blast dest:order_antisym)
       
   951   qed
       
   952 qed
       
   953 
       
   954 lemma Max[simp]: assumes a: "finite S" "S \<noteq> {}"
       
   955                  shows "Max S \<in> S \<and> (\<forall>s \<in> S. s \<le> Max S)" (is "?P(Max S)")
       
   956 proof (unfold Max_def, rule theI')
       
   957   show "\<exists>!m. ?P m"
       
   958   proof (rule ex_ex1I)
       
   959     show "\<exists>m. ?P m" using ex_Max[OF a] by blast
       
   960   next
       
   961     fix m1 m2 assume "?P m1" "?P m2"
       
   962     thus "m1 = m2" by (blast dest:order_antisym)
       
   963   qed
       
   964 qed
       
   965 
   885 
   966 
   886 text {*
   967 text {*
   887   \medskip Basic theorem about @{text "choose"}.  By Florian
   968   \medskip Basic theorem about @{text "choose"}.  By Florian
   888   Kammüller, tidied by LCP.
   969   Kammüller, tidied by LCP.
   889 *}
   970 *}