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/Z/sigma_p".
18 include "nat/primes.ma".
20 include "nat/generic_iter_p.ma".
22 (* sigma_p in Z is a specialization of iter_p_gen *)
23 definition sigma_p: nat \to (nat \to bool) \to (nat \to Z) \to Z \def
24 \lambda n, p, g. (iter_p_gen n p Z g OZ Zplus).
26 theorem symmetricZPlus: symmetric Z Zplus.
27 change with (\forall a,b:Z. (Zplus a b) = (Zplus b a)).
33 theorem true_to_sigma_p_Sn:
34 \forall n:nat. \forall p:nat \to bool. \forall g:nat \to Z.
35 p n = true \to sigma_p (S n) p g =
36 (g n)+(sigma_p n p g).
39 apply true_to_iter_p_gen_Sn.
43 theorem false_to_sigma_p_Sn:
44 \forall n:nat. \forall p:nat \to bool. \forall g:nat \to Z.
45 p n = false \to sigma_p (S n) p g = sigma_p n p g.
48 apply false_to_iter_p_gen_Sn.
52 theorem eq_sigma_p: \forall p1,p2:nat \to bool.
53 \forall g1,g2: nat \to Z.\forall n.
54 (\forall x. x < n \to p1 x = p2 x) \to
55 (\forall x. x < n \to g1 x = g2 x) \to
56 sigma_p n p1 g1 = sigma_p n p2 g2.
63 theorem eq_sigma_p1: \forall p1,p2:nat \to bool.
64 \forall g1,g2: nat \to Z.\forall n.
65 (\forall x. x < n \to p1 x = p2 x) \to
66 (\forall x. x < n \to p1 x = true \to g1 x = g2 x) \to
67 sigma_p n p1 g1 = sigma_p n p2 g2.
74 theorem sigma_p_false:
75 \forall g: nat \to Z.\forall n.sigma_p n (\lambda x.false) g = O.
78 apply iter_p_gen_false.
81 theorem sigma_p_plus: \forall n,k:nat.\forall p:nat \to bool.
84 = sigma_p k (\lambda x.p (x+n)) (\lambda x.g (x+n)) + sigma_p n p g.
87 apply (iter_p_gen_plusA Z n k p g OZ Zplus)
88 [ apply symmetricZPlus.
90 apply cic:/matita/Z/plus/Zplus_z_OZ.con
91 | apply associative_Zplus
95 theorem false_to_eq_sigma_p: \forall n,m:nat.n \le m \to
96 \forall p:nat \to bool.
97 \forall g: nat \to Z. (\forall i:nat. n \le i \to i < m \to
98 p i = false) \to sigma_p m p g = sigma_p n p g.
101 apply (false_to_eq_iter_p_gen);
107 \forall p1,p2:nat \to bool.
108 \forall g: nat \to nat \to Z.
110 (\lambda x.andb (p1 (div x m)) (p2 (mod x m)))
111 (\lambda x.g (div x m) (mod x m)) =
113 (\lambda x.sigma_p m p2 (g x)).
116 apply (iter_p_gen2 n m p1 p2 Z g OZ Zplus)
117 [ apply symmetricZPlus
118 | apply associative_Zplus
124 (* a stronger, dependent version, required e.g. for dirichlet product *)
128 \forall p1:nat \to bool.
129 \forall p2:nat \to nat \to bool.
130 \forall g: nat \to nat \to Z.
132 (\lambda x.andb (p1 (div x m)) (p2 (div x m) (mod x m)))
133 (\lambda x.g (div x m) (mod x m)) =
135 (\lambda x.sigma_p m (p2 x) (g x)).
138 apply (iter_p_gen2' n m p1 p2 Z g OZ Zplus)
139 [ apply symmetricZPlus
140 | apply associative_Zplus
146 lemma sigma_p_gi: \forall g: nat \to Z.
147 \forall n,i.\forall p:nat \to bool.i < n \to p i = true \to
148 sigma_p n p g = g i + sigma_p n (\lambda x. andb (p x) (notb (eqb x i))) g.
151 apply (iter_p_gen_gi)
152 [ apply symmetricZPlus
153 | apply associative_Zplus
161 theorem eq_sigma_p_gh:
162 \forall g: nat \to Z.
163 \forall h,h1: nat \to nat.\forall n,n1.
164 \forall p1,p2:nat \to bool.
165 (\forall i. i < n \to p1 i = true \to p2 (h i) = true) \to
166 (\forall i. i < n \to p1 i = true \to h1 (h i) = i) \to
167 (\forall i. i < n \to p1 i = true \to h i < n1) \to
168 (\forall j. j < n1 \to p2 j = true \to p1 (h1 j) = true) \to
169 (\forall j. j < n1 \to p2 j = true \to h (h1 j) = j) \to
170 (\forall j. j < n1 \to p2 j = true \to h1 j < n) \to
171 sigma_p n p1 (\lambda x.g(h x)) = sigma_p n1 p2 g.
174 apply (eq_iter_p_gen_gh Z OZ Zplus ? ? ? g h h1 n n1 p1 p2)
175 [ apply symmetricZPlus
176 | apply associative_Zplus
189 theorem divides_exp_to_lt_ord:\forall n,m,j,p. O < n \to prime p \to
190 p \ndivides n \to j \divides n*(exp p m) \to ord j p < S m.
192 cut (m = ord (n*(exp p m)) p)
195 apply divides_to_le_ord
196 [elim (le_to_or_lt_eq ? ? (le_O_n j))
199 apply (lt_to_not_eq ? ? H).
201 rewrite < H4 in H5.simplify in H5.
202 elim (times_O_to_O ? ? H5)
203 [apply sym_eq.assumption
205 apply (not_le_Sn_n O).
206 rewrite < H6 in \vdash (? ? %).
208 elim H1.apply lt_to_le.assumption
211 |rewrite > (times_n_O O).
213 [assumption|apply lt_O_exp.apply (prime_to_lt_O ? H1)]
218 rewrite > (p_ord_exp1 p ? m n)
220 |apply (prime_to_lt_O ? H1)
227 theorem divides_exp_to_divides_ord_rem:\forall n,m,j,p. O < n \to prime p \to
228 p \ndivides n \to j \divides n*(exp p m) \to ord_rem j p \divides n.
231 [cut (n = ord_rem (n*(exp p m)) p)
233 apply divides_to_divides_ord_rem
235 |rewrite > (times_n_O O).
237 [assumption|apply lt_O_exp.apply (prime_to_lt_O ? H1)]
242 rewrite > (p_ord_exp1 p ? m n)
244 |apply (prime_to_lt_O ? H1)
249 |elim (le_to_or_lt_eq ? ? (le_O_n j))
252 apply (lt_to_not_eq ? ? H).
254 rewrite < H4 in H5.simplify in H5.
255 elim (times_O_to_O ? ? H5)
256 [apply sym_eq.assumption
258 apply (not_le_Sn_n O).
259 rewrite < H6 in \vdash (? ? %).
261 elim H1.apply lt_to_le.assumption
268 theorem sigma_p_divides_b:
269 \forall n,m,p:nat.O < n \to prime p \to Not (divides p n) \to
270 \forall g: nat \to Z.
271 sigma_p (S (n*(exp p m))) (\lambda x.divides_b x (n*(exp p m))) g =
272 sigma_p (S n) (\lambda x.divides_b x n)
273 (\lambda x.sigma_p (S m) (\lambda y.true) (\lambda y.g (x*(exp p y)))).
276 apply (iter_p_gen_divides Z OZ Zplus n m p ? ? ? g)
280 | apply symmetricZPlus
281 | apply associative_Zplus
288 (* sigma_p and Ztimes *)
289 lemma Ztimes_sigma_pl: \forall z:Z.\forall n:nat.\forall p. \forall f.
290 z * (sigma_p n p f) = sigma_p n p (\lambda i.z*(f i)).
292 apply (distributive_times_plus_iter_p_gen Z Zplus OZ Ztimes n z p f)
293 [ apply symmetricZPlus
294 | apply associative_Zplus
297 | apply symmetric_Ztimes
298 | apply distributive_Ztimes_Zplus
300 rewrite > (Ztimes_z_OZ a).
305 lemma Ztimes_sigma_pr: \forall z:Z.\forall n:nat.\forall p. \forall f.
306 (sigma_p n p f) * z = sigma_p n p (\lambda i.(f i)*z).
308 rewrite < sym_Ztimes.
309 rewrite > Ztimes_sigma_pl.
312 |intros.apply sym_Ztimes
317 (* sigma from n1*m1 to n2*m2 *)
319 \forall g: nat \to nat \to Z.
320 \forall h11,h12,h21,h22: nat \to nat \to nat.
322 \forall p11,p21:nat \to bool.
323 \forall p12,p22:nat \to nat \to bool.
324 (\forall i,j. i < n2 \to j < m2 \to p21 i = true \to p22 i j = true \to
325 p11 (h11 i j) = true \land p12 (h11 i j) (h12 i j) = true
326 \land h21 (h11 i j) (h12 i j) = i \land h22 (h11 i j) (h12 i j) = j
327 \land h11 i j < n1 \land h12 i j < m1) \to
328 (\forall i,j. i < n1 \to j < m1 \to p11 i = true \to p12 i j = true \to
329 p21 (h21 i j) = true \land p22 (h21 i j) (h22 i j) = true
330 \land h11 (h21 i j) (h22 i j) = i \land h12 (h21 i j) (h22 i j) = j
331 \land (h21 i j) < n2 \land (h22 i j) < m2) \to
332 sigma_p n1 p11 (\lambda x:nat .sigma_p m1 (p12 x) (\lambda y. g x y)) =
333 sigma_p n2 p21 (\lambda x:nat .sigma_p m2 (p22 x) (\lambda y. g (h11 x y) (h12 x y))).
338 letin h := (\lambda x.(h11 (x/m2) (x\mod m2))*m1 + (h12 (x/m2) (x\mod m2))).
339 letin h1 := (\lambda x.(h21 (x/m1) (x\mod m1))*m2 + (h22 (x/m1) (x\mod m1))).
341 (sigma_p (n2*m2) (\lambda x:nat.p21 (x/m2)\land p22 (x/m2) (x\mod m2))
342 (\lambda x:nat.g ((h x)/m1) ((h x)\mod m1))))
349 [cut (x \mod m2 < m2)
350 [elim (and_true ? ? H3).
351 elim (H ? ? Hcut1 Hcut2 H4 H5).
358 apply div_plus_times.
365 |apply (lt_times_n_to_lt m2)
367 |apply (le_to_lt_to_lt ? x)
368 [apply (eq_plus_to_le ? ? (x \mod m2)).
375 |apply not_le_to_lt.unfold.intro.
376 generalize in match H2.
377 apply (le_n_O_elim ? H4).
383 |apply (eq_sigma_p_gh ? h h1);intros
386 [cut (i \mod m2 < m2)
387 [elim (and_true ? ? H3).
388 elim (H ? ? Hcut1 Hcut2 H4 H5).
393 cut ((h11 (i/m2) (i\mod m2)*m1+h12 (i/m2) (i\mod m2))/m1 =
394 h11 (i/m2) (i\mod m2))
395 [cut ((h11 (i/m2) (i\mod m2)*m1+h12 (i/m2) (i\mod m2))\mod m1 =
396 h12 (i/m2) (i\mod m2))
402 |apply mod_plus_times.
405 |apply div_plus_times.
411 |apply (lt_times_n_to_lt m2)
413 |apply (le_to_lt_to_lt ? i)
414 [apply (eq_plus_to_le ? ? (i \mod m2)).
421 |apply not_le_to_lt.unfold.intro.
422 generalize in match H2.
423 apply (le_n_O_elim ? H4).
430 [cut (i \mod m2 < m2)
431 [elim (and_true ? ? H3).
432 elim (H ? ? Hcut1 Hcut2 H4 H5).
437 cut ((h11 (i/m2) (i\mod m2)*m1+h12 (i/m2) (i\mod m2))/m1 =
438 h11 (i/m2) (i\mod m2))
439 [cut ((h11 (i/m2) (i\mod m2)*m1+h12 (i/m2) (i\mod m2))\mod m1 =
440 h12 (i/m2) (i\mod m2))
448 |apply mod_plus_times.
451 |apply div_plus_times.
457 |apply (lt_times_n_to_lt m2)
459 |apply (le_to_lt_to_lt ? i)
460 [apply (eq_plus_to_le ? ? (i \mod m2)).
467 |apply not_le_to_lt.unfold.intro.
468 generalize in match H2.
469 apply (le_n_O_elim ? H4).
476 [cut (i \mod m2 < m2)
477 [elim (and_true ? ? H3).
478 elim (H ? ? Hcut1 Hcut2 H4 H5).
483 apply lt_times_plus_times
484 [assumption|assumption]
488 |apply (lt_times_n_to_lt m2)
490 |apply (le_to_lt_to_lt ? i)
491 [apply (eq_plus_to_le ? ? (i \mod m2)).
498 |apply not_le_to_lt.unfold.intro.
499 generalize in match H2.
500 apply (le_n_O_elim ? H4).
507 [cut (j \mod m1 < m1)
508 [elim (and_true ? ? H3).
509 elim (H1 ? ? Hcut1 Hcut2 H4 H5).
514 cut ((h21 (j/m1) (j\mod m1)*m2+h22 (j/m1) (j\mod m1))/m2 =
515 h21 (j/m1) (j\mod m1))
516 [cut ((h21 (j/m1) (j\mod m1)*m2+h22 (j/m1) (j\mod m1))\mod m2 =
517 h22 (j/m1) (j\mod m1))
523 |apply mod_plus_times.
526 |apply div_plus_times.
532 |apply (lt_times_n_to_lt m1)
534 |apply (le_to_lt_to_lt ? j)
535 [apply (eq_plus_to_le ? ? (j \mod m1)).
542 |apply not_le_to_lt.unfold.intro.
543 generalize in match H2.
544 apply (le_n_O_elim ? H4).
551 [cut (j \mod m1 < m1)
552 [elim (and_true ? ? H3).
553 elim (H1 ? ? Hcut1 Hcut2 H4 H5).
558 cut ((h21 (j/m1) (j\mod m1)*m2+h22 (j/m1) (j\mod m1))/m2 =
559 h21 (j/m1) (j\mod m1))
560 [cut ((h21 (j/m1) (j\mod m1)*m2+h22 (j/m1) (j\mod m1))\mod m2 =
561 h22 (j/m1) (j\mod m1))
569 |apply mod_plus_times.
572 |apply div_plus_times.
578 |apply (lt_times_n_to_lt m1)
580 |apply (le_to_lt_to_lt ? j)
581 [apply (eq_plus_to_le ? ? (j \mod m1)).
588 |apply not_le_to_lt.unfold.intro.
589 generalize in match H2.
590 apply (le_n_O_elim ? H4).
597 [cut (j \mod m1 < m1)
598 [elim (and_true ? ? H3).
599 elim (H1 ? ? Hcut1 Hcut2 H4 H5).
604 apply (lt_times_plus_times ? ? ? m2)
605 [assumption|assumption]
609 |apply (lt_times_n_to_lt m1)
611 |apply (le_to_lt_to_lt ? j)
612 [apply (eq_plus_to_le ? ? (j \mod m1)).
619 |apply not_le_to_lt.unfold.intro.
620 generalize in match H2.
621 apply (le_n_O_elim ? H4).