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 let rec enumerator_integral_fraction l ≝
24 match enumerator_integral_fraction r with
27 [ pos n ⇒ Some ? (pp n)
39 let rec denominator_integral_fraction l ≝
42 | nn n ⇒ Some ? (pp n)
44 match denominator_integral_fraction r with
47 [ neg n ⇒ Some ? (pp n)
54 | neg m ⇒ cons (pos m) r'
60 definition enumerator_of_fraction ≝
65 match enumerator_integral_fraction f with
67 | Some l ⇒ defactorize_aux (nat_fact_of_integral_fraction l) O
71 definition denominator_of_fraction ≝
76 match denominator_integral_fraction f with
78 | Some l ⇒ defactorize_aux (nat_fact_of_integral_fraction l) O
82 definition enumerator ≝
86 | Qpos r ⇒ (enumerator_of_fraction r : Z)
87 | Qneg r ⇒ neg(pred (enumerator_of_fraction r))
90 definition denominator ≝
94 | Qpos r ⇒ denominator_of_fraction r
95 | Qneg r ⇒ denominator_of_fraction r