src/HOL/Library/Nat_Infinity.thy
author noschinl
Thu May 26 23:21:00 2011 +0200 (2011-05-26)
changeset 42993 da014b00d7a4
parent 41855 c3b6e69da386
child 43532 d32d72ea3215
permissions -rw-r--r--
instance inat for complete_lattice
wenzelm@11355
     1
(*  Title:      HOL/Library/Nat_Infinity.thy
haftmann@27110
     2
    Author:     David von Oheimb, TU Muenchen;  Florian Haftmann, TU Muenchen
nipkow@41853
     3
    Contributions: David Trachtenherz, TU Muenchen
oheimb@11351
     4
*)
oheimb@11351
     5
wenzelm@14706
     6
header {* Natural numbers with infinity *}
oheimb@11351
     7
nipkow@15131
     8
theory Nat_Infinity
haftmann@30663
     9
imports Main
nipkow@15131
    10
begin
oheimb@11351
    11
haftmann@27110
    12
subsection {* Type definition *}
oheimb@11351
    13
oheimb@11351
    14
text {*
wenzelm@11355
    15
  We extend the standard natural numbers by a special value indicating
haftmann@27110
    16
  infinity.
oheimb@11351
    17
*}
oheimb@11351
    18
oheimb@11351
    19
datatype inat = Fin nat | Infty
oheimb@11351
    20
wenzelm@21210
    21
notation (xsymbols)
wenzelm@19736
    22
  Infty  ("\<infinity>")
wenzelm@19736
    23
wenzelm@21210
    24
notation (HTML output)
wenzelm@19736
    25
  Infty  ("\<infinity>")
wenzelm@19736
    26
oheimb@11351
    27
nipkow@31084
    28
lemma not_Infty_eq[iff]: "(x ~= Infty) = (EX i. x = Fin i)"
nipkow@31084
    29
by (cases x) auto
nipkow@31084
    30
nipkow@31084
    31
lemma not_Fin_eq [iff]: "(ALL y. x ~= Fin y) = (x = Infty)"
nipkow@31077
    32
by (cases x) auto
nipkow@31077
    33
nipkow@31077
    34
nipkow@41855
    35
primrec the_Fin :: "inat \<Rightarrow> nat"
nipkow@41855
    36
where "the_Fin (Fin n) = n"
nipkow@41855
    37
nipkow@41855
    38
haftmann@27110
    39
subsection {* Constructors and numbers *}
haftmann@27110
    40
haftmann@27110
    41
instantiation inat :: "{zero, one, number}"
haftmann@25594
    42
begin
haftmann@25594
    43
haftmann@25594
    44
definition
haftmann@27110
    45
  "0 = Fin 0"
haftmann@25594
    46
haftmann@25594
    47
definition
haftmann@32069
    48
  [code_unfold]: "1 = Fin 1"
haftmann@25594
    49
haftmann@25594
    50
definition
haftmann@32069
    51
  [code_unfold, code del]: "number_of k = Fin (number_of k)"
oheimb@11351
    52
haftmann@25594
    53
instance ..
haftmann@25594
    54
haftmann@25594
    55
end
haftmann@25594
    56
haftmann@27110
    57
definition iSuc :: "inat \<Rightarrow> inat" where
haftmann@27110
    58
  "iSuc i = (case i of Fin n \<Rightarrow> Fin (Suc n) | \<infinity> \<Rightarrow> \<infinity>)"
oheimb@11351
    59
oheimb@11351
    60
lemma Fin_0: "Fin 0 = 0"
haftmann@27110
    61
  by (simp add: zero_inat_def)
haftmann@27110
    62
haftmann@27110
    63
lemma Fin_1: "Fin 1 = 1"
haftmann@27110
    64
  by (simp add: one_inat_def)
haftmann@27110
    65
haftmann@27110
    66
lemma Fin_number: "Fin (number_of k) = number_of k"
haftmann@27110
    67
  by (simp add: number_of_inat_def)
haftmann@27110
    68
haftmann@27110
    69
lemma one_iSuc: "1 = iSuc 0"
haftmann@27110
    70
  by (simp add: zero_inat_def one_inat_def iSuc_def)
oheimb@11351
    71
oheimb@11351
    72
lemma Infty_ne_i0 [simp]: "\<infinity> \<noteq> 0"
haftmann@27110
    73
  by (simp add: zero_inat_def)
oheimb@11351
    74
oheimb@11351
    75
lemma i0_ne_Infty [simp]: "0 \<noteq> \<infinity>"
haftmann@27110
    76
  by (simp add: zero_inat_def)
haftmann@27110
    77
haftmann@27110
    78
lemma zero_inat_eq [simp]:
haftmann@27110
    79
  "number_of k = (0\<Colon>inat) \<longleftrightarrow> number_of k = (0\<Colon>nat)"
haftmann@27110
    80
  "(0\<Colon>inat) = number_of k \<longleftrightarrow> number_of k = (0\<Colon>nat)"
haftmann@27110
    81
  unfolding zero_inat_def number_of_inat_def by simp_all
haftmann@27110
    82
haftmann@27110
    83
lemma one_inat_eq [simp]:
haftmann@27110
    84
  "number_of k = (1\<Colon>inat) \<longleftrightarrow> number_of k = (1\<Colon>nat)"
haftmann@27110
    85
  "(1\<Colon>inat) = number_of k \<longleftrightarrow> number_of k = (1\<Colon>nat)"
haftmann@27110
    86
  unfolding one_inat_def number_of_inat_def by simp_all
haftmann@27110
    87
haftmann@27110
    88
lemma zero_one_inat_neq [simp]:
haftmann@27110
    89
  "\<not> 0 = (1\<Colon>inat)"
haftmann@27110
    90
  "\<not> 1 = (0\<Colon>inat)"
haftmann@27110
    91
  unfolding zero_inat_def one_inat_def by simp_all
oheimb@11351
    92
haftmann@27110
    93
lemma Infty_ne_i1 [simp]: "\<infinity> \<noteq> 1"
haftmann@27110
    94
  by (simp add: one_inat_def)
haftmann@27110
    95
haftmann@27110
    96
lemma i1_ne_Infty [simp]: "1 \<noteq> \<infinity>"
haftmann@27110
    97
  by (simp add: one_inat_def)
haftmann@27110
    98
haftmann@27110
    99
lemma Infty_ne_number [simp]: "\<infinity> \<noteq> number_of k"
haftmann@27110
   100
  by (simp add: number_of_inat_def)
haftmann@27110
   101
haftmann@27110
   102
lemma number_ne_Infty [simp]: "number_of k \<noteq> \<infinity>"
haftmann@27110
   103
  by (simp add: number_of_inat_def)
haftmann@27110
   104
haftmann@27110
   105
lemma iSuc_Fin: "iSuc (Fin n) = Fin (Suc n)"
haftmann@27110
   106
  by (simp add: iSuc_def)
haftmann@27110
   107
haftmann@27110
   108
lemma iSuc_number_of: "iSuc (number_of k) = Fin (Suc (number_of k))"
haftmann@27110
   109
  by (simp add: iSuc_Fin number_of_inat_def)
oheimb@11351
   110
oheimb@11351
   111
lemma iSuc_Infty [simp]: "iSuc \<infinity> = \<infinity>"
haftmann@27110
   112
  by (simp add: iSuc_def)
oheimb@11351
   113
oheimb@11351
   114
lemma iSuc_ne_0 [simp]: "iSuc n \<noteq> 0"
haftmann@27110
   115
  by (simp add: iSuc_def zero_inat_def split: inat.splits)
haftmann@27110
   116
haftmann@27110
   117
lemma zero_ne_iSuc [simp]: "0 \<noteq> iSuc n"
haftmann@27110
   118
  by (rule iSuc_ne_0 [symmetric])
oheimb@11351
   119
haftmann@27110
   120
lemma iSuc_inject [simp]: "iSuc m = iSuc n \<longleftrightarrow> m = n"
haftmann@27110
   121
  by (simp add: iSuc_def split: inat.splits)
haftmann@27110
   122
haftmann@27110
   123
lemma number_of_inat_inject [simp]:
haftmann@27110
   124
  "(number_of k \<Colon> inat) = number_of l \<longleftrightarrow> (number_of k \<Colon> nat) = number_of l"
haftmann@27110
   125
  by (simp add: number_of_inat_def)
oheimb@11351
   126
oheimb@11351
   127
haftmann@27110
   128
subsection {* Addition *}
haftmann@27110
   129
haftmann@27110
   130
instantiation inat :: comm_monoid_add
haftmann@27110
   131
begin
haftmann@27110
   132
blanchet@38167
   133
definition [nitpick_simp]:
haftmann@37765
   134
  "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
   135
haftmann@27110
   136
lemma plus_inat_simps [simp, code]:
haftmann@27110
   137
  "Fin m + Fin n = Fin (m + n)"
haftmann@27110
   138
  "\<infinity> + q = \<infinity>"
haftmann@27110
   139
  "q + \<infinity> = \<infinity>"
haftmann@27110
   140
  by (simp_all add: plus_inat_def split: inat.splits)
haftmann@27110
   141
haftmann@27110
   142
instance proof
haftmann@27110
   143
  fix n m q :: inat
haftmann@27110
   144
  show "n + m + q = n + (m + q)"
haftmann@27110
   145
    by (cases n, auto, cases m, auto, cases q, auto)
haftmann@27110
   146
  show "n + m = m + n"
haftmann@27110
   147
    by (cases n, auto, cases m, auto)
haftmann@27110
   148
  show "0 + n = n"
haftmann@27110
   149
    by (cases n) (simp_all add: zero_inat_def)
huffman@26089
   150
qed
huffman@26089
   151
haftmann@27110
   152
end
oheimb@11351
   153
haftmann@27110
   154
lemma plus_inat_0 [simp]:
haftmann@27110
   155
  "0 + (q\<Colon>inat) = q"
haftmann@27110
   156
  "(q\<Colon>inat) + 0 = q"
haftmann@27110
   157
  by (simp_all add: plus_inat_def zero_inat_def split: inat.splits)
oheimb@11351
   158
haftmann@27110
   159
lemma plus_inat_number [simp]:
huffman@29012
   160
  "(number_of k \<Colon> inat) + number_of l = (if k < Int.Pls then number_of l
huffman@29012
   161
    else if l < Int.Pls then number_of k else number_of (k + l))"
haftmann@27110
   162
  unfolding number_of_inat_def plus_inat_simps nat_arith(1) if_distrib [symmetric, of _ Fin] ..
oheimb@11351
   163
haftmann@27110
   164
lemma iSuc_number [simp]:
haftmann@27110
   165
  "iSuc (number_of k) = (if neg (number_of k \<Colon> int) then 1 else number_of (Int.succ k))"
haftmann@27110
   166
  unfolding iSuc_number_of
haftmann@27110
   167
  unfolding one_inat_def number_of_inat_def Suc_nat_number_of if_distrib [symmetric] ..
oheimb@11351
   168
haftmann@27110
   169
lemma iSuc_plus_1:
haftmann@27110
   170
  "iSuc n = n + 1"
haftmann@27110
   171
  by (cases n) (simp_all add: iSuc_Fin one_inat_def)
haftmann@27110
   172
  
haftmann@27110
   173
lemma plus_1_iSuc:
haftmann@27110
   174
  "1 + q = iSuc q"
haftmann@27110
   175
  "q + 1 = iSuc q"
nipkow@41853
   176
by (simp_all add: iSuc_plus_1 add_ac)
nipkow@41853
   177
nipkow@41853
   178
lemma iadd_Suc: "iSuc m + n = iSuc (m + n)"
nipkow@41853
   179
by (simp_all add: iSuc_plus_1 add_ac)
oheimb@11351
   180
nipkow@41853
   181
lemma iadd_Suc_right: "m + iSuc n = iSuc (m + n)"
nipkow@41853
   182
by (simp only: add_commute[of m] iadd_Suc)
nipkow@41853
   183
nipkow@41853
   184
lemma iadd_is_0: "(m + n = (0::inat)) = (m = 0 \<and> n = 0)"
nipkow@41853
   185
by (cases m, cases n, simp_all add: zero_inat_def)
oheimb@11351
   186
huffman@29014
   187
subsection {* Multiplication *}
huffman@29014
   188
huffman@29014
   189
instantiation inat :: comm_semiring_1
huffman@29014
   190
begin
huffman@29014
   191
blanchet@38167
   192
definition times_inat_def [nitpick_simp]:
huffman@29014
   193
  "m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | Fin m \<Rightarrow>
huffman@29014
   194
    (case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | Fin n \<Rightarrow> Fin (m * n)))"
huffman@29014
   195
huffman@29014
   196
lemma times_inat_simps [simp, code]:
huffman@29014
   197
  "Fin m * Fin n = Fin (m * n)"
huffman@29014
   198
  "\<infinity> * \<infinity> = \<infinity>"
huffman@29014
   199
  "\<infinity> * Fin n = (if n = 0 then 0 else \<infinity>)"
huffman@29014
   200
  "Fin m * \<infinity> = (if m = 0 then 0 else \<infinity>)"
huffman@29014
   201
  unfolding times_inat_def zero_inat_def
huffman@29014
   202
  by (simp_all split: inat.split)
huffman@29014
   203
huffman@29014
   204
instance proof
huffman@29014
   205
  fix a b c :: inat
huffman@29014
   206
  show "(a * b) * c = a * (b * c)"
huffman@29014
   207
    unfolding times_inat_def zero_inat_def
huffman@29014
   208
    by (simp split: inat.split)
huffman@29014
   209
  show "a * b = b * a"
huffman@29014
   210
    unfolding times_inat_def zero_inat_def
huffman@29014
   211
    by (simp split: inat.split)
huffman@29014
   212
  show "1 * a = a"
huffman@29014
   213
    unfolding times_inat_def zero_inat_def one_inat_def
huffman@29014
   214
    by (simp split: inat.split)
huffman@29014
   215
  show "(a + b) * c = a * c + b * c"
huffman@29014
   216
    unfolding times_inat_def zero_inat_def
huffman@29014
   217
    by (simp split: inat.split add: left_distrib)
huffman@29014
   218
  show "0 * a = 0"
huffman@29014
   219
    unfolding times_inat_def zero_inat_def
huffman@29014
   220
    by (simp split: inat.split)
huffman@29014
   221
  show "a * 0 = 0"
huffman@29014
   222
    unfolding times_inat_def zero_inat_def
huffman@29014
   223
    by (simp split: inat.split)
huffman@29014
   224
  show "(0::inat) \<noteq> 1"
huffman@29014
   225
    unfolding zero_inat_def one_inat_def
huffman@29014
   226
    by simp
huffman@29014
   227
qed
huffman@29014
   228
huffman@29014
   229
end
huffman@29014
   230
huffman@29014
   231
lemma mult_iSuc: "iSuc m * n = n + m * n"
nipkow@29667
   232
  unfolding iSuc_plus_1 by (simp add: algebra_simps)
huffman@29014
   233
huffman@29014
   234
lemma mult_iSuc_right: "m * iSuc n = m + m * n"
nipkow@29667
   235
  unfolding iSuc_plus_1 by (simp add: algebra_simps)
huffman@29014
   236
huffman@29023
   237
lemma of_nat_eq_Fin: "of_nat n = Fin n"
huffman@29023
   238
  apply (induct n)
huffman@29023
   239
  apply (simp add: Fin_0)
huffman@29023
   240
  apply (simp add: plus_1_iSuc iSuc_Fin)
huffman@29023
   241
  done
huffman@29023
   242
haftmann@38621
   243
instance inat :: semiring_char_0 proof
haftmann@38621
   244
  have "inj Fin" by (rule injI) simp
haftmann@38621
   245
  then show "inj (\<lambda>n. of_nat n :: inat)" by (simp add: of_nat_eq_Fin)
haftmann@38621
   246
qed
huffman@29023
   247
nipkow@41853
   248
lemma imult_is_0[simp]: "((m::inat) * n = 0) = (m = 0 \<or> n = 0)"
nipkow@41853
   249
by(auto simp add: times_inat_def zero_inat_def split: inat.split)
nipkow@41853
   250
nipkow@41853
   251
lemma imult_is_Infty: "((a::inat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)"
nipkow@41853
   252
by(auto simp add: times_inat_def zero_inat_def split: inat.split)
nipkow@41853
   253
nipkow@41853
   254
nipkow@41853
   255
subsection {* Subtraction *}
nipkow@41853
   256
nipkow@41853
   257
instantiation inat :: minus
nipkow@41853
   258
begin
nipkow@41853
   259
nipkow@41853
   260
definition diff_inat_def:
nipkow@41853
   261
"a - b = (case a of (Fin x) \<Rightarrow> (case b of (Fin y) \<Rightarrow> Fin (x - y) | \<infinity> \<Rightarrow> 0)
nipkow@41853
   262
          | \<infinity> \<Rightarrow> \<infinity>)"
nipkow@41853
   263
nipkow@41853
   264
instance ..
nipkow@41853
   265
nipkow@41853
   266
end
nipkow@41853
   267
nipkow@41853
   268
lemma idiff_Fin_Fin[simp,code]: "Fin a - Fin b = Fin (a - b)"
nipkow@41853
   269
by(simp add: diff_inat_def)
nipkow@41853
   270
nipkow@41853
   271
lemma idiff_Infty[simp,code]: "\<infinity> - n = \<infinity>"
nipkow@41853
   272
by(simp add: diff_inat_def)
nipkow@41853
   273
nipkow@41853
   274
lemma idiff_Infty_right[simp,code]: "Fin a - \<infinity> = 0"
nipkow@41853
   275
by(simp add: diff_inat_def)
nipkow@41853
   276
nipkow@41853
   277
lemma idiff_0[simp]: "(0::inat) - n = 0"
nipkow@41853
   278
by (cases n, simp_all add: zero_inat_def)
nipkow@41853
   279
nipkow@41853
   280
lemmas idiff_Fin_0[simp] = idiff_0[unfolded zero_inat_def]
nipkow@41853
   281
nipkow@41853
   282
lemma idiff_0_right[simp]: "(n::inat) - 0 = n"
nipkow@41853
   283
by (cases n) (simp_all add: zero_inat_def)
nipkow@41853
   284
nipkow@41853
   285
lemmas idiff_Fin_0_right[simp] = idiff_0_right[unfolded zero_inat_def]
nipkow@41853
   286
nipkow@41853
   287
lemma idiff_self[simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::inat) - n = 0"
nipkow@41853
   288
by(auto simp: zero_inat_def)
nipkow@41853
   289
nipkow@41855
   290
lemma iSuc_minus_iSuc [simp]: "iSuc n - iSuc m = n - m"
nipkow@41855
   291
by(simp add: iSuc_def split: inat.split)
nipkow@41855
   292
nipkow@41855
   293
lemma iSuc_minus_1 [simp]: "iSuc n - 1 = n"
nipkow@41855
   294
by(simp add: one_inat_def iSuc_Fin[symmetric] zero_inat_def[symmetric])
nipkow@41855
   295
nipkow@41853
   296
(*lemmas idiff_self_eq_0_Fin = idiff_self_eq_0[unfolded zero_inat_def]*)
nipkow@41853
   297
huffman@29014
   298
haftmann@27110
   299
subsection {* Ordering *}
haftmann@27110
   300
haftmann@35028
   301
instantiation inat :: linordered_ab_semigroup_add
haftmann@27110
   302
begin
oheimb@11351
   303
blanchet@38167
   304
definition [nitpick_simp]:
haftmann@37765
   305
  "m \<le> n = (case n of Fin n1 \<Rightarrow> (case m of Fin m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False)
haftmann@27110
   306
    | \<infinity> \<Rightarrow> True)"
oheimb@11351
   307
blanchet@38167
   308
definition [nitpick_simp]:
haftmann@37765
   309
  "m < n = (case m of Fin m1 \<Rightarrow> (case n of Fin n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True)
haftmann@27110
   310
    | \<infinity> \<Rightarrow> False)"
oheimb@11351
   311
haftmann@27110
   312
lemma inat_ord_simps [simp]:
haftmann@27110
   313
  "Fin m \<le> Fin n \<longleftrightarrow> m \<le> n"
haftmann@27110
   314
  "Fin m < Fin n \<longleftrightarrow> m < n"
haftmann@27110
   315
  "q \<le> \<infinity>"
haftmann@27110
   316
  "q < \<infinity> \<longleftrightarrow> q \<noteq> \<infinity>"
haftmann@27110
   317
  "\<infinity> \<le> q \<longleftrightarrow> q = \<infinity>"
haftmann@27110
   318
  "\<infinity> < q \<longleftrightarrow> False"
haftmann@27110
   319
  by (simp_all add: less_eq_inat_def less_inat_def split: inat.splits)
oheimb@11351
   320
haftmann@27110
   321
lemma inat_ord_code [code]:
haftmann@27110
   322
  "Fin m \<le> Fin n \<longleftrightarrow> m \<le> n"
haftmann@27110
   323
  "Fin m < Fin n \<longleftrightarrow> m < n"
haftmann@27110
   324
  "q \<le> \<infinity> \<longleftrightarrow> True"
haftmann@27110
   325
  "Fin m < \<infinity> \<longleftrightarrow> True"
haftmann@27110
   326
  "\<infinity> \<le> Fin n \<longleftrightarrow> False"
haftmann@27110
   327
  "\<infinity> < q \<longleftrightarrow> False"
haftmann@27110
   328
  by simp_all
oheimb@11351
   329
haftmann@27110
   330
instance by default
haftmann@27110
   331
  (auto simp add: less_eq_inat_def less_inat_def plus_inat_def split: inat.splits)
oheimb@11351
   332
haftmann@27110
   333
end
haftmann@27110
   334
haftmann@35028
   335
instance inat :: ordered_comm_semiring
huffman@29014
   336
proof
huffman@29014
   337
  fix a b c :: inat
huffman@29014
   338
  assume "a \<le> b" and "0 \<le> c"
huffman@29014
   339
  thus "c * a \<le> c * b"
huffman@29014
   340
    unfolding times_inat_def less_eq_inat_def zero_inat_def
huffman@29014
   341
    by (simp split: inat.splits)
huffman@29014
   342
qed
huffman@29014
   343
haftmann@27110
   344
lemma inat_ord_number [simp]:
haftmann@27110
   345
  "(number_of m \<Colon> inat) \<le> number_of n \<longleftrightarrow> (number_of m \<Colon> nat) \<le> number_of n"
haftmann@27110
   346
  "(number_of m \<Colon> inat) < number_of n \<longleftrightarrow> (number_of m \<Colon> nat) < number_of n"
haftmann@27110
   347
  by (simp_all add: number_of_inat_def)
oheimb@11351
   348
haftmann@27110
   349
lemma i0_lb [simp]: "(0\<Colon>inat) \<le> n"
haftmann@27110
   350
  by (simp add: zero_inat_def less_eq_inat_def split: inat.splits)
oheimb@11351
   351
nipkow@41853
   352
lemma ile0_eq [simp]: "n \<le> (0\<Colon>inat) \<longleftrightarrow> n = 0"
nipkow@41853
   353
by (simp add: zero_inat_def less_eq_inat_def split: inat.splits)
haftmann@27110
   354
haftmann@27110
   355
lemma Infty_ileE [elim!]: "\<infinity> \<le> Fin m \<Longrightarrow> R"
haftmann@27110
   356
  by (simp add: zero_inat_def less_eq_inat_def split: inat.splits)
oheimb@11351
   357
haftmann@27110
   358
lemma Infty_ilessE [elim!]: "\<infinity> < Fin m \<Longrightarrow> R"
haftmann@27110
   359
  by simp
oheimb@11351
   360
nipkow@41853
   361
lemma not_iless0 [simp]: "\<not> n < (0\<Colon>inat)"
haftmann@27110
   362
  by (simp add: zero_inat_def less_inat_def split: inat.splits)
haftmann@27110
   363
nipkow@41853
   364
lemma i0_less [simp]: "(0\<Colon>inat) < n \<longleftrightarrow> n \<noteq> 0"
nipkow@41853
   365
by (simp add: zero_inat_def less_inat_def split: inat.splits)
oheimb@11351
   366
haftmann@27110
   367
lemma iSuc_ile_mono [simp]: "iSuc n \<le> iSuc m \<longleftrightarrow> n \<le> m"
haftmann@27110
   368
  by (simp add: iSuc_def less_eq_inat_def split: inat.splits)
haftmann@27110
   369
 
haftmann@27110
   370
lemma iSuc_mono [simp]: "iSuc n < iSuc m \<longleftrightarrow> n < m"
haftmann@27110
   371
  by (simp add: iSuc_def less_inat_def split: inat.splits)
oheimb@11351
   372
haftmann@27110
   373
lemma ile_iSuc [simp]: "n \<le> iSuc n"
haftmann@27110
   374
  by (simp add: iSuc_def less_eq_inat_def split: inat.splits)
oheimb@11351
   375
wenzelm@11355
   376
lemma not_iSuc_ilei0 [simp]: "\<not> iSuc n \<le> 0"
haftmann@27110
   377
  by (simp add: zero_inat_def iSuc_def less_eq_inat_def split: inat.splits)
haftmann@27110
   378
haftmann@27110
   379
lemma i0_iless_iSuc [simp]: "0 < iSuc n"
haftmann@27110
   380
  by (simp add: zero_inat_def iSuc_def less_inat_def split: inat.splits)
haftmann@27110
   381
nipkow@41853
   382
lemma iless_iSuc0[simp]: "(n < iSuc 0) = (n = 0)"
nipkow@41853
   383
by (simp add: zero_inat_def iSuc_def less_inat_def split: inat.split)
nipkow@41853
   384
haftmann@27110
   385
lemma ileI1: "m < n \<Longrightarrow> iSuc m \<le> n"
haftmann@27110
   386
  by (simp add: iSuc_def less_eq_inat_def less_inat_def split: inat.splits)
haftmann@27110
   387
haftmann@27110
   388
lemma Suc_ile_eq: "Fin (Suc m) \<le> n \<longleftrightarrow> Fin m < n"
haftmann@27110
   389
  by (cases n) auto
haftmann@27110
   390
haftmann@27110
   391
lemma iless_Suc_eq [simp]: "Fin m < iSuc n \<longleftrightarrow> Fin m \<le> n"
haftmann@27110
   392
  by (auto simp add: iSuc_def less_inat_def split: inat.splits)
oheimb@11351
   393
nipkow@41853
   394
lemma imult_Infty: "(0::inat) < n \<Longrightarrow> \<infinity> * n = \<infinity>"
nipkow@41853
   395
by (simp add: zero_inat_def less_inat_def split: inat.splits)
nipkow@41853
   396
nipkow@41853
   397
lemma imult_Infty_right: "(0::inat) < n \<Longrightarrow> n * \<infinity> = \<infinity>"
nipkow@41853
   398
by (simp add: zero_inat_def less_inat_def split: inat.splits)
nipkow@41853
   399
nipkow@41853
   400
lemma inat_0_less_mult_iff: "(0 < (m::inat) * n) = (0 < m \<and> 0 < n)"
nipkow@41853
   401
by (simp only: i0_less imult_is_0, simp)
nipkow@41853
   402
nipkow@41853
   403
lemma mono_iSuc: "mono iSuc"
nipkow@41853
   404
by(simp add: mono_def)
nipkow@41853
   405
nipkow@41853
   406
haftmann@27110
   407
lemma min_inat_simps [simp]:
haftmann@27110
   408
  "min (Fin m) (Fin n) = Fin (min m n)"
haftmann@27110
   409
  "min q 0 = 0"
haftmann@27110
   410
  "min 0 q = 0"
haftmann@27110
   411
  "min q \<infinity> = q"
haftmann@27110
   412
  "min \<infinity> q = q"
haftmann@27110
   413
  by (auto simp add: min_def)
oheimb@11351
   414
haftmann@27110
   415
lemma max_inat_simps [simp]:
haftmann@27110
   416
  "max (Fin m) (Fin n) = Fin (max m n)"
haftmann@27110
   417
  "max q 0 = q"
haftmann@27110
   418
  "max 0 q = q"
haftmann@27110
   419
  "max q \<infinity> = \<infinity>"
haftmann@27110
   420
  "max \<infinity> q = \<infinity>"
haftmann@27110
   421
  by (simp_all add: max_def)
haftmann@27110
   422
haftmann@27110
   423
lemma Fin_ile: "n \<le> Fin m \<Longrightarrow> \<exists>k. n = Fin k"
haftmann@27110
   424
  by (cases n) simp_all
haftmann@27110
   425
haftmann@27110
   426
lemma Fin_iless: "n < Fin m \<Longrightarrow> \<exists>k. n = Fin k"
haftmann@27110
   427
  by (cases n) simp_all
oheimb@11351
   428
oheimb@11351
   429
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. Fin k < Y j"
nipkow@25134
   430
apply (induct_tac k)
nipkow@25134
   431
 apply (simp (no_asm) only: Fin_0)
haftmann@27110
   432
 apply (fast intro: le_less_trans [OF i0_lb])
nipkow@25134
   433
apply (erule exE)
nipkow@25134
   434
apply (drule spec)
nipkow@25134
   435
apply (erule exE)
nipkow@25134
   436
apply (drule ileI1)
nipkow@25134
   437
apply (rule iSuc_Fin [THEN subst])
nipkow@25134
   438
apply (rule exI)
haftmann@27110
   439
apply (erule (1) le_less_trans)
nipkow@25134
   440
done
oheimb@11351
   441
haftmann@29337
   442
instantiation inat :: "{bot, top}"
haftmann@29337
   443
begin
haftmann@29337
   444
haftmann@29337
   445
definition bot_inat :: inat where
haftmann@29337
   446
  "bot_inat = 0"
haftmann@29337
   447
haftmann@29337
   448
definition top_inat :: inat where
haftmann@29337
   449
  "top_inat = \<infinity>"
haftmann@29337
   450
haftmann@29337
   451
instance proof
haftmann@29337
   452
qed (simp_all add: bot_inat_def top_inat_def)
haftmann@29337
   453
haftmann@29337
   454
end
haftmann@29337
   455
noschinl@42993
   456
lemma finite_Fin_bounded:
noschinl@42993
   457
  assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> Fin n"
noschinl@42993
   458
  shows "finite A"
noschinl@42993
   459
proof (rule finite_subset)
noschinl@42993
   460
  show "finite (Fin ` {..n})" by blast
noschinl@42993
   461
noschinl@42993
   462
  have "A \<subseteq> {..Fin n}" using le_fin by fastsimp
noschinl@42993
   463
  also have "\<dots> \<subseteq> Fin ` {..n}"
noschinl@42993
   464
    by (rule subsetI) (case_tac x, auto)
noschinl@42993
   465
  finally show "A \<subseteq> Fin ` {..n}" .
noschinl@42993
   466
qed
noschinl@42993
   467
huffman@26089
   468
haftmann@27110
   469
subsection {* Well-ordering *}
huffman@26089
   470
huffman@26089
   471
lemma less_FinE:
huffman@26089
   472
  "[| n < Fin m; !!k. n = Fin k ==> k < m ==> P |] ==> P"
huffman@26089
   473
by (induct n) auto
huffman@26089
   474
huffman@26089
   475
lemma less_InftyE:
huffman@26089
   476
  "[| n < Infty; !!k. n = Fin k ==> P |] ==> P"
huffman@26089
   477
by (induct n) auto
huffman@26089
   478
huffman@26089
   479
lemma inat_less_induct:
huffman@26089
   480
  assumes prem: "!!n. \<forall>m::inat. m < n --> P m ==> P n" shows "P n"
huffman@26089
   481
proof -
huffman@26089
   482
  have P_Fin: "!!k. P (Fin k)"
huffman@26089
   483
    apply (rule nat_less_induct)
huffman@26089
   484
    apply (rule prem, clarify)
huffman@26089
   485
    apply (erule less_FinE, simp)
huffman@26089
   486
    done
huffman@26089
   487
  show ?thesis
huffman@26089
   488
  proof (induct n)
huffman@26089
   489
    fix nat
huffman@26089
   490
    show "P (Fin nat)" by (rule P_Fin)
huffman@26089
   491
  next
huffman@26089
   492
    show "P Infty"
huffman@26089
   493
      apply (rule prem, clarify)
huffman@26089
   494
      apply (erule less_InftyE)
huffman@26089
   495
      apply (simp add: P_Fin)
huffman@26089
   496
      done
huffman@26089
   497
  qed
huffman@26089
   498
qed
huffman@26089
   499
huffman@26089
   500
instance inat :: wellorder
huffman@26089
   501
proof
haftmann@27823
   502
  fix P and n
haftmann@27823
   503
  assume hyp: "(\<And>n\<Colon>inat. (\<And>m\<Colon>inat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)"
haftmann@27823
   504
  show "P n" by (blast intro: inat_less_induct hyp)
huffman@26089
   505
qed
huffman@26089
   506
noschinl@42993
   507
subsection {* Complete Lattice *}
noschinl@42993
   508
noschinl@42993
   509
instantiation inat :: complete_lattice
noschinl@42993
   510
begin
noschinl@42993
   511
noschinl@42993
   512
definition inf_inat :: "inat \<Rightarrow> inat \<Rightarrow> inat" where
noschinl@42993
   513
  "inf_inat \<equiv> min"
noschinl@42993
   514
noschinl@42993
   515
definition sup_inat :: "inat \<Rightarrow> inat \<Rightarrow> inat" where
noschinl@42993
   516
  "sup_inat \<equiv> max"
noschinl@42993
   517
noschinl@42993
   518
definition Inf_inat :: "inat set \<Rightarrow> inat" where
noschinl@42993
   519
  "Inf_inat A \<equiv> if A = {} then \<infinity> else (LEAST x. x \<in> A)"
noschinl@42993
   520
noschinl@42993
   521
definition Sup_inat :: "inat set \<Rightarrow> inat" where
noschinl@42993
   522
  "Sup_inat A \<equiv> if A = {} then 0
noschinl@42993
   523
    else if finite A then Max A
noschinl@42993
   524
                     else \<infinity>"
noschinl@42993
   525
instance proof
noschinl@42993
   526
  fix x :: "inat" and A :: "inat set"
noschinl@42993
   527
  { assume "x \<in> A" then show "Inf A \<le> x"
noschinl@42993
   528
      unfolding Inf_inat_def by (auto intro: Least_le) }
noschinl@42993
   529
  { assume "\<And>y. y \<in> A \<Longrightarrow> x \<le> y" then show "x \<le> Inf A"
noschinl@42993
   530
      unfolding Inf_inat_def
noschinl@42993
   531
      by (cases "A = {}") (auto intro: LeastI2_ex) }
noschinl@42993
   532
  { assume "x \<in> A" then show "x \<le> Sup A"
noschinl@42993
   533
      unfolding Sup_inat_def by (cases "finite A") auto }
noschinl@42993
   534
  { assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x"
noschinl@42993
   535
      unfolding Sup_inat_def using finite_Fin_bounded by auto }
noschinl@42993
   536
qed (simp_all add: inf_inat_def sup_inat_def)
noschinl@42993
   537
end
noschinl@42993
   538
haftmann@27110
   539
haftmann@27110
   540
subsection {* Traditional theorem names *}
haftmann@27110
   541
haftmann@27110
   542
lemmas inat_defs = zero_inat_def one_inat_def number_of_inat_def iSuc_def
haftmann@27110
   543
  plus_inat_def less_eq_inat_def less_inat_def
haftmann@27110
   544
oheimb@11351
   545
end