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 "basics/types.ma".
13 include "arithmetics/div_and_mod.ma".
15 definition sameF_upto: nat → ∀A.relation(nat→A) ≝
16 λk.λA.λf,g.∀i. i < k → f i = g i.
18 definition sameF_p: nat → (nat → bool) →∀A.relation(nat→A) ≝
19 λk,p,A,f,g.∀i. i < k → p i = true → f i = g i.
21 lemma sameF_upto_le: ∀A,f,g,n,m.
22 n ≤m → sameF_upto m A f g → sameF_upto n A f g.
23 #A #f #g #n #m #lenm #samef #i #ltin @samef /2 by lt_to_le_to_lt/
26 lemma sameF_p_le: ∀A,p,f,g,n,m.
27 n ≤m → sameF_p m p A f g → sameF_p n p A f g.
28 #A #p #f #g #n #m #lenm #samef #i #ltin #pi @samef /2 by lt_to_le_to_lt/
32 definition sumF ≝ λA.λf,g:nat → A.λn,i.
33 if_then_else ? (leb n i) (g (i-n)) (f i).
35 lemma sumF_unfold: ∀A,f,g,n,i.
36 sumF A f g n i = if_then_else ? (leb n i) (g (i-n)) (f i).
40 λA,B.λf:nat→A.λg:nat→B.λm,x.〈 f(div x m), g(mod x m) 〉.
43 let rec bigop (n:nat) (p:nat → bool) (B:Type[0])
44 (nil: B) (op: B → B → B) (f: nat → B) ≝
49 [true ⇒ op (f k) (bigop k p B nil op f)
50 |false ⇒ bigop k p B nil op f]
53 notation "\big [ op , nil ]_{ ident i < n | p } f"
55 for @{'bigop $n $op $nil (λ${ident i}. $p) (λ${ident i}. $f)}.
57 notation "\big [ op , nil ]_{ ident i < n } f"
59 for @{'bigop $n $op $nil (λ${ident i}.true) (λ${ident i}. $f)}.
61 interpretation "bigop" 'bigop n op nil p f = (bigop n p ? nil op f).
63 notation "\big [ op , nil ]_{ ident j ∈ [a,b[ | p } f"
65 for @{'bigop ($b-$a) $op $nil (λ${ident j}.((λ${ident j}.$p) (${ident j}+$a)))
66 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
68 notation "\big [ op , nil ]_{ ident j ∈ [a,b[ } f"
70 for @{'bigop ($b-$a) $op $nil (λ${ident j}.((λ${ident j}.true) (${ident j}+$a)))
71 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
73 (* notation "\big [ op , nil ]_{( term 55) a ≤ ident j < b | p } f"
75 for @{\big[$op,$nil]_{${ident j} < ($b-$a) | ((λ${ident j}.$p) (${ident j}+$a))}((λ${ident j}.$f)(${ident j}+$a))}.
78 interpretation "bigop" 'bigop n op nil p f = (bigop n p ? nil op f).
80 lemma bigop_Strue: ∀k,p,B,nil,op.∀f:nat→B. p k = true →
81 \big[op,nil]_{i < S k | p i}(f i) =
82 op (f k) (\big[op,nil]_{i < k | p i}(f i)).
83 #k #p #B #nil #op #f #H normalize >H // qed.
85 lemma bigop_Sfalse: ∀k,p,B,nil,op.∀f:nat→B. p k = false →
86 \big[op,nil]_{ i < S k | p i}(f i) =
87 \big[op,nil]_{i < k | p i}(f i).
88 #k #p #B #nil #op #f #H normalize >H // qed.
90 lemma same_bigop : ∀k,p1,p2,B,nil,op.∀f,g:nat→B.
91 sameF_upto k bool p1 p2 → sameF_p k p1 B f g →
92 \big[op,nil]_{i < k | p1 i}(f i) =
93 \big[op,nil]_{i < k | p2 i}(g i).
94 #k #p1 #p2 #B #nil #op #f #g (elim k) //
95 #n #Hind #samep #samef normalize >Hind /2/
96 <(samep … (le_n …)) cases(true_or_false (p1 n)) #H1 >H1
97 normalize // <(samef … (le_n …) H1) //
100 theorem pad_bigop: ∀k,n,p,B,nil,op.∀f:nat→B. n ≤ k →
101 \big[op,nil]_{i < n | p i}(f i)
102 = \big[op,nil]_{i < k | if leb n i then false else p i}(f i).
103 #k #n #p #B #nil #op #f #lenk (elim lenk)
104 [@same_bigop #i #lti // >(not_le_to_leb_false …) /2/
105 |#j #leup #Hind >bigop_Sfalse >(le_to_leb_true … leup) //
108 theorem pad_bigop1: ∀k,n,p,B,nil,op.∀f:nat→B. n ≤ k →
109 (∀i. n ≤ i → i < k → p i = false) →
110 \big[op,nil]_{i < n | p i}(f i)
111 = \big[op,nil]_{i < k | p i}(f i).
112 #k #n #p #B #nil #op #f #lenk (elim lenk)
113 [#_ @same_bigop #i #lti //
114 |#j #leup #Hind #Hfalse >bigop_Sfalse
115 [@Hind #i #leni #ltij @Hfalse // @le_S //
121 theorem bigop_false: ∀n,B,nil,op.∀f:nat→B.
122 \big[op,nil]_{i < n | false }(f i) = nil.
123 #n #B #nil #op #f elim n // #n1 #Hind
127 record Aop (A:Type[0]) (nil:A) : Type[0] ≝
129 nill:∀a. op nil a = a;
130 nilr:∀a. op a nil = a;
131 assoc: ∀a,b,c.op a (op b c) = op (op a b) c
134 theorem pad_bigop_nil: ∀k,n,p,B,nil.∀op:Aop B nil.∀f:nat→B. n ≤ k →
135 (∀i. n ≤ i → i < k → p i = false ∨ f i = nil) →
136 \big[op,nil]_{i < n | p i}(f i)
137 = \big[op,nil]_{i < k | p i}(f i).
138 #k #n #p #B #nil #op #f #lenk (elim lenk)
139 [#_ @same_bigop #i #lti //
140 |#j #leup #Hind #Hfalse cases (true_or_false (p j)) #Hpj
143 [cases (Hfalse j leup (le_n … )) // >Hpj #H destruct (H)] #Hfj
144 >Hfj >nill @Hind #i #leni #ltij
145 cases (Hfalse i leni (le_S … ltij)) /2/
146 |>bigop_Sfalse // @Hind #i #leni #ltij
147 cases (Hfalse i leni (le_S … ltij)) /2/
152 theorem bigop_sum: ∀k1,k2,p1,p2,B.∀nil.∀op:Aop B nil.∀f,g:nat→B.
153 op (\big[op,nil]_{i<k1|p1 i}(f i)) \big[op,nil]_{i<k2|p2 i}(g i) =
154 \big[op,nil]_{i<k1+k2|if leb k2 i then p1 (i-k2) else p2 i}
155 (if leb k2 i then f (i-k2) else g i).
156 #k1 #k2 #p1 #p2 #B #nil #op #f #g (elim k1)
157 [normalize >nill @same_bigop #i #lti
158 >(lt_to_leb_false … lti) normalize /2/
159 |#i #Hind normalize <minus_plus_m_m (cases (p1 i))
160 >(le_to_leb_true … (le_plus_n …)) normalize <Hind //
165 lemma plus_minus1: ∀a,b,c. c ≤ b → a + (b -c) = a + b -c.
166 #a #b #c #lecb @sym_eq @plus_to_minus >(commutative_plus c)
167 >associative_plus <plus_minus_m_m //
170 theorem bigop_I: ∀n,p,B.∀nil.∀op:Aop B nil.∀f:nat→B.
171 \big[op,nil]_{i∈[0,n[ |p i}(f i) = \big[op,nil]_{i < n|p i}(f i).
172 #n #p #B #nil #op #f <minus_n_O @same_bigop //
175 theorem bigop_sumI: ∀a,b,c,p,B.∀nil.∀op:Aop B nil.∀f:nat→B.
177 \big[op,nil]_{i∈[a,c[ |p i}(f i) =
178 op (\big[op,nil]_{i ∈ [b,c[ |p i}(f i))
179 \big[op,nil]_{i ∈ [a,b[ |p i}(f i).
180 #a #b # c #p #B #nil #op #f #leab #lebc
181 >(plus_minus_m_m (c-a) (b-a)) in ⊢ (??%?); /2/
182 >minus_plus >(commutative_plus a) <plus_minus_m_m //
183 >bigop_sum (cut (∀i. b -a ≤ i → i+a = i-(b-a)+b))
184 [#i #lei >plus_minus // <plus_minus1
185 [@eq_f @sym_eq @plus_to_minus /2/ | /2/]]
186 #H @same_bigop #i #ltic @leb_elim normalize // #lei <H //
189 theorem bigop_a: ∀a,b,B.∀nil.∀op:Aop B nil.∀f:nat→B. a ≤ b →
190 \big[op,nil]_{i∈[a,S b[ }(f i) =
191 op (\big[op,nil]_{i ∈ [a,b[ }(f (S i))) (f a).
192 #a #b #B #nil #op #f #leab
193 >(bigop_sumI a (S a) (S b)) [|@le_S_S //|//] @eq_f2
194 [@same_bigop // |<minus_Sn_n normalize @nilr]
197 theorem bigop_0: ∀n,B.∀nil.∀op:Aop B nil.∀f:nat→B.
198 \big[op,nil]_{i < S n}(f i) =
199 op (\big[op,nil]_{i < n}(f (S i))) (f 0).
201 <bigop_I >bigop_a [|//] @eq_f2 [|//] <minus_n_O
205 theorem bigop_prod: ∀k1,k2,p1,p2,B.∀nil.∀op:Aop B nil.∀f: nat →nat → B.
206 \big[op,nil]_{x<k1|p1 x}(\big[op,nil]_{i<k2|p2 x i}(f x i)) =
207 \big[op,nil]_{i<k1*k2|andb (p1 (i/k2)) (p2 (i/k2) (i \mod k2))}
208 (f (i/k2) (i \mod k2)).
209 #k1 #k2 #p1 #p2 #B #nil #op #f (elim k1) //
210 #n #Hind cases(true_or_false (p1 n)) #Hp1
211 [>bigop_Strue // >Hind >bigop_sum @same_bigop
212 #i #lti @leb_elim // #lei cut (i = n*k2+(i-n*k2)) /2 by plus_minus/
213 #eqi [|#H] >eqi in ⊢ (???%);
214 >div_plus_times /2 by monotonic_lt_minus_l/
215 >Hp1 >(mod_plus_times …) /2 by refl, monotonic_lt_minus_l, eq_f/
216 |>bigop_Sfalse // >Hind >(pad_bigop (S n*k2)) // @same_bigop
217 #i #lti @leb_elim // #lei cut (i = n*k2+(i-n*k2)) /2/
218 #eqi >eqi in ⊢ (???%); >div_plus_times /2/
222 record ACop (A:Type[0]) (nil:A) : Type[0] ≝
224 comm: ∀a,b.aop a b = aop b a
227 lemma bigop_op: ∀k,p,B.∀nil.∀op:ACop B nil.∀f,g: nat → B.
228 op (\big[op,nil]_{i<k|p i}(f i)) (\big[op,nil]_{i<k|p i}(g i)) =
229 \big[op,nil]_{i<k|p i}(op (f i) (g i)).
230 #k #p #B #nil #op #f #g (elim k) [normalize @nill]
231 -k #k #Hind (cases (true_or_false (p k))) #H
232 [>bigop_Strue // >bigop_Strue // >bigop_Strue //
233 normalize <assoc <assoc in ⊢ (???%); @eq_f >assoc >comm in ⊢ (??(????%?)?);
235 |>bigop_Sfalse // >bigop_Sfalse // >bigop_Sfalse //
239 lemma bigop_diff: ∀p,B.∀nil.∀op:ACop B nil.∀f:nat → B.∀i,n.
241 \big[op,nil]_{x<n|p x}(f x)=
242 op (f i) (\big[op,nil]_{x<n|andb(notb(eqb i x))(p x)}(f x)).
243 #p #B #nil #op #f #i #n (elim n)
245 |#n #Hind #lein #pi cases (le_to_or_lt_eq … (le_S_S_to_le …lein)) #Hi
246 [cut (andb(notb(eqb i n))(p n) = (p n))
247 [>(not_eq_to_eqb_false … (lt_to_not_eq … Hi)) //] #Hcut
248 cases (true_or_false (p n)) #pn
249 [>bigop_Strue // >bigop_Strue //
250 normalize >assoc >(comm ?? op (f i) (f n)) <assoc >Hind //
251 |>bigop_Sfalse // >bigop_Sfalse // >Hind //
253 |<Hi >bigop_Strue // @eq_f >bigop_Sfalse
254 [@same_bigop // #k #ltki >not_eq_to_eqb_false /2/
262 record range (A:Type[0]): Type[0] ≝
263 {enum:nat→A; upto:nat; filter:nat→bool}.
265 definition sub_hk: (nat→nat)→(nat→nat)→∀A:Type[0].relation (range A) ≝
266 λh,k,A,I,J.∀i.i<(upto A I) → (filter A I i)=true →
268 ∧ filter A J (h i) = true
271 definition iso: ∀A:Type[0].relation (range A) ≝
273 (∀i. i < (upto A I) → (filter A I i) = true →
274 enum A I i = enum A J (h i)) ∧
275 sub_hk h k A I J ∧ sub_hk k h A J I.
277 lemma sub_hkO: ∀h,k,A,I,J. upto A I = 0 → sub_hk h k A I J.
278 #h #k #A #I #J #up0 #i #lti >up0 @False_ind /2/
281 lemma sub0_to_false: ∀h,k,A,I,J. upto A I = 0 → sub_hk h k A J I →
282 ∀i. i < upto A J → filter A J i = false.
283 #h #k #A #I #J #up0 #sub #i #lti cases(true_or_false (filter A J i)) //
284 #ptrue (cases (sub i lti ptrue)) * #hi @False_ind /2/
287 lemma sub_lt: ∀A,e,p,n,m. n ≤ m →
288 sub_hk (λx.x) (λx.x) A (mk_range A e n p) (mk_range A e m p).
289 #A #e #f #n #m #lenm #i #lti #fi % // % /2 by lt_to_le_to_lt/
292 theorem transitive_sub: ∀h1,k1,h2,k2,A,I,J,K.
293 sub_hk h1 k1 A I J → sub_hk h2 k2 A J K →
294 sub_hk (λx.h2(h1 x)) (λx.k1(k2 x)) A I K.
295 #h1 #k1 #h2 #k2 #A #I #J #K #sub1 #sub2 #i #lti #fi
296 cases(sub1 i lti fi) * #lth1i #fh1i #ei
297 cases(sub2 (h1 i) lth1i fh1i) * #H1 #H2 #H3 % // % //
300 theorem bigop_iso: ∀n1,n2,p1,p2,B.∀nil.∀op:ACop B nil.∀f1,f2.
301 iso B (mk_range B f1 n1 p1) (mk_range B f2 n2 p2) →
302 \big[op,nil]_{i<n1|p1 i}(f1 i) = \big[op,nil]_{i<n2|p2 i}(f2 i).
303 #n1 #n2 #p1 #p2 #B #nil #op #f1 #f2 * #h * #k * * #same
304 @(le_gen ? n1) #i lapply p2 (elim i)
305 [(elim n2) // #m #Hind #p2 #_ #sub1 #sub2
307 [@(Hind ? (le_O_n ?)) [/2/ | @(transitive_sub … (sub_lt …) sub2) //]
308 |@(sub0_to_false … sub2) //
310 |#n #Hind #p2 #ltn #sub1 #sub2 (cut (n ≤n1)) [/2/] #len
311 cases(true_or_false (p1 n)) #p1n
312 [>bigop_Strue // (cases (sub1 n (le_n …) p1n)) * #hn #p2hn #eqn
313 >(bigop_diff … (h n) n2) // >same //
315 [#i #ltin #p1i (cases (sub1 i (le_S … ltin) p1i)) *
316 #h1i #p2h1i #eqi % // % // >not_eq_to_eqb_false normalize //
317 @(not_to_not ??? (lt_to_not_eq ? ? ltin)) //
318 |#j #ltj #p2j (cases (sub2 j ltj (andb_true_r …p2j))) *
319 #ltkj #p1kj #eqj % // % //
320 (cases (le_to_or_lt_eq …(le_S_S_to_le …ltkj))) //
321 #eqkj @False_ind lapply p2j @eqb_elim
324 |>bigop_Sfalse // @(Hind ? len)
325 [@(transitive_sub … (sub_lt …) sub1) //
326 |#i #lti #p2i cases(sub2 i lti p2i) * #ltki #p1ki #eqi
327 % // % // cases(le_to_or_lt_eq …(le_S_S_to_le …ltki)) //
334 (* lemma div_mod_exchange: ∀i,n,m. i < n*m → i\n = i mod m. *)
337 theorem bigop_commute: ∀n,m,p11,p12,p21,p22,B.∀nil.∀op:ACop B nil.∀f.
339 (∀i,j. i < n → j < m → (p11 i ∧ p12 i j) = (p21 j ∧ p22 i j)) →
340 \big[op,nil]_{i<n|p11 i}(\big[op,nil]_{j<m|p12 i j}(f i j)) =
341 \big[op,nil]_{j<m|p21 j}(\big[op,nil]_{i<n|p22 i j}(f i j)).
342 #n #m #p11 #p12 #p21 #p22 #B #nil #op #f #posn #posm #Heq
343 >bigop_prod >bigop_prod @bigop_iso
344 %{(λi.(i\mod m)*n + i/m)} %{(λi.(i\mod n)*m + i/n)} %
346 [#i #lti #Heq (* whd in ⊢ (???(?(?%?)?)); *) @eq_f2
347 [@sym_eq @mod_plus_times /2 by lt_times_to_lt_div/
348 |@sym_eq @div_plus_times /2 by lt_times_to_lt_div/
351 cut ((i\mod m*n+i/m)\mod n=i/m)
352 [@mod_plus_times @lt_times_to_lt_div //] #H1
353 cut ((i\mod m*n+i/m)/n=i \mod m)
354 [@div_plus_times @lt_times_to_lt_div //] #H2
355 %[%[@(lt_to_le_to_lt ? (i\mod m*n+n))
356 [whd >plus_n_Sm @monotonic_le_plus_r @lt_times_to_lt_div //
357 |>commutative_plus @(le_times (S(i \mod m)) m n n) // @lt_mod_m_m //
359 |lapply (Heq (i/m) (i \mod m) ??)
360 [@lt_mod_m_m // |@lt_times_to_lt_div //|>Hi >H1 >H2 //]
366 cut ((i\mod n*m+i/n)\mod m=i/n)
367 [@mod_plus_times @lt_times_to_lt_div //] #H1
368 cut ((i\mod n*m+i/n)/m=i \mod n)
369 [@div_plus_times @lt_times_to_lt_div //] #H2
370 %[%[@(lt_to_le_to_lt ? (i\mod n*m+m))
371 [whd >plus_n_Sm @monotonic_le_plus_r @lt_times_to_lt_div //
372 |>commutative_plus @(le_times (S(i \mod n)) n m m) // @lt_mod_m_m //
374 |lapply (Heq (i \mod n) (i/n) ??)
375 [@lt_times_to_lt_div // |@lt_mod_m_m // |>Hi >H1 >H2 //]
384 record Dop (A:Type[0]) (nil:A): Type[0] ≝
387 null: \forall a. prod a nil = nil;
388 distr: ∀a,b,c:A. prod a (sum b c) = sum (prod a b) (prod a c)
391 theorem bigop_distr: ∀n,p,B,nil.∀R:Dop B nil.∀f,a.
392 let aop ≝ sum B nil R in
393 let mop ≝ prod B nil R in
394 mop a \big[aop,nil]_{i<n|p i}(f i) =
395 \big[aop,nil]_{i<n|p i}(mop a (f i)).
396 #n #p #B #nil #R #f #a normalize (elim n) [@null]
397 #n #Hind (cases (true_or_false (p n))) #H
398 [>bigop_Strue // >bigop_Strue // >(distr B nil R) >Hind //
399 |>bigop_Sfalse // >bigop_Sfalse //
405 notation "∑_{ ident i < n | p } f"
407 for @{'bigop $n plus 0 (λ${ident i}. $p) (λ${ident i}. $f)}.
409 notation "∑_{ ident i < n } f"
411 for @{'bigop $n plus 0 (λ${ident i}.true) (λ${ident i}. $f)}.
413 notation "∑_{ ident j ∈ [a,b[ } f"
415 for @{'bigop ($b-$a) plus 0 (λ${ident j}.((λ${ident j}.true) (${ident j}+$a)))
416 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
418 notation "∑_{ ident j ∈ [a,b[ | p } f"
420 for @{'bigop ($b-$a) plus 0 (λ${ident j}.((λ${ident j}.$p) (${ident j}+$a)))
421 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
423 notation "∏_{ ident i < n | p} f"
425 for @{'bigop $n times 1 (λ${ident i}.$p) (λ${ident i}. $f)}.
427 notation "∏_{ ident i < n } f"
429 for @{'bigop $n times 1 (λ${ident i}.true) (λ${ident i}. $f)}.
431 notation "∏_{ ident j ∈ [a,b[ } f"
433 for @{'bigop ($b-$a) times 1 (λ${ident j}.((λ${ident j}.true) (${ident j}+$a)))
434 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
436 notation "∏_{ ident j ∈ [a,b[ | p } f"
438 for @{'bigop ($b-$a) times 1 (λ${ident j}.((λ${ident j}.$p) (${ident j}+$a)))
439 (λ${ident j}.((λ${ident j}.$f)(${ident j}+$a)))}.
444 definition p_ord_times \def
447 [pair q r \Rightarrow r*m+q].
449 theorem eq_p_ord_times: \forall p,m,x.
450 p_ord_times p m x = (ord_rem x p)*m+(ord x p).
451 intros.unfold p_ord_times. unfold ord_rem.
457 theorem div_p_ord_times:
458 \forall p,m,x. ord x p < m \to p_ord_times p m x / m = ord_rem x p.
459 intros.rewrite > eq_p_ord_times.
460 apply div_plus_times.
464 theorem mod_p_ord_times:
465 \forall p,m,x. ord x p < m \to p_ord_times p m x \mod m = ord x p.
466 intros.rewrite > eq_p_ord_times.
467 apply mod_plus_times.
471 lemma lt_times_to_lt_O: \forall i,n,m:nat. i < n*m \to O < m.
473 elim (le_to_or_lt_eq O ? (le_O_n m))
477 rewrite < times_n_O in H.
478 apply (not_le_Sn_O ? H)
482 theorem iter_p_gen_knm:
485 \forall plusA: A \to A \to A.
486 (symmetric A plusA) \to
487 (associative A plusA) \to
488 (\forall a:A.(plusA a baseA) = a)\to
489 \forall g: nat \to A.
490 \forall h2:nat \to nat \to nat.
491 \forall h11,h12:nat \to nat.
493 \forall p1,p21:nat \to bool.
494 \forall p22:nat \to nat \to bool.
495 (\forall x. x < k \to p1 x = true \to
496 p21 (h11 x) = true \land p22 (h11 x) (h12 x) = true
497 \land h2 (h11 x) (h12 x) = x
498 \land (h11 x) < n \land (h12 x) < m) \to
499 (\forall i,j. i < n \to j < m \to p21 i = true \to p22 i j = true \to
500 p1 (h2 i j) = true \land
501 h11 (h2 i j) = i \land h12 (h2 i j) = j
502 \land h2 i j < k) \to
503 iter_p_gen k p1 A g baseA plusA =
504 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.
506 rewrite < (iter_p_gen2' n m p21 p22 ? ? ? ? H H1 H2).
508 apply (eq_iter_p_gen_gh A baseA plusA H H1 H2 g ? (\lambda x.(h11 x)*m+(h12 x)))
510 elim (H4 (i/m) (i \mod m));clear H4
514 |apply (lt_times_to_lt_div ? ? ? H5)
516 apply (lt_times_to_lt_O ? ? ? H5)
517 |apply (andb_true_true ? ? H6)
518 |apply (andb_true_true_r ? ? H6)
521 elim (H4 (i/m) (i \mod m));clear H4
528 apply (lt_times_to_lt_O ? ? ? H5)
529 |apply (lt_times_to_lt_div ? ? ? H5)
531 apply (lt_times_to_lt_O ? ? ? H5)
532 |apply (andb_true_true ? ? H6)
533 |apply (andb_true_true_r ? ? H6)
536 elim (H4 (i/m) (i \mod m));clear H4
540 |apply (lt_times_to_lt_div ? ? ? H5)
542 apply (lt_times_to_lt_O ? ? ? H5)
543 |apply (andb_true_true ? ? H6)
544 |apply (andb_true_true_r ? ? H6)
551 rewrite > div_plus_times
552 [rewrite > mod_plus_times
565 rewrite > div_plus_times
566 [rewrite > mod_plus_times
577 apply (lt_to_le_to_lt ? ((h11 j)*m+m))
578 [apply monotonic_lt_plus_r.
581 change with ((S (h11 j)*m) \le n*m).
582 apply monotonic_le_times_l.
588 theorem iter_p_gen_divides:
591 \forall plusA: A \to A \to A.
592 \forall n,m,p:nat.O < n \to prime p \to Not (divides p n) \to
593 \forall g: nat \to A.
594 (symmetric A plusA) \to (associative A plusA) \to (\forall a:A.(plusA a baseA) = a)
598 iter_p_gen (S (n*(exp p m))) (\lambda x.divides_b x (n*(exp p m))) A g baseA plusA =
599 iter_p_gen (S n) (\lambda x.divides_b x n) A
600 (\lambda x.iter_p_gen (S m) (\lambda y.true) A (\lambda y.g (x*(exp p y))) baseA plusA) baseA plusA.
603 [rewrite < (iter_p_gen2 ? ? ? ? ? ? ? ? H3 H4 H5).
605 (iter_p_gen (S n*S m) (\lambda x:nat.divides_b (x/S m) n) A
606 (\lambda x:nat.g (x/S m*(p)\sup(x\mod S m))) baseA plusA) )
608 apply (eq_iter_p_gen_gh ? ? ? ? ? ? g ? (p_ord_times p (S m)))
613 lapply (divides_b_true_to_lt_O ? ? H H7).
614 apply divides_to_divides_b_true
615 [rewrite > (times_n_O O).
618 |apply lt_O_exp.assumption
621 [apply divides_b_true_to_divides.assumption
622 |apply (witness ? ? (p \sup (m-i \mod (S m)))).
623 rewrite < exp_plus_times.
626 apply plus_minus_m_m.
627 autobatch by le_S_S_to_le, lt_mod_m_m, lt_O_S;
631 lapply (divides_b_true_to_lt_O ? ? H H7).
633 rewrite > (p_ord_exp1 p ? (i \mod (S m)) (i/S m))
634 [change with ((i/S m)*S m+i \mod S m=i).
641 apply (trans_divides ? (i/ S m))
643 apply divides_b_true_to_divides;assumption]
650 change with ((i/S m) < S n).
651 apply (lt_times_to_lt_l m).
652 apply (le_to_lt_to_lt ? i);[2:assumption]
653 autobatch by eq_plus_to_le, div_mod, lt_O_S.
663 [rewrite > div_p_ord_times
664 [apply divides_to_divides_b_true
667 |apply (divides_b_true_to_lt_O ? ? ? H7).
668 rewrite > (times_n_O O).
670 [assumption|apply lt_O_exp.assumption]
672 |cut (n = ord_rem (n*(exp p m)) p)
674 apply divides_to_divides_ord_rem
675 [apply (divides_b_true_to_lt_O ? ? ? H7).
676 rewrite > (times_n_O O).
678 [assumption|apply lt_O_exp.assumption]
679 |rewrite > (times_n_O O).
681 [assumption|apply lt_O_exp.assumption]
683 |apply divides_b_true_to_divides.
687 rewrite > (p_ord_exp1 p ? m n)
697 |cut (m = ord (n*(exp p m)) p)
700 apply divides_to_le_ord
701 [apply (divides_b_true_to_lt_O ? ? ? H7).
702 rewrite > (times_n_O O).
704 [assumption|apply lt_O_exp.assumption]
705 |rewrite > (times_n_O O).
707 [assumption|apply lt_O_exp.assumption]
709 |apply divides_b_true_to_divides.
713 rewrite > (p_ord_exp1 p ? m n)
723 [rewrite > div_p_ord_times
724 [rewrite > mod_p_ord_times
725 [rewrite > sym_times.
729 |apply (divides_b_true_to_lt_O ? ? ? H7).
730 rewrite > (times_n_O O).
732 [assumption|apply lt_O_exp.assumption]
734 |cut (m = ord (n*(exp p m)) p)
737 apply divides_to_le_ord
738 [apply (divides_b_true_to_lt_O ? ? ? H7).
739 rewrite > (times_n_O O).
741 [assumption|apply lt_O_exp.assumption]
742 |rewrite > (times_n_O O).
744 [assumption|apply lt_O_exp.assumption]
746 |apply divides_b_true_to_divides.
750 rewrite > (p_ord_exp1 p ? m n)
760 |cut (m = ord (n*(exp p m)) p)
763 apply divides_to_le_ord
764 [apply (divides_b_true_to_lt_O ? ? ? H7).
765 rewrite > (times_n_O O).
767 [assumption|apply lt_O_exp.assumption]
768 |rewrite > (times_n_O O).
770 [assumption|apply lt_O_exp.assumption]
772 |apply divides_b_true_to_divides.
776 rewrite > (p_ord_exp1 p ? m n)
785 rewrite > eq_p_ord_times.
787 apply (lt_to_le_to_lt ? (S m +ord_rem j p*S m))
790 cut (m = ord (n*(p \sup m)) p)
792 apply divides_to_le_ord
793 [apply (divides_b_true_to_lt_O ? ? ? H7).
794 rewrite > (times_n_O O).
796 [assumption|apply lt_O_exp.assumption]
797 |rewrite > (times_n_O O).
799 [assumption|apply lt_O_exp.assumption]
801 |apply divides_b_true_to_divides.
806 rewrite > (p_ord_exp1 p ? m n)
813 |change with (S (ord_rem j p)*S m \le S n*S m).
816 cut (n = ord_rem (n*(p \sup m)) p)
821 |rewrite > (times_n_O O).
823 [assumption|apply lt_O_exp.assumption]
825 |apply divides_to_divides_ord_rem
826 [apply (divides_b_true_to_lt_O ? ? ? H7).
827 rewrite > (times_n_O O).
829 [assumption|apply lt_O_exp.assumption]
830 |rewrite > (times_n_O O).
832 [assumption|apply lt_O_exp.assumption]
834 |apply divides_b_true_to_divides.
840 rewrite > (p_ord_exp1 p ? m n)
852 elim (divides_b (x/S m) n);reflexivity
856 |elim H1.apply lt_to_le.assumption
862 theorem iter_p_gen_2_eq:
865 \forall plusA: A \to A \to A.
866 (symmetric A plusA) \to
867 (associative A plusA) \to
868 (\forall a:A.(plusA a baseA) = a)\to
869 \forall g: nat \to nat \to A.
870 \forall h11,h12,h21,h22: nat \to nat \to nat.
872 \forall p11,p21:nat \to bool.
873 \forall p12,p22:nat \to nat \to bool.
874 (\forall i,j. i < n2 \to j < m2 \to p21 i = true \to p22 i j = true \to
875 p11 (h11 i j) = true \land p12 (h11 i j) (h12 i j) = true
876 \land h21 (h11 i j) (h12 i j) = i \land h22 (h11 i j) (h12 i j) = j
877 \land h11 i j < n1 \land h12 i j < m1) \to
878 (\forall i,j. i < n1 \to j < m1 \to p11 i = true \to p12 i j = true \to
879 p21 (h21 i j) = true \land p22 (h21 i j) (h22 i j) = true
880 \land h11 (h21 i j) (h22 i j) = i \land h12 (h21 i j) (h22 i j) = j
881 \land (h21 i j) < n2 \land (h22 i j) < m2) \to
883 (\lambda x:nat .iter_p_gen m1 (p12 x) A (\lambda y. g x y) baseA plusA)
886 (\lambda x:nat .iter_p_gen m2 (p22 x) A (\lambda y. g (h11 x y) (h12 x y)) baseA plusA )
890 rewrite < (iter_p_gen2' ? ? ? ? ? ? ? ? H H1 H2).
891 letin ha:= (\lambda x,y.(((h11 x y)*m1) + (h12 x y))).
892 letin ha12:= (\lambda x.(h21 (x/m1) (x \mod m1))).
893 letin ha22:= (\lambda x.(h22 (x/m1) (x \mod m1))).
896 (iter_p_gen n2 p21 A (\lambda x:nat. iter_p_gen m2 (p22 x) A
897 (\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))
899 apply (iter_p_gen_knm A baseA plusA H H1 H2 (\lambda e. (g (e/m1) (e \mod m1))) ha ha12 ha22);intros
900 [ elim (and_true ? ? H6).
903 [ cut((x \mod m1) < m1)
904 [ elim (H4 ? ? Hcut1 Hcut2 H7 H8).
932 | apply (lt_times_n_to_lt m1)
934 | apply (le_to_lt_to_lt ? x)
935 [ apply (eq_plus_to_le ? ? (x \mod m1)).
942 | apply not_le_to_lt.unfold.intro.
943 generalize in match H5.
944 apply (le_n_O_elim ? H9).
949 | elim (H3 ? ? H5 H6 H7 H8).
954 cut(((h11 i j)*m1 + (h12 i j))/m1 = (h11 i j))
955 [ cut(((h11 i j)*m1 + (h12 i j)) \mod m1 = (h12 i j))
959 [ apply true_to_true_to_andb_true
980 [ apply (lt_to_le_to_lt ? ((h11 i j)*m1 + m1) )
984 | rewrite > sym_plus.
985 rewrite > (sym_times (h11 i j) m1).
986 rewrite > times_n_Sm.
991 | apply not_le_to_lt.unfold.intro.
992 generalize in match H12.
993 apply (le_n_O_elim ? H11).
997 | apply not_le_to_lt.unfold.intro.
998 generalize in match H10.
999 apply (le_n_O_elim ? H11).
1004 | rewrite > (mod_plus_times m1 (h11 i j) (h12 i j)).
1008 | rewrite > (div_plus_times m1 (h11 i j) (h12 i j)).
1013 | apply (eq_iter_p_gen1)
1014 [ intros. reflexivity
1016 apply (eq_iter_p_gen1)
1017 [ intros. reflexivity
1019 rewrite > (div_plus_times)
1020 [ rewrite > (mod_plus_times)
1022 | elim (H3 x x1 H5 H7 H6 H8).
1025 | elim (H3 x x1 H5 H7 H6 H8).
1033 theorem iter_p_gen_iter_p_gen:
1036 \forall plusA: A \to A \to A.
1037 (symmetric A plusA) \to
1038 (associative A plusA) \to
1039 (\forall a:A.(plusA a baseA) = a)\to
1040 \forall g: nat \to nat \to A.
1042 \forall p11,p21:nat \to bool.
1043 \forall p12,p22:nat \to nat \to bool.
1044 (\forall x,y. x < n \to y < m \to
1045 (p11 x \land p12 x y) = (p21 y \land p22 y x)) \to
1047 (\lambda x:nat.iter_p_gen m (p12 x) A (\lambda y. g x y) baseA plusA)
1050 (\lambda y:nat.iter_p_gen n (p22 y) A (\lambda x. g x y) baseA plusA )
1053 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)
1054 n m m n p11 p21 p12 p22)
1060 [apply (andb_true_true ? (p12 j i)).
1062 [rewrite > H6.rewrite > H7.reflexivity
1066 |apply (andb_true_true_r (p11 j)).
1068 [rewrite > H6.rewrite > H7.reflexivity
1086 [apply (andb_true_true ? (p22 j i)).
1088 [rewrite > H6.rewrite > H7.reflexivity
1092 |apply (andb_true_true_r (p21 j)).
1094 [rewrite > H6.rewrite > H7.reflexivity