src/HOL/Hyperreal/NthRoot.thy
author huffman
Wed Mar 14 21:52:26 2007 +0100 (2007-03-14)
changeset 22443 346729a55460
parent 21865 55cc354fd2d9
child 22630 2a9b64b26612
permissions -rw-r--r--
move sqrt_divide_self_eq to NthRoot.thy
     1 (*  Title       : NthRoot.thy
     2     Author      : Jacques D. Fleuriot
     3     Copyright   : 1998  University of Cambridge
     4     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     5 *)
     6 
     7 header{*Existence of Nth Root*}
     8 
     9 theory NthRoot
    10 imports SEQ Parity
    11 begin
    12 
    13 definition
    14   root :: "[nat, real] \<Rightarrow> real" where
    15   "root n x = (THE u. (0 < x \<longrightarrow> 0 < u) \<and> (u ^ n = x))"
    16 
    17 definition
    18   sqrt :: "real \<Rightarrow> real" where
    19   "sqrt x = root 2 x"
    20 
    21 
    22 text {*
    23   Various lemmas needed for this result. We follow the proof given by
    24   John Lindsay Orr (\texttt{jorr@math.unl.edu}) in his Analysis
    25   Webnotes available at \url{http://www.math.unl.edu/~webnotes}.
    26 
    27   Lemmas about sequences of reals are used to reach the result.
    28 *}
    29 
    30 lemma lemma_nth_realpow_non_empty:
    31      "[| (0::real) < a; 0 < n |] ==> \<exists>s. s : {x. x ^ n <= a & 0 < x}"
    32 apply (case_tac "1 <= a")
    33 apply (rule_tac x = 1 in exI)
    34 apply (drule_tac [2] linorder_not_le [THEN iffD1])
    35 apply (drule_tac [2] less_not_refl2 [THEN not0_implies_Suc], simp) 
    36 apply (force intro!: realpow_Suc_le_self simp del: realpow_Suc)
    37 done
    38 
    39 text{*Used only just below*}
    40 lemma realpow_ge_self2: "[| (1::real) \<le> r; 0 < n |] ==> r \<le> r ^ n"
    41 by (insert power_increasing [of 1 n r], simp)
    42 
    43 lemma lemma_nth_realpow_isUb_ex:
    44      "[| (0::real) < a; 0 < n |]  
    45       ==> \<exists>u. isUb (UNIV::real set) {x. x ^ n <= a & 0 < x} u"
    46 apply (case_tac "1 <= a")
    47 apply (rule_tac x = a in exI)
    48 apply (drule_tac [2] linorder_not_le [THEN iffD1])
    49 apply (rule_tac [2] x = 1 in exI)
    50 apply (rule_tac [!] setleI [THEN isUbI], safe)
    51 apply (simp_all (no_asm))
    52 apply (rule_tac [!] ccontr)
    53 apply (drule_tac [!] linorder_not_le [THEN iffD1])
    54 apply (drule realpow_ge_self2, assumption)
    55 apply (drule_tac n = n in realpow_less)
    56 apply (assumption+)
    57 apply (drule real_le_trans, assumption)
    58 apply (drule_tac y = "y ^ n" in order_less_le_trans, assumption, simp) 
    59 apply (drule_tac n = n in zero_less_one [THEN realpow_less], auto)
    60 done
    61 
    62 lemma nth_realpow_isLub_ex:
    63      "[| (0::real) < a; 0 < n |]  
    64       ==> \<exists>u. isLub (UNIV::real set) {x. x ^ n <= a & 0 < x} u"
    65 by (blast intro: lemma_nth_realpow_isUb_ex lemma_nth_realpow_non_empty reals_complete)
    66 
    67  
    68 subsection{*First Half -- Lemmas First*}
    69 
    70 lemma lemma_nth_realpow_seq:
    71      "isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u  
    72            ==> u + inverse(real (Suc k)) ~: {x. x ^ n <= a & 0 < x}"
    73 apply (safe, drule isLubD2, blast)
    74 apply (simp add: linorder_not_less [symmetric])
    75 done
    76 
    77 lemma lemma_nth_realpow_isLub_gt_zero:
    78      "[| isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u;  
    79          0 < a; 0 < n |] ==> 0 < u"
    80 apply (drule lemma_nth_realpow_non_empty, auto)
    81 apply (drule_tac y = s in isLub_isUb [THEN isUbD])
    82 apply (auto intro: order_less_le_trans)
    83 done
    84 
    85 lemma lemma_nth_realpow_isLub_ge:
    86      "[| isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u;  
    87          0 < a; 0 < n |] ==> ALL k. a <= (u + inverse(real (Suc k))) ^ n"
    88 apply safe
    89 apply (frule lemma_nth_realpow_seq, safe)
    90 apply (auto elim: order_less_asym simp add: linorder_not_less [symmetric]
    91             iff: real_0_less_add_iff) --{*legacy iff rule!*}
    92 apply (simp add: linorder_not_less)
    93 apply (rule order_less_trans [of _ 0])
    94 apply (auto intro: lemma_nth_realpow_isLub_gt_zero)
    95 done
    96 
    97 text{*First result we want*}
    98 lemma realpow_nth_ge:
    99      "[| (0::real) < a; 0 < n;  
   100      isLub (UNIV::real set)  
   101      {x. x ^ n <= a & 0 < x} u |] ==> a <= u ^ n"
   102 apply (frule lemma_nth_realpow_isLub_ge, safe)
   103 apply (rule LIMSEQ_inverse_real_of_nat_add [THEN LIMSEQ_pow, THEN LIMSEQ_le_const])
   104 apply (auto simp add: real_of_nat_def)
   105 done
   106 
   107 subsection{*Second Half*}
   108 
   109 lemma less_isLub_not_isUb:
   110      "[| isLub (UNIV::real set) S u; x < u |]  
   111            ==> ~ isUb (UNIV::real set) S x"
   112 apply safe
   113 apply (drule isLub_le_isUb, assumption)
   114 apply (drule order_less_le_trans, auto)
   115 done
   116 
   117 lemma not_isUb_less_ex:
   118      "~ isUb (UNIV::real set) S u ==> \<exists>x \<in> S. u < x"
   119 apply (rule ccontr, erule contrapos_np)
   120 apply (rule setleI [THEN isUbI])
   121 apply (auto simp add: linorder_not_less [symmetric])
   122 done
   123 
   124 lemma real_mult_less_self: "0 < r ==> r * (1 + -inverse(real (Suc n))) < r"
   125 apply (simp (no_asm) add: right_distrib)
   126 apply (rule add_less_cancel_left [of "-r", THEN iffD1])
   127 apply (auto intro: mult_pos_pos
   128             simp add: add_assoc [symmetric] neg_less_0_iff_less)
   129 done
   130 
   131 lemma real_mult_add_one_minus_ge_zero:
   132      "0 < r ==>  0 <= r*(1 + -inverse(real (Suc n)))"
   133 by (simp add: zero_le_mult_iff real_of_nat_inverse_le_iff real_0_le_add_iff)
   134 
   135 lemma lemma_nth_realpow_isLub_le:
   136      "[| isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u;  
   137        0 < a; 0 < n |] ==> ALL k. (u*(1 + -inverse(real (Suc k)))) ^ n <= a"
   138 apply safe
   139 apply (frule less_isLub_not_isUb [THEN not_isUb_less_ex])
   140 apply (rule_tac n = k in real_mult_less_self)
   141 apply (blast intro: lemma_nth_realpow_isLub_gt_zero, safe)
   142 apply (drule_tac n = k in
   143         lemma_nth_realpow_isLub_gt_zero [THEN real_mult_add_one_minus_ge_zero], assumption+)
   144 apply (blast intro: order_trans order_less_imp_le power_mono) 
   145 done
   146 
   147 text{*Second result we want*}
   148 lemma realpow_nth_le:
   149      "[| (0::real) < a; 0 < n;  
   150      isLub (UNIV::real set)  
   151      {x. x ^ n <= a & 0 < x} u |] ==> u ^ n <= a"
   152 apply (frule lemma_nth_realpow_isLub_le, safe)
   153 apply (rule LIMSEQ_inverse_real_of_nat_add_minus_mult
   154                 [THEN LIMSEQ_pow, THEN LIMSEQ_le_const2])
   155 apply (auto simp add: real_of_nat_def)
   156 done
   157 
   158 text{*The theorem at last!*}
   159 lemma realpow_nth: "[| (0::real) < a; 0 < n |] ==> \<exists>r. r ^ n = a"
   160 apply (frule nth_realpow_isLub_ex, auto)
   161 apply (auto intro: realpow_nth_le realpow_nth_ge order_antisym)
   162 done
   163 
   164 (* positive only *)
   165 lemma realpow_pos_nth: "[| (0::real) < a; 0 < n |] ==> \<exists>r. 0 < r & r ^ n = a"
   166 apply (frule nth_realpow_isLub_ex, auto)
   167 apply (auto intro: realpow_nth_le realpow_nth_ge order_antisym lemma_nth_realpow_isLub_gt_zero)
   168 done
   169 
   170 lemma realpow_pos_nth2: "(0::real) < a  ==> \<exists>r. 0 < r & r ^ Suc n = a"
   171 by (blast intro: realpow_pos_nth)
   172 
   173 (* uniqueness of nth positive root *)
   174 lemma realpow_pos_nth_unique:
   175      "[| (0::real) < a; 0 < n |] ==> EX! r. 0 < r & r ^ n = a"
   176 apply (auto intro!: realpow_pos_nth)
   177 apply (cut_tac x = r and y = y in linorder_less_linear, auto)
   178 apply (drule_tac x = r in realpow_less)
   179 apply (drule_tac [4] x = y in realpow_less, auto)
   180 done
   181 
   182 subsection {* Nth Root *}
   183 
   184 lemma real_root_zero [simp]: "root (Suc n) 0 = 0"
   185 apply (simp add: root_def)
   186 apply (safe intro!: the_equality power_0_Suc elim!: realpow_zero_zero)
   187 done
   188 
   189 lemma real_root_pow_pos: 
   190      "0 < x ==> (root (Suc n) x) ^ (Suc n) = x"
   191 apply (simp add: root_def del: realpow_Suc)
   192 apply (drule_tac n="Suc n" in realpow_pos_nth_unique, simp)
   193 apply (erule theI' [THEN conjunct2])
   194 done
   195 
   196 lemma real_root_pow_pos2: "0 \<le> x ==> (root (Suc n) x) ^ (Suc n) = x"
   197 by (auto dest!: real_le_imp_less_or_eq dest: real_root_pow_pos)
   198 
   199 lemma real_root_pos: 
   200      "0 < x ==> root(Suc n) (x ^ (Suc n)) = x"
   201 apply (simp add: root_def)
   202 apply (rule the_equality)
   203 apply (frule_tac [2] n = n in zero_less_power)
   204 apply (auto simp add: zero_less_mult_iff)
   205 apply (rule_tac x = u and y = x in linorder_cases)
   206 apply (drule_tac n1 = n and x = u in zero_less_Suc [THEN [3] realpow_less])
   207 apply (drule_tac [4] n1 = n and x = x in zero_less_Suc [THEN [3] realpow_less])
   208 apply (auto)
   209 done
   210 
   211 lemma real_root_pos2: "0 \<le> x ==> root(Suc n) (x ^ (Suc n)) = x"
   212 by (auto dest!: real_le_imp_less_or_eq real_root_pos)
   213 
   214 lemma real_root_gt_zero:
   215      "0 < x ==> 0 < root (Suc n) x"
   216 apply (simp add: root_def del: realpow_Suc)
   217 apply (drule_tac n="Suc n" in realpow_pos_nth_unique, simp)
   218 apply (erule theI' [THEN conjunct1])
   219 done
   220 
   221 lemma real_root_pos_pos: 
   222      "0 < x ==> 0 \<le> root(Suc n) x"
   223 by (rule real_root_gt_zero [THEN order_less_imp_le])
   224 
   225 lemma real_root_pos_pos_le: "0 \<le> x ==> 0 \<le> root(Suc n) x"
   226 by (auto simp add: order_le_less real_root_gt_zero)
   227 
   228 lemma real_root_one [simp]: "root (Suc n) 1 = 1"
   229 apply (simp add: root_def)
   230 apply (rule the_equality, auto)
   231 apply (rule ccontr)
   232 apply (rule_tac x = u and y = 1 in linorder_cases)
   233 apply (drule_tac n = n in realpow_Suc_less_one)
   234 apply (drule_tac [4] n = n in power_gt1_lemma)
   235 apply (auto)
   236 done
   237 
   238 
   239 subsection{*Square Root*}
   240 
   241 text{*needed because 2 is a binary numeral!*}
   242 lemma root_2_eq [simp]: "root 2 = root (Suc (Suc 0))"
   243 by (simp del: nat_numeral_0_eq_0 nat_numeral_1_eq_1 
   244          add: nat_numeral_0_eq_0 [symmetric])
   245 
   246 lemma real_sqrt_zero [simp]: "sqrt 0 = 0"
   247 by (simp add: sqrt_def)
   248 
   249 lemma real_sqrt_one [simp]: "sqrt 1 = 1"
   250 by (simp add: sqrt_def)
   251 
   252 lemma real_sqrt_pow2_iff [iff]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)"
   253 apply (simp add: sqrt_def)
   254 apply (rule iffI) 
   255  apply (cut_tac r = "root 2 x" in realpow_two_le)
   256  apply (simp add: numeral_2_eq_2)
   257 apply (subst numeral_2_eq_2)
   258 apply (erule real_root_pow_pos2)
   259 done
   260 
   261 lemma [simp]: "(sqrt(u2\<twosuperior> + v2\<twosuperior>))\<twosuperior> = u2\<twosuperior> + v2\<twosuperior>"
   262 by (rule realpow_two_le_add_order [THEN real_sqrt_pow2_iff [THEN iffD2]])
   263 
   264 lemma real_sqrt_pow2 [simp]: "0 \<le> x ==> (sqrt x)\<twosuperior> = x"
   265 by (simp)
   266 
   267 lemma real_sqrt_abs_abs [simp]: "sqrt\<bar>x\<bar> ^ 2 = \<bar>x\<bar>"
   268 by (rule real_sqrt_pow2_iff [THEN iffD2], arith)
   269 
   270 lemma real_pow_sqrt_eq_sqrt_pow: 
   271       "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(x\<twosuperior>)"
   272 apply (simp add: sqrt_def)
   273 apply (simp only: numeral_2_eq_2 real_root_pow_pos2 real_root_pos2)
   274 done
   275 
   276 lemma real_pow_sqrt_eq_sqrt_abs_pow2:
   277      "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(\<bar>x\<bar> ^ 2)" 
   278 by (simp add: real_pow_sqrt_eq_sqrt_pow [symmetric])
   279 
   280 lemma real_sqrt_pow_abs: "0 \<le> x ==> (sqrt x)\<twosuperior> = \<bar>x\<bar>"
   281 apply (rule real_sqrt_abs_abs [THEN subst])
   282 apply (rule_tac x1 = x in real_pow_sqrt_eq_sqrt_abs_pow2 [THEN ssubst])
   283 apply (rule_tac [2] real_pow_sqrt_eq_sqrt_pow [symmetric])
   284 apply (assumption, arith)
   285 done
   286 
   287 lemma not_real_square_gt_zero [simp]: "(~ (0::real) < x*x) = (x = 0)"
   288 apply auto
   289 apply (cut_tac x = x and y = 0 in linorder_less_linear)
   290 apply (simp add: zero_less_mult_iff)
   291 done
   292 
   293 lemma real_sqrt_gt_zero: "0 < x ==> 0 < sqrt(x)"
   294 by (simp add: sqrt_def real_root_gt_zero)
   295 
   296 lemma real_sqrt_ge_zero: "0 \<le> x ==> 0 \<le> sqrt(x)"
   297 by (auto intro: real_sqrt_gt_zero simp add: order_le_less)
   298 
   299 lemma real_sqrt_mult_self_sum_ge_zero [simp]: "0 \<le> sqrt(x*x + y*y)"
   300 by (rule real_sqrt_ge_zero [OF real_mult_self_sum_ge_zero]) 
   301 
   302 
   303 (*we need to prove something like this:
   304 lemma "[|r ^ n = a; 0<n; 0 < a \<longrightarrow> 0 < r|] ==> root n a = r"
   305 apply (case_tac n, simp) 
   306 apply (simp add: root_def) 
   307 apply (rule someI2 [of _ r], safe)
   308 apply (auto simp del: realpow_Suc dest: power_inject_base)
   309 *)
   310 
   311 lemma sqrt_eqI: "[|r\<twosuperior> = a; 0 \<le> r|] ==> sqrt a = r"
   312 apply (erule subst)
   313 apply (simp add: sqrt_def numeral_2_eq_2 del: realpow_Suc)
   314 apply (erule real_root_pos2)
   315 done
   316 
   317 lemma real_sqrt_mult_distrib: 
   318      "[| 0 \<le> x; 0 \<le> y |] ==> sqrt(x*y) = sqrt(x) * sqrt(y)"
   319 apply (rule sqrt_eqI)
   320 apply (simp add: power_mult_distrib)  
   321 apply (simp add: zero_le_mult_iff real_sqrt_ge_zero) 
   322 done
   323 
   324 lemma real_sqrt_mult_distrib2:
   325      "[|0\<le>x; 0\<le>y |] ==> sqrt(x*y) =  sqrt(x) * sqrt(y)"
   326 by (auto intro: real_sqrt_mult_distrib simp add: order_le_less)
   327 
   328 lemma real_sqrt_sum_squares_ge_zero [simp]: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   329 by (auto intro!: real_sqrt_ge_zero)
   330 
   331 lemma real_sqrt_sum_squares_mult_ge_zero [simp]:
   332      "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))"
   333 by (auto intro!: real_sqrt_ge_zero simp add: zero_le_mult_iff)
   334 
   335 lemma real_sqrt_sum_squares_mult_squared_eq [simp]:
   336      "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)"
   337 by (auto simp add: zero_le_mult_iff simp del: realpow_Suc)
   338 
   339 lemma real_sqrt_abs [simp]: "sqrt(x\<twosuperior>) = \<bar>x\<bar>"
   340 apply (rule abs_realpow_two [THEN subst])
   341 apply (rule real_sqrt_abs_abs [THEN subst])
   342 apply (subst real_pow_sqrt_eq_sqrt_pow)
   343 apply (auto simp add: numeral_2_eq_2)
   344 done
   345 
   346 lemma real_sqrt_abs2 [simp]: "sqrt(x*x) = \<bar>x\<bar>"
   347 apply (rule realpow_two [THEN subst])
   348 apply (subst numeral_2_eq_2 [symmetric])
   349 apply (rule real_sqrt_abs)
   350 done
   351 
   352 lemma real_sqrt_pow2_gt_zero: "0 < x ==> 0 < (sqrt x)\<twosuperior>"
   353 by simp
   354 
   355 lemma real_sqrt_not_eq_zero: "0 < x ==> sqrt x \<noteq> 0"
   356 apply (frule real_sqrt_pow2_gt_zero)
   357 apply (auto simp add: numeral_2_eq_2)
   358 done
   359 
   360 lemma real_inv_sqrt_pow2: "0 < x ==> inverse (sqrt(x)) ^ 2 = inverse x"
   361 by (cut_tac n = 2 and a = "sqrt x" in power_inverse [symmetric], auto)
   362 
   363 lemma real_sqrt_eq_zero_cancel: "[| 0 \<le> x; sqrt(x) = 0|] ==> x = 0"
   364 apply (drule real_le_imp_less_or_eq)
   365 apply (auto dest: real_sqrt_not_eq_zero)
   366 done
   367 
   368 lemma real_sqrt_eq_zero_cancel_iff [simp]: "0 \<le> x ==> ((sqrt x = 0) = (x=0))"
   369 by (auto simp add: real_sqrt_eq_zero_cancel)
   370 
   371 lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
   372 apply (subgoal_tac "x \<le> 0 | 0 \<le> x", safe)
   373 apply (rule real_le_trans)
   374 apply (auto simp del: realpow_Suc)
   375 apply (rule_tac n = 1 in realpow_increasing)
   376 apply (auto simp add: numeral_2_eq_2 [symmetric] simp del: realpow_Suc)
   377 done
   378 
   379 lemma real_sqrt_sum_squares_ge2 [simp]: "y \<le> sqrt(z\<twosuperior> + y\<twosuperior>)"
   380 apply (simp (no_asm) add: real_add_commute del: realpow_Suc)
   381 done
   382 
   383 lemma real_sqrt_ge_one: "1 \<le> x ==> 1 \<le> sqrt x"
   384 apply (rule_tac n = 1 in realpow_increasing)
   385 apply (auto simp add: numeral_2_eq_2 [symmetric] real_sqrt_ge_zero simp 
   386             del: realpow_Suc)
   387 done
   388 
   389 lemma sqrt_divide_self_eq:
   390   assumes nneg: "0 \<le> x"
   391   shows "sqrt x / x = inverse (sqrt x)"
   392 proof cases
   393   assume "x=0" thus ?thesis by simp
   394 next
   395   assume nz: "x\<noteq>0" 
   396   hence pos: "0<x" using nneg by arith
   397   show ?thesis
   398   proof (rule right_inverse_eq [THEN iffD1, THEN sym]) 
   399     show "sqrt x / x \<noteq> 0" by (simp add: divide_inverse nneg nz) 
   400     show "inverse (sqrt x) / (sqrt x / x) = 1"
   401       by (simp add: divide_inverse mult_assoc [symmetric] 
   402                   power2_eq_square [symmetric] real_inv_sqrt_pow2 pos nz) 
   403   qed
   404 qed
   405 
   406 end