# HG changeset patch # User paulson # Date 1151479673 -7200 # Node ID e4c9f6946db341e79119d427556539d67b38cb96 # Parent 2f54a51f18015c3381f7951a0afc9b0924f0ca87 disjunctive wellfoundedness diff -r 2f54a51f1801 -r e4c9f6946db3 src/HOL/Library/Ramsey.thy --- a/src/HOL/Library/Ramsey.thy Tue Jun 27 10:10:20 2006 +0200 +++ b/src/HOL/Library/Ramsey.thy Wed Jun 28 09:27:53 2006 +0200 @@ -8,7 +8,9 @@ theory Ramsey imports Main begin -subsection{*``Axiom'' of Dependent Choice*} +subsection{*Preliminaries*} + +subsubsection{*``Axiom'' of Dependent Choice*} consts choice :: "('a => bool) => ('a * 'a) set => nat => 'a" --{*An integer-indexed chain of choices*} @@ -32,24 +34,23 @@ assumes trans: "trans r" and P0: "P x0" and Pstep: "!!x. P x ==> \y. P y & (x,y) \ r" - shows "\f::nat=>'a. (\n. P (f n)) & (\n m. n (f n, f m) \ r)" -proof (intro exI conjI) - show "\n. P (choice P r n)" by (blast intro: choice_n [OF P0 Pstep]) + obtains f :: "nat => 'a" where + "!!n. P (f n)" and "!!n m. n < m ==> (f n, f m) \ r" +proof + fix n + show "P (choice P r n)" by (blast intro: choice_n [OF P0 Pstep]) next have PSuc: "\n. (choice P r n, choice P r (Suc n)) \ r" using Pstep [OF choice_n [OF P0 Pstep]] by (auto intro: someI2_ex) - show "\n m. n (choice P r n, choice P r m) \ r" - proof (intro strip) - fix n m :: nat - assume less: "n r" using PSuc - by (auto intro: less_Suc_induct [OF less] transD [OF trans]) - qed -qed + fix n m :: nat + assume less: "n < m" + show "(choice P r n, choice P r m) \ r" using PSuc + by (auto intro: less_Suc_induct [OF less] transD [OF trans]) +qed -subsection {*Partitions of a Set*} +subsubsection {*Partitions of a Set*} definition part :: "nat => nat => 'a set => ('a set => nat) => bool" @@ -72,8 +73,8 @@ subsection {*Ramsey's Theorem: Infinitary Version*} -lemma ramsey_induction: - fixes s r :: nat +lemma Ramsey_induction: + fixes s and r::nat shows "!!(YY::'a set) (f::'a set => nat). [|infinite YY; part r s YY f|] @@ -127,7 +128,7 @@ qed from dependent_choice [OF transr propr0 proprstep] obtain g where pg: "!!n::nat. ?propr (g n)" - and rg: "!!n m. n (g n, g m) \ ?ramr" by force + and rg: "!!n m. n (g n, g m) \ ?ramr" by blast let ?gy = "(\n. let (y,Y,t) = g n in y)" let ?gt = "(\n. let (y,Y,t) = g n in t)" have rangeg: "\k. range ?gt \ {.. Ya" proof - fix x - assume x: "x \ X - {ya}" + fix x assume x: "x \ X - {ya}" then obtain a' where xeq: "x = ?gy a'" and a': "a' \ AA" by (auto simp add: Xeq) hence "a' \ (LEAST x. x \ AA)" using x fields by auto @@ -203,7 +203,6 @@ qed -text{*Repackaging of Tom Ridge's final result*} theorem Ramsey: fixes s r :: nat and Z::"'a set" and f::"'a set => nat" shows @@ -211,6 +210,129 @@ \X. X \ Z & finite X & card X = r --> f X < s|] ==> \Y t. Y \ Z & infinite Y & t < s & (\X. X \ Y & finite X & card X = r --> f X = t)" -by (blast intro: ramsey_induction [unfolded part_def]) +by (blast intro: Ramsey_induction [unfolded part_def]) + + +corollary Ramsey2: + fixes s::nat and Z::"'a set" and f::"'a set => nat" + assumes infZ: "infinite Z" + and part: "\x\Z. \y\Z. x\y --> f{x,y} < s" + shows + "\Y t. Y \ Z & infinite Y & t < s & (\x\Y. \y\Y. x\y --> f{x,y} = t)" +proof - + have part2: "\X. X \ Z & finite X & card X = 2 --> f X < s" + by (auto simp add: numeral_2_eq_2 card_2_eq part) + obtain Y t + where "Y \ Z" "infinite Y" "t < s" + "(\X. X \ Y & finite X & card X = 2 --> f X = t)" + by (insert Ramsey [OF infZ part2]) auto + moreover from this have "\x\Y. \y\Y. x \ y \ f {x, y} = t" by auto + ultimately show ?thesis by iprover +qed + + + + +subsection {*Disjunctive Well-Foundedness*} + +text{*An application of Ramsey's theorem to program termination. See + +Andreas Podelski and Andrey Rybalchenko, Transition Invariants, 19th Annual +IEEE Symposium on Logic in Computer Science (LICS'04), pages 32--41 (2004). +*} + +constdefs + disj_wf :: "('a * 'a)set => bool" + "disj_wf(r) == \T. \n::nat. (\ii 'a, nat => ('a*'a)set, nat set] => nat" + "transition_idx s T A == + LEAST k. \i j. A = {i,j} & i T k" + + +lemma transition_idx_less: + "[|i T k; k transition_idx s T {i,j} < n" +apply (subgoal_tac "transition_idx s T {i, j} \ k", simp) +apply (simp add: transition_idx_def, blast intro: Least_le) +done + +lemma transition_idx_in: + "[|i T k|] ==> (s j, s i) \ T (transition_idx s T {i,j})" +apply (simp add: transition_idx_def doubleton_eq_iff conj_disj_distribR + cong: conj_cong) +apply (erule LeastI) +done + +text{*To be equal to the union of some well-founded relations is equivalent +to being the subset of such a union.*} +lemma disj_wf: + "disj_wf(r) = (\T. \n::nat. (\i (\is. \i. (s (Suc i), s i) \ r" + then obtain s where sSuc: "\i. (s (Suc i), s i) \ r" .. + have s: "!!i j. i < j ==> (s j, s i) \ r" + proof - + fix i and j::nat + assume less: "i r" + proof (rule less_Suc_induct) + show "\i. (s (Suc i), s i) \ r" by (simp add: sSuc) + show "\i j k. \(s j, s i) \ r; (s k, s j) \ r\ \ (s k, s i) \ r" + using transr by (unfold trans_def, blast) + qed + qed + from dwf + obtain T and n::nat where wfT: "\kki j. i \k. (s j, s i) \ T k & k r" by (rule s [of i j]) + thus "\k. (s j, s i) \ T k & kj ==> transition_idx s T {i,j} < n" + apply (auto simp add: linorder_neq_iff) + apply (blast dest: s_in_T transition_idx_less) + apply (subst insert_commute) + apply (blast dest: s_in_T transition_idx_less) + done + have + "\K k. K \ UNIV & infinite K & k < n & + (\i\K. \j\K. i\j --> transition_idx s T {i,j} = k)" + by (rule Ramsey2) (auto intro: trless nat_infinite) + then obtain K and k + where infK: "infinite K" and less: "k < n" and + allk: "\i\K. \j\K. i\j --> transition_idx s T {i,j} = k" + by auto + have "\m. (s (enumerate K (Suc m)), s(enumerate K m)) \ T k" + proof + fix m::nat + let ?j = "enumerate K (Suc m)" + let ?i = "enumerate K m" + have jK: "?j \ K" by (simp add: enumerate_in_set infK) + have iK: "?i \ K" by (simp add: enumerate_in_set infK) + have ij: "?i < ?j" by (simp add: enumerate_step infK) + have ijk: "transition_idx s T {?i,?j} = k" using iK jK ij + by (simp add: allk) + obtain k' where "(s ?j, s ?i) \ T k'" "k' T k" + by (simp add: ijk [symmetric] transition_idx_in ij) + qed + hence "~ wf(T k)" by (force simp add: wf_iff_no_infinite_down_chain) + thus False using wfT less by blast +qed + end