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 include "nat/primes.ma".
16 (* include "nat/ord.ma". *)
17 include "nat/generic_iter_p.ma".
18 (* include "nat/count.ma". necessary just to use bool_to_nat and bool_to_nat_andb*)
19 include "nat/iteration2.ma".
21 (* pi_p on nautral numbers is a specialization of iter_p_gen *)
22 definition pi_p: nat \to (nat \to bool) \to (nat \to nat) \to nat \def
23 \lambda n, p, g. (iter_p_gen n p nat g (S O) times).
25 theorem true_to_pi_p_Sn:
26 \forall n:nat. \forall p:nat \to bool. \forall g:nat \to nat.
27 p n = true \to pi_p (S n) p g = (g n)*(pi_p n p g).
30 apply true_to_iter_p_gen_Sn.
34 theorem false_to_pi_p_Sn:
35 \forall n:nat. \forall p:nat \to bool. \forall g:nat \to nat.
36 p n = false \to pi_p (S n) p g = pi_p n p g.
39 apply false_to_iter_p_gen_Sn.
43 theorem eq_pi_p: \forall p1,p2:nat \to bool.
44 \forall g1,g2: nat \to nat.\forall n.
45 (\forall x. x < n \to p1 x = p2 x) \to
46 (\forall x. x < n \to g1 x = g2 x) \to
47 pi_p n p1 g1 = pi_p n p2 g2.
54 theorem eq_pi_p1: \forall p1,p2:nat \to bool.
55 \forall g1,g2: nat \to nat.\forall n.
56 (\forall x. x < n \to p1 x = p2 x) \to
57 (\forall x. x < n \to p1 x = true \to g1 x = g2 x) \to
58 pi_p n p1 g1 = pi_p n p2 g2.
66 \forall g: nat \to nat.\forall n.pi_p n (\lambda x.false) g = S O.
69 apply iter_p_gen_false.
72 theorem pi_p_times: \forall n,k:nat.\forall p:nat \to bool.
73 \forall g: nat \to nat.
75 = pi_p k (\lambda x.p (x+n)) (\lambda x.g (x+n)) * pi_p n p g.
78 apply (iter_p_gen_plusA nat n k p g (S O) times)
83 | apply associative_times
87 theorem false_to_eq_pi_p: \forall n,m:nat.n \le m \to
88 \forall p:nat \to bool.
89 \forall g: nat \to nat. (\forall i:nat. n \le i \to i < m \to
90 p i = false) \to pi_p m p g = pi_p n p g.
93 apply (false_to_eq_iter_p_gen);
97 theorem or_false_eq_SO_to_eq_pi_p:
98 \forall n,m:nat.\forall p:nat \to bool.
99 \forall g: nat \to nat.
100 n \le m \to (\forall i:nat. n \le i \to i < m \to p i = false \lor g i = S O)
101 \to pi_p m p g = pi_p n p g.
104 apply or_false_eq_baseA_to_eq_iter_p_gen
105 [intros.simplify.rewrite < plus_n_O.reflexivity
113 \forall p1,p2:nat \to bool.
114 \forall g: nat \to nat \to nat.
116 (\lambda x.andb (p1 (div x m)) (p2 (mod x m)))
117 (\lambda x.g (div x m) (mod x m)) =
119 (\lambda x.pi_p m p2 (g x)).
122 apply (iter_p_gen2 n m p1 p2 nat g (S O) times)
124 | apply associative_times
133 \forall p1:nat \to bool.
134 \forall p2:nat \to nat \to bool.
135 \forall g: nat \to nat \to nat.
137 (\lambda x.andb (p1 (div x m)) (p2 (div x m) (mod x m)))
138 (\lambda x.g (div x m) (mod x m)) =
140 (\lambda x.pi_p m (p2 x) (g x)).
143 apply (iter_p_gen2' n m p1 p2 nat g (S O) times)
145 | apply associative_times
152 lemma pi_p_gi: \forall g: nat \to nat.
153 \forall n,i.\forall p:nat \to bool.i < n \to p i = true \to
154 pi_p n p g = g i * pi_p n (\lambda x. andb (p x) (notb (eqb x i))) g.
157 apply (iter_p_gen_gi)
159 | apply associative_times
169 \forall g,h,h1: nat \to nat.\forall n,n1.
170 \forall p1,p2:nat \to bool.
171 (\forall i. i < n \to p1 i = true \to p2 (h i) = true) \to
172 (\forall i. i < n \to p1 i = true \to h1 (h i) = i) \to
173 (\forall i. i < n \to p1 i = true \to h i < n1) \to
174 (\forall j. j < n1 \to p2 j = true \to p1 (h1 j) = true) \to
175 (\forall j. j < n1 \to p2 j = true \to h (h1 j) = j) \to
176 (\forall j. j < n1 \to p2 j = true \to h1 j < n) \to
177 pi_p n p1 (\lambda x.g(h x)) = pi_p n1 p2 g.
180 apply (eq_iter_p_gen_gh nat (S O) times ? ? ? g h h1 n n1 p1 p2)
182 | apply associative_times
197 \forall n:nat. \forall p:nat \to bool. \forall g1,g2:nat \to nat.
198 (\forall i. i < n \to p i = true \to g1 i \le g2 i ) \to
199 pi_p n p g1 \le pi_p n p g2.
203 |apply (bool_elim ? (p n1));intros
204 [rewrite > true_to_pi_p_Sn
205 [rewrite > true_to_pi_p_Sn in ⊢ (? ? %)
207 [apply H1[apply le_n|assumption]
210 apply H1[apply le_S.assumption|assumption]
216 |rewrite > false_to_pi_p_Sn
217 [rewrite > false_to_pi_p_Sn in ⊢ (? ? %)
220 apply H1[apply le_S.assumption|assumption]
229 theorem exp_sigma_p: \forall n,a,p.
230 pi_p n p (\lambda x.a) = (exp a (sigma_p n p (\lambda x.S O))).
234 |apply (bool_elim ? (p n1))
236 rewrite > true_to_pi_p_Sn
237 [rewrite > true_to_sigma_p_Sn
246 rewrite > false_to_pi_p_Sn
247 [rewrite > false_to_sigma_p_Sn
257 theorem exp_sigma_p1: \forall n,a,p,f.
258 pi_p n p (\lambda x.(exp a (f x))) = (exp a (sigma_p n p f)).
262 |apply (bool_elim ? (p n1))
264 rewrite > true_to_pi_p_Sn
265 [rewrite > true_to_sigma_p_Sn
268 rewrite > exp_plus_times.
275 rewrite > false_to_pi_p_Sn
276 [rewrite > false_to_sigma_p_Sn
286 theorem times_pi_p: \forall n,p,f,g.
287 pi_p n p (\lambda x.f x*g x) = pi_p n p f * pi_p n p g.
290 [simplify.reflexivity
291 |apply (bool_elim ? (p n1))
293 rewrite > true_to_pi_p_Sn
294 [rewrite > true_to_pi_p_Sn
295 [rewrite > true_to_pi_p_Sn
296 [rewrite > H.autobatch
304 rewrite > false_to_pi_p_Sn
305 [rewrite > false_to_pi_p_Sn
306 [rewrite > false_to_pi_p_Sn;assumption
315 theorem pi_p_SO: \forall n,p.
316 pi_p n p (\lambda i.S O) = S O.
319 |simplify.elim (p n1)
320 [simplify.rewrite < plus_n_O.assumption
326 theorem exp_pi_p: \forall n,m,p,f.
327 pi_p n p (\lambda x.exp (f x) m) = exp (pi_p n p f) m.
330 [simplify.apply pi_p_SO
332 rewrite > times_pi_p.
338 theorem exp_times_pi_p: \forall n,m,k,p,f.
339 pi_p n p (\lambda x.exp k (m*(f x))) =
340 exp (pi_p n p (\lambda x.exp k (f x))) m.
342 apply (trans_eq ? ? (pi_p n p (\lambda x.(exp (exp k (f x)) m))))
343 [apply eq_pi_p;intros
345 |apply sym_eq.rewrite > sym_times.
354 \forall g: nat \to nat.
355 \forall h2:nat \to nat \to nat.
356 \forall h11,h12:nat \to nat.
358 \forall p1,p21:nat \to bool.
359 \forall p22:nat \to nat \to bool.
360 (\forall x. x < k \to p1 x = true \to
361 p21 (h11 x) = true \land p22 (h11 x) (h12 x) = true
362 \land h2 (h11 x) (h12 x) = x
363 \land (h11 x) < n \land (h12 x) < m) \to
364 (\forall i,j. i < n \to j < m \to p21 i = true \to p22 i j = true \to
365 p1 (h2 i j) = true \land
366 h11 (h2 i j) = i \land h12 (h2 i j) = j
367 \land h2 i j < k) \to
369 pi_p n p21 (\lambda x:nat.pi_p m (p22 x) (\lambda y. g (h2 x y))).
371 unfold pi_p.unfold pi_p.
372 apply (iter_p_gen_knm nat (S O) times sym_times assoc_times ? ? ? h11 h12)
373 [intros.apply sym_eq.apply times_n_SO.
380 \forall g: nat \to nat \to nat.
381 \forall h11,h12,h21,h22: nat \to nat \to nat.
383 \forall p11,p21:nat \to bool.
384 \forall p12,p22:nat \to nat \to bool.
385 (\forall i,j. i < n2 \to j < m2 \to p21 i = true \to p22 i j = true \to
386 p11 (h11 i j) = true \land p12 (h11 i j) (h12 i j) = true
387 \land h21 (h11 i j) (h12 i j) = i \land h22 (h11 i j) (h12 i j) = j
388 \land h11 i j < n1 \land h12 i j < m1) \to
389 (\forall i,j. i < n1 \to j < m1 \to p11 i = true \to p12 i j = true \to
390 p21 (h21 i j) = true \land p22 (h21 i j) (h22 i j) = true
391 \land h11 (h21 i j) (h22 i j) = i \land h12 (h21 i j) (h22 i j) = j
392 \land (h21 i j) < n2 \land (h22 i j) < m2) \to
394 (\lambda x:nat .pi_p m1 (p12 x) (\lambda y. g x y)) =
396 (\lambda x:nat .pi_p m2 (p22 x) (\lambda y. g (h11 x y) (h12 x y))).
398 unfold pi_p.unfold pi_p.
399 apply (iter_p_gen_2_eq ? ? ? sym_times assoc_times ? ? ? ? h21 h22)
400 [intros.apply sym_eq.apply times_n_SO.
407 \forall g: nat \to nat \to nat.
409 \forall p11,p21:nat \to bool.
410 \forall p12,p22:nat \to nat \to bool.
411 (\forall x,y. x < n \to y < m \to
412 (p11 x \land p12 x y) = (p21 y \land p22 y x)) \to
413 pi_p n p11 (\lambda x:nat.pi_p m (p12 x) (\lambda y. g x y)) =
414 pi_p m p21 (\lambda y:nat.pi_p n (p22 y) (\lambda x. g x y)).
416 unfold pi_p.unfold pi_p.
417 apply (iter_p_gen_iter_p_gen ? ? ? sym_times assoc_times)
418 [intros.apply sym_eq.apply times_n_SO.