]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/Q/q/q.ma
More Q stuff organized in a coherent way.
[helm.git] / helm / software / matita / library / Q / q / q.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/ratio/ratio.ma".
16
17 (* a rational number is either O or a ratio with a sign *)
18 inductive Q : Set \def 
19     OQ : Q
20   | Qpos : ratio  \to Q
21   | Qneg : ratio  \to Q.
22
23 definition Qone ≝ Qpos one.
24
25 definition Qopp ≝
26  λq.
27   match q with
28    [ OQ ⇒ OQ
29    | Qpos r ⇒ Qneg r
30    | Qneg r ⇒ Qpos r
31    ].
32
33 definition nat_fact_all_to_Q \def
34 \lambda n.
35   match n with
36   [nfa_zero \Rightarrow OQ
37   |nfa_one \Rightarrow Qpos one
38   |nfa_proper l \Rightarrow Qpos (frac (nat_fact_to_fraction l))
39   ].
40
41 definition nat_to_Q ≝ λn.nat_fact_all_to_Q (factorize n).
42
43 definition Z_to_Q ≝
44  λz.
45   match z with
46    [ OZ ⇒ OQ
47    | pos n ⇒ nat_to_Q (S n)
48    | neg n ⇒ Qopp (nat_to_Q (S n))
49    ].
50
51 definition numeratorQ \def
52 \lambda q.match q with
53   [OQ \Rightarrow nfa_zero
54   |Qpos r \Rightarrow 
55     match r with 
56     [one \Rightarrow nfa_one
57     |frac x \Rightarrow numerator x
58     ]
59   |Qneg r \Rightarrow 
60     match r with 
61     [one \Rightarrow nfa_one
62     |frac x \Rightarrow numerator x
63     ]
64   ].
65
66 theorem numeratorQ_nat_fact_all_to_Q: \forall g.
67 numeratorQ (nat_fact_all_to_Q g) = g.
68 intro.cases g
69   [reflexivity
70   |reflexivity
71   |apply numerator_nat_fact_to_fraction
72   ]
73 qed.