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