src/HOL/Real/RealPow.thy
author huffman
Mon May 14 08:15:13 2007 +0200 (2007-05-14)
changeset 22958 b3a5569a81e5
parent 22945 2863582c61b5
child 22962 4bb05ba38939
permissions -rw-r--r--
cleaned up
wenzelm@9435
     1
(*  Title       : HOL/Real/RealPow.thy
paulson@7219
     2
    ID          : $Id$
paulson@7077
     3
    Author      : Jacques D. Fleuriot  
paulson@7077
     4
    Copyright   : 1998  University of Cambridge
huffman@20634
     5
*)
paulson@7077
     6
huffman@20634
     7
header {* Natural powers theory *}
paulson@7077
     8
nipkow@15131
     9
theory RealPow
nipkow@15140
    10
imports RealDef
nipkow@15131
    11
begin
wenzelm@9435
    12
paulson@14348
    13
declare abs_mult_self [simp]
paulson@14348
    14
wenzelm@10309
    15
instance real :: power ..
paulson@7077
    16
wenzelm@8856
    17
primrec (realpow)
paulson@12018
    18
     realpow_0:   "r ^ 0       = 1"
wenzelm@9435
    19
     realpow_Suc: "r ^ (Suc n) = (r::real) * (r ^ n)"
paulson@7077
    20
paulson@14265
    21
paulson@15003
    22
instance real :: recpower
paulson@14348
    23
proof
paulson@14348
    24
  fix z :: real
paulson@14348
    25
  fix n :: nat
paulson@14348
    26
  show "z^0 = 1" by simp
paulson@14348
    27
  show "z^(Suc n) = z * (z^n)" by simp
paulson@14348
    28
qed
paulson@14265
    29
paulson@14348
    30
paulson@14348
    31
lemma realpow_not_zero: "r \<noteq> (0::real) ==> r ^ n \<noteq> 0"
paulson@14348
    32
  by (rule field_power_not_zero)
paulson@14265
    33
paulson@14265
    34
lemma realpow_zero_zero: "r ^ n = (0::real) ==> r = 0"
paulson@14268
    35
by simp
paulson@14265
    36
paulson@14265
    37
lemma realpow_two: "(r::real)^ (Suc (Suc 0)) = r * r"
paulson@14268
    38
by simp
paulson@14265
    39
wenzelm@19765
    40
text{*Legacy: weaker version of the theorem @{text power_strict_mono}*}
paulson@14348
    41
lemma realpow_less:
paulson@14348
    42
     "[|(0::real) < x; x < y; 0 < n|] ==> x ^ n < y ^ n"
paulson@14348
    43
apply (rule power_strict_mono, auto) 
paulson@14265
    44
done
paulson@14265
    45
paulson@14268
    46
lemma realpow_two_le [simp]: "(0::real) \<le> r^ Suc (Suc 0)"
paulson@14268
    47
by (simp add: real_le_square)
paulson@14265
    48
paulson@14268
    49
lemma abs_realpow_two [simp]: "abs((x::real)^Suc (Suc 0)) = x^Suc (Suc 0)"
paulson@14348
    50
by (simp add: abs_mult)
paulson@14265
    51
paulson@14268
    52
lemma realpow_two_abs [simp]: "abs(x::real)^Suc (Suc 0) = x^Suc (Suc 0)"
paulson@15229
    53
by (simp add: power_abs [symmetric] del: realpow_Suc)
paulson@14265
    54
paulson@14268
    55
lemma two_realpow_ge_one [simp]: "(1::real) \<le> 2 ^ n"
paulson@14348
    56
by (insert power_increasing [of 0 n "2::real"], simp)
paulson@14265
    57
paulson@14268
    58
lemma two_realpow_gt [simp]: "real (n::nat) < 2 ^ n"
paulson@15251
    59
apply (induct "n")
paulson@14265
    60
apply (auto simp add: real_of_nat_Suc)
paulson@14387
    61
apply (subst mult_2)
paulson@14265
    62
apply (rule real_add_less_le_mono)
paulson@14265
    63
apply (auto simp add: two_realpow_ge_one)
paulson@14265
    64
done
paulson@14265
    65
paulson@14348
    66
lemma realpow_Suc_le_self: "[| 0 \<le> r; r \<le> (1::real) |] ==> r ^ Suc n \<le> r"
paulson@14348
    67
by (insert power_decreasing [of 1 "Suc n" r], simp)
paulson@14265
    68
paulson@14348
    69
lemma realpow_Suc_less_one: "[| 0 < r; r < (1::real) |] ==> r ^ Suc n < 1"
huffman@22958
    70
by (rule power_Suc_less_one)
paulson@14265
    71
paulson@14348
    72
lemma realpow_minus_mult [rule_format]:
paulson@14348
    73
     "0 < n --> (x::real) ^ (n - 1) * x = x ^ n" 
paulson@14348
    74
apply (simp split add: nat_diff_split)
paulson@14265
    75
done
paulson@14265
    76
paulson@14348
    77
lemma realpow_two_mult_inverse [simp]:
paulson@14348
    78
     "r \<noteq> 0 ==> r * inverse r ^Suc (Suc 0) = inverse (r::real)"
paulson@14268
    79
by (simp add: realpow_two real_mult_assoc [symmetric])
paulson@14265
    80
paulson@14268
    81
lemma realpow_two_minus [simp]: "(-x)^Suc (Suc 0) = (x::real)^Suc (Suc 0)"
paulson@14268
    82
by simp
paulson@14265
    83
paulson@14348
    84
lemma realpow_two_diff:
paulson@14348
    85
     "(x::real)^Suc (Suc 0) - y^Suc (Suc 0) = (x - y) * (x + y)"
paulson@14265
    86
apply (unfold real_diff_def)
paulson@14334
    87
apply (simp add: right_distrib left_distrib mult_ac)
paulson@14265
    88
done
paulson@14265
    89
paulson@14348
    90
lemma realpow_two_disj:
paulson@14348
    91
     "((x::real)^Suc (Suc 0) = y^Suc (Suc 0)) = (x = y | x = -y)"
paulson@14268
    92
apply (cut_tac x = x and y = y in realpow_two_diff)
paulson@14265
    93
apply (auto simp del: realpow_Suc)
paulson@14265
    94
done
paulson@14265
    95
paulson@14265
    96
lemma realpow_real_of_nat: "real (m::nat) ^ n = real (m ^ n)"
paulson@15251
    97
apply (induct "n")
paulson@14265
    98
apply (auto simp add: real_of_nat_one real_of_nat_mult)
paulson@14265
    99
done
paulson@14265
   100
paulson@14268
   101
lemma realpow_real_of_nat_two_pos [simp] : "0 < real (Suc (Suc 0) ^ n)"
paulson@15251
   102
apply (induct "n")
paulson@14334
   103
apply (auto simp add: real_of_nat_mult zero_less_mult_iff)
paulson@14265
   104
done
paulson@14265
   105
paulson@14265
   106
lemma realpow_increasing:
paulson@14348
   107
     "[|(0::real) \<le> x; 0 \<le> y; x ^ Suc n \<le> y ^ Suc n|] ==> x \<le> y"
paulson@14348
   108
  by (rule power_le_imp_le_base)
paulson@14265
   109
paulson@14265
   110
paulson@14348
   111
lemma zero_less_realpow_abs_iff [simp]:
paulson@14348
   112
     "(0 < (abs x)^n) = (x \<noteq> (0::real) | n=0)" 
paulson@15251
   113
apply (induct "n")
paulson@14334
   114
apply (auto simp add: zero_less_mult_iff)
paulson@14265
   115
done
paulson@14265
   116
paulson@14268
   117
lemma zero_le_realpow_abs [simp]: "(0::real) \<le> (abs x)^n"
huffman@22958
   118
by (rule zero_le_power_abs)
paulson@14265
   119
paulson@14265
   120
paulson@14348
   121
subsection{*Literal Arithmetic Involving Powers, Type @{typ real}*}
paulson@14265
   122
paulson@14265
   123
lemma real_of_int_power: "real (x::int) ^ n = real (x ^ n)"
paulson@15251
   124
apply (induct "n")
paulson@14387
   125
apply (simp_all add: nat_mult_distrib)
paulson@14265
   126
done
paulson@14265
   127
declare real_of_int_power [symmetric, simp]
paulson@14265
   128
paulson@14348
   129
lemma power_real_number_of:
paulson@14348
   130
     "(number_of v :: real) ^ n = real ((number_of v :: int) ^ n)"
paulson@14387
   131
by (simp only: real_number_of [symmetric] real_of_int_power)
paulson@14265
   132
paulson@14265
   133
declare power_real_number_of [of _ "number_of w", standard, simp]
paulson@14265
   134
paulson@14265
   135
paulson@14268
   136
subsection{*Various Other Theorems*}
paulson@14268
   137
paulson@14268
   138
lemma real_sum_squares_cancel_a: "x * x = -(y * y) ==> x = (0::real) & y=0"
paulson@15085
   139
  apply (auto dest: real_sum_squares_cancel simp add: real_add_eq_0_iff [symmetric])
paulson@15085
   140
  apply (auto dest: real_sum_squares_cancel simp add: add_commute)
paulson@15085
   141
  done
paulson@14268
   142
paulson@14268
   143
lemma real_squared_diff_one_factored: "x*x - (1::real) = (x + 1)*(x - 1)"
paulson@14348
   144
by (auto simp add: left_distrib right_distrib real_diff_def)
paulson@14268
   145
paulson@14348
   146
lemma real_mult_is_one [simp]: "(x*x = (1::real)) = (x = 1 | x = - 1)"
paulson@14268
   147
apply auto
paulson@14268
   148
apply (drule right_minus_eq [THEN iffD2]) 
paulson@14268
   149
apply (auto simp add: real_squared_diff_one_factored)
paulson@14268
   150
done
paulson@14268
   151
paulson@14304
   152
lemma real_le_add_half_cancel: "(x + y/2 \<le> (y::real)) = (x \<le> y /2)"
paulson@14348
   153
by auto
paulson@14268
   154
paulson@14348
   155
lemma real_minus_half_eq [simp]: "(x::real) - x/2 = x/2"
paulson@14348
   156
by auto
paulson@14268
   157
paulson@14268
   158
lemma real_mult_inverse_cancel:
paulson@14268
   159
     "[|(0::real) < x; 0 < x1; x1 * y < x * u |] 
paulson@14268
   160
      ==> inverse x * y < inverse x1 * u"
paulson@14268
   161
apply (rule_tac c=x in mult_less_imp_less_left) 
paulson@14268
   162
apply (auto simp add: real_mult_assoc [symmetric])
paulson@14334
   163
apply (simp (no_asm) add: mult_ac)
paulson@14268
   164
apply (rule_tac c=x1 in mult_less_imp_less_right) 
paulson@14334
   165
apply (auto simp add: mult_ac)
paulson@14268
   166
done
paulson@14268
   167
paulson@14348
   168
lemma real_mult_inverse_cancel2:
paulson@14348
   169
     "[|(0::real) < x;0 < x1; x1 * y < x * u |] ==> y * inverse x < u * inverse x1"
paulson@14334
   170
apply (auto dest: real_mult_inverse_cancel simp add: mult_ac)
paulson@14268
   171
done
paulson@14268
   172
paulson@14348
   173
lemma inverse_real_of_nat_gt_zero [simp]: "0 < inverse (real (Suc n))"
huffman@20517
   174
by simp
paulson@14268
   175
paulson@14348
   176
lemma inverse_real_of_nat_ge_zero [simp]: "0 \<le> inverse (real (Suc n))"
huffman@20517
   177
by simp
paulson@14268
   178
paulson@14268
   179
lemma real_sum_squares_not_zero: "x ~= 0 ==> x * x + y * y ~= (0::real)"
paulson@14348
   180
by (blast dest!: real_sum_squares_cancel)
paulson@14268
   181
paulson@14268
   182
lemma real_sum_squares_not_zero2: "y ~= 0 ==> x * x + y * y ~= (0::real)"
paulson@14348
   183
by (blast dest!: real_sum_squares_cancel2)
paulson@14268
   184
paulson@14268
   185
paulson@14268
   186
subsection {*Various Other Theorems*}
paulson@14268
   187
paulson@14348
   188
lemma realpow_two_sum_zero_iff [simp]:
paulson@14348
   189
     "(x ^ 2 + y ^ 2 = (0::real)) = (x = 0 & y = 0)"
paulson@14348
   190
apply (auto intro: real_sum_squares_cancel real_sum_squares_cancel2 
paulson@14352
   191
                   simp add: power2_eq_square)
paulson@14268
   192
done
paulson@14268
   193
paulson@14348
   194
lemma realpow_two_le_add_order [simp]: "(0::real) \<le> u ^ 2 + v ^ 2"
paulson@14268
   195
apply (rule real_le_add_order)
paulson@14352
   196
apply (auto simp add: power2_eq_square)
paulson@14268
   197
done
paulson@14268
   198
paulson@14348
   199
lemma realpow_two_le_add_order2 [simp]: "(0::real) \<le> u ^ 2 + v ^ 2 + w ^ 2"
paulson@14268
   200
apply (rule real_le_add_order)+
paulson@14352
   201
apply (auto simp add: power2_eq_square)
paulson@14268
   202
done
paulson@14268
   203
paulson@14268
   204
lemma real_sum_square_gt_zero: "x ~= 0 ==> (0::real) < x * x + y * y"
paulson@14348
   205
apply (cut_tac x = x and y = y in real_mult_self_sum_ge_zero)
paulson@14268
   206
apply (drule real_le_imp_less_or_eq)
paulson@14348
   207
apply (drule_tac y = y in real_sum_squares_not_zero, auto)
paulson@14268
   208
done
paulson@14268
   209
paulson@14268
   210
lemma real_sum_square_gt_zero2: "y ~= 0 ==> (0::real) < x * x + y * y"
paulson@14268
   211
apply (rule real_add_commute [THEN subst])
paulson@14268
   212
apply (erule real_sum_square_gt_zero)
paulson@14268
   213
done
paulson@14268
   214
paulson@14348
   215
lemma real_minus_mult_self_le [simp]: "-(u * u) \<le> (x * (x::real))"
paulson@14348
   216
by (rule_tac j = 0 in real_le_trans, auto)
paulson@14268
   217
paulson@14348
   218
lemma realpow_square_minus_le [simp]: "-(u ^ 2) \<le> (x::real) ^ 2"
paulson@14352
   219
by (auto simp add: power2_eq_square)
paulson@14268
   220
ballarin@19279
   221
(* The following theorem is by Benjamin Porter *)
ballarin@19279
   222
lemma real_sq_order:
ballarin@19279
   223
  fixes x::real
ballarin@19279
   224
  assumes xgt0: "0 \<le> x" and ygt0: "0 \<le> y" and sq: "x^2 \<le> y^2"
ballarin@19279
   225
  shows "x \<le> y"
huffman@20517
   226
proof -
huffman@20517
   227
  from sq have "x ^ Suc (Suc 0) \<le> y ^ Suc (Suc 0)"
huffman@20517
   228
    by (simp only: numeral_2_eq_2)
huffman@22624
   229
  thus "x \<le> y" using ygt0
huffman@20517
   230
    by (rule power_le_imp_le_base)
ballarin@19279
   231
qed
ballarin@19279
   232
paulson@14268
   233
lemma realpow_num_eq_if: "(m::real) ^ n = (if n=0 then 1 else m * m ^ (n - 1))"
paulson@14348
   234
by (case_tac "n", auto)
paulson@14268
   235
paulson@7077
   236
end