src/HOL/Real/RealDef.thy
 author nipkow Mon Aug 16 14:22:27 2004 +0200 (2004-08-16) changeset 15131 c69542757a4d parent 15086 e6a2a98d5ef5 child 15140 322485b816ac permissions -rw-r--r--
```     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 import 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 "congruent2 realrel realrel
```
```   158         (\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). {Abs_Real (realrel `` {(x+u, y+v)})}) w) z)"
```
```   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 "congruent realrel (\<lambda>(x,y). {Abs_Real (realrel``{(y,x)})})"
```
```   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     "congruent2 realrel realrel (%p1 p2.
```
```   207         (%(x1,y1). (%(x2,y2).
```
```   208           { Abs_Real (realrel``{(x1*x2 + y1*y2, x1*y2+y1*x2)}) }) p2) p1)"
```
```   209 apply (rule congruent2_commuteI [OF equiv_realrel], clarify)
```
```   210 apply (simp add: preal_mult_commute preal_add_commute)
```
```   211 apply (auto simp add: real_mult_congruent2_lemma)
```
```   212 done
```
```   213
```
```   214 lemma real_mult:
```
```   215       "Abs_Real((realrel``{(x1,y1)})) * Abs_Real((realrel``{(x2,y2)})) =
```
```   216        Abs_Real(realrel `` {(x1*x2+y1*y2,x1*y2+y1*x2)})"
```
```   217 by (simp add: real_mult_def UN_UN_split_split_eq
```
```   218          UN_equiv_class2 [OF equiv_realrel equiv_realrel real_mult_congruent2])
```
```   219
```
```   220 lemma real_mult_commute: "(z::real) * w = w * z"
```
```   221 by (cases z, cases w, simp add: real_mult preal_add_ac preal_mult_ac)
```
```   222
```
```   223 lemma real_mult_assoc: "((z1::real) * z2) * z3 = z1 * (z2 * z3)"
```
```   224 apply (cases z1, cases z2, cases z3)
```
```   225 apply (simp add: real_mult preal_add_mult_distrib2 preal_add_ac preal_mult_ac)
```
```   226 done
```
```   227
```
```   228 lemma real_mult_1: "(1::real) * z = z"
```
```   229 apply (cases z)
```
```   230 apply (simp add: real_mult real_one_def preal_add_mult_distrib2
```
```   231                  preal_mult_1_right preal_mult_ac preal_add_ac)
```
```   232 done
```
```   233
```
```   234 lemma real_add_mult_distrib: "((z1::real) + z2) * w = (z1 * w) + (z2 * w)"
```
```   235 apply (cases z1, cases z2, cases w)
```
```   236 apply (simp add: real_add real_mult preal_add_mult_distrib2
```
```   237                  preal_add_ac preal_mult_ac)
```
```   238 done
```
```   239
```
```   240 text{*one and zero are distinct*}
```
```   241 lemma real_zero_not_eq_one: "0 \<noteq> (1::real)"
```
```   242 proof -
```
```   243   have "preal_of_rat 1 < preal_of_rat 1 + preal_of_rat 1"
```
```   244     by (simp add: preal_self_less_add_left)
```
```   245   thus ?thesis
```
```   246     by (simp add: real_zero_def real_one_def preal_add_right_cancel_iff)
```
```   247 qed
```
```   248
```
```   249 subsection{*existence of inverse*}
```
```   250
```
```   251 lemma real_zero_iff: "Abs_Real (realrel `` {(x, x)}) = 0"
```
```   252 by (simp add: real_zero_def preal_add_commute)
```
```   253
```
```   254 text{*Instead of using an existential quantifier and constructing the inverse
```
```   255 within the proof, we could define the inverse explicitly.*}
```
```   256
```
```   257 lemma real_mult_inverse_left_ex: "x \<noteq> 0 ==> \<exists>y. y*x = (1::real)"
```
```   258 apply (simp add: real_zero_def real_one_def, cases x)
```
```   259 apply (cut_tac x = xa and y = y in linorder_less_linear)
```
```   260 apply (auto dest!: less_add_left_Ex simp add: real_zero_iff)
```
```   261 apply (rule_tac
```
```   262         x = "Abs_Real (realrel `` { (preal_of_rat 1,
```
```   263                             inverse (D) + preal_of_rat 1)}) "
```
```   264        in exI)
```
```   265 apply (rule_tac [2]
```
```   266         x = "Abs_Real (realrel `` { (inverse (D) + preal_of_rat 1,
```
```   267                    preal_of_rat 1)})"
```
```   268        in exI)
```
```   269 apply (auto simp add: real_mult preal_mult_1_right
```
```   270               preal_add_mult_distrib2 preal_add_mult_distrib preal_mult_1
```
```   271               preal_mult_inverse_right preal_add_ac preal_mult_ac)
```
```   272 done
```
```   273
```
```   274 lemma real_mult_inverse_left: "x \<noteq> 0 ==> inverse(x)*x = (1::real)"
```
```   275 apply (simp add: real_inverse_def)
```
```   276 apply (frule real_mult_inverse_left_ex, safe)
```
```   277 apply (rule someI2, auto)
```
```   278 done
```
```   279
```
```   280
```
```   281 subsection{*The Real Numbers form a Field*}
```
```   282
```
```   283 instance real :: field
```
```   284 proof
```
```   285   fix x y z :: real
```
```   286   show "- x + x = 0" by (rule real_add_minus_left)
```
```   287   show "x - y = x + (-y)" by (simp add: real_diff_def)
```
```   288   show "(x * y) * z = x * (y * z)" by (rule real_mult_assoc)
```
```   289   show "x * y = y * x" by (rule real_mult_commute)
```
```   290   show "1 * x = x" by (rule real_mult_1)
```
```   291   show "(x + y) * z = x * z + y * z" by (simp add: real_add_mult_distrib)
```
```   292   show "0 \<noteq> (1::real)" by (rule real_zero_not_eq_one)
```
```   293   show "x \<noteq> 0 ==> inverse x * x = 1" by (rule real_mult_inverse_left)
```
```   294   show "x / y = x * inverse y" by (simp add: real_divide_def)
```
```   295 qed
```
```   296
```
```   297
```
```   298 text{*Inverse of zero!  Useful to simplify certain equations*}
```
```   299
```
```   300 lemma INVERSE_ZERO: "inverse 0 = (0::real)"
```
```   301 by (simp add: real_inverse_def)
```
```   302
```
```   303 instance real :: division_by_zero
```
```   304 proof
```
```   305   show "inverse 0 = (0::real)" by (rule INVERSE_ZERO)
```
```   306 qed
```
```   307
```
```   308
```
```   309 (*Pull negations out*)
```
```   310 declare minus_mult_right [symmetric, simp]
```
```   311         minus_mult_left [symmetric, simp]
```
```   312
```
```   313 lemma real_mult_1_right: "z * (1::real) = z"
```
```   314   by (rule OrderedGroup.mult_1_right)
```
```   315
```
```   316
```
```   317 subsection{*The @{text "\<le>"} Ordering*}
```
```   318
```
```   319 lemma real_le_refl: "w \<le> (w::real)"
```
```   320 by (cases w, force simp add: real_le_def)
```
```   321
```
```   322 text{*The arithmetic decision procedure is not set up for type preal.
```
```   323   This lemma is currently unused, but it could simplify the proofs of the
```
```   324   following two lemmas.*}
```
```   325 lemma preal_eq_le_imp_le:
```
```   326   assumes eq: "a+b = c+d" and le: "c \<le> a"
```
```   327   shows "b \<le> (d::preal)"
```
```   328 proof -
```
```   329   have "c+d \<le> a+d" by (simp add: prems preal_cancels)
```
```   330   hence "a+b \<le> a+d" by (simp add: prems)
```
```   331   thus "b \<le> d" by (simp add: preal_cancels)
```
```   332 qed
```
```   333
```
```   334 lemma real_le_lemma:
```
```   335   assumes l: "u1 + v2 \<le> u2 + v1"
```
```   336       and "x1 + v1 = u1 + y1"
```
```   337       and "x2 + v2 = u2 + y2"
```
```   338   shows "x1 + y2 \<le> x2 + (y1::preal)"
```
```   339 proof -
```
```   340   have "(x1+v1) + (u2+y2) = (u1+y1) + (x2+v2)" by (simp add: prems)
```
```   341   hence "(x1+y2) + (u2+v1) = (x2+y1) + (u1+v2)" by (simp add: preal_add_ac)
```
```   342   also have "... \<le> (x2+y1) + (u2+v1)"
```
```   343          by (simp add: prems preal_add_le_cancel_left)
```
```   344   finally show ?thesis by (simp add: preal_add_le_cancel_right)
```
```   345 qed
```
```   346
```
```   347 lemma real_le:
```
```   348      "(Abs_Real(realrel``{(x1,y1)}) \<le> Abs_Real(realrel``{(x2,y2)})) =
```
```   349       (x1 + y2 \<le> x2 + y1)"
```
```   350 apply (simp add: real_le_def)
```
```   351 apply (auto intro: real_le_lemma)
```
```   352 done
```
```   353
```
```   354 lemma real_le_anti_sym: "[| z \<le> w; w \<le> z |] ==> z = (w::real)"
```
```   355 by (cases z, cases w, simp add: real_le order_antisym)
```
```   356
```
```   357 lemma real_trans_lemma:
```
```   358   assumes "x + v \<le> u + y"
```
```   359       and "u + v' \<le> u' + v"
```
```   360       and "x2 + v2 = u2 + y2"
```
```   361   shows "x + v' \<le> u' + (y::preal)"
```
```   362 proof -
```
```   363   have "(x+v') + (u+v) = (x+v) + (u+v')" by (simp add: preal_add_ac)
```
```   364   also have "... \<le> (u+y) + (u+v')"
```
```   365     by (simp add: preal_add_le_cancel_right prems)
```
```   366   also have "... \<le> (u+y) + (u'+v)"
```
```   367     by (simp add: preal_add_le_cancel_left prems)
```
```   368   also have "... = (u'+y) + (u+v)"  by (simp add: preal_add_ac)
```
```   369   finally show ?thesis by (simp add: preal_add_le_cancel_right)
```
```   370 qed
```
```   371
```
```   372 lemma real_le_trans: "[| i \<le> j; j \<le> k |] ==> i \<le> (k::real)"
```
```   373 apply (cases i, cases j, cases k)
```
```   374 apply (simp add: real_le)
```
```   375 apply (blast intro: real_trans_lemma)
```
```   376 done
```
```   377
```
```   378 (* Axiom 'order_less_le' of class 'order': *)
```
```   379 lemma real_less_le: "((w::real) < z) = (w \<le> z & w \<noteq> z)"
```
```   380 by (simp add: real_less_def)
```
```   381
```
```   382 instance real :: order
```
```   383 proof qed
```
```   384  (assumption |
```
```   385   rule real_le_refl real_le_trans real_le_anti_sym real_less_le)+
```
```   386
```
```   387 (* Axiom 'linorder_linear' of class 'linorder': *)
```
```   388 lemma real_le_linear: "(z::real) \<le> w | w \<le> z"
```
```   389 apply (cases z, cases w)
```
```   390 apply (auto simp add: real_le real_zero_def preal_add_ac preal_cancels)
```
```   391 done
```
```   392
```
```   393
```
```   394 instance real :: linorder
```
```   395   by (intro_classes, rule real_le_linear)
```
```   396
```
```   397
```
```   398 lemma real_le_eq_diff: "(x \<le> y) = (x-y \<le> (0::real))"
```
```   399 apply (cases x, cases y)
```
```   400 apply (auto simp add: real_le real_zero_def real_diff_def real_add real_minus
```
```   401                       preal_add_ac)
```
```   402 apply (simp_all add: preal_add_assoc [symmetric] preal_cancels)
```
```   403 done
```
```   404
```
```   405 lemma real_add_left_mono:
```
```   406   assumes le: "x \<le> y" shows "z + x \<le> z + (y::real)"
```
```   407 proof -
```
```   408   have "z + x - (z + y) = (z + -z) + (x - y)"
```
```   409     by (simp add: diff_minus add_ac)
```
```   410   with le show ?thesis
```
```   411     by (simp add: real_le_eq_diff[of x] real_le_eq_diff[of "z+x"] diff_minus)
```
```   412 qed
```
```   413
```
```   414 lemma real_sum_gt_zero_less: "(0 < S + (-W::real)) ==> (W < S)"
```
```   415 by (simp add: linorder_not_le [symmetric] real_le_eq_diff [of S] diff_minus)
```
```   416
```
```   417 lemma real_less_sum_gt_zero: "(W < S) ==> (0 < S + (-W::real))"
```
```   418 by (simp add: linorder_not_le [symmetric] real_le_eq_diff [of S] diff_minus)
```
```   419
```
```   420 lemma real_mult_order: "[| 0 < x; 0 < y |] ==> (0::real) < x * y"
```
```   421 apply (cases x, cases y)
```
```   422 apply (simp add: linorder_not_le [where 'a = real, symmetric]
```
```   423                  linorder_not_le [where 'a = preal]
```
```   424                   real_zero_def real_le real_mult)
```
```   425   --{*Reduce to the (simpler) @{text "\<le>"} relation *}
```
```   426 apply (auto  dest!: less_add_left_Ex
```
```   427      simp add: preal_add_ac preal_mult_ac
```
```   428           preal_add_mult_distrib2 preal_cancels preal_self_less_add_right)
```
```   429 done
```
```   430
```
```   431 lemma real_mult_less_mono2: "[| (0::real) < z; x < y |] ==> z * x < z * y"
```
```   432 apply (rule real_sum_gt_zero_less)
```
```   433 apply (drule real_less_sum_gt_zero [of x y])
```
```   434 apply (drule real_mult_order, assumption)
```
```   435 apply (simp add: right_distrib)
```
```   436 done
```
```   437
```
```   438 text{*lemma for proving @{term "0<(1::real)"}*}
```
```   439 lemma real_zero_le_one: "0 \<le> (1::real)"
```
```   440 by (simp add: real_zero_def real_one_def real_le
```
```   441                  preal_self_less_add_left order_less_imp_le)
```
```   442
```
```   443
```
```   444 subsection{*The Reals Form an Ordered Field*}
```
```   445
```
```   446 instance real :: ordered_field
```
```   447 proof
```
```   448   fix x y z :: real
```
```   449   show "x \<le> y ==> z + x \<le> z + y" by (rule real_add_left_mono)
```
```   450   show "x < y ==> 0 < z ==> z * x < z * y" by (simp add: real_mult_less_mono2)
```
```   451   show "\<bar>x\<bar> = (if x < 0 then -x else x)"
```
```   452     by (auto dest: order_le_less_trans simp add: real_abs_def linorder_not_le)
```
```   453 qed
```
```   454
```
```   455
```
```   456
```
```   457 text{*The function @{term real_of_preal} requires many proofs, but it seems
```
```   458 to be essential for proving completeness of the reals from that of the
```
```   459 positive reals.*}
```
```   460
```
```   461 lemma real_of_preal_add:
```
```   462      "real_of_preal ((x::preal) + y) = real_of_preal x + real_of_preal y"
```
```   463 by (simp add: real_of_preal_def real_add preal_add_mult_distrib preal_mult_1
```
```   464               preal_add_ac)
```
```   465
```
```   466 lemma real_of_preal_mult:
```
```   467      "real_of_preal ((x::preal) * y) = real_of_preal x* real_of_preal y"
```
```   468 by (simp add: real_of_preal_def real_mult preal_add_mult_distrib2
```
```   469               preal_mult_1 preal_mult_1_right preal_add_ac preal_mult_ac)
```
```   470
```
```   471
```
```   472 text{*Gleason prop 9-4.4 p 127*}
```
```   473 lemma real_of_preal_trichotomy:
```
```   474       "\<exists>m. (x::real) = real_of_preal m | x = 0 | x = -(real_of_preal m)"
```
```   475 apply (simp add: real_of_preal_def real_zero_def, cases x)
```
```   476 apply (auto simp add: real_minus preal_add_ac)
```
```   477 apply (cut_tac x = x and y = y in linorder_less_linear)
```
```   478 apply (auto dest!: less_add_left_Ex simp add: preal_add_assoc [symmetric])
```
```   479 apply (auto simp add: preal_add_commute)
```
```   480 done
```
```   481
```
```   482 lemma real_of_preal_leD:
```
```   483       "real_of_preal m1 \<le> real_of_preal m2 ==> m1 \<le> m2"
```
```   484 by (simp add: real_of_preal_def real_le preal_cancels)
```
```   485
```
```   486 lemma real_of_preal_lessI: "m1 < m2 ==> real_of_preal m1 < real_of_preal m2"
```
```   487 by (auto simp add: real_of_preal_leD linorder_not_le [symmetric])
```
```   488
```
```   489 lemma real_of_preal_lessD:
```
```   490       "real_of_preal m1 < real_of_preal m2 ==> m1 < m2"
```
```   491 by (simp add: real_of_preal_def real_le linorder_not_le [symmetric]
```
```   492               preal_cancels)
```
```   493
```
```   494
```
```   495 lemma real_of_preal_less_iff [simp]:
```
```   496      "(real_of_preal m1 < real_of_preal m2) = (m1 < m2)"
```
```   497 by (blast intro: real_of_preal_lessI real_of_preal_lessD)
```
```   498
```
```   499 lemma real_of_preal_le_iff:
```
```   500      "(real_of_preal m1 \<le> real_of_preal m2) = (m1 \<le> m2)"
```
```   501 by (simp add: linorder_not_less [symmetric])
```
```   502
```
```   503 lemma real_of_preal_zero_less: "0 < real_of_preal m"
```
```   504 apply (auto simp add: real_zero_def real_of_preal_def real_less_def real_le_def
```
```   505             preal_add_ac preal_cancels)
```
```   506 apply (simp_all add: preal_add_assoc [symmetric] preal_cancels)
```
```   507 apply (blast intro: preal_self_less_add_left order_less_imp_le)
```
```   508 apply (insert preal_not_eq_self [of "preal_of_rat 1" m])
```
```   509 apply (simp add: preal_add_ac)
```
```   510 done
```
```   511
```
```   512 lemma real_of_preal_minus_less_zero: "- real_of_preal m < 0"
```
```   513 by (simp add: real_of_preal_zero_less)
```
```   514
```
```   515 lemma real_of_preal_not_minus_gt_zero: "~ 0 < - real_of_preal m"
```
```   516 proof -
```
```   517   from real_of_preal_minus_less_zero
```
```   518   show ?thesis by (blast dest: order_less_trans)
```
```   519 qed
```
```   520
```
```   521
```
```   522 subsection{*Theorems About the Ordering*}
```
```   523
```
```   524 text{*obsolete but used a lot*}
```
```   525
```
```   526 lemma real_not_refl2: "x < y ==> x \<noteq> (y::real)"
```
```   527 by blast
```
```   528
```
```   529 lemma real_le_imp_less_or_eq: "!!(x::real). x \<le> y ==> x < y | x = y"
```
```   530 by (simp add: order_le_less)
```
```   531
```
```   532 lemma real_gt_zero_preal_Ex: "(0 < x) = (\<exists>y. x = real_of_preal y)"
```
```   533 apply (auto simp add: real_of_preal_zero_less)
```
```   534 apply (cut_tac x = x in real_of_preal_trichotomy)
```
```   535 apply (blast elim!: real_of_preal_not_minus_gt_zero [THEN notE])
```
```   536 done
```
```   537
```
```   538 lemma real_gt_preal_preal_Ex:
```
```   539      "real_of_preal z < x ==> \<exists>y. x = real_of_preal y"
```
```   540 by (blast dest!: real_of_preal_zero_less [THEN order_less_trans]
```
```   541              intro: real_gt_zero_preal_Ex [THEN iffD1])
```
```   542
```
```   543 lemma real_ge_preal_preal_Ex:
```
```   544      "real_of_preal z \<le> x ==> \<exists>y. x = real_of_preal y"
```
```   545 by (blast dest: order_le_imp_less_or_eq real_gt_preal_preal_Ex)
```
```   546
```
```   547 lemma real_less_all_preal: "y \<le> 0 ==> \<forall>x. y < real_of_preal x"
```
```   548 by (auto elim: order_le_imp_less_or_eq [THEN disjE]
```
```   549             intro: real_of_preal_zero_less [THEN [2] order_less_trans]
```
```   550             simp add: real_of_preal_zero_less)
```
```   551
```
```   552 lemma real_less_all_real2: "~ 0 < y ==> \<forall>x. y < real_of_preal x"
```
```   553 by (blast intro!: real_less_all_preal linorder_not_less [THEN iffD1])
```
```   554
```
```   555 lemma real_add_less_le_mono: "[| w'<w; z'\<le>z |] ==> w' + z' < w + (z::real)"
```
```   556   by (rule OrderedGroup.add_less_le_mono)
```
```   557
```
```   558 lemma real_add_le_less_mono:
```
```   559      "!!z z'::real. [| w'\<le>w; z'<z |] ==> w' + z' < w + z"
```
```   560   by (rule OrderedGroup.add_le_less_mono)
```
```   561
```
```   562 lemma real_le_square [simp]: "(0::real) \<le> x*x"
```
```   563  by (rule Ring_and_Field.zero_le_square)
```
```   564
```
```   565
```
```   566 subsection{*More Lemmas*}
```
```   567
```
```   568 lemma real_mult_left_cancel: "(c::real) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
```
```   569 by auto
```
```   570
```
```   571 lemma real_mult_right_cancel: "(c::real) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
```
```   572 by auto
```
```   573
```
```   574 text{*The precondition could be weakened to @{term "0\<le>x"}*}
```
```   575 lemma real_mult_less_mono:
```
```   576      "[| u<v;  x<y;  (0::real) < v;  0 < x |] ==> u*x < v* y"
```
```   577  by (simp add: Ring_and_Field.mult_strict_mono order_less_imp_le)
```
```   578
```
```   579 lemma real_mult_less_iff1 [simp]: "(0::real) < z ==> (x*z < y*z) = (x < y)"
```
```   580   by (force elim: order_less_asym
```
```   581             simp add: Ring_and_Field.mult_less_cancel_right)
```
```   582
```
```   583 lemma real_mult_le_cancel_iff1 [simp]: "(0::real) < z ==> (x*z \<le> y*z) = (x\<le>y)"
```
```   584 apply (simp add: mult_le_cancel_right)
```
```   585 apply (blast intro: elim: order_less_asym)
```
```   586 done
```
```   587
```
```   588 lemma real_mult_le_cancel_iff2 [simp]: "(0::real) < z ==> (z*x \<le> z*y) = (x\<le>y)"
```
```   589   by (force elim: order_less_asym
```
```   590             simp add: Ring_and_Field.mult_le_cancel_left)
```
```   591
```
```   592 text{*Only two uses?*}
```
```   593 lemma real_mult_less_mono':
```
```   594      "[| x < y;  r1 < r2;  (0::real) \<le> r1;  0 \<le> x|] ==> r1 * x < r2 * y"
```
```   595  by (rule Ring_and_Field.mult_strict_mono')
```
```   596
```
```   597 text{*FIXME: delete or at least combine the next two lemmas*}
```
```   598 lemma real_sum_squares_cancel: "x * x + y * y = 0 ==> x = (0::real)"
```
```   599 apply (drule OrderedGroup.equals_zero_I [THEN sym])
```
```   600 apply (cut_tac x = y in real_le_square)
```
```   601 apply (auto, drule order_antisym, auto)
```
```   602 done
```
```   603
```
```   604 lemma real_sum_squares_cancel2: "x * x + y * y = 0 ==> y = (0::real)"
```
```   605 apply (rule_tac y = x in real_sum_squares_cancel)
```
```   606 apply (simp add: add_commute)
```
```   607 done
```
```   608
```
```   609 lemma real_add_order: "[| 0 < x; 0 < y |] ==> (0::real) < x + y"
```
```   610 by (drule add_strict_mono [of concl: 0 0], assumption, simp)
```
```   611
```
```   612 lemma real_le_add_order: "[| 0 \<le> x; 0 \<le> y |] ==> (0::real) \<le> x + y"
```
```   613 apply (drule order_le_imp_less_or_eq)+
```
```   614 apply (auto intro: real_add_order order_less_imp_le)
```
```   615 done
```
```   616
```
```   617 lemma real_inverse_unique: "x*y = (1::real) ==> y = inverse x"
```
```   618 apply (case_tac "x \<noteq> 0")
```
```   619 apply (rule_tac c1 = x in real_mult_left_cancel [THEN iffD1], auto)
```
```   620 done
```
```   621
```
```   622 lemma real_inverse_gt_one: "[| (0::real) < x; x < 1 |] ==> 1 < inverse x"
```
```   623 by (auto dest: less_imp_inverse_less)
```
```   624
```
```   625 lemma real_mult_self_sum_ge_zero: "(0::real) \<le> x*x + y*y"
```
```   626 proof -
```
```   627   have "0 + 0 \<le> x*x + y*y" by (blast intro: add_mono zero_le_square)
```
```   628   thus ?thesis by simp
```
```   629 qed
```
```   630
```
```   631
```
```   632 subsection{*Embedding the Integers into the Reals*}
```
```   633
```
```   634 defs (overloaded)
```
```   635   real_of_nat_def: "real z == of_nat z"
```
```   636   real_of_int_def: "real z == of_int z"
```
```   637
```
```   638 lemma real_of_int_zero [simp]: "real (0::int) = 0"
```
```   639 by (simp add: real_of_int_def)
```
```   640
```
```   641 lemma real_of_one [simp]: "real (1::int) = (1::real)"
```
```   642 by (simp add: real_of_int_def)
```
```   643
```
```   644 lemma real_of_int_add: "real (x::int) + real y = real (x + y)"
```
```   645 by (simp add: real_of_int_def)
```
```   646 declare real_of_int_add [symmetric, simp]
```
```   647
```
```   648 lemma real_of_int_minus: "-real (x::int) = real (-x)"
```
```   649 by (simp add: real_of_int_def)
```
```   650 declare real_of_int_minus [symmetric, simp]
```
```   651
```
```   652 lemma real_of_int_diff: "real (x::int) - real y = real (x - y)"
```
```   653 by (simp add: real_of_int_def)
```
```   654 declare real_of_int_diff [symmetric, simp]
```
```   655
```
```   656 lemma real_of_int_mult: "real (x::int) * real y = real (x * y)"
```
```   657 by (simp add: real_of_int_def)
```
```   658 declare real_of_int_mult [symmetric, simp]
```
```   659
```
```   660 lemma real_of_int_zero_cancel [simp]: "(real x = 0) = (x = (0::int))"
```
```   661 by (simp add: real_of_int_def)
```
```   662
```
```   663 lemma real_of_int_inject [iff]: "(real (x::int) = real y) = (x = y)"
```
```   664 by (simp add: real_of_int_def)
```
```   665
```
```   666 lemma real_of_int_less_iff [iff]: "(real (x::int) < real y) = (x < y)"
```
```   667 by (simp add: real_of_int_def)
```
```   668
```
```   669 lemma real_of_int_le_iff [simp]: "(real (x::int) \<le> real y) = (x \<le> y)"
```
```   670 by (simp add: real_of_int_def)
```
```   671
```
```   672
```
```   673 subsection{*Embedding the Naturals into the Reals*}
```
```   674
```
```   675 lemma real_of_nat_zero [simp]: "real (0::nat) = 0"
```
```   676 by (simp add: real_of_nat_def)
```
```   677
```
```   678 lemma real_of_nat_one [simp]: "real (Suc 0) = (1::real)"
```
```   679 by (simp add: real_of_nat_def)
```
```   680
```
```   681 lemma real_of_nat_add [simp]: "real (m + n) = real (m::nat) + real n"
```
```   682 by (simp add: real_of_nat_def)
```
```   683
```
```   684 (*Not for addsimps: often the LHS is used to represent a positive natural*)
```
```   685 lemma real_of_nat_Suc: "real (Suc n) = real n + (1::real)"
```
```   686 by (simp add: real_of_nat_def)
```
```   687
```
```   688 lemma real_of_nat_less_iff [iff]:
```
```   689      "(real (n::nat) < real m) = (n < m)"
```
```   690 by (simp add: real_of_nat_def)
```
```   691
```
```   692 lemma real_of_nat_le_iff [iff]: "(real (n::nat) \<le> real m) = (n \<le> m)"
```
```   693 by (simp add: real_of_nat_def)
```
```   694
```
```   695 lemma real_of_nat_ge_zero [iff]: "0 \<le> real (n::nat)"
```
```   696 by (simp add: real_of_nat_def zero_le_imp_of_nat)
```
```   697
```
```   698 lemma real_of_nat_Suc_gt_zero: "0 < real (Suc n)"
```
```   699 by (simp add: real_of_nat_def del: of_nat_Suc)
```
```   700
```
```   701 lemma real_of_nat_mult [simp]: "real (m * n) = real (m::nat) * real n"
```
```   702 by (simp add: real_of_nat_def)
```
```   703
```
```   704 lemma real_of_nat_inject [iff]: "(real (n::nat) = real m) = (n = m)"
```
```   705 by (simp add: real_of_nat_def)
```
```   706
```
```   707 lemma real_of_nat_zero_iff [iff]: "(real (n::nat) = 0) = (n = 0)"
```
```   708 by (simp add: real_of_nat_def)
```
```   709
```
```   710 lemma real_of_nat_diff: "n \<le> m ==> real (m - n) = real (m::nat) - real n"
```
```   711 by (simp add: add: real_of_nat_def)
```
```   712
```
```   713 lemma real_of_nat_gt_zero_cancel_iff [simp]: "(0 < real (n::nat)) = (0 < n)"
```
```   714 by (simp add: add: real_of_nat_def)
```
```   715
```
```   716 lemma real_of_nat_le_zero_cancel_iff [simp]: "(real (n::nat) \<le> 0) = (n = 0)"
```
```   717 by (simp add: add: real_of_nat_def)
```
```   718
```
```   719 lemma not_real_of_nat_less_zero [simp]: "~ real (n::nat) < 0"
```
```   720 by (simp add: add: real_of_nat_def)
```
```   721
```
```   722 lemma real_of_nat_ge_zero_cancel_iff [simp]: "(0 \<le> real (n::nat)) = (0 \<le> n)"
```
```   723 by (simp add: add: real_of_nat_def)
```
```   724
```
```   725 lemma real_of_int_real_of_nat: "real (int n) = real n"
```
```   726 by (simp add: real_of_nat_def real_of_int_def int_eq_of_nat)
```
```   727
```
```   728 lemma real_of_int_of_nat_eq [simp]: "real (of_nat n :: int) = real n"
```
```   729 by (simp add: real_of_int_def real_of_nat_def)
```
```   730
```
```   731
```
```   732
```
```   733 subsection{*Numerals and Arithmetic*}
```
```   734
```
```   735 instance real :: number ..
```
```   736
```
```   737 defs (overloaded)
```
```   738   real_number_of_def: "(number_of w :: real) == of_int (Rep_Bin w)"
```
```   739     --{*the type constraint is essential!*}
```
```   740
```
```   741 instance real :: number_ring
```
```   742 by (intro_classes, simp add: real_number_of_def)
```
```   743
```
```   744
```
```   745 text{*Collapse applications of @{term real} to @{term number_of}*}
```
```   746 lemma real_number_of [simp]: "real (number_of v :: int) = number_of v"
```
```   747 by (simp add:  real_of_int_def of_int_number_of_eq)
```
```   748
```
```   749 lemma real_of_nat_number_of [simp]:
```
```   750      "real (number_of v :: nat) =
```
```   751         (if neg (number_of v :: int) then 0
```
```   752          else (number_of v :: real))"
```
```   753 by (simp add: real_of_int_real_of_nat [symmetric] int_nat_number_of)
```
```   754
```
```   755
```
```   756 use "real_arith.ML"
```
```   757
```
```   758 setup real_arith_setup
```
```   759
```
```   760 subsection{* Simprules combining x+y and 0: ARE THEY NEEDED?*}
```
```   761
```
```   762 text{*Needed in this non-standard form by Hyperreal/Transcendental*}
```
```   763 lemma real_0_le_divide_iff:
```
```   764      "((0::real) \<le> x/y) = ((x \<le> 0 | 0 \<le> y) & (0 \<le> x | y \<le> 0))"
```
```   765 by (simp add: real_divide_def zero_le_mult_iff, auto)
```
```   766
```
```   767 lemma real_add_minus_iff [simp]: "(x + - a = (0::real)) = (x=a)"
```
```   768 by arith
```
```   769
```
```   770 lemma real_add_eq_0_iff: "(x+y = (0::real)) = (y = -x)"
```
```   771 by auto
```
```   772
```
```   773 lemma real_add_less_0_iff: "(x+y < (0::real)) = (y < -x)"
```
```   774 by auto
```
```   775
```
```   776 lemma real_0_less_add_iff: "((0::real) < x+y) = (-x < y)"
```
```   777 by auto
```
```   778
```
```   779 lemma real_add_le_0_iff: "(x+y \<le> (0::real)) = (y \<le> -x)"
```
```   780 by auto
```
```   781
```
```   782 lemma real_0_le_add_iff: "((0::real) \<le> x+y) = (-x \<le> y)"
```
```   783 by auto
```
```   784
```
```   785
```
```   786 (*
```
```   787 FIXME: we should have this, as for type int, but many proofs would break.
```
```   788 It replaces x+-y by x-y.
```
```   789 declare real_diff_def [symmetric, simp]
```
```   790 *)
```
```   791
```
```   792
```
```   793 subsubsection{*Density of the Reals*}
```
```   794
```
```   795 lemma real_lbound_gt_zero:
```
```   796      "[| (0::real) < d1; 0 < d2 |] ==> \<exists>e. 0 < e & e < d1 & e < d2"
```
```   797 apply (rule_tac x = " (min d1 d2) /2" in exI)
```
```   798 apply (simp add: min_def)
```
```   799 done
```
```   800
```
```   801
```
```   802 text{*Similar results are proved in @{text Ring_and_Field}*}
```
```   803 lemma real_less_half_sum: "x < y ==> x < (x+y) / (2::real)"
```
```   804   by auto
```
```   805
```
```   806 lemma real_gt_half_sum: "x < y ==> (x+y)/(2::real) < y"
```
```   807   by auto
```
```   808
```
```   809
```
```   810 subsection{*Absolute Value Function for the Reals*}
```
```   811
```
```   812 text{*FIXME: these should go!*}
```
```   813 lemma abs_eqI1: "(0::real)\<le>x ==> abs x = x"
```
```   814 by (simp add: abs_if)
```
```   815
```
```   816 lemma abs_eqI2: "(0::real) < x ==> abs x = x"
```
```   817 by (simp add: abs_if)
```
```   818
```
```   819 lemma abs_minus_eqI2: "x < (0::real) ==> abs x = -x"
```
```   820 by (simp add: abs_if linorder_not_less [symmetric])
```
```   821
```
```   822 lemma abs_minus_add_cancel: "abs(x + (-y)) = abs (y + (-(x::real)))"
```
```   823 by (simp add: abs_if)
```
```   824
```
```   825 lemma abs_interval_iff: "(abs x < r) = (-r < x & x < (r::real))"
```
```   826 by (force simp add: Ring_and_Field.abs_less_iff)
```
```   827
```
```   828 lemma abs_le_interval_iff: "(abs x \<le> r) = (-r\<le>x & x\<le>(r::real))"
```
```   829 by (force simp add: OrderedGroup.abs_le_iff)
```
```   830
```
```   831 (*FIXME: used only once, in SEQ.ML*)
```
```   832 lemma abs_add_one_gt_zero [simp]: "(0::real) < 1 + abs(x)"
```
```   833 by (simp add: abs_if)
```
```   834
```
```   835 lemma abs_real_of_nat_cancel [simp]: "abs (real x) = real (x::nat)"
```
```   836 by (auto intro: abs_eqI1 simp add: real_of_nat_ge_zero)
```
```   837
```
```   838 lemma abs_add_one_not_less_self [simp]: "~ abs(x) + (1::real) < x"
```
```   839 apply (simp add: linorder_not_less)
```
```   840 apply (auto intro: abs_ge_self [THEN order_trans])
```
```   841 done
```
```   842
```
```   843 text{*Used only in Hyperreal/Lim.ML*}
```
```   844 lemma abs_sum_triangle_ineq: "abs ((x::real) + y + (-l + -m)) \<le> abs(x + -l) + abs(y + -m)"
```
```   845 apply (simp add: real_add_assoc)
```
```   846 apply (rule_tac a1 = y in add_left_commute [THEN ssubst])
```
```   847 apply (rule real_add_assoc [THEN subst])
```
```   848 apply (rule abs_triangle_ineq)
```
```   849 done
```
```   850
```
```   851
```
```   852
```
```   853 ML
```
```   854 {*
```
```   855 val real_lbound_gt_zero = thm"real_lbound_gt_zero";
```
```   856 val real_less_half_sum = thm"real_less_half_sum";
```
```   857 val real_gt_half_sum = thm"real_gt_half_sum";
```
```   858
```
```   859 val abs_eqI1 = thm"abs_eqI1";
```
```   860 val abs_eqI2 = thm"abs_eqI2";
```
```   861 val abs_minus_eqI2 = thm"abs_minus_eqI2";
```
```   862 val abs_ge_zero = thm"abs_ge_zero";
```
```   863 val abs_idempotent = thm"abs_idempotent";
```
```   864 val abs_eq_0 = thm"abs_eq_0";
```
```   865 val abs_ge_self = thm"abs_ge_self";
```
```   866 val abs_ge_minus_self = thm"abs_ge_minus_self";
```
```   867 val abs_mult = thm"abs_mult";
```
```   868 val abs_inverse = thm"abs_inverse";
```
```   869 val abs_triangle_ineq = thm"abs_triangle_ineq";
```
```   870 val abs_minus_cancel = thm"abs_minus_cancel";
```
```   871 val abs_minus_add_cancel = thm"abs_minus_add_cancel";
```
```   872 val abs_interval_iff = thm"abs_interval_iff";
```
```   873 val abs_le_interval_iff = thm"abs_le_interval_iff";
```
```   874 val abs_add_one_gt_zero = thm"abs_add_one_gt_zero";
```
```   875 val abs_le_zero_iff = thm"abs_le_zero_iff";
```
```   876 val abs_add_one_not_less_self = thm"abs_add_one_not_less_self";
```
```   877 val abs_sum_triangle_ineq = thm"abs_sum_triangle_ineq";
```
```   878
```
```   879 val abs_mult_less = thm"abs_mult_less";
```
```   880 *}
```
```   881
```
```   882
```
```   883 end
```