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