1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/nat/binomial".
17 include "nat/iteration2.ma".
18 include "nat/factorial2.ma".
20 definition bc \def \lambda n,k. n!/(k!*(n-k)!).
22 theorem bc_n_n: \forall n. bc n n = S O.
25 simplify in ⊢ (? ? (? ? (? ? %)) ?).
31 theorem bc_n_O: \forall n. bc n O = S O.
34 simplify in ⊢ (? ? (? ? %) ?).
40 theorem fact_minus: \forall n,k. k < n \to
41 (n-k)*(n - S k)! = (n - k)!.
43 [intro.apply False_ind.
44 apply (lt_to_not_le ? ? H).
54 theorem bc2 : \forall n.
55 \forall k. k \leq n \to divides (k!*(n-k)!) n!.
57 [rewrite < (le_n_O_to_eq ? H);apply reflexive_divides
58 |generalize in match H1;cases k
59 [intro;simplify in ⊢ (? (? ? (? %)) ?);simplify in ⊢ (? (? % ?) ?);
60 rewrite > sym_times;rewrite < times_n_SO;apply reflexive_divides
61 |intro;elim (decidable_eq_nat n2 n1)
62 [rewrite > H3;rewrite < minus_n_n;
63 rewrite > times_n_SO in ⊢ (? ? %);apply reflexive_divides
65 [lapply (H (n1 - (S n2)))
66 [change in ⊢ (? ? %) with ((S n1)*n1!);
67 rewrite > (plus_minus_m_m n1 n2) in ⊢ (? ? (? (? %) ?))
69 change in ⊢ (? ? (? % ?)) with ((S n2) + (n1 - n2));
70 rewrite > sym_times in \vdash (? ? %);
71 rewrite > distr_times_plus in ⊢ (? ? %);
72 simplify in ⊢ (? (? ? (? %)) ?);
75 change in ⊢ (? (? ? %) ?) with ((S n2)*n2!);
76 rewrite > sym_times in ⊢ (? (? ? %) ?);
77 rewrite < assoc_times;
79 [rewrite > sym_times;assumption
80 |apply reflexive_divides]
81 |rewrite < fact_minus in ⊢ (? (? ? %) ?)
82 [rewrite > sym_times in ⊢ (? (? ? %) ?);
83 rewrite < assoc_times;
85 [rewrite < eq_plus_minus_minus_minus in Hletin1;
86 [rewrite > sym_times;rewrite < minus_n_n in Hletin1;
87 rewrite < plus_n_O in Hletin1;assumption
88 |lapply (le_S_S_to_le ? ? H2);
89 elim (le_to_or_lt_eq ? ? Hletin2);
93 |apply reflexive_divides]
94 |lapply (le_S_S_to_le ? ? H2);
95 elim (le_to_or_lt_eq ? ? Hletin2);
98 |apply le_S_S_to_le;assumption]
99 |apply le_minus_m;apply le_S_S_to_le;assumption]
100 |apply le_S_S_to_le;assumption]]]]
103 theorem bc1: \forall n.\forall k. k < n \to bc (S n) (S k) = (bc n k) + (bc n (S k)).
105 rewrite > (lt_to_lt_to_eq_div_div_times_times ? ? (S k)) in ⊢ (? ? ? (? % ?))
106 [rewrite > sym_times in ⊢ (? ? ? (? (? ? %) ?)).
107 rewrite < assoc_times in ⊢ (? ? ? (? (? ? %) ?)).
108 rewrite > (lt_to_lt_to_eq_div_div_times_times ? ? (n - k)) in ⊢ (? ? ? (? ? %))
109 [rewrite > assoc_times in ⊢ (? ? ? (? ? (? ? %))).
110 rewrite > sym_times in ⊢ (? ? ? (? ? (? ? (? ? %)))).
112 [rewrite < eq_div_plus
113 [rewrite < distr_times_plus.
114 simplify in ⊢ (? ? ? (? (? ? %) ?)).
115 rewrite > sym_plus in ⊢ (? ? ? (? (? ? (? %)) ?)).
116 rewrite < plus_minus_m_m
117 [rewrite > sym_times in ⊢ (? ? ? (? % ?)).
122 |rewrite > (times_n_O O).
123 apply lt_times;apply lt_O_fact
124 |change in ⊢ (? (? % ?) ?) with ((S k)*k!);
125 rewrite < sym_times in ⊢ (? ? %);
126 rewrite > assoc_times;apply divides_times
127 [apply reflexive_divides
128 |apply bc2;apply le_S_S_to_le;constructor 2;assumption]
129 |rewrite < fact_minus
130 [rewrite > sym_times in ⊢ (? (? ? %) ?);rewrite < assoc_times;
132 [apply bc2;assumption
133 |apply reflexive_divides]
136 |apply lt_to_lt_O_minus;assumption
137 |rewrite > (times_n_O O).
138 apply lt_times;apply lt_O_fact]
140 |rewrite > (times_n_O O).
141 apply lt_times;apply lt_O_fact]
144 theorem exp_plus_sigma_p:\forall a,b,n.
145 exp (a+b) n = sigma_p (S n) (\lambda k.true)
146 (\lambda k.(bc n k)*(exp a (n-k))*(exp b k)).
148 [simplify.reflexivity
149 |simplify in ⊢ (? ? % ?).
150 rewrite > true_to_sigma_p_Sn
151 [rewrite > H;rewrite > sym_times in ⊢ (? ? % ?);
152 rewrite > distr_times_plus in ⊢ (? ? % ?);
153 rewrite < minus_n_n in ⊢ (? ? ? (? (? (? ? (? ? %)) ?) ?));
154 rewrite > sym_times in ⊢ (? ? (? % ?) ?);
155 rewrite > sym_times in ⊢ (? ? (? ? %) ?);
156 rewrite > distributive_times_plus_sigma_p in ⊢ (? ? (? % ?) ?);
157 rewrite > distributive_times_plus_sigma_p in ⊢ (? ? (? ? %) ?);
158 rewrite > true_to_sigma_p_Sn in ⊢ (? ? (? ? %) ?)
159 [rewrite < assoc_plus;rewrite < sym_plus in ⊢ (? ? (? % ?) ?);
160 rewrite > assoc_plus;
162 [rewrite > sym_times;rewrite > assoc_times;autobatch paramodulation
163 |rewrite > (sigma_p_gi ? ? O);
164 [rewrite < (eq_sigma_p_gh ? S pred n1 (S n1) (λx:nat.true)) in ⊢ (? ? (? (? ? %) ?) ?)
165 [rewrite > (sigma_p_gi ? ? O) in ⊢ (? ? ? %);
166 [rewrite > assoc_plus;apply eq_f2
167 [autobatch paramodulation;
168 |rewrite < sigma_p_plus_1;
169 rewrite < (eq_sigma_p_gh ? S pred n1 (S n1) (λx:nat.true)) in \vdash (? ? ? %);
172 |intros;rewrite > sym_times;rewrite > assoc_times;
173 rewrite > sym_times in ⊢ (? ? (? (? ? %) ?) ?);
174 rewrite > assoc_times;rewrite < assoc_times in ⊢ (? ? (? (? ? %) ?) ?);
175 rewrite > sym_times in ⊢ (? ? (? (? ? (? % ?)) ?) ?);
176 change in ⊢ (? ? (? (? ? (? % ?)) ?) ?) with (exp a (S (n1 - S x)));
177 rewrite < (minus_Sn_m ? ? H1);rewrite > minus_S_S;
178 rewrite > sym_times in \vdash (? ? (? ? %) ?);
179 rewrite > assoc_times;
180 rewrite > sym_times in ⊢ (? ? (? ? (? ? %)) ?);
181 change in \vdash (? ? (? ? (? ? %)) ?) with (exp b (S x));
182 rewrite > assoc_times in \vdash (? ? (? ? %) ?);
183 rewrite > sym_times in \vdash (? ? (? % ?) ?);
184 rewrite > sym_times in \vdash (? ? (? ? %) ?);
185 rewrite > assoc_times in \vdash (? ? ? %);
186 rewrite > sym_times in \vdash (? ? ? %);
187 rewrite < distr_times_plus;
188 rewrite > sym_plus;rewrite < bc1;
189 [reflexivity|assumption]]
190 |intros;simplify;reflexivity
191 |intros;simplify;reflexivity
192 |intros;apply le_S_S;assumption
195 [simplify in H2;destruct H2
196 |simplify;reflexivity]
198 [simplify in H2;destruct H2
199 |simplify;apply le_S_S_to_le;assumption]]]
200 |apply le_S_S;apply le_O_n
202 |intros;simplify;reflexivity
203 |intros;simplify;reflexivity
204 |intros;apply le_S_S;assumption
207 [simplify in H2;destruct H2
208 |simplify;reflexivity]
210 [simplify in H2;destruct H2
211 |simplify;apply le_S_S_to_le;assumption]]
212 |apply le_S_S;apply le_O_n
218 theorem exp_S_sigma_p:\forall a,n.
219 exp (S a) n = sigma_p (S n) (\lambda k.true) (\lambda k.(bc n k)*(exp a (n-k))).
222 rewrite > exp_plus_sigma_p.
223 apply eq_sigma_p;intros
226 rewrite < times_n_SO.