753 by (auto intro: prod_zero) |
753 by (auto intro: prod_zero) |
754 with \<open>n < k\<close> show ?thesis |
754 with \<open>n < k\<close> show ?thesis |
755 by (simp add: binomial_eq_0 gbinomial_prod_rev prod_zero) |
755 by (simp add: binomial_eq_0 gbinomial_prod_rev prod_zero) |
756 next |
756 next |
757 case True |
757 case True |
758 then have "inj_on (op - n) {0..<k}" |
758 from True have *: "prod (op - n) {0..<k} = \<Prod>{Suc (n - k)..n}" |
759 by (auto intro: inj_onI) |
759 by (intro prod.reindex_bij_witness[of _ "\<lambda>i. n - i" "\<lambda>i. n - i"]) auto |
760 then have "\<Prod>(op - n ` {0..<k}) = prod (op - n) {0..<k}" |
|
761 by (auto dest: prod.reindex) |
|
762 also have "op - n ` {0..<k} = {Suc (n - k)..n}" |
|
763 using True by (auto simp add: image_def Bex_def) presburger (* FIXME slow *) |
|
764 finally have *: "prod (\<lambda>q. n - q) {0..<k} = \<Prod>{Suc (n - k)..n}" .. |
|
765 from True have "n choose k = fact n div (fact k * fact (n - k))" |
760 from True have "n choose k = fact n div (fact k * fact (n - k))" |
766 by (rule binomial_fact') |
761 by (rule binomial_fact') |
767 with * show ?thesis |
762 with * show ?thesis |
768 by (simp add: gbinomial_prod_rev mult.commute [of "fact k"] div_mult2_eq fact_div_fact) |
763 by (simp add: gbinomial_prod_rev mult.commute [of "fact k"] div_mult2_eq fact_div_fact) |
769 qed |
764 qed |
1556 have fin_B: "finite ?B" |
1551 have fin_B: "finite ?B" |
1557 by (intro finite_subset[where ?A = "?B" and ?B = "{xs. size xs = m \<and> set xs \<subseteq> {0..<N}}"]) |
1552 by (intro finite_subset[where ?A = "?B" and ?B = "{xs. size xs = m \<and> set xs \<subseteq> {0..<N}}"]) |
1558 (auto simp: member_le_sum_list_nat less_Suc_eq_le fin) |
1553 (auto simp: member_le_sum_list_nat less_Suc_eq_le fin) |
1559 have uni: "?C = ?A' \<union> ?B'" |
1554 have uni: "?C = ?A' \<union> ?B'" |
1560 by auto |
1555 by auto |
1561 have disj: "?A' \<inter> ?B' = {}" |
1556 have disj: "?A' \<inter> ?B' = {}" by blast |
1562 by auto |
|
1563 have "card ?C = card(?A' \<union> ?B')" |
1557 have "card ?C = card(?A' \<union> ?B')" |
1564 using uni by simp |
1558 using uni by simp |
1565 also have "\<dots> = card ?A + card ?B" |
1559 also have "\<dots> = card ?A + card ?B" |
1566 using card_Un_disjoint[OF _ _ disj] bij_betw_finite[OF f] bij_betw_finite[OF g] |
1560 using card_Un_disjoint[OF _ _ disj] bij_betw_finite[OF f] bij_betw_finite[OF g] |
1567 bij_betw_same_card[OF f] bij_betw_same_card[OF g] fin_A fin_B |
1561 bij_betw_same_card[OF f] bij_betw_same_card[OF g] fin_A fin_B |
1620 then show ?case |
1614 then show ?case |
1621 using card_length_sum_list_rec[OF Suc.prems] by auto |
1615 using card_length_sum_list_rec[OF Suc.prems] by auto |
1622 qed |
1616 qed |
1623 qed |
1617 qed |
1624 |
1618 |
|
1619 lemma card_disjoint_shuffle: |
|
1620 assumes "set xs \<inter> set ys = {}" |
|
1621 shows "card (shuffle xs ys) = (length xs + length ys) choose length xs" |
|
1622 using assms |
|
1623 proof (induction xs ys rule: shuffle.induct) |
|
1624 case (3 x xs y ys) |
|
1625 have "shuffle (x # xs) (y # ys) = op # x ` shuffle xs (y # ys) \<union> op # y ` shuffle (x # xs) ys" |
|
1626 by (rule shuffle.simps) |
|
1627 also have "card \<dots> = card (op # x ` shuffle xs (y # ys)) + card (op # y ` shuffle (x # xs) ys)" |
|
1628 by (rule card_Un_disjoint) (insert "3.prems", auto) |
|
1629 also have "card (op # x ` shuffle xs (y # ys)) = card (shuffle xs (y # ys))" |
|
1630 by (rule card_image) auto |
|
1631 also have "\<dots> = (length xs + length (y # ys)) choose length xs" |
|
1632 using "3.prems" by (intro "3.IH") auto |
|
1633 also have "card (op # y ` shuffle (x # xs) ys) = card (shuffle (x # xs) ys)" |
|
1634 by (rule card_image) auto |
|
1635 also have "\<dots> = (length (x # xs) + length ys) choose length (x # xs)" |
|
1636 using "3.prems" by (intro "3.IH") auto |
|
1637 also have "length xs + length (y # ys) choose length xs + \<dots> = |
|
1638 (length (x # xs) + length (y # ys)) choose length (x # xs)" by simp |
|
1639 finally show ?case . |
|
1640 qed auto |
|
1641 |
1625 lemma Suc_times_binomial_add: "Suc a * (Suc (a + b) choose Suc a) = Suc b * (Suc (a + b) choose a)" |
1642 lemma Suc_times_binomial_add: "Suc a * (Suc (a + b) choose Suc a) = Suc b * (Suc (a + b) choose a)" |
1626 \<comment> \<open>by Lukas Bulwahn\<close> |
1643 \<comment> \<open>by Lukas Bulwahn\<close> |
1627 proof - |
1644 proof - |
1628 have dvd: "Suc a * (fact a * fact b) dvd fact (Suc (a + b))" for a b |
1645 have dvd: "Suc a * (fact a * fact b) dvd fact (Suc (a + b))" for a b |
1629 using fact_fact_dvd_fact[of "Suc a" "b", where 'a=nat] |
1646 using fact_fact_dvd_fact[of "Suc a" "b", where 'a=nat] |