src/HOL/Library/Nat_Infinity.thy
author blanchet
Mon Aug 02 18:52:51 2010 +0200 (2010-08-02)
changeset 38167 ab528533db92
parent 37765 26bdfb7b680b
child 38621 d6cb7e625d75
permissions -rw-r--r--
help Nitpick
wenzelm@11355
     1
(*  Title:      HOL/Library/Nat_Infinity.thy
haftmann@27110
     2
    Author:     David von Oheimb, TU Muenchen;  Florian Haftmann, TU Muenchen
oheimb@11351
     3
*)
oheimb@11351
     4
wenzelm@14706
     5
header {* Natural numbers with infinity *}
oheimb@11351
     6
nipkow@15131
     7
theory Nat_Infinity
haftmann@30663
     8
imports Main
nipkow@15131
     9
begin
oheimb@11351
    10
haftmann@27110
    11
subsection {* Type definition *}
oheimb@11351
    12
oheimb@11351
    13
text {*
wenzelm@11355
    14
  We extend the standard natural numbers by a special value indicating
haftmann@27110
    15
  infinity.
oheimb@11351
    16
*}
oheimb@11351
    17
oheimb@11351
    18
datatype inat = Fin nat | Infty
oheimb@11351
    19
wenzelm@21210
    20
notation (xsymbols)
wenzelm@19736
    21
  Infty  ("\<infinity>")
wenzelm@19736
    22
wenzelm@21210
    23
notation (HTML output)
wenzelm@19736
    24
  Infty  ("\<infinity>")
wenzelm@19736
    25
oheimb@11351
    26
nipkow@31084
    27
lemma not_Infty_eq[iff]: "(x ~= Infty) = (EX i. x = Fin i)"
nipkow@31084
    28
by (cases x) auto
nipkow@31084
    29
nipkow@31084
    30
lemma not_Fin_eq [iff]: "(ALL y. x ~= Fin y) = (x = Infty)"
nipkow@31077
    31
by (cases x) auto
nipkow@31077
    32
nipkow@31077
    33
haftmann@27110
    34
subsection {* Constructors and numbers *}
haftmann@27110
    35
haftmann@27110
    36
instantiation inat :: "{zero, one, number}"
haftmann@25594
    37
begin
haftmann@25594
    38
haftmann@25594
    39
definition
haftmann@27110
    40
  "0 = Fin 0"
haftmann@25594
    41
haftmann@25594
    42
definition
haftmann@32069
    43
  [code_unfold]: "1 = Fin 1"
haftmann@25594
    44
haftmann@25594
    45
definition
haftmann@32069
    46
  [code_unfold, code del]: "number_of k = Fin (number_of k)"
oheimb@11351
    47
haftmann@25594
    48
instance ..
haftmann@25594
    49
haftmann@25594
    50
end
haftmann@25594
    51
haftmann@27110
    52
definition iSuc :: "inat \<Rightarrow> inat" where
haftmann@27110
    53
  "iSuc i = (case i of Fin n \<Rightarrow> Fin (Suc n) | \<infinity> \<Rightarrow> \<infinity>)"
oheimb@11351
    54
oheimb@11351
    55
lemma Fin_0: "Fin 0 = 0"
haftmann@27110
    56
  by (simp add: zero_inat_def)
haftmann@27110
    57
haftmann@27110
    58
lemma Fin_1: "Fin 1 = 1"
haftmann@27110
    59
  by (simp add: one_inat_def)
haftmann@27110
    60
haftmann@27110
    61
lemma Fin_number: "Fin (number_of k) = number_of k"
haftmann@27110
    62
  by (simp add: number_of_inat_def)
haftmann@27110
    63
haftmann@27110
    64
lemma one_iSuc: "1 = iSuc 0"
haftmann@27110
    65
  by (simp add: zero_inat_def one_inat_def iSuc_def)
oheimb@11351
    66
oheimb@11351
    67
lemma Infty_ne_i0 [simp]: "\<infinity> \<noteq> 0"
haftmann@27110
    68
  by (simp add: zero_inat_def)
oheimb@11351
    69
oheimb@11351
    70
lemma i0_ne_Infty [simp]: "0 \<noteq> \<infinity>"
haftmann@27110
    71
  by (simp add: zero_inat_def)
haftmann@27110
    72
haftmann@27110
    73
lemma zero_inat_eq [simp]:
haftmann@27110
    74
  "number_of k = (0\<Colon>inat) \<longleftrightarrow> number_of k = (0\<Colon>nat)"
haftmann@27110
    75
  "(0\<Colon>inat) = number_of k \<longleftrightarrow> number_of k = (0\<Colon>nat)"
haftmann@27110
    76
  unfolding zero_inat_def number_of_inat_def by simp_all
haftmann@27110
    77
haftmann@27110
    78
lemma one_inat_eq [simp]:
haftmann@27110
    79
  "number_of k = (1\<Colon>inat) \<longleftrightarrow> number_of k = (1\<Colon>nat)"
haftmann@27110
    80
  "(1\<Colon>inat) = number_of k \<longleftrightarrow> number_of k = (1\<Colon>nat)"
haftmann@27110
    81
  unfolding one_inat_def number_of_inat_def by simp_all
haftmann@27110
    82
haftmann@27110
    83
lemma zero_one_inat_neq [simp]:
haftmann@27110
    84
  "\<not> 0 = (1\<Colon>inat)"
haftmann@27110
    85
  "\<not> 1 = (0\<Colon>inat)"
haftmann@27110
    86
  unfolding zero_inat_def one_inat_def by simp_all
oheimb@11351
    87
haftmann@27110
    88
lemma Infty_ne_i1 [simp]: "\<infinity> \<noteq> 1"
haftmann@27110
    89
  by (simp add: one_inat_def)
haftmann@27110
    90
haftmann@27110
    91
lemma i1_ne_Infty [simp]: "1 \<noteq> \<infinity>"
haftmann@27110
    92
  by (simp add: one_inat_def)
haftmann@27110
    93
haftmann@27110
    94
lemma Infty_ne_number [simp]: "\<infinity> \<noteq> number_of k"
haftmann@27110
    95
  by (simp add: number_of_inat_def)
haftmann@27110
    96
haftmann@27110
    97
lemma number_ne_Infty [simp]: "number_of k \<noteq> \<infinity>"
haftmann@27110
    98
  by (simp add: number_of_inat_def)
haftmann@27110
    99
haftmann@27110
   100
lemma iSuc_Fin: "iSuc (Fin n) = Fin (Suc n)"
haftmann@27110
   101
  by (simp add: iSuc_def)
haftmann@27110
   102
haftmann@27110
   103
lemma iSuc_number_of: "iSuc (number_of k) = Fin (Suc (number_of k))"
haftmann@27110
   104
  by (simp add: iSuc_Fin number_of_inat_def)
oheimb@11351
   105
oheimb@11351
   106
lemma iSuc_Infty [simp]: "iSuc \<infinity> = \<infinity>"
haftmann@27110
   107
  by (simp add: iSuc_def)
oheimb@11351
   108
oheimb@11351
   109
lemma iSuc_ne_0 [simp]: "iSuc n \<noteq> 0"
haftmann@27110
   110
  by (simp add: iSuc_def zero_inat_def split: inat.splits)
haftmann@27110
   111
haftmann@27110
   112
lemma zero_ne_iSuc [simp]: "0 \<noteq> iSuc n"
haftmann@27110
   113
  by (rule iSuc_ne_0 [symmetric])
oheimb@11351
   114
haftmann@27110
   115
lemma iSuc_inject [simp]: "iSuc m = iSuc n \<longleftrightarrow> m = n"
haftmann@27110
   116
  by (simp add: iSuc_def split: inat.splits)
haftmann@27110
   117
haftmann@27110
   118
lemma number_of_inat_inject [simp]:
haftmann@27110
   119
  "(number_of k \<Colon> inat) = number_of l \<longleftrightarrow> (number_of k \<Colon> nat) = number_of l"
haftmann@27110
   120
  by (simp add: number_of_inat_def)
oheimb@11351
   121
oheimb@11351
   122
haftmann@27110
   123
subsection {* Addition *}
haftmann@27110
   124
haftmann@27110
   125
instantiation inat :: comm_monoid_add
haftmann@27110
   126
begin
haftmann@27110
   127
blanchet@38167
   128
definition [nitpick_simp]:
haftmann@37765
   129
  "m + n = (case m of \<infinity> \<Rightarrow> \<infinity> | Fin m \<Rightarrow> (case n of \<infinity> \<Rightarrow> \<infinity> | Fin n \<Rightarrow> Fin (m + n)))"
oheimb@11351
   130
haftmann@27110
   131
lemma plus_inat_simps [simp, code]:
haftmann@27110
   132
  "Fin m + Fin n = Fin (m + n)"
haftmann@27110
   133
  "\<infinity> + q = \<infinity>"
haftmann@27110
   134
  "q + \<infinity> = \<infinity>"
haftmann@27110
   135
  by (simp_all add: plus_inat_def split: inat.splits)
haftmann@27110
   136
haftmann@27110
   137
instance proof
haftmann@27110
   138
  fix n m q :: inat
haftmann@27110
   139
  show "n + m + q = n + (m + q)"
haftmann@27110
   140
    by (cases n, auto, cases m, auto, cases q, auto)
haftmann@27110
   141
  show "n + m = m + n"
haftmann@27110
   142
    by (cases n, auto, cases m, auto)
haftmann@27110
   143
  show "0 + n = n"
haftmann@27110
   144
    by (cases n) (simp_all add: zero_inat_def)
huffman@26089
   145
qed
huffman@26089
   146
haftmann@27110
   147
end
oheimb@11351
   148
haftmann@27110
   149
lemma plus_inat_0 [simp]:
haftmann@27110
   150
  "0 + (q\<Colon>inat) = q"
haftmann@27110
   151
  "(q\<Colon>inat) + 0 = q"
haftmann@27110
   152
  by (simp_all add: plus_inat_def zero_inat_def split: inat.splits)
oheimb@11351
   153
haftmann@27110
   154
lemma plus_inat_number [simp]:
huffman@29012
   155
  "(number_of k \<Colon> inat) + number_of l = (if k < Int.Pls then number_of l
huffman@29012
   156
    else if l < Int.Pls then number_of k else number_of (k + l))"
haftmann@27110
   157
  unfolding number_of_inat_def plus_inat_simps nat_arith(1) if_distrib [symmetric, of _ Fin] ..
oheimb@11351
   158
haftmann@27110
   159
lemma iSuc_number [simp]:
haftmann@27110
   160
  "iSuc (number_of k) = (if neg (number_of k \<Colon> int) then 1 else number_of (Int.succ k))"
haftmann@27110
   161
  unfolding iSuc_number_of
haftmann@27110
   162
  unfolding one_inat_def number_of_inat_def Suc_nat_number_of if_distrib [symmetric] ..
oheimb@11351
   163
haftmann@27110
   164
lemma iSuc_plus_1:
haftmann@27110
   165
  "iSuc n = n + 1"
haftmann@27110
   166
  by (cases n) (simp_all add: iSuc_Fin one_inat_def)
haftmann@27110
   167
  
haftmann@27110
   168
lemma plus_1_iSuc:
haftmann@27110
   169
  "1 + q = iSuc q"
haftmann@27110
   170
  "q + 1 = iSuc q"
haftmann@27110
   171
  unfolding iSuc_plus_1 by (simp_all add: add_ac)
oheimb@11351
   172
oheimb@11351
   173
huffman@29014
   174
subsection {* Multiplication *}
huffman@29014
   175
huffman@29014
   176
instantiation inat :: comm_semiring_1
huffman@29014
   177
begin
huffman@29014
   178
blanchet@38167
   179
definition times_inat_def [nitpick_simp]:
huffman@29014
   180
  "m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | Fin m \<Rightarrow>
huffman@29014
   181
    (case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | Fin n \<Rightarrow> Fin (m * n)))"
huffman@29014
   182
huffman@29014
   183
lemma times_inat_simps [simp, code]:
huffman@29014
   184
  "Fin m * Fin n = Fin (m * n)"
huffman@29014
   185
  "\<infinity> * \<infinity> = \<infinity>"
huffman@29014
   186
  "\<infinity> * Fin n = (if n = 0 then 0 else \<infinity>)"
huffman@29014
   187
  "Fin m * \<infinity> = (if m = 0 then 0 else \<infinity>)"
huffman@29014
   188
  unfolding times_inat_def zero_inat_def
huffman@29014
   189
  by (simp_all split: inat.split)
huffman@29014
   190
huffman@29014
   191
instance proof
huffman@29014
   192
  fix a b c :: inat
huffman@29014
   193
  show "(a * b) * c = a * (b * c)"
huffman@29014
   194
    unfolding times_inat_def zero_inat_def
huffman@29014
   195
    by (simp split: inat.split)
huffman@29014
   196
  show "a * b = b * a"
huffman@29014
   197
    unfolding times_inat_def zero_inat_def
huffman@29014
   198
    by (simp split: inat.split)
huffman@29014
   199
  show "1 * a = a"
huffman@29014
   200
    unfolding times_inat_def zero_inat_def one_inat_def
huffman@29014
   201
    by (simp split: inat.split)
huffman@29014
   202
  show "(a + b) * c = a * c + b * c"
huffman@29014
   203
    unfolding times_inat_def zero_inat_def
huffman@29014
   204
    by (simp split: inat.split add: left_distrib)
huffman@29014
   205
  show "0 * a = 0"
huffman@29014
   206
    unfolding times_inat_def zero_inat_def
huffman@29014
   207
    by (simp split: inat.split)
huffman@29014
   208
  show "a * 0 = 0"
huffman@29014
   209
    unfolding times_inat_def zero_inat_def
huffman@29014
   210
    by (simp split: inat.split)
huffman@29014
   211
  show "(0::inat) \<noteq> 1"
huffman@29014
   212
    unfolding zero_inat_def one_inat_def
huffman@29014
   213
    by simp
huffman@29014
   214
qed
huffman@29014
   215
huffman@29014
   216
end
huffman@29014
   217
huffman@29014
   218
lemma mult_iSuc: "iSuc m * n = n + m * n"
nipkow@29667
   219
  unfolding iSuc_plus_1 by (simp add: algebra_simps)
huffman@29014
   220
huffman@29014
   221
lemma mult_iSuc_right: "m * iSuc n = m + m * n"
nipkow@29667
   222
  unfolding iSuc_plus_1 by (simp add: algebra_simps)
huffman@29014
   223
huffman@29023
   224
lemma of_nat_eq_Fin: "of_nat n = Fin n"
huffman@29023
   225
  apply (induct n)
huffman@29023
   226
  apply (simp add: Fin_0)
huffman@29023
   227
  apply (simp add: plus_1_iSuc iSuc_Fin)
huffman@29023
   228
  done
huffman@29023
   229
huffman@29023
   230
instance inat :: semiring_char_0
huffman@29023
   231
  by default (simp add: of_nat_eq_Fin)
huffman@29023
   232
huffman@29014
   233
haftmann@27110
   234
subsection {* Ordering *}
haftmann@27110
   235
haftmann@35028
   236
instantiation inat :: linordered_ab_semigroup_add
haftmann@27110
   237
begin
oheimb@11351
   238
blanchet@38167
   239
definition [nitpick_simp]:
haftmann@37765
   240
  "m \<le> n = (case n of Fin n1 \<Rightarrow> (case m of Fin m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False)
haftmann@27110
   241
    | \<infinity> \<Rightarrow> True)"
oheimb@11351
   242
blanchet@38167
   243
definition [nitpick_simp]:
haftmann@37765
   244
  "m < n = (case m of Fin m1 \<Rightarrow> (case n of Fin n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True)
haftmann@27110
   245
    | \<infinity> \<Rightarrow> False)"
oheimb@11351
   246
haftmann@27110
   247
lemma inat_ord_simps [simp]:
haftmann@27110
   248
  "Fin m \<le> Fin n \<longleftrightarrow> m \<le> n"
haftmann@27110
   249
  "Fin m < Fin n \<longleftrightarrow> m < n"
haftmann@27110
   250
  "q \<le> \<infinity>"
haftmann@27110
   251
  "q < \<infinity> \<longleftrightarrow> q \<noteq> \<infinity>"
haftmann@27110
   252
  "\<infinity> \<le> q \<longleftrightarrow> q = \<infinity>"
haftmann@27110
   253
  "\<infinity> < q \<longleftrightarrow> False"
haftmann@27110
   254
  by (simp_all add: less_eq_inat_def less_inat_def split: inat.splits)
oheimb@11351
   255
haftmann@27110
   256
lemma inat_ord_code [code]:
haftmann@27110
   257
  "Fin m \<le> Fin n \<longleftrightarrow> m \<le> n"
haftmann@27110
   258
  "Fin m < Fin n \<longleftrightarrow> m < n"
haftmann@27110
   259
  "q \<le> \<infinity> \<longleftrightarrow> True"
haftmann@27110
   260
  "Fin m < \<infinity> \<longleftrightarrow> True"
haftmann@27110
   261
  "\<infinity> \<le> Fin n \<longleftrightarrow> False"
haftmann@27110
   262
  "\<infinity> < q \<longleftrightarrow> False"
haftmann@27110
   263
  by simp_all
oheimb@11351
   264
haftmann@27110
   265
instance by default
haftmann@27110
   266
  (auto simp add: less_eq_inat_def less_inat_def plus_inat_def split: inat.splits)
oheimb@11351
   267
haftmann@27110
   268
end
haftmann@27110
   269
haftmann@35028
   270
instance inat :: ordered_comm_semiring
huffman@29014
   271
proof
huffman@29014
   272
  fix a b c :: inat
huffman@29014
   273
  assume "a \<le> b" and "0 \<le> c"
huffman@29014
   274
  thus "c * a \<le> c * b"
huffman@29014
   275
    unfolding times_inat_def less_eq_inat_def zero_inat_def
huffman@29014
   276
    by (simp split: inat.splits)
huffman@29014
   277
qed
huffman@29014
   278
haftmann@27110
   279
lemma inat_ord_number [simp]:
haftmann@27110
   280
  "(number_of m \<Colon> inat) \<le> number_of n \<longleftrightarrow> (number_of m \<Colon> nat) \<le> number_of n"
haftmann@27110
   281
  "(number_of m \<Colon> inat) < number_of n \<longleftrightarrow> (number_of m \<Colon> nat) < number_of n"
haftmann@27110
   282
  by (simp_all add: number_of_inat_def)
oheimb@11351
   283
haftmann@27110
   284
lemma i0_lb [simp]: "(0\<Colon>inat) \<le> n"
haftmann@27110
   285
  by (simp add: zero_inat_def less_eq_inat_def split: inat.splits)
oheimb@11351
   286
haftmann@27110
   287
lemma i0_neq [simp]: "n \<le> (0\<Colon>inat) \<longleftrightarrow> n = 0"
haftmann@27110
   288
  by (simp add: zero_inat_def less_eq_inat_def split: inat.splits)
haftmann@27110
   289
haftmann@27110
   290
lemma Infty_ileE [elim!]: "\<infinity> \<le> Fin m \<Longrightarrow> R"
haftmann@27110
   291
  by (simp add: zero_inat_def less_eq_inat_def split: inat.splits)
oheimb@11351
   292
haftmann@27110
   293
lemma Infty_ilessE [elim!]: "\<infinity> < Fin m \<Longrightarrow> R"
haftmann@27110
   294
  by simp
oheimb@11351
   295
haftmann@27110
   296
lemma not_ilessi0 [simp]: "\<not> n < (0\<Colon>inat)"
haftmann@27110
   297
  by (simp add: zero_inat_def less_inat_def split: inat.splits)
haftmann@27110
   298
haftmann@27110
   299
lemma i0_eq [simp]: "(0\<Colon>inat) < n \<longleftrightarrow> n \<noteq> 0"
haftmann@27110
   300
  by (simp add: zero_inat_def less_inat_def split: inat.splits)
oheimb@11351
   301
haftmann@27110
   302
lemma iSuc_ile_mono [simp]: "iSuc n \<le> iSuc m \<longleftrightarrow> n \<le> m"
haftmann@27110
   303
  by (simp add: iSuc_def less_eq_inat_def split: inat.splits)
haftmann@27110
   304
 
haftmann@27110
   305
lemma iSuc_mono [simp]: "iSuc n < iSuc m \<longleftrightarrow> n < m"
haftmann@27110
   306
  by (simp add: iSuc_def less_inat_def split: inat.splits)
oheimb@11351
   307
haftmann@27110
   308
lemma ile_iSuc [simp]: "n \<le> iSuc n"
haftmann@27110
   309
  by (simp add: iSuc_def less_eq_inat_def split: inat.splits)
oheimb@11351
   310
wenzelm@11355
   311
lemma not_iSuc_ilei0 [simp]: "\<not> iSuc n \<le> 0"
haftmann@27110
   312
  by (simp add: zero_inat_def iSuc_def less_eq_inat_def split: inat.splits)
haftmann@27110
   313
haftmann@27110
   314
lemma i0_iless_iSuc [simp]: "0 < iSuc n"
haftmann@27110
   315
  by (simp add: zero_inat_def iSuc_def less_inat_def split: inat.splits)
haftmann@27110
   316
haftmann@27110
   317
lemma ileI1: "m < n \<Longrightarrow> iSuc m \<le> n"
haftmann@27110
   318
  by (simp add: iSuc_def less_eq_inat_def less_inat_def split: inat.splits)
haftmann@27110
   319
haftmann@27110
   320
lemma Suc_ile_eq: "Fin (Suc m) \<le> n \<longleftrightarrow> Fin m < n"
haftmann@27110
   321
  by (cases n) auto
haftmann@27110
   322
haftmann@27110
   323
lemma iless_Suc_eq [simp]: "Fin m < iSuc n \<longleftrightarrow> Fin m \<le> n"
haftmann@27110
   324
  by (auto simp add: iSuc_def less_inat_def split: inat.splits)
oheimb@11351
   325
haftmann@27110
   326
lemma min_inat_simps [simp]:
haftmann@27110
   327
  "min (Fin m) (Fin n) = Fin (min m n)"
haftmann@27110
   328
  "min q 0 = 0"
haftmann@27110
   329
  "min 0 q = 0"
haftmann@27110
   330
  "min q \<infinity> = q"
haftmann@27110
   331
  "min \<infinity> q = q"
haftmann@27110
   332
  by (auto simp add: min_def)
oheimb@11351
   333
haftmann@27110
   334
lemma max_inat_simps [simp]:
haftmann@27110
   335
  "max (Fin m) (Fin n) = Fin (max m n)"
haftmann@27110
   336
  "max q 0 = q"
haftmann@27110
   337
  "max 0 q = q"
haftmann@27110
   338
  "max q \<infinity> = \<infinity>"
haftmann@27110
   339
  "max \<infinity> q = \<infinity>"
haftmann@27110
   340
  by (simp_all add: max_def)
haftmann@27110
   341
haftmann@27110
   342
lemma Fin_ile: "n \<le> Fin m \<Longrightarrow> \<exists>k. n = Fin k"
haftmann@27110
   343
  by (cases n) simp_all
haftmann@27110
   344
haftmann@27110
   345
lemma Fin_iless: "n < Fin m \<Longrightarrow> \<exists>k. n = Fin k"
haftmann@27110
   346
  by (cases n) simp_all
oheimb@11351
   347
oheimb@11351
   348
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. Fin k < Y j"
nipkow@25134
   349
apply (induct_tac k)
nipkow@25134
   350
 apply (simp (no_asm) only: Fin_0)
haftmann@27110
   351
 apply (fast intro: le_less_trans [OF i0_lb])
nipkow@25134
   352
apply (erule exE)
nipkow@25134
   353
apply (drule spec)
nipkow@25134
   354
apply (erule exE)
nipkow@25134
   355
apply (drule ileI1)
nipkow@25134
   356
apply (rule iSuc_Fin [THEN subst])
nipkow@25134
   357
apply (rule exI)
haftmann@27110
   358
apply (erule (1) le_less_trans)
nipkow@25134
   359
done
oheimb@11351
   360
haftmann@29337
   361
instantiation inat :: "{bot, top}"
haftmann@29337
   362
begin
haftmann@29337
   363
haftmann@29337
   364
definition bot_inat :: inat where
haftmann@29337
   365
  "bot_inat = 0"
haftmann@29337
   366
haftmann@29337
   367
definition top_inat :: inat where
haftmann@29337
   368
  "top_inat = \<infinity>"
haftmann@29337
   369
haftmann@29337
   370
instance proof
haftmann@29337
   371
qed (simp_all add: bot_inat_def top_inat_def)
haftmann@29337
   372
haftmann@29337
   373
end
haftmann@29337
   374
huffman@26089
   375
haftmann@27110
   376
subsection {* Well-ordering *}
huffman@26089
   377
huffman@26089
   378
lemma less_FinE:
huffman@26089
   379
  "[| n < Fin m; !!k. n = Fin k ==> k < m ==> P |] ==> P"
huffman@26089
   380
by (induct n) auto
huffman@26089
   381
huffman@26089
   382
lemma less_InftyE:
huffman@26089
   383
  "[| n < Infty; !!k. n = Fin k ==> P |] ==> P"
huffman@26089
   384
by (induct n) auto
huffman@26089
   385
huffman@26089
   386
lemma inat_less_induct:
huffman@26089
   387
  assumes prem: "!!n. \<forall>m::inat. m < n --> P m ==> P n" shows "P n"
huffman@26089
   388
proof -
huffman@26089
   389
  have P_Fin: "!!k. P (Fin k)"
huffman@26089
   390
    apply (rule nat_less_induct)
huffman@26089
   391
    apply (rule prem, clarify)
huffman@26089
   392
    apply (erule less_FinE, simp)
huffman@26089
   393
    done
huffman@26089
   394
  show ?thesis
huffman@26089
   395
  proof (induct n)
huffman@26089
   396
    fix nat
huffman@26089
   397
    show "P (Fin nat)" by (rule P_Fin)
huffman@26089
   398
  next
huffman@26089
   399
    show "P Infty"
huffman@26089
   400
      apply (rule prem, clarify)
huffman@26089
   401
      apply (erule less_InftyE)
huffman@26089
   402
      apply (simp add: P_Fin)
huffman@26089
   403
      done
huffman@26089
   404
  qed
huffman@26089
   405
qed
huffman@26089
   406
huffman@26089
   407
instance inat :: wellorder
huffman@26089
   408
proof
haftmann@27823
   409
  fix P and n
haftmann@27823
   410
  assume hyp: "(\<And>n\<Colon>inat. (\<And>m\<Colon>inat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)"
haftmann@27823
   411
  show "P n" by (blast intro: inat_less_induct hyp)
huffman@26089
   412
qed
huffman@26089
   413
haftmann@27110
   414
haftmann@27110
   415
subsection {* Traditional theorem names *}
haftmann@27110
   416
haftmann@27110
   417
lemmas inat_defs = zero_inat_def one_inat_def number_of_inat_def iSuc_def
haftmann@27110
   418
  plus_inat_def less_eq_inat_def less_inat_def
haftmann@27110
   419
haftmann@27110
   420
lemmas inat_splits = inat.splits
haftmann@27110
   421
oheimb@11351
   422
end