src/HOL/Real/Hyperreal/HyperDef.ML
author paulson
Wed Jun 07 12:14:18 2000 +0200 (2000-06-07)
changeset 9043 ca761fe227d8
parent 9013 9dd0274f76af
child 9055 f020e00c6304
permissions -rw-r--r--
First round of changes, towards installation of simprocs

* replacing 0r by (0::real0
* better rewriting, especially pulling out signs in (-x)*y = - (x*y), etc.
paulson@7218
     1
(*  Title       : HOL/Real/Hyperreal/Hyper.ML
paulson@7218
     2
    ID          : $Id$
paulson@7218
     3
    Author      : Jacques D. Fleuriot
paulson@7218
     4
    Copyright   : 1998  University of Cambridge
paulson@7218
     5
    Description : Ultrapower construction of hyperreals
paulson@7218
     6
*) 
paulson@7218
     7
paulson@7218
     8
(*------------------------------------------------------------------------
paulson@7218
     9
             Proof that the set of naturals is not finite
paulson@7218
    10
 ------------------------------------------------------------------------*)
paulson@7218
    11
paulson@7218
    12
(*** based on James' proof that the set of naturals is not finite ***)
paulson@7218
    13
Goal "finite (A::nat set) --> (? n. !m. Suc (n + m) ~: A)";
paulson@7218
    14
by (rtac impI 1);
paulson@7218
    15
by (eres_inst_tac [("F","A")] finite_induct 1);
paulson@7218
    16
by (Blast_tac 1 THEN etac exE 1);
paulson@7218
    17
by (res_inst_tac [("x","n + x")] exI 1);
paulson@7218
    18
by (rtac allI 1 THEN eres_inst_tac [("x","x + m")] allE 1);
paulson@7218
    19
by (auto_tac (claset(), simpset() addsimps add_ac));
paulson@7218
    20
by (auto_tac (claset(),
paulson@7218
    21
	      simpset() addsimps [add_assoc RS sym,
paulson@7218
    22
				  less_add_Suc2 RS less_not_refl2]));
paulson@7218
    23
qed_spec_mp "finite_exhausts";
paulson@7218
    24
paulson@7218
    25
Goal "finite (A :: nat set) --> (? n. n ~:A)";
paulson@7218
    26
by (rtac impI 1 THEN dtac finite_exhausts 1);
paulson@7218
    27
by (Blast_tac 1);
paulson@7218
    28
qed_spec_mp "finite_not_covers";
paulson@7218
    29
paulson@7218
    30
Goal "~ finite(UNIV:: nat set)";
paulson@7218
    31
by (fast_tac (claset() addSDs [finite_exhausts]) 1);
paulson@7218
    32
qed "not_finite_nat";
paulson@7218
    33
paulson@7218
    34
(*------------------------------------------------------------------------
paulson@7218
    35
   Existence of free ultrafilter over the naturals and proof of various 
paulson@7218
    36
   properties of the FreeUltrafilterNat- an arbitrary free ultrafilter
paulson@7218
    37
 ------------------------------------------------------------------------*)
paulson@7218
    38
paulson@7218
    39
Goal "EX U. U: FreeUltrafilter (UNIV::nat set)";
paulson@7218
    40
by (rtac (not_finite_nat RS FreeUltrafilter_Ex) 1);
paulson@7218
    41
qed "FreeUltrafilterNat_Ex";
paulson@7218
    42
paulson@7218
    43
Goalw [FreeUltrafilterNat_def] 
paulson@7218
    44
     "FreeUltrafilterNat: FreeUltrafilter(UNIV:: nat set)";
paulson@7218
    45
by (rtac (FreeUltrafilterNat_Ex RS exE) 1);
paulson@7218
    46
by (rtac selectI2 1 THEN ALLGOALS(assume_tac));
paulson@7218
    47
qed "FreeUltrafilterNat_mem";
paulson@7218
    48
Addsimps [FreeUltrafilterNat_mem];
paulson@7218
    49
paulson@7218
    50
Goalw [FreeUltrafilterNat_def] "finite x ==> x ~: FreeUltrafilterNat";
paulson@7218
    51
by (rtac (FreeUltrafilterNat_Ex RS exE) 1);
paulson@7218
    52
by (rtac selectI2 1 THEN assume_tac 1);
paulson@7218
    53
by (blast_tac (claset() addDs [mem_FreeUltrafiltersetD1]) 1);
paulson@7218
    54
qed "FreeUltrafilterNat_finite";
paulson@7218
    55
paulson@7218
    56
Goal "x: FreeUltrafilterNat ==> ~ finite x";
paulson@7218
    57
by (blast_tac (claset() addDs [FreeUltrafilterNat_finite]) 1);
paulson@7218
    58
qed "FreeUltrafilterNat_not_finite";
paulson@7218
    59
paulson@7218
    60
Goalw [FreeUltrafilterNat_def] "{} ~: FreeUltrafilterNat";
paulson@7218
    61
by (rtac (FreeUltrafilterNat_Ex RS exE) 1);
paulson@7218
    62
by (rtac selectI2 1 THEN assume_tac 1);
paulson@7218
    63
by (blast_tac (claset() addDs [FreeUltrafilter_Ultrafilter,
paulson@7218
    64
			       Ultrafilter_Filter,Filter_empty_not_mem]) 1);
paulson@7218
    65
qed "FreeUltrafilterNat_empty";
paulson@7218
    66
Addsimps [FreeUltrafilterNat_empty];
paulson@7218
    67
paulson@7218
    68
Goal "[| X: FreeUltrafilterNat;  Y: FreeUltrafilterNat |]  \
paulson@7218
    69
\     ==> X Int Y : FreeUltrafilterNat";
paulson@7218
    70
by (cut_facts_tac [FreeUltrafilterNat_mem] 1);
paulson@7218
    71
by (blast_tac (claset() addDs [FreeUltrafilter_Ultrafilter,
paulson@7218
    72
			       Ultrafilter_Filter,mem_FiltersetD1]) 1);
paulson@7218
    73
qed "FreeUltrafilterNat_Int";
paulson@7218
    74
paulson@7218
    75
Goal "[| X: FreeUltrafilterNat;  X <= Y |] \
paulson@7218
    76
\     ==> Y : FreeUltrafilterNat";
paulson@7218
    77
by (cut_facts_tac [FreeUltrafilterNat_mem] 1);
paulson@7218
    78
by (blast_tac (claset() addDs [FreeUltrafilter_Ultrafilter,
paulson@7218
    79
			       Ultrafilter_Filter,mem_FiltersetD2]) 1);
paulson@7218
    80
qed "FreeUltrafilterNat_subset";
paulson@7218
    81
paulson@7218
    82
Goal "X: FreeUltrafilterNat ==> -X ~: FreeUltrafilterNat";
paulson@7218
    83
by (Step_tac 1);
paulson@7218
    84
by (dtac FreeUltrafilterNat_Int 1 THEN assume_tac 1);
paulson@7218
    85
by Auto_tac;
paulson@7218
    86
qed "FreeUltrafilterNat_Compl";
paulson@7218
    87
paulson@7218
    88
Goal "X~: FreeUltrafilterNat ==> -X : FreeUltrafilterNat";
paulson@7218
    89
by (cut_facts_tac [FreeUltrafilterNat_mem RS (FreeUltrafilter_iff RS iffD1)] 1);
paulson@7218
    90
by (Step_tac 1 THEN dres_inst_tac [("x","X")] bspec 1);
paulson@7218
    91
by (auto_tac (claset(),simpset() addsimps [UNIV_diff_Compl]));
paulson@7218
    92
qed "FreeUltrafilterNat_Compl_mem";
paulson@7218
    93
paulson@7218
    94
Goal "(X ~: FreeUltrafilterNat) = (-X: FreeUltrafilterNat)";
paulson@7218
    95
by (blast_tac (claset() addDs [FreeUltrafilterNat_Compl,
paulson@7218
    96
			       FreeUltrafilterNat_Compl_mem]) 1);
paulson@7218
    97
qed "FreeUltrafilterNat_Compl_iff1";
paulson@7218
    98
paulson@7218
    99
Goal "(X: FreeUltrafilterNat) = (-X ~: FreeUltrafilterNat)";
paulson@7218
   100
by (auto_tac (claset(),
paulson@7218
   101
	      simpset() addsimps [FreeUltrafilterNat_Compl_iff1 RS sym]));
paulson@7218
   102
qed "FreeUltrafilterNat_Compl_iff2";
paulson@7218
   103
paulson@7218
   104
Goal "(UNIV::nat set) : FreeUltrafilterNat";
paulson@7218
   105
by (rtac (FreeUltrafilterNat_mem RS FreeUltrafilter_Ultrafilter RS 
paulson@7218
   106
          Ultrafilter_Filter RS mem_FiltersetD4) 1);
paulson@7218
   107
qed "FreeUltrafilterNat_UNIV";
paulson@7218
   108
Addsimps [FreeUltrafilterNat_UNIV];
paulson@7218
   109
paulson@7218
   110
Goal "{n::nat. True}: FreeUltrafilterNat";
paulson@7218
   111
by (subgoal_tac "{n::nat. True} = (UNIV::nat set)" 1);
paulson@7218
   112
by Auto_tac;
paulson@7218
   113
qed "FreeUltrafilterNat_Nat_set";
paulson@7218
   114
Addsimps [FreeUltrafilterNat_Nat_set];
paulson@7218
   115
paulson@7218
   116
Goal "{n. P(n) = P(n)} : FreeUltrafilterNat";
paulson@7218
   117
by (Simp_tac 1);
paulson@7218
   118
qed "FreeUltrafilterNat_Nat_set_refl";
paulson@7218
   119
AddIs [FreeUltrafilterNat_Nat_set_refl];
paulson@7218
   120
paulson@7218
   121
Goal "{n::nat. P} : FreeUltrafilterNat ==> P";
paulson@7218
   122
by (rtac ccontr 1);
paulson@7218
   123
by (rotate_tac 1 1);
paulson@7218
   124
by (Asm_full_simp_tac 1);
paulson@7218
   125
qed "FreeUltrafilterNat_P";
paulson@7218
   126
paulson@7218
   127
Goal "{n. P(n)} : FreeUltrafilterNat ==> EX n. P(n)";
paulson@7218
   128
by (rtac ccontr 1 THEN rotate_tac 1 1);
paulson@7218
   129
by (Asm_full_simp_tac 1);
paulson@7218
   130
qed "FreeUltrafilterNat_Ex_P";
paulson@7218
   131
paulson@7218
   132
Goal "ALL n. P(n) ==> {n. P(n)} : FreeUltrafilterNat";
paulson@7218
   133
by (auto_tac (claset() addIs [FreeUltrafilterNat_Nat_set],simpset()));
paulson@7218
   134
qed "FreeUltrafilterNat_all";
paulson@7218
   135
paulson@7218
   136
(*-----------------------------------------
paulson@7218
   137
     Define and use Ultrafilter tactics
paulson@7218
   138
 -----------------------------------------*)
paulson@7218
   139
use "fuf.ML";
paulson@7218
   140
paulson@7218
   141
paulson@7218
   142
paulson@7218
   143
(*------------------------------------------------------
paulson@7218
   144
   Now prove one further property of our free ultrafilter
paulson@7218
   145
 -------------------------------------------------------*)
paulson@7218
   146
Goal "X Un Y: FreeUltrafilterNat \
paulson@7218
   147
\     ==> X: FreeUltrafilterNat | Y: FreeUltrafilterNat";
paulson@7218
   148
by Auto_tac;
paulson@7218
   149
by (Ultra_tac 1);
paulson@7218
   150
qed "FreeUltrafilterNat_Un";
paulson@7218
   151
paulson@7218
   152
(*------------------------------------------------------------------------
paulson@7218
   153
                       Properties of hyprel
paulson@7218
   154
 ------------------------------------------------------------------------*)
paulson@7218
   155
paulson@7218
   156
(** Proving that hyprel is an equivalence relation **)
paulson@7218
   157
(** Natural deduction for hyprel **)
paulson@7218
   158
paulson@7218
   159
Goalw [hyprel_def]
paulson@7218
   160
   "((X,Y): hyprel) = ({n. X n = Y n}: FreeUltrafilterNat)";
paulson@7218
   161
by (Fast_tac 1);
paulson@7218
   162
qed "hyprel_iff";
paulson@7218
   163
paulson@7218
   164
Goalw [hyprel_def] 
paulson@7218
   165
     "{n. X n = Y n}: FreeUltrafilterNat  ==> (X,Y): hyprel";
paulson@7218
   166
by (Fast_tac 1);
paulson@7218
   167
qed "hyprelI";
paulson@7218
   168
paulson@7218
   169
Goalw [hyprel_def]
paulson@7218
   170
  "p: hyprel --> (EX X Y. \
paulson@7218
   171
\                 p = (X,Y) & {n. X n = Y n} : FreeUltrafilterNat)";
paulson@7218
   172
by (Fast_tac 1);
paulson@7218
   173
qed "hyprelE_lemma";
paulson@7218
   174
paulson@7218
   175
val [major,minor] = goal thy
paulson@7218
   176
  "[| p: hyprel;  \
paulson@7218
   177
\     !!X Y. [| p = (X,Y); {n. X n = Y n}: FreeUltrafilterNat\
paulson@7218
   178
\                    |] ==> Q |] ==> Q";
paulson@7218
   179
by (cut_facts_tac [major RS (hyprelE_lemma RS mp)] 1);
paulson@7218
   180
by (REPEAT (eresolve_tac [asm_rl,exE,conjE,minor] 1));
paulson@7218
   181
qed "hyprelE";
paulson@7218
   182
paulson@7218
   183
AddSIs [hyprelI];
paulson@7218
   184
AddSEs [hyprelE];
paulson@7218
   185
paulson@7218
   186
Goalw [hyprel_def] "(x,x): hyprel";
paulson@7218
   187
by (auto_tac (claset(),simpset() addsimps 
paulson@7218
   188
         [FreeUltrafilterNat_Nat_set]));
paulson@7218
   189
qed "hyprel_refl";
paulson@7218
   190
paulson@7218
   191
Goal "{n. X n = Y n} = {n. Y n = X n}";
paulson@7218
   192
by Auto_tac;
paulson@7218
   193
qed "lemma_perm";
paulson@7218
   194
paulson@7218
   195
Goalw [hyprel_def] "(x,y): hyprel --> (y,x):hyprel";
paulson@7218
   196
by (auto_tac (claset() addIs [lemma_perm RS subst],simpset()));
paulson@7218
   197
qed_spec_mp "hyprel_sym";
paulson@7218
   198
paulson@7218
   199
Goalw [hyprel_def]
paulson@7218
   200
      "(x,y): hyprel --> (y,z):hyprel --> (x,z):hyprel";
paulson@7218
   201
by Auto_tac;
paulson@7218
   202
by (Ultra_tac 1);
paulson@7218
   203
qed_spec_mp "hyprel_trans";
paulson@7218
   204
paulson@7218
   205
Goalw [equiv_def, refl_def, sym_def, trans_def]
paulson@7218
   206
    "equiv {x::nat=>real. True} hyprel";
paulson@7218
   207
by (auto_tac (claset() addSIs [hyprel_refl] 
paulson@7218
   208
                       addSEs [hyprel_sym,hyprel_trans] 
paulson@7218
   209
                       delrules [hyprelI,hyprelE],
paulson@7218
   210
	      simpset() addsimps [FreeUltrafilterNat_Nat_set]));
paulson@7218
   211
qed "equiv_hyprel";
paulson@7218
   212
paulson@7218
   213
val equiv_hyprel_iff =
paulson@7218
   214
    [TrueI, TrueI] MRS 
paulson@7218
   215
    ([CollectI, CollectI] MRS 
paulson@7218
   216
    (equiv_hyprel RS eq_equiv_class_iff));
paulson@7218
   217
paulson@7218
   218
Goalw  [hypreal_def,hyprel_def,quotient_def] "hyprel^^{x}:hypreal";
paulson@7218
   219
by (Blast_tac 1);
paulson@7218
   220
qed "hyprel_in_hypreal";
paulson@7218
   221
paulson@7218
   222
Goal "inj_on Abs_hypreal hypreal";
paulson@7218
   223
by (rtac inj_on_inverseI 1);
paulson@7218
   224
by (etac Abs_hypreal_inverse 1);
paulson@7218
   225
qed "inj_on_Abs_hypreal";
paulson@7218
   226
paulson@7218
   227
Addsimps [equiv_hyprel_iff,inj_on_Abs_hypreal RS inj_on_iff,
paulson@7218
   228
          hyprel_iff, hyprel_in_hypreal, Abs_hypreal_inverse];
paulson@7218
   229
paulson@7218
   230
Addsimps [equiv_hyprel RS eq_equiv_class_iff];
paulson@7218
   231
val eq_hyprelD = equiv_hyprel RSN (2,eq_equiv_class);
paulson@7218
   232
paulson@7218
   233
Goal "inj(Rep_hypreal)";
paulson@7218
   234
by (rtac inj_inverseI 1);
paulson@7218
   235
by (rtac Rep_hypreal_inverse 1);
paulson@7218
   236
qed "inj_Rep_hypreal";
paulson@7218
   237
paulson@7218
   238
Goalw [hyprel_def] "x: hyprel ^^ {x}";
paulson@7218
   239
by (Step_tac 1);
paulson@7218
   240
by (auto_tac (claset() addSIs [FreeUltrafilterNat_Nat_set],simpset()));
paulson@7218
   241
qed "lemma_hyprel_refl";
paulson@7218
   242
paulson@7218
   243
Addsimps [lemma_hyprel_refl];
paulson@7218
   244
paulson@7218
   245
Goalw [hypreal_def] "{} ~: hypreal";
paulson@7218
   246
by (auto_tac (claset() addSEs [quotientE], simpset()));
paulson@7218
   247
qed "hypreal_empty_not_mem";
paulson@7218
   248
paulson@7218
   249
Addsimps [hypreal_empty_not_mem];
paulson@7218
   250
paulson@7218
   251
Goal "Rep_hypreal x ~= {}";
paulson@7218
   252
by (cut_inst_tac [("x","x")] Rep_hypreal 1);
paulson@7218
   253
by Auto_tac;
paulson@7218
   254
qed "Rep_hypreal_nonempty";
paulson@7218
   255
paulson@7218
   256
Addsimps [Rep_hypreal_nonempty];
paulson@7218
   257
paulson@7218
   258
(*------------------------------------------------------------------------
paulson@7218
   259
   hypreal_of_real: the injection from real to hypreal
paulson@7218
   260
 ------------------------------------------------------------------------*)
paulson@7218
   261
paulson@7218
   262
Goal "inj(hypreal_of_real)";
paulson@7218
   263
by (rtac injI 1);
paulson@7218
   264
by (rewtac hypreal_of_real_def);
paulson@7218
   265
by (dtac (inj_on_Abs_hypreal RS inj_onD) 1);
paulson@7218
   266
by (REPEAT (rtac hyprel_in_hypreal 1));
paulson@7218
   267
by (dtac eq_equiv_class 1);
paulson@7218
   268
by (rtac equiv_hyprel 1);
paulson@7218
   269
by (Fast_tac 1);
paulson@7218
   270
by (rtac ccontr 1 THEN rotate_tac 1 1);
paulson@7218
   271
by Auto_tac;
paulson@7218
   272
qed "inj_hypreal_of_real";
paulson@7218
   273
paulson@7218
   274
val [prem] = goal thy
paulson@7218
   275
    "(!!x y. z = Abs_hypreal(hyprel^^{x}) ==> P) ==> P";
paulson@7218
   276
by (res_inst_tac [("x1","z")] 
paulson@7218
   277
    (rewrite_rule [hypreal_def] Rep_hypreal RS quotientE) 1);
paulson@7218
   278
by (dres_inst_tac [("f","Abs_hypreal")] arg_cong 1);
paulson@7218
   279
by (res_inst_tac [("x","x")] prem 1);
paulson@7218
   280
by (asm_full_simp_tac (simpset() addsimps [Rep_hypreal_inverse]) 1);
paulson@7218
   281
qed "eq_Abs_hypreal";
paulson@7218
   282
paulson@7218
   283
(**** hypreal_minus: additive inverse on hypreal ****)
paulson@7218
   284
paulson@7218
   285
Goalw [congruent_def]
paulson@7218
   286
  "congruent hyprel (%X. hyprel^^{%n. - (X n)})";
paulson@7218
   287
by Safe_tac;
paulson@7218
   288
by (ALLGOALS Ultra_tac);
paulson@7218
   289
qed "hypreal_minus_congruent";
paulson@7218
   290
paulson@7218
   291
(*Resolve th against the corresponding facts for hypreal_minus*)
paulson@7218
   292
val hypreal_minus_ize = RSLIST [equiv_hyprel, hypreal_minus_congruent];
paulson@7218
   293
paulson@7218
   294
Goalw [hypreal_minus_def]
paulson@7218
   295
      "- (Abs_hypreal(hyprel^^{%n. X n})) = Abs_hypreal(hyprel ^^ {%n. -(X n)})";
paulson@7218
   296
by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
paulson@7218
   297
by (simp_tac (simpset() addsimps 
paulson@7218
   298
   [hyprel_in_hypreal RS Abs_hypreal_inverse,hypreal_minus_ize UN_equiv_class]) 1);
paulson@7218
   299
qed "hypreal_minus";
paulson@7218
   300
paulson@7218
   301
Goal "- (- z) = (z::hypreal)";
paulson@7218
   302
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   303
by (asm_simp_tac (simpset() addsimps [hypreal_minus]) 1);
paulson@7218
   304
qed "hypreal_minus_minus";
paulson@7218
   305
paulson@7218
   306
Addsimps [hypreal_minus_minus];
paulson@7218
   307
paulson@7218
   308
Goal "inj(%r::hypreal. -r)";
paulson@7218
   309
by (rtac injI 1);
paulson@7218
   310
by (dres_inst_tac [("f","uminus")] arg_cong 1);
paulson@7218
   311
by (asm_full_simp_tac (simpset() addsimps [hypreal_minus_minus]) 1);
paulson@7218
   312
qed "inj_hypreal_minus";
paulson@7218
   313
paulson@7218
   314
Goalw [hypreal_zero_def] "-0hr = 0hr";
paulson@7218
   315
by (simp_tac (simpset() addsimps [hypreal_minus]) 1);
paulson@7218
   316
qed "hypreal_minus_zero";
paulson@7218
   317
paulson@7218
   318
Addsimps [hypreal_minus_zero];
paulson@7218
   319
paulson@7218
   320
Goal "(-x = 0hr) = (x = 0hr)"; 
paulson@7218
   321
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   322
by (auto_tac (claset(),simpset() addsimps [hypreal_zero_def,
paulson@7218
   323
    hypreal_minus] @ real_add_ac));
paulson@7218
   324
qed "hypreal_minus_zero_iff";
paulson@7218
   325
paulson@7218
   326
Addsimps [hypreal_minus_zero_iff];
paulson@7218
   327
(**** hrinv: multiplicative inverse on hypreal ****)
paulson@7218
   328
paulson@7218
   329
Goalw [congruent_def]
fleuriot@9013
   330
  "congruent hyprel (%X. hyprel^^{%n. if X n = #0 then #0 else rinv(X n)})";
paulson@7218
   331
by (Auto_tac THEN Ultra_tac 1);
paulson@7218
   332
qed "hypreal_hrinv_congruent";
paulson@7218
   333
paulson@7218
   334
(* Resolve th against the corresponding facts for hrinv *)
paulson@7218
   335
val hypreal_hrinv_ize = RSLIST [equiv_hyprel, hypreal_hrinv_congruent];
paulson@7218
   336
paulson@7218
   337
Goalw [hrinv_def]
paulson@7218
   338
      "hrinv (Abs_hypreal(hyprel^^{%n. X n})) = \
fleuriot@9013
   339
\      Abs_hypreal(hyprel ^^ {%n. if X n = #0 then #0 else rinv(X n)})";
paulson@7218
   340
by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
paulson@7218
   341
by (simp_tac (simpset() addsimps 
paulson@7218
   342
   [hyprel_in_hypreal RS Abs_hypreal_inverse,hypreal_hrinv_ize UN_equiv_class]) 1);
paulson@7218
   343
qed "hypreal_hrinv";
paulson@7218
   344
paulson@7218
   345
Goal "z ~= 0hr ==> hrinv (hrinv z) = z";
paulson@7218
   346
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   347
by (rotate_tac 1 1);
paulson@7218
   348
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
   349
    [hypreal_hrinv,hypreal_zero_def] setloop (split_tac [expand_if])) 1);
fleuriot@9013
   350
by (ultra_tac (claset() addDs (map (full_rename_numerals thy)
fleuriot@9013
   351
    [rinv_not_zero,real_rinv_rinv]),simpset()) 1);
paulson@7218
   352
qed "hypreal_hrinv_hrinv";
paulson@7218
   353
paulson@7218
   354
Addsimps [hypreal_hrinv_hrinv];
paulson@7218
   355
paulson@7218
   356
Goalw [hypreal_one_def] "hrinv(1hr) = 1hr";
paulson@7218
   357
by (full_simp_tac (simpset() addsimps [hypreal_hrinv,
paulson@7218
   358
       real_zero_not_eq_one RS not_sym] 
paulson@7218
   359
                   setloop (split_tac [expand_if])) 1);
paulson@7218
   360
qed "hypreal_hrinv_1";
paulson@7218
   361
Addsimps [hypreal_hrinv_1];
paulson@7218
   362
paulson@7218
   363
(**** hyperreal addition: hypreal_add  ****)
paulson@7218
   364
paulson@7218
   365
Goalw [congruent2_def]
paulson@7218
   366
    "congruent2 hyprel (%X Y. hyprel^^{%n. X n + Y n})";
paulson@7218
   367
by Safe_tac;
paulson@7218
   368
by (ALLGOALS(Ultra_tac));
paulson@7218
   369
qed "hypreal_add_congruent2";
paulson@7218
   370
paulson@7218
   371
(*Resolve th against the corresponding facts for hyppreal_add*)
paulson@7218
   372
val hypreal_add_ize = RSLIST [equiv_hyprel, hypreal_add_congruent2];
paulson@7218
   373
paulson@7218
   374
Goalw [hypreal_add_def]
paulson@7218
   375
  "Abs_hypreal(hyprel^^{%n. X n}) + Abs_hypreal(hyprel^^{%n. Y n}) = \
paulson@7218
   376
\  Abs_hypreal(hyprel^^{%n. X n + Y n})";
paulson@7218
   377
by (asm_simp_tac
paulson@7218
   378
    (simpset() addsimps [hypreal_add_ize UN_equiv_class2]) 1);
paulson@7218
   379
qed "hypreal_add";
paulson@7218
   380
paulson@7218
   381
Goal "(z::hypreal) + w = w + z";
paulson@7218
   382
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   383
by (res_inst_tac [("z","w")] eq_Abs_hypreal 1);
paulson@7218
   384
by (asm_simp_tac (simpset() addsimps (real_add_ac @ [hypreal_add])) 1);
paulson@7218
   385
qed "hypreal_add_commute";
paulson@7218
   386
paulson@7218
   387
Goal "((z1::hypreal) + z2) + z3 = z1 + (z2 + z3)";
paulson@7218
   388
by (res_inst_tac [("z","z1")] eq_Abs_hypreal 1);
paulson@7218
   389
by (res_inst_tac [("z","z2")] eq_Abs_hypreal 1);
paulson@7218
   390
by (res_inst_tac [("z","z3")] eq_Abs_hypreal 1);
paulson@7218
   391
by (asm_simp_tac (simpset() addsimps [hypreal_add, real_add_assoc]) 1);
paulson@7218
   392
qed "hypreal_add_assoc";
paulson@7218
   393
paulson@7218
   394
(*For AC rewriting*)
paulson@7218
   395
Goal "(x::hypreal)+(y+z)=y+(x+z)";
paulson@7218
   396
by (rtac (hypreal_add_commute RS trans) 1);
paulson@7218
   397
by (rtac (hypreal_add_assoc RS trans) 1);
paulson@7218
   398
by (rtac (hypreal_add_commute RS arg_cong) 1);
paulson@7218
   399
qed "hypreal_add_left_commute";
paulson@7218
   400
paulson@7218
   401
(* hypreal addition is an AC operator *)
paulson@7218
   402
val hypreal_add_ac = [hypreal_add_assoc,hypreal_add_commute,
paulson@7218
   403
                      hypreal_add_left_commute];
paulson@7218
   404
paulson@7218
   405
Goalw [hypreal_zero_def] "0hr + z = z";
paulson@7218
   406
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   407
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
   408
    [hypreal_add]) 1);
paulson@7218
   409
qed "hypreal_add_zero_left";
paulson@7218
   410
paulson@7218
   411
Goal "z + 0hr = z";
paulson@7218
   412
by (simp_tac (simpset() addsimps 
paulson@7218
   413
    [hypreal_add_zero_left,hypreal_add_commute]) 1);
paulson@7218
   414
qed "hypreal_add_zero_right";
paulson@7218
   415
paulson@7218
   416
Goalw [hypreal_zero_def] "z + -z = 0hr";
paulson@7218
   417
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   418
by (asm_full_simp_tac (simpset() addsimps [hypreal_minus,
paulson@7218
   419
        hypreal_add]) 1);
paulson@7218
   420
qed "hypreal_add_minus";
paulson@7218
   421
paulson@7218
   422
Goal "-z + z = 0hr";
paulson@7218
   423
by (simp_tac (simpset() addsimps 
paulson@7218
   424
    [hypreal_add_commute,hypreal_add_minus]) 1);
paulson@7218
   425
qed "hypreal_add_minus_left";
paulson@7218
   426
paulson@7218
   427
Addsimps [hypreal_add_minus,hypreal_add_minus_left,
paulson@7218
   428
          hypreal_add_zero_left,hypreal_add_zero_right];
paulson@7218
   429
paulson@7218
   430
Goal "? y. (x::hypreal) + y = 0hr";
paulson@7218
   431
by (fast_tac (claset() addIs [hypreal_add_minus]) 1);
paulson@7218
   432
qed "hypreal_minus_ex";
paulson@7218
   433
paulson@7218
   434
Goal "?! y. (x::hypreal) + y = 0hr";
paulson@7218
   435
by (auto_tac (claset() addIs [hypreal_add_minus],simpset()));
paulson@7218
   436
by (dres_inst_tac [("f","%x. ya+x")] arg_cong 1);
paulson@7218
   437
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
paulson@7218
   438
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
paulson@7218
   439
qed "hypreal_minus_ex1";
paulson@7218
   440
paulson@7218
   441
Goal "?! y. y + (x::hypreal) = 0hr";
paulson@7218
   442
by (auto_tac (claset() addIs [hypreal_add_minus_left],simpset()));
paulson@7218
   443
by (dres_inst_tac [("f","%x. x+ya")] arg_cong 1);
paulson@7218
   444
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
paulson@7218
   445
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
paulson@7218
   446
qed "hypreal_minus_left_ex1";
paulson@7218
   447
paulson@7218
   448
Goal "x + y = 0hr ==> x = -y";
paulson@7218
   449
by (cut_inst_tac [("z","y")] hypreal_add_minus_left 1);
paulson@7218
   450
by (res_inst_tac [("x1","y")] (hypreal_minus_left_ex1 RS ex1E) 1);
paulson@7218
   451
by (Blast_tac 1);
paulson@7218
   452
qed "hypreal_add_minus_eq_minus";
paulson@7218
   453
paulson@7218
   454
Goal "? y::hypreal. x = -y";
paulson@7218
   455
by (cut_inst_tac [("x","x")] hypreal_minus_ex 1);
paulson@7218
   456
by (etac exE 1 THEN dtac hypreal_add_minus_eq_minus 1);
paulson@7218
   457
by (Fast_tac 1);
paulson@7218
   458
qed "hypreal_as_add_inverse_ex";
paulson@7218
   459
paulson@7218
   460
Goal "-(x + (y::hypreal)) = -x + -y";
paulson@7218
   461
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   462
by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
paulson@7218
   463
by (auto_tac (claset(),simpset() addsimps [hypreal_minus,
paulson@7218
   464
    hypreal_add,real_minus_add_distrib]));
paulson@7218
   465
qed "hypreal_minus_add_distrib";
paulson@7218
   466
paulson@7218
   467
Goal "-(y + -(x::hypreal)) = x + -y";
paulson@7218
   468
by (simp_tac (simpset() addsimps [hypreal_minus_add_distrib,
paulson@7218
   469
    hypreal_add_commute]) 1);
paulson@7218
   470
qed "hypreal_minus_distrib1";
paulson@7218
   471
paulson@7218
   472
Goal "(x + - (y::hypreal)) + (y + - z) = x + -z";
paulson@7218
   473
by (res_inst_tac [("w1","y")] (hypreal_add_commute RS subst) 1);
paulson@7218
   474
by (simp_tac (simpset() addsimps [hypreal_add_left_commute,
paulson@7218
   475
    hypreal_add_assoc]) 1);
paulson@7218
   476
by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
paulson@7218
   477
qed "hypreal_add_minus_cancel1";
paulson@7218
   478
paulson@7218
   479
Goal "((x::hypreal) + y = x + z) = (y = z)";
paulson@7218
   480
by (Step_tac 1);
paulson@7218
   481
by (dres_inst_tac [("f","%t.-x + t")] arg_cong 1);
paulson@7218
   482
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
paulson@7218
   483
qed "hypreal_add_left_cancel";
paulson@7218
   484
paulson@7218
   485
Goal "z + (x + (y + -z)) = x + (y::hypreal)";
paulson@7218
   486
by (simp_tac (simpset() addsimps hypreal_add_ac) 1);
paulson@7218
   487
qed "hypreal_add_minus_cancel2";
paulson@7218
   488
Addsimps [hypreal_add_minus_cancel2];
paulson@7218
   489
paulson@7218
   490
Goal "y + -(x + y) = -(x::hypreal)";
paulson@7218
   491
by (full_simp_tac (simpset() addsimps [hypreal_minus_add_distrib]) 1);
paulson@7218
   492
by (rtac (hypreal_add_left_commute RS subst) 1);
paulson@7218
   493
by (Full_simp_tac 1);
paulson@7218
   494
qed "hypreal_add_minus_cancel";
paulson@7218
   495
Addsimps [hypreal_add_minus_cancel];
paulson@7218
   496
paulson@7218
   497
Goal "y + -(y + x) = -(x::hypreal)";
paulson@7218
   498
by (simp_tac (simpset() addsimps [hypreal_minus_add_distrib,
paulson@7218
   499
              hypreal_add_assoc RS sym]) 1);
paulson@7218
   500
qed "hypreal_add_minus_cancelc";
paulson@7218
   501
Addsimps [hypreal_add_minus_cancelc];
paulson@7218
   502
paulson@7218
   503
Goal "(z + -x) + (y + -z) = (y + -(x::hypreal))";
paulson@7218
   504
by (full_simp_tac (simpset() addsimps [hypreal_minus_add_distrib
paulson@7218
   505
    RS sym, hypreal_add_left_cancel] @ hypreal_add_ac) 1); 
paulson@7218
   506
qed "hypreal_add_minus_cancel3";
paulson@7218
   507
Addsimps [hypreal_add_minus_cancel3];
paulson@7218
   508
paulson@7218
   509
Goal "(y + (x::hypreal)= z + x) = (y = z)";
paulson@7218
   510
by (simp_tac (simpset() addsimps [hypreal_add_commute,
paulson@7218
   511
    hypreal_add_left_cancel]) 1);
paulson@7218
   512
qed "hypreal_add_right_cancel";
paulson@7218
   513
paulson@7218
   514
Goal "z + (y + -z) = (y::hypreal)";
paulson@7218
   515
by (simp_tac (simpset() addsimps hypreal_add_ac) 1);
paulson@7218
   516
qed "hypreal_add_minus_cancel4";
paulson@7218
   517
Addsimps [hypreal_add_minus_cancel4];
paulson@7218
   518
paulson@7218
   519
Goal "z + (w + (x + (-z + y))) = w + x + (y::hypreal)";
paulson@7218
   520
by (simp_tac (simpset() addsimps hypreal_add_ac) 1);
paulson@7218
   521
qed "hypreal_add_minus_cancel5";
paulson@7218
   522
Addsimps [hypreal_add_minus_cancel5];
paulson@7218
   523
paulson@7218
   524
paulson@7218
   525
(**** hyperreal multiplication: hypreal_mult  ****)
paulson@7218
   526
paulson@7218
   527
Goalw [congruent2_def]
paulson@7218
   528
    "congruent2 hyprel (%X Y. hyprel^^{%n. X n * Y n})";
paulson@7218
   529
by Safe_tac;
paulson@7218
   530
by (ALLGOALS(Ultra_tac));
paulson@7218
   531
qed "hypreal_mult_congruent2";
paulson@7218
   532
paulson@7218
   533
(*Resolve th against the corresponding facts for hypreal_mult*)
paulson@7218
   534
val hypreal_mult_ize = RSLIST [equiv_hyprel, hypreal_mult_congruent2];
paulson@7218
   535
paulson@7218
   536
Goalw [hypreal_mult_def]
paulson@7218
   537
  "Abs_hypreal(hyprel^^{%n. X n}) * Abs_hypreal(hyprel^^{%n. Y n}) = \
paulson@7218
   538
\  Abs_hypreal(hyprel^^{%n. X n * Y n})";
paulson@7218
   539
by (asm_simp_tac
paulson@7218
   540
    (simpset() addsimps [hypreal_mult_ize UN_equiv_class2]) 1);
paulson@7218
   541
qed "hypreal_mult";
paulson@7218
   542
paulson@7218
   543
Goal "(z::hypreal) * w = w * z";
paulson@7218
   544
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   545
by (res_inst_tac [("z","w")] eq_Abs_hypreal 1);
paulson@7218
   546
by (asm_simp_tac (simpset() addsimps ([hypreal_mult] @ real_mult_ac)) 1);
paulson@7218
   547
qed "hypreal_mult_commute";
paulson@7218
   548
paulson@7218
   549
Goal "((z1::hypreal) * z2) * z3 = z1 * (z2 * z3)";
paulson@7218
   550
by (res_inst_tac [("z","z1")] eq_Abs_hypreal 1);
paulson@7218
   551
by (res_inst_tac [("z","z2")] eq_Abs_hypreal 1);
paulson@7218
   552
by (res_inst_tac [("z","z3")] eq_Abs_hypreal 1);
paulson@7218
   553
by (asm_simp_tac (simpset() addsimps [hypreal_mult,real_mult_assoc]) 1);
paulson@7218
   554
qed "hypreal_mult_assoc";
paulson@7218
   555
paulson@7218
   556
qed_goal "hypreal_mult_left_commute" thy
paulson@7218
   557
    "(z1::hypreal) * (z2 * z3) = z2 * (z1 * z3)"
paulson@7218
   558
 (fn _ => [rtac (hypreal_mult_commute RS trans) 1, rtac (hypreal_mult_assoc RS trans) 1,
paulson@7218
   559
           rtac (hypreal_mult_commute RS arg_cong) 1]);
paulson@7218
   560
paulson@7218
   561
(* hypreal multiplication is an AC operator *)
paulson@7218
   562
val hypreal_mult_ac = [hypreal_mult_assoc, hypreal_mult_commute, 
paulson@7218
   563
                       hypreal_mult_left_commute];
paulson@7218
   564
paulson@7218
   565
Goalw [hypreal_one_def] "1hr * z = z";
paulson@7218
   566
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   567
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult]) 1);
paulson@7218
   568
qed "hypreal_mult_1";
paulson@7218
   569
paulson@7218
   570
Goal "z * 1hr = z";
paulson@7218
   571
by (simp_tac (simpset() addsimps [hypreal_mult_commute,
paulson@7218
   572
    hypreal_mult_1]) 1);
paulson@7218
   573
qed "hypreal_mult_1_right";
paulson@7218
   574
paulson@7218
   575
Goalw [hypreal_zero_def] "0hr * z = 0hr";
paulson@7218
   576
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
   577
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult,real_mult_0]) 1);
paulson@7218
   578
qed "hypreal_mult_0";
paulson@7218
   579
paulson@7218
   580
Goal "z * 0hr = 0hr";
paulson@7218
   581
by (simp_tac (simpset() addsimps [hypreal_mult_commute,
paulson@7218
   582
    hypreal_mult_0]) 1);
paulson@7218
   583
qed "hypreal_mult_0_right";
paulson@7218
   584
paulson@7218
   585
Addsimps [hypreal_mult_0,hypreal_mult_0_right];
paulson@7218
   586
paulson@7218
   587
Goal "-(x * y) = -x * (y::hypreal)";
paulson@7218
   588
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   589
by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
paulson@9043
   590
by (auto_tac (claset(),
paulson@9043
   591
	      simpset() addsimps [hypreal_minus, hypreal_mult] 
paulson@9043
   592
                                 @ real_mult_ac @ real_add_ac));
paulson@7218
   593
qed "hypreal_minus_mult_eq1";
paulson@7218
   594
paulson@7218
   595
Goal "-(x * y) = (x::hypreal) * -y";
paulson@7218
   596
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   597
by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
paulson@7218
   598
by (auto_tac (claset(),simpset() addsimps [hypreal_minus,
paulson@9043
   599
					   hypreal_mult] 
paulson@9043
   600
                                           @ real_mult_ac @ real_add_ac));
paulson@7218
   601
qed "hypreal_minus_mult_eq2";
paulson@7218
   602
paulson@7218
   603
Goal "-x*-y = x*(y::hypreal)";
paulson@7218
   604
by (full_simp_tac (simpset() addsimps [hypreal_minus_mult_eq2 RS sym,
paulson@9043
   605
				       hypreal_minus_mult_eq1 RS sym]) 1);
paulson@7218
   606
qed "hypreal_minus_mult_cancel";
paulson@7218
   607
paulson@7218
   608
Addsimps [hypreal_minus_mult_cancel];
paulson@7218
   609
paulson@7218
   610
Goal "-x*y = (x::hypreal)*-y";
paulson@7218
   611
by (full_simp_tac (simpset() addsimps [hypreal_minus_mult_eq2 RS sym,
paulson@9043
   612
				       hypreal_minus_mult_eq1 RS sym]) 1);
paulson@7218
   613
qed "hypreal_minus_mult_commute";
paulson@7218
   614
paulson@7218
   615
paulson@7218
   616
(*-----------------------------------------------------------------------------
paulson@7218
   617
    A few more theorems
paulson@7218
   618
 ----------------------------------------------------------------------------*)
paulson@7218
   619
Goal "(z::hypreal) + v = z' + v' ==> z + (v + w) = z' + (v' + w)";
paulson@7218
   620
by (asm_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
paulson@7218
   621
qed "hypreal_add_assoc_cong";
paulson@7218
   622
paulson@7218
   623
Goal "(z::hypreal) + (v + w) = v + (z + w)";
paulson@7218
   624
by (REPEAT (ares_tac [hypreal_add_commute RS hypreal_add_assoc_cong] 1));
paulson@7218
   625
qed "hypreal_add_assoc_swap";
paulson@7218
   626
paulson@7218
   627
Goal "((z1::hypreal) + z2) * w = (z1 * w) + (z2 * w)";
paulson@7218
   628
by (res_inst_tac [("z","z1")] eq_Abs_hypreal 1);
paulson@7218
   629
by (res_inst_tac [("z","z2")] eq_Abs_hypreal 1);
paulson@7218
   630
by (res_inst_tac [("z","w")] eq_Abs_hypreal 1);
paulson@7218
   631
by (asm_simp_tac (simpset() addsimps [hypreal_mult,hypreal_add,
paulson@7218
   632
     real_add_mult_distrib]) 1);
paulson@7218
   633
qed "hypreal_add_mult_distrib";
paulson@7218
   634
paulson@7218
   635
val hypreal_mult_commute'= read_instantiate [("z","w")] hypreal_mult_commute;
paulson@7218
   636
paulson@7218
   637
Goal "(w::hypreal) * (z1 + z2) = (w * z1) + (w * z2)";
paulson@7218
   638
by (simp_tac (simpset() addsimps [hypreal_mult_commute',hypreal_add_mult_distrib]) 1);
paulson@7218
   639
qed "hypreal_add_mult_distrib2";
paulson@7218
   640
paulson@7218
   641
val hypreal_mult_simps = [hypreal_mult_1, hypreal_mult_1_right];
paulson@7218
   642
Addsimps hypreal_mult_simps;
paulson@7218
   643
paulson@7218
   644
(*** one and zero are distinct ***)
paulson@7218
   645
Goalw [hypreal_zero_def,hypreal_one_def] "0hr ~= 1hr";
paulson@7218
   646
by (auto_tac (claset(),simpset() addsimps [real_zero_not_eq_one]));
paulson@7218
   647
qed "hypreal_zero_not_eq_one";
paulson@7218
   648
paulson@7218
   649
(*** existence of inverse ***)
paulson@7218
   650
Goalw [hypreal_one_def,hypreal_zero_def] 
paulson@7218
   651
          "x ~= 0hr ==> x*hrinv(x) = 1hr";
paulson@7218
   652
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   653
by (rotate_tac 1 1);
paulson@7218
   654
by (asm_full_simp_tac (simpset() addsimps [hypreal_hrinv,
paulson@7218
   655
    hypreal_mult] setloop (split_tac [expand_if])) 1);
paulson@7218
   656
by (dtac FreeUltrafilterNat_Compl_mem 1);
paulson@7218
   657
by (blast_tac (claset() addSIs [real_mult_inv_right,
paulson@7218
   658
    FreeUltrafilterNat_subset]) 1);
paulson@7218
   659
qed "hypreal_mult_hrinv";
paulson@7218
   660
paulson@7218
   661
Goal "x ~= 0hr ==> hrinv(x)*x = 1hr";
paulson@7218
   662
by (asm_simp_tac (simpset() addsimps [hypreal_mult_hrinv,
paulson@7218
   663
    hypreal_mult_commute]) 1);
paulson@7218
   664
qed "hypreal_mult_hrinv_left";
paulson@7218
   665
paulson@7218
   666
Goal "x ~= 0hr ==> ? y. (x::hypreal) * y = 1hr";
paulson@7218
   667
by (fast_tac (claset() addDs [hypreal_mult_hrinv]) 1);
paulson@7218
   668
qed "hypreal_hrinv_ex";
paulson@7218
   669
paulson@7218
   670
Goal "x ~= 0hr ==> ? y. y * (x::hypreal) = 1hr";
paulson@7218
   671
by (fast_tac (claset() addDs [hypreal_mult_hrinv_left]) 1);
paulson@7218
   672
qed "hypreal_hrinv_left_ex";
paulson@7218
   673
paulson@7218
   674
Goal "x ~= 0hr ==> ?! y. (x::hypreal) * y = 1hr";
paulson@7218
   675
by (auto_tac (claset() addIs [hypreal_mult_hrinv],simpset()));
paulson@7218
   676
by (dres_inst_tac [("f","%x. ya*x")] arg_cong 1);
paulson@7218
   677
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym]) 1);
paulson@7218
   678
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_commute]) 1);
paulson@7218
   679
qed "hypreal_hrinv_ex1";
paulson@7218
   680
paulson@7218
   681
Goal "x ~= 0hr ==> ?! y. y * (x::hypreal) = 1hr";
paulson@7218
   682
by (auto_tac (claset() addIs [hypreal_mult_hrinv_left],simpset()));
paulson@7218
   683
by (dres_inst_tac [("f","%x. x*ya")] arg_cong 1);
paulson@7218
   684
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_assoc]) 1);
paulson@7218
   685
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_commute]) 1);
paulson@7218
   686
qed "hypreal_hrinv_left_ex1";
paulson@7218
   687
paulson@7218
   688
Goal "[| y~= 0hr; x * y = 1hr |]  ==> x = hrinv y";
paulson@7218
   689
by (forw_inst_tac [("x","y")] hypreal_mult_hrinv_left 1);
paulson@7218
   690
by (res_inst_tac [("x1","y")] (hypreal_hrinv_left_ex1 RS ex1E) 1);
paulson@7218
   691
by (assume_tac 1);
paulson@7218
   692
by (Blast_tac 1);
paulson@7218
   693
qed "hypreal_mult_inv_hrinv";
paulson@7218
   694
paulson@7218
   695
Goal "x ~= 0hr ==> ? y. x = hrinv y";
paulson@7218
   696
by (forw_inst_tac [("x","x")] hypreal_hrinv_left_ex 1);
paulson@7218
   697
by (etac exE 1 THEN 
paulson@7218
   698
    forw_inst_tac [("x","y")] hypreal_mult_inv_hrinv 1);
paulson@7218
   699
by (res_inst_tac [("x","y")] exI 2);
paulson@7218
   700
by Auto_tac;
paulson@7218
   701
qed "hypreal_as_inverse_ex";
paulson@7218
   702
paulson@7218
   703
Goal "(c::hypreal) ~= 0hr ==> (c*a=c*b) = (a=b)";
paulson@7218
   704
by Auto_tac;
paulson@7218
   705
by (dres_inst_tac [("f","%x. x*hrinv c")] arg_cong 1);
paulson@7218
   706
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_hrinv] @ hypreal_mult_ac)  1);
paulson@7218
   707
qed "hypreal_mult_left_cancel";
paulson@7218
   708
    
paulson@7218
   709
Goal "(c::hypreal) ~= 0hr ==> (a*c=b*c) = (a=b)";
paulson@7218
   710
by (Step_tac 1);
paulson@7218
   711
by (dres_inst_tac [("f","%x. x*hrinv c")] arg_cong 1);
paulson@7218
   712
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_hrinv] @ hypreal_mult_ac)  1);
paulson@7218
   713
qed "hypreal_mult_right_cancel";
paulson@7218
   714
paulson@7218
   715
Goalw [hypreal_zero_def] "x ~= 0hr ==> hrinv(x) ~= 0hr";
paulson@7218
   716
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   717
by (rotate_tac 1 1);
paulson@7218
   718
by (asm_full_simp_tac (simpset() addsimps [hypreal_hrinv,
paulson@7218
   719
    hypreal_mult] setloop (split_tac [expand_if])) 1);
paulson@7218
   720
by (dtac FreeUltrafilterNat_Compl_mem 1 THEN Clarify_tac 1);
paulson@7218
   721
by (ultra_tac (claset() addIs [ccontr] addDs 
fleuriot@9013
   722
    [full_rename_numerals thy rinv_not_zero],simpset()) 1);
paulson@7218
   723
qed "hrinv_not_zero";
paulson@7218
   724
paulson@7218
   725
Addsimps [hypreal_mult_hrinv,hypreal_mult_hrinv_left];
paulson@7218
   726
paulson@7218
   727
Goal "[| x ~= 0hr; y ~= 0hr |] ==> x * y ~= 0hr";
paulson@7218
   728
by (Step_tac 1);
paulson@7218
   729
by (dres_inst_tac [("f","%z. hrinv x*z")] arg_cong 1);
paulson@7218
   730
by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym]) 1);
paulson@7218
   731
qed "hypreal_mult_not_0";
paulson@7218
   732
paulson@7218
   733
bind_thm ("hypreal_mult_not_0E",hypreal_mult_not_0 RS notE);
paulson@7218
   734
paulson@7218
   735
Goal "x ~= 0hr ==> x * x ~= 0hr";
paulson@7218
   736
by (blast_tac (claset() addDs [hypreal_mult_not_0]) 1);
paulson@7218
   737
qed "hypreal_mult_self_not_zero";
paulson@7218
   738
paulson@7218
   739
Goal "[| x ~= 0hr; y ~= 0hr |] ==> hrinv(x*y) = hrinv(x)*hrinv(y)";
paulson@7218
   740
by (res_inst_tac [("c1","x")] (hypreal_mult_left_cancel RS iffD1) 1);
paulson@7218
   741
by (auto_tac (claset(),simpset() addsimps [hypreal_mult_assoc RS sym,
paulson@7218
   742
    hypreal_mult_not_0]));
paulson@7218
   743
by (res_inst_tac [("c1","y")] (hypreal_mult_right_cancel RS iffD1) 1);
paulson@7218
   744
by (auto_tac (claset(),simpset() addsimps [hypreal_mult_not_0] @ hypreal_mult_ac));
paulson@7218
   745
by (auto_tac (claset(),simpset() addsimps [hypreal_mult_assoc RS sym,hypreal_mult_not_0]));
paulson@7218
   746
qed "hrinv_mult_eq";
paulson@7218
   747
paulson@7218
   748
Goal "x ~= 0hr ==> hrinv(-x) = -hrinv(x)";
paulson@7218
   749
by (res_inst_tac [("c1","-x")] (hypreal_mult_right_cancel RS iffD1) 1);
paulson@7218
   750
by Auto_tac;
paulson@7218
   751
qed "hypreal_minus_hrinv";
paulson@7218
   752
paulson@7218
   753
Goal "[| x ~= 0hr; y ~= 0hr |] \
paulson@7218
   754
\     ==> hrinv(x*y) = hrinv(x)*hrinv(y)";
paulson@7218
   755
by (forw_inst_tac [("y","y")] hypreal_mult_not_0 1 THEN assume_tac 1);
paulson@7218
   756
by (res_inst_tac [("c1","x")] (hypreal_mult_left_cancel RS iffD1) 1);
paulson@7218
   757
by (auto_tac (claset(),simpset() addsimps [hypreal_mult_assoc RS sym]));
paulson@7218
   758
by (res_inst_tac [("c1","y")] (hypreal_mult_left_cancel RS iffD1) 1);
paulson@7218
   759
by (auto_tac (claset(),simpset() addsimps [hypreal_mult_left_commute]));
paulson@7218
   760
by (asm_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym]) 1);
paulson@7218
   761
qed "hypreal_hrinv_distrib";
paulson@7218
   762
paulson@7218
   763
(*------------------------------------------------------------------
paulson@7218
   764
                   Theorems for ordering 
paulson@7218
   765
 ------------------------------------------------------------------*)
paulson@7218
   766
paulson@7218
   767
(* prove introduction and elimination rules for hypreal_less *)
paulson@7218
   768
paulson@7218
   769
Goalw [hypreal_less_def]
paulson@7218
   770
 "P < (Q::hypreal) = (EX X Y. X : Rep_hypreal(P) & \
paulson@7218
   771
\                             Y : Rep_hypreal(Q) & \
paulson@7218
   772
\                             {n. X n < Y n} : FreeUltrafilterNat)";
paulson@7218
   773
by (Fast_tac 1);
paulson@7218
   774
qed "hypreal_less_iff";
paulson@7218
   775
paulson@7218
   776
Goalw [hypreal_less_def]
paulson@7218
   777
 "[| {n. X n < Y n} : FreeUltrafilterNat; \
paulson@7218
   778
\         X : Rep_hypreal(P); \
paulson@7218
   779
\         Y : Rep_hypreal(Q) |] ==> P < (Q::hypreal)";
paulson@7218
   780
by (Fast_tac 1);
paulson@7218
   781
qed "hypreal_lessI";
paulson@7218
   782
paulson@7218
   783
paulson@7218
   784
Goalw [hypreal_less_def]
paulson@7218
   785
     "!! R1. [| R1 < (R2::hypreal); \
paulson@7218
   786
\         !!X Y. {n. X n < Y n} : FreeUltrafilterNat ==> P; \
paulson@7218
   787
\         !!X. X : Rep_hypreal(R1) ==> P; \ 
paulson@7218
   788
\         !!Y. Y : Rep_hypreal(R2) ==> P |] \
paulson@7218
   789
\     ==> P";
paulson@7218
   790
by Auto_tac;
paulson@7218
   791
qed "hypreal_lessE";
paulson@7218
   792
paulson@7218
   793
Goalw [hypreal_less_def]
paulson@7218
   794
 "R1 < (R2::hypreal) ==> (EX X Y. {n. X n < Y n} : FreeUltrafilterNat & \
paulson@7218
   795
\                                  X : Rep_hypreal(R1) & \
paulson@7218
   796
\                                  Y : Rep_hypreal(R2))";
paulson@7218
   797
by (Fast_tac 1);
paulson@7218
   798
qed "hypreal_lessD";
paulson@7218
   799
paulson@7218
   800
Goal "~ (R::hypreal) < R";
paulson@7218
   801
by (res_inst_tac [("z","R")] eq_Abs_hypreal 1);
paulson@7218
   802
by (auto_tac (claset(),simpset() addsimps [hypreal_less_def]));
paulson@7218
   803
by (Ultra_tac 1);
paulson@7218
   804
qed "hypreal_less_not_refl";
paulson@7218
   805
paulson@7218
   806
(*** y < y ==> P ***)
paulson@7218
   807
bind_thm("hypreal_less_irrefl",hypreal_less_not_refl RS notE);
paulson@7218
   808
paulson@7218
   809
Goal "!!(x::hypreal). x < y ==> x ~= y";
paulson@7218
   810
by (auto_tac (claset(),simpset() addsimps [hypreal_less_not_refl]));
paulson@7218
   811
qed "hypreal_not_refl2";
paulson@7218
   812
paulson@7218
   813
Goal "!!(R1::hypreal). [| R1 < R2; R2 < R3 |] ==> R1 < R3";
paulson@7218
   814
by (res_inst_tac [("z","R1")] eq_Abs_hypreal 1);
paulson@7218
   815
by (res_inst_tac [("z","R2")] eq_Abs_hypreal 1);
paulson@7218
   816
by (res_inst_tac [("z","R3")] eq_Abs_hypreal 1);
paulson@7218
   817
by (auto_tac (claset() addSIs [exI],simpset() 
paulson@7218
   818
     addsimps [hypreal_less_def]));
paulson@7218
   819
by (ultra_tac (claset() addIs [real_less_trans],simpset()) 1);
paulson@7218
   820
qed "hypreal_less_trans";
paulson@7218
   821
paulson@7218
   822
Goal "!! (R1::hypreal). [| R1 < R2; R2 < R1 |] ==> P";
paulson@7218
   823
by (dtac hypreal_less_trans 1 THEN assume_tac 1);
paulson@7218
   824
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
   825
    [hypreal_less_not_refl]) 1);
paulson@7218
   826
qed "hypreal_less_asym";
paulson@7218
   827
paulson@7218
   828
(*--------------------------------------------------------
paulson@7218
   829
  TODO: The following theorem should have been proved 
paulson@7218
   830
  first and then used througout the proofs as it probably 
paulson@7218
   831
  makes many of them more straightforward. 
paulson@7218
   832
 -------------------------------------------------------*)
paulson@7218
   833
Goalw [hypreal_less_def]
paulson@7218
   834
      "(Abs_hypreal(hyprel^^{%n. X n}) < \
paulson@7218
   835
\           Abs_hypreal(hyprel^^{%n. Y n})) = \
paulson@7218
   836
\      ({n. X n < Y n} : FreeUltrafilterNat)";
paulson@7218
   837
by (auto_tac (claset() addSIs [lemma_hyprel_refl],simpset()));
paulson@7218
   838
by (Ultra_tac 1);
paulson@7218
   839
qed "hypreal_less";
paulson@7218
   840
paulson@7218
   841
(*---------------------------------------------------------------------------------
paulson@7218
   842
             Hyperreals as a linearly ordered field
paulson@7218
   843
 ---------------------------------------------------------------------------------*)
paulson@7218
   844
(*** sum order ***)
paulson@7218
   845
paulson@7218
   846
Goalw [hypreal_zero_def] 
paulson@7218
   847
      "[| 0hr < x; 0hr < y |] ==> 0hr < x + y";
paulson@7218
   848
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   849
by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
paulson@7218
   850
by (auto_tac (claset(),simpset() addsimps
paulson@7218
   851
    [hypreal_less_def,hypreal_add]));
paulson@7218
   852
by (auto_tac (claset() addSIs [exI],simpset() addsimps
paulson@7218
   853
    [hypreal_less_def,hypreal_add]));
paulson@7218
   854
by (ultra_tac (claset() addIs [real_add_order],simpset()) 1);
paulson@7218
   855
qed "hypreal_add_order";
paulson@7218
   856
paulson@7218
   857
(*** mult order ***)
paulson@7218
   858
paulson@7218
   859
Goalw [hypreal_zero_def] 
paulson@7218
   860
          "[| 0hr < x; 0hr < y |] ==> 0hr < x * y";
paulson@7218
   861
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   862
by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
paulson@7218
   863
by (auto_tac (claset() addSIs [exI],simpset() addsimps
paulson@7218
   864
    [hypreal_less_def,hypreal_mult]));
fleuriot@9013
   865
by (ultra_tac (claset() addIs [rename_numerals thy 
fleuriot@9013
   866
    real_mult_order],simpset()) 1);
paulson@7218
   867
qed "hypreal_mult_order";
paulson@7218
   868
paulson@7218
   869
(*---------------------------------------------------------------------------------
paulson@7218
   870
                         Trichotomy of the hyperreals
paulson@7218
   871
  --------------------------------------------------------------------------------*)
paulson@7218
   872
fleuriot@9013
   873
Goalw [hyprel_def] "? x. x: hyprel ^^ {%n. #0}";
fleuriot@9013
   874
by (res_inst_tac [("x","%n. #0")] exI 1);
paulson@7218
   875
by (Step_tac 1);
paulson@7218
   876
by (auto_tac (claset() addSIs [FreeUltrafilterNat_Nat_set],simpset()));
paulson@7218
   877
qed "lemma_hyprel_0r_mem";
paulson@7218
   878
paulson@7218
   879
Goalw [hypreal_zero_def]"0hr <  x | x = 0hr | x < 0hr";
paulson@7218
   880
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
   881
by (auto_tac (claset(),simpset() addsimps [hypreal_less_def]));
paulson@7218
   882
by (cut_facts_tac [lemma_hyprel_0r_mem] 1 THEN etac exE 1);
paulson@7218
   883
by (dres_inst_tac [("x","xa")] spec 1);
paulson@7218
   884
by (dres_inst_tac [("x","x")] spec 1);
paulson@7218
   885
by (cut_inst_tac [("x","x")] lemma_hyprel_refl 1);
paulson@7218
   886
by Auto_tac;
paulson@7218
   887
by (dres_inst_tac [("x","x")] spec 1);
paulson@7218
   888
by (dres_inst_tac [("x","xa")] spec 1);
paulson@7218
   889
by Auto_tac;
paulson@7218
   890
by (Ultra_tac 1);
paulson@7218
   891
by (auto_tac (claset() addIs [real_linear_less2],simpset()));
paulson@7218
   892
qed "hypreal_trichotomy";
paulson@7218
   893
paulson@7218
   894
val prems = Goal "[| 0hr < x ==> P; \
paulson@7218
   895
\                 x = 0hr ==> P; \
paulson@7218
   896
\                 x < 0hr ==> P |] ==> P";
paulson@7218
   897
by (cut_inst_tac [("x","x")] hypreal_trichotomy 1);
paulson@7218
   898
by (REPEAT (eresolve_tac (disjE::prems) 1));
paulson@7218
   899
qed "hypreal_trichotomyE";
paulson@7218
   900
paulson@7218
   901
(*----------------------------------------------------------------------------
paulson@7218
   902
            More properties of <
paulson@7218
   903
 ----------------------------------------------------------------------------*)
paulson@7218
   904
Goal "!!(A::hypreal). A < B ==> A + C < B + C";
paulson@7218
   905
by (res_inst_tac [("z","A")] eq_Abs_hypreal 1);
paulson@7218
   906
by (res_inst_tac [("z","B")] eq_Abs_hypreal 1);
paulson@7218
   907
by (res_inst_tac [("z","C")] eq_Abs_hypreal 1);
paulson@7218
   908
by (auto_tac (claset() addSIs [exI],simpset() addsimps
paulson@7218
   909
    [hypreal_less_def,hypreal_add]));
paulson@7218
   910
by (Ultra_tac 1);
paulson@7218
   911
qed "hypreal_add_less_mono1";
paulson@7218
   912
paulson@7218
   913
Goal "!!(A::hypreal). A < B ==> C + A < C + B";
paulson@7218
   914
by (auto_tac (claset() addIs [hypreal_add_less_mono1],
paulson@7218
   915
    simpset() addsimps [hypreal_add_commute]));
paulson@7218
   916
qed "hypreal_add_less_mono2";
paulson@7218
   917
paulson@7218
   918
Goal "((x::hypreal) < y) = (0hr < y + -x)";
paulson@7218
   919
by (Step_tac 1);
paulson@7218
   920
by (dres_inst_tac [("C","-x")] hypreal_add_less_mono1 1);
paulson@7218
   921
by (dres_inst_tac [("C","x")] hypreal_add_less_mono1 2);
paulson@7218
   922
by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
paulson@7218
   923
qed "hypreal_less_minus_iff"; 
paulson@7218
   924
paulson@7218
   925
Goal "((x::hypreal) < y) = (x + -y< 0hr)";
paulson@7218
   926
by (Step_tac 1);
paulson@7218
   927
by (dres_inst_tac [("C","-y")] hypreal_add_less_mono1 1);
paulson@7218
   928
by (dres_inst_tac [("C","y")] hypreal_add_less_mono1 2);
paulson@7218
   929
by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
paulson@7218
   930
qed "hypreal_less_minus_iff2";
paulson@7218
   931
paulson@7218
   932
Goal  "!!(y1 :: hypreal). [| z1 < y1; z2 < y2 |] ==> z1 + z2 < y1 + y2";
paulson@7218
   933
by (dtac (hypreal_less_minus_iff RS iffD1) 1);
paulson@7218
   934
by (dtac (hypreal_less_minus_iff RS iffD1) 1);
paulson@7218
   935
by (dtac hypreal_add_order 1 THEN assume_tac 1);
paulson@7218
   936
by (thin_tac "0hr < y2 + - z2" 1);
paulson@7218
   937
by (dres_inst_tac [("C","z1 + z2")] hypreal_add_less_mono1 1);
paulson@7218
   938
by (auto_tac (claset(),simpset() addsimps 
paulson@7218
   939
    [hypreal_minus_add_distrib RS sym] @ hypreal_add_ac));
paulson@7218
   940
qed "hypreal_add_less_mono";
paulson@7218
   941
paulson@7218
   942
Goal "((x::hypreal) = y) = (0hr = x + - y)";
paulson@7218
   943
by Auto_tac;
paulson@7218
   944
by (res_inst_tac [("x1","-y")] (hypreal_add_right_cancel RS iffD1) 1);
paulson@7218
   945
by Auto_tac;
paulson@7218
   946
qed "hypreal_eq_minus_iff"; 
paulson@7218
   947
paulson@7218
   948
Goal "((x::hypreal) = y) = (0hr = y + - x)";
paulson@7218
   949
by Auto_tac;
paulson@7218
   950
by (res_inst_tac [("x1","-x")] (hypreal_add_right_cancel RS iffD1) 1);
paulson@7218
   951
by Auto_tac;
paulson@7218
   952
qed "hypreal_eq_minus_iff2"; 
paulson@7218
   953
paulson@7218
   954
Goal "(x = y + z) = (x + -z = (y::hypreal))";
paulson@7218
   955
by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
paulson@7218
   956
qed "hypreal_eq_minus_iff3";
paulson@7218
   957
paulson@7218
   958
Goal "(x = z + y) = (x + -z = (y::hypreal))";
paulson@7218
   959
by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
paulson@7218
   960
qed "hypreal_eq_minus_iff4";
paulson@7218
   961
paulson@7218
   962
Goal "(x ~= a) = (x + -a ~= 0hr)";
paulson@7218
   963
by (auto_tac (claset() addDs [sym RS 
paulson@7218
   964
    (hypreal_eq_minus_iff RS iffD2)],simpset())); 
paulson@7218
   965
qed "hypreal_not_eq_minus_iff";
paulson@7218
   966
paulson@7218
   967
(*** linearity ***)
paulson@7218
   968
Goal "(x::hypreal) < y | x = y | y < x";
wenzelm@7322
   969
by (stac hypreal_eq_minus_iff2 1);
paulson@7218
   970
by (res_inst_tac [("x1","x")] (hypreal_less_minus_iff RS ssubst) 1);
paulson@7218
   971
by (res_inst_tac [("x1","y")] (hypreal_less_minus_iff2 RS ssubst) 1);
paulson@7218
   972
by (rtac hypreal_trichotomyE 1);
paulson@7218
   973
by Auto_tac;
paulson@7218
   974
qed "hypreal_linear";
paulson@7218
   975
paulson@7218
   976
Goal "!!(x::hypreal). [| x < y ==> P;  x = y ==> P; \
paulson@7218
   977
\          y < x ==> P |] ==> P";
paulson@7218
   978
by (cut_inst_tac [("x","x"),("y","y")] hypreal_linear 1);
paulson@7218
   979
by Auto_tac;
paulson@7218
   980
qed "hypreal_linear_less2";
paulson@7218
   981
paulson@7218
   982
(*------------------------------------------------------------------------------
paulson@7218
   983
                            Properties of <=
paulson@7218
   984
 ------------------------------------------------------------------------------*)
paulson@7218
   985
(*------ hypreal le iff reals le a.e ------*)
paulson@7218
   986
paulson@7218
   987
Goalw [hypreal_le_def,real_le_def]
paulson@7218
   988
      "(Abs_hypreal(hyprel^^{%n. X n}) <= \
paulson@7218
   989
\           Abs_hypreal(hyprel^^{%n. Y n})) = \
paulson@7218
   990
\      ({n. X n <= Y n} : FreeUltrafilterNat)";
paulson@7218
   991
by (auto_tac (claset(),simpset() addsimps [hypreal_less]));
paulson@7218
   992
by (ALLGOALS(Ultra_tac));
paulson@7218
   993
qed "hypreal_le";
paulson@7218
   994
paulson@7218
   995
(*---------------------------------------------------------*)
paulson@7218
   996
(*---------------------------------------------------------*)
paulson@7218
   997
Goalw [hypreal_le_def] 
paulson@7218
   998
     "~(w < z) ==> z <= (w::hypreal)";
paulson@7218
   999
by (assume_tac 1);
paulson@7218
  1000
qed "hypreal_leI";
paulson@7218
  1001
paulson@7218
  1002
Goalw [hypreal_le_def] 
paulson@7218
  1003
      "z<=w ==> ~(w<(z::hypreal))";
paulson@7218
  1004
by (assume_tac 1);
paulson@7218
  1005
qed "hypreal_leD";
paulson@7218
  1006
paulson@7218
  1007
val hypreal_leE = make_elim hypreal_leD;
paulson@7218
  1008
paulson@7218
  1009
Goal "(~(w < z)) = (z <= (w::hypreal))";
paulson@7218
  1010
by (fast_tac (claset() addSIs [hypreal_leI,hypreal_leD]) 1);
paulson@7218
  1011
qed "hypreal_less_le_iff";
paulson@7218
  1012
paulson@7218
  1013
Goalw [hypreal_le_def] "~ z <= w ==> w<(z::hypreal)";
paulson@7218
  1014
by (Fast_tac 1);
paulson@7218
  1015
qed "not_hypreal_leE";
paulson@7218
  1016
paulson@7218
  1017
Goalw [hypreal_le_def] "z < w ==> z <= (w::hypreal)";
paulson@7218
  1018
by (fast_tac (claset() addEs [hypreal_less_asym]) 1);
paulson@7218
  1019
qed "hypreal_less_imp_le";
paulson@7218
  1020
paulson@7218
  1021
Goalw [hypreal_le_def] "!!(x::hypreal). x <= y ==> x < y | x = y";
paulson@7218
  1022
by (cut_facts_tac [hypreal_linear] 1);
paulson@7218
  1023
by (fast_tac (claset() addEs [hypreal_less_irrefl,hypreal_less_asym]) 1);
paulson@7218
  1024
qed "hypreal_le_imp_less_or_eq";
paulson@7218
  1025
paulson@7218
  1026
Goalw [hypreal_le_def] "z<w | z=w ==> z <=(w::hypreal)";
paulson@7218
  1027
by (cut_facts_tac [hypreal_linear] 1);
paulson@7218
  1028
by (fast_tac (claset() addEs [hypreal_less_irrefl,hypreal_less_asym]) 1);
paulson@7218
  1029
qed "hypreal_less_or_eq_imp_le";
paulson@7218
  1030
paulson@7218
  1031
Goal "(x <= (y::hypreal)) = (x < y | x=y)";
paulson@7218
  1032
by (REPEAT(ares_tac [iffI, hypreal_less_or_eq_imp_le, hypreal_le_imp_less_or_eq] 1));
paulson@7218
  1033
qed "hypreal_le_eq_less_or_eq";
paulson@7218
  1034
paulson@7218
  1035
Goal "w <= (w::hypreal)";
paulson@7218
  1036
by (simp_tac (simpset() addsimps [hypreal_le_eq_less_or_eq]) 1);
paulson@7218
  1037
qed "hypreal_le_refl";
paulson@7218
  1038
Addsimps [hypreal_le_refl];
paulson@7218
  1039
paulson@7218
  1040
Goal "[| i <= j; j < k |] ==> i < (k::hypreal)";
paulson@7218
  1041
by (dtac hypreal_le_imp_less_or_eq 1);
paulson@7218
  1042
by (fast_tac (claset() addIs [hypreal_less_trans]) 1);
paulson@7218
  1043
qed "hypreal_le_less_trans";
paulson@7218
  1044
paulson@7218
  1045
Goal "!! (i::hypreal). [| i < j; j <= k |] ==> i < k";
paulson@7218
  1046
by (dtac hypreal_le_imp_less_or_eq 1);
paulson@7218
  1047
by (fast_tac (claset() addIs [hypreal_less_trans]) 1);
paulson@7218
  1048
qed "hypreal_less_le_trans";
paulson@7218
  1049
paulson@7218
  1050
Goal "[| i <= j; j <= k |] ==> i <= (k::hypreal)";
paulson@7218
  1051
by (EVERY1 [dtac hypreal_le_imp_less_or_eq, dtac hypreal_le_imp_less_or_eq,
paulson@7218
  1052
            rtac hypreal_less_or_eq_imp_le, fast_tac (claset() addIs [hypreal_less_trans])]);
paulson@7218
  1053
qed "hypreal_le_trans";
paulson@7218
  1054
paulson@7218
  1055
Goal "[| z <= w; w <= z |] ==> z = (w::hypreal)";
paulson@7218
  1056
by (EVERY1 [dtac hypreal_le_imp_less_or_eq, dtac hypreal_le_imp_less_or_eq,
paulson@7218
  1057
            fast_tac (claset() addEs [hypreal_less_irrefl,hypreal_less_asym])]);
paulson@7218
  1058
qed "hypreal_le_anti_sym";
paulson@7218
  1059
paulson@7218
  1060
Goal "[| 0hr < x; 0hr <= y |] ==> 0hr < x + y";
paulson@7218
  1061
by (auto_tac (claset() addDs [sym,hypreal_le_imp_less_or_eq]
paulson@7218
  1062
              addIs [hypreal_add_order],simpset()));
paulson@7218
  1063
qed "hypreal_add_order_le";            
paulson@7218
  1064
paulson@7218
  1065
(*------------------------------------------------------------------------
paulson@7218
  1066
 ------------------------------------------------------------------------*)
paulson@7218
  1067
paulson@7218
  1068
Goal "[| ~ y < x; y ~= x |] ==> x < (y::hypreal)";
paulson@7218
  1069
by (rtac not_hypreal_leE 1);
paulson@7218
  1070
by (fast_tac (claset() addDs [hypreal_le_imp_less_or_eq]) 1);
paulson@7218
  1071
qed "not_less_not_eq_hypreal_less";
paulson@7218
  1072
paulson@7218
  1073
Goal "(0hr < -R) = (R < 0hr)";
paulson@7218
  1074
by (Step_tac 1);
paulson@7218
  1075
by (dres_inst_tac [("C","R")] hypreal_add_less_mono1 1);
paulson@7218
  1076
by (dres_inst_tac [("C","-R")] hypreal_add_less_mono1 2);
paulson@7218
  1077
by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
paulson@7218
  1078
qed "hypreal_minus_zero_less_iff";
paulson@7218
  1079
paulson@7218
  1080
Goal "(-R < 0hr) = (0hr < R)";
paulson@7218
  1081
by (Step_tac 1);
paulson@7218
  1082
by (dres_inst_tac [("C","R")] hypreal_add_less_mono1 1);
paulson@7218
  1083
by (dres_inst_tac [("C","-R")] hypreal_add_less_mono1 2);
paulson@7218
  1084
by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
paulson@7218
  1085
qed "hypreal_minus_zero_less_iff2";
paulson@7218
  1086
paulson@7218
  1087
Goal "((x::hypreal) < y) = (-y < -x)";
wenzelm@7322
  1088
by (stac hypreal_less_minus_iff 1);
paulson@7218
  1089
by (res_inst_tac [("x1","x")] (hypreal_less_minus_iff RS ssubst) 1);
paulson@7218
  1090
by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
paulson@7218
  1091
qed "hypreal_less_swap_iff";
paulson@7218
  1092
paulson@7218
  1093
Goal "(0hr < x) = (-x < x)";
paulson@7218
  1094
by (Step_tac 1);
paulson@7218
  1095
by (rtac ccontr 2 THEN forward_tac 
paulson@7218
  1096
    [hypreal_leI RS hypreal_le_imp_less_or_eq] 2);
paulson@7218
  1097
by (Step_tac 2);
paulson@7218
  1098
by (dtac (hypreal_minus_zero_less_iff RS iffD2) 2);
paulson@7218
  1099
by (dres_inst_tac [("R2.0","-x")] hypreal_less_trans 2);
paulson@7218
  1100
by (Auto_tac );
wenzelm@7499
  1101
by (ftac hypreal_add_order 1 THEN assume_tac 1);
paulson@7218
  1102
by (dres_inst_tac [("C","-x"),("B","x + x")] hypreal_add_less_mono1 1);
paulson@7218
  1103
by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
paulson@7218
  1104
qed "hypreal_gt_zero_iff";
paulson@7218
  1105
paulson@7218
  1106
Goal "(x < 0hr) = (x < -x)";
paulson@7218
  1107
by (rtac (hypreal_minus_zero_less_iff RS subst) 1);
wenzelm@7322
  1108
by (stac hypreal_gt_zero_iff 1);
paulson@7218
  1109
by (Full_simp_tac 1);
paulson@7218
  1110
qed "hypreal_lt_zero_iff";
paulson@7218
  1111
paulson@7218
  1112
Goalw [hypreal_le_def] "(0hr <= x) = (-x <= x)";
paulson@7218
  1113
by (auto_tac (claset(),simpset() addsimps [hypreal_lt_zero_iff RS sym]));
paulson@7218
  1114
qed "hypreal_ge_zero_iff";
paulson@7218
  1115
paulson@7218
  1116
Goalw [hypreal_le_def] "(x <= 0hr) = (x <= -x)";
paulson@7218
  1117
by (auto_tac (claset(),simpset() addsimps [hypreal_gt_zero_iff RS sym]));
paulson@7218
  1118
qed "hypreal_le_zero_iff";
paulson@7218
  1119
paulson@7218
  1120
Goal "[| x < 0hr; y < 0hr |] ==> 0hr < x * y";
paulson@7218
  1121
by (REPEAT(dtac (hypreal_minus_zero_less_iff RS iffD2) 1));
paulson@7218
  1122
by (dtac hypreal_mult_order 1 THEN assume_tac 1);
paulson@7218
  1123
by (Asm_full_simp_tac 1);
paulson@7218
  1124
qed "hypreal_mult_less_zero1";
paulson@7218
  1125
paulson@7218
  1126
Goal "[| 0hr <= x; 0hr <= y |] ==> 0hr <= x * y";
paulson@7218
  1127
by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
paulson@7218
  1128
by (auto_tac (claset() addIs [hypreal_mult_order,
paulson@7218
  1129
    hypreal_less_imp_le],simpset()));
paulson@7218
  1130
qed "hypreal_le_mult_order";
paulson@7218
  1131
paulson@7218
  1132
Goal "[| x <= 0hr; y <= 0hr |] ==> 0hr <= x * y";
paulson@7218
  1133
by (rtac hypreal_less_or_eq_imp_le 1);
paulson@7218
  1134
by (dtac hypreal_le_imp_less_or_eq 1 THEN etac disjE 1);
paulson@7218
  1135
by Auto_tac;
paulson@7218
  1136
by (dtac hypreal_le_imp_less_or_eq 1);
paulson@7218
  1137
by (auto_tac (claset() addDs [hypreal_mult_less_zero1],simpset()));
paulson@7218
  1138
qed "real_mult_le_zero1";
paulson@7218
  1139
paulson@7218
  1140
Goal "[| 0hr <= x; y < 0hr |] ==> x * y <= 0hr";
paulson@7218
  1141
by (rtac hypreal_less_or_eq_imp_le 1);
paulson@7218
  1142
by (dtac hypreal_le_imp_less_or_eq 1 THEN etac disjE 1);
paulson@7218
  1143
by Auto_tac;
paulson@7218
  1144
by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
paulson@7218
  1145
by (rtac (hypreal_minus_zero_less_iff RS subst) 1);
paulson@7218
  1146
by (blast_tac (claset() addDs [hypreal_mult_order] 
paulson@7218
  1147
    addIs [hypreal_minus_mult_eq2 RS ssubst]) 1);
paulson@7218
  1148
qed "hypreal_mult_le_zero";
paulson@7218
  1149
paulson@7218
  1150
Goal "[| 0hr < x; y < 0hr |] ==> x*y < 0hr";
paulson@7218
  1151
by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
paulson@7218
  1152
by (dtac hypreal_mult_order 1 THEN assume_tac 1);
paulson@7218
  1153
by (rtac (hypreal_minus_zero_less_iff RS iffD1) 1);
paulson@7218
  1154
by (asm_full_simp_tac (simpset() addsimps [hypreal_minus_mult_eq2]) 1);
paulson@7218
  1155
qed "hypreal_mult_less_zero";
paulson@7218
  1156
paulson@7218
  1157
Goalw [hypreal_one_def,hypreal_zero_def,hypreal_less_def] "0hr < 1hr";
fleuriot@9013
  1158
by (res_inst_tac [("x","%n. #0")] exI 1);
fleuriot@9013
  1159
by (res_inst_tac [("x","%n. #1")] exI 1);
paulson@7218
  1160
by (auto_tac (claset(),simpset() addsimps [real_zero_less_one,
paulson@7218
  1161
    FreeUltrafilterNat_Nat_set]));
paulson@7218
  1162
qed "hypreal_zero_less_one";
paulson@7218
  1163
paulson@7218
  1164
Goal "[| 0hr <= x; 0hr <= y |] ==> 0hr <= x + y";
paulson@7218
  1165
by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
paulson@7218
  1166
by (auto_tac (claset() addIs [hypreal_add_order,
paulson@7218
  1167
    hypreal_less_imp_le],simpset()));
paulson@7218
  1168
qed "hypreal_le_add_order";
paulson@7218
  1169
paulson@7218
  1170
Goal "!!(q1::hypreal). q1 <= q2  ==> x + q1 <= x + q2";
paulson@7218
  1171
by (dtac hypreal_le_imp_less_or_eq 1);
paulson@7218
  1172
by (Step_tac 1);
paulson@7218
  1173
by (auto_tac (claset() addSIs [hypreal_le_refl,
paulson@7218
  1174
    hypreal_less_imp_le,hypreal_add_less_mono1],
paulson@7218
  1175
    simpset() addsimps [hypreal_add_commute]));
paulson@7218
  1176
qed "hypreal_add_left_le_mono1";
paulson@7218
  1177
paulson@7218
  1178
Goal "!!(q1::hypreal). q1 <= q2  ==> q1 + x <= q2 + x";
paulson@7218
  1179
by (auto_tac (claset() addDs [hypreal_add_left_le_mono1],
paulson@7218
  1180
    simpset() addsimps [hypreal_add_commute]));
paulson@7218
  1181
qed "hypreal_add_le_mono1";
paulson@7218
  1182
paulson@7218
  1183
Goal "!!k l::hypreal. [|i<=j;  k<=l |] ==> i + k <= j + l";
paulson@7218
  1184
by (etac (hypreal_add_le_mono1 RS hypreal_le_trans) 1);
paulson@7218
  1185
by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
paulson@7218
  1186
(*j moves to the end because it is free while k, l are bound*)
paulson@7218
  1187
by (etac hypreal_add_le_mono1 1);
paulson@7218
  1188
qed "hypreal_add_le_mono";
paulson@7218
  1189
paulson@7218
  1190
Goal "!!k l::hypreal. [|i<j;  k<=l |] ==> i + k < j + l";
paulson@7218
  1191
by (auto_tac (claset() addSDs [hypreal_le_imp_less_or_eq] 
paulson@7218
  1192
    addIs [hypreal_add_less_mono1,hypreal_add_less_mono],simpset()));
paulson@7218
  1193
qed "hypreal_add_less_le_mono";
paulson@7218
  1194
paulson@7218
  1195
Goal "!!k l::hypreal. [|i<=j;  k<l |] ==> i + k < j + l";
paulson@7218
  1196
by (auto_tac (claset() addSDs [hypreal_le_imp_less_or_eq] 
paulson@7218
  1197
    addIs [hypreal_add_less_mono2,hypreal_add_less_mono],simpset()));
paulson@7218
  1198
qed "hypreal_add_le_less_mono";
paulson@7218
  1199
paulson@7218
  1200
Goal "(0hr*x<r)=(0hr<r)";
paulson@7218
  1201
by (Simp_tac 1);
paulson@7218
  1202
qed "hypreal_mult_0_less";
paulson@7218
  1203
paulson@7218
  1204
Goal "[| 0hr < z; x < y |] ==> x*z < y*z";       
paulson@7218
  1205
by (rotate_tac 1 1);
paulson@7218
  1206
by (dtac (hypreal_less_minus_iff RS iffD1) 1);
paulson@7218
  1207
by (rtac (hypreal_less_minus_iff RS iffD2) 1);
paulson@7218
  1208
by (dtac hypreal_mult_order 1 THEN assume_tac 1);
paulson@7218
  1209
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_mult_distrib2,
paulson@7218
  1210
    hypreal_minus_mult_eq2 RS sym, hypreal_mult_commute ]) 1);
paulson@7218
  1211
qed "hypreal_mult_less_mono1";
paulson@7218
  1212
paulson@7218
  1213
Goal "[| 0hr<z; x<y |] ==> z*x<z*y";       
paulson@7218
  1214
by (asm_simp_tac (simpset() addsimps [hypreal_mult_commute,hypreal_mult_less_mono1]) 1);
paulson@7218
  1215
qed "hypreal_mult_less_mono2";
paulson@7218
  1216
paulson@7218
  1217
Goal "[| 0hr<=z; x<y |] ==> x*z<=y*z";
paulson@7218
  1218
by (EVERY1 [rtac hypreal_less_or_eq_imp_le, dtac hypreal_le_imp_less_or_eq]);
paulson@7218
  1219
by (auto_tac (claset() addIs [hypreal_mult_less_mono1],simpset()));
paulson@7218
  1220
qed "hypreal_mult_le_less_mono1";
paulson@7218
  1221
paulson@7218
  1222
Goal "[| 0hr<=z; x<y |] ==> z*x<=z*y";
paulson@7218
  1223
by (asm_simp_tac (simpset() addsimps [hypreal_mult_commute,
paulson@7218
  1224
				      hypreal_mult_le_less_mono1]) 1);
paulson@7218
  1225
qed "hypreal_mult_le_less_mono2";
paulson@7218
  1226
paulson@7218
  1227
Goal "[| 0hr<=z; x<=y |] ==> z*x<=z*y";
paulson@7218
  1228
by (dres_inst_tac [("x","x")] hypreal_le_imp_less_or_eq 1);
paulson@7218
  1229
by (auto_tac (claset() addIs [hypreal_mult_le_less_mono2,hypreal_le_refl],simpset()));
paulson@7218
  1230
qed "hypreal_mult_le_le_mono1";
paulson@7218
  1231
paulson@7218
  1232
val prem1::prem2::prem3::rest = goal thy
paulson@7218
  1233
     "[| 0hr<y; x<r; y*r<t*s |] ==> y*x<t*s";
paulson@7218
  1234
by (rtac ([([prem1,prem2] MRS hypreal_mult_less_mono2),prem3] MRS hypreal_less_trans) 1);
paulson@7218
  1235
qed "hypreal_mult_less_trans";
paulson@7218
  1236
paulson@7218
  1237
Goal "[| 0hr<=y; x<r; y*r<t*s; 0hr<t*s|] ==> y*x<t*s";
paulson@7218
  1238
by (dtac hypreal_le_imp_less_or_eq 1);
paulson@7218
  1239
by (fast_tac (HOL_cs addEs [(hypreal_mult_0_less RS iffD2),hypreal_mult_less_trans]) 1);
paulson@7218
  1240
qed "hypreal_mult_le_less_trans";
paulson@7218
  1241
paulson@7218
  1242
Goal "[| 0hr <= y; x <= r; y*r < t*s; 0hr < t*s|] ==> y*x < t*s";
paulson@7218
  1243
by (dres_inst_tac [("x","x")] hypreal_le_imp_less_or_eq 1);
paulson@7218
  1244
by (fast_tac (claset() addIs [hypreal_mult_le_less_trans]) 1);
paulson@7218
  1245
qed "hypreal_mult_le_le_trans";
paulson@7218
  1246
paulson@7218
  1247
Goal "[| 0hr < r1; r1 <r2; 0hr < x; x < y|] \
paulson@7218
  1248
\                     ==> r1 * x < r2 * y";
paulson@7218
  1249
by (dres_inst_tac [("x","x")] hypreal_mult_less_mono2 1);
paulson@7218
  1250
by (dres_inst_tac [("R1.0","0hr")] hypreal_less_trans 2);
paulson@7218
  1251
by (dres_inst_tac [("x","r1")] hypreal_mult_less_mono1 3);
paulson@7218
  1252
by Auto_tac;
paulson@7218
  1253
by (blast_tac (claset() addIs [hypreal_less_trans]) 1);
paulson@7218
  1254
qed "hypreal_mult_less_mono";
paulson@7218
  1255
paulson@7218
  1256
Goal "[| 0hr < r1; r1 <r2; 0hr < y|] \
paulson@7218
  1257
\                           ==> 0hr < r2 * y";
paulson@7218
  1258
by (dres_inst_tac [("R1.0","0hr")] hypreal_less_trans 1);
paulson@7218
  1259
by (assume_tac 1);
paulson@7218
  1260
by (blast_tac (claset() addIs [hypreal_mult_order]) 1);
paulson@7218
  1261
qed "hypreal_mult_order_trans";
paulson@7218
  1262
paulson@7218
  1263
Goal "[| 0hr < r1; r1 <= r2; 0hr <= x; x <= y |] \
paulson@7218
  1264
\                  ==> r1 * x <= r2 * y";
paulson@7218
  1265
by (rtac hypreal_less_or_eq_imp_le 1);
paulson@7218
  1266
by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
paulson@7218
  1267
by (auto_tac (claset() addIs [hypreal_mult_less_mono,
paulson@7218
  1268
    hypreal_mult_less_mono1,hypreal_mult_less_mono2,
paulson@7218
  1269
    hypreal_mult_order_trans,hypreal_mult_order],simpset()));
paulson@7218
  1270
qed "hypreal_mult_le_mono";
paulson@7218
  1271
paulson@7218
  1272
(*----------------------------------------------------------
paulson@7218
  1273
  hypreal_of_real preserves field and order properties
paulson@7218
  1274
 -----------------------------------------------------------*)
paulson@7218
  1275
Goalw [hypreal_of_real_def] 
paulson@7218
  1276
      "hypreal_of_real ((z1::real) + z2) = \
paulson@7218
  1277
\      hypreal_of_real z1 + hypreal_of_real z2";
paulson@7218
  1278
by (asm_simp_tac (simpset() addsimps [hypreal_add,
paulson@7218
  1279
       hypreal_add_mult_distrib]) 1);
paulson@7218
  1280
qed "hypreal_of_real_add";
paulson@7218
  1281
paulson@7218
  1282
Goalw [hypreal_of_real_def] 
paulson@7218
  1283
            "hypreal_of_real ((z1::real) * z2) = hypreal_of_real z1 * hypreal_of_real z2";
paulson@7218
  1284
by (full_simp_tac (simpset() addsimps [hypreal_mult,
paulson@7218
  1285
        hypreal_add_mult_distrib2]) 1);
paulson@7218
  1286
qed "hypreal_of_real_mult";
paulson@7218
  1287
paulson@7218
  1288
Goalw [hypreal_less_def,hypreal_of_real_def] 
paulson@7218
  1289
            "(z1 < z2) = (hypreal_of_real z1 <  hypreal_of_real z2)";
paulson@7218
  1290
by Auto_tac;
paulson@7218
  1291
by (res_inst_tac [("x","%n. z1")] exI 1);
paulson@7218
  1292
by (Step_tac 1); 
paulson@7218
  1293
by (res_inst_tac [("x","%n. z2")] exI 2);
paulson@7218
  1294
by Auto_tac;
paulson@7218
  1295
by (rtac FreeUltrafilterNat_P 1);
paulson@7218
  1296
by (Ultra_tac 1);
paulson@7218
  1297
qed "hypreal_of_real_less_iff";
paulson@7218
  1298
paulson@7218
  1299
Addsimps [hypreal_of_real_less_iff RS sym];
paulson@7218
  1300
paulson@7218
  1301
Goalw [hypreal_le_def,real_le_def] 
paulson@7218
  1302
            "(z1 <= z2) = (hypreal_of_real z1 <=  hypreal_of_real z2)";
paulson@7218
  1303
by Auto_tac;
paulson@7218
  1304
qed "hypreal_of_real_le_iff";
paulson@7218
  1305
paulson@7218
  1306
Goalw [hypreal_of_real_def] "hypreal_of_real (-r) = - hypreal_of_real  r";
paulson@7218
  1307
by (auto_tac (claset(),simpset() addsimps [hypreal_minus]));
paulson@7218
  1308
qed "hypreal_of_real_minus";
paulson@7218
  1309
paulson@7218
  1310
Goal "0hr < x ==> 0hr < hrinv x";
paulson@7218
  1311
by (EVERY1[rtac ccontr, dtac hypreal_leI]);
paulson@7218
  1312
by (forward_tac [hypreal_minus_zero_less_iff2 RS iffD2] 1);
paulson@7218
  1313
by (forward_tac [hypreal_not_refl2 RS not_sym] 1);
paulson@7218
  1314
by (dtac (hypreal_not_refl2 RS not_sym RS hrinv_not_zero) 1);
paulson@7218
  1315
by (EVERY1[dtac hypreal_le_imp_less_or_eq, Step_tac]); 
paulson@7218
  1316
by (dtac hypreal_mult_less_zero1 1 THEN assume_tac 1);
paulson@7218
  1317
by (auto_tac (claset() addIs [hypreal_zero_less_one RS hypreal_less_asym],
paulson@7218
  1318
    simpset() addsimps [hypreal_minus_mult_eq1 RS sym,
paulson@7218
  1319
     hypreal_minus_zero_less_iff]));
paulson@7218
  1320
qed "hypreal_hrinv_gt_zero";
paulson@7218
  1321
paulson@7218
  1322
Goal "x < 0hr ==> hrinv x < 0hr";
wenzelm@7499
  1323
by (ftac hypreal_not_refl2 1);
paulson@7218
  1324
by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
paulson@7218
  1325
by (rtac (hypreal_minus_zero_less_iff RS iffD1) 1);
paulson@7218
  1326
by (dtac (hypreal_minus_hrinv RS sym) 1);
paulson@7218
  1327
by (auto_tac (claset() addIs [hypreal_hrinv_gt_zero],
paulson@7218
  1328
    simpset()));
paulson@7218
  1329
qed "hypreal_hrinv_less_zero";
paulson@7218
  1330
fleuriot@9013
  1331
Goalw [hypreal_of_real_def,hypreal_one_def] "hypreal_of_real  #1 = 1hr";
paulson@7218
  1332
by (Step_tac 1);
paulson@7218
  1333
qed "hypreal_of_real_one";
paulson@7218
  1334
fleuriot@9013
  1335
Goalw [hypreal_of_real_def,hypreal_zero_def] "hypreal_of_real  #0 = 0hr";
paulson@7218
  1336
by (Step_tac 1);
paulson@7218
  1337
qed "hypreal_of_real_zero";
paulson@7218
  1338
fleuriot@9013
  1339
Goal "(hypreal_of_real  r = 0hr) = (r = #0)";
paulson@7218
  1340
by (auto_tac (claset() addIs [FreeUltrafilterNat_P],
paulson@7218
  1341
    simpset() addsimps [hypreal_of_real_def,
paulson@7218
  1342
    hypreal_zero_def,FreeUltrafilterNat_Nat_set]));
paulson@7218
  1343
qed "hypreal_of_real_zero_iff";
paulson@7218
  1344
fleuriot@9013
  1345
Goal "(hypreal_of_real  r ~= 0hr) = (r ~= #0)";
paulson@7218
  1346
by (full_simp_tac (simpset() addsimps [hypreal_of_real_zero_iff]) 1);
paulson@7218
  1347
qed "hypreal_of_real_not_zero_iff";
paulson@7218
  1348
fleuriot@9013
  1349
Goal "r ~= #0 ==> hrinv (hypreal_of_real r) = \
paulson@7218
  1350
\          hypreal_of_real (rinv r)";
paulson@7218
  1351
by (res_inst_tac [("c1","hypreal_of_real r")] (hypreal_mult_left_cancel RS iffD1) 1);
paulson@7218
  1352
by (etac (hypreal_of_real_not_zero_iff RS iffD2) 1);
paulson@7218
  1353
by (forward_tac [hypreal_of_real_not_zero_iff RS iffD2] 1);
paulson@7218
  1354
by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_mult RS sym,hypreal_of_real_one]));
paulson@7218
  1355
qed "hypreal_of_real_hrinv";
paulson@7218
  1356
paulson@7218
  1357
Goal "hypreal_of_real r ~= 0hr ==> hrinv (hypreal_of_real r) = \
paulson@7218
  1358
\          hypreal_of_real (rinv r)";
paulson@7218
  1359
by (etac (hypreal_of_real_not_zero_iff RS iffD1 RS hypreal_of_real_hrinv) 1);
paulson@7218
  1360
qed "hypreal_of_real_hrinv2";
paulson@7218
  1361
paulson@7218
  1362
Goal "x+x=x*(1hr+1hr)";
paulson@7218
  1363
by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib2]) 1);
paulson@7218
  1364
qed "hypreal_add_self";
paulson@7218
  1365
paulson@7218
  1366
Goal "1hr < 1hr + 1hr";
paulson@7218
  1367
by (rtac (hypreal_less_minus_iff RS iffD2) 1);
paulson@7218
  1368
by (full_simp_tac (simpset() addsimps [hypreal_zero_less_one,
paulson@7218
  1369
    hypreal_add_assoc]) 1);
paulson@7218
  1370
qed "hypreal_one_less_two";
paulson@7218
  1371
paulson@7218
  1372
Goal "0hr < 1hr + 1hr";
paulson@7218
  1373
by (rtac ([hypreal_zero_less_one,
paulson@7218
  1374
          hypreal_one_less_two] MRS hypreal_less_trans) 1);
paulson@7218
  1375
qed "hypreal_zero_less_two";
paulson@7218
  1376
paulson@7218
  1377
Goal "1hr + 1hr ~= 0hr";
paulson@7218
  1378
by (rtac (hypreal_zero_less_two RS hypreal_not_refl2 RS not_sym) 1);
paulson@7218
  1379
qed "hypreal_two_not_zero";
paulson@7218
  1380
Addsimps [hypreal_two_not_zero];
paulson@7218
  1381
paulson@7218
  1382
Goal "x*hrinv(1hr + 1hr) + x*hrinv(1hr + 1hr) = x";
wenzelm@7322
  1383
by (stac hypreal_add_self 1);
paulson@7218
  1384
by (full_simp_tac (simpset() addsimps [hypreal_mult_assoc]) 1);
paulson@7218
  1385
qed "hypreal_sum_of_halves";
paulson@7218
  1386
paulson@7218
  1387
Goal "z ~= 0hr ==> x*y = (x*hrinv(z))*(z*y)";
paulson@7218
  1388
by (asm_simp_tac (simpset() addsimps hypreal_mult_ac)  1);
paulson@7218
  1389
qed "lemma_chain";
paulson@7218
  1390
paulson@7218
  1391
Goal "0hr < r ==> 0hr < r*hrinv(1hr+1hr)";
paulson@7218
  1392
by (dtac (hypreal_zero_less_two RS hypreal_hrinv_gt_zero 
paulson@7218
  1393
          RS hypreal_mult_less_mono1) 1);
paulson@7218
  1394
by Auto_tac;
paulson@7218
  1395
qed "hypreal_half_gt_zero";
paulson@7218
  1396
paulson@7218
  1397
(* TODO: remove redundant  0hr < x *)
paulson@7218
  1398
Goal "[| 0hr < r; 0hr < x; r < x |] ==> hrinv x < hrinv r";
wenzelm@7499
  1399
by (ftac hypreal_hrinv_gt_zero 1);
paulson@7218
  1400
by (forw_inst_tac [("x","x")] hypreal_hrinv_gt_zero 1);
paulson@7218
  1401
by (forw_inst_tac [("x","r"),("z","hrinv r")] hypreal_mult_less_mono1 1);
paulson@7218
  1402
by (assume_tac 1);
paulson@7218
  1403
by (asm_full_simp_tac (simpset() addsimps [hypreal_not_refl2 RS 
paulson@7218
  1404
         not_sym RS hypreal_mult_hrinv]) 1);
wenzelm@7499
  1405
by (ftac hypreal_hrinv_gt_zero 1);
paulson@7218
  1406
by (forw_inst_tac [("x","1hr"),("z","hrinv x")] hypreal_mult_less_mono2 1);
paulson@7218
  1407
by (assume_tac 1);
paulson@7218
  1408
by (asm_full_simp_tac (simpset() addsimps [hypreal_not_refl2 RS 
paulson@7218
  1409
         not_sym RS hypreal_mult_hrinv_left,hypreal_mult_assoc RS sym]) 1);
paulson@7218
  1410
qed "hypreal_hrinv_less_swap";
paulson@7218
  1411
paulson@7218
  1412
Goal "[| 0hr < r; 0hr < x|] ==> (r < x) = (hrinv x < hrinv r)";
paulson@7218
  1413
by (auto_tac (claset() addIs [hypreal_hrinv_less_swap],simpset()));
paulson@7218
  1414
by (res_inst_tac [("t","r")] (hypreal_hrinv_hrinv RS subst) 1);
paulson@7218
  1415
by (etac (hypreal_not_refl2 RS not_sym) 1);
paulson@7218
  1416
by (res_inst_tac [("t","x")] (hypreal_hrinv_hrinv RS subst) 1);
paulson@7218
  1417
by (etac (hypreal_not_refl2 RS not_sym) 1);
paulson@7218
  1418
by (auto_tac (claset() addIs [hypreal_hrinv_less_swap],
paulson@7218
  1419
    simpset() addsimps [hypreal_hrinv_gt_zero]));
paulson@7218
  1420
qed "hypreal_hrinv_less_iff";
paulson@7218
  1421
paulson@7218
  1422
Goal "[| 0hr < z; x < y |] ==> x*hrinv(z) < y*hrinv(z)";
paulson@7218
  1423
by (blast_tac (claset() addSIs [hypreal_mult_less_mono1,
paulson@7218
  1424
    hypreal_hrinv_gt_zero]) 1);
paulson@7218
  1425
qed "hypreal_mult_hrinv_less_mono1";
paulson@7218
  1426
paulson@7218
  1427
Goal "[| 0hr < z; x < y |] ==> hrinv(z)*x < hrinv(z)*y";
paulson@7218
  1428
by (blast_tac (claset() addSIs [hypreal_mult_less_mono2,
paulson@7218
  1429
    hypreal_hrinv_gt_zero]) 1);
paulson@7218
  1430
qed "hypreal_mult_hrinv_less_mono2";
paulson@7218
  1431
paulson@7218
  1432
Goal "[| 0hr < z; x*z < y*z |] ==> x < y";
paulson@7218
  1433
by (forw_inst_tac [("x","x*z")] hypreal_mult_hrinv_less_mono1 1);
paulson@7218
  1434
by (dtac (hypreal_not_refl2 RS not_sym) 2);
paulson@7218
  1435
by (auto_tac (claset() addSDs [hypreal_mult_hrinv],
paulson@7218
  1436
              simpset() addsimps hypreal_mult_ac));
paulson@7218
  1437
qed "hypreal_less_mult_right_cancel";
paulson@7218
  1438
paulson@7218
  1439
Goal "[| 0hr < z; z*x < z*y |] ==> x < y";
paulson@7218
  1440
by (auto_tac (claset() addIs [hypreal_less_mult_right_cancel],
paulson@7218
  1441
    simpset() addsimps [hypreal_mult_commute]));
paulson@7218
  1442
qed "hypreal_less_mult_left_cancel";
paulson@7218
  1443
paulson@7218
  1444
Goal "[| 0hr < r; 0hr < ra; \
paulson@7218
  1445
\                 r < x; ra < y |] \
paulson@7218
  1446
\              ==> r*ra < x*y";
paulson@7218
  1447
by (forw_inst_tac [("R2.0","r")] hypreal_less_trans 1);
paulson@7218
  1448
by (dres_inst_tac [("z","ra"),("x","r")] hypreal_mult_less_mono1 2);
paulson@7218
  1449
by (dres_inst_tac [("z","x"),("x","ra")] hypreal_mult_less_mono2 3);
paulson@7218
  1450
by (auto_tac (claset() addIs [hypreal_less_trans],simpset()));
paulson@7218
  1451
qed "hypreal_mult_less_gt_zero"; 
paulson@7218
  1452
paulson@7218
  1453
Goal "[| 0hr < r; 0hr < ra; \
paulson@7218
  1454
\                 r <= x; ra <= y |] \
paulson@7218
  1455
\              ==> r*ra <= x*y";
paulson@7218
  1456
by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
paulson@7218
  1457
by (rtac hypreal_less_or_eq_imp_le 1);
paulson@7218
  1458
by (auto_tac (claset() addIs [hypreal_mult_less_mono1,
paulson@7218
  1459
    hypreal_mult_less_mono2,hypreal_mult_less_gt_zero],
paulson@7218
  1460
    simpset()));
paulson@7218
  1461
qed "hypreal_mult_le_ge_zero"; 
paulson@7218
  1462
paulson@7218
  1463
Goal "? (x::hypreal). x < y";
paulson@7218
  1464
by (rtac (hypreal_add_zero_right RS subst) 1);
paulson@7218
  1465
by (res_inst_tac [("x","y + -1hr")] exI 1);
paulson@7218
  1466
by (auto_tac (claset() addSIs [hypreal_add_less_mono2],
paulson@7218
  1467
    simpset() addsimps [hypreal_minus_zero_less_iff2,
paulson@7218
  1468
    hypreal_zero_less_one] delsimps [hypreal_add_zero_right]));
paulson@7218
  1469
qed "hypreal_less_Ex";
paulson@7218
  1470
paulson@7218
  1471
Goal "!!(A::hypreal). A + C < B + C ==> A < B";
paulson@7218
  1472
by (dres_inst_tac [("C","-C")] hypreal_add_less_mono1 1);
paulson@7218
  1473
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
paulson@7218
  1474
qed "hypreal_less_add_right_cancel";
paulson@7218
  1475
paulson@7218
  1476
Goal "!!(A::hypreal). C + A < C + B ==> A < B";
paulson@7218
  1477
by (dres_inst_tac [("C","-C")] hypreal_add_less_mono2 1);
paulson@7218
  1478
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
paulson@7218
  1479
qed "hypreal_less_add_left_cancel";
paulson@7218
  1480
paulson@7218
  1481
Goal "0hr <= x*x";
paulson@7218
  1482
by (res_inst_tac [("x","0hr"),("y","x")] hypreal_linear_less2 1);
paulson@7218
  1483
by (auto_tac (claset() addIs [hypreal_mult_order,
paulson@7218
  1484
    hypreal_mult_less_zero1,hypreal_less_imp_le],
paulson@7218
  1485
    simpset()));
paulson@7218
  1486
qed "hypreal_le_square";
paulson@7218
  1487
Addsimps [hypreal_le_square];
paulson@7218
  1488
paulson@7218
  1489
Goalw [hypreal_le_def] "- (x*x) <= 0hr";
paulson@7218
  1490
by (auto_tac (claset() addSDs [(hypreal_le_square RS 
paulson@7218
  1491
    hypreal_le_less_trans)],simpset() addsimps 
paulson@7218
  1492
    [hypreal_minus_zero_less_iff,hypreal_less_not_refl]));
paulson@7218
  1493
qed "hypreal_less_minus_square";
paulson@7218
  1494
Addsimps [hypreal_less_minus_square];
paulson@7218
  1495
paulson@7218
  1496
Goal "[|x ~= 0hr; y ~= 0hr |] ==> \
paulson@7218
  1497
\                   hrinv(x) + hrinv(y) = (x + y)*hrinv(x*y)";
paulson@7218
  1498
by (asm_full_simp_tac (simpset() addsimps [hypreal_hrinv_distrib,
paulson@7218
  1499
             hypreal_add_mult_distrib,hypreal_mult_assoc RS sym]) 1);
wenzelm@7322
  1500
by (stac hypreal_mult_assoc 1);
paulson@7218
  1501
by (rtac (hypreal_mult_left_commute RS subst) 1);
paulson@7218
  1502
by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
paulson@7218
  1503
qed "hypreal_hrinv_add";
paulson@7218
  1504
paulson@7218
  1505
Goal "x = -x ==> x = 0hr";
paulson@7218
  1506
by (dtac (hypreal_eq_minus_iff RS iffD1 RS sym) 1);
paulson@7218
  1507
by (Asm_full_simp_tac 1);
paulson@7218
  1508
by (dtac (hypreal_add_self RS subst) 1);
paulson@7218
  1509
by (rtac ccontr 1);
paulson@7218
  1510
by (blast_tac (claset() addDs [hypreal_two_not_zero RSN
paulson@7218
  1511
               (2,hypreal_mult_not_0)]) 1);
paulson@7218
  1512
qed "hypreal_self_eq_minus_self_zero";
paulson@7218
  1513
paulson@7218
  1514
Goal "(x + x = 0hr) = (x = 0hr)";
paulson@7218
  1515
by Auto_tac;
paulson@7218
  1516
by (dtac (hypreal_add_self RS subst) 1);
paulson@7218
  1517
by (rtac ccontr 1 THEN rtac hypreal_mult_not_0E 1);
paulson@7218
  1518
by Auto_tac;
paulson@7218
  1519
qed "hypreal_add_self_zero_cancel";
paulson@7218
  1520
Addsimps [hypreal_add_self_zero_cancel];
paulson@7218
  1521
paulson@7218
  1522
Goal "(x + x + y = y) = (x = 0hr)";
paulson@7218
  1523
by Auto_tac;
paulson@7218
  1524
by (dtac (hypreal_eq_minus_iff RS iffD1) 1 THEN dtac sym 1);
paulson@7218
  1525
by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
paulson@7218
  1526
qed "hypreal_add_self_zero_cancel2";
paulson@7218
  1527
Addsimps [hypreal_add_self_zero_cancel2];
paulson@7218
  1528
paulson@7218
  1529
Goal "(x + (x + y) = y) = (x = 0hr)";
paulson@7218
  1530
by (simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
paulson@7218
  1531
qed "hypreal_add_self_zero_cancel2a";
paulson@7218
  1532
Addsimps [hypreal_add_self_zero_cancel2a];
paulson@7218
  1533
paulson@7218
  1534
Goal "(b = -a) = (-b = (a::hypreal))";
paulson@7218
  1535
by Auto_tac;
paulson@7218
  1536
qed "hypreal_minus_eq_swap";
paulson@7218
  1537
paulson@7218
  1538
Goal "(-b = -a) = (b = (a::hypreal))";
paulson@7218
  1539
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
  1540
    [hypreal_minus_eq_swap]) 1);
paulson@7218
  1541
qed "hypreal_minus_eq_cancel";
paulson@7218
  1542
Addsimps [hypreal_minus_eq_cancel];
paulson@7218
  1543
paulson@7218
  1544
Goal "x < x + 1hr";
paulson@7218
  1545
by (cut_inst_tac [("C","x")] 
paulson@7218
  1546
    (hypreal_zero_less_one RS hypreal_add_less_mono2) 1);
paulson@7218
  1547
by (Asm_full_simp_tac 1);
paulson@7218
  1548
qed "hypreal_less_self_add_one";
paulson@7218
  1549
Addsimps [hypreal_less_self_add_one];
paulson@7218
  1550
paulson@7218
  1551
Goal "((x::hypreal) + x = y + y) = (x = y)";
paulson@7218
  1552
by (auto_tac (claset() addIs [hypreal_two_not_zero RS 
paulson@7218
  1553
     hypreal_mult_left_cancel RS iffD1],simpset() addsimps 
paulson@7218
  1554
     [hypreal_add_mult_distrib]));
paulson@7218
  1555
qed "hypreal_add_self_cancel";
paulson@7218
  1556
Addsimps [hypreal_add_self_cancel];
paulson@7218
  1557
paulson@7218
  1558
Goal "(y = x + - y + x) = (y = (x::hypreal))";
paulson@7218
  1559
by Auto_tac;
paulson@7218
  1560
by (dres_inst_tac [("x1","y")] 
paulson@7218
  1561
    (hypreal_add_right_cancel RS iffD2) 1);
paulson@7218
  1562
by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
paulson@7218
  1563
qed "hypreal_add_self_minus_cancel";
paulson@7218
  1564
Addsimps [hypreal_add_self_minus_cancel];
paulson@7218
  1565
paulson@7218
  1566
Goal "(y = x + (- y + x)) = (y = (x::hypreal))";
paulson@7218
  1567
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
  1568
         [hypreal_add_assoc RS sym])1);
paulson@7218
  1569
qed "hypreal_add_self_minus_cancel2";
paulson@7218
  1570
Addsimps [hypreal_add_self_minus_cancel2];
paulson@7218
  1571
paulson@7218
  1572
Goal "z + -x = y + (y + (-x + -z)) = (y = (z::hypreal))";
paulson@7218
  1573
by Auto_tac;
paulson@7218
  1574
by (dres_inst_tac [("x1","z")] 
paulson@7218
  1575
    (hypreal_add_right_cancel RS iffD2) 1);
paulson@7218
  1576
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
  1577
    [hypreal_minus_add_distrib RS sym] @ hypreal_add_ac) 1);
paulson@7218
  1578
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
  1579
     [hypreal_add_assoc RS sym,hypreal_add_right_cancel]) 1);
paulson@7218
  1580
qed "hypreal_add_self_minus_cancel3";
paulson@7218
  1581
Addsimps [hypreal_add_self_minus_cancel3];
paulson@7218
  1582
paulson@7218
  1583
(* check why this does not work without 2nd substiution anymore! *)
paulson@7218
  1584
Goal "x < y ==> x < (x + y)*hrinv(1hr + 1hr)";
paulson@7218
  1585
by (dres_inst_tac [("C","x")] hypreal_add_less_mono2 1);
paulson@7218
  1586
by (dtac (hypreal_add_self RS subst) 1);
paulson@7218
  1587
by (dtac (hypreal_zero_less_two RS hypreal_hrinv_gt_zero RS 
paulson@7218
  1588
          hypreal_mult_less_mono1) 1);
paulson@7218
  1589
by (auto_tac (claset() addDs [hypreal_two_not_zero RS 
paulson@7218
  1590
          (hypreal_mult_hrinv RS subst)],simpset() 
paulson@7218
  1591
          addsimps [hypreal_mult_assoc]));
paulson@7218
  1592
qed "hypreal_less_half_sum";
paulson@7218
  1593
paulson@7218
  1594
(* check why this does not work without 2nd substiution anymore! *)
paulson@7218
  1595
Goal "x < y ==> (x + y)*hrinv(1hr + 1hr) < y";
paulson@7218
  1596
by (dres_inst_tac [("C","y")] hypreal_add_less_mono1 1);
paulson@7218
  1597
by (dtac (hypreal_add_self RS subst) 1);
paulson@7218
  1598
by (dtac (hypreal_zero_less_two RS hypreal_hrinv_gt_zero RS 
paulson@7218
  1599
          hypreal_mult_less_mono1) 1);
paulson@7218
  1600
by (auto_tac (claset() addDs [hypreal_two_not_zero RS 
paulson@7218
  1601
          (hypreal_mult_hrinv RS subst)],simpset() 
paulson@7218
  1602
          addsimps [hypreal_mult_assoc]));
paulson@7218
  1603
qed "hypreal_gt_half_sum";
paulson@7218
  1604
paulson@7218
  1605
Goal "!!(x::hypreal). x < y ==> EX r. x < r & r < y";
paulson@7218
  1606
by (blast_tac (claset() addSIs [hypreal_less_half_sum,
paulson@7218
  1607
    hypreal_gt_half_sum]) 1);
paulson@7218
  1608
qed "hypreal_dense";
paulson@7218
  1609
paulson@7218
  1610
Goal "(x * x = 0hr) = (x = 0hr)";
paulson@7218
  1611
by Auto_tac;
paulson@7218
  1612
by (blast_tac (claset() addIs [hypreal_mult_not_0E]) 1);
paulson@7218
  1613
qed "hypreal_mult_self_eq_zero_iff";
paulson@7218
  1614
Addsimps [hypreal_mult_self_eq_zero_iff];
paulson@7218
  1615
paulson@7218
  1616
Goal "(0hr = x * x) = (x = 0hr)";
paulson@7218
  1617
by (auto_tac (claset() addDs [sym],simpset()));
paulson@7218
  1618
qed "hypreal_mult_self_eq_zero_iff2";
paulson@7218
  1619
Addsimps [hypreal_mult_self_eq_zero_iff2];
paulson@7218
  1620
paulson@7218
  1621
Goal "(x*x + y*y = 0hr) = (x = 0hr & y = 0hr)";
paulson@7218
  1622
by Auto_tac;
paulson@7218
  1623
by (dtac (sym RS (hypreal_eq_minus_iff3 RS iffD1))  1);
paulson@7218
  1624
by (dtac (sym RS (hypreal_eq_minus_iff4 RS iffD1))  2);
paulson@7218
  1625
by (ALLGOALS(rtac ccontr));
paulson@7218
  1626
by (ALLGOALS(dtac hypreal_mult_self_not_zero));
paulson@7218
  1627
by (cut_inst_tac [("x1","x")] (hypreal_le_square 
paulson@7218
  1628
        RS hypreal_le_imp_less_or_eq) 1);
paulson@7218
  1629
by (cut_inst_tac [("x1","y")] (hypreal_le_square 
paulson@7218
  1630
        RS hypreal_le_imp_less_or_eq) 2);
paulson@7218
  1631
by (auto_tac (claset() addDs [sym],simpset()));
paulson@7218
  1632
by (dres_inst_tac [("x1","y")] (hypreal_less_minus_square 
paulson@7218
  1633
    RS hypreal_le_less_trans) 1);
paulson@7218
  1634
by (dres_inst_tac [("x1","x")] (hypreal_less_minus_square 
paulson@7218
  1635
    RS hypreal_le_less_trans) 2);
paulson@7218
  1636
by (auto_tac (claset(),simpset() addsimps 
paulson@7218
  1637
       [hypreal_less_not_refl]));
paulson@7218
  1638
qed "hypreal_squares_add_zero_iff";
paulson@7218
  1639
Addsimps [hypreal_squares_add_zero_iff];
paulson@7218
  1640
paulson@7218
  1641
Goal "x * x ~= 0hr ==> 0hr < x* x + y*y + z*z";
paulson@7218
  1642
by (cut_inst_tac [("x1","x")] (hypreal_le_square 
paulson@7218
  1643
        RS hypreal_le_imp_less_or_eq) 1);
paulson@7218
  1644
by (auto_tac (claset() addSIs 
paulson@7218
  1645
              [hypreal_add_order_le],simpset()));
paulson@7218
  1646
qed "hypreal_sum_squares3_gt_zero";
paulson@7218
  1647
paulson@7218
  1648
Goal "x * x ~= 0hr ==> 0hr < y*y + x*x + z*z";
paulson@7218
  1649
by (dtac hypreal_sum_squares3_gt_zero 1);
paulson@7218
  1650
by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
paulson@7218
  1651
qed "hypreal_sum_squares3_gt_zero2";
paulson@7218
  1652
paulson@7218
  1653
Goal "x * x ~= 0hr ==> 0hr < y*y + z*z + x*x";
paulson@7218
  1654
by (dtac hypreal_sum_squares3_gt_zero 1);
paulson@7218
  1655
by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
paulson@7218
  1656
qed "hypreal_sum_squares3_gt_zero3";
paulson@7218
  1657
paulson@7218
  1658
Goal "(x*x + y*y + z*z = 0hr) = \ 
paulson@7218
  1659
\               (x = 0hr & y = 0hr & z = 0hr)";
paulson@7218
  1660
by Auto_tac;
paulson@7218
  1661
by (ALLGOALS(rtac ccontr));
paulson@7218
  1662
by (ALLGOALS(dtac hypreal_mult_self_not_zero));
paulson@7218
  1663
by (auto_tac (claset() addDs [hypreal_not_refl2 RS not_sym,
paulson@7218
  1664
   hypreal_sum_squares3_gt_zero3,hypreal_sum_squares3_gt_zero,
paulson@7218
  1665
   hypreal_sum_squares3_gt_zero2],simpset() delsimps
paulson@7218
  1666
   [hypreal_mult_self_eq_zero_iff]));
paulson@7218
  1667
qed "hypreal_three_squares_add_zero_iff";
paulson@7218
  1668
Addsimps [hypreal_three_squares_add_zero_iff];
paulson@7218
  1669
fleuriot@9013
  1670
Addsimps [rename_numerals thy real_le_square];
paulson@7218
  1671
Goal "(x::hypreal)*x <= x*x + y*y";
paulson@7218
  1672
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
  1673
by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
paulson@7218
  1674
by (auto_tac (claset(),simpset() addsimps 
paulson@7218
  1675
    [hypreal_mult,hypreal_add,hypreal_le]));
paulson@7218
  1676
qed "hypreal_self_le_add_pos";
paulson@7218
  1677
Addsimps [hypreal_self_le_add_pos];
paulson@7218
  1678
paulson@7218
  1679
Goal "(x::hypreal)*x <= x*x + y*y + z*z";
paulson@7218
  1680
by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
paulson@7218
  1681
by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
paulson@7218
  1682
by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
paulson@7218
  1683
by (auto_tac (claset(),simpset() addsimps 
paulson@7218
  1684
    [hypreal_mult,hypreal_add,hypreal_le,
fleuriot@9013
  1685
    rename_numerals thy real_le_add_order]));
paulson@7218
  1686
qed "hypreal_self_le_add_pos2";
paulson@7218
  1687
Addsimps [hypreal_self_le_add_pos2];
paulson@7218
  1688
paulson@7218
  1689
(*---------------------------------------------------------------------------------
paulson@7218
  1690
             Embedding of the naturals in the hyperreals
paulson@7218
  1691
 ---------------------------------------------------------------------------------*)
paulson@7218
  1692
Goalw [hypreal_of_posnat_def] "hypreal_of_posnat 0 = 1hr";
paulson@7218
  1693
by (full_simp_tac (simpset() addsimps 
paulson@7218
  1694
    [pnat_one_iff RS sym,real_of_preal_def]) 1);
paulson@7218
  1695
by (fold_tac [real_one_def]);
fleuriot@9013
  1696
by (simp_tac (simpset() addsimps [hypreal_of_real_one]) 1);
paulson@7218
  1697
qed "hypreal_of_posnat_one";
paulson@7218
  1698
paulson@7218
  1699
Goalw [hypreal_of_posnat_def] "hypreal_of_posnat 1 = 1hr + 1hr";
fleuriot@9013
  1700
by (full_simp_tac (simpset() addsimps [real_of_preal_def,
fleuriot@9013
  1701
    rename_numerals thy (real_one_def RS meta_eq_to_obj_eq),
fleuriot@9013
  1702
     hypreal_add,hypreal_of_real_def,pnat_two_eq,hypreal_one_def,
fleuriot@9013
  1703
    real_add,prat_of_pnat_add RS sym,preal_of_prat_add RS sym] @ 
fleuriot@9013
  1704
    pnat_add_ac) 1);
paulson@7218
  1705
qed "hypreal_of_posnat_two";
paulson@7218
  1706
paulson@7218
  1707
Goalw [hypreal_of_posnat_def]
paulson@7218
  1708
          "hypreal_of_posnat n1 + hypreal_of_posnat n2 = \
paulson@7218
  1709
\          hypreal_of_posnat (n1 + n2) + 1hr";
paulson@7218
  1710
by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_one RS sym,
paulson@7218
  1711
    hypreal_of_real_add RS sym,hypreal_of_posnat_def,real_of_preal_add RS sym,
paulson@7218
  1712
    preal_of_prat_add RS sym,prat_of_pnat_add RS sym,pnat_of_nat_add]) 1);
paulson@7218
  1713
qed "hypreal_of_posnat_add";
paulson@7218
  1714
paulson@7218
  1715
Goal "hypreal_of_posnat (n + 1) = hypreal_of_posnat n + 1hr";
paulson@7218
  1716
by (res_inst_tac [("x1","1hr")] (hypreal_add_right_cancel RS iffD1) 1);
paulson@7218
  1717
by (rtac (hypreal_of_posnat_add RS subst) 1);
paulson@7218
  1718
by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_two,hypreal_add_assoc]) 1);
paulson@7218
  1719
qed "hypreal_of_posnat_add_one";
paulson@7218
  1720
paulson@7218
  1721
Goalw [real_of_posnat_def,hypreal_of_posnat_def] 
paulson@7218
  1722
      "hypreal_of_posnat n = hypreal_of_real (real_of_posnat n)";
paulson@7218
  1723
by (rtac refl 1);
paulson@7218
  1724
qed "hypreal_of_real_of_posnat";
paulson@7218
  1725
paulson@7218
  1726
Goalw [hypreal_of_posnat_def] 
paulson@7218
  1727
      "(n < m) = (hypreal_of_posnat n < hypreal_of_posnat m)";
paulson@7218
  1728
by Auto_tac;
paulson@7218
  1729
qed "hypreal_of_posnat_less_iff";
paulson@7218
  1730
paulson@7218
  1731
Addsimps [hypreal_of_posnat_less_iff RS sym];
paulson@7218
  1732
(*---------------------------------------------------------------------------------
paulson@7218
  1733
               Existence of infinite hyperreal number
paulson@7218
  1734
 ---------------------------------------------------------------------------------*)
paulson@7218
  1735
paulson@7218
  1736
Goal "hyprel^^{%n::nat. real_of_posnat n} : hypreal";
paulson@7218
  1737
by Auto_tac;
paulson@7218
  1738
qed "hypreal_omega";
paulson@7218
  1739
paulson@7218
  1740
Goalw [omega_def] "Rep_hypreal(whr) : hypreal";
paulson@7218
  1741
by (rtac Rep_hypreal 1);
paulson@7218
  1742
qed "Rep_hypreal_omega";
paulson@7218
  1743
paulson@7218
  1744
(* existence of infinite number not corresponding to any real number *)
paulson@7218
  1745
(* use assumption that member FreeUltrafilterNat is not finite       *)
paulson@7218
  1746
(* a few lemmas first *)
paulson@7218
  1747
paulson@7218
  1748
Goal "{n::nat. x = real_of_posnat n} = {} | \
paulson@7218
  1749
\     (? y. {n::nat. x = real_of_posnat n} = {y})";
paulson@7218
  1750
by (auto_tac (claset() addDs [inj_real_of_posnat RS injD],simpset()));
paulson@7218
  1751
qed "lemma_omega_empty_singleton_disj";
paulson@7218
  1752
paulson@7218
  1753
Goal "finite {n::nat. x = real_of_posnat n}";
paulson@7218
  1754
by (cut_inst_tac [("x","x")] lemma_omega_empty_singleton_disj 1);
paulson@7218
  1755
by Auto_tac;
paulson@7218
  1756
qed "lemma_finite_omega_set";
paulson@7218
  1757
paulson@7218
  1758
Goalw [omega_def,hypreal_of_real_def] 
paulson@7218
  1759
      "~ (? x. hypreal_of_real x = whr)";
paulson@7218
  1760
by (auto_tac (claset(),simpset() addsimps [lemma_finite_omega_set 
paulson@7218
  1761
    RS FreeUltrafilterNat_finite]));
paulson@7218
  1762
qed "not_ex_hypreal_of_real_eq_omega";
paulson@7218
  1763
paulson@7218
  1764
Goal "hypreal_of_real x ~= whr";
paulson@7218
  1765
by (cut_facts_tac [not_ex_hypreal_of_real_eq_omega] 1);
paulson@7218
  1766
by Auto_tac;
paulson@7218
  1767
qed "hypreal_of_real_not_eq_omega";
paulson@7218
  1768
paulson@7218
  1769
(* existence of infinitesimal number also not *)
paulson@7218
  1770
(* corresponding to any real number *)
paulson@7218
  1771
paulson@7218
  1772
Goal "{n::nat. x = rinv(real_of_posnat n)} = {} | \
paulson@7218
  1773
\     (? y. {n::nat. x = rinv(real_of_posnat n)} = {y})";
paulson@7218
  1774
by (Step_tac 1 THEN Step_tac 1);
paulson@7218
  1775
by (auto_tac (claset() addIs [real_of_posnat_rinv_inj],simpset()));
paulson@7218
  1776
qed "lemma_epsilon_empty_singleton_disj";
paulson@7218
  1777
paulson@7218
  1778
Goal "finite {n::nat. x = rinv(real_of_posnat n)}";
paulson@7218
  1779
by (cut_inst_tac [("x","x")] lemma_epsilon_empty_singleton_disj 1);
paulson@7218
  1780
by Auto_tac;
paulson@7218
  1781
qed "lemma_finite_epsilon_set";
paulson@7218
  1782
paulson@7218
  1783
Goalw [epsilon_def,hypreal_of_real_def] 
paulson@7218
  1784
      "~ (? x. hypreal_of_real x = ehr)";
paulson@7218
  1785
by (auto_tac (claset(),simpset() addsimps [lemma_finite_epsilon_set 
paulson@7218
  1786
    RS FreeUltrafilterNat_finite]));
paulson@7218
  1787
qed "not_ex_hypreal_of_real_eq_epsilon";
paulson@7218
  1788
paulson@7218
  1789
Goal "hypreal_of_real x ~= ehr";
paulson@7218
  1790
by (cut_facts_tac [not_ex_hypreal_of_real_eq_epsilon] 1);
paulson@7218
  1791
by Auto_tac;
paulson@7218
  1792
qed "hypreal_of_real_not_eq_epsilon";
paulson@7218
  1793
paulson@7218
  1794
Goalw [epsilon_def,hypreal_zero_def] "ehr ~= 0hr";
paulson@7218
  1795
by (auto_tac (claset(),simpset() addsimps 
fleuriot@9013
  1796
    [rename_numerals thy real_of_posnat_rinv_not_zero]));
paulson@7218
  1797
qed "hypreal_epsilon_not_zero";
paulson@7218
  1798
fleuriot@9013
  1799
Addsimps [rename_numerals thy real_of_posnat_not_eq_zero];
paulson@7218
  1800
Goalw [omega_def,hypreal_zero_def] "whr ~= 0hr";
paulson@7218
  1801
by (Simp_tac 1);
paulson@7218
  1802
qed "hypreal_omega_not_zero";
paulson@7218
  1803
paulson@7218
  1804
Goal "ehr = hrinv(whr)";
paulson@7218
  1805
by (asm_full_simp_tac (simpset() addsimps 
paulson@7218
  1806
    [hypreal_hrinv,omega_def,epsilon_def]
paulson@7218
  1807
    setloop (split_tac [expand_if])) 1);
paulson@7218
  1808
qed "hypreal_epsilon_hrinv_omega";
paulson@7218
  1809
paulson@7218
  1810
(*----------------------------------------------------------------
paulson@7218
  1811
     Another embedding of the naturals in the 
paulson@7218
  1812
    hyperreals (see hypreal_of_posnat)
paulson@7218
  1813
 ----------------------------------------------------------------*)
paulson@7218
  1814
Goalw [hypreal_of_nat_def] "hypreal_of_nat 0 = 0hr";
paulson@7218
  1815
by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_one]) 1);
paulson@7218
  1816
qed "hypreal_of_nat_zero";
paulson@7218
  1817
paulson@7218
  1818
Goalw [hypreal_of_nat_def] "hypreal_of_nat 1 = 1hr";
paulson@7218
  1819
by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_two,
paulson@7218
  1820
    hypreal_add_assoc]) 1);
paulson@7218
  1821
qed "hypreal_of_nat_one";
paulson@7218
  1822
paulson@7218
  1823
Goalw [hypreal_of_nat_def]
paulson@7218
  1824
      "hypreal_of_nat n1 + hypreal_of_nat n2 = \
paulson@7218
  1825
\      hypreal_of_nat (n1 + n2)";
paulson@7218
  1826
by (full_simp_tac (simpset() addsimps hypreal_add_ac) 1);
paulson@7218
  1827
by (simp_tac (simpset() addsimps [hypreal_of_posnat_add,
paulson@7218
  1828
    hypreal_add_assoc RS sym]) 1);
paulson@7218
  1829
by (rtac (hypreal_add_commute RS subst) 1);
paulson@7218
  1830
by (simp_tac (simpset() addsimps [hypreal_add_left_cancel,
paulson@7218
  1831
    hypreal_add_assoc]) 1);
paulson@7218
  1832
qed "hypreal_of_nat_add";
paulson@7218
  1833
paulson@7218
  1834
Goal "hypreal_of_nat 2 = 1hr + 1hr";
paulson@7218
  1835
by (simp_tac (simpset() addsimps [hypreal_of_nat_one 
paulson@7218
  1836
    RS sym,hypreal_of_nat_add]) 1);
paulson@7218
  1837
qed "hypreal_of_nat_two";
paulson@7218
  1838
paulson@7218
  1839
Goalw [hypreal_of_nat_def] 
paulson@7218
  1840
      "(n < m) = (hypreal_of_nat n < hypreal_of_nat m)";
paulson@7218
  1841
by (auto_tac (claset() addIs [hypreal_add_less_mono1],simpset()));
paulson@7218
  1842
by (dres_inst_tac [("C","1hr")] hypreal_add_less_mono1 1);
paulson@7218
  1843
by (full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
paulson@7218
  1844
qed "hypreal_of_nat_less_iff";
paulson@7218
  1845
Addsimps [hypreal_of_nat_less_iff RS sym];
paulson@7218
  1846
paulson@7218
  1847
(* naturals embedded in hyperreals is an hyperreal *)
paulson@7218
  1848
Goalw [hypreal_of_nat_def,real_of_nat_def] 
paulson@7218
  1849
      "hypreal_of_nat  m = Abs_hypreal(hyprel^^{%n. real_of_nat m})";
paulson@7218
  1850
by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_def,
paulson@7218
  1851
    hypreal_of_real_of_posnat,hypreal_minus,hypreal_one_def,hypreal_add]));
paulson@7218
  1852
qed "hypreal_of_nat_iff";
paulson@7218
  1853
paulson@7218
  1854
Goal "inj hypreal_of_nat";
paulson@7218
  1855
by (rtac injI 1);
paulson@7218
  1856
by (auto_tac (claset() addSDs [FreeUltrafilterNat_P],
paulson@7825
  1857
        simpset() addsimps [split_if_mem1, hypreal_of_nat_iff,
paulson@7218
  1858
        real_add_right_cancel,inj_real_of_nat RS injD]));
paulson@7218
  1859
qed "inj_hypreal_of_nat";
paulson@7218
  1860
paulson@7218
  1861
Goalw [hypreal_of_nat_def,hypreal_of_real_def,hypreal_of_posnat_def,
paulson@7218
  1862
       real_of_posnat_def,hypreal_one_def,real_of_nat_def] 
paulson@7218
  1863
       "hypreal_of_nat n = hypreal_of_real (real_of_nat n)";
paulson@7218
  1864
by (simp_tac (simpset() addsimps [hypreal_add,hypreal_minus]) 1);
paulson@7218
  1865
qed "hypreal_of_nat_real_of_nat";