author | bulwahn |
Wed, 14 Dec 2011 16:30:32 +0100 | |
changeset 45873 | 37ffb8797a63 |
parent 45775 | 6c340de26a0d |
child 45934 | 9321cd2572fe |
permissions | -rw-r--r-- |
43919 | 1 |
(* Title: HOL/Library/Extended_Nat.thy |
27110 | 2 |
Author: David von Oheimb, TU Muenchen; Florian Haftmann, TU Muenchen |
41853 | 3 |
Contributions: David Trachtenherz, TU Muenchen |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
4 |
*) |
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
5 |
|
43919 | 6 |
header {* Extended natural numbers (i.e. with infinity) *} |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
7 |
|
43919 | 8 |
theory Extended_Nat |
30663
0b6aff7451b2
Main is (Complex_Main) base entry point in library theories
haftmann
parents:
29668
diff
changeset
|
9 |
imports Main |
15131 | 10 |
begin |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
11 |
|
43921 | 12 |
class infinity = |
13 |
fixes infinity :: "'a" |
|
14 |
||
15 |
notation (xsymbols) |
|
16 |
infinity ("\<infinity>") |
|
17 |
||
18 |
notation (HTML output) |
|
19 |
infinity ("\<infinity>") |
|
20 |
||
27110 | 21 |
subsection {* Type definition *} |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
22 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
23 |
text {* |
11355 | 24 |
We extend the standard natural numbers by a special value indicating |
27110 | 25 |
infinity. |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
26 |
*} |
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
27 |
|
43921 | 28 |
typedef (open) enat = "UNIV :: nat option set" .. |
29 |
||
43924 | 30 |
definition enat :: "nat \<Rightarrow> enat" where |
31 |
"enat n = Abs_enat (Some n)" |
|
43921 | 32 |
|
33 |
instantiation enat :: infinity |
|
34 |
begin |
|
35 |
definition "\<infinity> = Abs_enat None" |
|
36 |
instance proof qed |
|
37 |
end |
|
38 |
||
43924 | 39 |
rep_datatype enat "\<infinity> :: enat" |
43921 | 40 |
proof - |
43924 | 41 |
fix P i assume "\<And>j. P (enat j)" "P \<infinity>" |
43921 | 42 |
then show "P i" |
43 |
proof induct |
|
44 |
case (Abs_enat y) then show ?case |
|
45 |
by (cases y rule: option.exhaust) |
|
43924 | 46 |
(auto simp: enat_def infinity_enat_def) |
43921 | 47 |
qed |
43924 | 48 |
qed (auto simp add: enat_def infinity_enat_def Abs_enat_inject) |
19736 | 49 |
|
43924 | 50 |
declare [[coercion "enat::nat\<Rightarrow>enat"]] |
19736 | 51 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
52 |
lemma not_infinity_eq [iff]: "(x \<noteq> \<infinity>) = (EX i. x = enat i)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
53 |
by (cases x) auto |
31084 | 54 |
|
43924 | 55 |
lemma not_enat_eq [iff]: "(ALL y. x ~= enat y) = (x = \<infinity>)" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
56 |
by (cases x) auto |
31077 | 57 |
|
43924 | 58 |
primrec the_enat :: "enat \<Rightarrow> nat" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
59 |
where "the_enat (enat n) = n" |
41855 | 60 |
|
27110 | 61 |
subsection {* Constructors and numbers *} |
62 |
||
43919 | 63 |
instantiation enat :: "{zero, one, number}" |
25594 | 64 |
begin |
65 |
||
66 |
definition |
|
43924 | 67 |
"0 = enat 0" |
25594 | 68 |
|
69 |
definition |
|
43924 | 70 |
[code_unfold]: "1 = enat 1" |
25594 | 71 |
|
72 |
definition |
|
43924 | 73 |
[code_unfold, code del]: "number_of k = enat (number_of k)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
74 |
|
25594 | 75 |
instance .. |
76 |
||
77 |
end |
|
78 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
79 |
definition eSuc :: "enat \<Rightarrow> enat" where |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
80 |
"eSuc i = (case i of enat n \<Rightarrow> enat (Suc n) | \<infinity> \<Rightarrow> \<infinity>)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
81 |
|
43924 | 82 |
lemma enat_0: "enat 0 = 0" |
43919 | 83 |
by (simp add: zero_enat_def) |
27110 | 84 |
|
43924 | 85 |
lemma enat_1: "enat 1 = 1" |
43919 | 86 |
by (simp add: one_enat_def) |
27110 | 87 |
|
43924 | 88 |
lemma enat_number: "enat (number_of k) = number_of k" |
43919 | 89 |
by (simp add: number_of_enat_def) |
27110 | 90 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
91 |
lemma one_eSuc: "1 = eSuc 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
92 |
by (simp add: zero_enat_def one_enat_def eSuc_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
93 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
94 |
lemma infinity_ne_i0 [simp]: "(\<infinity>::enat) \<noteq> 0" |
43919 | 95 |
by (simp add: zero_enat_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
96 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
97 |
lemma i0_ne_infinity [simp]: "0 \<noteq> (\<infinity>::enat)" |
43919 | 98 |
by (simp add: zero_enat_def) |
27110 | 99 |
|
43919 | 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 |
|
27110 | 104 |
|
43919 | 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 |
|
27110 | 109 |
|
43919 | 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 |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
114 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
115 |
lemma infinity_ne_i1 [simp]: "(\<infinity>::enat) \<noteq> 1" |
43919 | 116 |
by (simp add: one_enat_def) |
27110 | 117 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
118 |
lemma i1_ne_infinity [simp]: "1 \<noteq> (\<infinity>::enat)" |
43919 | 119 |
by (simp add: one_enat_def) |
27110 | 120 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
121 |
lemma infinity_ne_number [simp]: "(\<infinity>::enat) \<noteq> number_of k" |
43919 | 122 |
by (simp add: number_of_enat_def) |
27110 | 123 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
124 |
lemma number_ne_infinity [simp]: "number_of k \<noteq> (\<infinity>::enat)" |
43919 | 125 |
by (simp add: number_of_enat_def) |
27110 | 126 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
127 |
lemma eSuc_enat: "eSuc (enat n) = enat (Suc n)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
128 |
by (simp add: eSuc_def) |
27110 | 129 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
130 |
lemma eSuc_number_of: "eSuc (number_of k) = enat (Suc (number_of k))" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
131 |
by (simp add: eSuc_enat number_of_enat_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
132 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
133 |
lemma eSuc_infinity [simp]: "eSuc \<infinity> = \<infinity>" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
134 |
by (simp add: eSuc_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
135 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
136 |
lemma eSuc_ne_0 [simp]: "eSuc n \<noteq> 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
137 |
by (simp add: eSuc_def zero_enat_def split: enat.splits) |
27110 | 138 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
139 |
lemma zero_ne_eSuc [simp]: "0 \<noteq> eSuc n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
140 |
by (rule eSuc_ne_0 [symmetric]) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
141 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
142 |
lemma eSuc_inject [simp]: "eSuc m = eSuc n \<longleftrightarrow> m = n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
143 |
by (simp add: eSuc_def split: enat.splits) |
27110 | 144 |
|
43919 | 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) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
148 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
149 |
|
27110 | 150 |
subsection {* Addition *} |
151 |
||
43919 | 152 |
instantiation enat :: comm_monoid_add |
27110 | 153 |
begin |
154 |
||
38167 | 155 |
definition [nitpick_simp]: |
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)))" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
157 |
|
43919 | 158 |
lemma plus_enat_simps [simp, code]: |
43921 | 159 |
fixes q :: enat |
43924 | 160 |
shows "enat m + enat n = enat (m + n)" |
43921 | 161 |
and "\<infinity> + q = \<infinity>" |
162 |
and "q + \<infinity> = \<infinity>" |
|
43919 | 163 |
by (simp_all add: plus_enat_def split: enat.splits) |
27110 | 164 |
|
165 |
instance proof |
|
43919 | 166 |
fix n m q :: enat |
27110 | 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" |
|
43919 | 172 |
by (cases n) (simp_all add: zero_enat_def) |
26089 | 173 |
qed |
174 |
||
27110 | 175 |
end |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
176 |
|
43919 | 177 |
lemma plus_enat_number [simp]: |
178 |
"(number_of k \<Colon> enat) + number_of l = (if k < Int.Pls then number_of l |
|
29012 | 179 |
else if l < Int.Pls then number_of k else number_of (k + l))" |
43924 | 180 |
unfolding number_of_enat_def plus_enat_simps nat_arith(1) if_distrib [symmetric, of _ enat] .. |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
181 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
182 |
lemma eSuc_number [simp]: |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
183 |
"eSuc (number_of k) = (if neg (number_of k \<Colon> int) then 1 else number_of (Int.succ k))" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
184 |
unfolding eSuc_number_of |
43919 | 185 |
unfolding one_enat_def number_of_enat_def Suc_nat_number_of if_distrib [symmetric] .. |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
186 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
187 |
lemma eSuc_plus_1: |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
188 |
"eSuc n = n + 1" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
189 |
by (cases n) (simp_all add: eSuc_enat one_enat_def) |
27110 | 190 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
191 |
lemma plus_1_eSuc: |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
192 |
"1 + q = eSuc q" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
193 |
"q + 1 = eSuc q" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
194 |
by (simp_all add: eSuc_plus_1 add_ac) |
41853 | 195 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
196 |
lemma iadd_Suc: "eSuc m + n = eSuc (m + n)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
197 |
by (simp_all add: eSuc_plus_1 add_ac) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
198 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
199 |
lemma iadd_Suc_right: "m + eSuc n = eSuc (m + n)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
200 |
by (simp only: add_commute[of m] iadd_Suc) |
41853 | 201 |
|
43919 | 202 |
lemma iadd_is_0: "(m + n = (0::enat)) = (m = 0 \<and> n = 0)" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
203 |
by (cases m, cases n, simp_all add: zero_enat_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
204 |
|
29014 | 205 |
subsection {* Multiplication *} |
206 |
||
43919 | 207 |
instantiation enat :: comm_semiring_1 |
29014 | 208 |
begin |
209 |
||
43919 | 210 |
definition times_enat_def [nitpick_simp]: |
43924 | 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)))" |
|
29014 | 213 |
|
43919 | 214 |
lemma times_enat_simps [simp, code]: |
43924 | 215 |
"enat m * enat n = enat (m * n)" |
43921 | 216 |
"\<infinity> * \<infinity> = (\<infinity>::enat)" |
43924 | 217 |
"\<infinity> * enat n = (if n = 0 then 0 else \<infinity>)" |
218 |
"enat m * \<infinity> = (if m = 0 then 0 else \<infinity>)" |
|
43919 | 219 |
unfolding times_enat_def zero_enat_def |
220 |
by (simp_all split: enat.split) |
|
29014 | 221 |
|
222 |
instance proof |
|
43919 | 223 |
fix a b c :: enat |
29014 | 224 |
show "(a * b) * c = a * (b * c)" |
43919 | 225 |
unfolding times_enat_def zero_enat_def |
226 |
by (simp split: enat.split) |
|
29014 | 227 |
show "a * b = b * a" |
43919 | 228 |
unfolding times_enat_def zero_enat_def |
229 |
by (simp split: enat.split) |
|
29014 | 230 |
show "1 * a = a" |
43919 | 231 |
unfolding times_enat_def zero_enat_def one_enat_def |
232 |
by (simp split: enat.split) |
|
29014 | 233 |
show "(a + b) * c = a * c + b * c" |
43919 | 234 |
unfolding times_enat_def zero_enat_def |
235 |
by (simp split: enat.split add: left_distrib) |
|
29014 | 236 |
show "0 * a = 0" |
43919 | 237 |
unfolding times_enat_def zero_enat_def |
238 |
by (simp split: enat.split) |
|
29014 | 239 |
show "a * 0 = 0" |
43919 | 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 |
|
29014 | 244 |
by simp |
245 |
qed |
|
246 |
||
247 |
end |
|
248 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
249 |
lemma mult_eSuc: "eSuc m * n = n + m * n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
250 |
unfolding eSuc_plus_1 by (simp add: algebra_simps) |
29014 | 251 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
252 |
lemma mult_eSuc_right: "m * eSuc n = m + m * n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
253 |
unfolding eSuc_plus_1 by (simp add: algebra_simps) |
29014 | 254 |
|
43924 | 255 |
lemma of_nat_eq_enat: "of_nat n = enat n" |
29023 | 256 |
apply (induct n) |
43924 | 257 |
apply (simp add: enat_0) |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
258 |
apply (simp add: plus_1_eSuc eSuc_enat) |
29023 | 259 |
done |
260 |
||
43919 | 261 |
instance enat :: number_semiring |
43532 | 262 |
proof |
43919 | 263 |
fix n show "number_of (int n) = (of_nat n :: enat)" |
43924 | 264 |
unfolding number_of_enat_def number_of_int of_nat_id of_nat_eq_enat .. |
43532 | 265 |
qed |
266 |
||
43919 | 267 |
instance enat :: semiring_char_0 proof |
43924 | 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) |
|
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
38167
diff
changeset
|
270 |
qed |
29023 | 271 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
272 |
lemma imult_is_0 [simp]: "((m::enat) * n = 0) = (m = 0 \<or> n = 0)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
273 |
by (auto simp add: times_enat_def zero_enat_def split: enat.split) |
41853 | 274 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
275 |
lemma imult_is_infinity: "((a::enat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
276 |
by (auto simp add: times_enat_def zero_enat_def split: enat.split) |
41853 | 277 |
|
278 |
||
279 |
subsection {* Subtraction *} |
|
280 |
||
43919 | 281 |
instantiation enat :: minus |
41853 | 282 |
begin |
283 |
||
43919 | 284 |
definition diff_enat_def: |
43924 | 285 |
"a - b = (case a of (enat x) \<Rightarrow> (case b of (enat y) \<Rightarrow> enat (x - y) | \<infinity> \<Rightarrow> 0) |
41853 | 286 |
| \<infinity> \<Rightarrow> \<infinity>)" |
287 |
||
288 |
instance .. |
|
289 |
||
290 |
end |
|
291 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
292 |
lemma idiff_enat_enat [simp,code]: "enat a - enat b = enat (a - b)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
293 |
by (simp add: diff_enat_def) |
41853 | 294 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
295 |
lemma idiff_infinity [simp,code]: "\<infinity> - n = (\<infinity>::enat)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
296 |
by (simp add: diff_enat_def) |
41853 | 297 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
298 |
lemma idiff_infinity_right [simp,code]: "enat a - \<infinity> = 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
299 |
by (simp add: diff_enat_def) |
41853 | 300 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
301 |
lemma idiff_0 [simp]: "(0::enat) - n = 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
302 |
by (cases n, simp_all add: zero_enat_def) |
41853 | 303 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
304 |
lemmas idiff_enat_0 [simp] = idiff_0 [unfolded zero_enat_def] |
41853 | 305 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
306 |
lemma idiff_0_right [simp]: "(n::enat) - 0 = n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
307 |
by (cases n) (simp_all add: zero_enat_def) |
41853 | 308 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
309 |
lemmas idiff_enat_0_right [simp] = idiff_0_right [unfolded zero_enat_def] |
41853 | 310 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
311 |
lemma idiff_self [simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::enat) - n = 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
312 |
by (auto simp: zero_enat_def) |
41853 | 313 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
314 |
lemma eSuc_minus_eSuc [simp]: "eSuc n - eSuc m = n - m" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
315 |
by (simp add: eSuc_def split: enat.split) |
41855 | 316 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
317 |
lemma eSuc_minus_1 [simp]: "eSuc n - 1 = n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
318 |
by (simp add: one_enat_def eSuc_enat[symmetric] zero_enat_def[symmetric]) |
41855 | 319 |
|
43924 | 320 |
(*lemmas idiff_self_eq_0_enat = idiff_self_eq_0[unfolded zero_enat_def]*) |
41853 | 321 |
|
27110 | 322 |
subsection {* Ordering *} |
323 |
||
43919 | 324 |
instantiation enat :: linordered_ab_semigroup_add |
27110 | 325 |
begin |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
326 |
|
38167 | 327 |
definition [nitpick_simp]: |
43924 | 328 |
"m \<le> n = (case n of enat n1 \<Rightarrow> (case m of enat m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False) |
27110 | 329 |
| \<infinity> \<Rightarrow> True)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
330 |
|
38167 | 331 |
definition [nitpick_simp]: |
43924 | 332 |
"m < n = (case m of enat m1 \<Rightarrow> (case n of enat n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True) |
27110 | 333 |
| \<infinity> \<Rightarrow> False)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
334 |
|
43919 | 335 |
lemma enat_ord_simps [simp]: |
43924 | 336 |
"enat m \<le> enat n \<longleftrightarrow> m \<le> n" |
337 |
"enat m < enat n \<longleftrightarrow> m < n" |
|
43921 | 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" |
|
43919 | 342 |
by (simp_all add: less_eq_enat_def less_enat_def split: enat.splits) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
343 |
|
43919 | 344 |
lemma enat_ord_code [code]: |
43924 | 345 |
"enat m \<le> enat n \<longleftrightarrow> m \<le> n" |
346 |
"enat m < enat n \<longleftrightarrow> m < n" |
|
43921 | 347 |
"q \<le> (\<infinity>::enat) \<longleftrightarrow> True" |
43924 | 348 |
"enat m < \<infinity> \<longleftrightarrow> True" |
349 |
"\<infinity> \<le> enat n \<longleftrightarrow> False" |
|
43921 | 350 |
"(\<infinity>::enat) < q \<longleftrightarrow> False" |
27110 | 351 |
by simp_all |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
352 |
|
27110 | 353 |
instance by default |
43919 | 354 |
(auto simp add: less_eq_enat_def less_enat_def plus_enat_def split: enat.splits) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
355 |
|
27110 | 356 |
end |
357 |
||
43919 | 358 |
instance enat :: ordered_comm_semiring |
29014 | 359 |
proof |
43919 | 360 |
fix a b c :: enat |
29014 | 361 |
assume "a \<le> b" and "0 \<le> c" |
362 |
thus "c * a \<le> c * b" |
|
43919 | 363 |
unfolding times_enat_def less_eq_enat_def zero_enat_def |
364 |
by (simp split: enat.splits) |
|
29014 | 365 |
qed |
366 |
||
43919 | 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) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
371 |
|
43919 | 372 |
lemma i0_lb [simp]: "(0\<Colon>enat) \<le> n" |
373 |
by (simp add: zero_enat_def less_eq_enat_def split: enat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
374 |
|
43919 | 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) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
377 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
378 |
lemma infinity_ileE [elim!]: "\<infinity> \<le> enat m \<Longrightarrow> R" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
379 |
by (simp add: zero_enat_def less_eq_enat_def split: enat.splits) |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
380 |
|
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
381 |
lemma infinity_ilessE [elim!]: "\<infinity> < enat m \<Longrightarrow> R" |
27110 | 382 |
by simp |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
383 |
|
43919 | 384 |
lemma not_iless0 [simp]: "\<not> n < (0\<Colon>enat)" |
385 |
by (simp add: zero_enat_def less_enat_def split: enat.splits) |
|
27110 | 386 |
|
43919 | 387 |
lemma i0_less [simp]: "(0\<Colon>enat) < n \<longleftrightarrow> n \<noteq> 0" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
388 |
by (simp add: zero_enat_def less_enat_def split: enat.splits) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
389 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
390 |
lemma eSuc_ile_mono [simp]: "eSuc n \<le> eSuc m \<longleftrightarrow> n \<le> m" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
391 |
by (simp add: eSuc_def less_eq_enat_def split: enat.splits) |
27110 | 392 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
393 |
lemma eSuc_mono [simp]: "eSuc n < eSuc m \<longleftrightarrow> n < m" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
394 |
by (simp add: eSuc_def less_enat_def split: enat.splits) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
395 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
396 |
lemma ile_eSuc [simp]: "n \<le> eSuc n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
397 |
by (simp add: eSuc_def less_eq_enat_def split: enat.splits) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
398 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
399 |
lemma not_eSuc_ilei0 [simp]: "\<not> eSuc n \<le> 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
400 |
by (simp add: zero_enat_def eSuc_def less_eq_enat_def split: enat.splits) |
27110 | 401 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
402 |
lemma i0_iless_eSuc [simp]: "0 < eSuc n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
403 |
by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.splits) |
27110 | 404 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
405 |
lemma iless_eSuc0[simp]: "(n < eSuc 0) = (n = 0)" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
406 |
by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.split) |
41853 | 407 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
408 |
lemma ileI1: "m < n \<Longrightarrow> eSuc m \<le> n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
409 |
by (simp add: eSuc_def less_eq_enat_def less_enat_def split: enat.splits) |
27110 | 410 |
|
43924 | 411 |
lemma Suc_ile_eq: "enat (Suc m) \<le> n \<longleftrightarrow> enat m < n" |
27110 | 412 |
by (cases n) auto |
413 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
414 |
lemma iless_Suc_eq [simp]: "enat m < eSuc n \<longleftrightarrow> enat m \<le> n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
415 |
by (auto simp add: eSuc_def less_enat_def split: enat.splits) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
416 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
417 |
lemma imult_infinity: "(0::enat) < n \<Longrightarrow> \<infinity> * n = \<infinity>" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
418 |
by (simp add: zero_enat_def less_enat_def split: enat.splits) |
41853 | 419 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
420 |
lemma imult_infinity_right: "(0::enat) < n \<Longrightarrow> n * \<infinity> = \<infinity>" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
421 |
by (simp add: zero_enat_def less_enat_def split: enat.splits) |
41853 | 422 |
|
43919 | 423 |
lemma enat_0_less_mult_iff: "(0 < (m::enat) * n) = (0 < m \<and> 0 < n)" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
424 |
by (simp only: i0_less imult_is_0, simp) |
41853 | 425 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
426 |
lemma mono_eSuc: "mono eSuc" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
427 |
by (simp add: mono_def) |
41853 | 428 |
|
429 |
||
43919 | 430 |
lemma min_enat_simps [simp]: |
43924 | 431 |
"min (enat m) (enat n) = enat (min m n)" |
27110 | 432 |
"min q 0 = 0" |
433 |
"min 0 q = 0" |
|
43921 | 434 |
"min q (\<infinity>::enat) = q" |
435 |
"min (\<infinity>::enat) q = q" |
|
27110 | 436 |
by (auto simp add: min_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
437 |
|
43919 | 438 |
lemma max_enat_simps [simp]: |
43924 | 439 |
"max (enat m) (enat n) = enat (max m n)" |
27110 | 440 |
"max q 0 = q" |
441 |
"max 0 q = q" |
|
43921 | 442 |
"max q \<infinity> = (\<infinity>::enat)" |
443 |
"max \<infinity> q = (\<infinity>::enat)" |
|
27110 | 444 |
by (simp_all add: max_def) |
445 |
||
43924 | 446 |
lemma enat_ile: "n \<le> enat m \<Longrightarrow> \<exists>k. n = enat k" |
27110 | 447 |
by (cases n) simp_all |
448 |
||
43924 | 449 |
lemma enat_iless: "n < enat m \<Longrightarrow> \<exists>k. n = enat k" |
27110 | 450 |
by (cases n) simp_all |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
451 |
|
43924 | 452 |
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. enat k < Y j" |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
453 |
apply (induct_tac k) |
43924 | 454 |
apply (simp (no_asm) only: enat_0) |
27110 | 455 |
apply (fast intro: le_less_trans [OF i0_lb]) |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
456 |
apply (erule exE) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
457 |
apply (drule spec) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
458 |
apply (erule exE) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
459 |
apply (drule ileI1) |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
460 |
apply (rule eSuc_enat [THEN subst]) |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
461 |
apply (rule exI) |
27110 | 462 |
apply (erule (1) le_less_trans) |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
463 |
done |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
464 |
|
43919 | 465 |
instantiation enat :: "{bot, top}" |
29337 | 466 |
begin |
467 |
||
43919 | 468 |
definition bot_enat :: enat where |
469 |
"bot_enat = 0" |
|
29337 | 470 |
|
43919 | 471 |
definition top_enat :: enat where |
472 |
"top_enat = \<infinity>" |
|
29337 | 473 |
|
474 |
instance proof |
|
43919 | 475 |
qed (simp_all add: bot_enat_def top_enat_def) |
29337 | 476 |
|
477 |
end |
|
478 |
||
43924 | 479 |
lemma finite_enat_bounded: |
480 |
assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> enat n" |
|
42993 | 481 |
shows "finite A" |
482 |
proof (rule finite_subset) |
|
43924 | 483 |
show "finite (enat ` {..n})" by blast |
42993 | 484 |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44019
diff
changeset
|
485 |
have "A \<subseteq> {..enat n}" using le_fin by fastforce |
43924 | 486 |
also have "\<dots> \<subseteq> enat ` {..n}" |
42993 | 487 |
by (rule subsetI) (case_tac x, auto) |
43924 | 488 |
finally show "A \<subseteq> enat ` {..n}" . |
42993 | 489 |
qed |
490 |
||
26089 | 491 |
|
45775 | 492 |
subsection {* Cancellation simprocs *} |
493 |
||
494 |
lemma enat_add_left_cancel: "a + b = a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b = c" |
|
495 |
unfolding plus_enat_def by (simp split: enat.split) |
|
496 |
||
497 |
lemma enat_add_left_cancel_le: "a + b \<le> a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b \<le> c" |
|
498 |
unfolding plus_enat_def by (simp split: enat.split) |
|
499 |
||
500 |
lemma enat_add_left_cancel_less: "a + b < a + c \<longleftrightarrow> a \<noteq> (\<infinity>::enat) \<and> b < c" |
|
501 |
unfolding plus_enat_def by (simp split: enat.split) |
|
502 |
||
503 |
ML {* |
|
504 |
structure Cancel_Enat_Common = |
|
505 |
struct |
|
506 |
(* copied from src/HOL/Tools/nat_numeral_simprocs.ML *) |
|
507 |
fun find_first_t _ _ [] = raise TERM("find_first_t", []) |
|
508 |
| find_first_t past u (t::terms) = |
|
509 |
if u aconv t then (rev past @ terms) |
|
510 |
else find_first_t (t::past) u terms |
|
511 |
||
512 |
val mk_sum = Arith_Data.long_mk_sum |
|
513 |
val dest_sum = Arith_Data.dest_sum |
|
514 |
val find_first = find_first_t [] |
|
515 |
val trans_tac = Numeral_Simprocs.trans_tac |
|
516 |
val norm_ss = HOL_basic_ss addsimps |
|
517 |
@{thms add_ac semiring_numeral_0_eq_0 add_0_left add_0_right} |
|
518 |
fun norm_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss)) |
|
519 |
fun simplify_meta_eq ss cancel_th th = |
|
520 |
Arith_Data.simplify_meta_eq @{thms semiring_numeral_0_eq_0} ss |
|
521 |
([th, cancel_th] MRS trans) |
|
522 |
fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b)) |
|
523 |
end |
|
524 |
||
525 |
structure Eq_Enat_Cancel = ExtractCommonTermFun |
|
526 |
(open Cancel_Enat_Common |
|
527 |
val mk_bal = HOLogic.mk_eq |
|
528 |
val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} @{typ enat} |
|
529 |
fun simp_conv _ _ = SOME @{thm enat_add_left_cancel} |
|
530 |
) |
|
531 |
||
532 |
structure Le_Enat_Cancel = ExtractCommonTermFun |
|
533 |
(open Cancel_Enat_Common |
|
534 |
val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less_eq} |
|
535 |
val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} @{typ enat} |
|
536 |
fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le} |
|
537 |
) |
|
538 |
||
539 |
structure Less_Enat_Cancel = ExtractCommonTermFun |
|
540 |
(open Cancel_Enat_Common |
|
541 |
val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less} |
|
542 |
val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} @{typ enat} |
|
543 |
fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less} |
|
544 |
) |
|
545 |
*} |
|
546 |
||
547 |
simproc_setup enat_eq_cancel |
|
548 |
("(l::enat) + m = n" | "(l::enat) = m + n") = |
|
549 |
{* fn phi => fn ss => fn ct => Eq_Enat_Cancel.proc ss (term_of ct) *} |
|
550 |
||
551 |
simproc_setup enat_le_cancel |
|
552 |
("(l::enat) + m \<le> n" | "(l::enat) \<le> m + n") = |
|
553 |
{* fn phi => fn ss => fn ct => Le_Enat_Cancel.proc ss (term_of ct) *} |
|
554 |
||
555 |
simproc_setup enat_less_cancel |
|
556 |
("(l::enat) + m < n" | "(l::enat) < m + n") = |
|
557 |
{* fn phi => fn ss => fn ct => Less_Enat_Cancel.proc ss (term_of ct) *} |
|
558 |
||
559 |
text {* TODO: add regression tests for these simprocs *} |
|
560 |
||
561 |
text {* TODO: add simprocs for combining and cancelling numerals *} |
|
562 |
||
563 |
||
27110 | 564 |
subsection {* Well-ordering *} |
26089 | 565 |
|
43924 | 566 |
lemma less_enatE: |
567 |
"[| n < enat m; !!k. n = enat k ==> k < m ==> P |] ==> P" |
|
26089 | 568 |
by (induct n) auto |
569 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
570 |
lemma less_infinityE: |
43924 | 571 |
"[| n < \<infinity>; !!k. n = enat k ==> P |] ==> P" |
26089 | 572 |
by (induct n) auto |
573 |
||
43919 | 574 |
lemma enat_less_induct: |
575 |
assumes prem: "!!n. \<forall>m::enat. m < n --> P m ==> P n" shows "P n" |
|
26089 | 576 |
proof - |
43924 | 577 |
have P_enat: "!!k. P (enat k)" |
26089 | 578 |
apply (rule nat_less_induct) |
579 |
apply (rule prem, clarify) |
|
43924 | 580 |
apply (erule less_enatE, simp) |
26089 | 581 |
done |
582 |
show ?thesis |
|
583 |
proof (induct n) |
|
584 |
fix nat |
|
43924 | 585 |
show "P (enat nat)" by (rule P_enat) |
26089 | 586 |
next |
43921 | 587 |
show "P \<infinity>" |
26089 | 588 |
apply (rule prem, clarify) |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
589 |
apply (erule less_infinityE) |
43924 | 590 |
apply (simp add: P_enat) |
26089 | 591 |
done |
592 |
qed |
|
593 |
qed |
|
594 |
||
43919 | 595 |
instance enat :: wellorder |
26089 | 596 |
proof |
27823 | 597 |
fix P and n |
43919 | 598 |
assume hyp: "(\<And>n\<Colon>enat. (\<And>m\<Colon>enat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)" |
599 |
show "P n" by (blast intro: enat_less_induct hyp) |
|
26089 | 600 |
qed |
601 |
||
42993 | 602 |
subsection {* Complete Lattice *} |
603 |
||
43919 | 604 |
instantiation enat :: complete_lattice |
42993 | 605 |
begin |
606 |
||
43919 | 607 |
definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where |
608 |
"inf_enat \<equiv> min" |
|
42993 | 609 |
|
43919 | 610 |
definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where |
611 |
"sup_enat \<equiv> max" |
|
42993 | 612 |
|
43919 | 613 |
definition Inf_enat :: "enat set \<Rightarrow> enat" where |
614 |
"Inf_enat A \<equiv> if A = {} then \<infinity> else (LEAST x. x \<in> A)" |
|
42993 | 615 |
|
43919 | 616 |
definition Sup_enat :: "enat set \<Rightarrow> enat" where |
617 |
"Sup_enat A \<equiv> if A = {} then 0 |
|
42993 | 618 |
else if finite A then Max A |
619 |
else \<infinity>" |
|
620 |
instance proof |
|
43919 | 621 |
fix x :: "enat" and A :: "enat set" |
42993 | 622 |
{ assume "x \<in> A" then show "Inf A \<le> x" |
43919 | 623 |
unfolding Inf_enat_def by (auto intro: Least_le) } |
42993 | 624 |
{ assume "\<And>y. y \<in> A \<Longrightarrow> x \<le> y" then show "x \<le> Inf A" |
43919 | 625 |
unfolding Inf_enat_def |
42993 | 626 |
by (cases "A = {}") (auto intro: LeastI2_ex) } |
627 |
{ assume "x \<in> A" then show "x \<le> Sup A" |
|
43919 | 628 |
unfolding Sup_enat_def by (cases "finite A") auto } |
42993 | 629 |
{ assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x" |
43924 | 630 |
unfolding Sup_enat_def using finite_enat_bounded by auto } |
43919 | 631 |
qed (simp_all add: inf_enat_def sup_enat_def) |
42993 | 632 |
end |
633 |
||
43978 | 634 |
instance enat :: complete_linorder .. |
27110 | 635 |
|
636 |
subsection {* Traditional theorem names *} |
|
637 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
638 |
lemmas enat_defs = zero_enat_def one_enat_def number_of_enat_def eSuc_def |
43919 | 639 |
plus_enat_def less_eq_enat_def less_enat_def |
27110 | 640 |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
641 |
end |