1343 ultimately have "bij_betw (g \<circ> f) A B" |
1343 ultimately have "bij_betw (g \<circ> f) A B" |
1344 by (auto simp: bij_betw_trans) |
1344 by (auto simp: bij_betw_trans) |
1345 thus "(\<exists>f. bij_betw f A B)" by blast |
1345 thus "(\<exists>f. bij_betw f A B)" by blast |
1346 qed (auto simp: bij_betw_same_card) |
1346 qed (auto simp: bij_betw_same_card) |
1347 |
1347 |
1348 lemma inj_on_iff_card_le: |
|
1349 assumes FIN: "finite A" and FIN': "finite B" |
|
1350 shows "(\<exists>f. inj_on f A \<and> f ` A \<le> B) = (card A \<le> card B)" |
|
1351 proof (safe intro!: card_inj_on_le) |
|
1352 assume *: "card A \<le> card B" |
|
1353 obtain f where 1: "inj_on f A" and 2: "f ` A = {0 ..< card A}" |
|
1354 using FIN ex_bij_betw_finite_nat unfolding bij_betw_def by force |
|
1355 moreover obtain g where "inj_on g {0 ..< card B}" and 3: "g ` {0 ..< card B} = B" |
|
1356 using FIN' ex_bij_betw_nat_finite unfolding bij_betw_def by force |
|
1357 ultimately have "inj_on g (f ` A)" using subset_inj_on[of g _ "f ` A"] * by force |
|
1358 hence "inj_on (g \<circ> f) A" using 1 comp_inj_on by blast |
|
1359 moreover |
|
1360 {have "{0 ..< card A} \<le> {0 ..< card B}" using * by force |
|
1361 with 2 have "f ` A \<le> {0 ..< card B}" by blast |
|
1362 hence "(g \<circ> f) ` A \<le> B" unfolding comp_def using 3 by force |
|
1363 } |
|
1364 ultimately show "(\<exists>f. inj_on f A \<and> f ` A \<le> B)" by blast |
|
1365 qed (insert assms, auto) |
|
1366 |
|
1367 lemma subset_eq_atLeast0_lessThan_card: |
1348 lemma subset_eq_atLeast0_lessThan_card: |
1368 fixes n :: nat |
1349 fixes n :: nat |
1369 assumes "N \<subseteq> {0..<n}" |
1350 assumes "N \<subseteq> {0..<n}" |
1370 shows "card N \<le> n" |
1351 shows "card N \<le> n" |
1371 proof - |
1352 proof - |
1372 from assms finite_lessThan have "card N \<le> card {0..<n}" |
1353 from assms finite_lessThan have "card N \<le> card {0..<n}" |
1373 using card_mono by blast |
1354 using card_mono by blast |
1374 then show ?thesis by simp |
1355 then show ?thesis by simp |
|
1356 qed |
|
1357 |
|
1358 text \<open>Relational version of @{thm [source] card_inj_on_le}:\<close> |
|
1359 lemma card_le_if_inj_on_rel: |
|
1360 assumes "finite B" |
|
1361 "\<And>a. a \<in> A \<Longrightarrow> \<exists>b. b\<in>B \<and> r a b" |
|
1362 "\<And>a1 a2 b. \<lbrakk> a1 \<in> A; a2 \<in> A; b \<in> B; r a1 b; r a2 b \<rbrakk> \<Longrightarrow> a1 = a2" |
|
1363 shows "card A \<le> card B" |
|
1364 proof - |
|
1365 let ?P = "\<lambda>a b. b \<in> B \<and> r a b" |
|
1366 let ?f = "\<lambda>a. SOME b. ?P a b" |
|
1367 have 1: "?f ` A \<subseteq> B" by (auto intro: someI2_ex[OF assms(2)]) |
|
1368 have "inj_on ?f A" |
|
1369 proof (auto simp: inj_on_def) |
|
1370 fix a1 a2 assume asms: "a1 \<in> A" "a2 \<in> A" "?f a1 = ?f a2" |
|
1371 have 0: "?f a1 \<in> B" using "1" \<open>a1 \<in> A\<close> by blast |
|
1372 have 1: "r a1 (?f a1)" using someI_ex[OF assms(2)[OF \<open>a1 \<in> A\<close>]] by blast |
|
1373 have 2: "r a2 (?f a1)" using someI_ex[OF assms(2)[OF \<open>a2 \<in> A\<close>]] asms(3) by auto |
|
1374 show "a1 = a2" using assms(3)[OF asms(1,2) 0 1 2] . |
|
1375 qed |
|
1376 with 1 show ?thesis using card_inj_on_le[of ?f A B] assms(1) by simp |
1375 qed |
1377 qed |
1376 |
1378 |
1377 |
1379 |
1378 subsection \<open>Intervals of integers\<close> |
1380 subsection \<open>Intervals of integers\<close> |
1379 |
1381 |