equal
deleted
inserted
replaced
547 definition gbinomial :: "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65) |
547 definition gbinomial :: "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65) |
548 where "a gchoose n = |
548 where "a gchoose n = |
549 (if n = 0 then 1 else (setprod (\<lambda>i. a - of_nat i) {0 .. n - 1}) / (fact n))" |
549 (if n = 0 then 1 else (setprod (\<lambda>i. a - of_nat i) {0 .. n - 1}) / (fact n))" |
550 |
550 |
551 lemma gbinomial_0 [simp]: "a gchoose 0 = 1" "0 gchoose (Suc n) = 0" |
551 lemma gbinomial_0 [simp]: "a gchoose 0 = 1" "0 gchoose (Suc n) = 0" |
552 apply (simp_all add: gbinomial_def) |
552 by (simp_all add: gbinomial_def) |
553 apply (subgoal_tac "(\<Prod>i\<Colon>nat\<in>{0\<Colon>nat..n}. - of_nat i) = (0::'b)") |
|
554 apply (simp del:setprod_zero_iff) |
|
555 apply simp |
|
556 done |
|
557 |
553 |
558 lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / (fact n)" |
554 lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / (fact n)" |
559 proof (cases "n = 0") |
555 proof (cases "n = 0") |
560 case True |
556 case True |
561 then show ?thesis by simp |
557 then show ?thesis by simp |
719 |
715 |
720 text{*Contributed by Manuel Eberl, generalised by LCP. |
716 text{*Contributed by Manuel Eberl, generalised by LCP. |
721 Alternative definition of the binomial coefficient as @{term "\<Prod>i<k. (n - i) / (k - i)"} *} |
717 Alternative definition of the binomial coefficient as @{term "\<Prod>i<k. (n - i) / (k - i)"} *} |
722 lemma gbinomial_altdef_of_nat: |
718 lemma gbinomial_altdef_of_nat: |
723 fixes k :: nat |
719 fixes k :: nat |
724 and x :: "'a :: {field_char_0,field_inverse_zero}" |
720 and x :: "'a :: {field_char_0,field}" |
725 shows "x gchoose k = (\<Prod>i<k. (x - of_nat i) / of_nat (k - i) :: 'a)" |
721 shows "x gchoose k = (\<Prod>i<k. (x - of_nat i) / of_nat (k - i) :: 'a)" |
726 proof - |
722 proof - |
727 have "(x gchoose k) = (\<Prod>i<k. x - of_nat i) / of_nat (fact k)" |
723 have "(x gchoose k) = (\<Prod>i<k. x - of_nat i) / of_nat (fact k)" |
728 unfolding gbinomial_def |
724 unfolding gbinomial_def |
729 by (auto simp: gr0_conv_Suc lessThan_Suc_atMost atLeast0AtMost) |
725 by (auto simp: gr0_conv_Suc lessThan_Suc_atMost atLeast0AtMost) |
733 finally show ?thesis . |
729 finally show ?thesis . |
734 qed |
730 qed |
735 |
731 |
736 lemma gbinomial_ge_n_over_k_pow_k: |
732 lemma gbinomial_ge_n_over_k_pow_k: |
737 fixes k :: nat |
733 fixes k :: nat |
738 and x :: "'a :: linordered_field_inverse_zero" |
734 and x :: "'a :: linordered_field" |
739 assumes "of_nat k \<le> x" |
735 assumes "of_nat k \<le> x" |
740 shows "(x / of_nat k :: 'a) ^ k \<le> x gchoose k" |
736 shows "(x / of_nat k :: 'a) ^ k \<le> x gchoose k" |
741 proof - |
737 proof - |
742 have x: "0 \<le> x" |
738 have x: "0 \<le> x" |
743 using assms of_nat_0_le_iff order_trans by blast |
739 using assms of_nat_0_le_iff order_trans by blast |
763 qed |
759 qed |
764 |
760 |
765 text{*Versions of the theorems above for the natural-number version of "choose"*} |
761 text{*Versions of the theorems above for the natural-number version of "choose"*} |
766 lemma binomial_altdef_of_nat: |
762 lemma binomial_altdef_of_nat: |
767 fixes n k :: nat |
763 fixes n k :: nat |
768 and x :: "'a :: {field_char_0,field_inverse_zero}" --{*the point is to constrain @{typ 'a}*} |
764 and x :: "'a :: {field_char_0,field}" --{*the point is to constrain @{typ 'a}*} |
769 assumes "k \<le> n" |
765 assumes "k \<le> n" |
770 shows "of_nat (n choose k) = (\<Prod>i<k. of_nat (n - i) / of_nat (k - i) :: 'a)" |
766 shows "of_nat (n choose k) = (\<Prod>i<k. of_nat (n - i) / of_nat (k - i) :: 'a)" |
771 using assms |
767 using assms |
772 by (simp add: gbinomial_altdef_of_nat binomial_gbinomial of_nat_diff) |
768 by (simp add: gbinomial_altdef_of_nat binomial_gbinomial of_nat_diff) |
773 |
769 |
774 lemma binomial_ge_n_over_k_pow_k: |
770 lemma binomial_ge_n_over_k_pow_k: |
775 fixes k n :: nat |
771 fixes k n :: nat |
776 and x :: "'a :: linordered_field_inverse_zero" |
772 and x :: "'a :: linordered_field" |
777 assumes "k \<le> n" |
773 assumes "k \<le> n" |
778 shows "(of_nat n / of_nat k :: 'a) ^ k \<le> of_nat (n choose k)" |
774 shows "(of_nat n / of_nat k :: 'a) ^ k \<le> of_nat (n choose k)" |
779 by (simp add: assms gbinomial_ge_n_over_k_pow_k binomial_gbinomial of_nat_diff) |
775 by (simp add: assms gbinomial_ge_n_over_k_pow_k binomial_gbinomial of_nat_diff) |
780 |
776 |
781 lemma binomial_le_pow: |
777 lemma binomial_le_pow: |