equal
deleted
inserted
replaced
241 unfolding setprod_insert[OF th0, unfolded eq] |
241 unfolding setprod_insert[OF th0, unfolded eq] |
242 using th1 by (simp add: ring_simps)} |
242 using th1 by (simp add: ring_simps)} |
243 ultimately show ?thesis by blast |
243 ultimately show ?thesis by blast |
244 qed |
244 qed |
245 |
245 |
246 lemma fact_setprod: "fact n = setprod id {1 .. n}" |
|
247 apply (induct n, simp) |
|
248 apply (simp only: fact_Suc atLeastAtMostSuc_conv) |
|
249 apply (subst setprod_insert) |
|
250 by simp_all |
|
251 |
|
252 lemma pochhammer_fact: "of_nat (fact n) = pochhammer 1 n" |
246 lemma pochhammer_fact: "of_nat (fact n) = pochhammer 1 n" |
253 unfolding fact_setprod |
247 unfolding fact_altdef_nat |
254 |
248 |
255 apply (cases n, simp_all add: of_nat_setprod pochhammer_Suc_setprod) |
249 apply (cases n, simp_all add: of_nat_setprod pochhammer_Suc_setprod) |
256 apply (rule setprod_reindex_cong[where f=Suc]) |
250 apply (rule setprod_reindex_cong[where f=Suc]) |
257 by (auto simp add: expand_fun_eq) |
251 by (auto simp add: expand_fun_eq) |
258 |
252 |
345 |
339 |
346 lemma binomial_fact: |
340 lemma binomial_fact: |
347 assumes kn: "k \<le> n" |
341 assumes kn: "k \<le> n" |
348 shows "(of_nat (n choose k) :: 'a::field_char_0) = of_nat (fact n) / (of_nat (fact k) * of_nat (fact (n - k)))" |
342 shows "(of_nat (n choose k) :: 'a::field_char_0) = of_nat (fact n) / (of_nat (fact k) * of_nat (fact (n - k)))" |
349 using binomial_fact_lemma[OF kn] |
343 using binomial_fact_lemma[OF kn] |
350 by (simp add: field_simps fact_not_eq_zero of_nat_mult[symmetric]) |
344 by (simp add: field_simps of_nat_mult[symmetric]) |
351 |
345 |
352 lemma binomial_gbinomial: "of_nat (n choose k) = of_nat n gchoose k" |
346 lemma binomial_gbinomial: "of_nat (n choose k) = of_nat n gchoose k" |
353 proof- |
347 proof- |
354 {assume kn: "k > n" |
348 {assume kn: "k > n" |
355 from kn binomial_eq_0[OF kn] have ?thesis |
349 from kn binomial_eq_0[OF kn] have ?thesis |
375 "{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 |
369 "{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 |
376 from eq[symmetric] |
370 from eq[symmetric] |
377 have ?thesis using kn |
371 have ?thesis using kn |
378 apply (simp add: binomial_fact[OF kn, where ?'a = 'a] |
372 apply (simp add: binomial_fact[OF kn, where ?'a = 'a] |
379 gbinomial_pochhammer field_simps pochhammer_Suc_setprod) |
373 gbinomial_pochhammer field_simps pochhammer_Suc_setprod) |
380 apply (simp add: pochhammer_Suc_setprod fact_setprod h of_nat_setprod setprod_timesf[symmetric] eq' del: One_nat_def power_Suc) |
374 apply (simp add: pochhammer_Suc_setprod fact_altdef_nat h of_nat_setprod setprod_timesf[symmetric] eq' del: One_nat_def power_Suc) |
381 unfolding setprod_Un_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h] |
375 unfolding setprod_Un_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h] |
382 unfolding mult_assoc[symmetric] |
376 unfolding mult_assoc[symmetric] |
383 unfolding setprod_timesf[symmetric] |
377 unfolding setprod_timesf[symmetric] |
384 apply simp |
378 apply simp |
385 apply (rule strong_setprod_reindex_cong[where f= "op - n"]) |
379 apply (rule strong_setprod_reindex_cong[where f= "op - n"]) |
402 |
396 |
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") |
397 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- |
398 proof- |
405 have "?r = ((- 1) ^n * pochhammer (- a) n / of_nat (fact n)) * (of_nat n - (- a + of_nat n))" |
399 have "?r = ((- 1) ^n * pochhammer (- a) n / of_nat (fact n)) * (of_nat n - (- a + of_nat n))" |
406 unfolding gbinomial_pochhammer |
400 unfolding gbinomial_pochhammer |
407 pochhammer_Suc fact_Suc of_nat_mult right_diff_distrib power_Suc |
401 pochhammer_Suc fact_Suc_nat of_nat_mult right_diff_distrib power_Suc |
408 by (simp add: field_simps del: of_nat_Suc) |
402 by (simp add: field_simps del: of_nat_Suc) |
409 also have "\<dots> = ?l" unfolding gbinomial_pochhammer |
403 also have "\<dots> = ?l" unfolding gbinomial_pochhammer |
410 by (simp add: ring_simps) |
404 by (simp add: ring_simps) |
411 finally show ?thesis .. |
405 finally show ?thesis .. |
412 qed |
406 qed |
418 by (simp add: gbinomial_def) |
412 by (simp add: gbinomial_def) |
419 |
413 |
420 lemma gbinomial_mult_fact: |
414 lemma gbinomial_mult_fact: |
421 "(of_nat (fact (Suc k)) :: 'a) * ((a::'a::field_char_0) gchoose (Suc k)) = (setprod (\<lambda>i. a - of_nat i) {0 .. k})" |
415 "(of_nat (fact (Suc k)) :: 'a) * ((a::'a::field_char_0) gchoose (Suc k)) = (setprod (\<lambda>i. a - of_nat i) {0 .. k})" |
422 unfolding gbinomial_Suc |
416 unfolding gbinomial_Suc |
423 by (simp_all add: field_simps del: fact_Suc) |
417 by (simp_all add: field_simps del: fact_Suc_nat) |
424 |
418 |
425 lemma gbinomial_mult_fact': |
419 lemma gbinomial_mult_fact': |
426 "((a::'a::field_char_0) gchoose (Suc k)) * (of_nat (fact (Suc k)) :: 'a) = (setprod (\<lambda>i. a - of_nat i) {0 .. k})" |
420 "((a::'a::field_char_0) 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] |
421 using gbinomial_mult_fact[of k a] |
428 apply (subst mult_commute) . |
422 apply (subst mult_commute) . |
436 apply (rule strong_setprod_reindex_cong[where f = Suc]) |
430 apply (rule strong_setprod_reindex_cong[where f = Suc]) |
437 using h by auto |
431 using h by auto |
438 |
432 |
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)" |
433 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 |
434 unfolding h |
441 apply (simp add: ring_simps del: fact_Suc) |
435 apply (simp add: ring_simps del: fact_Suc_nat) |
442 unfolding gbinomial_mult_fact' |
436 unfolding gbinomial_mult_fact' |
443 apply (subst fact_Suc) |
437 apply (subst fact_Suc_nat) |
444 unfolding of_nat_mult |
438 unfolding of_nat_mult |
445 apply (subst mult_commute) |
439 apply (subst mult_commute) |
446 unfolding mult_assoc |
440 unfolding mult_assoc |
447 unfolding gbinomial_mult_fact |
441 unfolding gbinomial_mult_fact |
448 by (simp add: ring_simps) |
442 by (simp add: ring_simps) |
453 using eq0 |
447 using eq0 |
454 unfolding h setprod_nat_ivl_1_Suc |
448 unfolding h setprod_nat_ivl_1_Suc |
455 by simp |
449 by simp |
456 also have "\<dots> = of_nat (fact (Suc k)) * ((a + 1) gchoose (Suc k))" |
450 also have "\<dots> = of_nat (fact (Suc k)) * ((a + 1) gchoose (Suc k))" |
457 unfolding gbinomial_mult_fact .. |
451 unfolding gbinomial_mult_fact .. |
458 finally have ?thesis by (simp del: fact_Suc) } |
452 finally have ?thesis by (simp del: fact_Suc_nat) } |
459 ultimately show ?thesis by (cases k, auto) |
453 ultimately show ?thesis by (cases k, auto) |
460 qed |
454 qed |
461 |
455 |
462 end |
456 end |