1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/nat/propr_div_mod_lt_le_totient1_aux/".
17 include "nat/iteration2.ma".
19 (*this part of the library contains some properties useful to prove
20 the main theorem in totient1.ma, and some new properties about gcd
21 (see gcd_properties1.ma).
22 These theorems are saved separately from the other part of the library
23 in order to avoid to create circular dependences in it.
26 (* some basic properties of and - or*)
27 theorem andb_sym: \forall A,B:bool.
28 (A \land B) = (B \land A).
36 theorem andb_assoc: \forall A,B,C:bool.
37 (A \land (B \land C)) = ((A \land B) \land C).
46 theorem orb_sym: \forall A,B:bool.
47 (A \lor B) = (B \lor A).
55 theorem andb_t_t_t: \forall A,B,C:bool.
56 A = true \to B = true \to C = true \to (A \land (B \land C)) = true.
64 (*properties about relational operators*)
66 theorem Sa_le_b_to_O_lt_b: \forall a,b:nat.
67 (S a) \le b \to O \lt b.
73 theorem n_gt_Uno_to_O_lt_pred_n: \forall n:nat.
74 (S O) \lt n \to O \lt (pred n).
76 apply (Sa_le_b_to_O_lt_b (pred (S O)) (pred n) ?).
77 apply (lt_pred (S O) n ? ?);
84 theorem NdivM_times_M_to_N: \forall n,m:nat.
85 O \lt m \to m \divides n \to (n / m) * m = n.
93 | apply divides_to_mod_O;
98 theorem lt_to_divides_to_div_le: \forall a,c:nat.
99 O \lt c \to c \divides a \to a/c \le a.
101 apply (le_times_to_le c (a/c) a)
103 | rewrite > (sym_times c (a/c)).
104 rewrite > (NdivM_times_M_to_N a c) in \vdash (? % ?)
105 [ rewrite < (sym_times a c).
106 apply (O_lt_const_to_le_times_const).
115 theorem bTIMESc_le_a_to_c_le_aDIVb: \forall a,b,c:nat.
116 O \lt b \to (b*c) \le a \to c \le (a /b).
118 rewrite > (div_mod a b) in H1
119 [ apply (le_times_to_le b ? ?)
121 | cut ( (c*b) \le ((a/b)*b) \lor ((a/b)*b) \lt (c*b))
123 [ rewrite < (sym_times c b).
124 rewrite < (sym_times (a/b) b).
127 [ change in Hcut1 with ((S (a/b)) \le c).
128 cut( b*(S (a/b)) \le b*c)
129 [ rewrite > (sym_times b (S (a/b))) in Hcut2.
131 cut ((b + (a/b)*b) \le ((a/b)*b + (a \mod b)))
132 [ cut (b \le (a \mod b))
134 apply (lt_to_not_le (a \mod b) b)
135 [ apply (lt_mod_m_m).
139 | apply (le_plus_to_le ((a/b)*b)).
143 | apply (trans_le ? (b*c) ?);
146 | apply (le_times_r b ? ?).
149 | apply (lt_times_n_to_lt b (a/b) c)
155 | apply (leb_elim (c*b) ((a/b)*b))
161 apply cic:/matita/nat/orders/not_le_to_lt.con.
170 theorem lt_O_a_lt_O_b_a_divides_b_to_lt_O_aDIVb:
172 O \lt a \to O \lt b \to a \divides b \to O \lt (b/a).
177 rewrite > (sym_times a n2).
178 rewrite > (div_times_ltO n2 a);
180 | apply (divides_to_lt_O n2 b)
182 | apply (witness n2 b a).
189 (* some properties of div operator between natural numbers *)
191 theorem separazioneFattoriSuDivisione: \forall a,b,c:nat.
192 O \lt b \to c \divides b \to a * (b /c) = (a*b)/c.
196 rewrite > (sym_times c n2).
198 [ rewrite > (div_times_ltO n2 c)
199 [ rewrite < assoc_times.
200 rewrite > (div_times_ltO (a *n2) c)
206 | apply (divides_to_lt_O c b);
212 theorem div_times_to_eqSO: \forall a,d:nat.
213 O \lt d \to a*d = d \to a = (S O).
215 apply (cic:/matita/nat/div_and_mod/inj_times_r1.con d)
217 | rewrite > sym_times.
218 rewrite < (times_n_SO d).
224 theorem div_mod_minus:
225 \forall a,b:nat. O \lt b \to
226 (a /b)*b = a - (a \mod b).
228 rewrite > (div_mod a b) in \vdash (? ? ? (? % ?))
229 [ apply (minus_plus_m_m (times (div a b) b) (mod a b))
234 theorem sum_div_eq_div: \forall a,b,c:nat.
235 O \lt c \to b \lt c \to c \divides a \to (a+b) /c = a/c.
239 rewrite > (sym_times c n2).
240 rewrite > (div_plus_times c n2 b)
241 [ rewrite > (div_times_ltO n2 c)
250 (* A corollary to the division theorem (between natural numbers).
252 * Forall a,b,c: Nat, b > O,
253 * a/b = c iff (b*c <= a && a < b*(c+1)
255 * two parts of the theorem are proved separately
256 * - (=>) th_div_interi_2
257 * - (<=) th_div_interi_1
260 theorem th_div_interi_2: \forall a,b,c:nat.
261 O \lt b \to a/b = c \to (b*c \le a \land a \lt b*(S c)).
266 rewrite > div_mod_minus
267 [ apply (le_minus_m a (a \mod b))
270 | rewrite < (times_n_Sm b c).
273 rewrite > div_mod_minus
274 [ rewrite < (eq_minus_plus_plus_minus b a (a \mod b))
275 [ rewrite < (sym_plus a b).
276 rewrite > (eq_minus_plus_plus_minus a b (a \mod b))
277 [ rewrite > (plus_n_O a) in \vdash (? % ?).
278 apply (le_to_lt_to_plus_lt)
280 | apply cic:/matita/nat/minus/lt_to_lt_O_minus.con.
281 apply cic:/matita/nat/div_and_mod/lt_mod_m_m.con.
288 | rewrite > (div_mod a b) in \vdash (? ? %)
289 [ rewrite > plus_n_O in \vdash (? % ?).
291 apply cic:/matita/nat/le_arith/le_plus_n.con
300 theorem th_div_interi_1: \forall a,c,b:nat.
301 O \lt b \to (b*c) \le a \to a \lt (b*(S c)) \to a/b = c.
303 apply (le_to_le_to_eq)
304 [ cut (a/b \le c \lor c \lt a/b)
307 | change in H3 with ((S c) \le (a/b)).
308 cut (b*(S c) \le (b*(a/b)))
309 [ rewrite > (sym_times b (S c)) in Hcut1.
310 cut (a \lt (b * (a/b)))
311 [ rewrite > (div_mod a b) in Hcut2:(? % ?)
312 [ rewrite > (plus_n_O (b*(a/b))) in Hcut2:(? ? %).
313 cut ((a \mod b) \lt O)
315 apply (lt_to_not_le (a \mod b) O)
319 | apply (lt_plus_to_lt_r ((a/b)*b)).
320 rewrite > (sym_times b (a/b)) in Hcut2:(? ? (? % ?)).
325 | apply (lt_to_le_to_lt ? (b*(S c)) ?)
327 | rewrite > (sym_times b (S c)).
335 | apply (leb_elim (a/b) c)
341 apply cic:/matita/nat/orders/not_le_to_lt.con.
345 | apply (bTIMESc_le_a_to_c_le_aDIVb);
350 theorem times_numerator_denominator_aux: \forall a,b,c,d:nat.
351 O \lt c \to O \lt b \to d = (a/b) \to d= (a*c)/(b*c).
354 cut (b*d \le a \land a \lt b*(S d))
356 apply th_div_interi_1
357 [ rewrite > (S_pred b)
358 [ rewrite > (S_pred c)
359 [ apply (lt_O_times_S_S)
364 | rewrite > assoc_times.
365 rewrite > (sym_times c d).
366 rewrite < assoc_times.
367 rewrite > (sym_times (b*d) c).
368 rewrite > (sym_times a c).
369 apply (le_times_r c (b*d) a).
371 | rewrite > (sym_times a c).
372 rewrite > (assoc_times ).
373 rewrite > (sym_times c (S d)).
374 rewrite < (assoc_times).
375 rewrite > (sym_times (b*(S d)) c).
376 apply (lt_times_r1 c a (b*(S d)));
379 | apply (th_div_interi_2)
387 theorem times_numerator_denominator: \forall a,b,c:nat.
388 O \lt c \to O \lt b \to (a/b) = (a*c)/(b*c).
390 apply (times_numerator_denominator_aux a b c (a/b))
397 theorem times_mod: \forall a,b,c:nat.
398 O \lt c \to O \lt b \to ((a*c) \mod (b*c)) = c*(a\mod b).
400 apply (div_mod_spec_to_eq2 (a*c) (b*c) (a/b) ((a*c) \mod (b*c)) (a/b) (c*(a \mod b)))
401 [ apply div_mod_spec_intro
402 [ apply (lt_mod_m_m (a*c) (b*c)).
404 [ rewrite > (S_pred c)
405 [ apply lt_O_times_S_S
410 | rewrite > (times_numerator_denominator a b c)
411 [ apply (div_mod (a*c) (b*c)).
413 [ rewrite > (S_pred c)
414 [ apply (lt_O_times_S_S)
424 [ rewrite > (sym_times b c).
425 apply (lt_times_r1 c)
427 | apply (lt_mod_m_m).
430 | rewrite < (assoc_times (a/b) b c).
431 rewrite > (sym_times a c).
432 rewrite > (sym_times ((a/b)*b) c).
433 rewrite < (distr_times_plus c ? ?).