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