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.
7 ||A|| This file is distributed under the terms of the
8 \ / GNU General Public License Version 2
10 V_______________________________________________________________ *)
12 include "arithmetics/bigops.ma".
14 definition natAop ≝ mk_Aop nat 0 plus (λa.refl ? a) (λn.sym_eq ??? (plus_n_O n))
15 (λa,b,c.sym_eq ??? (associative_plus a b c)).
17 definition natACop ≝ mk_ACop nat 0 natAop commutative_plus.
19 definition natDop ≝ mk_Dop nat 0 natACop times (λn.(sym_eq ??? (times_n_O n)))
20 distributive_times_plus.
22 unification hint 0 ≔ ;
24 (* ---------------------------------------- *) ⊢
27 unification hint 0 ≔ ;
29 (* ---------------------------------------- *) ⊢
32 unification hint 0 ≔ ;
34 (* ---------------------------------------- *) ⊢
37 unification hint 0 ≔ ;
39 (* ---------------------------------------- *) ⊢
44 notation "∑_{ ident i < n | p } f"
46 for @{'bigop $n plus 0 (λ${ident i}.$p) (λ${ident i}. $f)}.
48 notation "∑_{ ident i < n } f"
50 for @{'bigop $n plus 0 (λ${ident i}.true) (λ${ident i}. $f)}.
52 notation "∑_{ ident j ∈ [a,b[ } f"
54 for @{'bigop ($b-$a) plus 0 (λ${ident j}.((λ${ident j}.true) (${ident j}+$a)))
55 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
57 notation "∑_{ ident j ∈ [a,b[ | p } f"
59 for @{'bigop ($b-$a) plus 0 (λ${ident j}.((λ${ident j}.$p) (${ident j}+$a)))
60 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
62 notation "∏_{ ident i < n | p} f"
64 for @{'bigop $n times 1 (λ${ident i}.$p) (λ${ident i}. $f)}.
66 notation "∏_{ ident i < n } f"
68 for @{'bigop $n times 1 (λ${ident i}.true) (λ${ident i}. $f)}.
70 notation "∏_{ ident j ∈ [a,b[ } f"
72 for @{'bigop ($b-$a) times 1 (λ${ident j}.((λ${ident j}.true) (${ident j}+$a)))
73 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
75 notation "∏_{ ident j ∈ [a,b[ | p } f"
77 for @{'bigop ($b-$a) times 1 (λ${ident j}.((λ${ident j}.$p) (${ident j}+$a)))
78 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
83 definition p_ord_times \def
86 [pair q r \Rightarrow r*m+q].
88 theorem eq_p_ord_times: \forall p,m,x.
89 p_ord_times p m x = (ord_rem x p)*m+(ord x p).
90 intros.unfold p_ord_times. unfold ord_rem.
96 theorem div_p_ord_times:
97 \forall p,m,x. ord x p < m \to p_ord_times p m x / m = ord_rem x p.
98 intros.rewrite > eq_p_ord_times.
103 theorem mod_p_ord_times:
104 \forall p,m,x. ord x p < m \to p_ord_times p m x \mod m = ord x p.
105 intros.rewrite > eq_p_ord_times.
106 apply mod_plus_times.
110 lemma lt_times_to_lt_O: \forall i,n,m:nat. i < n*m \to O < m.
112 elim (le_to_or_lt_eq O ? (le_O_n m))
116 rewrite < times_n_O in H.
117 apply (not_le_Sn_O ? H)
121 theorem iter_p_gen_knm:
124 \forall plusA: A \to A \to A.
125 (symmetric A plusA) \to
126 (associative A plusA) \to
127 (\forall a:A.(plusA a baseA) = a)\to
128 \forall g: nat \to A.
129 \forall h2:nat \to nat \to nat.
130 \forall h11,h12:nat \to nat.
132 \forall p1,p21:nat \to bool.
133 \forall p22:nat \to nat \to bool.
134 (\forall x. x < k \to p1 x = true \to
135 p21 (h11 x) = true \land p22 (h11 x) (h12 x) = true
136 \land h2 (h11 x) (h12 x) = x
137 \land (h11 x) < n \land (h12 x) < m) \to
138 (\forall i,j. i < n \to j < m \to p21 i = true \to p22 i j = true \to
139 p1 (h2 i j) = true \land
140 h11 (h2 i j) = i \land h12 (h2 i j) = j
141 \land h2 i j < k) \to
142 iter_p_gen k p1 A g baseA plusA =
143 iter_p_gen n p21 A (\lambda x:nat.iter_p_gen m (p22 x) A (\lambda y. g (h2 x y)) baseA plusA) baseA plusA.
145 rewrite < (iter_p_gen2' n m p21 p22 ? ? ? ? H H1 H2).
147 apply (eq_iter_p_gen_gh A baseA plusA H H1 H2 g ? (\lambda x.(h11 x)*m+(h12 x)))
149 elim (H4 (i/m) (i \mod m));clear H4
153 |apply (lt_times_to_lt_div ? ? ? H5)
155 apply (lt_times_to_lt_O ? ? ? H5)
156 |apply (andb_true_true ? ? H6)
157 |apply (andb_true_true_r ? ? H6)
160 elim (H4 (i/m) (i \mod m));clear H4
167 apply (lt_times_to_lt_O ? ? ? H5)
168 |apply (lt_times_to_lt_div ? ? ? H5)
170 apply (lt_times_to_lt_O ? ? ? H5)
171 |apply (andb_true_true ? ? H6)
172 |apply (andb_true_true_r ? ? H6)
175 elim (H4 (i/m) (i \mod m));clear H4
179 |apply (lt_times_to_lt_div ? ? ? H5)
181 apply (lt_times_to_lt_O ? ? ? H5)
182 |apply (andb_true_true ? ? H6)
183 |apply (andb_true_true_r ? ? H6)
190 rewrite > div_plus_times
191 [rewrite > mod_plus_times
204 rewrite > div_plus_times
205 [rewrite > mod_plus_times
216 apply (lt_to_le_to_lt ? ((h11 j)*m+m))
217 [apply monotonic_lt_plus_r.
220 change with ((S (h11 j)*m) \le n*m).
221 apply monotonic_le_times_l.
227 theorem iter_p_gen_divides:
230 \forall plusA: A \to A \to A.
231 \forall n,m,p:nat.O < n \to prime p \to Not (divides p n) \to
232 \forall g: nat \to A.
233 (symmetric A plusA) \to (associative A plusA) \to (\forall a:A.(plusA a baseA) = a)
237 iter_p_gen (S (n*(exp p m))) (\lambda x.divides_b x (n*(exp p m))) A g baseA plusA =
238 iter_p_gen (S n) (\lambda x.divides_b x n) A
239 (\lambda x.iter_p_gen (S m) (\lambda y.true) A (\lambda y.g (x*(exp p y))) baseA plusA) baseA plusA.
242 [rewrite < (iter_p_gen2 ? ? ? ? ? ? ? ? H3 H4 H5).
244 (iter_p_gen (S n*S m) (\lambda x:nat.divides_b (x/S m) n) A
245 (\lambda x:nat.g (x/S m*(p)\sup(x\mod S m))) baseA plusA) )
247 apply (eq_iter_p_gen_gh ? ? ? ? ? ? g ? (p_ord_times p (S m)))
252 lapply (divides_b_true_to_lt_O ? ? H H7).
253 apply divides_to_divides_b_true
254 [rewrite > (times_n_O O).
257 |apply lt_O_exp.assumption
260 [apply divides_b_true_to_divides.assumption
261 |apply (witness ? ? (p \sup (m-i \mod (S m)))).
262 rewrite < exp_plus_times.
265 apply plus_minus_m_m.
266 autobatch by le_S_S_to_le, lt_mod_m_m, lt_O_S;
270 lapply (divides_b_true_to_lt_O ? ? H H7).
272 rewrite > (p_ord_exp1 p ? (i \mod (S m)) (i/S m))
273 [change with ((i/S m)*S m+i \mod S m=i).
280 apply (trans_divides ? (i/ S m))
282 apply divides_b_true_to_divides;assumption]
289 change with ((i/S m) < S n).
290 apply (lt_times_to_lt_l m).
291 apply (le_to_lt_to_lt ? i);[2:assumption]
292 autobatch by eq_plus_to_le, div_mod, lt_O_S.
302 [rewrite > div_p_ord_times
303 [apply divides_to_divides_b_true
306 |apply (divides_b_true_to_lt_O ? ? ? H7).
307 rewrite > (times_n_O O).
309 [assumption|apply lt_O_exp.assumption]
311 |cut (n = ord_rem (n*(exp p m)) p)
313 apply divides_to_divides_ord_rem
314 [apply (divides_b_true_to_lt_O ? ? ? H7).
315 rewrite > (times_n_O O).
317 [assumption|apply lt_O_exp.assumption]
318 |rewrite > (times_n_O O).
320 [assumption|apply lt_O_exp.assumption]
322 |apply divides_b_true_to_divides.
326 rewrite > (p_ord_exp1 p ? m n)
336 |cut (m = ord (n*(exp p m)) p)
339 apply divides_to_le_ord
340 [apply (divides_b_true_to_lt_O ? ? ? H7).
341 rewrite > (times_n_O O).
343 [assumption|apply lt_O_exp.assumption]
344 |rewrite > (times_n_O O).
346 [assumption|apply lt_O_exp.assumption]
348 |apply divides_b_true_to_divides.
352 rewrite > (p_ord_exp1 p ? m n)
362 [rewrite > div_p_ord_times
363 [rewrite > mod_p_ord_times
364 [rewrite > sym_times.
368 |apply (divides_b_true_to_lt_O ? ? ? H7).
369 rewrite > (times_n_O O).
371 [assumption|apply lt_O_exp.assumption]
373 |cut (m = ord (n*(exp p m)) p)
376 apply divides_to_le_ord
377 [apply (divides_b_true_to_lt_O ? ? ? H7).
378 rewrite > (times_n_O O).
380 [assumption|apply lt_O_exp.assumption]
381 |rewrite > (times_n_O O).
383 [assumption|apply lt_O_exp.assumption]
385 |apply divides_b_true_to_divides.
389 rewrite > (p_ord_exp1 p ? m n)
399 |cut (m = ord (n*(exp p m)) p)
402 apply divides_to_le_ord
403 [apply (divides_b_true_to_lt_O ? ? ? H7).
404 rewrite > (times_n_O O).
406 [assumption|apply lt_O_exp.assumption]
407 |rewrite > (times_n_O O).
409 [assumption|apply lt_O_exp.assumption]
411 |apply divides_b_true_to_divides.
415 rewrite > (p_ord_exp1 p ? m n)
424 rewrite > eq_p_ord_times.
426 apply (lt_to_le_to_lt ? (S m +ord_rem j p*S m))
429 cut (m = ord (n*(p \sup m)) p)
431 apply divides_to_le_ord
432 [apply (divides_b_true_to_lt_O ? ? ? H7).
433 rewrite > (times_n_O O).
435 [assumption|apply lt_O_exp.assumption]
436 |rewrite > (times_n_O O).
438 [assumption|apply lt_O_exp.assumption]
440 |apply divides_b_true_to_divides.
445 rewrite > (p_ord_exp1 p ? m n)
452 |change with (S (ord_rem j p)*S m \le S n*S m).
455 cut (n = ord_rem (n*(p \sup m)) p)
460 |rewrite > (times_n_O O).
462 [assumption|apply lt_O_exp.assumption]
464 |apply divides_to_divides_ord_rem
465 [apply (divides_b_true_to_lt_O ? ? ? H7).
466 rewrite > (times_n_O O).
468 [assumption|apply lt_O_exp.assumption]
469 |rewrite > (times_n_O O).
471 [assumption|apply lt_O_exp.assumption]
473 |apply divides_b_true_to_divides.
479 rewrite > (p_ord_exp1 p ? m n)
491 elim (divides_b (x/S m) n);reflexivity
495 |elim H1.apply lt_to_le.assumption
501 theorem iter_p_gen_2_eq:
504 \forall plusA: A \to A \to A.
505 (symmetric A plusA) \to
506 (associative A plusA) \to
507 (\forall a:A.(plusA a baseA) = a)\to
508 \forall g: nat \to nat \to A.
509 \forall h11,h12,h21,h22: nat \to nat \to nat.
511 \forall p11,p21:nat \to bool.
512 \forall p12,p22:nat \to nat \to bool.
513 (\forall i,j. i < n2 \to j < m2 \to p21 i = true \to p22 i j = true \to
514 p11 (h11 i j) = true \land p12 (h11 i j) (h12 i j) = true
515 \land h21 (h11 i j) (h12 i j) = i \land h22 (h11 i j) (h12 i j) = j
516 \land h11 i j < n1 \land h12 i j < m1) \to
517 (\forall i,j. i < n1 \to j < m1 \to p11 i = true \to p12 i j = true \to
518 p21 (h21 i j) = true \land p22 (h21 i j) (h22 i j) = true
519 \land h11 (h21 i j) (h22 i j) = i \land h12 (h21 i j) (h22 i j) = j
520 \land (h21 i j) < n2 \land (h22 i j) < m2) \to
522 (\lambda x:nat .iter_p_gen m1 (p12 x) A (\lambda y. g x y) baseA plusA)
525 (\lambda x:nat .iter_p_gen m2 (p22 x) A (\lambda y. g (h11 x y) (h12 x y)) baseA plusA )
529 rewrite < (iter_p_gen2' ? ? ? ? ? ? ? ? H H1 H2).
530 letin ha:= (\lambda x,y.(((h11 x y)*m1) + (h12 x y))).
531 letin ha12:= (\lambda x.(h21 (x/m1) (x \mod m1))).
532 letin ha22:= (\lambda x.(h22 (x/m1) (x \mod m1))).
535 (iter_p_gen n2 p21 A (\lambda x:nat. iter_p_gen m2 (p22 x) A
536 (\lambda y:nat.(g (((h11 x y)*m1+(h12 x y))/m1) (((h11 x y)*m1+(h12 x y))\mod m1))) baseA plusA ) baseA plusA))
538 apply (iter_p_gen_knm A baseA plusA H H1 H2 (\lambda e. (g (e/m1) (e \mod m1))) ha ha12 ha22);intros
539 [ elim (and_true ? ? H6).
542 [ cut((x \mod m1) < m1)
543 [ elim (H4 ? ? Hcut1 Hcut2 H7 H8).
571 | apply (lt_times_n_to_lt m1)
573 | apply (le_to_lt_to_lt ? x)
574 [ apply (eq_plus_to_le ? ? (x \mod m1)).
581 | apply not_le_to_lt.unfold.intro.
582 generalize in match H5.
583 apply (le_n_O_elim ? H9).
588 | elim (H3 ? ? H5 H6 H7 H8).
593 cut(((h11 i j)*m1 + (h12 i j))/m1 = (h11 i j))
594 [ cut(((h11 i j)*m1 + (h12 i j)) \mod m1 = (h12 i j))
598 [ apply true_to_true_to_andb_true
619 [ apply (lt_to_le_to_lt ? ((h11 i j)*m1 + m1) )
623 | rewrite > sym_plus.
624 rewrite > (sym_times (h11 i j) m1).
625 rewrite > times_n_Sm.
630 | apply not_le_to_lt.unfold.intro.
631 generalize in match H12.
632 apply (le_n_O_elim ? H11).
636 | apply not_le_to_lt.unfold.intro.
637 generalize in match H10.
638 apply (le_n_O_elim ? H11).
643 | rewrite > (mod_plus_times m1 (h11 i j) (h12 i j)).
647 | rewrite > (div_plus_times m1 (h11 i j) (h12 i j)).
652 | apply (eq_iter_p_gen1)
653 [ intros. reflexivity
655 apply (eq_iter_p_gen1)
656 [ intros. reflexivity
658 rewrite > (div_plus_times)
659 [ rewrite > (mod_plus_times)
661 | elim (H3 x x1 H5 H7 H6 H8).
664 | elim (H3 x x1 H5 H7 H6 H8).
672 theorem iter_p_gen_iter_p_gen:
675 \forall plusA: A \to A \to A.
676 (symmetric A plusA) \to
677 (associative A plusA) \to
678 (\forall a:A.(plusA a baseA) = a)\to
679 \forall g: nat \to nat \to A.
681 \forall p11,p21:nat \to bool.
682 \forall p12,p22:nat \to nat \to bool.
683 (\forall x,y. x < n \to y < m \to
684 (p11 x \land p12 x y) = (p21 y \land p22 y x)) \to
686 (\lambda x:nat.iter_p_gen m (p12 x) A (\lambda y. g x y) baseA plusA)
689 (\lambda y:nat.iter_p_gen n (p22 y) A (\lambda x. g x y) baseA plusA )
692 apply (iter_p_gen_2_eq A baseA plusA H H1 H2 (\lambda x,y. g x y) (\lambda x,y.y) (\lambda x,y.x) (\lambda x,y.y) (\lambda x,y.x)
693 n m m n p11 p21 p12 p22)
699 [apply (andb_true_true ? (p12 j i)).
701 [rewrite > H6.rewrite > H7.reflexivity
705 |apply (andb_true_true_r (p11 j)).
707 [rewrite > H6.rewrite > H7.reflexivity
725 [apply (andb_true_true ? (p22 j i)).
727 [rewrite > H6.rewrite > H7.reflexivity
731 |apply (andb_true_true_r (p21 j)).
733 [rewrite > H6.rewrite > H7.reflexivity