19944

1 
(* Title: HOL/Library/Ramsey.thy


2 
ID: $Id$


3 
Author: Tom Ridge. Converted to structured Isar by L C Paulson


4 
*)


5 


6 
header "Ramsey's Theorem"


7 


8 
theory Ramsey imports Main begin


9 


10 


11 
subsection{*``Axiom'' of Dependent Choice*}


12 


13 
consts choice :: "('a => bool) => (('a * 'a) set) => nat => 'a"


14 
{*An integerindexed chain of choices*}


15 
primrec


16 
choice_0: "choice P r 0 = (SOME x. P x)"


17 


18 
choice_Suc: "choice P r (Suc n) = (SOME y. P y & (choice P r n, y) \<in> r)"


19 


20 


21 
lemma choice_n:


22 
assumes P0: "P x0"


23 
and Pstep: "!!x. P x ==> \<exists>y. P y & (x,y) \<in> r"


24 
shows "P (choice P r n)"


25 
proof (induct n)


26 
case 0 show ?case by (force intro: someI P0)


27 
next


28 
case (Suc n) thus ?case by (auto intro: someI2_ex [OF Pstep])


29 
qed


30 


31 
lemma dependent_choice:


32 
assumes trans: "trans r"


33 
and P0: "P x0"


34 
and Pstep: "!!x. P x ==> \<exists>y. P y & (x,y) \<in> r"


35 
shows "\<exists>f::nat=>'a. (\<forall>n. P (f n)) & (\<forall>n m. n<m > (f n, f m) \<in> r)"


36 
proof (intro exI conjI)


37 
show "\<forall>n. P (choice P r n)" by (blast intro: choice_n [OF P0 Pstep])


38 
next


39 
have PSuc: "\<forall>n. (choice P r n, choice P r (Suc n)) \<in> r"


40 
using Pstep [OF choice_n [OF P0 Pstep]]


41 
by (auto intro: someI2_ex)


42 
show "\<forall>n m. n<m > (choice P r n, choice P r m) \<in> r"


43 
proof (intro strip)


44 
fix n and m::nat


45 
assume less: "n<m"


46 
show "(choice P r n, choice P r m) \<in> r" using PSuc


47 
by (auto intro: less_Suc_induct [OF less] transD [OF trans])


48 
qed


49 
qed


50 


51 


52 
subsection {*Partitions of a Set*}


53 


54 
constdefs part :: "nat => nat => 'a set => ('a set => nat) => bool"


55 
{*the function @{term f} partitions the @{term r}subsets of the typically


56 
infinite set @{term Y} into @{term s} distinct categories.*}


57 
"part r s Y f == \<forall>X. X \<subseteq> Y & finite X & card X = r > f X < s"


58 


59 
text{*For induction, we decrease the value of @{term r} in partitions.*}


60 
lemma part_Suc_imp_part:


61 
"[ infinite Y; part (Suc r) s Y f; y \<in> Y ]


62 
==> part r s (Y  {y}) (%u. f (insert y u))"


63 
apply(simp add: part_def, clarify)


64 
apply(drule_tac x="insert y X" in spec)


65 
apply(force simp:card_Diff_singleton_if)


66 
done


67 


68 
lemma part_subset: "part r s YY f ==> Y \<subseteq> YY ==> part r s Y f"


69 
by (simp add: part_def, blast)


70 


71 


72 
subsection {*Ramsey's Theorem: Infinitary Version*}


73 


74 
lemma ramsey_induction:


75 
fixes s::nat and r::nat


76 
shows


77 
"!!(YY::'a set) (f::'a set => nat).


78 
[infinite YY; part r s YY f]


79 
==> \<exists>Y' t'. Y' \<subseteq> YY & infinite Y' & t' < s &


80 
(\<forall>X. X \<subseteq> Y' & finite X & card X = r > f X = t')"


81 
proof (induct r)


82 
case 0


83 
thus ?case by (auto simp add: part_def card_eq_0_iff cong: conj_cong)


84 
next


85 
case (Suc r)


86 
show ?case


87 
proof 


88 
from Suc.prems infinite_imp_nonempty obtain yy where yy: "yy \<in> YY" by blast


89 
let ?ramr = "{((y,Y,t),(y',Y',t')). y' \<in> Y & Y' \<subseteq> Y}"


90 
let ?propr = "%(y,Y,t).


91 
y \<in> YY & y \<notin> Y & Y \<subseteq> YY & infinite Y & t < s


92 
& (\<forall>X. X\<subseteq>Y & finite X & card X = r > (f o insert y) X = t)"


93 
have infYY': "infinite (YY{yy})" using Suc.prems by auto


94 
have partf': "part r s (YY  {yy}) (f \<circ> insert yy)"


95 
by (simp add: o_def part_Suc_imp_part yy Suc.prems)


96 
have transr: "trans ?ramr" by (force simp add: trans_def)


97 
from Suc.hyps [OF infYY' partf']


98 
obtain Y0 and t0


99 
where "Y0 \<subseteq> YY  {yy}" "infinite Y0" "t0 < s"


100 
"\<forall>X. X\<subseteq>Y0 \<and> finite X \<and> card X = r \<longrightarrow> (f \<circ> insert yy) X = t0"


101 
by blast


102 
with yy have propr0: "?propr(yy,Y0,t0)" by blast


103 
have proprstep: "\<And>x. ?propr x \<Longrightarrow> \<exists>y. ?propr y \<and> (x, y) \<in> ?ramr"


104 
proof 


105 
fix x


106 
assume px: "?propr x" thus "?thesis x"


107 
proof (cases x)


108 
case (fields yx Yx tx)


109 
then obtain yx' where yx': "yx' \<in> Yx" using px


110 
by (blast dest: infinite_imp_nonempty)


111 
have infYx': "infinite (Yx{yx'})" using fields px by auto


112 
with fields px yx' Suc.prems


113 
have partfx': "part r s (Yx  {yx'}) (f \<circ> insert yx')"


114 
by (simp add: o_def part_Suc_imp_part part_subset [where ?YY=YY])


115 
from Suc.hyps [OF infYx' partfx']


116 
obtain Y' and t'


117 
where Y': "Y' \<subseteq> Yx  {yx'}" "infinite Y'" "t' < s"


118 
"\<forall>X. X\<subseteq>Y' \<and> finite X \<and> card X = r \<longrightarrow> (f \<circ> insert yx') X = t'"


119 
by blast


120 
show ?thesis


121 
proof


122 
show "?propr (yx',Y',t') & (x, (yx',Y',t')) \<in> ?ramr"


123 
using fields Y' yx' px by blast


124 
qed


125 
qed


126 
qed


127 
from dependent_choice [OF transr propr0 proprstep]


128 
obtain g where "(\<forall>n::nat. ?propr(g n)) & (\<forall>n m. n<m >(g n, g m) \<in> ?ramr)"


129 
.. {*for some reason, can't derive the following directly from dc*}


130 
hence pg: "!!n. ?propr (g n)"


131 
and rg: "!!n m. n<m ==> (g n, g m) \<in> ?ramr" by auto


132 
let ?gy = "(\<lambda>n. let (y,Y,t) = g n in y)"


133 
let ?gt = "(\<lambda>n. let (y,Y,t) = g n in t)"


134 
have rangeg: "\<exists>k. range ?gt \<subseteq> {..<k}"


135 
proof (intro exI subsetI)


136 
fix x


137 
assume "x \<in> range ?gt"


138 
then obtain n where "x = ?gt n" ..


139 
with pg [of n] show "x \<in> {..<s}" by (cases "g n") auto


140 
qed


141 
have "\<exists>s' \<in> range ?gt. infinite (?gt ` {s'})"


142 
by (rule inf_img_fin_dom [OF _ nat_infinite])


143 
(simp add: finite_nat_iff_bounded rangeg)


144 
then obtain s' and n'


145 
where s': "s' = ?gt n'"


146 
and infeqs': "infinite {n. ?gt n = s'}"


147 
by (auto simp add: vimage_def)


148 
with pg [of n'] have less': "s'<s" by (cases "g n'") auto


149 
have inj_gy: "inj ?gy"


150 
proof (rule linorder_injI)


151 
fix m and m'::nat assume less: "m < m'" show "?gy m \<noteq> ?gy m'"


152 
using rg [OF less] pg [of m] by (cases "g m", cases "g m'", auto)


153 
qed


154 
show ?thesis


155 
proof (intro exI conjI)


156 
show "?gy ` {n. ?gt n = s'} \<subseteq> YY" using pg


157 
by (auto simp add: Let_def split_beta)


158 
next


159 
show "infinite (?gy ` {n. ?gt n = s'})" using infeqs'


160 
by (blast intro: inj_gy [THEN subset_inj_on] dest: finite_imageD)


161 
next


162 
show "s' < s" by (rule less')


163 
next


164 
show "\<forall>X. X \<subseteq> ?gy ` {n. ?gt n = s'} & finite X & card X = Suc r


165 
> f X = s'"


166 
proof 


167 
{fix X


168 
assume "X \<subseteq> ?gy ` {n. ?gt n = s'}"


169 
and cardX: "finite X" "card X = Suc r"


170 
then obtain AA where AA: "AA \<subseteq> {n. ?gt n = s'}" and Xeq: "X = ?gy`AA"


171 
by (auto simp add: subset_image_iff)


172 
with cardX have "AA\<noteq>{}" by auto


173 
hence AAleast: "(LEAST x. x \<in> AA) \<in> AA" by (auto intro: LeastI_ex)


174 
have "f X = s'"


175 
proof (cases "g (LEAST x. x \<in> AA)")


176 
case (fields ya Ya ta)


177 
with AAleast Xeq


178 
have ya: "ya \<in> X" by (force intro!: rev_image_eqI)


179 
hence "f X = f (insert ya (X  {ya}))" by (simp add: insert_absorb)


180 
also have "... = ta"


181 
proof 


182 
have "X  {ya} \<subseteq> Ya"


183 
proof


184 
fix x


185 
assume x: "x \<in> X  {ya}"


186 
then obtain a' where xeq: "x = ?gy a'" and a': "a' \<in> AA"


187 
by (auto simp add: Xeq)


188 
hence "a' \<noteq> (LEAST x. x \<in> AA)" using x fields by auto


189 
hence lessa': "(LEAST x. x \<in> AA) < a'"


190 
using Least_le [of "%x. x \<in> AA", OF a'] by arith


191 
show "x \<in> Ya" using xeq fields rg [OF lessa'] by auto


192 
qed


193 
moreover


194 
have "card (X  {ya}) = r"


195 
by (simp add: card_Diff_singleton_if cardX ya)


196 
ultimately show ?thesis


197 
using pg [of "LEAST x. x \<in> AA"] fields cardX


198 
by (clarify, drule_tac x="X{ya}" in spec, simp)


199 
qed


200 
also have "... = s'" using AA AAleast fields by auto


201 
finally show ?thesis .


202 
qed}


203 
thus ?thesis by blast


204 
qed


205 
qed


206 
qed


207 
qed


208 


209 


210 
text{*Repackaging of Tom Ridge's final result*}


211 
theorem Ramsey:


212 
fixes s::nat and r::nat and Z::"'a set" and f::"'a set => nat"


213 
shows


214 
"[infinite Z;


215 
\<forall>X. X \<subseteq> Z & finite X & card X = r > f X < s]


216 
==> \<exists>Y t. Y \<subseteq> Z & infinite Y & t < s


217 
& (\<forall>X. X \<subseteq> Y & finite X & card X = r > f X = t)"


218 
by (blast intro: ramsey_induction [unfolded part_def, rule_format])


219 


220 
end


221 
