| author | wenzelm | 
| Tue, 05 Mar 2024 20:58:41 +0100 | |
| changeset 79793 | 6f08aef43dc5 | 
| parent 79586 | 9cde97e471df | 
| child 80175 | 200107cdd3ac | 
| 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  | 
||
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
9  | 
section \<open>Binomial Coefficients, Binomial Theorem, Inclusion-exclusion Principle\<close>  | 
| 
15094
 
a7d1a3fdc30d
conversion of Hyperreal/{Fact,Filter} to Isar scripts
 
paulson 
parents: 
12196 
diff
changeset
 | 
10  | 
|
| 
59669
 
de7792ea4090
renaming HOL/Fact.thy -> Binomial.thy
 
paulson <lp15@cam.ac.uk> 
parents: 
59667 
diff
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: 
59658 
diff
changeset
 | 
13  | 
begin  | 
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
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: 
58889 
diff
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: 
63363 
diff
changeset
 | 
19  | 
text \<open>Combinatorial definition\<close>  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
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: 
58889 
diff
changeset
 | 
23  | 
|
| 79586 | 24  | 
lemma binomial_mono:  | 
25  | 
assumes "m \<le> n" shows "m choose k \<le> n choose k"  | 
|
26  | 
proof -  | 
|
27  | 
  have "{K. K \<subseteq> {0..<m} \<and> card K = k} \<subseteq> {K. K \<subseteq> {0..<n} \<and> card K = k}"
 | 
|
28  | 
using assms by auto  | 
|
29  | 
then show ?thesis  | 
|
30  | 
by (simp add: binomial_def card_mono)  | 
|
31  | 
qed  | 
|
32  | 
||
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
33  | 
theorem n_subsets:  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
34  | 
assumes "finite A"  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
35  | 
  shows "card {B. B \<subseteq> A \<and> card B = k} = card A choose k"
 | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
36  | 
proof -  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
37  | 
  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: 
63373 
diff
changeset
 | 
38  | 
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: 
63373 
diff
changeset
 | 
39  | 
  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: 
63363 
diff
changeset
 | 
40  | 
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: 
63373 
diff
changeset
 | 
41  | 
  from bij have "bij_betw (image f) (Pow {0..<card A}) (Pow A)"
 | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
42  | 
by (rule bij_betw_Pow)  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
43  | 
  then have "inj_on (image f) (Pow {0..<card A})"
 | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
44  | 
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: 
63373 
diff
changeset
 | 
45  | 
  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: 
63363 
diff
changeset
 | 
46  | 
by auto  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
47  | 
  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: 
63363 
diff
changeset
 | 
48  | 
by (rule inj_on_subset)  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
49  | 
  then have "card {K. K \<subseteq> {0..<card A} \<and> card K = k} =
 | 
| 63466 | 50  | 
      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: 
63363 
diff
changeset
 | 
51  | 
by (simp add: card_image)  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
52  | 
  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: 
63363 
diff
changeset
 | 
53  | 
by (auto elim!: subset_imageE)  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
54  | 
  also have "f ` {0..<card A} = A"
 | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
55  | 
by (meson bij bij_betw_def)  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
56  | 
finally show ?thesis  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
57  | 
by (simp add: binomial_def)  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
58  | 
qed  | 
| 63466 | 59  | 
|
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
60  | 
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: 
58889 
diff
changeset
 | 
61  | 
|
| 68785 | 62  | 
lemma binomial_n_0 [simp]: "n choose 0 = 1"  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
63  | 
proof -  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
64  | 
  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: 
63373 
diff
changeset
 | 
65  | 
by (auto dest: finite_subset)  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
66  | 
then show ?thesis  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
67  | 
by (simp add: binomial_def)  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
68  | 
qed  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
69  | 
|
| 68785 | 70  | 
lemma binomial_0_Suc [simp]: "0 choose Suc k = 0"  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
71  | 
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: 
58889 
diff
changeset
 | 
72  | 
|
| 68785 | 73  | 
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: 
63363 
diff
changeset
 | 
74  | 
proof -  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
75  | 
  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: 
63363 
diff
changeset
 | 
76  | 
let ?Q = "?P (Suc n) (Suc k)"  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
77  | 
have inj: "inj_on (insert n) (?P n k)"  | 
| 63466 | 78  | 
by rule (auto; metis atLeastLessThan_iff insert_iff less_irrefl subsetCE)  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
79  | 
  have disjoint: "insert n ` ?P n k \<inter> ?P n (Suc k) = {}"
 | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
80  | 
by auto  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
81  | 
  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: 
63363 
diff
changeset
 | 
82  | 
by auto  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
83  | 
  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: 
63363 
diff
changeset
 | 
84  | 
proof (rule set_eqI)  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
85  | 
fix K  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
86  | 
    have K_finite: "finite K" if "K \<subseteq> insert n {0..<n}"
 | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
87  | 
using that by (rule finite_subset) simp_all  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
88  | 
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: 
63363 
diff
changeset
 | 
89  | 
and "finite K"  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
90  | 
proof -  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
91  | 
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: 
63363 
diff
changeset
 | 
92  | 
by (blast elim: Set.set_insert)  | 
| 
72302
 
d7d90ed4c74e
fixed some remarkably ugly proofs
 
paulson <lp15@cam.ac.uk> 
parents: 
71720 
diff
changeset
 | 
93  | 
with that show ?thesis by (simp add: card.insert_remove)  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
94  | 
qed  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
95  | 
show "K \<in> ?A \<longleftrightarrow> K \<in> ?B"  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
96  | 
by (subst in_image_insert_iff)  | 
| 
72302
 
d7d90ed4c74e
fixed some remarkably ugly proofs
 
paulson <lp15@cam.ac.uk> 
parents: 
71720 
diff
changeset
 | 
97  | 
(auto simp add: card.insert_remove subset_eq_atLeast0_lessThan_finite  | 
| 63466 | 98  | 
Diff_subset_conv K_finite Suc_card_K)  | 
99  | 
qed  | 
|
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
100  | 
  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: 
63373 
diff
changeset
 | 
101  | 
by (auto simp add: atLeast0_lessThan_Suc)  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
102  | 
finally show ?thesis using inj disjoint  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
103  | 
by (simp add: binomial_def card_Un_disjoint card_image)  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
104  | 
qed  | 
| 
59658
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
105  | 
|
| 63466 | 106  | 
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: 
63373 
diff
changeset
 | 
107  | 
by (auto simp add: binomial_def dest: subset_eq_atLeast0_lessThan_card)  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
108  | 
|
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
109  | 
lemma zero_less_binomial: "k \<le> n \<Longrightarrow> n choose k > 0"  | 
| 
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
110  | 
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: 
58889 
diff
changeset
 | 
111  | 
|
| 63466 | 112  | 
lemma binomial_eq_0_iff [simp]: "n choose k = 0 \<longleftrightarrow> n < k"  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
113  | 
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: 
58889 
diff
changeset
 | 
114  | 
|
| 63466 | 115  | 
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: 
63363 
diff
changeset
 | 
116  | 
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: 
58889 
diff
changeset
 | 
117  | 
|
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
118  | 
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: 
58889 
diff
changeset
 | 
119  | 
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: 
58889 
diff
changeset
 | 
120  | 
|
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
121  | 
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: 
58889 
diff
changeset
 | 
122  | 
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: 
58889 
diff
changeset
 | 
123  | 
|
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
124  | 
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: 
58889 
diff
changeset
 | 
125  | 
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: 
58889 
diff
changeset
 | 
126  | 
|
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
127  | 
lemma choose_one: "n choose 1 = n" for n :: nat  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
128  | 
by simp  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
129  | 
|
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
130  | 
lemma choose_reduce_nat:  | 
| 63466 | 131  | 
"0 < n \<Longrightarrow> 0 < k \<Longrightarrow>  | 
132  | 
n choose k = ((n - 1) choose (k - 1)) + ((n - 1) choose k)"  | 
|
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
133  | 
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: 
58889 
diff
changeset
 | 
134  | 
|
| 63466 | 135  | 
lemma Suc_times_binomial_eq: "Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"  | 
| 71699 | 136  | 
proof (induction n arbitrary: k)  | 
137  | 
case 0  | 
|
138  | 
then show ?case  | 
|
139  | 
by auto  | 
|
140  | 
next  | 
|
141  | 
case (Suc n)  | 
|
142  | 
show ?case  | 
|
143  | 
proof (cases k)  | 
|
144  | 
case (Suc k')  | 
|
145  | 
then show ?thesis  | 
|
146  | 
using Suc.IH  | 
|
147  | 
by (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq binomial_eq_0)  | 
|
148  | 
qed auto  | 
|
149  | 
qed  | 
|
| 
59658
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
150  | 
|
| 
60141
 
833adf7db7d8
New material, mostly about limits. Consolidation.
 
paulson <lp15@cam.ac.uk> 
parents: 
59867 
diff
changeset
 | 
151  | 
lemma binomial_le_pow2: "n choose k \<le> 2^n"  | 
| 71699 | 152  | 
proof (induction n arbitrary: k)  | 
153  | 
case 0  | 
|
154  | 
then show ?case  | 
|
155  | 
using le_less less_le_trans by fastforce  | 
|
156  | 
next  | 
|
157  | 
case (Suc n)  | 
|
158  | 
show ?case  | 
|
159  | 
proof (cases k)  | 
|
160  | 
case (Suc k')  | 
|
161  | 
then show ?thesis  | 
|
162  | 
using Suc.IH by (simp add: add_le_mono mult_2)  | 
|
163  | 
qed auto  | 
|
164  | 
qed  | 
|
| 
60141
 
833adf7db7d8
New material, mostly about limits. Consolidation.
 
paulson <lp15@cam.ac.uk> 
parents: 
59867 
diff
changeset
 | 
165  | 
|
| 63466 | 166  | 
text \<open>The absorption property.\<close>  | 
167  | 
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: 
58889 
diff
changeset
 | 
168  | 
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: 
58889 
diff
changeset
 | 
169  | 
|
| 63466 | 170  | 
text \<open>This is the well-known version of absorption, but it's harder to use  | 
171  | 
because of the need to reason about division.\<close>  | 
|
172  | 
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: 
58889 
diff
changeset
 | 
173  | 
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: 
58889 
diff
changeset
 | 
174  | 
|
| 63466 | 175  | 
text \<open>Another version of absorption, with \<open>-1\<close> instead of \<open>Suc\<close>.\<close>  | 
176  | 
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: 
58889 
diff
changeset
 | 
177  | 
using Suc_times_binomial_eq [where n = "n - 1" and k = "k - 1"]  | 
| 63648 | 178  | 
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: 
58889 
diff
changeset
 | 
179  | 
|
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
180  | 
|
| 60758 | 181  | 
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: 
58889 
diff
changeset
 | 
182  | 
|
| 63466 | 183  | 
text \<open>Avigad's version, generalized to any commutative ring\<close>  | 
| 
79544
 
50ee2921da94
A few more new theorems taken from AFP entries
 
paulson <lp15@cam.ac.uk> 
parents: 
78667 
diff
changeset
 | 
184  | 
theorem (in comm_semiring_1) binomial_ring:  | 
| 
 
50ee2921da94
A few more new theorems taken from AFP entries
 
paulson <lp15@cam.ac.uk> 
parents: 
78667 
diff
changeset
 | 
185  | 
"(a + b :: 'a)^n = (\<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: 
58889 
diff
changeset
 | 
186  | 
proof (induct n)  | 
| 63466 | 187  | 
case 0  | 
188  | 
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: 
58889 
diff
changeset
 | 
189  | 
next  | 
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
190  | 
case (Suc n)  | 
| 
79544
 
50ee2921da94
A few more new theorems taken from AFP entries
 
paulson <lp15@cam.ac.uk> 
parents: 
78667 
diff
changeset
 | 
191  | 
  have decomp: "{0..n+1} = {0} \<union> {n + 1} \<union> {1..n}" and 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: 
58889 
diff
changeset
 | 
192  | 
by auto  | 
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
193  | 
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: 
58889 
diff
changeset
 | 
194  | 
using Suc.hyps by simp  | 
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
195  | 
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: 
67443 
diff
changeset
 | 
196  | 
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: 
58889 
diff
changeset
 | 
197  | 
by (rule distrib_right)  | 
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
198  | 
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: 
67443 
diff
changeset
 | 
199  | 
(\<Sum>k\<le>n. of_nat (n choose k) * a^k * b^(n - k + 1))"  | 
| 64267 | 200  | 
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: 
67443 
diff
changeset
 | 
201  | 
also have "\<dots> = (\<Sum>k\<le>n. of_nat (n choose k) * a^k * b^(n + 1 - k)) +  | 
| 63466 | 202  | 
(\<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: 
70097 
diff
changeset
 | 
203  | 
by (simp add: atMost_atLeast0 sum.shift_bounds_cl_Suc_ivl Suc_diff_le field_simps del: sum.cl_ivl_Suc)  | 
| 71351 | 204  | 
also have "\<dots> = b^(n + 1) +  | 
205  | 
(\<Sum>k=1..n. of_nat (n choose k) * a^k * b^(n + 1 - k)) + (a^(n + 1) +  | 
|
206  | 
(\<Sum>k=1..n. of_nat (n choose (k - 1)) * a^k * b^(n + 1 - k)))"  | 
|
207  | 
using sum.nat_ivl_Suc' [of 1 n "\<lambda>k. of_nat (n choose (k-1)) * a ^ k * b ^ (n + 1 - k)"]  | 
|
208  | 
by (simp add: sum.atLeast_Suc_atMost atMost_atLeast0)  | 
|
| 63466 | 209  | 
also have "\<dots> = a^(n + 1) + b^(n + 1) +  | 
210  | 
(\<Sum>k=1..n. of_nat (n + 1 choose k) * a^k * b^(n + 1 - k))"  | 
|
| 64267 | 211  | 
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: 
67443 
diff
changeset
 | 
212  | 
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: 
67443 
diff
changeset
 | 
213  | 
using decomp by (simp add: atMost_atLeast0 field_simps)  | 
| 63466 | 214  | 
finally show ?case  | 
215  | 
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: 
58889 
diff
changeset
 | 
216  | 
qed  | 
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
217  | 
|
| 
79544
 
50ee2921da94
A few more new theorems taken from AFP entries
 
paulson <lp15@cam.ac.uk> 
parents: 
78667 
diff
changeset
 | 
218  | 
|
| 63466 | 219  | 
text \<open>Original version for the naturals.\<close>  | 
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
220  | 
corollary binomial: "(a + b :: nat)^n = (\<Sum>k\<le>n. (of_nat (n choose k)) * a^k * b^(n - k))"  | 
| 63466 | 221  | 
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: 
58889 
diff
changeset
 | 
222  | 
by (simp only: of_nat_add [symmetric] of_nat_mult [symmetric] of_nat_power [symmetric]  | 
| 64267 | 223  | 
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: 
58889 
diff
changeset
 | 
224  | 
|
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
225  | 
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: 
58889 
diff
changeset
 | 
226  | 
proof (induct n arbitrary: k rule: nat_less_induct)  | 
| 63466 | 227  | 
fix n k  | 
228  | 
assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) = fact m"  | 
|
229  | 
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: 
58889 
diff
changeset
 | 
230  | 
let ?ths = "fact k * fact (n - k) * (n choose k) = fact n"  | 
| 63466 | 231  | 
consider "n = 0 \<or> k = 0 \<or> n = k" | m h where "n = Suc m" "k = Suc h" "h < m"  | 
232  | 
using kn by atomize_elim presburger  | 
|
233  | 
then show "fact k * fact (n - k) * (n choose k) = fact n"  | 
|
234  | 
proof cases  | 
|
235  | 
case 1  | 
|
236  | 
with kn show ?thesis by auto  | 
|
237  | 
next  | 
|
238  | 
case 2  | 
|
239  | 
note n = \<open>n = Suc m\<close>  | 
|
240  | 
note k = \<open>k = Suc h\<close>  | 
|
241  | 
note hm = \<open>h < m\<close>  | 
|
242  | 
have mn: "m < n"  | 
|
243  | 
using n by arith  | 
|
244  | 
have hm': "h \<le> m"  | 
|
245  | 
using hm by arith  | 
|
246  | 
have km: "k \<le> m"  | 
|
247  | 
using hm k n kn by arith  | 
|
248  | 
have "m - h = Suc (m - Suc h)"  | 
|
249  | 
using k km hm by arith  | 
|
250  | 
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: 
58889 
diff
changeset
 | 
251  | 
by simp  | 
| 63466 | 252  | 
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: 
59658 
diff
changeset
 | 
253  | 
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: 
58889 
diff
changeset
 | 
254  | 
(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: 
58889 
diff
changeset
 | 
255  | 
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: 
58889 
diff
changeset
 | 
256  | 
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: 
58889 
diff
changeset
 | 
257  | 
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: 
58889 
diff
changeset
 | 
258  | 
by (simp add: field_simps)  | 
| 63466 | 259  | 
finally show ?thesis  | 
260  | 
using k n km by simp  | 
|
261  | 
qed  | 
|
| 
59658
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
262  | 
qed  | 
| 
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
263  | 
|
| 
63372
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
264  | 
lemma binomial_fact':  | 
| 
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
265  | 
assumes "k \<le> n"  | 
| 
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
266  | 
shows "n choose k = fact n div (fact k * fact (n - k))"  | 
| 
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
267  | 
using binomial_fact_lemma [OF assms]  | 
| 64240 | 268  | 
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: 
63367 
diff
changeset
 | 
269  | 
|
| 
59658
 
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
 
paulson <lp15@cam.ac.uk> 
parents: 
58889 
diff
changeset
 | 
270  | 
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: 
58889 
diff
changeset
 | 
271  | 
assumes kn: "k \<le> n"  | 
| 63466 | 272  | 
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: 
58889 
diff
changeset
 | 
273  | 
using binomial_fact_lemma[OF kn]  | 
| 71699 | 274  | 
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: 
58889 
diff
changeset
 | 
275  | 
|
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
276  | 
lemma fact_binomial:  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
277  | 
assumes "k \<le> n"  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
278  | 
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: 
63373 
diff
changeset
 | 
279  | 
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: 
63373 
diff
changeset
 | 
280  | 
|
| 79566 | 281  | 
lemma binomial_fact_pow: "(n choose s) * fact s \<le> n^s"  | 
282  | 
proof (cases "s \<le> n")  | 
|
283  | 
case True  | 
|
284  | 
then show ?thesis  | 
|
285  | 
by (smt (verit) binomial_fact_lemma mult.assoc mult.commute fact_div_fact_le_pow fact_nonzero nonzero_mult_div_cancel_right)  | 
|
286  | 
qed (simp add: binomial_eq_0)  | 
|
287  | 
||
| 63466 | 288  | 
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: 
63373 
diff
changeset
 | 
289  | 
proof (cases "n \<ge> 2")  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
290  | 
case False  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
291  | 
then have "n = 0 \<or> n = 1"  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
292  | 
by auto  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
293  | 
then show ?thesis by auto  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
294  | 
next  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
295  | 
case True  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
296  | 
define m where "m = n - 2"  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
297  | 
with True have "n = m + 2"  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
298  | 
by simp  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
299  | 
then have "fact n = n * (n - 1) * fact (n - 2)"  | 
| 64272 | 300  | 
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: 
63373 
diff
changeset
 | 
301  | 
with True show ?thesis  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
302  | 
by (simp add: binomial_fact')  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
303  | 
qed  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
304  | 
|
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
305  | 
lemma choose_row_sum: "(\<Sum>k\<le>n. n choose k) = 2^n"  | 
| 63466 | 306  | 
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: 
59658 
diff
changeset
 | 
307  | 
|
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
308  | 
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: 
59658 
diff
changeset
 | 
309  | 
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: 
59658 
diff
changeset
 | 
310  | 
|
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
311  | 
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: 
59658 
diff
changeset
 | 
312  | 
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: 
59658 
diff
changeset
 | 
313  | 
|
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
314  | 
lemma choose_alternating_sum:  | 
| 63466 | 315  | 
"n > 0 \<Longrightarrow> (\<Sum>i\<le>n. (-1)^i * of_nat (n choose i)) = (0 :: 'a::comm_ring_1)"  | 
316  | 
using binomial_ring[of "-1 :: 'a" 1 n]  | 
|
317  | 
by (simp add: atLeast0AtMost mult_of_nat_commute zero_power)  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
318  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
319  | 
lemma choose_even_sum:  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
320  | 
assumes "n > 0"  | 
| 63466 | 321  | 
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: 
62347 
diff
changeset
 | 
322  | 
proof -  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
323  | 
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: 
61076 
diff
changeset
 | 
324  | 
using choose_row_sum[of n]  | 
| 64267 | 325  | 
by (simp add: choose_alternating_sum assms atLeast0AtMost of_nat_sum[symmetric])  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
326  | 
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) + (-1) ^ i * of_nat (n choose i))"  | 
| 64267 | 327  | 
by (simp add: sum.distrib)  | 
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
328  | 
also have "\<dots> = 2 * (\<Sum>i\<le>n. if even i then of_nat (n choose i) else 0)"  | 
| 64267 | 329  | 
by (subst sum_distrib_left, intro sum.cong) simp_all  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
330  | 
finally show ?thesis ..  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
331  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
332  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
333  | 
lemma choose_odd_sum:  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
334  | 
assumes "n > 0"  | 
| 63466 | 335  | 
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: 
62347 
diff
changeset
 | 
336  | 
proof -  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
337  | 
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: 
61076 
diff
changeset
 | 
338  | 
using choose_row_sum[of n]  | 
| 64267 | 339  | 
by (simp add: choose_alternating_sum assms atLeast0AtMost of_nat_sum[symmetric])  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
340  | 
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) - (-1) ^ i * of_nat (n choose i))"  | 
| 64267 | 341  | 
by (simp add: sum_subtractf)  | 
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
342  | 
also have "\<dots> = 2 * (\<Sum>i\<le>n. if odd i then of_nat (n choose i) else 0)"  | 
| 64267 | 343  | 
by (subst sum_distrib_left, intro sum.cong) simp_all  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
344  | 
finally show ?thesis ..  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
345  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
346  | 
|
| 60758 | 347  | 
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: 
59658 
diff
changeset
 | 
348  | 
lemma sum_choose_diagonal:  | 
| 63466 | 349  | 
assumes "m \<le> n"  | 
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
350  | 
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: 
59658 
diff
changeset
 | 
351  | 
proof -  | 
| 
68077
 
ee8c13ae81e9
Some tidying up (mostly regarding summations from 0)
 
paulson <lp15@cam.ac.uk> 
parents: 
67443 
diff
changeset
 | 
352  | 
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: 
67399 
diff
changeset
 | 
353  | 
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: 
67443 
diff
changeset
 | 
354  | 
by (simp add: atMost_atLeast0)  | 
| 63466 | 355  | 
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: 
59658 
diff
changeset
 | 
356  | 
by (rule sum_choose_lower)  | 
| 63466 | 357  | 
also have "\<dots> = Suc n choose m"  | 
358  | 
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: 
59658 
diff
changeset
 | 
359  | 
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: 
59658 
diff
changeset
 | 
360  | 
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: 
59658 
diff
changeset
 | 
361  | 
|
| 63373 | 362  | 
|
| 
63372
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
363  | 
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: 
59658 
diff
changeset
 | 
364  | 
|
| 63466 | 365  | 
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: 
68786 
diff
changeset
 | 
366  | 
  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: 
63373 
diff
changeset
 | 
367  | 
|
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
368  | 
lemma gbinomial_0 [simp]:  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
369  | 
"a gchoose 0 = 1"  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
370  | 
"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: 
70097 
diff
changeset
 | 
371  | 
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: 
63366 
diff
changeset
 | 
372  | 
|
| 64272 | 373  | 
lemma gbinomial_Suc: "a gchoose (Suc k) = prod (\<lambda>i. a - of_nat i) {0..k} div fact (Suc k)"
 | 
374  | 
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: 
59658 
diff
changeset
 | 
375  | 
|
| 68786 | 376  | 
lemma gbinomial_1 [simp]: "a gchoose 1 = a"  | 
377  | 
by (simp add: gbinomial_prod_rev lessThan_Suc)  | 
|
378  | 
||
379  | 
lemma gbinomial_Suc0 [simp]: "a gchoose Suc 0 = a"  | 
|
380  | 
by (simp add: gbinomial_prod_rev lessThan_Suc)  | 
|
381  | 
||
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
382  | 
lemma gbinomial_mult_fact: "fact k * (a gchoose k) = (\<Prod>i = 0..<k. a - of_nat i)"  | 
| 63466 | 383  | 
for a :: "'a::field_char_0"  | 
| 64272 | 384  | 
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: 
63373 
diff
changeset
 | 
385  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
386  | 
lemma gbinomial_mult_fact': "(a gchoose k) * fact k = (\<Prod>i = 0..<k. a - of_nat i)"  | 
| 63466 | 387  | 
for a :: "'a::field_char_0"  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
388  | 
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: 
59658 
diff
changeset
 | 
389  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
390  | 
lemma gbinomial_pochhammer: "a gchoose k = (- 1) ^ k * pochhammer (- a) k / fact k"  | 
| 63466 | 391  | 
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: 
70097 
diff
changeset
 | 
392  | 
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: 
70097 
diff
changeset
 | 
393  | 
case (Suc k')  | 
| 71699 | 394  | 
then have "a gchoose k = pochhammer (a - of_nat k') (Suc k') / ((1 + of_nat k') * fact k')"  | 
395  | 
by (simp add: gbinomial_prod_rev pochhammer_prod_rev atLeastLessThanSuc_atLeastAtMost  | 
|
396  | 
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: 
70097 
diff
changeset
 | 
397  | 
then show ?thesis  | 
| 71699 | 398  | 
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: 
70097 
diff
changeset
 | 
399  | 
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: 
59658 
diff
changeset
 | 
400  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
401  | 
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: 
68786 
diff
changeset
 | 
402  | 
for a :: "'a::field_char_0"  | 
| 
61552
 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 
eberlm 
parents: 
61531 
diff
changeset
 | 
403  | 
proof -  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
404  | 
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: 
61531 
diff
changeset
 | 
405  | 
by (simp add: gbinomial_pochhammer pochhammer_minus mult_ac)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
406  | 
also have "(-1 :: 'a)^k * (-1)^k = 1"  | 
| 63466 | 407  | 
by (subst power_add [symmetric]) simp  | 
408  | 
finally show ?thesis  | 
|
409  | 
by simp  | 
|
| 
61552
 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 
eberlm 
parents: 
61531 
diff
changeset
 | 
410  | 
qed  | 
| 
 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 
eberlm 
parents: 
61531 
diff
changeset
 | 
411  | 
|
| 63466 | 412  | 
lemma gbinomial_binomial: "n gchoose k = n choose k"  | 
| 
63372
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
413  | 
proof (cases "k \<le> n")  | 
| 
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
414  | 
case False  | 
| 63466 | 415  | 
then have "n < k"  | 
416  | 
by (simp add: not_le)  | 
|
| 67399 | 417  | 
  then have "0 \<in> ((-) n) ` {0..<k}"
 | 
| 
63372
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
418  | 
by auto  | 
| 67399 | 419  | 
  then have "prod ((-) n) {0..<k} = 0"
 | 
| 64272 | 420  | 
by (auto intro: prod_zero)  | 
| 
63372
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
421  | 
with \<open>n < k\<close> show ?thesis  | 
| 64272 | 422  | 
by (simp add: binomial_eq_0 gbinomial_prod_rev prod_zero)  | 
| 
63372
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
423  | 
next  | 
| 
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
424  | 
case True  | 
| 67399 | 425  | 
  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: 
64272 
diff
changeset
 | 
426  | 
by (intro prod.reindex_bij_witness[of _ "\<lambda>i. n - i" "\<lambda>i. n - i"]) auto  | 
| 63466 | 427  | 
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: 
63367 
diff
changeset
 | 
428  | 
by (rule binomial_fact')  | 
| 
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
429  | 
with * show ?thesis  | 
| 64272 | 430  | 
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: 
63373 
diff
changeset
 | 
431  | 
qed  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
432  | 
|
| 63466 | 433  | 
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: 
63373 
diff
changeset
 | 
434  | 
proof (cases "k \<le> n")  | 
| 63466 | 435  | 
case False  | 
436  | 
then show ?thesis  | 
|
| 64272 | 437  | 
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: 
63373 
diff
changeset
 | 
438  | 
next  | 
| 63466 | 439  | 
case True  | 
440  | 
define m where "m = n - k"  | 
|
441  | 
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: 
63373 
diff
changeset
 | 
442  | 
by arith  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
443  | 
from n have "fact n = ((\<Prod>i = 0..<m + k. of_nat (m + k - i) ):: 'a)"  | 
| 64272 | 444  | 
by (simp add: fact_prod_rev)  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
445  | 
  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: 
63373 
diff
changeset
 | 
446  | 
by (simp add: ivl_disj_un)  | 
| 63466 | 447  | 
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: 
70097 
diff
changeset
 | 
448  | 
using prod.shift_bounds_nat_ivl [of "\<lambda>i. of_nat (m + k - i) :: 'a" 0 k m]  | 
| 64272 | 449  | 
by (simp add: fact_prod_rev [of m] prod.union_disjoint of_nat_diff)  | 
| 63466 | 450  | 
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: 
63373 
diff
changeset
 | 
451  | 
by (simp add: n)  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
452  | 
with True have "fact k * of_nat (n gchoose k) = (fact k * (of_nat n gchoose k) :: 'a)"  | 
| 63466 | 453  | 
by (simp only: gbinomial_mult_fact [of k "of_nat n"] gbinomial_binomial [of n k] fact_binomial)  | 
454  | 
then show ?thesis  | 
|
455  | 
by simp  | 
|
| 
63372
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
456  | 
qed  | 
| 
 
492b49535094
relating gbinomial and binomial, still using distinct definitions
 
haftmann 
parents: 
63367 
diff
changeset
 | 
457  | 
|
| 63466 | 458  | 
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: 
63373 
diff
changeset
 | 
459  | 
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: 
59658 
diff
changeset
 | 
460  | 
|
| 63466 | 461  | 
setup  | 
| 69593 | 462  | 
\<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: 
63367 
diff
changeset
 | 
463  | 
|
| 
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: 
59658 
diff
changeset
 | 
464  | 
lemma gbinomial_mult_1:  | 
| 63466 | 465  | 
fixes a :: "'a::field_char_0"  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
466  | 
shows "a * (a gchoose k) = of_nat k * (a gchoose k) + of_nat (Suc k) * (a gchoose (Suc k))"  | 
| 63466 | 467  | 
(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: 
59658 
diff
changeset
 | 
468  | 
proof -  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
469  | 
have "?r = ((- 1) ^k * pochhammer (- a) k / fact k) * (of_nat k - (- a + of_nat k))"  | 
| 71699 | 470  | 
unfolding gbinomial_pochhammer pochhammer_Suc right_diff_distrib power_Suc  | 
471  | 
by (auto simp add: field_simps simp del: of_nat_Suc)  | 
|
| 63466 | 472  | 
also have "\<dots> = ?l"  | 
473  | 
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: 
59658 
diff
changeset
 | 
474  | 
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: 
59658 
diff
changeset
 | 
475  | 
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: 
59658 
diff
changeset
 | 
476  | 
|
| 
 
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: 
59658 
diff
changeset
 | 
477  | 
lemma gbinomial_mult_1':  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
478  | 
"(a gchoose k) * a = of_nat k * (a gchoose k) + of_nat (Suc k) * (a gchoose (Suc k))"  | 
| 63466 | 479  | 
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: 
59658 
diff
changeset
 | 
480  | 
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: 
59658 
diff
changeset
 | 
481  | 
|
| 63466 | 482  | 
lemma gbinomial_Suc_Suc: "(a + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))"  | 
483  | 
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: 
59658 
diff
changeset
 | 
484  | 
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: 
59658 
diff
changeset
 | 
485  | 
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: 
59658 
diff
changeset
 | 
486  | 
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: 
59658 
diff
changeset
 | 
487  | 
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: 
59658 
diff
changeset
 | 
488  | 
case (Suc h)  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
489  | 
  have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)"
 | 
| 71699 | 490  | 
proof (rule prod.reindex_cong)  | 
491  | 
    show "{1..k} = Suc ` {0..h}"
 | 
|
492  | 
using Suc by (auto simp add: image_Suc_atMost)  | 
|
493  | 
qed auto  | 
|
| 
59730
 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 
paulson <lp15@cam.ac.uk> 
parents: 
59669 
diff
changeset
 | 
494  | 
have "fact (Suc k) * (a gchoose k + (a gchoose (Suc k))) =  | 
| 63466 | 495  | 
(a gchoose Suc h) * (fact (Suc (Suc h))) +  | 
496  | 
(a gchoose Suc (Suc h)) * (fact (Suc (Suc h)))"  | 
|
| 
63367
 
6c731c8b7f03
simplified definitions of combinatorial functions
 
haftmann 
parents: 
63366 
diff
changeset
 | 
497  | 
by (simp add: Suc field_simps del: fact_Suc)  | 
| 63466 | 498  | 
also have "\<dots> =  | 
499  | 
(a gchoose Suc h) * of_nat (Suc (Suc h) * fact (Suc h)) + (\<Prod>i=0..Suc h. a - of_nat i)"  | 
|
| 71699 | 500  | 
apply (simp only: gbinomial_mult_fact field_simps mult.left_commute [of _ "2"])  | 
| 63466 | 501  | 
apply (simp del: fact_Suc add: fact_Suc [of "Suc h"] field_simps gbinomial_mult_fact  | 
502  | 
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: 
63373 
diff
changeset
 | 
503  | 
done  | 
| 63466 | 504  | 
also have "\<dots> =  | 
505  | 
(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: 
63366 
diff
changeset
 | 
506  | 
by (simp only: fact_Suc mult.commute mult.left_commute of_nat_fact of_nat_id of_nat_mult)  | 
| 63466 | 507  | 
also have "\<dots> =  | 
508  | 
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: 
63373 
diff
changeset
 | 
509  | 
unfolding gbinomial_mult_fact atLeastLessThanSuc_atLeastAtMost by auto  | 
| 63466 | 510  | 
also have "\<dots> =  | 
511  | 
(\<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: 
59669 
diff
changeset
 | 
512  | 
by (simp add: field_simps)  | 
| 63466 | 513  | 
also have "\<dots> =  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
514  | 
    ((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: 
59658 
diff
changeset
 | 
515  | 
unfolding gbinomial_mult_fact'  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
516  | 
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: 
63373 
diff
changeset
 | 
517  | 
  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: 
63373 
diff
changeset
 | 
518  | 
unfolding gbinomial_mult_fact' atLeast0_atMost_Suc  | 
| 
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
519  | 
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: 
63373 
diff
changeset
 | 
520  | 
  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: 
63373 
diff
changeset
 | 
521  | 
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: 
70097 
diff
changeset
 | 
522  | 
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: 
59669 
diff
changeset
 | 
523  | 
also have "\<dots> = (fact (Suc k)) * ((a + 1) gchoose (Suc k))"  | 
| 63466 | 524  | 
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: 
59669 
diff
changeset
 | 
525  | 
finally show ?thesis  | 
| 
63417
 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 
haftmann 
parents: 
63373 
diff
changeset
 | 
526  | 
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: 
59658 
diff
changeset
 | 
527  | 
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: 
59658 
diff
changeset
 | 
528  | 
|
| 63466 | 529  | 
lemma gbinomial_reduce_nat: "0 < k \<Longrightarrow> a gchoose k = (a - 1) gchoose (k - 1) + ((a - 1) gchoose k)"  | 
530  | 
for a :: "'a::field_char_0"  | 
|
| 
59730
 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 
paulson <lp15@cam.ac.uk> 
parents: 
59669 
diff
changeset
 | 
531  | 
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: 
59658 
diff
changeset
 | 
532  | 
|
| 
60141
 
833adf7db7d8
New material, mostly about limits. Consolidation.
 
paulson <lp15@cam.ac.uk> 
parents: 
59867 
diff
changeset
 | 
533  | 
lemma gchoose_row_sum_weighted:  | 
| 63466 | 534  | 
"(\<Sum>k = 0..m. (r gchoose k) * (r/2 - of_nat k)) = of_nat(Suc m) / 2 * (r gchoose (Suc m))"  | 
535  | 
for r :: "'a::field_char_0"  | 
|
536  | 
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: 
59658 
diff
changeset
 | 
537  | 
|
| 
 
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: 
59658 
diff
changeset
 | 
538  | 
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: 
59658 
diff
changeset
 | 
539  | 
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: 
59658 
diff
changeset
 | 
540  | 
shows "n choose k = n choose (n - k)"  | 
| 63466 | 541  | 
proof -  | 
542  | 
have kn': "n - k \<le> n"  | 
|
543  | 
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: 
59658 
diff
changeset
 | 
544  | 
from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn']  | 
| 63466 | 545  | 
have "fact k * fact (n - k) * (n choose k) = fact (n - k) * fact (n - (n - k)) * (n choose (n - k))"  | 
546  | 
by simp  | 
|
547  | 
then show ?thesis  | 
|
548  | 
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: 
59658 
diff
changeset
 | 
549  | 
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: 
59658 
diff
changeset
 | 
550  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
551  | 
lemma choose_rising_sum:  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
552  | 
"(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose (n + 1))"  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
553  | 
"(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose m)"  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
554  | 
proof -  | 
| 63466 | 555  | 
show "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose (n + 1))"  | 
556  | 
by (induct m) simp_all  | 
|
557  | 
also have "\<dots> = (n + m + 1) choose m"  | 
|
558  | 
by (subst binomial_symmetric) simp_all  | 
|
559  | 
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: 
61076 
diff
changeset
 | 
560  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
561  | 
|
| 63466 | 562  | 
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: 
61076 
diff
changeset
 | 
563  | 
proof (cases n)  | 
| 63466 | 564  | 
case 0  | 
565  | 
then show ?thesis by simp  | 
|
566  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
567  | 
case (Suc m)  | 
| 63466 | 568  | 
have "(\<Sum>i\<le>n. i * (n choose i)) = (\<Sum>i\<le>Suc m. i * (Suc m choose i))"  | 
569  | 
by (simp add: Suc)  | 
|
570  | 
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: 
70097 
diff
changeset
 | 
571  | 
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: 
67443 
diff
changeset
 | 
572  | 
by (simp add: choose_row_sum)  | 
| 63466 | 573  | 
finally show ?thesis  | 
574  | 
using Suc by simp  | 
|
575  | 
qed  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
576  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
577  | 
lemma choose_alternating_linear_sum:  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
578  | 
assumes "n \<noteq> 1"  | 
| 63466 | 579  | 
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: 
61076 
diff
changeset
 | 
580  | 
proof (cases n)  | 
| 63466 | 581  | 
case 0  | 
582  | 
then show ?thesis by simp  | 
|
583  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
584  | 
case (Suc m)  | 
| 63466 | 585  | 
with assms have "m > 0"  | 
586  | 
by simp  | 
|
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
587  | 
have "(\<Sum>i\<le>n. (-1) ^ i * of_nat i * of_nat (n choose i) :: 'a) =  | 
| 63466 | 588  | 
(\<Sum>i\<le>Suc m. (-1) ^ i * of_nat i * of_nat (Suc m choose i))"  | 
589  | 
by (simp add: Suc)  | 
|
590  | 
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: 
70097 
diff
changeset
 | 
591  | 
by (simp only: sum.atMost_Suc_shift sum_distrib_left[symmetric] mult_ac of_nat_mult) simp  | 
| 63466 | 592  | 
also have "\<dots> = - of_nat (Suc m) * (\<Sum>i\<le>m. (-1) ^ i * of_nat (m choose i))"  | 
| 64267 | 593  | 
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: 
63363 
diff
changeset
 | 
594  | 
(simp add: algebra_simps)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
595  | 
also have "(\<Sum>i\<le>m. (-1 :: 'a) ^ i * of_nat ((m choose i))) = 0"  | 
| 61799 | 596  | 
using choose_alternating_sum[OF \<open>m > 0\<close>] by simp  | 
| 63466 | 597  | 
finally show ?thesis  | 
598  | 
by simp  | 
|
599  | 
qed  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
600  | 
|
| 63466 | 601  | 
lemma vandermonde: "(\<Sum>k\<le>r. (m choose k) * (n choose (r - k))) = (m + n) choose r"  | 
602  | 
proof (induct n arbitrary: r)  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
603  | 
case 0  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
604  | 
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 | 605  | 
by (intro sum.cong) simp_all  | 
| 63466 | 606  | 
also have "\<dots> = m choose r"  | 
| 68784 | 607  | 
by simp  | 
| 63466 | 608  | 
finally show ?case  | 
609  | 
by simp  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
610  | 
next  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
611  | 
case (Suc n r)  | 
| 63466 | 612  | 
show ?case  | 
| 64267 | 613  | 
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: 
61076 
diff
changeset
 | 
614  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
615  | 
|
| 63466 | 616  | 
lemma choose_square_sum: "(\<Sum>k\<le>n. (n choose k)^2) = ((2*n) choose n)"  | 
617  | 
using vandermonde[of n n n]  | 
|
618  | 
by (simp add: power2_eq_square mult_2 binomial_symmetric [symmetric])  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
619  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
620  | 
lemma pochhammer_binomial_sum:  | 
| 63466 | 621  | 
fixes a b :: "'a::comm_ring_1"  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
622  | 
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: 
61076 
diff
changeset
 | 
623  | 
proof (induction n arbitrary: a b)  | 
| 63466 | 624  | 
case 0  | 
625  | 
then show ?case by simp  | 
|
626  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
627  | 
case (Suc n a b)  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
628  | 
have "(\<Sum>k\<le>Suc n. of_nat (Suc n choose k) * pochhammer a k * pochhammer b (Suc n - k)) =  | 
| 63466 | 629  | 
(\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) +  | 
630  | 
((\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) +  | 
|
631  | 
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: 
70097 
diff
changeset
 | 
632  | 
by (subst sum.atMost_Suc_shift) (simp add: ring_distribs sum.distrib)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
633  | 
also have "(\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) =  | 
| 63466 | 634  | 
a * pochhammer ((a + 1) + b) n"  | 
| 64267 | 635  | 
by (subst Suc) (simp add: sum_distrib_left pochhammer_rec mult_ac)  | 
| 63466 | 636  | 
also have "(\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) +  | 
637  | 
pochhammer b (Suc n) =  | 
|
638  | 
(\<Sum>i=0..Suc n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))"  | 
|
| 71699 | 639  | 
apply (subst sum.atLeast_Suc_atMost, simp)  | 
640  | 
apply (simp add: sum.shift_bounds_cl_Suc_ivl atLeast0AtMost del: sum.cl_ivl_Suc)  | 
|
| 63466 | 641  | 
done  | 
642  | 
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))"  | 
|
| 64267 | 643  | 
using Suc by (intro sum.mono_neutral_right) (auto simp: not_le binomial_eq_0)  | 
| 63466 | 644  | 
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc (n - i)))"  | 
| 64267 | 645  | 
by (intro sum.cong) (simp_all add: Suc_diff_le)  | 
| 63466 | 646  | 
also have "\<dots> = b * pochhammer (a + (b + 1)) n"  | 
| 64267 | 647  | 
by (subst Suc) (simp add: sum_distrib_left mult_ac pochhammer_rec)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
648  | 
also have "a * pochhammer ((a + 1) + b) n + b * pochhammer (a + (b + 1)) n =  | 
| 63466 | 649  | 
pochhammer (a + b) (Suc n)"  | 
650  | 
by (simp add: pochhammer_rec algebra_simps)  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
651  | 
finally show ?case ..  | 
| 63466 | 652  | 
qed  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
653  | 
|
| 63466 | 654  | 
text \<open>Contributed by Manuel Eberl, generalised by LCP.  | 
| 69593 | 655  | 
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: 
68786 
diff
changeset
 | 
656  | 
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: 
68786 
diff
changeset
 | 
657  | 
for k :: nat and a :: "'a::field_char_0"  | 
| 64272 | 658  | 
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: 
59658 
diff
changeset
 | 
659  | 
|
| 
 
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: 
59658 
diff
changeset
 | 
660  | 
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: 
59658 
diff
changeset
 | 
661  | 
fixes k :: nat  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
662  | 
and a :: "'a::linordered_field"  | 
| 
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
663  | 
assumes "of_nat k \<le> a"  | 
| 
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
664  | 
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: 
59658 
diff
changeset
 | 
665  | 
proof -  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
666  | 
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: 
59658 
diff
changeset
 | 
667  | 
using assms of_nat_0_le_iff order_trans by blast  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
668  | 
have "(a / of_nat k :: 'a) ^ k = (\<Prod>i = 0..<k. a / of_nat k :: 'a)"  | 
| 68784 | 669  | 
by simp  | 
| 71699 | 670  | 
also have "\<dots> \<le> a gchoose k"  | 
671  | 
proof -  | 
|
672  | 
have "\<And>i. i < k \<Longrightarrow> 0 \<le> a / of_nat k"  | 
|
673  | 
by (simp add: x zero_le_divide_iff)  | 
|
674  | 
moreover have "a / of_nat k \<le> (a - of_nat i) / of_nat (k - i)" if "i < k" for i  | 
|
| 63466 | 675  | 
proof -  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
676  | 
from assms have "a * of_nat i \<ge> of_nat (i * k)"  | 
| 63466 | 677  | 
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: 
68786 
diff
changeset
 | 
678  | 
then have "a * of_nat k - a * of_nat i \<le> a * of_nat k - of_nat (i * k)"  | 
| 63466 | 679  | 
by arith  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
680  | 
then have "a * of_nat (k - i) \<le> (a - of_nat i) * of_nat k"  | 
| 63466 | 681  | 
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: 
68786 
diff
changeset
 | 
682  | 
then have "a * of_nat (k - i) \<le> (a - of_nat i) * (of_nat k :: 'a)"  | 
| 71699 | 683  | 
by blast  | 
| 63466 | 684  | 
with assms show ?thesis  | 
685  | 
using \<open>i < k\<close> by (simp add: field_simps)  | 
|
686  | 
qed  | 
|
| 71699 | 687  | 
ultimately show ?thesis  | 
688  | 
unfolding gbinomial_altdef_of_nat  | 
|
689  | 
by (intro prod_mono) auto  | 
|
690  | 
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: 
59658 
diff
changeset
 | 
691  | 
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: 
59658 
diff
changeset
 | 
692  | 
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: 
59658 
diff
changeset
 | 
693  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
694  | 
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: 
61076 
diff
changeset
 | 
695  | 
by (simp add: gbinomial_pochhammer pochhammer_minus algebra_simps)  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
696  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
697  | 
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: 
61076 
diff
changeset
 | 
698  | 
by (subst gbinomial_negated_upper) (simp add: add_ac)  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
699  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
700  | 
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: 
68786 
diff
changeset
 | 
701  | 
proof (cases k)  | 
| 63466 | 702  | 
case 0  | 
703  | 
then show ?thesis by simp  | 
|
704  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
705  | 
case (Suc b)  | 
| 63466 | 706  | 
then have "((a + 1) gchoose (Suc (Suc b))) = (\<Prod>i = 0..Suc b. a + (1 - of_nat i)) / fact (b + 2)"  | 
| 64272 | 707  | 
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: 
63373 
diff
changeset
 | 
708  | 
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: 
70097 
diff
changeset
 | 
709  | 
by (simp add: prod.atLeast0_atMost_Suc_shift del: prod.cl_ivl_Suc)  | 
| 63466 | 710  | 
also have "\<dots> / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)"  | 
| 64272 | 711  | 
by (simp_all add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
712  | 
finally show ?thesis by (simp add: Suc field_simps del: of_nat_Suc)  | 
| 63466 | 713  | 
qed  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
714  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
715  | 
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: 
68786 
diff
changeset
 | 
716  | 
proof (cases k)  | 
| 63466 | 717  | 
case 0  | 
718  | 
then show ?thesis by simp  | 
|
719  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
720  | 
case (Suc b)  | 
| 63466 | 721  | 
then have "((a + 1) gchoose (Suc (Suc b))) = (\<Prod>i = 0 .. Suc b. a + (1 - of_nat i)) / fact (b + 2)"  | 
| 64272 | 722  | 
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: 
63373 
diff
changeset
 | 
723  | 
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: 
70097 
diff
changeset
 | 
724  | 
by (simp add: prod.atLeast0_atMost_Suc_shift del: prod.cl_ivl_Suc)  | 
| 63466 | 725  | 
also have "\<dots> / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)"  | 
| 64272 | 726  | 
by (simp_all add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost atLeast0AtMost)  | 
| 63466 | 727  | 
finally show ?thesis  | 
728  | 
by (simp add: Suc)  | 
|
729  | 
qed  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
730  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
731  | 
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: 
68786 
diff
changeset
 | 
732  | 
using gbinomial_mult_1[of a k]  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
733  | 
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: 
61076 
diff
changeset
 | 
734  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
735  | 
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: 
61076 
diff
changeset
 | 
736  | 
using binomial_symmetric[of k n] by (simp add: binomial_gbinomial [symmetric])  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
737  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
738  | 
|
| 77172 | 739  | 
text \<open>The absorption identity (equation 5.5 \<^cite>\<open>\<open>p.~157\<close> in GKP_CM\<close>):  | 
| 63466 | 740  | 
\[  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
741  | 
{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: 
61076 
diff
changeset
 | 
742  | 
\]\<close>  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
743  | 
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: 
68786 
diff
changeset
 | 
744  | 
using gbinomial_rec[of "a - 1" "k - 1"]  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
745  | 
by (simp_all add: gbinomial_rec field_simps del: of_nat_Suc)  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
746  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
747  | 
text \<open>The absorption identity is written in the following form to avoid  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
748  | 
division by $k$ (the lower index) and therefore remove the $k \neq 0$  | 
| 77172 | 749  | 
restriction \<^cite>\<open>\<open>p.~157\<close> in GKP_CM\<close>:  | 
| 63466 | 750  | 
\[  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
751  | 
k{r \choose k} = r{r - 1 \choose k - 1}, \quad \textnormal{integer } k.
 | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
752  | 
\]\<close>  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
753  | 
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: 
68786 
diff
changeset
 | 
754  | 
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: 
61076 
diff
changeset
 | 
755  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
756  | 
text \<open>The absorption identity for natural number binomial coefficients:\<close>  | 
| 63466 | 757  | 
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: 
61076 
diff
changeset
 | 
758  | 
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: 
61076 
diff
changeset
 | 
759  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
760  | 
text \<open>The absorption companion identity for natural number coefficients,  | 
| 77172 | 761  | 
following the proof by GKP \<^cite>\<open>\<open>p.~157\<close> in GKP_CM\<close>:\<close>  | 
| 63466 | 762  | 
lemma binomial_absorb_comp: "(n - k) * (n choose k) = n * ((n - 1) choose k)"  | 
763  | 
(is "?lhs = ?rhs")  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
764  | 
proof (cases "n \<le> k")  | 
| 63466 | 765  | 
case True  | 
766  | 
then show ?thesis by auto  | 
|
767  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
768  | 
case False  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
769  | 
then have "?rhs = Suc ((n - 1) - k) * (n choose Suc ((n - 1) - k))"  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
770  | 
using binomial_symmetric[of k "n - 1"] binomial_absorption[of "(n - 1) - k" n]  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
771  | 
by simp  | 
| 63466 | 772  | 
also have "Suc ((n - 1) - k) = n - k"  | 
773  | 
using False by simp  | 
|
774  | 
also have "n choose \<dots> = n choose k"  | 
|
775  | 
using False by (intro binomial_symmetric [symmetric]) simp_all  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
776  | 
finally show ?thesis ..  | 
| 63466 | 777  | 
qed  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
778  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
779  | 
text \<open>The generalised absorption companion identity:\<close>  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
780  | 
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: 
68786 
diff
changeset
 | 
781  | 
using pochhammer_absorb_comp[of a k] by (simp add: gbinomial_pochhammer)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
782  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
783  | 
lemma gbinomial_addition_formula:  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
784  | 
"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: 
68786 
diff
changeset
 | 
785  | 
using gbinomial_Suc_Suc[of "a - 1" k] by (simp add: algebra_simps)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
786  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
787  | 
lemma binomial_addition_formula:  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
788  | 
"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: 
61076 
diff
changeset
 | 
789  | 
by (subst choose_reduce_nat) simp_all  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
790  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
791  | 
text \<open>  | 
| 77172 | 792  | 
Equation 5.9 of the reference material \<^cite>\<open>\<open>p.~159\<close> in GKP_CM\<close> is a useful  | 
| 63466 | 793  | 
summation formula, operating on both indices:  | 
794  | 
\[  | 
|
795  | 
   \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: 
61076 
diff
changeset
 | 
796  | 
   \quad \textnormal{integer } n.
 | 
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
797  | 
\]  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
798  | 
\<close>  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
799  | 
lemma gbinomial_parallel_sum: "(\<Sum>k\<le>n. (a + of_nat k) gchoose k) = (a + of_nat n + 1) gchoose n"  | 
| 63466 | 800  | 
proof (induct n)  | 
801  | 
case 0  | 
|
802  | 
then show ?case by simp  | 
|
803  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
804  | 
case (Suc m)  | 
| 63466 | 805  | 
then show ?case  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
806  | 
using gbinomial_Suc_Suc[of "(a + of_nat m + 1)" m]  | 
| 63466 | 807  | 
by (simp add: add_ac)  | 
808  | 
qed  | 
|
809  | 
||
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
810  | 
|
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
811  | 
subsection \<open>Summation on the upper index\<close>  | 
| 63466 | 812  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
813  | 
text \<open>  | 
| 77172 | 814  | 
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: 
62347 
diff
changeset
 | 
815  | 
  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: 
61076 
diff
changeset
 | 
816  | 
  {n + 1 \choose m + 1}, \quad \textnormal{integers } m, n \geq 0.\]
 | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
817  | 
\<close>  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
818  | 
lemma gbinomial_sum_up_index:  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
819  | 
"(\<Sum>j = 0..n. (of_nat j gchoose k) :: 'a::field_char_0) = (of_nat n + 1) gchoose (k + 1)"  | 
| 63466 | 820  | 
proof (induct n)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
821  | 
case 0  | 
| 63466 | 822  | 
show ?case  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
823  | 
using gbinomial_Suc_Suc[of 0 k]  | 
| 
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
824  | 
by (cases k) auto  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
825  | 
next  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
826  | 
case (Suc n)  | 
| 63466 | 827  | 
then show ?case  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
828  | 
using gbinomial_Suc_Suc[of "of_nat (Suc n) :: 'a" k]  | 
| 63466 | 829  | 
by (simp add: add_ac)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
830  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
831  | 
|
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
832  | 
lemma gbinomial_index_swap:  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
833  | 
"((-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: 
61076 
diff
changeset
 | 
834  | 
(is "?lhs = ?rhs")  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
835  | 
proof -  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
836  | 
have "?lhs = (of_nat (k + n) gchoose k)"  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
837  | 
by (subst gbinomial_negated_upper) (simp add: power_mult_distrib [symmetric])  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
838  | 
also have "\<dots> = (of_nat (k + n) gchoose n)"  | 
| 63466 | 839  | 
by (subst gbinomial_of_nat_symmetric) simp_all  | 
840  | 
also have "\<dots> = ?rhs"  | 
|
841  | 
by (subst gbinomial_negated_upper) simp  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
842  | 
finally show ?thesis .  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
843  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
844  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
845  | 
lemma gbinomial_sum_lower_neg: "(\<Sum>k\<le>m. (a gchoose k) * (- 1) ^ k) = (- 1) ^ m * (a - 1 gchoose m)"  | 
| 63466 | 846  | 
(is "?lhs = ?rhs")  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
847  | 
proof -  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
848  | 
have "?lhs = (\<Sum>k\<le>m. -(a + 1) + of_nat k gchoose k)"  | 
| 64267 | 849  | 
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: 
68786 
diff
changeset
 | 
850  | 
also have "\<dots> = - a + of_nat m gchoose m"  | 
| 63466 | 851  | 
by (subst gbinomial_parallel_sum) simp  | 
852  | 
also have "\<dots> = ?rhs"  | 
|
853  | 
by (subst gbinomial_negated_upper) (simp add: power_mult_distrib)  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
854  | 
finally show ?thesis .  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
855  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
856  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
857  | 
lemma gbinomial_partial_row_sum:  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
858  | 
"(\<Sum>k\<le>m. (a gchoose k) * ((a / 2) - of_nat k)) = ((of_nat m + 1)/2) * (a gchoose (m + 1))"  | 
| 63466 | 859  | 
proof (induct m)  | 
860  | 
case 0  | 
|
861  | 
then show ?case by simp  | 
|
862  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
863  | 
case (Suc mm)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
864  | 
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: 
68786 
diff
changeset
 | 
865  | 
(a - of_nat (Suc mm)) * (a gchoose Suc mm) / 2"  | 
| 63466 | 866  | 
by (simp add: field_simps)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
867  | 
also have "\<dots> = a * (a - 1 gchoose Suc mm) / 2"  | 
| 63466 | 868  | 
by (subst gbinomial_absorb_comp) (rule refl)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
869  | 
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: 
61076 
diff
changeset
 | 
870  | 
by (subst gbinomial_absorption [symmetric]) simp  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
871  | 
finally show ?case .  | 
| 63466 | 872  | 
qed  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
873  | 
|
| 64267 | 874  | 
lemma sum_bounds_lt_plus1: "(\<Sum>k<mm. f (Suc k)) = (\<Sum>k=1..mm. f k)"  | 
| 63466 | 875  | 
by (induct mm) simp_all  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
876  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
877  | 
lemma gbinomial_partial_sum_poly:  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
878  | 
"(\<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: 
68786 
diff
changeset
 | 
879  | 
(\<Sum>k\<le>m. (-a gchoose k) * (-x)^k * (x + y)^(m-k))"  | 
| 63466 | 880  | 
(is "?lhs m = ?rhs m")  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
881  | 
proof (induction m)  | 
| 63466 | 882  | 
case 0  | 
883  | 
then show ?case by simp  | 
|
884  | 
next  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
885  | 
case (Suc mm)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
886  | 
define G where "G i k = (of_nat i + a gchoose k) * x^k * y^(i - k)" for i k  | 
| 63040 | 887  | 
define S where "S = ?lhs"  | 
| 63466 | 888  | 
have SG_def: "S = (\<lambda>i. (\<Sum>k\<le>i. (G i k)))"  | 
889  | 
unfolding S_def G_def ..  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
890  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
891  | 
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: 
69768 
diff
changeset
 | 
892  | 
using SG_def by (simp add: sum.atLeast_Suc_atMost atLeast0AtMost [symmetric])  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
893  | 
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: 
70097 
diff
changeset
 | 
894  | 
by (subst sum.shift_bounds_cl_Suc_ivl) simp  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
895  | 
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: 
68786 
diff
changeset
 | 
896  | 
(of_nat mm + a gchoose k)) * x^(Suc k) * y^(mm - k))"  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
897  | 
unfolding G_def by (subst gbinomial_addition_formula) simp  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
898  | 
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: 
68786 
diff
changeset
 | 
899  | 
(\<Sum>k=0..mm. (of_nat mm + a gchoose k) * x^(Suc k) * y^(mm - k))"  | 
| 64267 | 900  | 
by (subst sum.distrib [symmetric]) (simp add: algebra_simps)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
901  | 
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: 
68786 
diff
changeset
 | 
902  | 
(\<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: 
61076 
diff
changeset
 | 
903  | 
by (simp only: atLeast0AtMost lessThan_Suc_atMost)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
904  | 
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: 
68786 
diff
changeset
 | 
905  | 
(of_nat mm + a gchoose (Suc mm)) * x^(Suc mm)"  | 
| 63466 | 906  | 
(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: 
69768 
diff
changeset
 | 
907  | 
by (subst sum.lessThan_Suc) simp  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
908  | 
also have "?A = (\<Sum>k=1..mm. (of_nat mm + a gchoose k) * x^k * y^(mm - k + 1))"  | 
| 64267 | 909  | 
proof (subst sum_bounds_lt_plus1 [symmetric], intro sum.cong[OF refl], clarify)  | 
| 63466 | 910  | 
fix k  | 
911  | 
assume "k < mm"  | 
|
912  | 
then have "mm - k = mm - Suc k + 1"  | 
|
913  | 
by linarith  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
914  | 
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: 
68786 
diff
changeset
 | 
915  | 
(of_nat mm + a gchoose Suc k) * x ^ Suc k * y ^ (mm - Suc k + 1)"  | 
| 63466 | 916  | 
by (simp only:)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
917  | 
qed  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
918  | 
also have "\<dots> + ?B = y * (\<Sum>k=1..mm. (G mm k)) + (of_nat mm + a gchoose (Suc mm)) * x^(Suc mm)"  | 
| 64267 | 919  | 
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: 
68786 
diff
changeset
 | 
920  | 
also have "(\<Sum>k=0..mm. (of_nat mm + a gchoose k) * x^(Suc k) * y^(mm - k)) = x * (S mm)"  | 
| 64267 | 921  | 
unfolding S_def by (subst sum_distrib_left) (simp add: atLeast0AtMost algebra_simps)  | 
| 63466 | 922  | 
also have "(G (Suc mm) 0) = y * (G mm 0)"  | 
923  | 
by (simp add: G_def)  | 
|
924  | 
finally have "S (Suc mm) =  | 
|
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
925  | 
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: 
61076 
diff
changeset
 | 
926  | 
by (simp add: ring_distribs)  | 
| 63466 | 927  | 
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: 
69768 
diff
changeset
 | 
928  | 
by (simp add: sum.atLeast_Suc_atMost[symmetric] SG_def atLeast0AtMost)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
929  | 
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: 
61076 
diff
changeset
 | 
930  | 
by (simp add: algebra_simps)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
931  | 
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: 
61076 
diff
changeset
 | 
932  | 
by (subst gbinomial_negated_upper) simp  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
933  | 
also have "(-1) ^ Suc mm * (- a gchoose Suc mm) * x ^ Suc mm =  | 
| 
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
934  | 
(- a gchoose (Suc mm)) * (-x) ^ Suc mm"  | 
| 63466 | 935  | 
by (simp add: power_minus[of x])  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
936  | 
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: 
61076 
diff
changeset
 | 
937  | 
unfolding S_def by (subst Suc.IH) simp  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
938  | 
also have "(x + y) * ?rhs mm = (\<Sum>n\<le>mm. ((- a gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n)))"  | 
| 64267 | 939  | 
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: 
68786 
diff
changeset
 | 
940  | 
also have "\<dots> + (-a gchoose (Suc mm)) * (-x)^Suc mm =  | 
| 
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
941  | 
(\<Sum>n\<le>Suc mm. (- a gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n))"  | 
| 63466 | 942  | 
by simp  | 
943  | 
finally show ?case  | 
|
944  | 
by (simp only: S_def)  | 
|
945  | 
qed  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
946  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
947  | 
lemma gbinomial_partial_sum_poly_xpos:  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
948  | 
"(\<Sum>k\<le>m. (of_nat m + a gchoose k) * x^k * y^(m-k)) =  | 
| 71699 | 949  | 
(\<Sum>k\<le>m. (of_nat k + a - 1 gchoose k) * x^k * (x + y)^(m-k))" (is "?lhs = ?rhs")  | 
950  | 
proof -  | 
|
951  | 
have "?lhs = (\<Sum>k\<le>m. (- a gchoose k) * (- x) ^ k * (x + y) ^ (m - k))"  | 
|
952  | 
by (simp add: gbinomial_partial_sum_poly)  | 
|
953  | 
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: 
72302 
diff
changeset
 | 
954  | 
by (metis (no_types, opaque_lifting) gbinomial_negated_upper)  | 
| 71699 | 955  | 
also have "... = ?rhs"  | 
956  | 
by (intro sum.cong) (auto simp flip: power_mult_distrib)  | 
|
957  | 
finally show ?thesis .  | 
|
958  | 
qed  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
959  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
960  | 
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: 
61076 
diff
changeset
 | 
961  | 
proof -  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
962  | 
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: 
67443 
diff
changeset
 | 
963  | 
using choose_row_sum[where n="2 * m + 1"] by (simp add: atMost_atLeast0)  | 
| 63466 | 964  | 
also have "(\<Sum>k = 0..(2 * m + 1). (2 * m + 1 choose k)) =  | 
965  | 
(\<Sum>k = 0..m. (2 * m + 1 choose k)) +  | 
|
966  | 
(\<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: 
70097 
diff
changeset
 | 
967  | 
using sum.ub_add_nat[of 0 m "\<lambda>k. 2 * m + 1 choose k" "m+1"]  | 
| 63466 | 968  | 
by (simp add: mult_2)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
969  | 
also have "(\<Sum>k = m+1..2*m+1. (2 * m + 1 choose k)) =  | 
| 63466 | 970  | 
(\<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: 
70097 
diff
changeset
 | 
971  | 
by (subst sum.shift_bounds_cl_nat_ivl [symmetric]) (simp add: mult_2)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
972  | 
also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose (m - k)))"  | 
| 64267 | 973  | 
by (intro sum.cong[OF refl], subst binomial_symmetric) simp_all  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
974  | 
also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose k))"  | 
| 
67411
 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 
haftmann 
parents: 
67399 
diff
changeset
 | 
975  | 
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: 
63373 
diff
changeset
 | 
976  | 
by simp  | 
| 63466 | 977  | 
also have "\<dots> + \<dots> = 2 * \<dots>"  | 
978  | 
by simp  | 
|
979  | 
finally show ?thesis  | 
|
980  | 
by (subst (asm) mult_cancel1) (simp add: atLeast0AtMost)  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
981  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
982  | 
|
| 63466 | 983  | 
lemma gbinomial_r_part_sum: "(\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k)) = 2 ^ (2 * m)"  | 
984  | 
(is "?lhs = ?rhs")  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
985  | 
proof -  | 
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
986  | 
have "?lhs = of_nat (\<Sum>k\<le>m. (2 * m + 1) choose k)"  | 
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
987  | 
by (simp add: binomial_gbinomial add_ac)  | 
| 63466 | 988  | 
also have "\<dots> = of_nat (2 ^ (2 * m))"  | 
989  | 
by (subst binomial_r_part_sum) (rule refl)  | 
|
| 
63366
 
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
 
haftmann 
parents: 
63363 
diff
changeset
 | 
990  | 
finally show ?thesis by simp  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
991  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
992  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
993  | 
lemma gbinomial_sum_nat_pow2:  | 
| 63466 | 994  | 
"(\<Sum>k\<le>m. (of_nat (m + k) gchoose k :: 'a::field_char_0) / 2 ^ k) = 2 ^ m"  | 
995  | 
(is "?lhs = ?rhs")  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
996  | 
proof -  | 
| 63466 | 997  | 
have "2 ^ m * 2 ^ m = (2 ^ (2*m) :: 'a)"  | 
998  | 
by (induct m) simp_all  | 
|
999  | 
also have "\<dots> = (\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k))"  | 
|
1000  | 
using gbinomial_r_part_sum ..  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1001  | 
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: 
68786 
diff
changeset
 | 
1002  | 
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: 
61076 
diff
changeset
 | 
1003  | 
by (simp add: add_ac)  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1004  | 
also have "\<dots> = 2 ^ m * (\<Sum>k\<le>m. (of_nat (m + k) gchoose k) / 2 ^ k)"  | 
| 64267 | 1005  | 
by (subst sum_distrib_left) (simp add: algebra_simps power_diff)  | 
| 63466 | 1006  | 
finally show ?thesis  | 
1007  | 
by (subst (asm) mult_left_cancel) simp_all  | 
|
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1008  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1009  | 
|
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1010  | 
lemma gbinomial_trinomial_revision:  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1011  | 
assumes "k \<le> m"  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
1012  | 
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: 
61076 
diff
changeset
 | 
1013  | 
proof -  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
1014  | 
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: 
61076 
diff
changeset
 | 
1015  | 
using assms by (simp add: binomial_gbinomial [symmetric] binomial_fact)  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
1016  | 
also have "\<dots> = (a gchoose k) * (a - of_nat k gchoose (m - k))"  | 
| 63466 | 1017  | 
using assms by (simp add: gbinomial_pochhammer power_diff pochhammer_product)  | 
| 
61531
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1018  | 
finally show ?thesis .  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1019  | 
qed  | 
| 
 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 
eberlm 
parents: 
61076 
diff
changeset
 | 
1020  | 
|
| 63466 | 1021  | 
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: 
59658 
diff
changeset
 | 
1022  | 
lemma binomial_altdef_of_nat:  | 
| 63466 | 1023  | 
"k \<le> n \<Longrightarrow> of_nat (n choose k) = (\<Prod>i = 0..<k. of_nat (n - i) / of_nat (k - i) :: 'a)"  | 
1024  | 
for n k :: nat and x :: "'a::field_char_0"  | 
|
1025  | 
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: 
59658 
diff
changeset
 | 
1026  | 
|
| 63466 | 1027  | 
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)"  | 
1028  | 
for k n :: nat and x :: "'a::linordered_field"  | 
|
1029  | 
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: 
59658 
diff
changeset
 | 
1030  | 
|
| 
 
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: 
59658 
diff
changeset
 | 
1031  | 
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: 
59658 
diff
changeset
 | 
1032  | 
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: 
59658 
diff
changeset
 | 
1033  | 
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: 
59658 
diff
changeset
 | 
1034  | 
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: 
59658 
diff
changeset
 | 
1035  | 
have "n choose r \<le> fact n div fact (n - r)"  | 
| 63466 | 1036  | 
using assms by (subst binomial_fact_lemma[symmetric]) auto  | 
1037  | 
with fact_div_fact_le_pow [OF assms] show ?thesis  | 
|
1038  | 
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: 
59658 
diff
changeset
 | 
1039  | 
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: 
59658 
diff
changeset
 | 
1040  | 
|
| 63466 | 1041  | 
lemma binomial_altdef_nat: "k \<le> n \<Longrightarrow> n choose k = fact n div (fact k * fact (n - k))"  | 
1042  | 
for k n :: nat  | 
|
1043  | 
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: 
59658 
diff
changeset
 | 
1044  | 
|
| 63466 | 1045  | 
lemma choose_dvd:  | 
| 71699 | 1046  | 
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: 
59669 
diff
changeset
 | 
1047  | 
unfolding dvd_def  | 
| 71699 | 1048  | 
proof  | 
1049  | 
show "fact n = fact k * fact (n - k) * of_nat (n choose k)"  | 
|
1050  | 
by (metis assms binomial_fact_lemma of_nat_fact of_nat_mult)  | 
|
1051  | 
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: 
59658 
diff
changeset
 | 
1052  | 
|
| 
62378
 
85ed00c1fe7c
generalize more theorems to support enat and ennreal
 
hoelzl 
parents: 
62347 
diff
changeset
 | 
1053  | 
lemma fact_fact_dvd_fact:  | 
| 
66806
 
a4e82b58d833
abolished (semi)ring_div in favour of euclidean_(semi)ring_cancel
 
haftmann 
parents: 
66311 
diff
changeset
 | 
1054  | 
"fact k * fact n dvd (fact (k + n) :: 'a::linordered_semidom)"  | 
| 63466 | 1055  | 
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: 
59658 
diff
changeset
 | 
1056  | 
|
| 
 
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: 
59658 
diff
changeset
 | 
1057  | 
lemma choose_mult_lemma:  | 
| 63466 | 1058  | 
"((m + r + k) choose (m + k)) * ((m + k) choose k) = ((m + r + k) choose k) * ((m + r) choose m)"  | 
1059  | 
(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: 
59658 
diff
changeset
 | 
1060  | 
proof -  | 
| 63466 | 1061  | 
have "?lhs =  | 
1062  | 
fact (m + r + k) div (fact (m + k) * fact (m + r - m)) * (fact (m + k) div (fact k * fact m))"  | 
|
| 63092 | 1063  | 
by (simp add: binomial_altdef_nat)  | 
| 71699 | 1064  | 
also have "... = fact (m + r + k) * fact (m + k) div  | 
1065  | 
(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: 
75856 
diff
changeset
 | 
1066  | 
by (metis add_implies_diff add_le_mono1 choose_dvd diff_cancel2 div_mult_div_if_dvd le_add1 le_add2)  | 
| 71699 | 1067  | 
also have "\<dots> = fact (m + r + k) div (fact r * (fact k * fact m))"  | 
1068  | 
by (auto simp: algebra_simps fact_fact_dvd_fact)  | 
|
| 63466 | 1069  | 
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: 
75856 
diff
changeset
 | 
1070  | 
by simp  | 
| 63466 | 1071  | 
also have "\<dots> =  | 
1072  | 
(fact (m + r + k) div (fact k * fact (m + r)) * (fact (m + r) div (fact r * fact m)))"  | 
|
| 71720 | 1073  | 
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: 
59658 
diff
changeset
 | 
1074  | 
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: 
59658 
diff
changeset
 | 
1075  | 
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: 
59658 
diff
changeset
 | 
1076  | 
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: 
59658 
diff
changeset
 | 
1077  | 
|
| 63466 | 1078  | 
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: 
59658 
diff
changeset
 | 
1079  | 
lemma choose_mult:  | 
| 63466 | 1080  | 
"k \<le> m \<Longrightarrow> m \<le> n \<Longrightarrow> (n choose m) * (m choose k) = (n choose k) * ((n - k) choose (m - k))"  | 
1081  | 
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: 
59658 
diff
changeset
 | 
1082  | 
|
| 
75864
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1083  | 
lemma of_nat_binomial_eq_mult_binomial_Suc:  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1084  | 
assumes "k \<le> n"  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1085  | 
  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: 
75856 
diff
changeset
 | 
1086  | 
proof (cases k)  | 
| 
75865
 
62c64e3e4741
The same, without adding a new simprule
 
paulson <lp15@cam.ac.uk> 
parents: 
75864 
diff
changeset
 | 
1087  | 
case 0 then show ?thesis  | 
| 
 
62c64e3e4741
The same, without adding a new simprule
 
paulson <lp15@cam.ac.uk> 
parents: 
75864 
diff
changeset
 | 
1088  | 
using of_nat_neq_0 by auto  | 
| 
75864
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1089  | 
next  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1090  | 
case (Suc l)  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1091  | 
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: 
75856 
diff
changeset
 | 
1092  | 
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: 
75856 
diff
changeset
 | 
1093  | 
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: 
75856 
diff
changeset
 | 
1094  | 
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: 
75856 
diff
changeset
 | 
1095  | 
by (simp add: Suc atLeast0_atMost_Suc atLeastLessThanSuc_atLeastAtMost)  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1096  | 
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: 
75856 
diff
changeset
 | 
1097  | 
by (simp only: Suc_eq_plus1)  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1098  | 
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: 
75864 
diff
changeset
 | 
1099  | 
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: 
75856 
diff
changeset
 | 
1100  | 
with assms show ?thesis  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1101  | 
by (simp add: binomial_altdef_of_nat prod_dividef)  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1102  | 
qed  | 
| 
 
3842556b757c
moved some material from Sum_of_Powers
 
paulson <lp15@cam.ac.uk> 
parents: 
75856 
diff
changeset
 | 
1103  | 
|
| 
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: 
59658 
diff
changeset
 | 
1104  | 
|
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1105  | 
subsection \<open>More on Binomial Coefficients\<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1106  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1107  | 
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>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1108  | 
lemma card_length_sum_list_rec:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1109  | 
assumes "m \<ge> 1"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1110  | 
  shows "card {l::nat list. length l = m \<and> sum_list l = N} =
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1111  | 
      card {l. length l = (m - 1) \<and> sum_list l = N} +
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1112  | 
      card {l. length l = m \<and> sum_list l + 1 = N}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1113  | 
(is "card ?C = card ?A + card ?B")  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1114  | 
proof -  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1115  | 
  let ?A' = "{l. length l = m \<and> sum_list l = N \<and> hd l = 0}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1116  | 
  let ?B' = "{l. length l = m \<and> sum_list l = N \<and> hd l \<noteq> 0}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1117  | 
let ?f = "\<lambda>l. 0 # l"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1118  | 
let ?g = "\<lambda>l. (hd l + 1) # tl l"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1119  | 
have 1: "xs \<noteq> [] \<Longrightarrow> x = hd xs \<Longrightarrow> x # tl xs = xs" for x :: nat and xs  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1120  | 
by simp  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1121  | 
have 2: "xs \<noteq> [] \<Longrightarrow> sum_list(tl xs) = sum_list xs - hd xs" for xs :: "nat list"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1122  | 
by (auto simp add: neq_Nil_conv)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1123  | 
have f: "bij_betw ?f ?A ?A'"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1124  | 
by (rule bij_betw_byWitness[where f' = tl]) (use assms in \<open>auto simp: 2 1 simp flip: length_0_conv\<close>)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1125  | 
have 3: "xs \<noteq> [] \<Longrightarrow> hd xs + (sum_list xs - hd xs) = sum_list xs" for xs :: "nat list"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1126  | 
by (metis 1 sum_list_simps(2) 2)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1127  | 
have g: "bij_betw ?g ?B ?B'"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1128  | 
apply (rule bij_betw_byWitness[where f' = "\<lambda>l. (hd l - 1) # tl l"])  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1129  | 
using assms  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1130  | 
by (auto simp: 2 simp flip: length_0_conv intro!: 3)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1131  | 
  have fin: "finite {xs. size xs = M \<and> set xs \<subseteq> {0..<N}}" for M N :: nat
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1132  | 
using finite_lists_length_eq[OF finite_atLeastLessThan] conj_commute by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1133  | 
have fin_A: "finite ?A" using fin[of _ "N+1"]  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1134  | 
    by (intro finite_subset[where ?A = "?A" and ?B = "{xs. size xs = m - 1 \<and> set xs \<subseteq> {0..<N+1}}"])
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1135  | 
(auto simp: member_le_sum_list less_Suc_eq_le)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1136  | 
have fin_B: "finite ?B"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1137  | 
    by (intro finite_subset[where ?A = "?B" and ?B = "{xs. size xs = m \<and> set xs \<subseteq> {0..<N}}"])
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1138  | 
(auto simp: member_le_sum_list less_Suc_eq_le fin)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1139  | 
have uni: "?C = ?A' \<union> ?B'"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1140  | 
by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1141  | 
  have disj: "?A' \<inter> ?B' = {}" by blast
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1142  | 
have "card ?C = card(?A' \<union> ?B')"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1143  | 
using uni by simp  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1144  | 
also have "\<dots> = card ?A + card ?B"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1145  | 
using card_Un_disjoint[OF _ _ disj] bij_betw_finite[OF f] bij_betw_finite[OF g]  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1146  | 
bij_betw_same_card[OF f] bij_betw_same_card[OF g] fin_A fin_B  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1147  | 
by presburger  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1148  | 
finally show ?thesis .  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1149  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1150  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1151  | 
lemma card_length_sum_list: "card {l::nat list. size l = m \<and> sum_list l = N} = (N + m - 1) choose N"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1152  | 
\<comment> \<open>by Holden Lee, tidied by Tobias Nipkow\<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1153  | 
proof (cases m)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1154  | 
case 0  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1155  | 
then show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1156  | 
by (cases N) (auto cong: conj_cong)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1157  | 
next  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1158  | 
case (Suc m')  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1159  | 
have m: "m \<ge> 1"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1160  | 
by (simp add: Suc)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1161  | 
then show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1162  | 
proof (induct "N + m - 1" arbitrary: N m)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1163  | 
case 0 \<comment> \<open>In the base case, the only solution is [0].\<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1164  | 
    have [simp]: "{l::nat list. length l = Suc 0 \<and> (\<forall>n\<in>set l. n = 0)} = {[0]}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1165  | 
by (auto simp: length_Suc_conv)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1166  | 
have "m = 1 \<and> N = 0"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1167  | 
using 0 by linarith  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1168  | 
then show ?case  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1169  | 
by simp  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1170  | 
next  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1171  | 
case (Suc k)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1172  | 
    have c1: "card {l::nat list. size l = (m - 1) \<and> sum_list l =  N} = (N + (m - 1) - 1) choose N"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1173  | 
proof (cases "m = 1")  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1174  | 
case True  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1175  | 
with Suc.hyps have "N \<ge> 1"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1176  | 
by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1177  | 
with True show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1178  | 
by (simp add: binomial_eq_0)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1179  | 
next  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1180  | 
case False  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1181  | 
then show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1182  | 
using Suc by fastforce  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1183  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1184  | 
    from Suc have c2: "card {l::nat list. size l = m \<and> sum_list l + 1 = N} =
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1185  | 
(if N > 0 then ((N - 1) + m - 1) choose (N - 1) else 0)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1186  | 
proof -  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1187  | 
have *: "n > 0 \<Longrightarrow> Suc m = n \<longleftrightarrow> m = n - 1" for m n  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1188  | 
by arith  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1189  | 
from Suc have "N > 0 \<Longrightarrow>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1190  | 
        card {l::nat list. size l = m \<and> sum_list l + 1 = N} =
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1191  | 
((N - 1) + m - 1) choose (N - 1)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1192  | 
by (simp add: *)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1193  | 
then show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1194  | 
by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1195  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1196  | 
    from Suc.prems have "(card {l::nat list. size l = (m - 1) \<and> sum_list l = N} +
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1197  | 
          card {l::nat list. size l = m \<and> sum_list l + 1 = N}) = (N + m - 1) choose N"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1198  | 
by (auto simp: c1 c2 choose_reduce_nat[of "N + m - 1" N] simp del: One_nat_def)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1199  | 
then show ?case  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1200  | 
using card_length_sum_list_rec[OF Suc.prems] by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1201  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1202  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1203  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1204  | 
lemma card_disjoint_shuffles:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1205  | 
  assumes "set xs \<inter> set ys = {}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1206  | 
shows "card (shuffles xs ys) = (length xs + length ys) choose length xs"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1207  | 
using assms  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1208  | 
proof (induction xs ys rule: shuffles.induct)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1209  | 
case (3 x xs y ys)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1210  | 
have "shuffles (x # xs) (y # ys) = (#) x ` shuffles xs (y # ys) \<union> (#) y ` shuffles (x # xs) ys"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1211  | 
by (rule shuffles.simps)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1212  | 
also have "card \<dots> = card ((#) x ` shuffles xs (y # ys)) + card ((#) y ` shuffles (x # xs) ys)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1213  | 
by (rule card_Un_disjoint) (insert "3.prems", auto)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1214  | 
also have "card ((#) x ` shuffles xs (y # ys)) = card (shuffles xs (y # ys))"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1215  | 
by (rule card_image) auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1216  | 
also have "\<dots> = (length xs + length (y # ys)) choose length xs"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1217  | 
using "3.prems" by (intro "3.IH") auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1218  | 
also have "card ((#) y ` shuffles (x # xs) ys) = card (shuffles (x # xs) ys)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1219  | 
by (rule card_image) auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1220  | 
also have "\<dots> = (length (x # xs) + length ys) choose length (x # xs)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1221  | 
using "3.prems" by (intro "3.IH") auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1222  | 
also have "length xs + length (y # ys) choose length xs + \<dots> =  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1223  | 
(length (x # xs) + length (y # ys)) choose length (x # xs)" by simp  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1224  | 
finally show ?case .  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1225  | 
qed auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1226  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1227  | 
lemma Suc_times_binomial_add: "Suc a * (Suc (a + b) choose Suc a) = Suc b * (Suc (a + b) choose a)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1228  | 
\<comment> \<open>by Lukas Bulwahn\<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1229  | 
proof -  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1230  | 
have dvd: "Suc a * (fact a * fact b) dvd fact (Suc (a + b))" for a b  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1231  | 
using fact_fact_dvd_fact[of "Suc a" "b", where 'a=nat]  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1232  | 
by (simp only: fact_Suc add_Suc[symmetric] of_nat_id mult.assoc)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1233  | 
have "Suc a * (fact (Suc (a + b)) div (Suc a * fact a * fact b)) =  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1234  | 
Suc a * fact (Suc (a + b)) div (Suc a * (fact a * fact b))"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1235  | 
by (subst div_mult_swap[symmetric]; simp only: mult.assoc dvd)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1236  | 
also have "\<dots> = Suc b * fact (Suc (a + b)) div (Suc b * (fact a * fact b))"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1237  | 
by (simp only: div_mult_mult1)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1238  | 
also have "\<dots> = Suc b * (fact (Suc (a + b)) div (Suc b * (fact a * fact b)))"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1239  | 
using dvd[of b a] by (subst div_mult_swap[symmetric]; simp only: ac_simps dvd)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1240  | 
finally show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1241  | 
by (subst (1 2) binomial_altdef_nat)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1242  | 
(simp_all only: ac_simps diff_Suc_Suc Suc_diff_le diff_add_inverse fact_Suc of_nat_id)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1243  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1244  | 
|
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1245  | 
subsection \<open>Inclusion-exclusion principle\<close>  | 
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1246  | 
text \<open>Ported from HOL Light by lcp\<close>  | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1247  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1248  | 
lemma Inter_over_Union:  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1249  | 
  "\<Inter> {\<Union> (\<F> x) |x. x \<in> S} = \<Union> {\<Inter> (G ` S) |G. \<forall>x\<in>S. G x \<in> \<F> x}" 
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1250  | 
proof -  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1251  | 
have "\<And>x. \<forall>s\<in>S. \<exists>X \<in> \<F> s. x \<in> X \<Longrightarrow> \<exists>G. (\<forall>x\<in>S. G x \<in> \<F> x) \<and> (\<forall>s\<in>S. x \<in> G s)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1252  | 
by metis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1253  | 
then show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1254  | 
by (auto simp flip: all_simps ex_simps)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1255  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1256  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1257  | 
lemma subset_insert_lemma:  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1258  | 
  "{T. T \<subseteq> (insert a S) \<and> P T} = {T. T \<subseteq> S \<and> P T} \<union> {insert a T |T. T \<subseteq> S \<and> P(insert a T)}" (is "?L=?R")
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1259  | 
proof  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1260  | 
show "?L \<subseteq> ?R"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1261  | 
by (smt (verit) UnI1 UnI2 insert_Diff mem_Collect_eq subsetI subset_insert_iff)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1262  | 
qed blast  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1263  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1264  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1265  | 
text\<open>Versions for additive real functions, where the additivity applies only to some  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1266  | 
specific subsets (e.g. cardinality of finite sets, measurable sets with bounded measure.  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1267  | 
(From HOL Light)\<close>  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1268  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1269  | 
locale Incl_Excl =  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1270  | 
fixes P :: "'a set \<Rightarrow> bool" and f :: "'a set \<Rightarrow> 'b::ring_1"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1271  | 
assumes disj_add: "\<lbrakk>P S; P T; disjnt S T\<rbrakk> \<Longrightarrow> f(S \<union> T) = f S + f T"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1272  | 
    and empty: "P{}"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1273  | 
and Int: "\<lbrakk>P S; P T\<rbrakk> \<Longrightarrow> P(S \<inter> T)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1274  | 
and Un: "\<lbrakk>P S; P T\<rbrakk> \<Longrightarrow> P(S \<union> T)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1275  | 
and Diff: "\<lbrakk>P S; P T\<rbrakk> \<Longrightarrow> P(S - T)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1276  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1277  | 
begin  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1278  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1279  | 
lemma f_empty [simp]: "f{} = 0"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1280  | 
using disj_add empty by fastforce  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1281  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1282  | 
lemma f_Un_Int: "\<lbrakk>P S; P T\<rbrakk> \<Longrightarrow> f(S \<union> T) + f(S \<inter> T) = f S + f T"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1283  | 
by (smt (verit, ccfv_threshold) Groups.add_ac(2) Incl_Excl.Diff Incl_Excl.Int Incl_Excl_axioms Int_Diff_Un Int_Diff_disjoint Int_absorb Un_Diff Un_Int_eq(2) disj_add disjnt_def group_cancel.add2 sup_bot.right_neutral)  | 
| 
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: 
59658 
diff
changeset
 | 
1284  | 
|
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1285  | 
lemma restricted_indexed:  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1286  | 
assumes "finite A" and X: "\<And>a. a \<in> A \<Longrightarrow> P(X a)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1287  | 
  shows "f(\<Union>(X ` A)) = (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ (card B + 1) * f (\<Inter> (X ` B)))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1288  | 
proof -  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1289  | 
have "\<lbrakk>finite A; card A = n; \<forall>a \<in> A. P (X a)\<rbrakk>  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1290  | 
              \<Longrightarrow> f(\<Union>(X ` A)) = (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ (card B + 1) * f (\<Inter> (X ` B)))" for n X and A :: "'c set"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1291  | 
proof (induction n arbitrary: A X rule: less_induct)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1292  | 
case (less n0 A0 X)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1293  | 
show ?case  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1294  | 
proof (cases "n0=0")  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1295  | 
case True  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1296  | 
with less show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1297  | 
by fastforce  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1298  | 
next  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1299  | 
case False  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1300  | 
with less.prems obtain A n a where *: "n0 = Suc n" "A0 = insert a A" "a \<notin> A" "card A = n" "finite A"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1301  | 
by (metis card_Suc_eq_finite not0_implies_Suc)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1302  | 
with less have "P (X a)" by blast  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1303  | 
have APX: "\<forall>a \<in> A. P (X a)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1304  | 
by (simp add: "*" less.prems)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1305  | 
have PUXA: "P (\<Union> (X ` A))"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1306  | 
using \<open>finite A\<close> APX  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1307  | 
by (induction) (auto simp: empty Un)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1308  | 
have "f (\<Union> (X ` A0)) = f (X a \<union> \<Union> (X ` A))"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1309  | 
by (simp add: *)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1310  | 
also have "... = f (X a) + f (\<Union> (X ` A)) - f (X a \<inter> \<Union> (X ` A))"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1311  | 
using f_Un_Int add_diff_cancel PUXA \<open>P (X a)\<close> by metis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1312  | 
      also have "... = f (X a) - (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ card B * f (\<Inter> (X ` B))) +
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1313  | 
                       (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ card B * f (X a \<inter> \<Inter> (X ` B)))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1314  | 
proof -  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1315  | 
        have 1: "f (\<Union>i\<in>A. X a \<inter> X i) = (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ (card B + 1) * f (\<Inter>b\<in>B. X a \<inter> X b))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1316  | 
using less.IH [of n A "\<lambda>i. X a \<inter> X i"] APX Int \<open>P (X a)\<close> by (simp add: *)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1317  | 
have 2: "X a \<inter> \<Union> (X ` A) = (\<Union>i\<in>A. X a \<inter> X i)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1318  | 
by auto  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1319  | 
        have 3: "f (\<Union> (X ` A)) = (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ (card B + 1) * f (\<Inter> (X ` B)))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1320  | 
using less.IH [of n A X] APX Int \<open>P (X a)\<close> by (simp add: *)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1321  | 
show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1322  | 
unfolding 3 2 1  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1323  | 
by (simp add: sum_negf)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1324  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1325  | 
      also have "... = (\<Sum>B | B \<subseteq> A0 \<and> B \<noteq> {}. (- 1) ^ (card B + 1) * f (\<Inter> (X ` B)))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1326  | 
proof -  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1327  | 
         have F: "{insert a B |B. B \<subseteq> A} = insert a ` Pow A \<and> {B. B \<subseteq> A \<and> B \<noteq> {}} = Pow A - {{}}"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1328  | 
by auto  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1329  | 
have G: "(\<Sum>B\<in>Pow A. (- 1) ^ card (insert a B) * f (X a \<inter> \<Inter> (X ` B))) = (\<Sum>B\<in>Pow A. - ((- 1) ^ card B * f (X a \<inter> \<Inter> (X ` B))))"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1330  | 
proof (rule sum.cong [OF refl])  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1331  | 
fix B  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1332  | 
assume B: "B \<in> Pow A"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1333  | 
then have "finite B"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1334  | 
using \<open>finite A\<close> finite_subset by auto  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1335  | 
show "(- 1) ^ card (insert a B) * f (X a \<inter> \<Inter> (X ` B)) = - ((- 1) ^ card B * f (X a \<inter> \<Inter> (X ` B)))"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1336  | 
using B * by (auto simp add: card_insert_if \<open>finite B\<close>)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1337  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1338  | 
        have disj: "{B. B \<subseteq> A \<and> B \<noteq> {}} \<inter> {insert a B |B. B \<subseteq> A} = {}"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1339  | 
using * by blast  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1340  | 
have inj: "inj_on (insert a) (Pow A)"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1341  | 
using "*" inj_on_def by fastforce  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1342  | 
show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1343  | 
apply (simp add: * subset_insert_lemma sum.union_disjoint disj sum_negf)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1344  | 
apply (simp add: F G sum_negf sum.reindex [OF inj] o_def sum_diff *)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1345  | 
done  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1346  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1347  | 
finally show ?thesis .  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1348  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1349  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1350  | 
then show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1351  | 
by (meson assms)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1352  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1353  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1354  | 
lemma restricted:  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1355  | 
assumes "finite A" "\<And>a. a \<in> A \<Longrightarrow> P a"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1356  | 
  shows  "f(\<Union> A) = (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ (card B + 1) * f (\<Inter> B))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1357  | 
using restricted_indexed [of A "\<lambda>x. x"] assms by auto  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1358  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1359  | 
end  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1360  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1361  | 
subsection\<open>Versions for unrestrictedly additive functions\<close>  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1362  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1363  | 
lemma Incl_Excl_UN:  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1364  | 
fixes f :: "'a set \<Rightarrow> 'b::ring_1"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1365  | 
assumes "\<And>S T. disjnt S T \<Longrightarrow> f(S \<union> T) = f S + f T" "finite A"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1366  | 
  shows "f(\<Union>(G ` A)) = (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (-1) ^ (card B + 1) * f (\<Inter> (G ` B)))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1367  | 
proof -  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1368  | 
interpret Incl_Excl "\<lambda>x. True" f  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1369  | 
by (simp add: Incl_Excl.intro assms(1))  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1370  | 
show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1371  | 
using restricted_indexed assms by blast  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1372  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1373  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1374  | 
lemma Incl_Excl_Union:  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1375  | 
fixes f :: "'a set \<Rightarrow> 'b::ring_1"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1376  | 
assumes "\<And>S T. disjnt S T \<Longrightarrow> f(S \<union> T) = f S + f T" "finite A"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1377  | 
  shows "f(\<Union> A) = (\<Sum>B | B \<subseteq> A \<and> B \<noteq> {}. (- 1) ^ (card B + 1) * f (\<Inter> B))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1378  | 
using Incl_Excl_UN[of f A "\<lambda>X. X"] 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: 
59658 
diff
changeset
 | 
1379  | 
|
| 
75856
 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 
paulson <lp15@cam.ac.uk> 
parents: 
73932 
diff
changeset
 | 
1380  | 
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: 
73932 
diff
changeset
 | 
1381  | 
lemma int_card_UNION:  | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1382  | 
assumes "finite A" "\<And>K. K \<in> A \<Longrightarrow> finite K"  | 
| 
75856
 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 
paulson <lp15@cam.ac.uk> 
parents: 
73932 
diff
changeset
 | 
1383  | 
  shows "int (card (\<Union>A)) = (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * int (card (\<Inter>I)))"
 | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1384  | 
proof -  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1385  | 
interpret Incl_Excl finite "int o card"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1386  | 
proof qed (auto simp add: card_Un_disjnt)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1387  | 
show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1388  | 
using restricted assms by auto  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1389  | 
qed  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1390  | 
|
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1391  | 
text\<open>A more conventional form\<close>  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1392  | 
lemma inclusion_exclusion:  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1393  | 
assumes "finite A" "\<And>K. K \<in> A \<Longrightarrow> finite K"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1394  | 
shows "int(card(\<Union> A)) =  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1395  | 
(\<Sum>n=1..card A. (-1) ^ (Suc n) * (\<Sum>B | B \<subseteq> A \<and> card B = n. int (card (\<Inter> B))))" (is "_=?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: 
59658 
diff
changeset
 | 
1396  | 
proof -  | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1397  | 
  have fin: "finite {I. I \<subseteq> A \<and> I \<noteq> {}}"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1398  | 
by (simp add: assms)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1399  | 
  have "\<And>k. \<lbrakk>Suc 0 \<le> k; k \<le> card A\<rbrakk> \<Longrightarrow> \<exists>B\<subseteq>A. B \<noteq> {} \<and> k = card B"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1400  | 
by (metis (mono_tags, lifting) Suc_le_D Zero_neq_Suc card_eq_0_iff obtain_subset_with_card_n)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1401  | 
with \<open>finite A\<close> finite_subset  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1402  | 
  have card_eq: "card ` {I. I \<subseteq> A \<and> I \<noteq> {}} = {1..card A}"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1403  | 
using not_less_eq_eq card_mono by (fastforce simp: image_iff)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1404  | 
have "int(card(\<Union> A))  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1405  | 
      = (\<Sum>y = 1..card A. \<Sum>I\<in>{x. x \<subseteq> A \<and> x \<noteq> {} \<and> card x = y}. - ((- 1) ^ y * int (card (\<Inter> I))))"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1406  | 
by (simp add: int_card_UNION assms sum.image_gen [OF fin, where g=card] card_eq)  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1407  | 
also have "... = ?R"  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1408  | 
proof -  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1409  | 
    have "{B. B \<subseteq> A \<and> B \<noteq> {} \<and> card B = k} = {B. B \<subseteq> A \<and> card B = k}"
 | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1410  | 
if "Suc 0 \<le> k" and "k \<le> card A" for k  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1411  | 
using that by auto  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1412  | 
then show ?thesis  | 
| 
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1413  | 
by (clarsimp simp add: sum_negf simp flip: sum_distrib_left)  | 
| 
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: 
59658 
diff
changeset
 | 
1414  | 
qed  | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1415  | 
finally show ?thesis .  | 
| 
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: 
59658 
diff
changeset
 | 
1416  | 
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: 
59658 
diff
changeset
 | 
1417  | 
|
| 
75856
 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 
paulson <lp15@cam.ac.uk> 
parents: 
73932 
diff
changeset
 | 
1418  | 
lemma card_UNION:  | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1419  | 
assumes "finite A" and "\<And>K. K \<in> A \<Longrightarrow> finite K"  | 
| 
75856
 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 
paulson <lp15@cam.ac.uk> 
parents: 
73932 
diff
changeset
 | 
1420  | 
  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: 
73932 
diff
changeset
 | 
1421  | 
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: 
73932 
diff
changeset
 | 
1422  | 
|
| 
 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 
paulson <lp15@cam.ac.uk> 
parents: 
73932 
diff
changeset
 | 
1423  | 
lemma card_UNION_nonneg:  | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1424  | 
assumes "finite A" and "\<And>K. K \<in> A \<Longrightarrow> finite K"  | 
| 
75856
 
4b507edcf6b5
The right way to formulate card_UNION, plus the old version for compatibility
 
paulson <lp15@cam.ac.uk> 
parents: 
73932 
diff
changeset
 | 
1425  | 
  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: 
73932 
diff
changeset
 | 
1426  | 
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: 
73932 
diff
changeset
 | 
1427  | 
|
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1428  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1429  | 
subsection \<open>General "Moebius inversion" inclusion-exclusion principle\<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1430  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1431  | 
text \<open>This "symmetric" form is from Ira Gessel: "Symmetric Inclusion-Exclusion" \<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1432  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1433  | 
lemma sum_Un_eq:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1434  | 
   "\<lbrakk>S \<inter> T = {}; S \<union> T = U; finite U\<rbrakk>
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1435  | 
\<Longrightarrow> (sum f S + sum f T = sum f U)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1436  | 
by (metis finite_Un sum.union_disjoint)  | 
| 
78656
 
4da1e18a9633
Loads of new material related to porting the Euler Polyhedron Formula from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
77172 
diff
changeset
 | 
1437  | 
|
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1438  | 
lemma card_adjust_lemma: "\<lbrakk>inj_on f S; x = y + card (f ` S)\<rbrakk> \<Longrightarrow> x = y + card S"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1439  | 
by (simp add: card_image)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1440  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1441  | 
lemma card_subsets_step:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1442  | 
assumes "finite S" "x \<notin> S" "U \<subseteq> S"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1443  | 
  shows "card {T. T \<subseteq> (insert x S) \<and> U \<subseteq> T \<and> odd(card T)} 
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1444  | 
       = card {T. T \<subseteq> S \<and> U \<subseteq> T \<and> odd(card T)} + card {T. T \<subseteq> S \<and> U \<subseteq> T \<and> even(card T)} \<and>
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1445  | 
         card {T. T \<subseteq> (insert x S) \<and> U \<subseteq> T \<and> even(card T)} 
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1446  | 
       = card {T. T \<subseteq> S \<and> U \<subseteq> T \<and> even(card T)} + card {T. T \<subseteq> S \<and> U \<subseteq> T \<and> odd(card T)}"
 | 
| 
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: 
59658 
diff
changeset
 | 
1447  | 
proof -  | 
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1448  | 
  have inj: "inj_on (insert x) {T. T \<subseteq> S \<and> P T}" for P
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1449  | 
using assms by (auto simp: inj_on_def)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1450  | 
  have [simp]: "finite {T. T \<subseteq> S \<and> P T}"  "finite (insert x ` {T. T \<subseteq> S \<and> P T})" for P
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1451  | 
using \<open>finite S\<close> by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1452  | 
  have [simp]: "disjnt {T. T \<subseteq> S \<and> P T} (insert x ` {T. T \<subseteq> S \<and> Q T})" for P Q
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1453  | 
using assms by (auto simp: disjnt_iff)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1454  | 
  have eq: "{T. T \<subseteq> S \<and> U \<subseteq> T \<and> P T} \<union> insert x ` {T. T \<subseteq> S \<and> U \<subseteq> T \<and> Q T}
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1455  | 
          = {T. T \<subseteq> insert x S \<and> U \<subseteq> T \<and> P T}"  (is "?L = ?R")
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1456  | 
if "\<And>A. A \<subseteq> S \<Longrightarrow> Q (insert x A) \<longleftrightarrow> P A" "\<And>A. \<not> Q A \<longleftrightarrow> P A" for P Q  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1457  | 
proof  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1458  | 
show "?L \<subseteq> ?R"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1459  | 
by (clarsimp simp: image_iff subset_iff) (meson subsetI that)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1460  | 
show "?R \<subseteq> ?L"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1461  | 
using \<open>U \<subseteq> S\<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1462  | 
by (clarsimp simp: image_iff) (smt (verit) insert_iff mk_disjoint_insert subset_iff that)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1463  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1464  | 
have [simp]: "\<And>A. A \<subseteq> S \<Longrightarrow> even (card (insert x A)) \<longleftrightarrow> odd (card A)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1465  | 
by (metis \<open>finite S\<close> \<open>x \<notin> S\<close> card_insert_disjoint even_Suc finite_subset subsetD)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1466  | 
show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1467  | 
by (intro conjI card_adjust_lemma [OF inj]; simp add: eq flip: card_Un_disjnt)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1468  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1469  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1470  | 
lemma card_subsupersets_even_odd:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1471  | 
assumes "finite S" "U \<subset> S"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1472  | 
  shows "card {T. T \<subseteq> S \<and> U \<subseteq> T \<and> even(card T)} 
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1473  | 
       = card {T. T \<subseteq> S \<and> U \<subseteq> T \<and> odd(card T)}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1474  | 
using assms  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1475  | 
proof (induction "card S" arbitrary: S rule: less_induct)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1476  | 
case (less S)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1477  | 
then obtain x where "x \<notin> U" "x \<in> S"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1478  | 
by blast  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1479  | 
  then have U: "U \<subseteq> S - {x}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1480  | 
using less.prems(2) by blast  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1481  | 
  let ?V = "S - {x}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1482  | 
show ?case  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1483  | 
using card_subsets_step [of ?V x U] less.prems U  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1484  | 
by (simp add: insert_absorb \<open>x \<in> S\<close>)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1485  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1486  | 
|
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1487  | 
lemma sum_alternating_cancels:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1488  | 
  assumes "finite S" "card {x. x \<in> S \<and> even(f x)} = card {x. x \<in> S \<and> odd(f x)}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1489  | 
shows "(\<Sum>x\<in>S. (-1) ^ f x) = (0::'b::ring_1)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1490  | 
proof -  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1491  | 
have "(\<Sum>x\<in>S. (-1) ^ f x)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1492  | 
= (\<Sum>x | x \<in> S \<and> even (f x). (-1) ^ f x) + (\<Sum>x | x \<in> S \<and> odd (f x). (-1) ^ f x)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1493  | 
by (rule sum_Un_eq [symmetric]; force simp: \<open>finite S\<close>)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1494  | 
also have "... = (0::'b::ring_1)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1495  | 
by (simp add: minus_one_power_iff assms 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: 
59658 
diff
changeset
 | 
1496  | 
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: 
59658 
diff
changeset
 | 
1497  | 
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: 
59658 
diff
changeset
 | 
1498  | 
|
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1499  | 
lemma inclusion_exclusion_symmetric:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1500  | 
fixes f :: "'a set \<Rightarrow> 'b::ring_1"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1501  | 
assumes \<section>: "\<And>S. finite S \<Longrightarrow> g S = (\<Sum>T \<in> Pow S. (-1) ^ card T * f T)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1502  | 
and "finite S"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1503  | 
shows "f S = (\<Sum>T \<in> Pow S. (-1) ^ card T * g T)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1504  | 
proof -  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1505  | 
have "(-1) ^ card T * g T = (-1) ^ card T * (\<Sum>U | U \<subseteq> S \<and> U \<subseteq> T. (-1) ^ card U * f U)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1506  | 
if "T \<subseteq> S" for T  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1507  | 
proof -  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1508  | 
    have [simp]: "{U. U \<subseteq> S \<and> U \<subseteq> T} = Pow T"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1509  | 
using that by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1510  | 
show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1511  | 
using that by (simp add: \<open>finite S\<close> finite_subset \<section>)  | 
| 63466 | 1512  | 
qed  | 
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1513  | 
then have "(\<Sum>T \<in> Pow S. (-1) ^ card T * g T)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1514  | 
      = (\<Sum>T\<in>Pow S. (-1) ^ card T * (\<Sum>U | U \<in> {U. U \<subseteq> S} \<and> U \<subseteq> T. (-1) ^ card U * f U))"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1515  | 
by simp  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1516  | 
also have "... = (\<Sum>U\<in>Pow S. (\<Sum>T | T \<subseteq> S \<and> U \<subseteq> T. (-1) ^ card T) * (-1) ^ card U * f U)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1517  | 
unfolding sum_distrib_left  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1518  | 
by (subst sum.swap_restrict; simp add: \<open>finite S\<close> algebra_simps sum_distrib_right Pow_def)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1519  | 
also have "... = (\<Sum>U\<in>Pow S. if U=S then f S else 0)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1520  | 
proof -  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1521  | 
    have [simp]: "{T. T \<subseteq> S \<and> S \<subseteq> T} = {S}"
 | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1522  | 
by auto  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1523  | 
show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1524  | 
apply (rule sum.cong [OF refl])  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1525  | 
by (simp add: sum_alternating_cancels card_subsupersets_even_odd \<open>finite S\<close> flip: power_add)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1526  | 
qed  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1527  | 
also have "... = f S"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1528  | 
by (simp add: \<open>finite S\<close>)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1529  | 
finally show ?thesis  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1530  | 
by presburger  | 
| 
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: 
59658 
diff
changeset
 | 
1531  | 
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: 
59658 
diff
changeset
 | 
1532  | 
|
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1533  | 
text\<open> The more typical non-symmetric version. \<close>  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1534  | 
lemma inclusion_exclusion_mobius:  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1535  | 
fixes f :: "'a set \<Rightarrow> 'b::ring_1"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1536  | 
assumes \<section>: "\<And>S. finite S \<Longrightarrow> g S = sum f (Pow S)" and "finite S"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1537  | 
shows "f S = (\<Sum>T \<in> Pow S. (-1) ^ (card S - card T) * g T)" (is "_ = ?rhs")  | 
| 60604 | 1538  | 
proof -  | 
| 
78667
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1539  | 
have "(- 1) ^ card S * f S = (\<Sum>T\<in>Pow S. (- 1) ^ card T * g T)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1540  | 
by (rule inclusion_exclusion_symmetric; simp add: assms flip: power_add mult.assoc)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1541  | 
then have "((- 1) ^ card S * (- 1) ^ card S) * f S = ((- 1) ^ card S) * (\<Sum>T\<in>Pow S. (- 1) ^ card T * g T)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1542  | 
by (simp add: mult_ac)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1543  | 
then have "f S = (\<Sum>T\<in>Pow S. (- 1) ^ (card S + card T) * g T)"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1544  | 
by (simp add: sum_distrib_left flip: power_add mult.assoc)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1545  | 
also have "... = ?rhs"  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1546  | 
by (simp add: \<open>finite S\<close> card_mono neg_one_power_add_eq_neg_one_power_diff)  | 
| 
 
d900ff3f314a
A few more inclusion-exclusion theorems from HOL Light
 
paulson <lp15@cam.ac.uk> 
parents: 
78656 
diff
changeset
 | 
1547  | 
finally show ?thesis .  | 
| 60604 | 1548  | 
qed  | 
1549  | 
||
| 63373 | 1550  | 
|
| 68785 | 1551  | 
subsection \<open>Executable code\<close>  | 
| 63373 | 1552  | 
|
| 
62128
 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 
eberlm 
parents: 
61799 
diff
changeset
 | 
1553  | 
lemma gbinomial_code [code]:  | 
| 
68787
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
1554  | 
"a gchoose k =  | 
| 
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
1555  | 
(if k = 0 then 1  | 
| 
 
b129052644e9
more uniform parameter naming convention for choose and gchoose
 
haftmann 
parents: 
68786 
diff
changeset
 | 
1556  | 
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: 
68786 
diff
changeset
 | 
1557  | 
by (cases k)  | 
| 64272 | 1558  | 
(simp_all add: gbinomial_prod_rev prod_atLeastAtMost_code [symmetric]  | 
| 63466 | 1559  | 
atLeastLessThanSuc_atLeastAtMost)  | 
| 
62128
 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 
eberlm 
parents: 
61799 
diff
changeset
 | 
1560  | 
|
| 
 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 
eberlm 
parents: 
61799 
diff
changeset
 | 
1561  | 
lemma binomial_code [code]:  | 
| 68785 | 1562  | 
"n choose k =  | 
| 
62128
 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 
eberlm 
parents: 
61799 
diff
changeset
 | 
1563  | 
(if k > n then 0  | 
| 68785 | 1564  | 
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: 
68787 
diff
changeset
 | 
1565  | 
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: 
61799 
diff
changeset
 | 
1566  | 
proof -  | 
| 
 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 
eberlm 
parents: 
61799 
diff
changeset
 | 
1567  | 
  {
 | 
| 
 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 
eberlm 
parents: 
61799 
diff
changeset
 | 
1568  | 
assume "k \<le> n"  | 
| 63466 | 1569  | 
    then have "{1..n} = {1..n-k} \<union> {n-k+1..n}" by auto
 | 
1570  | 
    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: 
65552 
diff
changeset
 | 
1571  | 
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: 
61799 
diff
changeset
 | 
1572  | 
}  | 
| 64272 | 1573  | 
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: 
62347 
diff
changeset
 | 
1574  | 
qed  | 
| 
62128
 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 
eberlm 
parents: 
61799 
diff
changeset
 | 
1575  | 
|
| 15131 | 1576  | 
end  |