src/HOL/Hyperreal/HyperNat.thy
author wenzelm
Fri Nov 17 02:20:03 2006 +0100 (2006-11-17)
changeset 21404 eb85850d3eb7
parent 20740 5a103b43da5a
child 21787 9edd495b6330
permissions -rw-r--r--
more robust syntax for definition/abbreviation/notation;
     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 header{*Hypernatural numbers*}
     9 
    10 theory HyperNat
    11 imports Star
    12 begin
    13 
    14 types hypnat = "nat star"
    15 
    16 abbreviation
    17   hypnat_of_nat :: "nat => nat star" where
    18   "hypnat_of_nat == star_of"
    19 
    20 subsection{*Properties Transferred from Naturals*}
    21 
    22 lemma hypnat_minus_zero [simp]: "!!z. z - z = (0::hypnat)"
    23 by transfer (rule diff_self_eq_0)
    24 
    25 lemma hypnat_diff_0_eq_0 [simp]: "!!n. (0::hypnat) - n = 0"
    26 by transfer (rule diff_0_eq_0)
    27 
    28 lemma hypnat_add_is_0 [iff]: "!!m n. (m+n = (0::hypnat)) = (m=0 & n=0)"
    29 by transfer (rule add_is_0)
    30 
    31 lemma hypnat_diff_diff_left: "!!i j k. (i::hypnat) - j - k = i - (j+k)"
    32 by transfer (rule diff_diff_left)
    33 
    34 lemma hypnat_diff_commute: "!!i j k. (i::hypnat) - j - k = i-k-j"
    35 by transfer (rule diff_commute)
    36 
    37 lemma hypnat_diff_add_inverse [simp]: "!!m n. ((n::hypnat) + m) - n = m"
    38 by transfer (rule diff_add_inverse)
    39 
    40 lemma hypnat_diff_add_inverse2 [simp]:  "!!m n. ((m::hypnat) + n) - n = m"
    41 by transfer (rule diff_add_inverse2)
    42 
    43 lemma hypnat_diff_cancel [simp]: "!!k m n. ((k::hypnat) + m) - (k+n) = m - n"
    44 by transfer (rule diff_cancel)
    45 
    46 lemma hypnat_diff_cancel2 [simp]: "!!k m n. ((m::hypnat) + k) - (n+k) = m - n"
    47 by transfer (rule diff_cancel2)
    48 
    49 lemma hypnat_diff_add_0 [simp]: "!!m n. (n::hypnat) - (n+m) = (0::hypnat)"
    50 by transfer (rule diff_add_0)
    51 
    52 lemma hypnat_diff_mult_distrib: "!!k m n. ((m::hypnat) - n) * k = (m * k) - (n * k)"
    53 by transfer (rule diff_mult_distrib)
    54 
    55 lemma hypnat_diff_mult_distrib2: "!!k m n. (k::hypnat) * (m - n) = (k * m) - (k * n)"
    56 by transfer (rule diff_mult_distrib2)
    57 
    58 lemma hypnat_le_zero_cancel [iff]: "!!n. (n \<le> (0::hypnat)) = (n = 0)"
    59 by transfer (rule le_0_eq)
    60 
    61 lemma hypnat_mult_is_0 [simp]: "!!m n. (m*n = (0::hypnat)) = (m=0 | n=0)"
    62 by transfer (rule mult_is_0)
    63 
    64 lemma hypnat_diff_is_0_eq [simp]: "!!m n. ((m::hypnat) - n = 0) = (m \<le> n)"
    65 by transfer (rule diff_is_0_eq)
    66 
    67 lemma hypnat_not_less0 [iff]: "!!n. ~ n < (0::hypnat)"
    68 by transfer (rule not_less0)
    69 
    70 lemma hypnat_less_one [iff]:
    71       "!!n. (n < (1::hypnat)) = (n=0)"
    72 by transfer (rule less_one)
    73 
    74 lemma hypnat_add_diff_inverse: "!!m n. ~ m<n ==> n+(m-n) = (m::hypnat)"
    75 by transfer (rule add_diff_inverse)
    76 
    77 lemma hypnat_le_add_diff_inverse [simp]: "!!m n. n \<le> m ==> n+(m-n) = (m::hypnat)"
    78 by transfer (rule le_add_diff_inverse)
    79 
    80 lemma hypnat_le_add_diff_inverse2 [simp]: "!!m n. n\<le>m ==> (m-n)+n = (m::hypnat)"
    81 by transfer (rule le_add_diff_inverse2)
    82 
    83 declare hypnat_le_add_diff_inverse2 [OF order_less_imp_le]
    84 
    85 lemma hypnat_le0 [iff]: "!!n. (0::hypnat) \<le> n"
    86 by transfer (rule le0)
    87 
    88 lemma hypnat_le_add1 [simp]: "!!x n. (x::hypnat) \<le> x + n"
    89 by transfer (rule le_add1)
    90 
    91 lemma hypnat_add_self_le [simp]: "!!x n. (x::hypnat) \<le> n + x"
    92 by transfer (rule le_add2)
    93 
    94 lemma hypnat_add_one_self_less [simp]: "(x::hypnat) < x + (1::hypnat)"
    95 by (insert add_strict_left_mono [OF zero_less_one], auto)
    96 
    97 lemma hypnat_neq0_conv [iff]: "!!n. (n \<noteq> 0) = (0 < (n::hypnat))"
    98 by transfer (rule neq0_conv)
    99 
   100 lemma hypnat_gt_zero_iff: "((0::hypnat) < n) = ((1::hypnat) \<le> n)"
   101 by (auto simp add: linorder_not_less [symmetric])
   102 
   103 lemma hypnat_gt_zero_iff2: "(0 < n) = (\<exists>m. n = m + (1::hypnat))"
   104 apply safe
   105  apply (rule_tac x = "n - (1::hypnat) " in exI)
   106  apply (simp add: hypnat_gt_zero_iff) 
   107 apply (insert add_le_less_mono [OF _ zero_less_one, of 0], auto) 
   108 done
   109 
   110 lemma hypnat_add_self_not_less: "~ (x + y < (x::hypnat))"
   111 by (simp add: linorder_not_le [symmetric] add_commute [of x]) 
   112 
   113 lemma hypnat_diff_split:
   114     "P(a - b::hypnat) = ((a<b --> P 0) & (ALL d. a = b + d --> P d))"
   115     -- {* elimination of @{text -} on @{text hypnat} *}
   116 proof (cases "a<b" rule: case_split)
   117   case True
   118     thus ?thesis
   119       by (auto simp add: hypnat_add_self_not_less order_less_imp_le 
   120                          hypnat_diff_is_0_eq [THEN iffD2])
   121 next
   122   case False
   123     thus ?thesis
   124       by (auto simp add: linorder_not_less dest: order_le_less_trans) 
   125 qed
   126 
   127 subsection{*Properties of the set of embedded natural numbers*}
   128 
   129 lemma of_nat_eq_star_of [simp]: "of_nat = star_of"
   130 proof
   131   fix n :: nat
   132   show "of_nat n = star_of n" by transfer simp
   133 qed
   134 
   135 lemma Nats_eq_Standard: "(Nats :: nat star set) = Standard"
   136 by (auto simp add: Nats_def Standard_def)
   137 
   138 lemma hypnat_of_nat_mem_Nats [simp]: "hypnat_of_nat n \<in> Nats"
   139 by (simp add: Nats_eq_Standard)
   140 
   141 lemma hypnat_of_nat_one [simp]: "hypnat_of_nat (Suc 0) = (1::hypnat)"
   142 by transfer simp
   143 
   144 lemma hypnat_of_nat_Suc [simp]:
   145      "hypnat_of_nat (Suc n) = hypnat_of_nat n + (1::hypnat)"
   146 by transfer simp
   147 
   148 lemma of_nat_eq_add [rule_format]:
   149      "\<forall>d::hypnat. of_nat m = of_nat n + d --> d \<in> range of_nat"
   150 apply (induct n) 
   151 apply (auto simp add: add_assoc) 
   152 apply (case_tac x) 
   153 apply (auto simp add: add_commute [of 1]) 
   154 done
   155 
   156 lemma Nats_diff [simp]: "[|a \<in> Nats; b \<in> Nats|] ==> (a-b :: hypnat) \<in> Nats"
   157 by (simp add: Nats_eq_Standard)
   158 
   159 
   160 subsection{*Infinite Hypernatural Numbers -- @{term HNatInfinite}*}
   161 
   162 definition
   163   (* the set of infinite hypernatural numbers *)
   164   HNatInfinite :: "hypnat set" where
   165   "HNatInfinite = {n. n \<notin> Nats}"
   166 
   167 lemma Nats_not_HNatInfinite_iff: "(x \<in> Nats) = (x \<notin> HNatInfinite)"
   168 by (simp add: HNatInfinite_def)
   169 
   170 lemma HNatInfinite_not_Nats_iff: "(x \<in> HNatInfinite) = (x \<notin> Nats)"
   171 by (simp add: HNatInfinite_def)
   172 
   173 lemma star_of_neq_HNatInfinite: "N \<in> HNatInfinite \<Longrightarrow> star_of n \<noteq> N"
   174 by (auto simp add: HNatInfinite_def Nats_eq_Standard)
   175 
   176 lemma star_of_Suc_lessI:
   177   "\<And>N. \<lbrakk>star_of n < N; star_of (Suc n) \<noteq> N\<rbrakk> \<Longrightarrow> star_of (Suc n) < N"
   178 by transfer (rule Suc_lessI)
   179 
   180 lemma star_of_less_HNatInfinite:
   181   assumes N: "N \<in> HNatInfinite"
   182   shows "star_of n < N"
   183 proof (induct n)
   184   case 0
   185   from N have "star_of 0 \<noteq> N" by (rule star_of_neq_HNatInfinite)
   186   thus "star_of 0 < N" by simp
   187 next
   188   case (Suc n)
   189   from N have "star_of (Suc n) \<noteq> N" by (rule star_of_neq_HNatInfinite)
   190   with Suc show "star_of (Suc n) < N" by (rule star_of_Suc_lessI)
   191 qed
   192 
   193 lemma star_of_le_HNatInfinite: "N \<in> HNatInfinite \<Longrightarrow> star_of n \<le> N"
   194 by (rule star_of_less_HNatInfinite [THEN order_less_imp_le])
   195 
   196 subsubsection {* Closure Rules *}
   197 
   198 lemma Nats_less_HNatInfinite: "\<lbrakk>x \<in> Nats; y \<in> HNatInfinite\<rbrakk> \<Longrightarrow> x < y"
   199 by (auto simp add: Nats_def star_of_less_HNatInfinite)
   200 
   201 lemma Nats_le_HNatInfinite: "\<lbrakk>x \<in> Nats; y \<in> HNatInfinite\<rbrakk> \<Longrightarrow> x \<le> y"
   202 by (rule Nats_less_HNatInfinite [THEN order_less_imp_le])
   203 
   204 lemma zero_less_HNatInfinite: "x \<in> HNatInfinite \<Longrightarrow> 0 < x"
   205 by (simp add: Nats_less_HNatInfinite)
   206 
   207 lemma one_less_HNatInfinite: "x \<in> HNatInfinite \<Longrightarrow> 1 < x"
   208 by (simp add: Nats_less_HNatInfinite)
   209 
   210 lemma one_le_HNatInfinite: "x \<in> HNatInfinite \<Longrightarrow> 1 \<le> x"
   211 by (simp add: Nats_le_HNatInfinite)
   212 
   213 lemma zero_not_mem_HNatInfinite [simp]: "0 \<notin> HNatInfinite"
   214 by (simp add: HNatInfinite_def)
   215 
   216 lemma Nats_downward_closed:
   217   "\<lbrakk>x \<in> Nats; (y::hypnat) \<le> x\<rbrakk> \<Longrightarrow> y \<in> Nats"
   218 apply (simp only: linorder_not_less [symmetric])
   219 apply (erule contrapos_np)
   220 apply (drule HNatInfinite_not_Nats_iff [THEN iffD2])
   221 apply (erule (1) Nats_less_HNatInfinite)
   222 done
   223 
   224 lemma HNatInfinite_upward_closed:
   225   "\<lbrakk>x \<in> HNatInfinite; x \<le> y\<rbrakk> \<Longrightarrow> y \<in> HNatInfinite"
   226 apply (simp only: HNatInfinite_not_Nats_iff)
   227 apply (erule contrapos_nn)
   228 apply (erule (1) Nats_downward_closed)
   229 done
   230 
   231 lemma HNatInfinite_add: "x \<in> HNatInfinite \<Longrightarrow> x + y \<in> HNatInfinite"
   232 apply (erule HNatInfinite_upward_closed)
   233 apply (rule hypnat_le_add1)
   234 done
   235 
   236 lemma HNatInfinite_add_one: "x \<in> HNatInfinite \<Longrightarrow> x + 1 \<in> HNatInfinite"
   237 by (rule HNatInfinite_add)
   238 
   239 lemma HNatInfinite_diff:
   240   "\<lbrakk>x \<in> HNatInfinite; y \<in> Nats\<rbrakk> \<Longrightarrow> x - y \<in> HNatInfinite"
   241 apply (frule (1) Nats_le_HNatInfinite)
   242 apply (simp only: HNatInfinite_not_Nats_iff)
   243 apply (erule contrapos_nn)
   244 apply (drule (1) Nats_add, simp)
   245 done
   246 
   247 lemma HNatInfinite_is_Suc: "x \<in> HNatInfinite ==> \<exists>y. x = y + (1::hypnat)"
   248 apply (rule_tac x = "x - (1::hypnat) " in exI)
   249 apply (simp add: Nats_le_HNatInfinite)
   250 done
   251 
   252 
   253 subsection{*Existence of an infinite hypernatural number*}
   254 
   255 definition
   256   (* omega is in fact an infinite hypernatural number = [<1,2,3,...>] *)
   257   whn :: hypnat where
   258   hypnat_omega_def: "whn = star_n (%n::nat. n)"
   259 
   260 lemma hypnat_of_nat_neq_whn: "hypnat_of_nat n \<noteq> whn"
   261 by (simp add: hypnat_omega_def star_of_def star_n_eq_iff FUFNat.finite)
   262 
   263 lemma whn_neq_hypnat_of_nat: "whn \<noteq> hypnat_of_nat n"
   264 by (simp add: hypnat_omega_def star_of_def star_n_eq_iff FUFNat.finite)
   265 
   266 lemma whn_not_Nats [simp]: "whn \<notin> Nats"
   267 by (simp add: Nats_def image_def whn_neq_hypnat_of_nat)
   268 
   269 lemma HNatInfinite_whn [simp]: "whn \<in> HNatInfinite"
   270 by (simp add: HNatInfinite_def)
   271 
   272 text{* Example of an hypersequence (i.e. an extended standard sequence)
   273    whose term with an hypernatural suffix is an infinitesimal i.e.
   274    the whn'nth term of the hypersequence is a member of Infinitesimal*}
   275 
   276 lemma SEQ_Infinitesimal:
   277       "( *f* (%n::nat. inverse(real(Suc n)))) whn : Infinitesimal"
   278 apply (simp add: hypnat_omega_def starfun star_n_inverse)
   279 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff)
   280 apply (simp add: real_of_nat_Suc_gt_zero FreeUltrafilterNat_inverse_real_of_posnat)
   281 done
   282 
   283 lemma lemma_unbounded_set [simp]: "{n::nat. m < n} \<in> FreeUltrafilterNat"
   284 apply (insert finite_atMost [of m]) 
   285 apply (simp add: atMost_def) 
   286 apply (drule FreeUltrafilterNat_finite)
   287 apply (drule FreeUltrafilterNat_Compl_mem, ultra)
   288 done
   289 
   290 lemma Compl_Collect_le: "- {n::nat. N \<le> n} = {n. n < N}"
   291 by (simp add: Collect_neg_eq [symmetric] linorder_not_le) 
   292 
   293 lemma hypnat_of_nat_eq:
   294      "hypnat_of_nat m  = star_n (%n::nat. m)"
   295 by (simp add: star_of_def)
   296 
   297 lemma SHNat_eq: "Nats = {n. \<exists>N. n = hypnat_of_nat N}"
   298 by (simp add: Nats_def image_def)
   299 
   300 lemma Nats_less_whn: "n \<in> Nats \<Longrightarrow> n < whn"
   301 by (simp add: Nats_less_HNatInfinite)
   302 
   303 lemma Nats_le_whn: "n \<in> Nats \<Longrightarrow> n \<le> whn"
   304 by (simp add: Nats_le_HNatInfinite)
   305 
   306 lemma hypnat_of_nat_less_whn [simp]: "hypnat_of_nat n < whn"
   307 by (simp add: Nats_less_whn)
   308 
   309 lemma hypnat_of_nat_le_whn [simp]: "hypnat_of_nat n \<le> whn"
   310 by (simp add: Nats_le_whn)
   311 
   312 lemma hypnat_zero_less_hypnat_omega [simp]: "0 < whn"
   313 by (simp add: Nats_less_whn)
   314 
   315 lemma hypnat_one_less_hypnat_omega [simp]: "1 < whn"
   316 by (simp add: Nats_less_whn)
   317 
   318 
   319 subsubsection{*Alternative characterization of the set of infinite hypernaturals*}
   320 
   321 text{* @{term "HNatInfinite = {N. \<forall>n \<in> Nats. n < N}"}*}
   322 
   323 (*??delete? similar reasoning in hypnat_omega_gt_SHNat above*)
   324 lemma HNatInfinite_FreeUltrafilterNat_lemma:
   325      "\<forall>N::nat. {n. f n \<noteq> N} \<in> FreeUltrafilterNat
   326       ==> {n. N < f n} \<in> FreeUltrafilterNat"
   327 apply (induct_tac N)
   328 apply (drule_tac x = 0 in spec)
   329 apply (rule ccontr, drule FreeUltrafilterNat_Compl_mem, drule FreeUltrafilterNat_Int, assumption, simp)
   330 apply (drule_tac x = "Suc n" in spec, ultra)
   331 done
   332 
   333 lemma HNatInfinite_iff: "HNatInfinite = {N. \<forall>n \<in> Nats. n < N}"
   334 apply (auto simp add: HNatInfinite_def SHNat_eq hypnat_of_nat_eq)
   335 apply (rule_tac x = x in star_cases)
   336 apply (auto elim: HNatInfinite_FreeUltrafilterNat_lemma 
   337             simp add: star_n_less FreeUltrafilterNat_Compl_iff1
   338                       star_n_eq_iff Collect_neg_eq [symmetric])
   339 done
   340 
   341 
   342 subsubsection{*Alternative Characterization of @{term HNatInfinite} using 
   343 Free Ultrafilter*}
   344 
   345 lemma HNatInfinite_FreeUltrafilterNat:
   346      "star_n X \<in> HNatInfinite ==> \<forall>u. {n. u < X n}:  FreeUltrafilterNat"
   347 apply (auto simp add: HNatInfinite_iff SHNat_eq)
   348 apply (drule_tac x="star_of u" in spec, simp)
   349 apply (simp add: star_of_def star_n_less)
   350 done
   351 
   352 lemma FreeUltrafilterNat_HNatInfinite:
   353      "\<forall>u. {n. u < X n}:  FreeUltrafilterNat ==> star_n X \<in> HNatInfinite"
   354 by (auto simp add: star_n_less HNatInfinite_iff SHNat_eq hypnat_of_nat_eq)
   355 
   356 lemma HNatInfinite_FreeUltrafilterNat_iff:
   357      "(star_n X \<in> HNatInfinite) = (\<forall>u. {n. u < X n}:  FreeUltrafilterNat)"
   358 by (rule iffI [OF HNatInfinite_FreeUltrafilterNat 
   359                  FreeUltrafilterNat_HNatInfinite])
   360 
   361 subsection{*Embedding of the Hypernaturals into the Hyperreals*}
   362 text{*Obtained using the nonstandard extension of the naturals*}
   363 
   364 definition
   365   hypreal_of_hypnat :: "hypnat => hypreal" where
   366   "hypreal_of_hypnat = *f* real"
   367 
   368 declare hypreal_of_hypnat_def [transfer_unfold]
   369 
   370 lemma hypreal_of_hypnat:
   371       "hypreal_of_hypnat (star_n X) = star_n (%n. real (X n))"
   372 by (simp add: hypreal_of_hypnat_def starfun)
   373 
   374 lemma hypreal_of_hypnat_inject [simp]:
   375      "!!m n. (hypreal_of_hypnat m = hypreal_of_hypnat n) = (m=n)"
   376 by (transfer, simp)
   377 
   378 lemma hypreal_of_hypnat_zero: "hypreal_of_hypnat 0 = 0"
   379 by (simp add: star_n_zero_num hypreal_of_hypnat)
   380 
   381 lemma hypreal_of_hypnat_one: "hypreal_of_hypnat (1::hypnat) = 1"
   382 by (simp add: star_n_one_num hypreal_of_hypnat)
   383 
   384 lemma hypreal_of_hypnat_add [simp]:
   385      "!!m n. hypreal_of_hypnat (m + n) = hypreal_of_hypnat m + hypreal_of_hypnat n"
   386 by (transfer, rule real_of_nat_add)
   387 
   388 lemma hypreal_of_hypnat_mult [simp]:
   389      "!!m n. hypreal_of_hypnat (m * n) = hypreal_of_hypnat m * hypreal_of_hypnat n"
   390 by (transfer, rule real_of_nat_mult)
   391 
   392 lemma hypreal_of_hypnat_less_iff [simp]:
   393      "!!m n. (hypreal_of_hypnat n < hypreal_of_hypnat m) = (n < m)"
   394 by (transfer, simp)
   395 
   396 lemma hypreal_of_hypnat_eq_zero_iff: "(hypreal_of_hypnat N = 0) = (N = 0)"
   397 by (simp add: hypreal_of_hypnat_zero [symmetric])
   398 declare hypreal_of_hypnat_eq_zero_iff [simp]
   399 
   400 lemma hypreal_of_hypnat_ge_zero [simp]: "!!n. 0 \<le> hypreal_of_hypnat n"
   401 by (transfer, simp)
   402 
   403 lemma HNatInfinite_inverse_Infinitesimal [simp]:
   404      "n \<in> HNatInfinite ==> inverse (hypreal_of_hypnat n) \<in> Infinitesimal"
   405 apply (cases n)
   406 apply (auto simp add: hypreal_of_hypnat star_n_inverse real_norm_def
   407       HNatInfinite_FreeUltrafilterNat_iff
   408       Infinitesimal_FreeUltrafilterNat_iff2)
   409 apply (drule_tac x="Suc m" in spec)
   410 apply (erule ultra, simp)
   411 done
   412 
   413 lemma HNatInfinite_hypreal_of_hypnat_gt_zero:
   414      "N \<in> HNatInfinite ==> 0 < hypreal_of_hypnat N"
   415 apply (rule ccontr)
   416 apply (simp add: hypreal_of_hypnat_zero [symmetric] linorder_not_less)
   417 done
   418 
   419 end