src/HOL/Library/Extended_Nat.thy
author huffman
Thu Nov 17 07:15:30 2011 +0100 (2011-11-17)
changeset 45539 787a1a097465
parent 44890 22f665a2e91c
child 45775 6c340de26a0d
permissions -rw-r--r--
remove redundant simp rules plus_enat_0
     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_number [simp]:
   178   "(number_of k \<Colon> enat) + number_of l = (if k < Int.Pls then number_of l
   179     else if l < Int.Pls then number_of k else number_of (k + l))"
   180   unfolding number_of_enat_def plus_enat_simps nat_arith(1) if_distrib [symmetric, of _ enat] ..
   181 
   182 lemma eSuc_number [simp]:
   183   "eSuc (number_of k) = (if neg (number_of k \<Colon> int) then 1 else number_of (Int.succ k))"
   184   unfolding eSuc_number_of
   185   unfolding one_enat_def number_of_enat_def Suc_nat_number_of if_distrib [symmetric] ..
   186 
   187 lemma eSuc_plus_1:
   188   "eSuc n = n + 1"
   189   by (cases n) (simp_all add: eSuc_enat one_enat_def)
   190   
   191 lemma plus_1_eSuc:
   192   "1 + q = eSuc q"
   193   "q + 1 = eSuc q"
   194   by (simp_all add: eSuc_plus_1 add_ac)
   195 
   196 lemma iadd_Suc: "eSuc m + n = eSuc (m + n)"
   197   by (simp_all add: eSuc_plus_1 add_ac)
   198 
   199 lemma iadd_Suc_right: "m + eSuc n = eSuc (m + n)"
   200   by (simp only: add_commute[of m] iadd_Suc)
   201 
   202 lemma iadd_is_0: "(m + n = (0::enat)) = (m = 0 \<and> n = 0)"
   203   by (cases m, cases n, simp_all add: zero_enat_def)
   204 
   205 subsection {* Multiplication *}
   206 
   207 instantiation enat :: comm_semiring_1
   208 begin
   209 
   210 definition times_enat_def [nitpick_simp]:
   211   "m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | enat m \<Rightarrow>
   212     (case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | enat n \<Rightarrow> enat (m * n)))"
   213 
   214 lemma times_enat_simps [simp, code]:
   215   "enat m * enat n = enat (m * n)"
   216   "\<infinity> * \<infinity> = (\<infinity>::enat)"
   217   "\<infinity> * enat n = (if n = 0 then 0 else \<infinity>)"
   218   "enat m * \<infinity> = (if m = 0 then 0 else \<infinity>)"
   219   unfolding times_enat_def zero_enat_def
   220   by (simp_all split: enat.split)
   221 
   222 instance proof
   223   fix a b c :: enat
   224   show "(a * b) * c = a * (b * c)"
   225     unfolding times_enat_def zero_enat_def
   226     by (simp split: enat.split)
   227   show "a * b = b * a"
   228     unfolding times_enat_def zero_enat_def
   229     by (simp split: enat.split)
   230   show "1 * a = a"
   231     unfolding times_enat_def zero_enat_def one_enat_def
   232     by (simp split: enat.split)
   233   show "(a + b) * c = a * c + b * c"
   234     unfolding times_enat_def zero_enat_def
   235     by (simp split: enat.split add: left_distrib)
   236   show "0 * a = 0"
   237     unfolding times_enat_def zero_enat_def
   238     by (simp split: enat.split)
   239   show "a * 0 = 0"
   240     unfolding times_enat_def zero_enat_def
   241     by (simp split: enat.split)
   242   show "(0::enat) \<noteq> 1"
   243     unfolding zero_enat_def one_enat_def
   244     by simp
   245 qed
   246 
   247 end
   248 
   249 lemma mult_eSuc: "eSuc m * n = n + m * n"
   250   unfolding eSuc_plus_1 by (simp add: algebra_simps)
   251 
   252 lemma mult_eSuc_right: "m * eSuc n = m + m * n"
   253   unfolding eSuc_plus_1 by (simp add: algebra_simps)
   254 
   255 lemma of_nat_eq_enat: "of_nat n = enat n"
   256   apply (induct n)
   257   apply (simp add: enat_0)
   258   apply (simp add: plus_1_eSuc eSuc_enat)
   259   done
   260 
   261 instance enat :: number_semiring
   262 proof
   263   fix n show "number_of (int n) = (of_nat n :: enat)"
   264     unfolding number_of_enat_def number_of_int of_nat_id of_nat_eq_enat ..
   265 qed
   266 
   267 instance enat :: semiring_char_0 proof
   268   have "inj enat" by (rule injI) simp
   269   then show "inj (\<lambda>n. of_nat n :: enat)" by (simp add: of_nat_eq_enat)
   270 qed
   271 
   272 lemma imult_is_0 [simp]: "((m::enat) * n = 0) = (m = 0 \<or> n = 0)"
   273   by (auto simp add: times_enat_def zero_enat_def split: enat.split)
   274 
   275 lemma imult_is_infinity: "((a::enat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)"
   276   by (auto simp add: times_enat_def zero_enat_def split: enat.split)
   277 
   278 
   279 subsection {* Subtraction *}
   280 
   281 instantiation enat :: minus
   282 begin
   283 
   284 definition diff_enat_def:
   285 "a - b = (case a of (enat x) \<Rightarrow> (case b of (enat y) \<Rightarrow> enat (x - y) | \<infinity> \<Rightarrow> 0)
   286           | \<infinity> \<Rightarrow> \<infinity>)"
   287 
   288 instance ..
   289 
   290 end
   291 
   292 lemma idiff_enat_enat [simp,code]: "enat a - enat b = enat (a - b)"
   293   by (simp add: diff_enat_def)
   294 
   295 lemma idiff_infinity [simp,code]: "\<infinity> - n = (\<infinity>::enat)"
   296   by (simp add: diff_enat_def)
   297 
   298 lemma idiff_infinity_right [simp,code]: "enat a - \<infinity> = 0"
   299   by (simp add: diff_enat_def)
   300 
   301 lemma idiff_0 [simp]: "(0::enat) - n = 0"
   302   by (cases n, simp_all add: zero_enat_def)
   303 
   304 lemmas idiff_enat_0 [simp] = idiff_0 [unfolded zero_enat_def]
   305 
   306 lemma idiff_0_right [simp]: "(n::enat) - 0 = n"
   307   by (cases n) (simp_all add: zero_enat_def)
   308 
   309 lemmas idiff_enat_0_right [simp] = idiff_0_right [unfolded zero_enat_def]
   310 
   311 lemma idiff_self [simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::enat) - n = 0"
   312   by (auto simp: zero_enat_def)
   313 
   314 lemma eSuc_minus_eSuc [simp]: "eSuc n - eSuc m = n - m"
   315   by (simp add: eSuc_def split: enat.split)
   316 
   317 lemma eSuc_minus_1 [simp]: "eSuc n - 1 = n"
   318   by (simp add: one_enat_def eSuc_enat[symmetric] zero_enat_def[symmetric])
   319 
   320 (*lemmas idiff_self_eq_0_enat = idiff_self_eq_0[unfolded zero_enat_def]*)
   321 
   322 subsection {* Ordering *}
   323 
   324 instantiation enat :: linordered_ab_semigroup_add
   325 begin
   326 
   327 definition [nitpick_simp]:
   328   "m \<le> n = (case n of enat n1 \<Rightarrow> (case m of enat m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False)
   329     | \<infinity> \<Rightarrow> True)"
   330 
   331 definition [nitpick_simp]:
   332   "m < n = (case m of enat m1 \<Rightarrow> (case n of enat n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True)
   333     | \<infinity> \<Rightarrow> False)"
   334 
   335 lemma enat_ord_simps [simp]:
   336   "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
   337   "enat m < enat n \<longleftrightarrow> m < n"
   338   "q \<le> (\<infinity>::enat)"
   339   "q < (\<infinity>::enat) \<longleftrightarrow> q \<noteq> \<infinity>"
   340   "(\<infinity>::enat) \<le> q \<longleftrightarrow> q = \<infinity>"
   341   "(\<infinity>::enat) < q \<longleftrightarrow> False"
   342   by (simp_all add: less_eq_enat_def less_enat_def split: enat.splits)
   343 
   344 lemma enat_ord_code [code]:
   345   "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
   346   "enat m < enat n \<longleftrightarrow> m < n"
   347   "q \<le> (\<infinity>::enat) \<longleftrightarrow> True"
   348   "enat m < \<infinity> \<longleftrightarrow> True"
   349   "\<infinity> \<le> enat n \<longleftrightarrow> False"
   350   "(\<infinity>::enat) < q \<longleftrightarrow> False"
   351   by simp_all
   352 
   353 instance by default
   354   (auto simp add: less_eq_enat_def less_enat_def plus_enat_def split: enat.splits)
   355 
   356 end
   357 
   358 instance enat :: ordered_comm_semiring
   359 proof
   360   fix a b c :: enat
   361   assume "a \<le> b" and "0 \<le> c"
   362   thus "c * a \<le> c * b"
   363     unfolding times_enat_def less_eq_enat_def zero_enat_def
   364     by (simp split: enat.splits)
   365 qed
   366 
   367 lemma enat_ord_number [simp]:
   368   "(number_of m \<Colon> enat) \<le> number_of n \<longleftrightarrow> (number_of m \<Colon> nat) \<le> number_of n"
   369   "(number_of m \<Colon> enat) < number_of n \<longleftrightarrow> (number_of m \<Colon> nat) < number_of n"
   370   by (simp_all add: number_of_enat_def)
   371 
   372 lemma i0_lb [simp]: "(0\<Colon>enat) \<le> n"
   373   by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
   374 
   375 lemma ile0_eq [simp]: "n \<le> (0\<Colon>enat) \<longleftrightarrow> n = 0"
   376   by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
   377 
   378 lemma infinity_ileE [elim!]: "\<infinity> \<le> enat m \<Longrightarrow> R"
   379   by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
   380 
   381 lemma infinity_ilessE [elim!]: "\<infinity> < enat m \<Longrightarrow> R"
   382   by simp
   383 
   384 lemma not_iless0 [simp]: "\<not> n < (0\<Colon>enat)"
   385   by (simp add: zero_enat_def less_enat_def split: enat.splits)
   386 
   387 lemma i0_less [simp]: "(0\<Colon>enat) < n \<longleftrightarrow> n \<noteq> 0"
   388   by (simp add: zero_enat_def less_enat_def split: enat.splits)
   389 
   390 lemma eSuc_ile_mono [simp]: "eSuc n \<le> eSuc m \<longleftrightarrow> n \<le> m"
   391   by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
   392  
   393 lemma eSuc_mono [simp]: "eSuc n < eSuc m \<longleftrightarrow> n < m"
   394   by (simp add: eSuc_def less_enat_def split: enat.splits)
   395 
   396 lemma ile_eSuc [simp]: "n \<le> eSuc n"
   397   by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
   398 
   399 lemma not_eSuc_ilei0 [simp]: "\<not> eSuc n \<le> 0"
   400   by (simp add: zero_enat_def eSuc_def less_eq_enat_def split: enat.splits)
   401 
   402 lemma i0_iless_eSuc [simp]: "0 < eSuc n"
   403   by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.splits)
   404 
   405 lemma iless_eSuc0[simp]: "(n < eSuc 0) = (n = 0)"
   406   by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.split)
   407 
   408 lemma ileI1: "m < n \<Longrightarrow> eSuc m \<le> n"
   409   by (simp add: eSuc_def less_eq_enat_def less_enat_def split: enat.splits)
   410 
   411 lemma Suc_ile_eq: "enat (Suc m) \<le> n \<longleftrightarrow> enat m < n"
   412   by (cases n) auto
   413 
   414 lemma iless_Suc_eq [simp]: "enat m < eSuc n \<longleftrightarrow> enat m \<le> n"
   415   by (auto simp add: eSuc_def less_enat_def split: enat.splits)
   416 
   417 lemma imult_infinity: "(0::enat) < n \<Longrightarrow> \<infinity> * n = \<infinity>"
   418   by (simp add: zero_enat_def less_enat_def split: enat.splits)
   419 
   420 lemma imult_infinity_right: "(0::enat) < n \<Longrightarrow> n * \<infinity> = \<infinity>"
   421   by (simp add: zero_enat_def less_enat_def split: enat.splits)
   422 
   423 lemma enat_0_less_mult_iff: "(0 < (m::enat) * n) = (0 < m \<and> 0 < n)"
   424   by (simp only: i0_less imult_is_0, simp)
   425 
   426 lemma mono_eSuc: "mono eSuc"
   427   by (simp add: mono_def)
   428 
   429 
   430 lemma min_enat_simps [simp]:
   431   "min (enat m) (enat n) = enat (min m n)"
   432   "min q 0 = 0"
   433   "min 0 q = 0"
   434   "min q (\<infinity>::enat) = q"
   435   "min (\<infinity>::enat) q = q"
   436   by (auto simp add: min_def)
   437 
   438 lemma max_enat_simps [simp]:
   439   "max (enat m) (enat n) = enat (max m n)"
   440   "max q 0 = q"
   441   "max 0 q = q"
   442   "max q \<infinity> = (\<infinity>::enat)"
   443   "max \<infinity> q = (\<infinity>::enat)"
   444   by (simp_all add: max_def)
   445 
   446 lemma enat_ile: "n \<le> enat m \<Longrightarrow> \<exists>k. n = enat k"
   447   by (cases n) simp_all
   448 
   449 lemma enat_iless: "n < enat m \<Longrightarrow> \<exists>k. n = enat k"
   450   by (cases n) simp_all
   451 
   452 lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. enat k < Y j"
   453 apply (induct_tac k)
   454  apply (simp (no_asm) only: enat_0)
   455  apply (fast intro: le_less_trans [OF i0_lb])
   456 apply (erule exE)
   457 apply (drule spec)
   458 apply (erule exE)
   459 apply (drule ileI1)
   460 apply (rule eSuc_enat [THEN subst])
   461 apply (rule exI)
   462 apply (erule (1) le_less_trans)
   463 done
   464 
   465 instantiation enat :: "{bot, top}"
   466 begin
   467 
   468 definition bot_enat :: enat where
   469   "bot_enat = 0"
   470 
   471 definition top_enat :: enat where
   472   "top_enat = \<infinity>"
   473 
   474 instance proof
   475 qed (simp_all add: bot_enat_def top_enat_def)
   476 
   477 end
   478 
   479 lemma finite_enat_bounded:
   480   assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> enat n"
   481   shows "finite A"
   482 proof (rule finite_subset)
   483   show "finite (enat ` {..n})" by blast
   484 
   485   have "A \<subseteq> {..enat n}" using le_fin by fastforce
   486   also have "\<dots> \<subseteq> enat ` {..n}"
   487     by (rule subsetI) (case_tac x, auto)
   488   finally show "A \<subseteq> enat ` {..n}" .
   489 qed
   490 
   491 
   492 subsection {* Well-ordering *}
   493 
   494 lemma less_enatE:
   495   "[| n < enat m; !!k. n = enat k ==> k < m ==> P |] ==> P"
   496 by (induct n) auto
   497 
   498 lemma less_infinityE:
   499   "[| n < \<infinity>; !!k. n = enat k ==> P |] ==> P"
   500 by (induct n) auto
   501 
   502 lemma enat_less_induct:
   503   assumes prem: "!!n. \<forall>m::enat. m < n --> P m ==> P n" shows "P n"
   504 proof -
   505   have P_enat: "!!k. P (enat k)"
   506     apply (rule nat_less_induct)
   507     apply (rule prem, clarify)
   508     apply (erule less_enatE, simp)
   509     done
   510   show ?thesis
   511   proof (induct n)
   512     fix nat
   513     show "P (enat nat)" by (rule P_enat)
   514   next
   515     show "P \<infinity>"
   516       apply (rule prem, clarify)
   517       apply (erule less_infinityE)
   518       apply (simp add: P_enat)
   519       done
   520   qed
   521 qed
   522 
   523 instance enat :: wellorder
   524 proof
   525   fix P and n
   526   assume hyp: "(\<And>n\<Colon>enat. (\<And>m\<Colon>enat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)"
   527   show "P n" by (blast intro: enat_less_induct hyp)
   528 qed
   529 
   530 subsection {* Complete Lattice *}
   531 
   532 instantiation enat :: complete_lattice
   533 begin
   534 
   535 definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
   536   "inf_enat \<equiv> min"
   537 
   538 definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
   539   "sup_enat \<equiv> max"
   540 
   541 definition Inf_enat :: "enat set \<Rightarrow> enat" where
   542   "Inf_enat A \<equiv> if A = {} then \<infinity> else (LEAST x. x \<in> A)"
   543 
   544 definition Sup_enat :: "enat set \<Rightarrow> enat" where
   545   "Sup_enat A \<equiv> if A = {} then 0
   546     else if finite A then Max A
   547                      else \<infinity>"
   548 instance proof
   549   fix x :: "enat" and A :: "enat set"
   550   { assume "x \<in> A" then show "Inf A \<le> x"
   551       unfolding Inf_enat_def by (auto intro: Least_le) }
   552   { assume "\<And>y. y \<in> A \<Longrightarrow> x \<le> y" then show "x \<le> Inf A"
   553       unfolding Inf_enat_def
   554       by (cases "A = {}") (auto intro: LeastI2_ex) }
   555   { assume "x \<in> A" then show "x \<le> Sup A"
   556       unfolding Sup_enat_def by (cases "finite A") auto }
   557   { assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x"
   558       unfolding Sup_enat_def using finite_enat_bounded by auto }
   559 qed (simp_all add: inf_enat_def sup_enat_def)
   560 end
   561 
   562 instance enat :: complete_linorder ..
   563 
   564 subsection {* Traditional theorem names *}
   565 
   566 lemmas enat_defs = zero_enat_def one_enat_def number_of_enat_def eSuc_def
   567   plus_enat_def less_eq_enat_def less_enat_def
   568 
   569 end