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