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