src/HOL/Hyperreal/NthRoot.thy
author huffman
Tue May 08 04:56:28 2007 +0200 (2007-05-08)
changeset 22858 5ca5d1cce388
parent 22856 eb0e0582092a
child 22943 0b928312ab94
permissions -rw-r--r--
add lemma real_sqrt_sum_squares_triangle_ineq
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@22856
   244
apply (subgoal_tac "0 \<le> y")
huffman@22856
   245
apply (rule_tac n="Suc n" in power_less_imp_less_base)
huffman@22856
   246
apply (simp only: real_root_pow_pos2)
huffman@22856
   247
apply (erule real_root_pos_pos_le)
huffman@22856
   248
apply (erule order_trans)
huffman@22856
   249
apply (erule order_less_imp_le)
huffman@22721
   250
done
huffman@22721
   251
huffman@22721
   252
lemma real_root_le_mono:
huffman@22721
   253
     "[| 0 \<le> x; x \<le> y |] ==> root(Suc n) x \<le> root(Suc n) y"
huffman@22721
   254
apply (drule_tac y = y in order_le_imp_less_or_eq)
huffman@22721
   255
apply (auto dest: real_root_less_mono intro: order_less_imp_le)
huffman@22721
   256
done
huffman@22721
   257
huffman@22721
   258
lemma real_root_less_iff [simp]:
huffman@22721
   259
     "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x < root(Suc n) y) = (x < y)"
huffman@22721
   260
apply (auto intro: real_root_less_mono)
huffman@22721
   261
apply (rule ccontr, drule linorder_not_less [THEN iffD1])
huffman@22721
   262
apply (drule_tac x = y and n = n in real_root_le_mono, auto)
huffman@22721
   263
done
huffman@22721
   264
huffman@22721
   265
lemma real_root_le_iff [simp]:
huffman@22721
   266
     "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x \<le> root(Suc n) y) = (x \<le> y)"
huffman@22721
   267
apply (auto intro: real_root_le_mono)
huffman@22721
   268
apply (simp (no_asm) add: linorder_not_less [symmetric])
huffman@22721
   269
apply auto
huffman@22721
   270
apply (drule_tac x = y and n = n in real_root_less_mono, auto)
huffman@22721
   271
done
huffman@22721
   272
huffman@22721
   273
lemma real_root_eq_iff [simp]:
huffman@22721
   274
     "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x = root(Suc n) y) = (x = y)"
huffman@22721
   275
apply (auto intro!: order_antisym [where 'a = real])
huffman@22721
   276
apply (rule_tac n1 = n in real_root_le_iff [THEN iffD1])
huffman@22721
   277
apply (rule_tac [4] n1 = n in real_root_le_iff [THEN iffD1], auto)
huffman@22721
   278
done
huffman@22721
   279
huffman@22721
   280
lemma real_root_pos_unique:
huffman@22721
   281
     "[| 0 \<le> x; 0 \<le> y; y ^ (Suc n) = x |] ==> root (Suc n) x = y"
huffman@22721
   282
by (auto dest: real_root_pos2 simp del: realpow_Suc)
huffman@22721
   283
huffman@22721
   284
lemma real_root_mult:
huffman@22721
   285
     "[| 0 \<le> x; 0 \<le> y |] 
huffman@22721
   286
      ==> root(Suc n) (x * y) = root(Suc n) x * root(Suc n) y"
huffman@22721
   287
apply (rule real_root_pos_unique)
huffman@22721
   288
apply (auto intro!: real_root_pos_pos_le 
huffman@22721
   289
            simp add: power_mult_distrib zero_le_mult_iff real_root_pow_pos2 
huffman@22721
   290
            simp del: realpow_Suc)
huffman@22721
   291
done
huffman@22721
   292
huffman@22721
   293
lemma real_root_inverse:
huffman@22721
   294
     "0 \<le> x ==> (root(Suc n) (inverse x) = inverse(root(Suc n) x))"
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_inverse [symmetric] real_root_pow_pos2 
huffman@22721
   298
            simp del: realpow_Suc)
huffman@22721
   299
done
huffman@22721
   300
huffman@22721
   301
lemma real_root_divide: 
huffman@22721
   302
     "[| 0 \<le> x; 0 \<le> y |]  
huffman@22721
   303
      ==> (root(Suc n) (x / y) = root(Suc n) x / root(Suc n) y)"
huffman@22721
   304
apply (simp add: divide_inverse)
huffman@22721
   305
apply (auto simp add: real_root_mult real_root_inverse)
huffman@22721
   306
done
huffman@22721
   307
huffman@20687
   308
huffman@20687
   309
subsection{*Square Root*}
huffman@20687
   310
huffman@20687
   311
text{*needed because 2 is a binary numeral!*}
huffman@20687
   312
lemma root_2_eq [simp]: "root 2 = root (Suc (Suc 0))"
huffman@22856
   313
by (simp only: numeral_2_eq_2)
huffman@20687
   314
huffman@20687
   315
lemma real_sqrt_zero [simp]: "sqrt 0 = 0"
huffman@20687
   316
by (simp add: sqrt_def)
huffman@20687
   317
huffman@20687
   318
lemma real_sqrt_one [simp]: "sqrt 1 = 1"
huffman@20687
   319
by (simp add: sqrt_def)
huffman@20687
   320
huffman@22856
   321
lemma real_sqrt_pow2 [simp]: "0 \<le> x ==> (sqrt x)\<twosuperior> = x"
huffman@22856
   322
unfolding sqrt_def numeral_2_eq_2
huffman@22856
   323
by (rule real_root_pow_pos2)
huffman@22856
   324
huffman@20687
   325
lemma real_sqrt_pow2_iff [iff]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)"
huffman@22856
   326
apply (rule iffI)
huffman@22856
   327
apply (erule subst)
huffman@22856
   328
apply (rule zero_le_power2)
huffman@22856
   329
apply (erule real_sqrt_pow2)
huffman@20687
   330
done
huffman@20687
   331
huffman@22856
   332
lemma real_sqrt_abs_abs [simp]: "(sqrt \<bar>x\<bar>)\<twosuperior> = \<bar>x\<bar>" (* TODO: delete *)
huffman@22856
   333
by simp
huffman@20687
   334
huffman@22856
   335
lemma sqrt_eqI: "\<lbrakk>r\<twosuperior> = a; 0 \<le> r\<rbrakk> \<Longrightarrow> sqrt a = r"
huffman@22856
   336
unfolding sqrt_def numeral_2_eq_2
huffman@22856
   337
by (erule subst, erule real_root_pos2)
huffman@20687
   338
huffman@22856
   339
lemma real_sqrt_abs [simp]: "sqrt (x\<twosuperior>) = \<bar>x\<bar>"
huffman@22856
   340
apply (rule sqrt_eqI)
huffman@22856
   341
apply (rule power2_abs)
huffman@22856
   342
apply (rule abs_ge_zero)
huffman@20687
   343
done
huffman@20687
   344
huffman@22856
   345
lemma real_pow_sqrt_eq_sqrt_pow: (* TODO: delete *)
huffman@22856
   346
      "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(x\<twosuperior>)"
huffman@22856
   347
by simp
huffman@20687
   348
huffman@22856
   349
lemma real_pow_sqrt_eq_sqrt_abs_pow2: (* TODO: delete *)
huffman@22856
   350
     "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(\<bar>x\<bar> ^ 2)" 
huffman@22856
   351
by simp
huffman@22856
   352
huffman@22856
   353
lemma real_sqrt_pow_abs: "0 \<le> x ==> (sqrt x)\<twosuperior> = \<bar>x\<bar>" (* TODO: delete *)
huffman@22856
   354
by simp
huffman@20687
   355
huffman@20687
   356
lemma not_real_square_gt_zero [simp]: "(~ (0::real) < x*x) = (x = 0)"
huffman@20687
   357
apply auto
huffman@20687
   358
apply (cut_tac x = x and y = 0 in linorder_less_linear)
huffman@20687
   359
apply (simp add: zero_less_mult_iff)
huffman@20687
   360
done
huffman@20687
   361
huffman@20687
   362
lemma real_sqrt_gt_zero: "0 < x ==> 0 < sqrt(x)"
huffman@20687
   363
by (simp add: sqrt_def real_root_gt_zero)
huffman@20687
   364
huffman@20687
   365
lemma real_sqrt_ge_zero: "0 \<le> x ==> 0 \<le> sqrt(x)"
huffman@20687
   366
by (auto intro: real_sqrt_gt_zero simp add: order_le_less)
huffman@20687
   367
huffman@20687
   368
huffman@20687
   369
(*we need to prove something like this:
huffman@20687
   370
lemma "[|r ^ n = a; 0<n; 0 < a \<longrightarrow> 0 < r|] ==> root n a = r"
huffman@20687
   371
apply (case_tac n, simp) 
huffman@20687
   372
apply (simp add: root_def) 
huffman@20687
   373
apply (rule someI2 [of _ r], safe)
huffman@20687
   374
apply (auto simp del: realpow_Suc dest: power_inject_base)
huffman@20687
   375
*)
huffman@20687
   376
huffman@20687
   377
lemma real_sqrt_mult_distrib: 
huffman@20687
   378
     "[| 0 \<le> x; 0 \<le> y |] ==> sqrt(x*y) = sqrt(x) * sqrt(y)"
huffman@22856
   379
unfolding sqrt_def numeral_2_eq_2
huffman@22856
   380
by (rule real_root_mult)
huffman@20687
   381
huffman@22856
   382
lemmas real_sqrt_mult_distrib2 = real_sqrt_mult_distrib
huffman@20687
   383
huffman@20687
   384
lemma real_sqrt_abs2 [simp]: "sqrt(x*x) = \<bar>x\<bar>"
huffman@22856
   385
apply (subst power2_eq_square [symmetric])
huffman@20687
   386
apply (rule real_sqrt_abs)
huffman@20687
   387
done
huffman@20687
   388
huffman@20687
   389
lemma real_sqrt_pow2_gt_zero: "0 < x ==> 0 < (sqrt x)\<twosuperior>"
huffman@20687
   390
by simp
huffman@20687
   391
huffman@20687
   392
lemma real_sqrt_not_eq_zero: "0 < x ==> sqrt x \<noteq> 0"
huffman@20687
   393
apply (frule real_sqrt_pow2_gt_zero)
huffman@20687
   394
apply (auto simp add: numeral_2_eq_2)
huffman@20687
   395
done
huffman@20687
   396
huffman@20687
   397
lemma real_inv_sqrt_pow2: "0 < x ==> inverse (sqrt(x)) ^ 2 = inverse x"
huffman@22856
   398
by (simp add: power_inverse [symmetric])
huffman@20687
   399
huffman@20687
   400
lemma real_sqrt_eq_zero_cancel: "[| 0 \<le> x; sqrt(x) = 0|] ==> x = 0"
huffman@20687
   401
apply (drule real_le_imp_less_or_eq)
huffman@20687
   402
apply (auto dest: real_sqrt_not_eq_zero)
huffman@20687
   403
done
huffman@20687
   404
huffman@20687
   405
lemma real_sqrt_eq_zero_cancel_iff [simp]: "0 \<le> x ==> ((sqrt x = 0) = (x=0))"
huffman@20687
   406
by (auto simp add: real_sqrt_eq_zero_cancel)
huffman@20687
   407
huffman@20687
   408
lemma real_sqrt_ge_one: "1 \<le> x ==> 1 \<le> sqrt x"
huffman@22856
   409
apply (rule power2_le_imp_le, simp)
huffman@22856
   410
apply (simp add: real_sqrt_ge_zero)
huffman@20687
   411
done
huffman@20687
   412
huffman@22443
   413
lemma sqrt_divide_self_eq:
huffman@22443
   414
  assumes nneg: "0 \<le> x"
huffman@22443
   415
  shows "sqrt x / x = inverse (sqrt x)"
huffman@22443
   416
proof cases
huffman@22443
   417
  assume "x=0" thus ?thesis by simp
huffman@22443
   418
next
huffman@22443
   419
  assume nz: "x\<noteq>0" 
huffman@22443
   420
  hence pos: "0<x" using nneg by arith
huffman@22443
   421
  show ?thesis
huffman@22443
   422
  proof (rule right_inverse_eq [THEN iffD1, THEN sym]) 
huffman@22443
   423
    show "sqrt x / x \<noteq> 0" by (simp add: divide_inverse nneg nz) 
huffman@22443
   424
    show "inverse (sqrt x) / (sqrt x / x) = 1"
huffman@22443
   425
      by (simp add: divide_inverse mult_assoc [symmetric] 
huffman@22443
   426
                  power2_eq_square [symmetric] real_inv_sqrt_pow2 pos nz) 
huffman@22443
   427
  qed
huffman@22443
   428
qed
huffman@22443
   429
huffman@22721
   430
huffman@22721
   431
lemma real_sqrt_less_mono: "[| 0 \<le> x; x < y |] ==> sqrt(x) < sqrt(y)"
huffman@22721
   432
by (simp add: sqrt_def)
huffman@22721
   433
huffman@22721
   434
lemma real_sqrt_le_mono: "[| 0 \<le> x; x \<le> y |] ==> sqrt(x) \<le> sqrt(y)"
huffman@22721
   435
by (simp add: sqrt_def)
huffman@22721
   436
huffman@22721
   437
lemma real_sqrt_less_iff [simp]:
huffman@22721
   438
     "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) < sqrt(y)) = (x < y)"
huffman@22721
   439
by (simp add: sqrt_def)
huffman@22721
   440
huffman@22721
   441
lemma real_sqrt_le_iff [simp]:
huffman@22721
   442
     "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) \<le> sqrt(y)) = (x \<le> y)"
huffman@22721
   443
by (simp add: sqrt_def)
huffman@22721
   444
huffman@22721
   445
lemma real_sqrt_eq_iff [simp]:
huffman@22721
   446
     "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) = sqrt(y)) = (x = y)"
huffman@22721
   447
by (simp add: sqrt_def)
huffman@22721
   448
huffman@22721
   449
lemma real_divide_square_eq [simp]: "(((r::real) * a) / (r * r)) = a / r"
huffman@22721
   450
apply (simp add: divide_inverse)
huffman@22721
   451
apply (case_tac "r=0")
huffman@22721
   452
apply (auto simp add: mult_ac)
huffman@22721
   453
done
huffman@22721
   454
huffman@22856
   455
subsection {* Square Root of Sum of Squares *}
huffman@22856
   456
huffman@22856
   457
lemma "(sqrt (x\<twosuperior> + y\<twosuperior>))\<twosuperior> = x\<twosuperior> + y\<twosuperior>"
huffman@22856
   458
by (rule realpow_two_le_add_order [THEN real_sqrt_pow2_iff [THEN iffD2]])
huffman@22856
   459
huffman@22856
   460
lemma real_sqrt_mult_self_sum_ge_zero [simp]: "0 \<le> sqrt(x*x + y*y)"
huffman@22856
   461
by (rule real_sqrt_ge_zero [OF real_mult_self_sum_ge_zero]) 
huffman@22856
   462
huffman@22856
   463
lemma real_sqrt_sum_squares_ge_zero [simp]: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
huffman@22856
   464
by (auto intro!: real_sqrt_ge_zero)
huffman@22856
   465
huffman@22856
   466
lemma real_sqrt_sum_squares_mult_ge_zero [simp]:
huffman@22856
   467
     "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))"
huffman@22856
   468
by (auto intro!: real_sqrt_ge_zero simp add: zero_le_mult_iff)
huffman@22856
   469
huffman@22856
   470
lemma real_sqrt_sum_squares_mult_squared_eq [simp]:
huffman@22856
   471
     "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)"
huffman@22856
   472
by (auto simp add: zero_le_mult_iff simp del: realpow_Suc)
huffman@22856
   473
huffman@22856
   474
lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
huffman@22856
   475
by (rule power2_le_imp_le, simp_all)
huffman@22856
   476
huffman@22856
   477
lemma real_sqrt_sum_squares_ge2 [simp]: "y \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
huffman@22856
   478
by (rule power2_le_imp_le, simp_all)
huffman@22856
   479
huffman@22856
   480
lemma real_sqrt_sos_less_one_iff [simp]: "(sqrt(x\<twosuperior> + y\<twosuperior>) < 1) = (x\<twosuperior> + y\<twosuperior> < 1)"
huffman@22856
   481
apply (subst real_sqrt_one [symmetric])
huffman@22856
   482
apply (rule real_sqrt_less_iff, auto)
huffman@22856
   483
done
huffman@22856
   484
huffman@22856
   485
lemma real_sqrt_sos_eq_one_iff [simp]: "(sqrt(x\<twosuperior> + y\<twosuperior>) = 1) = (x\<twosuperior> + y\<twosuperior> = 1)"
huffman@22856
   486
apply (subst real_sqrt_one [symmetric])
huffman@22856
   487
apply (rule real_sqrt_eq_iff, auto)
huffman@22856
   488
done
huffman@22721
   489
huffman@22858
   490
lemma power2_sum:
huffman@22858
   491
  fixes x y :: "'a::{number_ring,recpower}"
huffman@22858
   492
  shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y"
huffman@22858
   493
by (simp add: left_distrib right_distrib power2_eq_square)
huffman@22858
   494
huffman@22858
   495
lemma power2_diff:
huffman@22858
   496
  fixes x y :: "'a::{number_ring,recpower}"
huffman@22858
   497
  shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y"
huffman@22858
   498
by (simp add: left_diff_distrib right_diff_distrib power2_eq_square)
huffman@22858
   499
huffman@22858
   500
lemma real_sqrt_sum_squares_triangle_ineq:
huffman@22858
   501
  "sqrt ((a + c)\<twosuperior> + (b + d)\<twosuperior>) \<le> sqrt (a\<twosuperior> + b\<twosuperior>) + sqrt (c\<twosuperior> + d\<twosuperior>)"
huffman@22858
   502
apply (rule power2_le_imp_le, simp)
huffman@22858
   503
apply (simp add: power2_sum)
huffman@22858
   504
apply (simp only: mult_assoc right_distrib [symmetric])
huffman@22858
   505
apply (rule mult_left_mono)
huffman@22858
   506
apply (rule power2_le_imp_le)
huffman@22858
   507
apply (simp add: power2_sum power_mult_distrib)
huffman@22858
   508
apply (simp add: ring_distrib)
huffman@22858
   509
apply (subgoal_tac "0 \<le> b\<twosuperior> * c\<twosuperior> + a\<twosuperior> * d\<twosuperior> - 2 * (a * c) * (b * d)", simp)
huffman@22858
   510
apply (rule_tac b="(a * d - b * c)\<twosuperior>" in ord_le_eq_trans)
huffman@22858
   511
apply (rule zero_le_power2)
huffman@22858
   512
apply (simp add: power2_diff power_mult_distrib)
huffman@22858
   513
apply (simp add: mult_nonneg_nonneg)
huffman@22858
   514
apply simp
huffman@22858
   515
apply (simp add: add_increasing)
huffman@22858
   516
done
huffman@22858
   517
paulson@14324
   518
end