author | wenzelm |
Sat, 11 Mar 2017 14:18:21 +0100 | |
changeset 65183 | 37f1effd6683 |
parent 64272 | f76b6dda2e56 |
child 65350 | b149abe619f7 |
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 |
||
63373 | 9 |
section \<open>Combinatorial Functions: Factorial Function, Rising Factorials, Binomial Coefficients and Binomial Theorem\<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 |
63466 | 12 |
imports Main |
15131 | 13 |
begin |
15094
a7d1a3fdc30d
conversion of Hyperreal/{Fact,Filter} to Isar scripts
paulson
parents:
12196
diff
changeset
|
14 |
|
60758 | 15 |
subsection \<open>Factorial\<close> |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
16 |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
17 |
context semiring_char_0 |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
18 |
begin |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
19 |
|
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
20 |
definition fact :: "nat \<Rightarrow> 'a" |
64272 | 21 |
where fact_prod: "fact n = of_nat (\<Prod>{1..n})" |
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
22 |
|
64272 | 23 |
lemma fact_prod_Suc: "fact n = of_nat (prod Suc {0..<n})" |
63466 | 24 |
by (cases n) |
64272 | 25 |
(simp_all add: fact_prod prod.atLeast_Suc_atMost_Suc_shift |
63466 | 26 |
atLeastLessThanSuc_atLeastAtMost) |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
27 |
|
64272 | 28 |
lemma fact_prod_rev: "fact n = of_nat (\<Prod>i = 0..<n. n - i)" |
29 |
using prod.atLeast_atMost_rev [of "\<lambda>i. i" 1 n] |
|
63466 | 30 |
by (cases n) |
64272 | 31 |
(simp_all add: fact_prod_Suc prod.atLeast_Suc_atMost_Suc_shift |
63466 | 32 |
atLeastLessThanSuc_atLeastAtMost) |
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
33 |
|
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
34 |
lemma fact_0 [simp]: "fact 0 = 1" |
64272 | 35 |
by (simp add: fact_prod) |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
36 |
|
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
37 |
lemma fact_1 [simp]: "fact 1 = 1" |
64272 | 38 |
by (simp add: fact_prod) |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
39 |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
40 |
lemma fact_Suc_0 [simp]: "fact (Suc 0) = 1" |
64272 | 41 |
by (simp add: fact_prod) |
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
42 |
|
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
43 |
lemma fact_Suc [simp]: "fact (Suc n) = of_nat (Suc n) * fact n" |
64272 | 44 |
by (simp add: fact_prod atLeastAtMostSuc_conv algebra_simps) |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
45 |
|
63466 | 46 |
lemma fact_2 [simp]: "fact 2 = 2" |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
47 |
by (simp add: numeral_2_eq_2) |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
48 |
|
64272 | 49 |
lemma fact_split: "k \<le> n \<Longrightarrow> fact n = of_nat (prod Suc {n - k..<n}) * fact (n - k)" |
50 |
by (simp add: fact_prod_Suc prod.union_disjoint [symmetric] |
|
63466 | 51 |
ivl_disj_un ac_simps of_nat_mult [symmetric]) |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
52 |
|
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
53 |
end |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
54 |
|
63466 | 55 |
lemma of_nat_fact [simp]: "of_nat (fact n) = fact n" |
64272 | 56 |
by (simp add: fact_prod) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
57 |
|
63466 | 58 |
lemma of_int_fact [simp]: "of_int (fact n) = fact n" |
64272 | 59 |
by (simp only: fact_prod of_int_of_nat_eq) |
62347 | 60 |
|
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
61 |
lemma fact_reduce: "n > 0 \<Longrightarrow> fact n = of_nat n * fact (n - 1)" |
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
62 |
by (cases n) auto |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
63 |
|
59733
cd945dc13bec
more general type class for factorial. Now allows code generation (?)
paulson <lp15@cam.ac.uk>
parents:
59730
diff
changeset
|
64 |
lemma fact_nonzero [simp]: "fact n \<noteq> (0::'a::{semiring_char_0,semiring_no_zero_divisors})" |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
65 |
apply (induct n) |
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
66 |
apply auto |
63466 | 67 |
using of_nat_eq_0_iff |
68 |
apply fastforce |
|
69 |
done |
|
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
70 |
|
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
71 |
lemma fact_mono_nat: "m \<le> n \<Longrightarrow> fact m \<le> (fact n :: nat)" |
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
72 |
by (induct n) (auto simp: le_Suc_eq) |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
73 |
|
63466 | 74 |
lemma fact_in_Nats: "fact n \<in> \<nat>" |
75 |
by (induct n) auto |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
76 |
|
63466 | 77 |
lemma fact_in_Ints: "fact n \<in> \<int>" |
78 |
by (induct n) auto |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
79 |
|
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
80 |
context |
60241 | 81 |
assumes "SORT_CONSTRAINT('a::linordered_semidom)" |
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
|
82 |
begin |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
83 |
|
63466 | 84 |
lemma fact_mono: "m \<le> n \<Longrightarrow> fact m \<le> (fact n :: 'a)" |
85 |
by (metis of_nat_fact of_nat_le_iff fact_mono_nat) |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
86 |
|
63466 | 87 |
lemma fact_ge_1 [simp]: "fact n \<ge> (1 :: 'a)" |
88 |
by (metis le0 fact_0 fact_mono) |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
89 |
|
63466 | 90 |
lemma fact_gt_zero [simp]: "fact n > (0 :: 'a)" |
91 |
using fact_ge_1 less_le_trans zero_less_one by blast |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
92 |
|
63466 | 93 |
lemma fact_ge_zero [simp]: "fact n \<ge> (0 :: 'a)" |
94 |
by (simp add: less_imp_le) |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
95 |
|
63466 | 96 |
lemma fact_not_neg [simp]: "\<not> fact n < (0 :: 'a)" |
97 |
by (simp add: not_less_iff_gr_or_eq) |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
98 |
|
63466 | 99 |
lemma fact_le_power: "fact n \<le> (of_nat (n^n) :: 'a)" |
100 |
proof (induct n) |
|
101 |
case 0 |
|
102 |
then show ?case by simp |
|
103 |
next |
|
104 |
case (Suc n) |
|
105 |
then have *: "fact n \<le> (of_nat (Suc n ^ n) ::'a)" |
|
106 |
by (rule order_trans) (simp add: power_mono del: of_nat_power) |
|
107 |
have "fact (Suc n) = (of_nat (Suc n) * fact n ::'a)" |
|
108 |
by (simp add: algebra_simps) |
|
109 |
also have "\<dots> \<le> of_nat (Suc n) * of_nat (Suc n ^ n)" |
|
110 |
by (simp add: * ordered_comm_semiring_class.comm_mult_left_mono del: of_nat_power) |
|
111 |
also have "\<dots> \<le> of_nat (Suc n ^ Suc n)" |
|
112 |
by (metis of_nat_mult order_refl power_Suc) |
|
113 |
finally show ?case . |
|
114 |
qed |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
115 |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
116 |
end |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
117 |
|
63466 | 118 |
text \<open>Note that @{term "fact 0 = fact 1"}\<close> |
119 |
lemma fact_less_mono_nat: "0 < m \<Longrightarrow> m < n \<Longrightarrow> fact m < (fact n :: nat)" |
|
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
120 |
by (induct n) (auto simp: less_Suc_eq) |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
121 |
|
63466 | 122 |
lemma fact_less_mono: "0 < m \<Longrightarrow> m < n \<Longrightarrow> fact m < (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
|
123 |
by (metis of_nat_fact of_nat_less_iff fact_less_mono_nat) |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
124 |
|
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
125 |
lemma fact_ge_Suc_0_nat [simp]: "fact n \<ge> Suc 0" |
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
126 |
by (metis One_nat_def fact_ge_1) |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
127 |
|
63466 | 128 |
lemma dvd_fact: "1 \<le> m \<Longrightarrow> m \<le> n \<Longrightarrow> m dvd fact n" |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
129 |
by (induct n) (auto simp: dvdI le_Suc_eq) |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
130 |
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
131 |
lemma fact_ge_self: "fact n \<ge> n" |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
132 |
by (cases "n = 0") (simp_all add: dvd_imp_le dvd_fact) |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
133 |
|
63466 | 134 |
lemma fact_dvd: "n \<le> m \<Longrightarrow> fact n dvd (fact m :: 'a::{semiring_div,linordered_semidom})" |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
135 |
by (induct m) (auto simp: le_Suc_eq) |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
136 |
|
63466 | 137 |
lemma fact_mod: "m \<le> n \<Longrightarrow> fact n mod (fact m :: 'a::{semiring_div,linordered_semidom}) = 0" |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
138 |
by (auto simp add: fact_dvd) |
40033
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
139 |
|
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
140 |
lemma fact_div_fact: |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
141 |
assumes "m \<ge> n" |
63466 | 142 |
shows "fact m div fact n = \<Prod>{n + 1..m}" |
40033
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
143 |
proof - |
63466 | 144 |
obtain d where "d = m - n" |
145 |
by auto |
|
146 |
with assms have "m = n + d" |
|
147 |
by auto |
|
40033
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
148 |
have "fact (n + d) div (fact n) = \<Prod>{n + 1..n + d}" |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
149 |
proof (induct d) |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
150 |
case 0 |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
151 |
show ?case by simp |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
152 |
next |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
153 |
case (Suc d') |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
154 |
have "fact (n + Suc d') div fact n = Suc (n + d') * fact (n + d') div fact n" |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
155 |
by simp |
63466 | 156 |
also from Suc.hyps have "\<dots> = Suc (n + d') * \<Prod>{n + 1..n + d'}" |
40033
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
157 |
unfolding div_mult1_eq[of _ "fact (n + d')"] by (simp add: fact_mod) |
63466 | 158 |
also have "\<dots> = \<Prod>{n + 1..n + Suc d'}" |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
159 |
by (simp add: atLeastAtMostSuc_conv) |
40033
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
160 |
finally show ?case . |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
161 |
qed |
63466 | 162 |
with \<open>m = n + d\<close> show ?thesis by simp |
40033
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
163 |
qed |
84200d970bf0
added some facts about factorial and dvd, div and mod
bulwahn
parents:
35644
diff
changeset
|
164 |
|
63466 | 165 |
lemma fact_num_eq_if: "fact m = (if m = 0 then 1 else of_nat m * fact (m - 1))" |
166 |
by (cases m) auto |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
30242
diff
changeset
|
167 |
|
50240
019d642d422d
add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents:
50224
diff
changeset
|
168 |
lemma fact_div_fact_le_pow: |
63466 | 169 |
assumes "r \<le> n" |
170 |
shows "fact n div fact (n - r) \<le> n ^ r" |
|
50240
019d642d422d
add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents:
50224
diff
changeset
|
171 |
proof - |
63466 | 172 |
have "r \<le> n \<Longrightarrow> \<Prod>{n - r..n} = (n - r) * \<Prod>{Suc (n - r)..n}" for r |
64272 | 173 |
by (subst prod.insert[symmetric]) (auto simp: atLeastAtMost_insertL) |
50240
019d642d422d
add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents:
50224
diff
changeset
|
174 |
with assms show ?thesis |
019d642d422d
add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents:
50224
diff
changeset
|
175 |
by (induct r rule: nat.induct) (auto simp add: fact_div_fact Suc_diff_Suc mult_le_mono) |
019d642d422d
add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents:
50224
diff
changeset
|
176 |
qed |
019d642d422d
add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents:
50224
diff
changeset
|
177 |
|
63466 | 178 |
lemma fact_numeral: "fact (numeral k) = numeral k * fact (pred_numeral k)" |
179 |
\<comment> \<open>Evaluation for specific numerals\<close> |
|
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
180 |
by (metis fact_Suc numeral_eq_Suc of_nat_numeral) |
57113
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
paulson <lp15@cam.ac.uk>
parents:
50240
diff
changeset
|
181 |
|
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 |
|
63373 | 183 |
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
|
184 |
|
63466 | 185 |
text \<open>This development is based on the work of Andy Gordon and Florian Kammueller.\<close> |
186 |
||
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
187 |
text \<open>Combinatorial definition\<close> |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
188 |
|
63466 | 189 |
definition binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat" (infixl "choose" 65) |
190 |
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
|
191 |
|
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
192 |
theorem n_subsets: |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
193 |
assumes "finite A" |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
194 |
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
|
195 |
proof - |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
then have "inj_on (image f) (Pow {0..<card A})" |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
by auto |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
206 |
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
|
207 |
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
|
208 |
then have "card {K. K \<subseteq> {0..<card A} \<and> card K = k} = |
63466 | 209 |
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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
also have "f ` {0..<card A} = A" |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
214 |
by (meson bij bij_betw_def) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
215 |
finally show ?thesis |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
216 |
by (simp add: binomial_def) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
217 |
qed |
63466 | 218 |
|
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
219 |
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
|
220 |
|
63466 | 221 |
lemma binomial_n_0 [simp, code]: "n choose 0 = 1" |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
222 |
proof - |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
223 |
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
|
224 |
by (auto dest: finite_subset) |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
225 |
then show ?thesis |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
226 |
by (simp add: binomial_def) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
227 |
qed |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
228 |
|
63466 | 229 |
lemma binomial_0_Suc [simp, code]: "0 choose Suc k = 0" |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
230 |
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
|
231 |
|
63466 | 232 |
lemma binomial_Suc_Suc [simp, code]: "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
|
233 |
proof - |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
234 |
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
|
235 |
let ?Q = "?P (Suc n) (Suc k)" |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
236 |
have inj: "inj_on (insert n) (?P n k)" |
63466 | 237 |
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
|
238 |
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
|
239 |
by auto |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
240 |
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
|
241 |
by auto |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
242 |
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
|
243 |
proof (rule set_eqI) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
244 |
fix K |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
245 |
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
|
246 |
using that by (rule finite_subset) simp_all |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
247 |
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
|
248 |
and "finite K" |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
249 |
proof - |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
250 |
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
|
251 |
by (blast elim: Set.set_insert) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
252 |
with that show ?thesis by (simp add: card_insert) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
253 |
qed |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
254 |
show "K \<in> ?A \<longleftrightarrow> K \<in> ?B" |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
255 |
by (subst in_image_insert_iff) |
63466 | 256 |
(auto simp add: card_insert subset_eq_atLeast0_lessThan_finite |
257 |
Diff_subset_conv K_finite Suc_card_K) |
|
258 |
qed |
|
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
259 |
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
|
260 |
by (auto simp add: atLeast0_lessThan_Suc) |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
261 |
finally show ?thesis using inj disjoint |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
262 |
by (simp add: binomial_def card_Un_disjoint card_image) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
263 |
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
|
264 |
|
63466 | 265 |
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
|
266 |
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
|
267 |
|
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
268 |
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
|
269 |
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
|
270 |
|
63466 | 271 |
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
|
272 |
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
|
273 |
|
63466 | 274 |
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
|
275 |
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
|
276 |
|
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
|
277 |
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
|
278 |
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
|
279 |
|
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
|
280 |
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
|
281 |
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
|
282 |
|
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
|
283 |
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
|
284 |
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
|
285 |
|
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
286 |
lemma choose_reduce_nat: |
63466 | 287 |
"0 < n \<Longrightarrow> 0 < k \<Longrightarrow> |
288 |
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
|
289 |
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
|
290 |
|
63466 | 291 |
lemma Suc_times_binomial_eq: "Suc n * (n choose k) = (Suc n choose Suc k) * Suc k" |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
292 |
apply (induct n arbitrary: k) |
63466 | 293 |
apply simp |
294 |
apply arith |
|
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
|
295 |
apply (case_tac 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
|
296 |
apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq 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
|
297 |
done |
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
|
298 |
|
60141
833adf7db7d8
New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents:
59867
diff
changeset
|
299 |
lemma binomial_le_pow2: "n choose k \<le> 2^n" |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
300 |
apply (induct n arbitrary: k) |
63466 | 301 |
apply (case_tac k) |
302 |
apply simp_all |
|
60141
833adf7db7d8
New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents:
59867
diff
changeset
|
303 |
apply (case_tac k) |
63466 | 304 |
apply auto |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
305 |
apply (simp add: add_le_mono mult_2) |
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
306 |
done |
60141
833adf7db7d8
New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents:
59867
diff
changeset
|
307 |
|
63466 | 308 |
text \<open>The absorption property.\<close> |
309 |
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
|
310 |
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
|
311 |
|
63466 | 312 |
text \<open>This is the well-known version of absorption, but it's harder to use |
313 |
because of the need to reason about division.\<close> |
|
314 |
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
|
315 |
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
|
316 |
|
63466 | 317 |
text \<open>Another version of absorption, with \<open>-1\<close> instead of \<open>Suc\<close>.\<close> |
318 |
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
|
319 |
using Suc_times_binomial_eq [where n = "n - 1" and k = "k - 1"] |
63648 | 320 |
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
|
321 |
|
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
|
322 |
|
60758 | 323 |
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
|
324 |
|
63466 | 325 |
text \<open>Avigad's version, generalized to any commutative ring\<close> |
326 |
theorem binomial_ring: "(a + b :: 'a::{comm_ring_1,power})^n = |
|
327 |
(\<Sum>k=0..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
|
328 |
proof (induct n) |
63466 | 329 |
case 0 |
330 |
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
|
331 |
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
|
332 |
case (Suc n) |
63466 | 333 |
have decomp: "{0..n+1} = {0} \<union> {n + 1} \<union> {1..n}" |
59658
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
334 |
by auto |
63466 | 335 |
have decomp2: "{0..n} = {0} \<union> {1..n}" |
59658
0cc388370041
sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
336 |
by auto |
63466 | 337 |
have "(a + b)^(n+1) = (a + b) * (\<Sum>k=0..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
|
338 |
using Suc.hyps by simp |
63466 | 339 |
also have "\<dots> = a * (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k)) + |
340 |
b * (\<Sum>k=0..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
|
341 |
by (rule distrib_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
|
342 |
also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^(k+1) * b^(n-k)) + |
63466 | 343 |
(\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n - k + 1))" |
64267 | 344 |
by (auto simp add: sum_distrib_left ac_simps) |
63466 | 345 |
also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n + 1 - k)) + |
346 |
(\<Sum>k=1..n+1. of_nat (n choose (k - 1)) * a^k * b^(n + 1 - k))" |
|
64267 | 347 |
by (simp add:sum_shift_bounds_cl_Suc_ivl Suc_diff_le field_simps del: sum_cl_ivl_Suc) |
63466 | 348 |
also have "\<dots> = a^(n + 1) + b^(n + 1) + |
349 |
(\<Sum>k=1..n. of_nat (n choose (k - 1)) * a^k * b^(n + 1 - k)) + |
|
350 |
(\<Sum>k=1..n. of_nat (n choose k) * a^k * b^(n + 1 - 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
|
351 |
by (simp add: decomp2) |
63466 | 352 |
also have "\<dots> = a^(n + 1) + b^(n + 1) + |
353 |
(\<Sum>k=1..n. of_nat (n + 1 choose k) * a^k * b^(n + 1 - k))" |
|
64267 | 354 |
by (auto simp add: field_simps sum.distrib [symmetric] choose_reduce_nat) |
63466 | 355 |
also have "\<dots> = (\<Sum>k=0..n+1. of_nat (n + 1 choose k) * a^k * b^(n + 1 - 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
|
356 |
using decomp by (simp add: field_simps) |
63466 | 357 |
finally show ?case |
358 |
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
|
359 |
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
|
360 |
|
63466 | 361 |
text \<open>Original version for the naturals.\<close> |
362 |
corollary binomial: "(a + b :: nat)^n = (\<Sum>k=0..n. (of_nat (n choose k)) * a^k * b^(n - k))" |
|
363 |
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
|
364 |
by (simp only: of_nat_add [symmetric] of_nat_mult [symmetric] of_nat_power [symmetric] |
64267 | 365 |
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
|
366 |
|
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
|
367 |
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
|
368 |
proof (induct n arbitrary: k rule: nat_less_induct) |
63466 | 369 |
fix n k |
370 |
assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) = fact m" |
|
371 |
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
|
372 |
let ?ths = "fact k * fact (n - k) * (n choose k) = fact n" |
63466 | 373 |
consider "n = 0 \<or> k = 0 \<or> n = k" | m h where "n = Suc m" "k = Suc h" "h < m" |
374 |
using kn by atomize_elim presburger |
|
375 |
then show "fact k * fact (n - k) * (n choose k) = fact n" |
|
376 |
proof cases |
|
377 |
case 1 |
|
378 |
with kn show ?thesis by auto |
|
379 |
next |
|
380 |
case 2 |
|
381 |
note n = \<open>n = Suc m\<close> |
|
382 |
note k = \<open>k = Suc h\<close> |
|
383 |
note hm = \<open>h < m\<close> |
|
384 |
have mn: "m < n" |
|
385 |
using n by arith |
|
386 |
have hm': "h \<le> m" |
|
387 |
using hm by arith |
|
388 |
have km: "k \<le> m" |
|
389 |
using hm k n kn by arith |
|
390 |
have "m - h = Suc (m - Suc h)" |
|
391 |
using k km hm by arith |
|
392 |
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
|
393 |
by simp |
63466 | 394 |
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
|
395 |
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
|
396 |
(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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
by (simp add: field_simps) |
63466 | 401 |
finally show ?thesis |
402 |
using k n km by simp |
|
403 |
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
|
404 |
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
|
405 |
|
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
406 |
lemma binomial_fact': |
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
407 |
assumes "k \<le> n" |
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
408 |
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
|
409 |
using binomial_fact_lemma [OF assms] |
64240 | 410 |
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
|
411 |
|
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
|
412 |
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
|
413 |
assumes kn: "k \<le> n" |
63466 | 414 |
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
|
415 |
using binomial_fact_lemma[OF kn] |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
416 |
apply (simp add: field_simps) |
63466 | 417 |
apply (metis mult.commute of_nat_fact of_nat_mult) |
418 |
done |
|
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
|
419 |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
420 |
lemma fact_binomial: |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
421 |
assumes "k \<le> n" |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
422 |
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
|
423 |
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
|
424 |
|
63466 | 425 |
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
|
426 |
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
|
427 |
case False |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
428 |
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
|
429 |
by auto |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
430 |
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
|
431 |
next |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
432 |
case True |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
433 |
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
|
434 |
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
|
435 |
by simp |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
436 |
then have "fact n = n * (n - 1) * fact (n - 2)" |
64272 | 437 |
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
|
438 |
with True show ?thesis |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
439 |
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
|
440 |
qed |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
441 |
|
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
|
442 |
lemma choose_row_sum: "(\<Sum>k=0..n. n choose k) = 2^n" |
63466 | 443 |
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
|
444 |
|
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
|
445 |
lemma sum_choose_lower: "(\<Sum>k=0..n. (r+k) choose k) = Suc (r+n) choose 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
|
446 |
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
|
447 |
|
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
|
448 |
lemma sum_choose_upper: "(\<Sum>k=0..n. k choose m) = Suc n choose Suc m" |
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
|
449 |
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
|
450 |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
451 |
lemma choose_alternating_sum: |
63466 | 452 |
"n > 0 \<Longrightarrow> (\<Sum>i\<le>n. (-1)^i * of_nat (n choose i)) = (0 :: 'a::comm_ring_1)" |
453 |
using binomial_ring[of "-1 :: 'a" 1 n] |
|
454 |
by (simp add: atLeast0AtMost mult_of_nat_commute zero_power) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
455 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
456 |
lemma choose_even_sum: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
457 |
assumes "n > 0" |
63466 | 458 |
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
|
459 |
proof - |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
460 |
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
|
461 |
using choose_row_sum[of n] |
64267 | 462 |
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
|
463 |
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) + (-1) ^ i * of_nat (n choose i))" |
64267 | 464 |
by (simp add: sum.distrib) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
465 |
also have "\<dots> = 2 * (\<Sum>i\<le>n. if even i then of_nat (n choose i) else 0)" |
64267 | 466 |
by (subst sum_distrib_left, intro sum.cong) simp_all |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
467 |
finally show ?thesis .. |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
468 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
469 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
470 |
lemma choose_odd_sum: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
471 |
assumes "n > 0" |
63466 | 472 |
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
|
473 |
proof - |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
474 |
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
|
475 |
using choose_row_sum[of n] |
64267 | 476 |
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
|
477 |
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) - (-1) ^ i * of_nat (n choose i))" |
64267 | 478 |
by (simp add: sum_subtractf) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
479 |
also have "\<dots> = 2 * (\<Sum>i\<le>n. if odd i then of_nat (n choose i) else 0)" |
64267 | 480 |
by (subst sum_distrib_left, intro sum.cong) simp_all |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
481 |
finally show ?thesis .. |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
482 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
483 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
484 |
lemma choose_row_sum': "(\<Sum>k\<le>n. (n choose k)) = 2 ^ n" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
485 |
using choose_row_sum[of n] by (simp add: atLeast0AtMost) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
486 |
|
60758 | 487 |
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
|
488 |
lemma sum_choose_diagonal: |
63466 | 489 |
assumes "m \<le> n" |
490 |
shows "(\<Sum>k=0..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
|
491 |
proof - |
63466 | 492 |
have "(\<Sum>k=0..m. (n-k) choose (m - k)) = (\<Sum>k=0..m. (n - m + k) choose k)" |
64267 | 493 |
using sum.atLeast_atMost_rev [of "\<lambda>k. (n - k) choose (m - k)" 0 m] assms |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
494 |
by simp |
63466 | 495 |
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
|
496 |
by (rule sum_choose_lower) |
63466 | 497 |
also have "\<dots> = Suc n choose m" |
498 |
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
|
499 |
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
|
500 |
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
|
501 |
|
63373 | 502 |
|
63466 | 503 |
subsection \<open>Pochhammer's symbol: generalized rising factorial\<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
|
504 |
|
63680 | 505 |
text \<open>See \<^url>\<open>http://en.wikipedia.org/wiki/Pochhammer_symbol\<close>.\<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
|
506 |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
507 |
context comm_semiring_1 |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
508 |
begin |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
509 |
|
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
510 |
definition pochhammer :: "'a \<Rightarrow> nat \<Rightarrow> 'a" |
64272 | 511 |
where pochhammer_prod: "pochhammer a n = prod (\<lambda>i. a + of_nat i) {0..<n}" |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
512 |
|
64272 | 513 |
lemma pochhammer_prod_rev: "pochhammer a n = prod (\<lambda>i. a + of_nat (n - i)) {1..n}" |
514 |
using prod.atLeast_lessThan_rev_at_least_Suc_atMost [of "\<lambda>i. a + of_nat i" 0 n] |
|
515 |
by (simp add: pochhammer_prod) |
|
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
|
516 |
|
64272 | 517 |
lemma pochhammer_Suc_prod: "pochhammer a (Suc n) = prod (\<lambda>i. a + of_nat i) {0..n}" |
518 |
by (simp add: pochhammer_prod atLeastLessThanSuc_atLeastAtMost) |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
519 |
|
64272 | 520 |
lemma pochhammer_Suc_prod_rev: "pochhammer a (Suc n) = prod (\<lambda>i. a + of_nat (n - i)) {0..n}" |
521 |
by (simp add: pochhammer_prod_rev prod.atLeast_Suc_atMost_Suc_shift) |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
522 |
|
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
|
523 |
lemma pochhammer_0 [simp]: "pochhammer a 0 = 1" |
64272 | 524 |
by (simp add: pochhammer_prod) |
63466 | 525 |
|
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
|
526 |
lemma pochhammer_1 [simp]: "pochhammer a 1 = a" |
64272 | 527 |
by (simp add: pochhammer_prod lessThan_Suc) |
63466 | 528 |
|
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
|
529 |
lemma pochhammer_Suc0 [simp]: "pochhammer a (Suc 0) = a" |
64272 | 530 |
by (simp add: pochhammer_prod lessThan_Suc) |
63466 | 531 |
|
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
532 |
lemma pochhammer_Suc: "pochhammer a (Suc n) = pochhammer a n * (a + of_nat n)" |
64272 | 533 |
by (simp add: pochhammer_prod atLeast0_lessThan_Suc ac_simps) |
63466 | 534 |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
535 |
end |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
536 |
|
63725
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
537 |
lemma pochhammer_nonneg: |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
538 |
fixes x :: "'a :: linordered_semidom" |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
539 |
shows "x > 0 \<Longrightarrow> pochhammer x n \<ge> 0" |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
540 |
by (induction n) (auto simp: pochhammer_Suc intro!: mult_nonneg_nonneg add_nonneg_nonneg) |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
541 |
|
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
542 |
lemma pochhammer_pos: |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
543 |
fixes x :: "'a :: linordered_semidom" |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
544 |
shows "x > 0 \<Longrightarrow> pochhammer x n > 0" |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
545 |
by (induction n) (auto simp: pochhammer_Suc intro!: mult_pos_pos add_pos_nonneg) |
4c00ba1ad11a
Bohr-Mollerup theorem for the Gamma function
Manuel Eberl <eberlm@in.tum.de>
parents:
63680
diff
changeset
|
546 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
547 |
lemma pochhammer_of_nat: "pochhammer (of_nat x) n = of_nat (pochhammer x n)" |
64272 | 548 |
by (simp add: pochhammer_prod) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
549 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
550 |
lemma pochhammer_of_int: "pochhammer (of_int x) n = of_int (pochhammer x n)" |
64272 | 551 |
by (simp add: pochhammer_prod) |
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
|
552 |
|
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
|
553 |
lemma pochhammer_rec: "pochhammer a (Suc n) = a * pochhammer (a + 1) n" |
64272 | 554 |
by (simp add: pochhammer_prod prod.atLeast0_lessThan_Suc_shift 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
|
555 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
556 |
lemma pochhammer_rec': "pochhammer z (Suc n) = (z + of_nat n) * pochhammer z n" |
64272 | 557 |
by (simp add: pochhammer_prod prod.atLeast0_lessThan_Suc ac_simps) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
558 |
|
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
559 |
lemma pochhammer_fact: "fact n = pochhammer 1 n" |
64272 | 560 |
by (simp add: pochhammer_prod fact_prod_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
|
561 |
|
63466 | 562 |
lemma pochhammer_of_nat_eq_0_lemma: "k > n \<Longrightarrow> pochhammer (- (of_nat n :: 'a:: idom)) k = 0" |
64272 | 563 |
by (auto simp add: pochhammer_prod) |
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
|
564 |
|
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
|
565 |
lemma pochhammer_of_nat_eq_0_lemma': |
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
|
566 |
assumes kn: "k \<le> n" |
63466 | 567 |
shows "pochhammer (- (of_nat n :: 'a::{idom,ring_char_0})) k \<noteq> 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
|
568 |
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
|
569 |
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
|
570 |
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
|
571 |
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
|
572 |
case (Suc h) |
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
|
573 |
then show ?thesis |
64272 | 574 |
apply (simp add: pochhammer_Suc_prod) |
63466 | 575 |
using Suc kn |
576 |
apply (auto simp add: 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
|
577 |
done |
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
|
578 |
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
|
579 |
|
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
|
580 |
lemma pochhammer_of_nat_eq_0_iff: |
63466 | 581 |
"pochhammer (- (of_nat n :: 'a::{idom,ring_char_0})) k = 0 \<longleftrightarrow> k > 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
|
582 |
(is "?l = ?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
|
583 |
using pochhammer_of_nat_eq_0_lemma[of n k, where ?'a='a] |
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
|
584 |
pochhammer_of_nat_eq_0_lemma'[of k n, where ?'a = 'a] |
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
|
585 |
by (auto simp add: not_le[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
|
586 |
|
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
|
587 |
lemma pochhammer_eq_0_iff: "pochhammer a n = (0::'a::field_char_0) \<longleftrightarrow> (\<exists>k < n. a = - of_nat k)" |
64272 | 588 |
by (auto simp add: pochhammer_prod eq_neg_iff_add_eq_0) |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
589 |
|
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
|
590 |
lemma pochhammer_eq_0_mono: |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
591 |
"pochhammer a n = (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a m = 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
|
592 |
unfolding pochhammer_eq_0_iff by 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
|
593 |
|
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
|
594 |
lemma pochhammer_neq_0_mono: |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
595 |
"pochhammer a m \<noteq> (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a n \<noteq> 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
|
596 |
unfolding pochhammer_eq_0_iff by 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
|
597 |
|
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
|
598 |
lemma pochhammer_minus: |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
599 |
"pochhammer (- b) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (b - of_nat k + 1) 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
|
600 |
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
|
601 |
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
|
602 |
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
|
603 |
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
|
604 |
case (Suc h) |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
605 |
have eq: "((- 1) ^ Suc h :: 'a) = (\<Prod>i = 0..h. - 1)" |
64272 | 606 |
using prod_constant [where A="{0.. h}" and y="- 1 :: '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
|
607 |
by auto |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
608 |
with Suc show ?thesis |
64272 | 609 |
using pochhammer_Suc_prod_rev [of "b - of_nat k + 1"] |
610 |
by (auto simp add: pochhammer_Suc_prod prod.distrib [symmetric] eq 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
|
611 |
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
|
612 |
|
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
|
613 |
lemma pochhammer_minus': |
63466 | 614 |
"pochhammer (b - of_nat k + 1) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (- b) k" |
615 |
apply (simp only: pochhammer_minus [where b = b]) |
|
616 |
apply (simp only: mult.assoc [symmetric]) |
|
617 |
apply (simp only: power_add [symmetric]) |
|
618 |
apply simp |
|
619 |
done |
|
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
|
620 |
|
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
|
621 |
lemma pochhammer_same: "pochhammer (- of_nat n) n = |
63466 | 622 |
((- 1) ^ n :: 'a::{semiring_char_0,comm_ring_1,semiring_no_zero_divisors}) * fact n" |
59862 | 623 |
unfolding pochhammer_minus |
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
|
624 |
by (simp add: of_nat_diff pochhammer_fact) |
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
|
625 |
|
63466 | 626 |
lemma pochhammer_product': "pochhammer z (n + m) = pochhammer z n * pochhammer (z + of_nat n) m" |
627 |
proof (induct n arbitrary: z) |
|
628 |
case 0 |
|
629 |
then show ?case by simp |
|
630 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
631 |
case (Suc n z) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
632 |
have "pochhammer z (Suc n) * pochhammer (z + of_nat (Suc n)) m = |
63466 | 633 |
z * (pochhammer (z + 1) n * pochhammer (z + 1 + of_nat n) m)" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
634 |
by (simp add: pochhammer_rec ac_simps) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
635 |
also note Suc[symmetric] |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
636 |
also have "z * pochhammer (z + 1) (n + m) = pochhammer z (Suc (n + m))" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
637 |
by (subst pochhammer_rec) simp |
63466 | 638 |
finally show ?case |
639 |
by simp |
|
640 |
qed |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
641 |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
642 |
lemma pochhammer_product: |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
643 |
"m \<le> n \<Longrightarrow> pochhammer z n = pochhammer z m * pochhammer (z + of_nat m) (n - m)" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
644 |
using pochhammer_product'[of z m "n - m"] by simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
645 |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
646 |
lemma pochhammer_times_pochhammer_half: |
63466 | 647 |
fixes z :: "'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
|
648 |
shows "pochhammer z (Suc n) * pochhammer (z + 1/2) (Suc n) = (\<Prod>k=0..2*n+1. z + of_nat k / 2)" |
63466 | 649 |
proof (induct n) |
650 |
case 0 |
|
651 |
then show ?case |
|
652 |
by (simp add: atLeast0_atMost_Suc) |
|
653 |
next |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
654 |
case (Suc n) |
63040 | 655 |
define n' where "n' = Suc n" |
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
656 |
have "pochhammer z (Suc n') * pochhammer (z + 1 / 2) (Suc n') = |
63466 | 657 |
(pochhammer z n' * pochhammer (z + 1 / 2) n') * ((z + of_nat n') * (z + 1/2 + of_nat n'))" |
658 |
(is "_ = _ * ?A") |
|
659 |
by (simp_all add: pochhammer_rec' mult_ac) |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
660 |
also have "?A = (z + of_nat (Suc (2 * n + 1)) / 2) * (z + of_nat (Suc (Suc (2 * n + 1))) / 2)" |
63466 | 661 |
(is "_ = ?B") |
662 |
by (simp add: field_simps n'_def) |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
663 |
also note Suc[folded n'_def] |
63466 | 664 |
also have "(\<Prod>k=0..2 * n + 1. z + of_nat k / 2) * ?B = (\<Prod>k=0..2 * Suc n + 1. z + of_nat k / 2)" |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
665 |
by (simp add: atLeast0_atMost_Suc) |
63466 | 666 |
finally show ?case |
667 |
by (simp add: n'_def) |
|
668 |
qed |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
669 |
|
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
670 |
lemma pochhammer_double: |
63466 | 671 |
fixes z :: "'a::field_char_0" |
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
672 |
shows "pochhammer (2 * z) (2 * n) = of_nat (2^(2*n)) * pochhammer z n * pochhammer (z+1/2) n" |
63466 | 673 |
proof (induct n) |
674 |
case 0 |
|
675 |
then show ?case by simp |
|
676 |
next |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
677 |
case (Suc n) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
678 |
have "pochhammer (2 * z) (2 * (Suc n)) = pochhammer (2 * z) (2 * n) * |
63466 | 679 |
(2 * (z + of_nat n)) * (2 * (z + of_nat n) + 1)" |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
680 |
by (simp add: pochhammer_rec' ac_simps) |
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
681 |
also note Suc |
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
682 |
also have "of_nat (2 ^ (2 * n)) * pochhammer z n * pochhammer (z + 1/2) n * |
63466 | 683 |
(2 * (z + of_nat n)) * (2 * (z + of_nat n) + 1) = |
684 |
of_nat (2 ^ (2 * (Suc n))) * pochhammer z (Suc n) * pochhammer (z + 1/2) (Suc n)" |
|
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
685 |
by (simp add: field_simps pochhammer_rec') |
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
686 |
finally show ?case . |
63466 | 687 |
qed |
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
688 |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63092
diff
changeset
|
689 |
lemma fact_double: |
63466 | 690 |
"fact (2 * n) = (2 ^ (2 * n) * pochhammer (1 / 2) n * fact n :: 'a::field_char_0)" |
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63092
diff
changeset
|
691 |
using pochhammer_double[of "1/2::'a" n] by (simp add: pochhammer_fact) |
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63092
diff
changeset
|
692 |
|
63466 | 693 |
lemma pochhammer_absorb_comp: "(r - of_nat k) * pochhammer (- r) k = r * pochhammer (-r + 1) k" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
694 |
(is "?lhs = ?rhs") |
63466 | 695 |
for r :: "'a::comm_ring_1" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
696 |
proof - |
63466 | 697 |
have "?lhs = - pochhammer (- r) (Suc k)" |
698 |
by (subst pochhammer_rec') (simp add: algebra_simps) |
|
699 |
also have "\<dots> = ?rhs" |
|
700 |
by (subst pochhammer_rec) simp |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
701 |
finally show ?thesis . |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
702 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
703 |
|
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
|
704 |
|
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
705 |
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
|
706 |
|
63466 | 707 |
definition gbinomial :: "'a::{semidom_divide,semiring_char_0} \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65) |
64272 | 708 |
where gbinomial_prod_rev: "a gchoose n = prod (\<lambda>i. a - of_nat i) {0..<n} div fact n" |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
709 |
|
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
710 |
lemma gbinomial_0 [simp]: |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
711 |
"a gchoose 0 = 1" |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
712 |
"0 gchoose (Suc n) = 0" |
64272 | 713 |
by (simp_all add: gbinomial_prod_rev prod.atLeast0_lessThan_Suc_shift) |
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
714 |
|
64272 | 715 |
lemma gbinomial_Suc: "a gchoose (Suc k) = prod (\<lambda>i. a - of_nat i) {0..k} div fact (Suc k)" |
716 |
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
|
717 |
|
63466 | 718 |
lemma gbinomial_mult_fact: "fact n * (a gchoose n) = (\<Prod>i = 0..<n. a - of_nat i)" |
719 |
for a :: "'a::field_char_0" |
|
64272 | 720 |
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
|
721 |
|
63466 | 722 |
lemma gbinomial_mult_fact': "(a gchoose n) * fact n = (\<Prod>i = 0..<n. a - of_nat i)" |
723 |
for a :: "'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
|
724 |
using gbinomial_mult_fact [of n 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
|
725 |
|
63466 | 726 |
lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / fact n" |
727 |
for a :: "'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
|
728 |
by (cases n) |
63466 | 729 |
(simp_all add: pochhammer_minus, |
64272 | 730 |
simp_all add: gbinomial_prod_rev pochhammer_prod_rev |
63466 | 731 |
power_mult_distrib [symmetric] atLeastLessThanSuc_atLeastAtMost |
64272 | 732 |
prod.atLeast_Suc_atMost_Suc_shift 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
|
733 |
|
63466 | 734 |
lemma gbinomial_pochhammer': "s gchoose n = pochhammer (s - of_nat n + 1) n / fact n" |
735 |
for s :: "'a::field_char_0" |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
736 |
proof - |
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
737 |
have "s gchoose n = ((-1)^n * (-1)^n) * pochhammer (s - of_nat n + 1) n / fact n" |
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
738 |
by (simp add: gbinomial_pochhammer pochhammer_minus mult_ac) |
63466 | 739 |
also have "(-1 :: 'a)^n * (-1)^n = 1" |
740 |
by (subst power_add [symmetric]) simp |
|
741 |
finally show ?thesis |
|
742 |
by simp |
|
61552
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
743 |
qed |
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents:
61531
diff
changeset
|
744 |
|
63466 | 745 |
lemma gbinomial_binomial: "n gchoose k = n choose k" |
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
746 |
proof (cases "k \<le> n") |
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
747 |
case False |
63466 | 748 |
then have "n < k" |
749 |
by (simp add: not_le) |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
750 |
then have "0 \<in> (op - n) ` {0..<k}" |
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
751 |
by auto |
64272 | 752 |
then have "prod (op - n) {0..<k} = 0" |
753 |
by (auto intro: prod_zero) |
|
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
754 |
with \<open>n < k\<close> show ?thesis |
64272 | 755 |
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
|
756 |
next |
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
757 |
case True |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
758 |
then have "inj_on (op - n) {0..<k}" |
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
759 |
by (auto intro: inj_onI) |
64272 | 760 |
then have "\<Prod>(op - n ` {0..<k}) = prod (op - n) {0..<k}" |
761 |
by (auto dest: prod.reindex) |
|
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
762 |
also have "op - n ` {0..<k} = {Suc (n - k)..n}" |
63466 | 763 |
using True by (auto simp add: image_def Bex_def) presburger (* FIXME slow *) |
64272 | 764 |
finally have *: "prod (\<lambda>q. n - q) {0..<k} = \<Prod>{Suc (n - k)..n}" .. |
63466 | 765 |
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
|
766 |
by (rule binomial_fact') |
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
767 |
with * show ?thesis |
64272 | 768 |
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
|
769 |
qed |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
770 |
|
63466 | 771 |
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
|
772 |
proof (cases "k \<le> n") |
63466 | 773 |
case False |
774 |
then show ?thesis |
|
64272 | 775 |
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
|
776 |
next |
63466 | 777 |
case True |
778 |
define m where "m = n - k" |
|
779 |
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
|
780 |
by arith |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
781 |
from n have "fact n = ((\<Prod>i = 0..<m + k. of_nat (m + k - i) ):: 'a)" |
64272 | 782 |
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
|
783 |
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
|
784 |
by (simp add: ivl_disj_un) |
63466 | 785 |
finally have "fact n = (fact m * (\<Prod>i = 0..<k. of_nat m + of_nat k - of_nat i) :: 'a)" |
64272 | 786 |
using prod_shift_bounds_nat_ivl [of "\<lambda>i. of_nat (m + k - i) :: 'a" 0 k m] |
787 |
by (simp add: fact_prod_rev [of m] prod.union_disjoint of_nat_diff) |
|
63466 | 788 |
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
|
789 |
by (simp add: n) |
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
790 |
with True have "fact k * of_nat (n gchoose k) = (fact k * (of_nat n gchoose k) :: 'a)" |
63466 | 791 |
by (simp only: gbinomial_mult_fact [of k "of_nat n"] gbinomial_binomial [of n k] fact_binomial) |
792 |
then show ?thesis |
|
793 |
by simp |
|
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
794 |
qed |
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
795 |
|
63466 | 796 |
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
|
797 |
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
|
798 |
|
63466 | 799 |
setup |
800 |
\<open>Sign.add_const_constraint (@{const_name gbinomial}, SOME @{typ "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a"})\<close> |
|
63372
492b49535094
relating gbinomial and binomial, still using distinct definitions
haftmann
parents:
63367
diff
changeset
|
801 |
|
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
|
802 |
lemma gbinomial_1[simp]: "a gchoose 1 = a" |
64272 | 803 |
by (simp add: gbinomial_prod_rev lessThan_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
|
804 |
|
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
|
805 |
lemma gbinomial_Suc0[simp]: "a gchoose (Suc 0) = a" |
64272 | 806 |
by (simp add: gbinomial_prod_rev lessThan_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
|
807 |
|
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
|
808 |
lemma gbinomial_mult_1: |
63466 | 809 |
fixes a :: "'a::field_char_0" |
810 |
shows "a * (a gchoose n) = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))" |
|
811 |
(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
|
812 |
proof - |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
813 |
have "?r = ((- 1) ^n * pochhammer (- a) n / (fact n)) * (of_nat n - (- a + of_nat n))" |
63466 | 814 |
apply (simp only: gbinomial_pochhammer pochhammer_Suc right_diff_distrib power_Suc) |
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
815 |
apply (simp del: of_nat_Suc fact_Suc) |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
816 |
apply (auto simp add: field_simps simp del: of_nat_Suc) |
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
817 |
done |
63466 | 818 |
also have "\<dots> = ?l" |
819 |
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
|
820 |
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
|
821 |
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
|
822 |
|
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
|
823 |
lemma gbinomial_mult_1': |
63466 | 824 |
"(a gchoose n) * a = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))" |
825 |
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
|
826 |
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
|
827 |
|
63466 | 828 |
lemma gbinomial_Suc_Suc: "(a + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))" |
829 |
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
|
830 |
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
|
831 |
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
|
832 |
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
|
833 |
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
|
834 |
case (Suc h) |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
835 |
have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)" |
64272 | 836 |
apply (rule prod.reindex_cong [where l = 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
|
837 |
using Suc |
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
838 |
apply (auto simp add: image_Suc_atMost) |
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
|
839 |
done |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
840 |
have "fact (Suc k) * (a gchoose k + (a gchoose (Suc k))) = |
63466 | 841 |
(a gchoose Suc h) * (fact (Suc (Suc h))) + |
842 |
(a gchoose Suc (Suc h)) * (fact (Suc (Suc h)))" |
|
63367
6c731c8b7f03
simplified definitions of combinatorial functions
haftmann
parents:
63366
diff
changeset
|
843 |
by (simp add: Suc field_simps del: fact_Suc) |
63466 | 844 |
also have "\<dots> = |
845 |
(a gchoose Suc h) * of_nat (Suc (Suc h) * fact (Suc h)) + (\<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
|
846 |
apply (simp del: fact_Suc add: gbinomial_mult_fact field_simps mult.left_commute [of _ "2"]) |
63466 | 847 |
apply (simp del: fact_Suc add: fact_Suc [of "Suc h"] field_simps gbinomial_mult_fact |
848 |
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
|
849 |
done |
63466 | 850 |
also have "\<dots> = |
851 |
(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
|
852 |
by (simp only: fact_Suc mult.commute mult.left_commute of_nat_fact of_nat_id of_nat_mult) |
63466 | 853 |
also have "\<dots> = |
854 |
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
|
855 |
unfolding gbinomial_mult_fact atLeastLessThanSuc_atLeastAtMost by auto |
63466 | 856 |
also have "\<dots> = |
857 |
(\<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
|
858 |
by (simp add: field_simps) |
63466 | 859 |
also have "\<dots> = |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
860 |
((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
|
861 |
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
|
862 |
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
|
863 |
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
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
using eq0 |
64272 | 868 |
by (simp add: Suc prod.atLeast0_atMost_Suc_shift) |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
869 |
also have "\<dots> = (fact (Suc k)) * ((a + 1) gchoose (Suc k))" |
63466 | 870 |
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
|
871 |
finally show ?thesis |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
872 |
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
|
873 |
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
|
874 |
|
63466 | 875 |
lemma gbinomial_reduce_nat: "0 < k \<Longrightarrow> a gchoose k = (a - 1) gchoose (k - 1) + ((a - 1) gchoose k)" |
876 |
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
|
877 |
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
|
878 |
|
60141
833adf7db7d8
New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents:
59867
diff
changeset
|
879 |
lemma gchoose_row_sum_weighted: |
63466 | 880 |
"(\<Sum>k = 0..m. (r gchoose k) * (r/2 - of_nat k)) = of_nat(Suc m) / 2 * (r gchoose (Suc m))" |
881 |
for r :: "'a::field_char_0" |
|
882 |
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
|
883 |
|
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
|
884 |
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
|
885 |
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
|
886 |
shows "n choose k = n choose (n - k)" |
63466 | 887 |
proof - |
888 |
have kn': "n - k \<le> n" |
|
889 |
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
|
890 |
from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn'] |
63466 | 891 |
have "fact k * fact (n - k) * (n choose k) = fact (n - k) * fact (n - (n - k)) * (n choose (n - k))" |
892 |
by simp |
|
893 |
then show ?thesis |
|
894 |
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
|
895 |
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
|
896 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
897 |
lemma choose_rising_sum: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
898 |
"(\<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
|
899 |
"(\<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
|
900 |
proof - |
63466 | 901 |
show "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose (n + 1))" |
902 |
by (induct m) simp_all |
|
903 |
also have "\<dots> = (n + m + 1) choose m" |
|
904 |
by (subst binomial_symmetric) simp_all |
|
905 |
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
|
906 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
907 |
|
63466 | 908 |
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
|
909 |
proof (cases n) |
63466 | 910 |
case 0 |
911 |
then show ?thesis by simp |
|
912 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
913 |
case (Suc m) |
63466 | 914 |
have "(\<Sum>i\<le>n. i * (n choose i)) = (\<Sum>i\<le>Suc m. i * (Suc m choose i))" |
915 |
by (simp add: Suc) |
|
916 |
also have "\<dots> = Suc m * 2 ^ m" |
|
64267 | 917 |
by (simp only: sum_atMost_Suc_shift Suc_times_binomial sum_distrib_left[symmetric]) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
918 |
(simp add: choose_row_sum') |
63466 | 919 |
finally show ?thesis |
920 |
using Suc by simp |
|
921 |
qed |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
922 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
923 |
lemma choose_alternating_linear_sum: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
924 |
assumes "n \<noteq> 1" |
63466 | 925 |
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
|
926 |
proof (cases n) |
63466 | 927 |
case 0 |
928 |
then show ?thesis by simp |
|
929 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
930 |
case (Suc m) |
63466 | 931 |
with assms have "m > 0" |
932 |
by simp |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
933 |
have "(\<Sum>i\<le>n. (-1) ^ i * of_nat i * of_nat (n choose i) :: 'a) = |
63466 | 934 |
(\<Sum>i\<le>Suc m. (-1) ^ i * of_nat i * of_nat (Suc m choose i))" |
935 |
by (simp add: Suc) |
|
936 |
also have "\<dots> = (\<Sum>i\<le>m. (-1) ^ (Suc i) * of_nat (Suc i * (Suc m choose Suc i)))" |
|
64267 | 937 |
by (simp only: sum_atMost_Suc_shift sum_distrib_left[symmetric] mult_ac of_nat_mult) simp |
63466 | 938 |
also have "\<dots> = - of_nat (Suc m) * (\<Sum>i\<le>m. (-1) ^ i * of_nat (m choose i))" |
64267 | 939 |
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
|
940 |
(simp add: algebra_simps) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
941 |
also have "(\<Sum>i\<le>m. (-1 :: 'a) ^ i * of_nat ((m choose i))) = 0" |
61799 | 942 |
using choose_alternating_sum[OF \<open>m > 0\<close>] by simp |
63466 | 943 |
finally show ?thesis |
944 |
by simp |
|
945 |
qed |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
946 |
|
63466 | 947 |
lemma vandermonde: "(\<Sum>k\<le>r. (m choose k) * (n choose (r - k))) = (m + n) choose r" |
948 |
proof (induct n arbitrary: r) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
949 |
case 0 |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
950 |
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 | 951 |
by (intro sum.cong) simp_all |
63466 | 952 |
also have "\<dots> = m choose r" |
64267 | 953 |
by (simp add: sum.delta) |
63466 | 954 |
finally show ?case |
955 |
by simp |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
956 |
next |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
957 |
case (Suc n r) |
63466 | 958 |
show ?case |
64267 | 959 |
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
|
960 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
961 |
|
63466 | 962 |
lemma choose_square_sum: "(\<Sum>k\<le>n. (n choose k)^2) = ((2*n) choose n)" |
963 |
using vandermonde[of n n n] |
|
964 |
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
|
965 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
966 |
lemma pochhammer_binomial_sum: |
63466 | 967 |
fixes a b :: "'a::comm_ring_1" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
968 |
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
|
969 |
proof (induction n arbitrary: a b) |
63466 | 970 |
case 0 |
971 |
then show ?case by simp |
|
972 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
973 |
case (Suc n a b) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
974 |
have "(\<Sum>k\<le>Suc n. of_nat (Suc n choose k) * pochhammer a k * pochhammer b (Suc n - k)) = |
63466 | 975 |
(\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) + |
976 |
((\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) + |
|
977 |
pochhammer b (Suc n))" |
|
64267 | 978 |
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
|
979 |
also have "(\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) = |
63466 | 980 |
a * pochhammer ((a + 1) + b) n" |
64267 | 981 |
by (subst Suc) (simp add: sum_distrib_left pochhammer_rec mult_ac) |
63466 | 982 |
also have "(\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) + |
983 |
pochhammer b (Suc n) = |
|
984 |
(\<Sum>i=0..Suc n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))" |
|
64267 | 985 |
apply (subst sum_head_Suc) |
63466 | 986 |
apply simp |
64267 | 987 |
apply (subst sum_shift_bounds_cl_Suc_ivl) |
63466 | 988 |
apply (simp add: atLeast0AtMost) |
989 |
done |
|
990 |
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))" |
|
64267 | 991 |
using Suc by (intro sum.mono_neutral_right) (auto simp: not_le binomial_eq_0) |
63466 | 992 |
also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc (n - i)))" |
64267 | 993 |
by (intro sum.cong) (simp_all add: Suc_diff_le) |
63466 | 994 |
also have "\<dots> = b * pochhammer (a + (b + 1)) n" |
64267 | 995 |
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
|
996 |
also have "a * pochhammer ((a + 1) + b) n + b * pochhammer (a + (b + 1)) n = |
63466 | 997 |
pochhammer (a + b) (Suc n)" |
998 |
by (simp add: pochhammer_rec algebra_simps) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
999 |
finally show ?case .. |
63466 | 1000 |
qed |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1001 |
|
63466 | 1002 |
text \<open>Contributed by Manuel Eberl, generalised by LCP. |
1003 |
Alternative definition of the binomial coefficient as @{term "\<Prod>i<k. (n - i) / (k - i)"}.\<close> |
|
1004 |
lemma gbinomial_altdef_of_nat: "x gchoose k = (\<Prod>i = 0..<k. (x - of_nat i) / of_nat (k - i) :: 'a)" |
|
1005 |
for k :: nat and x :: "'a::field_char_0" |
|
64272 | 1006 |
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
|
1007 |
|
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
|
1008 |
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
|
1009 |
fixes k :: nat |
63466 | 1010 |
and x :: "'a::linordered_field" |
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
|
1011 |
assumes "of_nat k \<le> x" |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1012 |
shows "(x / of_nat k :: 'a) ^ k \<le> x gchoose 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
|
1013 |
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
|
1014 |
have x: "0 \<le> x" |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1015 |
using assms of_nat_0_le_iff order_trans by blast |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
1016 |
have "(x / of_nat k :: 'a) ^ k = (\<Prod>i = 0..<k. x / of_nat k :: 'a)" |
64272 | 1017 |
by (simp add: prod_constant) |
63466 | 1018 |
also have "\<dots> \<le> x gchoose k" (* FIXME *) |
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
|
1019 |
unfolding gbinomial_altdef_of_nat |
64272 | 1020 |
apply (safe intro!: prod_mono) |
63466 | 1021 |
apply simp_all |
1022 |
prefer 2 |
|
1023 |
subgoal premises for i |
|
1024 |
proof - |
|
1025 |
from assms have "x * of_nat i \<ge> of_nat (i * k)" |
|
1026 |
by (metis mult.commute mult_le_cancel_right of_nat_less_0_iff of_nat_mult) |
|
1027 |
then have "x * of_nat k - x * of_nat i \<le> x * of_nat k - of_nat (i * k)" |
|
1028 |
by arith |
|
1029 |
then have "x * of_nat (k - i) \<le> (x - of_nat i) * of_nat k" |
|
1030 |
using \<open>i < k\<close> by (simp add: algebra_simps zero_less_mult_iff of_nat_diff) |
|
1031 |
then have "x * of_nat (k - i) \<le> (x - of_nat i) * (of_nat k :: 'a)" |
|
1032 |
by (simp only: of_nat_mult[symmetric] of_nat_le_iff) |
|
1033 |
with assms show ?thesis |
|
1034 |
using \<open>i < k\<close> by (simp add: field_simps) |
|
1035 |
qed |
|
1036 |
apply (simp add: x zero_le_divide_iff) |
|
1037 |
done |
|
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
|
1038 |
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
|
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 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1041 |
lemma gbinomial_negated_upper: "(a gchoose b) = (-1) ^ b * ((of_nat b - a - 1) gchoose b)" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1042 |
by (simp add: gbinomial_pochhammer pochhammer_minus algebra_simps) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1043 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1044 |
lemma gbinomial_minus: "((-a) gchoose b) = (-1) ^ b * ((a + of_nat b - 1) gchoose b)" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1045 |
by (subst gbinomial_negated_upper) (simp add: add_ac) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1046 |
|
63466 | 1047 |
lemma Suc_times_gbinomial: "of_nat (Suc b) * ((a + 1) gchoose (Suc b)) = (a + 1) * (a gchoose b)" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1048 |
proof (cases b) |
63466 | 1049 |
case 0 |
1050 |
then show ?thesis by simp |
|
1051 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1052 |
case (Suc b) |
63466 | 1053 |
then have "((a + 1) gchoose (Suc (Suc b))) = (\<Prod>i = 0..Suc b. a + (1 - of_nat i)) / fact (b + 2)" |
64272 | 1054 |
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
|
1055 |
also have "(\<Prod>i = 0..Suc b. a + (1 - of_nat i)) = (a + 1) * (\<Prod>i = 0..b. a - of_nat i)" |
64272 | 1056 |
by (simp add: prod.atLeast0_atMost_Suc_shift) |
63466 | 1057 |
also have "\<dots> / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)" |
64272 | 1058 |
by (simp_all add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1059 |
finally show ?thesis by (simp add: Suc field_simps del: of_nat_Suc) |
63466 | 1060 |
qed |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1061 |
|
63466 | 1062 |
lemma gbinomial_factors: "((a + 1) gchoose (Suc b)) = (a + 1) / of_nat (Suc b) * (a gchoose b)" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1063 |
proof (cases b) |
63466 | 1064 |
case 0 |
1065 |
then show ?thesis by simp |
|
1066 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1067 |
case (Suc b) |
63466 | 1068 |
then have "((a + 1) gchoose (Suc (Suc b))) = (\<Prod>i = 0 .. Suc b. a + (1 - of_nat i)) / fact (b + 2)" |
64272 | 1069 |
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
|
1070 |
also have "(\<Prod>i = 0 .. Suc b. a + (1 - of_nat i)) = (a + 1) * (\<Prod>i = 0..b. a - of_nat i)" |
64272 | 1071 |
by (simp add: prod.atLeast0_atMost_Suc_shift) |
63466 | 1072 |
also have "\<dots> / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)" |
64272 | 1073 |
by (simp_all add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost atLeast0AtMost) |
63466 | 1074 |
finally show ?thesis |
1075 |
by (simp add: Suc) |
|
1076 |
qed |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1077 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1078 |
lemma gbinomial_rec: "((r + 1) gchoose (Suc k)) = (r gchoose k) * ((r + 1) / of_nat (Suc k))" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1079 |
using gbinomial_mult_1[of r k] |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1080 |
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
|
1081 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1082 |
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
|
1083 |
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
|
1084 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1085 |
|
63466 | 1086 |
text \<open>The absorption identity (equation 5.5 \cite[p.~157]{GKP}): |
1087 |
\[ |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1088 |
{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
|
1089 |
\]\<close> |
63466 | 1090 |
lemma gbinomial_absorption': "k > 0 \<Longrightarrow> r gchoose k = (r / of_nat k) * (r - 1 gchoose (k - 1))" |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1091 |
using gbinomial_rec[of "r - 1" "k - 1"] |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1092 |
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
|
1093 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1094 |
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
|
1095 |
division by $k$ (the lower index) and therefore remove the $k \neq 0$ |
63466 | 1096 |
restriction\cite[p.~157]{GKP}: |
1097 |
\[ |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1098 |
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
|
1099 |
\]\<close> |
63466 | 1100 |
lemma gbinomial_absorption: "of_nat (Suc k) * (r gchoose Suc k) = r * ((r - 1) gchoose k)" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1101 |
using gbinomial_absorption'[of "Suc k" r] by (simp add: field_simps del: of_nat_Suc) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1102 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1103 |
text \<open>The absorption identity for natural number binomial coefficients:\<close> |
63466 | 1104 |
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
|
1105 |
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
|
1106 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1107 |
text \<open>The absorption companion identity for natural number coefficients, |
63466 | 1108 |
following the proof by GKP \cite[p.~157]{GKP}:\<close> |
1109 |
lemma binomial_absorb_comp: "(n - k) * (n choose k) = n * ((n - 1) choose k)" |
|
1110 |
(is "?lhs = ?rhs") |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1111 |
proof (cases "n \<le> k") |
63466 | 1112 |
case True |
1113 |
then show ?thesis by auto |
|
1114 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1115 |
case False |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1116 |
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
|
1117 |
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
|
1118 |
by simp |
63466 | 1119 |
also have "Suc ((n - 1) - k) = n - k" |
1120 |
using False by simp |
|
1121 |
also have "n choose \<dots> = n choose k" |
|
1122 |
using False by (intro binomial_symmetric [symmetric]) simp_all |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1123 |
finally show ?thesis .. |
63466 | 1124 |
qed |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1125 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1126 |
text \<open>The generalised absorption companion identity:\<close> |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1127 |
lemma gbinomial_absorb_comp: "(r - of_nat k) * (r gchoose k) = r * ((r - 1) gchoose k)" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1128 |
using pochhammer_absorb_comp[of r k] by (simp add: gbinomial_pochhammer) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1129 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1130 |
lemma gbinomial_addition_formula: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1131 |
"r gchoose (Suc k) = ((r - 1) gchoose (Suc k)) + ((r - 1) gchoose k)" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1132 |
using gbinomial_Suc_Suc[of "r - 1" k] by (simp add: algebra_simps) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1133 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1134 |
lemma binomial_addition_formula: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1135 |
"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
|
1136 |
by (subst choose_reduce_nat) simp_all |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1137 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1138 |
text \<open> |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1139 |
Equation 5.9 of the reference material \cite[p.~159]{GKP} is a useful |
63466 | 1140 |
summation formula, operating on both indices: |
1141 |
\[ |
|
1142 |
\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
|
1143 |
\quad \textnormal{integer } n. |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1144 |
\] |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1145 |
\<close> |
63466 | 1146 |
lemma gbinomial_parallel_sum: "(\<Sum>k\<le>n. (r + of_nat k) gchoose k) = (r + of_nat n + 1) gchoose n" |
1147 |
proof (induct n) |
|
1148 |
case 0 |
|
1149 |
then show ?case by simp |
|
1150 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1151 |
case (Suc m) |
63466 | 1152 |
then show ?case |
1153 |
using gbinomial_Suc_Suc[of "(r + of_nat m + 1)" m] |
|
1154 |
by (simp add: add_ac) |
|
1155 |
qed |
|
1156 |
||
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1157 |
|
63373 | 1158 |
subsubsection \<open>Summation on the upper index\<close> |
63466 | 1159 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1160 |
text \<open> |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1161 |
Another summation formula is equation 5.10 of the reference material \cite[p.~160]{GKP}, |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1162 |
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
|
1163 |
{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
|
1164 |
\<close> |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1165 |
lemma gbinomial_sum_up_index: |
63466 | 1166 |
"(\<Sum>k = 0..n. (of_nat k gchoose m) :: 'a::field_char_0) = (of_nat n + 1) gchoose (m + 1)" |
1167 |
proof (induct n) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1168 |
case 0 |
63466 | 1169 |
show ?case |
1170 |
using gbinomial_Suc_Suc[of 0 m] |
|
1171 |
by (cases m) auto |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1172 |
next |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1173 |
case (Suc n) |
63466 | 1174 |
then show ?case |
1175 |
using gbinomial_Suc_Suc[of "of_nat (Suc n) :: 'a" m] |
|
1176 |
by (simp add: add_ac) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1177 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1178 |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1179 |
lemma gbinomial_index_swap: |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1180 |
"((-1) ^ m) * ((- (of_nat n) - 1) gchoose m) = ((-1) ^ n) * ((- (of_nat m) - 1) gchoose n)" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1181 |
(is "?lhs = ?rhs") |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1182 |
proof - |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1183 |
have "?lhs = (of_nat (m + n) gchoose m)" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1184 |
by (subst gbinomial_negated_upper) (simp add: power_mult_distrib [symmetric]) |
63466 | 1185 |
also have "\<dots> = (of_nat (m + n) gchoose n)" |
1186 |
by (subst gbinomial_of_nat_symmetric) simp_all |
|
1187 |
also have "\<dots> = ?rhs" |
|
1188 |
by (subst gbinomial_negated_upper) simp |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1189 |
finally show ?thesis . |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1190 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1191 |
|
63466 | 1192 |
lemma gbinomial_sum_lower_neg: "(\<Sum>k\<le>m. (r gchoose k) * (- 1) ^ k) = (- 1) ^ m * (r - 1 gchoose m)" |
1193 |
(is "?lhs = ?rhs") |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1194 |
proof - |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1195 |
have "?lhs = (\<Sum>k\<le>m. -(r + 1) + of_nat k gchoose k)" |
64267 | 1196 |
by (intro sum.cong[OF refl]) (subst gbinomial_negated_upper, simp add: power_mult_distrib) |
63466 | 1197 |
also have "\<dots> = - r + of_nat m gchoose m" |
1198 |
by (subst gbinomial_parallel_sum) simp |
|
1199 |
also have "\<dots> = ?rhs" |
|
1200 |
by (subst gbinomial_negated_upper) (simp add: power_mult_distrib) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1201 |
finally show ?thesis . |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1202 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1203 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1204 |
lemma gbinomial_partial_row_sum: |
63466 | 1205 |
"(\<Sum>k\<le>m. (r gchoose k) * ((r / 2) - of_nat k)) = ((of_nat m + 1)/2) * (r gchoose (m + 1))" |
1206 |
proof (induct m) |
|
1207 |
case 0 |
|
1208 |
then show ?case by simp |
|
1209 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1210 |
case (Suc mm) |
63466 | 1211 |
then have "(\<Sum>k\<le>Suc mm. (r gchoose k) * (r / 2 - of_nat k)) = |
1212 |
(r - of_nat (Suc mm)) * (r gchoose Suc mm) / 2" |
|
1213 |
by (simp add: field_simps) |
|
1214 |
also have "\<dots> = r * (r - 1 gchoose Suc mm) / 2" |
|
1215 |
by (subst gbinomial_absorb_comp) (rule refl) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1216 |
also have "\<dots> = (of_nat (Suc mm) + 1) / 2 * (r gchoose (Suc mm + 1))" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1217 |
by (subst gbinomial_absorption [symmetric]) simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1218 |
finally show ?case . |
63466 | 1219 |
qed |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1220 |
|
64267 | 1221 |
lemma sum_bounds_lt_plus1: "(\<Sum>k<mm. f (Suc k)) = (\<Sum>k=1..mm. f k)" |
63466 | 1222 |
by (induct mm) simp_all |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1223 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1224 |
lemma gbinomial_partial_sum_poly: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1225 |
"(\<Sum>k\<le>m. (of_nat m + r gchoose k) * x^k * y^(m-k)) = |
63466 | 1226 |
(\<Sum>k\<le>m. (-r gchoose k) * (-x)^k * (x + y)^(m-k))" |
1227 |
(is "?lhs m = ?rhs m") |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1228 |
proof (induction m) |
63466 | 1229 |
case 0 |
1230 |
then show ?case by simp |
|
1231 |
next |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1232 |
case (Suc mm) |
63466 | 1233 |
define G where "G i k = (of_nat i + r gchoose k) * x^k * y^(i - k)" for i k |
63040 | 1234 |
define S where "S = ?lhs" |
63466 | 1235 |
have SG_def: "S = (\<lambda>i. (\<Sum>k\<le>i. (G i k)))" |
1236 |
unfolding S_def G_def .. |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1237 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1238 |
have "S (Suc mm) = G (Suc mm) 0 + (\<Sum>k=Suc 0..Suc mm. G (Suc mm) k)" |
64267 | 1239 |
using SG_def by (simp add: sum_head_Suc atLeast0AtMost [symmetric]) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1240 |
also have "(\<Sum>k=Suc 0..Suc mm. G (Suc mm) k) = (\<Sum>k=0..mm. G (Suc mm) (Suc k))" |
64267 | 1241 |
by (subst sum_shift_bounds_cl_Suc_ivl) simp |
63466 | 1242 |
also have "\<dots> = (\<Sum>k=0..mm. ((of_nat mm + r gchoose (Suc k)) + |
1243 |
(of_nat mm + r gchoose k)) * x^(Suc k) * y^(mm - k))" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1244 |
unfolding G_def by (subst gbinomial_addition_formula) simp |
63466 | 1245 |
also have "\<dots> = (\<Sum>k=0..mm. (of_nat mm + r gchoose (Suc k)) * x^(Suc k) * y^(mm - k)) + |
1246 |
(\<Sum>k=0..mm. (of_nat mm + r gchoose k) * x^(Suc k) * y^(mm - k))" |
|
64267 | 1247 |
by (subst sum.distrib [symmetric]) (simp add: algebra_simps) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1248 |
also have "(\<Sum>k=0..mm. (of_nat mm + r gchoose (Suc k)) * x^(Suc k) * y^(mm - k)) = |
63466 | 1249 |
(\<Sum>k<Suc mm. (of_nat mm + r gchoose (Suc k)) * x^(Suc k) * y^(mm - k))" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1250 |
by (simp only: atLeast0AtMost lessThan_Suc_atMost) |
63466 | 1251 |
also have "\<dots> = (\<Sum>k<mm. (of_nat mm + r gchoose Suc k) * x^(Suc k) * y^(mm-k)) + |
1252 |
(of_nat mm + r gchoose (Suc mm)) * x^(Suc mm)" |
|
1253 |
(is "_ = ?A + ?B") |
|
64267 | 1254 |
by (subst sum_lessThan_Suc) simp |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1255 |
also have "?A = (\<Sum>k=1..mm. (of_nat mm + r gchoose k) * x^k * y^(mm - k + 1))" |
64267 | 1256 |
proof (subst sum_bounds_lt_plus1 [symmetric], intro sum.cong[OF refl], clarify) |
63466 | 1257 |
fix k |
1258 |
assume "k < mm" |
|
1259 |
then have "mm - k = mm - Suc k + 1" |
|
1260 |
by linarith |
|
1261 |
then show "(of_nat mm + r gchoose Suc k) * x ^ Suc k * y ^ (mm - k) = |
|
1262 |
(of_nat mm + r gchoose Suc k) * x ^ Suc k * y ^ (mm - Suc k + 1)" |
|
1263 |
by (simp only:) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1264 |
qed |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1265 |
also have "\<dots> + ?B = y * (\<Sum>k=1..mm. (G mm k)) + (of_nat mm + r gchoose (Suc mm)) * x^(Suc mm)" |
64267 | 1266 |
unfolding G_def by (subst sum_distrib_left) (simp add: algebra_simps) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1267 |
also have "(\<Sum>k=0..mm. (of_nat mm + r gchoose k) * x^(Suc k) * y^(mm - k)) = x * (S mm)" |
64267 | 1268 |
unfolding S_def by (subst sum_distrib_left) (simp add: atLeast0AtMost algebra_simps) |
63466 | 1269 |
also have "(G (Suc mm) 0) = y * (G mm 0)" |
1270 |
by (simp add: G_def) |
|
1271 |
finally have "S (Suc mm) = |
|
1272 |
y * (G mm 0 + (\<Sum>k=1..mm. (G mm k))) + (of_nat mm + r gchoose (Suc mm)) * x^(Suc mm) + x * (S mm)" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1273 |
by (simp add: ring_distribs) |
63466 | 1274 |
also have "G mm 0 + (\<Sum>k=1..mm. (G mm k)) = S mm" |
64267 | 1275 |
by (simp add: sum_head_Suc[symmetric] SG_def atLeast0AtMost) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1276 |
finally have "S (Suc mm) = (x + y) * (S mm) + (of_nat mm + r gchoose (Suc mm)) * x^(Suc mm)" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1277 |
by (simp add: algebra_simps) |
63466 | 1278 |
also have "(of_nat mm + r gchoose (Suc mm)) = (-1) ^ (Suc mm) * (- r gchoose (Suc mm))" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1279 |
by (subst gbinomial_negated_upper) simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1280 |
also have "(-1) ^ Suc mm * (- r gchoose Suc mm) * x ^ Suc mm = |
63466 | 1281 |
(- r gchoose (Suc mm)) * (-x) ^ Suc mm" |
1282 |
by (simp add: power_minus[of x]) |
|
1283 |
also have "(x + y) * S mm + \<dots> = (x + y) * ?rhs mm + (- r gchoose (Suc mm)) * (- x)^Suc mm" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1284 |
unfolding S_def by (subst Suc.IH) simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1285 |
also have "(x + y) * ?rhs mm = (\<Sum>n\<le>mm. ((- r gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n)))" |
64267 | 1286 |
by (subst sum_distrib_left, rule sum.cong) (simp_all add: Suc_diff_le) |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1287 |
also have "\<dots> + (-r gchoose (Suc mm)) * (-x)^Suc mm = |
63466 | 1288 |
(\<Sum>n\<le>Suc mm. (- r gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n))" |
1289 |
by simp |
|
1290 |
finally show ?case |
|
1291 |
by (simp only: S_def) |
|
1292 |
qed |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1293 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1294 |
lemma gbinomial_partial_sum_poly_xpos: |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1295 |
"(\<Sum>k\<le>m. (of_nat m + r gchoose k) * x^k * y^(m-k)) = |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1296 |
(\<Sum>k\<le>m. (of_nat k + r - 1 gchoose k) * x^k * (x + y)^(m-k))" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1297 |
apply (subst gbinomial_partial_sum_poly) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1298 |
apply (subst gbinomial_negated_upper) |
64267 | 1299 |
apply (intro sum.cong, rule refl) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1300 |
apply (simp add: power_mult_distrib [symmetric]) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1301 |
done |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1302 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1303 |
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
|
1304 |
proof - |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1305 |
have "2 * 2^(2*m) = (\<Sum>k = 0..(2 * m + 1). (2 * m + 1 choose k))" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1306 |
using choose_row_sum[where n="2 * m + 1"] by simp |
63466 | 1307 |
also have "(\<Sum>k = 0..(2 * m + 1). (2 * m + 1 choose k)) = |
1308 |
(\<Sum>k = 0..m. (2 * m + 1 choose k)) + |
|
1309 |
(\<Sum>k = m+1..2*m+1. (2 * m + 1 choose k))" |
|
64267 | 1310 |
using sum_ub_add_nat[of 0 m "\<lambda>k. 2 * m + 1 choose k" "m+1"] |
63466 | 1311 |
by (simp add: mult_2) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1312 |
also have "(\<Sum>k = m+1..2*m+1. (2 * m + 1 choose k)) = |
63466 | 1313 |
(\<Sum>k = 0..m. (2 * m + 1 choose (k + (m + 1))))" |
64267 | 1314 |
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
|
1315 |
also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose (m - k)))" |
64267 | 1316 |
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
|
1317 |
also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose k))" |
64267 | 1318 |
using sum.atLeast_atMost_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
|
1319 |
by simp |
63466 | 1320 |
also have "\<dots> + \<dots> = 2 * \<dots>" |
1321 |
by simp |
|
1322 |
finally show ?thesis |
|
1323 |
by (subst (asm) mult_cancel1) (simp add: atLeast0AtMost) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1324 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1325 |
|
63466 | 1326 |
lemma gbinomial_r_part_sum: "(\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k)) = 2 ^ (2 * m)" |
1327 |
(is "?lhs = ?rhs") |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1328 |
proof - |
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1329 |
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
|
1330 |
by (simp add: binomial_gbinomial add_ac) |
63466 | 1331 |
also have "\<dots> = of_nat (2 ^ (2 * m))" |
1332 |
by (subst binomial_r_part_sum) (rule refl) |
|
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
1333 |
finally show ?thesis by simp |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1334 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1335 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1336 |
lemma gbinomial_sum_nat_pow2: |
63466 | 1337 |
"(\<Sum>k\<le>m. (of_nat (m + k) gchoose k :: 'a::field_char_0) / 2 ^ k) = 2 ^ m" |
1338 |
(is "?lhs = ?rhs") |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1339 |
proof - |
63466 | 1340 |
have "2 ^ m * 2 ^ m = (2 ^ (2*m) :: 'a)" |
1341 |
by (induct m) simp_all |
|
1342 |
also have "\<dots> = (\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k))" |
|
1343 |
using gbinomial_r_part_sum .. |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1344 |
also have "\<dots> = (\<Sum>k\<le>m. (of_nat (m + k) gchoose k) * 2 ^ (m - k))" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1345 |
using gbinomial_partial_sum_poly_xpos[where x="1" and y="1" and r="of_nat m + 1" and m="m"] |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1346 |
by (simp add: add_ac) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1347 |
also have "\<dots> = 2 ^ m * (\<Sum>k\<le>m. (of_nat (m + k) gchoose k) / 2 ^ k)" |
64267 | 1348 |
by (subst sum_distrib_left) (simp add: algebra_simps power_diff) |
63466 | 1349 |
finally show ?thesis |
1350 |
by (subst (asm) mult_left_cancel) simp_all |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1351 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1352 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1353 |
lemma gbinomial_trinomial_revision: |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1354 |
assumes "k \<le> m" |
63466 | 1355 |
shows "(r gchoose m) * (of_nat m gchoose k) = (r gchoose k) * (r - of_nat k gchoose (m - k))" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1356 |
proof - |
63466 | 1357 |
have "(r gchoose m) * (of_nat m gchoose k) = (r gchoose m) * fact m / (fact k * fact (m - k))" |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1358 |
using assms by (simp add: binomial_gbinomial [symmetric] binomial_fact) |
63466 | 1359 |
also have "\<dots> = (r gchoose k) * (r - of_nat k gchoose (m - k))" |
1360 |
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
|
1361 |
finally show ?thesis . |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1362 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61076
diff
changeset
|
1363 |
|
63466 | 1364 |
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
|
1365 |
lemma binomial_altdef_of_nat: |
63466 | 1366 |
"k \<le> n \<Longrightarrow> of_nat (n choose k) = (\<Prod>i = 0..<k. of_nat (n - i) / of_nat (k - i) :: 'a)" |
1367 |
for n k :: nat and x :: "'a::field_char_0" |
|
1368 |
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
|
1369 |
|
63466 | 1370 |
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)" |
1371 |
for k n :: nat and x :: "'a::linordered_field" |
|
1372 |
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
|
1373 |
|
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
|
1374 |
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
|
1375 |
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
|
1376 |
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
|
1377 |
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
|
1378 |
have "n choose r \<le> fact n div fact (n - r)" |
63466 | 1379 |
using assms by (subst binomial_fact_lemma[symmetric]) auto |
1380 |
with fact_div_fact_le_pow [OF assms] show ?thesis |
|
1381 |
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
|
1382 |
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
|
1383 |
|
63466 | 1384 |
lemma binomial_altdef_nat: "k \<le> n \<Longrightarrow> n choose k = fact n div (fact k * fact (n - k))" |
1385 |
for k n :: nat |
|
1386 |
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
|
1387 |
|
63466 | 1388 |
lemma choose_dvd: |
1389 |
"k \<le> n \<Longrightarrow> fact k * fact (n - k) dvd (fact n :: 'a::{semiring_div,linordered_semidom})" |
|
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
1390 |
unfolding dvd_def |
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
1391 |
apply (rule exI [where x="of_nat (n choose k)"]) |
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
1392 |
using binomial_fact_lemma [of k n, THEN arg_cong [where f = of_nat and 'b='a]] |
63366
209c4cbbc4cd
define binomial coefficents directly via combinatorial definition
haftmann
parents:
63363
diff
changeset
|
1393 |
apply 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
|
1394 |
done |
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
|
1395 |
|
62378
85ed00c1fe7c
generalize more theorems to support enat and ennreal
hoelzl
parents:
62347
diff
changeset
|
1396 |
lemma fact_fact_dvd_fact: |
63466 | 1397 |
"fact k * fact n dvd (fact (k + n) :: 'a::{semiring_div,linordered_semidom})" |
1398 |
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
|
1399 |
|
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
|
1400 |
lemma choose_mult_lemma: |
63466 | 1401 |
"((m + r + k) choose (m + k)) * ((m + k) choose k) = ((m + r + k) choose k) * ((m + r) choose m)" |
1402 |
(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
|
1403 |
proof - |
63466 | 1404 |
have "?lhs = |
1405 |
fact (m + r + k) div (fact (m + k) * fact (m + r - m)) * (fact (m + k) div (fact k * fact m))" |
|
63092 | 1406 |
by (simp add: binomial_altdef_nat) |
63466 | 1407 |
also have "\<dots> = fact (m + r + k) div (fact r * (fact k * fact 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
|
1408 |
apply (subst div_mult_div_if_dvd) |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
1409 |
apply (auto simp: algebra_simps fact_fact_dvd_fact) |
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
|
1410 |
apply (metis add.assoc add.commute fact_fact_dvd_fact) |
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
|
1411 |
done |
63466 | 1412 |
also have "\<dots> = (fact (m + r + k) * fact (m + r)) div (fact r * (fact k * fact m) * fact (m + 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
|
1413 |
apply (subst div_mult_div_if_dvd [symmetric]) |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
1414 |
apply (auto simp add: algebra_simps) |
62344
759d684c0e60
pulled out legacy aliasses and infamous dvd interpretations into theory appendix
haftmann
parents:
62142
diff
changeset
|
1415 |
apply (metis fact_fact_dvd_fact dvd_trans nat_mult_dvd_cancel_disj) |
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 |
done |
63466 | 1417 |
also have "\<dots> = |
1418 |
(fact (m + r + k) div (fact k * fact (m + r)) * (fact (m + r) div (fact r * fact 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
|
1419 |
apply (subst div_mult_div_if_dvd) |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
1420 |
apply (auto simp: 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
|
1421 |
done |
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
|
1422 |
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
|
1423 |
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
|
1424 |
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
|
1425 |
|
63466 | 1426 |
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
|
1427 |
lemma choose_mult: |
63466 | 1428 |
"k \<le> m \<Longrightarrow> m \<le> n \<Longrightarrow> (n choose m) * (m choose k) = (n choose k) * ((n - k) choose (m - k))" |
1429 |
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
|
1430 |
|
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
|
1431 |
|
63373 | 1432 |
subsection \<open>More on Binomial Coefficients\<close> |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1433 |
|
63466 | 1434 |
lemma choose_one: "n choose 1 = n" for n :: nat |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1435 |
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
|
1436 |
|
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
|
1437 |
lemma card_UNION: |
63466 | 1438 |
assumes "finite A" |
1439 |
and "\<forall>k \<in> A. finite 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
|
1440 |
shows "card (\<Union>A) = nat (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * int (card (\<Inter>I)))" |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1441 |
(is "?lhs = ?rhs") |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1442 |
proof - |
63466 | 1443 |
have "?rhs = nat (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * (\<Sum>_\<in>\<Inter>I. 1))" |
1444 |
by simp |
|
1445 |
also have "\<dots> = nat (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (\<Sum>_\<in>\<Inter>I. (- 1) ^ (card I + 1)))" |
|
1446 |
(is "_ = nat ?rhs") |
|
64267 | 1447 |
by (subst sum_distrib_left) 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
|
1448 |
also have "?rhs = (\<Sum>(I, _)\<in>Sigma {I. I \<subseteq> A \<and> I \<noteq> {}} Inter. (- 1) ^ (card I + 1))" |
64267 | 1449 |
using assms by (subst sum.Sigma) auto |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1450 |
also have "\<dots> = (\<Sum>(x, I)\<in>(SIGMA x:UNIV. {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}). (- 1) ^ (card I + 1))" |
64267 | 1451 |
by (rule sum.reindex_cong [where l = "\<lambda>(x, y). (y, x)"]) (auto intro: inj_onI simp add: split_beta) |
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
|
1452 |
also have "\<dots> = (\<Sum>(x, I)\<in>(SIGMA x:\<Union>A. {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}). (- 1) ^ (card I + 1))" |
63466 | 1453 |
using assms |
64267 | 1454 |
by (auto intro!: sum.mono_neutral_cong_right finite_SigmaI2 intro: finite_subset[where B="\<Union>A"]) |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1455 |
also have "\<dots> = (\<Sum>x\<in>\<Union>A. (\<Sum>I|I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I. (- 1) ^ (card I + 1)))" |
64267 | 1456 |
using assms by (subst sum.Sigma) auto |
1457 |
also have "\<dots> = (\<Sum>_\<in>\<Union>A. 1)" (is "sum ?lhs _ = _") |
|
1458 |
proof (rule sum.cong[OF refl]) |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1459 |
fix x |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1460 |
assume x: "x \<in> \<Union>A" |
63040 | 1461 |
define K where "K = {X \<in> A. x \<in> X}" |
63466 | 1462 |
with \<open>finite A\<close> have K: "finite K" |
1463 |
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
|
1464 |
let ?I = "\<lambda>i. {I. I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I}" |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1465 |
have "inj_on snd (SIGMA i:{1..card A}. ?I i)" |
63466 | 1466 |
using assms by (auto intro!: inj_onI) |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1467 |
moreover have [symmetric]: "snd ` (SIGMA i:{1..card A}. ?I i) = {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}" |
63466 | 1468 |
using assms |
1469 |
by (auto intro!: rev_image_eqI[where x="(card a, a)" for a] |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1470 |
simp add: card_gt_0_iff[folded Suc_le_eq] |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1471 |
dest: finite_subset intro: card_mono) |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1472 |
ultimately have "?lhs x = (\<Sum>(i, I)\<in>(SIGMA i:{1..card A}. ?I i). (- 1) ^ (i + 1))" |
64267 | 1473 |
by (rule sum.reindex_cong [where l = snd]) fastforce |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1474 |
also have "\<dots> = (\<Sum>i=1..card A. (\<Sum>I|I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. (- 1) ^ (i + 1)))" |
64267 | 1475 |
using assms by (subst sum.Sigma) auto |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1476 |
also have "\<dots> = (\<Sum>i=1..card A. (- 1) ^ (i + 1) * (\<Sum>I|I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1))" |
64267 | 1477 |
by (subst sum_distrib_left) simp |
63466 | 1478 |
also have "\<dots> = (\<Sum>i=1..card K. (- 1) ^ (i + 1) * (\<Sum>I|I \<subseteq> K \<and> card I = i. 1))" |
1479 |
(is "_ = ?rhs") |
|
64267 | 1480 |
proof (rule sum.mono_neutral_cong_right[rule_format]) |
63466 | 1481 |
show "finite {1..card A}" |
1482 |
by simp |
|
1483 |
show "{1..card K} \<subseteq> {1..card A}" |
|
1484 |
using \<open>finite A\<close> by (auto simp add: K_def intro: card_mono) |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1485 |
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
|
1486 |
fix i |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1487 |
assume "i \<in> {1..card A} - {1..card K}" |
63466 | 1488 |
then have i: "i \<le> card A" "card K < i" |
1489 |
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
|
1490 |
have "{I. I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I} = {I. I \<subseteq> K \<and> card I = i}" |
63466 | 1491 |
by (auto simp add: K_def) |
1492 |
also have "\<dots> = {}" |
|
1493 |
using \<open>finite A\<close> i by (auto simp add: K_def dest: card_mono[rotated 1]) |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1494 |
finally show "(- 1) ^ (i + 1) * (\<Sum>I | I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1 :: int) = 0" |
63466 | 1495 |
by (simp only:) 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
|
1496 |
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
|
1497 |
fix i |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1498 |
have "(\<Sum>I | I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1) = (\<Sum>I | I \<subseteq> K \<and> card I = i. 1 :: int)" |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1499 |
(is "?lhs = ?rhs") |
64267 | 1500 |
by (rule sum.cong) (auto simp add: K_def) |
63466 | 1501 |
then show "(- 1) ^ (i + 1) * ?lhs = (- 1) ^ (i + 1) * ?rhs" |
1502 |
by simp |
|
1503 |
qed |
|
1504 |
also have "{I. I \<subseteq> K \<and> card I = 0} = {{}}" |
|
1505 |
using assms by (auto simp add: card_eq_0_iff K_def dest: finite_subset) |
|
1506 |
then have "?rhs = (\<Sum>i = 0..card K. (- 1) ^ (i + 1) * (\<Sum>I | I \<subseteq> K \<and> card I = i. 1 :: int)) + 1" |
|
64267 | 1507 |
by (subst (2) sum_head_Suc) simp_all |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1508 |
also have "\<dots> = (\<Sum>i = 0..card K. (- 1) * ((- 1) ^ i * int (card K choose i))) + 1" |
63466 | 1509 |
using K by (subst n_subsets[symmetric]) simp_all |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1510 |
also have "\<dots> = - (\<Sum>i = 0..card K. (- 1) ^ i * int (card K choose i)) + 1" |
64267 | 1511 |
by (subst sum_distrib_left[symmetric]) simp |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1512 |
also have "\<dots> = - ((-1 + 1) ^ card K) + 1" |
63466 | 1513 |
by (subst binomial_ring) (simp add: ac_simps) |
1514 |
also have "\<dots> = 1" |
|
1515 |
using x K by (auto simp add: K_def card_gt_0_iff) |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1516 |
finally show "?lhs x = 1" . |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1517 |
qed |
63466 | 1518 |
also have "nat \<dots> = card (\<Union>A)" |
1519 |
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
|
1520 |
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
|
1521 |
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
|
1522 |
|
63466 | 1523 |
text \<open>The number of nat lists of length \<open>m\<close> summing to \<open>N\<close> is @{term "(N + m - 1) choose N"}:\<close> |
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1524 |
lemma card_length_sum_list_rec: |
63466 | 1525 |
assumes "m \<ge> 1" |
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1526 |
shows "card {l::nat list. length l = m \<and> sum_list l = N} = |
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1527 |
card {l. length l = (m - 1) \<and> sum_list l = N} + |
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1528 |
card {l. length l = m \<and> sum_list l + 1 = N}" |
63466 | 1529 |
(is "card ?C = card ?A + card ?B") |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1530 |
proof - |
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1531 |
let ?A' = "{l. length l = m \<and> sum_list l = N \<and> hd l = 0}" |
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1532 |
let ?B' = "{l. length l = m \<and> sum_list l = N \<and> hd l \<noteq> 0}" |
63466 | 1533 |
let ?f = "\<lambda>l. 0 # l" |
1534 |
let ?g = "\<lambda>l. (hd l + 1) # tl l" |
|
1535 |
have 1: "xs \<noteq> [] \<Longrightarrow> x = hd xs \<Longrightarrow> x # tl xs = xs" for x xs |
|
1536 |
by simp |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1537 |
have 2: "xs \<noteq> [] \<Longrightarrow> sum_list(tl xs) = sum_list xs - hd xs" for xs :: "nat list" |
63466 | 1538 |
by (auto simp add: neq_Nil_conv) |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1539 |
have f: "bij_betw ?f ?A ?A'" |
63466 | 1540 |
apply (rule bij_betw_byWitness[where f' = tl]) |
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
|
1541 |
using assms |
63466 | 1542 |
apply (auto simp: 2 length_0_conv[symmetric] 1 simp del: length_0_conv) |
1543 |
done |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1544 |
have 3: "xs \<noteq> [] \<Longrightarrow> hd xs + (sum_list xs - hd xs) = sum_list xs" for xs :: "nat list" |
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1545 |
by (metis 1 sum_list_simps(2) 2) |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1546 |
have g: "bij_betw ?g ?B ?B'" |
63466 | 1547 |
apply (rule bij_betw_byWitness[where f' = "\<lambda>l. (hd l - 1) # tl l"]) |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1548 |
using assms |
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
|
1549 |
by (auto simp: 2 length_0_conv[symmetric] intro!: 3 |
63466 | 1550 |
simp del: length_greater_0_conv length_0_conv) |
1551 |
have fin: "finite {xs. size xs = M \<and> set xs \<subseteq> {0..<N}}" for M N :: nat |
|
1552 |
using finite_lists_length_eq[OF finite_atLeastLessThan] conj_commute by auto |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1553 |
have fin_A: "finite ?A" using fin[of _ "N+1"] |
63466 | 1554 |
by (intro finite_subset[where ?A = "?A" and ?B = "{xs. size xs = m - 1 \<and> set xs \<subseteq> {0..<N+1}}"]) |
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1555 |
(auto simp: member_le_sum_list_nat less_Suc_eq_le) |
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1556 |
have fin_B: "finite ?B" |
63466 | 1557 |
by (intro finite_subset[where ?A = "?B" and ?B = "{xs. size xs = m \<and> set xs \<subseteq> {0..<N}}"]) |
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1558 |
(auto simp: member_le_sum_list_nat less_Suc_eq_le fin) |
63466 | 1559 |
have uni: "?C = ?A' \<union> ?B'" |
1560 |
by auto |
|
1561 |
have disj: "?A' \<inter> ?B' = {}" |
|
1562 |
by auto |
|
1563 |
have "card ?C = card(?A' \<union> ?B')" |
|
1564 |
using uni by simp |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1565 |
also have "\<dots> = card ?A + card ?B" |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1566 |
using card_Un_disjoint[OF _ _ disj] bij_betw_finite[OF f] bij_betw_finite[OF g] |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1567 |
bij_betw_same_card[OF f] bij_betw_same_card[OF g] fin_A fin_B |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1568 |
by presburger |
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1569 |
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
|
1570 |
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
|
1571 |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1572 |
lemma card_length_sum_list: "card {l::nat list. size l = m \<and> sum_list l = N} = (N + m - 1) choose N" |
63466 | 1573 |
\<comment> "by Holden Lee, tidied by Tobias Nipkow" |
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
|
1574 |
proof (cases m) |
63466 | 1575 |
case 0 |
1576 |
then show ?thesis |
|
1577 |
by (cases N) (auto cong: conj_cong) |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1578 |
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
|
1579 |
case (Suc m') |
63466 | 1580 |
have m: "m \<ge> 1" |
1581 |
by (simp add: Suc) |
|
1582 |
then show ?thesis |
|
1583 |
proof (induct "N + m - 1" arbitrary: N m) |
|
1584 |
case 0 \<comment> "In the base case, the only solution is [0]." |
|
1585 |
have [simp]: "{l::nat list. length l = Suc 0 \<and> (\<forall>n\<in>set l. n = 0)} = {[0]}" |
|
1586 |
by (auto simp: length_Suc_conv) |
|
1587 |
have "m = 1 \<and> N = 0" |
|
1588 |
using 0 by linarith |
|
1589 |
then show ?case |
|
1590 |
by simp |
|
1591 |
next |
|
1592 |
case (Suc k) |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1593 |
have c1: "card {l::nat list. size l = (m - 1) \<and> sum_list l = N} = (N + (m - 1) - 1) choose N" |
63466 | 1594 |
proof (cases "m = 1") |
1595 |
case True |
|
1596 |
with Suc.hyps have "N \<ge> 1" |
|
1597 |
by auto |
|
1598 |
with True show ?thesis |
|
1599 |
by (simp add: binomial_eq_0) |
|
59667
651ea265d568
Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents:
59658
diff
changeset
|
1600 |
next |
63466 | 1601 |
case False |
1602 |
then show ?thesis |
|
1603 |
using Suc by fastforce |
|
1604 |
qed |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1605 |
from Suc have c2: "card {l::nat list. size l = m \<and> sum_list l + 1 = N} = |
63466 | 1606 |
(if N > 0 then ((N - 1) + m - 1) choose (N - 1) else 0)" |
1607 |
proof - |
|
1608 |
have *: "n > 0 \<Longrightarrow> Suc m = n \<longleftrightarrow> m = n - 1" for m n |
|
1609 |
by arith |
|
1610 |
from Suc have "N > 0 \<Longrightarrow> |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1611 |
card {l::nat list. size l = m \<and> sum_list l + 1 = N} = |
63466 | 1612 |
((N - 1) + m - 1) choose (N - 1)" |
1613 |
by (simp add: *) |
|
1614 |
then show ?thesis |
|
1615 |
by auto |
|
1616 |
qed |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1617 |
from Suc.prems have "(card {l::nat list. size l = (m - 1) \<and> sum_list l = N} + |
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1618 |
card {l::nat list. size l = m \<and> sum_list l + 1 = N}) = (N + m - 1) choose N" |
63466 | 1619 |
by (auto simp: c1 c2 choose_reduce_nat[of "N + m - 1" N] simp del: One_nat_def) |
1620 |
then show ?case |
|
63882
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
nipkow
parents:
63725
diff
changeset
|
1621 |
using card_length_sum_list_rec[OF Suc.prems] by auto |
63466 | 1622 |
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
|
1623 |
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
|
1624 |
|
63466 | 1625 |
lemma Suc_times_binomial_add: "Suc a * (Suc (a + b) choose Suc a) = Suc b * (Suc (a + b) choose a)" |
1626 |
\<comment> \<open>by Lukas Bulwahn\<close> |
|
60604 | 1627 |
proof - |
1628 |
have dvd: "Suc a * (fact a * fact b) dvd fact (Suc (a + b))" for a b |
|
1629 |
using fact_fact_dvd_fact[of "Suc a" "b", where 'a=nat] |
|
1630 |
by (simp only: fact_Suc add_Suc[symmetric] of_nat_id mult.assoc) |
|
1631 |
have "Suc a * (fact (Suc (a + b)) div (Suc a * fact a * fact b)) = |
|
1632 |
Suc a * fact (Suc (a + b)) div (Suc a * (fact a * fact b))" |
|
1633 |
by (subst div_mult_swap[symmetric]; simp only: mult.assoc dvd) |
|
1634 |
also have "\<dots> = Suc b * fact (Suc (a + b)) div (Suc b * (fact a * fact b))" |
|
1635 |
by (simp only: div_mult_mult1) |
|
1636 |
also have "\<dots> = Suc b * (fact (Suc (a + b)) div (Suc b * (fact a * fact b)))" |
|
1637 |
using dvd[of b a] by (subst div_mult_swap[symmetric]; simp only: ac_simps dvd) |
|
1638 |
finally show ?thesis |
|
1639 |
by (subst (1 2) binomial_altdef_nat) |
|
63466 | 1640 |
(simp_all only: ac_simps diff_Suc_Suc Suc_diff_le diff_add_inverse fact_Suc of_nat_id) |
60604 | 1641 |
qed |
1642 |
||
63373 | 1643 |
|
1644 |
subsection \<open>Misc\<close> |
|
1645 |
||
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1646 |
lemma fact_code [code]: |
63466 | 1647 |
"fact n = (of_nat (fold_atLeastAtMost_nat (op *) 2 n 1) :: 'a::semiring_char_0)" |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1648 |
proof - |
63417
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
haftmann
parents:
63373
diff
changeset
|
1649 |
have "fact n = (of_nat (\<Prod>{1..n}) :: 'a)" |
64272 | 1650 |
by (simp add: fact_prod) |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1651 |
also have "\<Prod>{1..n} = \<Prod>{2..n}" |
64272 | 1652 |
by (intro prod.mono_neutral_right) auto |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1653 |
also have "\<dots> = fold_atLeastAtMost_nat (op *) 2 n 1" |
64272 | 1654 |
by (simp add: prod_atLeastAtMost_code) |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1655 |
finally show ?thesis . |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1656 |
qed |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1657 |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1658 |
lemma pochhammer_code [code]: |
63466 | 1659 |
"pochhammer a n = |
1660 |
(if n = 0 then 1 |
|
1661 |
else fold_atLeastAtMost_nat (\<lambda>n acc. (a + of_nat n) * acc) 0 (n - 1) 1)" |
|
1662 |
by (cases n) |
|
64272 | 1663 |
(simp_all add: pochhammer_prod prod_atLeastAtMost_code [symmetric] |
63466 | 1664 |
atLeastLessThanSuc_atLeastAtMost) |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1665 |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1666 |
lemma gbinomial_code [code]: |
63466 | 1667 |
"a gchoose n = |
1668 |
(if n = 0 then 1 |
|
1669 |
else fold_atLeastAtMost_nat (\<lambda>n acc. (a - of_nat n) * acc) 0 (n - 1) 1 / fact n)" |
|
1670 |
by (cases n) |
|
64272 | 1671 |
(simp_all add: gbinomial_prod_rev prod_atLeastAtMost_code [symmetric] |
63466 | 1672 |
atLeastLessThanSuc_atLeastAtMost) |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1673 |
|
63466 | 1674 |
(* FIXME *) |
62142
18a217591310
Deleted problematic code equation in Binomial temporarily.
eberlm
parents:
62128
diff
changeset
|
1675 |
(*TODO: This code equation breaks Scala code generation in HOL-Codegenerator_Test. We have to figure out why and how to prevent that. *) |
18a217591310
Deleted problematic code equation in Binomial temporarily.
eberlm
parents:
62128
diff
changeset
|
1676 |
|
18a217591310
Deleted problematic code equation in Binomial temporarily.
eberlm
parents:
62128
diff
changeset
|
1677 |
(* |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1678 |
lemma binomial_code [code]: |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1679 |
"(n choose k) = |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1680 |
(if k > n then 0 |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1681 |
else if 2 * k > n then (n choose (n - k)) |
62142
18a217591310
Deleted problematic code equation in Binomial temporarily.
eberlm
parents:
62128
diff
changeset
|
1682 |
else (fold_atLeastAtMost_nat (op * ) (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
|
1683 |
proof - |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1684 |
{ |
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1685 |
assume "k \<le> n" |
63466 | 1686 |
then have "{1..n} = {1..n-k} \<union> {n-k+1..n}" by auto |
1687 |
then have "(fact n :: nat) = fact (n-k) * \<Prod>{n-k+1..n}" |
|
64272 | 1688 |
by (simp add: prod.union_disjoint fact_altdef_nat) |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1689 |
} |
64272 | 1690 |
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
|
1691 |
qed |
62142
18a217591310
Deleted problematic code equation in Binomial temporarily.
eberlm
parents:
62128
diff
changeset
|
1692 |
*) |
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
61799
diff
changeset
|
1693 |
|
15131 | 1694 |
end |