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