2043 |
2043 |
2044 lemma finite_UNIV_inj_surj: "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" |
2044 lemma finite_UNIV_inj_surj: "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" |
2045 for f :: "'a \<Rightarrow> 'a" |
2045 for f :: "'a \<Rightarrow> 'a" |
2046 by (fastforce simp:surj_def dest!: endo_inj_surj) |
2046 by (fastforce simp:surj_def dest!: endo_inj_surj) |
2047 |
2047 |
2048 corollary infinite_UNIV_nat [iff]: "\<not> finite (UNIV :: nat set)" |
2048 lemma surjective_iff_injective_gen: |
|
2049 assumes fS: "finite S" |
|
2050 and fT: "finite T" |
|
2051 and c: "card S = card T" |
|
2052 and ST: "f ` S \<subseteq> T" |
|
2053 shows "(\<forall>y \<in> T. \<exists>x \<in> S. f x = y) \<longleftrightarrow> inj_on f S" |
|
2054 (is "?lhs \<longleftrightarrow> ?rhs") |
|
2055 proof |
|
2056 assume h: "?lhs" |
|
2057 { |
|
2058 fix x y |
|
2059 assume x: "x \<in> S" |
|
2060 assume y: "y \<in> S" |
|
2061 assume f: "f x = f y" |
|
2062 from x fS have S0: "card S \<noteq> 0" |
|
2063 by auto |
|
2064 have "x = y" |
|
2065 proof (rule ccontr) |
|
2066 assume xy: "\<not> ?thesis" |
|
2067 have th: "card S \<le> card (f ` (S - {y}))" |
|
2068 unfolding c |
|
2069 proof (rule card_mono) |
|
2070 show "finite (f ` (S - {y}))" |
|
2071 by (simp add: fS) |
|
2072 have "\<lbrakk>x \<noteq> y; x \<in> S; z \<in> S; f x = f y\<rbrakk> |
|
2073 \<Longrightarrow> \<exists>x \<in> S. x \<noteq> y \<and> f z = f x" for z |
|
2074 by (case_tac "z = y \<longrightarrow> z = x") auto |
|
2075 then show "T \<subseteq> f ` (S - {y})" |
|
2076 using h xy x y f by fastforce |
|
2077 qed |
|
2078 also have " \<dots> \<le> card (S - {y})" |
|
2079 by (simp add: card_image_le fS) |
|
2080 also have "\<dots> \<le> card S - 1" using y fS by simp |
|
2081 finally show False using S0 by arith |
|
2082 qed |
|
2083 } |
|
2084 then show ?rhs |
|
2085 unfolding inj_on_def by blast |
|
2086 next |
|
2087 assume h: ?rhs |
|
2088 have "f ` S = T" |
|
2089 by (simp add: ST c card_image card_subset_eq fT h) |
|
2090 then show ?lhs by blast |
|
2091 qed |
|
2092 |
|
2093 hide_const (open) Finite_Set.fold |
|
2094 |
|
2095 |
|
2096 subsection \<open>Infinite Sets\<close> |
|
2097 |
|
2098 text \<open> |
|
2099 Some elementary facts about infinite sets, mostly by Stephan Merz. |
|
2100 Beware! Because "infinite" merely abbreviates a negation, these |
|
2101 lemmas may not work well with \<open>blast\<close>. |
|
2102 \<close> |
|
2103 |
|
2104 abbreviation infinite :: "'a set \<Rightarrow> bool" |
|
2105 where "infinite S \<equiv> \<not> finite S" |
|
2106 |
|
2107 text \<open> |
|
2108 Infinite sets are non-empty, and if we remove some elements from an |
|
2109 infinite set, the result is still infinite. |
|
2110 \<close> |
|
2111 |
|
2112 lemma infinite_UNIV_nat [iff]: "infinite (UNIV :: nat set)" |
2049 proof |
2113 proof |
2050 assume "finite (UNIV :: nat set)" |
2114 assume "finite (UNIV :: nat set)" |
2051 with finite_UNIV_inj_surj [of Suc] show False |
2115 with finite_UNIV_inj_surj [of Suc] show False |
2052 by simp (blast dest: Suc_neq_Zero surjD) |
2116 by simp (blast dest: Suc_neq_Zero surjD) |
2053 qed |
2117 qed |
2054 |
2118 |
2055 lemma infinite_UNIV_char_0: "\<not> finite (UNIV :: 'a::semiring_char_0 set)" |
2119 lemma infinite_UNIV_char_0: "infinite (UNIV :: 'a::semiring_char_0 set)" |
2056 proof |
2120 proof |
2057 assume "finite (UNIV :: 'a set)" |
2121 assume "finite (UNIV :: 'a set)" |
2058 with subset_UNIV have "finite (range of_nat :: 'a set)" |
2122 with subset_UNIV have "finite (range of_nat :: 'a set)" |
2059 by (rule finite_subset) |
2123 by (rule finite_subset) |
2060 moreover have "inj (of_nat :: nat \<Rightarrow> 'a)" |
2124 moreover have "inj (of_nat :: nat \<Rightarrow> 'a)" |
2062 ultimately have "finite (UNIV :: nat set)" |
2126 ultimately have "finite (UNIV :: nat set)" |
2063 by (rule finite_imageD) |
2127 by (rule finite_imageD) |
2064 then show False |
2128 then show False |
2065 by simp |
2129 by simp |
2066 qed |
2130 qed |
2067 |
|
2068 hide_const (open) Finite_Set.fold |
|
2069 |
|
2070 |
|
2071 subsection \<open>Infinite Sets\<close> |
|
2072 |
|
2073 text \<open> |
|
2074 Some elementary facts about infinite sets, mostly by Stephan Merz. |
|
2075 Beware! Because "infinite" merely abbreviates a negation, these |
|
2076 lemmas may not work well with \<open>blast\<close>. |
|
2077 \<close> |
|
2078 |
|
2079 abbreviation infinite :: "'a set \<Rightarrow> bool" |
|
2080 where "infinite S \<equiv> \<not> finite S" |
|
2081 |
|
2082 text \<open> |
|
2083 Infinite sets are non-empty, and if we remove some elements from an |
|
2084 infinite set, the result is still infinite. |
|
2085 \<close> |
|
2086 |
2131 |
2087 lemma infinite_imp_nonempty: "infinite S \<Longrightarrow> S \<noteq> {}" |
2132 lemma infinite_imp_nonempty: "infinite S \<Longrightarrow> S \<noteq> {}" |
2088 by auto |
2133 by auto |
2089 |
2134 |
2090 lemma infinite_remove: "infinite S \<Longrightarrow> infinite (S - {a})" |
2135 lemma infinite_remove: "infinite S \<Longrightarrow> infinite (S - {a})" |