src/HOL/Real/RealDef.thy
author nipkow
Mon Feb 21 19:23:46 2005 +0100 (2005-02-21)
changeset 15542 ee6cd48cf840
parent 15229 1eb23f805c06
child 15923 01d5d0c1c078
permissions -rw-r--r--
more fine tuniung
     1 (*  Title       : Real/RealDef.thy
     2     ID          : $Id$
     3     Author      : Jacques D. Fleuriot
     4     Copyright   : 1998  University of Cambridge
     5     Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
     6 *)
     7 
     8 header{*Defining the Reals from the Positive Reals*}
     9 
    10 theory RealDef
    11 imports PReal
    12 files ("real_arith.ML")
    13 begin
    14 
    15 constdefs
    16   realrel   ::  "((preal * preal) * (preal * preal)) set"
    17   "realrel == {p. \<exists>x1 y1 x2 y2. p = ((x1,y1),(x2,y2)) & x1+y2 = x2+y1}"
    18 
    19 typedef (Real)  real = "UNIV//realrel"
    20   by (auto simp add: quotient_def)
    21 
    22 instance real :: "{ord, zero, one, plus, times, minus, inverse}" ..
    23 
    24 constdefs
    25 
    26   (** these don't use the overloaded "real" function: users don't see them **)
    27 
    28   real_of_preal :: "preal => real"
    29   "real_of_preal m     ==
    30            Abs_Real(realrel``{(m + preal_of_rat 1, preal_of_rat 1)})"
    31 
    32 consts
    33    (*Overloaded constant denoting the Real subset of enclosing
    34      types such as hypreal and complex*)
    35    Reals :: "'a set"
    36 
    37    (*overloaded constant for injecting other types into "real"*)
    38    real :: "'a => real"
    39 
    40 syntax (xsymbols)
    41   Reals     :: "'a set"                   ("\<real>")
    42 
    43 
    44 defs (overloaded)
    45 
    46   real_zero_def:
    47   "0 == Abs_Real(realrel``{(preal_of_rat 1, preal_of_rat 1)})"
    48 
    49   real_one_def:
    50   "1 == Abs_Real(realrel``
    51                {(preal_of_rat 1 + preal_of_rat 1,
    52 		 preal_of_rat 1)})"
    53 
    54   real_minus_def:
    55   "- r ==  contents (\<Union>(x,y) \<in> Rep_Real(r). { Abs_Real(realrel``{(y,x)}) })"
    56 
    57   real_add_def:
    58    "z + w ==
    59        contents (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w).
    60 		 { Abs_Real(realrel``{(x+u, y+v)}) })"
    61 
    62   real_diff_def:
    63    "r - (s::real) == r + - s"
    64 
    65   real_mult_def:
    66     "z * w ==
    67        contents (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w).
    68 		 { Abs_Real(realrel``{(x*u + y*v, x*v + y*u)}) })"
    69 
    70   real_inverse_def:
    71   "inverse (R::real) == (SOME S. (R = 0 & S = 0) | S * R = 1)"
    72 
    73   real_divide_def:
    74   "R / (S::real) == R * inverse S"
    75 
    76   real_le_def:
    77    "z \<le> (w::real) == 
    78     \<exists>x y u v. x+v \<le> u+y & (x,y) \<in> Rep_Real z & (u,v) \<in> Rep_Real w"
    79 
    80   real_less_def: "(x < (y::real)) == (x \<le> y & x \<noteq> y)"
    81 
    82   real_abs_def:  "abs (r::real) == (if 0 \<le> r then r else -r)"
    83 
    84 
    85 
    86 subsection{*Proving that realrel is an equivalence relation*}
    87 
    88 lemma preal_trans_lemma:
    89   assumes "x + y1 = x1 + y"
    90       and "x + y2 = x2 + y"
    91   shows "x1 + y2 = x2 + (y1::preal)"
    92 proof -
    93   have "(x1 + y2) + x = (x + y2) + x1" by (simp add: preal_add_ac) 
    94   also have "... = (x2 + y) + x1"  by (simp add: prems)
    95   also have "... = x2 + (x1 + y)"  by (simp add: preal_add_ac)
    96   also have "... = x2 + (x + y1)"  by (simp add: prems)
    97   also have "... = (x2 + y1) + x"  by (simp add: preal_add_ac)
    98   finally have "(x1 + y2) + x = (x2 + y1) + x" .
    99   thus ?thesis by (simp add: preal_add_right_cancel_iff) 
   100 qed
   101 
   102 
   103 lemma realrel_iff [simp]: "(((x1,y1),(x2,y2)) \<in> realrel) = (x1 + y2 = x2 + y1)"
   104 by (simp add: realrel_def)
   105 
   106 lemma equiv_realrel: "equiv UNIV realrel"
   107 apply (auto simp add: equiv_def refl_def sym_def trans_def realrel_def)
   108 apply (blast dest: preal_trans_lemma) 
   109 done
   110 
   111 text{*Reduces equality of equivalence classes to the @{term realrel} relation:
   112   @{term "(realrel `` {x} = realrel `` {y}) = ((x,y) \<in> realrel)"} *}
   113 lemmas equiv_realrel_iff = 
   114        eq_equiv_class_iff [OF equiv_realrel UNIV_I UNIV_I]
   115 
   116 declare equiv_realrel_iff [simp]
   117 
   118 
   119 lemma realrel_in_real [simp]: "realrel``{(x,y)}: Real"
   120 by (simp add: Real_def realrel_def quotient_def, blast)
   121 
   122 
   123 lemma inj_on_Abs_Real: "inj_on Abs_Real Real"
   124 apply (rule inj_on_inverseI)
   125 apply (erule Abs_Real_inverse)
   126 done
   127 
   128 declare inj_on_Abs_Real [THEN inj_on_iff, simp]
   129 declare Abs_Real_inverse [simp]
   130 
   131 
   132 text{*Case analysis on the representation of a real number as an equivalence
   133       class of pairs of positive reals.*}
   134 lemma eq_Abs_Real [case_names Abs_Real, cases type: real]: 
   135      "(!!x y. z = Abs_Real(realrel``{(x,y)}) ==> P) ==> P"
   136 apply (rule Rep_Real [of z, unfolded Real_def, THEN quotientE])
   137 apply (drule arg_cong [where f=Abs_Real])
   138 apply (auto simp add: Rep_Real_inverse)
   139 done
   140 
   141 
   142 subsection{*Congruence property for addition*}
   143 
   144 lemma real_add_congruent2_lemma:
   145      "[|a + ba = aa + b; ab + bc = ac + bb|]
   146       ==> a + ab + (ba + bc) = aa + ac + (b + (bb::preal))"
   147 apply (simp add: preal_add_assoc) 
   148 apply (rule preal_add_left_commute [of ab, THEN ssubst])
   149 apply (simp add: preal_add_assoc [symmetric])
   150 apply (simp add: preal_add_ac)
   151 done
   152 
   153 lemma real_add:
   154      "Abs_Real (realrel``{(x,y)}) + Abs_Real (realrel``{(u,v)}) =
   155       Abs_Real (realrel``{(x+u, y+v)})"
   156 proof -
   157   have "(\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). {Abs_Real (realrel `` {(x+u, y+v)})}) w) z)
   158         respects2 realrel"
   159     by (simp add: congruent2_def, blast intro: real_add_congruent2_lemma) 
   160   thus ?thesis
   161     by (simp add: real_add_def UN_UN_split_split_eq
   162                   UN_equiv_class2 [OF equiv_realrel equiv_realrel])
   163 qed
   164 
   165 lemma real_add_commute: "(z::real) + w = w + z"
   166 by (cases z, cases w, simp add: real_add preal_add_ac)
   167 
   168 lemma real_add_assoc: "((z1::real) + z2) + z3 = z1 + (z2 + z3)"
   169 by (cases z1, cases z2, cases z3, simp add: real_add preal_add_assoc)
   170 
   171 lemma real_add_zero_left: "(0::real) + z = z"
   172 by (cases z, simp add: real_add real_zero_def preal_add_ac)
   173 
   174 instance real :: comm_monoid_add
   175   by (intro_classes,
   176       (assumption | 
   177        rule real_add_commute real_add_assoc real_add_zero_left)+)
   178 
   179 
   180 subsection{*Additive Inverse on real*}
   181 
   182 lemma real_minus: "- Abs_Real(realrel``{(x,y)}) = Abs_Real(realrel `` {(y,x)})"
   183 proof -
   184   have "(\<lambda>(x,y). {Abs_Real (realrel``{(y,x)})}) respects realrel"
   185     by (simp add: congruent_def preal_add_commute) 
   186   thus ?thesis
   187     by (simp add: real_minus_def UN_equiv_class [OF equiv_realrel])
   188 qed
   189 
   190 lemma real_add_minus_left: "(-z) + z = (0::real)"
   191 by (cases z, simp add: real_minus real_add real_zero_def preal_add_commute)
   192 
   193 
   194 subsection{*Congruence property for multiplication*}
   195 
   196 lemma real_mult_congruent2_lemma:
   197      "!!(x1::preal). [| x1 + y2 = x2 + y1 |] ==>
   198           x * x1 + y * y1 + (x * y2 + y * x2) =
   199           x * x2 + y * y2 + (x * y1 + y * x1)"
   200 apply (simp add: preal_add_left_commute preal_add_assoc [symmetric])
   201 apply (simp add: preal_add_assoc preal_add_mult_distrib2 [symmetric])
   202 apply (simp add: preal_add_commute)
   203 done
   204 
   205 lemma real_mult_congruent2:
   206     "(%p1 p2.
   207         (%(x1,y1). (%(x2,y2). 
   208           { Abs_Real (realrel``{(x1*x2 + y1*y2, x1*y2+y1*x2)}) }) p2) p1)
   209      respects2 realrel"
   210 apply (rule congruent2_commuteI [OF equiv_realrel], clarify)
   211 apply (simp add: preal_mult_commute preal_add_commute)
   212 apply (auto simp add: real_mult_congruent2_lemma)
   213 done
   214 
   215 lemma real_mult:
   216       "Abs_Real((realrel``{(x1,y1)})) * Abs_Real((realrel``{(x2,y2)})) =
   217        Abs_Real(realrel `` {(x1*x2+y1*y2,x1*y2+y1*x2)})"
   218 by (simp add: real_mult_def UN_UN_split_split_eq
   219          UN_equiv_class2 [OF equiv_realrel equiv_realrel real_mult_congruent2])
   220 
   221 lemma real_mult_commute: "(z::real) * w = w * z"
   222 by (cases z, cases w, simp add: real_mult preal_add_ac preal_mult_ac)
   223 
   224 lemma real_mult_assoc: "((z1::real) * z2) * z3 = z1 * (z2 * z3)"
   225 apply (cases z1, cases z2, cases z3)
   226 apply (simp add: real_mult preal_add_mult_distrib2 preal_add_ac preal_mult_ac)
   227 done
   228 
   229 lemma real_mult_1: "(1::real) * z = z"
   230 apply (cases z)
   231 apply (simp add: real_mult real_one_def preal_add_mult_distrib2
   232                  preal_mult_1_right preal_mult_ac preal_add_ac)
   233 done
   234 
   235 lemma real_add_mult_distrib: "((z1::real) + z2) * w = (z1 * w) + (z2 * w)"
   236 apply (cases z1, cases z2, cases w)
   237 apply (simp add: real_add real_mult preal_add_mult_distrib2 
   238                  preal_add_ac preal_mult_ac)
   239 done
   240 
   241 text{*one and zero are distinct*}
   242 lemma real_zero_not_eq_one: "0 \<noteq> (1::real)"
   243 proof -
   244   have "preal_of_rat 1 < preal_of_rat 1 + preal_of_rat 1"
   245     by (simp add: preal_self_less_add_left) 
   246   thus ?thesis
   247     by (simp add: real_zero_def real_one_def preal_add_right_cancel_iff)
   248 qed
   249 
   250 subsection{*existence of inverse*}
   251 
   252 lemma real_zero_iff: "Abs_Real (realrel `` {(x, x)}) = 0"
   253 by (simp add: real_zero_def preal_add_commute)
   254 
   255 text{*Instead of using an existential quantifier and constructing the inverse
   256 within the proof, we could define the inverse explicitly.*}
   257 
   258 lemma real_mult_inverse_left_ex: "x \<noteq> 0 ==> \<exists>y. y*x = (1::real)"
   259 apply (simp add: real_zero_def real_one_def, cases x)
   260 apply (cut_tac x = xa and y = y in linorder_less_linear)
   261 apply (auto dest!: less_add_left_Ex simp add: real_zero_iff)
   262 apply (rule_tac
   263         x = "Abs_Real (realrel `` { (preal_of_rat 1, 
   264                             inverse (D) + preal_of_rat 1)}) " 
   265        in exI)
   266 apply (rule_tac [2]
   267         x = "Abs_Real (realrel `` { (inverse (D) + preal_of_rat 1,
   268                    preal_of_rat 1)})" 
   269        in exI)
   270 apply (auto simp add: real_mult preal_mult_1_right
   271               preal_add_mult_distrib2 preal_add_mult_distrib preal_mult_1
   272               preal_mult_inverse_right preal_add_ac preal_mult_ac)
   273 done
   274 
   275 lemma real_mult_inverse_left: "x \<noteq> 0 ==> inverse(x)*x = (1::real)"
   276 apply (simp add: real_inverse_def)
   277 apply (frule real_mult_inverse_left_ex, safe)
   278 apply (rule someI2, auto)
   279 done
   280 
   281 
   282 subsection{*The Real Numbers form a Field*}
   283 
   284 instance real :: field
   285 proof
   286   fix x y z :: real
   287   show "- x + x = 0" by (rule real_add_minus_left)
   288   show "x - y = x + (-y)" by (simp add: real_diff_def)
   289   show "(x * y) * z = x * (y * z)" by (rule real_mult_assoc)
   290   show "x * y = y * x" by (rule real_mult_commute)
   291   show "1 * x = x" by (rule real_mult_1)
   292   show "(x + y) * z = x * z + y * z" by (simp add: real_add_mult_distrib)
   293   show "0 \<noteq> (1::real)" by (rule real_zero_not_eq_one)
   294   show "x \<noteq> 0 ==> inverse x * x = 1" by (rule real_mult_inverse_left)
   295   show "x / y = x * inverse y" by (simp add: real_divide_def)
   296 qed
   297 
   298 
   299 text{*Inverse of zero!  Useful to simplify certain equations*}
   300 
   301 lemma INVERSE_ZERO: "inverse 0 = (0::real)"
   302 by (simp add: real_inverse_def)
   303 
   304 instance real :: division_by_zero
   305 proof
   306   show "inverse 0 = (0::real)" by (rule INVERSE_ZERO)
   307 qed
   308 
   309 
   310 (*Pull negations out*)
   311 declare minus_mult_right [symmetric, simp] 
   312         minus_mult_left [symmetric, simp]
   313 
   314 lemma real_mult_1_right: "z * (1::real) = z"
   315   by (rule OrderedGroup.mult_1_right)
   316 
   317 
   318 subsection{*The @{text "\<le>"} Ordering*}
   319 
   320 lemma real_le_refl: "w \<le> (w::real)"
   321 by (cases w, force simp add: real_le_def)
   322 
   323 text{*The arithmetic decision procedure is not set up for type preal.
   324   This lemma is currently unused, but it could simplify the proofs of the
   325   following two lemmas.*}
   326 lemma preal_eq_le_imp_le:
   327   assumes eq: "a+b = c+d" and le: "c \<le> a"
   328   shows "b \<le> (d::preal)"
   329 proof -
   330   have "c+d \<le> a+d" by (simp add: prems preal_cancels)
   331   hence "a+b \<le> a+d" by (simp add: prems)
   332   thus "b \<le> d" by (simp add: preal_cancels)
   333 qed
   334 
   335 lemma real_le_lemma:
   336   assumes l: "u1 + v2 \<le> u2 + v1"
   337       and "x1 + v1 = u1 + y1"
   338       and "x2 + v2 = u2 + y2"
   339   shows "x1 + y2 \<le> x2 + (y1::preal)"
   340 proof -
   341   have "(x1+v1) + (u2+y2) = (u1+y1) + (x2+v2)" by (simp add: prems)
   342   hence "(x1+y2) + (u2+v1) = (x2+y1) + (u1+v2)" by (simp add: preal_add_ac)
   343   also have "... \<le> (x2+y1) + (u2+v1)"
   344          by (simp add: prems preal_add_le_cancel_left)
   345   finally show ?thesis by (simp add: preal_add_le_cancel_right)
   346 qed						 
   347 
   348 lemma real_le: 
   349      "(Abs_Real(realrel``{(x1,y1)}) \<le> Abs_Real(realrel``{(x2,y2)})) =  
   350       (x1 + y2 \<le> x2 + y1)"
   351 apply (simp add: real_le_def) 
   352 apply (auto intro: real_le_lemma)
   353 done
   354 
   355 lemma real_le_anti_sym: "[| z \<le> w; w \<le> z |] ==> z = (w::real)"
   356 by (cases z, cases w, simp add: real_le)
   357 
   358 lemma real_trans_lemma:
   359   assumes "x + v \<le> u + y"
   360       and "u + v' \<le> u' + v"
   361       and "x2 + v2 = u2 + y2"
   362   shows "x + v' \<le> u' + (y::preal)"
   363 proof -
   364   have "(x+v') + (u+v) = (x+v) + (u+v')" by (simp add: preal_add_ac)
   365   also have "... \<le> (u+y) + (u+v')" 
   366     by (simp add: preal_add_le_cancel_right prems) 
   367   also have "... \<le> (u+y) + (u'+v)" 
   368     by (simp add: preal_add_le_cancel_left prems) 
   369   also have "... = (u'+y) + (u+v)"  by (simp add: preal_add_ac)
   370   finally show ?thesis by (simp add: preal_add_le_cancel_right)
   371 qed
   372 
   373 lemma real_le_trans: "[| i \<le> j; j \<le> k |] ==> i \<le> (k::real)"
   374 apply (cases i, cases j, cases k)
   375 apply (simp add: real_le)
   376 apply (blast intro: real_trans_lemma) 
   377 done
   378 
   379 (* Axiom 'order_less_le' of class 'order': *)
   380 lemma real_less_le: "((w::real) < z) = (w \<le> z & w \<noteq> z)"
   381 by (simp add: real_less_def)
   382 
   383 instance real :: order
   384 proof qed
   385  (assumption |
   386   rule real_le_refl real_le_trans real_le_anti_sym real_less_le)+
   387 
   388 (* Axiom 'linorder_linear' of class 'linorder': *)
   389 lemma real_le_linear: "(z::real) \<le> w | w \<le> z"
   390 apply (cases z, cases w) 
   391 apply (auto simp add: real_le real_zero_def preal_add_ac preal_cancels)
   392 done
   393 
   394 
   395 instance real :: linorder
   396   by (intro_classes, rule real_le_linear)
   397 
   398 
   399 lemma real_le_eq_diff: "(x \<le> y) = (x-y \<le> (0::real))"
   400 apply (cases x, cases y) 
   401 apply (auto simp add: real_le real_zero_def real_diff_def real_add real_minus
   402                       preal_add_ac)
   403 apply (simp_all add: preal_add_assoc [symmetric] preal_cancels)
   404 done
   405 
   406 lemma real_add_left_mono: 
   407   assumes le: "x \<le> y" shows "z + x \<le> z + (y::real)"
   408 proof -
   409   have "z + x - (z + y) = (z + -z) + (x - y)"
   410     by (simp add: diff_minus add_ac) 
   411   with le show ?thesis 
   412     by (simp add: real_le_eq_diff[of x] real_le_eq_diff[of "z+x"] diff_minus)
   413 qed
   414 
   415 lemma real_sum_gt_zero_less: "(0 < S + (-W::real)) ==> (W < S)"
   416 by (simp add: linorder_not_le [symmetric] real_le_eq_diff [of S] diff_minus)
   417 
   418 lemma real_less_sum_gt_zero: "(W < S) ==> (0 < S + (-W::real))"
   419 by (simp add: linorder_not_le [symmetric] real_le_eq_diff [of S] diff_minus)
   420 
   421 lemma real_mult_order: "[| 0 < x; 0 < y |] ==> (0::real) < x * y"
   422 apply (cases x, cases y)
   423 apply (simp add: linorder_not_le [where 'a = real, symmetric] 
   424                  linorder_not_le [where 'a = preal] 
   425                   real_zero_def real_le real_mult)
   426   --{*Reduce to the (simpler) @{text "\<le>"} relation *}
   427 apply (auto  dest!: less_add_left_Ex 
   428      simp add: preal_add_ac preal_mult_ac 
   429           preal_add_mult_distrib2 preal_cancels preal_self_less_add_right)
   430 done
   431 
   432 lemma real_mult_less_mono2: "[| (0::real) < z; x < y |] ==> z * x < z * y"
   433 apply (rule real_sum_gt_zero_less)
   434 apply (drule real_less_sum_gt_zero [of x y])
   435 apply (drule real_mult_order, assumption)
   436 apply (simp add: right_distrib)
   437 done
   438 
   439 text{*lemma for proving @{term "0<(1::real)"}*}
   440 lemma real_zero_le_one: "0 \<le> (1::real)"
   441 by (simp add: real_zero_def real_one_def real_le 
   442                  preal_self_less_add_left order_less_imp_le)
   443 
   444 
   445 subsection{*The Reals Form an Ordered Field*}
   446 
   447 instance real :: ordered_field
   448 proof
   449   fix x y z :: real
   450   show "x \<le> y ==> z + x \<le> z + y" by (rule real_add_left_mono)
   451   show "x < y ==> 0 < z ==> z * x < z * y" by (simp add: real_mult_less_mono2)
   452   show "\<bar>x\<bar> = (if x < 0 then -x else x)"
   453     by (auto dest: order_le_less_trans simp add: real_abs_def linorder_not_le)
   454 qed
   455 
   456 
   457 
   458 text{*The function @{term real_of_preal} requires many proofs, but it seems
   459 to be essential for proving completeness of the reals from that of the
   460 positive reals.*}
   461 
   462 lemma real_of_preal_add:
   463      "real_of_preal ((x::preal) + y) = real_of_preal x + real_of_preal y"
   464 by (simp add: real_of_preal_def real_add preal_add_mult_distrib preal_mult_1 
   465               preal_add_ac)
   466 
   467 lemma real_of_preal_mult:
   468      "real_of_preal ((x::preal) * y) = real_of_preal x* real_of_preal y"
   469 by (simp add: real_of_preal_def real_mult preal_add_mult_distrib2
   470               preal_mult_1 preal_mult_1_right preal_add_ac preal_mult_ac)
   471 
   472 
   473 text{*Gleason prop 9-4.4 p 127*}
   474 lemma real_of_preal_trichotomy:
   475       "\<exists>m. (x::real) = real_of_preal m | x = 0 | x = -(real_of_preal m)"
   476 apply (simp add: real_of_preal_def real_zero_def, cases x)
   477 apply (auto simp add: real_minus preal_add_ac)
   478 apply (cut_tac x = x and y = y in linorder_less_linear)
   479 apply (auto dest!: less_add_left_Ex simp add: preal_add_assoc [symmetric])
   480 apply (auto simp add: preal_add_commute)
   481 done
   482 
   483 lemma real_of_preal_leD:
   484       "real_of_preal m1 \<le> real_of_preal m2 ==> m1 \<le> m2"
   485 by (simp add: real_of_preal_def real_le preal_cancels)
   486 
   487 lemma real_of_preal_lessI: "m1 < m2 ==> real_of_preal m1 < real_of_preal m2"
   488 by (auto simp add: real_of_preal_leD linorder_not_le [symmetric])
   489 
   490 lemma real_of_preal_lessD:
   491       "real_of_preal m1 < real_of_preal m2 ==> m1 < m2"
   492 by (simp add: real_of_preal_def real_le linorder_not_le [symmetric] 
   493               preal_cancels) 
   494 
   495 
   496 lemma real_of_preal_less_iff [simp]:
   497      "(real_of_preal m1 < real_of_preal m2) = (m1 < m2)"
   498 by (blast intro: real_of_preal_lessI real_of_preal_lessD)
   499 
   500 lemma real_of_preal_le_iff:
   501      "(real_of_preal m1 \<le> real_of_preal m2) = (m1 \<le> m2)"
   502 by (simp add: linorder_not_less [symmetric]) 
   503 
   504 lemma real_of_preal_zero_less: "0 < real_of_preal m"
   505 apply (auto simp add: real_zero_def real_of_preal_def real_less_def real_le_def
   506             preal_add_ac preal_cancels)
   507 apply (simp_all add: preal_add_assoc [symmetric] preal_cancels)
   508 apply (blast intro: preal_self_less_add_left order_less_imp_le)
   509 apply (insert preal_not_eq_self [of "preal_of_rat 1" m]) 
   510 apply (simp add: preal_add_ac) 
   511 done
   512 
   513 lemma real_of_preal_minus_less_zero: "- real_of_preal m < 0"
   514 by (simp add: real_of_preal_zero_less)
   515 
   516 lemma real_of_preal_not_minus_gt_zero: "~ 0 < - real_of_preal m"
   517 proof -
   518   from real_of_preal_minus_less_zero
   519   show ?thesis by (blast dest: order_less_trans)
   520 qed
   521 
   522 
   523 subsection{*Theorems About the Ordering*}
   524 
   525 text{*obsolete but used a lot*}
   526 
   527 lemma real_not_refl2: "x < y ==> x \<noteq> (y::real)"
   528 by blast 
   529 
   530 lemma real_le_imp_less_or_eq: "!!(x::real). x \<le> y ==> x < y | x = y"
   531 by (simp add: order_le_less)
   532 
   533 lemma real_gt_zero_preal_Ex: "(0 < x) = (\<exists>y. x = real_of_preal y)"
   534 apply (auto simp add: real_of_preal_zero_less)
   535 apply (cut_tac x = x in real_of_preal_trichotomy)
   536 apply (blast elim!: real_of_preal_not_minus_gt_zero [THEN notE])
   537 done
   538 
   539 lemma real_gt_preal_preal_Ex:
   540      "real_of_preal z < x ==> \<exists>y. x = real_of_preal y"
   541 by (blast dest!: real_of_preal_zero_less [THEN order_less_trans]
   542              intro: real_gt_zero_preal_Ex [THEN iffD1])
   543 
   544 lemma real_ge_preal_preal_Ex:
   545      "real_of_preal z \<le> x ==> \<exists>y. x = real_of_preal y"
   546 by (blast dest: order_le_imp_less_or_eq real_gt_preal_preal_Ex)
   547 
   548 lemma real_less_all_preal: "y \<le> 0 ==> \<forall>x. y < real_of_preal x"
   549 by (auto elim: order_le_imp_less_or_eq [THEN disjE] 
   550             intro: real_of_preal_zero_less [THEN [2] order_less_trans] 
   551             simp add: real_of_preal_zero_less)
   552 
   553 lemma real_less_all_real2: "~ 0 < y ==> \<forall>x. y < real_of_preal x"
   554 by (blast intro!: real_less_all_preal linorder_not_less [THEN iffD1])
   555 
   556 lemma real_add_less_le_mono: "[| w'<w; z'\<le>z |] ==> w' + z' < w + (z::real)"
   557   by (rule OrderedGroup.add_less_le_mono)
   558 
   559 lemma real_add_le_less_mono:
   560      "!!z z'::real. [| w'\<le>w; z'<z |] ==> w' + z' < w + z"
   561   by (rule OrderedGroup.add_le_less_mono)
   562 
   563 lemma real_le_square [simp]: "(0::real) \<le> x*x"
   564  by (rule Ring_and_Field.zero_le_square)
   565 
   566 
   567 subsection{*More Lemmas*}
   568 
   569 lemma real_mult_left_cancel: "(c::real) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
   570 by auto
   571 
   572 lemma real_mult_right_cancel: "(c::real) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
   573 by auto
   574 
   575 text{*The precondition could be weakened to @{term "0\<le>x"}*}
   576 lemma real_mult_less_mono:
   577      "[| u<v;  x<y;  (0::real) < v;  0 < x |] ==> u*x < v* y"
   578  by (simp add: Ring_and_Field.mult_strict_mono order_less_imp_le)
   579 
   580 lemma real_mult_less_iff1 [simp]: "(0::real) < z ==> (x*z < y*z) = (x < y)"
   581   by (force elim: order_less_asym
   582             simp add: Ring_and_Field.mult_less_cancel_right)
   583 
   584 lemma real_mult_le_cancel_iff1 [simp]: "(0::real) < z ==> (x*z \<le> y*z) = (x\<le>y)"
   585 apply (simp add: mult_le_cancel_right)
   586 apply (blast intro: elim: order_less_asym) 
   587 done
   588 
   589 lemma real_mult_le_cancel_iff2 [simp]: "(0::real) < z ==> (z*x \<le> z*y) = (x\<le>y)"
   590   by (force elim: order_less_asym
   591             simp add: Ring_and_Field.mult_le_cancel_left)
   592 
   593 text{*Only two uses?*}
   594 lemma real_mult_less_mono':
   595      "[| x < y;  r1 < r2;  (0::real) \<le> r1;  0 \<le> x|] ==> r1 * x < r2 * y"
   596  by (rule Ring_and_Field.mult_strict_mono')
   597 
   598 text{*FIXME: delete or at least combine the next two lemmas*}
   599 lemma real_sum_squares_cancel: "x * x + y * y = 0 ==> x = (0::real)"
   600 apply (drule OrderedGroup.equals_zero_I [THEN sym])
   601 apply (cut_tac x = y in real_le_square) 
   602 apply (auto, drule order_antisym, auto)
   603 done
   604 
   605 lemma real_sum_squares_cancel2: "x * x + y * y = 0 ==> y = (0::real)"
   606 apply (rule_tac y = x in real_sum_squares_cancel)
   607 apply (simp add: add_commute)
   608 done
   609 
   610 lemma real_add_order: "[| 0 < x; 0 < y |] ==> (0::real) < x + y"
   611 by (drule add_strict_mono [of concl: 0 0], assumption, simp)
   612 
   613 lemma real_le_add_order: "[| 0 \<le> x; 0 \<le> y |] ==> (0::real) \<le> x + y"
   614 apply (drule order_le_imp_less_or_eq)+
   615 apply (auto intro: real_add_order order_less_imp_le)
   616 done
   617 
   618 lemma real_inverse_unique: "x*y = (1::real) ==> y = inverse x"
   619 apply (case_tac "x \<noteq> 0")
   620 apply (rule_tac c1 = x in real_mult_left_cancel [THEN iffD1], auto)
   621 done
   622 
   623 lemma real_inverse_gt_one: "[| (0::real) < x; x < 1 |] ==> 1 < inverse x"
   624 by (auto dest: less_imp_inverse_less)
   625 
   626 lemma real_mult_self_sum_ge_zero: "(0::real) \<le> x*x + y*y"
   627 proof -
   628   have "0 + 0 \<le> x*x + y*y" by (blast intro: add_mono zero_le_square)
   629   thus ?thesis by simp
   630 qed
   631 
   632 
   633 subsection{*Embedding the Integers into the Reals*}
   634 
   635 defs (overloaded)
   636   real_of_nat_def: "real z == of_nat z"
   637   real_of_int_def: "real z == of_int z"
   638 
   639 lemma real_of_int_zero [simp]: "real (0::int) = 0"  
   640 by (simp add: real_of_int_def) 
   641 
   642 lemma real_of_one [simp]: "real (1::int) = (1::real)"
   643 by (simp add: real_of_int_def) 
   644 
   645 lemma real_of_int_add: "real (x::int) + real y = real (x + y)"
   646 by (simp add: real_of_int_def) 
   647 declare real_of_int_add [symmetric, simp]
   648 
   649 lemma real_of_int_minus: "-real (x::int) = real (-x)"
   650 by (simp add: real_of_int_def) 
   651 declare real_of_int_minus [symmetric, simp]
   652 
   653 lemma real_of_int_diff: "real (x::int) - real y = real (x - y)"
   654 by (simp add: real_of_int_def) 
   655 declare real_of_int_diff [symmetric, simp]
   656 
   657 lemma real_of_int_mult: "real (x::int) * real y = real (x * y)"
   658 by (simp add: real_of_int_def) 
   659 declare real_of_int_mult [symmetric, simp]
   660 
   661 lemma real_of_int_zero_cancel [simp]: "(real x = 0) = (x = (0::int))"
   662 by (simp add: real_of_int_def) 
   663 
   664 lemma real_of_int_inject [iff]: "(real (x::int) = real y) = (x = y)"
   665 by (simp add: real_of_int_def) 
   666 
   667 lemma real_of_int_less_iff [iff]: "(real (x::int) < real y) = (x < y)"
   668 by (simp add: real_of_int_def) 
   669 
   670 lemma real_of_int_le_iff [simp]: "(real (x::int) \<le> real y) = (x \<le> y)"
   671 by (simp add: real_of_int_def) 
   672 
   673 
   674 subsection{*Embedding the Naturals into the Reals*}
   675 
   676 lemma real_of_nat_zero [simp]: "real (0::nat) = 0"
   677 by (simp add: real_of_nat_def)
   678 
   679 lemma real_of_nat_one [simp]: "real (Suc 0) = (1::real)"
   680 by (simp add: real_of_nat_def)
   681 
   682 lemma real_of_nat_add [simp]: "real (m + n) = real (m::nat) + real n"
   683 by (simp add: real_of_nat_def)
   684 
   685 (*Not for addsimps: often the LHS is used to represent a positive natural*)
   686 lemma real_of_nat_Suc: "real (Suc n) = real n + (1::real)"
   687 by (simp add: real_of_nat_def)
   688 
   689 lemma real_of_nat_less_iff [iff]: 
   690      "(real (n::nat) < real m) = (n < m)"
   691 by (simp add: real_of_nat_def)
   692 
   693 lemma real_of_nat_le_iff [iff]: "(real (n::nat) \<le> real m) = (n \<le> m)"
   694 by (simp add: real_of_nat_def)
   695 
   696 lemma real_of_nat_ge_zero [iff]: "0 \<le> real (n::nat)"
   697 by (simp add: real_of_nat_def zero_le_imp_of_nat)
   698 
   699 lemma real_of_nat_Suc_gt_zero: "0 < real (Suc n)"
   700 by (simp add: real_of_nat_def del: of_nat_Suc)
   701 
   702 lemma real_of_nat_mult [simp]: "real (m * n) = real (m::nat) * real n"
   703 by (simp add: real_of_nat_def)
   704 
   705 lemma real_of_nat_inject [iff]: "(real (n::nat) = real m) = (n = m)"
   706 by (simp add: real_of_nat_def)
   707 
   708 lemma real_of_nat_zero_iff [iff]: "(real (n::nat) = 0) = (n = 0)"
   709 by (simp add: real_of_nat_def)
   710 
   711 lemma real_of_nat_diff: "n \<le> m ==> real (m - n) = real (m::nat) - real n"
   712 by (simp add: add: real_of_nat_def) 
   713 
   714 lemma real_of_nat_gt_zero_cancel_iff [simp]: "(0 < real (n::nat)) = (0 < n)"
   715 by (simp add: add: real_of_nat_def) 
   716 
   717 lemma real_of_nat_le_zero_cancel_iff [simp]: "(real (n::nat) \<le> 0) = (n = 0)"
   718 by (simp add: add: real_of_nat_def)
   719 
   720 lemma not_real_of_nat_less_zero [simp]: "~ real (n::nat) < 0"
   721 by (simp add: add: real_of_nat_def)
   722 
   723 lemma real_of_nat_ge_zero_cancel_iff [simp]: "(0 \<le> real (n::nat)) = (0 \<le> n)"
   724 by (simp add: add: real_of_nat_def)
   725 
   726 lemma real_of_int_real_of_nat: "real (int n) = real n"
   727 by (simp add: real_of_nat_def real_of_int_def int_eq_of_nat)
   728 
   729 lemma real_of_int_of_nat_eq [simp]: "real (of_nat n :: int) = real n"
   730 by (simp add: real_of_int_def real_of_nat_def)
   731 
   732 
   733 
   734 subsection{*Numerals and Arithmetic*}
   735 
   736 instance real :: number ..
   737 
   738 defs (overloaded)
   739   real_number_of_def: "(number_of w :: real) == of_int (Rep_Bin w)"
   740     --{*the type constraint is essential!*}
   741 
   742 instance real :: number_ring
   743 by (intro_classes, simp add: real_number_of_def) 
   744 
   745 
   746 text{*Collapse applications of @{term real} to @{term number_of}*}
   747 lemma real_number_of [simp]: "real (number_of v :: int) = number_of v"
   748 by (simp add:  real_of_int_def of_int_number_of_eq)
   749 
   750 lemma real_of_nat_number_of [simp]:
   751      "real (number_of v :: nat) =  
   752         (if neg (number_of v :: int) then 0  
   753          else (number_of v :: real))"
   754 by (simp add: real_of_int_real_of_nat [symmetric] int_nat_number_of)
   755  
   756 
   757 use "real_arith.ML"
   758 
   759 setup real_arith_setup
   760 
   761 subsection{* Simprules combining x+y and 0: ARE THEY NEEDED?*}
   762 
   763 text{*Needed in this non-standard form by Hyperreal/Transcendental*}
   764 lemma real_0_le_divide_iff:
   765      "((0::real) \<le> x/y) = ((x \<le> 0 | 0 \<le> y) & (0 \<le> x | y \<le> 0))"
   766 by (simp add: real_divide_def zero_le_mult_iff, auto)
   767 
   768 lemma real_add_minus_iff [simp]: "(x + - a = (0::real)) = (x=a)" 
   769 by arith
   770 
   771 lemma real_add_eq_0_iff: "(x+y = (0::real)) = (y = -x)"
   772 by auto
   773 
   774 lemma real_add_less_0_iff: "(x+y < (0::real)) = (y < -x)"
   775 by auto
   776 
   777 lemma real_0_less_add_iff: "((0::real) < x+y) = (-x < y)"
   778 by auto
   779 
   780 lemma real_add_le_0_iff: "(x+y \<le> (0::real)) = (y \<le> -x)"
   781 by auto
   782 
   783 lemma real_0_le_add_iff: "((0::real) \<le> x+y) = (-x \<le> y)"
   784 by auto
   785 
   786 
   787 (*
   788 FIXME: we should have this, as for type int, but many proofs would break.
   789 It replaces x+-y by x-y.
   790 declare real_diff_def [symmetric, simp]
   791 *)
   792 
   793 
   794 subsubsection{*Density of the Reals*}
   795 
   796 lemma real_lbound_gt_zero:
   797      "[| (0::real) < d1; 0 < d2 |] ==> \<exists>e. 0 < e & e < d1 & e < d2"
   798 apply (rule_tac x = " (min d1 d2) /2" in exI)
   799 apply (simp add: min_def)
   800 done
   801 
   802 
   803 text{*Similar results are proved in @{text Ring_and_Field}*}
   804 lemma real_less_half_sum: "x < y ==> x < (x+y) / (2::real)"
   805   by auto
   806 
   807 lemma real_gt_half_sum: "x < y ==> (x+y)/(2::real) < y"
   808   by auto
   809 
   810 
   811 subsection{*Absolute Value Function for the Reals*}
   812 
   813 lemma abs_minus_add_cancel: "abs(x + (-y)) = abs (y + (-(x::real)))"
   814 by (simp add: abs_if)
   815 
   816 lemma abs_interval_iff: "(abs x < r) = (-r < x & x < (r::real))"
   817 by (force simp add: Ring_and_Field.abs_less_iff)
   818 
   819 lemma abs_le_interval_iff: "(abs x \<le> r) = (-r\<le>x & x\<le>(r::real))"
   820 by (force simp add: OrderedGroup.abs_le_iff)
   821 
   822 (*FIXME: used only once, in SEQ.ML*)
   823 lemma abs_add_one_gt_zero [simp]: "(0::real) < 1 + abs(x)"
   824 by (simp add: abs_if)
   825 
   826 lemma abs_real_of_nat_cancel [simp]: "abs (real x) = real (x::nat)"
   827 by (simp add: real_of_nat_ge_zero)
   828 
   829 lemma abs_add_one_not_less_self [simp]: "~ abs(x) + (1::real) < x"
   830 apply (simp add: linorder_not_less)
   831 apply (auto intro: abs_ge_self [THEN order_trans])
   832 done
   833  
   834 text{*Used only in Hyperreal/Lim.ML*}
   835 lemma abs_sum_triangle_ineq: "abs ((x::real) + y + (-l + -m)) \<le> abs(x + -l) + abs(y + -m)"
   836 apply (simp add: real_add_assoc)
   837 apply (rule_tac a1 = y in add_left_commute [THEN ssubst])
   838 apply (rule real_add_assoc [THEN subst])
   839 apply (rule abs_triangle_ineq)
   840 done
   841 
   842 
   843 
   844 ML
   845 {*
   846 val real_lbound_gt_zero = thm"real_lbound_gt_zero";
   847 val real_less_half_sum = thm"real_less_half_sum";
   848 val real_gt_half_sum = thm"real_gt_half_sum";
   849 
   850 val abs_interval_iff = thm"abs_interval_iff";
   851 val abs_le_interval_iff = thm"abs_le_interval_iff";
   852 val abs_add_one_gt_zero = thm"abs_add_one_gt_zero";
   853 val abs_add_one_not_less_self = thm"abs_add_one_not_less_self";
   854 val abs_sum_triangle_ineq = thm"abs_sum_triangle_ineq";
   855 *}
   856 
   857 
   858 end