src/HOL/Real/RealPow.thy
author ballarin
Fri Mar 17 10:04:27 2006 +0100 (2006-03-17)
changeset 19279 48b527d0331b
parent 15251 bb6f072c8d10
child 19765 dfe940911617
permissions -rw-r--r--
Renamed setsum_mult to setsum_right_distrib.
     1 (*  Title       : HOL/Real/RealPow.thy
     2     ID          : $Id$
     3     Author      : Jacques D. Fleuriot  
     4     Copyright   : 1998  University of Cambridge
     5     Description : Natural powers theory
     6 
     7 *)
     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_not_zero: "r \<noteq> (0::real) ==> r ^ n \<noteq> 0"
    32   by (rule field_power_not_zero)
    33 
    34 lemma realpow_zero_zero: "r ^ n = (0::real) ==> r = 0"
    35 by simp
    36 
    37 lemma realpow_two: "(r::real)^ (Suc (Suc 0)) = r * r"
    38 by simp
    39 
    40 text{*Legacy: weaker version of the theorem @{text power_strict_mono},
    41 used 6 times in NthRoot and Transcendental*}
    42 lemma realpow_less:
    43      "[|(0::real) < x; x < y; 0 < n|] ==> x ^ n < y ^ n"
    44 apply (rule power_strict_mono, auto) 
    45 done
    46 
    47 lemma realpow_two_le [simp]: "(0::real) \<le> r^ Suc (Suc 0)"
    48 by (simp add: real_le_square)
    49 
    50 lemma abs_realpow_two [simp]: "abs((x::real)^Suc (Suc 0)) = x^Suc (Suc 0)"
    51 by (simp add: abs_mult)
    52 
    53 lemma realpow_two_abs [simp]: "abs(x::real)^Suc (Suc 0) = x^Suc (Suc 0)"
    54 by (simp add: power_abs [symmetric] del: realpow_Suc)
    55 
    56 lemma two_realpow_ge_one [simp]: "(1::real) \<le> 2 ^ n"
    57 by (insert power_increasing [of 0 n "2::real"], simp)
    58 
    59 lemma two_realpow_gt [simp]: "real (n::nat) < 2 ^ n"
    60 apply (induct "n")
    61 apply (auto simp add: real_of_nat_Suc)
    62 apply (subst mult_2)
    63 apply (rule real_add_less_le_mono)
    64 apply (auto simp add: two_realpow_ge_one)
    65 done
    66 
    67 lemma realpow_Suc_le_self: "[| 0 \<le> r; r \<le> (1::real) |] ==> r ^ Suc n \<le> r"
    68 by (insert power_decreasing [of 1 "Suc n" r], simp)
    69 
    70 text{*Used ONCE in Transcendental*}
    71 lemma realpow_Suc_less_one: "[| 0 < r; r < (1::real) |] ==> r ^ Suc n < 1"
    72 by (insert power_strict_decreasing [of 0 "Suc n" r], simp)
    73 
    74 text{*Used ONCE in Lim.ML*}
    75 lemma realpow_minus_mult [rule_format]:
    76      "0 < n --> (x::real) ^ (n - 1) * x = x ^ n" 
    77 apply (simp split add: nat_diff_split)
    78 done
    79 
    80 lemma realpow_two_mult_inverse [simp]:
    81      "r \<noteq> 0 ==> r * inverse r ^Suc (Suc 0) = inverse (r::real)"
    82 by (simp add: realpow_two real_mult_assoc [symmetric])
    83 
    84 lemma realpow_two_minus [simp]: "(-x)^Suc (Suc 0) = (x::real)^Suc (Suc 0)"
    85 by simp
    86 
    87 lemma realpow_two_diff:
    88      "(x::real)^Suc (Suc 0) - y^Suc (Suc 0) = (x - y) * (x + y)"
    89 apply (unfold real_diff_def)
    90 apply (simp add: right_distrib left_distrib mult_ac)
    91 done
    92 
    93 lemma realpow_two_disj:
    94      "((x::real)^Suc (Suc 0) = y^Suc (Suc 0)) = (x = y | x = -y)"
    95 apply (cut_tac x = x and y = y in realpow_two_diff)
    96 apply (auto simp del: realpow_Suc)
    97 done
    98 
    99 lemma realpow_real_of_nat: "real (m::nat) ^ n = real (m ^ n)"
   100 apply (induct "n")
   101 apply (auto simp add: real_of_nat_one real_of_nat_mult)
   102 done
   103 
   104 lemma realpow_real_of_nat_two_pos [simp] : "0 < real (Suc (Suc 0) ^ n)"
   105 apply (induct "n")
   106 apply (auto simp add: real_of_nat_mult zero_less_mult_iff)
   107 done
   108 
   109 lemma realpow_increasing:
   110      "[|(0::real) \<le> x; 0 \<le> y; x ^ Suc n \<le> y ^ Suc n|] ==> x \<le> y"
   111   by (rule power_le_imp_le_base)
   112 
   113 
   114 lemma zero_less_realpow_abs_iff [simp]:
   115      "(0 < (abs x)^n) = (x \<noteq> (0::real) | n=0)" 
   116 apply (induct "n")
   117 apply (auto simp add: zero_less_mult_iff)
   118 done
   119 
   120 lemma zero_le_realpow_abs [simp]: "(0::real) \<le> (abs x)^n"
   121 apply (induct "n")
   122 apply (auto simp add: zero_le_mult_iff)
   123 done
   124 
   125 
   126 subsection{*Literal Arithmetic Involving Powers, Type @{typ real}*}
   127 
   128 lemma real_of_int_power: "real (x::int) ^ n = real (x ^ n)"
   129 apply (induct "n")
   130 apply (simp_all add: nat_mult_distrib)
   131 done
   132 declare real_of_int_power [symmetric, simp]
   133 
   134 lemma power_real_number_of:
   135      "(number_of v :: real) ^ n = real ((number_of v :: int) ^ n)"
   136 by (simp only: real_number_of [symmetric] real_of_int_power)
   137 
   138 declare power_real_number_of [of _ "number_of w", standard, simp]
   139 
   140 
   141 subsection{*Various Other Theorems*}
   142 
   143 text{*Used several times in Hyperreal/Transcendental.ML*}
   144 lemma real_sum_squares_cancel_a: "x * x = -(y * y) ==> x = (0::real) & y=0"
   145   apply (auto dest: real_sum_squares_cancel simp add: real_add_eq_0_iff [symmetric])
   146   apply (auto dest: real_sum_squares_cancel simp add: add_commute)
   147   done
   148 
   149 lemma real_squared_diff_one_factored: "x*x - (1::real) = (x + 1)*(x - 1)"
   150 by (auto simp add: left_distrib right_distrib real_diff_def)
   151 
   152 lemma real_mult_is_one [simp]: "(x*x = (1::real)) = (x = 1 | x = - 1)"
   153 apply auto
   154 apply (drule right_minus_eq [THEN iffD2]) 
   155 apply (auto simp add: real_squared_diff_one_factored)
   156 done
   157 
   158 lemma real_le_add_half_cancel: "(x + y/2 \<le> (y::real)) = (x \<le> y /2)"
   159 by auto
   160 
   161 lemma real_minus_half_eq [simp]: "(x::real) - x/2 = x/2"
   162 by auto
   163 
   164 lemma real_mult_inverse_cancel:
   165      "[|(0::real) < x; 0 < x1; x1 * y < x * u |] 
   166       ==> inverse x * y < inverse x1 * u"
   167 apply (rule_tac c=x in mult_less_imp_less_left) 
   168 apply (auto simp add: real_mult_assoc [symmetric])
   169 apply (simp (no_asm) add: mult_ac)
   170 apply (rule_tac c=x1 in mult_less_imp_less_right) 
   171 apply (auto simp add: mult_ac)
   172 done
   173 
   174 text{*Used once: in Hyperreal/Transcendental.ML*}
   175 lemma real_mult_inverse_cancel2:
   176      "[|(0::real) < x;0 < x1; x1 * y < x * u |] ==> y * inverse x < u * inverse x1"
   177 apply (auto dest: real_mult_inverse_cancel simp add: mult_ac)
   178 done
   179 
   180 lemma inverse_real_of_nat_gt_zero [simp]: "0 < inverse (real (Suc n))"
   181 by auto
   182 
   183 lemma inverse_real_of_nat_ge_zero [simp]: "0 \<le> inverse (real (Suc n))"
   184 by auto
   185 
   186 lemma real_sum_squares_not_zero: "x ~= 0 ==> x * x + y * y ~= (0::real)"
   187 by (blast dest!: real_sum_squares_cancel)
   188 
   189 lemma real_sum_squares_not_zero2: "y ~= 0 ==> x * x + y * y ~= (0::real)"
   190 by (blast dest!: real_sum_squares_cancel2)
   191 
   192 
   193 subsection {*Various Other Theorems*}
   194 
   195 lemma realpow_divide: 
   196     "(x/y) ^ n = ((x::real) ^ n/ y ^ n)"
   197 apply (unfold real_divide_def)
   198 apply (auto simp add: power_mult_distrib power_inverse)
   199 done
   200 
   201 lemma realpow_two_sum_zero_iff [simp]:
   202      "(x ^ 2 + y ^ 2 = (0::real)) = (x = 0 & y = 0)"
   203 apply (auto intro: real_sum_squares_cancel real_sum_squares_cancel2 
   204                    simp add: power2_eq_square)
   205 done
   206 
   207 lemma realpow_two_le_add_order [simp]: "(0::real) \<le> u ^ 2 + v ^ 2"
   208 apply (rule real_le_add_order)
   209 apply (auto simp add: power2_eq_square)
   210 done
   211 
   212 lemma realpow_two_le_add_order2 [simp]: "(0::real) \<le> u ^ 2 + v ^ 2 + w ^ 2"
   213 apply (rule real_le_add_order)+
   214 apply (auto simp add: power2_eq_square)
   215 done
   216 
   217 lemma real_sum_square_gt_zero: "x ~= 0 ==> (0::real) < x * x + y * y"
   218 apply (cut_tac x = x and y = y in real_mult_self_sum_ge_zero)
   219 apply (drule real_le_imp_less_or_eq)
   220 apply (drule_tac y = y in real_sum_squares_not_zero, auto)
   221 done
   222 
   223 lemma real_sum_square_gt_zero2: "y ~= 0 ==> (0::real) < x * x + y * y"
   224 apply (rule real_add_commute [THEN subst])
   225 apply (erule real_sum_square_gt_zero)
   226 done
   227 
   228 lemma real_minus_mult_self_le [simp]: "-(u * u) \<le> (x * (x::real))"
   229 by (rule_tac j = 0 in real_le_trans, auto)
   230 
   231 lemma realpow_square_minus_le [simp]: "-(u ^ 2) \<le> (x::real) ^ 2"
   232 by (auto simp add: power2_eq_square)
   233 
   234 (* The following theorem is by Benjamin Porter *)
   235 lemma real_sq_order:
   236   fixes x::real
   237   assumes xgt0: "0 \<le> x" and ygt0: "0 \<le> y" and sq: "x^2 \<le> y^2"
   238   shows "x \<le> y"
   239 proof (rule ccontr)
   240   assume "\<not>(x \<le> y)"
   241   then have ylx: "y < x" by simp
   242   hence "y \<le> x" by simp
   243   with xgt0 have "x*y \<le> x*x"
   244     by (simp add: pordered_comm_semiring_class.mult_mono)
   245   moreover
   246   have "\<not> (y = 0)"
   247   proof
   248     assume "y = 0"
   249     with ylx have xg0: "0 < x" by simp
   250     from xg0 xg0 have "0 < x*x" by (rule real_mult_order)
   251     moreover have "y*y = 0" by simp
   252     ultimately show False using sq by auto
   253   qed
   254   with ygt0 have "0 < y" by simp
   255   with ylx have "y*y < x*y" by auto
   256   ultimately have "y*y < x*x" by simp
   257   with sq show False by (auto simp add: power2_eq_square [symmetric])
   258 qed
   259 
   260 lemma realpow_num_eq_if: "(m::real) ^ n = (if n=0 then 1 else m * m ^ (n - 1))"
   261 by (case_tac "n", auto)
   262 
   263 lemma real_num_zero_less_two_pow [simp]: "0 < (2::real) ^ (4*d)"
   264 apply (induct "d")
   265 apply (auto simp add: realpow_num_eq_if)
   266 done
   267 
   268 lemma lemma_realpow_num_two_mono:
   269      "x * (4::real)   < y ==> x * (2 ^ 8) < y * (2 ^ 6)"
   270 apply (subgoal_tac " (2::real) ^ 8 = 4 * (2 ^ 6) ")
   271 apply (simp (no_asm_simp) add: real_mult_assoc [symmetric])
   272 apply (auto simp add: realpow_num_eq_if)
   273 done
   274 
   275 
   276 ML
   277 {*
   278 val realpow_0 = thm "realpow_0";
   279 val realpow_Suc = thm "realpow_Suc";
   280 
   281 val realpow_not_zero = thm "realpow_not_zero";
   282 val realpow_zero_zero = thm "realpow_zero_zero";
   283 val realpow_two = thm "realpow_two";
   284 val realpow_less = thm "realpow_less";
   285 val realpow_two_le = thm "realpow_two_le";
   286 val abs_realpow_two = thm "abs_realpow_two";
   287 val realpow_two_abs = thm "realpow_two_abs";
   288 val two_realpow_ge_one = thm "two_realpow_ge_one";
   289 val two_realpow_gt = thm "two_realpow_gt";
   290 val realpow_Suc_le_self = thm "realpow_Suc_le_self";
   291 val realpow_Suc_less_one = thm "realpow_Suc_less_one";
   292 val realpow_minus_mult = thm "realpow_minus_mult";
   293 val realpow_two_mult_inverse = thm "realpow_two_mult_inverse";
   294 val realpow_two_minus = thm "realpow_two_minus";
   295 val realpow_two_disj = thm "realpow_two_disj";
   296 val realpow_real_of_nat = thm "realpow_real_of_nat";
   297 val realpow_real_of_nat_two_pos = thm "realpow_real_of_nat_two_pos";
   298 val realpow_increasing = thm "realpow_increasing";
   299 val zero_less_realpow_abs_iff = thm "zero_less_realpow_abs_iff";
   300 val zero_le_realpow_abs = thm "zero_le_realpow_abs";
   301 val real_of_int_power = thm "real_of_int_power";
   302 val power_real_number_of = thm "power_real_number_of";
   303 val real_sum_squares_cancel_a = thm "real_sum_squares_cancel_a";
   304 val real_mult_inverse_cancel2 = thm "real_mult_inverse_cancel2";
   305 val real_squared_diff_one_factored = thm "real_squared_diff_one_factored";
   306 val real_mult_is_one = thm "real_mult_is_one";
   307 val real_le_add_half_cancel = thm "real_le_add_half_cancel";
   308 val real_minus_half_eq = thm "real_minus_half_eq";
   309 val real_mult_inverse_cancel = thm "real_mult_inverse_cancel";
   310 val real_mult_inverse_cancel2 = thm "real_mult_inverse_cancel2";
   311 val inverse_real_of_nat_gt_zero = thm "inverse_real_of_nat_gt_zero";
   312 val inverse_real_of_nat_ge_zero = thm "inverse_real_of_nat_ge_zero";
   313 val real_sum_squares_not_zero = thm "real_sum_squares_not_zero";
   314 val real_sum_squares_not_zero2 = thm "real_sum_squares_not_zero2";
   315 
   316 val realpow_divide = thm "realpow_divide";
   317 val realpow_two_sum_zero_iff = thm "realpow_two_sum_zero_iff";
   318 val realpow_two_le_add_order = thm "realpow_two_le_add_order";
   319 val realpow_two_le_add_order2 = thm "realpow_two_le_add_order2";
   320 val real_sum_square_gt_zero = thm "real_sum_square_gt_zero";
   321 val real_sum_square_gt_zero2 = thm "real_sum_square_gt_zero2";
   322 val real_minus_mult_self_le = thm "real_minus_mult_self_le";
   323 val realpow_square_minus_le = thm "realpow_square_minus_le";
   324 val realpow_num_eq_if = thm "realpow_num_eq_if";
   325 val real_num_zero_less_two_pow = thm "real_num_zero_less_two_pow";
   326 val lemma_realpow_num_two_mono = thm "lemma_realpow_num_two_mono";
   327 *}
   328 
   329 
   330 end