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 "Z/compare.ma".
17 include "nat/factorization.ma".
19 alias id "pp" = "cic:/matita/Q/fraction/fraction/fraction.ind#xpointer(1/1/1)".
20 alias id "cons" = "cic:/matita/Q/fraction/fraction/fraction.ind#xpointer(1/1/3)".
21 let rec enumerator_integral_fraction l ≝
26 match enumerator_integral_fraction r with
29 [ pos n ⇒ Some ? (pp n)
41 let rec denominator_integral_fraction l ≝
44 | nn n ⇒ Some ? (pp n)
46 match denominator_integral_fraction r with
49 [ neg n ⇒ Some ? (pp n)
56 | neg m ⇒ cons (pos m) r'
63 definition enumerator_of_fraction ≝
68 match enumerator_integral_fraction f with
70 | Some l ⇒ defactorize_aux (nat_fact_of_integral_fraction l) O
74 definition denominator_of_fraction ≝
79 match denominator_integral_fraction f with
81 | Some l ⇒ defactorize_aux (nat_fact_of_integral_fraction l) O
85 definition enumerator ≝
89 | Qpos r ⇒ (enumerator_of_fraction r : Z)
90 | Qneg r ⇒ neg(pred (enumerator_of_fraction r))
93 definition denominator ≝
97 | Qpos r ⇒ denominator_of_fraction r
98 | Qneg r ⇒ denominator_of_fraction r