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/primes.ma".
13 include "arithmetics/bigops.ma".
15 theorem sigma_const: ∀n:nat. ∑_{i<n} 1 = n.
16 #n elim n // #n1 >bigop_Strue //
19 (* monotonicity; these roperty should be expressed at a more
23 ∀n.∀p:nat → bool.∀g1,g2:nat → nat.
24 (∀i.i<n → p i = true → g1 i ≤ g2 i ) →
25 ∏_{i < n | p i} (g1 i) ≤ ∏_{i < n | p i} (g2 i).
28 |#n1 #Hind #Hle cases (true_or_false (p n1)) #Hcase
29 [ >bigop_Strue // >bigop_Strue // @le_times
30 [@Hle // |@Hind #i #lti #Hpi @Hle [@lt_to_le @le_S_S @lti|@Hpi]]
31 |>bigop_Sfalse // >bigop_Sfalse // @Hind
32 #i #lti #Hpi @Hle [@lt_to_le @le_S_S @lti|@Hpi]
37 theorem exp_sigma: ∀n,a,p.
38 ∏_{i < n | p i} a = exp a (∑_{i < n | p i} 1).
39 #n #a #p elim n // #n1 cases (true_or_false (p n1)) #Hcase
40 [>bigop_Strue // >bigop_Strue // |>bigop_Sfalse // >bigop_Sfalse //]
43 theorem times_pi: ∀n,p,f,g.
44 ∏_{i<n|p i}(f i*g i) = ∏_{i<n|p i}(f i) * ∏_{i<n|p i}(g i).
45 #n #p #f #g elim n // #n1 cases (true_or_false (p n1)) #Hcase #Hind
46 [>bigop_Strue // >bigop_Strue // >bigop_Strue //
47 |>bigop_Sfalse // >bigop_Sfalse // >bigop_Sfalse //
52 theorem true_to_pi_p_Sn: ∀n,p,g.
53 p n = true \to pi_p (S n) p g = (g n)*(pi_p n p g).
56 apply true_to_iter_p_gen_Sn.
60 theorem false_to_pi_p_Sn:
61 \forall n:nat. \forall p:nat \to bool. \forall g:nat \to nat.
62 p n = false \to pi_p (S n) p g = pi_p n p g.
65 apply false_to_iter_p_gen_Sn.
69 theorem eq_pi_p: \forall p1,p2:nat \to bool.
70 \forall g1,g2: nat \to nat.\forall n.
71 (\forall x. x < n \to p1 x = p2 x) \to
72 (\forall x. x < n \to g1 x = g2 x) \to
73 pi_p n p1 g1 = pi_p n p2 g2.
80 theorem eq_pi_p1: \forall p1,p2:nat \to bool.
81 \forall g1,g2: nat \to nat.\forall n.
82 (\forall x. x < n \to p1 x = p2 x) \to
83 (\forall x. x < n \to p1 x = true \to g1 x = g2 x) \to
84 pi_p n p1 g1 = pi_p n p2 g2.
92 \forall g: nat \to nat.\forall n.pi_p n (\lambda x.false) g = S O.
95 apply iter_p_gen_false.
98 theorem pi_p_times: \forall n,k:nat.\forall p:nat \to bool.
99 \forall g: nat \to nat.
101 = pi_p k (\lambda x.p (x+n)) (\lambda x.g (x+n)) * pi_p n p g.
104 apply (iter_p_gen_plusA nat n k p g (S O) times)
109 | apply associative_times
113 theorem false_to_eq_pi_p: \forall n,m:nat.n \le m \to
114 \forall p:nat \to bool.
115 \forall g: nat \to nat. (\forall i:nat. n \le i \to i < m \to
116 p i = false) \to pi_p m p g = pi_p n p g.
119 apply (false_to_eq_iter_p_gen);
123 theorem or_false_eq_SO_to_eq_pi_p:
124 \forall n,m:nat.\forall p:nat \to bool.
125 \forall g: nat \to nat.
126 n \le m \to (\forall i:nat. n \le i \to i < m \to p i = false \lor g i = S O)
127 \to pi_p m p g = pi_p n p g.
130 apply or_false_eq_baseA_to_eq_iter_p_gen
131 [intros.simplify.rewrite < plus_n_O.reflexivity
139 \forall p1,p2:nat \to bool.
140 \forall g: nat \to nat \to nat.
142 (\lambda x.andb (p1 (div x m)) (p2 (mod x m)))
143 (\lambda x.g (div x m) (mod x m)) =
145 (\lambda x.pi_p m p2 (g x)).
148 apply (iter_p_gen2 n m p1 p2 nat g (S O) times)
150 | apply associative_times
159 \forall p1:nat \to bool.
160 \forall p2:nat \to nat \to bool.
161 \forall g: nat \to nat \to nat.
163 (\lambda x.andb (p1 (div x m)) (p2 (div x m) (mod x m)))
164 (\lambda x.g (div x m) (mod x m)) =
166 (\lambda x.pi_p m (p2 x) (g x)).
169 apply (iter_p_gen2' n m p1 p2 nat g (S O) times)
171 | apply associative_times
178 lemma pi_p_gi: \forall g: nat \to nat.
179 \forall n,i.\forall p:nat \to bool.i < n \to p i = true \to
180 pi_p n p g = g i * pi_p n (\lambda x. andb (p x) (notb (eqb x i))) g.
183 apply (iter_p_gen_gi)
185 | apply associative_times
195 \forall g,h,h1: nat \to nat.\forall n,n1.
196 \forall p1,p2:nat \to bool.
197 (\forall i. i < n \to p1 i = true \to p2 (h i) = true) \to
198 (\forall i. i < n \to p1 i = true \to h1 (h i) = i) \to
199 (\forall i. i < n \to p1 i = true \to h i < n1) \to
200 (\forall j. j < n1 \to p2 j = true \to p1 (h1 j) = true) \to
201 (\forall j. j < n1 \to p2 j = true \to h (h1 j) = j) \to
202 (\forall j. j < n1 \to p2 j = true \to h1 j < n) \to
203 pi_p n p1 (\lambda x.g(h x)) = pi_p n1 p2 g.
206 apply (eq_iter_p_gen_gh nat (S O) times ? ? ? g h h1 n n1 p1 p2)
208 | apply associative_times
221 theorem exp_sigma_p: \forall n,a,p.
222 pi_p n p (\lambda x.a) = (exp a (sigma_p n p (\lambda x.S O))).
226 |apply (bool_elim ? (p n1))
228 rewrite > true_to_pi_p_Sn
229 [rewrite > true_to_sigma_p_Sn
238 rewrite > false_to_pi_p_Sn
239 [rewrite > false_to_sigma_p_Sn
249 theorem exp_sigma_p1: \forall n,a,p,f.
250 pi_p n p (\lambda x.(exp a (f x))) = (exp a (sigma_p n p f)).
254 |apply (bool_elim ? (p n1))
256 rewrite > true_to_pi_p_Sn
257 [rewrite > true_to_sigma_p_Sn
260 rewrite > exp_plus_times.
267 rewrite > false_to_pi_p_Sn
268 [rewrite > false_to_sigma_p_Sn
278 theorem times_pi_p: \forall n,p,f,g.
279 pi_p n p (\lambda x.f x*g x) = pi_p n p f * pi_p n p g.
282 [simplify.reflexivity
283 |apply (bool_elim ? (p n1))
285 rewrite > true_to_pi_p_Sn
286 [rewrite > true_to_pi_p_Sn
287 [rewrite > true_to_pi_p_Sn
288 [rewrite > H.autobatch
296 rewrite > false_to_pi_p_Sn
297 [rewrite > false_to_pi_p_Sn
298 [rewrite > false_to_pi_p_Sn;assumption
307 theorem pi_p_SO: \forall n,p.
308 pi_p n p (\lambda i.S O) = S O.
311 |simplify.elim (p n1)
312 [simplify.rewrite < plus_n_O.assumption
318 theorem exp_pi_p: \forall n,m,p,f.
319 pi_p n p (\lambda x.exp (f x) m) = exp (pi_p n p f) m.
322 [simplify.apply pi_p_SO
324 rewrite > times_pi_p.
330 theorem exp_times_pi_p: \forall n,m,k,p,f.
331 pi_p n p (\lambda x.exp k (m*(f x))) =
332 exp (pi_p n p (\lambda x.exp k (f x))) m.
334 apply (trans_eq ? ? (pi_p n p (\lambda x.(exp (exp k (f x)) m))))
335 [apply eq_pi_p;intros
337 |apply sym_eq.rewrite > sym_times.
346 \forall g: nat \to nat.
347 \forall h2:nat \to nat \to nat.
348 \forall h11,h12:nat \to nat.
350 \forall p1,p21:nat \to bool.
351 \forall p22:nat \to nat \to bool.
352 (\forall x. x < k \to p1 x = true \to
353 p21 (h11 x) = true ∧ p22 (h11 x) (h12 x) = true
354 \land h2 (h11 x) (h12 x) = x
355 \land (h11 x) < n \land (h12 x) < m) \to
356 (\forall i,j. i < n \to j < m \to p21 i = true \to p22 i j = true \to
357 p1 (h2 i j) = true \land
358 h11 (h2 i j) = i \land h12 (h2 i j) = j
361 Pi z < k | p1 z. g z =
362 Pi x < n | p21 x. Pi y < m | p22 x y.g (h2 x y).
365 pi_p n p21 (\lambda x:nat.pi_p m (p22 x) (\lambda y. g (h2 x y))).
367 unfold pi_p.unfold pi_p.
368 apply (iter_p_gen_knm nat (S O) times sym_times assoc_times ? ? ? h11 h12)
369 [intros.apply sym_eq.apply times_n_SO.
376 \forall g: nat \to nat \to nat.
377 \forall h11,h12,h21,h22: nat \to nat \to nat.
379 \forall p11,p21:nat \to bool.
380 \forall p12,p22:nat \to nat \to bool.
381 (\forall i,j. i < n2 \to j < m2 \to p21 i = true \to p22 i j = true \to
382 p11 (h11 i j) = true \land p12 (h11 i j) (h12 i j) = true
383 \land h21 (h11 i j) (h12 i j) = i \land h22 (h11 i j) (h12 i j) = j
384 \land h11 i j < n1 \land h12 i j < m1) \to
385 (\forall i,j. i < n1 \to j < m1 \to p11 i = true \to p12 i j = true \to
386 p21 (h21 i j) = true \land p22 (h21 i j) (h22 i j) = true
387 \land h11 (h21 i j) (h22 i j) = i \land h12 (h21 i j) (h22 i j) = j
388 \land (h21 i j) < n2 \land (h22 i j) < m2) \to
390 (\lambda x:nat .pi_p m1 (p12 x) (\lambda y. g x y)) =
392 (\lambda x:nat .pi_p m2 (p22 x) (\lambda y. g (h11 x y) (h12 x y))).
394 unfold pi_p.unfold pi_p.
395 apply (iter_p_gen_2_eq ? ? ? sym_times assoc_times ? ? ? ? h21 h22)
396 [intros.apply sym_eq.apply times_n_SO.
403 \forall g: nat \to nat \to nat.
405 \forall p11,p21:nat \to bool.
406 \forall p12,p22:nat \to nat \to bool.
407 (\forall x,y. x < n \to y < m \to
408 (p11 x \land p12 x y) = (p21 y \land p22 y x)) \to
409 pi_p n p11 (\lambda x:nat.pi_p m (p12 x) (\lambda y. g x y)) =
410 pi_p m p21 (\lambda y:nat.pi_p n (p22 y) (\lambda x. g x y)).
412 unfold pi_p.unfold pi_p.
413 apply (iter_p_gen_iter_p_gen ? ? ? sym_times assoc_times)
414 [intros.apply sym_eq.apply times_n_SO.