1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 include "Q/ratio/rinv.ma".
16 include "Q/fraction/ftimes.ma".
18 definition rtimes : ratio → ratio → ratio ≝
25 | (frac g) ⇒ ftimes f g]].
27 theorem symmetric_rtimes : symmetric ratio rtimes.
28 change with (∀r,s:ratio. rtimes r s = rtimes s r).
35 simplify.apply symmetric2_ftimes.
38 variant sym_rtimes : ∀x,y:ratio. rtimes x y = rtimes y x ≝ symmetric_rtimes.
40 theorem rtimes_r_one: ∀r.rtimes r one = r.
41 intro; cases r;reflexivity.
44 theorem rtimes_one_r: ∀r.rtimes one r = r.
45 intro; cases r;reflexivity.
48 theorem rtimes_Zplus: \forall x,y.
49 rtimes (nat_frac_item_to_ratio x) (nat_frac_item_to_ratio y) =
50 nat_frac_item_to_ratio (x + y).
58 theorem rtimes_Zplus1: \forall x,y,f.
59 rtimes (nat_frac_item_to_ratio x) (frac (cons y f)) =
60 frac (cons ((x + y)) f).
68 theorem rtimes_Zplus2: \forall x,y,f.
69 rtimes (frac (cons y f)) (nat_frac_item_to_ratio x) =
70 frac (cons ((y + x)) f).
78 theorem or_one_frac: \forall f,g.
79 rtimes (frac f) (frac g) = one \lor
80 \exists h.rtimes (frac f) (frac g) = frac h.
82 elim (rtimes (frac f) (frac g))
84 |right.apply (ex_intro ? ? f1).reflexivity
88 theorem one_to_rtimes_Zplus3: \forall x,y:Z.\forall f,g:fraction.
89 rtimes (frac f) (frac g) = one \to
90 rtimes (frac (cons x f)) (frac (cons y g)) = nat_frac_item_to_ratio (x + y).
91 intros.simplify.simplify in H.rewrite > H.simplify.
95 theorem frac_to_rtimes_Zplus3: \forall x,y:Z.\forall f,g:fraction.
96 \forall h.rtimes (frac f) (frac g) = frac h \to
97 rtimes (frac (cons x f)) (frac (cons y g)) = frac (cons (x + y) h).
98 intros.simplify.simplify in H.rewrite > H.simplify.
103 theorem nat_frac_item_to_ratio_frac_frac: \forall z,f1,f2.
104 rtimes (rtimes (nat_frac_item_to_ratio z) (frac f1)) (frac f2)
105 =rtimes (nat_frac_item_to_ratio z) (rtimes (frac f1) (frac f2)).
109 (rtimes (rtimes (nat_frac_item_to_ratio z) (nat_frac_item_to_ratio (pos n))) (nat_frac_item_to_ratio (pos n1))
110 =rtimes (nat_frac_item_to_ratio z) (rtimes (nat_frac_item_to_ratio (pos n)) (nat_frac_item_to_ratio (pos n1)))).
111 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
112 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
113 rewrite > assoc_Zplus.reflexivity
115 (rtimes (rtimes (nat_frac_item_to_ratio z) (nat_frac_item_to_ratio (pos n))) (nat_frac_item_to_ratio (neg n1))
116 =rtimes (nat_frac_item_to_ratio z) (rtimes (nat_frac_item_to_ratio (pos n)) (nat_frac_item_to_ratio (neg n1)))).
117 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
118 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
119 rewrite > assoc_Zplus.reflexivity
121 (rtimes (rtimes (nat_frac_item_to_ratio z) (nat_frac_item_to_ratio (pos n))) (frac (cons z1 f))
122 = rtimes (nat_frac_item_to_ratio z) (rtimes (nat_frac_item_to_ratio (pos n)) (frac (cons z1 f)))).
123 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus1.
124 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus1.
125 rewrite > assoc_Zplus.reflexivity
129 (rtimes (rtimes (nat_frac_item_to_ratio z) (nat_frac_item_to_ratio (neg n))) (nat_frac_item_to_ratio (pos n1))
130 =rtimes (nat_frac_item_to_ratio z) (rtimes (nat_frac_item_to_ratio (neg n)) (nat_frac_item_to_ratio (pos n1)))).
131 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
132 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
133 rewrite > assoc_Zplus.reflexivity
135 (rtimes (rtimes (nat_frac_item_to_ratio z) (nat_frac_item_to_ratio (neg n))) (nat_frac_item_to_ratio (neg n1))
136 =rtimes (nat_frac_item_to_ratio z) (rtimes (nat_frac_item_to_ratio (neg n)) (nat_frac_item_to_ratio (neg n1)))).
137 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
138 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
139 rewrite > assoc_Zplus.reflexivity
141 (rtimes (rtimes (nat_frac_item_to_ratio z) (nat_frac_item_to_ratio (neg n))) (frac (cons z1 f))
142 = rtimes (nat_frac_item_to_ratio z) (rtimes (nat_frac_item_to_ratio (neg n)) (frac (cons z1 f)))).
143 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus1.
144 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus1.
145 rewrite > assoc_Zplus.reflexivity
149 (rtimes (rtimes (nat_frac_item_to_ratio z) (frac (cons z1 f))) (nat_frac_item_to_ratio (pos n))
150 =rtimes (nat_frac_item_to_ratio z) (rtimes (frac (cons z1 f)) (nat_frac_item_to_ratio (pos n)))).
151 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus2.
152 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
153 rewrite > assoc_Zplus.reflexivity
155 (rtimes (rtimes (nat_frac_item_to_ratio z) (frac (cons z1 f))) (nat_frac_item_to_ratio (neg n))
156 =rtimes (nat_frac_item_to_ratio z) (rtimes (frac (cons z1 f)) (nat_frac_item_to_ratio (neg n)))).
157 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus2.
158 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
159 rewrite > assoc_Zplus.reflexivity
160 |elim (or_one_frac f f3)
161 [rewrite > rtimes_Zplus1.
162 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
163 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
164 rewrite > rtimes_Zplus.
165 rewrite > assoc_Zplus.reflexivity
167 rewrite > rtimes_Zplus1.
168 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H3).
169 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H3).
170 rewrite > rtimes_Zplus1.
171 rewrite > assoc_Zplus.reflexivity
177 theorem cons_frac_frac: \forall f1,z,f,f2.
178 rtimes (rtimes (frac (cons z f)) (frac f1)) (frac f2)
179 =rtimes (frac (cons z f)) (rtimes (frac f1) (frac f2)).
183 (rtimes (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (pos n))) (nat_frac_item_to_ratio (pos n1))
184 =rtimes (frac (cons z f)) (rtimes (nat_frac_item_to_ratio (pos n)) (nat_frac_item_to_ratio (pos n1)))).
185 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
186 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
187 rewrite > assoc_Zplus.reflexivity
189 (rtimes (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (pos n))) (nat_frac_item_to_ratio (neg n1))
190 =rtimes (frac (cons z f)) (rtimes (nat_frac_item_to_ratio (pos n)) (nat_frac_item_to_ratio (neg n1)))).
191 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
192 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
193 rewrite > assoc_Zplus.reflexivity
195 (rtimes (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (pos n))) (frac (cons z1 f3))
196 = rtimes (frac (cons z f)) (rtimes (nat_frac_item_to_ratio (pos n)) (frac (cons z1 f3)))).
197 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
198 elim (or_one_frac f f3)
199 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
200 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
201 rewrite > assoc_Zplus.reflexivity
203 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
204 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
205 rewrite > assoc_Zplus.reflexivity
210 (rtimes (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (neg n))) (nat_frac_item_to_ratio (pos n1))
211 =rtimes (frac (cons z f)) (rtimes (nat_frac_item_to_ratio (neg n)) (nat_frac_item_to_ratio (pos n1)))).
212 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
213 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
214 rewrite > assoc_Zplus.reflexivity
216 (rtimes (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (neg n))) (nat_frac_item_to_ratio (neg n1))
217 =rtimes (frac (cons z f)) (rtimes (nat_frac_item_to_ratio (neg n)) (nat_frac_item_to_ratio (neg n1)))).
218 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
219 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
220 rewrite > assoc_Zplus.reflexivity
222 (rtimes (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (neg n))) (frac (cons z1 f3))
223 = rtimes (frac (cons z f)) (rtimes (nat_frac_item_to_ratio (neg n)) (frac (cons z1 f3)))).
224 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
225 elim (or_one_frac f f3)
226 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
227 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
228 rewrite > assoc_Zplus.reflexivity
230 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
231 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
232 rewrite > assoc_Zplus.reflexivity
237 (rtimes (rtimes (frac (cons z1 f2)) (frac (cons z f))) (nat_frac_item_to_ratio (pos n))
238 =rtimes (frac (cons z1 f2)) (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (pos n)))).
239 rewrite > rtimes_Zplus2.
240 elim (or_one_frac f2 f)
241 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
242 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
243 rewrite > rtimes_Zplus.
244 rewrite > assoc_Zplus.reflexivity
246 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
247 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
248 rewrite > rtimes_Zplus2.
249 rewrite > assoc_Zplus.reflexivity
252 (rtimes (rtimes (frac (cons z1 f2)) (frac (cons z f))) (nat_frac_item_to_ratio (neg n))
253 =rtimes (frac (cons z1 f2)) (rtimes (frac (cons z f)) (nat_frac_item_to_ratio (neg n)))).
254 rewrite > rtimes_Zplus2.
255 elim (or_one_frac f2 f)
256 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
257 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
258 rewrite > rtimes_Zplus.
259 rewrite > assoc_Zplus.reflexivity
261 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
262 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
263 rewrite > rtimes_Zplus2.
264 rewrite > assoc_Zplus.reflexivity
266 |elim (or_one_frac f2 f)
267 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
268 rewrite > rtimes_Zplus1.
269 elim (or_one_frac f f4)
270 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H3).
271 rewrite > rtimes_Zplus2.
274 rewrite > assoc_Zplus.reflexivity
275 |apply injective_frac.
276 rewrite < rtimes_one_r.
278 (* problema inaspettato: mi serve l'unicita' dell'inversa,
279 che richiede (?) l'associativita. Per fortuna basta
280 l'ipotesi induttiva. *)
283 (rtimes (rtimes (nat_frac_item_to_ratio (pos n)) (frac f)) (frac f4)=nat_frac_item_to_ratio (pos n)).
284 rewrite > nat_frac_item_to_ratio_frac_frac.
286 rewrite > rtimes_r_one.
289 (rtimes (rtimes (nat_frac_item_to_ratio (neg n)) (frac f)) (frac f4)=nat_frac_item_to_ratio (neg n)).
290 rewrite > nat_frac_item_to_ratio_frac_frac.
292 rewrite > rtimes_r_one.
296 rewrite > rtimes_r_one.
301 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H4).
302 cut (rtimes (frac f2) (frac a) = frac f4)
303 [rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? f4 Hcut).
304 rewrite > assoc_Zplus.reflexivity
306 generalize in match H2.
309 (rtimes (nat_frac_item_to_ratio (pos n)) (rtimes (frac f)(frac f4)) =frac f4).
310 rewrite < nat_frac_item_to_ratio_frac_frac.
312 rewrite > rtimes_one_r.
315 (rtimes (nat_frac_item_to_ratio (neg n)) (rtimes (frac f)(frac f4)) =frac f4).
316 rewrite < nat_frac_item_to_ratio_frac_frac.
318 rewrite > rtimes_one_r.
322 rewrite > rtimes_one_r.
328 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H3).
329 elim (or_one_frac f f4)
330 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
331 rewrite > rtimes_Zplus2.
332 cut (rtimes (frac a) (frac f4) = frac f2)
333 [rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? f2 Hcut).
334 rewrite > assoc_Zplus.reflexivity
336 generalize in match H2.
339 (rtimes (rtimes (nat_frac_item_to_ratio (pos n)) (frac f)) (frac f4)=nat_frac_item_to_ratio (pos n)).
340 rewrite > nat_frac_item_to_ratio_frac_frac.
342 rewrite > rtimes_r_one.
345 (rtimes (rtimes (nat_frac_item_to_ratio (neg n)) (frac f)) (frac f4)=nat_frac_item_to_ratio (neg n)).
346 rewrite > nat_frac_item_to_ratio_frac_frac.
348 rewrite > rtimes_r_one.
352 rewrite > rtimes_r_one.
357 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a1 H4).
358 elim (or_one_frac a f4)
359 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
360 cut (rtimes (frac f2) (frac a1) = one)
361 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? Hcut).
362 rewrite > assoc_Zplus.reflexivity
364 generalize in match H3.
367 (rtimes (nat_frac_item_to_ratio (pos n)) (rtimes (frac f)(frac f4)) = one).
368 rewrite < nat_frac_item_to_ratio_frac_frac.
372 (rtimes (nat_frac_item_to_ratio (neg n)) (rtimes (frac f)(frac f4)) = one).
373 rewrite < nat_frac_item_to_ratio_frac_frac.
382 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a2 H5).
383 cut (rtimes (frac f2) (frac a1) = frac a2)
384 [rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a2 Hcut).
385 rewrite > assoc_Zplus.reflexivity
387 generalize in match H3.
390 (rtimes (nat_frac_item_to_ratio (pos n)) (rtimes (frac f)(frac f4)) = frac a2).
391 rewrite < nat_frac_item_to_ratio_frac_frac.
395 (rtimes (nat_frac_item_to_ratio (neg n)) (rtimes (frac f)(frac f4)) = frac a2).
396 rewrite < nat_frac_item_to_ratio_frac_frac.
411 theorem frac_frac_fracaux: ∀f,f1,f2.
412 rtimes (rtimes (frac f) (frac f1)) (frac f2)
413 =rtimes (frac f) (rtimes (frac f1) (frac f2)).
417 (rtimes (rtimes (nat_frac_item_to_ratio (pos n)) (frac f1)) (frac f2)
418 =rtimes (nat_frac_item_to_ratio (pos n)) (rtimes (frac f1) (frac f2))).
419 apply nat_frac_item_to_ratio_frac_frac
421 (rtimes (rtimes (nat_frac_item_to_ratio (neg n)) (frac f1)) (frac f2)
422 =rtimes (nat_frac_item_to_ratio (neg n)) (rtimes (frac f1) (frac f2))).
423 apply nat_frac_item_to_ratio_frac_frac
424 |apply cons_frac_frac]
428 theorem associative_rtimes:associative ? rtimes.
435 [rewrite > rtimes_r_one.rewrite > rtimes_r_one.reflexivity
436 |apply frac_frac_fracaux
441 theorem rtimes_rinv: ∀r:ratio. rtimes r (rinv r) = one.
444 simplify.apply ftimes_finv.
447 theorem rtimes_Zplus3: \forall x,y:Z.\forall f,g:fraction.
448 (rtimes (frac f) (frac g) = one \land
449 rtimes (frac (cons x f)) (frac (cons y g)) = nat_frac_item_to_ratio (x + y))
450 \lor (\exists h.rtimes (frac f) (frac g) = frac h \land
451 rtimes (frac (cons x f)) (frac (cons y g)) =
452 frac (cons (x + y) h)).
455 elim (rtimes (frac f) (frac g));simplify
456 [left.split;reflexivity
458 apply (ex_intro ? ? f1).