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