src/HOL/RealPow.thy
author wenzelm
Mon Mar 22 20:58:52 2010 +0100 (2010-03-22)
changeset 35898 c890a3835d15
parent 35632 61fd75e33137
child 36777 be5461582d0f
permissions -rw-r--r--
recovered header;
     1 (*  Title       : HOL/RealPow.thy
     2     Author      : Jacques D. Fleuriot  
     3     Copyright   : 1998  University of Cambridge
     4 *)
     5 
     6 header {* Natural powers theory *}
     7 
     8 theory RealPow
     9 imports RealDef RComplete
    10 begin
    11 
    12 (* FIXME: declare this in Rings.thy or not at all *)
    13 declare abs_mult_self [simp]
    14 
    15 (* used by Import/HOL/real.imp *)
    16 lemma two_realpow_ge_one: "(1::real) \<le> 2 ^ n"
    17 by simp
    18 
    19 lemma two_realpow_gt [simp]: "real (n::nat) < 2 ^ n"
    20 apply (induct "n")
    21 apply (auto simp add: real_of_nat_Suc)
    22 apply (subst mult_2)
    23 apply (erule add_less_le_mono)
    24 apply (rule two_realpow_ge_one)
    25 done
    26 
    27 (* TODO: no longer real-specific; rename and move elsewhere *)
    28 lemma realpow_Suc_le_self:
    29   fixes r :: "'a::linordered_semidom"
    30   shows "[| 0 \<le> r; r \<le> 1 |] ==> r ^ Suc n \<le> r"
    31 by (insert power_decreasing [of 1 "Suc n" r], simp)
    32 
    33 (* TODO: no longer real-specific; rename and move elsewhere *)
    34 lemma realpow_minus_mult:
    35   fixes x :: "'a::monoid_mult"
    36   shows "0 < n \<Longrightarrow> x ^ (n - 1) * x = x ^ n"
    37 by (simp add: power_commutes split add: nat_diff_split)
    38 
    39 (* TODO: no longer real-specific; rename and move elsewhere *)
    40 lemma realpow_two_diff:
    41   fixes x :: "'a::comm_ring_1"
    42   shows "x^Suc (Suc 0) - y^Suc (Suc 0) = (x - y) * (x + y)"
    43 by (simp add: algebra_simps)
    44 
    45 (* TODO: move elsewhere *)
    46 lemma add_eq_0_iff:
    47   fixes x y :: "'a::group_add"
    48   shows "x + y = 0 \<longleftrightarrow> y = - x"
    49 by (auto dest: minus_unique)
    50 
    51 (* TODO: no longer real-specific; rename and move elsewhere *)
    52 lemma realpow_two_disj:
    53   fixes x :: "'a::idom"
    54   shows "(x^Suc (Suc 0) = y^Suc (Suc 0)) = (x = y | x = -y)"
    55 using realpow_two_diff [of x y]
    56 by (auto simp add: add_eq_0_iff)
    57 
    58 
    59 subsection{* Squares of Reals *}
    60 
    61 (* FIXME: declare this [simp] for all types, or not at all *)
    62 lemma real_two_squares_add_zero_iff [simp]:
    63   "(x * x + y * y = 0) = ((x::real) = 0 \<and> y = 0)"
    64 by (rule sum_squares_eq_zero_iff)
    65 
    66 (* TODO: no longer real-specific; rename and move elsewhere *)
    67 lemma real_squared_diff_one_factored:
    68   fixes x :: "'a::ring_1"
    69   shows "x * x - 1 = (x + 1) * (x - 1)"
    70 by (simp add: algebra_simps)
    71 
    72 (* TODO: no longer real-specific; rename and move elsewhere *)
    73 lemma real_mult_is_one [simp]:
    74   fixes x :: "'a::ring_1_no_zero_divisors"
    75   shows "x * x = 1 \<longleftrightarrow> x = 1 \<or> x = - 1"
    76 proof -
    77   have "x * x = 1 \<longleftrightarrow> (x + 1) * (x - 1) = 0"
    78     by (simp add: algebra_simps)
    79   also have "\<dots> \<longleftrightarrow> x = 1 \<or> x = - 1"
    80     by (auto simp add: add_eq_0_iff minus_equation_iff [of _ 1])
    81   finally show ?thesis .
    82 qed
    83 
    84 (* FIXME: declare this [simp] for all types, or not at all *)
    85 lemma realpow_two_sum_zero_iff [simp]:
    86      "(x ^ 2 + y ^ 2 = (0::real)) = (x = 0 & y = 0)"
    87 by (rule sum_power2_eq_zero_iff)
    88 
    89 (* FIXME: declare this [simp] for all types, or not at all *)
    90 lemma realpow_two_le_add_order [simp]: "(0::real) \<le> u ^ 2 + v ^ 2"
    91 by (rule sum_power2_ge_zero)
    92 
    93 (* FIXME: declare this [simp] for all types, or not at all *)
    94 lemma realpow_two_le_add_order2 [simp]: "(0::real) \<le> u ^ 2 + v ^ 2 + w ^ 2"
    95 by (intro add_nonneg_nonneg zero_le_power2)
    96 
    97 lemma real_minus_mult_self_le [simp]: "-(u * u) \<le> (x * (x::real))"
    98 by (rule_tac j = 0 in real_le_trans, auto)
    99 
   100 lemma realpow_square_minus_le [simp]: "-(u ^ 2) \<le> (x::real) ^ 2"
   101 by (auto simp add: power2_eq_square)
   102 
   103 (* The following theorem is by Benjamin Porter *)
   104 (* TODO: no longer real-specific; rename and move elsewhere *)
   105 lemma real_sq_order:
   106   fixes x :: "'a::linordered_semidom"
   107   assumes xgt0: "0 \<le> x" and ygt0: "0 \<le> y" and sq: "x^2 \<le> y^2"
   108   shows "x \<le> y"
   109 proof -
   110   from sq have "x ^ Suc (Suc 0) \<le> y ^ Suc (Suc 0)"
   111     by (simp only: numeral_2_eq_2)
   112   thus "x \<le> y" using ygt0
   113     by (rule power_le_imp_le_base)
   114 qed
   115 
   116 subsection {*Floor*}
   117 
   118 lemma floor_power:
   119   assumes "x = real (floor x)"
   120   shows "floor (x ^ n) = floor x ^ n"
   121 proof -
   122   have *: "x ^ n = real (floor x ^ n)"
   123     using assms by (induct n arbitrary: x) simp_all
   124   show ?thesis unfolding real_of_int_inject[symmetric]
   125     unfolding * floor_real_of_int ..
   126 qed
   127 
   128 lemma natfloor_power:
   129   assumes "x = real (natfloor x)"
   130   shows "natfloor (x ^ n) = natfloor x ^ n"
   131 proof -
   132   from assms have "0 \<le> floor x" by auto
   133   note assms[unfolded natfloor_def real_nat_eq_real[OF `0 \<le> floor x`]]
   134   from floor_power[OF this]
   135   show ?thesis unfolding natfloor_def nat_power_eq[OF `0 \<le> floor x`, symmetric]
   136     by simp
   137 qed
   138 
   139 subsection {*Various Other Theorems*}
   140 
   141 lemma real_le_add_half_cancel: "(x + y/2 \<le> (y::real)) = (x \<le> y /2)"
   142 by auto
   143 
   144 lemma real_mult_inverse_cancel:
   145      "[|(0::real) < x; 0 < x1; x1 * y < x * u |] 
   146       ==> inverse x * y < inverse x1 * u"
   147 apply (rule_tac c=x in mult_less_imp_less_left) 
   148 apply (auto simp add: real_mult_assoc [symmetric])
   149 apply (simp (no_asm) add: mult_ac)
   150 apply (rule_tac c=x1 in mult_less_imp_less_right) 
   151 apply (auto simp add: mult_ac)
   152 done
   153 
   154 lemma real_mult_inverse_cancel2:
   155      "[|(0::real) < x;0 < x1; x1 * y < x * u |] ==> y * inverse x < u * inverse x1"
   156 apply (auto dest: real_mult_inverse_cancel simp add: mult_ac)
   157 done
   158 
   159 (* TODO: no longer real-specific; rename and move elsewhere *)
   160 lemma realpow_num_eq_if:
   161   fixes m :: "'a::power"
   162   shows "m ^ n = (if n=0 then 1 else m * m ^ (n - 1))"
   163 by (cases n, auto)
   164 
   165 
   166 end