author | nipkow |
Sat, 26 Feb 2011 17:44:42 +0100 | |
changeset 41853 | 258a489c24b2 |
parent 38621 | d6cb7e625d75 |
child 41855 | c3b6e69da386 |
permissions | -rw-r--r-- |
11355 | 1 |
(* Title: HOL/Library/Nat_Infinity.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 |
|
14706 | 6 |
header {* Natural numbers with infinity *} |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
7 |
|
15131 | 8 |
theory Nat_Infinity |
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 |
|
27110 | 12 |
subsection {* Type definition *} |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
13 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
14 |
text {* |
11355 | 15 |
We extend the standard natural numbers by a special value indicating |
27110 | 16 |
infinity. |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
17 |
*} |
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
18 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
19 |
datatype inat = Fin nat | Infty |
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
20 |
|
21210 | 21 |
notation (xsymbols) |
19736 | 22 |
Infty ("\<infinity>") |
23 |
||
21210 | 24 |
notation (HTML output) |
19736 | 25 |
Infty ("\<infinity>") |
26 |
||
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
27 |
|
31084 | 28 |
lemma not_Infty_eq[iff]: "(x ~= Infty) = (EX i. x = Fin i)" |
29 |
by (cases x) auto |
|
30 |
||
31 |
lemma not_Fin_eq [iff]: "(ALL y. x ~= Fin y) = (x = Infty)" |
|
31077 | 32 |
by (cases x) auto |
33 |
||
34 |
||
27110 | 35 |
subsection {* Constructors and numbers *} |
36 |
||
37 |
instantiation inat :: "{zero, one, number}" |
|
25594 | 38 |
begin |
39 |
||
40 |
definition |
|
27110 | 41 |
"0 = Fin 0" |
25594 | 42 |
|
43 |
definition |
|
32069
6d28bbd33e2c
prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents:
31998
diff
changeset
|
44 |
[code_unfold]: "1 = Fin 1" |
25594 | 45 |
|
46 |
definition |
|
32069
6d28bbd33e2c
prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents:
31998
diff
changeset
|
47 |
[code_unfold, code del]: "number_of k = Fin (number_of k)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
48 |
|
25594 | 49 |
instance .. |
50 |
||
51 |
end |
|
52 |
||
27110 | 53 |
definition iSuc :: "inat \<Rightarrow> inat" where |
54 |
"iSuc i = (case i of Fin n \<Rightarrow> Fin (Suc n) | \<infinity> \<Rightarrow> \<infinity>)" |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
55 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
56 |
lemma Fin_0: "Fin 0 = 0" |
27110 | 57 |
by (simp add: zero_inat_def) |
58 |
||
59 |
lemma Fin_1: "Fin 1 = 1" |
|
60 |
by (simp add: one_inat_def) |
|
61 |
||
62 |
lemma Fin_number: "Fin (number_of k) = number_of k" |
|
63 |
by (simp add: number_of_inat_def) |
|
64 |
||
65 |
lemma one_iSuc: "1 = iSuc 0" |
|
66 |
by (simp add: zero_inat_def one_inat_def iSuc_def) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
67 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
68 |
lemma Infty_ne_i0 [simp]: "\<infinity> \<noteq> 0" |
27110 | 69 |
by (simp add: zero_inat_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
70 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
71 |
lemma i0_ne_Infty [simp]: "0 \<noteq> \<infinity>" |
27110 | 72 |
by (simp add: zero_inat_def) |
73 |
||
74 |
lemma zero_inat_eq [simp]: |
|
75 |
"number_of k = (0\<Colon>inat) \<longleftrightarrow> number_of k = (0\<Colon>nat)" |
|
76 |
"(0\<Colon>inat) = number_of k \<longleftrightarrow> number_of k = (0\<Colon>nat)" |
|
77 |
unfolding zero_inat_def number_of_inat_def by simp_all |
|
78 |
||
79 |
lemma one_inat_eq [simp]: |
|
80 |
"number_of k = (1\<Colon>inat) \<longleftrightarrow> number_of k = (1\<Colon>nat)" |
|
81 |
"(1\<Colon>inat) = number_of k \<longleftrightarrow> number_of k = (1\<Colon>nat)" |
|
82 |
unfolding one_inat_def number_of_inat_def by simp_all |
|
83 |
||
84 |
lemma zero_one_inat_neq [simp]: |
|
85 |
"\<not> 0 = (1\<Colon>inat)" |
|
86 |
"\<not> 1 = (0\<Colon>inat)" |
|
87 |
unfolding zero_inat_def one_inat_def by simp_all |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
88 |
|
27110 | 89 |
lemma Infty_ne_i1 [simp]: "\<infinity> \<noteq> 1" |
90 |
by (simp add: one_inat_def) |
|
91 |
||
92 |
lemma i1_ne_Infty [simp]: "1 \<noteq> \<infinity>" |
|
93 |
by (simp add: one_inat_def) |
|
94 |
||
95 |
lemma Infty_ne_number [simp]: "\<infinity> \<noteq> number_of k" |
|
96 |
by (simp add: number_of_inat_def) |
|
97 |
||
98 |
lemma number_ne_Infty [simp]: "number_of k \<noteq> \<infinity>" |
|
99 |
by (simp add: number_of_inat_def) |
|
100 |
||
101 |
lemma iSuc_Fin: "iSuc (Fin n) = Fin (Suc n)" |
|
102 |
by (simp add: iSuc_def) |
|
103 |
||
104 |
lemma iSuc_number_of: "iSuc (number_of k) = Fin (Suc (number_of k))" |
|
105 |
by (simp add: iSuc_Fin number_of_inat_def) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
106 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
107 |
lemma iSuc_Infty [simp]: "iSuc \<infinity> = \<infinity>" |
27110 | 108 |
by (simp add: iSuc_def) |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
109 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
110 |
lemma iSuc_ne_0 [simp]: "iSuc n \<noteq> 0" |
27110 | 111 |
by (simp add: iSuc_def zero_inat_def split: inat.splits) |
112 |
||
113 |
lemma zero_ne_iSuc [simp]: "0 \<noteq> iSuc n" |
|
114 |
by (rule iSuc_ne_0 [symmetric]) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
115 |
|
27110 | 116 |
lemma iSuc_inject [simp]: "iSuc m = iSuc n \<longleftrightarrow> m = n" |
117 |
by (simp add: iSuc_def split: inat.splits) |
|
118 |
||
119 |
lemma number_of_inat_inject [simp]: |
|
120 |
"(number_of k \<Colon> inat) = number_of l \<longleftrightarrow> (number_of k \<Colon> nat) = number_of l" |
|
121 |
by (simp add: number_of_inat_def) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
122 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
123 |
|
27110 | 124 |
subsection {* Addition *} |
125 |
||
126 |
instantiation inat :: comm_monoid_add |
|
127 |
begin |
|
128 |
||
38167 | 129 |
definition [nitpick_simp]: |
37765 | 130 |
"m + n = (case m of \<infinity> \<Rightarrow> \<infinity> | Fin m \<Rightarrow> (case n of \<infinity> \<Rightarrow> \<infinity> | Fin n \<Rightarrow> Fin (m + n)))" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
131 |
|
27110 | 132 |
lemma plus_inat_simps [simp, code]: |
133 |
"Fin m + Fin n = Fin (m + n)" |
|
134 |
"\<infinity> + q = \<infinity>" |
|
135 |
"q + \<infinity> = \<infinity>" |
|
136 |
by (simp_all add: plus_inat_def split: inat.splits) |
|
137 |
||
138 |
instance proof |
|
139 |
fix n m q :: inat |
|
140 |
show "n + m + q = n + (m + q)" |
|
141 |
by (cases n, auto, cases m, auto, cases q, auto) |
|
142 |
show "n + m = m + n" |
|
143 |
by (cases n, auto, cases m, auto) |
|
144 |
show "0 + n = n" |
|
145 |
by (cases n) (simp_all add: zero_inat_def) |
|
26089 | 146 |
qed |
147 |
||
27110 | 148 |
end |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
149 |
|
27110 | 150 |
lemma plus_inat_0 [simp]: |
151 |
"0 + (q\<Colon>inat) = q" |
|
152 |
"(q\<Colon>inat) + 0 = q" |
|
153 |
by (simp_all add: plus_inat_def zero_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
154 |
|
27110 | 155 |
lemma plus_inat_number [simp]: |
29012 | 156 |
"(number_of k \<Colon> inat) + number_of l = (if k < Int.Pls then number_of l |
157 |
else if l < Int.Pls then number_of k else number_of (k + l))" |
|
27110 | 158 |
unfolding number_of_inat_def plus_inat_simps nat_arith(1) if_distrib [symmetric, of _ Fin] .. |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
159 |
|
27110 | 160 |
lemma iSuc_number [simp]: |
161 |
"iSuc (number_of k) = (if neg (number_of k \<Colon> int) then 1 else number_of (Int.succ k))" |
|
162 |
unfolding iSuc_number_of |
|
163 |
unfolding one_inat_def number_of_inat_def Suc_nat_number_of if_distrib [symmetric] .. |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
164 |
|
27110 | 165 |
lemma iSuc_plus_1: |
166 |
"iSuc n = n + 1" |
|
167 |
by (cases n) (simp_all add: iSuc_Fin one_inat_def) |
|
168 |
||
169 |
lemma plus_1_iSuc: |
|
170 |
"1 + q = iSuc q" |
|
171 |
"q + 1 = iSuc q" |
|
41853 | 172 |
by (simp_all add: iSuc_plus_1 add_ac) |
173 |
||
174 |
lemma iadd_Suc: "iSuc m + n = iSuc (m + n)" |
|
175 |
by (simp_all add: iSuc_plus_1 add_ac) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
176 |
|
41853 | 177 |
lemma iadd_Suc_right: "m + iSuc n = iSuc (m + n)" |
178 |
by (simp only: add_commute[of m] iadd_Suc) |
|
179 |
||
180 |
lemma iadd_is_0: "(m + n = (0::inat)) = (m = 0 \<and> n = 0)" |
|
181 |
by (cases m, cases n, simp_all add: zero_inat_def) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
182 |
|
29014 | 183 |
subsection {* Multiplication *} |
184 |
||
185 |
instantiation inat :: comm_semiring_1 |
|
186 |
begin |
|
187 |
||
38167 | 188 |
definition times_inat_def [nitpick_simp]: |
29014 | 189 |
"m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | Fin m \<Rightarrow> |
190 |
(case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | Fin n \<Rightarrow> Fin (m * n)))" |
|
191 |
||
192 |
lemma times_inat_simps [simp, code]: |
|
193 |
"Fin m * Fin n = Fin (m * n)" |
|
194 |
"\<infinity> * \<infinity> = \<infinity>" |
|
195 |
"\<infinity> * Fin n = (if n = 0 then 0 else \<infinity>)" |
|
196 |
"Fin m * \<infinity> = (if m = 0 then 0 else \<infinity>)" |
|
197 |
unfolding times_inat_def zero_inat_def |
|
198 |
by (simp_all split: inat.split) |
|
199 |
||
200 |
instance proof |
|
201 |
fix a b c :: inat |
|
202 |
show "(a * b) * c = a * (b * c)" |
|
203 |
unfolding times_inat_def zero_inat_def |
|
204 |
by (simp split: inat.split) |
|
205 |
show "a * b = b * a" |
|
206 |
unfolding times_inat_def zero_inat_def |
|
207 |
by (simp split: inat.split) |
|
208 |
show "1 * a = a" |
|
209 |
unfolding times_inat_def zero_inat_def one_inat_def |
|
210 |
by (simp split: inat.split) |
|
211 |
show "(a + b) * c = a * c + b * c" |
|
212 |
unfolding times_inat_def zero_inat_def |
|
213 |
by (simp split: inat.split add: left_distrib) |
|
214 |
show "0 * a = 0" |
|
215 |
unfolding times_inat_def zero_inat_def |
|
216 |
by (simp split: inat.split) |
|
217 |
show "a * 0 = 0" |
|
218 |
unfolding times_inat_def zero_inat_def |
|
219 |
by (simp split: inat.split) |
|
220 |
show "(0::inat) \<noteq> 1" |
|
221 |
unfolding zero_inat_def one_inat_def |
|
222 |
by simp |
|
223 |
qed |
|
224 |
||
225 |
end |
|
226 |
||
227 |
lemma mult_iSuc: "iSuc m * n = n + m * n" |
|
29667 | 228 |
unfolding iSuc_plus_1 by (simp add: algebra_simps) |
29014 | 229 |
|
230 |
lemma mult_iSuc_right: "m * iSuc n = m + m * n" |
|
29667 | 231 |
unfolding iSuc_plus_1 by (simp add: algebra_simps) |
29014 | 232 |
|
29023 | 233 |
lemma of_nat_eq_Fin: "of_nat n = Fin n" |
234 |
apply (induct n) |
|
235 |
apply (simp add: Fin_0) |
|
236 |
apply (simp add: plus_1_iSuc iSuc_Fin) |
|
237 |
done |
|
238 |
||
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
38167
diff
changeset
|
239 |
instance inat :: semiring_char_0 proof |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
38167
diff
changeset
|
240 |
have "inj Fin" by (rule injI) simp |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
38167
diff
changeset
|
241 |
then show "inj (\<lambda>n. of_nat n :: inat)" by (simp add: of_nat_eq_Fin) |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
38167
diff
changeset
|
242 |
qed |
29023 | 243 |
|
41853 | 244 |
lemma imult_is_0[simp]: "((m::inat) * n = 0) = (m = 0 \<or> n = 0)" |
245 |
by(auto simp add: times_inat_def zero_inat_def split: inat.split) |
|
246 |
||
247 |
lemma imult_is_Infty: "((a::inat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)" |
|
248 |
by(auto simp add: times_inat_def zero_inat_def split: inat.split) |
|
249 |
||
250 |
||
251 |
subsection {* Subtraction *} |
|
252 |
||
253 |
instantiation inat :: minus |
|
254 |
begin |
|
255 |
||
256 |
definition diff_inat_def: |
|
257 |
"a - b = (case a of (Fin x) \<Rightarrow> (case b of (Fin y) \<Rightarrow> Fin (x - y) | \<infinity> \<Rightarrow> 0) |
|
258 |
| \<infinity> \<Rightarrow> \<infinity>)" |
|
259 |
||
260 |
instance .. |
|
261 |
||
262 |
end |
|
263 |
||
264 |
lemma idiff_Fin_Fin[simp,code]: "Fin a - Fin b = Fin (a - b)" |
|
265 |
by(simp add: diff_inat_def) |
|
266 |
||
267 |
lemma idiff_Infty[simp,code]: "\<infinity> - n = \<infinity>" |
|
268 |
by(simp add: diff_inat_def) |
|
269 |
||
270 |
lemma idiff_Infty_right[simp,code]: "Fin a - \<infinity> = 0" |
|
271 |
by(simp add: diff_inat_def) |
|
272 |
||
273 |
lemma idiff_0[simp]: "(0::inat) - n = 0" |
|
274 |
by (cases n, simp_all add: zero_inat_def) |
|
275 |
||
276 |
lemmas idiff_Fin_0[simp] = idiff_0[unfolded zero_inat_def] |
|
277 |
||
278 |
lemma idiff_0_right[simp]: "(n::inat) - 0 = n" |
|
279 |
by (cases n) (simp_all add: zero_inat_def) |
|
280 |
||
281 |
lemmas idiff_Fin_0_right[simp] = idiff_0_right[unfolded zero_inat_def] |
|
282 |
||
283 |
lemma idiff_self[simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::inat) - n = 0" |
|
284 |
by(auto simp: zero_inat_def) |
|
285 |
||
286 |
(*lemmas idiff_self_eq_0_Fin = idiff_self_eq_0[unfolded zero_inat_def]*) |
|
287 |
||
29014 | 288 |
|
27110 | 289 |
subsection {* Ordering *} |
290 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
32069
diff
changeset
|
291 |
instantiation inat :: linordered_ab_semigroup_add |
27110 | 292 |
begin |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
293 |
|
38167 | 294 |
definition [nitpick_simp]: |
37765 | 295 |
"m \<le> n = (case n of Fin n1 \<Rightarrow> (case m of Fin m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False) |
27110 | 296 |
| \<infinity> \<Rightarrow> True)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
297 |
|
38167 | 298 |
definition [nitpick_simp]: |
37765 | 299 |
"m < n = (case m of Fin m1 \<Rightarrow> (case n of Fin n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True) |
27110 | 300 |
| \<infinity> \<Rightarrow> False)" |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
301 |
|
27110 | 302 |
lemma inat_ord_simps [simp]: |
303 |
"Fin m \<le> Fin n \<longleftrightarrow> m \<le> n" |
|
304 |
"Fin m < Fin n \<longleftrightarrow> m < n" |
|
305 |
"q \<le> \<infinity>" |
|
306 |
"q < \<infinity> \<longleftrightarrow> q \<noteq> \<infinity>" |
|
307 |
"\<infinity> \<le> q \<longleftrightarrow> q = \<infinity>" |
|
308 |
"\<infinity> < q \<longleftrightarrow> False" |
|
309 |
by (simp_all add: less_eq_inat_def less_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
310 |
|
27110 | 311 |
lemma inat_ord_code [code]: |
312 |
"Fin m \<le> Fin n \<longleftrightarrow> m \<le> n" |
|
313 |
"Fin m < Fin n \<longleftrightarrow> m < n" |
|
314 |
"q \<le> \<infinity> \<longleftrightarrow> True" |
|
315 |
"Fin m < \<infinity> \<longleftrightarrow> True" |
|
316 |
"\<infinity> \<le> Fin n \<longleftrightarrow> False" |
|
317 |
"\<infinity> < q \<longleftrightarrow> False" |
|
318 |
by simp_all |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
319 |
|
27110 | 320 |
instance by default |
321 |
(auto simp add: less_eq_inat_def less_inat_def plus_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
322 |
|
27110 | 323 |
end |
324 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
32069
diff
changeset
|
325 |
instance inat :: ordered_comm_semiring |
29014 | 326 |
proof |
327 |
fix a b c :: inat |
|
328 |
assume "a \<le> b" and "0 \<le> c" |
|
329 |
thus "c * a \<le> c * b" |
|
330 |
unfolding times_inat_def less_eq_inat_def zero_inat_def |
|
331 |
by (simp split: inat.splits) |
|
332 |
qed |
|
333 |
||
27110 | 334 |
lemma inat_ord_number [simp]: |
335 |
"(number_of m \<Colon> inat) \<le> number_of n \<longleftrightarrow> (number_of m \<Colon> nat) \<le> number_of n" |
|
336 |
"(number_of m \<Colon> inat) < number_of n \<longleftrightarrow> (number_of m \<Colon> nat) < number_of n" |
|
337 |
by (simp_all add: number_of_inat_def) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
338 |
|
27110 | 339 |
lemma i0_lb [simp]: "(0\<Colon>inat) \<le> n" |
340 |
by (simp add: zero_inat_def less_eq_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
341 |
|
41853 | 342 |
lemma ile0_eq [simp]: "n \<le> (0\<Colon>inat) \<longleftrightarrow> n = 0" |
343 |
by (simp add: zero_inat_def less_eq_inat_def split: inat.splits) |
|
27110 | 344 |
|
345 |
lemma Infty_ileE [elim!]: "\<infinity> \<le> Fin m \<Longrightarrow> R" |
|
346 |
by (simp add: zero_inat_def less_eq_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
347 |
|
27110 | 348 |
lemma Infty_ilessE [elim!]: "\<infinity> < Fin m \<Longrightarrow> R" |
349 |
by simp |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
350 |
|
41853 | 351 |
lemma not_iless0 [simp]: "\<not> n < (0\<Colon>inat)" |
27110 | 352 |
by (simp add: zero_inat_def less_inat_def split: inat.splits) |
353 |
||
41853 | 354 |
lemma i0_less [simp]: "(0\<Colon>inat) < n \<longleftrightarrow> n \<noteq> 0" |
355 |
by (simp add: zero_inat_def less_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
356 |
|
27110 | 357 |
lemma iSuc_ile_mono [simp]: "iSuc n \<le> iSuc m \<longleftrightarrow> n \<le> m" |
358 |
by (simp add: iSuc_def less_eq_inat_def split: inat.splits) |
|
359 |
||
360 |
lemma iSuc_mono [simp]: "iSuc n < iSuc m \<longleftrightarrow> n < m" |
|
361 |
by (simp add: iSuc_def less_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
362 |
|
27110 | 363 |
lemma ile_iSuc [simp]: "n \<le> iSuc n" |
364 |
by (simp add: iSuc_def less_eq_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
365 |
|
11355 | 366 |
lemma not_iSuc_ilei0 [simp]: "\<not> iSuc n \<le> 0" |
27110 | 367 |
by (simp add: zero_inat_def iSuc_def less_eq_inat_def split: inat.splits) |
368 |
||
369 |
lemma i0_iless_iSuc [simp]: "0 < iSuc n" |
|
370 |
by (simp add: zero_inat_def iSuc_def less_inat_def split: inat.splits) |
|
371 |
||
41853 | 372 |
lemma iless_iSuc0[simp]: "(n < iSuc 0) = (n = 0)" |
373 |
by (simp add: zero_inat_def iSuc_def less_inat_def split: inat.split) |
|
374 |
||
27110 | 375 |
lemma ileI1: "m < n \<Longrightarrow> iSuc m \<le> n" |
376 |
by (simp add: iSuc_def less_eq_inat_def less_inat_def split: inat.splits) |
|
377 |
||
378 |
lemma Suc_ile_eq: "Fin (Suc m) \<le> n \<longleftrightarrow> Fin m < n" |
|
379 |
by (cases n) auto |
|
380 |
||
381 |
lemma iless_Suc_eq [simp]: "Fin m < iSuc n \<longleftrightarrow> Fin m \<le> n" |
|
382 |
by (auto simp add: iSuc_def less_inat_def split: inat.splits) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
383 |
|
41853 | 384 |
lemma imult_Infty: "(0::inat) < n \<Longrightarrow> \<infinity> * n = \<infinity>" |
385 |
by (simp add: zero_inat_def less_inat_def split: inat.splits) |
|
386 |
||
387 |
lemma imult_Infty_right: "(0::inat) < n \<Longrightarrow> n * \<infinity> = \<infinity>" |
|
388 |
by (simp add: zero_inat_def less_inat_def split: inat.splits) |
|
389 |
||
390 |
lemma inat_0_less_mult_iff: "(0 < (m::inat) * n) = (0 < m \<and> 0 < n)" |
|
391 |
by (simp only: i0_less imult_is_0, simp) |
|
392 |
||
393 |
lemma mono_iSuc: "mono iSuc" |
|
394 |
by(simp add: mono_def) |
|
395 |
||
396 |
||
27110 | 397 |
lemma min_inat_simps [simp]: |
398 |
"min (Fin m) (Fin n) = Fin (min m n)" |
|
399 |
"min q 0 = 0" |
|
400 |
"min 0 q = 0" |
|
401 |
"min q \<infinity> = q" |
|
402 |
"min \<infinity> q = q" |
|
403 |
by (auto simp add: min_def) |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
404 |
|
27110 | 405 |
lemma max_inat_simps [simp]: |
406 |
"max (Fin m) (Fin n) = Fin (max m n)" |
|
407 |
"max q 0 = q" |
|
408 |
"max 0 q = q" |
|
409 |
"max q \<infinity> = \<infinity>" |
|
410 |
"max \<infinity> q = \<infinity>" |
|
411 |
by (simp_all add: max_def) |
|
412 |
||
413 |
lemma Fin_ile: "n \<le> Fin m \<Longrightarrow> \<exists>k. n = Fin k" |
|
414 |
by (cases n) simp_all |
|
415 |
||
416 |
lemma Fin_iless: "n < Fin m \<Longrightarrow> \<exists>k. n = Fin k" |
|
417 |
by (cases n) simp_all |
|
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
418 |
|
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
419 |
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. Fin k < Y j" |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
420 |
apply (induct_tac k) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
421 |
apply (simp (no_asm) only: Fin_0) |
27110 | 422 |
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
|
423 |
apply (erule exE) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
424 |
apply (drule spec) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
425 |
apply (erule exE) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
426 |
apply (drule ileI1) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
427 |
apply (rule iSuc_Fin [THEN subst]) |
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
428 |
apply (rule exI) |
27110 | 429 |
apply (erule (1) le_less_trans) |
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
430 |
done |
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
431 |
|
29337 | 432 |
instantiation inat :: "{bot, top}" |
433 |
begin |
|
434 |
||
435 |
definition bot_inat :: inat where |
|
436 |
"bot_inat = 0" |
|
437 |
||
438 |
definition top_inat :: inat where |
|
439 |
"top_inat = \<infinity>" |
|
440 |
||
441 |
instance proof |
|
442 |
qed (simp_all add: bot_inat_def top_inat_def) |
|
443 |
||
444 |
end |
|
445 |
||
26089 | 446 |
|
27110 | 447 |
subsection {* Well-ordering *} |
26089 | 448 |
|
449 |
lemma less_FinE: |
|
450 |
"[| n < Fin m; !!k. n = Fin k ==> k < m ==> P |] ==> P" |
|
451 |
by (induct n) auto |
|
452 |
||
453 |
lemma less_InftyE: |
|
454 |
"[| n < Infty; !!k. n = Fin k ==> P |] ==> P" |
|
455 |
by (induct n) auto |
|
456 |
||
457 |
lemma inat_less_induct: |
|
458 |
assumes prem: "!!n. \<forall>m::inat. m < n --> P m ==> P n" shows "P n" |
|
459 |
proof - |
|
460 |
have P_Fin: "!!k. P (Fin k)" |
|
461 |
apply (rule nat_less_induct) |
|
462 |
apply (rule prem, clarify) |
|
463 |
apply (erule less_FinE, simp) |
|
464 |
done |
|
465 |
show ?thesis |
|
466 |
proof (induct n) |
|
467 |
fix nat |
|
468 |
show "P (Fin nat)" by (rule P_Fin) |
|
469 |
next |
|
470 |
show "P Infty" |
|
471 |
apply (rule prem, clarify) |
|
472 |
apply (erule less_InftyE) |
|
473 |
apply (simp add: P_Fin) |
|
474 |
done |
|
475 |
qed |
|
476 |
qed |
|
477 |
||
478 |
instance inat :: wellorder |
|
479 |
proof |
|
27823 | 480 |
fix P and n |
481 |
assume hyp: "(\<And>n\<Colon>inat. (\<And>m\<Colon>inat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)" |
|
482 |
show "P n" by (blast intro: inat_less_induct hyp) |
|
26089 | 483 |
qed |
484 |
||
27110 | 485 |
|
486 |
subsection {* Traditional theorem names *} |
|
487 |
||
488 |
lemmas inat_defs = zero_inat_def one_inat_def number_of_inat_def iSuc_def |
|
489 |
plus_inat_def less_eq_inat_def less_inat_def |
|
490 |
||
491 |
lemmas inat_splits = inat.splits |
|
492 |
||
11351
c5c403d30c77
added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff
changeset
|
493 |
end |