1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "models/q_function.ma".
17 alias symbol "lt" = "Q less than".
18 alias symbol "Q" = "Rationals".
19 axiom q_unlimited: ∀x:ℚ.∃y:ratio.x<Qpos y.
20 axiom q_halving: ∀x,y:ℚ.∃z:ℚ.x<z ∧ z<y.
21 lemma same_values_unit_OQ:
22 ∀b1,b2,h1,l. b2 < b1 → sorted q2_lt (〈b1,h1〉::l) →
23 sorted q2_lt [〈b2,〈OQ,OQ〉〉] →
24 same_values_simpl (〈b1,h1〉::l) [〈b2,〈OQ,OQ〉〉] → h1 = 〈OQ,OQ〉.
26 [1: intros; cases (q_unlimited b1); cut (b2 < Qpos w); [2:apply (q_lt_trans ??? H H4);]
27 lapply (H3 H1 ? H2 ? w H4 Hcut) as K; simplify; [1,2: autobatch]
28 rewrite > (value_unit 〈b1,h1〉) in K;
29 rewrite > (value_unit 〈b2,〈OQ,OQ〉〉) in K; assumption;
30 |2: intros; (* MANCA che le basi sono positive,
31 poi con halving prendi tra b1 e \fst p e hai h1=OQ,OQ*)
35 λP.λp:∃x:(list bar) × (list bar).P x.match p with [ex_introT p _ ⇒ p].
37 definition inject ≝ λP.λp:(list bar) × (list bar).λh:P p. ex_introT ? P p h.
38 coercion inject with 0 1 nocomposites.
40 definition rebase: ∀l1,l2:q_f.∃p:q_f × q_f.rebase_spec l1 l2 p.
41 intros 2 (f1 f2); cases f1 (b1 Hs1 Hb1 He1); cases f2 (b2 Hs2 Hb2 He2); clear f1 f2;
42 alias symbol "leq" = "natural 'less or equal to'".
43 alias symbol "minus" = "Q minus".
45 let rec aux (l1,l2:list bar) (n : nat) on n : (list bar) × (list bar) ≝
55 let base1 ≝ \fst he1 in
56 let base2 ≝ \fst he2 in
57 let height1 ≝ \snd he1 in
58 let height2 ≝ \snd he2 in
59 match q_cmp base1 base2 with
61 match q_cmp base2 base1 with
63 let rc ≝ aux tl1 tl2 m in
64 〈he1 :: \fst rc,he2 :: \snd rc〉
66 let rest ≝ base2 - base1 in
67 let rc ≝ aux tl1 (〈rest,height2〉 :: tl2) m in
68 〈〈base1,height1〉 :: \fst rc,〈base1,height2〉 :: \snd rc〉]
70 let rest ≝ base1 - base2 in
71 let rc ≝ aux (〈rest,height1〉 :: tl1) tl2 m in
72 〈〈base2,height1〉 :: \fst rc,〈base2,height2〉 :: \snd rc〉]]]]
73 in aux : ∀l1,l2,m.∃z.\len l1 + \len l2 ≤ m → rebase_spec_aux l1 l2 z);
74 [7: clearbody aux; cases (aux b1 b2 (\len b1 + \len b2)) (res Hres);
75 exists; [split; constructor 1; [apply (\fst res)|5:apply (\snd res)]]
76 [1,4: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); assumption;
77 |2,5: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); clear Hres aux;
78 lapply (H3 O) as K; clear H1 H2 H3 H4 H5; unfold nth_base;
79 cases H in K He1 He2 Hb1 Hb2; simplify; intros; assumption;
80 |3,6: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); clear Hres aux;
81 cases H in He1 He2; simplify; intros;
82 [1,6,8,12: assumption;
83 |2,7: rewrite > len_copy; generalize in match (\len ?); intro X;
84 cases X; [1,3: reflexivity] simplify;
85 [apply (copy_OQ ys n);|apply (copy_OQ xs n);]
86 |3,4: rewrite < H6; assumption;
87 |5: cases r1 in H6; simplify; intros; [reflexivity] rewrite < H6; assumption;
88 |9,11: rewrite < H7; assumption;
89 |10: cases r2 in H7; simplify; intros; [reflexivity] rewrite < H7; assumption]]
90 split; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); clear Hres; unfold same_values; intros;
92 |2,3: simplify in match (\snd 〈?,?〉); simplify in match (\fst 〈?,?〉);
93 apply same_values_simpl_to_same_values; assumption]
94 |3: cut (\fst b3 = \fst b) as E; [2: apply q_le_to_le_to_eq; assumption]
95 clear H6 H5 H4 H3 He2 Hb2 Hs2 b2 He1 Hb1 Hs1 b1; cases (aux l2 l3 n1) (rc Hrc);
96 clear aux; intro K; simplify in K; rewrite <plus_n_Sm in K;
97 lapply le_S_S_to_le to K as W; lapply lt_to_le to W as R;
98 simplify in match (? ≪rc,Hrc≫); intros (Hsbl2 Hendbl2 Hsb3l3 Hendb3l3);
99 change in Hendbl2 with (\snd (\last ▭ (b::l2)) = 〈OQ,OQ〉);
100 change in Hendb3l3 with (\snd (\last ▭ (b3::l3)) = 〈OQ,OQ〉);
101 cases (Hrc R) (RC S1 S2 SB SV1 SV2); clear Hrc R W K;
102 [2,4: apply (sorted_tail q2_lt);[apply b|3:apply b3]assumption;
103 |3: cases l2 in Hendbl2; simplify; intros; [reflexivity] assumption;
104 |5: cases l3 in Hendb3l3; simplify; intros; [reflexivity] assumption;]
105 constructor 1; simplify in match (\fst 〈?,?〉); simplify in match (\snd 〈?,?〉);
106 [1: cases b in E Hsbl2 Hendbl2; cases b3 in Hsb3l3 Hendb3l3; intros (Hsbl3 Hendbl2 E Hsb3l2 Hendb3l3);
107 simplify in E; destruct E; constructor 3;
108 [1: clear Hendbl2 Hsbl3 SV2 SB S2;
109 cases RC in S1 SV1 Hsb3l2 Hendb3l3; intros;
112 |5: simplify in H6:(??%) ⊢ %; rewrite > H3; cases r1 in H6; intros [2:reflexivity]
113 use same_values_unit_OQ;
115 |2: simplify in H3:(??%) ⊢ %; rewrite > H3; rewrite > len_copy; elim (\len ys); [reflexivity]
116 symmetry; apply (copy_OQ ys n2);
117 | cases H8 in H5 H7; simplify; intros; [2,6:reflexivity|3,4,5: assumption]
118 simplify; rewrite > H5; rewrite > len_copy; elim (\len xs); [reflexivity]
119 symmetry; apply (copy_OQ xs n2);]
120 |2: apply (aux_preserves_sorting ? b3 ??? H8); assumption;
121 |3: apply (aux_preserves_sorting2 ? b3 ??? H8); try assumption;
122 try reflexivity; cases (inversion_sorted ?? H4);[2:rewrite >H3; apply (sorted_one q2_lt);]
123 cases l2 in H3 H4; intros; [apply (sorted_one q2_lt)]
124 apply (sorted_cons q2_lt);[2:apply (sorted_tail q2_lt ?? H3);] whd;
125 rewrite > E; assumption;
128 |6: intro; elim i; intros; simplify; solve [symmetry;assumption|apply H13]
129 |7: unfold; intros; clear H9 H10 H11 H12 H13; simplify in Hi1 Hi2 H16 H18;
130 cases H8 in H14 H15 H17 H3 H16 H18 H5 H6;
131 simplify in match (\fst 〈?,?〉); simplify in match (\snd 〈?,?〉); intros;
133 |2: simplify in H3; rewrite > (value_unit b); rewrite > H3; symmetry;
134 cases b in H3 H12 Hi2; intros 2; simplify in H12; rewrite > H12;
135 intros; change in ⊢ (? ? (? % ? ? ? ?) ?) with (copy (〈q,〈OQ,OQ〉〉::〈b1,〈OQ,OQ〉〉::ys));
136 apply (value_copy (〈q,〈OQ,OQ〉〉::〈b1,〈OQ,OQ〉〉::ys));
137 |3: apply (same_value_tail b b1 h1 h3 xs r1 input); assumption;
138 |4: apply (same_value_tail b b1 h1 h1 xs r1 input); assumption;
139 |5: simplify in H9; STOP
147 include "Q/q/qtimes.ma".
149 let rec area (l:list bar) on l ≝
152 | cons he tl ⇒ area tl + Qpos (\fst he) * ⅆ[OQ,\snd he]].
154 alias symbol "pi1" = "exT \fst".
155 alias symbol "minus" = "Q minus".
156 alias symbol "exists" = "CProp exists".
157 definition minus_spec_bar ≝
159 same_bases f g → len f = len g →
160 ∀s,i:ℚ. \snd (\fst (value (mk_q_f s h) i)) =
161 \snd (\fst (value (mk_q_f s f) i)) - \snd (\fst (value (mk_q_f s g) i)).
163 definition minus_spec ≝
166 ∀i:ℚ. \snd (\fst (value h i)) =
167 \snd (\fst (value f i)) - \snd (\fst (value g i)).
169 definition eject_bar : ∀P:list bar → CProp.(∃l:list bar.P l) → list bar ≝
170 λP.λp.match p with [ex_introT x _ ⇒ x].
171 definition inject_bar ≝ ex_introT (list bar).
173 coercion inject_bar with 0 1 nocomposites.
174 coercion eject_bar with 0 0 nocomposites.
176 lemma minus_q_f : ∀f,g. minus_spec f g.
179 let rec aux (l1, l2 : list bar) on l1 ≝
185 | cons he2 tl2 ⇒ 〈\fst he1, \snd he1 - \snd he2〉 :: aux tl1 tl2]]
186 in aux : ∀l1,l2 : list bar.∃h.minus_spec_bar l1 l2 h);
187 [2: intros 4; simplify in H3; destruct H3;
188 |3: intros 4; simplify in H3; cases l1 in H2; [2: intro X; simplify in X; destruct X]
189 intros; rewrite > (value_OQ_e (mk_q_f s []) i); [2: reflexivity]
190 rewrite > q_elim_minus; rewrite > q_plus_OQ; reflexivity;
191 |1: cases (aux l2 l3); unfold in H2; intros 4;
192 simplify in ⊢ (? ? (? ? ? (? ? ? (? % ?))) ?);
193 cases (q_cmp i (s + Qpos (\fst b)));
198 λf,g.∃i.\snd (\fst (value f i)) < \snd (\fst (value g i)).