src/HOL/Library/Binomial.thy
author haftmann
Fri, 27 Dec 2013 14:35:14 +0100
changeset 54868 bab6cade3cc5
parent 54703 499f92dc6e45
child 55143 04448228381d
permissions -rw-r--r--
prefer target-style syntaxx for sublocale
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35372
ca158c7b1144 renamed theory Rational to Rat
haftmann
parents: 32960
diff changeset
     1
(*  Title:      HOL/Library/Binomial.thy
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
     2
    Author:     Lawrence C Paulson, Amine Chaieb
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     3
    Copyright   1997  University of Cambridge
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     4
*)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     5
21263
wenzelm
parents: 21256
diff changeset
     6
header {* Binomial Coefficients *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     7
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     8
theory Binomial
35372
ca158c7b1144 renamed theory Rational to Rat
haftmann
parents: 32960
diff changeset
     9
imports Complex_Main
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    10
begin
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    11
21263
wenzelm
parents: 21256
diff changeset
    12
text {* This development is based on the work of Andy Gordon and
wenzelm
parents: 21256
diff changeset
    13
  Florian Kammueller. *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    14
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
    15
subsection {* Basic definitions and lemmas *}
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
    16
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    17
primrec binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat" (infixl "choose" 65)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    18
where
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    19
  "0 choose k = (if k = 0 then 1 else 0)"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    20
| "Suc n choose k = (if k = 0 then 1 else (n choose (k - 1)) + (n choose k))"
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    21
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    22
lemma binomial_n_0 [simp]: "(n choose 0) = 1"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    23
  by (cases n) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    24
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    25
lemma binomial_0_Suc [simp]: "(0 choose Suc k) = 0"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    26
  by simp
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    27
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    28
lemma binomial_Suc_Suc [simp]: "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    29
  by simp
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    30
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
    31
lemma choose_reduce_nat: 
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
    32
  "0 < (n::nat) \<Longrightarrow> 0 < k \<Longrightarrow>
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
    33
    (n choose k) = ((n - 1) choose k) + ((n - 1) choose (k - 1))"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
    34
  by (metis Suc_diff_1 binomial.simps(2) nat_add_commute neq0_conv)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
    35
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    36
lemma binomial_eq_0: "n < k \<Longrightarrow> n choose k = 0"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    37
  by (induct n arbitrary: k) auto
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    38
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    39
declare binomial.simps [simp del]
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    40
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    41
lemma binomial_n_n [simp]: "n choose n = 1"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    42
  by (induct n) (simp_all add: binomial_eq_0)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    43
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    44
lemma binomial_Suc_n [simp]: "Suc n choose n = Suc n"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    45
  by (induct n) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    46
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    47
lemma binomial_1 [simp]: "n choose Suc 0 = n"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    48
  by (induct n) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    49
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    50
lemma zero_less_binomial: "k \<le> n \<Longrightarrow> n choose k > 0"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    51
  by (induct n k rule: diff_induct) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    52
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
    53
lemma binomial_eq_0_iff [simp]: "n choose k = 0 \<longleftrightarrow> n < k"
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
    54
  by (metis binomial_eq_0 less_numeral_extra(3) not_less zero_less_binomial)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    55
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
    56
lemma zero_less_binomial_iff [simp]: "n choose k > 0 \<longleftrightarrow> k \<le> n"
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
    57
  by (metis binomial_eq_0_iff not_less0 not_less zero_less_binomial)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    58
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    59
(*Might be more useful if re-oriented*)
21263
wenzelm
parents: 21256
diff changeset
    60
lemma Suc_times_binomial_eq:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    61
  "k \<le> n \<Longrightarrow> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    62
  apply (induct n arbitrary: k)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    63
   apply (simp add: binomial.simps)
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    64
   apply (case_tac k)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    65
  apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq binomial_eq_0)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    66
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    67
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    68
text{*This is the well-known version, but it's harder to use because of the
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    69
  need to reason about division.*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    70
lemma binomial_Suc_Suc_eq_times:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    71
    "k \<le> n \<Longrightarrow> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k"
46507
1b24c24017dd tuned proofs;
wenzelm
parents: 39302
diff changeset
    72
  by (simp add: Suc_times_binomial_eq del: mult_Suc mult_Suc_right)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    73
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    74
text{*Another version, with -1 instead of Suc.*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    75
lemma times_binomial_minus1_eq:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    76
  "k \<le> n \<Longrightarrow> 0 < k \<Longrightarrow> (n choose k) * k = n * ((n - 1) choose (k - 1))"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    77
  using Suc_times_binomial_eq [where n = "n - 1" and k = "k - 1"]
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    78
  by (auto split add: nat_diff_split)
21263
wenzelm
parents: 21256
diff changeset
    79
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    80
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
    81
subsection {* Combinatorial theorems involving @{text "choose"} *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    82
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
    83
text {*By Florian Kamm\"uller, tidied by LCP.*}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    84
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    85
lemma card_s_0_eq_empty: "finite A \<Longrightarrow> card {B. B \<subseteq> A & card B = 0} = 1"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    86
  by (simp cong add: conj_cong add: finite_subset [THEN card_0_eq])
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    87
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    88
lemma choose_deconstruct: "finite M \<Longrightarrow> x \<notin> M \<Longrightarrow>
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    89
    {s. s \<subseteq> insert x M \<and> card s = Suc k} =
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    90
    {s. s \<subseteq> M \<and> card s = Suc k} \<union> {s. \<exists>t. t \<subseteq> M \<and> card t = k \<and> s = insert x t}"
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    91
  apply safe
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
    92
     apply (auto intro: finite_subset [THEN card_insert_disjoint])
54585
bfbfecb3102e Small simplifications to proofs
paulson
parents: 54568
diff changeset
    93
  by (metis (full_types) Diff_insert_absorb Set.set_insert Zero_neq_Suc card_Diff_singleton_if 
bfbfecb3102e Small simplifications to proofs
paulson
parents: 54568
diff changeset
    94
     card_eq_0_iff diff_Suc_1 in_mono subset_insert_iff)
29918
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
    95
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    96
lemma finite_bex_subset [simp]:
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    97
  assumes "finite B"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    98
    and "\<And>A. A \<subseteq> B \<Longrightarrow> finite {x. P x A}"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
    99
  shows "finite {x. \<exists>A \<subseteq> B. P x A}"
54585
bfbfecb3102e Small simplifications to proofs
paulson
parents: 54568
diff changeset
   100
  by (metis (no_types) assms finite_Collect_bounded_ex finite_Collect_subsets)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   101
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   102
text{*There are as many subsets of @{term A} having cardinality @{term k}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   103
 as there are sets obtained from the former by inserting a fixed element
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   104
 @{term x} into each.*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   105
lemma constr_bij:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   106
   "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow>
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   107
    card {B. \<exists>C. C \<subseteq> A \<and> card C = k \<and> B = insert x C} =
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   108
    card {B. B \<subseteq> A & card(B) = k}"
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   109
  apply (rule card_bij_eq [where f = "\<lambda>s. s - {x}" and g = "insert x"])
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   110
  apply (auto elim!: equalityE simp add: inj_on_def)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   111
  apply (metis card_Diff_singleton_if finite_subset in_mono)
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   112
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   113
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   114
text {*
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   115
  Main theorem: combinatorial statement about number of subsets of a set.
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   116
*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   117
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   118
theorem n_subsets: "finite A \<Longrightarrow> card {B. B \<subseteq> A \<and> card B = k} = (card A choose k)"
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   119
proof (induct k arbitrary: A)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   120
  case 0 then show ?case by (simp add: card_s_0_eq_empty)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   121
next
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   122
  case (Suc k)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   123
  show ?case using `finite A`
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   124
  proof (induct A)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   125
    case empty show ?case by (simp add: card_s_0_eq_empty)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   126
  next
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   127
    case (insert x A)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   128
    then show ?case using Suc.hyps
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   129
      apply (simp add: card_s_0_eq_empty choose_deconstruct)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   130
      apply (subst card_Un_disjoint)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   131
         prefer 4 apply (force simp add: constr_bij)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   132
        prefer 3 apply force
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   133
       prefer 2 apply (blast intro: finite_Pow_iff [THEN iffD2]
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   134
         finite_subset [of _ "Pow (insert x F)", standard])
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   135
      apply (blast intro: finite_Pow_iff [THEN iffD2, THEN [2] finite_subset])
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   136
      done
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   137
  qed
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   138
qed
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   139
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   140
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   141
subsection {* The binomial theorem (courtesy of Tobias Nipkow): *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   142
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   143
text{* Avigad's version, generalized to any commutative ring *}
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   144
theorem binomial_ring: "(a+b::'a::{comm_ring_1,power})^n = 
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   145
  (\<Sum>k=0..n. (of_nat (n choose k)) * a^k * b^(n-k))" (is "?P n")
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   146
proof (induct n)
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   147
  case 0 then show "?P 0" by simp
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   148
next
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   149
  case (Suc n)
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   150
  have decomp: "{0..n+1} = {0} Un {n+1} Un {1..n}"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   151
    by auto
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   152
  have decomp2: "{0..n} = {0} Un {1..n}"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   153
    by auto
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   154
  have "(a+b)^(n+1) = 
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   155
      (a+b) * (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k))"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   156
    using Suc.hyps by simp
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   157
  also have "\<dots> = a*(\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k)) +
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   158
                   b*(\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k))"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   159
    by (rule distrib)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   160
  also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^(k+1) * b^(n-k)) +
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   161
                  (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k+1))"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   162
    by (auto simp add: setsum_right_distrib mult_ac)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   163
  also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n+1-k)) +
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   164
                  (\<Sum>k=1..n+1. of_nat (n choose (k - 1)) * a^k * b^(n+1-k))"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   165
    by (simp add:setsum_shift_bounds_cl_Suc_ivl Suc_diff_le field_simps  
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   166
        del:setsum_cl_ivl_Suc)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   167
  also have "\<dots> = a^(n+1) + b^(n+1) +
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   168
                  (\<Sum>k=1..n. of_nat (n choose (k - 1)) * a^k * b^(n+1-k)) +
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   169
                  (\<Sum>k=1..n. of_nat (n choose k) * a^k * b^(n+1-k))"
21263
wenzelm
parents: 21256
diff changeset
   170
    by (simp add: decomp2)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   171
  also have
54568
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   172
      "\<dots> = a^(n+1) + b^(n+1) + 
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   173
            (\<Sum>k=1..n. of_nat(n+1 choose k) * a^k * b^(n+1-k))"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   174
    by (auto simp add: field_simps setsum_addf [symmetric] choose_reduce_nat)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   175
  also have "\<dots> = (\<Sum>k=0..n+1. of_nat (n+1 choose k) * a^k * b^(n+1-k))"
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   176
    using decomp by (simp add: field_simps)
08b642269a0d Simplified, tidied and generalised proofs esp of Binomial Theorem.
paulson
parents: 54489
diff changeset
   177
  finally show "?P (Suc n)" by simp
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   178
qed
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   179
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   180
text{* Original version for the naturals *}
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   181
corollary binomial: "(a+b::nat)^n = (\<Sum>k=0..n. (of_nat (n choose k)) * a^k * b^(n-k))"
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   182
    using binomial_ring [of "int a" "int b" n]
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   183
  by (simp only: of_nat_add [symmetric] of_nat_mult [symmetric] of_nat_power [symmetric]
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   184
           of_nat_setsum [symmetric]
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   185
           of_nat_eq_iff of_nat_id)
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   186
54689
ecaf646b865a proper latex;
wenzelm
parents: 54679
diff changeset
   187
subsection{* Pochhammer's symbol : generalized rising factorial *}
ecaf646b865a proper latex;
wenzelm
parents: 54679
diff changeset
   188
54703
499f92dc6e45 more antiquotations;
wenzelm
parents: 54689
diff changeset
   189
text {* See @{url "http://en.wikipedia.org/wiki/Pochhammer_symbol"} *}
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   190
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   191
definition "pochhammer (a::'a::comm_semiring_1) n =
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   192
  (if n = 0 then 1 else setprod (\<lambda>n. a + of_nat n) {0 .. n - 1})"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   193
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   194
lemma pochhammer_0 [simp]: "pochhammer a 0 = 1"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   195
  by (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   196
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   197
lemma pochhammer_1 [simp]: "pochhammer a 1 = a"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   198
  by (simp add: pochhammer_def)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   199
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   200
lemma pochhammer_Suc0 [simp]: "pochhammer a (Suc 0) = a"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   201
  by (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   202
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   203
lemma pochhammer_Suc_setprod: "pochhammer a (Suc n) = setprod (\<lambda>n. a + of_nat n) {0 .. n}"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   204
  by (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   205
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   206
lemma setprod_nat_ivl_Suc: "setprod f {0 .. Suc n} = setprod f {0..n} * f (Suc n)"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   207
proof -
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   208
  have "{0..Suc n} = {0..n} \<union> {Suc n}" by auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   209
  then show ?thesis by (simp add: field_simps)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   210
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   211
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   212
lemma setprod_nat_ivl_1_Suc: "setprod f {0 .. Suc n} = f 0 * setprod f {1.. Suc n}"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   213
proof -
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   214
  have "{0..Suc n} = {0} \<union> {1 .. Suc n}" by auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   215
  then show ?thesis by simp
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   216
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   217
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   218
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   219
lemma pochhammer_Suc: "pochhammer a (Suc n) = pochhammer a n * (a + of_nat n)"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   220
proof (cases n)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   221
  case 0
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   222
  then show ?thesis by simp
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   223
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   224
  case (Suc n)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   225
  show ?thesis unfolding Suc pochhammer_Suc_setprod setprod_nat_ivl_Suc ..
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   226
qed
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   227
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   228
lemma pochhammer_rec: "pochhammer a (Suc n) = a * pochhammer (a + 1) n"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   229
proof (cases "n = 0")
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   230
  case True
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   231
  then show ?thesis by (simp add: pochhammer_Suc_setprod)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   232
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   233
  case False
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   234
  have *: "finite {1 .. n}" "0 \<notin> {1 .. n}" by auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   235
  have eq: "insert 0 {1 .. n} = {0..n}" by auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   236
  have **: "(\<Prod>n\<in>{1\<Colon>nat..n}. a + of_nat n) = (\<Prod>n\<in>{0\<Colon>nat..n - 1}. a + 1 + of_nat n)"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   237
    apply (rule setprod_reindex_cong [where f = Suc])
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   238
    using False
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   239
    apply (auto simp add: fun_eq_iff field_simps)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   240
    done
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   241
  show ?thesis
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   242
    apply (simp add: pochhammer_def)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   243
    unfolding setprod_insert [OF *, unfolded eq]
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   244
    using ** apply (simp add: field_simps)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   245
    done
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   246
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   247
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   248
lemma pochhammer_fact: "of_nat (fact n) = pochhammer 1 n"
32042
df28ead1cf19 Repairs regarding new Fact.thy.
avigad
parents: 31287
diff changeset
   249
  unfolding fact_altdef_nat
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   250
  apply (cases n)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   251
   apply (simp_all add: of_nat_setprod pochhammer_Suc_setprod)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   252
  apply (rule setprod_reindex_cong[where f=Suc])
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   253
    apply (auto simp add: fun_eq_iff)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   254
  done
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   255
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   256
lemma pochhammer_of_nat_eq_0_lemma:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   257
  assumes "k > n"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   258
  shows "pochhammer (- (of_nat n :: 'a:: idom)) k = 0"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   259
proof (cases "n = 0")
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   260
  case True
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   261
  then show ?thesis
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   262
    using assms by (cases k) (simp_all add: pochhammer_rec)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   263
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   264
  case False
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   265
  from assms obtain h where "k = Suc h" by (cases k) auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   266
  then show ?thesis
54585
bfbfecb3102e Small simplifications to proofs
paulson
parents: 54568
diff changeset
   267
    by (simp add: pochhammer_Suc_setprod)
bfbfecb3102e Small simplifications to proofs
paulson
parents: 54568
diff changeset
   268
       (metis Suc_leI Suc_le_mono assms atLeastAtMost_iff less_eq_nat.simps(1))
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   269
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   270
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   271
lemma pochhammer_of_nat_eq_0_lemma':
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   272
  assumes kn: "k \<le> n"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   273
  shows "pochhammer (- (of_nat n :: 'a:: {idom,ring_char_0})) k \<noteq> 0"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   274
proof (cases k)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   275
  case 0
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   276
  then show ?thesis by simp
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   277
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   278
  case (Suc h)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   279
  then show ?thesis
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   280
    apply (simp add: pochhammer_Suc_setprod)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   281
    using Suc kn apply (auto simp add: algebra_simps)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   282
    done
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   283
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   284
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   285
lemma pochhammer_of_nat_eq_0_iff:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   286
  shows "pochhammer (- (of_nat n :: 'a:: {idom,ring_char_0})) k = 0 \<longleftrightarrow> k > n"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   287
  (is "?l = ?r")
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   288
  using pochhammer_of_nat_eq_0_lemma[of n k, where ?'a='a]
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   289
    pochhammer_of_nat_eq_0_lemma'[of k n, where ?'a = 'a]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   290
  by (auto simp add: not_le[symmetric])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   291
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   292
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   293
lemma pochhammer_eq_0_iff: "pochhammer a n = (0::'a::field_char_0) \<longleftrightarrow> (\<exists>k < n. a = - of_nat k)"
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   294
  apply (auto simp add: pochhammer_of_nat_eq_0_iff)
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   295
  apply (cases n)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   296
   apply (auto simp add: pochhammer_def algebra_simps group_add_class.eq_neg_iff_add_eq_0)
54585
bfbfecb3102e Small simplifications to proofs
paulson
parents: 54568
diff changeset
   297
  apply (metis leD not_less_eq)
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   298
  done
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   299
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   300
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   301
lemma pochhammer_eq_0_mono:
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   302
  "pochhammer a n = (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a m = 0"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   303
  unfolding pochhammer_eq_0_iff by auto
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   304
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   305
lemma pochhammer_neq_0_mono:
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   306
  "pochhammer a m \<noteq> (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a n \<noteq> 0"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   307
  unfolding pochhammer_eq_0_iff by auto
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   308
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   309
lemma pochhammer_minus:
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   310
  assumes kn: "k \<le> n"
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   311
  shows "pochhammer (- b) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (b - of_nat k + 1) k"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   312
proof (cases k)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   313
  case 0
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   314
  then show ?thesis by simp
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   315
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   316
  case (Suc h)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   317
  have eq: "((- 1) ^ Suc h :: 'a) = setprod (%i. - 1) {0 .. h}"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   318
    using setprod_constant[where A="{0 .. h}" and y="- 1 :: 'a"]
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   319
    by auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   320
  show ?thesis
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   321
    unfolding Suc pochhammer_Suc_setprod eq setprod_timesf[symmetric]
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   322
    apply (rule strong_setprod_reindex_cong[where f = "%i. h - i"])
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   323
    using Suc
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   324
    apply (auto simp add: inj_on_def image_def of_nat_diff)
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   325
    apply (metis atLeast0AtMost atMost_iff diff_diff_cancel diff_le_self)
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   326
    done
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   327
qed
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   328
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   329
lemma pochhammer_minus':
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   330
  assumes kn: "k \<le> n"
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   331
  shows "pochhammer (b - of_nat k + 1) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (- b) k"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   332
  unfolding pochhammer_minus[OF kn, where b=b]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   333
  unfolding mult_assoc[symmetric]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   334
  unfolding power_add[symmetric]
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   335
  by simp
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   336
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   337
lemma pochhammer_same: "pochhammer (- of_nat n) n =
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   338
    ((- 1) ^ n :: 'a::comm_ring_1) * of_nat (fact n)"
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   339
  unfolding pochhammer_minus[OF le_refl[of n]]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   340
  by (simp add: of_nat_diff pochhammer_fact)
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   341
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   342
29906
80369da39838 section -> subsection
huffman
parents: 29694
diff changeset
   343
subsection{* Generalized binomial coefficients *}
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   344
31287
6c593b431f04 use class field_char_0
huffman
parents: 31166
diff changeset
   345
definition gbinomial :: "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65)
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   346
  where "a gchoose n =
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   347
    (if n = 0 then 1 else (setprod (\<lambda>i. a - of_nat i) {0 .. n - 1}) / of_nat (fact n))"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   348
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   349
lemma gbinomial_0 [simp]: "a gchoose 0 = 1" "0 gchoose (Suc n) = 0"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   350
  apply (simp_all add: gbinomial_def)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   351
  apply (subgoal_tac "(\<Prod>i\<Colon>nat\<in>{0\<Colon>nat..n}. - of_nat i) = (0::'b)")
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   352
   apply (simp del:setprod_zero_iff)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   353
  apply simp
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   354
  done
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   355
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   356
lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / of_nat (fact n)"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   357
proof (cases "n = 0")
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   358
  case True
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   359
  then show ?thesis by simp
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   360
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   361
  case False
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   362
  from this setprod_constant[of "{0 .. n - 1}" "- (1:: 'a)"]
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   363
  have eq: "(- (1\<Colon>'a)) ^ n = setprod (\<lambda>i. - 1) {0 .. n - 1}"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   364
    by auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   365
  from False show ?thesis
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   366
    by (simp add: pochhammer_def gbinomial_def field_simps
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 52903
diff changeset
   367
      eq setprod_timesf[symmetric])
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   368
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   369
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   370
lemma binomial_fact_lemma: "k \<le> n \<Longrightarrow> fact k * fact (n - k) * (n choose k) = fact n"
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   371
proof (induct n arbitrary: k rule: nat_less_induct)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   372
  fix n k assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) =
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   373
                      fact m" and kn: "k \<le> n"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   374
  let ?ths = "fact k * fact (n - k) * (n choose k) = fact n"
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   375
  { assume "n=0" then have ?ths using kn by simp }
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   376
  moreover
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   377
  { assume "k=0" then have ?ths using kn by simp }
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   378
  moreover
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   379
  { assume nk: "n=k" then have ?ths by simp }
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   380
  moreover
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   381
  { fix m h assume n: "n = Suc m" and h: "k = Suc h" and hm: "h < m"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   382
    from n have mn: "m < n" by arith
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   383
    from hm have hm': "h \<le> m" by arith
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   384
    from hm h n kn have km: "k \<le> m" by arith
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   385
    have "m - h = Suc (m - Suc h)" using  h km hm by arith
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   386
    with km h have th0: "fact (m - h) = (m - h) * fact (m - k)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   387
      by simp
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   388
    from n h th0
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   389
    have "fact k * fact (n - k) * (n choose k) =
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   390
        k * (fact h * fact (m - h) * (m choose h)) + 
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   391
        (m - h) * (fact k * fact (m - k) * (m choose k))"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36309
diff changeset
   392
      by (simp add: field_simps)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   393
    also have "\<dots> = (k + (m - h)) * fact m"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   394
      using H[rule_format, OF mn hm'] H[rule_format, OF mn km]
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36309
diff changeset
   395
      by (simp add: field_simps)
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   396
    finally have ?ths using h n km by simp }
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   397
  moreover have "n=0 \<or> k = 0 \<or> k = n \<or> (\<exists>m h. n = Suc m \<and> k = Suc h \<and> h < m)"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   398
    using kn by presburger
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   399
  ultimately show ?ths by blast
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   400
qed
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   401
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   402
lemma binomial_fact:
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   403
  assumes kn: "k \<le> n"
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   404
  shows "(of_nat (n choose k) :: 'a::field_char_0) =
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   405
    of_nat (fact n) / (of_nat (fact k) * of_nat (fact (n - k)))"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   406
  using binomial_fact_lemma[OF kn]
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36309
diff changeset
   407
  by (simp add: field_simps of_nat_mult [symmetric])
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   408
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   409
lemma binomial_gbinomial: "of_nat (n choose k) = of_nat n gchoose k"
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   410
proof -
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   411
  { assume kn: "k > n"
54679
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   412
    then have ?thesis
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   413
      by (subst binomial_eq_0[OF kn]) 
88adcd3b34e8 Better simprules and markup. Restored the natural number version of the binomial theorem
paulson
parents: 54585
diff changeset
   414
         (simp add: gbinomial_pochhammer field_simps  pochhammer_of_nat_eq_0_iff) }
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   415
  moreover
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   416
  { assume "k=0" then have ?thesis by simp }
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   417
  moreover
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   418
  { assume kn: "k \<le> n" and k0: "k\<noteq> 0"
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   419
    from k0 obtain h where h: "k = Suc h" by (cases k) auto
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   420
    from h
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   421
    have eq:"(- 1 :: 'a) ^ k = setprod (\<lambda>i. - 1) {0..h}"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   422
      by (subst setprod_constant) auto
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   423
    have eq': "(\<Prod>i\<in>{0..h}. of_nat n + - (of_nat i :: 'a)) = (\<Prod>i\<in>{n - h..n}. of_nat i)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   424
      apply (rule strong_setprod_reindex_cong[where f="op - n"])
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   425
        using h kn
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   426
        apply (simp_all add: inj_on_def image_iff Bex_def set_eq_iff)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   427
        apply clarsimp
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   428
        apply presburger
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   429
       apply presburger
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   430
      apply (simp add: fun_eq_iff field_simps of_nat_add[symmetric] del: of_nat_add)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   431
      done
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   432
    have th0: "finite {1..n - Suc h}" "finite {n - h .. n}"
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   433
        "{1..n - Suc h} \<inter> {n - h .. n} = {}" and
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   434
        eq3: "{1..n - Suc h} \<union> {n - h .. n} = {1..n}"
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   435
      using h kn by auto
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   436
    from eq[symmetric]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   437
    have ?thesis using kn
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   438
      apply (simp add: binomial_fact[OF kn, where ?'a = 'a]
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 52903
diff changeset
   439
        gbinomial_pochhammer field_simps pochhammer_Suc_setprod)
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   440
      apply (simp add: pochhammer_Suc_setprod fact_altdef_nat h
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 52903
diff changeset
   441
        of_nat_setprod setprod_timesf[symmetric] eq' del: One_nat_def power_Suc)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   442
      unfolding setprod_Un_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h]
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   443
      unfolding mult_assoc[symmetric]
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   444
      unfolding setprod_timesf[symmetric]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   445
      apply simp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   446
      apply (rule strong_setprod_reindex_cong[where f= "op - n"])
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   447
        apply (auto simp add: inj_on_def image_iff Bex_def)
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   448
       apply presburger
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   449
      apply (subgoal_tac "(of_nat (n - x) :: 'a) = of_nat n - of_nat x")
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   450
       apply simp
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   451
      apply (rule of_nat_diff)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   452
      apply simp
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   453
      done
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   454
  }
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   455
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   456
  have "k > n \<or> k = 0 \<or> (k \<le> n \<and> k \<noteq> 0)" by arith
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   457
  ultimately show ?thesis by blast
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   458
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   459
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   460
lemma gbinomial_1[simp]: "a gchoose 1 = a"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   461
  by (simp add: gbinomial_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   462
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   463
lemma gbinomial_Suc0[simp]: "a gchoose (Suc 0) = a"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   464
  by (simp add: gbinomial_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   465
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   466
lemma gbinomial_mult_1:
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   467
  "a * (a gchoose n) =
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   468
    of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"  (is "?l = ?r")
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   469
proof -
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   470
  have "?r = ((- 1) ^n * pochhammer (- a) n / of_nat (fact n)) * (of_nat n - (- a + of_nat n))"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   471
    unfolding gbinomial_pochhammer
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   472
      pochhammer_Suc fact_Suc of_nat_mult right_diff_distrib power_Suc
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36309
diff changeset
   473
    by (simp add:  field_simps del: of_nat_Suc)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   474
  also have "\<dots> = ?l" unfolding gbinomial_pochhammer
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36309
diff changeset
   475
    by (simp add: field_simps)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   476
  finally show ?thesis ..
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   477
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   478
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   479
lemma gbinomial_mult_1':
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   480
    "(a gchoose n) * a = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   481
  by (simp add: mult_commute gbinomial_mult_1)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   482
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   483
lemma gbinomial_Suc:
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   484
    "a gchoose (Suc k) = (setprod (\<lambda>i. a - of_nat i) {0 .. k}) / of_nat (fact (Suc k))"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   485
  by (simp add: gbinomial_def)
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   486
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   487
lemma gbinomial_mult_fact:
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   488
  "(of_nat (fact (Suc k)) :: 'a) * ((a::'a::field_char_0) gchoose (Suc k)) =
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   489
    (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   490
  by (simp_all add: gbinomial_Suc field_simps del: fact_Suc)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   491
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   492
lemma gbinomial_mult_fact':
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   493
  "((a::'a::field_char_0) gchoose (Suc k)) * (of_nat (fact (Suc k)) :: 'a) =
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   494
    (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   495
  using gbinomial_mult_fact[of k a]
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   496
  by (subst mult_commute)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   497
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   498
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   499
lemma gbinomial_Suc_Suc:
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   500
  "((a::'a::field_char_0) + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   501
proof (cases k)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   502
  case 0
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   503
  then show ?thesis by simp
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   504
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   505
  case (Suc h)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   506
  have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   507
    apply (rule strong_setprod_reindex_cong[where f = Suc])
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   508
      using Suc
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   509
      apply auto
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   510
    done
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   511
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   512
  have "of_nat (fact (Suc k)) * (a gchoose k + (a gchoose (Suc k))) =
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   513
    ((a gchoose Suc h) * of_nat (fact (Suc h)) * of_nat (Suc k)) + (\<Prod>i\<in>{0\<Colon>nat..Suc h}. a - of_nat i)"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   514
    apply (simp add: Suc field_simps del: fact_Suc)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   515
    unfolding gbinomial_mult_fact'
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   516
    apply (subst fact_Suc)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   517
    unfolding of_nat_mult
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   518
    apply (subst mult_commute)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   519
    unfolding mult_assoc
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   520
    unfolding gbinomial_mult_fact
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   521
    apply (simp add: field_simps)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   522
    done
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   523
  also have "\<dots> = (\<Prod>i\<in>{0..h}. a - of_nat i) * (a + 1)"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   524
    unfolding gbinomial_mult_fact' setprod_nat_ivl_Suc
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   525
    by (simp add: field_simps Suc)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   526
  also have "\<dots> = (\<Prod>i\<in>{0..k}. (a + 1) - of_nat i)"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   527
    using eq0
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   528
    by (simp add: Suc setprod_nat_ivl_1_Suc)
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   529
  also have "\<dots> = of_nat (fact (Suc k)) * ((a + 1) gchoose (Suc k))"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   530
    unfolding gbinomial_mult_fact ..
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   531
  finally show ?thesis by (simp del: fact_Suc)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   532
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   533
32158
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   534
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   535
lemma binomial_symmetric:
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   536
  assumes kn: "k \<le> n"
32158
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   537
  shows "n choose k = n choose (n - k)"
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   538
proof-
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   539
  from kn have kn': "n - k \<le> n" by arith
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   540
  from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn']
48830
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   541
  have "fact k * fact (n - k) * (n choose k) =
72efe3e0a46b tuned proofs;
wenzelm
parents: 47108
diff changeset
   542
    fact (n - k) * fact (n - (n - k)) * (n choose (n - k))" by simp
32158
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   543
  then show ?thesis using kn by simp
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   544
qed
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   545
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   546
(* Contributed by Manuel Eberl *)
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   547
(* Alternative definition of the binomial coefficient as \<Prod>i<k. (n - i) / (k - i) *)
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   548
lemma binomial_altdef_of_nat:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   549
  fixes n k :: nat
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   550
    and x :: "'a :: {field_char_0,field_inverse_zero}"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   551
  assumes "k \<le> n"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   552
  shows "of_nat (n choose k) = (\<Prod>i<k. of_nat (n - i) / of_nat (k - i) :: 'a)"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   553
proof (cases "0 < k")
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   554
  case True
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   555
  then have "(of_nat (n choose k) :: 'a) = (\<Prod>i<k. of_nat n - of_nat i) / of_nat (fact k)"
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   556
    unfolding binomial_gbinomial gbinomial_def
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   557
    by (auto simp: gr0_conv_Suc lessThan_Suc_atMost atLeast0AtMost)
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   558
  also have "\<dots> = (\<Prod>i<k. of_nat (n - i) / of_nat (k - i) :: 'a)"
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   559
    using `k \<le> n` unfolding fact_eq_rev_setprod_nat of_nat_setprod
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   560
    by (auto simp add: setprod_dividef intro!: setprod_cong of_nat_diff[symmetric])
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   561
  finally show ?thesis .
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   562
next
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   563
  case False
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   564
  then show ?thesis by simp
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   565
qed
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   566
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   567
lemma binomial_ge_n_over_k_pow_k:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   568
  fixes k n :: nat
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   569
    and x :: "'a :: linordered_field_inverse_zero"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   570
  assumes "0 < k"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   571
    and "k \<le> n"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   572
  shows "(of_nat n / of_nat k :: 'a) ^ k \<le> of_nat (n choose k)"
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   573
proof -
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   574
  have "(of_nat n / of_nat k :: 'a) ^ k = (\<Prod>i<k. of_nat n / of_nat k :: 'a)"
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   575
    by (simp add: setprod_constant)
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   576
  also have "\<dots> \<le> of_nat (n choose k)"
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   577
    unfolding binomial_altdef_of_nat[OF `k\<le>n`]
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   578
  proof (safe intro!: setprod_mono)
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   579
    fix i :: nat
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   580
    assume  "i < k"
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   581
    from assms have "n * i \<ge> i * k" by simp
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   582
    then have "n * k - n * i \<le> n * k - i * k" by arith
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   583
    then have "n * (k - i) \<le> (n - i) * k"
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   584
      by (simp add: diff_mult_distrib2 nat_mult_commute)
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   585
    then have "of_nat n * of_nat (k - i) \<le> of_nat (n - i) * (of_nat k :: 'a)"
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   586
      unfolding of_nat_mult[symmetric] of_nat_le_iff .
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   587
    with assms show "of_nat n / of_nat k \<le> of_nat (n - i) / (of_nat (k - i) :: 'a)"
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   588
      using `i < k` by (simp add: field_simps)
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   589
  qed (simp add: zero_le_divide_iff)
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   590
  finally show ?thesis .
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   591
qed
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 48830
diff changeset
   592
50240
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   593
lemma binomial_le_pow:
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   594
  assumes "r \<le> n"
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   595
  shows "n choose r \<le> n ^ r"
50240
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   596
proof -
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   597
  have "n choose r \<le> fact n div fact (n - r)"
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   598
    using `r \<le> n` by (subst binomial_fact_lemma[symmetric]) auto
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   599
  with fact_div_fact_le_pow [OF assms] show ?thesis by auto
50240
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   600
qed
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   601
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   602
lemma binomial_altdef_nat: "(k::nat) \<le> n \<Longrightarrow>
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   603
    n choose k = fact n div (fact k * fact (n - k))"
52903
6c89225ddeba tuned proofs;
wenzelm
parents: 50240
diff changeset
   604
 by (subst binomial_fact_lemma [symmetric]) auto
50240
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   605
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   606
end