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 (**************************************************************************)
17 definition Z_to_ratio: Z \to ratio \def
18 \lambda x:Z. match x with
20 | (pos n) \Rightarrow frac (pp n)
21 | (neg n) \Rightarrow frac (nn n)].
23 let rec ftimes f g \def
27 [(pp m) \Rightarrow Z_to_ratio (pos n + pos m)
28 | (nn m) \Rightarrow Z_to_ratio (pos n + neg m)
29 | (cons y g1) \Rightarrow frac (cons (pos n + y) g1)]
32 [(pp m) \Rightarrow Z_to_ratio (neg n + pos m)
33 | (nn m) \Rightarrow Z_to_ratio (neg n + neg m)
34 | (cons y g1) \Rightarrow frac (cons (neg n + y) g1)]
35 | (cons x f1) \Rightarrow
37 [ (pp m) \Rightarrow frac (cons (x + pos m) f1)
38 | (nn m) \Rightarrow frac (cons (x + neg m) f1)
39 | (cons y g1) \Rightarrow
40 match ftimes f1 g1 with
41 [ one \Rightarrow Z_to_ratio (x + y)
42 | (frac h) \Rightarrow frac (cons (x + y) h)]]].
44 theorem symmetric2_ftimes: symmetric2 fraction ratio ftimes.
45 unfold symmetric2. intros.apply (fraction_elim2 (\lambda f,g.ftimes f g = ftimes g f)).
47 change with (Z_to_ratio (pos n + pos n1) = Z_to_ratio (pos n1 + pos n)).
48 apply eq_f.apply sym_Zplus.
49 change with (Z_to_ratio (pos n + neg n1) = Z_to_ratio (neg n1 + pos n)).
50 apply eq_f.apply sym_Zplus.
51 change with (frac (cons (pos n + z) f) = frac (cons (z + pos n) f)).
52 rewrite < sym_Zplus.reflexivity.
54 change with (Z_to_ratio (neg n + pos n1) = Z_to_ratio (pos n1 + neg n)).
55 apply eq_f.apply sym_Zplus.
56 change with (Z_to_ratio (neg n + neg n1) = Z_to_ratio (neg n1 + neg n)).
57 apply eq_f.apply sym_Zplus.
58 change with (frac (cons (neg n + z) f) = frac (cons (z + neg n) f)).
59 rewrite < sym_Zplus.reflexivity.
60 intros.change with (frac (cons (x1 + pos m) f) = frac (cons (pos m + x1) f)).
61 rewrite < sym_Zplus.reflexivity.
62 intros.change with (frac (cons (x1 + neg m) f) = frac (cons (neg m + x1) f)).
63 rewrite < sym_Zplus.reflexivity.
65 (*CSC: simplify does something nasty here because of a redex in Zplus *)
67 (match ftimes f g with
68 [ one \Rightarrow Z_to_ratio (x1 + y1)
69 | (frac h) \Rightarrow frac (cons (x1 + y1) h)] =
71 [ one \Rightarrow Z_to_ratio (y1 + x1)
72 | (frac h) \Rightarrow frac (cons (y1 + x1) h)]).
73 rewrite < H.rewrite < sym_Zplus.reflexivity.
76 theorem ftimes_finv : \forall f:fraction. ftimes f (finv f) = one.
78 change with (Z_to_ratio (pos n + - (pos n)) = one).
79 rewrite > Zplus_Zopp.reflexivity.
80 change with (Z_to_ratio (neg n + - (neg n)) = one).
81 rewrite > Zplus_Zopp.reflexivity.
82 (*CSC: simplify does something nasty here because of a redex in Zplus *)
83 (* again: we would need something to help finding the right change *)
85 (match ftimes f1 (finv f1) with
86 [ one \Rightarrow Z_to_ratio (z + - z)
87 | (frac h) \Rightarrow frac (cons (z + - z) h)] = one).
88 rewrite > H.rewrite > Zplus_Zopp.reflexivity.
91 definition rtimes : ratio \to ratio \to ratio \def
95 | (frac f) \Rightarrow
97 [one \Rightarrow frac f
98 | (frac g) \Rightarrow ftimes f g]].
100 theorem rtimes_rinv: \forall r:ratio. rtimes r (rinv r) = one.
103 simplify.apply ftimes_finv.
106 theorem symmetric_rtimes : symmetric ratio rtimes.
107 change with (\forall r,s:ratio. rtimes r s = rtimes s r).
114 simplify.apply symmetric2_ftimes.
117 variant sym_rtimes : ∀x,y:ratio. rtimes x y = rtimes y x ≝ symmetric_rtimes.
119 definition Qtimes : Q \to Q \to Q \def
126 |Qpos q1 \Rightarrow Qpos (rtimes p1 q1)
127 |Qneg q1 \Rightarrow Qneg (rtimes p1 q1)
132 |Qpos q1 \Rightarrow Qneg (rtimes p1 q1)
133 |Qneg q1 \Rightarrow Qpos (rtimes p1 q1)
137 interpretation "rational times" 'times x y = (cic:/matita/Q/times/Qtimes.con x y).
139 theorem Qtimes_q_OQ: ∀q. q * OQ = OQ.
145 theorem symmetric_Qtimes: symmetric ? Qtimes.
148 [ rewrite > Qtimes_q_OQ; reflexivity
151 try rewrite > sym_rtimes;
156 theorem Qtimes_Qinv: ∀q. q ≠ OQ → q * (Qinv q) = Qpos one.
159 [ elim H; reflexivity
161 rewrite > rtimes_rinv;