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