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