src/HOL/Hyperreal/NthRoot.thy
 author huffman Tue Apr 17 00:55:00 2007 +0200 (2007-04-17) changeset 22721 d9be18bd7a28 parent 22630 2a9b64b26612 child 22856 eb0e0582092a permissions -rw-r--r--
moved root and sqrt lemmas from Transcendental.thy 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_of_nat_inverse_le_iff:
```
```   132   "(inverse (real(Suc n)) \<le> r) = (1 \<le> r * real(Suc n))"
```
```   133 by (simp add: inverse_eq_divide pos_divide_le_eq)
```
```   134
```
```   135 lemma real_mult_add_one_minus_ge_zero:
```
```   136      "0 < r ==>  0 <= r*(1 + -inverse(real (Suc n)))"
```
```   137 by (simp add: zero_le_mult_iff real_of_nat_inverse_le_iff real_0_le_add_iff)
```
```   138
```
```   139 lemma lemma_nth_realpow_isLub_le:
```
```   140      "[| isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u;
```
```   141        0 < a; 0 < n |] ==> ALL k. (u*(1 + -inverse(real (Suc k)))) ^ n <= a"
```
```   142 apply safe
```
```   143 apply (frule less_isLub_not_isUb [THEN not_isUb_less_ex])
```
```   144 apply (rule_tac n = k in real_mult_less_self)
```
```   145 apply (blast intro: lemma_nth_realpow_isLub_gt_zero, safe)
```
```   146 apply (drule_tac n = k in
```
```   147         lemma_nth_realpow_isLub_gt_zero [THEN real_mult_add_one_minus_ge_zero], assumption+)
```
```   148 apply (blast intro: order_trans order_less_imp_le power_mono)
```
```   149 done
```
```   150
```
```   151 text{*Second result we want*}
```
```   152 lemma realpow_nth_le:
```
```   153      "[| (0::real) < a; 0 < n;
```
```   154      isLub (UNIV::real set)
```
```   155      {x. x ^ n <= a & 0 < x} u |] ==> u ^ n <= a"
```
```   156 apply (frule lemma_nth_realpow_isLub_le, safe)
```
```   157 apply (rule LIMSEQ_inverse_real_of_nat_add_minus_mult
```
```   158                 [THEN LIMSEQ_pow, THEN LIMSEQ_le_const2])
```
```   159 apply (auto simp add: real_of_nat_def)
```
```   160 done
```
```   161
```
```   162 text{*The theorem at last!*}
```
```   163 lemma realpow_nth: "[| (0::real) < a; 0 < n |] ==> \<exists>r. r ^ n = a"
```
```   164 apply (frule nth_realpow_isLub_ex, auto)
```
```   165 apply (auto intro: realpow_nth_le realpow_nth_ge order_antisym)
```
```   166 done
```
```   167
```
```   168 (* positive only *)
```
```   169 lemma realpow_pos_nth: "[| (0::real) < a; 0 < n |] ==> \<exists>r. 0 < r & r ^ n = a"
```
```   170 apply (frule nth_realpow_isLub_ex, auto)
```
```   171 apply (auto intro: realpow_nth_le realpow_nth_ge order_antisym lemma_nth_realpow_isLub_gt_zero)
```
```   172 done
```
```   173
```
```   174 lemma realpow_pos_nth2: "(0::real) < a  ==> \<exists>r. 0 < r & r ^ Suc n = a"
```
```   175 by (blast intro: realpow_pos_nth)
```
```   176
```
```   177 (* uniqueness of nth positive root *)
```
```   178 lemma realpow_pos_nth_unique:
```
```   179      "[| (0::real) < a; 0 < n |] ==> EX! r. 0 < r & r ^ n = a"
```
```   180 apply (auto intro!: realpow_pos_nth)
```
```   181 apply (cut_tac x = r and y = y in linorder_less_linear, auto)
```
```   182 apply (drule_tac x = r in realpow_less)
```
```   183 apply (drule_tac [4] x = y in realpow_less, auto)
```
```   184 done
```
```   185
```
```   186 subsection {* Nth Root *}
```
```   187
```
```   188 lemma real_root_zero [simp]: "root (Suc n) 0 = 0"
```
```   189 apply (simp add: root_def)
```
```   190 apply (safe intro!: the_equality power_0_Suc elim!: realpow_zero_zero)
```
```   191 done
```
```   192
```
```   193 lemma real_root_pow_pos:
```
```   194      "0 < x ==> (root (Suc n) x) ^ (Suc n) = x"
```
```   195 apply (simp add: root_def del: realpow_Suc)
```
```   196 apply (drule_tac n="Suc n" in realpow_pos_nth_unique, simp)
```
```   197 apply (erule theI' [THEN conjunct2])
```
```   198 done
```
```   199
```
```   200 lemma real_root_pow_pos2: "0 \<le> x ==> (root (Suc n) x) ^ (Suc n) = x"
```
```   201 by (auto dest!: real_le_imp_less_or_eq dest: real_root_pow_pos)
```
```   202
```
```   203 lemma real_root_pos:
```
```   204      "0 < x ==> root(Suc n) (x ^ (Suc n)) = x"
```
```   205 apply (simp add: root_def)
```
```   206 apply (rule the_equality)
```
```   207 apply (frule_tac [2] n = n in zero_less_power)
```
```   208 apply (auto simp add: zero_less_mult_iff)
```
```   209 apply (rule_tac x = u and y = x in linorder_cases)
```
```   210 apply (drule_tac n1 = n and x = u in zero_less_Suc [THEN [3] realpow_less])
```
```   211 apply (drule_tac [4] n1 = n and x = x in zero_less_Suc [THEN [3] realpow_less])
```
```   212 apply (auto)
```
```   213 done
```
```   214
```
```   215 lemma real_root_pos2: "0 \<le> x ==> root(Suc n) (x ^ (Suc n)) = x"
```
```   216 by (auto dest!: real_le_imp_less_or_eq real_root_pos)
```
```   217
```
```   218 lemma real_root_gt_zero:
```
```   219      "0 < x ==> 0 < root (Suc n) x"
```
```   220 apply (simp add: root_def del: realpow_Suc)
```
```   221 apply (drule_tac n="Suc n" in realpow_pos_nth_unique, simp)
```
```   222 apply (erule theI' [THEN conjunct1])
```
```   223 done
```
```   224
```
```   225 lemma real_root_pos_pos:
```
```   226      "0 < x ==> 0 \<le> root(Suc n) x"
```
```   227 by (rule real_root_gt_zero [THEN order_less_imp_le])
```
```   228
```
```   229 lemma real_root_pos_pos_le: "0 \<le> x ==> 0 \<le> root(Suc n) x"
```
```   230 by (auto simp add: order_le_less real_root_gt_zero)
```
```   231
```
```   232 lemma real_root_one [simp]: "root (Suc n) 1 = 1"
```
```   233 apply (simp add: root_def)
```
```   234 apply (rule the_equality, auto)
```
```   235 apply (rule ccontr)
```
```   236 apply (rule_tac x = u and y = 1 in linorder_cases)
```
```   237 apply (drule_tac n = n in realpow_Suc_less_one)
```
```   238 apply (drule_tac [4] n = n in power_gt1_lemma)
```
```   239 apply (auto)
```
```   240 done
```
```   241
```
```   242 lemma real_root_less_mono:
```
```   243      "[| 0 \<le> x; x < y |] ==> root(Suc n) x < root(Suc n) y"
```
```   244 apply (frule order_le_less_trans, assumption)
```
```   245 apply (frule_tac n1 = n in real_root_pow_pos2 [THEN ssubst])
```
```   246 apply (rotate_tac 1, assumption)
```
```   247 apply (frule_tac n1 = n in real_root_pow_pos [THEN ssubst])
```
```   248 apply (rotate_tac 3, assumption)
```
```   249 apply (drule_tac y = "root (Suc n) y ^ Suc n" in order_less_imp_le)
```
```   250 apply (frule_tac n = n in real_root_pos_pos_le)
```
```   251 apply (frule_tac n = n in real_root_pos_pos)
```
```   252 apply (drule_tac x = "root (Suc n) x" and y = "root (Suc n) y" in realpow_increasing)
```
```   253 apply (assumption, assumption)
```
```   254 apply (drule_tac x = "root (Suc n) x" in order_le_imp_less_or_eq)
```
```   255 apply auto
```
```   256 apply (drule_tac f = "%x. x ^ (Suc n)" in arg_cong)
```
```   257 apply (auto simp add: real_root_pow_pos2 simp del: realpow_Suc)
```
```   258 done
```
```   259
```
```   260 lemma real_root_le_mono:
```
```   261      "[| 0 \<le> x; x \<le> y |] ==> root(Suc n) x \<le> root(Suc n) y"
```
```   262 apply (drule_tac y = y in order_le_imp_less_or_eq)
```
```   263 apply (auto dest: real_root_less_mono intro: order_less_imp_le)
```
```   264 done
```
```   265
```
```   266 lemma real_root_less_iff [simp]:
```
```   267      "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x < root(Suc n) y) = (x < y)"
```
```   268 apply (auto intro: real_root_less_mono)
```
```   269 apply (rule ccontr, drule linorder_not_less [THEN iffD1])
```
```   270 apply (drule_tac x = y and n = n in real_root_le_mono, auto)
```
```   271 done
```
```   272
```
```   273 lemma real_root_le_iff [simp]:
```
```   274      "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x \<le> root(Suc n) y) = (x \<le> y)"
```
```   275 apply (auto intro: real_root_le_mono)
```
```   276 apply (simp (no_asm) add: linorder_not_less [symmetric])
```
```   277 apply auto
```
```   278 apply (drule_tac x = y and n = n in real_root_less_mono, auto)
```
```   279 done
```
```   280
```
```   281 lemma real_root_eq_iff [simp]:
```
```   282      "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x = root(Suc n) y) = (x = y)"
```
```   283 apply (auto intro!: order_antisym [where 'a = real])
```
```   284 apply (rule_tac n1 = n in real_root_le_iff [THEN iffD1])
```
```   285 apply (rule_tac [4] n1 = n in real_root_le_iff [THEN iffD1], auto)
```
```   286 done
```
```   287
```
```   288 lemma real_root_pos_unique:
```
```   289      "[| 0 \<le> x; 0 \<le> y; y ^ (Suc n) = x |] ==> root (Suc n) x = y"
```
```   290 by (auto dest: real_root_pos2 simp del: realpow_Suc)
```
```   291
```
```   292 lemma real_root_mult:
```
```   293      "[| 0 \<le> x; 0 \<le> y |]
```
```   294       ==> root(Suc n) (x * y) = root(Suc n) x * root(Suc n) y"
```
```   295 apply (rule real_root_pos_unique)
```
```   296 apply (auto intro!: real_root_pos_pos_le
```
```   297             simp add: power_mult_distrib zero_le_mult_iff real_root_pow_pos2
```
```   298             simp del: realpow_Suc)
```
```   299 done
```
```   300
```
```   301 lemma real_root_inverse:
```
```   302      "0 \<le> x ==> (root(Suc n) (inverse x) = inverse(root(Suc n) x))"
```
```   303 apply (rule real_root_pos_unique)
```
```   304 apply (auto intro: real_root_pos_pos_le
```
```   305             simp add: power_inverse [symmetric] real_root_pow_pos2
```
```   306             simp del: realpow_Suc)
```
```   307 done
```
```   308
```
```   309 lemma real_root_divide:
```
```   310      "[| 0 \<le> x; 0 \<le> y |]
```
```   311       ==> (root(Suc n) (x / y) = root(Suc n) x / root(Suc n) y)"
```
```   312 apply (simp add: divide_inverse)
```
```   313 apply (auto simp add: real_root_mult real_root_inverse)
```
```   314 done
```
```   315
```
```   316
```
```   317 subsection{*Square Root*}
```
```   318
```
```   319 text{*needed because 2 is a binary numeral!*}
```
```   320 lemma root_2_eq [simp]: "root 2 = root (Suc (Suc 0))"
```
```   321 by (simp del: nat_numeral_0_eq_0 nat_numeral_1_eq_1
```
```   322          add: nat_numeral_0_eq_0 [symmetric])
```
```   323
```
```   324 lemma real_sqrt_zero [simp]: "sqrt 0 = 0"
```
```   325 by (simp add: sqrt_def)
```
```   326
```
```   327 lemma real_sqrt_one [simp]: "sqrt 1 = 1"
```
```   328 by (simp add: sqrt_def)
```
```   329
```
```   330 lemma real_sqrt_pow2_iff [iff]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)"
```
```   331 apply (simp add: sqrt_def)
```
```   332 apply (rule iffI)
```
```   333  apply (cut_tac r = "root 2 x" in realpow_two_le)
```
```   334  apply (simp add: numeral_2_eq_2)
```
```   335 apply (subst numeral_2_eq_2)
```
```   336 apply (erule real_root_pow_pos2)
```
```   337 done
```
```   338
```
```   339 lemma [simp]: "(sqrt(u2\<twosuperior> + v2\<twosuperior>))\<twosuperior> = u2\<twosuperior> + v2\<twosuperior>"
```
```   340 by (rule realpow_two_le_add_order [THEN real_sqrt_pow2_iff [THEN iffD2]])
```
```   341
```
```   342 lemma real_sqrt_pow2 [simp]: "0 \<le> x ==> (sqrt x)\<twosuperior> = x"
```
```   343 by (simp)
```
```   344
```
```   345 lemma real_sqrt_abs_abs [simp]: "sqrt\<bar>x\<bar> ^ 2 = \<bar>x\<bar>"
```
```   346 by (rule real_sqrt_pow2_iff [THEN iffD2], arith)
```
```   347
```
```   348 lemma real_pow_sqrt_eq_sqrt_pow:
```
```   349       "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(x\<twosuperior>)"
```
```   350 apply (simp add: sqrt_def)
```
```   351 apply (simp only: numeral_2_eq_2 real_root_pow_pos2 real_root_pos2)
```
```   352 done
```
```   353
```
```   354 lemma real_pow_sqrt_eq_sqrt_abs_pow2:
```
```   355      "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(\<bar>x\<bar> ^ 2)"
```
```   356 by (simp add: real_pow_sqrt_eq_sqrt_pow [symmetric])
```
```   357
```
```   358 lemma real_sqrt_pow_abs: "0 \<le> x ==> (sqrt x)\<twosuperior> = \<bar>x\<bar>"
```
```   359 apply (rule real_sqrt_abs_abs [THEN subst])
```
```   360 apply (rule_tac x1 = x in real_pow_sqrt_eq_sqrt_abs_pow2 [THEN ssubst])
```
```   361 apply (rule_tac [2] real_pow_sqrt_eq_sqrt_pow [symmetric])
```
```   362 apply (assumption, arith)
```
```   363 done
```
```   364
```
```   365 lemma not_real_square_gt_zero [simp]: "(~ (0::real) < x*x) = (x = 0)"
```
```   366 apply auto
```
```   367 apply (cut_tac x = x and y = 0 in linorder_less_linear)
```
```   368 apply (simp add: zero_less_mult_iff)
```
```   369 done
```
```   370
```
```   371 lemma real_sqrt_gt_zero: "0 < x ==> 0 < sqrt(x)"
```
```   372 by (simp add: sqrt_def real_root_gt_zero)
```
```   373
```
```   374 lemma real_sqrt_ge_zero: "0 \<le> x ==> 0 \<le> sqrt(x)"
```
```   375 by (auto intro: real_sqrt_gt_zero simp add: order_le_less)
```
```   376
```
```   377 lemma real_sqrt_mult_self_sum_ge_zero [simp]: "0 \<le> sqrt(x*x + y*y)"
```
```   378 by (rule real_sqrt_ge_zero [OF real_mult_self_sum_ge_zero])
```
```   379
```
```   380
```
```   381 (*we need to prove something like this:
```
```   382 lemma "[|r ^ n = a; 0<n; 0 < a \<longrightarrow> 0 < r|] ==> root n a = r"
```
```   383 apply (case_tac n, simp)
```
```   384 apply (simp add: root_def)
```
```   385 apply (rule someI2 [of _ r], safe)
```
```   386 apply (auto simp del: realpow_Suc dest: power_inject_base)
```
```   387 *)
```
```   388
```
```   389 lemma sqrt_eqI: "[|r\<twosuperior> = a; 0 \<le> r|] ==> sqrt a = r"
```
```   390 apply (erule subst)
```
```   391 apply (simp add: sqrt_def numeral_2_eq_2 del: realpow_Suc)
```
```   392 apply (erule real_root_pos2)
```
```   393 done
```
```   394
```
```   395 lemma real_sqrt_mult_distrib:
```
```   396      "[| 0 \<le> x; 0 \<le> y |] ==> sqrt(x*y) = sqrt(x) * sqrt(y)"
```
```   397 apply (rule sqrt_eqI)
```
```   398 apply (simp add: power_mult_distrib)
```
```   399 apply (simp add: zero_le_mult_iff real_sqrt_ge_zero)
```
```   400 done
```
```   401
```
```   402 lemma real_sqrt_mult_distrib2:
```
```   403      "[|0\<le>x; 0\<le>y |] ==> sqrt(x*y) =  sqrt(x) * sqrt(y)"
```
```   404 by (auto intro: real_sqrt_mult_distrib simp add: order_le_less)
```
```   405
```
```   406 lemma real_sqrt_sum_squares_ge_zero [simp]: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
```
```   407 by (auto intro!: real_sqrt_ge_zero)
```
```   408
```
```   409 lemma real_sqrt_sum_squares_mult_ge_zero [simp]:
```
```   410      "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))"
```
```   411 by (auto intro!: real_sqrt_ge_zero simp add: zero_le_mult_iff)
```
```   412
```
```   413 lemma real_sqrt_sum_squares_mult_squared_eq [simp]:
```
```   414      "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)"
```
```   415 by (auto simp add: zero_le_mult_iff simp del: realpow_Suc)
```
```   416
```
```   417 lemma real_sqrt_abs [simp]: "sqrt(x\<twosuperior>) = \<bar>x\<bar>"
```
```   418 apply (rule abs_realpow_two [THEN subst])
```
```   419 apply (rule real_sqrt_abs_abs [THEN subst])
```
```   420 apply (subst real_pow_sqrt_eq_sqrt_pow)
```
```   421 apply (auto simp add: numeral_2_eq_2)
```
```   422 done
```
```   423
```
```   424 lemma real_sqrt_abs2 [simp]: "sqrt(x*x) = \<bar>x\<bar>"
```
```   425 apply (rule realpow_two [THEN subst])
```
```   426 apply (subst numeral_2_eq_2 [symmetric])
```
```   427 apply (rule real_sqrt_abs)
```
```   428 done
```
```   429
```
```   430 lemma real_sqrt_pow2_gt_zero: "0 < x ==> 0 < (sqrt x)\<twosuperior>"
```
```   431 by simp
```
```   432
```
```   433 lemma real_sqrt_not_eq_zero: "0 < x ==> sqrt x \<noteq> 0"
```
```   434 apply (frule real_sqrt_pow2_gt_zero)
```
```   435 apply (auto simp add: numeral_2_eq_2)
```
```   436 done
```
```   437
```
```   438 lemma real_inv_sqrt_pow2: "0 < x ==> inverse (sqrt(x)) ^ 2 = inverse x"
```
```   439 by (cut_tac n = 2 and a = "sqrt x" in power_inverse [symmetric], auto)
```
```   440
```
```   441 lemma real_sqrt_eq_zero_cancel: "[| 0 \<le> x; sqrt(x) = 0|] ==> x = 0"
```
```   442 apply (drule real_le_imp_less_or_eq)
```
```   443 apply (auto dest: real_sqrt_not_eq_zero)
```
```   444 done
```
```   445
```
```   446 lemma real_sqrt_eq_zero_cancel_iff [simp]: "0 \<le> x ==> ((sqrt x = 0) = (x=0))"
```
```   447 by (auto simp add: real_sqrt_eq_zero_cancel)
```
```   448
```
```   449 lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
```
```   450 apply (subgoal_tac "x \<le> 0 | 0 \<le> x", safe)
```
```   451 apply (rule real_le_trans)
```
```   452 apply (auto simp del: realpow_Suc)
```
```   453 apply (rule_tac n = 1 in realpow_increasing)
```
```   454 apply (auto simp add: numeral_2_eq_2 [symmetric] simp del: realpow_Suc)
```
```   455 done
```
```   456
```
```   457 lemma real_sqrt_sum_squares_ge2 [simp]: "y \<le> sqrt(z\<twosuperior> + y\<twosuperior>)"
```
```   458 apply (simp (no_asm) add: real_add_commute del: realpow_Suc)
```
```   459 done
```
```   460
```
```   461 lemma real_sqrt_ge_one: "1 \<le> x ==> 1 \<le> sqrt x"
```
```   462 apply (rule_tac n = 1 in realpow_increasing)
```
```   463 apply (auto simp add: numeral_2_eq_2 [symmetric] real_sqrt_ge_zero simp
```
```   464             del: realpow_Suc)
```
```   465 done
```
```   466
```
```   467 lemma sqrt_divide_self_eq:
```
```   468   assumes nneg: "0 \<le> x"
```
```   469   shows "sqrt x / x = inverse (sqrt x)"
```
```   470 proof cases
```
```   471   assume "x=0" thus ?thesis by simp
```
```   472 next
```
```   473   assume nz: "x\<noteq>0"
```
```   474   hence pos: "0<x" using nneg by arith
```
```   475   show ?thesis
```
```   476   proof (rule right_inverse_eq [THEN iffD1, THEN sym])
```
```   477     show "sqrt x / x \<noteq> 0" by (simp add: divide_inverse nneg nz)
```
```   478     show "inverse (sqrt x) / (sqrt x / x) = 1"
```
```   479       by (simp add: divide_inverse mult_assoc [symmetric]
```
```   480                   power2_eq_square [symmetric] real_inv_sqrt_pow2 pos nz)
```
```   481   qed
```
```   482 qed
```
```   483
```
```   484
```
```   485 lemma real_sqrt_less_mono: "[| 0 \<le> x; x < y |] ==> sqrt(x) < sqrt(y)"
```
```   486 by (simp add: sqrt_def)
```
```   487
```
```   488 lemma real_sqrt_le_mono: "[| 0 \<le> x; x \<le> y |] ==> sqrt(x) \<le> sqrt(y)"
```
```   489 by (simp add: sqrt_def)
```
```   490
```
```   491 lemma real_sqrt_less_iff [simp]:
```
```   492      "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) < sqrt(y)) = (x < y)"
```
```   493 by (simp add: sqrt_def)
```
```   494
```
```   495 lemma real_sqrt_le_iff [simp]:
```
```   496      "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) \<le> sqrt(y)) = (x \<le> y)"
```
```   497 by (simp add: sqrt_def)
```
```   498
```
```   499 lemma real_sqrt_eq_iff [simp]:
```
```   500      "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) = sqrt(y)) = (x = y)"
```
```   501 by (simp add: sqrt_def)
```
```   502
```
```   503 lemma real_sqrt_sos_less_one_iff [simp]: "(sqrt(x\<twosuperior> + y\<twosuperior>) < 1) = (x\<twosuperior> + y\<twosuperior> < 1)"
```
```   504 apply (rule real_sqrt_one [THEN subst], safe)
```
```   505 apply (rule_tac [2] real_sqrt_less_mono)
```
```   506 apply (drule real_sqrt_less_iff [THEN [2] rev_iffD1], auto)
```
```   507 done
```
```   508
```
```   509 lemma real_sqrt_sos_eq_one_iff [simp]: "(sqrt(x\<twosuperior> + y\<twosuperior>) = 1) = (x\<twosuperior> + y\<twosuperior> = 1)"
```
```   510 apply (rule real_sqrt_one [THEN subst], safe)
```
```   511 apply (drule real_sqrt_eq_iff [THEN [2] rev_iffD1], auto)
```
```   512 done
```
```   513
```
```   514 lemma real_divide_square_eq [simp]: "(((r::real) * a) / (r * r)) = a / r"
```
```   515 apply (simp add: divide_inverse)
```
```   516 apply (case_tac "r=0")
```
```   517 apply (auto simp add: mult_ac)
```
```   518 done
```
```   519
```
```   520
```
```   521 end
```