WQO_Finite_Lists.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 14 Sep 2013 14:08:19 +0100
changeset 387 288637d9dcde
parent 368 2d6beddb6fa6
permissions -rw-r--r--
more changes for final submission
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
368
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     1
theory WQO_Finite_Lists
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     2
imports "Seq"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     3
begin
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     4
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     5
subsection {* Auxiliary Lemmas *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     6
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     7
lemma funpow_non_decreasing:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     8
  fixes f :: "'a::order \<Rightarrow> 'a"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     9
  assumes "\<forall>i\<ge>n. f i \<ge> i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    10
  shows "(f ^^ i) n \<ge> n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    11
  using assms by (induct i) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    12
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    13
lemma funpow_mono:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    14
  assumes "\<forall>i\<ge>n::nat. f i > i" and "j > i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    15
  shows "(f ^^ j) n > (f ^^ i) n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    16
using assms(2)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    17
proof (induct "j - i" arbitrary: i j)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    18
  case 0 thus ?case by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    19
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    20
  case (Suc m)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    21
  then obtain j' where j: "j = Suc j'" by (cases j) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    22
  show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    23
  proof (cases "i < j'")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    24
    case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    25
    with Suc(1)[of j'] and Suc(2)[unfolded j]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    26
      have "(f ^^ j') n > (f ^^ i) n" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    27
    moreover have "(f ^^ j) n > (f ^^ j') n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    28
    proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    29
      have "(f ^^ j) n = f ((f ^^ j') n)" by (simp add: j)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    30
      also have "\<dots> > (f ^^ j') n" using assms and funpow_non_decreasing[of n f j'] by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    31
      finally show ?thesis .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    32
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    33
    ultimately show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    34
  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    35
    case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    36
    with Suc have i: "i = j'" unfolding j by (induct i) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    37
    show ?thesis unfolding i j using assms and funpow_non_decreasing[of n f j'] by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    38
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    39
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    40
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    41
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    42
subsection {* Basic Definitions *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    43
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    44
definition reflp_on :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    45
  "reflp_on P A \<equiv> \<forall>a\<in>A. P a a"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    46
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    47
lemma reflp_onI [Pure.intro]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    48
  "(\<And>a. a \<in> A \<Longrightarrow> P a a) \<Longrightarrow> reflp_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    49
  unfolding reflp_on_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    50
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    51
definition transp_on :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    52
  "transp_on P A \<equiv> \<forall>a\<in>A. \<forall>b\<in>A. \<forall>c\<in>A. P a b \<and> P b c \<longrightarrow> P a c"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    53
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    54
lemma transp_onI [Pure.intro]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    55
  "(\<And>a b c. \<lbrakk>a \<in> A; b \<in> A; c \<in> A; P a b; P b c\<rbrakk> \<Longrightarrow> P a c) \<Longrightarrow> transp_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    56
  unfolding transp_on_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    57
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    58
definition goodp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a seq \<Rightarrow> bool" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    59
  "goodp P f \<equiv> \<exists>i j. i < j \<and> P\<^sup>=\<^sup>= (f i) (f j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    60
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    61
abbreviation bad where "bad P f \<equiv> \<not> goodp P f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    62
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    63
definition wqo_on :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    64
  "wqo_on P A \<equiv> reflp_on P A \<and> transp_on P A \<and> (\<forall>f. (\<forall>i. f i \<in> A) \<longrightarrow> goodp P f)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    65
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    66
lemma wqo_onI [Pure.intro]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    67
  "\<lbrakk>reflp_on P A; transp_on P A; \<And>f. \<forall>i. f i \<in> A \<Longrightarrow> goodp P f\<rbrakk> \<Longrightarrow> wqo_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    68
  unfolding wqo_on_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    69
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    70
lemma reflp_on_reflclp [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    71
  assumes "reflp_on P A" and "a \<in> A" and "b \<in> A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    72
  shows "P\<^sup>=\<^sup>= a b = P a b"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    73
  using assms by (auto simp: reflp_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    74
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    75
lemma transp_on_tranclp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    76
  assumes "transp_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    77
  shows "(\<lambda>x y. x \<in> A \<and> y \<in> A \<and> P x y)\<^sup>+\<^sup>+ a b \<longleftrightarrow> a \<in> A \<and> b \<in> A \<and> P a b"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    78
    (is "?lhs = ?rhs")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    79
  by (rule iffI, induction rule: tranclp.induct)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    80
     (insert assms, auto simp: transp_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    81
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    82
lemma wqo_on_imp_reflp_on:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    83
  "wqo_on P A \<Longrightarrow> reflp_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    84
  by (auto simp: wqo_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    85
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    86
lemma wqo_on_imp_transp_on:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    87
  "wqo_on P A \<Longrightarrow> transp_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    88
  by (auto simp: wqo_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    89
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    90
lemma wqo_on_imp_goodp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    91
  "wqo_on P A \<Longrightarrow> \<forall>i. f i \<in> A \<Longrightarrow> goodp P f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    92
  by (auto simp: wqo_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    93
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    94
lemma reflp_on_converse:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    95
  "reflp_on P A \<Longrightarrow> reflp_on P\<inverse>\<inverse> A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    96
  unfolding reflp_on_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    97
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    98
lemma transp_on_converse:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    99
  "transp_on P A \<Longrightarrow> transp_on P\<inverse>\<inverse> A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   100
  unfolding transp_on_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   101
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   102
subsection {* Dickson's Lemma *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   103
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   104
text {*When two sets are wqo, then their cartesian product is wqo.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   105
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   106
definition
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   107
  prod_le :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'a \<times> 'b \<Rightarrow> bool"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   108
where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   109
  "prod_le P1 P2 \<equiv> \<lambda>(p1, p2) (q1, q2). P1 p1 q1 \<and> P2 p2 q2"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   110
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   111
lemma wqo_on_Sigma:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   112
  fixes A1 :: "'a set" and A2 :: "'b set"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   113
  assumes "wqo_on P1 A1" and "wqo_on P2 A2"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   114
  shows "wqo_on (prod_le P1 P2) (A1 \<times> A2)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   115
    (is "wqo_on ?P ?A")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   116
proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   117
  show "reflp_on ?P ?A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   118
    using assms by (auto simp: wqo_on_def reflp_on_def prod_le_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   119
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   120
  from assms have "transp_on P1 A1" and "transp_on P2 A2" by (auto simp: wqo_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   121
  thus "transp_on ?P ?A" unfolding transp_on_def prod_le_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   122
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   123
  fix g :: "('a \<times> 'b) seq"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   124
  let ?p = "\<lambda>i. fst (g i)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   125
  let ?q = "\<lambda>i. snd (g i)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   126
  assume g: "\<forall>i. g i \<in> ?A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   127
  have p: "\<forall>i. ?p i \<in> A1"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   128
  proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   129
    fix i
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   130
    from g have "g i \<in> ?A" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   131
    thus "?p i \<in> A1" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   132
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   133
  have q: "\<forall>i. ?q i \<in> A2"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   134
  proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   135
    fix i
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   136
    from g have "g i \<in> ?A" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   137
    thus "?q i \<in> A2" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   138
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   139
  let ?T = "{m. \<forall>n>m. \<not> (P1 (?p m) (?p n))}"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   140
  have "finite ?T"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   141
  proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   142
    assume "infinite ?T"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   143
    hence "INFM m. m \<in> ?T" unfolding INFM_iff_infinite by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   144
    then interpret infinitely_many "\<lambda>m. m \<in> ?T" by (unfold_locales) assumption
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   145
    let ?p' = "\<lambda>i. ?p (index i)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   146
    have p': "\<forall>i. ?p' i \<in> A1" using p by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   147
    have "bad P1 ?p'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   148
    proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   149
      assume "goodp P1 ?p'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   150
      then obtain i j :: nat where "i < j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   151
        and "P1\<^sup>=\<^sup>= (?p' i) (?p' j)" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   152
      hence "P1 (?p' i) (?p' j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   153
        using p' and reflp_on_reflclp[OF wqo_on_imp_reflp_on[OF assms(1)]] by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   154
      moreover from index_ordered_less[OF `i < j`] have "index j > index i" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   155
      moreover from index_p have "index i \<in> ?T" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   156
      ultimately show False by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   157
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   158
    with assms(1) show False using p' by (auto simp: wqo_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   159
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   160
  then obtain n where "\<forall>r\<ge>n. r \<notin> ?T"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   161
    using infinite_nat_iff_unbounded_le[of "?T"] by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   162
  hence "\<forall>i\<in>{n..}. \<exists>j>i. P1 (?p i) (?p j)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   163
  with p have "\<forall>i\<in>{n..}. \<exists>j>i. ?p j \<in> A1 \<and> ?p i \<in> A1 \<and> P1 (?p i) (?p j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   164
  from bchoice[OF this] obtain f :: "nat seq"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   165
    where 1: "\<forall>i\<ge>n. i < f i \<and> ?p i \<in> A1 \<and> ?p (f i) \<in> A1 \<and> P1 (?p i) (?p (f i))" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   166
  from stepfun_imp_chainp[of n f "\<lambda>x y. x \<in> A1 \<and> y \<in> A1 \<and> P1 x y" ?p, OF this]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   167
    have chain: "chainp (\<lambda>x y. x \<in> A1 \<and> y \<in> A1 \<and> P1 x y) (\<lambda>i. ?p ((f^^i) n))" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   168
  let ?f = "\<lambda>i. (f^^i) n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   169
  from 1 have inc: "\<forall>i\<ge>n. f i > i" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   170
  from wqo_on_imp_goodp[OF assms(2), of "?q \<circ> ?f"] and q
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   171
    obtain i j where "\<And>i. ?q (?f i) \<in> A2" and "j > i" and "P2\<^sup>=\<^sup>= (?q (?f i)) (?q (?f j))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   172
    by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   173
  hence "P2 (?q (?f i)) (?q (?f j))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   174
    using reflp_on_reflclp[OF wqo_on_imp_reflp_on[OF assms(2)]] by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   175
  moreover from funpow_mono[OF inc `j > i`] have "?f j > ?f i" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   176
  moreover from chainp_imp_tranclp[of "\<lambda>x y. x \<in> A1 \<and> y \<in> A1 \<and> P1 x y", OF chain `j > i`]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   177
    have "P1 (?p (?f i)) (?p (?f j))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   178
    unfolding transp_on_tranclp[OF wqo_on_imp_transp_on[OF assms(1)]] by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   179
  ultimately have "\<exists>i j. j > i \<and> P1 (?p i) (?p j) \<and> P2 (?q i) (?q j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   180
  thus "goodp ?P g" by (auto simp: split_def goodp_def prod_le_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   181
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   182
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   183
subsection {* Higman's Lemma *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   184
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   185
inductive
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   186
  emb :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   187
where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   188
  emb0 [intro]: "emb [] y"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   189
| emb1 [intro]: "emb x y \<Longrightarrow> emb x (c # y)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   190
| emb2 [intro]: "emb x y \<Longrightarrow> emb (c # x) (c # y)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   191
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   192
lemma emb_refl [simp]: "emb xs xs"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   193
  by (induct xs) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   194
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   195
lemma emb_Nil2 [simp]: "emb y [] \<Longrightarrow> y = []"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   196
  by (cases rule: emb.cases) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   197
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   198
lemma emb_right [intro]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   199
  assumes a: "emb x y"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   200
  shows "emb x (y @ y')"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   201
using a 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   202
by (induct arbitrary: y') (auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   203
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   204
lemma emb_left [intro]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   205
  assumes a: "emb x y"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   206
  shows "emb x (y' @ y)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   207
using a by (induct y') (auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   208
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   209
lemma emb_appendI [intro]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   210
  assumes a: "emb x x'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   211
  and     b: "emb y y'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   212
  shows "emb (x @ y) (x' @ y')"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   213
using a b by (induct) (auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   214
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   215
lemma emb_cons_leftD:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   216
  assumes "emb (a # x) y"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   217
  shows "\<exists>y1 y2. y = y1 @ [a] @ y2 \<and> emb x y2"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   218
using assms
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   219
apply(induct x\<equiv>"a # x" y\<equiv>"y" arbitrary: a x y)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   220
apply(auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   221
apply(metis append_Cons)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   222
done
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   223
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   224
lemma emb_append_leftD:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   225
  assumes "emb (x1 @ x2) y"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   226
  shows "\<exists>y1 y2. y = y1 @ y2 \<and> emb x1 y1 \<and> emb x2 y2"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   227
using assms
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   228
apply(induct x1 arbitrary: x2 y)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   229
apply(auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   230
apply(drule emb_cons_leftD)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   231
apply(auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   232
apply(drule_tac x="x2" in meta_spec)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   233
apply(drule_tac x="y2" in meta_spec)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   234
apply(auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   235
apply(rule_tac x="y1 @ (a # y1a)" in exI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   236
apply(rule_tac x="y2a" in exI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   237
apply(auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   238
done
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   239
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   240
lemma emb_trans:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   241
  assumes a: "emb x1 x2"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   242
  and     b: "emb x2 x3"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   243
  shows "emb x1 x3"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   244
using a b
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   245
apply(induct arbitrary: x3)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   246
apply(metis emb0)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   247
apply(metis emb_cons_leftD emb_left)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   248
apply(drule_tac emb_cons_leftD)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   249
apply(auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   250
done
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   251
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   252
lemma empty_imp_goodp_emb [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   253
  assumes "f i = []"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   254
  shows "goodp emb f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   255
proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   256
  assume "bad emb f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   257
  moreover have "(emb)\<^sup>=\<^sup>= (f i) (f (Suc i))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   258
    unfolding assms by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   259
  ultimately show False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   260
    unfolding goodp_def by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   261
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   262
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   263
lemma bad_imp_not_empty:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   264
  "bad emb f \<Longrightarrow> f i \<noteq> []"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   265
  by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   266
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   267
text {*Replace the elements of an infinite sequence, starting from a given
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   268
position, by those of another infinite sequence.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   269
definition repl :: "nat \<Rightarrow> 'a seq \<Rightarrow> 'a seq \<Rightarrow> 'a seq" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   270
  "repl i f g \<equiv> \<lambda>j. if j \<ge> i then g j else f j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   271
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   272
lemma repl_0 [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   273
  "repl 0 f g = g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   274
  by (simp add: repl_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   275
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   276
lemma repl_simps [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   277
  "j \<ge> i \<Longrightarrow> repl i f g j = g j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   278
  "j < i \<Longrightarrow> repl i f g j = f j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   279
  by (auto simp: repl_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   280
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   281
lemma repl_ident [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   282
   "repl i f f = f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   283
   by (auto simp: repl_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   284
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   285
lemma repl_repl_ident [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   286
  "repl n f (repl n g h) = repl n f h"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   287
  by (auto simp: repl_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   288
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   289
lemma repl_repl_ident' [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   290
  "repl n (repl n f g) h = repl n f h"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   291
  by (auto simp: repl_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   292
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   293
lemma bad_emb_repl:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   294
  assumes "bad emb f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   295
    and "bad emb g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   296
    and "\<forall>i\<ge>n. \<exists>j\<ge>n. emb (g i) (f j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   297
  shows "bad emb (repl n f g)" (is "bad emb ?f")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   298
proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   299
  presume "goodp emb ?f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   300
  then obtain i j where "i < j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   301
    and good: "emb\<^sup>=\<^sup>= (?f i) (?f j)" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   302
  {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   303
    assume "j < n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   304
    with `i < j` and good have "emb\<^sup>=\<^sup>= (f i) (f j)" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   305
    with assms(1) have False using `i < j` by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   306
  } moreover {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   307
    assume "n \<le> i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   308
    with `i < j` and good have "i - n < j - n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   309
      and "emb\<^sup>=\<^sup>= (g i) (g j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   310
    with assms(2) have False by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   311
  } moreover {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   312
    assume "i < n" and "n \<le> j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   313
    with assms(3) obtain k where "k \<ge> n" and emb: "emb (g j) (f k)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   314
    from `i < j` and `i < n` and `n \<le> j` and good
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   315
      have "emb\<^sup>=\<^sup>= (f i) (g j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   316
    hence "emb\<^sup>=\<^sup>= (f i) (f k)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   317
    proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   318
      assume fi: "f i = g j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   319
      with emb_refl have "emb (f i) (f i)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   320
      with emb_trans[OF emb] show "emb\<^sup>=\<^sup>= (f i) (f k)" by (auto simp: fi)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   321
    next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   322
      assume "emb (f i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   323
      from emb_trans[OF this emb] show "emb\<^sup>=\<^sup>= (f i) (f k)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   324
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   325
    with `i < n` and `n \<le> k` and assms(1) have False by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   326
  } ultimately show False using `i < j` by arith
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   327
qed simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   328
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   329
text {*A \emph{minimal bad prefix} of an infinite sequence, is a
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   330
prefix of its first @{text n} elements, such that every subsequence (of subsets)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   331
starting with the same @{text n} elements is good, whenever the @{text n}-th
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   332
element is replaced by a proper subset of itself.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   333
definition mbp :: "'a list seq \<Rightarrow> nat \<Rightarrow> bool" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   334
  "mbp f n \<equiv>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   335
    \<forall>g. (\<forall>i<n. g i = f i) \<and> g n \<noteq> f n \<and> emb (g n) (f n) \<and> (\<forall>i\<ge>n. \<exists>j\<ge>n. emb (g i) (f j))
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   336
    \<longrightarrow> goodp emb g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   337
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   338
lemma ex_repl_conv:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   339
  "(\<exists>j\<ge>n. P (repl n f g j)) \<longleftrightarrow> (\<exists>j\<ge>n. P (g j))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   340
  by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   341
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   342
lemma emb_strict_length:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   343
  assumes a: "emb x y" "x \<noteq> y" 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   344
  shows "length x < length y"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   345
  using a by (induct) (auto simp add: less_Suc_eq)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   346
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   347
lemma emb_wf:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   348
  shows "wf {(x, y). emb x y \<and> x \<noteq> y}"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   349
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   350
  have "wf (measure length)" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   351
  moreover
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   352
  have "{(x, y). emb x y \<and> x \<noteq> y} \<subseteq> measure length"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   353
    unfolding measure_def by (auto simp add: emb_strict_length)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   354
  ultimately 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   355
  show "wf {(x, y). emb x y \<and> x \<noteq> y}" by (rule wf_subset)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   356
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   357
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   358
lemma minimal_bad_element:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   359
  fixes f :: "'a list seq"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   360
  assumes "mbp f n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   361
    and "bad emb f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   362
  shows "\<exists>M.
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   363
    (\<forall>i\<le>n. M i = f i) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   364
    emb (M (Suc n)) (f (Suc n)) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   365
    (\<forall>i\<ge>Suc n. \<exists>j\<ge>Suc n. emb ((repl (Suc n) f M) i) (f j)) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   366
    bad emb (repl (Suc n) f M) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   367
    mbp (repl (Suc n) f M) (Suc n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   368
using assms
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   369
proof (induct "f (Suc n)" arbitrary: f n rule: wf_induct_rule[OF emb_wf])
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   370
  case (1 g)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   371
  show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   372
  proof (cases "mbp g (Suc n)")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   373
    case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   374
    let ?g = "repl (Suc n) g g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   375
    have "\<forall>i\<le>n. ?g i = g i" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   376
    moreover have "emb (g (Suc n)) (g (Suc n))" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   377
    moreover have "\<forall>i\<ge>Suc n. \<exists>j\<ge>Suc n. emb ((repl (Suc n) g g) i) (g j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   378
    moreover from `bad emb g`
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   379
      have "bad emb (repl (Suc n) g g)" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   380
    moreover from True have "mbp (repl (Suc n) g g) (Suc n)" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   381
    ultimately show ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   382
  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   383
    case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   384
    then obtain h where less: "\<forall>i<Suc n. h i = g i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   385
      and emb: "(h (Suc n), g (Suc n)) \<in> {(x, y). emb x y \<and> x \<noteq> y}"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   386
        (is "_ \<in> ?emb")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   387
      and greater: "\<forall>i\<ge>Suc n. \<exists>j\<ge>Suc n. emb (h i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   388
      and bad: "bad emb h"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   389
      unfolding mbp_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   390
    let ?g = "repl (Suc n) g h"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   391
    from emb have emb': "(?g (Suc n), g (Suc n)) \<in> ?emb" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   392
    have mbp: "mbp ?g n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   393
    proof (unfold mbp_def, intro allI impI, elim conjE)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   394
      fix e
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   395
      assume "\<forall>i<n. e i = ?g i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   396
      hence 1: "\<forall>i<n. e i = g i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   397
      assume "e n \<noteq> ?g n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   398
      hence 2: "e n \<noteq> ?g n" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   399
      assume "emb (e n) (?g n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   400
      hence 3: "emb (e n) (g n)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   401
      assume *: "\<forall>i\<ge>n. \<exists>j\<ge>n. emb (e i) (?g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   402
      have 4: "\<forall>i\<ge>n. \<exists>j\<ge>n. emb (e i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   403
      proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   404
        fix i assume "n \<le> i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   405
        with * obtain j where "j \<ge> n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   406
          and **: "emb (e i) (?g j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   407
        show "\<exists>j\<ge>n. emb (e i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   408
        proof (cases "j \<le> n")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   409
          case True with ** show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   410
            using `j \<ge> n` by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   411
        next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   412
          case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   413
          with `j \<ge> n` have "j \<ge> Suc n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   414
          with ** have "emb (e i) (h j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   415
          with greater obtain k where "k \<ge> Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   416
            and "emb (h j) (g k)" using `j \<ge> Suc n` by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   417
          with `emb (e i) (h j)` have "emb (e i) (g k)" by (auto intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   418
          moreover from `k \<ge> Suc n` have "k \<ge> n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   419
          ultimately show ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   420
        qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   421
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   422
      from `mbp g n`[unfolded mbp_def] and 1 and 2 and 3 and 4
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   423
        show "goodp emb e" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   424
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   425
    have bad: "bad emb ?g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   426
      using bad_emb_repl[OF `bad emb g` `bad emb h`, of "Suc n",
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   427
      OF greater] .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   428
    let ?g' = "repl (Suc n) g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   429
    from 1(1)[of ?g n, OF emb' mbp bad] obtain M
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   430
      where "\<forall>i\<le>n. M i = g i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   431
      and "emb (M (Suc n)) (?g' h (Suc n))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   432
      and *: "\<forall>i\<ge>Suc n. \<exists>j\<ge>Suc n. emb (?g' M i) (h j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   433
      and "bad emb (?g' M)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   434
      and "mbp (?g' M) (Suc n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   435
      unfolding ex_repl_conv by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   436
    moreover with emb have "emb (M (Suc n)) (g (Suc n))" by (auto intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   437
    moreover have "\<forall>i\<ge>Suc n. \<exists>j\<ge>Suc n. emb (?g' M i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   438
    proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   439
      fix i assume "Suc n \<le> i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   440
      with * obtain j where "j \<ge> Suc n" and "emb (?g' M i) (h j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   441
      hence "j \<ge> Suc n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   442
      from greater and `j \<ge> Suc n` obtain k where "k \<ge> Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   443
        and "emb (h j) (g k)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   444
      with `emb (?g' M i) (h j)` show "\<exists>j\<ge>Suc n. emb (?g' M i) (g j)" by (blast intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   445
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   446
    ultimately show ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   447
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   448
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   449
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   450
lemma choice2:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   451
  "\<forall>x y. P x y \<longrightarrow> (\<exists>z. Q x y z) \<Longrightarrow> \<exists>f. \<forall>x y. P x y \<longrightarrow> Q x y (f x y)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   452
  using bchoice[of "{(x, y). P x y}" "\<lambda>(x, y) z. Q x y z"] by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   453
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   454
fun minimal_bad_seq :: "('a seq \<Rightarrow> nat \<Rightarrow> 'a seq) \<Rightarrow> 'a seq \<Rightarrow> nat \<Rightarrow> 'a seq" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   455
  "minimal_bad_seq A f 0 = A f 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   456
| "minimal_bad_seq A f (Suc n) = (
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   457
    let g = minimal_bad_seq A f n in
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   458
    repl (Suc n) g (A g n))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   459
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   460
lemma bad_imp_mbp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   461
  assumes "bad emb f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   462
  shows "\<exists>g. (\<forall>i. \<exists>j. emb (g i) (f j)) \<and> mbp g 0 \<and> bad emb g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   463
using assms
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   464
proof (induct "f 0" arbitrary: f rule: wf_induct_rule[OF emb_wf])
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   465
  case (1 g)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   466
  show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   467
  proof (cases "mbp g 0")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   468
    case True with 1 show ?thesis by (blast intro: emb_refl)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   469
  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   470
    case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   471
    then obtain h where less: "\<forall>i<0. h i = g i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   472
      and emb: "(h 0, g 0) \<in> {(x, y). emb x y \<and> x \<noteq> y}" (is "_ \<in> ?emb")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   473
      and greater: "\<forall>i\<ge>0. \<exists>j\<ge>0. emb (h i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   474
      and bad: "bad emb h"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   475
      unfolding mbp_def by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   476
    from 1(1)[of h, OF emb bad] obtain e
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   477
      where "\<forall>i. \<exists>j. emb (e i) (h j)" and "mbp e 0" and "bad emb e"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   478
      by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   479
    moreover with greater have "\<forall>i. \<exists>j. emb (e i) (g j)" by (force intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   480
    ultimately show ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   481
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   482
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   483
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   484
lemma repl_1 [simp]:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   485
  assumes "f 0 = g 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   486
  shows "repl (Suc 0) f g = g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   487
proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   488
  fix i show "repl (Suc 0) f g i = g i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   489
    by (induct i) (simp_all add: assms)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   490
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   491
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   492
lemma bad_repl:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   493
  assumes "\<forall>i. f i \<ge> f 0" and "\<forall>i j. i > j \<longrightarrow> f i > f j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   494
    and "bad P (repl (f 0) A B)" (is "bad P ?A")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   495
  shows "bad P (B \<circ> f)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   496
proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   497
  assume "goodp P (B \<circ> f)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   498
  then obtain i j where "i < j" and "P\<^sup>=\<^sup>= (B (f i)) (B (f j))" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   499
  hence "P\<^sup>=\<^sup>= (?A (f i)) (?A (f j))" using assms by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   500
  moreover from `i < j` have "f i < f j" using assms by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   501
  ultimately show False using assms(3) by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   502
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   503
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   504
lemma iterated_subseq:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   505
  assumes "\<forall>n>0::nat. \<forall>i\<ge>n. \<exists>j\<ge>n. emb (g n i) (g (n - 1) j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   506
    and "m \<le> n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   507
  shows "\<forall>i\<ge>n. \<exists>j\<ge>m. emb (g n i) (g m j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   508
using assms(2)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   509
proof (induct "n - m" arbitrary: n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   510
  case 0 thus ?case by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   511
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   512
  case (Suc k)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   513
  then obtain n' where n: "n = Suc n'" by (cases n) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   514
  with Suc have "k = n' - m" and "m \<le> n'" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   515
  have "n > 0" by (auto simp: n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   516
  show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   517
  proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   518
    fix i assume "i \<ge> n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   519
    with assms(1)[rule_format, OF `n > 0`] obtain j where "j \<ge> n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   520
      and "emb (g (Suc n') i) (g n' j)" by (auto simp: n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   521
    with Suc(1)[OF `k = n' - m` `m \<le> n'`, THEN spec[of _ j]]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   522
      obtain k where "k \<ge> m" and "emb (g n' j) (g m k)" by (auto simp: n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   523
    with `emb (g (Suc n') i) (g n' j)` have "emb (g n i) (g m k)" by (auto intro: emb_trans simp: n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   524
    thus "\<exists>j\<ge>m. emb (g n i) (g m j)" using `k \<ge> m` by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   525
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   526
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   527
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   528
lemma no_bad_of_special_shape_imp_goodp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   529
  assumes "\<not> (\<exists>f:: nat seq. (\<forall>i. f 0 \<le> f i) \<and> bad P (B \<circ> f))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   530
    and "\<forall>i. f i \<in> {B i | i. True}"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   531
  shows "goodp P f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   532
proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   533
  assume "bad P f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   534
  from assms(2) have "\<forall>i. \<exists>j. f i = B j" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   535
  from choice[OF this] obtain g where "\<And>i. f i = B (g i)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   536
  with `bad P f` have "bad P (B \<circ> g)" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   537
  have "\<forall>i. \<exists>j>i. g j \<ge> g 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   538
  proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   539
    assume "\<not> ?thesis"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   540
    then obtain i::nat where "\<forall>j>i. \<not> (g j \<ge> g 0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   541
    hence *: "\<forall>j>i. g j < g 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   542
    let ?I = "{j. j > i}"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   543
    from * have "\<forall>j>i. g j \<in> {..<g 0}" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   544
    hence "\<forall>j\<in>?I. g j \<in> {..<g 0}" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   545
    hence "g ` ?I \<subseteq> {..<g 0}" unfolding image_subset_iff by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   546
    moreover have "finite {..<g 0}" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   547
    ultimately have 1: "finite (g ` ?I)" using finite_subset by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   548
    have 2: "infinite ?I"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   549
    proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   550
      {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   551
      fix m have "\<exists>n>m. i < n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   552
      proof (cases "m > i")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   553
        case True thus ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   554
      next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   555
        case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   556
        hence "m \<le> i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   557
        hence "Suc i > m" and "i < Suc i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   558
        thus ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   559
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   560
      }
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   561
      thus ?thesis unfolding infinite_nat_iff_unbounded by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   562
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   563
    from pigeonhole_infinite[OF 2 1]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   564
      obtain k where "k > i" and "infinite {j. j > i \<and> g j = g k}" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   565
    then obtain l where "k < l" and "g l = g k"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   566
      unfolding infinite_nat_iff_unbounded by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   567
    hence "P\<^sup>=\<^sup>= (B (g k)) (B (g l))" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   568
    with `k < l` and `bad P (B \<circ> g)` show False by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   569
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   570
  from choice[OF this] obtain h
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   571
    where "\<forall>i. (h i) > i" and *: "\<And>i. g (h i) \<ge> g 0" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   572
  hence "\<forall>i\<ge>0. (h i) > i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   573
  from funpow_mono[OF this] have **: "\<And>i j. i < j \<Longrightarrow> (h ^^ i) 0 < (h ^^ j) 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   574
  let ?i = "\<lambda>i. (h ^^ i) 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   575
  let ?f = "\<lambda>i. g (?i i)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   576
  have "\<forall>i. ?f i \<ge> ?f 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   577
  proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   578
    fix i show "?f i \<ge> ?f 0" using * by (induct i) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   579
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   580
  moreover have "bad P (B \<circ> ?f)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   581
  proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   582
    assume "goodp P (B \<circ> ?f)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   583
    then obtain i j where "i < j" and "P\<^sup>=\<^sup>= (B (?f i)) (B (?f j))" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   584
    hence "P\<^sup>=\<^sup>= (B (g (?i i))) (B (g (?i j)))" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   585
    moreover from **[OF `i < j`] have "?i i < ?i j" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   586
    ultimately show False using `bad P (B \<circ> g)` by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   587
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   588
  ultimately have "(\<forall>i. ?f i \<ge> ?f 0) \<and> bad P (B \<circ> ?f)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   589
  hence "\<exists>f. (\<forall>i. f i \<ge> f 0) \<and> bad P (B \<circ> f)" by (rule exI[of _ ?f])
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   590
  with assms(1) show False by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   591
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   592
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   593
lemma emb_tl_left [simp]: "xs \<noteq> [] \<Longrightarrow> emb (tl xs) xs"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   594
  by (induct xs) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   595
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   596
lemma tl_ne [simp]: "xs \<noteq> [] \<Longrightarrow> tl xs = xs \<Longrightarrow> False"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   597
  by (induct xs) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   598
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   599
text {*Every reflexive and transitive relation on a finite set
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   600
is a wqo.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   601
lemma finite_wqo_on:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   602
  fixes A :: "('a::finite) set"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   603
  assumes "reflp_on P A" and "transp_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   604
  shows "wqo_on P A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   605
proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   606
  fix f::"'a::finite seq"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   607
  assume *: "\<forall>i. f i \<in> A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   608
  let ?I = "UNIV::nat set"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   609
  have "f ` ?I \<subseteq> A" using * by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   610
  with finite[of A] and finite_subset have 1: "finite (f ` ?I)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   611
  have "infinite ?I" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   612
  from pigeonhole_infinite[OF this 1]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   613
    obtain k where "infinite {j. f j = f k}" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   614
  then obtain l where "k < l" and "f l = f k"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   615
    unfolding infinite_nat_iff_unbounded by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   616
  hence "P\<^sup>=\<^sup>= (f k) (f l)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   617
  with `k < l` show "goodp P f" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   618
qed fact+
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   619
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   620
lemma finite_eq_wqo_on:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   621
  "wqo_on (op =) (A::('a::finite) set)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   622
  using finite_wqo_on[of "op =" A]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   623
  by (auto simp: reflp_on_def transp_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   624
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   625
lemma wqo_on_finite_lists:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   626
  shows "wqo_on emb (UNIV::('a::finite) list set)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   627
    (is "wqo_on ?P ?A")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   628
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   629
  {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   630
    from emb_refl
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   631
      have "reflp_on ?P ?A" unfolding reflp_on_def by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   632
  }
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   633
  note refl = this
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   634
  {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   635
    from emb_trans
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   636
      have "transp_on ?P ?A" unfolding transp_on_def by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   637
  }
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   638
  note trans = this
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   639
  {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   640
    have "\<forall>f. (\<forall>i. f i \<in> ?A) \<longrightarrow> goodp ?P f"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   641
    proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   642
      assume "\<not> ?thesis"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   643
      then obtain f where "bad ?P f" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   644
      from bad_imp_mbp[of f, OF `bad ?P f`] obtain g
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   645
        where "\<forall>i. \<exists>j. emb (g i) (f j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   646
        and "mbp g 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   647
        and "bad ?P g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   648
        by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   649
      from minimal_bad_element
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   650
        have "\<forall>f n.
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   651
        mbp f n \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   652
        bad ?P f \<longrightarrow>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   653
        (\<exists>M.
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   654
          (\<forall>i\<le>n. M i = f i) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   655
          emb (M (Suc n)) (f (Suc n)) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   656
          (\<forall>i\<ge>Suc n. \<exists>j\<ge>Suc n. emb (repl (Suc n) f M i) (f j)) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   657
          bad ?P (repl (Suc n) f M) \<and>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   658
          mbp (repl (Suc n) f M) (Suc n))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   659
        (is "\<forall>f n. ?Q f n \<longrightarrow> (\<exists>M. ?Q' f n M)")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   660
        by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   661
      from choice2[OF this] obtain M
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   662
        where *[rule_format]: "\<forall>f n. ?Q f n \<longrightarrow> ?Q' f n (M f n)" by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   663
      let ?g = "minimal_bad_seq M g"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   664
      let ?A = "\<lambda>i. ?g i i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   665
      have "\<forall>n. (n = 0 \<longrightarrow> (\<forall>i\<ge>n. \<exists>j\<ge>n. emb (?g n i) (g j))) \<and> (n > 0 \<longrightarrow> (\<forall>i\<ge>n. \<exists>j\<ge>n. emb (?g n i) (?g (n - 1) j))) \<and> (\<forall>i\<le>n. mbp (?g n) i) \<and> (\<forall>i\<le>n. ?A i = ?g n i) \<and> bad ?P (?g n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   666
      proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   667
        fix n
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   668
        show "(n = 0 \<longrightarrow> (\<forall>i\<ge>n. \<exists>j\<ge>n. emb (?g n i) (g j))) \<and> (n > 0 \<longrightarrow> (\<forall>i\<ge>n. \<exists>j\<ge>n. emb (?g n i) (?g (n - 1) j))) \<and> (\<forall>i\<le>n. mbp (?g n) i) \<and> (\<forall>i\<le>n. ?A i = ?g n i) \<and> bad ?P (?g n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   669
        proof (induction n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   670
          case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   671
          have "mbp g 0" by fact
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   672
          moreover have "bad ?P g" by fact
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   673
          ultimately
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   674
            have [simp]: "M g 0 0 = g 0" and "emb (M g 0 (Suc 0)) (g (Suc 0))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   675
            and "bad ?P (M g 0)" and "mbp (M g 0) (Suc 0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   676
            and **: "\<forall>i\<ge>Suc 0. \<exists>j\<ge>Suc 0. emb (M g 0 i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   677
            using *[of g 0] by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   678
          moreover have "mbp (M g 0) 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   679
          proof (unfold mbp_def, intro allI impI, elim conjE)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   680
            fix e :: "'a list seq"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   681
            presume "(e 0, g 0) \<in> {(x, y). emb x y \<and> x \<noteq> y}" (is "_ \<in> ?emb")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   682
              and *: "\<forall>i. \<exists>j\<ge>0. emb (e i) (M g 0 j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   683
            have "\<forall>i. \<exists>j\<ge>0::nat. emb (e i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   684
            proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   685
              fix i
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   686
              from * obtain j where "j \<ge> 0" and "emb (e i) (M g 0 j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   687
              show "\<exists>j\<ge>0. emb (e i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   688
              proof (cases "j = 0")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   689
                case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   690
                with `emb (e i) (M g 0 j)` have "emb (e i) (g 0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   691
                thus ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   692
              next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   693
                case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   694
                hence "j \<ge> Suc 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   695
                with ** obtain k where "k \<ge> Suc 0" and "emb (M g 0 j) (g k)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   696
                with `emb (e i) (M g 0 j)` have "emb (e i) (g k)" by (blast intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   697
                moreover with `k \<ge> Suc 0` have "k \<ge> 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   698
                ultimately show ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   699
              qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   700
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   701
            with `mbp g 0`[unfolded mbp_def]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   702
            show "goodp ?P e" using `(e 0, g 0) \<in> ?emb` by (simp add: mbp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   703
          qed auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   704
          moreover have "\<forall>i\<ge>0. \<exists>j\<ge>0. emb (?g 0 i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   705
          proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   706
            fix i::nat
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   707
            assume "i \<ge> 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   708
            hence "i = 0 \<or> i \<ge> Suc 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   709
            thus "\<exists>j\<ge>0. emb (?g 0 i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   710
            proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   711
              assume "i \<ge> Suc 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   712
              with ** obtain j where "j \<ge> Suc 0" and "emb (?g 0 i) (g j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   713
              moreover from this have "j \<ge> 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   714
              ultimately show "?thesis" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   715
            next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   716
              assume "i = 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   717
              hence "emb (?g 0 i) (g 0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   718
              thus ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   719
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   720
          qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   721
          ultimately show ?case by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   722
        next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   723
          case (Suc n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   724
          with *[of "?g n" n]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   725
            have eq: "\<forall>i\<le>n. ?A i = ?g n i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   726
            and emb: "emb (?g (Suc n) (Suc n)) (?g n (Suc n))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   727
            and subseq: "\<forall>i\<ge>Suc n. \<exists>j\<ge>Suc n. emb (?g (Suc n) i) (?g n j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   728
            and "bad ?P (?g (Suc n))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   729
            and mbp: "mbp (?g (Suc n)) (Suc n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   730
            by (simp_all add: Let_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   731
          moreover have *: "\<forall>i\<le>Suc n. ?A i = ?g (Suc n) i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   732
          proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   733
            fix i assume "i \<le> Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   734
            show "?A i = ?g (Suc n) i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   735
            proof (cases "i = Suc n")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   736
              assume "i = Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   737
              thus ?thesis by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   738
            next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   739
              assume "i \<noteq> Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   740
              with `i \<le> Suc n` have "i < Suc n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   741
              thus ?thesis by (simp add: Let_def eq)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   742
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   743
          qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   744
          moreover have "\<forall>i\<le>Suc n. mbp (?g (Suc n)) i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   745
          proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   746
            fix i assume "i \<le> Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   747
            show "mbp (?g (Suc n)) i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   748
            proof (cases "i = Suc n")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   749
              case True with mbp show ?thesis by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   750
            next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   751
              case False with `i \<le> Suc n` have le: "i \<le> Suc n" "i \<le> n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   752
              show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   753
              proof (unfold mbp_def, intro allI impI, elim conjE)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   754
                fix e
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   755
                note * = *[rule_format, symmetric] eq[rule_format, symmetric]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   756
                assume "\<forall>i'<i. e i' = ?g (Suc n) i'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   757
                hence 1: "\<forall>i'<i. e i' = ?g n i'" using * and le by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   758
                presume "(e i, ?g (Suc n) i) \<in> {(x, y). emb x y \<and> x \<noteq> y}" (is "_ \<in> ?emb")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   759
                hence 2: "(e i, ?g n i) \<in> ?emb" using * and le by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   760
                assume **: "\<forall>j\<ge>i. \<exists>k\<ge>i. emb (e j) (?g (Suc n) k)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   761
                have 3: "\<forall>j\<ge>i. \<exists>k\<ge>i. emb (e j) (?g n k)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   762
                proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   763
                  fix j assume "i \<le> j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   764
                  with ** obtain k where "k \<ge> i" and "emb (e j) (?g (Suc n) k)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   765
                  show "\<exists>k\<ge>i. emb (e j) (?g n k)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   766
                  proof (cases "k \<le> n")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   767
                    case True with `emb (e j) (?g (Suc n) k)`
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   768
                      have "emb (e j) (?g n k)" using * by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   769
                    thus ?thesis using `k \<ge> i` by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   770
                  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   771
                    case False hence "k \<ge> Suc n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   772
                    with subseq obtain l where "l \<ge> Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   773
                      and "emb (?g (Suc n) k) (?g n l)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   774
                    with `emb (e j) (?g (Suc n) k)` have "emb (e j) (?g n l)" by (auto intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   775
                    moreover from `i \<le> Suc n` and `l \<ge> Suc n` have "l \<ge> i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   776
                    ultimately show ?thesis by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   777
                  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   778
                qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   779
                from 1 2 3 and Suc[THEN conjunct2, THEN conjunct2] and `i \<le> n`
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   780
                show "goodp ?P e" unfolding mbp_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   781
              qed simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   782
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   783
          qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   784
          ultimately show ?case by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   785
        qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   786
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   787
      hence 1: "\<forall>n. \<forall>i\<le>n. mbp (?g n) i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   788
        and 2: "\<forall>n. \<forall>i\<le>n. ?A i = ?g n i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   789
        and 3: "\<forall>n. bad ?P (?g n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   790
        and 6: "\<forall>i\<ge>0. \<exists>j\<ge>0. emb (?g 0 i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   791
        and 7: "\<forall>n>0. \<forall>i\<ge>n. \<exists>j\<ge>n. emb (?g n i) (?g (n - 1) j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   792
        by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   793
      have ex_subset: "\<forall>n. \<forall>i. \<exists>j. emb (?g n i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   794
      proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   795
        fix n show "\<forall>i. \<exists>j. emb (?g n i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   796
        proof (induct n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   797
          case 0 with 6 show ?case by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   798
        next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   799
          case (Suc n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   800
          show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   801
          proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   802
            fix i
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   803
            have "i < Suc n \<or> i \<ge> Suc n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   804
            thus "\<exists>j. emb (?g (Suc n) i) (g j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   805
            proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   806
              assume "i < Suc n" hence "i \<le> Suc n" and "i \<le> n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   807
              from `i \<le> Suc n` have "?g (Suc n) i = ?g i i" using 2 by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   808
              moreover from `i \<le> n` have "?g n i = ?g i i" using 2 by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   809
              ultimately have "?g (Suc n) i = ?g n i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   810
              with Suc show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   811
            next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   812
              assume "i \<ge> Suc n"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   813
              with 7[THEN spec[of _ "Suc n"]]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   814
                obtain j where "j \<ge> Suc n" and "emb (?g (Suc n) i) (?g n j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   815
              moreover from Suc obtain k where "emb (?g n j) (g k)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   816
              ultimately show ?thesis by (blast intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   817
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   818
          qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   819
        qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   820
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   821
      have bad: "bad ?P ?A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   822
      proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   823
        assume "goodp ?P ?A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   824
        then obtain i j :: nat where "i < j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   825
          and "?P\<^sup>=\<^sup>= (?g i i) (?g j j)" unfolding goodp_def by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   826
        moreover with 2[rule_format, of i j]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   827
          have "?P\<^sup>=\<^sup>= (?g j i) (?g j j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   828
        ultimately have "goodp ?P (?g j)" unfolding goodp_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   829
        with 3 show False by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   830
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   831
      have non_empty: "\<forall>i. ?A i \<noteq> []" using bad and bad_imp_not_empty[of ?A] by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   832
      then obtain a as where a: "\<forall>i. hd (?A i) = a i \<and> tl (?A i) = as i" by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   833
      let ?B = "\<lambda>i. tl (?A i)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   834
      {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   835
        assume "\<exists>f::nat seq. (\<forall>i. f i \<ge> f 0) \<and> bad ?P (?B \<circ> f)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   836
        then obtain f :: "nat seq" where ge: "\<forall>i. f i \<ge> f 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   837
          and "bad ?P (?B \<circ> f)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   838
        let ?C = "\<lambda>i. if i < f 0 then ?A i else ?B (f (i - f 0))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   839
        have [simp]: "\<And>i. i < f 0 \<Longrightarrow> ?C i = ?A i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   840
        have [simp]: "\<And>i. f 0 \<le> i \<Longrightarrow> ?C i = ?B (f (i - f 0))" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   841
        have "bad ?P ?C"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   842
        proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   843
          assume "goodp ?P ?C"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   844
          then obtain i j where "i < j" and *: "?P\<^sup>=\<^sup>= (?C i) (?C j)" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   845
          {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   846
            assume "j < f 0" with `i < j` and * have "?P\<^sup>=\<^sup>= (?A i) (?A j)" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   847
            with `i < j` and `bad ?P ?A` have False by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   848
          } moreover {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   849
            assume "f 0 \<le> i" with `i < j` and * have "?P\<^sup>=\<^sup>= (?B (f (i - f 0))) (?B (f (j - f 0)))" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   850
            moreover with `i < j` and `f 0 \<le> i` have "i - f 0 < j - f 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   851
            ultimately have False using `bad ?P (?B \<circ> f)` by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   852
          } moreover {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   853
            have emb: "emb (?B (f (j - f 0))) (?A (f (j - f 0)))" using non_empty by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   854
            assume "i < f 0" and "f 0 \<le> j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   855
            with * have "?P\<^sup>=\<^sup>= (?A i) (?B (f (j - f 0)))" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   856
            hence "?P (?A i) (?B (f (j - f 0))) \<or> ?A i = ?B (f (j - f 0))" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   857
            hence False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   858
            proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   859
              assume "?P (?A i) (?B (f (j - f 0)))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   860
              with emb have "?P (?A i) (?A (f (j - f 0)))" by (blast intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   861
              moreover from ge[THEN spec[of _ "j - f 0"]] and `i < f 0` have "i < f (j - f 0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   862
              ultimately show ?thesis using `bad ?P ?A` by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   863
            next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   864
              assume "?A i = ?B (f (j - f 0))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   865
              with emb have "emb (?A i) (?A (f (j - f 0)))" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   866
              moreover have "?P (?A i) (?A i)" using emb_refl by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   867
              ultimately have "?P (?A i) (?A (f (j - f 0)))" by (blast intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   868
              moreover from ge[THEN spec[of _ "j - f 0"]] and `i < f 0` have "i < f (j - f 0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   869
              ultimately show ?thesis using `bad ?P ?A` by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   870
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   871
          } ultimately show False by arith
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   872
        qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   873
        have "\<forall>i<f 0. ?C i = ?g (f 0) i" using 2 by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   874
        moreover have "(?C (f 0), ?g (f 0) (f 0)) \<in> {(x, y). emb x y \<and> x \<noteq> y}" using non_empty tl_ne by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   875
        moreover have "\<forall>i\<ge>f 0. \<exists>j\<ge>f 0. emb (?C i) (?g (f 0) j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   876
        proof (intro allI impI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   877
          fix i
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   878
          let ?i = "f (i - f 0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   879
          assume "f 0 \<le> i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   880
          with `\<forall>i. f 0 \<le> f i` have "f 0 \<le> ?i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   881
          from `f 0 \<le> i` have *: "?C i = ?B ?i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   882
          have "emb (?C i) (?g ?i ?i)" unfolding * using non_empty emb_tl_left by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   883
          from iterated_subseq[OF 7, of "f 0" "?i", THEN spec[of _ "?i"], OF `f 0 \<le> ?i`]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   884
            obtain j where "j \<ge> f 0" and "emb (?g ?i ?i) (?g (f 0) j)" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   885
          with `emb (?C i) (?g ?i ?i)`
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   886
            show "\<exists>j\<ge>f 0. emb (?C i) (?g (f 0) j)" by (blast intro: emb_trans)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   887
        qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   888
        ultimately have "goodp ?P ?C"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   889
          using 1[rule_format, of "f 0", OF le_refl, unfolded mbp_def] by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   890
        with `bad ?P ?C` have False by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   891
      }
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   892
      hence no_index: "\<not> (\<exists>f. (\<forall>i. f 0 \<le> f i) \<and> bad ?P (?B \<circ> f))" by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   893
      let ?B' = "{?B i | i. True}"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   894
      have subset: "?B' \<subseteq> UNIV" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   895
      have "wqo_on ?P ?B'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   896
      proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   897
        from emb_refl show "reflp_on ?P ?B'" by (auto simp: reflp_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   898
      next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   899
        from emb_trans show "transp_on ?P ?B'" by (auto simp: transp_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   900
      next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   901
        fix f :: "'a list seq" assume "\<forall>i. f i \<in> ?B'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   902
        from no_bad_of_special_shape_imp_goodp[of ?P ?B f, OF no_index this]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   903
          show "goodp ?P f" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   904
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   905
      let ?a' = "{a i | i. True}"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   906
      have "?a' \<subseteq> UNIV" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   907
      with finite_eq_wqo_on
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   908
        have "wqo_on op = ?a'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   909
        using finite[of UNIV] and finite_subset by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   910
      from wqo_on_Sigma[OF `wqo_on op = ?a'` `wqo_on ?P ?B'`]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   911
        have wqo: "wqo_on (prod_le op = ?P) (?a' \<times> ?B')" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   912
      let ?aB = "\<lambda>i. (a i, ?B i)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   913
      let ?P' = "prod_le op = ?P"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   914
      have "\<forall>i. ?aB i \<in> (?a' \<times> ?B')" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   915
      with wqo have "goodp ?P' ?aB" unfolding wqo_on_def by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   916
      then obtain i j where "i < j" and *: "?P'\<^sup>=\<^sup>= (?aB i) (?aB j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   917
        by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   918
      from hd_Cons_tl and non_empty
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   919
        have hd_tl: "hd (?A i) # tl (?A i) = ?A i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   920
          "hd (?A j) # tl (?A j) = ?A j" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   921
      from * have "(a i = a j \<and> ?B i = ?B j) \<or> (a i = a j \<and> ?P (?B i) (?B j))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   922
        unfolding prod_le_def by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   923
      thus False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   924
      proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   925
        assume *: "a i = a j \<and> ?B i = ?B j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   926
        hence "?A i = ?A j" using a and hd_tl by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   927
        hence "?P\<^sup>=\<^sup>= (?A i) (?A j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   928
        with `i < j` and `bad ?P ?A` show False by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   929
      next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   930
        assume "op = (a i) (a j) \<and> ?P (?B i) (?B j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   931
        hence *: "op = (a i) (a j)" and **: "?P (?B i) (?B j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   932
        with emb_appendI[OF emb_refl[of "[hd (?A i)]"] **]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   933
          have "emb (?A i) (?A j)" using hd_tl a by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   934
        hence "?P\<^sup>=\<^sup>= (?A i) (?A j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   935
        with `i < j` and `bad ?P ?A` show False by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   936
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   937
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   938
  }
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   939
  with refl and trans show ?thesis unfolding wqo_on_def by blast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   940
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   941
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   942
lemma Higman_antichains:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   943
  fixes A :: "('a::finite) list set"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   944
  assumes a: "\<forall>x \<in> A. \<forall>y \<in> A. x \<noteq> y \<longrightarrow> \<not>(emb x y) \<and> \<not>(emb y x)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   945
  shows "finite A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   946
proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   947
  assume "infinite A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   948
  then obtain f :: "nat \<Rightarrow> ('a::finite) list" where b: "inj f" and c: "range f \<subseteq> A"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   949
    by (auto simp add: infinite_iff_countable_subset)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   950
  from wqo_on_imp_goodp[OF wqo_on_finite_lists, simplified, of f]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   951
    obtain i j where d: "i < j" and e: "emb (f i) (f j)" by (auto simp: goodp_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   952
  have "f i \<noteq> f j" using b d by (auto simp add: inj_on_def)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   953
  moreover
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   954
  have "f i \<in> A" using c by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   955
  moreover
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   956
  have "f j \<in> A" using c by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   957
  ultimately have "\<not> (emb (f i) (f j))" using a by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   958
  with e show "False" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   959
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   960
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   961
end