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