src/HOL/Hyperreal/NthRoot.thy
author nipkow
Sat Jun 23 19:33:22 2007 +0200 (2007-06-23)
changeset 23477 f4b83f03cac9
parent 23475 c869b52a9077
child 25602 137ebc0603f4
permissions -rw-r--r--
tuned and renamed group_eq_simps and ring_eq_simps
     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 {* Nth Roots of Real Numbers *}
     8 
     9 theory NthRoot
    10 imports SEQ Parity Deriv
    11 begin
    12 
    13 subsection {* Existence of Nth Root *}
    14 
    15 text {* Existence follows from the Intermediate Value Theorem *}
    16 
    17 lemma realpow_pos_nth:
    18   assumes n: "0 < n"
    19   assumes a: "0 < a"
    20   shows "\<exists>r>0. r ^ n = (a::real)"
    21 proof -
    22   have "\<exists>r\<ge>0. r \<le> (max 1 a) \<and> r ^ n = a"
    23   proof (rule IVT)
    24     show "0 ^ n \<le> a" using n a by (simp add: power_0_left)
    25     show "0 \<le> max 1 a" by simp
    26     from n have n1: "1 \<le> n" by simp
    27     have "a \<le> max 1 a ^ 1" by simp
    28     also have "max 1 a ^ 1 \<le> max 1 a ^ n"
    29       using n1 by (rule power_increasing, simp)
    30     finally show "a \<le> max 1 a ^ n" .
    31     show "\<forall>r. 0 \<le> r \<and> r \<le> max 1 a \<longrightarrow> isCont (\<lambda>x. x ^ n) r"
    32       by (simp add: isCont_power)
    33   qed
    34   then obtain r where r: "0 \<le> r \<and> r ^ n = a" by fast
    35   with n a have "r \<noteq> 0" by (auto simp add: power_0_left)
    36   with r have "0 < r \<and> r ^ n = a" by simp
    37   thus ?thesis ..
    38 qed
    39 
    40 (* Used by Integration/RealRandVar.thy in AFP *)
    41 lemma realpow_pos_nth2: "(0::real) < a \<Longrightarrow> \<exists>r>0. r ^ Suc n = a"
    42 by (blast intro: realpow_pos_nth)
    43 
    44 text {* Uniqueness of nth positive root *}
    45 
    46 lemma realpow_pos_nth_unique:
    47   "\<lbrakk>0 < n; 0 < a\<rbrakk> \<Longrightarrow> \<exists>!r. 0 < r \<and> r ^ n = (a::real)"
    48 apply (auto intro!: realpow_pos_nth)
    49 apply (rule_tac n=n in power_eq_imp_eq_base, simp_all)
    50 done
    51 
    52 subsection {* Nth Root *}
    53 
    54 text {* We define roots of negative reals such that
    55   @{term "root n (- x) = - root n x"}. This allows
    56   us to omit side conditions from many theorems. *}
    57 
    58 definition
    59   root :: "[nat, real] \<Rightarrow> real" where
    60   "root n x = (if 0 < x then (THE u. 0 < u \<and> u ^ n = x) else
    61                if x < 0 then - (THE u. 0 < u \<and> u ^ n = - x) else 0)"
    62 
    63 lemma real_root_zero [simp]: "root n 0 = 0"
    64 unfolding root_def by simp
    65 
    66 lemma real_root_minus: "0 < n \<Longrightarrow> root n (- x) = - root n x"
    67 unfolding root_def by simp
    68 
    69 lemma real_root_gt_zero: "\<lbrakk>0 < n; 0 < x\<rbrakk> \<Longrightarrow> 0 < root n x"
    70 apply (simp add: root_def)
    71 apply (drule (1) realpow_pos_nth_unique)
    72 apply (erule theI' [THEN conjunct1])
    73 done
    74 
    75 lemma real_root_pow_pos: (* TODO: rename *)
    76   "\<lbrakk>0 < n; 0 < x\<rbrakk> \<Longrightarrow> root n x ^ n = x"
    77 apply (simp add: root_def)
    78 apply (drule (1) realpow_pos_nth_unique)
    79 apply (erule theI' [THEN conjunct2])
    80 done
    81 
    82 lemma real_root_pow_pos2 [simp]: (* TODO: rename *)
    83   "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> root n x ^ n = x"
    84 by (auto simp add: order_le_less real_root_pow_pos)
    85 
    86 lemma odd_pos: "odd (n::nat) \<Longrightarrow> 0 < n"
    87 by (cases n, simp_all)
    88 
    89 lemma odd_real_root_pow: "odd n \<Longrightarrow> root n x ^ n = x"
    90 apply (rule_tac x=0 and y=x in linorder_le_cases)
    91 apply (erule (1) real_root_pow_pos2 [OF odd_pos])
    92 apply (subgoal_tac "root n (- x) ^ n = - x")
    93 apply (simp add: real_root_minus odd_pos)
    94 apply (simp add: odd_pos)
    95 done
    96 
    97 lemma real_root_ge_zero: "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> 0 \<le> root n x"
    98 by (auto simp add: order_le_less real_root_gt_zero)
    99 
   100 lemma real_root_power_cancel: "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> root n (x ^ n) = x"
   101 apply (subgoal_tac "0 \<le> x ^ n")
   102 apply (subgoal_tac "0 \<le> root n (x ^ n)")
   103 apply (subgoal_tac "root n (x ^ n) ^ n = x ^ n")
   104 apply (erule (3) power_eq_imp_eq_base)
   105 apply (erule (1) real_root_pow_pos2)
   106 apply (erule (1) real_root_ge_zero)
   107 apply (erule zero_le_power)
   108 done
   109 
   110 lemma odd_real_root_power_cancel: "odd n \<Longrightarrow> root n (x ^ n) = x"
   111 apply (rule_tac x=0 and y=x in linorder_le_cases)
   112 apply (erule (1) real_root_power_cancel [OF odd_pos])
   113 apply (subgoal_tac "root n ((- x) ^ n) = - x")
   114 apply (simp add: real_root_minus odd_pos)
   115 apply (erule real_root_power_cancel [OF odd_pos], simp)
   116 done
   117 
   118 lemma real_root_pos_unique:
   119   "\<lbrakk>0 < n; 0 \<le> y; y ^ n = x\<rbrakk> \<Longrightarrow> root n x = y"
   120 by (erule subst, rule real_root_power_cancel)
   121 
   122 lemma odd_real_root_unique:
   123   "\<lbrakk>odd n; y ^ n = x\<rbrakk> \<Longrightarrow> root n x = y"
   124 by (erule subst, rule odd_real_root_power_cancel)
   125 
   126 lemma real_root_one [simp]: "0 < n \<Longrightarrow> root n 1 = 1"
   127 by (simp add: real_root_pos_unique)
   128 
   129 text {* Root function is strictly monotonic, hence injective *}
   130 
   131 lemma real_root_less_mono_lemma:
   132   "\<lbrakk>0 < n; 0 \<le> x; x < y\<rbrakk> \<Longrightarrow> root n x < root n y"
   133 apply (subgoal_tac "0 \<le> y")
   134 apply (subgoal_tac "root n x ^ n < root n y ^ n")
   135 apply (erule power_less_imp_less_base)
   136 apply (erule (1) real_root_ge_zero)
   137 apply simp
   138 apply simp
   139 done
   140 
   141 lemma real_root_less_mono: "\<lbrakk>0 < n; x < y\<rbrakk> \<Longrightarrow> root n x < root n y"
   142 apply (cases "0 \<le> x")
   143 apply (erule (2) real_root_less_mono_lemma)
   144 apply (cases "0 \<le> y")
   145 apply (rule_tac y=0 in order_less_le_trans)
   146 apply (subgoal_tac "0 < root n (- x)")
   147 apply (simp add: real_root_minus)
   148 apply (simp add: real_root_gt_zero)
   149 apply (simp add: real_root_ge_zero)
   150 apply (subgoal_tac "root n (- y) < root n (- x)")
   151 apply (simp add: real_root_minus)
   152 apply (simp add: real_root_less_mono_lemma)
   153 done
   154 
   155 lemma real_root_le_mono: "\<lbrakk>0 < n; x \<le> y\<rbrakk> \<Longrightarrow> root n x \<le> root n y"
   156 by (auto simp add: order_le_less real_root_less_mono)
   157 
   158 lemma real_root_less_iff [simp]:
   159   "0 < n \<Longrightarrow> (root n x < root n y) = (x < y)"
   160 apply (cases "x < y")
   161 apply (simp add: real_root_less_mono)
   162 apply (simp add: linorder_not_less real_root_le_mono)
   163 done
   164 
   165 lemma real_root_le_iff [simp]:
   166   "0 < n \<Longrightarrow> (root n x \<le> root n y) = (x \<le> y)"
   167 apply (cases "x \<le> y")
   168 apply (simp add: real_root_le_mono)
   169 apply (simp add: linorder_not_le real_root_less_mono)
   170 done
   171 
   172 lemma real_root_eq_iff [simp]:
   173   "0 < n \<Longrightarrow> (root n x = root n y) = (x = y)"
   174 by (simp add: order_eq_iff)
   175 
   176 lemmas real_root_gt_0_iff [simp] = real_root_less_iff [where x=0, simplified]
   177 lemmas real_root_lt_0_iff [simp] = real_root_less_iff [where y=0, simplified]
   178 lemmas real_root_ge_0_iff [simp] = real_root_le_iff [where x=0, simplified]
   179 lemmas real_root_le_0_iff [simp] = real_root_le_iff [where y=0, simplified]
   180 lemmas real_root_eq_0_iff [simp] = real_root_eq_iff [where y=0, simplified]
   181 
   182 lemma real_root_gt_1_iff [simp]: "0 < n \<Longrightarrow> (1 < root n y) = (1 < y)"
   183 by (insert real_root_less_iff [where x=1], simp)
   184 
   185 lemma real_root_lt_1_iff [simp]: "0 < n \<Longrightarrow> (root n x < 1) = (x < 1)"
   186 by (insert real_root_less_iff [where y=1], simp)
   187 
   188 lemma real_root_ge_1_iff [simp]: "0 < n \<Longrightarrow> (1 \<le> root n y) = (1 \<le> y)"
   189 by (insert real_root_le_iff [where x=1], simp)
   190 
   191 lemma real_root_le_1_iff [simp]: "0 < n \<Longrightarrow> (root n x \<le> 1) = (x \<le> 1)"
   192 by (insert real_root_le_iff [where y=1], simp)
   193 
   194 lemma real_root_eq_1_iff [simp]: "0 < n \<Longrightarrow> (root n x = 1) = (x = 1)"
   195 by (insert real_root_eq_iff [where y=1], simp)
   196 
   197 text {* Roots of roots *}
   198 
   199 lemma real_root_Suc_0 [simp]: "root (Suc 0) x = x"
   200 by (simp add: odd_real_root_unique)
   201 
   202 lemma real_root_pos_mult_exp:
   203   "\<lbrakk>0 < m; 0 < n; 0 < x\<rbrakk> \<Longrightarrow> root (m * n) x = root m (root n x)"
   204 by (rule real_root_pos_unique, simp_all add: power_mult)
   205 
   206 lemma real_root_mult_exp:
   207   "\<lbrakk>0 < m; 0 < n\<rbrakk> \<Longrightarrow> root (m * n) x = root m (root n x)"
   208 apply (rule linorder_cases [where x=x and y=0])
   209 apply (subgoal_tac "root (m * n) (- x) = root m (root n (- x))")
   210 apply (simp add: real_root_minus)
   211 apply (simp_all add: real_root_pos_mult_exp)
   212 done
   213 
   214 lemma real_root_commute:
   215   "\<lbrakk>0 < m; 0 < n\<rbrakk> \<Longrightarrow> root m (root n x) = root n (root m x)"
   216 by (simp add: real_root_mult_exp [symmetric] mult_commute)
   217 
   218 text {* Monotonicity in first argument *}
   219 
   220 lemma real_root_strict_decreasing:
   221   "\<lbrakk>0 < n; n < N; 1 < x\<rbrakk> \<Longrightarrow> root N x < root n x"
   222 apply (subgoal_tac "root n (root N x) ^ n < root N (root n x) ^ N", simp)
   223 apply (simp add: real_root_commute power_strict_increasing
   224             del: real_root_pow_pos2)
   225 done
   226 
   227 lemma real_root_strict_increasing:
   228   "\<lbrakk>0 < n; n < N; 0 < x; x < 1\<rbrakk> \<Longrightarrow> root n x < root N x"
   229 apply (subgoal_tac "root N (root n x) ^ N < root n (root N x) ^ n", simp)
   230 apply (simp add: real_root_commute power_strict_decreasing
   231             del: real_root_pow_pos2)
   232 done
   233 
   234 lemma real_root_decreasing:
   235   "\<lbrakk>0 < n; n < N; 1 \<le> x\<rbrakk> \<Longrightarrow> root N x \<le> root n x"
   236 by (auto simp add: order_le_less real_root_strict_decreasing)
   237 
   238 lemma real_root_increasing:
   239   "\<lbrakk>0 < n; n < N; 0 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> root n x \<le> root N x"
   240 by (auto simp add: order_le_less real_root_strict_increasing)
   241 
   242 text {* Roots of multiplication and division *}
   243 
   244 lemma real_root_mult_lemma:
   245   "\<lbrakk>0 < n; 0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> root n (x * y) = root n x * root n y"
   246 by (simp add: real_root_pos_unique mult_nonneg_nonneg power_mult_distrib)
   247 
   248 lemma real_root_inverse_lemma:
   249   "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> root n (inverse x) = inverse (root n x)"
   250 by (simp add: real_root_pos_unique power_inverse [symmetric])
   251 
   252 lemma real_root_mult:
   253   assumes n: "0 < n"
   254   shows "root n (x * y) = root n x * root n y"
   255 proof (rule linorder_le_cases, rule_tac [!] linorder_le_cases)
   256   assume "0 \<le> x" and "0 \<le> y"
   257   thus ?thesis by (rule real_root_mult_lemma [OF n])
   258 next
   259   assume "0 \<le> x" and "y \<le> 0"
   260   hence "0 \<le> x" and "0 \<le> - y" by simp_all
   261   hence "root n (x * - y) = root n x * root n (- y)"
   262     by (rule real_root_mult_lemma [OF n])
   263   thus ?thesis by (simp add: real_root_minus [OF n])
   264 next
   265   assume "x \<le> 0" and "0 \<le> y"
   266   hence "0 \<le> - x" and "0 \<le> y" by simp_all
   267   hence "root n (- x * y) = root n (- x) * root n y"
   268     by (rule real_root_mult_lemma [OF n])
   269   thus ?thesis by (simp add: real_root_minus [OF n])
   270 next
   271   assume "x \<le> 0" and "y \<le> 0"
   272   hence "0 \<le> - x" and "0 \<le> - y" by simp_all
   273   hence "root n (- x * - y) = root n (- x) * root n (- y)"
   274     by (rule real_root_mult_lemma [OF n])
   275   thus ?thesis by (simp add: real_root_minus [OF n])
   276 qed
   277 
   278 lemma real_root_inverse:
   279   assumes n: "0 < n"
   280   shows "root n (inverse x) = inverse (root n x)"
   281 proof (rule linorder_le_cases)
   282   assume "0 \<le> x"
   283   thus ?thesis by (rule real_root_inverse_lemma [OF n])
   284 next
   285   assume "x \<le> 0"
   286   hence "0 \<le> - x" by simp
   287   hence "root n (inverse (- x)) = inverse (root n (- x))"
   288     by (rule real_root_inverse_lemma [OF n])
   289   thus ?thesis by (simp add: real_root_minus [OF n])
   290 qed
   291 
   292 lemma real_root_divide:
   293   "0 < n \<Longrightarrow> root n (x / y) = root n x / root n y"
   294 by (simp add: divide_inverse real_root_mult real_root_inverse)
   295 
   296 lemma real_root_power:
   297   "0 < n \<Longrightarrow> root n (x ^ k) = root n x ^ k"
   298 by (induct k, simp_all add: real_root_mult)
   299 
   300 lemma real_root_abs: "0 < n \<Longrightarrow> root n \<bar>x\<bar> = \<bar>root n x\<bar>"
   301 by (simp add: abs_if real_root_minus)
   302 
   303 text {* Continuity and derivatives *}
   304 
   305 lemma isCont_root_pos:
   306   assumes n: "0 < n"
   307   assumes x: "0 < x"
   308   shows "isCont (root n) x"
   309 proof -
   310   have "isCont (root n) (root n x ^ n)"
   311   proof (rule isCont_inverse_function [where f="\<lambda>a. a ^ n"])
   312     show "0 < root n x" using n x by simp
   313     show "\<forall>z. \<bar>z - root n x\<bar> \<le> root n x \<longrightarrow> root n (z ^ n) = z"
   314       by (simp add: abs_le_iff real_root_power_cancel n)
   315     show "\<forall>z. \<bar>z - root n x\<bar> \<le> root n x \<longrightarrow> isCont (\<lambda>a. a ^ n) z"
   316       by (simp add: isCont_power)
   317   qed
   318   thus ?thesis using n x by simp
   319 qed
   320 
   321 lemma isCont_root_neg:
   322   "\<lbrakk>0 < n; x < 0\<rbrakk> \<Longrightarrow> isCont (root n) x"
   323 apply (subgoal_tac "isCont (\<lambda>x. - root n (- x)) x")
   324 apply (simp add: real_root_minus)
   325 apply (rule isCont_o2 [OF isCont_minus [OF isCont_ident]])
   326 apply (simp add: isCont_minus isCont_root_pos)
   327 done
   328 
   329 lemma isCont_root_zero:
   330   "0 < n \<Longrightarrow> isCont (root n) 0"
   331 unfolding isCont_def
   332 apply (rule LIM_I)
   333 apply (rule_tac x="r ^ n" in exI, safe)
   334 apply (simp add: zero_less_power)
   335 apply (simp add: real_root_abs [symmetric])
   336 apply (rule_tac n="n" in power_less_imp_less_base, simp_all)
   337 done
   338 
   339 lemma isCont_real_root: "0 < n \<Longrightarrow> isCont (root n) x"
   340 apply (rule_tac x=x and y=0 in linorder_cases)
   341 apply (simp_all add: isCont_root_pos isCont_root_neg isCont_root_zero)
   342 done
   343 
   344 lemma DERIV_real_root:
   345   assumes n: "0 < n"
   346   assumes x: "0 < x"
   347   shows "DERIV (root n) x :> inverse (real n * root n x ^ (n - Suc 0))"
   348 proof (rule DERIV_inverse_function)
   349   show "0 < x" using x .
   350   show "x < x + 1" by simp
   351   show "\<forall>y. 0 < y \<and> y < x + 1 \<longrightarrow> root n y ^ n = y"
   352     using n by simp
   353   show "DERIV (\<lambda>x. x ^ n) (root n x) :> real n * root n x ^ (n - Suc 0)"
   354     by (rule DERIV_pow)
   355   show "real n * root n x ^ (n - Suc 0) \<noteq> 0"
   356     using n x by simp
   357   show "isCont (root n) x"
   358     using n by (rule isCont_real_root)
   359 qed
   360 
   361 lemma DERIV_odd_real_root:
   362   assumes n: "odd n"
   363   assumes x: "x \<noteq> 0"
   364   shows "DERIV (root n) x :> inverse (real n * root n x ^ (n - Suc 0))"
   365 proof (rule DERIV_inverse_function)
   366   show "x - 1 < x" by simp
   367   show "x < x + 1" by simp
   368   show "\<forall>y. x - 1 < y \<and> y < x + 1 \<longrightarrow> root n y ^ n = y"
   369     using n by (simp add: odd_real_root_pow)
   370   show "DERIV (\<lambda>x. x ^ n) (root n x) :> real n * root n x ^ (n - Suc 0)"
   371     by (rule DERIV_pow)
   372   show "real n * root n x ^ (n - Suc 0) \<noteq> 0"
   373     using odd_pos [OF n] x by simp
   374   show "isCont (root n) x"
   375     using odd_pos [OF n] by (rule isCont_real_root)
   376 qed
   377 
   378 subsection {* Square Root *}
   379 
   380 definition
   381   sqrt :: "real \<Rightarrow> real" where
   382   "sqrt = root 2"
   383 
   384 lemma pos2: "0 < (2::nat)" by simp
   385 
   386 lemma real_sqrt_unique: "\<lbrakk>y\<twosuperior> = x; 0 \<le> y\<rbrakk> \<Longrightarrow> sqrt x = y"
   387 unfolding sqrt_def by (rule real_root_pos_unique [OF pos2])
   388 
   389 lemma real_sqrt_abs [simp]: "sqrt (x\<twosuperior>) = \<bar>x\<bar>"
   390 apply (rule real_sqrt_unique)
   391 apply (rule power2_abs)
   392 apply (rule abs_ge_zero)
   393 done
   394 
   395 lemma real_sqrt_pow2 [simp]: "0 \<le> x \<Longrightarrow> (sqrt x)\<twosuperior> = x"
   396 unfolding sqrt_def by (rule real_root_pow_pos2 [OF pos2])
   397 
   398 lemma real_sqrt_pow2_iff [simp]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)"
   399 apply (rule iffI)
   400 apply (erule subst)
   401 apply (rule zero_le_power2)
   402 apply (erule real_sqrt_pow2)
   403 done
   404 
   405 lemma real_sqrt_zero [simp]: "sqrt 0 = 0"
   406 unfolding sqrt_def by (rule real_root_zero)
   407 
   408 lemma real_sqrt_one [simp]: "sqrt 1 = 1"
   409 unfolding sqrt_def by (rule real_root_one [OF pos2])
   410 
   411 lemma real_sqrt_minus: "sqrt (- x) = - sqrt x"
   412 unfolding sqrt_def by (rule real_root_minus [OF pos2])
   413 
   414 lemma real_sqrt_mult: "sqrt (x * y) = sqrt x * sqrt y"
   415 unfolding sqrt_def by (rule real_root_mult [OF pos2])
   416 
   417 lemma real_sqrt_inverse: "sqrt (inverse x) = inverse (sqrt x)"
   418 unfolding sqrt_def by (rule real_root_inverse [OF pos2])
   419 
   420 lemma real_sqrt_divide: "sqrt (x / y) = sqrt x / sqrt y"
   421 unfolding sqrt_def by (rule real_root_divide [OF pos2])
   422 
   423 lemma real_sqrt_power: "sqrt (x ^ k) = sqrt x ^ k"
   424 unfolding sqrt_def by (rule real_root_power [OF pos2])
   425 
   426 lemma real_sqrt_gt_zero: "0 < x \<Longrightarrow> 0 < sqrt x"
   427 unfolding sqrt_def by (rule real_root_gt_zero [OF pos2])
   428 
   429 lemma real_sqrt_ge_zero: "0 \<le> x \<Longrightarrow> 0 \<le> sqrt x"
   430 unfolding sqrt_def by (rule real_root_ge_zero [OF pos2])
   431 
   432 lemma real_sqrt_less_mono: "x < y \<Longrightarrow> sqrt x < sqrt y"
   433 unfolding sqrt_def by (rule real_root_less_mono [OF pos2])
   434 
   435 lemma real_sqrt_le_mono: "x \<le> y \<Longrightarrow> sqrt x \<le> sqrt y"
   436 unfolding sqrt_def by (rule real_root_le_mono [OF pos2])
   437 
   438 lemma real_sqrt_less_iff [simp]: "(sqrt x < sqrt y) = (x < y)"
   439 unfolding sqrt_def by (rule real_root_less_iff [OF pos2])
   440 
   441 lemma real_sqrt_le_iff [simp]: "(sqrt x \<le> sqrt y) = (x \<le> y)"
   442 unfolding sqrt_def by (rule real_root_le_iff [OF pos2])
   443 
   444 lemma real_sqrt_eq_iff [simp]: "(sqrt x = sqrt y) = (x = y)"
   445 unfolding sqrt_def by (rule real_root_eq_iff [OF pos2])
   446 
   447 lemmas real_sqrt_gt_0_iff [simp] = real_sqrt_less_iff [where x=0, simplified]
   448 lemmas real_sqrt_lt_0_iff [simp] = real_sqrt_less_iff [where y=0, simplified]
   449 lemmas real_sqrt_ge_0_iff [simp] = real_sqrt_le_iff [where x=0, simplified]
   450 lemmas real_sqrt_le_0_iff [simp] = real_sqrt_le_iff [where y=0, simplified]
   451 lemmas real_sqrt_eq_0_iff [simp] = real_sqrt_eq_iff [where y=0, simplified]
   452 
   453 lemmas real_sqrt_gt_1_iff [simp] = real_sqrt_less_iff [where x=1, simplified]
   454 lemmas real_sqrt_lt_1_iff [simp] = real_sqrt_less_iff [where y=1, simplified]
   455 lemmas real_sqrt_ge_1_iff [simp] = real_sqrt_le_iff [where x=1, simplified]
   456 lemmas real_sqrt_le_1_iff [simp] = real_sqrt_le_iff [where y=1, simplified]
   457 lemmas real_sqrt_eq_1_iff [simp] = real_sqrt_eq_iff [where y=1, simplified]
   458 
   459 lemma isCont_real_sqrt: "isCont sqrt x"
   460 unfolding sqrt_def by (rule isCont_real_root [OF pos2])
   461 
   462 lemma DERIV_real_sqrt:
   463   "0 < x \<Longrightarrow> DERIV sqrt x :> inverse (sqrt x) / 2"
   464 unfolding sqrt_def by (rule DERIV_real_root [OF pos2, simplified])
   465 
   466 lemma not_real_square_gt_zero [simp]: "(~ (0::real) < x*x) = (x = 0)"
   467 apply auto
   468 apply (cut_tac x = x and y = 0 in linorder_less_linear)
   469 apply (simp add: zero_less_mult_iff)
   470 done
   471 
   472 lemma real_sqrt_abs2 [simp]: "sqrt(x*x) = \<bar>x\<bar>"
   473 apply (subst power2_eq_square [symmetric])
   474 apply (rule real_sqrt_abs)
   475 done
   476 
   477 lemma real_sqrt_pow2_gt_zero: "0 < x ==> 0 < (sqrt x)\<twosuperior>"
   478 by simp (* TODO: delete *)
   479 
   480 lemma real_sqrt_not_eq_zero: "0 < x ==> sqrt x \<noteq> 0"
   481 by simp (* TODO: delete *)
   482 
   483 lemma real_inv_sqrt_pow2: "0 < x ==> inverse (sqrt(x)) ^ 2 = inverse x"
   484 by (simp add: power_inverse [symmetric])
   485 
   486 lemma real_sqrt_eq_zero_cancel: "[| 0 \<le> x; sqrt(x) = 0|] ==> x = 0"
   487 by simp
   488 
   489 lemma real_sqrt_ge_one: "1 \<le> x ==> 1 \<le> sqrt x"
   490 by simp
   491 
   492 lemma real_sqrt_two_gt_zero [simp]: "0 < sqrt 2"
   493 by simp
   494 
   495 lemma real_sqrt_two_ge_zero [simp]: "0 \<le> sqrt 2"
   496 by simp
   497 
   498 lemma real_sqrt_two_gt_one [simp]: "1 < sqrt 2"
   499 by simp
   500 
   501 lemma sqrt_divide_self_eq:
   502   assumes nneg: "0 \<le> x"
   503   shows "sqrt x / x = inverse (sqrt x)"
   504 proof cases
   505   assume "x=0" thus ?thesis by simp
   506 next
   507   assume nz: "x\<noteq>0" 
   508   hence pos: "0<x" using nneg by arith
   509   show ?thesis
   510   proof (rule right_inverse_eq [THEN iffD1, THEN sym]) 
   511     show "sqrt x / x \<noteq> 0" by (simp add: divide_inverse nneg nz) 
   512     show "inverse (sqrt x) / (sqrt x / x) = 1"
   513       by (simp add: divide_inverse mult_assoc [symmetric] 
   514                   power2_eq_square [symmetric] real_inv_sqrt_pow2 pos nz) 
   515   qed
   516 qed
   517 
   518 lemma real_divide_square_eq [simp]: "(((r::real) * a) / (r * r)) = a / r"
   519 apply (simp add: divide_inverse)
   520 apply (case_tac "r=0")
   521 apply (auto simp add: mult_ac)
   522 done
   523 
   524 lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u"
   525 by (simp add: divide_less_eq mult_compare_simps)
   526 
   527 lemma four_x_squared: 
   528   fixes x::real
   529   shows "4 * x\<twosuperior> = (2 * x)\<twosuperior>"
   530 by (simp add: power2_eq_square)
   531 
   532 subsection {* Square Root of Sum of Squares *}
   533 
   534 lemma real_sqrt_mult_self_sum_ge_zero [simp]: "0 \<le> sqrt(x*x + y*y)"
   535 by (rule real_sqrt_ge_zero [OF sum_squares_ge_zero])
   536 
   537 lemma real_sqrt_sum_squares_ge_zero [simp]: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   538 by simp
   539 
   540 declare real_sqrt_sum_squares_ge_zero [THEN abs_of_nonneg, simp]
   541 
   542 lemma real_sqrt_sum_squares_mult_ge_zero [simp]:
   543      "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))"
   544 by (auto intro!: real_sqrt_ge_zero simp add: zero_le_mult_iff)
   545 
   546 lemma real_sqrt_sum_squares_mult_squared_eq [simp]:
   547      "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)"
   548 by (auto simp add: zero_le_mult_iff)
   549 
   550 lemma real_sqrt_sum_squares_eq_cancel: "sqrt (x\<twosuperior> + y\<twosuperior>) = x \<Longrightarrow> y = 0"
   551 by (drule_tac f = "%x. x\<twosuperior>" in arg_cong, simp)
   552 
   553 lemma real_sqrt_sum_squares_eq_cancel2: "sqrt (x\<twosuperior> + y\<twosuperior>) = y \<Longrightarrow> x = 0"
   554 by (drule_tac f = "%x. x\<twosuperior>" in arg_cong, simp)
   555 
   556 lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   557 by (rule power2_le_imp_le, simp_all)
   558 
   559 lemma real_sqrt_sum_squares_ge2 [simp]: "y \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   560 by (rule power2_le_imp_le, simp_all)
   561 
   562 lemma real_sqrt_ge_abs1 [simp]: "\<bar>x\<bar> \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   563 by (rule power2_le_imp_le, simp_all)
   564 
   565 lemma real_sqrt_ge_abs2 [simp]: "\<bar>y\<bar> \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   566 by (rule power2_le_imp_le, simp_all)
   567 
   568 lemma le_real_sqrt_sumsq [simp]: "x \<le> sqrt (x * x + y * y)"
   569 by (simp add: power2_eq_square [symmetric])
   570 
   571 lemma power2_sum:
   572   fixes x y :: "'a::{number_ring,recpower}"
   573   shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y"
   574 by (simp add: ring_distribs power2_eq_square)
   575 
   576 lemma power2_diff:
   577   fixes x y :: "'a::{number_ring,recpower}"
   578   shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y"
   579 by (simp add: ring_distribs power2_eq_square)
   580 
   581 lemma real_sqrt_sum_squares_triangle_ineq:
   582   "sqrt ((a + c)\<twosuperior> + (b + d)\<twosuperior>) \<le> sqrt (a\<twosuperior> + b\<twosuperior>) + sqrt (c\<twosuperior> + d\<twosuperior>)"
   583 apply (rule power2_le_imp_le, simp)
   584 apply (simp add: power2_sum)
   585 apply (simp only: mult_assoc right_distrib [symmetric])
   586 apply (rule mult_left_mono)
   587 apply (rule power2_le_imp_le)
   588 apply (simp add: power2_sum power_mult_distrib)
   589 apply (simp add: ring_distribs)
   590 apply (subgoal_tac "0 \<le> b\<twosuperior> * c\<twosuperior> + a\<twosuperior> * d\<twosuperior> - 2 * (a * c) * (b * d)", simp)
   591 apply (rule_tac b="(a * d - b * c)\<twosuperior>" in ord_le_eq_trans)
   592 apply (rule zero_le_power2)
   593 apply (simp add: power2_diff power_mult_distrib)
   594 apply (simp add: mult_nonneg_nonneg)
   595 apply simp
   596 apply (simp add: add_increasing)
   597 done
   598 
   599 lemma real_sqrt_sum_squares_less:
   600   "\<lbrakk>\<bar>x\<bar> < u / sqrt 2; \<bar>y\<bar> < u / sqrt 2\<rbrakk> \<Longrightarrow> sqrt (x\<twosuperior> + y\<twosuperior>) < u"
   601 apply (rule power2_less_imp_less, simp)
   602 apply (drule power_strict_mono [OF _ abs_ge_zero pos2])
   603 apply (drule power_strict_mono [OF _ abs_ge_zero pos2])
   604 apply (simp add: power_divide)
   605 apply (drule order_le_less_trans [OF abs_ge_zero])
   606 apply (simp add: zero_less_divide_iff)
   607 done
   608 
   609 text{*Needed for the infinitely close relation over the nonstandard
   610     complex numbers*}
   611 lemma lemma_sqrt_hcomplex_capprox:
   612      "[| 0 < u; x < u/2; y < u/2; 0 \<le> x; 0 \<le> y |] ==> sqrt (x\<twosuperior> + y\<twosuperior>) < u"
   613 apply (rule_tac y = "u/sqrt 2" in order_le_less_trans)
   614 apply (erule_tac [2] lemma_real_divide_sqrt_less)
   615 apply (rule power2_le_imp_le)
   616 apply (auto simp add: real_0_le_divide_iff power_divide)
   617 apply (rule_tac t = "u\<twosuperior>" in real_sum_of_halves [THEN subst])
   618 apply (rule add_mono)
   619 apply (auto simp add: four_x_squared simp del: realpow_Suc intro: power_mono)
   620 done
   621 
   622 text "Legacy theorem names:"
   623 lemmas real_root_pos2 = real_root_power_cancel
   624 lemmas real_root_pos_pos = real_root_gt_zero [THEN order_less_imp_le]
   625 lemmas real_root_pos_pos_le = real_root_ge_zero
   626 lemmas real_sqrt_mult_distrib = real_sqrt_mult
   627 lemmas real_sqrt_mult_distrib2 = real_sqrt_mult
   628 lemmas real_sqrt_eq_zero_cancel_iff = real_sqrt_eq_0_iff
   629 
   630 (* needed for CauchysMeanTheorem.het_base from AFP *)
   631 lemma real_root_pos: "0 < x \<Longrightarrow> root (Suc n) (x ^ (Suc n)) = x"
   632 by (rule real_root_power_cancel [OF zero_less_Suc order_less_imp_le])
   633 
   634 end