| author | wenzelm | 
| Sat, 17 Mar 2012 10:55:08 +0100 | |
| changeset 46978 | 23a59a495934 | 
| parent 46757 | ad878aff9c15 | 
| child 47108 | 2a1953f0d20d | 
| 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: 
27487diff
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 | |
| 29931 | 15 | primrec binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat" (infixl "choose" 65) where | 
| 21263 | 16 | binomial_0: "(0 choose k) = (if k = 0 then 1 else 0)" | 
| 29931 | 17 | | binomial_Suc: "(Suc n choose k) = | 
| 21256 | 18 | (if k = 0 then 1 else (n choose (k - 1)) + (n choose k))" | 
| 19 | ||
| 20 | lemma binomial_n_0 [simp]: "(n choose 0) = 1" | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 21 | by (cases n) simp_all | 
| 21256 | 22 | |
| 23 | lemma binomial_0_Suc [simp]: "(0 choose Suc k) = 0" | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 24 | by simp | 
| 21256 | 25 | |
| 26 | lemma binomial_Suc_Suc [simp]: | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 27 | "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)" | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 28 | by simp | 
| 21256 | 29 | |
| 21263 | 30 | lemma binomial_eq_0: "!!k. n < k ==> (n choose k) = 0" | 
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 31 | by (induct n) auto | 
| 21256 | 32 | |
| 33 | declare binomial_0 [simp del] binomial_Suc [simp del] | |
| 34 | ||
| 35 | lemma binomial_n_n [simp]: "(n choose n) = 1" | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 36 | by (induct n) (simp_all add: binomial_eq_0) | 
| 21256 | 37 | |
| 38 | lemma binomial_Suc_n [simp]: "(Suc n choose n) = Suc n" | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 39 | by (induct n) simp_all | 
| 21256 | 40 | |
| 41 | lemma binomial_1 [simp]: "(n choose Suc 0) = n" | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 42 | by (induct n) simp_all | 
| 21256 | 43 | |
| 25162 | 44 | lemma zero_less_binomial: "k \<le> n ==> (n choose k) > 0" | 
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 45 | by (induct n k rule: diff_induct) simp_all | 
| 21256 | 46 | |
| 47 | lemma binomial_eq_0_iff: "(n choose k = 0) = (n<k)" | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 48 | apply (safe intro!: binomial_eq_0) | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 49 | apply (erule contrapos_pp) | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 50 | apply (simp add: zero_less_binomial) | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 51 | done | 
| 21256 | 52 | |
| 25162 | 53 | lemma zero_less_binomial_iff: "(n choose k > 0) = (k\<le>n)" | 
| 54 | by(simp add: linorder_not_less binomial_eq_0_iff neq0_conv[symmetric] | |
| 55 | del:neq0_conv) | |
| 21256 | 56 | |
| 57 | (*Might be more useful if re-oriented*) | |
| 21263 | 58 | lemma Suc_times_binomial_eq: | 
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 59 | "!!k. k \<le> n ==> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k" | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 60 | apply (induct n) | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 61 | apply (simp add: binomial_0) | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 62 | apply (case_tac k) | 
| 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 63 | apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq | 
| 21263 | 64 | binomial_eq_0) | 
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 65 | done | 
| 21256 | 66 | |
| 67 | text{*This is the well-known version, but it's harder to use because of the
 | |
| 68 | need to reason about division.*} | |
| 69 | lemma binomial_Suc_Suc_eq_times: | |
| 21263 | 70 | "k \<le> n ==> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k" | 
| 46507 | 71 | by (simp add: Suc_times_binomial_eq del: mult_Suc mult_Suc_right) | 
| 21256 | 72 | |
| 73 | text{*Another version, with -1 instead of Suc.*}
 | |
| 74 | lemma times_binomial_minus1_eq: | |
| 21263 | 75 | "[|k \<le> n; 0<k|] ==> (n choose k) * k = n * ((n - 1) choose (k - 1))" | 
| 76 | apply (cut_tac n = "n - 1" and k = "k - 1" in Suc_times_binomial_eq) | |
| 77 | apply (simp split add: nat_diff_split, auto) | |
| 78 | done | |
| 79 | ||
| 21256 | 80 | |
| 25378 | 81 | subsection {* Theorems about @{text "choose"} *}
 | 
| 21256 | 82 | |
| 83 | text {*
 | |
| 84 |   \medskip Basic theorem about @{text "choose"}.  By Florian
 | |
| 85 | Kamm\"uller, tidied by LCP. | |
| 86 | *} | |
| 87 | ||
| 88 | lemma card_s_0_eq_empty: | |
| 89 |     "finite A ==> card {B. B \<subseteq> A & card B = 0} = 1"
 | |
| 31166 
a90fe83f58ea
"{x. P x & x=t & Q x}" is now rewritten to "if P t & Q t then {t} else {}"
 nipkow parents: 
31021diff
changeset | 90 | by (simp cong add: conj_cong add: finite_subset [THEN card_0_eq]) | 
| 21256 | 91 | |
| 92 | lemma choose_deconstruct: "finite M ==> x \<notin> M | |
| 93 |   ==> {s. s <= insert x M & card(s) = Suc k}
 | |
| 94 |        = {s. s <= M & card(s) = Suc k} Un
 | |
| 95 |          {s. EX t. t <= M & card(t) = k & s = insert x t}"
 | |
| 96 | apply safe | |
| 97 | apply (auto intro: finite_subset [THEN card_insert_disjoint]) | |
| 98 |   apply (drule_tac x = "xa - {x}" in spec)
 | |
| 99 | apply (subgoal_tac "x \<notin> xa", auto) | |
| 100 | apply (erule rev_mp, subst card_Diff_singleton) | |
| 101 | apply (auto intro: finite_subset) | |
| 102 | done | |
| 29918 | 103 | (* | 
| 104 | lemma "finite(UN y. {x. P x y})"
 | |
| 105 | apply simp | |
| 106 | lemma Collect_ex_eq | |
| 107 | ||
| 108 | lemma "{x. EX y. P x y} = (UN y. {x. P x y})"
 | |
| 109 | apply blast | |
| 110 | *) | |
| 111 | ||
| 112 | lemma finite_bex_subset[simp]: | |
| 113 |   "finite B \<Longrightarrow> (!!A. A<=B \<Longrightarrow> finite{x. P x A}) \<Longrightarrow> finite{x. EX A<=B. P x A}"
 | |
| 114 | apply(subgoal_tac "{x. EX A<=B. P x A} = (UN A:Pow B. {x. P x A})")
 | |
| 115 | apply simp | |
| 116 | apply blast | |
| 117 | done | |
| 21256 | 118 | |
| 119 | text{*There are as many subsets of @{term A} having cardinality @{term k}
 | |
| 120 | as there are sets obtained from the former by inserting a fixed element | |
| 121 |  @{term x} into each.*}
 | |
| 122 | lemma constr_bij: | |
| 123 | "[|finite A; x \<notin> A|] ==> | |
| 124 |     card {B. EX C. C <= A & card(C) = k & B = insert x C} =
 | |
| 125 |     card {B. B <= A & card(B) = k}"
 | |
| 29918 | 126 | apply (rule_tac f = "%s. s - {x}" and g = "insert x" in card_bij_eq)
 | 
| 127 | apply (auto elim!: equalityE simp add: inj_on_def) | |
| 128 | apply (subst Diff_insert0, auto) | |
| 129 | done | |
| 21256 | 130 | |
| 131 | text {*
 | |
| 132 | Main theorem: combinatorial statement about number of subsets of a set. | |
| 133 | *} | |
| 134 | ||
| 135 | lemma n_sub_lemma: | |
| 21263 | 136 |     "!!A. finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
 | 
| 21256 | 137 | apply (induct k) | 
| 138 | apply (simp add: card_s_0_eq_empty, atomize) | |
| 139 | apply (rotate_tac -1, erule finite_induct) | |
| 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 | ||
| 150 | theorem n_subsets: | |
| 151 |     "finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
 | |
| 152 | by (simp add: n_sub_lemma) | |
| 153 | ||
| 154 | ||
| 155 | text{* The binomial theorem (courtesy of Tobias Nipkow): *}
 | |
| 156 | ||
| 157 | theorem binomial: "(a+b::nat)^n = (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))" | |
| 158 | proof (induct n) | |
| 159 | case 0 thus ?case by simp | |
| 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) | |
| 166 | have "(a+b::nat)^(n+1) = (a+b) * (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))" | |
| 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: 
27487diff
changeset | 191 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 192 | definition "pochhammer (a::'a::comm_semiring_1) n = (if n = 0 then 1 else setprod (\<lambda>n. a + of_nat n) {0 .. n - 1})"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 193 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 194 | lemma pochhammer_0[simp]: "pochhammer a 0 = 1" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 195 | by (simp add: pochhammer_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 196 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 197 | lemma pochhammer_1[simp]: "pochhammer a 1 = a" by (simp add: pochhammer_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 198 | lemma pochhammer_Suc0[simp]: "pochhammer a (Suc 0) = a" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 199 | by (simp add: pochhammer_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 200 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 201 | 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: 
27487diff
changeset | 202 | by (simp add: pochhammer_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 203 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 204 | lemma setprod_nat_ivl_Suc: "setprod f {0 .. Suc n} = setprod f {0..n} * f (Suc n)"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 205 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 206 |   have eq: "{0..Suc n} = {0..n} \<union> {Suc n}" by auto
 | 
| 46757 | 207 | show ?thesis unfolding eq by (simp add: field_simps) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 208 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 209 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 210 | lemma setprod_nat_ivl_1_Suc: "setprod f {0 .. Suc n} = f 0 * setprod f {1.. Suc n}"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 211 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 212 |   have eq: "{0..Suc n} = {0} \<union> {1 .. Suc n}" by auto
 | 
| 46757 | 213 | show ?thesis unfolding eq by simp | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 214 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 215 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 216 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 217 | lemma pochhammer_Suc: "pochhammer a (Suc n) = pochhammer a n * (a + of_nat n)" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 218 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 219 |   {assume "n=0" then have ?thesis by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 220 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 221 |   {fix m assume m: "n = Suc m"
 | 
| 46757 | 222 | have ?thesis unfolding m pochhammer_Suc_setprod setprod_nat_ivl_Suc ..} | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 223 | ultimately show ?thesis by (cases n, auto) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 224 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 225 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 226 | lemma pochhammer_rec: "pochhammer a (Suc n) = a * pochhammer (a + 1) n" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 227 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 228 |   {assume "n=0" then have ?thesis by (simp add: pochhammer_Suc_setprod)}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 229 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 230 |   {assume n0: "n \<noteq> 0"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 231 |     have th0: "finite {1 .. n}" "0 \<notin> {1 .. n}" by auto
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 232 |     have eq: "insert 0 {1 .. n} = {0..n}" by auto
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 233 |     have th1: "(\<Prod>n\<in>{1\<Colon>nat..n}. a + of_nat n) =
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 234 |       (\<Prod>n\<in>{0\<Colon>nat..n - 1}. a + 1 + of_nat n)"
 | 
| 37388 | 235 | apply (rule setprod_reindex_cong [where f = Suc]) | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 236 | using n0 by (auto simp add: fun_eq_iff field_simps) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 237 | have ?thesis apply (simp add: pochhammer_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 238 | unfolding setprod_insert[OF th0, unfolded eq] | 
| 36350 | 239 | using th1 by (simp add: field_simps)} | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 240 | ultimately show ?thesis by blast | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 241 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 242 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 243 | lemma pochhammer_fact: "of_nat (fact n) = pochhammer 1 n" | 
| 32042 | 244 | unfolding fact_altdef_nat | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 245 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 246 | apply (cases n, simp_all add: of_nat_setprod pochhammer_Suc_setprod) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 247 | apply (rule setprod_reindex_cong[where f=Suc]) | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 248 | by (auto simp add: fun_eq_iff) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 249 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 250 | lemma pochhammer_of_nat_eq_0_lemma: assumes kn: "k > n" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 251 | shows "pochhammer (- (of_nat n :: 'a:: idom)) k = 0" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 252 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 253 | from kn obtain h where h: "k = Suc h" by (cases k, auto) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 254 |   {assume n0: "n=0" then have ?thesis using kn 
 | 
| 46507 | 255 | by (cases k) (simp_all add: pochhammer_rec)} | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 256 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 257 |   {assume n0: "n \<noteq> 0"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 258 | then have ?thesis apply (simp add: h pochhammer_Suc_setprod) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 259 | apply (rule_tac x="n" in bexI) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 260 | using h kn by auto} | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 261 | ultimately show ?thesis by blast | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 262 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 263 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 264 | lemma pochhammer_of_nat_eq_0_lemma': assumes kn: "k \<le> n" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 265 |   shows "pochhammer (- (of_nat n :: 'a:: {idom, ring_char_0})) k \<noteq> 0"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 266 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 267 |   {assume "k=0" then have ?thesis by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 268 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 269 |   {fix h assume h: "k = Suc h"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 270 | then have ?thesis apply (simp add: pochhammer_Suc_setprod) | 
| 30843 | 271 | using h kn by (auto simp add: algebra_simps)} | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 272 | ultimately show ?thesis by (cases k, auto) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 273 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 274 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 275 | lemma pochhammer_of_nat_eq_0_iff: | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 276 |   shows "pochhammer (- (of_nat n :: 'a:: {idom, ring_char_0})) k = 0 \<longleftrightarrow> k > n"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 277 | (is "?l = ?r") | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 278 | using pochhammer_of_nat_eq_0_lemma[of n k, where ?'a='a] | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 279 | 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: 
27487diff
changeset | 280 | by (auto simp add: not_le[symmetric]) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 281 | |
| 32159 | 282 | |
| 283 | lemma pochhammer_eq_0_iff: | |
| 284 | "pochhammer a n = (0::'a::field_char_0) \<longleftrightarrow> (EX k < n . a = - of_nat k) " | |
| 285 | apply (auto simp add: pochhammer_of_nat_eq_0_iff) | |
| 286 | apply (cases n, auto simp add: pochhammer_def algebra_simps group_add_class.eq_neg_iff_add_eq_0) | |
| 287 | apply (rule_tac x=x in exI) | |
| 288 | apply auto | |
| 289 | done | |
| 290 | ||
| 291 | ||
| 292 | lemma pochhammer_eq_0_mono: | |
| 293 | "pochhammer a n = (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a m = 0" | |
| 294 | unfolding pochhammer_eq_0_iff by auto | |
| 295 | ||
| 296 | lemma pochhammer_neq_0_mono: | |
| 297 | "pochhammer a m \<noteq> (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a n \<noteq> 0" | |
| 298 | unfolding pochhammer_eq_0_iff by auto | |
| 299 | ||
| 300 | lemma pochhammer_minus: | |
| 301 | assumes kn: "k \<le> n" | |
| 302 | shows "pochhammer (- b) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (b - of_nat k + 1) k" | |
| 303 | proof- | |
| 304 |   {assume k0: "k = 0" then have ?thesis by simp}
 | |
| 305 | moreover | |
| 306 |   {fix h assume h: "k = Suc h"
 | |
| 307 |     have eq: "((- 1) ^ Suc h :: 'a) = setprod (%i. - 1) {0 .. h}"
 | |
| 308 |       using setprod_constant[where A="{0 .. h}" and y="- 1 :: 'a"]
 | |
| 309 | by auto | |
| 310 | have ?thesis | |
| 46507 | 311 | unfolding h pochhammer_Suc_setprod eq setprod_timesf[symmetric] | 
| 32159 | 312 | apply (rule strong_setprod_reindex_cong[where f = "%i. h - i"]) | 
| 313 | apply (auto simp add: inj_on_def image_def h ) | |
| 314 | apply (rule_tac x="h - x" in bexI) | |
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 315 | by (auto simp add: fun_eq_iff h of_nat_diff)} | 
| 32159 | 316 | ultimately show ?thesis by (cases k, auto) | 
| 317 | qed | |
| 318 | ||
| 319 | lemma pochhammer_minus': | |
| 320 | assumes kn: "k \<le> n" | |
| 321 | shows "pochhammer (b - of_nat k + 1) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (- b) k" | |
| 322 | unfolding pochhammer_minus[OF kn, where b=b] | |
| 323 | unfolding mult_assoc[symmetric] | |
| 324 | unfolding power_add[symmetric] | |
| 325 | apply simp | |
| 326 | done | |
| 327 | ||
| 328 | lemma pochhammer_same: "pochhammer (- of_nat n) n = ((- 1) ^ n :: 'a::comm_ring_1) * of_nat (fact n)" | |
| 329 | unfolding pochhammer_minus[OF le_refl[of n]] | |
| 330 | by (simp add: of_nat_diff pochhammer_fact) | |
| 331 | ||
| 29906 | 332 | subsection{* Generalized binomial coefficients *}
 | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 333 | |
| 31287 | 334 | definition gbinomial :: "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 335 |   where "a gchoose n = (if n = 0 then 1 else (setprod (\<lambda>i. a - of_nat i) {0 .. n - 1}) / of_nat (fact n))"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 336 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 337 | lemma gbinomial_0[simp]: "a gchoose 0 = 1" "0 gchoose (Suc n) = 0" | 
| 30843 | 338 | apply (simp_all add: gbinomial_def) | 
| 339 | apply (subgoal_tac "(\<Prod>i\<Colon>nat\<in>{0\<Colon>nat..n}. - of_nat i) = (0::'b)")
 | |
| 340 | apply (simp del:setprod_zero_iff) | |
| 341 | apply simp | |
| 342 | done | |
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 343 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 344 | lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / of_nat (fact n)" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 345 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 346 |   {assume "n=0" then have ?thesis by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 347 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 348 |   {assume n0: "n\<noteq>0"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 349 |     from n0 setprod_constant[of "{0 .. n - 1}" "- (1:: 'a)"]
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 350 |     have eq: "(- (1\<Colon>'a)) ^ n = setprod (\<lambda>i. - 1) {0 .. n - 1}"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 351 | by auto | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 352 | from n0 have ?thesis | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 353 | by (simp add: pochhammer_def gbinomial_def field_simps eq setprod_timesf[symmetric])} | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 354 | ultimately show ?thesis by blast | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 355 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 356 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 357 | lemma binomial_fact_lemma: | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 358 | "k \<le> n \<Longrightarrow> fact k * fact (n - k) * (n choose k) = fact n" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 359 | proof(induct n arbitrary: k rule: nat_less_induct) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 360 | 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: 
27487diff
changeset | 361 | fact m" and kn: "k \<le> n" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 362 | let ?ths = "fact k * fact (n - k) * (n choose k) = fact n" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 363 |   {assume "n=0" then have ?ths using kn by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 364 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 365 |   {assume "k=0" then have ?ths using kn by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 366 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 367 |   {assume nk: "n=k" then have ?ths by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 368 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 369 |   {fix m h assume n: "n = Suc m" and h: "k = Suc h" and hm: "h < m"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 370 | from n have mn: "m < n" by arith | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 371 | 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: 
27487diff
changeset | 372 | from hm h n kn have km: "k \<le> m" by arith | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 373 | have "m - h = Suc (m - Suc h)" using h km hm by arith | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 374 | 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: 
27487diff
changeset | 375 | by simp | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 376 | from n h th0 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 377 | have "fact k * fact (n - k) * (n choose k) = k * (fact h * fact (m - h) * (m choose h)) + (m - h) * (fact k * fact (m - k) * (m choose k))" | 
| 36350 | 378 | by (simp add: field_simps) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 379 | also have "\<dots> = (k + (m - h)) * fact m" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 380 | using H[rule_format, OF mn hm'] H[rule_format, OF mn km] | 
| 36350 | 381 | by (simp add: field_simps) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 382 | finally have ?ths using h n km by simp} | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 383 | moreover have "n=0 \<or> k = 0 \<or> k = n \<or> (EX m h. n=Suc m \<and> k = Suc h \<and> h < m)" using kn by presburger | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 384 | ultimately show ?ths by blast | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 385 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 386 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 387 | lemma binomial_fact: | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 388 | assumes kn: "k \<le> n" | 
| 31287 | 389 | shows "(of_nat (n choose k) :: 'a::field_char_0) = 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: 
27487diff
changeset | 390 | using binomial_fact_lemma[OF kn] | 
| 36350 | 391 | 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: 
27487diff
changeset | 392 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 393 | lemma binomial_gbinomial: "of_nat (n choose k) = of_nat n gchoose k" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 394 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 395 |   {assume kn: "k > n" 
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 396 | from kn binomial_eq_0[OF kn] have ?thesis | 
| 36350 | 397 | by (simp add: gbinomial_pochhammer field_simps | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32161diff
changeset | 398 | pochhammer_of_nat_eq_0_iff)} | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 399 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 400 |   {assume "k=0" then have ?thesis by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 401 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 402 |   {assume kn: "k \<le> n" and k0: "k\<noteq> 0"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 403 | from k0 obtain h where h: "k = Suc h" by (cases k, auto) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 404 | from h | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 405 |     have eq:"(- 1 :: 'a) ^ k = setprod (\<lambda>i. - 1) {0..h}"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 406 | by (subst setprod_constant, auto) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 407 |     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: 
27487diff
changeset | 408 | apply (rule strong_setprod_reindex_cong[where f="op - n"]) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 409 | using h kn | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 410 | apply (simp_all add: inj_on_def image_iff Bex_def set_eq_iff) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 411 | apply clarsimp | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 412 | apply (presburger) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 413 | apply presburger | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 414 | by (simp add: fun_eq_iff field_simps of_nat_add[symmetric] del: of_nat_add) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 415 |     have th0: "finite {1..n - Suc h}" "finite {n - h .. n}" 
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 416 | "{1..n - Suc h} \<inter> {n - h .. n} = {}" and eq3: "{1..n - Suc h} \<union> {n - h .. n} = {1..n}" using h kn by auto
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 417 | from eq[symmetric] | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 418 | have ?thesis using kn | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 419 | apply (simp add: binomial_fact[OF kn, where ?'a = 'a] | 
| 36350 | 420 | gbinomial_pochhammer field_simps pochhammer_Suc_setprod) | 
| 32042 | 421 | apply (simp add: pochhammer_Suc_setprod fact_altdef_nat h 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: 
27487diff
changeset | 422 | unfolding setprod_Un_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h] | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 423 | unfolding mult_assoc[symmetric] | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 424 | unfolding setprod_timesf[symmetric] | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 425 | apply simp | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 426 | apply (rule strong_setprod_reindex_cong[where f= "op - n"]) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 427 | apply (auto simp add: inj_on_def image_iff Bex_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 428 | apply presburger | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 429 | apply (subgoal_tac "(of_nat (n - x) :: 'a) = of_nat n - of_nat x") | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 430 | apply simp | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 431 | by (rule of_nat_diff, simp) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 432 | } | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 433 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 434 | 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: 
27487diff
changeset | 435 | ultimately show ?thesis by blast | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 436 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 437 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 438 | lemma gbinomial_1[simp]: "a gchoose 1 = a" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 439 | by (simp add: gbinomial_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 440 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 441 | 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: 
27487diff
changeset | 442 | by (simp add: gbinomial_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 443 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 444 | lemma gbinomial_mult_1: "a * (a gchoose n) = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))" (is "?l = ?r") | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 445 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 446 | 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: 
27487diff
changeset | 447 | unfolding gbinomial_pochhammer | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 448 | pochhammer_Suc fact_Suc of_nat_mult right_diff_distrib power_Suc | 
| 36350 | 449 | 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: 
27487diff
changeset | 450 | also have "\<dots> = ?l" unfolding gbinomial_pochhammer | 
| 36350 | 451 | by (simp add: field_simps) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 452 | finally show ?thesis .. | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 453 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 454 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 455 | lemma gbinomial_mult_1': "(a gchoose n) * a = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 456 | by (simp add: mult_commute gbinomial_mult_1) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 457 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 458 | lemma gbinomial_Suc: "a gchoose (Suc k) = (setprod (\<lambda>i. a - of_nat i) {0 .. k}) / of_nat (fact (Suc k))"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 459 | by (simp add: gbinomial_def) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 460 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 461 | lemma gbinomial_mult_fact: | 
| 31287 | 462 |   "(of_nat (fact (Suc k)) :: 'a) * ((a::'a::field_char_0) gchoose (Suc k)) = (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: 
27487diff
changeset | 463 | unfolding gbinomial_Suc | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 464 | by (simp_all add: field_simps del: fact_Suc) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 465 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 466 | lemma gbinomial_mult_fact': | 
| 31287 | 467 |   "((a::'a::field_char_0) gchoose (Suc k)) * (of_nat (fact (Suc k)) :: 'a) = (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: 
27487diff
changeset | 468 | using gbinomial_mult_fact[of k a] | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 469 | apply (subst mult_commute) . | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 470 | |
| 31287 | 471 | lemma gbinomial_Suc_Suc: "((a::'a::field_char_0) + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))" | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 472 | proof- | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 473 |   {assume "k = 0" then have ?thesis by simp}
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 474 | moreover | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 475 |   {fix h assume h: "k = Suc h"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 476 |    have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 477 | apply (rule strong_setprod_reindex_cong[where f = Suc]) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 478 | using h by auto | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 479 | |
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 480 |     have "of_nat (fact (Suc k)) * (a gchoose k + (a gchoose (Suc k))) = ((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)" 
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 481 | unfolding h | 
| 36350 | 482 | apply (simp add: field_simps del: fact_Suc) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 483 | unfolding gbinomial_mult_fact' | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 484 | apply (subst fact_Suc) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 485 | unfolding of_nat_mult | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 486 | apply (subst mult_commute) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 487 | unfolding mult_assoc | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 488 | unfolding gbinomial_mult_fact | 
| 36350 | 489 | by (simp add: field_simps) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 490 |     also have "\<dots> = (\<Prod>i\<in>{0..h}. a - of_nat i) * (a + 1)"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 491 | unfolding gbinomial_mult_fact' setprod_nat_ivl_Suc | 
| 36350 | 492 | by (simp add: field_simps h) | 
| 29694 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 493 |     also have "\<dots> = (\<Prod>i\<in>{0..k}. (a + 1) - of_nat i)"
 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 494 | using eq0 | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 495 | unfolding h setprod_nat_ivl_1_Suc | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 496 | by simp | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 497 | also have "\<dots> = of_nat (fact (Suc k)) * ((a + 1) gchoose (Suc k))" | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 498 | unfolding gbinomial_mult_fact .. | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 499 | finally have ?thesis by (simp del: fact_Suc) } | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 500 | ultimately show ?thesis by (cases k, auto) | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 501 | qed | 
| 
2f2558d7bc3e
Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
 chaieb parents: 
27487diff
changeset | 502 | |
| 32158 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 503 | |
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 504 | lemma binomial_symmetric: assumes kn: "k \<le> n" | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 505 | shows "n choose k = n choose (n - k)" | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 506 | proof- | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 507 | from kn have kn': "n - k \<le> n" by arith | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 508 | from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn'] | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 509 | have "fact k * fact (n - k) * (n choose k) = fact (n - k) * fact (n - (n - k)) * (n choose (n - k))" by simp | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 510 | then show ?thesis using kn by simp | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 511 | qed | 
| 
4dc119d4fc8b
Moved theorem binomial_symmetric from Formal_Power_Series to here
 chaieb parents: 
31287diff
changeset | 512 | |
| 21256 | 513 | end |