src/HOL/Real/RealDef.thy
changeset 23287 063039db59dd
parent 23031 9da9585c816e
child 23288 3e45b5464d2b
equal deleted inserted replaced
23286:85e7e043b980 23287:063039db59dd
    35 
    35 
    36 
    36 
    37 defs (overloaded)
    37 defs (overloaded)
    38 
    38 
    39   real_zero_def:
    39   real_zero_def:
    40   "0 == Abs_Real(realrel``{(preal_of_rat 1, preal_of_rat 1)})"
    40   "0 == Abs_Real(realrel``{(1, 1)})"
    41 
    41 
    42   real_one_def:
    42   real_one_def:
    43   "1 == Abs_Real(realrel``
    43   "1 == Abs_Real(realrel``{(1 + 1, 1)})"
    44                {(preal_of_rat 1 + preal_of_rat 1,
       
    45 		 preal_of_rat 1)})"
       
    46 
    44 
    47   real_minus_def:
    45   real_minus_def:
    48   "- r ==  contents (\<Union>(x,y) \<in> Rep_Real(r). { Abs_Real(realrel``{(y,x)}) })"
    46   "- r ==  contents (\<Union>(x,y) \<in> Rep_Real(r). { Abs_Real(realrel``{(y,x)}) })"
    49 
    47 
    50   real_add_def:
    48   real_add_def:
    59     "z * w ==
    57     "z * w ==
    60        contents (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w).
    58        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)}) })"
    59 		 { Abs_Real(realrel``{(x*u + y*v, x*v + y*u)}) })"
    62 
    60 
    63   real_inverse_def:
    61   real_inverse_def:
    64   "inverse (R::real) == (SOME S. (R = 0 & S = 0) | S * R = 1)"
    62   "inverse (R::real) == (THE S. (R = 0 & S = 0) | S * R = 1)"
    65 
    63 
    66   real_divide_def:
    64   real_divide_def:
    67   "R / (S::real) == R * inverse S"
    65   "R / (S::real) == R * inverse S"
    68 
    66 
    69   real_le_def:
    67   real_le_def:
    73   real_less_def: "(x < (y::real)) == (x \<le> y & x \<noteq> y)"
    71   real_less_def: "(x < (y::real)) == (x \<le> y & x \<noteq> y)"
    74 
    72 
    75   real_abs_def:  "abs (r::real) == (if r < 0 then - r else r)"
    73   real_abs_def:  "abs (r::real) == (if r < 0 then - r else r)"
    76 
    74 
    77 
    75 
    78 
    76 subsection {* Equivalence relation over positive reals *}
    79 subsection{*Proving that realrel is an equivalence relation*}
       
    80 
    77 
    81 lemma preal_trans_lemma:
    78 lemma preal_trans_lemma:
    82   assumes "x + y1 = x1 + y"
    79   assumes "x + y1 = x1 + y"
    83       and "x + y2 = x2 + y"
    80       and "x + y2 = x2 + y"
    84   shows "x1 + y2 = x2 + (y1::preal)"
    81   shows "x1 + y2 = x2 + (y1::preal)"
    85 proof -
    82 proof -
    86   have "(x1 + y2) + x = (x + y2) + x1" by (simp add: preal_add_ac) 
    83   have "(x1 + y2) + x = (x + y2) + x1" by (simp add: add_ac)
    87   also have "... = (x2 + y) + x1"  by (simp add: prems)
    84   also have "... = (x2 + y) + x1"  by (simp add: prems)
    88   also have "... = x2 + (x1 + y)"  by (simp add: preal_add_ac)
    85   also have "... = x2 + (x1 + y)"  by (simp add: add_ac)
    89   also have "... = x2 + (x + y1)"  by (simp add: prems)
    86   also have "... = x2 + (x + y1)"  by (simp add: prems)
    90   also have "... = (x2 + y1) + x"  by (simp add: preal_add_ac)
    87   also have "... = (x2 + y1) + x"  by (simp add: add_ac)
    91   finally have "(x1 + y2) + x = (x2 + y1) + x" .
    88   finally have "(x1 + y2) + x = (x2 + y1) + x" .
    92   thus ?thesis by (simp add: preal_add_right_cancel_iff) 
    89   thus ?thesis by (rule add_right_imp_eq)
    93 qed
    90 qed
    94 
    91 
    95 
    92 
    96 lemma realrel_iff [simp]: "(((x1,y1),(x2,y2)) \<in> realrel) = (x1 + y2 = x2 + y1)"
    93 lemma realrel_iff [simp]: "(((x1,y1),(x2,y2)) \<in> realrel) = (x1 + y2 = x2 + y1)"
    97 by (simp add: realrel_def)
    94 by (simp add: realrel_def)
   124 apply (drule arg_cong [where f=Abs_Real])
   121 apply (drule arg_cong [where f=Abs_Real])
   125 apply (auto simp add: Rep_Real_inverse)
   122 apply (auto simp add: Rep_Real_inverse)
   126 done
   123 done
   127 
   124 
   128 
   125 
   129 subsection{*Congruence property for addition*}
   126 subsection {* Addition and Subtraction *}
   130 
   127 
   131 lemma real_add_congruent2_lemma:
   128 lemma real_add_congruent2_lemma:
   132      "[|a + ba = aa + b; ab + bc = ac + bb|]
   129      "[|a + ba = aa + b; ab + bc = ac + bb|]
   133       ==> a + ab + (ba + bc) = aa + ac + (b + (bb::preal))"
   130       ==> a + ab + (ba + bc) = aa + ac + (b + (bb::preal))"
   134 apply (simp add: preal_add_assoc) 
   131 apply (simp add: add_assoc)
   135 apply (rule preal_add_left_commute [of ab, THEN ssubst])
   132 apply (rule add_left_commute [of ab, THEN ssubst])
   136 apply (simp add: preal_add_assoc [symmetric])
   133 apply (simp add: add_assoc [symmetric])
   137 apply (simp add: preal_add_ac)
   134 apply (simp add: add_ac)
   138 done
   135 done
   139 
   136 
   140 lemma real_add:
   137 lemma real_add:
   141      "Abs_Real (realrel``{(x,y)}) + Abs_Real (realrel``{(u,v)}) =
   138      "Abs_Real (realrel``{(x,y)}) + Abs_Real (realrel``{(u,v)}) =
   142       Abs_Real (realrel``{(x+u, y+v)})"
   139       Abs_Real (realrel``{(x+u, y+v)})"
   147   thus ?thesis
   144   thus ?thesis
   148     by (simp add: real_add_def UN_UN_split_split_eq
   145     by (simp add: real_add_def UN_UN_split_split_eq
   149                   UN_equiv_class2 [OF equiv_realrel equiv_realrel])
   146                   UN_equiv_class2 [OF equiv_realrel equiv_realrel])
   150 qed
   147 qed
   151 
   148 
   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)})"
   149 lemma real_minus: "- Abs_Real(realrel``{(x,y)}) = Abs_Real(realrel `` {(y,x)})"
   170 proof -
   150 proof -
   171   have "(\<lambda>(x,y). {Abs_Real (realrel``{(y,x)})}) respects realrel"
   151   have "(\<lambda>(x,y). {Abs_Real (realrel``{(y,x)})}) respects realrel"
   172     by (simp add: congruent_def preal_add_commute) 
   152     by (simp add: congruent_def preal_add_commute) 
   173   thus ?thesis
   153   thus ?thesis
   174     by (simp add: real_minus_def UN_equiv_class [OF equiv_realrel])
   154     by (simp add: real_minus_def UN_equiv_class [OF equiv_realrel])
   175 qed
   155 qed
   176 
   156 
   177 lemma real_add_minus_left: "(-z) + z = (0::real)"
   157 instance real :: ab_group_add
   178 by (cases z, simp add: real_minus real_add real_zero_def preal_add_commute)
   158 proof
   179 
   159   fix x y z :: real
   180 
   160   show "(x + y) + z = x + (y + z)"
   181 subsection{*Congruence property for multiplication*}
   161     by (cases x, cases y, cases z, simp add: real_add add_assoc)
       
   162   show "x + y = y + x"
       
   163     by (cases x, cases y, simp add: real_add add_commute)
       
   164   show "0 + x = x"
       
   165     by (cases x, simp add: real_add real_zero_def add_ac)
       
   166   show "- x + x = 0"
       
   167     by (cases x, simp add: real_minus real_add real_zero_def add_commute)
       
   168   show "x - y = x + - y"
       
   169     by (simp add: real_diff_def)
       
   170 qed
       
   171 
       
   172 
       
   173 subsection {* Multiplication *}
   182 
   174 
   183 lemma real_mult_congruent2_lemma:
   175 lemma real_mult_congruent2_lemma:
   184      "!!(x1::preal). [| x1 + y2 = x2 + y1 |] ==>
   176      "!!(x1::preal). [| x1 + y2 = x2 + y1 |] ==>
   185           x * x1 + y * y1 + (x * y2 + y * x2) =
   177           x * x1 + y * y1 + (x * y2 + y * x2) =
   186           x * x2 + y * y2 + (x * y1 + y * x1)"
   178           x * x2 + y * y2 + (x * y1 + y * x1)"
   187 apply (simp add: preal_add_left_commute preal_add_assoc [symmetric])
   179 apply (simp add: add_left_commute add_assoc [symmetric])
   188 apply (simp add: preal_add_assoc preal_add_mult_distrib2 [symmetric])
   180 apply (simp add: preal_add_assoc preal_add_mult_distrib2 [symmetric])
   189 apply (simp add: preal_add_commute)
   181 apply (simp add: preal_add_commute)
   190 done
   182 done
   191 
   183 
   192 lemma real_mult_congruent2:
   184 lemma real_mult_congruent2:
   226 done
   218 done
   227 
   219 
   228 text{*one and zero are distinct*}
   220 text{*one and zero are distinct*}
   229 lemma real_zero_not_eq_one: "0 \<noteq> (1::real)"
   221 lemma real_zero_not_eq_one: "0 \<noteq> (1::real)"
   230 proof -
   222 proof -
   231   have "preal_of_rat 1 < preal_of_rat 1 + preal_of_rat 1"
   223   have "(1::preal) < 1 + 1"
   232     by (simp add: preal_self_less_add_left) 
   224     by (simp add: preal_self_less_add_left)
   233   thus ?thesis
   225   thus ?thesis
   234     by (simp add: real_zero_def real_one_def preal_add_right_cancel_iff)
   226     by (simp add: real_zero_def real_one_def preal_add_right_cancel_iff)
   235 qed
   227 qed
   236 
   228 
   237 subsection{*existence of inverse*}
   229 instance real :: comm_ring_1
       
   230 proof
       
   231   fix x y z :: real
       
   232   show "(x * y) * z = x * (y * z)" by (rule real_mult_assoc)
       
   233   show "x * y = y * x" by (rule real_mult_commute)
       
   234   show "1 * x = x" by (rule real_mult_1)
       
   235   show "(x + y) * z = x * z + y * z" by (rule real_add_mult_distrib)
       
   236   show "0 \<noteq> (1::real)" by (rule real_zero_not_eq_one)
       
   237 qed
       
   238 
       
   239 subsection {* Inverse and Division *}
   238 
   240 
   239 lemma real_zero_iff: "Abs_Real (realrel `` {(x, x)}) = 0"
   241 lemma real_zero_iff: "Abs_Real (realrel `` {(x, x)}) = 0"
   240 by (simp add: real_zero_def preal_add_commute)
   242 by (simp add: real_zero_def preal_add_commute)
   241 
   243 
   242 text{*Instead of using an existential quantifier and constructing the inverse
   244 text{*Instead of using an existential quantifier and constructing the inverse
   245 lemma real_mult_inverse_left_ex: "x \<noteq> 0 ==> \<exists>y. y*x = (1::real)"
   247 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)
   248 apply (simp add: real_zero_def real_one_def, cases x)
   247 apply (cut_tac x = xa and y = y in linorder_less_linear)
   249 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)
   250 apply (auto dest!: less_add_left_Ex simp add: real_zero_iff)
   249 apply (rule_tac
   251 apply (rule_tac
   250         x = "Abs_Real (realrel `` { (preal_of_rat 1, 
   252         x = "Abs_Real (realrel``{(1, inverse (D) + 1)})"
   251                             inverse (D) + preal_of_rat 1)}) " 
       
   252        in exI)
   253        in exI)
   253 apply (rule_tac [2]
   254 apply (rule_tac [2]
   254         x = "Abs_Real (realrel `` { (inverse (D) + preal_of_rat 1,
   255         x = "Abs_Real (realrel``{(inverse (D) + 1, 1)})" 
   255                    preal_of_rat 1)})" 
       
   256        in exI)
   256        in exI)
   257 apply (auto simp add: real_mult preal_mult_1_right
   257 apply (auto simp add: real_mult preal_mult_1_right
   258               preal_add_mult_distrib2 preal_add_mult_distrib preal_mult_1
   258               preal_add_mult_distrib2 preal_add_mult_distrib preal_mult_1
   259               preal_mult_inverse_right preal_add_ac preal_mult_ac)
   259               preal_mult_inverse_right preal_add_ac preal_mult_ac)
   260 done
   260 done
   261 
   261 
   262 lemma real_mult_inverse_left: "x \<noteq> 0 ==> inverse(x)*x = (1::real)"
   262 lemma real_mult_inverse_left: "x \<noteq> 0 ==> inverse(x)*x = (1::real)"
   263 apply (simp add: real_inverse_def)
   263 apply (simp add: real_inverse_def)
   264 apply (frule real_mult_inverse_left_ex, safe)
   264 apply (drule real_mult_inverse_left_ex, safe)
   265 apply (rule someI2, auto)
   265 apply (rule theI, assumption, rename_tac z)
       
   266 apply (subgoal_tac "(z * x) * y = z * (x * y)")
       
   267 apply (simp add: mult_commute)
       
   268 apply (rule mult_assoc)
   266 done
   269 done
   267 
   270 
   268 
   271 
   269 subsection{*The Real Numbers form a Field*}
   272 subsection{*The Real Numbers form a Field*}
   270 
   273 
   271 instance real :: field
   274 instance real :: field
   272 proof
   275 proof
   273   fix x y z :: real
   276   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)
   277   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)
   278   show "x / y = x * inverse y" by (simp add: real_divide_def)
   283 qed
   279 qed
   284 
   280 
   285 
   281