]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/arithmetics/big_pi.ma
Still porting chebyshev
[helm.git] / matita / matita / lib / arithmetics / big_pi.ma
1 (*
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.                     
5     ||I||                                                                 
6     ||T||  
7     ||A||  This file is distributed under the terms of the 
8     \   /  GNU General Public License Version 2        
9      \ /      
10       V_______________________________________________________________ *)
11
12 include "arithmetics/primes.ma".
13 include "arithmetics/bigops.ma".
14
15 theorem sigma_const: ∀n:nat. ∑_{i<n} 1 = n.
16 #n elim n // #n1 >bigop_Strue //
17 qed.
18
19 (* monotonicity; these roperty should be expressed at a more
20 genral level *)
21
22 theorem le_pi: 
23 ∀n.∀p:nat → bool.∀g1,g2:nat → nat. 
24   (∀i.i<n → p i = true → g1 i ≤ g2 i ) → 
25   ∏_{i < n | p i} (g1 i) ≤ ∏_{i < n | p i} (g2 i).
26 #n #p #g1 #g2 elim n 
27   [#_ @le_n
28   |#n1 #Hind #Hle cases (true_or_false (p n1)) #Hcase
29     [ >bigop_Strue // >bigop_Strue // @le_times
30       [@Hle // |@Hind #i #lti #Hpi @Hle [@lt_to_le @le_S_S @lti|@Hpi]]
31     |>bigop_Sfalse // >bigop_Sfalse // @Hind
32      #i #lti #Hpi @Hle [@lt_to_le @le_S_S @lti|@Hpi]
33     ]
34   ]
35 qed.
36     
37 theorem exp_sigma: ∀n,a,p. 
38   ∏_{i < n | p i} a = exp a (∑_{i < n | p i} 1).
39 #n #a #p elim n // #n1 cases (true_or_false (p n1)) #Hcase
40   [>bigop_Strue // >bigop_Strue // |>bigop_Sfalse // >bigop_Sfalse //] 
41 qed.
42
43 theorem times_pi: ∀n,p,f,g. 
44   ∏_{i<n|p i}(f i*g i) = ∏_{i<n|p i}(f i) * ∏_{i<n|p i}(g i). 
45 #n #p #f #g elim n // #n1 cases (true_or_false (p n1)) #Hcase #Hind
46   [>bigop_Strue // >bigop_Strue // >bigop_Strue //
47   |>bigop_Sfalse // >bigop_Sfalse // >bigop_Sfalse //
48   ]
49 qed.
50
51 theorem pi_1: ∀n,p. 
52   ∏_{i < n | p i} 1 = 1.
53 #n #p elim n // #n1 #Hind cases (true_or_false (p n1)) #Hc 
54   [>bigop_Strue >Hind // |>bigop_Sfalse // ]
55 qed.
56
57 theorem exp_pi: ∀n,m,p,f. 
58   ∏_{i < n | p i}(exp (f i) m) = exp (∏_{i < n | p i}(f i)) m.
59 #n #m #p #f elim m
60   [@pi_1
61   |#m1 #Hind >times_pi >Hind %
62   ]
63 qed.
64
65 (*
66 theorem true_to_pi_p_Sn: ∀n,p,g.
67   p n = true \to pi_p (S n) p g = (g n)*(pi_p n p g).
68 intros.
69 unfold pi_p.
70 apply true_to_iter_p_gen_Sn.
71 assumption.
72 qed.
73    
74 theorem false_to_pi_p_Sn: 
75 \forall n:nat. \forall p:nat \to bool. \forall g:nat \to nat.
76 p n = false \to pi_p (S n) p g = pi_p n p g.
77 intros.
78 unfold pi_p.
79 apply false_to_iter_p_gen_Sn.
80 assumption.
81 qed.  
82
83 theorem eq_pi_p: \forall p1,p2:nat \to bool.
84 \forall g1,g2: nat \to nat.\forall n.
85 (\forall x.  x < n \to p1 x = p2 x) \to
86 (\forall x.  x < n \to g1 x = g2 x) \to
87 pi_p n p1 g1 = pi_p n p2 g2.
88 intros.
89 unfold pi_p.
90 apply eq_iter_p_gen;
91 assumption.
92 qed.
93
94 theorem eq_pi_p1: \forall p1,p2:nat \to bool.
95 \forall g1,g2: nat \to nat.\forall n.
96 (\forall x.  x < n \to p1 x = p2 x) \to
97 (\forall x.  x < n \to p1 x = true \to g1 x = g2 x) \to
98 pi_p n p1 g1 = pi_p n p2 g2.
99 intros.
100 unfold pi_p.
101 apply eq_iter_p_gen1;
102 assumption.
103 qed.
104
105 theorem pi_p_false: 
106 \forall g: nat \to nat.\forall n.pi_p n (\lambda x.false) g = S O.
107 intros.
108 unfold pi_p.
109 apply iter_p_gen_false.
110 qed.
111
112 theorem pi_p_times: \forall n,k:nat.\forall p:nat \to bool.
113 \forall g: nat \to nat.
114 pi_p (k+n) p g 
115 = pi_p k (\lambda x.p (x+n)) (\lambda x.g (x+n)) * pi_p n p g.
116 intros.
117 unfold pi_p.
118 apply (iter_p_gen_plusA nat n k p g (S O) times)
119 [ apply sym_times.
120 | intros.
121   apply sym_eq.
122   apply times_n_SO
123 | apply associative_times
124 ]
125 qed.
126
127 theorem false_to_eq_pi_p: \forall n,m:nat.n \le m \to
128 \forall p:nat \to bool.
129 \forall g: nat \to nat. (\forall i:nat. n \le i \to i < m \to
130 p i = false) \to pi_p m p g = pi_p n p g.
131 intros.
132 unfold pi_p.
133 apply (false_to_eq_iter_p_gen);
134 assumption.
135 qed.
136
137 theorem or_false_eq_SO_to_eq_pi_p: 
138 \forall n,m:nat.\forall p:nat \to bool.
139 \forall g: nat \to nat.
140 n \le m \to (\forall i:nat. n \le i \to i < m \to p i = false \lor g i = S O)
141 \to pi_p m p g = pi_p n p g.
142 intros.
143 unfold pi_p.
144 apply or_false_eq_baseA_to_eq_iter_p_gen
145   [intros.simplify.rewrite < plus_n_O.reflexivity
146   |assumption
147   |assumption
148   ]
149 qed.
150
151 theorem pi_p2 : 
152 \forall n,m:nat.
153 \forall p1,p2:nat \to bool.
154 \forall g: nat \to nat \to nat.
155 pi_p (n*m) 
156   (\lambda x.andb (p1 (div x m)) (p2 (mod x m))) 
157   (\lambda x.g (div x m) (mod x m)) =
158 pi_p n p1 
159   (\lambda x.pi_p m p2 (g x)).
160 intros.
161 unfold pi_p.
162 apply (iter_p_gen2 n m p1 p2 nat g (S O) times)
163 [ apply sym_times
164 | apply associative_times
165 | intros.
166   apply sym_eq.
167   apply times_n_SO
168 ]
169 qed.
170
171 theorem pi_p2' : 
172 \forall n,m:nat.
173 \forall p1:nat \to bool.
174 \forall p2:nat \to nat \to bool.
175 \forall g: nat \to nat \to nat.
176 pi_p (n*m) 
177   (\lambda x.andb (p1 (div x m)) (p2 (div x m) (mod x  m))) 
178   (\lambda x.g (div x m) (mod x m)) =
179 pi_p n p1 
180   (\lambda x.pi_p m (p2 x) (g x)).
181 intros.
182 unfold pi_p.
183 apply (iter_p_gen2' n m p1 p2 nat g (S O) times)
184 [ apply sym_times
185 | apply associative_times
186 | intros.
187   apply sym_eq.
188   apply times_n_SO
189 ]
190 qed.
191
192 lemma pi_p_gi: \forall g: nat \to nat.
193 \forall n,i.\forall p:nat \to bool.i < n \to p i = true \to 
194 pi_p n p g = g i * pi_p n (\lambda x. andb (p x) (notb (eqb x i))) g.
195 intros.
196 unfold pi_p.
197 apply (iter_p_gen_gi)
198 [ apply sym_times
199 | apply associative_times
200 | intros.
201   apply sym_eq.
202   apply times_n_SO
203 | assumption
204 | assumption
205 ]
206 qed.
207
208 theorem eq_pi_p_gh: 
209 \forall g,h,h1: nat \to nat.\forall n,n1.
210 \forall p1,p2:nat \to bool.
211 (\forall i. i < n \to p1 i = true \to p2 (h i) = true) \to
212 (\forall i. i < n \to p1 i = true \to h1 (h i) = i) \to 
213 (\forall i. i < n \to p1 i = true \to h i < n1) \to 
214 (\forall j. j < n1 \to p2 j = true \to p1 (h1 j) = true) \to
215 (\forall j. j < n1 \to p2 j = true \to h (h1 j) = j) \to 
216 (\forall j. j < n1 \to p2 j = true \to h1 j < n) \to 
217 pi_p n p1 (\lambda x.g(h x)) = pi_p n1 p2 g.
218 intros.
219 unfold pi_p.
220 apply (eq_iter_p_gen_gh nat (S O) times ? ? ? g h h1 n n1 p1 p2)
221 [ apply sym_times
222 | apply associative_times
223 | intros.
224   apply sym_eq.
225   apply times_n_SO
226 | assumption
227 | assumption
228 | assumption
229 | assumption
230 | assumption
231 | assumption
232 ]
233 qed.
234      
235 theorem exp_sigma_p: \forall n,a,p. 
236 pi_p n p (\lambda x.a) = (exp a (sigma_p n p (\lambda x.S O))).
237 intros.
238 elim n
239   [reflexivity
240   |apply (bool_elim ? (p n1))
241     [intro.
242      rewrite > true_to_pi_p_Sn
243       [rewrite > true_to_sigma_p_Sn
244         [simplify.
245          rewrite > H.
246          reflexivity.
247         |assumption
248         ]
249       |assumption
250       ]
251     |intro.
252      rewrite > false_to_pi_p_Sn
253       [rewrite > false_to_sigma_p_Sn
254         [simplify.assumption
255         |assumption
256         ]
257       |assumption
258       ]
259     ]
260   ]
261 qed.
262
263 theorem exp_sigma_p1: \forall n,a,p,f. 
264 pi_p n p (\lambda x.(exp a (f x))) = (exp a (sigma_p n p f)).
265 intros.
266 elim n
267   [reflexivity
268   |apply (bool_elim ? (p n1))
269     [intro.
270      rewrite > true_to_pi_p_Sn
271       [rewrite > true_to_sigma_p_Sn
272         [simplify.
273          rewrite > H.
274          rewrite > exp_plus_times.
275          reflexivity.
276         |assumption
277         ]
278       |assumption
279       ]
280     |intro.
281      rewrite > false_to_pi_p_Sn
282       [rewrite > false_to_sigma_p_Sn
283         [simplify.assumption
284         |assumption
285         ]
286       |assumption
287       ]
288     ]
289   ]
290 qed.
291
292 theorem times_pi_p: \forall n,p,f,g. 
293 pi_p n p (\lambda x.f x*g x) = pi_p n p f * pi_p n p  g. 
294 intros.
295 elim n
296   [simplify.reflexivity
297   |apply (bool_elim ? (p n1))
298     [intro.
299      rewrite > true_to_pi_p_Sn
300       [rewrite > true_to_pi_p_Sn
301         [rewrite > true_to_pi_p_Sn
302           [rewrite > H.autobatch
303           |assumption
304           ]
305         |assumption
306         ]
307       |assumption
308       ]
309     |intro.
310      rewrite > false_to_pi_p_Sn
311       [rewrite > false_to_pi_p_Sn
312         [rewrite > false_to_pi_p_Sn;assumption
313         |assumption
314         ]
315       |assumption
316       ]
317     ]
318   ]
319 qed.
320
321
322 theorem exp_times_pi_p: \forall n,m,k,p,f. 
323 pi_p n p (\lambda x.exp k (m*(f x))) = 
324 exp (pi_p n p (\lambda x.exp k (f x))) m.
325 intros.
326 apply (trans_eq ? ? (pi_p n p (\lambda x.(exp (exp k (f x)) m))))
327   [apply eq_pi_p;intros
328     [reflexivity
329     |apply sym_eq.rewrite > sym_times.
330      apply exp_exp_times
331     ]
332   |apply exp_pi_p
333   ]
334 qed.
335
336
337 theorem pi_p_knm:
338 \forall g: nat \to nat.
339 \forall h2:nat \to nat \to nat.
340 \forall h11,h12:nat \to nat. 
341 \forall k,n,m.
342 \forall p1,p21:nat \to bool.
343 \forall p22:nat \to nat \to bool.
344 (\forall x. x < k \to p1 x = true \to 
345 p21 (h11 x) = true ∧ p22 (h11 x) (h12 x) = true
346 \land h2 (h11 x) (h12 x) = x 
347 \land (h11 x) < n \land (h12 x) < m) \to
348 (\forall i,j. i < n \to j < m \to p21 i = true \to p22 i j = true \to 
349 p1 (h2 i j) = true \land 
350 h11 (h2 i j) = i \land h12 (h2 i j) = j
351 \land h2 i j < k) →
352 (*
353 Pi z < k | p1 z. g z = 
354 Pi x < n | p21 x. Pi y < m | p22 x y.g (h2 x y).
355 *)
356 pi_p k p1 g =
357 pi_p n p21 (\lambda x:nat.pi_p m (p22 x) (\lambda y. g (h2 x y))).
358 intros.
359 unfold pi_p.unfold pi_p.
360 apply (iter_p_gen_knm nat (S O) times sym_times assoc_times ? ? ? h11 h12)
361   [intros.apply sym_eq.apply times_n_SO.
362   |assumption
363   |assumption
364   ]
365 qed.
366
367 theorem pi_p_pi_p: 
368 \forall g: nat \to nat \to nat.
369 \forall h11,h12,h21,h22: nat \to nat \to nat. 
370 \forall n1,m1,n2,m2.
371 \forall p11,p21:nat \to bool.
372 \forall p12,p22:nat \to nat \to bool.
373 (\forall i,j. i < n2 \to j < m2 \to p21 i = true \to p22 i j = true \to 
374 p11 (h11 i j) = true \land p12 (h11 i j) (h12 i j) = true
375 \land h21 (h11 i j) (h12 i j) = i \land h22 (h11 i j) (h12 i j) = j
376 \land h11 i j < n1 \land h12 i j < m1) \to
377 (\forall i,j. i < n1 \to j < m1 \to p11 i = true \to p12 i j = true \to 
378 p21 (h21 i j) = true \land p22 (h21 i j) (h22 i j) = true
379 \land h11 (h21 i j) (h22 i j) = i \land h12 (h21 i j) (h22 i j) = j
380 \land (h21 i j) < n2 \land (h22 i j) < m2) \to
381 pi_p n1 p11 
382      (\lambda x:nat .pi_p m1 (p12 x) (\lambda y. g x y)) =
383 pi_p n2 p21 
384     (\lambda x:nat .pi_p m2 (p22 x)  (\lambda y. g (h11 x y) (h12 x y))).
385 intros.
386 unfold pi_p.unfold pi_p.
387 apply (iter_p_gen_2_eq ? ? ? sym_times assoc_times ? ? ? ? h21 h22)
388   [intros.apply sym_eq.apply times_n_SO.
389   |assumption
390   |assumption
391   ]
392 qed.
393
394 theorem pi_p_pi_p1: 
395 \forall g: nat \to nat \to nat.
396 \forall n,m.
397 \forall p11,p21:nat \to bool.
398 \forall p12,p22:nat \to nat \to bool.
399 (\forall x,y. x < n \to y < m \to 
400  (p11 x \land p12 x y) = (p21 y \land p22 y x)) \to
401 pi_p n p11 (\lambda x:nat.pi_p m (p12 x) (\lambda y. g x y)) =
402 pi_p m p21 (\lambda y:nat.pi_p n (p22 y) (\lambda x. g x y)).
403 intros.
404 unfold pi_p.unfold pi_p.
405 apply (iter_p_gen_iter_p_gen ? ? ? sym_times assoc_times)
406   [intros.apply sym_eq.apply times_n_SO.
407   |assumption
408   ]
409 qed. *)