src/HOL/Library/Binomial.thy
author chaieb
Mon Feb 09 17:21:46 2009 +0000 (2009-02-09)
changeset 29847 af32126ee729
parent 29694 2f2558d7bc3e
child 29906 80369da39838
permissions -rw-r--r--
added Determinants to Library
     1 (*  Title:      HOL/Binomial.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Amine Chaieb
     4     Copyright   1997  University of Cambridge
     5 *)
     6 
     7 header {* Binomial Coefficients *}
     8 
     9 theory Binomial
    10 imports Fact Plain "~~/src/HOL/SetInterval" Presburger 
    11 begin
    12 
    13 text {* This development is based on the work of Andy Gordon and
    14   Florian Kammueller. *}
    15 
    16 consts
    17   binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat"      (infixl "choose" 65)
    18 primrec
    19   binomial_0: "(0 choose k) = (if k = 0 then 1 else 0)"
    20   binomial_Suc: "(Suc n choose k) =
    21                  (if k = 0 then 1 else (n choose (k - 1)) + (n choose k))"
    22 
    23 lemma binomial_n_0 [simp]: "(n choose 0) = 1"
    24 by (cases n) simp_all
    25 
    26 lemma binomial_0_Suc [simp]: "(0 choose Suc k) = 0"
    27 by simp
    28 
    29 lemma binomial_Suc_Suc [simp]:
    30   "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)"
    31 by simp
    32 
    33 lemma binomial_eq_0: "!!k. n < k ==> (n choose k) = 0"
    34 by (induct n) auto
    35 
    36 declare binomial_0 [simp del] binomial_Suc [simp del]
    37 
    38 lemma binomial_n_n [simp]: "(n choose n) = 1"
    39 by (induct n) (simp_all add: binomial_eq_0)
    40 
    41 lemma binomial_Suc_n [simp]: "(Suc n choose n) = Suc n"
    42 by (induct n) simp_all
    43 
    44 lemma binomial_1 [simp]: "(n choose Suc 0) = n"
    45 by (induct n) simp_all
    46 
    47 lemma zero_less_binomial: "k \<le> n ==> (n choose k) > 0"
    48 by (induct n k rule: diff_induct) simp_all
    49 
    50 lemma binomial_eq_0_iff: "(n choose k = 0) = (n<k)"
    51 apply (safe intro!: binomial_eq_0)
    52 apply (erule contrapos_pp)
    53 apply (simp add: zero_less_binomial)
    54 done
    55 
    56 lemma zero_less_binomial_iff: "(n choose k > 0) = (k\<le>n)"
    57 by(simp add: linorder_not_less binomial_eq_0_iff neq0_conv[symmetric]
    58         del:neq0_conv)
    59 
    60 (*Might be more useful if re-oriented*)
    61 lemma Suc_times_binomial_eq:
    62   "!!k. k \<le> n ==> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"
    63 apply (induct n)
    64 apply (simp add: binomial_0)
    65 apply (case_tac k)
    66 apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq
    67     binomial_eq_0)
    68 done
    69 
    70 text{*This is the well-known version, but it's harder to use because of the
    71   need to reason about division.*}
    72 lemma binomial_Suc_Suc_eq_times:
    73     "k \<le> n ==> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k"
    74   by (simp add: Suc_times_binomial_eq div_mult_self_is_m zero_less_Suc
    75     del: mult_Suc mult_Suc_right)
    76 
    77 text{*Another version, with -1 instead of Suc.*}
    78 lemma times_binomial_minus1_eq:
    79     "[|k \<le> n;  0<k|] ==> (n choose k) * k = n * ((n - 1) choose (k - 1))"
    80   apply (cut_tac n = "n - 1" and k = "k - 1" in Suc_times_binomial_eq)
    81   apply (simp split add: nat_diff_split, auto)
    82   done
    83 
    84 
    85 subsection {* Theorems about @{text "choose"} *}
    86 
    87 text {*
    88   \medskip Basic theorem about @{text "choose"}.  By Florian
    89   Kamm\"uller, tidied by LCP.
    90 *}
    91 
    92 lemma card_s_0_eq_empty:
    93     "finite A ==> card {B. B \<subseteq> A & card B = 0} = 1"
    94   apply (simp cong add: conj_cong add: finite_subset [THEN card_0_eq])
    95   apply (simp cong add: rev_conj_cong)
    96   done
    97 
    98 lemma choose_deconstruct: "finite M ==> x \<notin> M
    99   ==> {s. s <= insert x M & card(s) = Suc k}
   100        = {s. s <= M & card(s) = Suc k} Un
   101          {s. EX t. t <= M & card(t) = k & s = insert x t}"
   102   apply safe
   103    apply (auto intro: finite_subset [THEN card_insert_disjoint])
   104   apply (drule_tac x = "xa - {x}" in spec)
   105   apply (subgoal_tac "x \<notin> xa", auto)
   106   apply (erule rev_mp, subst card_Diff_singleton)
   107   apply (auto intro: finite_subset)
   108   done
   109 
   110 text{*There are as many subsets of @{term A} having cardinality @{term k}
   111  as there are sets obtained from the former by inserting a fixed element
   112  @{term x} into each.*}
   113 lemma constr_bij:
   114    "[|finite A; x \<notin> A|] ==>
   115     card {B. EX C. C <= A & card(C) = k & B = insert x C} =
   116     card {B. B <= A & card(B) = k}"
   117   apply (rule_tac f = "%s. s - {x}" and g = "insert x" in card_bij_eq)
   118        apply (auto elim!: equalityE simp add: inj_on_def)
   119     apply (subst Diff_insert0, auto)
   120    txt {* finiteness of the two sets *}
   121    apply (rule_tac [2] B = "Pow (A)" in finite_subset)
   122    apply (rule_tac B = "Pow (insert x A)" in finite_subset)
   123    apply fast+
   124   done
   125 
   126 text {*
   127   Main theorem: combinatorial statement about number of subsets of a set.
   128 *}
   129 
   130 lemma n_sub_lemma:
   131     "!!A. finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
   132   apply (induct k)
   133    apply (simp add: card_s_0_eq_empty, atomize)
   134   apply (rotate_tac -1, erule finite_induct)
   135    apply (simp_all (no_asm_simp) cong add: conj_cong
   136      add: card_s_0_eq_empty choose_deconstruct)
   137   apply (subst card_Un_disjoint)
   138      prefer 4 apply (force simp add: constr_bij)
   139     prefer 3 apply force
   140    prefer 2 apply (blast intro: finite_Pow_iff [THEN iffD2]
   141      finite_subset [of _ "Pow (insert x F)", standard])
   142   apply (blast intro: finite_Pow_iff [THEN iffD2, THEN [2] finite_subset])
   143   done
   144 
   145 theorem n_subsets:
   146     "finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
   147   by (simp add: n_sub_lemma)
   148 
   149 
   150 text{* The binomial theorem (courtesy of Tobias Nipkow): *}
   151 
   152 theorem binomial: "(a+b::nat)^n = (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
   153 proof (induct n)
   154   case 0 thus ?case by simp
   155 next
   156   case (Suc n)
   157   have decomp: "{0..n+1} = {0} \<union> {n+1} \<union> {1..n}"
   158     by (auto simp add:atLeastAtMost_def atLeast_def atMost_def)
   159   have decomp2: "{0..n} = {0} \<union> {1..n}"
   160     by (auto simp add:atLeastAtMost_def atLeast_def atMost_def)
   161   have "(a+b::nat)^(n+1) = (a+b) * (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
   162     using Suc by simp
   163   also have "\<dots> =  a*(\<Sum>k=0..n. (n choose k) * a^k * b^(n-k)) +
   164                    b*(\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
   165     by (rule nat_distrib)
   166   also have "\<dots> = (\<Sum>k=0..n. (n choose k) * a^(k+1) * b^(n-k)) +
   167                   (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k+1))"
   168     by (simp add: setsum_right_distrib mult_ac)
   169   also have "\<dots> = (\<Sum>k=0..n. (n choose k) * a^k * b^(n+1-k)) +
   170                   (\<Sum>k=1..n+1. (n choose (k - 1)) * a^k * b^(n+1-k))"
   171     by (simp add:setsum_shift_bounds_cl_Suc_ivl Suc_diff_le
   172              del:setsum_cl_ivl_Suc)
   173   also have "\<dots> = a^(n+1) + b^(n+1) +
   174                   (\<Sum>k=1..n. (n choose (k - 1)) * a^k * b^(n+1-k)) +
   175                   (\<Sum>k=1..n. (n choose k) * a^k * b^(n+1-k))"
   176     by (simp add: decomp2)
   177   also have
   178       "\<dots> = a^(n+1) + b^(n+1) + (\<Sum>k=1..n. (n+1 choose k) * a^k * b^(n+1-k))"
   179     by (simp add: nat_distrib setsum_addf binomial.simps)
   180   also have "\<dots> = (\<Sum>k=0..n+1. (n+1 choose k) * a^k * b^(n+1-k))"
   181     using decomp by simp
   182   finally show ?case by simp
   183 qed
   184 
   185 section{* Pochhammer's symbol : generalized raising factorial*}
   186 
   187 definition "pochhammer (a::'a::comm_semiring_1) n = (if n = 0 then 1 else setprod (\<lambda>n. a + of_nat n) {0 .. n - 1})"
   188 
   189 lemma pochhammer_0[simp]: "pochhammer a 0 = 1" 
   190   by (simp add: pochhammer_def)
   191 
   192 lemma pochhammer_1[simp]: "pochhammer a 1 = a" by (simp add: pochhammer_def)
   193 lemma pochhammer_Suc0[simp]: "pochhammer a (Suc 0) = a" 
   194   by (simp add: pochhammer_def)
   195 
   196 lemma pochhammer_Suc_setprod: "pochhammer a (Suc n) = setprod (\<lambda>n. a + of_nat n) {0 .. n}"
   197   by (simp add: pochhammer_def)
   198 
   199 lemma setprod_nat_ivl_Suc: "setprod f {0 .. Suc n} = setprod f {0..n} * f (Suc n)"
   200 proof-
   201   have th: "finite {0..n}" "finite {Suc n}" "{0..n} \<inter> {Suc n} = {}" by auto
   202   have eq: "{0..Suc n} = {0..n} \<union> {Suc n}" by auto
   203   show ?thesis unfolding eq setprod_Un_disjoint[OF th] by simp
   204 qed
   205 
   206 lemma setprod_nat_ivl_1_Suc: "setprod f {0 .. Suc n} = f 0 * setprod f {1.. Suc n}"
   207 proof-
   208   have th: "finite {0}" "finite {1..Suc n}" "{0} \<inter> {1.. Suc n} = {}" by auto
   209   have eq: "{0..Suc n} = {0} \<union> {1 .. Suc n}" by auto
   210   show ?thesis unfolding eq setprod_Un_disjoint[OF th] by simp
   211 qed
   212 
   213 
   214 lemma pochhammer_Suc: "pochhammer a (Suc n) = pochhammer a n * (a + of_nat n)"
   215 proof-
   216   {assume "n=0" then have ?thesis by simp}
   217   moreover
   218   {fix m assume m: "n = Suc m"
   219     have ?thesis  unfolding m pochhammer_Suc_setprod setprod_nat_ivl_Suc ..}
   220   ultimately show ?thesis by (cases n, auto)
   221 qed 
   222 
   223 lemma pochhammer_rec: "pochhammer a (Suc n) = a * pochhammer (a + 1) n"
   224 proof-
   225   {assume "n=0" then have ?thesis by (simp add: pochhammer_Suc_setprod)}
   226   moreover
   227   {assume n0: "n \<noteq> 0"
   228     have th0: "finite {1 .. n}" "0 \<notin> {1 .. n}" by auto
   229     have eq: "insert 0 {1 .. n} = {0..n}" by auto
   230     have th1: "(\<Prod>n\<in>{1\<Colon>nat..n}. a + of_nat n) =
   231       (\<Prod>n\<in>{0\<Colon>nat..n - 1}. a + 1 + of_nat n)"
   232       apply (rule setprod_reindex_cong[where f = "Suc"])
   233       using n0 by (auto simp add: expand_fun_eq ring_simps)
   234     have ?thesis apply (simp add: pochhammer_def)
   235     unfolding setprod_insert[OF th0, unfolded eq]
   236     using th1 by (simp add: ring_simps)}
   237 ultimately show ?thesis by blast
   238 qed
   239 
   240 lemma fact_setprod: "fact n = setprod id {1 .. n}"
   241   apply (induct n, simp)
   242   apply (simp only: fact_Suc atLeastAtMostSuc_conv)
   243   apply (subst setprod_insert)
   244   by simp_all
   245 
   246 lemma pochhammer_fact: "of_nat (fact n) = pochhammer 1 n"
   247   unfolding fact_setprod
   248   
   249   apply (cases n, simp_all add: of_nat_setprod pochhammer_Suc_setprod)
   250   apply (rule setprod_reindex_cong[where f=Suc])
   251   by (auto simp add: expand_fun_eq)
   252 
   253 lemma pochhammer_of_nat_eq_0_lemma: assumes kn: "k > n"
   254   shows "pochhammer (- (of_nat n :: 'a:: idom)) k = 0"
   255 proof-
   256   from kn obtain h where h: "k = Suc h" by (cases k, auto)
   257   {assume n0: "n=0" then have ?thesis using kn 
   258       by (cases k, simp_all add: pochhammer_rec del: pochhammer_Suc)}
   259   moreover
   260   {assume n0: "n \<noteq> 0"
   261     then have ?thesis apply (simp add: h pochhammer_Suc_setprod)
   262   apply (rule iffD2[OF setprod_zero_eq])
   263   apply auto
   264   apply (rule_tac x="n" in bexI)
   265   using h kn by auto}
   266 ultimately show ?thesis by blast
   267 qed
   268 
   269 lemma pochhammer_of_nat_eq_0_lemma': assumes kn: "k \<le> n"
   270   shows "pochhammer (- (of_nat n :: 'a:: {idom, ring_char_0})) k \<noteq> 0"
   271 proof-
   272   {assume "k=0" then have ?thesis by simp}
   273   moreover
   274   {fix h assume h: "k = Suc h"
   275     then have ?thesis apply (simp add: pochhammer_Suc_setprod)
   276       apply (subst setprod_zero_eq_field)
   277       using h kn by (auto simp add: ring_simps)}
   278   ultimately show ?thesis by (cases k, auto)
   279 qed
   280 
   281 lemma pochhammer_of_nat_eq_0_iff: 
   282   shows "pochhammer (- (of_nat n :: 'a:: {idom, ring_char_0})) k = 0 \<longleftrightarrow> k > n"
   283   (is "?l = ?r")
   284   using pochhammer_of_nat_eq_0_lemma[of n k, where ?'a='a] 
   285     pochhammer_of_nat_eq_0_lemma'[of k n, where ?'a = 'a]
   286   by (auto simp add: not_le[symmetric])
   287 
   288 section{* Generalized binomial coefficients *}
   289 
   290 definition gbinomial :: "'a::{field, recpower,ring_char_0} \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65)
   291   where "a gchoose n = (if n = 0 then 1 else (setprod (\<lambda>i. a - of_nat i) {0 .. n - 1}) / of_nat (fact n))"
   292 
   293 lemma gbinomial_0[simp]: "a gchoose 0 = 1" "0 gchoose (Suc n) = 0"
   294   apply (simp_all add: gbinomial_def)
   295   apply (subgoal_tac "(\<Prod>i\<Colon>nat\<in>{0\<Colon>nat..n}. - of_nat i) = (0::'b)")
   296   apply simp
   297   apply (rule iffD2[OF setprod_zero_eq])
   298   by auto
   299 
   300 lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / of_nat (fact n)"
   301 proof-
   302 
   303   {assume "n=0" then have ?thesis by simp}
   304   moreover
   305   {assume n0: "n\<noteq>0"
   306     from n0 setprod_constant[of "{0 .. n - 1}" "- (1:: 'a)"]
   307     have eq: "(- (1\<Colon>'a)) ^ n = setprod (\<lambda>i. - 1) {0 .. n - 1}"
   308       by auto
   309     from n0 have ?thesis 
   310       by (simp add: pochhammer_def gbinomial_def field_simps eq setprod_timesf[symmetric])}
   311   ultimately show ?thesis by blast
   312 qed
   313 
   314 lemma binomial_fact_lemma:
   315   "k \<le> n \<Longrightarrow> fact k * fact (n - k) * (n choose k) = fact n"
   316 proof(induct n arbitrary: k rule: nat_less_induct)
   317   fix n k assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) =
   318                       fact m" and kn: "k \<le> n"
   319     let ?ths = "fact k * fact (n - k) * (n choose k) = fact n"
   320   {assume "n=0" then have ?ths using kn by simp}
   321   moreover
   322   {assume "k=0" then have ?ths using kn by simp}
   323   moreover
   324   {assume nk: "n=k" then have ?ths by simp}
   325   moreover
   326   {fix m h assume n: "n = Suc m" and h: "k = Suc h" and hm: "h < m"
   327     from n have mn: "m < n" by arith
   328     from hm have hm': "h \<le> m" by arith
   329     from hm h n kn have km: "k \<le> m" by arith
   330     have "m - h = Suc (m - Suc h)" using  h km hm by arith 
   331     with km h have th0: "fact (m - h) = (m - h) * fact (m - k)"
   332       by simp
   333     from n h th0 
   334     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))"
   335       by (simp add: ring_simps)
   336     also have "\<dots> = (k + (m - h)) * fact m"
   337       using H[rule_format, OF mn hm'] H[rule_format, OF mn km]
   338       by (simp add: ring_simps)
   339     finally have ?ths using h n km by simp}
   340   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
   341   ultimately show ?ths by blast
   342 qed
   343   
   344 lemma binomial_fact: 
   345   assumes kn: "k \<le> n" 
   346   shows "(of_nat (n choose k) :: 'a::{field, ring_char_0}) = of_nat (fact n) / (of_nat (fact k) * of_nat (fact (n - k)))"
   347   using binomial_fact_lemma[OF kn]
   348   by (simp add: field_simps fact_not_eq_zero of_nat_mult[symmetric])
   349 
   350 
   351 lemma binomial_gbinomial: "of_nat (n choose k) = of_nat n gchoose k"
   352 proof-
   353   {assume kn: "k > n" 
   354     from kn binomial_eq_0[OF kn] have ?thesis 
   355       by (simp add: gbinomial_pochhammer field_simps
   356 	pochhammer_of_nat_eq_0_iff)}
   357   moreover
   358   {assume "k=0" then have ?thesis by simp}
   359   moreover
   360   {assume kn: "k \<le> n" and k0: "k\<noteq> 0"
   361     from k0 obtain h where h: "k = Suc h" by (cases k, auto)
   362     from h
   363     have eq:"(- 1 :: 'a) ^ k = setprod (\<lambda>i. - 1) {0..h}"
   364       by (subst setprod_constant, auto)
   365     have eq': "(\<Prod>i\<in>{0..h}. of_nat n + - (of_nat i :: 'a)) = (\<Prod>i\<in>{n - h..n}. of_nat i)"
   366       apply (rule strong_setprod_reindex_cong[where f="op - n"])
   367       using h kn 
   368       apply (simp_all add: inj_on_def image_iff Bex_def expand_set_eq)
   369       apply clarsimp
   370       apply (presburger)
   371       apply presburger
   372       by (simp add: expand_fun_eq ring_simps of_nat_add[symmetric] del: of_nat_add)
   373     have th0: "finite {1..n - Suc h}" "finite {n - h .. n}" 
   374 "{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
   375     from eq[symmetric]
   376     have ?thesis using kn
   377       apply (simp add: binomial_fact[OF kn, where ?'a = 'a] 
   378 	gbinomial_pochhammer field_simps pochhammer_Suc_setprod)
   379       apply (simp add: pochhammer_Suc_setprod fact_setprod h of_nat_setprod setprod_timesf[symmetric] eq' del: One_nat_def)
   380       unfolding setprod_Un_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h]
   381       unfolding mult_assoc[symmetric] 
   382       unfolding setprod_timesf[symmetric]
   383       apply simp
   384       apply (rule disjI2)
   385       apply (rule strong_setprod_reindex_cong[where f= "op - n"])
   386       apply (auto simp add: inj_on_def image_iff Bex_def)
   387       apply presburger
   388       apply (subgoal_tac "(of_nat (n - x) :: 'a) = of_nat n - of_nat x")
   389       apply simp
   390       by (rule of_nat_diff, simp)
   391   }
   392   moreover
   393   have "k > n \<or> k = 0 \<or> (k \<le> n \<and> k \<noteq> 0)" by arith
   394   ultimately show ?thesis by blast
   395 qed
   396 
   397 lemma gbinomial_1[simp]: "a gchoose 1 = a"
   398   by (simp add: gbinomial_def)
   399 
   400 lemma gbinomial_Suc0[simp]: "a gchoose (Suc 0) = a"
   401   by (simp add: gbinomial_def)
   402 
   403 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")
   404 proof-
   405   have "?r = ((- 1) ^n * pochhammer (- a) n / of_nat (fact n)) * (of_nat n - (- a + of_nat n))"
   406     unfolding gbinomial_pochhammer
   407     pochhammer_Suc fact_Suc of_nat_mult right_diff_distrib power_Suc
   408     by (simp add:  field_simps del: of_nat_Suc)
   409   also have "\<dots> = ?l" unfolding gbinomial_pochhammer
   410     by (simp add: ring_simps)
   411   finally show ?thesis ..
   412 qed
   413 
   414 lemma gbinomial_mult_1': "(a gchoose n) * a = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"
   415   by (simp add: mult_commute gbinomial_mult_1)
   416 
   417 lemma gbinomial_Suc: "a gchoose (Suc k) = (setprod (\<lambda>i. a - of_nat i) {0 .. k}) / of_nat (fact (Suc k))"
   418   by (simp add: gbinomial_def)
   419  
   420 lemma gbinomial_mult_fact:
   421   "(of_nat (fact (Suc k)) :: 'a) * ((a::'a::{field, ring_char_0,recpower}) gchoose (Suc k)) = (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
   422   unfolding gbinomial_Suc
   423   by (simp_all add: field_simps del: fact_Suc)
   424 
   425 lemma gbinomial_mult_fact':
   426   "((a::'a::{field, ring_char_0,recpower}) gchoose (Suc k)) * (of_nat (fact (Suc k)) :: 'a) = (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
   427   using gbinomial_mult_fact[of k a]
   428   apply (subst mult_commute) .
   429 
   430 lemma gbinomial_Suc_Suc: "((a::'a::{field,recpower, ring_char_0}) + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))"
   431 proof-
   432   {assume "k = 0" then have ?thesis by simp}
   433   moreover
   434   {fix h assume h: "k = Suc h"
   435    have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)"
   436      apply (rule strong_setprod_reindex_cong[where f = Suc])
   437      using h by auto
   438 
   439     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)" 
   440       unfolding h
   441       apply (simp add: ring_simps del: fact_Suc)
   442       unfolding gbinomial_mult_fact'
   443       apply (subst fact_Suc)
   444       unfolding of_nat_mult 
   445       apply (subst mult_commute)
   446       unfolding mult_assoc
   447       unfolding gbinomial_mult_fact
   448       by (simp add: ring_simps)
   449     also have "\<dots> = (\<Prod>i\<in>{0..h}. a - of_nat i) * (a + 1)"
   450       unfolding gbinomial_mult_fact' setprod_nat_ivl_Suc
   451       by (simp add: ring_simps h)
   452     also have "\<dots> = (\<Prod>i\<in>{0..k}. (a + 1) - of_nat i)"
   453       using eq0
   454       unfolding h  setprod_nat_ivl_1_Suc
   455       by simp
   456     also have "\<dots> = of_nat (fact (Suc k)) * ((a + 1) gchoose (Suc k))"
   457       unfolding gbinomial_mult_fact ..
   458     finally have ?thesis by (simp del: fact_Suc) }
   459   ultimately show ?thesis by (cases k, auto)
   460 qed
   461 
   462 end