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 set "baseuri" "cic:/matita/Q/frac".
17 include "nat/factorization.ma".
20 (* transformation from nat_fact to fracion *)
21 let rec nat_fact_to_fraction l \def
23 [nf_last a \Rightarrow pp a
24 |nf_cons a p \Rightarrow
25 cons (Z_of_nat a) (nat_fact_to_fraction p)
29 (* returns the numerator of a fraction in the form of a nat_fact_all *)
30 let rec numerator f \def
32 [pp a \Rightarrow nfa_proper (nf_last a)
33 |nn a \Rightarrow nfa_one
35 let n \def numerator l in
37 [nfa_zero \Rightarrow (* this case is vacuous *) nfa_zero
40 [OZ \Rightarrow nfa_one
41 |pos x \Rightarrow nfa_proper (nf_last x)
42 |neg x \Rightarrow nfa_one
44 |nfa_proper g \Rightarrow
46 [OZ \Rightarrow nfa_proper (nf_cons O g)
47 |pos x \Rightarrow nfa_proper (nf_cons (S x) g)
48 |neg x \Rightarrow nfa_proper (nf_cons O g)
54 theorem not_eq_numerator_nfa_zero:
55 \forall f.numerator f \neq nfa_zero.
57 [simplify.intro.destruct H
58 |simplify.intro.destruct H
59 |simplify.generalize in match H.
61 [intro.elim H1.reflexivity
63 cases z;simplify;intro;destruct H2
65 cases z;simplify;intro;destruct H2
70 theorem or_numerator_nfa_one_nfa_proper:
71 \forall f.(numerator f = nfa_one \land \exists g.numerator (finv f) =
72 nfa_proper g) \lor \exists g.numerator f = nfa_proper g.
75 apply (ex_intro ? ? (nf_last n)).reflexivity
78 |apply (ex_intro ? ? (nf_last n)).reflexivity
85 rewrite > H.rewrite > H1.simplify.
88 |apply (ex_intro ? ? (nf_cons O a)).reflexivity
91 rewrite > H.rewrite > H1.simplify.
92 right.apply (ex_intro ? ? (nf_last n)).reflexivity
94 rewrite > H.rewrite > H1.simplify.
97 |apply (ex_intro ? ? (nf_cons (S n) a)).reflexivity
103 rewrite > H.simplify.
105 apply (ex_intro ? ? (nf_cons O a)).reflexivity
107 rewrite > H.simplify.
108 right.apply (ex_intro ? ? (nf_cons (S n) a)).reflexivity
110 rewrite > H.simplify.
112 apply (ex_intro ? ? (nf_cons O a)).reflexivity
118 theorem eq_nfa_one_to_eq_finv_nfa_proper:
119 \forall f.numerator f = nfa_one \to
120 \exist h.numerator (finv f) = nfa_proper h.
122 [simplify in H.destruct H
123 |simplify.apply (ex_intro ? ? (nf_last n)).reflexivity
124 |generalize in match H1.clear H1.
125 generalize in match H.clear H.
127 cases (numerator f1);simplify
129 |intros;elim (H (refl_eq ? ?)).
130 rewrite > H2.simplify.
132 [apply (ex_intro ? ? (nf_cons O a)).reflexivity
133 |apply (ex_intro ? ? (nf_cons O a)).reflexivity
134 |apply (ex_intro ? ? (nf_cons (S n) a)).reflexivity
141 theorem numerator_nat_fact_to_fraction: \forall g:nat_fact.
142 numerator (nat_fact_to_fraction g) = nfa_proper g.
145 [simplify.reflexivity.
146 |simplify.rewrite > H.simplify.
151 definition numeratorQ \def
152 \lambda q.match q with
153 [OQ \Rightarrow nfa_zero
156 [one \Rightarrow nfa_one
157 |frac x \Rightarrow numerator x
161 [one \Rightarrow nfa_one
162 |frac x \Rightarrow numerator x
167 definition nat_fact_all_to_Q \def
170 [nfa_zero \Rightarrow OQ
171 |nfa_one \Rightarrow Qpos one
172 |nfa_proper l \Rightarrow Qpos (frac (nat_fact_to_fraction l))
176 theorem numeratorQ_nat_fact_all_to_Q: \forall g.
177 numeratorQ (nat_fact_all_to_Q g) = g.
181 |apply numerator_nat_fact_to_fraction
185 definition nat_to_Q \def
186 \lambda n. nat_fact_all_to_Q (factorize n).
188 let rec nat_fact_to_fraction_inv l \def
190 [nf_last a \Rightarrow nn a
191 |nf_cons a p \Rightarrow
192 cons (neg_Z_of_nat a) (nat_fact_to_fraction_inv p)
197 definition nat_fact_all_to_Q_inv \def
200 [nfa_zero \Rightarrow OQ
201 |nfa_one \Rightarrow Qpos one
202 |nfa_proper l \Rightarrow Qpos (frac (nat_fact_to_fraction_inv l))
206 definition nat_to_Q_inv \def
207 \lambda n. nat_fact_all_to_Q_inv (factorize n).
211 \lambda q.match q with
213 |Qpos r \Rightarrow Qpos (rinv r)
214 |Qneg r \Rightarrow Qneg (rinv r)
217 definition frac:nat \to nat \to Q \def
218 \lambda p,q. Qtimes (nat_to_Q p) (Qinv (nat_to_Q q)).
220 theorem rtimes_oner: \forall r.rtimes r one = r.
221 intro.cases r;reflexivity.
224 theorem rtimes_onel: \forall r.rtimes one r = r.
225 intro.cases r;reflexivity.
228 definition Qone \def Qpos one.
230 theorem Qtimes_Qoner: \forall q.Qtimes q Qone = q.
244 theorem Qtimes_Qonel: \forall q.Qtimes Qone q = q.
258 let rec times_f h g \def
260 [nf_last a \Rightarrow
262 [nf_last b \Rightarrow nf_last (S (a+b))
263 |nf_cons b g1 \Rightarrow nf_cons (S (a+b)) g1
265 |nf_cons a h1 \Rightarrow
267 [nf_last b \Rightarrow nf_cons (S (a+b)) h1
268 |nf_cons b g1 \Rightarrow nf_cons (a+b) (times_f h1 g1)
273 definition times_fa \def
276 [nfa_zero \Rightarrow nfa_zero
277 |nfa_one \Rightarrow g
278 |nfa_proper f1 \Rightarrow match g with
279 [nfa_zero \Rightarrow nfa_zero
280 |nfa_one \Rightarrow nfa_proper f1
281 |nfa_proper g1 \Rightarrow nfa_proper (times_f f1 g1)
286 theorem eq_times_f_times1:\forall g,h,m. defactorize_aux (times_f g h) m
287 =defactorize_aux g m*defactorize_aux h m.
289 [elim h;simplify;autobatch
292 |simplify.rewrite > (H n3 (S m)).autobatch
297 theorem eq_times_fa_times: \forall f,g.
298 defactorize (times_fa f g) = defactorize f*defactorize g.
302 |simplify.apply plus_n_O
306 |apply eq_times_f_times1
311 theorem eq_times_times_fa: \forall n,m.
312 factorize (n*m) = times_fa (factorize n) (factorize m).
314 rewrite <(factorize_defactorize (times_fa (factorize n) (factorize m))).
315 rewrite > eq_times_fa_times.
316 rewrite > defactorize_factorize.
317 rewrite > defactorize_factorize.
322 theorem eq_plus_Zplus: \forall n,m:nat. Z_of_nat (n+m) =
323 Z_of_nat n + Z_of_nat m.
327 [simplify.rewrite < plus_n_O.reflexivity
328 |simplify.reflexivity.
333 definition unfrac \def \lambda f.
335 [one \Rightarrow pp O
336 |frac f \Rightarrow f
340 lemma injective_frac: injective fraction ratio frac.
342 change with ((unfrac (frac x)) = (unfrac (frac y))).
343 rewrite < H.reflexivity.
346 theorem times_f_ftimes: \forall n,m.
347 frac (nat_fact_to_fraction (times_f n m))
348 = ftimes (nat_fact_to_fraction n) (nat_fact_to_fraction m).
353 rewrite < plus_n_Sm.reflexivity
355 [simplify.rewrite < plus_n_O.reflexivity
356 |simplify.reflexivity.
361 [simplify.reflexivity
362 |simplify.rewrite < plus_n_Sm.reflexivity
365 cut (\exist h.ftimes (nat_fact_to_fraction n2) (nat_fact_to_fraction n4) = frac h)
371 |apply injective_frac.
375 |generalize in match n4.
377 [cases n6;simplify;autobatch
391 theorem times_fa_Qtimes: \forall f,g. nat_fact_all_to_Q (times_fa f g) =
392 Qtimes (nat_fact_all_to_Q f) (nat_fact_all_to_Q g).
400 |rewrite > times_f_ftimes.reflexivity
405 theorem times_Qtimes: \forall p,q.
406 (nat_to_Q (p*q)) = Qtimes (nat_to_Q p) (nat_to_Q q).
407 intros.unfold nat_to_Q.
408 rewrite < times_fa_Qtimes.
409 rewrite < eq_times_times_fa.
413 theorem rtimes_Zplus: \forall x,y.
414 rtimes (Z_to_ratio x) (Z_to_ratio y) =
424 theorem rtimes_Zplus1: \forall x,y,f.
425 rtimes (Z_to_ratio x) (frac (cons y f)) =
426 frac (cons ((x + y)) f).
435 theorem rtimes_Zplus2: \forall x,y,f.
436 rtimes (frac (cons y f)) (Z_to_ratio x) =
437 frac (cons ((y + x)) f).
446 theorem or_one_frac: \forall f,g.
447 rtimes (frac f) (frac g) = one \lor
448 \exists h.rtimes (frac f) (frac g) = frac h.
450 elim (rtimes (frac f) (frac g))
452 |right.apply (ex_intro ? ? f1).reflexivity
456 theorem one_to_rtimes_Zplus3: \forall x,y:Z.\forall f,g:fraction.
457 rtimes (frac f) (frac g) = one \to
458 rtimes (frac (cons x f)) (frac (cons y g)) = Z_to_ratio (x + y).
459 intros.simplify.simplify in H.rewrite > H.simplify.
463 theorem frac_to_rtimes_Zplus3: \forall x,y:Z.\forall f,g:fraction.
464 \forall h.rtimes (frac f) (frac g) = frac h \to
465 rtimes (frac (cons x f)) (frac (cons y g)) = frac (cons (x + y) h).
466 intros.simplify.simplify in H.rewrite > H.simplify.
470 theorem rtimes_Zplus3: \forall x,y:Z.\forall f,g:fraction.
471 (rtimes (frac f) (frac g) = one \land
472 rtimes (frac (cons x f)) (frac (cons y g)) = Z_to_ratio (x + y))
473 \lor (\exists h.rtimes (frac f) (frac g) = frac h \land
474 rtimes (frac (cons x f)) (frac (cons y g)) =
475 frac (cons (x + y) h)).
478 elim (rtimes (frac f) (frac g));simplify
479 [left.split;reflexivity
481 apply (ex_intro ? ? f1).
486 theorem Z_to_ratio_frac_frac: \forall z,f1,f2.
487 rtimes (rtimes (Z_to_ratio z) (frac f1)) (frac f2)
488 =rtimes (Z_to_ratio z) (rtimes (frac f1) (frac f2)).
492 (rtimes (rtimes (Z_to_ratio z) (Z_to_ratio (pos n))) (Z_to_ratio (pos n1))
493 =rtimes (Z_to_ratio z) (rtimes (Z_to_ratio (pos n)) (Z_to_ratio (pos n1)))).
494 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
495 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
496 rewrite > assoc_Zplus.reflexivity
498 (rtimes (rtimes (Z_to_ratio z) (Z_to_ratio (pos n))) (Z_to_ratio (neg n1))
499 =rtimes (Z_to_ratio z) (rtimes (Z_to_ratio (pos n)) (Z_to_ratio (neg n1)))).
500 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
501 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
502 rewrite > assoc_Zplus.reflexivity
504 (rtimes (rtimes (Z_to_ratio z) (Z_to_ratio (pos n))) (frac (cons z1 f))
505 = rtimes (Z_to_ratio z) (rtimes (Z_to_ratio (pos n)) (frac (cons z1 f)))).
506 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus1.
507 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus1.
508 rewrite > assoc_Zplus.reflexivity
512 (rtimes (rtimes (Z_to_ratio z) (Z_to_ratio (neg n))) (Z_to_ratio (pos n1))
513 =rtimes (Z_to_ratio z) (rtimes (Z_to_ratio (neg n)) (Z_to_ratio (pos n1)))).
514 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
515 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
516 rewrite > assoc_Zplus.reflexivity
518 (rtimes (rtimes (Z_to_ratio z) (Z_to_ratio (neg n))) (Z_to_ratio (neg n1))
519 =rtimes (Z_to_ratio z) (rtimes (Z_to_ratio (neg n)) (Z_to_ratio (neg n1)))).
520 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
521 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus.
522 rewrite > assoc_Zplus.reflexivity
524 (rtimes (rtimes (Z_to_ratio z) (Z_to_ratio (neg n))) (frac (cons z1 f))
525 = rtimes (Z_to_ratio z) (rtimes (Z_to_ratio (neg n)) (frac (cons z1 f)))).
526 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus1.
527 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus1.
528 rewrite > assoc_Zplus.reflexivity
532 (rtimes (rtimes (Z_to_ratio z) (frac (cons z1 f))) (Z_to_ratio (pos n))
533 =rtimes (Z_to_ratio z) (rtimes (frac (cons z1 f)) (Z_to_ratio (pos n)))).
534 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus2.
535 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
536 rewrite > assoc_Zplus.reflexivity
538 (rtimes (rtimes (Z_to_ratio z) (frac (cons z1 f))) (Z_to_ratio (neg n))
539 =rtimes (Z_to_ratio z) (rtimes (frac (cons z1 f)) (Z_to_ratio (neg n)))).
540 rewrite > rtimes_Zplus1.rewrite > rtimes_Zplus2.
541 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
542 rewrite > assoc_Zplus.reflexivity
543 |elim (or_one_frac f f3)
544 [rewrite > rtimes_Zplus1.
545 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
546 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
547 rewrite > rtimes_Zplus.
548 rewrite > assoc_Zplus.reflexivity
550 rewrite > rtimes_Zplus1.
551 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H3).
552 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H3).
553 rewrite > rtimes_Zplus1.
554 rewrite > assoc_Zplus.reflexivity
560 theorem cons_frac_frac: \forall f1,z,f,f2.
561 rtimes (rtimes (frac (cons z f)) (frac f1)) (frac f2)
562 =rtimes (frac (cons z f)) (rtimes (frac f1) (frac f2)).
566 (rtimes (rtimes (frac (cons z f)) (Z_to_ratio (pos n))) (Z_to_ratio (pos n1))
567 =rtimes (frac (cons z f)) (rtimes (Z_to_ratio (pos n)) (Z_to_ratio (pos n1)))).
568 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
569 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
570 rewrite > assoc_Zplus.reflexivity
572 (rtimes (rtimes (frac (cons z f)) (Z_to_ratio (pos n))) (Z_to_ratio (neg n1))
573 =rtimes (frac (cons z f)) (rtimes (Z_to_ratio (pos n)) (Z_to_ratio (neg n1)))).
574 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
575 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
576 rewrite > assoc_Zplus.reflexivity
578 (rtimes (rtimes (frac (cons z f)) (Z_to_ratio (pos n))) (frac (cons z1 f3))
579 = rtimes (frac (cons z f)) (rtimes (Z_to_ratio (pos n)) (frac (cons z1 f3)))).
580 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
581 elim (or_one_frac f f3)
582 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
583 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
584 rewrite > assoc_Zplus.reflexivity
586 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
587 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
588 rewrite > assoc_Zplus.reflexivity
593 (rtimes (rtimes (frac (cons z f)) (Z_to_ratio (neg n))) (Z_to_ratio (pos n1))
594 =rtimes (frac (cons z f)) (rtimes (Z_to_ratio (neg n)) (Z_to_ratio (pos n1)))).
595 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
596 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
597 rewrite > assoc_Zplus.reflexivity
599 (rtimes (rtimes (frac (cons z f)) (Z_to_ratio (neg n))) (Z_to_ratio (neg n1))
600 =rtimes (frac (cons z f)) (rtimes (Z_to_ratio (neg n)) (Z_to_ratio (neg n1)))).
601 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus2.
602 rewrite > rtimes_Zplus.rewrite > rtimes_Zplus2.
603 rewrite > assoc_Zplus.reflexivity
605 (rtimes (rtimes (frac (cons z f)) (Z_to_ratio (neg n))) (frac (cons z1 f3))
606 = rtimes (frac (cons z f)) (rtimes (Z_to_ratio (neg n)) (frac (cons z1 f3)))).
607 rewrite > rtimes_Zplus2.rewrite > rtimes_Zplus1.
608 elim (or_one_frac f f3)
609 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
610 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
611 rewrite > assoc_Zplus.reflexivity
613 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
614 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
615 rewrite > assoc_Zplus.reflexivity
620 (rtimes (rtimes (frac (cons z1 f2)) (frac (cons z f))) (Z_to_ratio (pos n))
621 =rtimes (frac (cons z1 f2)) (rtimes (frac (cons z f)) (Z_to_ratio (pos n)))).
622 rewrite > rtimes_Zplus2.
623 elim (or_one_frac f2 f)
624 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
625 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
626 rewrite > rtimes_Zplus.
627 rewrite > assoc_Zplus.reflexivity
629 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
630 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
631 rewrite > rtimes_Zplus2.
632 rewrite > assoc_Zplus.reflexivity
635 (rtimes (rtimes (frac (cons z1 f2)) (frac (cons z f))) (Z_to_ratio (neg n))
636 =rtimes (frac (cons z1 f2)) (rtimes (frac (cons z f)) (Z_to_ratio (neg n)))).
637 rewrite > rtimes_Zplus2.
638 elim (or_one_frac f2 f)
639 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
640 rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H1).
641 rewrite > rtimes_Zplus.
642 rewrite > assoc_Zplus.reflexivity
644 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
645 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H2).
646 rewrite > rtimes_Zplus2.
647 rewrite > assoc_Zplus.reflexivity
649 |elim (or_one_frac f2 f)
650 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
651 rewrite > rtimes_Zplus1.
652 elim (or_one_frac f f4)
653 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H3).
654 rewrite > rtimes_Zplus2.
657 rewrite > assoc_Zplus.reflexivity
658 |apply injective_frac.
659 rewrite < rtimes_onel.
661 (* problema inaspettato: mi serve l'unicita' dell'inversa,
662 che richiede (?) l'associativita. Per fortuna basta
663 l'ipotesi induttiva. *)
666 (rtimes (rtimes (Z_to_ratio (pos n)) (frac f)) (frac f4)=Z_to_ratio (pos n)).
667 rewrite > Z_to_ratio_frac_frac.
669 rewrite > rtimes_oner.
672 (rtimes (rtimes (Z_to_ratio (neg n)) (frac f)) (frac f4)=Z_to_ratio (neg n)).
673 rewrite > Z_to_ratio_frac_frac.
675 rewrite > rtimes_oner.
679 rewrite > rtimes_oner.
684 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H4).
685 cut (rtimes (frac f2) (frac a) = frac f4)
686 [rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? f4 Hcut).
687 rewrite > assoc_Zplus.reflexivity
689 generalize in match H2.
692 (rtimes (Z_to_ratio (pos n)) (rtimes (frac f)(frac f4)) =frac f4).
693 rewrite < Z_to_ratio_frac_frac.
695 rewrite > rtimes_onel.
698 (rtimes (Z_to_ratio (neg n)) (rtimes (frac f)(frac f4)) =frac f4).
699 rewrite < Z_to_ratio_frac_frac.
701 rewrite > rtimes_onel.
705 rewrite > rtimes_onel.
711 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a H3).
712 elim (or_one_frac f f4)
713 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
714 rewrite > rtimes_Zplus2.
715 cut (rtimes (frac a) (frac f4) = frac f2)
716 [rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? f2 Hcut).
717 rewrite > assoc_Zplus.reflexivity
719 generalize in match H2.
722 (rtimes (rtimes (Z_to_ratio (pos n)) (frac f)) (frac f4)=Z_to_ratio (pos n)).
723 rewrite > Z_to_ratio_frac_frac.
725 rewrite > rtimes_oner.
728 (rtimes (rtimes (Z_to_ratio (neg n)) (frac f)) (frac f4)=Z_to_ratio (neg n)).
729 rewrite > Z_to_ratio_frac_frac.
731 rewrite > rtimes_oner.
735 rewrite > rtimes_oner.
740 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a1 H4).
741 elim (or_one_frac a f4)
742 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? H2).
743 cut (rtimes (frac f2) (frac a1) = one)
744 [rewrite > (one_to_rtimes_Zplus3 ? ? ? ? Hcut).
745 rewrite > assoc_Zplus.reflexivity
747 generalize in match H3.
750 (rtimes (Z_to_ratio (pos n)) (rtimes (frac f)(frac f4)) = one).
751 rewrite < Z_to_ratio_frac_frac.
755 (rtimes (Z_to_ratio (neg n)) (rtimes (frac f)(frac f4)) = one).
756 rewrite < Z_to_ratio_frac_frac.
765 rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a2 H5).
766 cut (rtimes (frac f2) (frac a1) = frac a2)
767 [rewrite > (frac_to_rtimes_Zplus3 ? ? ? ? a2 Hcut).
768 rewrite > assoc_Zplus.reflexivity
770 generalize in match H3.
773 (rtimes (Z_to_ratio (pos n)) (rtimes (frac f)(frac f4)) = frac a2).
774 rewrite < Z_to_ratio_frac_frac.
778 (rtimes (Z_to_ratio (neg n)) (rtimes (frac f)(frac f4)) = frac a2).
779 rewrite < Z_to_ratio_frac_frac.
794 theorem frac_frac_fracaux: \forall f,f1,f2.
795 rtimes (rtimes (frac f) (frac f1)) (frac f2)
796 =rtimes (frac f) (rtimes (frac f1) (frac f2)).
800 (rtimes (rtimes (Z_to_ratio (pos n)) (frac f1)) (frac f2)
801 =rtimes (Z_to_ratio (pos n)) (rtimes (frac f1) (frac f2))).
802 apply Z_to_ratio_frac_frac
804 (rtimes (rtimes (Z_to_ratio (neg n)) (frac f1)) (frac f2)
805 =rtimes (Z_to_ratio (neg n)) (rtimes (frac f1) (frac f2))).
806 apply Z_to_ratio_frac_frac
807 |apply cons_frac_frac
811 theorem associative_rtimes:associative ? rtimes.
818 [rewrite > rtimes_oner.rewrite > rtimes_oner.reflexivity
819 |apply frac_frac_fracaux
825 theorem associative_Qtimes:associative ? Qtimes.
829 (* non posso scrivere 2,3: ... ?? *)
834 |simplify.rewrite > associative_rtimes.
836 |simplify.rewrite > associative_rtimes.
841 |simplify.rewrite > associative_rtimes.
843 |simplify.rewrite > associative_rtimes.
851 |simplify.rewrite > associative_rtimes.
853 |simplify.rewrite > associative_rtimes.
858 |simplify.rewrite > associative_rtimes.
860 |simplify.rewrite > associative_rtimes.
867 theorem Qtimes_OQ: \forall q.Qtimes q OQ = OQ.
868 intro.cases q;reflexivity.
871 theorem symmetric_Qtimes: symmetric ? Qtimes.
874 [simplify in ⊢ (? ? % ?).rewrite > Qtimes_OQ.reflexivity
877 |simplify.rewrite > symmetric_rtimes.reflexivity
878 |simplify.rewrite > symmetric_rtimes.reflexivity
882 |simplify.rewrite > symmetric_rtimes.reflexivity
883 |simplify.rewrite > symmetric_rtimes.reflexivity
888 theorem Qtimes_Qinv: \forall q. q \neq OQ \to Qtimes q (Qinv q) = Qone.
892 |simplify.rewrite > rtimes_rinv.reflexivity
893 |simplify.rewrite > rtimes_rinv.reflexivity
897 theorem eq_Qtimes_OQ_to_eq_OQ: \forall p,q.
898 Qtimes p q = OQ \to p = OQ \lor q = OQ.
901 [intro.left.reflexivity
903 [intro.right.reflexivity
904 |simplify.intro.destruct H
905 |simplify.intro.destruct H
908 [intro.right.reflexivity
909 |simplify.intro.destruct H
910 |simplify.intro.destruct H
915 theorem Qinv_Qtimes: \forall p,q.
916 p \neq OQ \to q \neq OQ \to
918 Qtimes (Qinv p) (Qinv q).
920 rewrite < Qtimes_Qonel in ⊢ (? ? ? %).
921 rewrite < (Qtimes_Qinv (Qtimes p q))
922 [lapply (Qtimes_Qinv ? H).
923 lapply (Qtimes_Qinv ? H1).
924 rewrite > symmetric_Qtimes in ⊢ (? ? ? (? % ?)).
925 rewrite > associative_Qtimes.
926 rewrite > associative_Qtimes.
927 rewrite < associative_Qtimes in ⊢ (? ? ? (? ? (? ? %))).
928 rewrite < symmetric_Qtimes in ⊢ (? ? ? (? ? (? ? (? % ?)))).
929 rewrite > associative_Qtimes in ⊢ (? ? ? (? ? (? ? %))).
931 rewrite > Qtimes_Qoner.
933 rewrite > Qtimes_Qoner.
936 elim (eq_Qtimes_OQ_to_eq_OQ ? ? H2)
937 [apply (H H3)|apply (H1 H3)]
941 (* a stronger version, taking advantage of inv(O) = O *)
942 theorem Qinv_Qtimes': \forall p,q.
944 Qtimes (Qinv p) (Qinv q).
950 |apply Qinv_Qtimes;intro;destruct H
951 |apply Qinv_Qtimes;intro;destruct H
955 |apply Qinv_Qtimes;intro;destruct H
956 |apply Qinv_Qtimes;intro;destruct H
961 theorem Qtimes_frac_frac: \forall p,q,r,s.
962 Qtimes (frac p q) (frac r s) = (frac (p*r) (q*s)).
965 rewrite > associative_Qtimes.
966 rewrite < associative_Qtimes in ⊢ (? ? (? ? %) ?).
967 rewrite > symmetric_Qtimes in ⊢ (? ? (? ? (? % ?)) ?).
968 rewrite > associative_Qtimes in ⊢ (? ? (? ? %) ?).
969 rewrite < associative_Qtimes.
970 rewrite < times_Qtimes.
971 rewrite < Qinv_Qtimes'.
972 rewrite < times_Qtimes.
977 (* la prova seguente e' tutta una ripetizione. Sistemare. *)
979 theorem Qtimes1: \forall f:fraction.
980 Qtimes (nat_fact_all_to_Q (numerator f))
981 (Qinv (nat_fact_all_to_Q (numerator (finv f))))
987 |elim (or_numerator_nfa_one_nfa_proper f1)
990 cut (finv (nat_fact_to_fraction a) = f1)
993 rewrite > H2.rewrite > H1.simplify.
994 rewrite > Hcut.reflexivity
996 rewrite > H2.rewrite > H1.simplify.
997 rewrite > Hcut.reflexivity
999 rewrite > H2.rewrite > H1.simplify.
1000 rewrite > Hcut.reflexivity
1002 |generalize in match H.
1003 rewrite > H2.rewrite > H1.simplify.
1004 intro.destruct H3.assumption
1009 rewrite > H2.rewrite > H2.simplify.
1010 elim (or_numerator_nfa_one_nfa_proper (finv f1))
1012 rewrite > H3.simplify.
1013 cut (nat_fact_to_fraction a = f1)
1014 [rewrite > Hcut.reflexivity
1015 |generalize in match H.
1018 rewrite > Qtimes_Qoner.
1024 generalize in match H.
1026 rewrite > H3.simplify.
1030 simplify.reflexivity
1032 |simplify.rewrite > H2.simplify.
1033 elim (or_numerator_nfa_one_nfa_proper (finv f1))
1035 rewrite > H3.simplify.
1036 cut (nat_fact_to_fraction a = f1)
1037 [rewrite > Hcut.reflexivity
1038 |generalize in match H.
1041 rewrite > Qtimes_Qoner.
1047 generalize in match H.
1049 rewrite > H3.simplify.
1053 simplify.reflexivity
1055 |simplify.rewrite > H2.simplify.
1056 elim (or_numerator_nfa_one_nfa_proper (finv f1))
1058 rewrite > H3.simplify.
1059 cut (nat_fact_to_fraction a = f1)
1060 [rewrite > Hcut.reflexivity
1061 |generalize in match H.
1064 rewrite > Qtimes_Qoner.
1070 generalize in match H.
1072 rewrite > H3.simplify.
1076 simplify.reflexivity
1084 definition numQ:Q \to Z \def
1088 |Qpos r \Rightarrow Z_of_nat (defactorize (numeratorQ (Qpos r)))
1089 |Qneg r \Rightarrow neg_Z_of_nat (defactorize (numeratorQ (Qpos r)))
1093 definition numQ:Q \to nat \def
1094 \lambda q. defactorize (numeratorQ q).
1096 definition denomQ:Q \to nat \def
1097 \lambda q. defactorize (numeratorQ (Qinv q)).
1099 definition Qopp:Q \to Q \def \lambda q.
1102 |Qpos q \Rightarrow Qneg q
1103 |Qneg q \Rightarrow Qpos q
1106 theorem frac_numQ_denomQ1: \forall r:ratio.
1107 frac (numQ (Qpos r)) (denomQ (Qpos r)) = (Qpos r).
1109 unfold frac.unfold denomQ.unfold numQ.
1111 rewrite > factorize_defactorize.
1112 rewrite > factorize_defactorize.
1123 theorem frac_numQ_denomQ2: \forall r:ratio.
1124 frac (numQ (Qneg r)) (denomQ (Qneg r)) = (Qpos r).
1126 unfold frac.unfold denomQ.unfold numQ.
1128 rewrite > factorize_defactorize.
1129 rewrite > factorize_defactorize.
1140 definition Qabs:Q \to Q \def \lambda q.
1143 |Qpos q \Rightarrow Qpos q
1144 |Qneg q \Rightarrow Qpos q
1147 theorem frac_numQ_denomQ: \forall q.
1148 frac (numQ q) (denomQ q) = (Qabs q).
1152 |simplify in ⊢ (? ? ? %).apply frac_numQ_denomQ1
1153 |simplify in ⊢ (? ? ? %).apply frac_numQ_denomQ2
1157 definition Qfrac: Z \to nat \to Q \def
1158 \lambda z,n.match z with
1160 |Zpos m \Rightarrow (frac (S m) n)
1161 |Zneg m \Rightarrow Qopp (frac (S m) n)
1164 definition QnumZ \def \lambda q.
1167 |Qpos r \Rightarrow Z_of_nat (numQ (Qpos r))
1168 |Qneg r \Rightarrow neg_Z_of_nat (numQ (Qpos r))
1171 theorem Qfrac_Z_of_nat: \forall n,m.
1172 Qfrac (Z_of_nat n) m = frac n m.
1173 intros.cases n;reflexivity.
1176 theorem Qfrac_neg_Z_of_nat: \forall n,m.
1177 Qfrac (neg_Z_of_nat n) m = Qopp (frac n m).
1178 intros.cases n;reflexivity.
1181 theorem Qfrac_QnumZ_denomQ: \forall q.
1182 Qfrac (QnumZ q) (denomQ q) = q.
1187 (Qfrac (Z_of_nat (numQ (Qpos r))) (denomQ (Qpos r))=Qpos r).
1188 rewrite > Qfrac_Z_of_nat.
1189 apply frac_numQ_denomQ1.
1190 |simplify in ⊢ (? ? ? %).apply frac_numQ_denomQ2