src/HOL/Power.thy
author nipkow
Wed Aug 18 11:09:40 2004 +0200 (2004-08-18)
changeset 15140 322485b816ac
parent 15131 c69542757a4d
child 15251 bb6f072c8d10
permissions -rw-r--r--
import -> imports
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
paulson@14348
     8
header{*Exponentiation and Binomial Coefficients*}
paulson@14348
     9
nipkow@15131
    10
theory Power
nipkow@15140
    11
imports Divides
nipkow@15131
    12
begin
paulson@14348
    13
paulson@15066
    14
subsection{*Powers for Arbitrary Semirings*}
paulson@14348
    15
paulson@15004
    16
axclass recpower \<subseteq> comm_semiring_1_cancel, power
paulson@15004
    17
  power_0 [simp]: "a ^ 0       = 1"
paulson@15004
    18
  power_Suc:      "a ^ (Suc n) = a * (a ^ n)"
paulson@14348
    19
paulson@15004
    20
lemma power_0_Suc [simp]: "(0::'a::recpower) ^ (Suc n) = 0"
paulson@14348
    21
by (simp add: power_Suc)
paulson@14348
    22
paulson@14348
    23
text{*It looks plausible as a simprule, but its effect can be strange.*}
paulson@15004
    24
lemma power_0_left: "0^n = (if n=0 then 1 else (0::'a::recpower))"
paulson@14348
    25
by (induct_tac "n", auto)
paulson@14348
    26
paulson@15004
    27
lemma power_one [simp]: "1^n = (1::'a::recpower)"
paulson@14348
    28
apply (induct_tac "n")
wenzelm@14577
    29
apply (auto simp add: power_Suc)
paulson@14348
    30
done
paulson@14348
    31
paulson@15004
    32
lemma power_one_right [simp]: "(a::'a::recpower) ^ 1 = a"
paulson@14348
    33
by (simp add: power_Suc)
paulson@14348
    34
paulson@15004
    35
lemma power_add: "(a::'a::recpower) ^ (m+n) = (a^m) * (a^n)"
paulson@14348
    36
apply (induct_tac "n")
paulson@14348
    37
apply (simp_all add: power_Suc mult_ac)
paulson@14348
    38
done
paulson@14348
    39
paulson@15004
    40
lemma power_mult: "(a::'a::recpower) ^ (m*n) = (a^m) ^ n"
paulson@14348
    41
apply (induct_tac "n")
paulson@14348
    42
apply (simp_all add: power_Suc power_add)
paulson@14348
    43
done
paulson@14348
    44
paulson@15004
    45
lemma power_mult_distrib: "((a::'a::recpower) * b) ^ n = (a^n) * (b^n)"
wenzelm@14577
    46
apply (induct_tac "n")
paulson@14348
    47
apply (auto simp add: power_Suc mult_ac)
paulson@14348
    48
done
paulson@14348
    49
paulson@14348
    50
lemma zero_less_power:
paulson@15004
    51
     "0 < (a::'a::{ordered_semidom,recpower}) ==> 0 < a^n"
paulson@14348
    52
apply (induct_tac "n")
paulson@14348
    53
apply (simp_all add: power_Suc zero_less_one mult_pos)
paulson@14348
    54
done
paulson@14348
    55
paulson@14348
    56
lemma zero_le_power:
paulson@15004
    57
     "0 \<le> (a::'a::{ordered_semidom,recpower}) ==> 0 \<le> a^n"
paulson@14348
    58
apply (simp add: order_le_less)
wenzelm@14577
    59
apply (erule disjE)
paulson@14348
    60
apply (simp_all add: zero_less_power zero_less_one power_0_left)
paulson@14348
    61
done
paulson@14348
    62
paulson@14348
    63
lemma one_le_power:
paulson@15004
    64
     "1 \<le> (a::'a::{ordered_semidom,recpower}) ==> 1 \<le> a^n"
paulson@14348
    65
apply (induct_tac "n")
paulson@14348
    66
apply (simp_all add: power_Suc)
wenzelm@14577
    67
apply (rule order_trans [OF _ mult_mono [of 1 _ 1]])
wenzelm@14577
    68
apply (simp_all add: zero_le_one order_trans [OF zero_le_one])
paulson@14348
    69
done
paulson@14348
    70
obua@14738
    71
lemma gt1_imp_ge0: "1 < a ==> 0 \<le> (a::'a::ordered_semidom)"
paulson@14348
    72
  by (simp add: order_trans [OF zero_le_one order_less_imp_le])
paulson@14348
    73
paulson@14348
    74
lemma power_gt1_lemma:
paulson@15004
    75
  assumes gt1: "1 < (a::'a::{ordered_semidom,recpower})"
wenzelm@14577
    76
  shows "1 < a * a^n"
paulson@14348
    77
proof -
wenzelm@14577
    78
  have "1*1 < a*1" using gt1 by simp
wenzelm@14577
    79
  also have "\<dots> \<le> a * a^n" using gt1
wenzelm@14577
    80
    by (simp only: mult_mono gt1_imp_ge0 one_le_power order_less_imp_le
wenzelm@14577
    81
        zero_le_one order_refl)
wenzelm@14577
    82
  finally show ?thesis by simp
paulson@14348
    83
qed
paulson@14348
    84
paulson@14348
    85
lemma power_gt1:
paulson@15004
    86
     "1 < (a::'a::{ordered_semidom,recpower}) ==> 1 < a ^ (Suc n)"
paulson@14348
    87
by (simp add: power_gt1_lemma power_Suc)
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
wenzelm@14577
   100
    from prems have "a * a^m \<le> 1" by (simp add: power_Suc)
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
wenzelm@14577
   108
          simp add: power_Suc 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"
wenzelm@14577
   127
apply (induct_tac "n")
paulson@14348
   128
apply (simp_all add: power_Suc)
paulson@14348
   129
apply (auto intro: mult_mono zero_le_power 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"
wenzelm@14577
   135
apply (induct_tac "n")
paulson@14348
   136
apply (auto simp add: mult_strict_mono zero_le_power power_Suc
paulson@14348
   137
                      order_le_less_trans [of 0 a b])
paulson@14348
   138
done
paulson@14348
   139
paulson@14348
   140
lemma power_eq_0_iff [simp]:
paulson@15004
   141
     "(a^n = 0) = (a = (0::'a::{ordered_idom,recpower}) & 0<n)"
paulson@14348
   142
apply (induct_tac "n")
paulson@14348
   143
apply (auto simp add: power_Suc zero_neq_one [THEN not_sym])
paulson@14348
   144
done
paulson@14348
   145
paulson@14348
   146
lemma field_power_eq_0_iff [simp]:
paulson@15004
   147
     "(a^n = 0) = (a = (0::'a::{field,recpower}) & 0<n)"
paulson@14348
   148
apply (induct_tac "n")
paulson@14348
   149
apply (auto simp add: power_Suc field_mult_eq_0_iff zero_neq_one[THEN not_sym])
paulson@14348
   150
done
paulson@14348
   151
paulson@15004
   152
lemma field_power_not_zero: "a \<noteq> (0::'a::{field,recpower}) ==> a^n \<noteq> 0"
paulson@14348
   153
by force
paulson@14348
   154
paulson@14353
   155
lemma nonzero_power_inverse:
paulson@15004
   156
  "a \<noteq> 0 ==> inverse ((a::'a::{field,recpower}) ^ n) = (inverse a) ^ n"
paulson@14353
   157
apply (induct_tac "n")
paulson@14353
   158
apply (auto simp add: power_Suc nonzero_inverse_mult_distrib mult_commute)
paulson@14353
   159
done
paulson@14353
   160
paulson@14348
   161
text{*Perhaps these should be simprules.*}
paulson@14348
   162
lemma power_inverse:
paulson@15004
   163
  "inverse ((a::'a::{field,division_by_zero,recpower}) ^ n) = (inverse a) ^ n"
paulson@14348
   164
apply (induct_tac "n")
paulson@14348
   165
apply (auto simp add: power_Suc inverse_mult_distrib)
paulson@14348
   166
done
paulson@14348
   167
wenzelm@14577
   168
lemma nonzero_power_divide:
paulson@15004
   169
    "b \<noteq> 0 ==> (a/b) ^ n = ((a::'a::{field,recpower}) ^ n) / (b ^ n)"
paulson@14353
   170
by (simp add: divide_inverse power_mult_distrib nonzero_power_inverse)
paulson@14353
   171
wenzelm@14577
   172
lemma power_divide:
paulson@15004
   173
    "(a/b) ^ n = ((a::'a::{field,division_by_zero,recpower}) ^ n / b ^ n)"
paulson@14353
   174
apply (case_tac "b=0", simp add: power_0_left)
wenzelm@14577
   175
apply (rule nonzero_power_divide)
wenzelm@14577
   176
apply assumption
paulson@14353
   177
done
paulson@14353
   178
paulson@15004
   179
lemma power_abs: "abs(a ^ n) = abs(a::'a::{ordered_idom,recpower}) ^ n"
paulson@14348
   180
apply (induct_tac "n")
paulson@14348
   181
apply (auto simp add: power_Suc abs_mult)
paulson@14348
   182
done
paulson@14348
   183
paulson@14353
   184
lemma zero_less_power_abs_iff [simp]:
paulson@15004
   185
     "(0 < (abs a)^n) = (a \<noteq> (0::'a::{ordered_idom,recpower}) | n=0)"
paulson@14353
   186
proof (induct "n")
paulson@14353
   187
  case 0
paulson@14353
   188
    show ?case by (simp add: zero_less_one)
paulson@14353
   189
next
paulson@14353
   190
  case (Suc n)
paulson@14353
   191
    show ?case by (force simp add: prems power_Suc zero_less_mult_iff)
paulson@14353
   192
qed
paulson@14353
   193
paulson@14353
   194
lemma zero_le_power_abs [simp]:
paulson@15004
   195
     "(0::'a::{ordered_idom,recpower}) \<le> (abs a)^n"
paulson@14353
   196
apply (induct_tac "n")
paulson@14353
   197
apply (auto simp add: zero_le_one zero_le_power)
paulson@14353
   198
done
paulson@14353
   199
paulson@15004
   200
lemma power_minus: "(-a) ^ n = (- 1)^n * (a::'a::{comm_ring_1,recpower}) ^ n"
paulson@14348
   201
proof -
paulson@14348
   202
  have "-a = (- 1) * a"  by (simp add: minus_mult_left [symmetric])
paulson@14348
   203
  thus ?thesis by (simp only: power_mult_distrib)
paulson@14348
   204
qed
paulson@14348
   205
paulson@14348
   206
text{*Lemma for @{text power_strict_decreasing}*}
paulson@14348
   207
lemma power_Suc_less:
paulson@15004
   208
     "[|(0::'a::{ordered_semidom,recpower}) < a; a < 1|]
paulson@14348
   209
      ==> a * a^n < a^n"
wenzelm@14577
   210
apply (induct_tac n)
wenzelm@14577
   211
apply (auto simp add: power_Suc mult_strict_left_mono)
paulson@14348
   212
done
paulson@14348
   213
paulson@14348
   214
lemma power_strict_decreasing:
paulson@15004
   215
     "[|n < N; 0 < a; a < (1::'a::{ordered_semidom,recpower})|]
paulson@14348
   216
      ==> a^N < a^n"
wenzelm@14577
   217
apply (erule rev_mp)
wenzelm@14577
   218
apply (induct_tac "N")
wenzelm@14577
   219
apply (auto simp add: power_Suc power_Suc_less less_Suc_eq)
wenzelm@14577
   220
apply (rename_tac m)
paulson@14348
   221
apply (subgoal_tac "a * a^m < 1 * a^n", simp)
wenzelm@14577
   222
apply (rule mult_strict_mono)
paulson@14348
   223
apply (auto simp add: zero_le_power zero_less_one order_less_imp_le)
paulson@14348
   224
done
paulson@14348
   225
paulson@14348
   226
text{*Proof resembles that of @{text power_strict_decreasing}*}
paulson@14348
   227
lemma power_decreasing:
paulson@15004
   228
     "[|n \<le> N; 0 \<le> a; a \<le> (1::'a::{ordered_semidom,recpower})|]
paulson@14348
   229
      ==> a^N \<le> a^n"
wenzelm@14577
   230
apply (erule rev_mp)
wenzelm@14577
   231
apply (induct_tac "N")
wenzelm@14577
   232
apply (auto simp add: power_Suc  le_Suc_eq)
wenzelm@14577
   233
apply (rename_tac m)
paulson@14348
   234
apply (subgoal_tac "a * a^m \<le> 1 * a^n", simp)
wenzelm@14577
   235
apply (rule mult_mono)
paulson@14348
   236
apply (auto simp add: zero_le_power zero_le_one)
paulson@14348
   237
done
paulson@14348
   238
paulson@14348
   239
lemma power_Suc_less_one:
paulson@15004
   240
     "[| 0 < a; a < (1::'a::{ordered_semidom,recpower}) |] ==> a ^ Suc n < 1"
wenzelm@14577
   241
apply (insert power_strict_decreasing [of 0 "Suc n" a], simp)
paulson@14348
   242
done
paulson@14348
   243
paulson@14348
   244
text{*Proof again resembles that of @{text power_strict_decreasing}*}
paulson@14348
   245
lemma power_increasing:
paulson@15004
   246
     "[|n \<le> N; (1::'a::{ordered_semidom,recpower}) \<le> a|] ==> a^n \<le> a^N"
wenzelm@14577
   247
apply (erule rev_mp)
wenzelm@14577
   248
apply (induct_tac "N")
wenzelm@14577
   249
apply (auto simp add: power_Suc le_Suc_eq)
paulson@14348
   250
apply (rename_tac m)
paulson@14348
   251
apply (subgoal_tac "1 * a^n \<le> a * a^m", simp)
wenzelm@14577
   252
apply (rule mult_mono)
paulson@14348
   253
apply (auto simp add: order_trans [OF zero_le_one] zero_le_power)
paulson@14348
   254
done
paulson@14348
   255
paulson@14348
   256
text{*Lemma for @{text power_strict_increasing}*}
paulson@14348
   257
lemma power_less_power_Suc:
paulson@15004
   258
     "(1::'a::{ordered_semidom,recpower}) < a ==> a^n < a * a^n"
wenzelm@14577
   259
apply (induct_tac n)
wenzelm@14577
   260
apply (auto simp add: power_Suc mult_strict_left_mono order_less_trans [OF zero_less_one])
paulson@14348
   261
done
paulson@14348
   262
paulson@14348
   263
lemma power_strict_increasing:
paulson@15004
   264
     "[|n < N; (1::'a::{ordered_semidom,recpower}) < a|] ==> a^n < a^N"
wenzelm@14577
   265
apply (erule rev_mp)
wenzelm@14577
   266
apply (induct_tac "N")
wenzelm@14577
   267
apply (auto simp add: power_less_power_Suc power_Suc less_Suc_eq)
paulson@14348
   268
apply (rename_tac m)
paulson@14348
   269
apply (subgoal_tac "1 * a^n < a * a^m", simp)
wenzelm@14577
   270
apply (rule mult_strict_mono)
paulson@14348
   271
apply (auto simp add: order_less_trans [OF zero_less_one] zero_le_power
paulson@14348
   272
                 order_less_imp_le)
paulson@14348
   273
done
paulson@14348
   274
paulson@15066
   275
lemma power_increasing_iff [simp]: 
paulson@15066
   276
     "1 < (b::'a::{ordered_semidom,recpower}) ==> (b ^ x \<le> b ^ y) = (x \<le> y)"
paulson@15066
   277
  by (blast intro: power_le_imp_le_exp power_increasing order_less_imp_le) 
paulson@15066
   278
paulson@15066
   279
lemma power_strict_increasing_iff [simp]:
paulson@15066
   280
     "1 < (b::'a::{ordered_semidom,recpower}) ==> (b ^ x < b ^ y) = (x < y)"
paulson@15066
   281
  by (blast intro: power_less_imp_less_exp power_strict_increasing) 
paulson@15066
   282
paulson@14348
   283
lemma power_le_imp_le_base:
paulson@14348
   284
  assumes le: "a ^ Suc n \<le> b ^ Suc n"
paulson@15004
   285
      and xnonneg: "(0::'a::{ordered_semidom,recpower}) \<le> a"
paulson@14348
   286
      and ynonneg: "0 \<le> b"
paulson@14348
   287
  shows "a \<le> b"
paulson@14348
   288
 proof (rule ccontr)
paulson@14348
   289
   assume "~ a \<le> b"
paulson@14348
   290
   then have "b < a" by (simp only: linorder_not_le)
paulson@14348
   291
   then have "b ^ Suc n < a ^ Suc n"
wenzelm@14577
   292
     by (simp only: prems power_strict_mono)
paulson@14348
   293
   from le and this show "False"
paulson@14348
   294
      by (simp add: linorder_not_less [symmetric])
paulson@14348
   295
 qed
wenzelm@14577
   296
paulson@14348
   297
lemma power_inject_base:
wenzelm@14577
   298
     "[| a ^ Suc n = b ^ Suc n; 0 \<le> a; 0 \<le> b |]
paulson@15004
   299
      ==> a = (b::'a::{ordered_semidom,recpower})"
paulson@14348
   300
by (blast intro: power_le_imp_le_base order_antisym order_eq_refl sym)
paulson@14348
   301
paulson@14348
   302
paulson@14348
   303
subsection{*Exponentiation for the Natural Numbers*}
paulson@3390
   304
wenzelm@8844
   305
primrec (power)
paulson@3390
   306
  "p ^ 0 = 1"
paulson@3390
   307
  "p ^ (Suc n) = (p::nat) * (p ^ n)"
wenzelm@14577
   308
paulson@15004
   309
instance nat :: recpower
paulson@14348
   310
proof
paulson@14438
   311
  fix z n :: nat
paulson@14348
   312
  show "z^0 = 1" by simp
paulson@14348
   313
  show "z^(Suc n) = z * (z^n)" by simp
paulson@14348
   314
qed
paulson@14348
   315
paulson@14348
   316
lemma nat_one_le_power [simp]: "1 \<le> i ==> Suc 0 \<le> i^n"
paulson@14348
   317
by (insert one_le_power [of i n], simp)
paulson@14348
   318
paulson@14348
   319
lemma le_imp_power_dvd: "!!i::nat. m \<le> n ==> i^m dvd i^n"
paulson@14348
   320
apply (unfold dvd_def)
paulson@14348
   321
apply (erule not_less_iff_le [THEN iffD2, THEN add_diff_inverse, THEN subst])
paulson@14348
   322
apply (simp add: power_add)
paulson@14348
   323
done
paulson@14348
   324
paulson@14348
   325
text{*Valid for the naturals, but what if @{text"0<i<1"}?
paulson@14348
   326
Premises cannot be weakened: consider the case where @{term "i=0"},
paulson@14348
   327
@{term "m=1"} and @{term "n=0"}.*}
paulson@14348
   328
lemma nat_power_less_imp_less: "!!i::nat. [| 0 < i; i^m < i^n |] ==> m < n"
paulson@14348
   329
apply (rule ccontr)
paulson@14348
   330
apply (drule leI [THEN le_imp_power_dvd, THEN dvd_imp_le, THEN leD])
wenzelm@14577
   331
apply (erule zero_less_power, auto)
paulson@14348
   332
done
paulson@14348
   333
paulson@14348
   334
lemma nat_zero_less_power_iff [simp]: "(0 < x^n) = (x \<noteq> (0::nat) | n=0)"
paulson@14348
   335
by (induct_tac "n", auto)
paulson@14348
   336
paulson@14348
   337
lemma power_le_dvd [rule_format]: "k^j dvd n --> i\<le>j --> k^i dvd (n::nat)"
paulson@14348
   338
apply (induct_tac "j")
paulson@14348
   339
apply (simp_all add: le_Suc_eq)
paulson@14348
   340
apply (blast dest!: dvd_mult_right)
paulson@14348
   341
done
paulson@14348
   342
paulson@14348
   343
lemma power_dvd_imp_le: "[|i^m dvd i^n;  (1::nat) < i|] ==> m \<le> n"
paulson@14348
   344
apply (rule power_le_imp_le_exp, assumption)
paulson@14348
   345
apply (erule dvd_imp_le, simp)
paulson@14348
   346
done
paulson@14348
   347
paulson@14348
   348
paulson@14348
   349
subsection{*Binomial Coefficients*}
paulson@14348
   350
wenzelm@14577
   351
text{*This development is based on the work of Andy Gordon and
paulson@14348
   352
Florian Kammueller*}
paulson@14348
   353
paulson@14348
   354
consts
paulson@14348
   355
  binomial :: "[nat,nat] => nat"      (infixl "choose" 65)
paulson@14348
   356
berghofe@5183
   357
primrec
paulson@14348
   358
  binomial_0:   "(0     choose k) = (if k = 0 then 1 else 0)"
paulson@14348
   359
paulson@14348
   360
  binomial_Suc: "(Suc n choose k) =
paulson@14348
   361
                 (if k = 0 then 1 else (n choose (k - 1)) + (n choose k))"
paulson@14348
   362
paulson@14348
   363
lemma binomial_n_0 [simp]: "(n choose 0) = 1"
paulson@14348
   364
by (case_tac "n", simp_all)
paulson@14348
   365
paulson@14348
   366
lemma binomial_0_Suc [simp]: "(0 choose Suc k) = 0"
paulson@14348
   367
by simp
paulson@14348
   368
paulson@14348
   369
lemma binomial_Suc_Suc [simp]:
paulson@14348
   370
     "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)"
paulson@14348
   371
by simp
paulson@14348
   372
paulson@14348
   373
lemma binomial_eq_0 [rule_format]: "\<forall>k. n < k --> (n choose k) = 0"
paulson@14348
   374
apply (induct_tac "n", auto)
paulson@14348
   375
apply (erule allE)
paulson@14348
   376
apply (erule mp, arith)
paulson@14348
   377
done
paulson@14348
   378
paulson@14348
   379
declare binomial_0 [simp del] binomial_Suc [simp del]
paulson@14348
   380
paulson@14348
   381
lemma binomial_n_n [simp]: "(n choose n) = 1"
paulson@14348
   382
apply (induct_tac "n")
paulson@14348
   383
apply (simp_all add: binomial_eq_0)
paulson@14348
   384
done
paulson@14348
   385
paulson@14348
   386
lemma binomial_Suc_n [simp]: "(Suc n choose n) = Suc n"
paulson@14348
   387
by (induct_tac "n", simp_all)
paulson@14348
   388
paulson@14348
   389
lemma binomial_1 [simp]: "(n choose Suc 0) = n"
paulson@14348
   390
by (induct_tac "n", simp_all)
paulson@14348
   391
paulson@14348
   392
lemma zero_less_binomial [rule_format]: "k \<le> n --> 0 < (n choose k)"
paulson@14348
   393
by (rule_tac m = n and n = k in diff_induct, simp_all)
paulson@3390
   394
paulson@14348
   395
lemma binomial_eq_0_iff: "(n choose k = 0) = (n<k)"
paulson@14348
   396
apply (safe intro!: binomial_eq_0)
paulson@14348
   397
apply (erule contrapos_pp)
paulson@14348
   398
apply (simp add: zero_less_binomial)
paulson@14348
   399
done
paulson@14348
   400
paulson@14348
   401
lemma zero_less_binomial_iff: "(0 < n choose k) = (k\<le>n)"
paulson@14348
   402
by (simp add: linorder_not_less [symmetric] binomial_eq_0_iff [symmetric])
paulson@14348
   403
paulson@14348
   404
(*Might be more useful if re-oriented*)
paulson@14348
   405
lemma Suc_times_binomial_eq [rule_format]:
paulson@14348
   406
     "\<forall>k. k \<le> n --> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"
paulson@14348
   407
apply (induct_tac "n")
paulson@14348
   408
apply (simp add: binomial_0, clarify)
paulson@14348
   409
apply (case_tac "k")
wenzelm@14577
   410
apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq
paulson@14348
   411
                      binomial_eq_0)
paulson@14348
   412
done
paulson@14348
   413
paulson@14348
   414
text{*This is the well-known version, but it's harder to use because of the
paulson@14348
   415
  need to reason about division.*}
paulson@14348
   416
lemma binomial_Suc_Suc_eq_times:
paulson@14348
   417
     "k \<le> n ==> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k"
wenzelm@14577
   418
by (simp add: Suc_times_binomial_eq div_mult_self_is_m zero_less_Suc
paulson@14348
   419
        del: mult_Suc mult_Suc_right)
paulson@14348
   420
paulson@14348
   421
text{*Another version, with -1 instead of Suc.*}
paulson@14348
   422
lemma times_binomial_minus1_eq:
paulson@14348
   423
     "[|k \<le> n;  0<k|] ==> (n choose k) * k = n * ((n - 1) choose (k - 1))"
paulson@14348
   424
apply (cut_tac n = "n - 1" and k = "k - 1" in Suc_times_binomial_eq)
paulson@14348
   425
apply (simp split add: nat_diff_split, auto)
paulson@14348
   426
done
paulson@14348
   427
paulson@14348
   428
text{*ML bindings for the general exponentiation theorems*}
paulson@14348
   429
ML
paulson@14348
   430
{*
paulson@14348
   431
val power_0 = thm"power_0";
paulson@14348
   432
val power_Suc = thm"power_Suc";
paulson@14348
   433
val power_0_Suc = thm"power_0_Suc";
paulson@14348
   434
val power_0_left = thm"power_0_left";
paulson@14348
   435
val power_one = thm"power_one";
paulson@14348
   436
val power_one_right = thm"power_one_right";
paulson@14348
   437
val power_add = thm"power_add";
paulson@14348
   438
val power_mult = thm"power_mult";
paulson@14348
   439
val power_mult_distrib = thm"power_mult_distrib";
paulson@14348
   440
val zero_less_power = thm"zero_less_power";
paulson@14348
   441
val zero_le_power = thm"zero_le_power";
paulson@14348
   442
val one_le_power = thm"one_le_power";
paulson@14348
   443
val gt1_imp_ge0 = thm"gt1_imp_ge0";
paulson@14348
   444
val power_gt1_lemma = thm"power_gt1_lemma";
paulson@14348
   445
val power_gt1 = thm"power_gt1";
paulson@14348
   446
val power_le_imp_le_exp = thm"power_le_imp_le_exp";
paulson@14348
   447
val power_inject_exp = thm"power_inject_exp";
paulson@14348
   448
val power_less_imp_less_exp = thm"power_less_imp_less_exp";
paulson@14348
   449
val power_mono = thm"power_mono";
paulson@14348
   450
val power_strict_mono = thm"power_strict_mono";
paulson@14348
   451
val power_eq_0_iff = thm"power_eq_0_iff";
paulson@14348
   452
val field_power_eq_0_iff = thm"field_power_eq_0_iff";
paulson@14348
   453
val field_power_not_zero = thm"field_power_not_zero";
paulson@14348
   454
val power_inverse = thm"power_inverse";
paulson@14353
   455
val nonzero_power_divide = thm"nonzero_power_divide";
paulson@14353
   456
val power_divide = thm"power_divide";
paulson@14348
   457
val power_abs = thm"power_abs";
paulson@14353
   458
val zero_less_power_abs_iff = thm"zero_less_power_abs_iff";
paulson@14353
   459
val zero_le_power_abs = thm "zero_le_power_abs";
paulson@14348
   460
val power_minus = thm"power_minus";
paulson@14348
   461
val power_Suc_less = thm"power_Suc_less";
paulson@14348
   462
val power_strict_decreasing = thm"power_strict_decreasing";
paulson@14348
   463
val power_decreasing = thm"power_decreasing";
paulson@14348
   464
val power_Suc_less_one = thm"power_Suc_less_one";
paulson@14348
   465
val power_increasing = thm"power_increasing";
paulson@14348
   466
val power_strict_increasing = thm"power_strict_increasing";
paulson@14348
   467
val power_le_imp_le_base = thm"power_le_imp_le_base";
paulson@14348
   468
val power_inject_base = thm"power_inject_base";
paulson@14348
   469
*}
wenzelm@14577
   470
paulson@14348
   471
text{*ML bindings for the remaining theorems*}
paulson@14348
   472
ML
paulson@14348
   473
{*
paulson@14348
   474
val nat_one_le_power = thm"nat_one_le_power";
paulson@14348
   475
val le_imp_power_dvd = thm"le_imp_power_dvd";
paulson@14348
   476
val nat_power_less_imp_less = thm"nat_power_less_imp_less";
paulson@14348
   477
val nat_zero_less_power_iff = thm"nat_zero_less_power_iff";
paulson@14348
   478
val power_le_dvd = thm"power_le_dvd";
paulson@14348
   479
val power_dvd_imp_le = thm"power_dvd_imp_le";
paulson@14348
   480
val binomial_n_0 = thm"binomial_n_0";
paulson@14348
   481
val binomial_0_Suc = thm"binomial_0_Suc";
paulson@14348
   482
val binomial_Suc_Suc = thm"binomial_Suc_Suc";
paulson@14348
   483
val binomial_eq_0 = thm"binomial_eq_0";
paulson@14348
   484
val binomial_n_n = thm"binomial_n_n";
paulson@14348
   485
val binomial_Suc_n = thm"binomial_Suc_n";
paulson@14348
   486
val binomial_1 = thm"binomial_1";
paulson@14348
   487
val zero_less_binomial = thm"zero_less_binomial";
paulson@14348
   488
val binomial_eq_0_iff = thm"binomial_eq_0_iff";
paulson@14348
   489
val zero_less_binomial_iff = thm"zero_less_binomial_iff";
paulson@14348
   490
val Suc_times_binomial_eq = thm"Suc_times_binomial_eq";
paulson@14348
   491
val binomial_Suc_Suc_eq_times = thm"binomial_Suc_Suc_eq_times";
paulson@14348
   492
val times_binomial_minus1_eq = thm"times_binomial_minus1_eq";
paulson@14348
   493
*}
paulson@3390
   494
paulson@3390
   495
end
paulson@3390
   496