1 (* Title : HyperNat.thy |
|
2 Author : Jacques D. Fleuriot |
|
3 Copyright : 1998 University of Cambridge |
|
4 |
|
5 Converted to Isar and polished by lcp |
|
6 *) |
|
7 |
|
8 section\<open>Hypernatural numbers\<close> |
|
9 |
|
10 theory HyperNat |
|
11 imports StarDef |
|
12 begin |
|
13 |
|
14 type_synonym hypnat = "nat star" |
|
15 |
|
16 abbreviation |
|
17 hypnat_of_nat :: "nat => nat star" where |
|
18 "hypnat_of_nat == star_of" |
|
19 |
|
20 definition |
|
21 hSuc :: "hypnat => hypnat" where |
|
22 hSuc_def [transfer_unfold]: "hSuc = *f* Suc" |
|
23 |
|
24 subsection\<open>Properties Transferred from Naturals\<close> |
|
25 |
|
26 lemma hSuc_not_zero [iff]: "\<And>m. hSuc m \<noteq> 0" |
|
27 by transfer (rule Suc_not_Zero) |
|
28 |
|
29 lemma zero_not_hSuc [iff]: "\<And>m. 0 \<noteq> hSuc m" |
|
30 by transfer (rule Zero_not_Suc) |
|
31 |
|
32 lemma hSuc_hSuc_eq [iff]: "\<And>m n. (hSuc m = hSuc n) = (m = n)" |
|
33 by transfer (rule nat.inject) |
|
34 |
|
35 lemma zero_less_hSuc [iff]: "\<And>n. 0 < hSuc n" |
|
36 by transfer (rule zero_less_Suc) |
|
37 |
|
38 lemma hypnat_minus_zero [simp]: "!!z. z - z = (0::hypnat)" |
|
39 by transfer (rule diff_self_eq_0) |
|
40 |
|
41 lemma hypnat_diff_0_eq_0 [simp]: "!!n. (0::hypnat) - n = 0" |
|
42 by transfer (rule diff_0_eq_0) |
|
43 |
|
44 lemma hypnat_add_is_0 [iff]: "!!m n. (m+n = (0::hypnat)) = (m=0 & n=0)" |
|
45 by transfer (rule add_is_0) |
|
46 |
|
47 lemma hypnat_diff_diff_left: "!!i j k. (i::hypnat) - j - k = i - (j+k)" |
|
48 by transfer (rule diff_diff_left) |
|
49 |
|
50 lemma hypnat_diff_commute: "!!i j k. (i::hypnat) - j - k = i-k-j" |
|
51 by transfer (rule diff_commute) |
|
52 |
|
53 lemma hypnat_diff_add_inverse [simp]: "!!m n. ((n::hypnat) + m) - n = m" |
|
54 by transfer (rule diff_add_inverse) |
|
55 |
|
56 lemma hypnat_diff_add_inverse2 [simp]: "!!m n. ((m::hypnat) + n) - n = m" |
|
57 by transfer (rule diff_add_inverse2) |
|
58 |
|
59 lemma hypnat_diff_cancel [simp]: "!!k m n. ((k::hypnat) + m) - (k+n) = m - n" |
|
60 by transfer (rule diff_cancel) |
|
61 |
|
62 lemma hypnat_diff_cancel2 [simp]: "!!k m n. ((m::hypnat) + k) - (n+k) = m - n" |
|
63 by transfer (rule diff_cancel2) |
|
64 |
|
65 lemma hypnat_diff_add_0 [simp]: "!!m n. (n::hypnat) - (n+m) = (0::hypnat)" |
|
66 by transfer (rule diff_add_0) |
|
67 |
|
68 lemma hypnat_diff_mult_distrib: "!!k m n. ((m::hypnat) - n) * k = (m * k) - (n * k)" |
|
69 by transfer (rule diff_mult_distrib) |
|
70 |
|
71 lemma hypnat_diff_mult_distrib2: "!!k m n. (k::hypnat) * (m - n) = (k * m) - (k * n)" |
|
72 by transfer (rule diff_mult_distrib2) |
|
73 |
|
74 lemma hypnat_le_zero_cancel [iff]: "!!n. (n \<le> (0::hypnat)) = (n = 0)" |
|
75 by transfer (rule le_0_eq) |
|
76 |
|
77 lemma hypnat_mult_is_0 [simp]: "!!m n. (m*n = (0::hypnat)) = (m=0 | n=0)" |
|
78 by transfer (rule mult_is_0) |
|
79 |
|
80 lemma hypnat_diff_is_0_eq [simp]: "!!m n. ((m::hypnat) - n = 0) = (m \<le> n)" |
|
81 by transfer (rule diff_is_0_eq) |
|
82 |
|
83 lemma hypnat_not_less0 [iff]: "!!n. ~ n < (0::hypnat)" |
|
84 by transfer (rule not_less0) |
|
85 |
|
86 lemma hypnat_less_one [iff]: |
|
87 "!!n. (n < (1::hypnat)) = (n=0)" |
|
88 by transfer (rule less_one) |
|
89 |
|
90 lemma hypnat_add_diff_inverse: "!!m n. ~ m<n ==> n+(m-n) = (m::hypnat)" |
|
91 by transfer (rule add_diff_inverse) |
|
92 |
|
93 lemma hypnat_le_add_diff_inverse [simp]: "!!m n. n \<le> m ==> n+(m-n) = (m::hypnat)" |
|
94 by transfer (rule le_add_diff_inverse) |
|
95 |
|
96 lemma hypnat_le_add_diff_inverse2 [simp]: "!!m n. n\<le>m ==> (m-n)+n = (m::hypnat)" |
|
97 by transfer (rule le_add_diff_inverse2) |
|
98 |
|
99 declare hypnat_le_add_diff_inverse2 [OF order_less_imp_le] |
|
100 |
|
101 lemma hypnat_le0 [iff]: "!!n. (0::hypnat) \<le> n" |
|
102 by transfer (rule le0) |
|
103 |
|
104 lemma hypnat_le_add1 [simp]: "!!x n. (x::hypnat) \<le> x + n" |
|
105 by transfer (rule le_add1) |
|
106 |
|
107 lemma hypnat_add_self_le [simp]: "!!x n. (x::hypnat) \<le> n + x" |
|
108 by transfer (rule le_add2) |
|
109 |
|
110 lemma hypnat_add_one_self_less [simp]: "(x::hypnat) < x + (1::hypnat)" |
|
111 by (fact less_add_one) |
|
112 |
|
113 lemma hypnat_neq0_conv [iff]: "!!n. (n \<noteq> 0) = (0 < (n::hypnat))" |
|
114 by transfer (rule neq0_conv) |
|
115 |
|
116 lemma hypnat_gt_zero_iff: "((0::hypnat) < n) = ((1::hypnat) \<le> n)" |
|
117 by (auto simp add: linorder_not_less [symmetric]) |
|
118 |
|
119 lemma hypnat_gt_zero_iff2: "(0 < n) = (\<exists>m. n = m + (1::hypnat))" |
|
120 by (auto intro!: add_nonneg_pos exI[of _ "n - 1"] simp: hypnat_gt_zero_iff) |
|
121 |
|
122 lemma hypnat_add_self_not_less: "~ (x + y < (x::hypnat))" |
|
123 by (simp add: linorder_not_le [symmetric] add.commute [of x]) |
|
124 |
|
125 lemma hypnat_diff_split: |
|
126 "P(a - b::hypnat) = ((a<b --> P 0) & (ALL d. a = b + d --> P d))" |
|
127 \<comment> \<open>elimination of \<open>-\<close> on \<open>hypnat\<close>\<close> |
|
128 proof (cases "a<b" rule: case_split) |
|
129 case True |
|
130 thus ?thesis |
|
131 by (auto simp add: hypnat_add_self_not_less order_less_imp_le |
|
132 hypnat_diff_is_0_eq [THEN iffD2]) |
|
133 next |
|
134 case False |
|
135 thus ?thesis |
|
136 by (auto simp add: linorder_not_less dest: order_le_less_trans) |
|
137 qed |
|
138 |
|
139 subsection\<open>Properties of the set of embedded natural numbers\<close> |
|
140 |
|
141 lemma of_nat_eq_star_of [simp]: "of_nat = star_of" |
|
142 proof |
|
143 fix n :: nat |
|
144 show "of_nat n = star_of n" by transfer simp |
|
145 qed |
|
146 |
|
147 lemma Nats_eq_Standard: "(Nats :: nat star set) = Standard" |
|
148 by (auto simp add: Nats_def Standard_def) |
|
149 |
|
150 lemma hypnat_of_nat_mem_Nats [simp]: "hypnat_of_nat n \<in> Nats" |
|
151 by (simp add: Nats_eq_Standard) |
|
152 |
|
153 lemma hypnat_of_nat_one [simp]: "hypnat_of_nat (Suc 0) = (1::hypnat)" |
|
154 by transfer simp |
|
155 |
|
156 lemma hypnat_of_nat_Suc [simp]: |
|
157 "hypnat_of_nat (Suc n) = hypnat_of_nat n + (1::hypnat)" |
|
158 by transfer simp |
|
159 |
|
160 lemma of_nat_eq_add [rule_format]: |
|
161 "\<forall>d::hypnat. of_nat m = of_nat n + d --> d \<in> range of_nat" |
|
162 apply (induct n) |
|
163 apply (auto simp add: add.assoc) |
|
164 apply (case_tac x) |
|
165 apply (auto simp add: add.commute [of 1]) |
|
166 done |
|
167 |
|
168 lemma Nats_diff [simp]: "[|a \<in> Nats; b \<in> Nats|] ==> (a-b :: hypnat) \<in> Nats" |
|
169 by (simp add: Nats_eq_Standard) |
|
170 |
|
171 |
|
172 subsection\<open>Infinite Hypernatural Numbers -- @{term HNatInfinite}\<close> |
|
173 |
|
174 definition |
|
175 (* the set of infinite hypernatural numbers *) |
|
176 HNatInfinite :: "hypnat set" where |
|
177 "HNatInfinite = {n. n \<notin> Nats}" |
|
178 |
|
179 lemma Nats_not_HNatInfinite_iff: "(x \<in> Nats) = (x \<notin> HNatInfinite)" |
|
180 by (simp add: HNatInfinite_def) |
|
181 |
|
182 lemma HNatInfinite_not_Nats_iff: "(x \<in> HNatInfinite) = (x \<notin> Nats)" |
|
183 by (simp add: HNatInfinite_def) |
|
184 |
|
185 lemma star_of_neq_HNatInfinite: "N \<in> HNatInfinite \<Longrightarrow> star_of n \<noteq> N" |
|
186 by (auto simp add: HNatInfinite_def Nats_eq_Standard) |
|
187 |
|
188 lemma star_of_Suc_lessI: |
|
189 "\<And>N. \<lbrakk>star_of n < N; star_of (Suc n) \<noteq> N\<rbrakk> \<Longrightarrow> star_of (Suc n) < N" |
|
190 by transfer (rule Suc_lessI) |
|
191 |
|
192 lemma star_of_less_HNatInfinite: |
|
193 assumes N: "N \<in> HNatInfinite" |
|
194 shows "star_of n < N" |
|
195 proof (induct n) |
|
196 case 0 |
|
197 from N have "star_of 0 \<noteq> N" by (rule star_of_neq_HNatInfinite) |
|
198 thus "star_of 0 < N" by simp |
|
199 next |
|
200 case (Suc n) |
|
201 from N have "star_of (Suc n) \<noteq> N" by (rule star_of_neq_HNatInfinite) |
|
202 with Suc show "star_of (Suc n) < N" by (rule star_of_Suc_lessI) |
|
203 qed |
|
204 |
|
205 lemma star_of_le_HNatInfinite: "N \<in> HNatInfinite \<Longrightarrow> star_of n \<le> N" |
|
206 by (rule star_of_less_HNatInfinite [THEN order_less_imp_le]) |
|
207 |
|
208 subsubsection \<open>Closure Rules\<close> |
|
209 |
|
210 lemma Nats_less_HNatInfinite: "\<lbrakk>x \<in> Nats; y \<in> HNatInfinite\<rbrakk> \<Longrightarrow> x < y" |
|
211 by (auto simp add: Nats_def star_of_less_HNatInfinite) |
|
212 |
|
213 lemma Nats_le_HNatInfinite: "\<lbrakk>x \<in> Nats; y \<in> HNatInfinite\<rbrakk> \<Longrightarrow> x \<le> y" |
|
214 by (rule Nats_less_HNatInfinite [THEN order_less_imp_le]) |
|
215 |
|
216 lemma zero_less_HNatInfinite: "x \<in> HNatInfinite \<Longrightarrow> 0 < x" |
|
217 by (simp add: Nats_less_HNatInfinite) |
|
218 |
|
219 lemma one_less_HNatInfinite: "x \<in> HNatInfinite \<Longrightarrow> 1 < x" |
|
220 by (simp add: Nats_less_HNatInfinite) |
|
221 |
|
222 lemma one_le_HNatInfinite: "x \<in> HNatInfinite \<Longrightarrow> 1 \<le> x" |
|
223 by (simp add: Nats_le_HNatInfinite) |
|
224 |
|
225 lemma zero_not_mem_HNatInfinite [simp]: "0 \<notin> HNatInfinite" |
|
226 by (simp add: HNatInfinite_def) |
|
227 |
|
228 lemma Nats_downward_closed: |
|
229 "\<lbrakk>x \<in> Nats; (y::hypnat) \<le> x\<rbrakk> \<Longrightarrow> y \<in> Nats" |
|
230 apply (simp only: linorder_not_less [symmetric]) |
|
231 apply (erule contrapos_np) |
|
232 apply (drule HNatInfinite_not_Nats_iff [THEN iffD2]) |
|
233 apply (erule (1) Nats_less_HNatInfinite) |
|
234 done |
|
235 |
|
236 lemma HNatInfinite_upward_closed: |
|
237 "\<lbrakk>x \<in> HNatInfinite; x \<le> y\<rbrakk> \<Longrightarrow> y \<in> HNatInfinite" |
|
238 apply (simp only: HNatInfinite_not_Nats_iff) |
|
239 apply (erule contrapos_nn) |
|
240 apply (erule (1) Nats_downward_closed) |
|
241 done |
|
242 |
|
243 lemma HNatInfinite_add: "x \<in> HNatInfinite \<Longrightarrow> x + y \<in> HNatInfinite" |
|
244 apply (erule HNatInfinite_upward_closed) |
|
245 apply (rule hypnat_le_add1) |
|
246 done |
|
247 |
|
248 lemma HNatInfinite_add_one: "x \<in> HNatInfinite \<Longrightarrow> x + 1 \<in> HNatInfinite" |
|
249 by (rule HNatInfinite_add) |
|
250 |
|
251 lemma HNatInfinite_diff: |
|
252 "\<lbrakk>x \<in> HNatInfinite; y \<in> Nats\<rbrakk> \<Longrightarrow> x - y \<in> HNatInfinite" |
|
253 apply (frule (1) Nats_le_HNatInfinite) |
|
254 apply (simp only: HNatInfinite_not_Nats_iff) |
|
255 apply (erule contrapos_nn) |
|
256 apply (drule (1) Nats_add, simp) |
|
257 done |
|
258 |
|
259 lemma HNatInfinite_is_Suc: "x \<in> HNatInfinite ==> \<exists>y. x = y + (1::hypnat)" |
|
260 apply (rule_tac x = "x - (1::hypnat) " in exI) |
|
261 apply (simp add: Nats_le_HNatInfinite) |
|
262 done |
|
263 |
|
264 |
|
265 subsection\<open>Existence of an infinite hypernatural number\<close> |
|
266 |
|
267 definition |
|
268 (* \<omega> is in fact an infinite hypernatural number = [<1,2,3,...>] *) |
|
269 whn :: hypnat where |
|
270 hypnat_omega_def: "whn = star_n (%n::nat. n)" |
|
271 |
|
272 lemma hypnat_of_nat_neq_whn: "hypnat_of_nat n \<noteq> whn" |
|
273 by (simp add: FreeUltrafilterNat.singleton' hypnat_omega_def star_of_def star_n_eq_iff) |
|
274 |
|
275 lemma whn_neq_hypnat_of_nat: "whn \<noteq> hypnat_of_nat n" |
|
276 by (simp add: FreeUltrafilterNat.singleton hypnat_omega_def star_of_def star_n_eq_iff) |
|
277 |
|
278 lemma whn_not_Nats [simp]: "whn \<notin> Nats" |
|
279 by (simp add: Nats_def image_def whn_neq_hypnat_of_nat) |
|
280 |
|
281 lemma HNatInfinite_whn [simp]: "whn \<in> HNatInfinite" |
|
282 by (simp add: HNatInfinite_def) |
|
283 |
|
284 lemma lemma_unbounded_set [simp]: "eventually (\<lambda>n::nat. m < n) \<U>" |
|
285 by (rule filter_leD[OF FreeUltrafilterNat.le_cofinite]) |
|
286 (auto simp add: cofinite_eq_sequentially eventually_at_top_dense) |
|
287 |
|
288 lemma hypnat_of_nat_eq: |
|
289 "hypnat_of_nat m = star_n (%n::nat. m)" |
|
290 by (simp add: star_of_def) |
|
291 |
|
292 lemma SHNat_eq: "Nats = {n. \<exists>N. n = hypnat_of_nat N}" |
|
293 by (simp add: Nats_def image_def) |
|
294 |
|
295 lemma Nats_less_whn: "n \<in> Nats \<Longrightarrow> n < whn" |
|
296 by (simp add: Nats_less_HNatInfinite) |
|
297 |
|
298 lemma Nats_le_whn: "n \<in> Nats \<Longrightarrow> n \<le> whn" |
|
299 by (simp add: Nats_le_HNatInfinite) |
|
300 |
|
301 lemma hypnat_of_nat_less_whn [simp]: "hypnat_of_nat n < whn" |
|
302 by (simp add: Nats_less_whn) |
|
303 |
|
304 lemma hypnat_of_nat_le_whn [simp]: "hypnat_of_nat n \<le> whn" |
|
305 by (simp add: Nats_le_whn) |
|
306 |
|
307 lemma hypnat_zero_less_hypnat_omega [simp]: "0 < whn" |
|
308 by (simp add: Nats_less_whn) |
|
309 |
|
310 lemma hypnat_one_less_hypnat_omega [simp]: "1 < whn" |
|
311 by (simp add: Nats_less_whn) |
|
312 |
|
313 |
|
314 subsubsection\<open>Alternative characterization of the set of infinite hypernaturals\<close> |
|
315 |
|
316 text\<open>@{term "HNatInfinite = {N. \<forall>n \<in> Nats. n < N}"}\<close> |
|
317 |
|
318 (*??delete? similar reasoning in hypnat_omega_gt_SHNat above*) |
|
319 lemma HNatInfinite_FreeUltrafilterNat_lemma: |
|
320 assumes "\<forall>N::nat. eventually (\<lambda>n. f n \<noteq> N) \<U>" |
|
321 shows "eventually (\<lambda>n. N < f n) \<U>" |
|
322 apply (induct N) |
|
323 using assms |
|
324 apply (drule_tac x = 0 in spec, simp) |
|
325 using assms |
|
326 apply (drule_tac x = "Suc N" in spec) |
|
327 apply (auto elim: eventually_elim2) |
|
328 done |
|
329 |
|
330 lemma HNatInfinite_iff: "HNatInfinite = {N. \<forall>n \<in> Nats. n < N}" |
|
331 apply (safe intro!: Nats_less_HNatInfinite) |
|
332 apply (auto simp add: HNatInfinite_def) |
|
333 done |
|
334 |
|
335 |
|
336 subsubsection\<open>Alternative Characterization of @{term HNatInfinite} using |
|
337 Free Ultrafilter\<close> |
|
338 |
|
339 lemma HNatInfinite_FreeUltrafilterNat: |
|
340 "star_n X \<in> HNatInfinite ==> \<forall>u. eventually (\<lambda>n. u < X n) FreeUltrafilterNat" |
|
341 apply (auto simp add: HNatInfinite_iff SHNat_eq) |
|
342 apply (drule_tac x="star_of u" in spec, simp) |
|
343 apply (simp add: star_of_def star_less_def starP2_star_n) |
|
344 done |
|
345 |
|
346 lemma FreeUltrafilterNat_HNatInfinite: |
|
347 "\<forall>u. eventually (\<lambda>n. u < X n) FreeUltrafilterNat ==> star_n X \<in> HNatInfinite" |
|
348 by (auto simp add: star_less_def starP2_star_n HNatInfinite_iff SHNat_eq hypnat_of_nat_eq) |
|
349 |
|
350 lemma HNatInfinite_FreeUltrafilterNat_iff: |
|
351 "(star_n X \<in> HNatInfinite) = (\<forall>u. eventually (\<lambda>n. u < X n) FreeUltrafilterNat)" |
|
352 by (rule iffI [OF HNatInfinite_FreeUltrafilterNat |
|
353 FreeUltrafilterNat_HNatInfinite]) |
|
354 |
|
355 subsection \<open>Embedding of the Hypernaturals into other types\<close> |
|
356 |
|
357 definition |
|
358 of_hypnat :: "hypnat \<Rightarrow> 'a::semiring_1_cancel star" where |
|
359 of_hypnat_def [transfer_unfold]: "of_hypnat = *f* of_nat" |
|
360 |
|
361 lemma of_hypnat_0 [simp]: "of_hypnat 0 = 0" |
|
362 by transfer (rule of_nat_0) |
|
363 |
|
364 lemma of_hypnat_1 [simp]: "of_hypnat 1 = 1" |
|
365 by transfer (rule of_nat_1) |
|
366 |
|
367 lemma of_hypnat_hSuc: "\<And>m. of_hypnat (hSuc m) = 1 + of_hypnat m" |
|
368 by transfer (rule of_nat_Suc) |
|
369 |
|
370 lemma of_hypnat_add [simp]: |
|
371 "\<And>m n. of_hypnat (m + n) = of_hypnat m + of_hypnat n" |
|
372 by transfer (rule of_nat_add) |
|
373 |
|
374 lemma of_hypnat_mult [simp]: |
|
375 "\<And>m n. of_hypnat (m * n) = of_hypnat m * of_hypnat n" |
|
376 by transfer (rule of_nat_mult) |
|
377 |
|
378 lemma of_hypnat_less_iff [simp]: |
|
379 "\<And>m n. (of_hypnat m < (of_hypnat n::'a::linordered_semidom star)) = (m < n)" |
|
380 by transfer (rule of_nat_less_iff) |
|
381 |
|
382 lemma of_hypnat_0_less_iff [simp]: |
|
383 "\<And>n. (0 < (of_hypnat n::'a::linordered_semidom star)) = (0 < n)" |
|
384 by transfer (rule of_nat_0_less_iff) |
|
385 |
|
386 lemma of_hypnat_less_0_iff [simp]: |
|
387 "\<And>m. \<not> (of_hypnat m::'a::linordered_semidom star) < 0" |
|
388 by transfer (rule of_nat_less_0_iff) |
|
389 |
|
390 lemma of_hypnat_le_iff [simp]: |
|
391 "\<And>m n. (of_hypnat m \<le> (of_hypnat n::'a::linordered_semidom star)) = (m \<le> n)" |
|
392 by transfer (rule of_nat_le_iff) |
|
393 |
|
394 lemma of_hypnat_0_le_iff [simp]: |
|
395 "\<And>n. 0 \<le> (of_hypnat n::'a::linordered_semidom star)" |
|
396 by transfer (rule of_nat_0_le_iff) |
|
397 |
|
398 lemma of_hypnat_le_0_iff [simp]: |
|
399 "\<And>m. ((of_hypnat m::'a::linordered_semidom star) \<le> 0) = (m = 0)" |
|
400 by transfer (rule of_nat_le_0_iff) |
|
401 |
|
402 lemma of_hypnat_eq_iff [simp]: |
|
403 "\<And>m n. (of_hypnat m = (of_hypnat n::'a::linordered_semidom star)) = (m = n)" |
|
404 by transfer (rule of_nat_eq_iff) |
|
405 |
|
406 lemma of_hypnat_eq_0_iff [simp]: |
|
407 "\<And>m. ((of_hypnat m::'a::linordered_semidom star) = 0) = (m = 0)" |
|
408 by transfer (rule of_nat_eq_0_iff) |
|
409 |
|
410 lemma HNatInfinite_of_hypnat_gt_zero: |
|
411 "N \<in> HNatInfinite \<Longrightarrow> (0::'a::linordered_semidom star) < of_hypnat N" |
|
412 by (rule ccontr, simp add: linorder_not_less) |
|
413 |
|
414 end |
|