author | wenzelm |
Mon, 06 Jul 2015 22:57:34 +0200 | |
changeset 60679 | ade12ef2773c |
parent 60636 | ee18efe9b246 |
child 61076 | bdc1e2f0a86a |
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 |
|
60500 | 6 |
section \<open>Extended natural numbers (i.e. with infinity)\<close> |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
7 |
|
43919 | 8 |
theory Extended_Nat |
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
9 |
imports Main Countable Order_Continuity |
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 |
||
60500 | 21 |
subsection \<open>Type definition\<close> |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
22 |
|
60500 | 23 |
text \<open> |
11355 | 24 |
We extend the standard natural numbers by a special value indicating |
27110 | 25 |
infinity. |
60500 | 26 |
\<close> |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
27 |
|
49834 | 28 |
typedef enat = "UNIV :: nat option set" .. |
54415 | 29 |
|
60500 | 30 |
text \<open>TODO: introduce enat as coinductive datatype, enat is just @{const of_nat}\<close> |
54415 | 31 |
|
43924 | 32 |
definition enat :: "nat \<Rightarrow> enat" where |
33 |
"enat n = Abs_enat (Some n)" |
|
43921 | 34 |
|
35 |
instantiation enat :: infinity |
|
36 |
begin |
|
60679 | 37 |
|
38 |
definition "\<infinity> = Abs_enat None" |
|
39 |
instance .. |
|
40 |
||
43921 | 41 |
end |
54415 | 42 |
|
43 |
instance enat :: countable |
|
44 |
proof |
|
45 |
show "\<exists>to_nat::enat \<Rightarrow> nat. inj to_nat" |
|
46 |
by (rule exI[of _ "to_nat \<circ> Rep_enat"]) (simp add: inj_on_def Rep_enat_inject) |
|
47 |
qed |
|
43921 | 48 |
|
58306
117ba6cbe414
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
blanchet
parents:
57514
diff
changeset
|
49 |
old_rep_datatype enat "\<infinity> :: enat" |
43921 | 50 |
proof - |
43924 | 51 |
fix P i assume "\<And>j. P (enat j)" "P \<infinity>" |
43921 | 52 |
then show "P i" |
53 |
proof induct |
|
54 |
case (Abs_enat y) then show ?case |
|
55 |
by (cases y rule: option.exhaust) |
|
43924 | 56 |
(auto simp: enat_def infinity_enat_def) |
43921 | 57 |
qed |
43924 | 58 |
qed (auto simp add: enat_def infinity_enat_def Abs_enat_inject) |
19736 | 59 |
|
43924 | 60 |
declare [[coercion "enat::nat\<Rightarrow>enat"]] |
19736 | 61 |
|
45934 | 62 |
lemmas enat2_cases = enat.exhaust[case_product enat.exhaust] |
63 |
lemmas enat3_cases = enat.exhaust[case_product enat.exhaust enat.exhaust] |
|
64 |
||
54416 | 65 |
lemma not_infinity_eq [iff]: "(x \<noteq> \<infinity>) = (\<exists>i. x = enat i)" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
66 |
by (cases x) auto |
31084 | 67 |
|
54416 | 68 |
lemma not_enat_eq [iff]: "(\<forall>y. x \<noteq> enat y) = (x = \<infinity>)" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
69 |
by (cases x) auto |
31077 | 70 |
|
43924 | 71 |
primrec the_enat :: "enat \<Rightarrow> nat" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
72 |
where "the_enat (enat n) = n" |
41855 | 73 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
74 |
|
60500 | 75 |
subsection \<open>Constructors and numbers\<close> |
27110 | 76 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
77 |
instantiation enat :: "{zero, one}" |
25594 | 78 |
begin |
79 |
||
80 |
definition |
|
43924 | 81 |
"0 = enat 0" |
25594 | 82 |
|
83 |
definition |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
84 |
"1 = enat 1" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
85 |
|
25594 | 86 |
instance .. |
87 |
||
88 |
end |
|
89 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
90 |
definition eSuc :: "enat \<Rightarrow> enat" where |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
91 |
"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
|
92 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
93 |
lemma enat_0 [code_post]: "enat 0 = 0" |
43919 | 94 |
by (simp add: zero_enat_def) |
27110 | 95 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
96 |
lemma enat_1 [code_post]: "enat 1 = 1" |
43919 | 97 |
by (simp add: one_enat_def) |
27110 | 98 |
|
54416 | 99 |
lemma enat_0_iff: "enat x = 0 \<longleftrightarrow> x = 0" "0 = enat x \<longleftrightarrow> x = 0" |
100 |
by (auto simp add: zero_enat_def) |
|
101 |
||
102 |
lemma enat_1_iff: "enat x = 1 \<longleftrightarrow> x = 1" "1 = enat x \<longleftrightarrow> x = 1" |
|
103 |
by (auto simp add: one_enat_def) |
|
104 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
105 |
lemma one_eSuc: "1 = eSuc 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
106 |
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
|
107 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
108 |
lemma infinity_ne_i0 [simp]: "(\<infinity>::enat) \<noteq> 0" |
43919 | 109 |
by (simp add: zero_enat_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
110 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
111 |
lemma i0_ne_infinity [simp]: "0 \<noteq> (\<infinity>::enat)" |
43919 | 112 |
by (simp add: zero_enat_def) |
27110 | 113 |
|
43919 | 114 |
lemma zero_one_enat_neq [simp]: |
115 |
"\<not> 0 = (1\<Colon>enat)" |
|
116 |
"\<not> 1 = (0\<Colon>enat)" |
|
117 |
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
|
118 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
119 |
lemma infinity_ne_i1 [simp]: "(\<infinity>::enat) \<noteq> 1" |
43919 | 120 |
by (simp add: one_enat_def) |
27110 | 121 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
122 |
lemma i1_ne_infinity [simp]: "1 \<noteq> (\<infinity>::enat)" |
43919 | 123 |
by (simp add: one_enat_def) |
27110 | 124 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
125 |
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
|
126 |
by (simp add: eSuc_def) |
27110 | 127 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
128 |
lemma eSuc_infinity [simp]: "eSuc \<infinity> = \<infinity>" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
129 |
by (simp add: eSuc_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
130 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
131 |
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
|
132 |
by (simp add: eSuc_def zero_enat_def split: enat.splits) |
27110 | 133 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
134 |
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
|
135 |
by (rule eSuc_ne_0 [symmetric]) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
136 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
137 |
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
|
138 |
by (simp add: eSuc_def split: enat.splits) |
27110 | 139 |
|
59000 | 140 |
lemma eSuc_enat_iff: "eSuc x = enat y \<longleftrightarrow> (\<exists>n. y = Suc n \<and> x = enat n)" |
141 |
by (cases y) (auto simp: enat_0 eSuc_enat[symmetric]) |
|
142 |
||
143 |
lemma enat_eSuc_iff: "enat y = eSuc x \<longleftrightarrow> (\<exists>n. y = Suc n \<and> enat n = x)" |
|
144 |
by (cases y) (auto simp: enat_0 eSuc_enat[symmetric]) |
|
145 |
||
60500 | 146 |
subsection \<open>Addition\<close> |
27110 | 147 |
|
43919 | 148 |
instantiation enat :: comm_monoid_add |
27110 | 149 |
begin |
150 |
||
38167 | 151 |
definition [nitpick_simp]: |
43924 | 152 |
"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
|
153 |
|
43919 | 154 |
lemma plus_enat_simps [simp, code]: |
43921 | 155 |
fixes q :: enat |
43924 | 156 |
shows "enat m + enat n = enat (m + n)" |
43921 | 157 |
and "\<infinity> + q = \<infinity>" |
158 |
and "q + \<infinity> = \<infinity>" |
|
43919 | 159 |
by (simp_all add: plus_enat_def split: enat.splits) |
27110 | 160 |
|
60679 | 161 |
instance |
162 |
proof |
|
43919 | 163 |
fix n m q :: enat |
27110 | 164 |
show "n + m + q = n + (m + q)" |
45934 | 165 |
by (cases n m q rule: enat3_cases) auto |
27110 | 166 |
show "n + m = m + n" |
45934 | 167 |
by (cases n m rule: enat2_cases) auto |
27110 | 168 |
show "0 + n = n" |
43919 | 169 |
by (cases n) (simp_all add: zero_enat_def) |
26089 | 170 |
qed |
171 |
||
27110 | 172 |
end |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
173 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
174 |
lemma eSuc_plus_1: |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
175 |
"eSuc n = n + 1" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
176 |
by (cases n) (simp_all add: eSuc_enat one_enat_def) |
27110 | 177 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
178 |
lemma plus_1_eSuc: |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
179 |
"1 + q = eSuc q" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
180 |
"q + 1 = eSuc q" |
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
181 |
by (simp_all add: eSuc_plus_1 ac_simps) |
41853 | 182 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
183 |
lemma iadd_Suc: "eSuc m + n = eSuc (m + n)" |
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
184 |
by (simp_all add: eSuc_plus_1 ac_simps) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
185 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
186 |
lemma iadd_Suc_right: "m + eSuc n = eSuc (m + n)" |
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
56777
diff
changeset
|
187 |
by (simp only: add.commute[of m] iadd_Suc) |
41853 | 188 |
|
43919 | 189 |
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
|
190 |
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
|
191 |
|
60500 | 192 |
subsection \<open>Multiplication\<close> |
29014 | 193 |
|
43919 | 194 |
instantiation enat :: comm_semiring_1 |
29014 | 195 |
begin |
196 |
||
43919 | 197 |
definition times_enat_def [nitpick_simp]: |
43924 | 198 |
"m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | enat m \<Rightarrow> |
199 |
(case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | enat n \<Rightarrow> enat (m * n)))" |
|
29014 | 200 |
|
43919 | 201 |
lemma times_enat_simps [simp, code]: |
43924 | 202 |
"enat m * enat n = enat (m * n)" |
43921 | 203 |
"\<infinity> * \<infinity> = (\<infinity>::enat)" |
43924 | 204 |
"\<infinity> * enat n = (if n = 0 then 0 else \<infinity>)" |
205 |
"enat m * \<infinity> = (if m = 0 then 0 else \<infinity>)" |
|
43919 | 206 |
unfolding times_enat_def zero_enat_def |
207 |
by (simp_all split: enat.split) |
|
29014 | 208 |
|
60679 | 209 |
instance |
210 |
proof |
|
43919 | 211 |
fix a b c :: enat |
29014 | 212 |
show "(a * b) * c = a * (b * c)" |
43919 | 213 |
unfolding times_enat_def zero_enat_def |
214 |
by (simp split: enat.split) |
|
29014 | 215 |
show "a * b = b * a" |
43919 | 216 |
unfolding times_enat_def zero_enat_def |
217 |
by (simp split: enat.split) |
|
29014 | 218 |
show "1 * a = a" |
43919 | 219 |
unfolding times_enat_def zero_enat_def one_enat_def |
220 |
by (simp split: enat.split) |
|
29014 | 221 |
show "(a + b) * c = a * c + b * c" |
43919 | 222 |
unfolding times_enat_def zero_enat_def |
49962
a8cc904a6820
Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents:
49834
diff
changeset
|
223 |
by (simp split: enat.split add: distrib_right) |
29014 | 224 |
show "0 * a = 0" |
43919 | 225 |
unfolding times_enat_def zero_enat_def |
226 |
by (simp split: enat.split) |
|
29014 | 227 |
show "a * 0 = 0" |
43919 | 228 |
unfolding times_enat_def zero_enat_def |
229 |
by (simp split: enat.split) |
|
230 |
show "(0::enat) \<noteq> 1" |
|
231 |
unfolding zero_enat_def one_enat_def |
|
29014 | 232 |
by simp |
233 |
qed |
|
234 |
||
235 |
end |
|
236 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
237 |
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
|
238 |
unfolding eSuc_plus_1 by (simp add: algebra_simps) |
29014 | 239 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
240 |
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
|
241 |
unfolding eSuc_plus_1 by (simp add: algebra_simps) |
29014 | 242 |
|
43924 | 243 |
lemma of_nat_eq_enat: "of_nat n = enat n" |
29023 | 244 |
apply (induct n) |
43924 | 245 |
apply (simp add: enat_0) |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
246 |
apply (simp add: plus_1_eSuc eSuc_enat) |
29023 | 247 |
done |
248 |
||
60679 | 249 |
instance enat :: semiring_char_0 |
250 |
proof |
|
43924 | 251 |
have "inj enat" by (rule injI) simp |
252 |
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
|
253 |
qed |
29023 | 254 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
255 |
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
|
256 |
by (auto simp add: times_enat_def zero_enat_def split: enat.split) |
41853 | 257 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
258 |
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
|
259 |
by (auto simp add: times_enat_def zero_enat_def split: enat.split) |
41853 | 260 |
|
261 |
||
60500 | 262 |
subsection \<open>Numerals\<close> |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
263 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
264 |
lemma numeral_eq_enat: |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
265 |
"numeral k = enat (numeral k)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
266 |
using of_nat_eq_enat [of "numeral k"] by simp |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
267 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
268 |
lemma enat_numeral [code_abbrev]: |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
269 |
"enat (numeral k) = numeral k" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
270 |
using numeral_eq_enat .. |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
271 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
272 |
lemma infinity_ne_numeral [simp]: "(\<infinity>::enat) \<noteq> numeral k" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
273 |
by (simp add: numeral_eq_enat) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
274 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
275 |
lemma numeral_ne_infinity [simp]: "numeral k \<noteq> (\<infinity>::enat)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
276 |
by (simp add: numeral_eq_enat) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
277 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
278 |
lemma eSuc_numeral [simp]: "eSuc (numeral k) = numeral (k + Num.One)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
279 |
by (simp only: eSuc_plus_1 numeral_plus_one) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
280 |
|
60500 | 281 |
subsection \<open>Subtraction\<close> |
41853 | 282 |
|
43919 | 283 |
instantiation enat :: minus |
41853 | 284 |
begin |
285 |
||
43919 | 286 |
definition diff_enat_def: |
43924 | 287 |
"a - b = (case a of (enat x) \<Rightarrow> (case b of (enat y) \<Rightarrow> enat (x - y) | \<infinity> \<Rightarrow> 0) |
41853 | 288 |
| \<infinity> \<Rightarrow> \<infinity>)" |
289 |
||
290 |
instance .. |
|
291 |
||
292 |
end |
|
293 |
||
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
294 |
lemma idiff_enat_enat [simp, code]: "enat a - enat b = enat (a - b)" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
295 |
by (simp add: diff_enat_def) |
41853 | 296 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
297 |
lemma idiff_infinity [simp, code]: "\<infinity> - n = (\<infinity>::enat)" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
298 |
by (simp add: diff_enat_def) |
41853 | 299 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
300 |
lemma idiff_infinity_right [simp, code]: "enat a - \<infinity> = 0" |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
301 |
by (simp add: diff_enat_def) |
41853 | 302 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
303 |
lemma idiff_0 [simp]: "(0::enat) - n = 0" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
304 |
by (cases n, simp_all add: zero_enat_def) |
41853 | 305 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
306 |
lemmas idiff_enat_0 [simp] = idiff_0 [unfolded zero_enat_def] |
41853 | 307 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
308 |
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
|
309 |
by (cases n) (simp_all add: zero_enat_def) |
41853 | 310 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
311 |
lemmas idiff_enat_0_right [simp] = idiff_0_right [unfolded zero_enat_def] |
41853 | 312 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
313 |
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
|
314 |
by (auto simp: zero_enat_def) |
41853 | 315 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
316 |
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
|
317 |
by (simp add: eSuc_def split: enat.split) |
41855 | 318 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
319 |
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
|
320 |
by (simp add: one_enat_def eSuc_enat[symmetric] zero_enat_def[symmetric]) |
41855 | 321 |
|
43924 | 322 |
(*lemmas idiff_self_eq_0_enat = idiff_self_eq_0[unfolded zero_enat_def]*) |
41853 | 323 |
|
60500 | 324 |
subsection \<open>Ordering\<close> |
27110 | 325 |
|
43919 | 326 |
instantiation enat :: linordered_ab_semigroup_add |
27110 | 327 |
begin |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
328 |
|
38167 | 329 |
definition [nitpick_simp]: |
43924 | 330 |
"m \<le> n = (case n of enat n1 \<Rightarrow> (case m of enat m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False) |
27110 | 331 |
| \<infinity> \<Rightarrow> True)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
332 |
|
38167 | 333 |
definition [nitpick_simp]: |
43924 | 334 |
"m < n = (case m of enat m1 \<Rightarrow> (case n of enat n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True) |
27110 | 335 |
| \<infinity> \<Rightarrow> False)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
336 |
|
43919 | 337 |
lemma enat_ord_simps [simp]: |
43924 | 338 |
"enat m \<le> enat n \<longleftrightarrow> m \<le> n" |
339 |
"enat m < enat n \<longleftrightarrow> m < n" |
|
43921 | 340 |
"q \<le> (\<infinity>::enat)" |
341 |
"q < (\<infinity>::enat) \<longleftrightarrow> q \<noteq> \<infinity>" |
|
342 |
"(\<infinity>::enat) \<le> q \<longleftrightarrow> q = \<infinity>" |
|
343 |
"(\<infinity>::enat) < q \<longleftrightarrow> False" |
|
43919 | 344 |
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
|
345 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
346 |
lemma numeral_le_enat_iff[simp]: |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
347 |
shows "numeral m \<le> enat n \<longleftrightarrow> numeral m \<le> n" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
348 |
by (auto simp: numeral_eq_enat) |
45934 | 349 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
350 |
lemma numeral_less_enat_iff[simp]: |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
351 |
shows "numeral m < enat n \<longleftrightarrow> numeral m < n" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
352 |
by (auto simp: numeral_eq_enat) |
45934 | 353 |
|
43919 | 354 |
lemma enat_ord_code [code]: |
43924 | 355 |
"enat m \<le> enat n \<longleftrightarrow> m \<le> n" |
356 |
"enat m < enat n \<longleftrightarrow> m < n" |
|
43921 | 357 |
"q \<le> (\<infinity>::enat) \<longleftrightarrow> True" |
43924 | 358 |
"enat m < \<infinity> \<longleftrightarrow> True" |
359 |
"\<infinity> \<le> enat n \<longleftrightarrow> False" |
|
43921 | 360 |
"(\<infinity>::enat) < q \<longleftrightarrow> False" |
27110 | 361 |
by simp_all |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
362 |
|
60679 | 363 |
instance |
364 |
by standard (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
|
365 |
|
27110 | 366 |
end |
367 |
||
43919 | 368 |
instance enat :: ordered_comm_semiring |
29014 | 369 |
proof |
43919 | 370 |
fix a b c :: enat |
29014 | 371 |
assume "a \<le> b" and "0 \<le> c" |
372 |
thus "c * a \<le> c * b" |
|
43919 | 373 |
unfolding times_enat_def less_eq_enat_def zero_enat_def |
374 |
by (simp split: enat.splits) |
|
29014 | 375 |
qed |
376 |
||
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
377 |
(* BH: These equations are already proven generally for any type in |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
378 |
class linordered_semidom. However, enat is not in that class because |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
379 |
it does not have the cancellation property. Would it be worthwhile to |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
380 |
a generalize linordered_semidom to a new class that includes enat? *) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
381 |
|
43919 | 382 |
lemma enat_ord_number [simp]: |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
383 |
"(numeral m \<Colon> enat) \<le> numeral n \<longleftrightarrow> (numeral m \<Colon> nat) \<le> numeral n" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
384 |
"(numeral m \<Colon> enat) < numeral n \<longleftrightarrow> (numeral m \<Colon> nat) < numeral n" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
385 |
by (simp_all add: numeral_eq_enat) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
386 |
|
43919 | 387 |
lemma i0_lb [simp]: "(0\<Colon>enat) \<le> n" |
388 |
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
|
389 |
|
43919 | 390 |
lemma ile0_eq [simp]: "n \<le> (0\<Colon>enat) \<longleftrightarrow> n = 0" |
391 |
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
|
392 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
393 |
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
|
394 |
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
|
395 |
|
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
396 |
lemma infinity_ilessE [elim!]: "\<infinity> < enat m \<Longrightarrow> R" |
27110 | 397 |
by simp |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
398 |
|
43919 | 399 |
lemma not_iless0 [simp]: "\<not> n < (0\<Colon>enat)" |
400 |
by (simp add: zero_enat_def less_enat_def split: enat.splits) |
|
27110 | 401 |
|
43919 | 402 |
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
|
403 |
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
|
404 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
405 |
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
|
406 |
by (simp add: eSuc_def less_eq_enat_def split: enat.splits) |
27110 | 407 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
408 |
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
|
409 |
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
|
410 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
411 |
lemma ile_eSuc [simp]: "n \<le> eSuc n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
412 |
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
|
413 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
414 |
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
|
415 |
by (simp add: zero_enat_def eSuc_def less_eq_enat_def split: enat.splits) |
27110 | 416 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
417 |
lemma i0_iless_eSuc [simp]: "0 < eSuc n" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
418 |
by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.splits) |
27110 | 419 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
420 |
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
|
421 |
by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.split) |
41853 | 422 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
423 |
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
|
424 |
by (simp add: eSuc_def less_eq_enat_def less_enat_def split: enat.splits) |
27110 | 425 |
|
43924 | 426 |
lemma Suc_ile_eq: "enat (Suc m) \<le> n \<longleftrightarrow> enat m < n" |
27110 | 427 |
by (cases n) auto |
428 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
432 |
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
|
433 |
by (simp add: zero_enat_def less_enat_def split: enat.splits) |
41853 | 434 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
435 |
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
|
436 |
by (simp add: zero_enat_def less_enat_def split: enat.splits) |
41853 | 437 |
|
43919 | 438 |
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
|
439 |
by (simp only: i0_less imult_is_0, simp) |
41853 | 440 |
|
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
441 |
lemma mono_eSuc: "mono eSuc" |
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
442 |
by (simp add: mono_def) |
41853 | 443 |
|
444 |
||
43919 | 445 |
lemma min_enat_simps [simp]: |
43924 | 446 |
"min (enat m) (enat n) = enat (min m n)" |
27110 | 447 |
"min q 0 = 0" |
448 |
"min 0 q = 0" |
|
43921 | 449 |
"min q (\<infinity>::enat) = q" |
450 |
"min (\<infinity>::enat) q = q" |
|
27110 | 451 |
by (auto simp add: min_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
452 |
|
43919 | 453 |
lemma max_enat_simps [simp]: |
43924 | 454 |
"max (enat m) (enat n) = enat (max m n)" |
27110 | 455 |
"max q 0 = q" |
456 |
"max 0 q = q" |
|
43921 | 457 |
"max q \<infinity> = (\<infinity>::enat)" |
458 |
"max \<infinity> q = (\<infinity>::enat)" |
|
27110 | 459 |
by (simp_all add: max_def) |
460 |
||
43924 | 461 |
lemma enat_ile: "n \<le> enat m \<Longrightarrow> \<exists>k. n = enat k" |
27110 | 462 |
by (cases n) simp_all |
463 |
||
43924 | 464 |
lemma enat_iless: "n < enat m \<Longrightarrow> \<exists>k. n = enat k" |
27110 | 465 |
by (cases n) simp_all |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
466 |
|
43924 | 467 |
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
|
468 |
apply (induct_tac k) |
43924 | 469 |
apply (simp (no_asm) only: enat_0) |
27110 | 470 |
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
|
471 |
apply (erule exE) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
472 |
apply (drule spec) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
473 |
apply (erule exE) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
474 |
apply (drule ileI1) |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
475 |
apply (rule eSuc_enat [THEN subst]) |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
476 |
apply (rule exI) |
27110 | 477 |
apply (erule (1) le_less_trans) |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
478 |
done |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
479 |
|
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
480 |
lemma eSuc_max: "eSuc (max x y) = max (eSuc x) (eSuc y)" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
481 |
by (simp add: eSuc_def split: enat.split) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
482 |
|
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
483 |
lemma eSuc_Max: |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
484 |
assumes "finite A" "A \<noteq> {}" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
485 |
shows "eSuc (Max A) = Max (eSuc ` A)" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
486 |
using assms proof induction |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
487 |
case (insert x A) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
488 |
thus ?case by(cases "A = {}")(simp_all add: eSuc_max) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
489 |
qed simp |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
490 |
|
52729
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51717
diff
changeset
|
491 |
instantiation enat :: "{order_bot, order_top}" |
29337 | 492 |
begin |
493 |
||
60679 | 494 |
definition bot_enat :: enat where "bot_enat = 0" |
495 |
definition top_enat :: enat where "top_enat = \<infinity>" |
|
29337 | 496 |
|
60679 | 497 |
instance |
498 |
by standard (simp_all add: bot_enat_def top_enat_def) |
|
29337 | 499 |
|
500 |
end |
|
501 |
||
43924 | 502 |
lemma finite_enat_bounded: |
503 |
assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> enat n" |
|
42993 | 504 |
shows "finite A" |
505 |
proof (rule finite_subset) |
|
43924 | 506 |
show "finite (enat ` {..n})" by blast |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44019
diff
changeset
|
507 |
have "A \<subseteq> {..enat n}" using le_fin by fastforce |
43924 | 508 |
also have "\<dots> \<subseteq> enat ` {..n}" |
60679 | 509 |
apply (rule subsetI) |
510 |
subgoal for x by (cases x) auto |
|
511 |
done |
|
43924 | 512 |
finally show "A \<subseteq> enat ` {..n}" . |
42993 | 513 |
qed |
514 |
||
26089 | 515 |
|
60500 | 516 |
subsection \<open>Cancellation simprocs\<close> |
45775 | 517 |
|
518 |
lemma enat_add_left_cancel: "a + b = a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b = c" |
|
519 |
unfolding plus_enat_def by (simp split: enat.split) |
|
520 |
||
521 |
lemma enat_add_left_cancel_le: "a + b \<le> a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b \<le> c" |
|
522 |
unfolding plus_enat_def by (simp split: enat.split) |
|
523 |
||
524 |
lemma enat_add_left_cancel_less: "a + b < a + c \<longleftrightarrow> a \<noteq> (\<infinity>::enat) \<and> b < c" |
|
525 |
unfolding plus_enat_def by (simp split: enat.split) |
|
526 |
||
60500 | 527 |
ML \<open> |
45775 | 528 |
structure Cancel_Enat_Common = |
529 |
struct |
|
530 |
(* copied from src/HOL/Tools/nat_numeral_simprocs.ML *) |
|
531 |
fun find_first_t _ _ [] = raise TERM("find_first_t", []) |
|
532 |
| find_first_t past u (t::terms) = |
|
533 |
if u aconv t then (rev past @ terms) |
|
534 |
else find_first_t (t::past) u terms |
|
535 |
||
51366
abdcf1a7cabf
avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents:
51301
diff
changeset
|
536 |
fun dest_summing (Const (@{const_name Groups.plus}, _) $ t $ u, ts) = |
abdcf1a7cabf
avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents:
51301
diff
changeset
|
537 |
dest_summing (t, dest_summing (u, ts)) |
abdcf1a7cabf
avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents:
51301
diff
changeset
|
538 |
| dest_summing (t, ts) = t :: ts |
abdcf1a7cabf
avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents:
51301
diff
changeset
|
539 |
|
45775 | 540 |
val mk_sum = Arith_Data.long_mk_sum |
51366
abdcf1a7cabf
avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents:
51301
diff
changeset
|
541 |
fun dest_sum t = dest_summing (t, []) |
45775 | 542 |
val find_first = find_first_t [] |
543 |
val trans_tac = Numeral_Simprocs.trans_tac |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51366
diff
changeset
|
544 |
val norm_ss = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51366
diff
changeset
|
545 |
simpset_of (put_simpset HOL_basic_ss @{context} |
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
546 |
addsimps @{thms ac_simps add_0_left add_0_right}) |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51366
diff
changeset
|
547 |
fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset norm_ss ctxt)) |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51366
diff
changeset
|
548 |
fun simplify_meta_eq ctxt cancel_th th = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51366
diff
changeset
|
549 |
Arith_Data.simplify_meta_eq [] ctxt |
45775 | 550 |
([th, cancel_th] MRS trans) |
551 |
fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b)) |
|
552 |
end |
|
553 |
||
554 |
structure Eq_Enat_Cancel = ExtractCommonTermFun |
|
555 |
(open Cancel_Enat_Common |
|
556 |
val mk_bal = HOLogic.mk_eq |
|
557 |
val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} @{typ enat} |
|
558 |
fun simp_conv _ _ = SOME @{thm enat_add_left_cancel} |
|
559 |
) |
|
560 |
||
561 |
structure Le_Enat_Cancel = ExtractCommonTermFun |
|
562 |
(open Cancel_Enat_Common |
|
563 |
val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less_eq} |
|
564 |
val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} @{typ enat} |
|
565 |
fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le} |
|
566 |
) |
|
567 |
||
568 |
structure Less_Enat_Cancel = ExtractCommonTermFun |
|
569 |
(open Cancel_Enat_Common |
|
570 |
val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less} |
|
571 |
val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} @{typ enat} |
|
572 |
fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less} |
|
573 |
) |
|
60500 | 574 |
\<close> |
45775 | 575 |
|
576 |
simproc_setup enat_eq_cancel |
|
577 |
("(l::enat) + m = n" | "(l::enat) = m + n") = |
|
60500 | 578 |
\<open>fn phi => fn ctxt => fn ct => Eq_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close> |
45775 | 579 |
|
580 |
simproc_setup enat_le_cancel |
|
581 |
("(l::enat) + m \<le> n" | "(l::enat) \<le> m + n") = |
|
60500 | 582 |
\<open>fn phi => fn ctxt => fn ct => Le_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close> |
45775 | 583 |
|
584 |
simproc_setup enat_less_cancel |
|
585 |
("(l::enat) + m < n" | "(l::enat) < m + n") = |
|
60500 | 586 |
\<open>fn phi => fn ctxt => fn ct => Less_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close> |
45775 | 587 |
|
60500 | 588 |
text \<open>TODO: add regression tests for these simprocs\<close> |
45775 | 589 |
|
60500 | 590 |
text \<open>TODO: add simprocs for combining and cancelling numerals\<close> |
45775 | 591 |
|
60500 | 592 |
subsection \<open>Well-ordering\<close> |
26089 | 593 |
|
43924 | 594 |
lemma less_enatE: |
595 |
"[| n < enat m; !!k. n = enat k ==> k < m ==> P |] ==> P" |
|
26089 | 596 |
by (induct n) auto |
597 |
||
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
598 |
lemma less_infinityE: |
43924 | 599 |
"[| n < \<infinity>; !!k. n = enat k ==> P |] ==> P" |
26089 | 600 |
by (induct n) auto |
601 |
||
43919 | 602 |
lemma enat_less_induct: |
603 |
assumes prem: "!!n. \<forall>m::enat. m < n --> P m ==> P n" shows "P n" |
|
26089 | 604 |
proof - |
43924 | 605 |
have P_enat: "!!k. P (enat k)" |
26089 | 606 |
apply (rule nat_less_induct) |
607 |
apply (rule prem, clarify) |
|
43924 | 608 |
apply (erule less_enatE, simp) |
26089 | 609 |
done |
610 |
show ?thesis |
|
611 |
proof (induct n) |
|
612 |
fix nat |
|
43924 | 613 |
show "P (enat nat)" by (rule P_enat) |
26089 | 614 |
next |
43921 | 615 |
show "P \<infinity>" |
26089 | 616 |
apply (rule prem, clarify) |
44019
ee784502aed5
Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents:
43978
diff
changeset
|
617 |
apply (erule less_infinityE) |
43924 | 618 |
apply (simp add: P_enat) |
26089 | 619 |
done |
620 |
qed |
|
621 |
qed |
|
622 |
||
43919 | 623 |
instance enat :: wellorder |
26089 | 624 |
proof |
27823 | 625 |
fix P and n |
43919 | 626 |
assume hyp: "(\<And>n\<Colon>enat. (\<And>m\<Colon>enat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)" |
627 |
show "P n" by (blast intro: enat_less_induct hyp) |
|
26089 | 628 |
qed |
629 |
||
60500 | 630 |
subsection \<open>Complete Lattice\<close> |
42993 | 631 |
|
43919 | 632 |
instantiation enat :: complete_lattice |
42993 | 633 |
begin |
634 |
||
43919 | 635 |
definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where |
56777 | 636 |
"inf_enat = min" |
42993 | 637 |
|
43919 | 638 |
definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where |
56777 | 639 |
"sup_enat = max" |
42993 | 640 |
|
43919 | 641 |
definition Inf_enat :: "enat set \<Rightarrow> enat" where |
56777 | 642 |
"Inf_enat A = (if A = {} then \<infinity> else (LEAST x. x \<in> A))" |
42993 | 643 |
|
43919 | 644 |
definition Sup_enat :: "enat set \<Rightarrow> enat" where |
56777 | 645 |
"Sup_enat A = (if A = {} then 0 else if finite A then Max A else \<infinity>)" |
646 |
instance |
|
647 |
proof |
|
43919 | 648 |
fix x :: "enat" and A :: "enat set" |
42993 | 649 |
{ assume "x \<in> A" then show "Inf A \<le> x" |
43919 | 650 |
unfolding Inf_enat_def by (auto intro: Least_le) } |
42993 | 651 |
{ assume "\<And>y. y \<in> A \<Longrightarrow> x \<le> y" then show "x \<le> Inf A" |
43919 | 652 |
unfolding Inf_enat_def |
42993 | 653 |
by (cases "A = {}") (auto intro: LeastI2_ex) } |
654 |
{ assume "x \<in> A" then show "x \<le> Sup A" |
|
43919 | 655 |
unfolding Sup_enat_def by (cases "finite A") auto } |
42993 | 656 |
{ assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x" |
43924 | 657 |
unfolding Sup_enat_def using finite_enat_bounded by auto } |
52729
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51717
diff
changeset
|
658 |
qed (simp_all add: |
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51717
diff
changeset
|
659 |
inf_enat_def sup_enat_def bot_enat_def top_enat_def Inf_enat_def Sup_enat_def) |
42993 | 660 |
end |
661 |
||
43978 | 662 |
instance enat :: complete_linorder .. |
27110 | 663 |
|
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
664 |
lemma eSuc_Sup: "A \<noteq> {} \<Longrightarrow> eSuc (Sup A) = Sup (eSuc ` A)" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
665 |
by(auto simp add: Sup_enat_def eSuc_Max inj_on_def dest: finite_imageD) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
666 |
|
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
667 |
lemma sup_continuous_eSuc: "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. eSuc (f x))" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
668 |
using eSuc_Sup[of "_ ` UNIV"] by (auto simp: sup_continuous_def) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60500
diff
changeset
|
669 |
|
60500 | 670 |
subsection \<open>Traditional theorem names\<close> |
27110 | 671 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45934
diff
changeset
|
672 |
lemmas enat_defs = zero_enat_def one_enat_def eSuc_def |
43919 | 673 |
plus_enat_def less_eq_enat_def less_enat_def |
27110 | 674 |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
675 |
end |