src/HOL/Hyperreal/NthRoot.thy
author huffman
Fri May 18 17:35:07 2007 +0200 (2007-05-18)
changeset 23009 01c295dd4a36
parent 22968 7134874437ac
child 23042 492514b39956
permissions -rw-r--r--
Prove existence of nth roots using Intermediate Value Theorem
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
huffman@22956
     7
header {* Nth Roots of Real Numbers *}
paulson@14324
     8
nipkow@15131
     9
theory NthRoot
huffman@23009
    10
imports SEQ Parity Deriv
nipkow@15131
    11
begin
paulson@14324
    12
huffman@22956
    13
subsection {* Existence of Nth Root *}
huffman@20687
    14
huffman@23009
    15
text {* Existence follows from the Intermediate Value Theorem *}
paulson@14324
    16
huffman@23009
    17
lemma realpow_pos_nth:
huffman@23009
    18
  assumes n: "0 < n"
huffman@23009
    19
  assumes a: "0 < a"
huffman@23009
    20
  shows "\<exists>r>0. r ^ n = (a::real)"
huffman@23009
    21
proof -
huffman@23009
    22
  have "\<exists>r\<ge>0. r \<le> (max 1 a) \<and> r ^ n = a"
huffman@23009
    23
  proof (rule IVT)
huffman@23009
    24
    show "0 ^ n \<le> a" using n a by (simp add: power_0_left)
huffman@23009
    25
    show "0 \<le> max 1 a" by simp
huffman@23009
    26
    from n have n1: "1 \<le> n" by simp
huffman@23009
    27
    have "a \<le> max 1 a ^ 1" by simp
huffman@23009
    28
    also have "max 1 a ^ 1 \<le> max 1 a ^ n"
huffman@23009
    29
      using n1 by (rule power_increasing, simp)
huffman@23009
    30
    finally show "a \<le> max 1 a ^ n" .
huffman@23009
    31
    show "\<forall>r. 0 \<le> r \<and> r \<le> max 1 a \<longrightarrow> isCont (\<lambda>x. x ^ n) r"
huffman@23009
    32
      by (simp add: isCont_power isCont_Id)
huffman@23009
    33
  qed
huffman@23009
    34
  then obtain r where r: "0 \<le> r \<and> r ^ n = a" by fast
huffman@23009
    35
  with n a have "r \<noteq> 0" by (auto simp add: power_0_left)
huffman@23009
    36
  with r have "0 < r \<and> r ^ n = a" by simp
huffman@23009
    37
  thus ?thesis ..
huffman@23009
    38
qed
paulson@14325
    39
huffman@23009
    40
text {* Uniqueness of nth positive root *}
paulson@14324
    41
paulson@14324
    42
lemma realpow_pos_nth_unique:
huffman@23009
    43
  "\<lbrakk>0 < n; 0 < a\<rbrakk> \<Longrightarrow> \<exists>!r. 0 < r \<and> r ^ n = (a::real)"
paulson@14324
    44
apply (auto intro!: realpow_pos_nth)
huffman@23009
    45
apply (rule_tac n=n in power_eq_imp_eq_base, simp_all)
paulson@14324
    46
done
paulson@14324
    47
huffman@20687
    48
subsection {* Nth Root *}
huffman@20687
    49
huffman@22956
    50
text {* We define roots of negative reals such that
huffman@22956
    51
  @{term "root n (- x) = - root n x"}. This allows
huffman@22956
    52
  us to omit side conditions from many theorems. *}
huffman@20687
    53
huffman@22956
    54
definition
huffman@22956
    55
  root :: "[nat, real] \<Rightarrow> real" where
huffman@22956
    56
  "root n x = (if 0 < x then (THE u. 0 < u \<and> u ^ n = x) else
huffman@22956
    57
               if x < 0 then - (THE u. 0 < u \<and> u ^ n = - x) else 0)"
huffman@20687
    58
huffman@22956
    59
lemma real_root_zero [simp]: "root n 0 = 0"
huffman@22956
    60
unfolding root_def by simp
huffman@22956
    61
huffman@22956
    62
lemma real_root_minus: "0 < n \<Longrightarrow> root n (- x) = - root n x"
huffman@22956
    63
unfolding root_def by simp
huffman@22956
    64
huffman@22956
    65
lemma real_root_gt_zero: "\<lbrakk>0 < n; 0 < x\<rbrakk> \<Longrightarrow> 0 < root n x"
huffman@20687
    66
apply (simp add: root_def)
huffman@22956
    67
apply (drule (1) realpow_pos_nth_unique)
huffman@20687
    68
apply (erule theI' [THEN conjunct1])
huffman@20687
    69
done
huffman@20687
    70
huffman@22956
    71
lemma real_root_pow_pos: (* TODO: rename *)
huffman@22956
    72
  "\<lbrakk>0 < n; 0 < x\<rbrakk> \<Longrightarrow> root n x ^ n = x"
huffman@22956
    73
apply (simp add: root_def)
huffman@22956
    74
apply (drule (1) realpow_pos_nth_unique)
huffman@22956
    75
apply (erule theI' [THEN conjunct2])
huffman@22956
    76
done
huffman@20687
    77
huffman@22956
    78
lemma real_root_pow_pos2 [simp]: (* TODO: rename *)
huffman@22956
    79
  "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> root n x ^ n = x"
huffman@22956
    80
by (auto simp add: order_le_less real_root_pow_pos)
huffman@22956
    81
huffman@22956
    82
lemma real_root_ge_zero: "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> 0 \<le> root n x"
huffman@20687
    83
by (auto simp add: order_le_less real_root_gt_zero)
huffman@20687
    84
huffman@22956
    85
lemma real_root_power_cancel: "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> root n (x ^ n) = x"
huffman@22956
    86
apply (subgoal_tac "0 \<le> x ^ n")
huffman@22956
    87
apply (subgoal_tac "0 \<le> root n (x ^ n)")
huffman@22956
    88
apply (subgoal_tac "root n (x ^ n) ^ n = x ^ n")
huffman@22956
    89
apply (erule (3) power_eq_imp_eq_base)
huffman@22956
    90
apply (erule (1) real_root_pow_pos2)
huffman@22956
    91
apply (erule (1) real_root_ge_zero)
huffman@22956
    92
apply (erule zero_le_power)
huffman@20687
    93
done
huffman@20687
    94
huffman@22956
    95
lemma real_root_pos_unique:
huffman@22956
    96
  "\<lbrakk>0 < n; 0 \<le> y; y ^ n = x\<rbrakk> \<Longrightarrow> root n x = y"
huffman@22956
    97
by (erule subst, rule real_root_power_cancel)
huffman@22956
    98
huffman@22956
    99
lemma real_root_one [simp]: "0 < n \<Longrightarrow> root n 1 = 1"
huffman@22956
   100
by (simp add: real_root_pos_unique)
huffman@22956
   101
huffman@22956
   102
text {* Root function is strictly monotonic, hence injective *}
huffman@22956
   103
huffman@22956
   104
lemma real_root_less_mono_lemma:
huffman@22956
   105
  "\<lbrakk>0 < n; 0 \<le> x; x < y\<rbrakk> \<Longrightarrow> root n x < root n y"
huffman@22856
   106
apply (subgoal_tac "0 \<le> y")
huffman@22956
   107
apply (subgoal_tac "root n x ^ n < root n y ^ n")
huffman@22956
   108
apply (erule power_less_imp_less_base)
huffman@22956
   109
apply (erule (1) real_root_ge_zero)
huffman@22956
   110
apply simp
huffman@22956
   111
apply simp
huffman@22721
   112
done
huffman@22721
   113
huffman@22956
   114
lemma real_root_less_mono: "\<lbrakk>0 < n; x < y\<rbrakk> \<Longrightarrow> root n x < root n y"
huffman@22956
   115
apply (cases "0 \<le> x")
huffman@22956
   116
apply (erule (2) real_root_less_mono_lemma)
huffman@22956
   117
apply (cases "0 \<le> y")
huffman@22956
   118
apply (rule_tac y=0 in order_less_le_trans)
huffman@22956
   119
apply (subgoal_tac "0 < root n (- x)")
huffman@22956
   120
apply (simp add: real_root_minus)
huffman@22956
   121
apply (simp add: real_root_gt_zero)
huffman@22956
   122
apply (simp add: real_root_ge_zero)
huffman@22956
   123
apply (subgoal_tac "root n (- y) < root n (- x)")
huffman@22956
   124
apply (simp add: real_root_minus)
huffman@22956
   125
apply (simp add: real_root_less_mono_lemma)
huffman@22721
   126
done
huffman@22721
   127
huffman@22956
   128
lemma real_root_le_mono: "\<lbrakk>0 < n; x \<le> y\<rbrakk> \<Longrightarrow> root n x \<le> root n y"
huffman@22956
   129
by (auto simp add: order_le_less real_root_less_mono)
huffman@22956
   130
huffman@22721
   131
lemma real_root_less_iff [simp]:
huffman@22956
   132
  "0 < n \<Longrightarrow> (root n x < root n y) = (x < y)"
huffman@22956
   133
apply (cases "x < y")
huffman@22956
   134
apply (simp add: real_root_less_mono)
huffman@22956
   135
apply (simp add: linorder_not_less real_root_le_mono)
huffman@22721
   136
done
huffman@22721
   137
huffman@22721
   138
lemma real_root_le_iff [simp]:
huffman@22956
   139
  "0 < n \<Longrightarrow> (root n x \<le> root n y) = (x \<le> y)"
huffman@22956
   140
apply (cases "x \<le> y")
huffman@22956
   141
apply (simp add: real_root_le_mono)
huffman@22956
   142
apply (simp add: linorder_not_le real_root_less_mono)
huffman@22721
   143
done
huffman@22721
   144
huffman@22721
   145
lemma real_root_eq_iff [simp]:
huffman@22956
   146
  "0 < n \<Longrightarrow> (root n x = root n y) = (x = y)"
huffman@22956
   147
by (simp add: order_eq_iff)
huffman@22956
   148
huffman@22956
   149
lemmas real_root_gt_0_iff [simp] = real_root_less_iff [where x=0, simplified]
huffman@22956
   150
lemmas real_root_lt_0_iff [simp] = real_root_less_iff [where y=0, simplified]
huffman@22956
   151
lemmas real_root_ge_0_iff [simp] = real_root_le_iff [where x=0, simplified]
huffman@22956
   152
lemmas real_root_le_0_iff [simp] = real_root_le_iff [where y=0, simplified]
huffman@22956
   153
lemmas real_root_eq_0_iff [simp] = real_root_eq_iff [where y=0, simplified]
huffman@22721
   154
huffman@22956
   155
text {* Roots of multiplication and division *}
huffman@22956
   156
huffman@22956
   157
lemma real_root_mult_lemma:
huffman@22956
   158
  "\<lbrakk>0 < n; 0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> root n (x * y) = root n x * root n y"
huffman@22956
   159
by (simp add: real_root_pos_unique mult_nonneg_nonneg power_mult_distrib)
huffman@22956
   160
huffman@22956
   161
lemma real_root_inverse_lemma:
huffman@22956
   162
  "\<lbrakk>0 < n; 0 \<le> x\<rbrakk> \<Longrightarrow> root n (inverse x) = inverse (root n x)"
huffman@22956
   163
by (simp add: real_root_pos_unique power_inverse [symmetric])
huffman@22721
   164
huffman@22721
   165
lemma real_root_mult:
huffman@22956
   166
  assumes n: "0 < n"
huffman@22956
   167
  shows "root n (x * y) = root n x * root n y"
huffman@22956
   168
proof (rule linorder_le_cases, rule_tac [!] linorder_le_cases)
huffman@22956
   169
  assume "0 \<le> x" and "0 \<le> y"
huffman@22956
   170
  thus ?thesis by (rule real_root_mult_lemma [OF n])
huffman@22956
   171
next
huffman@22956
   172
  assume "0 \<le> x" and "y \<le> 0"
huffman@22956
   173
  hence "0 \<le> x" and "0 \<le> - y" by simp_all
huffman@22956
   174
  hence "root n (x * - y) = root n x * root n (- y)"
huffman@22956
   175
    by (rule real_root_mult_lemma [OF n])
huffman@22956
   176
  thus ?thesis by (simp add: real_root_minus [OF n])
huffman@22956
   177
next
huffman@22956
   178
  assume "x \<le> 0" and "0 \<le> y"
huffman@22956
   179
  hence "0 \<le> - x" and "0 \<le> y" by simp_all
huffman@22956
   180
  hence "root n (- x * y) = root n (- x) * root n y"
huffman@22956
   181
    by (rule real_root_mult_lemma [OF n])
huffman@22956
   182
  thus ?thesis by (simp add: real_root_minus [OF n])
huffman@22956
   183
next
huffman@22956
   184
  assume "x \<le> 0" and "y \<le> 0"
huffman@22956
   185
  hence "0 \<le> - x" and "0 \<le> - y" by simp_all
huffman@22956
   186
  hence "root n (- x * - y) = root n (- x) * root n (- y)"
huffman@22956
   187
    by (rule real_root_mult_lemma [OF n])
huffman@22956
   188
  thus ?thesis by (simp add: real_root_minus [OF n])
huffman@22956
   189
qed
huffman@22721
   190
huffman@22721
   191
lemma real_root_inverse:
huffman@22956
   192
  assumes n: "0 < n"
huffman@22956
   193
  shows "root n (inverse x) = inverse (root n x)"
huffman@22956
   194
proof (rule linorder_le_cases)
huffman@22956
   195
  assume "0 \<le> x"
huffman@22956
   196
  thus ?thesis by (rule real_root_inverse_lemma [OF n])
huffman@22956
   197
next
huffman@22956
   198
  assume "x \<le> 0"
huffman@22956
   199
  hence "0 \<le> - x" by simp
huffman@22956
   200
  hence "root n (inverse (- x)) = inverse (root n (- x))"
huffman@22956
   201
    by (rule real_root_inverse_lemma [OF n])
huffman@22956
   202
  thus ?thesis by (simp add: real_root_minus [OF n])
huffman@22956
   203
qed
huffman@22721
   204
huffman@22956
   205
lemma real_root_divide:
huffman@22956
   206
  "0 < n \<Longrightarrow> root n (x / y) = root n x / root n y"
huffman@22956
   207
by (simp add: divide_inverse real_root_mult real_root_inverse)
huffman@22956
   208
huffman@22956
   209
lemma real_root_power:
huffman@22956
   210
  "0 < n \<Longrightarrow> root n (x ^ k) = root n x ^ k"
huffman@22956
   211
by (induct k, simp_all add: real_root_mult)
huffman@22721
   212
huffman@22956
   213
subsection {* Square Root *}
huffman@20687
   214
huffman@22956
   215
definition
huffman@22956
   216
  sqrt :: "real \<Rightarrow> real" where
huffman@22956
   217
  "sqrt = root 2"
huffman@20687
   218
huffman@22956
   219
lemma pos2: "0 < (2::nat)" by simp
huffman@22956
   220
huffman@22956
   221
lemma real_sqrt_unique: "\<lbrakk>y\<twosuperior> = x; 0 \<le> y\<rbrakk> \<Longrightarrow> sqrt x = y"
huffman@22956
   222
unfolding sqrt_def by (rule real_root_pos_unique [OF pos2])
huffman@20687
   223
huffman@22956
   224
lemma real_sqrt_abs [simp]: "sqrt (x\<twosuperior>) = \<bar>x\<bar>"
huffman@22956
   225
apply (rule real_sqrt_unique)
huffman@22956
   226
apply (rule power2_abs)
huffman@22956
   227
apply (rule abs_ge_zero)
huffman@22956
   228
done
huffman@20687
   229
huffman@22956
   230
lemma real_sqrt_pow2 [simp]: "0 \<le> x \<Longrightarrow> (sqrt x)\<twosuperior> = x"
huffman@22956
   231
unfolding sqrt_def by (rule real_root_pow_pos2 [OF pos2])
huffman@22856
   232
huffman@22956
   233
lemma real_sqrt_pow2_iff [simp]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)"
huffman@22856
   234
apply (rule iffI)
huffman@22856
   235
apply (erule subst)
huffman@22856
   236
apply (rule zero_le_power2)
huffman@22856
   237
apply (erule real_sqrt_pow2)
huffman@20687
   238
done
huffman@20687
   239
huffman@22956
   240
lemma real_sqrt_zero [simp]: "sqrt 0 = 0"
huffman@22956
   241
unfolding sqrt_def by (rule real_root_zero)
huffman@22956
   242
huffman@22956
   243
lemma real_sqrt_one [simp]: "sqrt 1 = 1"
huffman@22956
   244
unfolding sqrt_def by (rule real_root_one [OF pos2])
huffman@22956
   245
huffman@22956
   246
lemma real_sqrt_minus: "sqrt (- x) = - sqrt x"
huffman@22956
   247
unfolding sqrt_def by (rule real_root_minus [OF pos2])
huffman@22956
   248
huffman@22956
   249
lemma real_sqrt_mult: "sqrt (x * y) = sqrt x * sqrt y"
huffman@22956
   250
unfolding sqrt_def by (rule real_root_mult [OF pos2])
huffman@22956
   251
huffman@22956
   252
lemma real_sqrt_inverse: "sqrt (inverse x) = inverse (sqrt x)"
huffman@22956
   253
unfolding sqrt_def by (rule real_root_inverse [OF pos2])
huffman@22956
   254
huffman@22956
   255
lemma real_sqrt_divide: "sqrt (x / y) = sqrt x / sqrt y"
huffman@22956
   256
unfolding sqrt_def by (rule real_root_divide [OF pos2])
huffman@22956
   257
huffman@22956
   258
lemma real_sqrt_power: "sqrt (x ^ k) = sqrt x ^ k"
huffman@22956
   259
unfolding sqrt_def by (rule real_root_power [OF pos2])
huffman@22956
   260
huffman@22956
   261
lemma real_sqrt_gt_zero: "0 < x \<Longrightarrow> 0 < sqrt x"
huffman@22956
   262
unfolding sqrt_def by (rule real_root_gt_zero [OF pos2])
huffman@22956
   263
huffman@22956
   264
lemma real_sqrt_ge_zero: "0 \<le> x \<Longrightarrow> 0 \<le> sqrt x"
huffman@22956
   265
unfolding sqrt_def by (rule real_root_ge_zero [OF pos2])
huffman@20687
   266
huffman@22956
   267
lemma real_sqrt_less_mono: "x < y \<Longrightarrow> sqrt x < sqrt y"
huffman@22956
   268
unfolding sqrt_def by (rule real_root_less_mono [OF pos2])
huffman@22956
   269
huffman@22956
   270
lemma real_sqrt_le_mono: "x \<le> y \<Longrightarrow> sqrt x \<le> sqrt y"
huffman@22956
   271
unfolding sqrt_def by (rule real_root_le_mono [OF pos2])
huffman@22956
   272
huffman@22956
   273
lemma real_sqrt_less_iff [simp]: "(sqrt x < sqrt y) = (x < y)"
huffman@22956
   274
unfolding sqrt_def by (rule real_root_less_iff [OF pos2])
huffman@22956
   275
huffman@22956
   276
lemma real_sqrt_le_iff [simp]: "(sqrt x \<le> sqrt y) = (x \<le> y)"
huffman@22956
   277
unfolding sqrt_def by (rule real_root_le_iff [OF pos2])
huffman@22956
   278
huffman@22956
   279
lemma real_sqrt_eq_iff [simp]: "(sqrt x = sqrt y) = (x = y)"
huffman@22956
   280
unfolding sqrt_def by (rule real_root_eq_iff [OF pos2])
huffman@22956
   281
huffman@22956
   282
lemmas real_sqrt_gt_0_iff [simp] = real_sqrt_less_iff [where x=0, simplified]
huffman@22956
   283
lemmas real_sqrt_lt_0_iff [simp] = real_sqrt_less_iff [where y=0, simplified]
huffman@22956
   284
lemmas real_sqrt_ge_0_iff [simp] = real_sqrt_le_iff [where x=0, simplified]
huffman@22956
   285
lemmas real_sqrt_le_0_iff [simp] = real_sqrt_le_iff [where y=0, simplified]
huffman@22956
   286
lemmas real_sqrt_eq_0_iff [simp] = real_sqrt_eq_iff [where y=0, simplified]
huffman@22956
   287
huffman@22956
   288
lemmas real_sqrt_gt_1_iff [simp] = real_sqrt_less_iff [where x=1, simplified]
huffman@22956
   289
lemmas real_sqrt_lt_1_iff [simp] = real_sqrt_less_iff [where y=1, simplified]
huffman@22956
   290
lemmas real_sqrt_ge_1_iff [simp] = real_sqrt_le_iff [where x=1, simplified]
huffman@22956
   291
lemmas real_sqrt_le_1_iff [simp] = real_sqrt_le_iff [where y=1, simplified]
huffman@22956
   292
lemmas real_sqrt_eq_1_iff [simp] = real_sqrt_eq_iff [where y=1, simplified]
huffman@20687
   293
huffman@20687
   294
lemma not_real_square_gt_zero [simp]: "(~ (0::real) < x*x) = (x = 0)"
huffman@20687
   295
apply auto
huffman@20687
   296
apply (cut_tac x = x and y = 0 in linorder_less_linear)
huffman@20687
   297
apply (simp add: zero_less_mult_iff)
huffman@20687
   298
done
huffman@20687
   299
huffman@20687
   300
lemma real_sqrt_abs2 [simp]: "sqrt(x*x) = \<bar>x\<bar>"
huffman@22856
   301
apply (subst power2_eq_square [symmetric])
huffman@20687
   302
apply (rule real_sqrt_abs)
huffman@20687
   303
done
huffman@20687
   304
huffman@20687
   305
lemma real_sqrt_pow2_gt_zero: "0 < x ==> 0 < (sqrt x)\<twosuperior>"
huffman@22956
   306
by simp (* TODO: delete *)
huffman@20687
   307
huffman@20687
   308
lemma real_sqrt_not_eq_zero: "0 < x ==> sqrt x \<noteq> 0"
huffman@22956
   309
by simp (* TODO: delete *)
huffman@20687
   310
huffman@20687
   311
lemma real_inv_sqrt_pow2: "0 < x ==> inverse (sqrt(x)) ^ 2 = inverse x"
huffman@22856
   312
by (simp add: power_inverse [symmetric])
huffman@20687
   313
huffman@20687
   314
lemma real_sqrt_eq_zero_cancel: "[| 0 \<le> x; sqrt(x) = 0|] ==> x = 0"
huffman@22956
   315
by simp
huffman@20687
   316
huffman@20687
   317
lemma real_sqrt_ge_one: "1 \<le> x ==> 1 \<le> sqrt x"
huffman@22956
   318
by simp
huffman@20687
   319
huffman@22443
   320
lemma sqrt_divide_self_eq:
huffman@22443
   321
  assumes nneg: "0 \<le> x"
huffman@22443
   322
  shows "sqrt x / x = inverse (sqrt x)"
huffman@22443
   323
proof cases
huffman@22443
   324
  assume "x=0" thus ?thesis by simp
huffman@22443
   325
next
huffman@22443
   326
  assume nz: "x\<noteq>0" 
huffman@22443
   327
  hence pos: "0<x" using nneg by arith
huffman@22443
   328
  show ?thesis
huffman@22443
   329
  proof (rule right_inverse_eq [THEN iffD1, THEN sym]) 
huffman@22443
   330
    show "sqrt x / x \<noteq> 0" by (simp add: divide_inverse nneg nz) 
huffman@22443
   331
    show "inverse (sqrt x) / (sqrt x / x) = 1"
huffman@22443
   332
      by (simp add: divide_inverse mult_assoc [symmetric] 
huffman@22443
   333
                  power2_eq_square [symmetric] real_inv_sqrt_pow2 pos nz) 
huffman@22443
   334
  qed
huffman@22443
   335
qed
huffman@22443
   336
huffman@22721
   337
lemma real_divide_square_eq [simp]: "(((r::real) * a) / (r * r)) = a / r"
huffman@22721
   338
apply (simp add: divide_inverse)
huffman@22721
   339
apply (case_tac "r=0")
huffman@22721
   340
apply (auto simp add: mult_ac)
huffman@22721
   341
done
huffman@22721
   342
huffman@22856
   343
subsection {* Square Root of Sum of Squares *}
huffman@22856
   344
huffman@22856
   345
lemma real_sqrt_mult_self_sum_ge_zero [simp]: "0 \<le> sqrt(x*x + y*y)"
huffman@22968
   346
by (rule real_sqrt_ge_zero [OF sum_squares_ge_zero])
huffman@22856
   347
huffman@22856
   348
lemma real_sqrt_sum_squares_ge_zero [simp]: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
huffman@22961
   349
by simp
huffman@22856
   350
huffman@22856
   351
lemma real_sqrt_sum_squares_mult_ge_zero [simp]:
huffman@22856
   352
     "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))"
huffman@22856
   353
by (auto intro!: real_sqrt_ge_zero simp add: zero_le_mult_iff)
huffman@22856
   354
huffman@22856
   355
lemma real_sqrt_sum_squares_mult_squared_eq [simp]:
huffman@22856
   356
     "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)"
huffman@22956
   357
by (auto simp add: zero_le_mult_iff)
huffman@22856
   358
huffman@22856
   359
lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
huffman@22856
   360
by (rule power2_le_imp_le, simp_all)
huffman@22856
   361
huffman@22856
   362
lemma real_sqrt_sum_squares_ge2 [simp]: "y \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
huffman@22856
   363
by (rule power2_le_imp_le, simp_all)
huffman@22856
   364
huffman@22858
   365
lemma power2_sum:
huffman@22858
   366
  fixes x y :: "'a::{number_ring,recpower}"
huffman@22858
   367
  shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y"
huffman@22858
   368
by (simp add: left_distrib right_distrib power2_eq_square)
huffman@22858
   369
huffman@22858
   370
lemma power2_diff:
huffman@22858
   371
  fixes x y :: "'a::{number_ring,recpower}"
huffman@22858
   372
  shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y"
huffman@22858
   373
by (simp add: left_diff_distrib right_diff_distrib power2_eq_square)
huffman@22858
   374
huffman@22858
   375
lemma real_sqrt_sum_squares_triangle_ineq:
huffman@22858
   376
  "sqrt ((a + c)\<twosuperior> + (b + d)\<twosuperior>) \<le> sqrt (a\<twosuperior> + b\<twosuperior>) + sqrt (c\<twosuperior> + d\<twosuperior>)"
huffman@22858
   377
apply (rule power2_le_imp_le, simp)
huffman@22858
   378
apply (simp add: power2_sum)
huffman@22858
   379
apply (simp only: mult_assoc right_distrib [symmetric])
huffman@22858
   380
apply (rule mult_left_mono)
huffman@22858
   381
apply (rule power2_le_imp_le)
huffman@22858
   382
apply (simp add: power2_sum power_mult_distrib)
huffman@22858
   383
apply (simp add: ring_distrib)
huffman@22858
   384
apply (subgoal_tac "0 \<le> b\<twosuperior> * c\<twosuperior> + a\<twosuperior> * d\<twosuperior> - 2 * (a * c) * (b * d)", simp)
huffman@22858
   385
apply (rule_tac b="(a * d - b * c)\<twosuperior>" in ord_le_eq_trans)
huffman@22858
   386
apply (rule zero_le_power2)
huffman@22858
   387
apply (simp add: power2_diff power_mult_distrib)
huffman@22858
   388
apply (simp add: mult_nonneg_nonneg)
huffman@22858
   389
apply simp
huffman@22858
   390
apply (simp add: add_increasing)
huffman@22858
   391
done
huffman@22858
   392
huffman@22956
   393
text "Legacy theorem names:"
huffman@22956
   394
lemmas real_root_pos2 = real_root_power_cancel
huffman@22956
   395
lemmas real_root_pos_pos = real_root_gt_zero [THEN order_less_imp_le]
huffman@22956
   396
lemmas real_root_pos_pos_le = real_root_ge_zero
huffman@22956
   397
lemmas real_sqrt_mult_distrib = real_sqrt_mult
huffman@22956
   398
lemmas real_sqrt_mult_distrib2 = real_sqrt_mult
huffman@22956
   399
lemmas real_sqrt_eq_zero_cancel_iff = real_sqrt_eq_0_iff
huffman@22956
   400
huffman@22956
   401
(* needed for CauchysMeanTheorem.het_base from AFP *)
huffman@22956
   402
lemma real_root_pos: "0 < x \<Longrightarrow> root (Suc n) (x ^ (Suc n)) = x"
huffman@22956
   403
by (rule real_root_power_cancel [OF zero_less_Suc order_less_imp_le])
huffman@22956
   404
huffman@22956
   405
(* FIXME: the stronger version of real_root_less_iff
huffman@22956
   406
 breaks CauchysMeanTheorem.list_gmean_gt_iff from AFP. *)
huffman@22956
   407
huffman@22956
   408
declare real_root_less_iff [simp del]
huffman@22956
   409
lemma real_root_less_iff_nonneg [simp]:
huffman@22956
   410
  "\<lbrakk>0 < n; 0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> (root n x < root n y) = (x < y)"
huffman@22956
   411
by (rule real_root_less_iff)
huffman@22956
   412
paulson@14324
   413
end