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