| author | wenzelm | 
| Mon, 06 Feb 2023 15:04:21 +0100 | |
| changeset 77208 | a3f67a4459e1 | 
| parent 77172 | 816959264c32 | 
| child 78656 | 4da1e18a9633 | 
| permissions | -rw-r--r-- | 
| 63466 | 1 | (* Title: HOL/Binomial.thy | 
| 2 | Author: Jacques D. Fleuriot | |
| 3 | Author: Lawrence C Paulson | |
| 4 | Author: Jeremy Avigad | |
| 5 | Author: Chaitanya Mangla | |
| 6 | Author: Manuel Eberl | |
| 12196 | 7 | *) | 
| 8 | ||
| 65812 | 9 | section \<open>Binomial Coefficients and Binomial Theorem\<close> | 
| 15094 
a7d1a3fdc30d
conversion of Hyperreal/{Fact,Filter} to Isar scripts
 paulson parents: 
12196diff
changeset | 10 | |
| 59669 
de7792ea4090
renaming HOL/Fact.thy -> Binomial.thy
 paulson <lp15@cam.ac.uk> parents: 
59667diff
changeset | 11 | theory Binomial | 
| 65813 | 12 | imports Presburger Factorial | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 13 | begin | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 14 | |
| 63373 | 15 | subsection \<open>Binomial coefficients\<close> | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 16 | |
| 63466 | 17 | text \<open>This development is based on the work of Andy Gordon and Florian Kammueller.\<close> | 
| 18 | ||
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 19 | text \<open>Combinatorial definition\<close> | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 20 | |
| 63466 | 21 | definition binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat" (infixl "choose" 65) | 
| 22 |   where "n choose k = card {K\<in>Pow {0..<n}. card K = k}"
 | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 23 | |
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 24 | theorem n_subsets: | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 25 | assumes "finite A" | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 26 |   shows "card {B. B \<subseteq> A \<and> card B = k} = card A choose k"
 | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 27 | proof - | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 28 |   from assms obtain f where bij: "bij_betw f {0..<card A} A"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 29 | by (blast dest: ex_bij_betw_nat_finite) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 30 |   then have [simp]: "card (f ` C) = card C" if "C \<subseteq> {0..<card A}" for C
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 31 | by (meson bij_betw_imp_inj_on bij_betw_subset card_image that) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 32 |   from bij have "bij_betw (image f) (Pow {0..<card A}) (Pow A)"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 33 | by (rule bij_betw_Pow) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 34 |   then have "inj_on (image f) (Pow {0..<card A})"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 35 | by (rule bij_betw_imp_inj_on) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 36 |   moreover have "{K. K \<subseteq> {0..<card A} \<and> card K = k} \<subseteq> Pow {0..<card A}"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 37 | by auto | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 38 |   ultimately have "inj_on (image f) {K. K \<subseteq> {0..<card A} \<and> card K = k}"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 39 | by (rule inj_on_subset) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 40 |   then have "card {K. K \<subseteq> {0..<card A} \<and> card K = k} =
 | 
| 63466 | 41 |       card (image f ` {K. K \<subseteq> {0..<card A} \<and> card K = k})" (is "_ = card ?C")
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 42 | by (simp add: card_image) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 43 |   also have "?C = {K. K \<subseteq> f ` {0..<card A} \<and> card K = k}"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 44 | by (auto elim!: subset_imageE) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 45 |   also have "f ` {0..<card A} = A"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 46 | by (meson bij bij_betw_def) | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 47 | finally show ?thesis | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 48 | by (simp add: binomial_def) | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 49 | qed | 
| 63466 | 50 | |
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 51 | text \<open>Recursive characterization\<close> | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 52 | |
| 68785 | 53 | lemma binomial_n_0 [simp]: "n choose 0 = 1" | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 54 | proof - | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 55 |   have "{K \<in> Pow {0..<n}. card K = 0} = {{}}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 56 | by (auto dest: finite_subset) | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 57 | then show ?thesis | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 58 | by (simp add: binomial_def) | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 59 | qed | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 60 | |
| 68785 | 61 | lemma binomial_0_Suc [simp]: "0 choose Suc k = 0" | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 62 | by (simp add: binomial_def) | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 63 | |
| 68785 | 64 | lemma binomial_Suc_Suc [simp]: "Suc n choose Suc k = (n choose k) + (n choose Suc k)" | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 65 | proof - | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 66 |   let ?P = "\<lambda>n k. {K. K \<subseteq> {0..<n} \<and> card K = k}"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 67 | let ?Q = "?P (Suc n) (Suc k)" | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 68 | have inj: "inj_on (insert n) (?P n k)" | 
| 63466 | 69 | by rule (auto; metis atLeastLessThan_iff insert_iff less_irrefl subsetCE) | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 70 |   have disjoint: "insert n ` ?P n k \<inter> ?P n (Suc k) = {}"
 | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 71 | by auto | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 72 |   have "?Q = {K\<in>?Q. n \<in> K} \<union> {K\<in>?Q. n \<notin> K}"
 | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 73 | by auto | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 74 |   also have "{K\<in>?Q. n \<in> K} = insert n ` ?P n k" (is "?A = ?B")
 | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 75 | proof (rule set_eqI) | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 76 | fix K | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 77 |     have K_finite: "finite K" if "K \<subseteq> insert n {0..<n}"
 | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 78 | using that by (rule finite_subset) simp_all | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 79 | have Suc_card_K: "Suc (card K - Suc 0) = card K" if "n \<in> K" | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 80 | and "finite K" | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 81 | proof - | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 82 | from \<open>n \<in> K\<close> obtain L where "K = insert n L" and "n \<notin> L" | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 83 | by (blast elim: Set.set_insert) | 
| 72302 
d7d90ed4c74e
fixed some remarkably ugly proofs
 paulson <lp15@cam.ac.uk> parents: 
71720diff
changeset | 84 | with that show ?thesis by (simp add: card.insert_remove) | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 85 | qed | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 86 | show "K \<in> ?A \<longleftrightarrow> K \<in> ?B" | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 87 | by (subst in_image_insert_iff) | 
| 72302 
d7d90ed4c74e
fixed some remarkably ugly proofs
 paulson <lp15@cam.ac.uk> parents: 
71720diff
changeset | 88 | (auto simp add: card.insert_remove subset_eq_atLeast0_lessThan_finite | 
| 63466 | 89 | Diff_subset_conv K_finite Suc_card_K) | 
| 90 | qed | |
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 91 |   also have "{K\<in>?Q. n \<notin> K} = ?P n (Suc k)"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 92 | by (auto simp add: atLeast0_lessThan_Suc) | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 93 | finally show ?thesis using inj disjoint | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 94 | by (simp add: binomial_def card_Un_disjoint card_image) | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 95 | qed | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 96 | |
| 63466 | 97 | lemma binomial_eq_0: "n < k \<Longrightarrow> n choose k = 0" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 98 | by (auto simp add: binomial_def dest: subset_eq_atLeast0_lessThan_card) | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 99 | |
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 100 | lemma zero_less_binomial: "k \<le> n \<Longrightarrow> n choose k > 0" | 
| 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 101 | by (induct n k rule: diff_induct) simp_all | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 102 | |
| 63466 | 103 | lemma binomial_eq_0_iff [simp]: "n choose k = 0 \<longleftrightarrow> n < k" | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 104 | by (metis binomial_eq_0 less_numeral_extra(3) not_less zero_less_binomial) | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 105 | |
| 63466 | 106 | lemma zero_less_binomial_iff [simp]: "n choose k > 0 \<longleftrightarrow> k \<le> n" | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 107 | by (metis binomial_eq_0_iff not_less0 not_less zero_less_binomial) | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 108 | |
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 109 | lemma binomial_n_n [simp]: "n choose n = 1" | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 110 | by (induct n) (simp_all add: binomial_eq_0) | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 111 | |
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 112 | lemma binomial_Suc_n [simp]: "Suc n choose n = Suc n" | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 113 | by (induct n) simp_all | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 114 | |
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 115 | lemma binomial_1 [simp]: "n choose Suc 0 = n" | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 116 | by (induct n) simp_all | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 117 | |
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 118 | lemma choose_reduce_nat: | 
| 63466 | 119 | "0 < n \<Longrightarrow> 0 < k \<Longrightarrow> | 
| 120 | n choose k = ((n - 1) choose (k - 1)) + ((n - 1) choose k)" | |
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 121 | using binomial_Suc_Suc [of "n - 1" "k - 1"] by simp | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 122 | |
| 63466 | 123 | lemma Suc_times_binomial_eq: "Suc n * (n choose k) = (Suc n choose Suc k) * Suc k" | 
| 71699 | 124 | proof (induction n arbitrary: k) | 
| 125 | case 0 | |
| 126 | then show ?case | |
| 127 | by auto | |
| 128 | next | |
| 129 | case (Suc n) | |
| 130 | show ?case | |
| 131 | proof (cases k) | |
| 132 | case (Suc k') | |
| 133 | then show ?thesis | |
| 134 | using Suc.IH | |
| 135 | by (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq binomial_eq_0) | |
| 136 | qed auto | |
| 137 | qed | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 138 | |
| 60141 
833adf7db7d8
New material, mostly about limits. Consolidation.
 paulson <lp15@cam.ac.uk> parents: 
59867diff
changeset | 139 | lemma binomial_le_pow2: "n choose k \<le> 2^n" | 
| 71699 | 140 | proof (induction n arbitrary: k) | 
| 141 | case 0 | |
| 142 | then show ?case | |
| 143 | using le_less less_le_trans by fastforce | |
| 144 | next | |
| 145 | case (Suc n) | |
| 146 | show ?case | |
| 147 | proof (cases k) | |
| 148 | case (Suc k') | |
| 149 | then show ?thesis | |
| 150 | using Suc.IH by (simp add: add_le_mono mult_2) | |
| 151 | qed auto | |
| 152 | qed | |
| 60141 
833adf7db7d8
New material, mostly about limits. Consolidation.
 paulson <lp15@cam.ac.uk> parents: 
59867diff
changeset | 153 | |
| 63466 | 154 | text \<open>The absorption property.\<close> | 
| 155 | lemma Suc_times_binomial: "Suc k * (Suc n choose Suc k) = Suc n * (n choose k)" | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 156 | using Suc_times_binomial_eq by auto | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 157 | |
| 63466 | 158 | text \<open>This is the well-known version of absorption, but it's harder to use | 
| 159 | because of the need to reason about division.\<close> | |
| 160 | lemma binomial_Suc_Suc_eq_times: "(Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k" | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 161 | by (simp add: Suc_times_binomial_eq del: mult_Suc mult_Suc_right) | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 162 | |
| 63466 | 163 | text \<open>Another version of absorption, with \<open>-1\<close> instead of \<open>Suc\<close>.\<close> | 
| 164 | lemma times_binomial_minus1_eq: "0 < k \<Longrightarrow> k * (n choose k) = n * ((n - 1) choose (k - 1))" | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 165 | using Suc_times_binomial_eq [where n = "n - 1" and k = "k - 1"] | 
| 63648 | 166 | by (auto split: nat_diff_split) | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 167 | |
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 168 | |
| 60758 | 169 | subsection \<open>The binomial theorem (courtesy of Tobias Nipkow):\<close> | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 170 | |
| 63466 | 171 | text \<open>Avigad's version, generalized to any commutative ring\<close> | 
| 71351 | 172 | theorem binomial_ring: "(a + b :: 'a::comm_semiring_1)^n = | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 173 | (\<Sum>k\<le>n. (of_nat (n choose k)) * a^k * b^(n-k))" | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 174 | proof (induct n) | 
| 63466 | 175 | case 0 | 
| 176 | then show ?case by simp | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 177 | next | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 178 | case (Suc n) | 
| 63466 | 179 |   have decomp: "{0..n+1} = {0} \<union> {n + 1} \<union> {1..n}"
 | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 180 | by auto | 
| 63466 | 181 |   have decomp2: "{0..n} = {0} \<union> {1..n}"
 | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 182 | by auto | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 183 | have "(a + b)^(n+1) = (a + b) * (\<Sum>k\<le>n. of_nat (n choose k) * a^k * b^(n - k))" | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 184 | using Suc.hyps by simp | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 185 | also have "\<dots> = a * (\<Sum>k\<le>n. of_nat (n choose k) * a^k * b^(n-k)) + | 
| 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 186 | b * (\<Sum>k\<le>n. of_nat (n choose k) * a^k * b^(n-k))" | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 187 | by (rule distrib_right) | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 188 | also have "\<dots> = (\<Sum>k\<le>n. of_nat (n choose k) * a^(k+1) * b^(n-k)) + | 
| 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 189 | (\<Sum>k\<le>n. of_nat (n choose k) * a^k * b^(n - k + 1))" | 
| 64267 | 190 | by (auto simp add: sum_distrib_left ac_simps) | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 191 | also have "\<dots> = (\<Sum>k\<le>n. of_nat (n choose k) * a^k * b^(n + 1 - k)) + | 
| 63466 | 192 | (\<Sum>k=1..n+1. of_nat (n choose (k - 1)) * a^k * b^(n + 1 - k))" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 193 | by (simp add: atMost_atLeast0 sum.shift_bounds_cl_Suc_ivl Suc_diff_le field_simps del: sum.cl_ivl_Suc) | 
| 71351 | 194 | also have "\<dots> = b^(n + 1) + | 
| 195 | (\<Sum>k=1..n. of_nat (n choose k) * a^k * b^(n + 1 - k)) + (a^(n + 1) + | |
| 196 | (\<Sum>k=1..n. of_nat (n choose (k - 1)) * a^k * b^(n + 1 - k)))" | |
| 197 | using sum.nat_ivl_Suc' [of 1 n "\<lambda>k. of_nat (n choose (k-1)) * a ^ k * b ^ (n + 1 - k)"] | |
| 198 | by (simp add: sum.atLeast_Suc_atMost atMost_atLeast0) | |
| 63466 | 199 | also have "\<dots> = a^(n + 1) + b^(n + 1) + | 
| 200 | (\<Sum>k=1..n. of_nat (n + 1 choose k) * a^k * b^(n + 1 - k))" | |
| 64267 | 201 | by (auto simp add: field_simps sum.distrib [symmetric] choose_reduce_nat) | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 202 | also have "\<dots> = (\<Sum>k\<le>n+1. of_nat (n + 1 choose k) * a^k * b^(n + 1 - k))" | 
| 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 203 | using decomp by (simp add: atMost_atLeast0 field_simps) | 
| 63466 | 204 | finally show ?case | 
| 205 | by simp | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 206 | qed | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 207 | |
| 63466 | 208 | text \<open>Original version for the naturals.\<close> | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 209 | corollary binomial: "(a + b :: nat)^n = (\<Sum>k\<le>n. (of_nat (n choose k)) * a^k * b^(n - k))" | 
| 63466 | 210 | using binomial_ring [of "int a" "int b" n] | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 211 | by (simp only: of_nat_add [symmetric] of_nat_mult [symmetric] of_nat_power [symmetric] | 
| 64267 | 212 | of_nat_sum [symmetric] of_nat_eq_iff of_nat_id) | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 213 | |
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 214 | lemma binomial_fact_lemma: "k \<le> n \<Longrightarrow> fact k * fact (n - k) * (n choose k) = fact n" | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 215 | proof (induct n arbitrary: k rule: nat_less_induct) | 
| 63466 | 216 | fix n k | 
| 217 | assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) = fact m" | |
| 218 | assume kn: "k \<le> n" | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 219 | let ?ths = "fact k * fact (n - k) * (n choose k) = fact n" | 
| 63466 | 220 | consider "n = 0 \<or> k = 0 \<or> n = k" | m h where "n = Suc m" "k = Suc h" "h < m" | 
| 221 | using kn by atomize_elim presburger | |
| 222 | then show "fact k * fact (n - k) * (n choose k) = fact n" | |
| 223 | proof cases | |
| 224 | case 1 | |
| 225 | with kn show ?thesis by auto | |
| 226 | next | |
| 227 | case 2 | |
| 228 | note n = \<open>n = Suc m\<close> | |
| 229 | note k = \<open>k = Suc h\<close> | |
| 230 | note hm = \<open>h < m\<close> | |
| 231 | have mn: "m < n" | |
| 232 | using n by arith | |
| 233 | have hm': "h \<le> m" | |
| 234 | using hm by arith | |
| 235 | have km: "k \<le> m" | |
| 236 | using hm k n kn by arith | |
| 237 | have "m - h = Suc (m - Suc h)" | |
| 238 | using k km hm by arith | |
| 239 | with km k have "fact (m - h) = (m - h) * fact (m - k)" | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 240 | by simp | 
| 63466 | 241 | with n k have "fact k * fact (n - k) * (n choose k) = | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 242 | k * (fact h * fact (m - h) * (m choose h)) + | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 243 | (m - h) * (fact k * fact (m - k) * (m choose k))" | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 244 | by (simp add: field_simps) | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 245 | also have "\<dots> = (k + (m - h)) * fact m" | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 246 | using H[rule_format, OF mn hm'] H[rule_format, OF mn km] | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 247 | by (simp add: field_simps) | 
| 63466 | 248 | finally show ?thesis | 
| 249 | using k n km by simp | |
| 250 | qed | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 251 | qed | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 252 | |
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 253 | lemma binomial_fact': | 
| 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 254 | assumes "k \<le> n" | 
| 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 255 | shows "n choose k = fact n div (fact k * fact (n - k))" | 
| 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 256 | using binomial_fact_lemma [OF assms] | 
| 64240 | 257 | by (metis fact_nonzero mult_eq_0_iff nonzero_mult_div_cancel_left) | 
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 258 | |
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 259 | lemma binomial_fact: | 
| 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 260 | assumes kn: "k \<le> n" | 
| 63466 | 261 | shows "(of_nat (n choose k) :: 'a::field_char_0) = fact n / (fact k * fact (n - k))" | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 262 | using binomial_fact_lemma[OF kn] | 
| 71699 | 263 | by (metis (mono_tags, lifting) fact_nonzero mult_eq_0_iff nonzero_mult_div_cancel_left of_nat_fact of_nat_mult) | 
| 59658 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 paulson <lp15@cam.ac.uk> parents: 
58889diff
changeset | 264 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 265 | lemma fact_binomial: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 266 | assumes "k \<le> n" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 267 | shows "fact k * of_nat (n choose k) = (fact n / fact (n - k) :: 'a::field_char_0)" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 268 | unfolding binomial_fact [OF assms] by (simp add: field_simps) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 269 | |
| 63466 | 270 | lemma choose_two: "n choose 2 = n * (n - 1) div 2" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 271 | proof (cases "n \<ge> 2") | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 272 | case False | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 273 | then have "n = 0 \<or> n = 1" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 274 | by auto | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 275 | then show ?thesis by auto | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 276 | next | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 277 | case True | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 278 | define m where "m = n - 2" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 279 | with True have "n = m + 2" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 280 | by simp | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 281 | then have "fact n = n * (n - 1) * fact (n - 2)" | 
| 64272 | 282 | by (simp add: fact_prod_Suc atLeast0_lessThan_Suc algebra_simps) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 283 | with True show ?thesis | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 284 | by (simp add: binomial_fact') | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 285 | qed | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 286 | |
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 287 | lemma choose_row_sum: "(\<Sum>k\<le>n. n choose k) = 2^n" | 
| 63466 | 288 | using binomial [of 1 "1" n] by (simp add: numeral_2_eq_2) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 289 | |
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 290 | lemma sum_choose_lower: "(\<Sum>k\<le>n. (r+k) choose k) = Suc (r+n) choose n" | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 291 | by (induct n) auto | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 292 | |
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 293 | lemma sum_choose_upper: "(\<Sum>k\<le>n. k choose m) = Suc n choose Suc m" | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 294 | by (induct n) auto | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 295 | |
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 296 | lemma choose_alternating_sum: | 
| 63466 | 297 | "n > 0 \<Longrightarrow> (\<Sum>i\<le>n. (-1)^i * of_nat (n choose i)) = (0 :: 'a::comm_ring_1)" | 
| 298 | using binomial_ring[of "-1 :: 'a" 1 n] | |
| 299 | by (simp add: atLeast0AtMost mult_of_nat_commute zero_power) | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 300 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 301 | lemma choose_even_sum: | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 302 | assumes "n > 0" | 
| 63466 | 303 | shows "2 * (\<Sum>i\<le>n. if even i then of_nat (n choose i) else 0) = (2 ^ n :: 'a::comm_ring_1)" | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 304 | proof - | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 305 | have "2 ^ n = (\<Sum>i\<le>n. of_nat (n choose i)) + (\<Sum>i\<le>n. (-1) ^ i * of_nat (n choose i) :: 'a)" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 306 | using choose_row_sum[of n] | 
| 64267 | 307 | by (simp add: choose_alternating_sum assms atLeast0AtMost of_nat_sum[symmetric]) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 308 | also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) + (-1) ^ i * of_nat (n choose i))" | 
| 64267 | 309 | by (simp add: sum.distrib) | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 310 | also have "\<dots> = 2 * (\<Sum>i\<le>n. if even i then of_nat (n choose i) else 0)" | 
| 64267 | 311 | by (subst sum_distrib_left, intro sum.cong) simp_all | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 312 | finally show ?thesis .. | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 313 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 314 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 315 | lemma choose_odd_sum: | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 316 | assumes "n > 0" | 
| 63466 | 317 | shows "2 * (\<Sum>i\<le>n. if odd i then of_nat (n choose i) else 0) = (2 ^ n :: 'a::comm_ring_1)" | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 318 | proof - | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 319 | have "2 ^ n = (\<Sum>i\<le>n. of_nat (n choose i)) - (\<Sum>i\<le>n. (-1) ^ i * of_nat (n choose i) :: 'a)" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 320 | using choose_row_sum[of n] | 
| 64267 | 321 | by (simp add: choose_alternating_sum assms atLeast0AtMost of_nat_sum[symmetric]) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 322 | also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) - (-1) ^ i * of_nat (n choose i))" | 
| 64267 | 323 | by (simp add: sum_subtractf) | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 324 | also have "\<dots> = 2 * (\<Sum>i\<le>n. if odd i then of_nat (n choose i) else 0)" | 
| 64267 | 325 | by (subst sum_distrib_left, intro sum.cong) simp_all | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 326 | finally show ?thesis .. | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 327 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 328 | |
| 60758 | 329 | text\<open>NW diagonal sum property\<close> | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 330 | lemma sum_choose_diagonal: | 
| 63466 | 331 | assumes "m \<le> n" | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 332 | shows "(\<Sum>k\<le>m. (n - k) choose (m - k)) = Suc n choose m" | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 333 | proof - | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 334 | have "(\<Sum>k\<le>m. (n-k) choose (m - k)) = (\<Sum>k\<le>m. (n - m + k) choose k)" | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 335 | using sum.atLeastAtMost_rev [of "\<lambda>k. (n - k) choose (m - k)" 0 m] assms | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 336 | by (simp add: atMost_atLeast0) | 
| 63466 | 337 | also have "\<dots> = Suc (n - m + m) choose m" | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 338 | by (rule sum_choose_lower) | 
| 63466 | 339 | also have "\<dots> = Suc n choose m" | 
| 340 | using assms by simp | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 341 | finally show ?thesis . | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 342 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 343 | |
| 63373 | 344 | |
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 345 | subsection \<open>Generalized binomial coefficients\<close> | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 346 | |
| 63466 | 347 | definition gbinomial :: "'a::{semidom_divide,semiring_char_0} \<Rightarrow> nat \<Rightarrow> 'a"  (infixl "gchoose" 65)
 | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 348 |   where gbinomial_prod_rev: "a gchoose k = prod (\<lambda>i. a - of_nat i) {0..<k} div fact k"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 349 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 350 | lemma gbinomial_0 [simp]: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 351 | "a gchoose 0 = 1" | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 352 | "0 gchoose (Suc k) = 0" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 353 | by (simp_all add: gbinomial_prod_rev prod.atLeast0_lessThan_Suc_shift del: prod.op_ivl_Suc) | 
| 63367 
6c731c8b7f03
simplified definitions of combinatorial functions
 haftmann parents: 
63366diff
changeset | 354 | |
| 64272 | 355 | lemma gbinomial_Suc: "a gchoose (Suc k) = prod (\<lambda>i. a - of_nat i) {0..k} div fact (Suc k)"
 | 
| 356 | by (simp add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 357 | |
| 68786 | 358 | lemma gbinomial_1 [simp]: "a gchoose 1 = a" | 
| 359 | by (simp add: gbinomial_prod_rev lessThan_Suc) | |
| 360 | ||
| 361 | lemma gbinomial_Suc0 [simp]: "a gchoose Suc 0 = a" | |
| 362 | by (simp add: gbinomial_prod_rev lessThan_Suc) | |
| 363 | ||
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 364 | lemma gbinomial_mult_fact: "fact k * (a gchoose k) = (\<Prod>i = 0..<k. a - of_nat i)" | 
| 63466 | 365 | for a :: "'a::field_char_0" | 
| 64272 | 366 | by (simp_all add: gbinomial_prod_rev field_simps) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 367 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 368 | lemma gbinomial_mult_fact': "(a gchoose k) * fact k = (\<Prod>i = 0..<k. a - of_nat i)" | 
| 63466 | 369 | for a :: "'a::field_char_0" | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 370 | using gbinomial_mult_fact [of k a] by (simp add: ac_simps) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 371 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 372 | lemma gbinomial_pochhammer: "a gchoose k = (- 1) ^ k * pochhammer (- a) k / fact k" | 
| 63466 | 373 | for a :: "'a::field_char_0" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 374 | proof (cases k) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 375 | case (Suc k') | 
| 71699 | 376 | then have "a gchoose k = pochhammer (a - of_nat k') (Suc k') / ((1 + of_nat k') * fact k')" | 
| 377 | by (simp add: gbinomial_prod_rev pochhammer_prod_rev atLeastLessThanSuc_atLeastAtMost | |
| 378 | prod.atLeast_Suc_atMost_Suc_shift of_nat_diff flip: power_mult_distrib prod.cl_ivl_Suc) | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 379 | then show ?thesis | 
| 71699 | 380 | by (simp add: pochhammer_minus Suc) | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 381 | qed auto | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 382 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 383 | lemma gbinomial_pochhammer': "a gchoose k = pochhammer (a - of_nat k + 1) k / fact k" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 384 | for a :: "'a::field_char_0" | 
| 61552 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
61531diff
changeset | 385 | proof - | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 386 | have "a gchoose k = ((-1)^k * (-1)^k) * pochhammer (a - of_nat k + 1) k / fact k" | 
| 61552 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
61531diff
changeset | 387 | by (simp add: gbinomial_pochhammer pochhammer_minus mult_ac) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 388 | also have "(-1 :: 'a)^k * (-1)^k = 1" | 
| 63466 | 389 | by (subst power_add [symmetric]) simp | 
| 390 | finally show ?thesis | |
| 391 | by simp | |
| 61552 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
61531diff
changeset | 392 | qed | 
| 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
61531diff
changeset | 393 | |
| 63466 | 394 | lemma gbinomial_binomial: "n gchoose k = n choose k" | 
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 395 | proof (cases "k \<le> n") | 
| 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 396 | case False | 
| 63466 | 397 | then have "n < k" | 
| 398 | by (simp add: not_le) | |
| 67399 | 399 |   then have "0 \<in> ((-) n) ` {0..<k}"
 | 
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 400 | by auto | 
| 67399 | 401 |   then have "prod ((-) n) {0..<k} = 0"
 | 
| 64272 | 402 | by (auto intro: prod_zero) | 
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 403 | with \<open>n < k\<close> show ?thesis | 
| 64272 | 404 | by (simp add: binomial_eq_0 gbinomial_prod_rev prod_zero) | 
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 405 | next | 
| 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 406 | case True | 
| 67399 | 407 |   from True have *: "prod ((-) n) {0..<k} = \<Prod>{Suc (n - k)..n}"
 | 
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 408 | by (intro prod.reindex_bij_witness[of _ "\<lambda>i. n - i" "\<lambda>i. n - i"]) auto | 
| 63466 | 409 | from True have "n choose k = fact n div (fact k * fact (n - k))" | 
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 410 | by (rule binomial_fact') | 
| 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 411 | with * show ?thesis | 
| 64272 | 412 | by (simp add: gbinomial_prod_rev mult.commute [of "fact k"] div_mult2_eq fact_div_fact) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 413 | qed | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 414 | |
| 63466 | 415 | lemma of_nat_gbinomial: "of_nat (n gchoose k) = (of_nat n gchoose k :: 'a::field_char_0)" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 416 | proof (cases "k \<le> n") | 
| 63466 | 417 | case False | 
| 418 | then show ?thesis | |
| 64272 | 419 | by (simp add: not_le gbinomial_binomial binomial_eq_0 gbinomial_prod_rev) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 420 | next | 
| 63466 | 421 | case True | 
| 422 | define m where "m = n - k" | |
| 423 | with True have n: "n = m + k" | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 424 | by arith | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 425 | from n have "fact n = ((\<Prod>i = 0..<m + k. of_nat (m + k - i) ):: 'a)" | 
| 64272 | 426 | by (simp add: fact_prod_rev) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 427 |   also have "\<dots> = ((\<Prod>i\<in>{0..<k} \<union> {k..<m + k}. of_nat (m + k - i)) :: 'a)"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 428 | by (simp add: ivl_disj_un) | 
| 63466 | 429 | finally have "fact n = (fact m * (\<Prod>i = 0..<k. of_nat m + of_nat k - of_nat i) :: 'a)" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 430 | using prod.shift_bounds_nat_ivl [of "\<lambda>i. of_nat (m + k - i) :: 'a" 0 k m] | 
| 64272 | 431 | by (simp add: fact_prod_rev [of m] prod.union_disjoint of_nat_diff) | 
| 63466 | 432 | then have "fact n / fact (n - k) = ((\<Prod>i = 0..<k. of_nat n - of_nat i) :: 'a)" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 433 | by (simp add: n) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 434 | with True have "fact k * of_nat (n gchoose k) = (fact k * (of_nat n gchoose k) :: 'a)" | 
| 63466 | 435 | by (simp only: gbinomial_mult_fact [of k "of_nat n"] gbinomial_binomial [of n k] fact_binomial) | 
| 436 | then show ?thesis | |
| 437 | by simp | |
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 438 | qed | 
| 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 439 | |
| 63466 | 440 | lemma binomial_gbinomial: "of_nat (n choose k) = (of_nat n gchoose k :: 'a::field_char_0)" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 441 | by (simp add: gbinomial_binomial [symmetric] of_nat_gbinomial) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 442 | |
| 63466 | 443 | setup | 
| 69593 | 444 | \<open>Sign.add_const_constraint (\<^const_name>\<open>gbinomial\<close>, SOME \<^typ>\<open>'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a\<close>)\<close> | 
| 63372 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 haftmann parents: 
63367diff
changeset | 445 | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 446 | lemma gbinomial_mult_1: | 
| 63466 | 447 | fixes a :: "'a::field_char_0" | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 448 | shows "a * (a gchoose k) = of_nat k * (a gchoose k) + of_nat (Suc k) * (a gchoose (Suc k))" | 
| 63466 | 449 | (is "?l = ?r") | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 450 | proof - | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 451 | have "?r = ((- 1) ^k * pochhammer (- a) k / fact k) * (of_nat k - (- a + of_nat k))" | 
| 71699 | 452 | unfolding gbinomial_pochhammer pochhammer_Suc right_diff_distrib power_Suc | 
| 453 | by (auto simp add: field_simps simp del: of_nat_Suc) | |
| 63466 | 454 | also have "\<dots> = ?l" | 
| 455 | by (simp add: field_simps gbinomial_pochhammer) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 456 | finally show ?thesis .. | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 457 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 458 | |
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 459 | lemma gbinomial_mult_1': | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 460 | "(a gchoose k) * a = of_nat k * (a gchoose k) + of_nat (Suc k) * (a gchoose (Suc k))" | 
| 63466 | 461 | for a :: "'a::field_char_0" | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 462 | by (simp add: mult.commute gbinomial_mult_1) | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 463 | |
| 63466 | 464 | lemma gbinomial_Suc_Suc: "(a + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))" | 
| 465 | for a :: "'a::field_char_0" | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 466 | proof (cases k) | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 467 | case 0 | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 468 | then show ?thesis by simp | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 469 | next | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 470 | case (Suc h) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 471 |   have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)"
 | 
| 71699 | 472 | proof (rule prod.reindex_cong) | 
| 473 |     show "{1..k} = Suc ` {0..h}"
 | |
| 474 | using Suc by (auto simp add: image_Suc_atMost) | |
| 475 | qed auto | |
| 59730 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 paulson <lp15@cam.ac.uk> parents: 
59669diff
changeset | 476 | have "fact (Suc k) * (a gchoose k + (a gchoose (Suc k))) = | 
| 63466 | 477 | (a gchoose Suc h) * (fact (Suc (Suc h))) + | 
| 478 | (a gchoose Suc (Suc h)) * (fact (Suc (Suc h)))" | |
| 63367 
6c731c8b7f03
simplified definitions of combinatorial functions
 haftmann parents: 
63366diff
changeset | 479 | by (simp add: Suc field_simps del: fact_Suc) | 
| 63466 | 480 | also have "\<dots> = | 
| 481 | (a gchoose Suc h) * of_nat (Suc (Suc h) * fact (Suc h)) + (\<Prod>i=0..Suc h. a - of_nat i)" | |
| 71699 | 482 | apply (simp only: gbinomial_mult_fact field_simps mult.left_commute [of _ "2"]) | 
| 63466 | 483 | apply (simp del: fact_Suc add: fact_Suc [of "Suc h"] field_simps gbinomial_mult_fact | 
| 484 | mult.left_commute [of _ "2"] atLeastLessThanSuc_atLeastAtMost) | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 485 | done | 
| 63466 | 486 | also have "\<dots> = | 
| 487 | (fact (Suc h) * (a gchoose Suc h)) * of_nat (Suc (Suc h)) + (\<Prod>i=0..Suc h. a - of_nat i)" | |
| 63367 
6c731c8b7f03
simplified definitions of combinatorial functions
 haftmann parents: 
63366diff
changeset | 488 | by (simp only: fact_Suc mult.commute mult.left_commute of_nat_fact of_nat_id of_nat_mult) | 
| 63466 | 489 | also have "\<dots> = | 
| 490 | of_nat (Suc (Suc h)) * (\<Prod>i=0..h. a - of_nat i) + (\<Prod>i=0..Suc h. a - of_nat i)" | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 491 | unfolding gbinomial_mult_fact atLeastLessThanSuc_atLeastAtMost by auto | 
| 63466 | 492 | also have "\<dots> = | 
| 493 | (\<Prod>i=0..Suc h. a - of_nat i) + (of_nat h * (\<Prod>i=0..h. a - of_nat i) + 2 * (\<Prod>i=0..h. a - of_nat i))" | |
| 59730 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 paulson <lp15@cam.ac.uk> parents: 
59669diff
changeset | 494 | by (simp add: field_simps) | 
| 63466 | 495 | also have "\<dots> = | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 496 |     ((a gchoose Suc h) * (fact (Suc h)) * of_nat (Suc k)) + (\<Prod>i\<in>{0..Suc h}. a - of_nat i)"
 | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 497 | unfolding gbinomial_mult_fact' | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 498 | by (simp add: comm_semiring_class.distrib field_simps Suc atLeastLessThanSuc_atLeastAtMost) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 499 |   also have "\<dots> = (\<Prod>i\<in>{0..h}. a - of_nat i) * (a + 1)"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 500 | unfolding gbinomial_mult_fact' atLeast0_atMost_Suc | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 501 | by (simp add: field_simps Suc atLeastLessThanSuc_atLeastAtMost) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 502 |   also have "\<dots> = (\<Prod>i\<in>{0..k}. (a + 1) - of_nat i)"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 503 | using eq0 | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 504 | by (simp add: Suc prod.atLeast0_atMost_Suc_shift del: prod.cl_ivl_Suc) | 
| 59730 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 paulson <lp15@cam.ac.uk> parents: 
59669diff
changeset | 505 | also have "\<dots> = (fact (Suc k)) * ((a + 1) gchoose (Suc k))" | 
| 63466 | 506 | by (simp only: gbinomial_mult_fact atLeastLessThanSuc_atLeastAtMost) | 
| 59730 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 paulson <lp15@cam.ac.uk> parents: 
59669diff
changeset | 507 | finally show ?thesis | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 508 | using fact_nonzero [of "Suc k"] by auto | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 509 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 510 | |
| 63466 | 511 | lemma gbinomial_reduce_nat: "0 < k \<Longrightarrow> a gchoose k = (a - 1) gchoose (k - 1) + ((a - 1) gchoose k)" | 
| 512 | for a :: "'a::field_char_0" | |
| 59730 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 paulson <lp15@cam.ac.uk> parents: 
59669diff
changeset | 513 | by (metis Suc_pred' diff_add_cancel gbinomial_Suc_Suc) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 514 | |
| 60141 
833adf7db7d8
New material, mostly about limits. Consolidation.
 paulson <lp15@cam.ac.uk> parents: 
59867diff
changeset | 515 | lemma gchoose_row_sum_weighted: | 
| 63466 | 516 | "(\<Sum>k = 0..m. (r gchoose k) * (r/2 - of_nat k)) = of_nat(Suc m) / 2 * (r gchoose (Suc m))" | 
| 517 | for r :: "'a::field_char_0" | |
| 518 | by (induct m) (simp_all add: field_simps distrib gbinomial_mult_1) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 519 | |
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 520 | lemma binomial_symmetric: | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 521 | assumes kn: "k \<le> n" | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 522 | shows "n choose k = n choose (n - k)" | 
| 63466 | 523 | proof - | 
| 524 | have kn': "n - k \<le> n" | |
| 525 | using kn by arith | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 526 | from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn'] | 
| 63466 | 527 | have "fact k * fact (n - k) * (n choose k) = fact (n - k) * fact (n - (n - k)) * (n choose (n - k))" | 
| 528 | by simp | |
| 529 | then show ?thesis | |
| 530 | using kn by simp | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 531 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 532 | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 533 | lemma choose_rising_sum: | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 534 | "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose (n + 1))" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 535 | "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose m)" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 536 | proof - | 
| 63466 | 537 | show "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose (n + 1))" | 
| 538 | by (induct m) simp_all | |
| 539 | also have "\<dots> = (n + m + 1) choose m" | |
| 540 | by (subst binomial_symmetric) simp_all | |
| 541 | finally show "(\<Sum>j\<le>m. ((n + j) choose n)) = (n + m + 1) choose m" . | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 542 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 543 | |
| 63466 | 544 | lemma choose_linear_sum: "(\<Sum>i\<le>n. i * (n choose i)) = n * 2 ^ (n - 1)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 545 | proof (cases n) | 
| 63466 | 546 | case 0 | 
| 547 | then show ?thesis by simp | |
| 548 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 549 | case (Suc m) | 
| 63466 | 550 | have "(\<Sum>i\<le>n. i * (n choose i)) = (\<Sum>i\<le>Suc m. i * (Suc m choose i))" | 
| 551 | by (simp add: Suc) | |
| 552 | also have "\<dots> = Suc m * 2 ^ m" | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 553 | unfolding sum.atMost_Suc_shift Suc_times_binomial sum_distrib_left[symmetric] | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 554 | by (simp add: choose_row_sum) | 
| 63466 | 555 | finally show ?thesis | 
| 556 | using Suc by simp | |
| 557 | qed | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 558 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 559 | lemma choose_alternating_linear_sum: | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 560 | assumes "n \<noteq> 1" | 
| 63466 | 561 | shows "(\<Sum>i\<le>n. (-1)^i * of_nat i * of_nat (n choose i) :: 'a::comm_ring_1) = 0" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 562 | proof (cases n) | 
| 63466 | 563 | case 0 | 
| 564 | then show ?thesis by simp | |
| 565 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 566 | case (Suc m) | 
| 63466 | 567 | with assms have "m > 0" | 
| 568 | by simp | |
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 569 | have "(\<Sum>i\<le>n. (-1) ^ i * of_nat i * of_nat (n choose i) :: 'a) = | 
| 63466 | 570 | (\<Sum>i\<le>Suc m. (-1) ^ i * of_nat i * of_nat (Suc m choose i))" | 
| 571 | by (simp add: Suc) | |
| 572 | also have "\<dots> = (\<Sum>i\<le>m. (-1) ^ (Suc i) * of_nat (Suc i * (Suc m choose Suc i)))" | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 573 | by (simp only: sum.atMost_Suc_shift sum_distrib_left[symmetric] mult_ac of_nat_mult) simp | 
| 63466 | 574 | also have "\<dots> = - of_nat (Suc m) * (\<Sum>i\<le>m. (-1) ^ i * of_nat (m choose i))" | 
| 64267 | 575 | by (subst sum_distrib_left, rule sum.cong[OF refl], subst Suc_times_binomial) | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 576 | (simp add: algebra_simps) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 577 | also have "(\<Sum>i\<le>m. (-1 :: 'a) ^ i * of_nat ((m choose i))) = 0" | 
| 61799 | 578 | using choose_alternating_sum[OF \<open>m > 0\<close>] by simp | 
| 63466 | 579 | finally show ?thesis | 
| 580 | by simp | |
| 581 | qed | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 582 | |
| 63466 | 583 | lemma vandermonde: "(\<Sum>k\<le>r. (m choose k) * (n choose (r - k))) = (m + n) choose r" | 
| 584 | proof (induct n arbitrary: r) | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 585 | case 0 | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 586 | have "(\<Sum>k\<le>r. (m choose k) * (0 choose (r - k))) = (\<Sum>k\<le>r. if k = r then (m choose k) else 0)" | 
| 64267 | 587 | by (intro sum.cong) simp_all | 
| 63466 | 588 | also have "\<dots> = m choose r" | 
| 68784 | 589 | by simp | 
| 63466 | 590 | finally show ?case | 
| 591 | by simp | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 592 | next | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 593 | case (Suc n r) | 
| 63466 | 594 | show ?case | 
| 64267 | 595 | by (cases r) (simp_all add: Suc [symmetric] algebra_simps sum.distrib Suc_diff_le) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 596 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 597 | |
| 63466 | 598 | lemma choose_square_sum: "(\<Sum>k\<le>n. (n choose k)^2) = ((2*n) choose n)" | 
| 599 | using vandermonde[of n n n] | |
| 600 | by (simp add: power2_eq_square mult_2 binomial_symmetric [symmetric]) | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 601 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 602 | lemma pochhammer_binomial_sum: | 
| 63466 | 603 | fixes a b :: "'a::comm_ring_1" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 604 | shows "pochhammer (a + b) n = (\<Sum>k\<le>n. of_nat (n choose k) * pochhammer a k * pochhammer b (n - k))" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 605 | proof (induction n arbitrary: a b) | 
| 63466 | 606 | case 0 | 
| 607 | then show ?case by simp | |
| 608 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 609 | case (Suc n a b) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 610 | have "(\<Sum>k\<le>Suc n. of_nat (Suc n choose k) * pochhammer a k * pochhammer b (Suc n - k)) = | 
| 63466 | 611 | (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) + | 
| 612 | ((\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) + | |
| 613 | pochhammer b (Suc n))" | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 614 | by (subst sum.atMost_Suc_shift) (simp add: ring_distribs sum.distrib) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 615 | also have "(\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) = | 
| 63466 | 616 | a * pochhammer ((a + 1) + b) n" | 
| 64267 | 617 | by (subst Suc) (simp add: sum_distrib_left pochhammer_rec mult_ac) | 
| 63466 | 618 | also have "(\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) + | 
| 619 | pochhammer b (Suc n) = | |
| 620 | (\<Sum>i=0..Suc n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))" | |
| 71699 | 621 | apply (subst sum.atLeast_Suc_atMost, simp) | 
| 622 | apply (simp add: sum.shift_bounds_cl_Suc_ivl atLeast0AtMost del: sum.cl_ivl_Suc) | |
| 63466 | 623 | done | 
| 624 | also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))" | |
| 64267 | 625 | using Suc by (intro sum.mono_neutral_right) (auto simp: not_le binomial_eq_0) | 
| 63466 | 626 | also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc (n - i)))" | 
| 64267 | 627 | by (intro sum.cong) (simp_all add: Suc_diff_le) | 
| 63466 | 628 | also have "\<dots> = b * pochhammer (a + (b + 1)) n" | 
| 64267 | 629 | by (subst Suc) (simp add: sum_distrib_left mult_ac pochhammer_rec) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 630 | also have "a * pochhammer ((a + 1) + b) n + b * pochhammer (a + (b + 1)) n = | 
| 63466 | 631 | pochhammer (a + b) (Suc n)" | 
| 632 | by (simp add: pochhammer_rec algebra_simps) | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 633 | finally show ?case .. | 
| 63466 | 634 | qed | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 635 | |
| 63466 | 636 | text \<open>Contributed by Manuel Eberl, generalised by LCP. | 
| 69593 | 637 | Alternative definition of the binomial coefficient as \<^term>\<open>\<Prod>i<k. (n - i) / (k - i)\<close>.\<close> | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 638 | lemma gbinomial_altdef_of_nat: "a gchoose k = (\<Prod>i = 0..<k. (a - of_nat i) / of_nat (k - i) :: 'a)" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 639 | for k :: nat and a :: "'a::field_char_0" | 
| 64272 | 640 | by (simp add: prod_dividef gbinomial_prod_rev fact_prod_rev) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 641 | |
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 642 | lemma gbinomial_ge_n_over_k_pow_k: | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 643 | fixes k :: nat | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 644 | and a :: "'a::linordered_field" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 645 | assumes "of_nat k \<le> a" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 646 | shows "(a / of_nat k :: 'a) ^ k \<le> a gchoose k" | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 647 | proof - | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 648 | have x: "0 \<le> a" | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 649 | using assms of_nat_0_le_iff order_trans by blast | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 650 | have "(a / of_nat k :: 'a) ^ k = (\<Prod>i = 0..<k. a / of_nat k :: 'a)" | 
| 68784 | 651 | by simp | 
| 71699 | 652 | also have "\<dots> \<le> a gchoose k" | 
| 653 | proof - | |
| 654 | have "\<And>i. i < k \<Longrightarrow> 0 \<le> a / of_nat k" | |
| 655 | by (simp add: x zero_le_divide_iff) | |
| 656 | moreover have "a / of_nat k \<le> (a - of_nat i) / of_nat (k - i)" if "i < k" for i | |
| 63466 | 657 | proof - | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 658 | from assms have "a * of_nat i \<ge> of_nat (i * k)" | 
| 63466 | 659 | by (metis mult.commute mult_le_cancel_right of_nat_less_0_iff of_nat_mult) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 660 | then have "a * of_nat k - a * of_nat i \<le> a * of_nat k - of_nat (i * k)" | 
| 63466 | 661 | by arith | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 662 | then have "a * of_nat (k - i) \<le> (a - of_nat i) * of_nat k" | 
| 63466 | 663 | using \<open>i < k\<close> by (simp add: algebra_simps zero_less_mult_iff of_nat_diff) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 664 | then have "a * of_nat (k - i) \<le> (a - of_nat i) * (of_nat k :: 'a)" | 
| 71699 | 665 | by blast | 
| 63466 | 666 | with assms show ?thesis | 
| 667 | using \<open>i < k\<close> by (simp add: field_simps) | |
| 668 | qed | |
| 71699 | 669 | ultimately show ?thesis | 
| 670 | unfolding gbinomial_altdef_of_nat | |
| 671 | by (intro prod_mono) auto | |
| 672 | qed | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 673 | finally show ?thesis . | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 674 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 675 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 676 | lemma gbinomial_negated_upper: "(a gchoose k) = (-1) ^ k * ((of_nat k - a - 1) gchoose k)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 677 | by (simp add: gbinomial_pochhammer pochhammer_minus algebra_simps) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 678 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 679 | lemma gbinomial_minus: "((-a) gchoose k) = (-1) ^ k * ((a + of_nat k - 1) gchoose k)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 680 | by (subst gbinomial_negated_upper) (simp add: add_ac) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 681 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 682 | lemma Suc_times_gbinomial: "of_nat (Suc k) * ((a + 1) gchoose (Suc k)) = (a + 1) * (a gchoose k)" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 683 | proof (cases k) | 
| 63466 | 684 | case 0 | 
| 685 | then show ?thesis by simp | |
| 686 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 687 | case (Suc b) | 
| 63466 | 688 | then have "((a + 1) gchoose (Suc (Suc b))) = (\<Prod>i = 0..Suc b. a + (1 - of_nat i)) / fact (b + 2)" | 
| 64272 | 689 | by (simp add: field_simps gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 690 | also have "(\<Prod>i = 0..Suc b. a + (1 - of_nat i)) = (a + 1) * (\<Prod>i = 0..b. a - of_nat i)" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 691 | by (simp add: prod.atLeast0_atMost_Suc_shift del: prod.cl_ivl_Suc) | 
| 63466 | 692 | also have "\<dots> / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)" | 
| 64272 | 693 | by (simp_all add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 694 | finally show ?thesis by (simp add: Suc field_simps del: of_nat_Suc) | 
| 63466 | 695 | qed | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 696 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 697 | lemma gbinomial_factors: "((a + 1) gchoose (Suc k)) = (a + 1) / of_nat (Suc k) * (a gchoose k)" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 698 | proof (cases k) | 
| 63466 | 699 | case 0 | 
| 700 | then show ?thesis by simp | |
| 701 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 702 | case (Suc b) | 
| 63466 | 703 | then have "((a + 1) gchoose (Suc (Suc b))) = (\<Prod>i = 0 .. Suc b. a + (1 - of_nat i)) / fact (b + 2)" | 
| 64272 | 704 | by (simp add: field_simps gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 705 | also have "(\<Prod>i = 0 .. Suc b. a + (1 - of_nat i)) = (a + 1) * (\<Prod>i = 0..b. a - of_nat i)" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 706 | by (simp add: prod.atLeast0_atMost_Suc_shift del: prod.cl_ivl_Suc) | 
| 63466 | 707 | also have "\<dots> / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)" | 
| 64272 | 708 | by (simp_all add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost atLeast0AtMost) | 
| 63466 | 709 | finally show ?thesis | 
| 710 | by (simp add: Suc) | |
| 711 | qed | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 712 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 713 | lemma gbinomial_rec: "((a + 1) gchoose (Suc k)) = (a gchoose k) * ((a + 1) / of_nat (Suc k))" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 714 | using gbinomial_mult_1[of a k] | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 715 | by (subst gbinomial_Suc_Suc) (simp add: field_simps del: of_nat_Suc, simp add: algebra_simps) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 716 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 717 | lemma gbinomial_of_nat_symmetric: "k \<le> n \<Longrightarrow> (of_nat n) gchoose k = (of_nat n) gchoose (n - k)" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 718 | using binomial_symmetric[of k n] by (simp add: binomial_gbinomial [symmetric]) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 719 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 720 | |
| 77172 | 721 | text \<open>The absorption identity (equation 5.5 \<^cite>\<open>\<open>p.~157\<close> in GKP_CM\<close>): | 
| 63466 | 722 | \[ | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 723 | {r \choose k} = \frac{r}{k}{r - 1 \choose k - 1},\quad \textnormal{integer } k \neq 0.
 | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 724 | \]\<close> | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 725 | lemma gbinomial_absorption': "k > 0 \<Longrightarrow> a gchoose k = (a / of_nat k) * (a - 1 gchoose (k - 1))" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 726 | using gbinomial_rec[of "a - 1" "k - 1"] | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 727 | by (simp_all add: gbinomial_rec field_simps del: of_nat_Suc) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 728 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 729 | text \<open>The absorption identity is written in the following form to avoid | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 730 | division by $k$ (the lower index) and therefore remove the $k \neq 0$ | 
| 77172 | 731 | restriction \<^cite>\<open>\<open>p.~157\<close> in GKP_CM\<close>: | 
| 63466 | 732 | \[ | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 733 | k{r \choose k} = r{r - 1 \choose k - 1}, \quad \textnormal{integer } k.
 | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 734 | \]\<close> | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 735 | lemma gbinomial_absorption: "of_nat (Suc k) * (a gchoose Suc k) = a * ((a - 1) gchoose k)" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 736 | using gbinomial_absorption'[of "Suc k" a] by (simp add: field_simps del: of_nat_Suc) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 737 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 738 | text \<open>The absorption identity for natural number binomial coefficients:\<close> | 
| 63466 | 739 | lemma binomial_absorption: "Suc k * (n choose Suc k) = n * ((n - 1) choose k)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 740 | by (cases n) (simp_all add: binomial_eq_0 Suc_times_binomial del: binomial_Suc_Suc mult_Suc) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 741 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 742 | text \<open>The absorption companion identity for natural number coefficients, | 
| 77172 | 743 | following the proof by GKP \<^cite>\<open>\<open>p.~157\<close> in GKP_CM\<close>:\<close> | 
| 63466 | 744 | lemma binomial_absorb_comp: "(n - k) * (n choose k) = n * ((n - 1) choose k)" | 
| 745 | (is "?lhs = ?rhs") | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 746 | proof (cases "n \<le> k") | 
| 63466 | 747 | case True | 
| 748 | then show ?thesis by auto | |
| 749 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 750 | case False | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 751 | then have "?rhs = Suc ((n - 1) - k) * (n choose Suc ((n - 1) - k))" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 752 | using binomial_symmetric[of k "n - 1"] binomial_absorption[of "(n - 1) - k" n] | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 753 | by simp | 
| 63466 | 754 | also have "Suc ((n - 1) - k) = n - k" | 
| 755 | using False by simp | |
| 756 | also have "n choose \<dots> = n choose k" | |
| 757 | using False by (intro binomial_symmetric [symmetric]) simp_all | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 758 | finally show ?thesis .. | 
| 63466 | 759 | qed | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 760 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 761 | text \<open>The generalised absorption companion identity:\<close> | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 762 | lemma gbinomial_absorb_comp: "(a - of_nat k) * (a gchoose k) = a * ((a - 1) gchoose k)" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 763 | using pochhammer_absorb_comp[of a k] by (simp add: gbinomial_pochhammer) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 764 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 765 | lemma gbinomial_addition_formula: | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 766 | "a gchoose (Suc k) = ((a - 1) gchoose (Suc k)) + ((a - 1) gchoose k)" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 767 | using gbinomial_Suc_Suc[of "a - 1" k] by (simp add: algebra_simps) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 768 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 769 | lemma binomial_addition_formula: | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 770 | "0 < n \<Longrightarrow> n choose (Suc k) = ((n - 1) choose (Suc k)) + ((n - 1) choose k)" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 771 | by (subst choose_reduce_nat) simp_all | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 772 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 773 | text \<open> | 
| 77172 | 774 | Equation 5.9 of the reference material \<^cite>\<open>\<open>p.~159\<close> in GKP_CM\<close> is a useful | 
| 63466 | 775 | summation formula, operating on both indices: | 
| 776 | \[ | |
| 777 |    \sum\limits_{k \leq n}{r + k \choose k} = {r + n + 1 \choose n},
 | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 778 |    \quad \textnormal{integer } n.
 | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 779 | \] | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 780 | \<close> | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 781 | lemma gbinomial_parallel_sum: "(\<Sum>k\<le>n. (a + of_nat k) gchoose k) = (a + of_nat n + 1) gchoose n" | 
| 63466 | 782 | proof (induct n) | 
| 783 | case 0 | |
| 784 | then show ?case by simp | |
| 785 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 786 | case (Suc m) | 
| 63466 | 787 | then show ?case | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 788 | using gbinomial_Suc_Suc[of "(a + of_nat m + 1)" m] | 
| 63466 | 789 | by (simp add: add_ac) | 
| 790 | qed | |
| 791 | ||
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 792 | |
| 63373 | 793 | subsubsection \<open>Summation on the upper index\<close> | 
| 63466 | 794 | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 795 | text \<open> | 
| 77172 | 796 | Another summation formula is equation 5.10 of the reference material \<^cite>\<open>\<open>p.~160\<close> in GKP_CM\<close>, | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 797 |   aptly named \emph{summation on the upper index}:\[\sum_{0 \leq k \leq n} {k \choose m} =
 | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 798 |   {n + 1 \choose m + 1}, \quad \textnormal{integers } m, n \geq 0.\]
 | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 799 | \<close> | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 800 | lemma gbinomial_sum_up_index: | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 801 | "(\<Sum>j = 0..n. (of_nat j gchoose k) :: 'a::field_char_0) = (of_nat n + 1) gchoose (k + 1)" | 
| 63466 | 802 | proof (induct n) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 803 | case 0 | 
| 63466 | 804 | show ?case | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 805 | using gbinomial_Suc_Suc[of 0 k] | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 806 | by (cases k) auto | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 807 | next | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 808 | case (Suc n) | 
| 63466 | 809 | then show ?case | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 810 | using gbinomial_Suc_Suc[of "of_nat (Suc n) :: 'a" k] | 
| 63466 | 811 | by (simp add: add_ac) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 812 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 813 | |
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 814 | lemma gbinomial_index_swap: | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 815 | "((-1) ^ k) * ((- (of_nat n) - 1) gchoose k) = ((-1) ^ n) * ((- (of_nat k) - 1) gchoose n)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 816 | (is "?lhs = ?rhs") | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 817 | proof - | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 818 | have "?lhs = (of_nat (k + n) gchoose k)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 819 | by (subst gbinomial_negated_upper) (simp add: power_mult_distrib [symmetric]) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 820 | also have "\<dots> = (of_nat (k + n) gchoose n)" | 
| 63466 | 821 | by (subst gbinomial_of_nat_symmetric) simp_all | 
| 822 | also have "\<dots> = ?rhs" | |
| 823 | by (subst gbinomial_negated_upper) simp | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 824 | finally show ?thesis . | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 825 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 826 | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 827 | lemma gbinomial_sum_lower_neg: "(\<Sum>k\<le>m. (a gchoose k) * (- 1) ^ k) = (- 1) ^ m * (a - 1 gchoose m)" | 
| 63466 | 828 | (is "?lhs = ?rhs") | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 829 | proof - | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 830 | have "?lhs = (\<Sum>k\<le>m. -(a + 1) + of_nat k gchoose k)" | 
| 64267 | 831 | by (intro sum.cong[OF refl]) (subst gbinomial_negated_upper, simp add: power_mult_distrib) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 832 | also have "\<dots> = - a + of_nat m gchoose m" | 
| 63466 | 833 | by (subst gbinomial_parallel_sum) simp | 
| 834 | also have "\<dots> = ?rhs" | |
| 835 | by (subst gbinomial_negated_upper) (simp add: power_mult_distrib) | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 836 | finally show ?thesis . | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 837 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 838 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 839 | lemma gbinomial_partial_row_sum: | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 840 | "(\<Sum>k\<le>m. (a gchoose k) * ((a / 2) - of_nat k)) = ((of_nat m + 1)/2) * (a gchoose (m + 1))" | 
| 63466 | 841 | proof (induct m) | 
| 842 | case 0 | |
| 843 | then show ?case by simp | |
| 844 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 845 | case (Suc mm) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 846 | then have "(\<Sum>k\<le>Suc mm. (a gchoose k) * (a / 2 - of_nat k)) = | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 847 | (a - of_nat (Suc mm)) * (a gchoose Suc mm) / 2" | 
| 63466 | 848 | by (simp add: field_simps) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 849 | also have "\<dots> = a * (a - 1 gchoose Suc mm) / 2" | 
| 63466 | 850 | by (subst gbinomial_absorb_comp) (rule refl) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 851 | also have "\<dots> = (of_nat (Suc mm) + 1) / 2 * (a gchoose (Suc mm + 1))" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 852 | by (subst gbinomial_absorption [symmetric]) simp | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 853 | finally show ?case . | 
| 63466 | 854 | qed | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 855 | |
| 64267 | 856 | lemma sum_bounds_lt_plus1: "(\<Sum>k<mm. f (Suc k)) = (\<Sum>k=1..mm. f k)" | 
| 63466 | 857 | by (induct mm) simp_all | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 858 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 859 | lemma gbinomial_partial_sum_poly: | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 860 | "(\<Sum>k\<le>m. (of_nat m + a gchoose k) * x^k * y^(m-k)) = | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 861 | (\<Sum>k\<le>m. (-a gchoose k) * (-x)^k * (x + y)^(m-k))" | 
| 63466 | 862 | (is "?lhs m = ?rhs m") | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 863 | proof (induction m) | 
| 63466 | 864 | case 0 | 
| 865 | then show ?case by simp | |
| 866 | next | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 867 | case (Suc mm) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 868 | define G where "G i k = (of_nat i + a gchoose k) * x^k * y^(i - k)" for i k | 
| 63040 | 869 | define S where "S = ?lhs" | 
| 63466 | 870 | have SG_def: "S = (\<lambda>i. (\<Sum>k\<le>i. (G i k)))" | 
| 871 | unfolding S_def G_def .. | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 872 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 873 | have "S (Suc mm) = G (Suc mm) 0 + (\<Sum>k=Suc 0..Suc mm. G (Suc mm) k)" | 
| 70097 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 874 | using SG_def by (simp add: sum.atLeast_Suc_atMost atLeast0AtMost [symmetric]) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 875 | also have "(\<Sum>k=Suc 0..Suc mm. G (Suc mm) k) = (\<Sum>k=0..mm. G (Suc mm) (Suc k))" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 876 | by (subst sum.shift_bounds_cl_Suc_ivl) simp | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 877 | also have "\<dots> = (\<Sum>k=0..mm. ((of_nat mm + a gchoose (Suc k)) + | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 878 | (of_nat mm + a gchoose k)) * x^(Suc k) * y^(mm - k))" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 879 | unfolding G_def by (subst gbinomial_addition_formula) simp | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 880 | also have "\<dots> = (\<Sum>k=0..mm. (of_nat mm + a gchoose (Suc k)) * x^(Suc k) * y^(mm - k)) + | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 881 | (\<Sum>k=0..mm. (of_nat mm + a gchoose k) * x^(Suc k) * y^(mm - k))" | 
| 64267 | 882 | by (subst sum.distrib [symmetric]) (simp add: algebra_simps) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 883 | also have "(\<Sum>k=0..mm. (of_nat mm + a gchoose (Suc k)) * x^(Suc k) * y^(mm - k)) = | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 884 | (\<Sum>k<Suc mm. (of_nat mm + a gchoose (Suc k)) * x^(Suc k) * y^(mm - k))" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 885 | by (simp only: atLeast0AtMost lessThan_Suc_atMost) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 886 | also have "\<dots> = (\<Sum>k<mm. (of_nat mm + a gchoose Suc k) * x^(Suc k) * y^(mm-k)) + | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 887 | (of_nat mm + a gchoose (Suc mm)) * x^(Suc mm)" | 
| 63466 | 888 | (is "_ = ?A + ?B") | 
| 70097 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 889 | by (subst sum.lessThan_Suc) simp | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 890 | also have "?A = (\<Sum>k=1..mm. (of_nat mm + a gchoose k) * x^k * y^(mm - k + 1))" | 
| 64267 | 891 | proof (subst sum_bounds_lt_plus1 [symmetric], intro sum.cong[OF refl], clarify) | 
| 63466 | 892 | fix k | 
| 893 | assume "k < mm" | |
| 894 | then have "mm - k = mm - Suc k + 1" | |
| 895 | by linarith | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 896 | then show "(of_nat mm + a gchoose Suc k) * x ^ Suc k * y ^ (mm - k) = | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 897 | (of_nat mm + a gchoose Suc k) * x ^ Suc k * y ^ (mm - Suc k + 1)" | 
| 63466 | 898 | by (simp only:) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 899 | qed | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 900 | also have "\<dots> + ?B = y * (\<Sum>k=1..mm. (G mm k)) + (of_nat mm + a gchoose (Suc mm)) * x^(Suc mm)" | 
| 64267 | 901 | unfolding G_def by (subst sum_distrib_left) (simp add: algebra_simps) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 902 | also have "(\<Sum>k=0..mm. (of_nat mm + a gchoose k) * x^(Suc k) * y^(mm - k)) = x * (S mm)" | 
| 64267 | 903 | unfolding S_def by (subst sum_distrib_left) (simp add: atLeast0AtMost algebra_simps) | 
| 63466 | 904 | also have "(G (Suc mm) 0) = y * (G mm 0)" | 
| 905 | by (simp add: G_def) | |
| 906 | finally have "S (Suc mm) = | |
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 907 | y * (G mm 0 + (\<Sum>k=1..mm. (G mm k))) + (of_nat mm + a gchoose (Suc mm)) * x^(Suc mm) + x * (S mm)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 908 | by (simp add: ring_distribs) | 
| 63466 | 909 | also have "G mm 0 + (\<Sum>k=1..mm. (G mm k)) = S mm" | 
| 70097 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 910 | by (simp add: sum.atLeast_Suc_atMost[symmetric] SG_def atLeast0AtMost) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 911 | finally have "S (Suc mm) = (x + y) * (S mm) + (of_nat mm + a gchoose (Suc mm)) * x^(Suc mm)" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 912 | by (simp add: algebra_simps) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 913 | also have "(of_nat mm + a gchoose (Suc mm)) = (-1) ^ (Suc mm) * (- a gchoose (Suc mm))" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 914 | by (subst gbinomial_negated_upper) simp | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 915 | also have "(-1) ^ Suc mm * (- a gchoose Suc mm) * x ^ Suc mm = | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 916 | (- a gchoose (Suc mm)) * (-x) ^ Suc mm" | 
| 63466 | 917 | by (simp add: power_minus[of x]) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 918 | also have "(x + y) * S mm + \<dots> = (x + y) * ?rhs mm + (- a gchoose (Suc mm)) * (- x)^Suc mm" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 919 | unfolding S_def by (subst Suc.IH) simp | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 920 | also have "(x + y) * ?rhs mm = (\<Sum>n\<le>mm. ((- a gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n)))" | 
| 64267 | 921 | by (subst sum_distrib_left, rule sum.cong) (simp_all add: Suc_diff_le) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 922 | also have "\<dots> + (-a gchoose (Suc mm)) * (-x)^Suc mm = | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 923 | (\<Sum>n\<le>Suc mm. (- a gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n))" | 
| 63466 | 924 | by simp | 
| 925 | finally show ?case | |
| 926 | by (simp only: S_def) | |
| 927 | qed | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 928 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 929 | lemma gbinomial_partial_sum_poly_xpos: | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 930 | "(\<Sum>k\<le>m. (of_nat m + a gchoose k) * x^k * y^(m-k)) = | 
| 71699 | 931 | (\<Sum>k\<le>m. (of_nat k + a - 1 gchoose k) * x^k * (x + y)^(m-k))" (is "?lhs = ?rhs") | 
| 932 | proof - | |
| 933 | have "?lhs = (\<Sum>k\<le>m. (- a gchoose k) * (- x) ^ k * (x + y) ^ (m - k))" | |
| 934 | by (simp add: gbinomial_partial_sum_poly) | |
| 935 | also have "... = (\<Sum>k\<le>m. (-1) ^ k * (of_nat k - - a - 1 gchoose k) * (- x) ^ k * (x + y) ^ (m - k))" | |
| 73932 
fd21b4a93043
added opaque_combs and renamed hide_lams to opaque_lifting
 desharna parents: 
72302diff
changeset | 936 | by (metis (no_types, opaque_lifting) gbinomial_negated_upper) | 
| 71699 | 937 | also have "... = ?rhs" | 
| 938 | by (intro sum.cong) (auto simp flip: power_mult_distrib) | |
| 939 | finally show ?thesis . | |
| 940 | qed | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 941 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 942 | lemma binomial_r_part_sum: "(\<Sum>k\<le>m. (2 * m + 1 choose k)) = 2 ^ (2 * m)" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 943 | proof - | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 944 | have "2 * 2^(2*m) = (\<Sum>k = 0..(2 * m + 1). (2 * m + 1 choose k))" | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 945 | using choose_row_sum[where n="2 * m + 1"] by (simp add: atMost_atLeast0) | 
| 63466 | 946 | also have "(\<Sum>k = 0..(2 * m + 1). (2 * m + 1 choose k)) = | 
| 947 | (\<Sum>k = 0..m. (2 * m + 1 choose k)) + | |
| 948 | (\<Sum>k = m+1..2*m+1. (2 * m + 1 choose k))" | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 949 | using sum.ub_add_nat[of 0 m "\<lambda>k. 2 * m + 1 choose k" "m+1"] | 
| 63466 | 950 | by (simp add: mult_2) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 951 | also have "(\<Sum>k = m+1..2*m+1. (2 * m + 1 choose k)) = | 
| 63466 | 952 | (\<Sum>k = 0..m. (2 * m + 1 choose (k + (m + 1))))" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 953 | by (subst sum.shift_bounds_cl_nat_ivl [symmetric]) (simp add: mult_2) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 954 | also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose (m - k)))" | 
| 64267 | 955 | by (intro sum.cong[OF refl], subst binomial_symmetric) simp_all | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 956 | also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose k))" | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 957 | using sum.atLeastAtMost_rev [of "\<lambda>k. 2 * m + 1 choose (m - k)" 0 m] | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63373diff
changeset | 958 | by simp | 
| 63466 | 959 | also have "\<dots> + \<dots> = 2 * \<dots>" | 
| 960 | by simp | |
| 961 | finally show ?thesis | |
| 962 | by (subst (asm) mult_cancel1) (simp add: atLeast0AtMost) | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 963 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 964 | |
| 63466 | 965 | lemma gbinomial_r_part_sum: "(\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k)) = 2 ^ (2 * m)" | 
| 966 | (is "?lhs = ?rhs") | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 967 | proof - | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 968 | have "?lhs = of_nat (\<Sum>k\<le>m. (2 * m + 1) choose k)" | 
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 969 | by (simp add: binomial_gbinomial add_ac) | 
| 63466 | 970 | also have "\<dots> = of_nat (2 ^ (2 * m))" | 
| 971 | by (subst binomial_r_part_sum) (rule refl) | |
| 63366 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 haftmann parents: 
63363diff
changeset | 972 | finally show ?thesis by simp | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 973 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 974 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 975 | lemma gbinomial_sum_nat_pow2: | 
| 63466 | 976 | "(\<Sum>k\<le>m. (of_nat (m + k) gchoose k :: 'a::field_char_0) / 2 ^ k) = 2 ^ m" | 
| 977 | (is "?lhs = ?rhs") | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 978 | proof - | 
| 63466 | 979 | have "2 ^ m * 2 ^ m = (2 ^ (2*m) :: 'a)" | 
| 980 | by (induct m) simp_all | |
| 981 | also have "\<dots> = (\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k))" | |
| 982 | using gbinomial_r_part_sum .. | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 983 | also have "\<dots> = (\<Sum>k\<le>m. (of_nat (m + k) gchoose k) * 2 ^ (m - k))" | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 984 | using gbinomial_partial_sum_poly_xpos[where x="1" and y="1" and a="of_nat m + 1" and m="m"] | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 985 | by (simp add: add_ac) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 986 | also have "\<dots> = 2 ^ m * (\<Sum>k\<le>m. (of_nat (m + k) gchoose k) / 2 ^ k)" | 
| 64267 | 987 | by (subst sum_distrib_left) (simp add: algebra_simps power_diff) | 
| 63466 | 988 | finally show ?thesis | 
| 989 | by (subst (asm) mult_left_cancel) simp_all | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 990 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 991 | |
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 992 | lemma gbinomial_trinomial_revision: | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 993 | assumes "k \<le> m" | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 994 | shows "(a gchoose m) * (of_nat m gchoose k) = (a gchoose k) * (a - of_nat k gchoose (m - k))" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 995 | proof - | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 996 | have "(a gchoose m) * (of_nat m gchoose k) = (a gchoose m) * fact m / (fact k * fact (m - k))" | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 997 | using assms by (simp add: binomial_gbinomial [symmetric] binomial_fact) | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 998 | also have "\<dots> = (a gchoose k) * (a - of_nat k gchoose (m - k))" | 
| 63466 | 999 | using assms by (simp add: gbinomial_pochhammer power_diff pochhammer_product) | 
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 1000 | finally show ?thesis . | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 1001 | qed | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61076diff
changeset | 1002 | |
| 63466 | 1003 | text \<open>Versions of the theorems above for the natural-number version of "choose"\<close> | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1004 | lemma binomial_altdef_of_nat: | 
| 63466 | 1005 | "k \<le> n \<Longrightarrow> of_nat (n choose k) = (\<Prod>i = 0..<k. of_nat (n - i) / of_nat (k - i) :: 'a)" | 
| 1006 | for n k :: nat and x :: "'a::field_char_0" | |
| 1007 | by (simp add: gbinomial_altdef_of_nat binomial_gbinomial of_nat_diff) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1008 | |
| 63466 | 1009 | lemma binomial_ge_n_over_k_pow_k: "k \<le> n \<Longrightarrow> (of_nat n / of_nat k :: 'a) ^ k \<le> of_nat (n choose k)" | 
| 1010 | for k n :: nat and x :: "'a::linordered_field" | |
| 1011 | by (simp add: gbinomial_ge_n_over_k_pow_k binomial_gbinomial of_nat_diff) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1012 | |
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1013 | lemma binomial_le_pow: | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1014 | assumes "r \<le> n" | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1015 | shows "n choose r \<le> n ^ r" | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1016 | proof - | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1017 | have "n choose r \<le> fact n div fact (n - r)" | 
| 63466 | 1018 | using assms by (subst binomial_fact_lemma[symmetric]) auto | 
| 1019 | with fact_div_fact_le_pow [OF assms] show ?thesis | |
| 1020 | by auto | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1021 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1022 | |
| 63466 | 1023 | lemma binomial_altdef_nat: "k \<le> n \<Longrightarrow> n choose k = fact n div (fact k * fact (n - k))" | 
| 1024 | for k n :: nat | |
| 1025 | by (subst binomial_fact_lemma [symmetric]) auto | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1026 | |
| 63466 | 1027 | lemma choose_dvd: | 
| 71699 | 1028 | assumes "k \<le> n" shows "fact k * fact (n - k) dvd (fact n :: 'a::linordered_semidom)" | 
| 59730 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 paulson <lp15@cam.ac.uk> parents: 
59669diff
changeset | 1029 | unfolding dvd_def | 
| 71699 | 1030 | proof | 
| 1031 | show "fact n = fact k * fact (n - k) * of_nat (n choose k)" | |
| 1032 | by (metis assms binomial_fact_lemma of_nat_fact of_nat_mult) | |
| 1033 | qed | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1034 | |
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 1035 | lemma fact_fact_dvd_fact: | 
| 66806 
a4e82b58d833
abolished (semi)ring_div in favour of euclidean_(semi)ring_cancel
 haftmann parents: 
66311diff
changeset | 1036 | "fact k * fact n dvd (fact (k + n) :: 'a::linordered_semidom)" | 
| 63466 | 1037 | by (metis add.commute add_diff_cancel_left' choose_dvd le_add2) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1038 | |
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1039 | lemma choose_mult_lemma: | 
| 63466 | 1040 | "((m + r + k) choose (m + k)) * ((m + k) choose k) = ((m + r + k) choose k) * ((m + r) choose m)" | 
| 1041 | (is "?lhs = _") | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1042 | proof - | 
| 63466 | 1043 | have "?lhs = | 
| 1044 | fact (m + r + k) div (fact (m + k) * fact (m + r - m)) * (fact (m + k) div (fact k * fact m))" | |
| 63092 | 1045 | by (simp add: binomial_altdef_nat) | 
| 71699 | 1046 | also have "... = fact (m + r + k) * fact (m + k) div | 
| 1047 | (fact (m + k) * fact (m + r - m) * (fact k * fact m))" | |
| 75864 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1048 | by (metis add_implies_diff add_le_mono1 choose_dvd diff_cancel2 div_mult_div_if_dvd le_add1 le_add2) | 
| 71699 | 1049 | also have "\<dots> = fact (m + r + k) div (fact r * (fact k * fact m))" | 
| 1050 | by (auto simp: algebra_simps fact_fact_dvd_fact) | |
| 63466 | 1051 | also have "\<dots> = (fact (m + r + k) * fact (m + r)) div (fact r * (fact k * fact m) * fact (m + r))" | 
| 75864 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1052 | by simp | 
| 63466 | 1053 | also have "\<dots> = | 
| 1054 | (fact (m + r + k) div (fact k * fact (m + r)) * (fact (m + r) div (fact r * fact m)))" | |
| 71720 | 1055 | by (auto simp: div_mult_div_if_dvd fact_fact_dvd_fact algebra_simps) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1056 | finally show ?thesis | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1057 | by (simp add: binomial_altdef_nat mult.commute) | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1058 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1059 | |
| 63466 | 1060 | text \<open>The "Subset of a Subset" identity.\<close> | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1061 | lemma choose_mult: | 
| 63466 | 1062 | "k \<le> m \<Longrightarrow> m \<le> n \<Longrightarrow> (n choose m) * (m choose k) = (n choose k) * ((n - k) choose (m - k))" | 
| 1063 | using choose_mult_lemma [of "m-k" "n-m" k] by simp | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1064 | |
| 75864 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1065 | lemma of_nat_binomial_eq_mult_binomial_Suc: | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1066 | assumes "k \<le> n" | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1067 |   shows "(of_nat :: (nat \<Rightarrow> ('a :: field_char_0))) (n choose k) = of_nat (n + 1 - k) / of_nat (n + 1) * of_nat (Suc n choose k)"
 | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1068 | proof (cases k) | 
| 75865 
62c64e3e4741
The same, without adding a new simprule
 paulson <lp15@cam.ac.uk> parents: 
75864diff
changeset | 1069 | case 0 then show ?thesis | 
| 
62c64e3e4741
The same, without adding a new simprule
 paulson <lp15@cam.ac.uk> parents: 
75864diff
changeset | 1070 | using of_nat_neq_0 by auto | 
| 75864 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1071 | next | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1072 | case (Suc l) | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1073 | have "of_nat (n + 1) * (\<Prod>i=0..<k. of_nat (n - i)) = (of_nat :: (nat \<Rightarrow> 'a)) (n + 1 - k) * (\<Prod>i=0..<k. of_nat (Suc n - i))" | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1074 | using prod.atLeast0_lessThan_Suc [where ?'a = 'a, symmetric, of "\<lambda>i. of_nat (Suc n - i)" k] | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1075 | by (simp add: ac_simps prod.atLeast0_lessThan_Suc_shift del: prod.op_ivl_Suc) | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1076 | also have "... = (of_nat :: (nat \<Rightarrow> 'a)) (Suc n - k) * (\<Prod>i=0..<k. of_nat (Suc n - i))" | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1077 | by (simp add: Suc atLeast0_atMost_Suc atLeastLessThanSuc_atLeastAtMost) | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1078 | also have "... = (of_nat :: (nat \<Rightarrow> 'a)) (n + 1 - k) * (\<Prod>i=0..<k. of_nat (Suc n - i))" | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1079 | by (simp only: Suc_eq_plus1) | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1080 | finally have "(\<Prod>i=0..<k. of_nat (n - i)) = (of_nat :: (nat \<Rightarrow> 'a)) (n + 1 - k) / of_nat (n + 1) * (\<Prod>i=0..<k. of_nat (Suc n - i))" | 
| 75865 
62c64e3e4741
The same, without adding a new simprule
 paulson <lp15@cam.ac.uk> parents: 
75864diff
changeset | 1081 | using of_nat_neq_0 by (auto simp: mult.commute divide_simps) | 
| 75864 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1082 | with assms show ?thesis | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1083 | by (simp add: binomial_altdef_of_nat prod_dividef) | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1084 | qed | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75856diff
changeset | 1085 | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1086 | |
| 63373 | 1087 | subsection \<open>More on Binomial Coefficients\<close> | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1088 | |
| 63466 | 1089 | lemma choose_one: "n choose 1 = n" for n :: nat | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1090 | by simp | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1091 | |
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1092 | text \<open>The famous inclusion-exclusion formula for the cardinality of a union\<close> | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1093 | lemma int_card_UNION: | 
| 63466 | 1094 | assumes "finite A" | 
| 1095 | and "\<forall>k \<in> A. finite k" | |
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1096 |   shows "int (card (\<Union>A)) = (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * int (card (\<Inter>I)))"
 | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1097 | (is "?lhs = ?rhs") | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1098 | proof - | 
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1099 |   have "?rhs = (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * (\<Sum>_\<in>\<Inter>I. 1))"
 | 
| 63466 | 1100 | by simp | 
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1101 |   also have "\<dots> = (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (\<Sum>_\<in>\<Inter>I. (- 1) ^ (card I + 1)))"
 | 
| 64267 | 1102 | by (subst sum_distrib_left) simp | 
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1103 |   also have "\<dots> = (\<Sum>(I, _)\<in>Sigma {I. I \<subseteq> A \<and> I \<noteq> {}} Inter. (- 1) ^ (card I + 1))"
 | 
| 64267 | 1104 | using assms by (subst sum.Sigma) auto | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1105 |   also have "\<dots> = (\<Sum>(x, I)\<in>(SIGMA x:UNIV. {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}). (- 1) ^ (card I + 1))"
 | 
| 69768 | 1106 | by (rule sum.reindex_cong [where l = "\<lambda>(x, y). (y, x)"]) (auto intro: inj_onI) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1107 |   also have "\<dots> = (\<Sum>(x, I)\<in>(SIGMA x:\<Union>A. {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}). (- 1) ^ (card I + 1))"
 | 
| 63466 | 1108 | using assms | 
| 64267 | 1109 | by (auto intro!: sum.mono_neutral_cong_right finite_SigmaI2 intro: finite_subset[where B="\<Union>A"]) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1110 |   also have "\<dots> = (\<Sum>x\<in>\<Union>A. (\<Sum>I|I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I. (- 1) ^ (card I + 1)))"
 | 
| 64267 | 1111 | using assms by (subst sum.Sigma) auto | 
| 1112 | also have "\<dots> = (\<Sum>_\<in>\<Union>A. 1)" (is "sum ?lhs _ = _") | |
| 1113 | proof (rule sum.cong[OF refl]) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1114 | fix x | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1115 | assume x: "x \<in> \<Union>A" | 
| 63040 | 1116 |     define K where "K = {X \<in> A. x \<in> X}"
 | 
| 63466 | 1117 | with \<open>finite A\<close> have K: "finite K" | 
| 1118 | by auto | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1119 |     let ?I = "\<lambda>i. {I. I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I}"
 | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1120 |     have "inj_on snd (SIGMA i:{1..card A}. ?I i)"
 | 
| 63466 | 1121 | using assms by (auto intro!: inj_onI) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1122 |     moreover have [symmetric]: "snd ` (SIGMA i:{1..card A}. ?I i) = {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}"
 | 
| 63466 | 1123 | using assms | 
| 1124 | by (auto intro!: rev_image_eqI[where x="(card a, a)" for a] | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1125 | simp add: card_gt_0_iff[folded Suc_le_eq] | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1126 | dest: finite_subset intro: card_mono) | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1127 |     ultimately have "?lhs x = (\<Sum>(i, I)\<in>(SIGMA i:{1..card A}. ?I i). (- 1) ^ (i + 1))"
 | 
| 64267 | 1128 | by (rule sum.reindex_cong [where l = snd]) fastforce | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1129 | also have "\<dots> = (\<Sum>i=1..card A. (\<Sum>I|I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. (- 1) ^ (i + 1)))" | 
| 64267 | 1130 | using assms by (subst sum.Sigma) auto | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1131 | also have "\<dots> = (\<Sum>i=1..card A. (- 1) ^ (i + 1) * (\<Sum>I|I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1))" | 
| 64267 | 1132 | by (subst sum_distrib_left) simp | 
| 63466 | 1133 | also have "\<dots> = (\<Sum>i=1..card K. (- 1) ^ (i + 1) * (\<Sum>I|I \<subseteq> K \<and> card I = i. 1))" | 
| 1134 | (is "_ = ?rhs") | |
| 64267 | 1135 | proof (rule sum.mono_neutral_cong_right[rule_format]) | 
| 63466 | 1136 |       show "finite {1..card A}"
 | 
| 1137 | by simp | |
| 1138 |       show "{1..card K} \<subseteq> {1..card A}"
 | |
| 1139 | using \<open>finite A\<close> by (auto simp add: K_def intro: card_mono) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1140 | next | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1141 | fix i | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1142 |       assume "i \<in> {1..card A} - {1..card K}"
 | 
| 63466 | 1143 | then have i: "i \<le> card A" "card K < i" | 
| 1144 | by auto | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1145 |       have "{I. I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I} = {I. I \<subseteq> K \<and> card I = i}"
 | 
| 63466 | 1146 | by (auto simp add: K_def) | 
| 1147 |       also have "\<dots> = {}"
 | |
| 1148 | using \<open>finite A\<close> i by (auto simp add: K_def dest: card_mono[rotated 1]) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1149 | finally show "(- 1) ^ (i + 1) * (\<Sum>I | I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1 :: int) = 0" | 
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1150 | by (metis mult_zero_right sum.empty) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1151 | next | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1152 | fix i | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1153 | have "(\<Sum>I | I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1) = (\<Sum>I | I \<subseteq> K \<and> card I = i. 1 :: int)" | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1154 | (is "?lhs = ?rhs") | 
| 64267 | 1155 | by (rule sum.cong) (auto simp add: K_def) | 
| 63466 | 1156 | then show "(- 1) ^ (i + 1) * ?lhs = (- 1) ^ (i + 1) * ?rhs" | 
| 1157 | by simp | |
| 1158 | qed | |
| 1159 |     also have "{I. I \<subseteq> K \<and> card I = 0} = {{}}"
 | |
| 1160 | using assms by (auto simp add: card_eq_0_iff K_def dest: finite_subset) | |
| 1161 | then have "?rhs = (\<Sum>i = 0..card K. (- 1) ^ (i + 1) * (\<Sum>I | I \<subseteq> K \<and> card I = i. 1 :: int)) + 1" | |
| 70097 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1162 | by (subst (2) sum.atLeast_Suc_atMost) simp_all | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1163 | also have "\<dots> = (\<Sum>i = 0..card K. (- 1) * ((- 1) ^ i * int (card K choose i))) + 1" | 
| 63466 | 1164 | using K by (subst n_subsets[symmetric]) simp_all | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1165 | also have "\<dots> = - (\<Sum>i = 0..card K. (- 1) ^ i * int (card K choose i)) + 1" | 
| 64267 | 1166 | by (subst sum_distrib_left[symmetric]) simp | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1167 | also have "\<dots> = - ((-1 + 1) ^ card K) + 1" | 
| 68077 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 paulson <lp15@cam.ac.uk> parents: 
67443diff
changeset | 1168 | by (subst binomial_ring) (simp add: ac_simps atMost_atLeast0) | 
| 63466 | 1169 | also have "\<dots> = 1" | 
| 1170 | using x K by (auto simp add: K_def card_gt_0_iff) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1171 | finally show "?lhs x = 1" . | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1172 | qed | 
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1173 | also have "\<dots> = int (card (\<Union>A))" | 
| 63466 | 1174 | by simp | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1175 | finally show ?thesis .. | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1176 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1177 | |
| 75856 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1178 | lemma card_UNION: | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1179 | assumes "finite A" | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1180 | and "\<forall>k \<in> A. finite k" | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1181 |   shows "card (\<Union>A) = nat (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * int (card (\<Inter>I)))"
 | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1182 | by (simp only: flip: int_card_UNION [OF assms]) | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1183 | |
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1184 | lemma card_UNION_nonneg: | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1185 | assumes "finite A" | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1186 | and "\<forall>k \<in> A. finite k" | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1187 |   shows "(\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * int (card (\<Inter>I))) \<ge> 0"
 | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1188 | using int_card_UNION [OF assms] by presburger | 
| 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 paulson <lp15@cam.ac.uk> parents: 
73932diff
changeset | 1189 | |
| 69593 | 1190 | text \<open>The number of nat lists of length \<open>m\<close> summing to \<open>N\<close> is \<^term>\<open>(N + m - 1) choose N\<close>:\<close> | 
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1191 | lemma card_length_sum_list_rec: | 
| 63466 | 1192 | assumes "m \<ge> 1" | 
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1193 |   shows "card {l::nat list. length l = m \<and> sum_list l = N} =
 | 
| 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1194 |       card {l. length l = (m - 1) \<and> sum_list l = N} +
 | 
| 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1195 |       card {l. length l = m \<and> sum_list l + 1 = N}"
 | 
| 63466 | 1196 | (is "card ?C = card ?A + card ?B") | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1197 | proof - | 
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1198 |   let ?A' = "{l. length l = m \<and> sum_list l = N \<and> hd l = 0}"
 | 
| 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1199 |   let ?B' = "{l. length l = m \<and> sum_list l = N \<and> hd l \<noteq> 0}"
 | 
| 63466 | 1200 | let ?f = "\<lambda>l. 0 # l" | 
| 1201 | let ?g = "\<lambda>l. (hd l + 1) # tl l" | |
| 65812 | 1202 | have 1: "xs \<noteq> [] \<Longrightarrow> x = hd xs \<Longrightarrow> x # tl xs = xs" for x :: nat and xs | 
| 63466 | 1203 | by simp | 
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1204 | have 2: "xs \<noteq> [] \<Longrightarrow> sum_list(tl xs) = sum_list xs - hd xs" for xs :: "nat list" | 
| 63466 | 1205 | by (auto simp add: neq_Nil_conv) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1206 | have f: "bij_betw ?f ?A ?A'" | 
| 71720 | 1207 | by (rule bij_betw_byWitness[where f' = tl]) (use assms in \<open>auto simp: 2 1 simp flip: length_0_conv\<close>) | 
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1208 | have 3: "xs \<noteq> [] \<Longrightarrow> hd xs + (sum_list xs - hd xs) = sum_list xs" for xs :: "nat list" | 
| 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1209 | by (metis 1 sum_list_simps(2) 2) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1210 | have g: "bij_betw ?g ?B ?B'" | 
| 63466 | 1211 | apply (rule bij_betw_byWitness[where f' = "\<lambda>l. (hd l - 1) # tl l"]) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1212 | using assms | 
| 71720 | 1213 | by (auto simp: 2 simp flip: length_0_conv intro!: 3) | 
| 63466 | 1214 |   have fin: "finite {xs. size xs = M \<and> set xs \<subseteq> {0..<N}}" for M N :: nat
 | 
| 1215 | using finite_lists_length_eq[OF finite_atLeastLessThan] conj_commute by auto | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1216 | have fin_A: "finite ?A" using fin[of _ "N+1"] | 
| 63466 | 1217 |     by (intro finite_subset[where ?A = "?A" and ?B = "{xs. size xs = m - 1 \<and> set xs \<subseteq> {0..<N+1}}"])
 | 
| 66311 | 1218 | (auto simp: member_le_sum_list less_Suc_eq_le) | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1219 | have fin_B: "finite ?B" | 
| 63466 | 1220 |     by (intro finite_subset[where ?A = "?B" and ?B = "{xs. size xs = m \<and> set xs \<subseteq> {0..<N}}"])
 | 
| 66311 | 1221 | (auto simp: member_le_sum_list less_Suc_eq_le fin) | 
| 63466 | 1222 | have uni: "?C = ?A' \<union> ?B'" | 
| 1223 | by auto | |
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1224 |   have disj: "?A' \<inter> ?B' = {}" by blast
 | 
| 63466 | 1225 | have "card ?C = card(?A' \<union> ?B')" | 
| 1226 | using uni by simp | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1227 | also have "\<dots> = card ?A + card ?B" | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1228 | using card_Un_disjoint[OF _ _ disj] bij_betw_finite[OF f] bij_betw_finite[OF g] | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1229 | bij_betw_same_card[OF f] bij_betw_same_card[OF g] fin_A fin_B | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1230 | by presburger | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1231 | finally show ?thesis . | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1232 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1233 | |
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1234 | lemma card_length_sum_list: "card {l::nat list. size l = m \<and> sum_list l = N} = (N + m - 1) choose N"
 | 
| 67443 
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
 wenzelm parents: 
67411diff
changeset | 1235 | \<comment> \<open>by Holden Lee, tidied by Tobias Nipkow\<close> | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1236 | proof (cases m) | 
| 63466 | 1237 | case 0 | 
| 1238 | then show ?thesis | |
| 1239 | by (cases N) (auto cong: conj_cong) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1240 | next | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1241 | case (Suc m') | 
| 63466 | 1242 | have m: "m \<ge> 1" | 
| 1243 | by (simp add: Suc) | |
| 1244 | then show ?thesis | |
| 1245 | proof (induct "N + m - 1" arbitrary: N m) | |
| 67443 
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
 wenzelm parents: 
67411diff
changeset | 1246 | case 0 \<comment> \<open>In the base case, the only solution is [0].\<close> | 
| 63466 | 1247 |     have [simp]: "{l::nat list. length l = Suc 0 \<and> (\<forall>n\<in>set l. n = 0)} = {[0]}"
 | 
| 1248 | by (auto simp: length_Suc_conv) | |
| 1249 | have "m = 1 \<and> N = 0" | |
| 1250 | using 0 by linarith | |
| 1251 | then show ?case | |
| 1252 | by simp | |
| 1253 | next | |
| 1254 | case (Suc k) | |
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1255 |     have c1: "card {l::nat list. size l = (m - 1) \<and> sum_list l =  N} = (N + (m - 1) - 1) choose N"
 | 
| 63466 | 1256 | proof (cases "m = 1") | 
| 1257 | case True | |
| 1258 | with Suc.hyps have "N \<ge> 1" | |
| 1259 | by auto | |
| 1260 | with True show ?thesis | |
| 1261 | by (simp add: binomial_eq_0) | |
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1262 | next | 
| 63466 | 1263 | case False | 
| 1264 | then show ?thesis | |
| 1265 | using Suc by fastforce | |
| 1266 | qed | |
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1267 |     from Suc have c2: "card {l::nat list. size l = m \<and> sum_list l + 1 = N} =
 | 
| 63466 | 1268 | (if N > 0 then ((N - 1) + m - 1) choose (N - 1) else 0)" | 
| 1269 | proof - | |
| 1270 | have *: "n > 0 \<Longrightarrow> Suc m = n \<longleftrightarrow> m = n - 1" for m n | |
| 1271 | by arith | |
| 1272 | from Suc have "N > 0 \<Longrightarrow> | |
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1273 |         card {l::nat list. size l = m \<and> sum_list l + 1 = N} =
 | 
| 63466 | 1274 | ((N - 1) + m - 1) choose (N - 1)" | 
| 1275 | by (simp add: *) | |
| 1276 | then show ?thesis | |
| 1277 | by auto | |
| 1278 | qed | |
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1279 |     from Suc.prems have "(card {l::nat list. size l = (m - 1) \<and> sum_list l = N} +
 | 
| 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1280 |           card {l::nat list. size l = m \<and> sum_list l + 1 = N}) = (N + m - 1) choose N"
 | 
| 63466 | 1281 | by (auto simp: c1 c2 choose_reduce_nat[of "N + m - 1" N] simp del: One_nat_def) | 
| 1282 | then show ?case | |
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63725diff
changeset | 1283 | using card_length_sum_list_rec[OF Suc.prems] by auto | 
| 63466 | 1284 | qed | 
| 59667 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1285 | qed | 
| 
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
 paulson <lp15@cam.ac.uk> parents: 
59658diff
changeset | 1286 | |
| 69107 | 1287 | lemma card_disjoint_shuffles: | 
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1288 |   assumes "set xs \<inter> set ys = {}"
 | 
| 69107 | 1289 | shows "card (shuffles xs ys) = (length xs + length ys) choose length xs" | 
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1290 | using assms | 
| 69107 | 1291 | proof (induction xs ys rule: shuffles.induct) | 
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1292 | case (3 x xs y ys) | 
| 69107 | 1293 | have "shuffles (x # xs) (y # ys) = (#) x ` shuffles xs (y # ys) \<union> (#) y ` shuffles (x # xs) ys" | 
| 1294 | by (rule shuffles.simps) | |
| 1295 | also have "card \<dots> = card ((#) x ` shuffles xs (y # ys)) + card ((#) y ` shuffles (x # xs) ys)" | |
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1296 | by (rule card_Un_disjoint) (insert "3.prems", auto) | 
| 69107 | 1297 | also have "card ((#) x ` shuffles xs (y # ys)) = card (shuffles xs (y # ys))" | 
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1298 | by (rule card_image) auto | 
| 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1299 | also have "\<dots> = (length xs + length (y # ys)) choose length xs" | 
| 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1300 | using "3.prems" by (intro "3.IH") auto | 
| 69107 | 1301 | also have "card ((#) y ` shuffles (x # xs) ys) = card (shuffles (x # xs) ys)" | 
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1302 | by (rule card_image) auto | 
| 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1303 | also have "\<dots> = (length (x # xs) + length ys) choose length (x # xs)" | 
| 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1304 | using "3.prems" by (intro "3.IH") auto | 
| 65552 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 wenzelm parents: 
65350diff
changeset | 1305 | also have "length xs + length (y # ys) choose length xs + \<dots> = | 
| 65350 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1306 | (length (x # xs) + length (y # ys)) choose length (x # xs)" by simp | 
| 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1307 | finally show ?case . | 
| 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1308 | qed auto | 
| 
b149abe619f7
added shuffle product to HOL/List
 eberlm <eberlm@in.tum.de> parents: 
64272diff
changeset | 1309 | |
| 63466 | 1310 | lemma Suc_times_binomial_add: "Suc a * (Suc (a + b) choose Suc a) = Suc b * (Suc (a + b) choose a)" | 
| 1311 | \<comment> \<open>by Lukas Bulwahn\<close> | |
| 60604 | 1312 | proof - | 
| 1313 | have dvd: "Suc a * (fact a * fact b) dvd fact (Suc (a + b))" for a b | |
| 1314 | using fact_fact_dvd_fact[of "Suc a" "b", where 'a=nat] | |
| 1315 | by (simp only: fact_Suc add_Suc[symmetric] of_nat_id mult.assoc) | |
| 1316 | have "Suc a * (fact (Suc (a + b)) div (Suc a * fact a * fact b)) = | |
| 1317 | Suc a * fact (Suc (a + b)) div (Suc a * (fact a * fact b))" | |
| 1318 | by (subst div_mult_swap[symmetric]; simp only: mult.assoc dvd) | |
| 1319 | also have "\<dots> = Suc b * fact (Suc (a + b)) div (Suc b * (fact a * fact b))" | |
| 1320 | by (simp only: div_mult_mult1) | |
| 1321 | also have "\<dots> = Suc b * (fact (Suc (a + b)) div (Suc b * (fact a * fact b)))" | |
| 1322 | using dvd[of b a] by (subst div_mult_swap[symmetric]; simp only: ac_simps dvd) | |
| 1323 | finally show ?thesis | |
| 1324 | by (subst (1 2) binomial_altdef_nat) | |
| 63466 | 1325 | (simp_all only: ac_simps diff_Suc_Suc Suc_diff_le diff_add_inverse fact_Suc of_nat_id) | 
| 60604 | 1326 | qed | 
| 1327 | ||
| 63373 | 1328 | |
| 68785 | 1329 | subsection \<open>Executable code\<close> | 
| 63373 | 1330 | |
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1331 | lemma gbinomial_code [code]: | 
| 68787 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 1332 | "a gchoose k = | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 1333 | (if k = 0 then 1 | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 1334 | else fold_atLeastAtMost_nat (\<lambda>k acc. (a - of_nat k) * acc) 0 (k - 1) 1 / fact k)" | 
| 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 haftmann parents: 
68786diff
changeset | 1335 | by (cases k) | 
| 64272 | 1336 | (simp_all add: gbinomial_prod_rev prod_atLeastAtMost_code [symmetric] | 
| 63466 | 1337 | atLeastLessThanSuc_atLeastAtMost) | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1338 | |
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1339 | lemma binomial_code [code]: | 
| 68785 | 1340 | "n choose k = | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1341 | (if k > n then 0 | 
| 68785 | 1342 | else if 2 * k > n then n choose (n - k) | 
| 69064 
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
 nipkow parents: 
68787diff
changeset | 1343 | else (fold_atLeastAtMost_nat (*) (n - k + 1) n 1 div fact k))" | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1344 | proof - | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1345 |   {
 | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1346 | assume "k \<le> n" | 
| 63466 | 1347 |     then have "{1..n} = {1..n-k} \<union> {n-k+1..n}" by auto
 | 
| 1348 |     then have "(fact n :: nat) = fact (n-k) * \<Prod>{n-k+1..n}"
 | |
| 65581 
baf96277ee76
better code equation for binomial
 eberlm <eberlm@in.tum.de> parents: 
65552diff
changeset | 1349 | by (simp add: prod.union_disjoint fact_prod) | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1350 | } | 
| 64272 | 1351 | then show ?thesis by (auto simp: binomial_altdef_nat mult_ac prod_atLeastAtMost_code) | 
| 62378 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 hoelzl parents: 
62347diff
changeset | 1352 | qed | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61799diff
changeset | 1353 | |
| 15131 | 1354 | end |