1 (* Title: HOL/Library/Extended_Nat.thy
2 Author: David von Oheimb, TU Muenchen; Florian Haftmann, TU Muenchen
3 Contributions: David Trachtenherz, TU Muenchen
6 section \<open>Extended natural numbers (i.e. with infinity)\<close>
9 imports Main Countable Order_Continuity
13 fixes infinity :: "'a" ("\<infinity>")
16 subsection \<open>Type definition\<close>
19 We extend the standard natural numbers by a special value indicating
23 typedef enat = "UNIV :: nat option set" ..
25 text \<open>TODO: introduce enat as coinductive datatype, enat is just @{const of_nat}\<close>
27 definition enat :: "nat \<Rightarrow> enat" where
28 "enat n = Abs_enat (Some n)"
30 instantiation enat :: infinity
33 definition "\<infinity> = Abs_enat None"
38 instance enat :: countable
40 show "\<exists>to_nat::enat \<Rightarrow> nat. inj to_nat"
41 by (rule exI[of _ "to_nat \<circ> Rep_enat"]) (simp add: inj_on_def Rep_enat_inject)
44 old_rep_datatype enat "\<infinity> :: enat"
46 fix P i assume "\<And>j. P (enat j)" "P \<infinity>"
49 case (Abs_enat y) then show ?case
50 by (cases y rule: option.exhaust)
51 (auto simp: enat_def infinity_enat_def)
53 qed (auto simp add: enat_def infinity_enat_def Abs_enat_inject)
55 declare [[coercion "enat::nat\<Rightarrow>enat"]]
57 lemmas enat2_cases = enat.exhaust[case_product enat.exhaust]
58 lemmas enat3_cases = enat.exhaust[case_product enat.exhaust enat.exhaust]
60 lemma not_infinity_eq [iff]: "(x \<noteq> \<infinity>) = (\<exists>i. x = enat i)"
63 lemma not_enat_eq [iff]: "(\<forall>y. x \<noteq> enat y) = (x = \<infinity>)"
66 primrec the_enat :: "enat \<Rightarrow> nat"
67 where "the_enat (enat n) = n"
70 subsection \<open>Constructors and numbers\<close>
72 instantiation enat :: "{zero, one}"
85 definition eSuc :: "enat \<Rightarrow> enat" where
86 "eSuc i = (case i of enat n \<Rightarrow> enat (Suc n) | \<infinity> \<Rightarrow> \<infinity>)"
88 lemma enat_0 [code_post]: "enat 0 = 0"
89 by (simp add: zero_enat_def)
91 lemma enat_1 [code_post]: "enat 1 = 1"
92 by (simp add: one_enat_def)
94 lemma enat_0_iff: "enat x = 0 \<longleftrightarrow> x = 0" "0 = enat x \<longleftrightarrow> x = 0"
95 by (auto simp add: zero_enat_def)
97 lemma enat_1_iff: "enat x = 1 \<longleftrightarrow> x = 1" "1 = enat x \<longleftrightarrow> x = 1"
98 by (auto simp add: one_enat_def)
100 lemma one_eSuc: "1 = eSuc 0"
101 by (simp add: zero_enat_def one_enat_def eSuc_def)
103 lemma infinity_ne_i0 [simp]: "(\<infinity>::enat) \<noteq> 0"
104 by (simp add: zero_enat_def)
106 lemma i0_ne_infinity [simp]: "0 \<noteq> (\<infinity>::enat)"
107 by (simp add: zero_enat_def)
109 lemma zero_one_enat_neq [simp]:
110 "\<not> 0 = (1::enat)"
111 "\<not> 1 = (0::enat)"
112 unfolding zero_enat_def one_enat_def by simp_all
114 lemma infinity_ne_i1 [simp]: "(\<infinity>::enat) \<noteq> 1"
115 by (simp add: one_enat_def)
117 lemma i1_ne_infinity [simp]: "1 \<noteq> (\<infinity>::enat)"
118 by (simp add: one_enat_def)
120 lemma eSuc_enat: "eSuc (enat n) = enat (Suc n)"
121 by (simp add: eSuc_def)
123 lemma eSuc_infinity [simp]: "eSuc \<infinity> = \<infinity>"
124 by (simp add: eSuc_def)
126 lemma eSuc_ne_0 [simp]: "eSuc n \<noteq> 0"
127 by (simp add: eSuc_def zero_enat_def split: enat.splits)
129 lemma zero_ne_eSuc [simp]: "0 \<noteq> eSuc n"
130 by (rule eSuc_ne_0 [symmetric])
132 lemma eSuc_inject [simp]: "eSuc m = eSuc n \<longleftrightarrow> m = n"
133 by (simp add: eSuc_def split: enat.splits)
135 lemma eSuc_enat_iff: "eSuc x = enat y \<longleftrightarrow> (\<exists>n. y = Suc n \<and> x = enat n)"
136 by (cases y) (auto simp: enat_0 eSuc_enat[symmetric])
138 lemma enat_eSuc_iff: "enat y = eSuc x \<longleftrightarrow> (\<exists>n. y = Suc n \<and> enat n = x)"
139 by (cases y) (auto simp: enat_0 eSuc_enat[symmetric])
141 subsection \<open>Addition\<close>
143 instantiation enat :: comm_monoid_add
146 definition [nitpick_simp]:
147 "m + n = (case m of \<infinity> \<Rightarrow> \<infinity> | enat m \<Rightarrow> (case n of \<infinity> \<Rightarrow> \<infinity> | enat n \<Rightarrow> enat (m + n)))"
149 lemma plus_enat_simps [simp, code]:
151 shows "enat m + enat n = enat (m + n)"
152 and "\<infinity> + q = \<infinity>"
153 and "q + \<infinity> = \<infinity>"
154 by (simp_all add: plus_enat_def split: enat.splits)
159 show "n + m + q = n + (m + q)"
160 by (cases n m q rule: enat3_cases) auto
162 by (cases n m rule: enat2_cases) auto
164 by (cases n) (simp_all add: zero_enat_def)
171 by (cases n) (simp_all add: eSuc_enat one_enat_def)
176 by (simp_all add: eSuc_plus_1 ac_simps)
178 lemma iadd_Suc: "eSuc m + n = eSuc (m + n)"
179 by (simp_all add: eSuc_plus_1 ac_simps)
181 lemma iadd_Suc_right: "m + eSuc n = eSuc (m + n)"
182 by (simp only: add.commute[of m] iadd_Suc)
184 lemma iadd_is_0: "(m + n = (0::enat)) = (m = 0 \<and> n = 0)"
185 by (cases m, cases n, simp_all add: zero_enat_def)
187 subsection \<open>Multiplication\<close>
189 instantiation enat :: comm_semiring_1
192 definition times_enat_def [nitpick_simp]:
193 "m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | enat m \<Rightarrow>
194 (case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | enat n \<Rightarrow> enat (m * n)))"
196 lemma times_enat_simps [simp, code]:
197 "enat m * enat n = enat (m * n)"
198 "\<infinity> * \<infinity> = (\<infinity>::enat)"
199 "\<infinity> * enat n = (if n = 0 then 0 else \<infinity>)"
200 "enat m * \<infinity> = (if m = 0 then 0 else \<infinity>)"
201 unfolding times_enat_def zero_enat_def
202 by (simp_all split: enat.split)
207 show "(a * b) * c = a * (b * c)"
208 unfolding times_enat_def zero_enat_def
209 by (simp split: enat.split)
211 unfolding times_enat_def zero_enat_def
212 by (simp split: enat.split)
214 unfolding times_enat_def zero_enat_def one_enat_def
215 by (simp split: enat.split)
216 show "(a + b) * c = a * c + b * c"
217 unfolding times_enat_def zero_enat_def
218 by (simp split: enat.split add: distrib_right)
220 unfolding times_enat_def zero_enat_def
221 by (simp split: enat.split)
223 unfolding times_enat_def zero_enat_def
224 by (simp split: enat.split)
225 show "(0::enat) \<noteq> 1"
226 unfolding zero_enat_def one_enat_def
232 lemma mult_eSuc: "eSuc m * n = n + m * n"
233 unfolding eSuc_plus_1 by (simp add: algebra_simps)
235 lemma mult_eSuc_right: "m * eSuc n = m + m * n"
236 unfolding eSuc_plus_1 by (simp add: algebra_simps)
238 lemma of_nat_eq_enat: "of_nat n = enat n"
240 apply (simp add: enat_0)
241 apply (simp add: plus_1_eSuc eSuc_enat)
244 instance enat :: semiring_char_0
246 have "inj enat" by (rule injI) simp
247 then show "inj (\<lambda>n. of_nat n :: enat)" by (simp add: of_nat_eq_enat)
250 lemma imult_is_0 [simp]: "((m::enat) * n = 0) = (m = 0 \<or> n = 0)"
251 by (auto simp add: times_enat_def zero_enat_def split: enat.split)
253 lemma imult_is_infinity: "((a::enat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)"
254 by (auto simp add: times_enat_def zero_enat_def split: enat.split)
257 subsection \<open>Numerals\<close>
259 lemma numeral_eq_enat:
260 "numeral k = enat (numeral k)"
261 using of_nat_eq_enat [of "numeral k"] by simp
263 lemma enat_numeral [code_abbrev]:
264 "enat (numeral k) = numeral k"
265 using numeral_eq_enat ..
267 lemma infinity_ne_numeral [simp]: "(\<infinity>::enat) \<noteq> numeral k"
268 by (simp add: numeral_eq_enat)
270 lemma numeral_ne_infinity [simp]: "numeral k \<noteq> (\<infinity>::enat)"
271 by (simp add: numeral_eq_enat)
273 lemma eSuc_numeral [simp]: "eSuc (numeral k) = numeral (k + Num.One)"
274 by (simp only: eSuc_plus_1 numeral_plus_one)
276 subsection \<open>Subtraction\<close>
278 instantiation enat :: minus
281 definition diff_enat_def:
282 "a - b = (case a of (enat x) \<Rightarrow> (case b of (enat y) \<Rightarrow> enat (x - y) | \<infinity> \<Rightarrow> 0)
283 | \<infinity> \<Rightarrow> \<infinity>)"
289 lemma idiff_enat_enat [simp, code]: "enat a - enat b = enat (a - b)"
290 by (simp add: diff_enat_def)
292 lemma idiff_infinity [simp, code]: "\<infinity> - n = (\<infinity>::enat)"
293 by (simp add: diff_enat_def)
295 lemma idiff_infinity_right [simp, code]: "enat a - \<infinity> = 0"
296 by (simp add: diff_enat_def)
298 lemma idiff_0 [simp]: "(0::enat) - n = 0"
299 by (cases n, simp_all add: zero_enat_def)
301 lemmas idiff_enat_0 [simp] = idiff_0 [unfolded zero_enat_def]
303 lemma idiff_0_right [simp]: "(n::enat) - 0 = n"
304 by (cases n) (simp_all add: zero_enat_def)
306 lemmas idiff_enat_0_right [simp] = idiff_0_right [unfolded zero_enat_def]
308 lemma idiff_self [simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::enat) - n = 0"
309 by (auto simp: zero_enat_def)
311 lemma eSuc_minus_eSuc [simp]: "eSuc n - eSuc m = n - m"
312 by (simp add: eSuc_def split: enat.split)
314 lemma eSuc_minus_1 [simp]: "eSuc n - 1 = n"
315 by (simp add: one_enat_def eSuc_enat[symmetric] zero_enat_def[symmetric])
317 (*lemmas idiff_self_eq_0_enat = idiff_self_eq_0[unfolded zero_enat_def]*)
319 subsection \<open>Ordering\<close>
321 instantiation enat :: linordered_ab_semigroup_add
324 definition [nitpick_simp]:
325 "m \<le> n = (case n of enat n1 \<Rightarrow> (case m of enat m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False)
326 | \<infinity> \<Rightarrow> True)"
328 definition [nitpick_simp]:
329 "m < n = (case m of enat m1 \<Rightarrow> (case n of enat n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True)
330 | \<infinity> \<Rightarrow> False)"
332 lemma enat_ord_simps [simp]:
333 "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
334 "enat m < enat n \<longleftrightarrow> m < n"
335 "q \<le> (\<infinity>::enat)"
336 "q < (\<infinity>::enat) \<longleftrightarrow> q \<noteq> \<infinity>"
337 "(\<infinity>::enat) \<le> q \<longleftrightarrow> q = \<infinity>"
338 "(\<infinity>::enat) < q \<longleftrightarrow> False"
339 by (simp_all add: less_eq_enat_def less_enat_def split: enat.splits)
341 lemma numeral_le_enat_iff[simp]:
342 shows "numeral m \<le> enat n \<longleftrightarrow> numeral m \<le> n"
343 by (auto simp: numeral_eq_enat)
345 lemma numeral_less_enat_iff[simp]:
346 shows "numeral m < enat n \<longleftrightarrow> numeral m < n"
347 by (auto simp: numeral_eq_enat)
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"
359 by standard (auto simp add: less_eq_enat_def less_enat_def plus_enat_def split: enat.splits)
363 instance enat :: ordered_comm_semiring
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)
372 (* BH: These equations are already proven generally for any type in
373 class linordered_semidom. However, enat is not in that class because
374 it does not have the cancellation property. Would it be worthwhile to
375 a generalize linordered_semidom to a new class that includes enat? *)
377 lemma enat_ord_number [simp]:
378 "(numeral m :: enat) \<le> numeral n \<longleftrightarrow> (numeral m :: nat) \<le> numeral n"
379 "(numeral m :: enat) < numeral n \<longleftrightarrow> (numeral m :: nat) < numeral n"
380 by (simp_all add: numeral_eq_enat)
382 lemma i0_lb [simp]: "(0::enat) \<le> n"
383 by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
385 lemma ile0_eq [simp]: "n \<le> (0::enat) \<longleftrightarrow> n = 0"
386 by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
388 lemma infinity_ileE [elim!]: "\<infinity> \<le> enat m \<Longrightarrow> R"
389 by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
391 lemma infinity_ilessE [elim!]: "\<infinity> < enat m \<Longrightarrow> R"
394 lemma not_iless0 [simp]: "\<not> n < (0::enat)"
395 by (simp add: zero_enat_def less_enat_def split: enat.splits)
397 lemma i0_less [simp]: "(0::enat) < n \<longleftrightarrow> n \<noteq> 0"
398 by (simp add: zero_enat_def less_enat_def split: enat.splits)
400 lemma eSuc_ile_mono [simp]: "eSuc n \<le> eSuc m \<longleftrightarrow> n \<le> m"
401 by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
403 lemma eSuc_mono [simp]: "eSuc n < eSuc m \<longleftrightarrow> n < m"
404 by (simp add: eSuc_def less_enat_def split: enat.splits)
406 lemma ile_eSuc [simp]: "n \<le> eSuc n"
407 by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
409 lemma not_eSuc_ilei0 [simp]: "\<not> eSuc n \<le> 0"
410 by (simp add: zero_enat_def eSuc_def less_eq_enat_def split: enat.splits)
412 lemma i0_iless_eSuc [simp]: "0 < eSuc n"
413 by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.splits)
415 lemma iless_eSuc0[simp]: "(n < eSuc 0) = (n = 0)"
416 by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.split)
418 lemma ileI1: "m < n \<Longrightarrow> eSuc m \<le> n"
419 by (simp add: eSuc_def less_eq_enat_def less_enat_def split: enat.splits)
421 lemma Suc_ile_eq: "enat (Suc m) \<le> n \<longleftrightarrow> enat m < n"
424 lemma iless_Suc_eq [simp]: "enat m < eSuc n \<longleftrightarrow> enat m \<le> n"
425 by (auto simp add: eSuc_def less_enat_def split: enat.splits)
427 lemma imult_infinity: "(0::enat) < n \<Longrightarrow> \<infinity> * n = \<infinity>"
428 by (simp add: zero_enat_def less_enat_def split: enat.splits)
430 lemma imult_infinity_right: "(0::enat) < n \<Longrightarrow> n * \<infinity> = \<infinity>"
431 by (simp add: zero_enat_def less_enat_def split: enat.splits)
433 lemma enat_0_less_mult_iff: "(0 < (m::enat) * n) = (0 < m \<and> 0 < n)"
434 by (simp only: i0_less imult_is_0, simp)
436 lemma mono_eSuc: "mono eSuc"
437 by (simp add: mono_def)
440 lemma min_enat_simps [simp]:
441 "min (enat m) (enat n) = enat (min m n)"
444 "min q (\<infinity>::enat) = q"
445 "min (\<infinity>::enat) q = q"
446 by (auto simp add: min_def)
448 lemma max_enat_simps [simp]:
449 "max (enat m) (enat n) = enat (max m n)"
452 "max q \<infinity> = (\<infinity>::enat)"
453 "max \<infinity> q = (\<infinity>::enat)"
454 by (simp_all add: max_def)
456 lemma enat_ile: "n \<le> enat m \<Longrightarrow> \<exists>k. n = enat k"
457 by (cases n) simp_all
459 lemma enat_iless: "n < enat m \<Longrightarrow> \<exists>k. n = enat k"
460 by (cases n) simp_all
462 lemma iadd_le_enat_iff:
463 "x + y \<le> enat n \<longleftrightarrow> (\<exists>y' x'. x = enat x' \<and> y = enat y' \<and> x' + y' \<le> n)"
464 by(cases x y rule: enat.exhaust[case_product enat.exhaust]) simp_all
466 lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. enat k < Y j"
468 apply (simp (no_asm) only: enat_0)
469 apply (fast intro: le_less_trans [OF i0_lb])
474 apply (rule eSuc_enat [THEN subst])
476 apply (erule (1) le_less_trans)
479 lemma eSuc_max: "eSuc (max x y) = max (eSuc x) (eSuc y)"
480 by (simp add: eSuc_def split: enat.split)
483 assumes "finite A" "A \<noteq> {}"
484 shows "eSuc (Max A) = Max (eSuc ` A)"
485 using assms proof induction
487 thus ?case by(cases "A = {}")(simp_all add: eSuc_max)
490 instantiation enat :: "{order_bot, order_top}"
493 definition bot_enat :: enat where "bot_enat = 0"
494 definition top_enat :: enat where "top_enat = \<infinity>"
497 by standard (simp_all add: bot_enat_def top_enat_def)
501 lemma finite_enat_bounded:
502 assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> enat n"
504 proof (rule finite_subset)
505 show "finite (enat ` {..n})" by blast
506 have "A \<subseteq> {..enat n}" using le_fin by fastforce
507 also have "\<dots> \<subseteq> enat ` {..n}"
509 subgoal for x by (cases x) auto
511 finally show "A \<subseteq> enat ` {..n}" .
515 subsection \<open>Cancellation simprocs\<close>
517 lemma enat_add_left_cancel: "a + b = a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b = c"
518 unfolding plus_enat_def by (simp split: enat.split)
520 lemma enat_add_left_cancel_le: "a + b \<le> a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b \<le> c"
521 unfolding plus_enat_def by (simp split: enat.split)
523 lemma enat_add_left_cancel_less: "a + b < a + c \<longleftrightarrow> a \<noteq> (\<infinity>::enat) \<and> b < c"
524 unfolding plus_enat_def by (simp split: enat.split)
527 structure Cancel_Enat_Common =
529 (* copied from src/HOL/Tools/nat_numeral_simprocs.ML *)
530 fun find_first_t _ _ [] = raise TERM("find_first_t", [])
531 | find_first_t past u (t::terms) =
532 if u aconv t then (rev past @ terms)
533 else find_first_t (t::past) u terms
535 fun dest_summing (Const (@{const_name Groups.plus}, _) $ t $ u, ts) =
536 dest_summing (t, dest_summing (u, ts))
537 | dest_summing (t, ts) = t :: ts
539 val mk_sum = Arith_Data.long_mk_sum
540 fun dest_sum t = dest_summing (t, [])
541 val find_first = find_first_t []
542 val trans_tac = Numeral_Simprocs.trans_tac
544 simpset_of (put_simpset HOL_basic_ss @{context}
545 addsimps @{thms ac_simps add_0_left add_0_right})
546 fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset norm_ss ctxt))
547 fun simplify_meta_eq ctxt cancel_th th =
548 Arith_Data.simplify_meta_eq [] ctxt
549 ([th, cancel_th] MRS trans)
550 fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b))
553 structure Eq_Enat_Cancel = ExtractCommonTermFun
554 (open Cancel_Enat_Common
555 val mk_bal = HOLogic.mk_eq
556 val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} @{typ enat}
557 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel}
560 structure Le_Enat_Cancel = ExtractCommonTermFun
561 (open Cancel_Enat_Common
562 val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less_eq}
563 val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} @{typ enat}
564 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le}
567 structure Less_Enat_Cancel = ExtractCommonTermFun
568 (open Cancel_Enat_Common
569 val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less}
570 val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} @{typ enat}
571 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less}
575 simproc_setup enat_eq_cancel
576 ("(l::enat) + m = n" | "(l::enat) = m + n") =
577 \<open>fn phi => fn ctxt => fn ct => Eq_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close>
579 simproc_setup enat_le_cancel
580 ("(l::enat) + m \<le> n" | "(l::enat) \<le> m + n") =
581 \<open>fn phi => fn ctxt => fn ct => Le_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close>
583 simproc_setup enat_less_cancel
584 ("(l::enat) + m < n" | "(l::enat) < m + n") =
585 \<open>fn phi => fn ctxt => fn ct => Less_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close>
587 text \<open>TODO: add regression tests for these simprocs\<close>
589 text \<open>TODO: add simprocs for combining and cancelling numerals\<close>
591 subsection \<open>Well-ordering\<close>
594 "[| n < enat m; !!k. n = enat k ==> k < m ==> P |] ==> P"
597 lemma less_infinityE:
598 "[| n < \<infinity>; !!k. n = enat k ==> P |] ==> P"
601 lemma enat_less_induct:
602 assumes prem: "!!n. \<forall>m::enat. m < n --> P m ==> P n" shows "P n"
604 have P_enat: "!!k. P (enat k)"
605 apply (rule nat_less_induct)
606 apply (rule prem, clarify)
607 apply (erule less_enatE, simp)
612 show "P (enat nat)" by (rule P_enat)
615 apply (rule prem, clarify)
616 apply (erule less_infinityE)
617 apply (simp add: P_enat)
622 instance enat :: wellorder
625 assume hyp: "(\<And>n::enat. (\<And>m::enat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)"
626 show "P n" by (blast intro: enat_less_induct hyp)
629 subsection \<open>Complete Lattice\<close>
631 instantiation enat :: complete_lattice
634 definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
637 definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
640 definition Inf_enat :: "enat set \<Rightarrow> enat" where
641 "Inf_enat A = (if A = {} then \<infinity> else (LEAST x. x \<in> A))"
643 definition Sup_enat :: "enat set \<Rightarrow> enat" where
644 "Sup_enat A = (if A = {} then 0 else if finite A then Max A else \<infinity>)"
647 fix x :: "enat" and A :: "enat set"
648 { assume "x \<in> A" then show "Inf A \<le> x"
649 unfolding Inf_enat_def by (auto intro: Least_le) }
650 { assume "\<And>y. y \<in> A \<Longrightarrow> x \<le> y" then show "x \<le> Inf A"
651 unfolding Inf_enat_def
652 by (cases "A = {}") (auto intro: LeastI2_ex) }
653 { assume "x \<in> A" then show "x \<le> Sup A"
654 unfolding Sup_enat_def by (cases "finite A") auto }
655 { assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x"
656 unfolding Sup_enat_def using finite_enat_bounded by auto }
658 inf_enat_def sup_enat_def bot_enat_def top_enat_def Inf_enat_def Sup_enat_def)
661 instance enat :: complete_linorder ..
663 lemma eSuc_Sup: "A \<noteq> {} \<Longrightarrow> eSuc (Sup A) = Sup (eSuc ` A)"
664 by(auto simp add: Sup_enat_def eSuc_Max inj_on_def dest: finite_imageD)
666 lemma sup_continuous_eSuc: "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. eSuc (f x))"
667 using eSuc_Sup[of "_ ` UNIV"] by (auto simp: sup_continuous_def)
669 subsection \<open>Traditional theorem names\<close>
671 lemmas enat_defs = zero_enat_def one_enat_def eSuc_def
672 plus_enat_def less_eq_enat_def less_enat_def