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