2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department of the University of Bologna, Italy.
7 ||A|| This file is distributed under the terms of the
8 \ / GNU General Public License Version 2
10 V_______________________________________________________________ *)
12 include "arithmetics/bigops.ma".
13 include "arithmetics/primes.ma".
15 (* binomial coefficient *)
16 definition bc ≝ λn,k. n!/(k!*(n-k)!).
18 lemma bceq :∀n,k. bc n k = n!/(k!*(n-k)!).
21 theorem bc_n_n: ∀n. bc n n = 1.
22 #n >bceq <minus_n_n <times_n_1 @div_n_n //
25 theorem bc_n_O: ∀n. bc n O = 1.
26 #n >bceq <minus_n_O /2/
29 theorem fact_minus: ∀n,k. k < n →
30 (n-k)*(n - S k)! = (n - k)!.
33 |#l #ltl >minus_Sn_m [>commutative_times //|@le_S_S_to_le //]
38 ∀k. k ≤n → k!*(n-k)! ∣ n!.
40 [#k #lek0 <(le_n_O_to_eq ? lek0) //
41 |#m #Hind #k generalize in match H1;cases k
42 [intro;simplify in ⊢ (? (? ? (? %)) ?);simplify in ⊢ (? (? % ?) ?);
43 rewrite > sym_times;rewrite < times_n_SO;apply reflexive_divides
44 |intro;elim (decidable_eq_nat n2 n1)
45 [rewrite > H3;rewrite < minus_n_n;
46 rewrite > times_n_SO in ⊢ (? ? %);apply reflexive_divides
48 [lapply (H (n1 - (S n2)))
49 [change in ⊢ (? ? %) with ((S n1)*n1!);
50 rewrite > (plus_minus_m_m n1 n2) in ⊢ (? ? (? (? %) ?))
52 change in ⊢ (? ? (? % ?)) with ((S n2) + (n1 - n2));
53 rewrite > sym_times in \vdash (? ? %);
54 rewrite > distr_times_plus in ⊢ (? ? %);
55 simplify in ⊢ (? (? ? (? %)) ?);
58 change in ⊢ (? (? ? %) ?) with ((S n2)*n2!);
59 rewrite > sym_times in ⊢ (? (? ? %) ?);
60 rewrite < assoc_times;
62 [rewrite > sym_times;assumption
63 |apply reflexive_divides]
64 |rewrite < fact_minus in ⊢ (? (? ? %) ?)
65 [rewrite > sym_times in ⊢ (? (? ? %) ?);
66 rewrite < assoc_times;
68 [rewrite < eq_plus_minus_minus_minus in Hletin1;
69 [rewrite > sym_times;rewrite < minus_n_n in Hletin1;
70 rewrite < plus_n_O in Hletin1;assumption
71 |lapply (le_S_S_to_le ? ? H2);
72 elim (le_to_or_lt_eq ? ? Hletin2);
76 |apply reflexive_divides]
77 |lapply (le_S_S_to_le ? ? H2);
78 elim (le_to_or_lt_eq ? ? Hletin2);
81 |apply le_S_S_to_le;assumption]
82 |apply le_minus_m;apply le_S_S_to_le;assumption]
83 |apply le_S_S_to_le;assumption]]]]
86 theorem bc1: \forall n.\forall k. k < n \to bc (S n) (S k) = (bc n k) + (bc n (S k)).
88 rewrite > (lt_to_lt_to_eq_div_div_times_times ? ? (S k)) in ⊢ (? ? ? (? % ?))
89 [rewrite > sym_times in ⊢ (? ? ? (? (? ? %) ?)).
90 rewrite < assoc_times in ⊢ (? ? ? (? (? ? %) ?)).
91 rewrite > (lt_to_lt_to_eq_div_div_times_times ? ? (n - k)) in ⊢ (? ? ? (? ? %))
92 [rewrite > assoc_times in ⊢ (? ? ? (? ? (? ? %))).
93 rewrite > sym_times in ⊢ (? ? ? (? ? (? ? (? ? %)))).
95 [rewrite < eq_div_plus
96 [rewrite < distr_times_plus.
97 simplify in ⊢ (? ? ? (? (? ? %) ?)).
98 rewrite > sym_plus in ⊢ (? ? ? (? (? ? (? %)) ?)).
99 rewrite < plus_minus_m_m
100 [rewrite > sym_times in ⊢ (? ? ? (? % ?)).
105 |rewrite > (times_n_O O).
106 apply lt_times;apply lt_O_fact
107 |change in ⊢ (? (? % ?) ?) with ((S k)*k!);
108 rewrite < sym_times in ⊢ (? ? %);
109 rewrite > assoc_times;apply divides_times
110 [apply reflexive_divides
111 |apply bc2;apply le_S_S_to_le;constructor 2;assumption]
112 |rewrite < fact_minus
113 [rewrite > sym_times in ⊢ (? (? ? %) ?);rewrite < assoc_times;
115 [apply bc2;assumption
116 |apply reflexive_divides]
119 |apply lt_to_lt_O_minus;assumption
120 |rewrite > (times_n_O O).
121 apply lt_times;apply lt_O_fact]
123 |rewrite > (times_n_O O).
124 apply lt_times;apply lt_O_fact]
127 theorem lt_O_bc: \forall n,m. m \le n \to O < bc n m.
129 [apply (le_n_O_elim ? H).
131 |elim (le_to_or_lt_eq ? ? H1)
132 [generalize in match H2.cases m;intro
133 [rewrite > bc_n_O.apply le_n
135 [apply (trans_le ? (bc n1 n2))
136 [apply H.apply le_S_S_to_le.apply lt_to_le.assumption
139 |apply le_S_S_to_le.assumption
149 theorem exp_plus_sigma_p:\forall a,b,n.
150 exp (a+b) n = sigma_p (S n) (\lambda k.true)
151 (\lambda k.(bc n k)*(exp a (n-k))*(exp b k)).
153 [simplify.reflexivity
154 |simplify in ⊢ (? ? % ?).
155 rewrite > true_to_sigma_p_Sn
156 [rewrite > H;rewrite > sym_times in ⊢ (? ? % ?);
157 rewrite > distr_times_plus in ⊢ (? ? % ?);
158 rewrite < minus_n_n in ⊢ (? ? ? (? (? (? ? (? ? %)) ?) ?));
159 rewrite > sym_times in ⊢ (? ? (? % ?) ?);
160 rewrite > sym_times in ⊢ (? ? (? ? %) ?);
161 rewrite > distributive_times_plus_sigma_p in ⊢ (? ? (? % ?) ?);
162 rewrite > distributive_times_plus_sigma_p in ⊢ (? ? (? ? %) ?);
163 rewrite > true_to_sigma_p_Sn in ⊢ (? ? (? ? %) ?)
164 [rewrite < assoc_plus;rewrite < sym_plus in ⊢ (? ? (? % ?) ?);
165 rewrite > assoc_plus;
167 [rewrite > sym_times;rewrite > assoc_times;autobatch paramodulation
168 |rewrite > (sigma_p_gi ? ? O);
169 [rewrite < (eq_sigma_p_gh ? S pred n1 (S n1) (λx:nat.true)) in ⊢ (? ? (? (? ? %) ?) ?)
170 [rewrite > (sigma_p_gi ? ? O) in ⊢ (? ? ? %);
171 [rewrite > assoc_plus;apply eq_f2
172 [autobatch paramodulation;
173 |rewrite < sigma_p_plus_1;
174 rewrite < (eq_sigma_p_gh ? S pred n1 (S n1) (λx:nat.true)) in \vdash (? ? ? %);
177 |intros;rewrite > sym_times;rewrite > assoc_times;
178 rewrite > sym_times in ⊢ (? ? (? (? ? %) ?) ?);
179 rewrite > assoc_times;rewrite < assoc_times in ⊢ (? ? (? (? ? %) ?) ?);
180 rewrite > sym_times in ⊢ (? ? (? (? ? (? % ?)) ?) ?);
181 change in ⊢ (? ? (? (? ? (? % ?)) ?) ?) with (exp a (S (n1 - S x)));
182 rewrite < (minus_Sn_m ? ? H1);rewrite > minus_S_S;
183 rewrite > sym_times in \vdash (? ? (? ? %) ?);
184 rewrite > assoc_times;
185 rewrite > sym_times in ⊢ (? ? (? ? (? ? %)) ?);
186 change in \vdash (? ? (? ? (? ? %)) ?) with (exp b (S x));
187 rewrite > assoc_times in \vdash (? ? (? ? %) ?);
188 rewrite > sym_times in \vdash (? ? (? % ?) ?);
189 rewrite > sym_times in \vdash (? ? (? ? %) ?);
190 rewrite > assoc_times in \vdash (? ? ? %);
191 rewrite > sym_times in \vdash (? ? ? %);
192 rewrite < distr_times_plus;
193 rewrite > sym_plus;rewrite < bc1;
194 [reflexivity|assumption]]
195 |intros;simplify;reflexivity
196 |intros;simplify;reflexivity
197 |intros;apply le_S_S;assumption
200 [simplify in H2;destruct H2
201 |simplify;reflexivity]
203 [simplify in H2;destruct H2
204 |simplify;apply le_S_S_to_le;assumption]]]
205 |apply le_S_S;apply le_O_n
207 |intros;simplify;reflexivity
208 |intros;simplify;reflexivity
209 |intros;apply le_S_S;assumption
212 [simplify in H2;destruct H2
213 |simplify;reflexivity]
215 [simplify in H2;destruct H2
216 |simplify;apply le_S_S_to_le;assumption]]
217 |apply le_S_S;apply le_O_n
223 theorem exp_S_sigma_p:\forall a,n.
224 exp (S a) n = sigma_p (S n) (\lambda k.true) (\lambda k.(bc n k)*(exp a (n-k))).
227 rewrite > exp_plus_sigma_p.
228 apply eq_sigma_p;intros
231 rewrite < times_n_SO.
236 theorem exp_Sn_SSO: \forall n. exp (S n) 2 = S((exp n 2) + 2*n).
238 rewrite < times_n_SO.
240 rewrite < sym_times.simplify.
241 rewrite < assoc_plus.