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