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_______________________________________________________________ *)
13 include "arithmetics/bigops.ma".
15 definition natAop ≝ mk_Aop nat 0 plus (λa.refl ? a) (λn.sym_eq ??? (plus_n_O n))
16 (λa,b,c.sym_eq ??? (associative_plus a b c)).
18 definition natACop ≝ mk_ACop nat 0 natAop commutative_plus.
20 definition natDop ≝ mk_Dop nat 0 natACop times (λn.(sym_eq ??? (times_n_O n)))
21 distributive_times_plus.
23 unification hint 0 ≔ ;
25 (* ---------------------------------------- *) ⊢
28 unification hint 0 ≔ ;
30 (* ---------------------------------------- *) ⊢
33 unification hint 0 ≔ ;
35 (* ---------------------------------------- *) ⊢
38 unification hint 0 ≔ ;
40 (* ---------------------------------------- *) ⊢
45 notation "∑_{ ident i < n | p } f"
47 for @{'bigop $n plus 0 (λ${ident i}.$p) (λ${ident i}. $f)}.
49 notation "∑_{ ident i < n } f"
51 for @{'bigop $n plus 0 (λ${ident i}.true) (λ${ident i}. $f)}.
53 notation "∑_{ ident j ∈ [a,b[ } f"
55 for @{'bigop ($b-$a) plus 0 (λ${ident j}.((λ${ident j}.true) (${ident j}+$a)))
56 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
58 notation "∑_{ ident j ∈ [a,b[ | p } f"
60 for @{'bigop ($b-$a) plus 0 (λ${ident j}.((λ${ident j}.$p) (${ident j}+$a)))
61 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
63 notation "∏_{ ident i < n | p} f"
65 for @{'bigop $n times 1 (λ${ident i}.$p) (λ${ident i}. $f)}.
67 notation "∏_{ ident i < n } f"
69 for @{'bigop $n times 1 (λ${ident i}.true) (λ${ident i}. $f)}.
71 notation "∏_{ ident j ∈ [a,b[ } f"
73 for @{'bigop ($b-$a) times 1 (λ${ident j}.((λ${ident j}.true) (${ident j}+$a)))
74 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
76 notation "∏_{ ident j ∈ [a,b[ | p } f"
78 for @{'bigop ($b-$a) times 1 (λ${ident j}.((λ${ident j}.$p) (${ident j}+$a)))
79 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
84 definition p_ord_times \def
87 [pair q r \Rightarrow r*m+q].
89 theorem eq_p_ord_times: \forall p,m,x.
90 p_ord_times p m x = (ord_rem x p)*m+(ord x p).
91 intros.unfold p_ord_times. unfold ord_rem.
97 theorem div_p_ord_times:
98 \forall p,m,x. ord x p < m \to p_ord_times p m x / m = ord_rem x p.
99 intros.rewrite > eq_p_ord_times.
100 apply div_plus_times.
104 theorem mod_p_ord_times:
105 \forall p,m,x. ord x p < m \to p_ord_times p m x \mod m = ord x p.
106 intros.rewrite > eq_p_ord_times.
107 apply mod_plus_times.
111 lemma lt_times_to_lt_O: \forall i,n,m:nat. i < n*m \to O < m.
113 elim (le_to_or_lt_eq O ? (le_O_n m))
117 rewrite < times_n_O in H.
118 apply (not_le_Sn_O ? H)
122 theorem iter_p_gen_knm:
125 \forall plusA: A \to A \to A.
126 (symmetric A plusA) \to
127 (associative A plusA) \to
128 (\forall a:A.(plusA a baseA) = a)\to
129 \forall g: nat \to A.
130 \forall h2:nat \to nat \to nat.
131 \forall h11,h12:nat \to nat.
133 \forall p1,p21:nat \to bool.
134 \forall p22:nat \to nat \to bool.
135 (\forall x. x < k \to p1 x = true \to
136 p21 (h11 x) = true \land p22 (h11 x) (h12 x) = true
137 \land h2 (h11 x) (h12 x) = x
138 \land (h11 x) < n \land (h12 x) < m) \to
139 (\forall i,j. i < n \to j < m \to p21 i = true \to p22 i j = true \to
140 p1 (h2 i j) = true \land
141 h11 (h2 i j) = i \land h12 (h2 i j) = j
142 \land h2 i j < k) \to
143 iter_p_gen k p1 A g baseA plusA =
144 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.
146 rewrite < (iter_p_gen2' n m p21 p22 ? ? ? ? H H1 H2).
148 apply (eq_iter_p_gen_gh A baseA plusA H H1 H2 g ? (\lambda x.(h11 x)*m+(h12 x)))
150 elim (H4 (i/m) (i \mod m));clear H4
154 |apply (lt_times_to_lt_div ? ? ? H5)
156 apply (lt_times_to_lt_O ? ? ? H5)
157 |apply (andb_true_true ? ? H6)
158 |apply (andb_true_true_r ? ? H6)
161 elim (H4 (i/m) (i \mod m));clear H4
168 apply (lt_times_to_lt_O ? ? ? H5)
169 |apply (lt_times_to_lt_div ? ? ? H5)
171 apply (lt_times_to_lt_O ? ? ? H5)
172 |apply (andb_true_true ? ? H6)
173 |apply (andb_true_true_r ? ? H6)
176 elim (H4 (i/m) (i \mod m));clear H4
180 |apply (lt_times_to_lt_div ? ? ? H5)
182 apply (lt_times_to_lt_O ? ? ? H5)
183 |apply (andb_true_true ? ? H6)
184 |apply (andb_true_true_r ? ? H6)
191 rewrite > div_plus_times
192 [rewrite > mod_plus_times
205 rewrite > div_plus_times
206 [rewrite > mod_plus_times
217 apply (lt_to_le_to_lt ? ((h11 j)*m+m))
218 [apply monotonic_lt_plus_r.
221 change with ((S (h11 j)*m) \le n*m).
222 apply monotonic_le_times_l.
228 theorem iter_p_gen_divides:
231 \forall plusA: A \to A \to A.
232 \forall n,m,p:nat.O < n \to prime p \to Not (divides p n) \to
233 \forall g: nat \to A.
234 (symmetric A plusA) \to (associative A plusA) \to (\forall a:A.(plusA a baseA) = a)
238 iter_p_gen (S (n*(exp p m))) (\lambda x.divides_b x (n*(exp p m))) A g baseA plusA =
239 iter_p_gen (S n) (\lambda x.divides_b x n) A
240 (\lambda x.iter_p_gen (S m) (\lambda y.true) A (\lambda y.g (x*(exp p y))) baseA plusA) baseA plusA.
243 [rewrite < (iter_p_gen2 ? ? ? ? ? ? ? ? H3 H4 H5).
245 (iter_p_gen (S n*S m) (\lambda x:nat.divides_b (x/S m) n) A
246 (\lambda x:nat.g (x/S m*(p)\sup(x\mod S m))) baseA plusA) )
248 apply (eq_iter_p_gen_gh ? ? ? ? ? ? g ? (p_ord_times p (S m)))
253 lapply (divides_b_true_to_lt_O ? ? H H7).
254 apply divides_to_divides_b_true
255 [rewrite > (times_n_O O).
258 |apply lt_O_exp.assumption
261 [apply divides_b_true_to_divides.assumption
262 |apply (witness ? ? (p \sup (m-i \mod (S m)))).
263 rewrite < exp_plus_times.
266 apply plus_minus_m_m.
267 autobatch by le_S_S_to_le, lt_mod_m_m, lt_O_S;
271 lapply (divides_b_true_to_lt_O ? ? H H7).
273 rewrite > (p_ord_exp1 p ? (i \mod (S m)) (i/S m))
274 [change with ((i/S m)*S m+i \mod S m=i).
281 apply (trans_divides ? (i/ S m))
283 apply divides_b_true_to_divides;assumption]
290 change with ((i/S m) < S n).
291 apply (lt_times_to_lt_l m).
292 apply (le_to_lt_to_lt ? i);[2:assumption]
293 autobatch by eq_plus_to_le, div_mod, lt_O_S.
303 [rewrite > div_p_ord_times
304 [apply divides_to_divides_b_true
307 |apply (divides_b_true_to_lt_O ? ? ? H7).
308 rewrite > (times_n_O O).
310 [assumption|apply lt_O_exp.assumption]
312 |cut (n = ord_rem (n*(exp p m)) p)
314 apply divides_to_divides_ord_rem
315 [apply (divides_b_true_to_lt_O ? ? ? H7).
316 rewrite > (times_n_O O).
318 [assumption|apply lt_O_exp.assumption]
319 |rewrite > (times_n_O O).
321 [assumption|apply lt_O_exp.assumption]
323 |apply divides_b_true_to_divides.
327 rewrite > (p_ord_exp1 p ? m n)
337 |cut (m = ord (n*(exp p m)) p)
340 apply divides_to_le_ord
341 [apply (divides_b_true_to_lt_O ? ? ? H7).
342 rewrite > (times_n_O O).
344 [assumption|apply lt_O_exp.assumption]
345 |rewrite > (times_n_O O).
347 [assumption|apply lt_O_exp.assumption]
349 |apply divides_b_true_to_divides.
353 rewrite > (p_ord_exp1 p ? m n)
363 [rewrite > div_p_ord_times
364 [rewrite > mod_p_ord_times
365 [rewrite > sym_times.
369 |apply (divides_b_true_to_lt_O ? ? ? H7).
370 rewrite > (times_n_O O).
372 [assumption|apply lt_O_exp.assumption]
374 |cut (m = ord (n*(exp p m)) p)
377 apply divides_to_le_ord
378 [apply (divides_b_true_to_lt_O ? ? ? H7).
379 rewrite > (times_n_O O).
381 [assumption|apply lt_O_exp.assumption]
382 |rewrite > (times_n_O O).
384 [assumption|apply lt_O_exp.assumption]
386 |apply divides_b_true_to_divides.
390 rewrite > (p_ord_exp1 p ? m n)
400 |cut (m = ord (n*(exp p m)) p)
403 apply divides_to_le_ord
404 [apply (divides_b_true_to_lt_O ? ? ? H7).
405 rewrite > (times_n_O O).
407 [assumption|apply lt_O_exp.assumption]
408 |rewrite > (times_n_O O).
410 [assumption|apply lt_O_exp.assumption]
412 |apply divides_b_true_to_divides.
416 rewrite > (p_ord_exp1 p ? m n)
425 rewrite > eq_p_ord_times.
427 apply (lt_to_le_to_lt ? (S m +ord_rem j p*S m))
430 cut (m = ord (n*(p \sup m)) p)
432 apply divides_to_le_ord
433 [apply (divides_b_true_to_lt_O ? ? ? H7).
434 rewrite > (times_n_O O).
436 [assumption|apply lt_O_exp.assumption]
437 |rewrite > (times_n_O O).
439 [assumption|apply lt_O_exp.assumption]
441 |apply divides_b_true_to_divides.
446 rewrite > (p_ord_exp1 p ? m n)
453 |change with (S (ord_rem j p)*S m \le S n*S m).
456 cut (n = ord_rem (n*(p \sup m)) p)
461 |rewrite > (times_n_O O).
463 [assumption|apply lt_O_exp.assumption]
465 |apply divides_to_divides_ord_rem
466 [apply (divides_b_true_to_lt_O ? ? ? H7).
467 rewrite > (times_n_O O).
469 [assumption|apply lt_O_exp.assumption]
470 |rewrite > (times_n_O O).
472 [assumption|apply lt_O_exp.assumption]
474 |apply divides_b_true_to_divides.
480 rewrite > (p_ord_exp1 p ? m n)
492 elim (divides_b (x/S m) n);reflexivity
496 |elim H1.apply lt_to_le.assumption
502 theorem iter_p_gen_2_eq:
505 \forall plusA: A \to A \to A.
506 (symmetric A plusA) \to
507 (associative A plusA) \to
508 (\forall a:A.(plusA a baseA) = a)\to
509 \forall g: nat \to nat \to A.
510 \forall h11,h12,h21,h22: nat \to nat \to nat.
512 \forall p11,p21:nat \to bool.
513 \forall p12,p22:nat \to nat \to bool.
514 (\forall i,j. i < n2 \to j < m2 \to p21 i = true \to p22 i j = true \to
515 p11 (h11 i j) = true \land p12 (h11 i j) (h12 i j) = true
516 \land h21 (h11 i j) (h12 i j) = i \land h22 (h11 i j) (h12 i j) = j
517 \land h11 i j < n1 \land h12 i j < m1) \to
518 (\forall i,j. i < n1 \to j < m1 \to p11 i = true \to p12 i j = true \to
519 p21 (h21 i j) = true \land p22 (h21 i j) (h22 i j) = true
520 \land h11 (h21 i j) (h22 i j) = i \land h12 (h21 i j) (h22 i j) = j
521 \land (h21 i j) < n2 \land (h22 i j) < m2) \to
523 (\lambda x:nat .iter_p_gen m1 (p12 x) A (\lambda y. g x y) baseA plusA)
526 (\lambda x:nat .iter_p_gen m2 (p22 x) A (\lambda y. g (h11 x y) (h12 x y)) baseA plusA )
530 rewrite < (iter_p_gen2' ? ? ? ? ? ? ? ? H H1 H2).
531 letin ha:= (\lambda x,y.(((h11 x y)*m1) + (h12 x y))).
532 letin ha12:= (\lambda x.(h21 (x/m1) (x \mod m1))).
533 letin ha22:= (\lambda x.(h22 (x/m1) (x \mod m1))).
536 (iter_p_gen n2 p21 A (\lambda x:nat. iter_p_gen m2 (p22 x) A
537 (\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))
539 apply (iter_p_gen_knm A baseA plusA H H1 H2 (\lambda e. (g (e/m1) (e \mod m1))) ha ha12 ha22);intros
540 [ elim (and_true ? ? H6).
543 [ cut((x \mod m1) < m1)
544 [ elim (H4 ? ? Hcut1 Hcut2 H7 H8).
572 | apply (lt_times_n_to_lt m1)
574 | apply (le_to_lt_to_lt ? x)
575 [ apply (eq_plus_to_le ? ? (x \mod m1)).
582 | apply not_le_to_lt.unfold.intro.
583 generalize in match H5.
584 apply (le_n_O_elim ? H9).
589 | elim (H3 ? ? H5 H6 H7 H8).
594 cut(((h11 i j)*m1 + (h12 i j))/m1 = (h11 i j))
595 [ cut(((h11 i j)*m1 + (h12 i j)) \mod m1 = (h12 i j))
599 [ apply true_to_true_to_andb_true
620 [ apply (lt_to_le_to_lt ? ((h11 i j)*m1 + m1) )
624 | rewrite > sym_plus.
625 rewrite > (sym_times (h11 i j) m1).
626 rewrite > times_n_Sm.
631 | apply not_le_to_lt.unfold.intro.
632 generalize in match H12.
633 apply (le_n_O_elim ? H11).
637 | apply not_le_to_lt.unfold.intro.
638 generalize in match H10.
639 apply (le_n_O_elim ? H11).
644 | rewrite > (mod_plus_times m1 (h11 i j) (h12 i j)).
648 | rewrite > (div_plus_times m1 (h11 i j) (h12 i j)).
653 | apply (eq_iter_p_gen1)
654 [ intros. reflexivity
656 apply (eq_iter_p_gen1)
657 [ intros. reflexivity
659 rewrite > (div_plus_times)
660 [ rewrite > (mod_plus_times)
662 | elim (H3 x x1 H5 H7 H6 H8).
665 | elim (H3 x x1 H5 H7 H6 H8).
673 theorem iter_p_gen_iter_p_gen:
676 \forall plusA: A \to A \to A.
677 (symmetric A plusA) \to
678 (associative A plusA) \to
679 (\forall a:A.(plusA a baseA) = a)\to
680 \forall g: nat \to nat \to A.
682 \forall p11,p21:nat \to bool.
683 \forall p12,p22:nat \to nat \to bool.
684 (\forall x,y. x < n \to y < m \to
685 (p11 x \land p12 x y) = (p21 y \land p22 y x)) \to
687 (\lambda x:nat.iter_p_gen m (p12 x) A (\lambda y. g x y) baseA plusA)
690 (\lambda y:nat.iter_p_gen n (p22 y) A (\lambda x. g x y) baseA plusA )
693 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)
694 n m m n p11 p21 p12 p22)
700 [apply (andb_true_true ? (p12 j i)).
702 [rewrite > H6.rewrite > H7.reflexivity
706 |apply (andb_true_true_r (p11 j)).
708 [rewrite > H6.rewrite > H7.reflexivity
726 [apply (andb_true_true ? (p22 j i)).
728 [rewrite > H6.rewrite > H7.reflexivity
732 |apply (andb_true_true_r (p21 j)).
734 [rewrite > H6.rewrite > H7.reflexivity