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 (**************************************************************************)
17 (* this file contains some important properites of gcd in N *)
19 (* an alternative characterization for gcd *)
20 theorem gcd1: \forall a,b,c:nat.
21 c \divides a \to c \divides b \to
22 (\forall d:nat. d \divides a \to d \divides b \to d \divides c) \to (gcd a b) = c.
25 [ apply (antisymmetric_divides (gcd a b) c)
26 [ apply (witness (gcd a b) c n1).
28 | apply divides_d_gcd;
38 theorem eq_gcd_times_times_times_gcd: \forall a,b,c:nat.
39 (gcd (c*a) (c*b)) = c*(gcd a b).
50 | apply divides_gcd_n.
58 apply (divides_d_times_gcd)
68 theorem associative_nat_gcd: associative nat gcd.
69 change with (\forall a,b,c:nat. (gcd (gcd a b) c) = (gcd a (gcd b c))).
73 [ apply (trans_divides ? (gcd b c) ?)
79 | apply (trans_divides ? (gcd b c) ?)
84 cut (d \divides a \land d \divides b)
86 cut (d \divides (gcd b c))
87 [ apply (divides_d_gcd (gcd b c) a d Hcut1 H2)
88 | apply (divides_d_gcd c b d H1 H3)
91 [ apply (trans_divides d (gcd a b) a H).
93 | apply (trans_divides d (gcd a b) b H).
101 theorem eq_gcd_div_div_div_gcd: \forall a,b,m:nat.
102 O \lt m \to m \divides a \to m \divides b \to
103 (gcd (a/m) (b/m)) = (gcd a b) / m.
105 apply (inj_times_r1 m H).
106 rewrite > (sym_times m ((gcd a b)/m)).
107 rewrite > (divides_to_div m (gcd a b))
108 [ rewrite < eq_gcd_times_times_times_gcd.
109 rewrite > (sym_times m (a/m)).
110 rewrite > (sym_times m (b/m)).
111 rewrite > (divides_to_div m a H1).
112 rewrite > (divides_to_div m b H2).
114 | apply divides_d_gcd;
121 theorem divides_times_to_divides_div_gcd: \forall a,b,c:nat.
122 a \divides (b*c) \to (a/(gcd a b)) \divides c.
127 [ (*It's an impossible situation*)
134 apply (divides_n_n O)
135 | apply (lt_times_eq_O b c)
138 | apply antisymmetric_divides
150 [ cut (O \lt (gcd a b))
151 [ apply (gcd_SO_to_divides_times_to_divides (b/(gcd a b)) (a/(gcd a b)) c)
152 [ apply (O_lt_times_to_O_lt (a/(gcd a b)) (gcd a b)).
153 rewrite > (divides_to_div (gcd a b) a)
155 | apply divides_gcd_n
157 | rewrite < (div_n_n (gcd a b)) in \vdash (? ? ? %)
158 [ apply eq_gcd_div_div_div_gcd
160 | apply divides_gcd_n
161 | apply divides_gcd_m
165 | apply (witness ? ? n1).
166 apply (inj_times_r1 (gcd a b) Hcut1).
167 rewrite < assoc_times.
168 rewrite < sym_times in \vdash (? ? (? % ?) ?).
169 rewrite > (divides_to_div (gcd a b) b)
170 [ rewrite < assoc_times in \vdash (? ? ? %).
171 rewrite < sym_times in \vdash (? ? ? (? % ?)).
172 rewrite > (divides_to_div (gcd a b) a)
174 | apply divides_gcd_n
176 | apply divides_gcd_m
189 theorem gcd_plus_times_gcd: \forall a,b,d,m:nat.
190 (gcd (a+m*b) b) = (gcd a b).
194 [ apply divides_gcd_n
195 | apply (trans_divides ? b ?)
196 [ apply divides_gcd_m
197 | rewrite > sym_times.
198 apply (witness b (b*m) m).
202 | apply divides_gcd_m
206 | rewrite > (minus_plus_m_m a (m*b)).
209 | apply (trans_divides ? b ?)
211 | rewrite > sym_times.
212 apply (witness b (b*m) m).
222 theorem gcd_SO_to_divides_to_divides_to_divides_times: \forall c,e,f:nat.
223 (gcd e f) = (S O) \to e \divides c \to f \divides c \to
226 apply (nat_case1 c); intros
232 rewrite > (sym_times e f).
233 apply (divides_times)
234 [ apply (divides_n_n)
235 | rewrite > H5 in H1.
236 apply (gcd_SO_to_divides_times_to_divides f e n)
237 [ rewrite < H5 in H1.
239 apply (divides_to_lt_O e (S m))
249 (* the following theorem shows that gcd is a multiplicative function in
250 the following sense: if a1 and a2 are relatively prime, then
251 gcd(a1·a2, b) = gcd(a1, b)·gcd(a2, b).
253 theorem gcd_SO_to_eq_gcd_times_times_gcd_gcd: \forall a,b,c:nat.
254 (gcd a b) = (S O) \to (gcd (a*b) c) = (gcd a c) * (gcd b c).
257 [ apply divides_times;
259 | apply (gcd_SO_to_divides_to_divides_to_divides_times c (gcd a c) (gcd b c))
267 apply (divides_d_gcd b a d Hcut1 Hcut)
268 | apply (trans_divides d (gcd b c) b)
270 | apply (divides_gcd_n)
273 | apply (trans_divides d (gcd a c) a)
275 | apply (divides_gcd_n)
279 | apply (divides_gcd_m)
280 | apply (divides_gcd_m)
283 rewrite < (eq_gcd_times_times_times_gcd b c (gcd a c)).
284 rewrite > (sym_times (gcd a c) b).
285 rewrite > (sym_times (gcd a c) c).
286 rewrite < (eq_gcd_times_times_times_gcd a c b).
287 rewrite < (eq_gcd_times_times_times_gcd a c c).
288 apply (divides_d_gcd)
289 [ apply (divides_d_gcd)
290 [ rewrite > (times_n_SO d).
291 apply (divides_times)
295 | rewrite > (times_n_SO d).
296 apply (divides_times)
301 | apply (divides_d_gcd)
302 [ rewrite > (times_n_SO d).
303 rewrite > (sym_times d (S O)).
304 apply (divides_times)
305 [ apply (divides_SO_n)
308 | rewrite < (sym_times a b).
316 theorem eq_gcd_gcd_minus: \forall a,b:nat.
317 a \lt b \to (gcd a b) = (gcd (b - a) b).
321 [ apply (divides_minus (gcd a b) b a)
322 [ apply divides_gcd_m
323 | apply divides_gcd_n
325 | apply divides_gcd_m
330 [ cut (b - (d*n1) = a)
331 [ rewrite > H4 in Hcut1.
332 rewrite < (distr_times_minus d n n1) in Hcut1.
335 | apply (witness d a (n - n1)).
339 | apply (plus_to_minus ? ? ? Hcut)
341 | rewrite > sym_plus.
342 apply (minus_to_plus)