diff --git a/thys/Irrationals_From_THEBOOK/Irrationals_From_THEBOOK.thy b/thys/Irrationals_From_THEBOOK/Irrationals_From_THEBOOK.thy --- a/thys/Irrationals_From_THEBOOK/Irrationals_From_THEBOOK.thy +++ b/thys/Irrationals_From_THEBOOK/Irrationals_From_THEBOOK.thy @@ -1,297 +1,290 @@ section \Some irrational numbers\ text \From Aigner and Ziegler, \emph{Proofs from THE BOOK} (Springer, 2018), Chapter 8, pp. 50--51.\ theory Irrationals_From_THEBOOK imports "Stirling_Formula.Stirling_Formula" begin -subsection \Library additions\ - -lemma field_differentiable_diff_const [simp,derivative_intros]: - "(-)c field_differentiable F" - unfolding field_differentiable_def - by (rule derivative_eq_intros exI | force)+ - subsection \Basic definitions and their consequences\ definition hf where "hf \ \n. \x::real. (x^n * (1-x)^n) / fact n" definition cf where "cf \ \n i. if i < n then 0 else (n choose (i-n)) * (-1)^(i-n)" text \Mere knowledge that the coefficients are integers is not enough later on.\ lemma hf_int_poly: fixes x::real shows "hf n = (\x. (1 / fact n) * (\i=0..2*n. real_of_int (cf n i) * x^i))" proof fix x have inj: "inj_on ((+)n) {..n}" by (auto simp: inj_on_def) have [simp]: "((+)n) ` {..n} = {n..2*n}" using nat_le_iff_add by fastforce have "(x^n * (-x + 1)^n) = x ^ n * (\k\n. real (n choose k) * (- x) ^ k)" unfolding binomial_ring by simp also have "\ = x ^ n * (\k\n. real_of_int ((n choose k) * (-1)^k) * x ^ k)" by (simp add: mult.assoc flip: power_minus) also have "\ = (\k\n. real_of_int ((n choose k) * (-1)^k) * x ^ (n+k))" by (simp add: sum_distrib_left mult_ac power_add) also have "\ = (\i=n..2*n. real_of_int (cf n i) * x^i)" by (simp add: sum.reindex [OF inj, simplified] cf_def) finally have "hf n x = (1 / fact n) * (\i = n..2 * n. real_of_int (cf n i) * x^i)" by (simp add: hf_def) moreover have "(\i = 0..i = 0..2 * n. real_of_int (cf n i) * x^i)" using sum.union_disjoint [of "{0..i. real_of_int (cf n i) * x^i"] by (simp add: ivl_disj_int_two(7) ivl_disj_un_two(7) mult_2) qed text \Lemma (ii) in the text has strict inequalities, but that's more work and is less useful.\ lemma assumes "0 \ x" "x \ 1" shows hf_nonneg: "0 \ hf n x" and hf_le_inverse_fact: "hf n x \ 1/fact n" using assms by (auto simp: hf_def divide_simps mult_le_one power_le_one) lemma hf_differt [iff]: "hf n differentiable at x" unfolding hf_int_poly differentiable_def by (intro derivative_eq_intros exI | simp)+ lemma deriv_sum_int: "deriv (\x. \i=0..n. real_of_int (c i) * x^i) x = (if n=0 then 0 else (\i=0..n - Suc 0. real_of_int ((int i + 1) * c (Suc i)) * x^i))" (is "deriv ?f x = (if n=0 then 0 else ?g)") proof - have "(?f has_real_derivative ?g) (at x)" if "n > 0" proof - have "(\i = 0..n. i * x ^ (i - Suc 0) * (c i)) = (\i = Suc 0..n. (real (i - Suc 0) + 1) * real_of_int (c i) * x ^ (i - Suc 0))" using that by (auto simp add: sum.atLeast_Suc_atMost intro!: sum.cong) also have "\ = sum ((\i. (real i + 1) * real_of_int (c (Suc i)) * x^i) \ (\n. n - Suc 0)) {Suc 0..Suc (n - Suc 0)}" using that by simp also have "\ = ?g" by (simp flip: sum.atLeast_atMost_pred_shift [where m=0]) finally have \
: "(\a = 0..n. a * x ^ (a - Suc 0) * (c a)) = ?g" . show ?thesis by (rule derivative_eq_intros \
| simp)+ qed then show ?thesis by (force intro: DERIV_imp_deriv) qed text \We calculate the coefficients of the $k$th derivative precisely.\ lemma hf_deriv_int_poly: "(deriv^^k) (hf n) = (\x. (1/fact n) * (\i=0..2*n-k. of_int (int(\{i<..i+k}) * cf n (i+k)) * x^i))" proof (induction k) case 0 show ?case by (simp add: hf_int_poly) next case (Suc k) define F where "F \ \x. (\i = 0..2*n - k. real_of_int (int(\{i<..i+k}) * cf n (i+k)) * x^i)" have Fd: "F field_differentiable at x" for x unfolding field_differentiable_def F_def by (rule derivative_eq_intros exI | force)+ have [simp]: "prod int {i<..Suc (i + k)} = (1 + int i) * prod int {Suc i<..Suc (i + k)}" for i by (metis Suc_le_mono atLeastSucAtMost_greaterThanAtMost le_add1 of_nat_Suc prod.head) have "deriv (\x. F x / fact n) x = (\i = 0..2 * n - Suc k. of_int (int(\{i<..i+ Suc k}) * cf n (Suc (i+k))) * x^i) / fact n" for x unfolding deriv_cdivide_right [OF Fd] by (fastforce simp add: F_def deriv_sum_int cf_def simp flip: of_int_mult intro: sum.cong) then show ?case by (simp add: Suc F_def) qed lemma hf_deriv_0: "(deriv^^k) (hf n) 0 \ \" proof (cases "n \ k") case True then obtain j where "(fact k::real) = real_of_int j * fact n" by (metis fact_dvd dvd_def mult.commute of_int_fact of_int_mult) moreover have "prod real {0<..k} = fact k" by (simp add: fact_prod atLeastSucAtMost_greaterThanAtMost) ultimately show ?thesis by (simp add: hf_deriv_int_poly dvd_def) next case False then show ?thesis by (simp add: hf_deriv_int_poly cf_def) qed lemma deriv_hf_minus: "deriv (hf n) = (\x. - deriv (hf n) (1-x))" proof fix x have "hf n = hf n \ (\x. (1-x))" by (simp add: fun_eq_iff hf_def mult.commute) then have "deriv (hf n) x = deriv (hf n \ (\x. (1-x))) x" by fastforce also have "\ = deriv (hf n) (1-x) * deriv ((-) 1) x" by (intro real_derivative_chain) auto finally show "deriv (hf n) x = - deriv (hf n) (1-x)" by simp qed lemma deriv_n_hf_diffr [iff]: "(deriv^^k) (hf n) field_differentiable at x" unfolding field_differentiable_def hf_deriv_int_poly by (rule derivative_eq_intros exI | force)+ lemma deriv_n_hf_minus: "(deriv^^k) (hf n) = (\x. (-1)^k * (deriv^^k) (hf n) (1-x))" proof (induction k) case 0 then show ?case by (simp add: fun_eq_iff hf_def) next case (Suc k) have o: "(\x. (deriv ^^ k) (hf n) (1-x)) = (deriv ^^ k) (hf n) \ (-) 1" by auto show ?case proof fix x have [simp]: "((deriv^^k) (hf n) \ (-) 1) field_differentiable at x" by (force intro: field_differentiable_compose) have "(deriv ^^ Suc k) (hf n) x = deriv (\x. (-1) ^ k * (deriv ^^ k) (hf n) (1-x)) x" by simp (metis Suc) also have "\ = (-1) ^ k * deriv (\x. (deriv ^^ k) (hf n) (1-x)) x" using o by fastforce also have "\ = (-1) ^ Suc k * (deriv ^^ Suc k) (hf n) (1-x)" by (subst o, subst deriv_chain, auto) finally show "(deriv ^^ Suc k) (hf n) x = (-1) ^ Suc k * (deriv ^^ Suc k) (hf n) (1-x)" . qed qed subsection \Towards the main result\ lemma hf_deriv_1: "(deriv^^k) (hf n) 1 \ \" by (smt (verit, best) Ints_1 Ints_minus Ints_mult Ints_power deriv_n_hf_minus hf_deriv_0) lemma hf_deriv_eq_0: "k > 2*n \ (deriv^^k) (hf n) = (\x. 0)" by (force simp add: cf_def hf_deriv_int_poly) text \The case for positive integers\ lemma exp_nat_irrational: assumes "s > 0" shows "exp (real_of_int s) \ \" proof assume "exp (real_of_int s) \ \" then obtain a b where ab: "a > 0" "b > 0" "coprime a b" and exp_s: "exp s = of_int a / of_int b" using Rats_cases' div_0 exp_not_eq_zero of_int_0 by (smt (verit, best) exp_gt_zero of_int_0_less_iff zero_less_divide_iff) define n where "n \ nat (max (a^2) (3 * s^3))" then have ns3: "s^3 \ real n / 3" by linarith have "n > 0" using \a > 0\ n_def by (smt (verit, best) zero_less_nat_eq zero_less_power) then have "s ^ (2*n+1) \ s ^ (3*n)" using \a > 0\ assms by (intro power_increasing) auto also have "\ = real_of_int(s^3) ^ n" by (simp add: power_mult) also have "\ \ (n / 3) ^ n" using assms ns3 by (simp add: power_mono) also have "\ \ (n / exp 1) ^ n" using exp_le \n > 0\ by (auto simp add: divide_simps) finally have s_le: "s ^ (2*n+1) \ (n / exp 1) ^ n" by presburger have a_less: "a < sqrt (2*pi*n)" proof - have "2*pi > 1" by (smt (z3) pi_gt_zero sin_gt_zero_02 sin_le_zero) have "a = sqrt (a^2)" by (simp add: ab(1) order_less_imp_le) also have "\ \ sqrt n" unfolding n_def by (smt (verit, ccfv_SIG) int_nat_eq of_nat_less_of_int_iff real_sqrt_le_mono) also have "\ < sqrt (2*pi*n)" by (simp add: \0 < n\ \1 < 2 * pi\) finally show ?thesis . qed have "sqrt (2*pi*n) * (n / exp 1) ^ n > a * s ^ (2*n+1)" using mult_strict_right_mono [OF a_less] mult_left_mono [OF s_le] by (smt (verit, best) s_le ab(1) assms of_int_1 of_int_le_iff of_int_mult zero_less_power) then have n: "fact n > a * s ^ (2*n+1)" using fact_bounds(1) by (smt (verit, best) \0 < n\ of_int_fact of_int_less_iff) define F where "F \ \x. \i\2*n. (-1)^i * s^(2*n-i) * (deriv^^i) (hf n) x" have Fder: "(F has_real_derivative -s * F x + s^(2*n+1) * hf n x) (at x)" for x proof - have *: "sum f {..n+n} = sum f {.. real" by (smt (verit, best) lessThan_Suc_atMost sum.lessThan_Suc that) have [simp]: "(deriv ((deriv ^^ (n+n)) (hf n)) x) = 0" using hf_deriv_eq_0 [where k= "Suc(n+n)"] by simp have \
: "(\k\n+n. (-1) ^ k * ((deriv ^^ Suc k) (hf n) x * of_int s ^ (n+n - k))) + s * (\j=0..n+n. (-1) ^ j * ((deriv ^^ j) (hf n) x * of_int s ^ (n+n - j))) = s * (hf n x * of_int s ^ (n+n))" using \n>0\ apply (subst sum_Suc_reindex) apply (simp add: algebra_simps atLeast0AtMost) apply (force simp add: * mult.left_commute [of "of_int s"] minus_nat.diff_Suc sum_distrib_left simp flip: sum.distrib intro: comm_monoid_add_class.sum.neutral split: nat.split_asm) done show ?thesis unfolding F_def apply (rule derivative_eq_intros field_differentiable_derivI | simp)+ using \
by (simp add: algebra_simps atLeast0AtMost eval_nat_numeral) qed have F01_Ints: "F 0 \ \" "F 1 \ \" by (simp_all add: F_def hf_deriv_0 hf_deriv_1 Ints_sum) define sF where "sF \ \x. exp (of_int s * x) * F x" define sF' where "sF' \ \x. of_int s ^ Suc(2*n) * (exp (of_int s * x) * hf n x)" have sF_der: "(sF has_real_derivative sF' x) (at x)" for x unfolding sF_def sF'_def by (rule refl Fder derivative_eq_intros | force simp: algebra_simps)+ let ?N = "b * integral {0..1} sF'" have sF'_integral: "(sF' has_integral sF 1 - sF 0) {0..1}" by (smt (verit) fundamental_theorem_of_calculus has_field_derivative_iff_has_vector_derivative has_vector_derivative_at_within sF_der) then have "?N = a * F 1 - b * F 0" using \b > 0\ by (simp add: integral_unique exp_s sF_def algebra_simps) also have "\ \ \" using hf_deriv_1 by (simp add: F01_Ints) finally have N_Ints: "?N \ \" . have "sF' (1/2) > 0" and ge0: "\x. x \ {0..1} \ 0 \ sF' x" using assms by (auto simp add: sF'_def hf_def) moreover have "continuous_on {0..1} sF'" unfolding sF'_def hf_def by (intro continuous_intros) auto ultimately have False if "(sF' has_integral 0) {0..1}" using has_integral_0_cbox_imp_0 [of 0 1 sF' "1/2"] that by auto then have "integral {0..1} sF' > 0" by (metis ge0 has_integral_nonneg integral_unique order_le_less sF'_integral) then have "0 < ?N" by (simp add: \b > 0\) have "integral {0..1} sF' = of_int s ^ Suc(2*n) * integral {0..1} (\x. exp (s*x) * hf n x)" unfolding sF'_def by force also have "\ \ of_int s ^ Suc(2*n) * (exp s * (1 / fact n))" proof (rule mult_left_mono) have "integral {0..1} (\x. exp (s*x) * hf n x) \ integral {0..1} (\x::real. exp s * (1/fact n))" proof (intro mult_mono integral_le) show "(\x. exp (s*x) * hf n x) integrable_on {0..1}" using \0 < ?N\ not_integrable_integral sF'_def by fastforce qed (use assms hf_nonneg hf_le_inverse_fact in auto) also have "\ = exp s * (1 / fact n)" by simp finally show "integral {0..1} (\x. exp (s*x) * hf n x) \ exp s * (1 / fact n)" . qed (use assms in auto) finally have "?N \ b * of_int s ^ Suc(2*n) * exp s * (1 / fact n)" using \b > 0\ by (simp add: sF'_def mult_ac divide_simps) also have "\ < 1" using n apply (simp add: field_simps exp_s) by (metis of_int_fact of_int_less_iff of_int_mult of_int_power) finally show False using \0 < ?N\ Ints_cases N_Ints by force qed theorem exp_irrational: fixes q::real assumes "q \ \" "q \ 0" shows "exp q \ \" proof assume q: "exp q \ \" obtain s t where "s \ 0" "t > 0" "q = of_int s / of_int t" by (metis Rats_cases' assms div_0 of_int_0) then have "(exp q) ^ (nat t) = exp s" by (smt (verit, best) exp_divide_power_eq of_nat_nat zero_less_nat_eq) moreover have "exp q ^ (nat t) \ \" by (simp add: q) ultimately show False by (smt (verit, del_insts) Rats_inverse \s \ 0\ exp_minus exp_nat_irrational of_int_of_nat) qed corollary ln_irrational: fixes q::real assumes "q \ \" "q > 0" "q \ 1" shows "ln q \ \" using assms exp_irrational [of "ln q"] exp_ln_iff [of q] by force end diff --git a/thys/Sunflowers/Erdos_Rado_Sunflower.thy b/thys/Sunflowers/Erdos_Rado_Sunflower.thy --- a/thys/Sunflowers/Erdos_Rado_Sunflower.thy +++ b/thys/Sunflowers/Erdos_Rado_Sunflower.thy @@ -1,358 +1,358 @@ (* author: R. Thiemann *) section \The Sunflower Lemma\ text \We formalize the proof of the sunflower lemma of Erd\H{o}s and Rado~\cite{erdos_rado}, as it is presented in the textbook~\cite[Chapter~6]{book}. We further integrate Exercise 6.2 from the textbook, which provides a lower bound on the existence of sunflowers.\ theory Erdos_Rado_Sunflower imports Sunflower begin text \When removing an element from all subsets, then one can afterwards add these elements to a sunflower and get a new sunflower.\ lemma sunflower_remove_element_lift: assumes S: "S \ { A - {a} | A . A \ F \ a \ A}" and sf: "sunflower S" shows "\ Sa. sunflower Sa \ Sa \ F \ card Sa = card S \ Sa = insert a ` S" proof (intro exI[of _ "insert a ` S"] conjI refl) let ?Sa = "insert a ` S" { fix B assume "B \ ?Sa" then obtain C where C: "C \ S" and B: "B = insert a C" by auto from C S obtain T where "T \ F" "a \ T" "C = T - {a}" by auto with B have "B = T" by auto with \T \ F\ have "B \ F" by auto } thus SaF: "?Sa \ F" by auto have inj: "inj_on (insert a) S" using S by (intro inj_on_inverseI[of _ "\ B. B - {a}"], auto) thus "card ?Sa = card S" by (rule card_image) show "sunflower ?Sa" unfolding sunflower_def proof (intro allI, intro impI) fix x assume "\C D. C \ ?Sa \ D \ ?Sa \ C \ D \ x \ C \ x \ D" then obtain C D where *: "C \ ?Sa" "D \ ?Sa" "C \ D" "x \ C" "x \ D" by auto from *(1-2) obtain C' D' where **: "C' \ S" "D' \ S" "C = insert a C'" "D = insert a D'" by auto with \C \ D\ inj have CD': "C' \ D'" by auto show "\E. E \ ?Sa \ x \ E" proof (cases "x = a") case False with * ** have "x \ C'" "x \ D'" by auto with ** CD' have "\C D. C \ S \ D \ S \ C \ D \ x \ C \ x \ D" by auto from sf[unfolded sunflower_def, rule_format, OF this] show ?thesis by auto qed auto qed qed text \The sunflower-lemma of Erd\H{o}s and Rado: if a set has a certain size and all elements have the same cardinality, then a sunflower exists.\ lemma Erdos_Rado_sunflower_same_card: assumes "\ A \ F. finite A \ card A = k" and "card F > (r - 1)^k * fact k" shows "\ S. S \ F \ sunflower S \ card S = r \ {} \ S" using assms proof (induct k arbitrary: F) case 0 hence "F = {{}} \ F = {}" "card F \ 2" by auto hence False by auto thus ?case by simp next case (Suc k F) define pd_sub :: "'a set set \ nat \ bool" where "pd_sub = (\ G t. G \ F \ card G = t \ pairwise disjnt G \ {} \ G)" show ?case proof (cases "\ t G. pd_sub G t \ t \ r") case True then obtain t G where pd_sub: "pd_sub G t" and t: "t \ r" by auto from pd_sub[unfolded pd_sub_def] pairwise_disjnt_imp_sunflower have *: "G \ F" "card G = t" "sunflower G" "{} \ G" by auto from t \card G = t\ obtain H where "H \ G" "card H = r" by (metis obtain_subset_with_card_n) with sunflower_subset[OF \H \ G\] * show ?thesis by blast next case False define P where "P = (\ t. \ G. pd_sub G t)" have ex: "\ t. P t" unfolding P_def by (intro exI[of _ 0] exI[of _ "{}"], auto simp: pd_sub_def) have large': "\ t. P t \ t < r" using False unfolding P_def by auto hence large: "\ t. P t \ t \ r" by fastforce define t where "t = (GREATEST t. P t)" from GreatestI_ex_nat[OF ex large, folded t_def] have Pt: "P t" . from Greatest_le_nat[of P, OF _ large] have greatest: "\ s. P s \ s \ t" unfolding t_def by auto from large'[OF Pt] have tr: "t \ r - 1" by simp from Pt[unfolded P_def pd_sub_def] obtain G where cardG: "card G = t" and disj: "pairwise disjnt G" and GF: "G \ F" by blast define A where "A = (\ G)" from Suc(3) have "card F > 0" by simp hence "finite F" by (rule card_ge_0_finite) from GF \finite F\ have finG: "finite G" by (rule finite_subset) - have "card (\ G) \ sum card G" - by (rule card_Union_le_sum_card, insert Suc(2) GF, auto) - also have "\ \ of_nat (card G) * Suc k" - by (rule sum_bounded_above, insert GF Suc(2), auto) + have "card (\ G) \ sum card G" + using card_Union_le_sum_card by blast + also have "\ \ of_nat (card G) * Suc k" + by (metis GF Suc.prems(1) le_Suc_eq subsetD sum_bounded_above) also have "\ \ (r - 1) * Suc k" using tr[folded cardG] by (metis id_apply mult_le_mono1 of_nat_eq_id) finally have cardA: "card A \ (r - 1) * Suc k" unfolding A_def . { fix B assume *: "B \ F" with Suc(2) have nE: "B \ {}" by auto from Suc(2) have eF: "{} \ F" by auto have "B \ A \ {}" proof assume dis: "B \ A = {}" hence disj: "pairwise disjnt ({B} \ G)" using disj unfolding A_def by (smt (verit, ccfv_SIG) Int_commute Un_iff Union_disjoint disjnt_def pairwise_def singleton_iff) from nE dis have "B \ G" unfolding A_def by auto with finG have c: "card ({B} \ G) = Suc t" by (simp add: cardG) have "P (Suc t)" unfolding P_def pd_sub_def by (intro exI[of _ "{B} \ G"], insert eF disj c * GF, auto) with greatest show False by force qed } note overlap = this have "F \ {}" using Suc(2-) by auto with overlap have Ane: "A \ {}" unfolding A_def by auto have "finite A" unfolding A_def using finG Suc(2-) GF by auto let ?g = "\ B x. x \ B \ A" define f where "f = (\ B. SOME x. ?g B x)" have "f \ F \ A" proof fix B assume "B \ F" from overlap[OF this] have "\ x. ?g B x" unfolding A_def by auto from someI_ex[OF this] show "f B \ A" unfolding f_def by auto qed from pigeonhole_card[OF this \finite F\ \finite A\ Ane] obtain a where a: "a \ A" and le: "card F \ card (f -` {a} \ F) * card A" by auto { fix S assume "S \ F" "f S \ {a}" with someI_ex[of "?g S"] a overlap[OF this(1)] have "a \ S" unfolding f_def by auto } note FaS = this let ?F = "{S - {a} | S . S \ F \ f S \ {a}}" from cardA have "((r - 1) ^ k * fact k) * card A \ ((r - 1) ^ k * fact k) * ((r - 1) * Suc k)" by simp also have "\ = (r - 1) ^ (Suc k) * fact (Suc k)" by (metis (no_types, lifting) fact_Suc mult.assoc mult.commute of_nat_id power_Suc2) also have "\ < card (f -` {a} \ F) * card A" using Suc(3) le by auto also have "f -` {a} \ F = {S \ F. f S \ {a}}" by auto also have "card \ = card ((\ S. S - {a}) ` {S \ F. f S \ {a}})" by (subst card_image; intro inj_onI refl, insert FaS) auto also have "(\ S. S - {a}) ` {S \ F. f S \ {a}} = ?F" by auto finally have lt: "(r - 1) ^ k * fact k < card ?F" by simp have "\ A \ ?F. finite A \ card A = k" using Suc(2) FaS by auto from Suc(1)[OF this lt] obtain S where "sunflower S" "card S = r" "S \ ?F" by auto from \S \ ?F\ FaS have "S \ {A - {a} |A. A \ F \ a \ A}" by auto from sunflower_remove_element_lift[OF this \sunflower S\] \card S = r\ show ?thesis by auto qed qed text \Using @{thm [source] sunflower_card_subset_lift} we can easily replace the condition that the cardinality is exactly @{term k} by the requirement that the cardinality is at most @{term k}. However, then @{term "{} \ S"} cannot be ensured. Consider @{term "(r :: nat) = 1 \ (k :: nat) > 0 \ F = {{}}"}.\ lemma Erdos_Rado_sunflower: assumes "\ A \ F. finite A \ card A \ k" and "card F > (r - 1)^k * fact k" shows "\ S. S \ F \ sunflower S \ card S = r" by (rule sunflower_card_subset_lift[OF _ assms], metis Erdos_Rado_sunflower_same_card) text \We further provide a lower bound on the existence of sunflowers, i.e., Exercise 6.2 of the textbook~\cite{book}. To be more precise, we prove that there is a set of sets of cardinality @{term \(r - 1 :: nat)^k\}, where each element is a set of cardinality @{term k}, such that there is no subset which is a sunflower with cardinality of at least @{term r}.\ lemma sunflower_lower_bound: assumes inf: "infinite (UNIV :: 'a set)" and r: "r \ 0" and rk: "r = 1 \ k \ 0" shows "\ F. card F = (r - 1)^k \ finite F \ (\ A \ F. finite (A :: 'a set) \ card A = k) \ (\ S. S \ F \ sunflower S \ card S \ r)" proof (cases "r = 1") case False with r have r: "r > 1" by auto show ?thesis proof (induct k) case 0 have id: "S \ {{}} \ (S = {} \ S = {{}})" for S :: "'a set set" by auto show ?case using r by (intro exI[of _ "{{}}"], auto simp: id) next case (Suc k) then obtain F where cardF: "card F = (r - 1) ^ k" and fin: "finite F" and AF: "\ A. (A :: 'a set) \ F \ finite A \ card A = k" and sf: "\ (\S\F. sunflower S \ r \ card S)" by metis text \main idea: get @{term "k-1 :: nat"} fresh elements and add one of these to all elements of F\ have "finite (\ F)" using fin AF by simp hence "infinite (UNIV - \ F)" using inf by simp from infinite_arbitrarily_large[OF this, of "r - 1"] obtain New where New: "finite New" "card New = r - 1" "New \ \ F = {}" by auto define G where "G = (\ (A, a). insert a A) ` (F \ New)" show ?case proof (intro exI[of _ G] conjI) show "finite G" using New fin unfolding G_def by simp have "card G = card (F \ New)" unfolding G_def proof ((subst card_image; (intro refl)?), intro inj_onI, clarsimp, goal_cases) case (1 A a B b) hence ab: "a = b" using New by auto from 1(1) have "insert a A - {a} = insert b B - {a}" by simp also have "insert a A - {a} = A" using New 1 by auto also have "insert b B - {a} = B" using New 1 ab[symmetric] by auto finally show ?case using ab by auto qed also have "\ = card F * card New" using New fin by auto finally show "card G = (r - 1) ^ Suc k" unfolding cardF New by simp { fix B assume "B \ G" then obtain a A where G: "a \ New" "A \ F" "B = insert a A" unfolding G_def by auto with AF[of A] New have "finite B" "card B = Suc k" by (auto simp: card_insert_if) } thus "\A\G. finite A \ card A = Suc k" by auto show "\ (\S\G. sunflower S \ r \ card S)" proof (intro notI, elim exE conjE) fix S assume *: "S \ G" "sunflower S" "r \ card S" define g where "g B = (SOME a. a \ New \ a \ B)" for B { fix B assume "B \ S" with \S \ G\ have "B \ G" by auto hence "\ a. a \ New \ a \ B" unfolding G_def by auto from someI_ex[OF this, folded g_def] have "g B \ New" "g B \ B" by auto } note gB = this have "card (g ` S) \ card New" by (rule card_mono, insert New gB, auto) also have "\ < r" unfolding New using r by simp also have "\ \ card S" by fact finally have "card (g ` S) < card S" . from pigeonhole[OF this] have "\ inj_on g S" . then obtain B1 B2 where B12: "B1 \ S" "B2 \ S" "B1 \ B2" "g B1 = g B2" unfolding inj_on_def by auto define a where "a = g B2" from B12 gB[of B1] gB[of B2] have a: "a \ New" "a \ B1" "a \ B2" unfolding a_def by auto with B12 have "\B1 B2. B1 \ S \ B2 \ S \ B1 \ B2 \ a \ B1 \ a \ B2" unfolding a_def by blast from \sunflower S\[unfolded sunflower_def, rule_format, OF this] have aS: "B \ S \ a \ B" for B by auto define h where "h B = B - {a}" for B define T where "T = h ` S" have "\S\F. sunflower S \ r \ card S" proof (intro exI[of _ T] conjI) { fix B assume "B \ S" have hB: "h B = B - {a}" unfolding h_def T_def by auto from aS \B \ S\ have aB: "a \ B" by auto from \B \ S\ \S \ G\ obtain a' A where AF: "A \ F" and B: "B = insert a' A" and a': "a' \ New" unfolding G_def by force from aB B a' New AF a(1) hB AF have "insert a (h B) = B" "h B = A" by auto hence "insert a (h B) = B" "h B \ F" "insert a (h B) \ S" using AF \B \ S\ by auto } note main = this have CTS: "C \ T \ insert a C \ S" for C using main unfolding T_def by force show "T \ F" unfolding T_def using main by auto have "r \ card S" by fact also have "\ = card T" unfolding T_def by (subst card_image, intro inj_on_inverseI[of _ "insert a"], insert main, auto) finally show "r \ card T" . show "sunflower T" unfolding sunflower_def proof (intro allI impI, elim exE conjE, goal_cases) case (1 x C C1 C2) from CTS[OF \C1 \ T\] CTS[OF \C2 \ T\] CTS[OF \C \ T\] have *: "insert a C1 \ S" "insert a C2 \ S" "insert a C \ S" by auto from 1 have "insert a C1 \ insert a C2" using main unfolding T_def by auto hence "\A B. A \ S \ B \ S \ A \ B \ x \ A \ x \ B" using * 1 by auto from \sunflower S\[unfolded sunflower_def, rule_format, OF this *(3)] have "x \ insert a C" . with 1 show "x \ C" unfolding T_def h_def by auto qed qed with sf show False .. qed qed qed next case r: True with rk have "k \ 0" by auto then obtain l where k: "k = Suc l" by (cases k, auto) show ?thesis unfolding r k by (intro exI[of _ "{}"], auto) qed text \The difference between the lower and the upper bound on the existence of sunflowers as they have been formalized is @{term \fact k\}. There is more recent work with tighter bounds \cite{sunflower_new}, but we only integrate the initial result of Erd\H{o}s and Rado in this theory.\ text \We further provide the Erd\H{o}s Rado lemma lifted to obtain non-empty cores or cores of arbitrary cardinality.\ lemma Erdos_Rado_sunflower_card_core: assumes "finite E" and "\ A \ F. A \ E \ s \ card A \ card A \ k" and "card F > (card E choose s) * (r - 1)^k * fact k" and "s \ 0" and "r \ 0" shows "\ S. S \ F \ sunflower S \ card S = r \ card (\ S) \ s" by (rule sunflower_card_core_lift[OF assms(1) _ assms(2) _ assms(4-5), of "(r - 1)^k * fact k"], rule Erdos_Rado_sunflower, insert assms(3), auto simp: ac_simps) lemma Erdos_Rado_sunflower_nonempty_core: assumes "finite E" and "\ A \ F. A \ E \ card A \ k" and "{} \ F" and "card F > card E * (r - 1)^k * fact k" shows "\ S. S \ F \ sunflower S \ card S = r \ \ S \ {}" by (rule sunflower_nonempty_core_lift[OF assms(1) _ assms(2-3), of "(r - 1)^k * fact k"], rule Erdos_Rado_sunflower, insert assms(4), auto simp: ac_simps) end