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