src/HOL/Hyperreal/HyperDef.thy
author wenzelm
Sun Jul 11 20:33:22 2004 +0200 (2004-07-11)
changeset 15032 02aed07e01bf
parent 15013 34264f5e4691
child 15085 5693a977a767
permissions -rw-r--r--
local_cla/simpset_of;
     1 (*  Title       : HOL/Real/Hyperreal/HyperDef.thy
     2     ID          : $Id$
     3     Author      : Jacques D. Fleuriot
     4     Copyright   : 1998  University of Cambridge
     5     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     6 *)
     7 
     8 header{*Construction of Hyperreals Using Ultrafilters*}
     9 
    10 theory HyperDef = Filter + Real
    11 files ("fuf.ML"):  (*Warning: file fuf.ML refers to the name Hyperdef!*)
    12 
    13 
    14 constdefs
    15 
    16   FreeUltrafilterNat   :: "nat set set"    ("\<U>")
    17     "FreeUltrafilterNat == (SOME U. U \<in> FreeUltrafilter (UNIV:: nat set))"
    18 
    19   hyprel :: "((nat=>real)*(nat=>real)) set"
    20     "hyprel == {p. \<exists>X Y. p = ((X::nat=>real),Y) &
    21                    {n::nat. X(n) = Y(n)} \<in> FreeUltrafilterNat}"
    22 
    23 typedef hypreal = "UNIV//hyprel" 
    24     by (auto simp add: quotient_def) 
    25 
    26 instance hypreal :: "{ord, zero, one, plus, times, minus, inverse}" ..
    27 
    28 defs (overloaded)
    29 
    30   hypreal_zero_def:
    31   "0 == Abs_hypreal(hyprel``{%n. 0})"
    32 
    33   hypreal_one_def:
    34   "1 == Abs_hypreal(hyprel``{%n. 1})"
    35 
    36   hypreal_minus_def:
    37   "- P == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). hyprel``{%n. - (X n)})"
    38 
    39   hypreal_diff_def:
    40   "x - y == x + -(y::hypreal)"
    41 
    42   hypreal_inverse_def:
    43   "inverse P == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P).
    44                     hyprel``{%n. if X n = 0 then 0 else inverse (X n)})"
    45 
    46   hypreal_divide_def:
    47   "P / Q::hypreal == P * inverse Q"
    48 
    49 constdefs
    50 
    51   hypreal_of_real  :: "real => hypreal"
    52   "hypreal_of_real r         == Abs_hypreal(hyprel``{%n. r})"
    53 
    54   omega   :: hypreal   -- {*an infinite number @{text "= [<1,2,3,...>]"} *}
    55   "omega == Abs_hypreal(hyprel``{%n. real (Suc n)})"
    56 
    57   epsilon :: hypreal   -- {*an infinitesimal number @{text "= [<1,1/2,1/3,...>]"} *}
    58   "epsilon == Abs_hypreal(hyprel``{%n. inverse (real (Suc n))})"
    59 
    60 syntax (xsymbols)
    61   omega   :: hypreal   ("\<omega>")
    62   epsilon :: hypreal   ("\<epsilon>")
    63 
    64 syntax (HTML output)
    65   omega   :: hypreal   ("\<omega>")
    66   epsilon :: hypreal   ("\<epsilon>")
    67 
    68 
    69 defs (overloaded)
    70 
    71   hypreal_add_def:
    72   "P + Q == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). \<Union>Y \<in> Rep_hypreal(Q).
    73                 hyprel``{%n. X n + Y n})"
    74 
    75   hypreal_mult_def:
    76   "P * Q == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). \<Union>Y \<in> Rep_hypreal(Q).
    77                 hyprel``{%n. X n * Y n})"
    78 
    79   hypreal_le_def:
    80   "P \<le> (Q::hypreal) == \<exists>X Y. X \<in> Rep_hypreal(P) &
    81                                Y \<in> Rep_hypreal(Q) &
    82                                {n. X n \<le> Y n} \<in> FreeUltrafilterNat"
    83 
    84   hypreal_less_def: "(x < (y::hypreal)) == (x \<le> y & x \<noteq> y)"
    85 
    86   hrabs_def:  "abs (r::hypreal) == (if 0 \<le> r then r else -r)"
    87 
    88 
    89 subsection{*The Set of Naturals is not Finite*}
    90 
    91 (*** based on James' proof that the set of naturals is not finite ***)
    92 lemma finite_exhausts [rule_format]:
    93      "finite (A::nat set) --> (\<exists>n. \<forall>m. Suc (n + m) \<notin> A)"
    94 apply (rule impI)
    95 apply (erule_tac F = A in finite_induct)
    96 apply (blast, erule exE)
    97 apply (rule_tac x = "n + x" in exI)
    98 apply (rule allI, erule_tac x = "x + m" in allE)
    99 apply (auto simp add: add_ac)
   100 done
   101 
   102 lemma finite_not_covers [rule_format (no_asm)]:
   103      "finite (A :: nat set) --> (\<exists>n. n \<notin>A)"
   104 by (rule impI, drule finite_exhausts, blast)
   105 
   106 lemma not_finite_nat: "~ finite(UNIV:: nat set)"
   107 by (fast dest!: finite_exhausts)
   108 
   109 
   110 subsection{*Existence of Free Ultrafilter over the Naturals*}
   111 
   112 text{*Also, proof of various properties of @{term FreeUltrafilterNat}: 
   113 an arbitrary free ultrafilter*}
   114 
   115 lemma FreeUltrafilterNat_Ex: "\<exists>U. U \<in> FreeUltrafilter (UNIV::nat set)"
   116 by (rule not_finite_nat [THEN FreeUltrafilter_Ex])
   117 
   118 lemma FreeUltrafilterNat_mem [simp]: 
   119      "FreeUltrafilterNat \<in> FreeUltrafilter(UNIV:: nat set)"
   120 apply (unfold FreeUltrafilterNat_def)
   121 apply (rule FreeUltrafilterNat_Ex [THEN exE])
   122 apply (rule someI2, assumption+)
   123 done
   124 
   125 lemma FreeUltrafilterNat_finite: "finite x ==> x \<notin> FreeUltrafilterNat"
   126 apply (unfold FreeUltrafilterNat_def)
   127 apply (rule FreeUltrafilterNat_Ex [THEN exE])
   128 apply (rule someI2, assumption)
   129 apply (blast dest: mem_FreeUltrafiltersetD1)
   130 done
   131 
   132 lemma FreeUltrafilterNat_not_finite: "x \<in> FreeUltrafilterNat ==> ~ finite x"
   133 by (blast dest: FreeUltrafilterNat_finite)
   134 
   135 lemma FreeUltrafilterNat_empty [simp]: "{} \<notin> FreeUltrafilterNat"
   136 apply (unfold FreeUltrafilterNat_def)
   137 apply (rule FreeUltrafilterNat_Ex [THEN exE])
   138 apply (rule someI2, assumption)
   139 apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter 
   140                    Filter_empty_not_mem)
   141 done
   142 
   143 lemma FreeUltrafilterNat_Int:
   144      "[| X \<in> FreeUltrafilterNat;  Y \<in> FreeUltrafilterNat |]   
   145       ==> X Int Y \<in> FreeUltrafilterNat"
   146 apply (insert FreeUltrafilterNat_mem)
   147 apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter mem_FiltersetD1)
   148 done
   149 
   150 lemma FreeUltrafilterNat_subset:
   151      "[| X \<in> FreeUltrafilterNat;  X \<subseteq> Y |]  
   152       ==> Y \<in> FreeUltrafilterNat"
   153 apply (insert FreeUltrafilterNat_mem)
   154 apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter mem_FiltersetD2)
   155 done
   156 
   157 lemma FreeUltrafilterNat_Compl:
   158      "X \<in> FreeUltrafilterNat ==> -X \<notin> FreeUltrafilterNat"
   159 proof
   160   assume "X \<in> \<U>" and "- X \<in> \<U>"
   161   hence "X Int - X \<in> \<U>" by (rule FreeUltrafilterNat_Int) 
   162   thus False by force
   163 qed
   164 
   165 lemma FreeUltrafilterNat_Compl_mem:
   166      "X\<notin> FreeUltrafilterNat ==> -X \<in> FreeUltrafilterNat"
   167 apply (cut_tac FreeUltrafilterNat_mem [THEN FreeUltrafilter_iff [THEN iffD1]])
   168 apply (safe, drule_tac x = X in bspec)
   169 apply (auto simp add: UNIV_diff_Compl)
   170 done
   171 
   172 lemma FreeUltrafilterNat_Compl_iff1:
   173      "(X \<notin> FreeUltrafilterNat) = (-X \<in> FreeUltrafilterNat)"
   174 by (blast dest: FreeUltrafilterNat_Compl FreeUltrafilterNat_Compl_mem)
   175 
   176 lemma FreeUltrafilterNat_Compl_iff2:
   177      "(X \<in> FreeUltrafilterNat) = (-X \<notin> FreeUltrafilterNat)"
   178 by (auto simp add: FreeUltrafilterNat_Compl_iff1 [symmetric])
   179 
   180 lemma cofinite_mem_FreeUltrafilterNat: "finite (-X) ==> X \<in> FreeUltrafilterNat"
   181 apply (drule FreeUltrafilterNat_finite)  
   182 apply (simp add: FreeUltrafilterNat_Compl_iff2 [symmetric])
   183 done
   184 
   185 lemma FreeUltrafilterNat_UNIV [simp]: "(UNIV::nat set) \<in> FreeUltrafilterNat"
   186 by (rule FreeUltrafilterNat_mem [THEN FreeUltrafilter_Ultrafilter, THEN Ultrafilter_Filter, THEN mem_FiltersetD4])
   187 
   188 lemma FreeUltrafilterNat_Nat_set [simp]: "UNIV \<in> FreeUltrafilterNat"
   189 by auto
   190 
   191 lemma FreeUltrafilterNat_Nat_set_refl [intro]:
   192      "{n. P(n) = P(n)} \<in> FreeUltrafilterNat"
   193 by simp
   194 
   195 lemma FreeUltrafilterNat_P: "{n::nat. P} \<in> FreeUltrafilterNat ==> P"
   196 by (rule ccontr, simp)
   197 
   198 lemma FreeUltrafilterNat_Ex_P: "{n. P(n)} \<in> FreeUltrafilterNat ==> \<exists>n. P(n)"
   199 by (rule ccontr, simp)
   200 
   201 lemma FreeUltrafilterNat_all: "\<forall>n. P(n) ==> {n. P(n)} \<in> FreeUltrafilterNat"
   202 by (auto intro: FreeUltrafilterNat_Nat_set)
   203 
   204 
   205 text{*Define and use Ultrafilter tactics*}
   206 use "fuf.ML"
   207 
   208 method_setup fuf = {*
   209     Method.ctxt_args (fn ctxt =>
   210         Method.METHOD (fn facts =>
   211             fuf_tac (local_clasimpset_of ctxt) 1)) *}
   212     "free ultrafilter tactic"
   213 
   214 method_setup ultra = {*
   215     Method.ctxt_args (fn ctxt =>
   216         Method.METHOD (fn facts =>
   217             ultra_tac (local_clasimpset_of ctxt) 1)) *}
   218     "ultrafilter tactic"
   219 
   220 
   221 text{*One further property of our free ultrafilter*}
   222 lemma FreeUltrafilterNat_Un:
   223      "X Un Y \<in> FreeUltrafilterNat  
   224       ==> X \<in> FreeUltrafilterNat | Y \<in> FreeUltrafilterNat"
   225 by (auto, ultra)
   226 
   227 
   228 subsection{*Properties of @{term hyprel}*}
   229 
   230 text{*Proving that @{term hyprel} is an equivalence relation*}
   231 
   232 lemma hyprel_iff: "((X,Y) \<in> hyprel) = ({n. X n = Y n} \<in> FreeUltrafilterNat)"
   233 by (simp add: hyprel_def)
   234 
   235 lemma hyprel_refl: "(x,x) \<in> hyprel"
   236 by (simp add: hyprel_def)
   237 
   238 lemma hyprel_sym [rule_format (no_asm)]: "(x,y) \<in> hyprel --> (y,x) \<in> hyprel"
   239 by (simp add: hyprel_def eq_commute)
   240 
   241 lemma hyprel_trans: 
   242       "[|(x,y) \<in> hyprel; (y,z) \<in> hyprel|] ==> (x,z) \<in> hyprel"
   243 by (simp add: hyprel_def, ultra)
   244 
   245 lemma equiv_hyprel: "equiv UNIV hyprel"
   246 apply (simp add: equiv_def refl_def sym_def trans_def hyprel_refl)
   247 apply (blast intro: hyprel_sym hyprel_trans) 
   248 done
   249 
   250 (* (hyprel `` {x} = hyprel `` {y}) = ((x,y) \<in> hyprel) *)
   251 lemmas equiv_hyprel_iff =
   252     eq_equiv_class_iff [OF equiv_hyprel UNIV_I UNIV_I, simp] 
   253 
   254 lemma hyprel_in_hypreal [simp]: "hyprel``{x}:hypreal"
   255 by (simp add: hypreal_def hyprel_def quotient_def, blast)
   256 
   257 lemma inj_on_Abs_hypreal: "inj_on Abs_hypreal hypreal"
   258 apply (rule inj_on_inverseI)
   259 apply (erule Abs_hypreal_inverse)
   260 done
   261 
   262 declare inj_on_Abs_hypreal [THEN inj_on_iff, simp] 
   263         Abs_hypreal_inverse [simp]
   264 
   265 declare equiv_hyprel [THEN eq_equiv_class_iff, simp]
   266 
   267 declare hyprel_iff [iff]
   268 
   269 lemmas eq_hyprelD = eq_equiv_class [OF _ equiv_hyprel]
   270 
   271 lemma inj_Rep_hypreal: "inj(Rep_hypreal)"
   272 apply (rule inj_on_inverseI)
   273 apply (rule Rep_hypreal_inverse)
   274 done
   275 
   276 lemma lemma_hyprel_refl [simp]: "x \<in> hyprel `` {x}"
   277 by (simp add: hyprel_def)
   278 
   279 lemma hypreal_empty_not_mem [simp]: "{} \<notin> hypreal"
   280 apply (simp add: hypreal_def)
   281 apply (auto elim!: quotientE equalityCE)
   282 done
   283 
   284 lemma Rep_hypreal_nonempty [simp]: "Rep_hypreal x \<noteq> {}"
   285 by (insert Rep_hypreal [of x], auto)
   286 
   287 
   288 subsection{*@{term hypreal_of_real}: 
   289             the Injection from @{typ real} to @{typ hypreal}*}
   290 
   291 lemma inj_hypreal_of_real: "inj(hypreal_of_real)"
   292 apply (rule inj_onI)
   293 apply (simp add: hypreal_of_real_def split: split_if_asm)
   294 done
   295 
   296 lemma eq_Abs_hypreal:
   297     "(!!x. z = Abs_hypreal(hyprel``{x}) ==> P) ==> P"
   298 apply (rule_tac x1=z in Rep_hypreal [unfolded hypreal_def, THEN quotientE])
   299 apply (drule_tac f = Abs_hypreal in arg_cong)
   300 apply (force simp add: Rep_hypreal_inverse)
   301 done
   302 
   303 theorem hypreal_cases [case_names Abs_hypreal, cases type: hypreal]:
   304     "(!!x. z = Abs_hypreal(hyprel``{x}) ==> P) ==> P"
   305 by (rule eq_Abs_hypreal [of z], blast)
   306 
   307 
   308 subsection{*Hyperreal Addition*}
   309 
   310 lemma hypreal_add_congruent2: 
   311     "congruent2 hyprel hyprel (%X Y. hyprel``{%n. X n + Y n})"
   312 by (simp add: congruent2_def, auto, ultra)
   313 
   314 lemma hypreal_add: 
   315   "Abs_hypreal(hyprel``{%n. X n}) + Abs_hypreal(hyprel``{%n. Y n}) =  
   316    Abs_hypreal(hyprel``{%n. X n + Y n})"
   317 by (simp add: hypreal_add_def 
   318          UN_equiv_class2 [OF equiv_hyprel equiv_hyprel hypreal_add_congruent2])
   319 
   320 lemma hypreal_add_commute: "(z::hypreal) + w = w + z"
   321 apply (cases z, cases w)
   322 apply (simp add: add_ac hypreal_add)
   323 done
   324 
   325 lemma hypreal_add_assoc: "((z1::hypreal) + z2) + z3 = z1 + (z2 + z3)"
   326 apply (cases z1, cases z2, cases z3)
   327 apply (simp add: hypreal_add real_add_assoc)
   328 done
   329 
   330 lemma hypreal_add_zero_left: "(0::hypreal) + z = z"
   331 by (cases z, simp add: hypreal_zero_def hypreal_add)
   332 
   333 instance hypreal :: comm_monoid_add
   334   by intro_classes
   335     (assumption | 
   336       rule hypreal_add_commute hypreal_add_assoc hypreal_add_zero_left)+
   337 
   338 lemma hypreal_add_zero_right [simp]: "z + (0::hypreal) = z"
   339 by (simp add: hypreal_add_zero_left hypreal_add_commute)
   340 
   341 
   342 subsection{*Additive inverse on @{typ hypreal}*}
   343 
   344 lemma hypreal_minus_congruent: 
   345   "congruent hyprel (%X. hyprel``{%n. - (X n)})"
   346 by (force simp add: congruent_def)
   347 
   348 lemma hypreal_minus: 
   349    "- (Abs_hypreal(hyprel``{%n. X n})) = Abs_hypreal(hyprel `` {%n. -(X n)})"
   350 by (simp add: hypreal_minus_def Abs_hypreal_inject 
   351               hyprel_in_hypreal [THEN Abs_hypreal_inverse] 
   352               UN_equiv_class [OF equiv_hyprel hypreal_minus_congruent])
   353 
   354 lemma hypreal_diff:
   355      "Abs_hypreal(hyprel``{%n. X n}) - Abs_hypreal(hyprel``{%n. Y n}) =  
   356       Abs_hypreal(hyprel``{%n. X n - Y n})"
   357 by (simp add: hypreal_diff_def hypreal_minus hypreal_add)
   358 
   359 lemma hypreal_add_minus [simp]: "z + -z = (0::hypreal)"
   360 by (cases z, simp add: hypreal_zero_def hypreal_minus hypreal_add)
   361 
   362 lemma hypreal_add_minus_left: "-z + z = (0::hypreal)"
   363 by (simp add: hypreal_add_commute hypreal_add_minus)
   364 
   365 
   366 subsection{*Hyperreal Multiplication*}
   367 
   368 lemma hypreal_mult_congruent2: 
   369     "congruent2 hyprel hyprel (%X Y. hyprel``{%n. X n * Y n})"
   370 by (simp add: congruent2_def, auto, ultra)
   371 
   372 lemma hypreal_mult: 
   373   "Abs_hypreal(hyprel``{%n. X n}) * Abs_hypreal(hyprel``{%n. Y n}) =  
   374    Abs_hypreal(hyprel``{%n. X n * Y n})"
   375 by (simp add: hypreal_mult_def
   376         UN_equiv_class2 [OF equiv_hyprel equiv_hyprel hypreal_mult_congruent2])
   377 
   378 lemma hypreal_mult_commute: "(z::hypreal) * w = w * z"
   379 by (cases z, cases w, simp add: hypreal_mult mult_ac)
   380 
   381 lemma hypreal_mult_assoc: "((z1::hypreal) * z2) * z3 = z1 * (z2 * z3)"
   382 by (cases z1, cases z2, cases z3, simp add: hypreal_mult mult_assoc)
   383 
   384 lemma hypreal_mult_1: "(1::hypreal) * z = z"
   385 by (cases z, simp add: hypreal_one_def hypreal_mult)
   386 
   387 lemma hypreal_add_mult_distrib:
   388      "((z1::hypreal) + z2) * w = (z1 * w) + (z2 * w)"
   389 by (cases z1, cases z2, cases w, simp add: hypreal_mult hypreal_add left_distrib)
   390 
   391 text{*one and zero are distinct*}
   392 lemma hypreal_zero_not_eq_one: "0 \<noteq> (1::hypreal)"
   393 by (simp add: hypreal_zero_def hypreal_one_def)
   394 
   395 
   396 subsection{*Multiplicative Inverse on @{typ hypreal} *}
   397 
   398 lemma hypreal_inverse_congruent: 
   399   "congruent hyprel (%X. hyprel``{%n. if X n = 0 then 0 else inverse(X n)})"
   400 by (auto simp add: congruent_def, ultra)
   401 
   402 lemma hypreal_inverse: 
   403       "inverse (Abs_hypreal(hyprel``{%n. X n})) =  
   404        Abs_hypreal(hyprel `` {%n. if X n = 0 then 0 else inverse(X n)})"
   405 by (simp add: hypreal_inverse_def Abs_hypreal_inject 
   406               hyprel_in_hypreal [THEN Abs_hypreal_inverse] 
   407               UN_equiv_class [OF equiv_hyprel hypreal_inverse_congruent])
   408 
   409 lemma hypreal_mult_inverse: 
   410      "x \<noteq> 0 ==> x*inverse(x) = (1::hypreal)"
   411 apply (cases x)
   412 apply (simp add: hypreal_one_def hypreal_zero_def hypreal_inverse hypreal_mult)
   413 apply (drule FreeUltrafilterNat_Compl_mem)
   414 apply (blast intro!: right_inverse FreeUltrafilterNat_subset)
   415 done
   416 
   417 lemma hypreal_mult_inverse_left:
   418      "x \<noteq> 0 ==> inverse(x)*x = (1::hypreal)"
   419 by (simp add: hypreal_mult_inverse hypreal_mult_commute)
   420 
   421 instance hypreal :: field
   422 proof
   423   fix x y z :: hypreal
   424   show "- x + x = 0" by (simp add: hypreal_add_minus_left)
   425   show "x - y = x + (-y)" by (simp add: hypreal_diff_def)
   426   show "(x * y) * z = x * (y * z)" by (rule hypreal_mult_assoc)
   427   show "x * y = y * x" by (rule hypreal_mult_commute)
   428   show "1 * x = x" by (simp add: hypreal_mult_1)
   429   show "(x + y) * z = x * z + y * z" by (simp add: hypreal_add_mult_distrib)
   430   show "0 \<noteq> (1::hypreal)" by (rule hypreal_zero_not_eq_one)
   431   show "x \<noteq> 0 ==> inverse x * x = 1" by (simp add: hypreal_mult_inverse_left)
   432   show "x / y = x * inverse y" by (simp add: hypreal_divide_def)
   433 qed
   434 
   435 
   436 instance hypreal :: division_by_zero
   437 proof
   438   show "inverse 0 = (0::hypreal)" 
   439     by (simp add: hypreal_inverse hypreal_zero_def)
   440 qed
   441 
   442 
   443 subsection{*Properties of The @{text "\<le>"} Relation*}
   444 
   445 lemma hypreal_le: 
   446       "(Abs_hypreal(hyprel``{%n. X n}) \<le> Abs_hypreal(hyprel``{%n. Y n})) =  
   447        ({n. X n \<le> Y n} \<in> FreeUltrafilterNat)"
   448 apply (simp add: hypreal_le_def)
   449 apply (auto intro!: lemma_hyprel_refl, ultra)
   450 done
   451 
   452 lemma hypreal_le_refl: "w \<le> (w::hypreal)"
   453 by (cases w, simp add: hypreal_le)
   454 
   455 lemma hypreal_le_trans: "[| i \<le> j; j \<le> k |] ==> i \<le> (k::hypreal)"
   456 by (cases i, cases j, cases k, simp add: hypreal_le, ultra)
   457 
   458 lemma hypreal_le_anti_sym: "[| z \<le> w; w \<le> z |] ==> z = (w::hypreal)"
   459 by (cases z, cases w, simp add: hypreal_le, ultra)
   460 
   461 (* Axiom 'order_less_le' of class 'order': *)
   462 lemma hypreal_less_le: "((w::hypreal) < z) = (w \<le> z & w \<noteq> z)"
   463 by (simp add: hypreal_less_def)
   464 
   465 instance hypreal :: order
   466   by intro_classes
   467     (assumption |
   468       rule hypreal_le_refl hypreal_le_trans hypreal_le_anti_sym hypreal_less_le)+
   469 
   470 
   471 (* Axiom 'linorder_linear' of class 'linorder': *)
   472 lemma hypreal_le_linear: "(z::hypreal) \<le> w | w \<le> z"
   473 apply (cases z, cases w)
   474 apply (auto simp add: hypreal_le, ultra)
   475 done
   476 
   477 instance hypreal :: linorder 
   478   by intro_classes (rule hypreal_le_linear)
   479 
   480 lemma hypreal_not_refl2: "!!(x::hypreal). x < y ==> x \<noteq> y"
   481 by (auto simp add: order_less_irrefl)
   482 
   483 lemma hypreal_add_left_mono: "x \<le> y ==> z + x \<le> z + (y::hypreal)"
   484 apply (cases x, cases y, cases z)
   485 apply (auto simp add: hypreal_le hypreal_add) 
   486 done
   487 
   488 lemma hypreal_mult_less_mono2: "[| (0::hypreal)<z; x<y |] ==> z*x<z*y"
   489 apply (cases x, cases y, cases z)
   490 apply (auto simp add: hypreal_zero_def hypreal_le hypreal_mult 
   491                       linorder_not_le [symmetric], ultra) 
   492 done
   493 
   494 
   495 subsection{*The Hyperreals Form an Ordered Field*}
   496 
   497 instance hypreal :: ordered_field
   498 proof
   499   fix x y z :: hypreal
   500   show "x \<le> y ==> z + x \<le> z + y" 
   501     by (rule hypreal_add_left_mono)
   502   show "x < y ==> 0 < z ==> z * x < z * y" 
   503     by (simp add: hypreal_mult_less_mono2)
   504   show "\<bar>x\<bar> = (if x < 0 then -x else x)"
   505     by (auto dest: order_le_less_trans simp add: hrabs_def linorder_not_le)
   506 qed
   507 
   508 lemma hypreal_eq_minus_iff: "((x::hypreal) = y) = (x + - y = 0)"
   509 apply auto
   510 apply (rule OrderedGroup.add_right_cancel [of _ "-y", THEN iffD1], auto)
   511 done
   512 
   513 lemma hypreal_mult_left_cancel: "(c::hypreal) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
   514 by auto
   515     
   516 lemma hypreal_mult_right_cancel: "(c::hypreal) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
   517 by auto
   518 
   519 
   520 subsection{*The Embedding @{term hypreal_of_real} Preserves Field and 
   521       Order Properties*}
   522 
   523 lemma hypreal_of_real_add [simp]: 
   524      "hypreal_of_real (w + z) = hypreal_of_real w + hypreal_of_real z"
   525 by (simp add: hypreal_of_real_def, simp add: hypreal_add left_distrib)
   526 
   527 lemma hypreal_of_real_minus [simp]:
   528      "hypreal_of_real (-r) = - hypreal_of_real  r"
   529 by (auto simp add: hypreal_of_real_def hypreal_minus)
   530 
   531 lemma hypreal_of_real_diff [simp]: 
   532      "hypreal_of_real (w - z) = hypreal_of_real w - hypreal_of_real z"
   533 by (simp add: diff_minus) 
   534 
   535 lemma hypreal_of_real_mult [simp]: 
   536      "hypreal_of_real (w * z) = hypreal_of_real w * hypreal_of_real z"
   537 by (simp add: hypreal_of_real_def, simp add: hypreal_mult right_distrib)
   538 
   539 lemma hypreal_of_real_one [simp]: "hypreal_of_real 1 = (1::hypreal)"
   540 by (simp add: hypreal_of_real_def hypreal_one_def)
   541 
   542 lemma hypreal_of_real_zero [simp]: "hypreal_of_real 0 = 0"
   543 by (simp add: hypreal_of_real_def hypreal_zero_def)
   544 
   545 lemma hypreal_of_real_le_iff [simp]: 
   546      "(hypreal_of_real w \<le> hypreal_of_real z) = (w \<le> z)"
   547 apply (simp add: hypreal_le_def hypreal_of_real_def, auto)
   548 apply (rule_tac [2] x = "%n. w" in exI, safe)
   549 apply (rule_tac [3] x = "%n. z" in exI, auto)
   550 apply (rule FreeUltrafilterNat_P, ultra)
   551 done
   552 
   553 lemma hypreal_of_real_less_iff [simp]: 
   554      "(hypreal_of_real w < hypreal_of_real z) = (w < z)"
   555 by (simp add: linorder_not_le [symmetric]) 
   556 
   557 lemma hypreal_of_real_eq_iff [simp]:
   558      "(hypreal_of_real w = hypreal_of_real z) = (w = z)"
   559 by (force intro: order_antisym hypreal_of_real_le_iff [THEN iffD1])
   560 
   561 text{*As above, for 0*}
   562 
   563 declare hypreal_of_real_less_iff [of 0, simplified, simp]
   564 declare hypreal_of_real_le_iff   [of 0, simplified, simp]
   565 declare hypreal_of_real_eq_iff   [of 0, simplified, simp]
   566 
   567 declare hypreal_of_real_less_iff [of _ 0, simplified, simp]
   568 declare hypreal_of_real_le_iff   [of _ 0, simplified, simp]
   569 declare hypreal_of_real_eq_iff   [of _ 0, simplified, simp]
   570 
   571 text{*As above, for 1*}
   572 
   573 declare hypreal_of_real_less_iff [of 1, simplified, simp]
   574 declare hypreal_of_real_le_iff   [of 1, simplified, simp]
   575 declare hypreal_of_real_eq_iff   [of 1, simplified, simp]
   576 
   577 declare hypreal_of_real_less_iff [of _ 1, simplified, simp]
   578 declare hypreal_of_real_le_iff   [of _ 1, simplified, simp]
   579 declare hypreal_of_real_eq_iff   [of _ 1, simplified, simp]
   580 
   581 lemma hypreal_of_real_inverse [simp]:
   582      "hypreal_of_real (inverse r) = inverse (hypreal_of_real r)"
   583 apply (case_tac "r=0", simp)
   584 apply (rule_tac c1 = "hypreal_of_real r" in hypreal_mult_left_cancel [THEN iffD1])
   585 apply (auto simp add: hypreal_of_real_mult [symmetric])
   586 done
   587 
   588 lemma hypreal_of_real_divide [simp]:
   589      "hypreal_of_real (w / z) = hypreal_of_real w / hypreal_of_real z"
   590 by (simp add: hypreal_divide_def real_divide_def)
   591 
   592 lemma hypreal_of_real_of_nat [simp]: "hypreal_of_real (of_nat n) = of_nat n"
   593 by (induct n, simp_all) 
   594 
   595 lemma hypreal_of_real_of_int [simp]:  "hypreal_of_real (of_int z) = of_int z"
   596 proof (cases z)
   597   case (1 n)
   598     thus ?thesis  by simp
   599 next
   600   case (2 n)
   601     thus ?thesis
   602       by (simp only: of_int_minus hypreal_of_real_minus, simp)
   603 qed
   604 
   605 
   606 subsection{*Misc Others*}
   607 
   608 lemma hypreal_less: 
   609       "(Abs_hypreal(hyprel``{%n. X n}) < Abs_hypreal(hyprel``{%n. Y n})) =  
   610        ({n. X n < Y n} \<in> FreeUltrafilterNat)"
   611 by (auto simp add: hypreal_le linorder_not_le [symmetric], ultra+)
   612 
   613 lemma hypreal_zero_num: "0 = Abs_hypreal (hyprel `` {%n. 0})"
   614 by (simp add: hypreal_zero_def [THEN meta_eq_to_obj_eq, symmetric])
   615 
   616 lemma hypreal_one_num: "1 = Abs_hypreal (hyprel `` {%n. 1})"
   617 by (simp add: hypreal_one_def [THEN meta_eq_to_obj_eq, symmetric])
   618 
   619 lemma hypreal_omega_gt_zero [simp]: "0 < omega"
   620 by (auto simp add: omega_def hypreal_less hypreal_zero_num)
   621 
   622 lemma hypreal_hrabs:
   623      "abs (Abs_hypreal (hyprel `` {X})) = 
   624       Abs_hypreal(hyprel `` {%n. abs (X n)})"
   625 apply (auto simp add: hrabs_def hypreal_zero_def hypreal_le hypreal_minus)
   626 apply (ultra, arith)+
   627 done
   628 
   629 
   630 
   631 lemma hypreal_add_zero_less_le_mono: "[|r < x; (0::hypreal) \<le> y|] ==> r < x+y"
   632 by (auto dest: add_less_le_mono)
   633 
   634 text{*The precondition could be weakened to @{term "0\<le>x"}*}
   635 lemma hypreal_mult_less_mono:
   636      "[| u<v;  x<y;  (0::hypreal) < v;  0 < x |] ==> u*x < v* y"
   637  by (simp add: Ring_and_Field.mult_strict_mono order_less_imp_le)
   638 
   639 
   640 subsection{*Existence of Infinite Hyperreal Number*}
   641 
   642 lemma Rep_hypreal_omega: "Rep_hypreal(omega) \<in> hypreal"
   643 by (simp add: omega_def)
   644 
   645 text{*Existence of infinite number not corresponding to any real number.
   646 Use assumption that member @{term FreeUltrafilterNat} is not finite.*}
   647 
   648 
   649 text{*A few lemmas first*}
   650 
   651 lemma lemma_omega_empty_singleton_disj: "{n::nat. x = real n} = {} |  
   652       (\<exists>y. {n::nat. x = real n} = {y})"
   653 by force
   654 
   655 lemma lemma_finite_omega_set: "finite {n::nat. x = real n}"
   656 by (cut_tac x = x in lemma_omega_empty_singleton_disj, auto)
   657 
   658 lemma not_ex_hypreal_of_real_eq_omega: 
   659       "~ (\<exists>x. hypreal_of_real x = omega)"
   660 apply (simp add: omega_def hypreal_of_real_def)
   661 apply (auto simp add: real_of_nat_Suc diff_eq_eq [symmetric] 
   662             lemma_finite_omega_set [THEN FreeUltrafilterNat_finite])
   663 done
   664 
   665 lemma hypreal_of_real_not_eq_omega: "hypreal_of_real x \<noteq> omega"
   666 by (insert not_ex_hypreal_of_real_eq_omega, auto)
   667 
   668 text{*Existence of infinitesimal number also not corresponding to any
   669  real number*}
   670 
   671 lemma lemma_epsilon_empty_singleton_disj:
   672      "{n::nat. x = inverse(real(Suc n))} = {} |  
   673       (\<exists>y. {n::nat. x = inverse(real(Suc n))} = {y})"
   674 by auto
   675 
   676 lemma lemma_finite_epsilon_set: "finite {n. x = inverse(real(Suc n))}"
   677 by (cut_tac x = x in lemma_epsilon_empty_singleton_disj, auto)
   678 
   679 lemma not_ex_hypreal_of_real_eq_epsilon: "~ (\<exists>x. hypreal_of_real x = epsilon)"
   680 by (auto simp add: epsilon_def hypreal_of_real_def 
   681                    lemma_finite_epsilon_set [THEN FreeUltrafilterNat_finite])
   682 
   683 lemma hypreal_of_real_not_eq_epsilon: "hypreal_of_real x \<noteq> epsilon"
   684 by (insert not_ex_hypreal_of_real_eq_epsilon, auto)
   685 
   686 lemma hypreal_epsilon_not_zero: "epsilon \<noteq> 0"
   687 by (simp add: epsilon_def hypreal_zero_def)
   688 
   689 lemma hypreal_epsilon_inverse_omega: "epsilon = inverse(omega)"
   690 by (simp add: hypreal_inverse omega_def epsilon_def)
   691 
   692 
   693 ML
   694 {*
   695 val hrabs_def = thm "hrabs_def";
   696 val hypreal_hrabs = thm "hypreal_hrabs";
   697 
   698 val hypreal_zero_def = thm "hypreal_zero_def";
   699 val hypreal_one_def = thm "hypreal_one_def";
   700 val hypreal_minus_def = thm "hypreal_minus_def";
   701 val hypreal_diff_def = thm "hypreal_diff_def";
   702 val hypreal_inverse_def = thm "hypreal_inverse_def";
   703 val hypreal_divide_def = thm "hypreal_divide_def";
   704 val hypreal_of_real_def = thm "hypreal_of_real_def";
   705 val omega_def = thm "omega_def";
   706 val epsilon_def = thm "epsilon_def";
   707 val hypreal_add_def = thm "hypreal_add_def";
   708 val hypreal_mult_def = thm "hypreal_mult_def";
   709 val hypreal_less_def = thm "hypreal_less_def";
   710 val hypreal_le_def = thm "hypreal_le_def";
   711 
   712 val finite_exhausts = thm "finite_exhausts";
   713 val finite_not_covers = thm "finite_not_covers";
   714 val not_finite_nat = thm "not_finite_nat";
   715 val FreeUltrafilterNat_Ex = thm "FreeUltrafilterNat_Ex";
   716 val FreeUltrafilterNat_mem = thm "FreeUltrafilterNat_mem";
   717 val FreeUltrafilterNat_finite = thm "FreeUltrafilterNat_finite";
   718 val FreeUltrafilterNat_not_finite = thm "FreeUltrafilterNat_not_finite";
   719 val FreeUltrafilterNat_empty = thm "FreeUltrafilterNat_empty";
   720 val FreeUltrafilterNat_Int = thm "FreeUltrafilterNat_Int";
   721 val FreeUltrafilterNat_subset = thm "FreeUltrafilterNat_subset";
   722 val FreeUltrafilterNat_Compl = thm "FreeUltrafilterNat_Compl";
   723 val FreeUltrafilterNat_Compl_mem = thm "FreeUltrafilterNat_Compl_mem";
   724 val FreeUltrafilterNat_Compl_iff1 = thm "FreeUltrafilterNat_Compl_iff1";
   725 val FreeUltrafilterNat_Compl_iff2 = thm "FreeUltrafilterNat_Compl_iff2";
   726 val FreeUltrafilterNat_UNIV = thm "FreeUltrafilterNat_UNIV";
   727 val FreeUltrafilterNat_Nat_set = thm "FreeUltrafilterNat_Nat_set";
   728 val FreeUltrafilterNat_Nat_set_refl = thm "FreeUltrafilterNat_Nat_set_refl";
   729 val FreeUltrafilterNat_P = thm "FreeUltrafilterNat_P";
   730 val FreeUltrafilterNat_Ex_P = thm "FreeUltrafilterNat_Ex_P";
   731 val FreeUltrafilterNat_all = thm "FreeUltrafilterNat_all";
   732 val FreeUltrafilterNat_Un = thm "FreeUltrafilterNat_Un";
   733 val hyprel_iff = thm "hyprel_iff";
   734 val hyprel_in_hypreal = thm "hyprel_in_hypreal";
   735 val Abs_hypreal_inverse = thm "Abs_hypreal_inverse";
   736 val inj_on_Abs_hypreal = thm "inj_on_Abs_hypreal";
   737 val inj_Rep_hypreal = thm "inj_Rep_hypreal";
   738 val lemma_hyprel_refl = thm "lemma_hyprel_refl";
   739 val hypreal_empty_not_mem = thm "hypreal_empty_not_mem";
   740 val Rep_hypreal_nonempty = thm "Rep_hypreal_nonempty";
   741 val inj_hypreal_of_real = thm "inj_hypreal_of_real";
   742 val eq_Abs_hypreal = thm "eq_Abs_hypreal";
   743 val hypreal_minus_congruent = thm "hypreal_minus_congruent";
   744 val hypreal_minus = thm "hypreal_minus";
   745 val hypreal_add = thm "hypreal_add";
   746 val hypreal_diff = thm "hypreal_diff";
   747 val hypreal_add_commute = thm "hypreal_add_commute";
   748 val hypreal_add_assoc = thm "hypreal_add_assoc";
   749 val hypreal_add_zero_left = thm "hypreal_add_zero_left";
   750 val hypreal_add_zero_right = thm "hypreal_add_zero_right";
   751 val hypreal_add_minus = thm "hypreal_add_minus";
   752 val hypreal_add_minus_left = thm "hypreal_add_minus_left";
   753 val hypreal_mult = thm "hypreal_mult";
   754 val hypreal_mult_commute = thm "hypreal_mult_commute";
   755 val hypreal_mult_assoc = thm "hypreal_mult_assoc";
   756 val hypreal_mult_1 = thm "hypreal_mult_1";
   757 val hypreal_zero_not_eq_one = thm "hypreal_zero_not_eq_one";
   758 val hypreal_inverse_congruent = thm "hypreal_inverse_congruent";
   759 val hypreal_inverse = thm "hypreal_inverse";
   760 val hypreal_mult_inverse = thm "hypreal_mult_inverse";
   761 val hypreal_mult_inverse_left = thm "hypreal_mult_inverse_left";
   762 val hypreal_mult_left_cancel = thm "hypreal_mult_left_cancel";
   763 val hypreal_mult_right_cancel = thm "hypreal_mult_right_cancel";
   764 val hypreal_not_refl2 = thm "hypreal_not_refl2";
   765 val hypreal_less = thm "hypreal_less";
   766 val hypreal_eq_minus_iff = thm "hypreal_eq_minus_iff";
   767 val hypreal_le = thm "hypreal_le";
   768 val hypreal_le_refl = thm "hypreal_le_refl";
   769 val hypreal_le_linear = thm "hypreal_le_linear";
   770 val hypreal_le_trans = thm "hypreal_le_trans";
   771 val hypreal_le_anti_sym = thm "hypreal_le_anti_sym";
   772 val hypreal_less_le = thm "hypreal_less_le";
   773 val hypreal_of_real_add = thm "hypreal_of_real_add";
   774 val hypreal_of_real_mult = thm "hypreal_of_real_mult";
   775 val hypreal_of_real_less_iff = thm "hypreal_of_real_less_iff";
   776 val hypreal_of_real_le_iff = thm "hypreal_of_real_le_iff";
   777 val hypreal_of_real_eq_iff = thm "hypreal_of_real_eq_iff";
   778 val hypreal_of_real_minus = thm "hypreal_of_real_minus";
   779 val hypreal_of_real_one = thm "hypreal_of_real_one";
   780 val hypreal_of_real_zero = thm "hypreal_of_real_zero";
   781 val hypreal_of_real_inverse = thm "hypreal_of_real_inverse";
   782 val hypreal_of_real_divide = thm "hypreal_of_real_divide";
   783 val hypreal_zero_num = thm "hypreal_zero_num";
   784 val hypreal_one_num = thm "hypreal_one_num";
   785 val hypreal_omega_gt_zero = thm "hypreal_omega_gt_zero";
   786 
   787 val hypreal_add_zero_less_le_mono = thm"hypreal_add_zero_less_le_mono";
   788 val Rep_hypreal_omega = thm"Rep_hypreal_omega";
   789 val lemma_omega_empty_singleton_disj = thm"lemma_omega_empty_singleton_disj";
   790 val lemma_finite_omega_set = thm"lemma_finite_omega_set";
   791 val not_ex_hypreal_of_real_eq_omega = thm"not_ex_hypreal_of_real_eq_omega";
   792 val hypreal_of_real_not_eq_omega = thm"hypreal_of_real_not_eq_omega";
   793 val not_ex_hypreal_of_real_eq_epsilon = thm"not_ex_hypreal_of_real_eq_epsilon";
   794 val hypreal_of_real_not_eq_epsilon = thm"hypreal_of_real_not_eq_epsilon";
   795 val hypreal_epsilon_not_zero = thm"hypreal_epsilon_not_zero";
   796 val hypreal_epsilon_inverse_omega = thm"hypreal_epsilon_inverse_omega";
   797 *}
   798 
   799 end