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