src/HOL/Power.thy
author wenzelm
Mon Mar 16 18:24:30 2009 +0100 (2009-03-16)
changeset 30549 d2d7874648bd
parent 30516 68b4a06cbd5c
child 30730 4d3565f2cb0e
permissions -rw-r--r--
simplified method setup;
paulson@3390
     1
(*  Title:      HOL/Power.thy
paulson@3390
     2
    ID:         $Id$
paulson@3390
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@3390
     4
    Copyright   1997  University of Cambridge
paulson@3390
     5
paulson@3390
     6
*)
paulson@3390
     7
nipkow@16733
     8
header{*Exponentiation*}
paulson@14348
     9
nipkow@15131
    10
theory Power
haftmann@21413
    11
imports Nat
nipkow@15131
    12
begin
paulson@14348
    13
haftmann@29608
    14
class power =
haftmann@25062
    15
  fixes power :: "'a \<Rightarrow> nat \<Rightarrow> 'a"            (infixr "^" 80)
haftmann@24996
    16
krauss@21199
    17
subsection{*Powers for Arbitrary Monoids*}
paulson@14348
    18
haftmann@22390
    19
class recpower = monoid_mult + power +
haftmann@25062
    20
  assumes power_0 [simp]: "a ^ 0       = 1"
huffman@30273
    21
  assumes power_Suc [simp]: "a ^ Suc n = a * (a ^ n)"
paulson@14348
    22
krauss@21199
    23
lemma power_0_Suc [simp]: "(0::'a::{recpower,semiring_0}) ^ (Suc n) = 0"
huffman@30273
    24
  by simp
paulson@14348
    25
paulson@14348
    26
text{*It looks plausible as a simprule, but its effect can be strange.*}
krauss@21199
    27
lemma power_0_left: "0^n = (if n=0 then 1 else (0::'a::{recpower,semiring_0}))"
haftmann@23183
    28
  by (induct n) simp_all
paulson@14348
    29
paulson@15004
    30
lemma power_one [simp]: "1^n = (1::'a::recpower)"
huffman@30273
    31
  by (induct n) simp_all
paulson@14348
    32
paulson@15004
    33
lemma power_one_right [simp]: "(a::'a::recpower) ^ 1 = a"
huffman@30273
    34
  unfolding One_nat_def by simp
paulson@14348
    35
krauss@21199
    36
lemma power_commutes: "(a::'a::recpower) ^ n * a = a * a ^ n"
huffman@30273
    37
  by (induct n) (simp_all add: mult_assoc)
krauss@21199
    38
huffman@28131
    39
lemma power_Suc2: "(a::'a::recpower) ^ Suc n = a ^ n * a"
huffman@30273
    40
  by (simp add: power_commutes)
huffman@28131
    41
paulson@15004
    42
lemma power_add: "(a::'a::recpower) ^ (m+n) = (a^m) * (a^n)"
huffman@30273
    43
  by (induct m) (simp_all add: mult_ac)
paulson@14348
    44
paulson@15004
    45
lemma power_mult: "(a::'a::recpower) ^ (m*n) = (a^m) ^ n"
huffman@30273
    46
  by (induct n) (simp_all add: power_add)
paulson@14348
    47
krauss@21199
    48
lemma power_mult_distrib: "((a::'a::{recpower,comm_monoid_mult}) * b) ^ n = (a^n) * (b^n)"
huffman@30273
    49
  by (induct n) (simp_all add: mult_ac)
paulson@14348
    50
nipkow@25874
    51
lemma zero_less_power[simp]:
paulson@15004
    52
     "0 < (a::'a::{ordered_semidom,recpower}) ==> 0 < a^n"
huffman@30273
    53
by (induct n) (simp_all add: mult_pos_pos)
paulson@14348
    54
nipkow@25874
    55
lemma zero_le_power[simp]:
paulson@15004
    56
     "0 \<le> (a::'a::{ordered_semidom,recpower}) ==> 0 \<le> a^n"
huffman@30273
    57
by (induct n) (simp_all add: mult_nonneg_nonneg)
paulson@14348
    58
nipkow@25874
    59
lemma one_le_power[simp]:
paulson@15004
    60
     "1 \<le> (a::'a::{ordered_semidom,recpower}) ==> 1 \<le> a^n"
paulson@15251
    61
apply (induct "n")
huffman@30273
    62
apply simp_all
wenzelm@14577
    63
apply (rule order_trans [OF _ mult_mono [of 1 _ 1]])
huffman@30273
    64
apply (simp_all add: order_trans [OF zero_le_one])
paulson@14348
    65
done
paulson@14348
    66
obua@14738
    67
lemma gt1_imp_ge0: "1 < a ==> 0 \<le> (a::'a::ordered_semidom)"
paulson@14348
    68
  by (simp add: order_trans [OF zero_le_one order_less_imp_le])
paulson@14348
    69
paulson@14348
    70
lemma power_gt1_lemma:
paulson@15004
    71
  assumes gt1: "1 < (a::'a::{ordered_semidom,recpower})"
wenzelm@14577
    72
  shows "1 < a * a^n"
paulson@14348
    73
proof -
wenzelm@14577
    74
  have "1*1 < a*1" using gt1 by simp
wenzelm@14577
    75
  also have "\<dots> \<le> a * a^n" using gt1
wenzelm@14577
    76
    by (simp only: mult_mono gt1_imp_ge0 one_le_power order_less_imp_le
wenzelm@14577
    77
        zero_le_one order_refl)
wenzelm@14577
    78
  finally show ?thesis by simp
paulson@14348
    79
qed
paulson@14348
    80
nipkow@25874
    81
lemma one_less_power[simp]:
huffman@24376
    82
  "\<lbrakk>1 < (a::'a::{ordered_semidom,recpower}); 0 < n\<rbrakk> \<Longrightarrow> 1 < a ^ n"
huffman@30273
    83
by (cases n, simp_all add: power_gt1_lemma)
huffman@24376
    84
paulson@14348
    85
lemma power_gt1:
paulson@15004
    86
     "1 < (a::'a::{ordered_semidom,recpower}) ==> 1 < a ^ (Suc n)"
huffman@30273
    87
by (simp add: power_gt1_lemma)
paulson@14348
    88
paulson@14348
    89
lemma power_le_imp_le_exp:
paulson@15004
    90
  assumes gt1: "(1::'a::{recpower,ordered_semidom}) < a"
wenzelm@14577
    91
  shows "!!n. a^m \<le> a^n ==> m \<le> n"
wenzelm@14577
    92
proof (induct m)
paulson@14348
    93
  case 0
wenzelm@14577
    94
  show ?case by simp
paulson@14348
    95
next
paulson@14348
    96
  case (Suc m)
wenzelm@14577
    97
  show ?case
wenzelm@14577
    98
  proof (cases n)
wenzelm@14577
    99
    case 0
huffman@30273
   100
    from prems have "a * a^m \<le> 1" by simp
wenzelm@14577
   101
    with gt1 show ?thesis
wenzelm@14577
   102
      by (force simp only: power_gt1_lemma
wenzelm@14577
   103
          linorder_not_less [symmetric])
wenzelm@14577
   104
  next
wenzelm@14577
   105
    case (Suc n)
wenzelm@14577
   106
    from prems show ?thesis
wenzelm@14577
   107
      by (force dest: mult_left_le_imp_le
huffman@30273
   108
          simp add: order_less_trans [OF zero_less_one gt1])
wenzelm@14577
   109
  qed
paulson@14348
   110
qed
paulson@14348
   111
wenzelm@14577
   112
text{*Surely we can strengthen this? It holds for @{text "0<a<1"} too.*}
paulson@14348
   113
lemma power_inject_exp [simp]:
paulson@15004
   114
     "1 < (a::'a::{ordered_semidom,recpower}) ==> (a^m = a^n) = (m=n)"
wenzelm@14577
   115
  by (force simp add: order_antisym power_le_imp_le_exp)
paulson@14348
   116
paulson@14348
   117
text{*Can relax the first premise to @{term "0<a"} in the case of the
paulson@14348
   118
natural numbers.*}
paulson@14348
   119
lemma power_less_imp_less_exp:
paulson@15004
   120
     "[| (1::'a::{recpower,ordered_semidom}) < a; a^m < a^n |] ==> m < n"
wenzelm@14577
   121
by (simp add: order_less_le [of m n] order_less_le [of "a^m" "a^n"]
wenzelm@14577
   122
              power_le_imp_le_exp)
paulson@14348
   123
paulson@14348
   124
paulson@14348
   125
lemma power_mono:
paulson@15004
   126
     "[|a \<le> b; (0::'a::{recpower,ordered_semidom}) \<le> a|] ==> a^n \<le> b^n"
paulson@15251
   127
apply (induct "n")
huffman@30273
   128
apply simp_all
nipkow@25874
   129
apply (auto intro: mult_mono order_trans [of 0 a b])
paulson@14348
   130
done
paulson@14348
   131
paulson@14348
   132
lemma power_strict_mono [rule_format]:
paulson@15004
   133
     "[|a < b; (0::'a::{recpower,ordered_semidom}) \<le> a|]
wenzelm@14577
   134
      ==> 0 < n --> a^n < b^n"
paulson@15251
   135
apply (induct "n")
huffman@30273
   136
apply (auto simp add: mult_strict_mono order_le_less_trans [of 0 a b])
paulson@14348
   137
done
paulson@14348
   138
paulson@14348
   139
lemma power_eq_0_iff [simp]:
nipkow@30056
   140
  "(a^n = 0) \<longleftrightarrow>
nipkow@30056
   141
   (a = (0::'a::{mult_zero,zero_neq_one,no_zero_divisors,recpower}) & n\<noteq>0)"
paulson@15251
   142
apply (induct "n")
huffman@30273
   143
apply (auto simp add: no_zero_divisors)
paulson@14348
   144
done
paulson@14348
   145
nipkow@30056
   146
nipkow@25134
   147
lemma field_power_not_zero:
nipkow@25134
   148
  "a \<noteq> (0::'a::{ring_1_no_zero_divisors,recpower}) ==> a^n \<noteq> 0"
paulson@14348
   149
by force
paulson@14348
   150
paulson@14353
   151
lemma nonzero_power_inverse:
huffman@22991
   152
  fixes a :: "'a::{division_ring,recpower}"
huffman@22991
   153
  shows "a \<noteq> 0 ==> inverse (a ^ n) = (inverse a) ^ n"
paulson@15251
   154
apply (induct "n")
huffman@30273
   155
apply (auto simp add: nonzero_inverse_mult_distrib power_commutes)
huffman@22991
   156
done (* TODO: reorient or rename to nonzero_inverse_power *)
paulson@14353
   157
paulson@14348
   158
text{*Perhaps these should be simprules.*}
paulson@14348
   159
lemma power_inverse:
huffman@22991
   160
  fixes a :: "'a::{division_ring,division_by_zero,recpower}"
huffman@22991
   161
  shows "inverse (a ^ n) = (inverse a) ^ n"
huffman@22991
   162
apply (cases "a = 0")
huffman@22991
   163
apply (simp add: power_0_left)
huffman@22991
   164
apply (simp add: nonzero_power_inverse)
huffman@22991
   165
done (* TODO: reorient or rename to inverse_power *)
paulson@14348
   166
avigad@16775
   167
lemma power_one_over: "1 / (a::'a::{field,division_by_zero,recpower})^n = 
avigad@16775
   168
    (1 / a)^n"
avigad@16775
   169
apply (simp add: divide_inverse)
avigad@16775
   170
apply (rule power_inverse)
avigad@16775
   171
done
avigad@16775
   172
wenzelm@14577
   173
lemma nonzero_power_divide:
paulson@15004
   174
    "b \<noteq> 0 ==> (a/b) ^ n = ((a::'a::{field,recpower}) ^ n) / (b ^ n)"
paulson@14353
   175
by (simp add: divide_inverse power_mult_distrib nonzero_power_inverse)
paulson@14353
   176
wenzelm@14577
   177
lemma power_divide:
paulson@15004
   178
    "(a/b) ^ n = ((a::'a::{field,division_by_zero,recpower}) ^ n / b ^ n)"
paulson@14353
   179
apply (case_tac "b=0", simp add: power_0_left)
wenzelm@14577
   180
apply (rule nonzero_power_divide)
wenzelm@14577
   181
apply assumption
paulson@14353
   182
done
paulson@14353
   183
paulson@15004
   184
lemma power_abs: "abs(a ^ n) = abs(a::'a::{ordered_idom,recpower}) ^ n"
paulson@15251
   185
apply (induct "n")
huffman@30273
   186
apply (auto simp add: abs_mult)
paulson@14348
   187
done
paulson@14348
   188
paulson@24286
   189
lemma zero_less_power_abs_iff [simp,noatp]:
paulson@15004
   190
     "(0 < (abs a)^n) = (a \<noteq> (0::'a::{ordered_idom,recpower}) | n=0)"
paulson@14353
   191
proof (induct "n")
paulson@14353
   192
  case 0
huffman@30273
   193
    show ?case by simp
paulson@14353
   194
next
paulson@14353
   195
  case (Suc n)
huffman@30273
   196
    show ?case by (auto simp add: prems zero_less_mult_iff)
paulson@14353
   197
qed
paulson@14353
   198
paulson@14353
   199
lemma zero_le_power_abs [simp]:
paulson@15004
   200
     "(0::'a::{ordered_idom,recpower}) \<le> (abs a)^n"
huffman@22957
   201
by (rule zero_le_power [OF abs_ge_zero])
paulson@14353
   202
huffman@28131
   203
lemma power_minus: "(-a) ^ n = (- 1)^n * (a::'a::{ring_1,recpower}) ^ n"
huffman@28131
   204
proof (induct n)
huffman@28131
   205
  case 0 show ?case by simp
huffman@28131
   206
next
huffman@28131
   207
  case (Suc n) then show ?case
huffman@30273
   208
    by (simp del: power_Suc add: power_Suc2 mult_assoc)
paulson@14348
   209
qed
paulson@14348
   210
paulson@14348
   211
text{*Lemma for @{text power_strict_decreasing}*}
paulson@14348
   212
lemma power_Suc_less:
paulson@15004
   213
     "[|(0::'a::{ordered_semidom,recpower}) < a; a < 1|]
paulson@14348
   214
      ==> a * a^n < a^n"
paulson@15251
   215
apply (induct n)
huffman@30273
   216
apply (auto simp add: mult_strict_left_mono)
paulson@14348
   217
done
paulson@14348
   218
paulson@14348
   219
lemma power_strict_decreasing:
paulson@15004
   220
     "[|n < N; 0 < a; a < (1::'a::{ordered_semidom,recpower})|]
paulson@14348
   221
      ==> a^N < a^n"
wenzelm@14577
   222
apply (erule rev_mp)
paulson@15251
   223
apply (induct "N")
huffman@30273
   224
apply (auto simp add: power_Suc_less less_Suc_eq)
wenzelm@14577
   225
apply (rename_tac m)
paulson@14348
   226
apply (subgoal_tac "a * a^m < 1 * a^n", simp)
wenzelm@14577
   227
apply (rule mult_strict_mono)
huffman@30273
   228
apply (auto simp add: order_less_imp_le)
paulson@14348
   229
done
paulson@14348
   230
paulson@14348
   231
text{*Proof resembles that of @{text power_strict_decreasing}*}
paulson@14348
   232
lemma power_decreasing:
paulson@15004
   233
     "[|n \<le> N; 0 \<le> a; a \<le> (1::'a::{ordered_semidom,recpower})|]
paulson@14348
   234
      ==> a^N \<le> a^n"
wenzelm@14577
   235
apply (erule rev_mp)
paulson@15251
   236
apply (induct "N")
huffman@30273
   237
apply (auto simp add: le_Suc_eq)
wenzelm@14577
   238
apply (rename_tac m)
paulson@14348
   239
apply (subgoal_tac "a * a^m \<le> 1 * a^n", simp)
wenzelm@14577
   240
apply (rule mult_mono)
huffman@30273
   241
apply auto
paulson@14348
   242
done
paulson@14348
   243
paulson@14348
   244
lemma power_Suc_less_one:
paulson@15004
   245
     "[| 0 < a; a < (1::'a::{ordered_semidom,recpower}) |] ==> a ^ Suc n < 1"
wenzelm@14577
   246
apply (insert power_strict_decreasing [of 0 "Suc n" a], simp)
paulson@14348
   247
done
paulson@14348
   248
paulson@14348
   249
text{*Proof again resembles that of @{text power_strict_decreasing}*}
paulson@14348
   250
lemma power_increasing:
paulson@15004
   251
     "[|n \<le> N; (1::'a::{ordered_semidom,recpower}) \<le> a|] ==> a^n \<le> a^N"
wenzelm@14577
   252
apply (erule rev_mp)
paulson@15251
   253
apply (induct "N")
huffman@30273
   254
apply (auto simp add: le_Suc_eq)
paulson@14348
   255
apply (rename_tac m)
paulson@14348
   256
apply (subgoal_tac "1 * a^n \<le> a * a^m", simp)
wenzelm@14577
   257
apply (rule mult_mono)
nipkow@25874
   258
apply (auto simp add: order_trans [OF zero_le_one])
paulson@14348
   259
done
paulson@14348
   260
paulson@14348
   261
text{*Lemma for @{text power_strict_increasing}*}
paulson@14348
   262
lemma power_less_power_Suc:
paulson@15004
   263
     "(1::'a::{ordered_semidom,recpower}) < a ==> a^n < a * a^n"
paulson@15251
   264
apply (induct n)
huffman@30273
   265
apply (auto simp add: mult_strict_left_mono order_less_trans [OF zero_less_one])
paulson@14348
   266
done
paulson@14348
   267
paulson@14348
   268
lemma power_strict_increasing:
paulson@15004
   269
     "[|n < N; (1::'a::{ordered_semidom,recpower}) < a|] ==> a^n < a^N"
wenzelm@14577
   270
apply (erule rev_mp)
paulson@15251
   271
apply (induct "N")
huffman@30273
   272
apply (auto simp add: power_less_power_Suc less_Suc_eq)
paulson@14348
   273
apply (rename_tac m)
paulson@14348
   274
apply (subgoal_tac "1 * a^n < a * a^m", simp)
wenzelm@14577
   275
apply (rule mult_strict_mono)
nipkow@25874
   276
apply (auto simp add: order_less_trans [OF zero_less_one] order_less_imp_le)
paulson@14348
   277
done
paulson@14348
   278
nipkow@25134
   279
lemma power_increasing_iff [simp]:
nipkow@25134
   280
  "1 < (b::'a::{ordered_semidom,recpower}) ==> (b ^ x \<le> b ^ y) = (x \<le> y)"
nipkow@25134
   281
by (blast intro: power_le_imp_le_exp power_increasing order_less_imp_le) 
paulson@15066
   282
paulson@15066
   283
lemma power_strict_increasing_iff [simp]:
nipkow@25134
   284
  "1 < (b::'a::{ordered_semidom,recpower}) ==> (b ^ x < b ^ y) = (x < y)"
nipkow@25134
   285
by (blast intro: power_less_imp_less_exp power_strict_increasing) 
paulson@15066
   286
paulson@14348
   287
lemma power_le_imp_le_base:
nipkow@25134
   288
assumes le: "a ^ Suc n \<le> b ^ Suc n"
nipkow@25134
   289
    and ynonneg: "(0::'a::{ordered_semidom,recpower}) \<le> b"
nipkow@25134
   290
shows "a \<le> b"
nipkow@25134
   291
proof (rule ccontr)
nipkow@25134
   292
  assume "~ a \<le> b"
nipkow@25134
   293
  then have "b < a" by (simp only: linorder_not_le)
nipkow@25134
   294
  then have "b ^ Suc n < a ^ Suc n"
nipkow@25134
   295
    by (simp only: prems power_strict_mono)
nipkow@25134
   296
  from le and this show "False"
nipkow@25134
   297
    by (simp add: linorder_not_less [symmetric])
nipkow@25134
   298
qed
wenzelm@14577
   299
huffman@22853
   300
lemma power_less_imp_less_base:
huffman@22853
   301
  fixes a b :: "'a::{ordered_semidom,recpower}"
huffman@22853
   302
  assumes less: "a ^ n < b ^ n"
huffman@22853
   303
  assumes nonneg: "0 \<le> b"
huffman@22853
   304
  shows "a < b"
huffman@22853
   305
proof (rule contrapos_pp [OF less])
huffman@22853
   306
  assume "~ a < b"
huffman@22853
   307
  hence "b \<le> a" by (simp only: linorder_not_less)
huffman@22853
   308
  hence "b ^ n \<le> a ^ n" using nonneg by (rule power_mono)
huffman@22853
   309
  thus "~ a ^ n < b ^ n" by (simp only: linorder_not_less)
huffman@22853
   310
qed
huffman@22853
   311
paulson@14348
   312
lemma power_inject_base:
wenzelm@14577
   313
     "[| a ^ Suc n = b ^ Suc n; 0 \<le> a; 0 \<le> b |]
paulson@15004
   314
      ==> a = (b::'a::{ordered_semidom,recpower})"
paulson@14348
   315
by (blast intro: power_le_imp_le_base order_antisym order_eq_refl sym)
paulson@14348
   316
huffman@22955
   317
lemma power_eq_imp_eq_base:
huffman@22955
   318
  fixes a b :: "'a::{ordered_semidom,recpower}"
huffman@22955
   319
  shows "\<lbrakk>a ^ n = b ^ n; 0 \<le> a; 0 \<le> b; 0 < n\<rbrakk> \<Longrightarrow> a = b"
huffman@30273
   320
by (cases n, simp_all del: power_Suc, rule power_inject_base)
huffman@22955
   321
huffman@29978
   322
text {* The divides relation *}
huffman@29978
   323
huffman@29978
   324
lemma le_imp_power_dvd:
huffman@29978
   325
  fixes a :: "'a::{comm_semiring_1,recpower}"
huffman@29978
   326
  assumes "m \<le> n" shows "a^m dvd a^n"
huffman@29978
   327
proof
huffman@29978
   328
  have "a^n = a^(m + (n - m))"
huffman@29978
   329
    using `m \<le> n` by simp
huffman@29978
   330
  also have "\<dots> = a^m * a^(n - m)"
huffman@29978
   331
    by (rule power_add)
huffman@29978
   332
  finally show "a^n = a^m * a^(n - m)" .
huffman@29978
   333
qed
huffman@29978
   334
huffman@29978
   335
lemma power_le_dvd:
huffman@29978
   336
  fixes a b :: "'a::{comm_semiring_1,recpower}"
huffman@29978
   337
  shows "a^n dvd b \<Longrightarrow> m \<le> n \<Longrightarrow> a^m dvd b"
huffman@29978
   338
  by (rule dvd_trans [OF le_imp_power_dvd])
huffman@29978
   339
paulson@14348
   340
nipkow@30313
   341
lemma dvd_power_same:
nipkow@30313
   342
  "(x::'a::{comm_semiring_1,recpower}) dvd y \<Longrightarrow> x^n dvd y^n"
nipkow@30313
   343
by (induct n) (auto simp add: mult_dvd_mono)
nipkow@30313
   344
nipkow@30313
   345
lemma dvd_power_le:
nipkow@30313
   346
  "(x::'a::{comm_semiring_1,recpower}) dvd y \<Longrightarrow> m >= n \<Longrightarrow> x^n dvd y^m"
nipkow@30313
   347
by(rule power_le_dvd[OF dvd_power_same])
nipkow@30313
   348
nipkow@30313
   349
lemma dvd_power [simp]:
nipkow@30313
   350
  "n > 0 | (x::'a::{comm_semiring_1,recpower}) = 1 \<Longrightarrow> x dvd x^n"
nipkow@30313
   351
apply (erule disjE)
nipkow@30313
   352
 apply (subgoal_tac "x ^ n = x^(Suc (n - 1))")
nipkow@30313
   353
  apply (erule ssubst)
nipkow@30313
   354
  apply (subst power_Suc)
nipkow@30313
   355
  apply auto
nipkow@30313
   356
done
nipkow@30313
   357
nipkow@30313
   358
paulson@14348
   359
subsection{*Exponentiation for the Natural Numbers*}
paulson@3390
   360
haftmann@25836
   361
instantiation nat :: recpower
haftmann@25836
   362
begin
haftmann@21456
   363
haftmann@25836
   364
primrec power_nat where
haftmann@25836
   365
  "p ^ 0 = (1\<Colon>nat)"
haftmann@25836
   366
  | "p ^ (Suc n) = (p\<Colon>nat) * (p ^ n)"
wenzelm@14577
   367
haftmann@25836
   368
instance proof
paulson@14438
   369
  fix z n :: nat
paulson@14348
   370
  show "z^0 = 1" by simp
paulson@14348
   371
  show "z^(Suc n) = z * (z^n)" by simp
paulson@14348
   372
qed
paulson@14348
   373
huffman@30273
   374
declare power_nat.simps [simp del]
huffman@30273
   375
haftmann@25836
   376
end
haftmann@25836
   377
huffman@23305
   378
lemma of_nat_power:
huffman@23305
   379
  "of_nat (m ^ n) = (of_nat m::'a::{semiring_1,recpower}) ^ n"
huffman@30273
   380
by (induct n, simp_all add: of_nat_mult)
huffman@23305
   381
huffman@30079
   382
lemma nat_one_le_power [simp]: "Suc 0 \<le> i ==> Suc 0 \<le> i^n"
huffman@30079
   383
by (rule one_le_power [of i n, unfolded One_nat_def])
paulson@14348
   384
nipkow@25162
   385
lemma nat_zero_less_power_iff [simp]: "(x^n > 0) = (x > (0::nat) | n=0)"
haftmann@21413
   386
by (induct "n", auto)
paulson@14348
   387
nipkow@30056
   388
lemma nat_power_eq_Suc_0_iff [simp]: 
nipkow@30056
   389
  "((x::nat)^m = Suc 0) = (m = 0 | x = Suc 0)"
nipkow@30056
   390
by (induct_tac m, auto)
nipkow@30056
   391
nipkow@30056
   392
lemma power_Suc_0[simp]: "(Suc 0)^n = Suc 0"
nipkow@30056
   393
by simp
nipkow@30056
   394
paulson@14348
   395
text{*Valid for the naturals, but what if @{text"0<i<1"}?
paulson@14348
   396
Premises cannot be weakened: consider the case where @{term "i=0"},
paulson@14348
   397
@{term "m=1"} and @{term "n=0"}.*}
haftmann@21413
   398
lemma nat_power_less_imp_less:
haftmann@21413
   399
  assumes nonneg: "0 < (i\<Colon>nat)"
haftmann@21413
   400
  assumes less: "i^m < i^n"
haftmann@21413
   401
  shows "m < n"
haftmann@21413
   402
proof (cases "i = 1")
haftmann@21413
   403
  case True with less power_one [where 'a = nat] show ?thesis by simp
haftmann@21413
   404
next
haftmann@21413
   405
  case False with nonneg have "1 < i" by auto
haftmann@21413
   406
  from power_strict_increasing_iff [OF this] less show ?thesis ..
haftmann@21413
   407
qed
paulson@14348
   408
ballarin@17149
   409
lemma power_diff:
ballarin@17149
   410
  assumes nz: "a ~= 0"
ballarin@17149
   411
  shows "n <= m ==> (a::'a::{recpower, field}) ^ (m-n) = (a^m) / (a^n)"
ballarin@17149
   412
  by (induct m n rule: diff_induct)
huffman@30273
   413
    (simp_all add: nonzero_mult_divide_cancel_left nz)
ballarin@17149
   414
paulson@3390
   415
end