src/HOL/Real/RealPow.thy
author nipkow
Thu Jun 07 11:25:27 2007 +0200 (2007-06-07)
changeset 23291 9179346e1208
parent 23096 423ad2fe9f76
child 23292 1c39f1bd1f53
permissions -rw-r--r--
somebody elses problem fixed
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@14265
    31
lemma realpow_zero_zero: "r ^ n = (0::real) ==> r = 0"
paulson@14268
    32
by simp
paulson@14265
    33
paulson@14265
    34
lemma realpow_two: "(r::real)^ (Suc (Suc 0)) = r * r"
paulson@14268
    35
by simp
paulson@14265
    36
wenzelm@19765
    37
text{*Legacy: weaker version of the theorem @{text power_strict_mono}*}
paulson@14348
    38
lemma realpow_less:
paulson@14348
    39
     "[|(0::real) < x; x < y; 0 < n|] ==> x ^ n < y ^ n"
paulson@14348
    40
apply (rule power_strict_mono, auto) 
paulson@14265
    41
done
paulson@14265
    42
paulson@14268
    43
lemma realpow_two_le [simp]: "(0::real) \<le> r^ Suc (Suc 0)"
nipkow@23291
    44
by (simp)
paulson@14265
    45
paulson@14268
    46
lemma abs_realpow_two [simp]: "abs((x::real)^Suc (Suc 0)) = x^Suc (Suc 0)"
paulson@14348
    47
by (simp add: abs_mult)
paulson@14265
    48
paulson@14268
    49
lemma realpow_two_abs [simp]: "abs(x::real)^Suc (Suc 0) = x^Suc (Suc 0)"
paulson@15229
    50
by (simp add: power_abs [symmetric] del: realpow_Suc)
paulson@14265
    51
paulson@14268
    52
lemma two_realpow_ge_one [simp]: "(1::real) \<le> 2 ^ n"
paulson@14348
    53
by (insert power_increasing [of 0 n "2::real"], simp)
paulson@14265
    54
paulson@14268
    55
lemma two_realpow_gt [simp]: "real (n::nat) < 2 ^ n"
paulson@15251
    56
apply (induct "n")
paulson@14265
    57
apply (auto simp add: real_of_nat_Suc)
paulson@14387
    58
apply (subst mult_2)
huffman@22962
    59
apply (rule add_less_le_mono)
paulson@14265
    60
apply (auto simp add: two_realpow_ge_one)
paulson@14265
    61
done
paulson@14265
    62
paulson@14348
    63
lemma realpow_Suc_le_self: "[| 0 \<le> r; r \<le> (1::real) |] ==> r ^ Suc n \<le> r"
paulson@14348
    64
by (insert power_decreasing [of 1 "Suc n" r], simp)
paulson@14265
    65
paulson@14348
    66
lemma realpow_minus_mult [rule_format]:
paulson@14348
    67
     "0 < n --> (x::real) ^ (n - 1) * x = x ^ n" 
paulson@14348
    68
apply (simp split add: nat_diff_split)
paulson@14265
    69
done
paulson@14265
    70
paulson@14348
    71
lemma realpow_two_mult_inverse [simp]:
paulson@14348
    72
     "r \<noteq> 0 ==> r * inverse r ^Suc (Suc 0) = inverse (r::real)"
paulson@14268
    73
by (simp add: realpow_two real_mult_assoc [symmetric])
paulson@14265
    74
paulson@14268
    75
lemma realpow_two_minus [simp]: "(-x)^Suc (Suc 0) = (x::real)^Suc (Suc 0)"
paulson@14268
    76
by simp
paulson@14265
    77
paulson@14348
    78
lemma realpow_two_diff:
paulson@14348
    79
     "(x::real)^Suc (Suc 0) - y^Suc (Suc 0) = (x - y) * (x + y)"
paulson@14265
    80
apply (unfold real_diff_def)
paulson@14334
    81
apply (simp add: right_distrib left_distrib mult_ac)
paulson@14265
    82
done
paulson@14265
    83
paulson@14348
    84
lemma realpow_two_disj:
paulson@14348
    85
     "((x::real)^Suc (Suc 0) = y^Suc (Suc 0)) = (x = y | x = -y)"
paulson@14268
    86
apply (cut_tac x = x and y = y in realpow_two_diff)
paulson@14265
    87
apply (auto simp del: realpow_Suc)
paulson@14265
    88
done
paulson@14265
    89
paulson@14265
    90
lemma realpow_real_of_nat: "real (m::nat) ^ n = real (m ^ n)"
paulson@15251
    91
apply (induct "n")
paulson@14265
    92
apply (auto simp add: real_of_nat_one real_of_nat_mult)
paulson@14265
    93
done
paulson@14265
    94
paulson@14268
    95
lemma realpow_real_of_nat_two_pos [simp] : "0 < real (Suc (Suc 0) ^ n)"
paulson@15251
    96
apply (induct "n")
paulson@14334
    97
apply (auto simp add: real_of_nat_mult zero_less_mult_iff)
paulson@14265
    98
done
paulson@14265
    99
huffman@22962
   100
(* used by AFP Integration theory *)
paulson@14265
   101
lemma realpow_increasing:
paulson@14348
   102
     "[|(0::real) \<le> x; 0 \<le> y; x ^ Suc n \<le> y ^ Suc n|] ==> x \<le> y"
paulson@14348
   103
  by (rule power_le_imp_le_base)
paulson@14265
   104
paulson@14265
   105
paulson@14348
   106
subsection{*Literal Arithmetic Involving Powers, Type @{typ real}*}
paulson@14265
   107
paulson@14265
   108
lemma real_of_int_power: "real (x::int) ^ n = real (x ^ n)"
paulson@15251
   109
apply (induct "n")
paulson@14387
   110
apply (simp_all add: nat_mult_distrib)
paulson@14265
   111
done
paulson@14265
   112
declare real_of_int_power [symmetric, simp]
paulson@14265
   113
paulson@14348
   114
lemma power_real_number_of:
paulson@14348
   115
     "(number_of v :: real) ^ n = real ((number_of v :: int) ^ n)"
paulson@14387
   116
by (simp only: real_number_of [symmetric] real_of_int_power)
paulson@14265
   117
paulson@14265
   118
declare power_real_number_of [of _ "number_of w", standard, simp]
paulson@14265
   119
paulson@14265
   120
huffman@22967
   121
subsection {* Properties of Squares *}
huffman@22967
   122
huffman@22967
   123
lemma sum_squares_ge_zero:
huffman@22967
   124
  fixes x y :: "'a::ordered_ring_strict"
huffman@22967
   125
  shows "0 \<le> x * x + y * y"
huffman@22967
   126
by (intro add_nonneg_nonneg zero_le_square)
huffman@22967
   127
huffman@22967
   128
lemma not_sum_squares_lt_zero:
huffman@22967
   129
  fixes x y :: "'a::ordered_ring_strict"
huffman@22967
   130
  shows "\<not> x * x + y * y < 0"
huffman@22967
   131
by (simp add: linorder_not_less sum_squares_ge_zero)
huffman@22967
   132
huffman@22967
   133
lemma sum_nonneg_eq_zero_iff:
huffman@22967
   134
  fixes x y :: "'a::pordered_ab_group_add"
huffman@22967
   135
  assumes x: "0 \<le> x" and y: "0 \<le> y"
huffman@22967
   136
  shows "(x + y = 0) = (x = 0 \<and> y = 0)"
huffman@22967
   137
proof (auto)
huffman@22967
   138
  from y have "x + 0 \<le> x + y" by (rule add_left_mono)
huffman@22967
   139
  also assume "x + y = 0"
huffman@22967
   140
  finally have "x \<le> 0" by simp
huffman@22967
   141
  thus "x = 0" using x by (rule order_antisym)
huffman@22967
   142
next
huffman@22967
   143
  from x have "0 + y \<le> x + y" by (rule add_right_mono)
huffman@22967
   144
  also assume "x + y = 0"
huffman@22967
   145
  finally have "y \<le> 0" by simp
huffman@22967
   146
  thus "y = 0" using y by (rule order_antisym)
huffman@22967
   147
qed
huffman@22967
   148
huffman@22967
   149
lemma sum_squares_eq_zero_iff:
huffman@22967
   150
  fixes x y :: "'a::ordered_ring_strict"
huffman@22967
   151
  shows "(x * x + y * y = 0) = (x = 0 \<and> y = 0)"
nipkow@23096
   152
by (simp add: sum_nonneg_eq_zero_iff)
huffman@22967
   153
huffman@22967
   154
lemma sum_squares_le_zero_iff:
huffman@22967
   155
  fixes x y :: "'a::ordered_ring_strict"
huffman@22967
   156
  shows "(x * x + y * y \<le> 0) = (x = 0 \<and> y = 0)"
huffman@22967
   157
by (simp add: order_le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff)
huffman@22967
   158
huffman@22967
   159
lemma sum_squares_gt_zero_iff:
huffman@22967
   160
  fixes x y :: "'a::ordered_ring_strict"
huffman@22967
   161
  shows "(0 < x * x + y * y) = (x \<noteq> 0 \<or> y \<noteq> 0)"
huffman@22967
   162
by (simp add: order_less_le sum_squares_ge_zero sum_squares_eq_zero_iff)
huffman@22967
   163
huffman@22967
   164
lemma sum_power2_ge_zero:
huffman@22967
   165
  fixes x y :: "'a::{ordered_idom,recpower}"
huffman@22967
   166
  shows "0 \<le> x\<twosuperior> + y\<twosuperior>"
huffman@22967
   167
unfolding power2_eq_square by (rule sum_squares_ge_zero)
huffman@22967
   168
huffman@22967
   169
lemma not_sum_power2_lt_zero:
huffman@22967
   170
  fixes x y :: "'a::{ordered_idom,recpower}"
huffman@22967
   171
  shows "\<not> x\<twosuperior> + y\<twosuperior> < 0"
huffman@22967
   172
unfolding power2_eq_square by (rule not_sum_squares_lt_zero)
huffman@22967
   173
huffman@22967
   174
lemma sum_power2_eq_zero_iff:
huffman@22967
   175
  fixes x y :: "'a::{ordered_idom,recpower}"
huffman@22967
   176
  shows "(x\<twosuperior> + y\<twosuperior> = 0) = (x = 0 \<and> y = 0)"
huffman@22967
   177
unfolding power2_eq_square by (rule sum_squares_eq_zero_iff)
huffman@22967
   178
huffman@22967
   179
lemma sum_power2_le_zero_iff:
huffman@22967
   180
  fixes x y :: "'a::{ordered_idom,recpower}"
huffman@22967
   181
  shows "(x\<twosuperior> + y\<twosuperior> \<le> 0) = (x = 0 \<and> y = 0)"
huffman@22967
   182
unfolding power2_eq_square by (rule sum_squares_le_zero_iff)
huffman@22967
   183
huffman@22967
   184
lemma sum_power2_gt_zero_iff:
huffman@22967
   185
  fixes x y :: "'a::{ordered_idom,recpower}"
huffman@22967
   186
  shows "(0 < x\<twosuperior> + y\<twosuperior>) = (x \<noteq> 0 \<or> y \<noteq> 0)"
huffman@22967
   187
unfolding power2_eq_square by (rule sum_squares_gt_zero_iff)
huffman@22967
   188
huffman@22967
   189
huffman@22970
   190
subsection{* Squares of Reals *}
huffman@22970
   191
huffman@22970
   192
lemma real_two_squares_add_zero_iff [simp]:
huffman@22970
   193
  "(x * x + y * y = 0) = ((x::real) = 0 \<and> y = 0)"
huffman@22970
   194
by (rule sum_squares_eq_zero_iff)
huffman@22970
   195
huffman@22970
   196
lemma real_sum_squares_cancel: "x * x + y * y = 0 ==> x = (0::real)"
huffman@22970
   197
by simp
huffman@22970
   198
huffman@22970
   199
lemma real_sum_squares_cancel2: "x * x + y * y = 0 ==> y = (0::real)"
huffman@22970
   200
by simp
huffman@22970
   201
huffman@22970
   202
lemma real_mult_self_sum_ge_zero: "(0::real) \<le> x*x + y*y"
huffman@22970
   203
by (rule sum_squares_ge_zero)
paulson@14268
   204
paulson@14268
   205
lemma real_sum_squares_cancel_a: "x * x = -(y * y) ==> x = (0::real) & y=0"
huffman@22970
   206
by (simp add: real_add_eq_0_iff [symmetric])
paulson@14268
   207
paulson@14268
   208
lemma real_squared_diff_one_factored: "x*x - (1::real) = (x + 1)*(x - 1)"
huffman@22970
   209
by (simp add: left_distrib right_diff_distrib)
paulson@14268
   210
paulson@14348
   211
lemma real_mult_is_one [simp]: "(x*x = (1::real)) = (x = 1 | x = - 1)"
paulson@14268
   212
apply auto
paulson@14268
   213
apply (drule right_minus_eq [THEN iffD2]) 
paulson@14268
   214
apply (auto simp add: real_squared_diff_one_factored)
paulson@14268
   215
done
paulson@14268
   216
huffman@22970
   217
lemma real_sum_squares_not_zero: "x ~= 0 ==> x * x + y * y ~= (0::real)"
huffman@22970
   218
by simp
huffman@22970
   219
huffman@22970
   220
lemma real_sum_squares_not_zero2: "y ~= 0 ==> x * x + y * y ~= (0::real)"
huffman@22970
   221
by simp
huffman@22970
   222
huffman@22970
   223
lemma realpow_two_sum_zero_iff [simp]:
huffman@22970
   224
     "(x ^ 2 + y ^ 2 = (0::real)) = (x = 0 & y = 0)"
huffman@22970
   225
by (rule sum_power2_eq_zero_iff)
huffman@22970
   226
huffman@22970
   227
lemma realpow_two_le_add_order [simp]: "(0::real) \<le> u ^ 2 + v ^ 2"
huffman@22970
   228
by (rule sum_power2_ge_zero)
huffman@22970
   229
huffman@22970
   230
lemma realpow_two_le_add_order2 [simp]: "(0::real) \<le> u ^ 2 + v ^ 2 + w ^ 2"
huffman@22970
   231
by (intro add_nonneg_nonneg zero_le_power2)
huffman@22970
   232
huffman@22970
   233
lemma real_sum_square_gt_zero: "x ~= 0 ==> (0::real) < x * x + y * y"
huffman@22970
   234
by (simp add: sum_squares_gt_zero_iff)
huffman@22970
   235
huffman@22970
   236
lemma real_sum_square_gt_zero2: "y ~= 0 ==> (0::real) < x * x + y * y"
huffman@22970
   237
by (simp add: sum_squares_gt_zero_iff)
huffman@22970
   238
huffman@22970
   239
lemma real_minus_mult_self_le [simp]: "-(u * u) \<le> (x * (x::real))"
huffman@22970
   240
by (rule_tac j = 0 in real_le_trans, auto)
huffman@22970
   241
huffman@22970
   242
lemma realpow_square_minus_le [simp]: "-(u ^ 2) \<le> (x::real) ^ 2"
huffman@22970
   243
by (auto simp add: power2_eq_square)
huffman@22970
   244
huffman@22970
   245
(* The following theorem is by Benjamin Porter *)
huffman@22970
   246
lemma real_sq_order:
huffman@22970
   247
  fixes x::real
huffman@22970
   248
  assumes xgt0: "0 \<le> x" and ygt0: "0 \<le> y" and sq: "x^2 \<le> y^2"
huffman@22970
   249
  shows "x \<le> y"
huffman@22970
   250
proof -
huffman@22970
   251
  from sq have "x ^ Suc (Suc 0) \<le> y ^ Suc (Suc 0)"
huffman@22970
   252
    by (simp only: numeral_2_eq_2)
huffman@22970
   253
  thus "x \<le> y" using ygt0
huffman@22970
   254
    by (rule power_le_imp_le_base)
huffman@22970
   255
qed
huffman@22970
   256
huffman@22970
   257
huffman@22970
   258
subsection {*Various Other Theorems*}
huffman@22970
   259
paulson@14304
   260
lemma real_le_add_half_cancel: "(x + y/2 \<le> (y::real)) = (x \<le> y /2)"
paulson@14348
   261
by auto
paulson@14268
   262
paulson@14348
   263
lemma real_minus_half_eq [simp]: "(x::real) - x/2 = x/2"
paulson@14348
   264
by auto
paulson@14268
   265
paulson@14268
   266
lemma real_mult_inverse_cancel:
paulson@14268
   267
     "[|(0::real) < x; 0 < x1; x1 * y < x * u |] 
paulson@14268
   268
      ==> inverse x * y < inverse x1 * u"
paulson@14268
   269
apply (rule_tac c=x in mult_less_imp_less_left) 
paulson@14268
   270
apply (auto simp add: real_mult_assoc [symmetric])
paulson@14334
   271
apply (simp (no_asm) add: mult_ac)
paulson@14268
   272
apply (rule_tac c=x1 in mult_less_imp_less_right) 
paulson@14334
   273
apply (auto simp add: mult_ac)
paulson@14268
   274
done
paulson@14268
   275
paulson@14348
   276
lemma real_mult_inverse_cancel2:
paulson@14348
   277
     "[|(0::real) < x;0 < x1; x1 * y < x * u |] ==> y * inverse x < u * inverse x1"
paulson@14334
   278
apply (auto dest: real_mult_inverse_cancel simp add: mult_ac)
paulson@14268
   279
done
paulson@14268
   280
paulson@14348
   281
lemma inverse_real_of_nat_gt_zero [simp]: "0 < inverse (real (Suc n))"
huffman@20517
   282
by simp
paulson@14268
   283
paulson@14348
   284
lemma inverse_real_of_nat_ge_zero [simp]: "0 \<le> inverse (real (Suc n))"
huffman@20517
   285
by simp
paulson@14268
   286
paulson@14268
   287
lemma realpow_num_eq_if: "(m::real) ^ n = (if n=0 then 1 else m * m ^ (n - 1))"
paulson@14348
   288
by (case_tac "n", auto)
paulson@14268
   289
paulson@7077
   290
end