src/HOL/Hyperreal/HyperDef.thy
author paulson
Thu Dec 25 22:48:32 2003 +0100 (2003-12-25)
changeset 14329 ff3210fe968f
parent 14305 f17ca9f6dc8c
child 14331 8dbbb7cf3637
permissions -rw-r--r--
re-organized some hyperreal and real lemmas
     1 (*  Title       : HOL/Real/Hyperreal/HyperDef.thy
     2     ID          : $Id$
     3     Author      : Jacques D. Fleuriot
     4     Copyright   : 1998  University of Cambridge
     5     Description : Construction of hyperreals using ultrafilters
     6 *)
     7 
     8 theory HyperDef = Filter + Real
     9 files ("fuf.ML"):  (*Warning: file fuf.ML refers to the name Hyperdef!*)
    10 
    11 
    12 constdefs
    13 
    14   FreeUltrafilterNat   :: "nat set set"    ("\\<U>")
    15     "FreeUltrafilterNat == (SOME U. U \<in> FreeUltrafilter (UNIV:: nat set))"
    16 
    17   hyprel :: "((nat=>real)*(nat=>real)) set"
    18     "hyprel == {p. \<exists>X Y. p = ((X::nat=>real),Y) &
    19                    {n::nat. X(n) = Y(n)}: FreeUltrafilterNat}"
    20 
    21 typedef hypreal = "UNIV//hyprel" 
    22     by (auto simp add: quotient_def) 
    23 
    24 instance hypreal :: ord ..
    25 instance hypreal :: zero ..
    26 instance hypreal :: one ..
    27 instance hypreal :: plus ..
    28 instance hypreal :: times ..
    29 instance hypreal :: minus ..
    30 instance hypreal :: inverse ..
    31 
    32 
    33 defs (overloaded)
    34 
    35   hypreal_zero_def:
    36   "0 == Abs_hypreal(hyprel``{%n::nat. (0::real)})"
    37 
    38   hypreal_one_def:
    39   "1 == Abs_hypreal(hyprel``{%n::nat. (1::real)})"
    40 
    41   hypreal_minus_def:
    42   "- P == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). hyprel``{%n::nat. - (X n)})"
    43 
    44   hypreal_diff_def:
    45   "x - y == x + -(y::hypreal)"
    46 
    47   hypreal_inverse_def:
    48   "inverse P == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P).
    49                     hyprel``{%n. if X n = 0 then 0 else inverse (X n)})"
    50 
    51   hypreal_divide_def:
    52   "P / Q::hypreal == P * inverse Q"
    53 
    54 constdefs
    55 
    56   hypreal_of_real  :: "real => hypreal"
    57   "hypreal_of_real r         == Abs_hypreal(hyprel``{%n::nat. r})"
    58 
    59   omega   :: hypreal   (*an infinite number = [<1,2,3,...>] *)
    60   "omega == Abs_hypreal(hyprel``{%n::nat. real (Suc n)})"
    61 
    62   epsilon :: hypreal   (*an infinitesimal number = [<1,1/2,1/3,...>] *)
    63   "epsilon == Abs_hypreal(hyprel``{%n::nat. inverse (real (Suc n))})"
    64 
    65 syntax (xsymbols)
    66   omega   :: hypreal   ("\<omega>")
    67   epsilon :: hypreal   ("\<epsilon>")
    68 
    69 
    70 defs
    71 
    72   hypreal_add_def:
    73   "P + Q == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). \<Union>Y \<in> Rep_hypreal(Q).
    74                 hyprel``{%n::nat. X n + Y n})"
    75 
    76   hypreal_mult_def:
    77   "P * Q == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). \<Union>Y \<in> Rep_hypreal(Q).
    78                 hyprel``{%n::nat. X n * Y n})"
    79 
    80   hypreal_less_def:
    81   "P < (Q::hypreal) == \<exists>X Y. X \<in> Rep_hypreal(P) &
    82                                Y \<in> Rep_hypreal(Q) &
    83                                {n::nat. X n < Y n} \<in> FreeUltrafilterNat"
    84   hypreal_le_def:
    85   "P <= (Q::hypreal) == ~(Q < P)"
    86 
    87   hrabs_def:  "abs (r::hypreal) == (if 0 \<le> r then r else -r)"
    88 
    89 
    90 subsection{*The Set of Naturals is not Finite*}
    91 
    92 (*** based on James' proof that the set of naturals is not finite ***)
    93 lemma finite_exhausts [rule_format]:
    94      "finite (A::nat set) --> (\<exists>n. \<forall>m. Suc (n + m) \<notin> A)"
    95 apply (rule impI)
    96 apply (erule_tac F = A in finite_induct)
    97 apply (blast, erule exE)
    98 apply (rule_tac x = "n + x" in exI)
    99 apply (rule allI, erule_tac x = "x + m" in allE)
   100 apply (auto simp add: add_ac)
   101 done
   102 
   103 lemma finite_not_covers [rule_format (no_asm)]:
   104      "finite (A :: nat set) --> (\<exists>n. n \<notin>A)"
   105 by (rule impI, drule finite_exhausts, blast)
   106 
   107 lemma not_finite_nat: "~ finite(UNIV:: nat set)"
   108 by (fast dest!: finite_exhausts)
   109 
   110 
   111 subsection{*Existence of Free Ultrafilter over the Naturals*}
   112 
   113 text{*Also, proof of various properties of @{term FreeUltrafilterNat}: 
   114 an arbitrary free ultrafilter*}
   115 
   116 lemma FreeUltrafilterNat_Ex: "\<exists>U. U: FreeUltrafilter (UNIV::nat set)"
   117 by (rule not_finite_nat [THEN FreeUltrafilter_Ex])
   118 
   119 lemma FreeUltrafilterNat_mem [simp]: 
   120      "FreeUltrafilterNat: FreeUltrafilter(UNIV:: nat set)"
   121 apply (unfold FreeUltrafilterNat_def)
   122 apply (rule FreeUltrafilterNat_Ex [THEN exE])
   123 apply (rule someI2, assumption+)
   124 done
   125 
   126 lemma FreeUltrafilterNat_finite: "finite x ==> x \<notin> FreeUltrafilterNat"
   127 apply (unfold FreeUltrafilterNat_def)
   128 apply (rule FreeUltrafilterNat_Ex [THEN exE])
   129 apply (rule someI2, assumption)
   130 apply (blast dest: mem_FreeUltrafiltersetD1)
   131 done
   132 
   133 lemma FreeUltrafilterNat_not_finite: "x: FreeUltrafilterNat ==> ~ finite x"
   134 by (blast dest: FreeUltrafilterNat_finite)
   135 
   136 lemma FreeUltrafilterNat_empty [simp]: "{} \<notin> FreeUltrafilterNat"
   137 apply (unfold FreeUltrafilterNat_def)
   138 apply (rule FreeUltrafilterNat_Ex [THEN exE])
   139 apply (rule someI2, assumption)
   140 apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter 
   141                    Filter_empty_not_mem)
   142 done
   143 
   144 lemma FreeUltrafilterNat_Int:
   145      "[| X: FreeUltrafilterNat;  Y: FreeUltrafilterNat |]   
   146       ==> X Int Y \<in> FreeUltrafilterNat"
   147 apply (cut_tac FreeUltrafilterNat_mem)
   148 apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter mem_FiltersetD1)
   149 done
   150 
   151 lemma FreeUltrafilterNat_subset:
   152      "[| X: FreeUltrafilterNat;  X <= Y |]  
   153       ==> Y \<in> FreeUltrafilterNat"
   154 apply (cut_tac FreeUltrafilterNat_mem)
   155 apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter mem_FiltersetD2)
   156 done
   157 
   158 lemma FreeUltrafilterNat_Compl:
   159      "X: FreeUltrafilterNat ==> -X \<notin> FreeUltrafilterNat"
   160 apply safe
   161 apply (drule FreeUltrafilterNat_Int, assumption, auto)
   162 done
   163 
   164 lemma FreeUltrafilterNat_Compl_mem:
   165      "X\<notin> FreeUltrafilterNat ==> -X \<in> FreeUltrafilterNat"
   166 apply (cut_tac FreeUltrafilterNat_mem [THEN FreeUltrafilter_iff [THEN iffD1]])
   167 apply (safe, drule_tac x = X in bspec)
   168 apply (auto simp add: UNIV_diff_Compl)
   169 done
   170 
   171 lemma FreeUltrafilterNat_Compl_iff1:
   172      "(X \<notin> FreeUltrafilterNat) = (-X: FreeUltrafilterNat)"
   173 by (blast dest: FreeUltrafilterNat_Compl FreeUltrafilterNat_Compl_mem)
   174 
   175 lemma FreeUltrafilterNat_Compl_iff2:
   176      "(X: FreeUltrafilterNat) = (-X \<notin> FreeUltrafilterNat)"
   177 by (auto simp add: FreeUltrafilterNat_Compl_iff1 [symmetric])
   178 
   179 lemma FreeUltrafilterNat_UNIV [simp]: "(UNIV::nat set) \<in> FreeUltrafilterNat"
   180 by (rule FreeUltrafilterNat_mem [THEN FreeUltrafilter_Ultrafilter, THEN Ultrafilter_Filter, THEN mem_FiltersetD4])
   181 
   182 lemma FreeUltrafilterNat_Nat_set [simp]: "UNIV \<in> FreeUltrafilterNat"
   183 by auto
   184 
   185 lemma FreeUltrafilterNat_Nat_set_refl [intro]:
   186      "{n. P(n) = P(n)} \<in> FreeUltrafilterNat"
   187 by simp
   188 
   189 lemma FreeUltrafilterNat_P: "{n::nat. P} \<in> FreeUltrafilterNat ==> P"
   190 by (rule ccontr, simp)
   191 
   192 lemma FreeUltrafilterNat_Ex_P: "{n. P(n)} \<in> FreeUltrafilterNat ==> \<exists>n. P(n)"
   193 by (rule ccontr, simp)
   194 
   195 lemma FreeUltrafilterNat_all: "\<forall>n. P(n) ==> {n. P(n)} \<in> FreeUltrafilterNat"
   196 by (auto intro: FreeUltrafilterNat_Nat_set)
   197 
   198 
   199 text{*Define and use Ultrafilter tactics*}
   200 use "fuf.ML"
   201 
   202 method_setup fuf = {*
   203     Method.ctxt_args (fn ctxt =>
   204         Method.METHOD (fn facts =>
   205             fuf_tac (Classical.get_local_claset ctxt,
   206                      Simplifier.get_local_simpset ctxt) 1)) *}
   207     "free ultrafilter tactic"
   208 
   209 method_setup ultra = {*
   210     Method.ctxt_args (fn ctxt =>
   211         Method.METHOD (fn facts =>
   212             ultra_tac (Classical.get_local_claset ctxt,
   213                        Simplifier.get_local_simpset ctxt) 1)) *}
   214     "ultrafilter tactic"
   215 
   216 
   217 text{*One further property of our free ultrafilter*}
   218 lemma FreeUltrafilterNat_Un:
   219      "X Un Y: FreeUltrafilterNat  
   220       ==> X: FreeUltrafilterNat | Y: FreeUltrafilterNat"
   221 apply auto
   222 apply ultra
   223 done
   224 
   225 
   226 subsection{*Properties of @{term hyprel}*}
   227 
   228 text{*Proving that @{term hyprel} is an equivalence relation*}
   229 
   230 lemma hyprel_iff: "((X,Y): hyprel) = ({n. X n = Y n}: FreeUltrafilterNat)"
   231 by (unfold hyprel_def, fast)
   232 
   233 lemma hyprel_refl: "(x,x): hyprel"
   234 apply (unfold hyprel_def)
   235 apply (auto simp add: FreeUltrafilterNat_Nat_set)
   236 done
   237 
   238 lemma hyprel_sym [rule_format (no_asm)]: "(x,y): hyprel --> (y,x):hyprel"
   239 by (simp add: hyprel_def eq_commute)
   240 
   241 lemma hyprel_trans: 
   242       "[|(x,y): hyprel; (y,z):hyprel|] ==> (x,z):hyprel"
   243 apply (unfold hyprel_def, auto, ultra)
   244 done
   245 
   246 lemma equiv_hyprel: "equiv UNIV hyprel"
   247 apply (simp add: equiv_def refl_def sym_def trans_def hyprel_refl)
   248 apply (blast intro: hyprel_sym hyprel_trans) 
   249 done
   250 
   251 (* (hyprel `` {x} = hyprel `` {y}) = ((x,y) \<in> hyprel) *)
   252 lemmas equiv_hyprel_iff =
   253     eq_equiv_class_iff [OF equiv_hyprel UNIV_I UNIV_I, simp] 
   254 
   255 lemma hyprel_in_hypreal [simp]: "hyprel``{x}:hypreal"
   256 by (unfold hypreal_def hyprel_def quotient_def, blast)
   257 
   258 lemma inj_on_Abs_hypreal: "inj_on Abs_hypreal hypreal"
   259 apply (rule inj_on_inverseI)
   260 apply (erule Abs_hypreal_inverse)
   261 done
   262 
   263 declare inj_on_Abs_hypreal [THEN inj_on_iff, simp] 
   264         Abs_hypreal_inverse [simp]
   265 
   266 declare equiv_hyprel [THEN eq_equiv_class_iff, simp]
   267 
   268 declare hyprel_iff [iff]
   269 
   270 lemmas eq_hyprelD = eq_equiv_class [OF _ equiv_hyprel]
   271 
   272 lemma inj_Rep_hypreal: "inj(Rep_hypreal)"
   273 apply (rule inj_on_inverseI)
   274 apply (rule Rep_hypreal_inverse)
   275 done
   276 
   277 lemma lemma_hyprel_refl [simp]: "x \<in> hyprel `` {x}"
   278 apply (unfold hyprel_def, safe)
   279 apply (auto intro!: FreeUltrafilterNat_Nat_set)
   280 done
   281 
   282 lemma hypreal_empty_not_mem [simp]: "{} \<notin> hypreal"
   283 apply (unfold hypreal_def)
   284 apply (auto elim!: quotientE equalityCE)
   285 done
   286 
   287 lemma Rep_hypreal_nonempty [simp]: "Rep_hypreal x \<noteq> {}"
   288 by (cut_tac x = x in Rep_hypreal, auto)
   289 
   290 
   291 subsection{*@{term hypreal_of_real}: 
   292             the Injection from @{typ real} to @{typ hypreal}*}
   293 
   294 lemma inj_hypreal_of_real: "inj(hypreal_of_real)"
   295 apply (rule inj_onI)
   296 apply (unfold hypreal_of_real_def)
   297 apply (drule inj_on_Abs_hypreal [THEN inj_onD])
   298 apply (rule hyprel_in_hypreal)+
   299 apply (drule eq_equiv_class)
   300 apply (rule equiv_hyprel)
   301 apply (simp_all add: split: split_if_asm) 
   302 done
   303 
   304 lemma eq_Abs_hypreal:
   305     "(!!x y. z = Abs_hypreal(hyprel``{x}) ==> P) ==> P"
   306 apply (rule_tac x1=z in Rep_hypreal [unfolded hypreal_def, THEN quotientE])
   307 apply (drule_tac f = Abs_hypreal in arg_cong)
   308 apply (force simp add: Rep_hypreal_inverse)
   309 done
   310 
   311 
   312 subsection{*Hyperreal Addition*}
   313 
   314 lemma hypreal_add_congruent2: 
   315     "congruent2 hyprel (%X Y. hyprel``{%n. X n + Y n})"
   316 apply (unfold congruent2_def, auto, ultra)
   317 done
   318 
   319 lemma hypreal_add: 
   320   "Abs_hypreal(hyprel``{%n. X n}) + Abs_hypreal(hyprel``{%n. Y n}) =  
   321    Abs_hypreal(hyprel``{%n. X n + Y n})"
   322 apply (unfold hypreal_add_def)
   323 apply (simp add: UN_equiv_class2 [OF equiv_hyprel hypreal_add_congruent2])
   324 done
   325 
   326 lemma hypreal_add_commute: "(z::hypreal) + w = w + z"
   327 apply (rule_tac z = z in eq_Abs_hypreal)
   328 apply (rule_tac z = w in eq_Abs_hypreal)
   329 apply (simp add: real_add_ac hypreal_add)
   330 done
   331 
   332 lemma hypreal_add_assoc: "((z1::hypreal) + z2) + z3 = z1 + (z2 + z3)"
   333 apply (rule_tac z = z1 in eq_Abs_hypreal)
   334 apply (rule_tac z = z2 in eq_Abs_hypreal)
   335 apply (rule_tac z = z3 in eq_Abs_hypreal)
   336 apply (simp add: hypreal_add real_add_assoc)
   337 done
   338 
   339 (*For AC rewriting*)
   340 lemma hypreal_add_left_commute: "(x::hypreal)+(y+z)=y+(x+z)"
   341   apply (rule mk_left_commute [of "op +"])
   342   apply (rule hypreal_add_assoc)
   343   apply (rule hypreal_add_commute)
   344   done
   345 
   346 (* hypreal addition is an AC operator *)
   347 lemmas hypreal_add_ac =
   348        hypreal_add_assoc hypreal_add_commute hypreal_add_left_commute
   349 
   350 lemma hypreal_add_zero_left [simp]: "(0::hypreal) + z = z"
   351 apply (unfold hypreal_zero_def)
   352 apply (rule_tac z = z in eq_Abs_hypreal)
   353 apply (simp add: hypreal_add)
   354 done
   355 
   356 instance hypreal :: plus_ac0
   357   by (intro_classes,
   358       (assumption | 
   359        rule hypreal_add_commute hypreal_add_assoc hypreal_add_zero_left)+)
   360 
   361 lemma hypreal_add_zero_right [simp]: "z + (0::hypreal) = z"
   362 by (simp add: hypreal_add_zero_left hypreal_add_commute)
   363 
   364 
   365 subsection{*Additive inverse on @{typ hypreal}*}
   366 
   367 lemma hypreal_minus_congruent: 
   368   "congruent hyprel (%X. hyprel``{%n. - (X n)})"
   369 by (force simp add: congruent_def)
   370 
   371 lemma hypreal_minus: 
   372    "- (Abs_hypreal(hyprel``{%n. X n})) = Abs_hypreal(hyprel `` {%n. -(X n)})"
   373 apply (unfold hypreal_minus_def)
   374 apply (rule_tac f = Abs_hypreal in arg_cong)
   375 apply (simp add: hyprel_in_hypreal [THEN Abs_hypreal_inverse] 
   376                UN_equiv_class [OF equiv_hyprel hypreal_minus_congruent])
   377 done
   378 
   379 lemma hypreal_minus_minus [simp]: "- (- z) = (z::hypreal)"
   380 apply (rule_tac z = z in eq_Abs_hypreal)
   381 apply (simp add: hypreal_minus)
   382 done
   383 
   384 lemma inj_hypreal_minus: "inj(%r::hypreal. -r)"
   385 apply (rule inj_onI)
   386 apply (drule_tac f = uminus in arg_cong)
   387 apply (simp add: hypreal_minus_minus)
   388 done
   389 
   390 lemma hypreal_minus_zero [simp]: "- 0 = (0::hypreal)"
   391 apply (unfold hypreal_zero_def)
   392 apply (simp add: hypreal_minus)
   393 done
   394 
   395 lemma hypreal_minus_zero_iff [simp]: "(-x = 0) = (x = (0::hypreal))"
   396 apply (rule_tac z = x in eq_Abs_hypreal)
   397 apply (auto simp add: hypreal_zero_def hypreal_minus)
   398 done
   399 
   400 lemma hypreal_diff:
   401      "Abs_hypreal(hyprel``{%n. X n}) - Abs_hypreal(hyprel``{%n. Y n}) =  
   402       Abs_hypreal(hyprel``{%n. X n - Y n})"
   403 apply (simp add: hypreal_diff_def hypreal_minus hypreal_add)
   404 done
   405 
   406 lemma hypreal_add_minus [simp]: "z + -z = (0::hypreal)"
   407 apply (unfold hypreal_zero_def)
   408 apply (rule_tac z = z in eq_Abs_hypreal)
   409 apply (simp add: hypreal_minus hypreal_add)
   410 done
   411 
   412 lemma hypreal_add_minus_left [simp]: "-z + z = (0::hypreal)"
   413 by (simp add: hypreal_add_commute hypreal_add_minus)
   414 
   415 lemma hypreal_add_left_cancel: "((x::hypreal) + y = x + z) = (y = z)"
   416 apply safe
   417 apply (drule_tac f = "%t.-x + t" in arg_cong)
   418 apply (simp add: hypreal_add_assoc [symmetric])
   419 done
   420 
   421 lemma hypreal_add_right_cancel: "(y + (x::hypreal)= z + x) = (y = z)"
   422 by (simp add: hypreal_add_commute hypreal_add_left_cancel)
   423 
   424 lemma hypreal_add_minus_cancelA [simp]: "z + ((- z) + w) = (w::hypreal)"
   425 by (simp add: hypreal_add_assoc [symmetric])
   426 
   427 lemma hypreal_minus_add_cancelA [simp]: "(-z) + (z + w) = (w::hypreal)"
   428 by (simp add: hypreal_add_assoc [symmetric])
   429 
   430 
   431 subsection{*Hyperreal Multiplication*}
   432 
   433 lemma hypreal_mult_congruent2: 
   434     "congruent2 hyprel (%X Y. hyprel``{%n. X n * Y n})"
   435 apply (unfold congruent2_def, auto, ultra)
   436 done
   437 
   438 lemma hypreal_mult: 
   439   "Abs_hypreal(hyprel``{%n. X n}) * Abs_hypreal(hyprel``{%n. Y n}) =  
   440    Abs_hypreal(hyprel``{%n. X n * Y n})"
   441 apply (unfold hypreal_mult_def)
   442 apply (simp add: UN_equiv_class2 [OF equiv_hyprel hypreal_mult_congruent2])
   443 done
   444 
   445 lemma hypreal_mult_commute: "(z::hypreal) * w = w * z"
   446 apply (rule_tac z = z in eq_Abs_hypreal)
   447 apply (rule_tac z = w in eq_Abs_hypreal)
   448 apply (simp add: hypreal_mult real_mult_ac)
   449 done
   450 
   451 lemma hypreal_mult_assoc: "((z1::hypreal) * z2) * z3 = z1 * (z2 * z3)"
   452 apply (rule_tac z = z1 in eq_Abs_hypreal)
   453 apply (rule_tac z = z2 in eq_Abs_hypreal)
   454 apply (rule_tac z = z3 in eq_Abs_hypreal)
   455 apply (simp add: hypreal_mult real_mult_assoc)
   456 done
   457 
   458 lemma hypreal_mult_left_commute: "(z1::hypreal) * (z2 * z3) = z2 * (z1 * z3)"
   459   apply (rule mk_left_commute [of "op *"])
   460   apply (rule hypreal_mult_assoc)
   461   apply (rule hypreal_mult_commute)
   462   done
   463 
   464 (* hypreal multiplication is an AC operator *)
   465 lemmas hypreal_mult_ac =
   466        hypreal_mult_assoc hypreal_mult_commute hypreal_mult_left_commute
   467 
   468 lemma hypreal_mult_1 [simp]: "(1::hypreal) * z = z"
   469 apply (unfold hypreal_one_def)
   470 apply (rule_tac z = z in eq_Abs_hypreal)
   471 apply (simp add: hypreal_mult)
   472 done
   473 
   474 lemma hypreal_mult_1_right [simp]: "z * (1::hypreal) = z"
   475 by (simp add: hypreal_mult_commute hypreal_mult_1)
   476 
   477 lemma hypreal_mult_0 [simp]: "0 * z = (0::hypreal)"
   478 apply (unfold hypreal_zero_def)
   479 apply (rule_tac z = z in eq_Abs_hypreal)
   480 apply (simp add: hypreal_mult)
   481 done
   482 
   483 lemma hypreal_mult_0_right [simp]: "z * 0 = (0::hypreal)"
   484 by (simp add: hypreal_mult_commute)
   485 
   486 lemma hypreal_minus_mult_eq1: "-(x * y) = -x * (y::hypreal)"
   487 apply (rule_tac z = x in eq_Abs_hypreal)
   488 apply (rule_tac z = y in eq_Abs_hypreal)
   489 apply (auto simp add: hypreal_minus hypreal_mult real_mult_ac real_add_ac)
   490 done
   491 
   492 lemma hypreal_minus_mult_eq2: "-(x * y) = (x::hypreal) * -y"
   493 apply (rule_tac z = x in eq_Abs_hypreal)
   494 apply (rule_tac z = y in eq_Abs_hypreal)
   495 apply (auto simp add: hypreal_minus hypreal_mult real_mult_ac real_add_ac)
   496 done
   497 
   498 (*Pull negations out*)
   499 declare hypreal_minus_mult_eq2 [symmetric, simp] 
   500         hypreal_minus_mult_eq1 [symmetric, simp]
   501 
   502 lemma hypreal_mult_minus_1 [simp]: "(- (1::hypreal)) * z = -z"
   503 by simp
   504 
   505 lemma hypreal_mult_minus_1_right [simp]: "z * (- (1::hypreal)) = -z"
   506 by (subst hypreal_mult_commute, simp)
   507 
   508 lemma hypreal_minus_mult_commute: "(-x) * y = (x::hypreal) * -y"
   509 by auto
   510 
   511 subsection{*A few more theorems *}
   512 
   513 lemma hypreal_add_mult_distrib:
   514      "((z1::hypreal) + z2) * w = (z1 * w) + (z2 * w)"
   515 apply (rule_tac z = z1 in eq_Abs_hypreal)
   516 apply (rule_tac z = z2 in eq_Abs_hypreal)
   517 apply (rule_tac z = w in eq_Abs_hypreal)
   518 apply (simp add: hypreal_mult hypreal_add real_add_mult_distrib)
   519 done
   520 
   521 lemma hypreal_add_mult_distrib2:
   522      "(w::hypreal) * (z1 + z2) = (w * z1) + (w * z2)"
   523 by (simp add: hypreal_mult_commute [of w] hypreal_add_mult_distrib)
   524 
   525 
   526 lemma hypreal_diff_mult_distrib:
   527      "((z1::hypreal) - z2) * w = (z1 * w) - (z2 * w)"
   528 
   529 apply (unfold hypreal_diff_def)
   530 apply (simp add: hypreal_add_mult_distrib)
   531 done
   532 
   533 lemma hypreal_diff_mult_distrib2:
   534      "(w::hypreal) * (z1 - z2) = (w * z1) - (w * z2)"
   535 by (simp add: hypreal_mult_commute [of w] hypreal_diff_mult_distrib)
   536 
   537 (*** one and zero are distinct ***)
   538 lemma hypreal_zero_not_eq_one: "0 \<noteq> (1::hypreal)"
   539 apply (unfold hypreal_zero_def hypreal_one_def)
   540 apply (auto simp add: real_zero_not_eq_one)
   541 done
   542 
   543 
   544 subsection{*Multiplicative Inverse on @{typ hypreal} *}
   545 
   546 lemma hypreal_inverse_congruent: 
   547   "congruent hyprel (%X. hyprel``{%n. if X n = 0 then 0 else inverse(X n)})"
   548 apply (unfold congruent_def)
   549 apply (auto, ultra)
   550 done
   551 
   552 lemma hypreal_inverse: 
   553       "inverse (Abs_hypreal(hyprel``{%n. X n})) =  
   554        Abs_hypreal(hyprel `` {%n. if X n = 0 then 0 else inverse(X n)})"
   555 apply (unfold hypreal_inverse_def)
   556 apply (rule_tac f = Abs_hypreal in arg_cong)
   557 apply (simp add: hyprel_in_hypreal [THEN Abs_hypreal_inverse] 
   558            UN_equiv_class [OF equiv_hyprel hypreal_inverse_congruent])
   559 done
   560 
   561 lemma HYPREAL_INVERSE_ZERO: "inverse 0 = (0::hypreal)"
   562 by (simp add: hypreal_inverse hypreal_zero_def)
   563 
   564 lemma HYPREAL_DIVISION_BY_ZERO: "a / (0::hypreal) = 0"
   565 by (simp add: hypreal_divide_def HYPREAL_INVERSE_ZERO)
   566 
   567 instance hypreal :: division_by_zero
   568 proof
   569   fix x :: hypreal
   570   show "inverse 0 = (0::hypreal)" by (rule HYPREAL_INVERSE_ZERO)
   571   show "x/0 = 0" by (rule HYPREAL_DIVISION_BY_ZERO) 
   572 qed
   573 
   574 
   575 subsection{*Existence of Inverse*}
   576 
   577 lemma hypreal_mult_inverse [simp]: 
   578      "x \<noteq> 0 ==> x*inverse(x) = (1::hypreal)"
   579 apply (unfold hypreal_one_def hypreal_zero_def)
   580 apply (rule_tac z = x in eq_Abs_hypreal)
   581 apply (simp add: hypreal_inverse hypreal_mult)
   582 apply (drule FreeUltrafilterNat_Compl_mem)
   583 apply (blast intro!: real_mult_inv_right FreeUltrafilterNat_subset)
   584 done
   585 
   586 lemma hypreal_mult_inverse_left [simp]:
   587      "x \<noteq> 0 ==> inverse(x)*x = (1::hypreal)"
   588 by (simp add: hypreal_mult_inverse hypreal_mult_commute)
   589 
   590 
   591 subsection{*Theorems for Ordering*}
   592 
   593 text{*TODO: define @{text "\<le>"} as the primitive concept and quickly 
   594 establish membership in class @{text linorder}. Then proofs could be
   595 simplified, since properties of @{text "<"} would be generic.*}
   596 
   597 text{*TODO: The following theorem should be used througout the proofs
   598   as it probably makes many of them more straightforward.*}
   599 lemma hypreal_less: 
   600       "(Abs_hypreal(hyprel``{%n. X n}) < Abs_hypreal(hyprel``{%n. Y n})) =  
   601        ({n. X n < Y n} \<in> FreeUltrafilterNat)"
   602 apply (unfold hypreal_less_def)
   603 apply (auto intro!: lemma_hyprel_refl, ultra)
   604 done
   605 
   606 (* prove introduction and elimination rules for hypreal_less *)
   607 
   608 lemma hypreal_less_not_refl: "~ (R::hypreal) < R"
   609 apply (rule_tac z = R in eq_Abs_hypreal)
   610 apply (auto simp add: hypreal_less_def, ultra)
   611 done
   612 
   613 lemmas hypreal_less_irrefl = hypreal_less_not_refl [THEN notE, standard]
   614 declare hypreal_less_irrefl [elim!]
   615 
   616 lemma hypreal_not_refl2: "!!(x::hypreal). x < y ==> x \<noteq> y"
   617 by (auto simp add: hypreal_less_not_refl)
   618 
   619 lemma hypreal_less_trans: "!!(R1::hypreal). [| R1 < R2; R2 < R3 |] ==> R1 < R3"
   620 apply (rule_tac z = R1 in eq_Abs_hypreal)
   621 apply (rule_tac z = R2 in eq_Abs_hypreal)
   622 apply (rule_tac z = R3 in eq_Abs_hypreal)
   623 apply (auto intro!: exI simp add: hypreal_less_def, ultra)
   624 done
   625 
   626 lemma hypreal_less_asym: "!! (R1::hypreal). [| R1 < R2; R2 < R1 |] ==> P"
   627 apply (drule hypreal_less_trans, assumption)
   628 apply (simp add: hypreal_less_not_refl)
   629 done
   630 
   631 
   632 subsection{*Trichotomy: the hyperreals are Linearly Ordered*}
   633 
   634 lemma lemma_hyprel_0_mem: "\<exists>x. x: hyprel `` {%n. 0}"
   635 apply (unfold hyprel_def)
   636 apply (rule_tac x = "%n. 0" in exI, safe)
   637 apply (auto intro!: FreeUltrafilterNat_Nat_set)
   638 done
   639 
   640 lemma hypreal_trichotomy: "0 <  x | x = 0 | x < (0::hypreal)"
   641 apply (unfold hypreal_zero_def)
   642 apply (rule_tac z = x in eq_Abs_hypreal)
   643 apply (auto simp add: hypreal_less_def)
   644 apply (cut_tac lemma_hyprel_0_mem, erule exE)
   645 apply (drule_tac x = xa in spec)
   646 apply (drule_tac x = x in spec)
   647 apply (cut_tac x = x in lemma_hyprel_refl, auto)
   648 apply (drule_tac x = x in spec)
   649 apply (drule_tac x = xa in spec, auto, ultra)
   650 done
   651 
   652 lemma hypreal_trichotomyE:
   653      "[| (0::hypreal) < x ==> P;  
   654          x = 0 ==> P;  
   655          x < 0 ==> P |] ==> P"
   656 apply (insert hypreal_trichotomy [of x], blast) 
   657 done
   658 
   659 subsection{*More properties of Less Than*}
   660 
   661 lemma hypreal_less_minus_iff: "((x::hypreal) < y) = (0 < y + -x)"
   662 apply (rule_tac z = x in eq_Abs_hypreal)
   663 apply (rule_tac z = y in eq_Abs_hypreal)
   664 apply (auto simp add: hypreal_add hypreal_zero_def hypreal_minus hypreal_less)
   665 done
   666 
   667 lemma hypreal_less_minus_iff2: "((x::hypreal) < y) = (x + -y < 0)"
   668 apply (rule_tac z = x in eq_Abs_hypreal)
   669 apply (rule_tac z = y in eq_Abs_hypreal)
   670 apply (auto simp add: hypreal_add hypreal_zero_def hypreal_minus hypreal_less)
   671 done
   672 
   673 lemma hypreal_eq_minus_iff: "((x::hypreal) = y) = (x + - y = 0)"
   674 apply auto
   675 apply (rule_tac x1 = "-y" in hypreal_add_right_cancel [THEN iffD1], auto)
   676 done
   677 
   678 lemma hypreal_eq_minus_iff2: "((x::hypreal) = y) = (0 = y + - x)"
   679 apply auto
   680 apply (rule_tac x1 = "-x" in hypreal_add_right_cancel [THEN iffD1], auto)
   681 done
   682 
   683 
   684 subsection{*Linearity*}
   685 
   686 lemma hypreal_linear: "(x::hypreal) < y | x = y | y < x"
   687 apply (subst hypreal_eq_minus_iff2)
   688 apply (rule_tac x1 = x in hypreal_less_minus_iff [THEN ssubst])
   689 apply (rule_tac x1 = y in hypreal_less_minus_iff2 [THEN ssubst])
   690 apply (rule hypreal_trichotomyE, auto)
   691 done
   692 
   693 lemma hypreal_neq_iff: "((w::hypreal) \<noteq> z) = (w<z | z<w)"
   694 by (cut_tac hypreal_linear, blast)
   695 
   696 lemma hypreal_linear_less2: "!!(x::hypreal). [| x < y ==> P;  x = y ==> P;  
   697            y < x ==> P |] ==> P"
   698 apply (cut_tac x = x and y = y in hypreal_linear, auto)
   699 done
   700 
   701 
   702 subsection{*Properties of The @{text "\<le>"} Relation*}
   703 
   704 lemma hypreal_le: 
   705       "(Abs_hypreal(hyprel``{%n. X n}) <=  
   706             Abs_hypreal(hyprel``{%n. Y n})) =  
   707        ({n. X n <= Y n} \<in> FreeUltrafilterNat)"
   708 apply (unfold hypreal_le_def real_le_def)
   709 apply (auto simp add: hypreal_less)
   710 apply (ultra+)
   711 done
   712 
   713 lemma hypreal_leI: 
   714      "~(w < z) ==> z <= (w::hypreal)"
   715 apply (unfold hypreal_le_def, assumption)
   716 done
   717 
   718 lemma hypreal_leD: 
   719       "z<=w ==> ~(w<(z::hypreal))"
   720 apply (unfold hypreal_le_def, assumption)
   721 done
   722 
   723 lemma hypreal_less_le_iff: "(~(w < z)) = (z <= (w::hypreal))"
   724 by (fast intro!: hypreal_leI hypreal_leD)
   725 
   726 lemma not_hypreal_leE: "~ z <= w ==> w<(z::hypreal)"
   727 by (unfold hypreal_le_def, fast)
   728 
   729 lemma hypreal_le_imp_less_or_eq: "!!(x::hypreal). x <= y ==> x < y | x = y"
   730 apply (unfold hypreal_le_def)
   731 apply (cut_tac hypreal_linear)
   732 apply (fast elim: hypreal_less_irrefl hypreal_less_asym)
   733 done
   734 
   735 lemma hypreal_less_or_eq_imp_le: "z<w | z=w ==> z <=(w::hypreal)"
   736 apply (unfold hypreal_le_def)
   737 apply (cut_tac hypreal_linear)
   738 apply (fast elim: hypreal_less_irrefl hypreal_less_asym)
   739 done
   740 
   741 lemma hypreal_le_eq_less_or_eq: "(x <= (y::hypreal)) = (x < y | x=y)"
   742 by (blast intro!: hypreal_less_or_eq_imp_le dest: hypreal_le_imp_less_or_eq) 
   743 
   744 lemmas hypreal_le_less = hypreal_le_eq_less_or_eq
   745 
   746 lemma hypreal_le_refl: "w <= (w::hypreal)"
   747 by (simp add: hypreal_le_eq_less_or_eq)
   748 
   749 (* Axiom 'linorder_linear' of class 'linorder': *)
   750 lemma hypreal_le_linear: "(z::hypreal) <= w | w <= z"
   751 apply (simp add: hypreal_le_less)
   752 apply (cut_tac hypreal_linear, blast)
   753 done
   754 
   755 lemma hypreal_le_trans: "[| i <= j; j <= k |] ==> i <= (k::hypreal)"
   756 apply (drule hypreal_le_imp_less_or_eq) 
   757 apply (drule hypreal_le_imp_less_or_eq) 
   758 apply (rule hypreal_less_or_eq_imp_le) 
   759 apply (blast intro: hypreal_less_trans) 
   760 done
   761 
   762 lemma hypreal_le_anti_sym: "[| z <= w; w <= z |] ==> z = (w::hypreal)"
   763 apply (drule hypreal_le_imp_less_or_eq) 
   764 apply (drule hypreal_le_imp_less_or_eq) 
   765 apply (fast elim: hypreal_less_irrefl hypreal_less_asym)
   766 done
   767 
   768 (* Axiom 'order_less_le' of class 'order': *)
   769 lemma hypreal_less_le: "((w::hypreal) < z) = (w <= z & w \<noteq> z)"
   770 apply (simp add: hypreal_le_def hypreal_neq_iff)
   771 apply (blast intro: hypreal_less_asym)
   772 done
   773 
   774 instance hypreal :: order
   775   by (intro_classes,
   776       (assumption | 
   777        rule hypreal_le_refl hypreal_le_trans hypreal_le_anti_sym
   778             hypreal_less_le)+)
   779 
   780 instance hypreal :: linorder 
   781   by (intro_classes, rule hypreal_le_linear)
   782 
   783 lemma hypreal_minus_zero_less_iff [simp]: "(0 < -R) = (R < (0::hypreal))"
   784 apply (rule_tac z = R in eq_Abs_hypreal)
   785 apply (auto simp add: hypreal_zero_def hypreal_less hypreal_minus)
   786 done
   787 
   788 lemma hypreal_minus_zero_less_iff2 [simp]: "(-R < 0) = ((0::hypreal) < R)"
   789 apply (rule_tac z = R in eq_Abs_hypreal)
   790 apply (auto simp add: hypreal_zero_def hypreal_less hypreal_minus)
   791 done
   792 
   793 lemma hypreal_minus_zero_le_iff [simp]: "((0::hypreal) <= -r) = (r <= 0)"
   794 apply (unfold hypreal_le_def)
   795 apply (simp add: hypreal_minus_zero_less_iff2)
   796 done
   797 
   798 lemma hypreal_minus_zero_le_iff2 [simp]: "(-r <= (0::hypreal)) = (0 <= r)"
   799 apply (unfold hypreal_le_def)
   800 apply (simp add: hypreal_minus_zero_less_iff2)
   801 done
   802 
   803 
   804 lemma hypreal_self_eq_minus_self_zero: "x = -x ==> x = (0::hypreal)"
   805 apply (rule_tac z = x in eq_Abs_hypreal)
   806 apply (auto simp add: hypreal_minus hypreal_zero_def, ultra)
   807 done
   808 
   809 lemma hypreal_add_self_zero_cancel [simp]: "(x + x = 0) = (x = (0::hypreal))"
   810 apply (rule_tac z = x in eq_Abs_hypreal)
   811 apply (auto simp add: hypreal_add hypreal_zero_def)
   812 done
   813 
   814 lemma hypreal_add_self_zero_cancel2 [simp]:
   815      "(x + x + y = y) = (x = (0::hypreal))"
   816 apply auto
   817 apply (drule hypreal_eq_minus_iff [THEN iffD1])
   818 apply (auto simp add: hypreal_add_assoc hypreal_self_eq_minus_self_zero)
   819 done
   820 
   821 lemma hypreal_minus_eq_swap: "(b = -a) = (-b = (a::hypreal))"
   822 by auto
   823 
   824 lemma hypreal_minus_eq_cancel [simp]: "(-b = -a) = (b = (a::hypreal))"
   825 by (simp add: hypreal_minus_eq_swap)
   826 
   827 lemma hypreal_add_less_mono1: "(A::hypreal) < B ==> A + C < B + C"
   828 apply (rule_tac z = A in eq_Abs_hypreal)
   829 apply (rule_tac z = B in eq_Abs_hypreal)
   830 apply (rule_tac z = C in eq_Abs_hypreal)
   831 apply (auto intro!: exI simp add: hypreal_less_def hypreal_add, ultra)
   832 done
   833 
   834 lemma hypreal_mult_order: "[| 0 < x; 0 < y |] ==> (0::hypreal) < x * y"
   835 apply (unfold hypreal_zero_def)
   836 apply (rule_tac z = x in eq_Abs_hypreal)
   837 apply (rule_tac z = y in eq_Abs_hypreal)
   838 apply (auto intro!: exI simp add: hypreal_less_def hypreal_mult, ultra)
   839 apply (auto intro: real_mult_order)
   840 done
   841 
   842 lemma hypreal_add_left_le_mono1: "(q1::hypreal) \<le> q2  ==> x + q1 \<le> x + q2"
   843 apply (drule order_le_imp_less_or_eq)
   844 apply (auto intro: order_less_imp_le hypreal_add_less_mono1 simp add: hypreal_add_commute)
   845 done
   846 
   847 lemma hypreal_mult_less_mono1: "[| (0::hypreal) < z; x < y |] ==> x*z < y*z"
   848 apply (rotate_tac 1)
   849 apply (drule hypreal_less_minus_iff [THEN iffD1])
   850 apply (rule hypreal_less_minus_iff [THEN iffD2])
   851 apply (drule hypreal_mult_order, assumption)
   852 apply (simp add: hypreal_add_mult_distrib2 hypreal_mult_commute)
   853 done
   854 
   855 lemma hypreal_mult_less_mono2: "[| (0::hypreal)<z; x<y |] ==> z*x<z*y"
   856 apply (simp (no_asm_simp) add: hypreal_mult_commute hypreal_mult_less_mono1)
   857 done
   858 
   859 subsection{*The Hyperreals Form an Ordered Field*}
   860 
   861 instance hypreal :: inverse ..
   862 
   863 instance hypreal :: ordered_field
   864 proof
   865   fix x y z :: hypreal
   866   show "(x + y) + z = x + (y + z)" by (rule hypreal_add_assoc)
   867   show "x + y = y + x" by (rule hypreal_add_commute)
   868   show "0 + x = x" by simp
   869   show "- x + x = 0" by simp
   870   show "x - y = x + (-y)" by (simp add: hypreal_diff_def)
   871   show "(x * y) * z = x * (y * z)" by (rule hypreal_mult_assoc)
   872   show "x * y = y * x" by (rule hypreal_mult_commute)
   873   show "1 * x = x" by simp
   874   show "(x + y) * z = x * z + y * z" by (simp add: hypreal_add_mult_distrib)
   875   show "0 \<noteq> (1::hypreal)" by (rule hypreal_zero_not_eq_one)
   876   show "x \<le> y ==> z + x \<le> z + y" by (rule hypreal_add_left_le_mono1)
   877   show "x < y ==> 0 < z ==> z * x < z * y" by (simp add: hypreal_mult_less_mono2)
   878   show "\<bar>x\<bar> = (if x < 0 then -x else x)"
   879     by (auto dest: order_le_less_trans simp add: hrabs_def linorder_not_le)
   880   show "x \<noteq> 0 ==> inverse x * x = 1" by simp
   881   show "y \<noteq> 0 ==> x / y = x * inverse y" by (simp add: hypreal_divide_def)
   882 qed
   883 
   884 lemma hypreal_minus_add_distrib [simp]: "-(x + (y::hypreal)) = -x + -y"
   885   by (rule Ring_and_Field.minus_add_distrib)
   886 
   887 (*Used ONCE: in NSA.ML*)
   888 lemma hypreal_minus_distrib1: "-(y + -(x::hypreal)) = x + -y"
   889 by (simp add: hypreal_add_commute)
   890 
   891 (*Used ONCE: in Lim.ML*)
   892 lemma hypreal_eq_minus_iff3: "(x = y + z) = (x + -z = (y::hypreal))"
   893 by (auto simp add: hypreal_add_assoc)
   894 
   895 lemma hypreal_not_eq_minus_iff: "(x \<noteq> a) = (x + -a \<noteq> (0::hypreal))"
   896 by (auto dest: hypreal_eq_minus_iff [THEN iffD2])
   897 
   898 lemma hypreal_mult_left_cancel: "(c::hypreal) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
   899 apply auto
   900 done
   901     
   902 lemma hypreal_mult_right_cancel: "(c::hypreal) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
   903 apply auto
   904 done
   905 
   906 lemma hypreal_inverse_not_zero: "x \<noteq> 0 ==> inverse (x::hypreal) \<noteq> 0"
   907   by (rule Ring_and_Field.nonzero_imp_inverse_nonzero)
   908 
   909 lemma hypreal_mult_not_0: "[| x \<noteq> 0; y \<noteq> 0 |] ==> x * y \<noteq> (0::hypreal)"
   910 by simp
   911 
   912 lemma hypreal_minus_inverse: "inverse(-x) = -inverse(x::hypreal)"
   913   by (rule Ring_and_Field.inverse_minus_eq)
   914 
   915 lemma hypreal_inverse_distrib: "inverse(x*y) = inverse(x)*inverse(y::hypreal)"
   916   by (rule Ring_and_Field.inverse_mult_distrib)
   917 
   918 
   919 subsection{* Division lemmas *}
   920 
   921 lemma hypreal_divide_one: "x/(1::hypreal) = x"
   922 by (simp add: hypreal_divide_def)
   923 
   924 
   925 (** As with multiplication, pull minus signs OUT of the / operator **)
   926 
   927 lemma hypreal_add_divide_distrib: "(x+y)/(z::hypreal) = x/z + y/z"
   928   by (rule Ring_and_Field.add_divide_distrib)
   929 
   930 lemma hypreal_inverse_add:
   931      "[|(x::hypreal) \<noteq> 0;  y \<noteq> 0 |]   
   932       ==> inverse(x) + inverse(y) = (x + y)*inverse(x*y)"
   933 by (simp add: Ring_and_Field.inverse_add mult_assoc)
   934 
   935 
   936 subsection{*@{term hypreal_of_real} Preserves Field and Order Properties*}
   937 
   938 lemma hypreal_of_real_add [simp]: 
   939      "hypreal_of_real (z1 + z2) = hypreal_of_real z1 + hypreal_of_real z2"
   940 apply (unfold hypreal_of_real_def)
   941 apply (simp add: hypreal_add hypreal_add_mult_distrib)
   942 done
   943 
   944 lemma hypreal_of_real_mult [simp]: 
   945      "hypreal_of_real (z1 * z2) = hypreal_of_real z1 * hypreal_of_real z2"
   946 apply (unfold hypreal_of_real_def)
   947 apply (simp add: hypreal_mult hypreal_add_mult_distrib2)
   948 done
   949 
   950 lemma hypreal_of_real_less_iff [simp]: 
   951      "(hypreal_of_real z1 <  hypreal_of_real z2) = (z1 < z2)"
   952 apply (unfold hypreal_less_def hypreal_of_real_def, auto)
   953 apply (rule_tac [2] x = "%n. z1" in exI, safe)
   954 apply (rule_tac [3] x = "%n. z2" in exI, auto)
   955 apply (rule FreeUltrafilterNat_P, ultra)
   956 done
   957 
   958 lemma hypreal_of_real_le_iff [simp]: 
   959      "(hypreal_of_real z1 <= hypreal_of_real z2) = (z1 <= z2)"
   960 apply (unfold hypreal_le_def real_le_def, auto)
   961 done
   962 
   963 lemma hypreal_of_real_eq_iff [simp]:
   964      "(hypreal_of_real z1 = hypreal_of_real z2) = (z1 = z2)"
   965 by (force intro: order_antisym hypreal_of_real_le_iff [THEN iffD1])
   966 
   967 lemma hypreal_of_real_minus [simp]:
   968      "hypreal_of_real (-r) = - hypreal_of_real  r"
   969 apply (unfold hypreal_of_real_def)
   970 apply (auto simp add: hypreal_minus)
   971 done
   972 
   973 lemma hypreal_of_real_one [simp]: "hypreal_of_real 1 = (1::hypreal)"
   974 by (unfold hypreal_of_real_def hypreal_one_def, simp)
   975 
   976 lemma hypreal_of_real_zero [simp]: "hypreal_of_real 0 = 0"
   977 by (unfold hypreal_of_real_def hypreal_zero_def, simp)
   978 
   979 lemma hypreal_of_real_zero_iff: "(hypreal_of_real r = 0) = (r = 0)"
   980 by (auto intro: FreeUltrafilterNat_P simp add: hypreal_of_real_def hypreal_zero_def FreeUltrafilterNat_Nat_set)
   981 
   982 lemma hypreal_of_real_inverse [simp]:
   983      "hypreal_of_real (inverse r) = inverse (hypreal_of_real r)"
   984 apply (case_tac "r=0")
   985 apply (simp add: DIVISION_BY_ZERO INVERSE_ZERO HYPREAL_INVERSE_ZERO)
   986 apply (rule_tac c1 = "hypreal_of_real r" in hypreal_mult_left_cancel [THEN iffD1])
   987 apply (auto simp add: hypreal_of_real_zero_iff hypreal_of_real_mult [symmetric])
   988 done
   989 
   990 lemma hypreal_of_real_divide [simp]:
   991      "hypreal_of_real (z1 / z2) = hypreal_of_real z1 / hypreal_of_real z2"
   992 by (simp add: hypreal_divide_def real_divide_def)
   993 
   994 
   995 subsection{*Misc Others*}
   996 
   997 lemma hypreal_zero_num: "0 = Abs_hypreal (hyprel `` {%n. 0})"
   998 by (simp add: hypreal_zero_def [THEN meta_eq_to_obj_eq, symmetric])
   999 
  1000 lemma hypreal_one_num: "1 = Abs_hypreal (hyprel `` {%n. 1})"
  1001 by (simp add: hypreal_one_def [THEN meta_eq_to_obj_eq, symmetric])
  1002 
  1003 lemma hypreal_omega_gt_zero [simp]: "0 < omega"
  1004 apply (unfold omega_def)
  1005 apply (auto simp add: hypreal_less hypreal_zero_num)
  1006 done
  1007 
  1008 
  1009 lemma hypreal_hrabs:
  1010      "abs (Abs_hypreal (hyprel `` {X})) = 
  1011       Abs_hypreal(hyprel `` {%n. abs (X n)})"
  1012 apply (auto simp add: hrabs_def hypreal_zero_def hypreal_le hypreal_minus)
  1013 apply (ultra, arith)+
  1014 done
  1015 
  1016 ML
  1017 {*
  1018 val hrabs_def = thm "hrabs_def";
  1019 val hypreal_hrabs = thm "hypreal_hrabs";
  1020 
  1021 val hypreal_zero_def = thm "hypreal_zero_def";
  1022 val hypreal_one_def = thm "hypreal_one_def";
  1023 val hypreal_minus_def = thm "hypreal_minus_def";
  1024 val hypreal_diff_def = thm "hypreal_diff_def";
  1025 val hypreal_inverse_def = thm "hypreal_inverse_def";
  1026 val hypreal_divide_def = thm "hypreal_divide_def";
  1027 val hypreal_of_real_def = thm "hypreal_of_real_def";
  1028 val omega_def = thm "omega_def";
  1029 val epsilon_def = thm "epsilon_def";
  1030 val hypreal_add_def = thm "hypreal_add_def";
  1031 val hypreal_mult_def = thm "hypreal_mult_def";
  1032 val hypreal_less_def = thm "hypreal_less_def";
  1033 val hypreal_le_def = thm "hypreal_le_def";
  1034 
  1035 val finite_exhausts = thm "finite_exhausts";
  1036 val finite_not_covers = thm "finite_not_covers";
  1037 val not_finite_nat = thm "not_finite_nat";
  1038 val FreeUltrafilterNat_Ex = thm "FreeUltrafilterNat_Ex";
  1039 val FreeUltrafilterNat_mem = thm "FreeUltrafilterNat_mem";
  1040 val FreeUltrafilterNat_finite = thm "FreeUltrafilterNat_finite";
  1041 val FreeUltrafilterNat_not_finite = thm "FreeUltrafilterNat_not_finite";
  1042 val FreeUltrafilterNat_empty = thm "FreeUltrafilterNat_empty";
  1043 val FreeUltrafilterNat_Int = thm "FreeUltrafilterNat_Int";
  1044 val FreeUltrafilterNat_subset = thm "FreeUltrafilterNat_subset";
  1045 val FreeUltrafilterNat_Compl = thm "FreeUltrafilterNat_Compl";
  1046 val FreeUltrafilterNat_Compl_mem = thm "FreeUltrafilterNat_Compl_mem";
  1047 val FreeUltrafilterNat_Compl_iff1 = thm "FreeUltrafilterNat_Compl_iff1";
  1048 val FreeUltrafilterNat_Compl_iff2 = thm "FreeUltrafilterNat_Compl_iff2";
  1049 val FreeUltrafilterNat_UNIV = thm "FreeUltrafilterNat_UNIV";
  1050 val FreeUltrafilterNat_Nat_set = thm "FreeUltrafilterNat_Nat_set";
  1051 val FreeUltrafilterNat_Nat_set_refl = thm "FreeUltrafilterNat_Nat_set_refl";
  1052 val FreeUltrafilterNat_P = thm "FreeUltrafilterNat_P";
  1053 val FreeUltrafilterNat_Ex_P = thm "FreeUltrafilterNat_Ex_P";
  1054 val FreeUltrafilterNat_all = thm "FreeUltrafilterNat_all";
  1055 val FreeUltrafilterNat_Un = thm "FreeUltrafilterNat_Un";
  1056 val hyprel_iff = thm "hyprel_iff";
  1057 val hyprel_refl = thm "hyprel_refl";
  1058 val hyprel_sym = thm "hyprel_sym";
  1059 val hyprel_trans = thm "hyprel_trans";
  1060 val equiv_hyprel = thm "equiv_hyprel";
  1061 val hyprel_in_hypreal = thm "hyprel_in_hypreal";
  1062 val Abs_hypreal_inverse = thm "Abs_hypreal_inverse";
  1063 val inj_on_Abs_hypreal = thm "inj_on_Abs_hypreal";
  1064 val inj_Rep_hypreal = thm "inj_Rep_hypreal";
  1065 val lemma_hyprel_refl = thm "lemma_hyprel_refl";
  1066 val hypreal_empty_not_mem = thm "hypreal_empty_not_mem";
  1067 val Rep_hypreal_nonempty = thm "Rep_hypreal_nonempty";
  1068 val inj_hypreal_of_real = thm "inj_hypreal_of_real";
  1069 val eq_Abs_hypreal = thm "eq_Abs_hypreal";
  1070 val hypreal_minus_congruent = thm "hypreal_minus_congruent";
  1071 val hypreal_minus = thm "hypreal_minus";
  1072 val hypreal_minus_minus = thm "hypreal_minus_minus";
  1073 val inj_hypreal_minus = thm "inj_hypreal_minus";
  1074 val hypreal_minus_zero = thm "hypreal_minus_zero";
  1075 val hypreal_minus_zero_iff = thm "hypreal_minus_zero_iff";
  1076 val hypreal_add_congruent2 = thm "hypreal_add_congruent2";
  1077 val hypreal_add = thm "hypreal_add";
  1078 val hypreal_diff = thm "hypreal_diff";
  1079 val hypreal_add_commute = thm "hypreal_add_commute";
  1080 val hypreal_add_assoc = thm "hypreal_add_assoc";
  1081 val hypreal_add_left_commute = thm "hypreal_add_left_commute";
  1082 val hypreal_add_zero_left = thm "hypreal_add_zero_left";
  1083 val hypreal_add_zero_right = thm "hypreal_add_zero_right";
  1084 val hypreal_add_minus = thm "hypreal_add_minus";
  1085 val hypreal_add_minus_left = thm "hypreal_add_minus_left";
  1086 val hypreal_minus_add_distrib = thm "hypreal_minus_add_distrib";
  1087 val hypreal_minus_distrib1 = thm "hypreal_minus_distrib1";
  1088 val hypreal_add_left_cancel = thm "hypreal_add_left_cancel";
  1089 val hypreal_add_right_cancel = thm "hypreal_add_right_cancel";
  1090 val hypreal_add_minus_cancelA = thm "hypreal_add_minus_cancelA";
  1091 val hypreal_minus_add_cancelA = thm "hypreal_minus_add_cancelA";
  1092 val hypreal_mult_congruent2 = thm "hypreal_mult_congruent2";
  1093 val hypreal_mult = thm "hypreal_mult";
  1094 val hypreal_mult_commute = thm "hypreal_mult_commute";
  1095 val hypreal_mult_assoc = thm "hypreal_mult_assoc";
  1096 val hypreal_mult_left_commute = thm "hypreal_mult_left_commute";
  1097 val hypreal_mult_1 = thm "hypreal_mult_1";
  1098 val hypreal_mult_1_right = thm "hypreal_mult_1_right";
  1099 val hypreal_mult_0 = thm "hypreal_mult_0";
  1100 val hypreal_mult_0_right = thm "hypreal_mult_0_right";
  1101 val hypreal_minus_mult_eq1 = thm "hypreal_minus_mult_eq1";
  1102 val hypreal_minus_mult_eq2 = thm "hypreal_minus_mult_eq2";
  1103 val hypreal_mult_minus_1 = thm "hypreal_mult_minus_1";
  1104 val hypreal_mult_minus_1_right = thm "hypreal_mult_minus_1_right";
  1105 val hypreal_minus_mult_commute = thm "hypreal_minus_mult_commute";
  1106 val hypreal_add_mult_distrib = thm "hypreal_add_mult_distrib";
  1107 val hypreal_add_mult_distrib2 = thm "hypreal_add_mult_distrib2";
  1108 val hypreal_diff_mult_distrib = thm "hypreal_diff_mult_distrib";
  1109 val hypreal_diff_mult_distrib2 = thm "hypreal_diff_mult_distrib2";
  1110 val hypreal_zero_not_eq_one = thm "hypreal_zero_not_eq_one";
  1111 val hypreal_inverse_congruent = thm "hypreal_inverse_congruent";
  1112 val hypreal_inverse = thm "hypreal_inverse";
  1113 val HYPREAL_INVERSE_ZERO = thm "HYPREAL_INVERSE_ZERO";
  1114 val HYPREAL_DIVISION_BY_ZERO = thm "HYPREAL_DIVISION_BY_ZERO";
  1115 val hypreal_mult_inverse = thm "hypreal_mult_inverse";
  1116 val hypreal_mult_inverse_left = thm "hypreal_mult_inverse_left";
  1117 val hypreal_mult_left_cancel = thm "hypreal_mult_left_cancel";
  1118 val hypreal_mult_right_cancel = thm "hypreal_mult_right_cancel";
  1119 val hypreal_inverse_not_zero = thm "hypreal_inverse_not_zero";
  1120 val hypreal_mult_not_0 = thm "hypreal_mult_not_0";
  1121 val hypreal_minus_inverse = thm "hypreal_minus_inverse";
  1122 val hypreal_inverse_distrib = thm "hypreal_inverse_distrib";
  1123 val hypreal_less_not_refl = thm "hypreal_less_not_refl";
  1124 val hypreal_not_refl2 = thm "hypreal_not_refl2";
  1125 val hypreal_less_trans = thm "hypreal_less_trans";
  1126 val hypreal_less_asym = thm "hypreal_less_asym";
  1127 val hypreal_less = thm "hypreal_less";
  1128 val hypreal_trichotomy = thm "hypreal_trichotomy";
  1129 val hypreal_less_minus_iff = thm "hypreal_less_minus_iff";
  1130 val hypreal_less_minus_iff2 = thm "hypreal_less_minus_iff2";
  1131 val hypreal_eq_minus_iff = thm "hypreal_eq_minus_iff";
  1132 val hypreal_eq_minus_iff2 = thm "hypreal_eq_minus_iff2";
  1133 val hypreal_eq_minus_iff3 = thm "hypreal_eq_minus_iff3";
  1134 val hypreal_not_eq_minus_iff = thm "hypreal_not_eq_minus_iff";
  1135 val hypreal_linear = thm "hypreal_linear";
  1136 val hypreal_neq_iff = thm "hypreal_neq_iff";
  1137 val hypreal_linear_less2 = thm "hypreal_linear_less2";
  1138 val hypreal_le = thm "hypreal_le";
  1139 val hypreal_leI = thm "hypreal_leI";
  1140 val hypreal_leD = thm "hypreal_leD";
  1141 val hypreal_less_le_iff = thm "hypreal_less_le_iff";
  1142 val not_hypreal_leE = thm "not_hypreal_leE";
  1143 val hypreal_le_imp_less_or_eq = thm "hypreal_le_imp_less_or_eq";
  1144 val hypreal_less_or_eq_imp_le = thm "hypreal_less_or_eq_imp_le";
  1145 val hypreal_le_eq_less_or_eq = thm "hypreal_le_eq_less_or_eq";
  1146 val hypreal_le_refl = thm "hypreal_le_refl";
  1147 val hypreal_le_linear = thm "hypreal_le_linear";
  1148 val hypreal_le_trans = thm "hypreal_le_trans";
  1149 val hypreal_le_anti_sym = thm "hypreal_le_anti_sym";
  1150 val hypreal_less_le = thm "hypreal_less_le";
  1151 val hypreal_minus_zero_less_iff = thm "hypreal_minus_zero_less_iff";
  1152 val hypreal_minus_zero_less_iff2 = thm "hypreal_minus_zero_less_iff2";
  1153 val hypreal_minus_zero_le_iff = thm "hypreal_minus_zero_le_iff";
  1154 val hypreal_minus_zero_le_iff2 = thm "hypreal_minus_zero_le_iff2";
  1155 val hypreal_of_real_add = thm "hypreal_of_real_add";
  1156 val hypreal_of_real_mult = thm "hypreal_of_real_mult";
  1157 val hypreal_of_real_less_iff = thm "hypreal_of_real_less_iff";
  1158 val hypreal_of_real_le_iff = thm "hypreal_of_real_le_iff";
  1159 val hypreal_of_real_eq_iff = thm "hypreal_of_real_eq_iff";
  1160 val hypreal_of_real_minus = thm "hypreal_of_real_minus";
  1161 val hypreal_of_real_one = thm "hypreal_of_real_one";
  1162 val hypreal_of_real_zero = thm "hypreal_of_real_zero";
  1163 val hypreal_of_real_zero_iff = thm "hypreal_of_real_zero_iff";
  1164 val hypreal_of_real_inverse = thm "hypreal_of_real_inverse";
  1165 val hypreal_of_real_divide = thm "hypreal_of_real_divide";
  1166 val hypreal_divide_one = thm "hypreal_divide_one";
  1167 val hypreal_add_divide_distrib = thm "hypreal_add_divide_distrib";
  1168 val hypreal_inverse_add = thm "hypreal_inverse_add";
  1169 val hypreal_self_eq_minus_self_zero = thm "hypreal_self_eq_minus_self_zero";
  1170 val hypreal_add_self_zero_cancel = thm "hypreal_add_self_zero_cancel";
  1171 val hypreal_add_self_zero_cancel2 = thm "hypreal_add_self_zero_cancel2";
  1172 val hypreal_minus_eq_swap = thm "hypreal_minus_eq_swap";
  1173 val hypreal_minus_eq_cancel = thm "hypreal_minus_eq_cancel";
  1174 val hypreal_zero_num = thm "hypreal_zero_num";
  1175 val hypreal_one_num = thm "hypreal_one_num";
  1176 val hypreal_omega_gt_zero = thm "hypreal_omega_gt_zero";
  1177 *}
  1178 
  1179 
  1180 end