src/HOL/Library/Ramsey.thy
author haftmann
Mon, 26 Mar 2007 14:53:02 +0200
changeset 22519 eb70ed79dac7
parent 22367 6860f09242bf
child 22665 cf152ff55d16
permissions -rwxr-xr-x
importing Eval theory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     1
(*  Title:      HOL/Library/Ramsey.thy
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     2
    ID:         $Id$
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     3
    Author:     Tom Ridge. Converted to structured Isar by L C Paulson
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     4
*)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     5
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     6
header "Ramsey's Theorem"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     7
20810
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
     8
theory Ramsey imports Main Infinite_Set begin
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
     9
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    10
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    11
subsection{*Preliminaries*}
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    12
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    13
subsubsection{*``Axiom'' of Dependent Choice*}
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    14
19948
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    15
consts choice :: "('a => bool) => ('a * 'a) set => nat => 'a"
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    16
  --{*An integer-indexed chain of choices*}
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    17
primrec
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    18
  choice_0:   "choice P r 0 = (SOME x. P x)"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    19
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    20
  choice_Suc: "choice P r (Suc n) = (SOME y. P y & (choice P r n, y) \<in> r)"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    21
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    22
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    23
lemma choice_n: 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    24
  assumes P0: "P x0"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    25
      and Pstep: "!!x. P x ==> \<exists>y. P y & (x,y) \<in> r"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    26
  shows "P (choice P r n)"
19948
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    27
proof (induct n)
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    28
  case 0 show ?case by (force intro: someI P0) 
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    29
next
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    30
  case Suc thus ?case by (auto intro: someI2_ex [OF Pstep]) 
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    31
qed
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    32
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    33
lemma dependent_choice: 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    34
  assumes trans: "trans r"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    35
      and P0: "P x0"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    36
      and Pstep: "!!x. P x ==> \<exists>y. P y & (x,y) \<in> r"
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    37
  obtains f :: "nat => 'a" where
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    38
    "!!n. P (f n)" and "!!n m. n < m ==> (f n, f m) \<in> r"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    39
proof
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    40
  fix n
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    41
  show "P (choice P r n)" by (blast intro: choice_n [OF P0 Pstep])
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    42
next
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    43
  have PSuc: "\<forall>n. (choice P r n, choice P r (Suc n)) \<in> r" 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    44
    using Pstep [OF choice_n [OF P0 Pstep]]
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    45
    by (auto intro: someI2_ex)
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    46
  fix n m :: nat
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    47
  assume less: "n < m"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    48
  show "(choice P r n, choice P r m) \<in> r" using PSuc
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    49
    by (auto intro: less_Suc_induct [OF less] transD [OF trans])
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    50
qed
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    51
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    52
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    53
subsubsection {*Partitions of a Set*}
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    54
19948
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    55
definition
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    56
  part :: "nat => nat => 'a set => ('a set => nat) => bool"
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    57
  --{*the function @{term f} partitions the @{term r}-subsets of the typically
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    58
       infinite set @{term Y} into @{term s} distinct categories.*}
21634
369e38e35686 fixed definition syntax
krauss
parents: 20810
diff changeset
    59
where
19948
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    60
  "part r s Y f = (\<forall>X. X \<subseteq> Y & finite X & card X = r --> f X < s)"
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    61
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    62
text{*For induction, we decrease the value of @{term r} in partitions.*}
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    63
lemma part_Suc_imp_part:
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    64
     "[| infinite Y; part (Suc r) s Y f; y \<in> Y |] 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    65
      ==> part r s (Y - {y}) (%u. f (insert y u))"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    66
  apply(simp add: part_def, clarify)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    67
  apply(drule_tac x="insert y X" in spec)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    68
  apply(force simp:card_Diff_singleton_if)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    69
  done
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    70
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    71
lemma part_subset: "part r s YY f ==> Y \<subseteq> YY ==> part r s Y f" 
19948
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
    72
  unfolding part_def by blast
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    73
  
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    74
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    75
subsection {*Ramsey's Theorem: Infinitary Version*}
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    76
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    77
lemma Ramsey_induction: 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
    78
  fixes s and r::nat
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    79
  shows
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    80
  "!!(YY::'a set) (f::'a set => nat). 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    81
      [|infinite YY; part r s YY f|]
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    82
      ==> \<exists>Y' t'. Y' \<subseteq> YY & infinite Y' & t' < s & 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    83
                  (\<forall>X. X \<subseteq> Y' & finite X & card X = r --> f X = t')"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    84
proof (induct r)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    85
  case 0
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    86
  thus ?case by (auto simp add: part_def card_eq_0_iff cong: conj_cong) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    87
next
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    88
  case (Suc r) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    89
  show ?case
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    90
  proof -
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    91
    from Suc.prems infinite_imp_nonempty obtain yy where yy: "yy \<in> YY" by blast
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    92
    let ?ramr = "{((y,Y,t),(y',Y',t')). y' \<in> Y & Y' \<subseteq> Y}"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    93
    let ?propr = "%(y,Y,t).     
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    94
		 y \<in> YY & y \<notin> Y & Y \<subseteq> YY & infinite Y & t < s
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    95
		 & (\<forall>X. X\<subseteq>Y & finite X & card X = r --> (f o insert y) X = t)"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    96
    have infYY': "infinite (YY-{yy})" using Suc.prems by auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    97
    have partf': "part r s (YY - {yy}) (f \<circ> insert yy)"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    98
      by (simp add: o_def part_Suc_imp_part yy Suc.prems)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
    99
    have transr: "trans ?ramr" by (force simp add: trans_def) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   100
    from Suc.hyps [OF infYY' partf']
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   101
    obtain Y0 and t0
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   102
    where "Y0 \<subseteq> YY - {yy}"  "infinite Y0"  "t0 < s"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   103
          "\<forall>X. X\<subseteq>Y0 \<and> finite X \<and> card X = r \<longrightarrow> (f \<circ> insert yy) X = t0"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   104
        by blast 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   105
    with yy have propr0: "?propr(yy,Y0,t0)" by blast
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   106
    have proprstep: "\<And>x. ?propr x \<Longrightarrow> \<exists>y. ?propr y \<and> (x, y) \<in> ?ramr" 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   107
    proof -
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   108
      fix x
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   109
      assume px: "?propr x" thus "?thesis x"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   110
      proof (cases x)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   111
        case (fields yx Yx tx)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   112
        then obtain yx' where yx': "yx' \<in> Yx" using px
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   113
               by (blast dest: infinite_imp_nonempty)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   114
        have infYx': "infinite (Yx-{yx'})" using fields px by auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   115
        with fields px yx' Suc.prems
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   116
        have partfx': "part r s (Yx - {yx'}) (f \<circ> insert yx')"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   117
          by (simp add: o_def part_Suc_imp_part part_subset [where ?YY=YY]) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   118
	from Suc.hyps [OF infYx' partfx']
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   119
	obtain Y' and t'
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   120
	where Y': "Y' \<subseteq> Yx - {yx'}"  "infinite Y'"  "t' < s"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   121
	       "\<forall>X. X\<subseteq>Y' \<and> finite X \<and> card X = r \<longrightarrow> (f \<circ> insert yx') X = t'"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   122
	    by blast 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   123
	show ?thesis
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   124
	proof
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   125
	  show "?propr (yx',Y',t') & (x, (yx',Y',t')) \<in> ?ramr"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   126
  	    using fields Y' yx' px by blast
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   127
	qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   128
      qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   129
    qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   130
    from dependent_choice [OF transr propr0 proprstep]
19946
e3ddb0812840 beautification
nipkow
parents: 19944
diff changeset
   131
    obtain g where pg: "!!n::nat.  ?propr (g n)"
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   132
      and rg: "!!n m. n<m ==> (g n, g m) \<in> ?ramr" by blast
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   133
    let ?gy = "(\<lambda>n. let (y,Y,t) = g n in y)"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   134
    let ?gt = "(\<lambda>n. let (y,Y,t) = g n in t)"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   135
    have rangeg: "\<exists>k. range ?gt \<subseteq> {..<k}"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   136
    proof (intro exI subsetI)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   137
      fix x
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   138
      assume "x \<in> range ?gt"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   139
      then obtain n where "x = ?gt n" ..
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   140
      with pg [of n] show "x \<in> {..<s}" by (cases "g n") auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   141
    qed
20810
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   142
    have "finite (range ?gt)"
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   143
      by (simp add: finite_nat_iff_bounded rangeg)
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   144
    then obtain s' and n'
20810
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   145
      where s': "s' = ?gt n'"
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   146
        and infeqs': "infinite {n. ?gt n = s'}"
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   147
      by (rule inf_img_fin_domE) (auto simp add: vimage_def intro: nat_infinite)
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   148
    with pg [of n'] have less': "s'<s" by (cases "g n'") auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   149
    have inj_gy: "inj ?gy"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   150
    proof (rule linorder_injI)
19949
0505dce27b0b fix/fixes: tuned type constraints;
wenzelm
parents: 19948
diff changeset
   151
      fix m m' :: nat assume less: "m < m'" show "?gy m \<noteq> ?gy m'"
19948
1be283f3f1ba minor tuning of definitions/proofs;
wenzelm
parents: 19946
diff changeset
   152
        using rg [OF less] pg [of m] by (cases "g m", cases "g m'") auto
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   153
    qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   154
    show ?thesis
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   155
    proof (intro exI conjI)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   156
      show "?gy ` {n. ?gt n = s'} \<subseteq> YY" using pg
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   157
        by (auto simp add: Let_def split_beta) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   158
      show "infinite (?gy ` {n. ?gt n = s'})" using infeqs'
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   159
        by (blast intro: inj_gy [THEN subset_inj_on] dest: finite_imageD) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   160
      show "s' < s" by (rule less')
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   161
      show "\<forall>X. X \<subseteq> ?gy ` {n. ?gt n = s'} & finite X & card X = Suc r 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   162
          --> f X = s'"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   163
      proof -
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   164
        {fix X 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   165
         assume "X \<subseteq> ?gy ` {n. ?gt n = s'}"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   166
            and cardX: "finite X" "card X = Suc r"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   167
         then obtain AA where AA: "AA \<subseteq> {n. ?gt n = s'}" and Xeq: "X = ?gy`AA" 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   168
             by (auto simp add: subset_image_iff) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   169
         with cardX have "AA\<noteq>{}" by auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   170
         hence AAleast: "(LEAST x. x \<in> AA) \<in> AA" by (auto intro: LeastI_ex) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   171
         have "f X = s'"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   172
         proof (cases "g (LEAST x. x \<in> AA)") 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   173
           case (fields ya Ya ta)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   174
           with AAleast Xeq 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   175
           have ya: "ya \<in> X" by (force intro!: rev_image_eqI) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   176
           hence "f X = f (insert ya (X - {ya}))" by (simp add: insert_absorb)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   177
           also have "... = ta" 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   178
           proof -
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   179
             have "X - {ya} \<subseteq> Ya"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   180
             proof 
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   181
               fix x assume x: "x \<in> X - {ya}"
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   182
               then obtain a' where xeq: "x = ?gy a'" and a': "a' \<in> AA" 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   183
                 by (auto simp add: Xeq) 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   184
               hence "a' \<noteq> (LEAST x. x \<in> AA)" using x fields by auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   185
               hence lessa': "(LEAST x. x \<in> AA) < a'"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   186
                 using Least_le [of "%x. x \<in> AA", OF a'] by arith
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   187
               show "x \<in> Ya" using xeq fields rg [OF lessa'] by auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   188
             qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   189
             moreover
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   190
             have "card (X - {ya}) = r"
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   191
               by (simp add: card_Diff_singleton_if cardX ya)
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   192
             ultimately show ?thesis 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   193
               using pg [of "LEAST x. x \<in> AA"] fields cardX
19946
e3ddb0812840 beautification
nipkow
parents: 19944
diff changeset
   194
	       by (clarsimp simp del:insert_Diff_single)
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   195
           qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   196
           also have "... = s'" using AA AAleast fields by auto
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   197
           finally show ?thesis .
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   198
         qed}
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   199
        thus ?thesis by blast
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   200
      qed 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   201
    qed 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   202
  qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   203
qed
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   204
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   205
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   206
theorem Ramsey:
19949
0505dce27b0b fix/fixes: tuned type constraints;
wenzelm
parents: 19948
diff changeset
   207
  fixes s r :: nat and Z::"'a set" and f::"'a set => nat"
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   208
  shows
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   209
   "[|infinite Z;
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   210
      \<forall>X. X \<subseteq> Z & finite X & card X = r --> f X < s|]
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   211
  ==> \<exists>Y t. Y \<subseteq> Z & infinite Y & t < s 
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   212
            & (\<forall>X. X \<subseteq> Y & finite X & card X = r --> f X = t)"
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   213
by (blast intro: Ramsey_induction [unfolded part_def])
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   214
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   215
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   216
corollary Ramsey2:
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   217
  fixes s::nat and Z::"'a set" and f::"'a set => nat"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   218
  assumes infZ: "infinite Z"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   219
      and part: "\<forall>x\<in>Z. \<forall>y\<in>Z. x\<noteq>y --> f{x,y} < s"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   220
  shows
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   221
   "\<exists>Y t. Y \<subseteq> Z & infinite Y & t < s & (\<forall>x\<in>Y. \<forall>y\<in>Y. x\<noteq>y --> f{x,y} = t)"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   222
proof -
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   223
  have part2: "\<forall>X. X \<subseteq> Z & finite X & card X = 2 --> f X < s"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   224
    by (auto simp add: numeral_2_eq_2 card_2_eq part) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   225
  obtain Y t 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   226
    where "Y \<subseteq> Z" "infinite Y" "t < s"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   227
          "(\<forall>X. X \<subseteq> Y & finite X & card X = 2 --> f X = t)"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   228
    by (insert Ramsey [OF infZ part2]) auto
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   229
  moreover from this have  "\<forall>x\<in>Y. \<forall>y\<in>Y. x \<noteq> y \<longrightarrow> f {x, y} = t" by auto
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   230
  ultimately show ?thesis by iprover
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   231
qed
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   232
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   233
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   234
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   235
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   236
subsection {*Disjunctive Well-Foundedness*}
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   237
22367
6860f09242bf tuned document;
wenzelm
parents: 21634
diff changeset
   238
text {*
6860f09242bf tuned document;
wenzelm
parents: 21634
diff changeset
   239
  An application of Ramsey's theorem to program termination. See
6860f09242bf tuned document;
wenzelm
parents: 21634
diff changeset
   240
  \cite{Podelski-Rybalchenko}.
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   241
*}
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   242
20810
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   243
definition
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   244
  disj_wf         :: "('a * 'a)set => bool"
21634
369e38e35686 fixed definition syntax
krauss
parents: 20810
diff changeset
   245
where
20810
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   246
  "disj_wf r = (\<exists>T. \<exists>n::nat. (\<forall>i<n. wf(T i)) & r = (\<Union>i<n. T i))"
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   247
21634
369e38e35686 fixed definition syntax
krauss
parents: 20810
diff changeset
   248
definition
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   249
  transition_idx :: "[nat => 'a, nat => ('a*'a)set, nat set] => nat"
21634
369e38e35686 fixed definition syntax
krauss
parents: 20810
diff changeset
   250
where
20810
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   251
  "transition_idx s T A =
3377a830b727 moved theory Infinite_Set to Library;
wenzelm
parents: 19954
diff changeset
   252
    (LEAST k. \<exists>i j. A = {i,j} & i<j & (s j, s i) \<in> T k)"
19954
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   253
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   254
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   255
lemma transition_idx_less:
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   256
    "[|i<j; (s j, s i) \<in> T k; k<n|] ==> transition_idx s T {i,j} < n"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   257
apply (subgoal_tac "transition_idx s T {i, j} \<le> k", simp) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   258
apply (simp add: transition_idx_def, blast intro: Least_le) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   259
done
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   260
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   261
lemma transition_idx_in:
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   262
    "[|i<j; (s j, s i) \<in> T k|] ==> (s j, s i) \<in> T (transition_idx s T {i,j})"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   263
apply (simp add: transition_idx_def doubleton_eq_iff conj_disj_distribR 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   264
            cong: conj_cong) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   265
apply (erule LeastI) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   266
done
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   267
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   268
text{*To be equal to the union of some well-founded relations is equivalent
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   269
to being the subset of such a union.*}
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   270
lemma disj_wf:
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   271
     "disj_wf(r) = (\<exists>T. \<exists>n::nat. (\<forall>i<n. wf(T i)) & r \<subseteq> (\<Union>i<n. T i))"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   272
apply (auto simp add: disj_wf_def) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   273
apply (rule_tac x="%i. T i Int r" in exI) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   274
apply (rule_tac x=n in exI) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   275
apply (force simp add: wf_Int1) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   276
done
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   277
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   278
theorem trans_disj_wf_implies_wf:
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   279
  assumes transr: "trans r"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   280
      and dwf:    "disj_wf(r)"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   281
  shows "wf r"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   282
proof (simp only: wf_iff_no_infinite_down_chain, rule notI)
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   283
  assume "\<exists>s. \<forall>i. (s (Suc i), s i) \<in> r"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   284
  then obtain s where sSuc: "\<forall>i. (s (Suc i), s i) \<in> r" ..
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   285
  have s: "!!i j. i < j ==> (s j, s i) \<in> r"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   286
  proof -
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   287
    fix i and j::nat
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   288
    assume less: "i<j"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   289
    thus "(s j, s i) \<in> r"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   290
    proof (rule less_Suc_induct)
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   291
      show "\<And>i. (s (Suc i), s i) \<in> r" by (simp add: sSuc) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   292
      show "\<And>i j k. \<lbrakk>(s j, s i) \<in> r; (s k, s j) \<in> r\<rbrakk> \<Longrightarrow> (s k, s i) \<in> r"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   293
        using transr by (unfold trans_def, blast) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   294
    qed
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   295
  qed    
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   296
  from dwf
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   297
  obtain T and n::nat where wfT: "\<forall>k<n. wf(T k)" and r: "r = (\<Union>k<n. T k)"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   298
    by (auto simp add: disj_wf_def)
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   299
  have s_in_T: "\<And>i j. i<j ==> \<exists>k. (s j, s i) \<in> T k & k<n"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   300
  proof -
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   301
    fix i and j::nat
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   302
    assume less: "i<j"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   303
    hence "(s j, s i) \<in> r" by (rule s [of i j]) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   304
    thus "\<exists>k. (s j, s i) \<in> T k & k<n" by (auto simp add: r)
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   305
  qed    
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   306
  have trless: "!!i j. i\<noteq>j ==> transition_idx s T {i,j} < n"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   307
    apply (auto simp add: linorder_neq_iff)
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   308
    apply (blast dest: s_in_T transition_idx_less) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   309
    apply (subst insert_commute)   
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   310
    apply (blast dest: s_in_T transition_idx_less) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   311
    done
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   312
  have
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   313
   "\<exists>K k. K \<subseteq> UNIV & infinite K & k < n & 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   314
          (\<forall>i\<in>K. \<forall>j\<in>K. i\<noteq>j --> transition_idx s T {i,j} = k)"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   315
    by (rule Ramsey2) (auto intro: trless nat_infinite) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   316
  then obtain K and k 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   317
    where infK: "infinite K" and less: "k < n" and
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   318
          allk: "\<forall>i\<in>K. \<forall>j\<in>K. i\<noteq>j --> transition_idx s T {i,j} = k"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   319
    by auto
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   320
  have "\<forall>m. (s (enumerate K (Suc m)), s(enumerate K m)) \<in> T k"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   321
  proof
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   322
    fix m::nat
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   323
    let ?j = "enumerate K (Suc m)"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   324
    let ?i = "enumerate K m"
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   325
    have jK: "?j \<in> K" by (simp add: enumerate_in_set infK) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   326
    have iK: "?i \<in> K" by (simp add: enumerate_in_set infK) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   327
    have ij: "?i < ?j" by (simp add: enumerate_step infK) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   328
    have ijk: "transition_idx s T {?i,?j} = k" using iK jK ij 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   329
      by (simp add: allk)
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   330
    obtain k' where "(s ?j, s ?i) \<in> T k'" "k'<n" 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   331
      using s_in_T [OF ij] by blast
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   332
    thus "(s ?j, s ?i) \<in> T k" 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   333
      by (simp add: ijk [symmetric] transition_idx_in ij) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   334
  qed
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   335
  hence "~ wf(T k)" by (force simp add: wf_iff_no_infinite_down_chain) 
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   336
  thus False using wfT less by blast
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   337
qed
e4c9f6946db3 disjunctive wellfoundedness
paulson
parents: 19949
diff changeset
   338
19944
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   339
60e0cbeae3d8 Introduction of Ramsey's theorem
paulson
parents:
diff changeset
   340
end