Seq.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 12 Sep 2013 17:20:48 +0100
changeset 386 92ca56c1a199
parent 368 2d6beddb6fa6
permissions -rw-r--r--
soem small changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
368
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     1
(*  Title:       Infinite Sequences
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     2
    Author:      Christian Sternagel <c-sterna@jaist.ac.jp>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     3
                 René Thiemann       <rene.thiemann@uibk.ac.at>
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     4
    Maintainer:  Christian Sternagel and René Thiemann
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     5
    License:     LGPL
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     6
*)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     7
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     8
(*
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
     9
Copyright 2012 Christian Sternagel, René Thiemann
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    10
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    11
This file is part of IsaFoR/CeTA.
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    12
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    13
IsaFoR/CeTA is free software: you can redistribute it and/or modify it under the
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    14
terms of the GNU Lesser General Public License as published by the Free Software
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    15
Foundation, either version 3 of the License, or (at your option) any later
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    16
version.
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    17
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    18
IsaFoR/CeTA is distributed in the hope that it will be useful, but WITHOUT ANY
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    19
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    20
PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    21
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    22
You should have received a copy of the GNU Lesser General Public License along
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    23
with IsaFoR/CeTA. If not, see <http://www.gnu.org/licenses/>.
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    24
*)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    25
header {* Infinite Sequences *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    26
theory Seq
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    27
imports
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    28
  Main
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    29
  "~~/src/HOL/Library/Infinite_Set"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    30
begin
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    31
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    32
text {*Infinite sequences are represented by functions of type @{typ "nat \<Rightarrow> 'a"}.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    33
type_synonym 'a seq = "nat \<Rightarrow> 'a"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    34
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    35
subsection {*Operations on Infinite Sequences*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    36
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    37
text {*Adding a new element at the front.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    38
abbreviation cons :: "'a \<Rightarrow> 'a seq \<Rightarrow> 'a seq" (infixr "#s" 65) where (*FIXME: find better infix symbol*)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    39
  "x #s S \<equiv> (\<lambda>i. case i of 0 \<Rightarrow> x | Suc n \<Rightarrow> S n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    40
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    41
text {*An infinite sequence is \emph{linked} by a binary predicate @{term P} if every two
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    42
consecutive elements satisfy it. Such a sequence is called a \emph{@{term P}-chain}. *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    43
abbreviation (input) chainp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow>'a seq \<Rightarrow> bool" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    44
  "chainp P S \<equiv> \<forall>i. P (S i) (S (Suc i))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    45
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    46
text {*Special version for relations.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    47
abbreviation (input) chain :: "'a rel \<Rightarrow> 'a seq \<Rightarrow> bool" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    48
  "chain r S \<equiv> chainp (\<lambda>x y. (x, y) \<in> r) S"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    49
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    50
text {*Extending a chain at the front.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    51
lemma cons_chainp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    52
  assumes "P x (S 0)" and "chainp P S"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    53
  shows "chainp P (x #s S)" (is "chainp P ?S")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    54
proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    55
  fix i show "P (?S i) (?S (Suc i))" using assms by (cases i) simp_all
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    56
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    57
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    58
text {*Special version for relations.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    59
lemma cons_chain:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    60
  assumes "(x, S 0) \<in> r" and "chain r S" shows "chain r (x #s S)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    61
  using cons_chainp[of "\<lambda>x y. (x, y) \<in> r", OF assms] .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    62
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    63
text {*A chain admits arbitrary transitive steps.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    64
lemma chainp_imp_relpowp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    65
  assumes "chainp P S" shows "(P^^j) (S i) (S (i + j))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    66
proof (induct "i + j" arbitrary: j)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    67
  case (Suc n) thus ?case using assms by (cases j) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    68
qed simp
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 chain_imp_relpow:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    71
  assumes "chain r S" shows "(S i, S (i + j)) \<in> r^^j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    72
proof (induct "i + j" arbitrary: j)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    73
  case (Suc n) thus ?case using assms by (cases j) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    74
qed simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    75
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    76
lemma chainp_imp_tranclp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    77
  assumes "chainp P S" and "i < j" shows "P^++ (S i) (S j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    78
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    79
  from less_imp_Suc_add[OF assms(2)] obtain n where "j = i + Suc n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    80
  with chainp_imp_relpowp[of P S "Suc n" i, OF assms(1)]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    81
    show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    82
      unfolding trancl_power[of "(S i, S j)", to_pred]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    83
      by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    84
qed
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 chain_imp_trancl:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    87
  assumes "chain r S" and "i < j" shows "(S i, S j) \<in> r^+"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    88
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    89
  from less_imp_Suc_add[OF assms(2)] obtain n where "j = i + Suc n" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    90
  with chain_imp_relpow[OF assms(1), of i "Suc n"]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    91
    show ?thesis unfolding trancl_power by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    92
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    93
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    94
text {*A chain admits arbitrary reflexive and transitive steps.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    95
lemma chainp_imp_rtranclp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    96
  assumes "chainp P S" and "i \<le> j" shows "P^** (S i) (S j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    97
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    98
  from assms(2) obtain n where "j = i + n" by (induct "j - i" arbitrary: j) force+
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
    99
  with chainp_imp_relpowp[of P S, OF assms(1), of n i] show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   100
    by (simp add: relpow_imp_rtrancl[of "(S i, S (i + n))", to_pred])
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   101
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   102
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   103
lemma chain_imp_rtrancl:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   104
  assumes "chain r S" and "i \<le> j" shows "(S i, S j) \<in> r^*"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   105
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   106
  from assms(2) obtain n where "j = i + n" by (induct "j - i" arbitrary: j) force+
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   107
  with chain_imp_relpow[OF assms(1), of i n] show ?thesis by (simp add: relpow_imp_rtrancl)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   108
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   109
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   110
text {*If for every @{term i} there is a later index @{term "f i"} such that the
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   111
corresponding elements satisfy the predicate @{term P}, then there is a @{term P}-chain.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   112
lemma stepfun_imp_chainp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   113
  assumes "\<forall>i\<ge>n::nat. f i > i \<and> P (S i) (S (f i))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   114
  shows "chainp P (\<lambda>i. S ((f ^^ i) n))" (is "chainp P ?T")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   115
proof
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   116
  fix i
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   117
  from assms have "(f ^^ i) n \<ge> n" by (induct i) auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   118
  with assms[THEN spec[of _ "(f ^^ i) n"]]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   119
    show "P (?T i) (?T (Suc i))" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   120
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   121
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   122
text {*If for every @{term i} there is a later index @{term j} such that the
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   123
corresponding elements satisfy the predicate @{term P}, then there is a @{term P}-chain.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   124
lemma steps_imp_chainp:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   125
  assumes "\<forall>i\<ge>n::nat. \<exists>j>i. P (S i) (S j)" shows "\<exists>T. chainp P T"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   126
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   127
  from assms have "\<forall>i\<in>{i. i \<ge> n}. \<exists>j>i. P (S i) (S j)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   128
  from bchoice[OF this]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   129
    obtain f where seq: "\<forall>i\<ge>n. f i > i \<and> P (S i) (S (f i))" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   130
  from stepfun_imp_chainp[of n f P S, OF this] show ?thesis by fast
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   131
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   132
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   133
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   134
subsection {* Predicates on Natural Numbers *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   135
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   136
text {*If some property holds for infinitely many natural numbers, obtain
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   137
an index function that points to these numbers in increasing order.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   138
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   139
locale infinitely_many =
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   140
  fixes p :: "nat \<Rightarrow> bool"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   141
  assumes infinite: "INFM j. p j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   142
begin
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   143
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   144
lemma inf: "\<exists>j\<ge>i. p j" using infinite[unfolded INFM_nat_le] by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   145
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   146
fun index :: "nat seq" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   147
  "index 0 = (LEAST n. p n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   148
| "index (Suc n) = (LEAST k. p k \<and> k > index n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   149
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   150
lemma index_p: "p (index n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   151
proof (induct n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   152
  case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   153
  from inf obtain j where "p j" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   154
  with LeastI[of p j] show ?case by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   155
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   156
  case (Suc n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   157
  from inf obtain k where "k \<ge> Suc (index n) \<and> p k" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   158
  with LeastI[of "\<lambda> k. p k \<and> k > index n" k] show ?case by auto
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
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   161
lemma index_ordered: "index n < index (Suc n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   162
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   163
  from inf obtain k where "k \<ge> Suc (index n) \<and> p k" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   164
  with LeastI[of "\<lambda> k. p k \<and> k > index n" k] show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   165
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   166
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   167
lemma index_not_p_between:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   168
  assumes i1: "index n < i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   169
    and i2: "i < index (Suc n)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   170
  shows "\<not> p i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   171
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   172
  from not_less_Least[OF i2[simplified]] i1 show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   173
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   174
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   175
lemma index_ordered_le:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   176
  assumes "i \<le> j" shows "index i \<le> index j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   177
proof - 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   178
  from assms have "j = i + (j - i)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   179
  then obtain k where j: "j = i + k" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   180
  have "index i \<le> index (i + k)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   181
  proof (induct k)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   182
    case (Suc k)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   183
    with index_ordered[of "i + k"]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   184
    show ?case by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   185
  qed simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   186
  thus ?thesis unfolding j .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   187
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   188
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   189
lemma index_surj:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   190
  assumes "k \<ge> index l"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   191
  shows "\<exists>i j. k = index i + j \<and> index i + j < index (Suc i)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   192
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   193
  from assms have "k = index l + (k - index l)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   194
  then obtain u where k: "k = index l + u" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   195
  show ?thesis unfolding k
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   196
  proof (induct u)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   197
    case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   198
    show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   199
      by (intro exI conjI, rule refl, insert index_ordered[of l], simp)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   200
  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   201
    case (Suc u)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   202
    then obtain i j
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   203
      where lu: "index l + u = index i + j" and lt: "index i + j < index (Suc i)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   204
    hence "index l + u < index (Suc i)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   205
    show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   206
    proof (cases "index l + (Suc u) = index (Suc i)")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   207
      case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   208
      show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   209
        by (rule exI[of _ i], rule exI[of _ "Suc j"], insert lu lt False, auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   210
    next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   211
      case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   212
      show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   213
        by (rule exI[of _ "Suc i"], rule exI[of _ 0], insert True index_ordered[of "Suc i"], auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   214
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   215
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   216
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   217
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   218
lemma index_ordered_less:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   219
  assumes "i < j" shows "index i < index j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   220
proof - 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   221
  from assms have "Suc i \<le> j" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   222
  from index_ordered_le[OF this]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   223
  have "index (Suc i) \<le> index j" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   224
  with index_ordered[of i] show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   225
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   226
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   227
lemma index_not_p_start: assumes i: "i < index 0" shows "\<not> p i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   228
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   229
  from i[simplified index.simps] have "i < Least p" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   230
  from not_less_Least[OF this] show ?thesis .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   231
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   232
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   233
end
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   234
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   235
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   236
subsection {* Assembling Infinite Words from Finite Words *}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   237
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   238
text {*Concatenate infinitely many non-empty words to an infinite word.*}
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   239
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   240
fun inf_concat_simple :: "(nat \<Rightarrow> nat) \<Rightarrow> nat \<Rightarrow> (nat \<times> nat)" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   241
  "inf_concat_simple f 0 = (0, 0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   242
| "inf_concat_simple f (Suc n) = (
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   243
    let (i, j) = inf_concat_simple f n in 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   244
    if Suc j < f i then (i, Suc j)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   245
    else (Suc i, 0))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   246
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   247
lemma inf_concat_simple_add:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   248
  assumes ck: "inf_concat_simple f k = (i, j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   249
    and jl: "j + l < f i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   250
  shows "inf_concat_simple f (k + l) = (i,j + l)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   251
using jl
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   252
proof (induct l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   253
  case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   254
  thus ?case using ck by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   255
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   256
  case (Suc l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   257
  hence c: "inf_concat_simple f (k + l) = (i, j+ l)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   258
  show ?case 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   259
    by (simp add: c, insert Suc(2), auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   260
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   261
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   262
lemma inf_concat_simple_surj_zero: "\<exists> k. inf_concat_simple f k = (i,0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   263
proof (induct i)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   264
  case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   265
  show ?case 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   266
    by (rule exI[of _ 0], simp)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   267
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   268
  case (Suc i)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   269
  then obtain k where ck: "inf_concat_simple f k = (i,0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   270
  show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   271
  proof (cases "f i")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   272
    case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   273
    show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   274
      by (rule exI[of _ "Suc k"], simp add: ck 0)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   275
  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   276
    case (Suc n)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   277
    hence "0 + n < f i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   278
    from inf_concat_simple_add[OF ck, OF this] Suc
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   279
    show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   280
      by (intro exI[of _ "k + Suc n"], auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   281
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   282
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   283
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   284
lemma inf_concat_simple_surj:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   285
  assumes "j < f i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   286
  shows "\<exists> k. inf_concat_simple f k = (i,j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   287
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   288
  from assms have j: "0 + j < f i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   289
  from inf_concat_simple_surj_zero obtain k where "inf_concat_simple f k = (i,0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   290
  from inf_concat_simple_add[OF this, OF j] show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   291
qed
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 inf_concat_simple_mono:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   294
  assumes "k \<le> k'" shows "fst (inf_concat_simple f k) \<le> fst (inf_concat_simple f k')"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   295
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   296
  from assms have "k' = k + (k' - k)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   297
  then obtain l where k': "k' = k + l" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   298
  show ?thesis  unfolding k'
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   299
  proof (induct l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   300
    case (Suc l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   301
    obtain i j where ckl: "inf_concat_simple f (k+l) = (i,j)" by (cases "inf_concat_simple f (k+l)", auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   302
    with Suc have "fst (inf_concat_simple f k) \<le> i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   303
    also have "... \<le> fst (inf_concat_simple f (k + Suc l))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   304
      by (simp add: ckl)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   305
    finally show ?case .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   306
  qed simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   307
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   308
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   309
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   310
(* inf_concat assembles infinitely many (possibly empty) words to an infinite word *)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   311
fun inf_concat :: "(nat \<Rightarrow> nat) \<Rightarrow> nat \<Rightarrow> nat \<times> nat" where
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   312
  "inf_concat n 0 = (LEAST j. n j > 0, 0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   313
| "inf_concat n (Suc k) = (let (i, j) = inf_concat n k in (if Suc j < n i then (i, Suc j) else (LEAST i'. i' > i \<and> n i' > 0, 0)))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   314
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   315
lemma inf_concat_bounds:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   316
  assumes inf: "INFM i. n i > 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   317
    and res: "inf_concat n k = (i,j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   318
  shows "j < n i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   319
proof (cases k)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   320
  case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   321
  with res have i: "i = (LEAST i. n i > 0)" and j: "j = 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   322
  from inf[unfolded INFM_nat_le] obtain i' where i': "0 < n i'" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   323
  have "0 < n (LEAST i. n i > 0)" 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   324
    by (rule LeastI, rule i')
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   325
  with i j show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   326
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   327
  case (Suc k')
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   328
  obtain i' j' where res': "inf_concat n k' = (i',j')" by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   329
  note res = res[unfolded Suc inf_concat.simps res' Let_def split]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   330
  show ?thesis 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   331
  proof (cases "Suc j' < n i'")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   332
    case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   333
    with res show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   334
  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   335
    case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   336
    with res have i: "i = (LEAST f. i' < f \<and> 0 < n f)" and j: "j = 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   337
    from inf[unfolded INFM_nat] obtain f where f: "i' < f \<and> 0 < n f" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   338
    have "0 < n (LEAST f. i' < f \<and> 0 < n f)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   339
      using LeastI[of "\<lambda> f. i' < f \<and> 0 < n f", OF f]
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
    with i j show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   342
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   343
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   344
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   345
lemma inf_concat_add:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   346
  assumes res: "inf_concat n k = (i,j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   347
    and j: "j + m < n i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   348
  shows "inf_concat n (k + m) = (i,j+m)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   349
  using j
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   350
proof (induct m)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   351
  case 0 show ?case using res by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   352
next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   353
  case (Suc m)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   354
  hence "inf_concat n (k + m) = (i, j+m)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   355
  with Suc(2)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   356
  show ?case by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   357
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   358
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   359
lemma inf_concat_step:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   360
  assumes res: "inf_concat n k = (i,j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   361
    and j: "Suc (j + m) = n i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   362
  shows "inf_concat n (k + Suc m) = (LEAST i'. i' > i \<and> 0 < n i', 0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   363
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   364
  from j have "j + m < n i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   365
  note res = inf_concat_add[OF res, OF this]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   366
  show ?thesis by (simp add: res j)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   367
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   368
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   369
lemma inf_concat_surj_zero:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   370
  assumes "0 < n i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   371
  shows "\<exists>k. inf_concat n k = (i, 0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   372
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   373
  {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   374
    fix l
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   375
    have "\<forall> j. j < l \<and> 0 < n j \<longrightarrow> (\<exists> k. inf_concat n k = (j,0))"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   376
    proof (induct l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   377
      case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   378
      thus ?case by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   379
    next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   380
      case (Suc l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   381
      show ?case
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   382
      proof (intro allI impI, elim conjE)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   383
        fix j
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   384
        assume j: "j < Suc l" and nj: "0 < n j"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   385
        show "\<exists> k. inf_concat n k = (j, 0)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   386
        proof (cases "j < l")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   387
          case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   388
          from Suc[THEN spec[of _ j]] True nj show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   389
        next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   390
          case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   391
          with j have j: "j = l" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   392
          show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   393
          proof (cases "\<exists> j'. j' < l \<and> 0 < n j'")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   394
            case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   395
            have l: "(LEAST i. 0 < n i) = l"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   396
            proof (rule Least_equality, rule nj[unfolded j])
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   397
              fix l'
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   398
              assume "0 < n l'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   399
              with False have "\<not> l' < l" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   400
              thus "l \<le> l'" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   401
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   402
            show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   403
              by (rule exI[of _ 0], simp add: l j)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   404
          next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   405
            case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   406
            then obtain lll where lll: "lll < l" and nlll: "0 < n lll" by auto 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   407
            then obtain ll where l: "l = Suc ll" by (cases l, auto)   
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   408
            from lll l have lll: "lll = ll - (ll - lll)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   409
            let ?l' = "LEAST d. 0 < n (ll - d)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   410
            have nl': "0 < n (ll - ?l')"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   411
            proof (rule LeastI)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   412
              show "0 < n (ll - (ll - lll))" using lll nlll by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   413
            qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   414
            with Suc[THEN spec[of _ "ll - ?l'"]] obtain k where k:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   415
              "inf_concat n k = (ll - ?l',0)" unfolding l by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   416
            from nl' obtain off where off: "Suc (0 + off) = n (ll - ?l')" by (cases "n (ll - ?l')", auto)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   417
            from inf_concat_step[OF k, OF off]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   418
            have id: "inf_concat n (k + Suc off) = (LEAST i'. ll - ?l' < i' \<and> 0 < n i',0)" (is "_ = (?l,0)") .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   419
            have ll: "?l = l" unfolding l
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   420
            proof (rule Least_equality)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   421
              show "ll - ?l' < Suc ll \<and> 0 < n (Suc ll)" using nj[unfolded j l] by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   422
            next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   423
              fix l'
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   424
              assume ass: "ll - ?l' < l' \<and> 0 < n l'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   425
              show "Suc ll \<le> l'" 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   426
              proof (rule ccontr)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   427
                assume not: "\<not> ?thesis"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   428
                hence "l' \<le> ll" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   429
                hence "ll = l' + (ll - l')" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   430
                then obtain k where ll: "ll = l' + k" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   431
                from ass have "l' + k - ?l' < l'" unfolding ll by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   432
                hence kl': "k < ?l'" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   433
                have "0 < n (ll - k)" using ass unfolding ll by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   434
                from Least_le[of "\<lambda> k. 0 < n (ll - k)", OF this] kl'
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   435
                show False by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   436
              qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   437
            qed            
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   438
            show ?thesis unfolding j
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   439
              by (rule exI[of _ "k + Suc off"], unfold id ll, simp)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   440
          qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   441
        qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   442
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   443
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   444
  }
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   445
  with assms show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   446
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   447
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   448
lemma inf_concat_surj:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   449
  assumes j: "j < n i"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   450
  shows "\<exists>k. inf_concat n k = (i, j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   451
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   452
  from j have "0 < n i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   453
  from inf_concat_surj_zero[of n, OF this]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   454
  obtain k where "inf_concat n k = (i,0)" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   455
  from inf_concat_add[OF this, of j] j
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   456
  show ?thesis by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   457
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   458
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   459
lemma inf_concat_mono:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   460
  assumes inf: "INFM i. n i > 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   461
    and resk: "inf_concat n k = (i, j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   462
    and reskp: "inf_concat n k' = (i', j')"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   463
    and lt: "i < i'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   464
  shows "k < k'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   465
proof -
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   466
  note bounds = inf_concat_bounds[OF inf]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   467
  {
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   468
    assume "k' \<le> k"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   469
    hence "k = k' + (k - k')" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   470
    then obtain l where k: "k = k' + l" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   471
    have "i' \<le> fst (inf_concat n (k' + l))" 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   472
    proof (induct l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   473
      case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   474
      with reskp show ?case by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   475
    next      
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   476
      case (Suc l)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   477
      obtain i'' j'' where l: "inf_concat n (k' + l) = (i'',j'')" by force
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   478
      with Suc have one: "i' \<le> i''" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   479
      from bounds[OF l] have j'': "j'' < n i''" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   480
      show ?case 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   481
      proof (cases "Suc j'' < n i''")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   482
        case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   483
        show ?thesis by (simp add: l True one)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   484
      next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   485
        case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   486
        let ?i = "LEAST i'. i'' < i' \<and> 0 < n i'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   487
        from inf[unfolded INFM_nat] obtain k where "i'' < k \<and> 0 < n k" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   488
        from LeastI[of "\<lambda> k. i'' < k \<and> 0 < n k", OF this]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   489
        have "i'' < ?i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   490
        with one show ?thesis by (simp add: l False)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   491
      qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   492
    qed      
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   493
    with resk k lt have False by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   494
  }
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   495
  thus ?thesis by arith
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   496
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   497
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   498
lemma inf_concat_Suc:
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   499
  assumes inf: "INFM i. n i > 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   500
    and f: "\<And> i. f i (n i) = f (Suc i) 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   501
    and resk: "inf_concat n k = (i, j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   502
    and ressk: "inf_concat n (Suc k) = (i', j')"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   503
  shows "f i' j' = f i (Suc j)"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   504
proof - 
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   505
  note bounds = inf_concat_bounds[OF inf]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   506
  from bounds[OF resk] have j: "j < n i" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   507
  show ?thesis
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   508
  proof (cases "Suc j < n i")
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   509
    case True
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   510
    with ressk resk
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   511
    show ?thesis by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   512
  next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   513
    case False
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   514
    let ?p = "\<lambda> i'. i < i' \<and> 0 < n i'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   515
    let ?i' = "LEAST i'. ?p i'"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   516
    from False j have id: "Suc (j + 0) = n i" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   517
    from inf_concat_step[OF resk, OF id] ressk
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   518
    have i': "i' = ?i'" and j': "j' = 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   519
    from id have j: "Suc j = n i" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   520
    from inf[unfolded INFM_nat] obtain k where "?p k" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   521
    from LeastI[of ?p, OF this] have "?p ?i'" .
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   522
    hence "?i' = Suc i + (?i' - Suc i)" by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   523
    then obtain d where ii': "?i' = Suc i + d" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   524
    from not_less_Least[of _ ?p, unfolded ii'] have d': "\<And> d'. d' < d \<Longrightarrow> n (Suc i + d') = 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   525
    have "f (Suc i) 0 = f ?i' 0" unfolding ii' using d'
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   526
    proof (induct d)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   527
      case 0
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   528
      show ?case by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   529
    next
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   530
      case (Suc d)
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   531
      hence "f (Suc i) 0 = f (Suc i + d) 0" by auto
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   532
      also have "... = f (Suc (Suc i + d)) 0"
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   533
        unfolding f[symmetric]
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   534
        using Suc(2)[of d] by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   535
      finally show ?case by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   536
    qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   537
    thus ?thesis unfolding i' j' j f by simp
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   538
  qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   539
qed
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   540
2d6beddb6fa6 some addition to the MN-paper
urbanc
parents:
diff changeset
   541
end