]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/Q/inv.ma
More work on rational numbers with unique representations.
[helm.git] / helm / software / matita / library / Q / inv.ma
1 (**************************************************************************)
2 (*       ___                                                                *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
8 (*      ||A||       E.Tassi, S.Zacchiroli                                 *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU Lesser General Public License Version 2.1         *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "Q/q.ma".
16
17 let rec finv f \def
18   match f with
19   [ (pp n) \Rightarrow (nn n)
20   | (nn n) \Rightarrow (pp n)
21   | (cons x g) \Rightarrow (cons (Zopp x) (finv g))].
22
23 definition rinv : ratio \to ratio \def
24 \lambda r:ratio.
25   match r with
26   [one \Rightarrow one
27   | (frac f) \Rightarrow frac (finv f)].
28
29 definition Qinv : Q → Q ≝
30  λp.
31   match p with
32    [ OQ ⇒ OQ  (* arbitrary value *)
33    | Qpos r ⇒ Qpos (rinv r)
34    | Qneg r ⇒ Qneg (rinv r)
35    ].