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".
18 include "Q/fraction/fraction.ma".
20 let rec enumerator_integral_fraction l ≝
25 match enumerator_integral_fraction r with
28 [ pos n ⇒ Some ? (pp n)
40 let rec denominator_integral_fraction l ≝
43 | nn n ⇒ Some ? (pp n)
45 match denominator_integral_fraction r with
48 [ neg n ⇒ Some ? (pp n)
55 | neg m ⇒ cons (pos m) r'
62 definition enumerator_of_fraction ≝
67 match enumerator_integral_fraction f with
69 | Some l ⇒ defactorize_aux (nat_fact_of_integral_fraction l) O
73 definition denominator_of_fraction ≝
78 match denominator_integral_fraction f with
80 | Some l ⇒ defactorize_aux (nat_fact_of_integral_fraction l) O
84 definition enumerator ≝
88 | Qpos r ⇒ (enumerator_of_fraction r : Z)
89 | Qneg r ⇒ neg(pred (enumerator_of_fraction r))
92 definition denominator ≝
96 | Qpos r ⇒ denominator_of_fraction r
97 | Qneg r ⇒ denominator_of_fraction r