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 "nat_ordered_set.ma".
16 include "models/q_shift.ma".
18 alias symbol "pi2" = "pair pi2".
19 alias symbol "pi1" = "pair pi1".
20 definition rebase_spec ≝
21 ∀l1,l2:q_f.∃p:q_f × q_f.
23 (*len (bars (\fst p)) = len (bars (\snd p))*)
24 (start (\fst p) = start (\snd p))
25 (same_bases (\fst p) (\snd p))
26 (same_values l1 (\fst p))
27 (same_values l2 (\snd p)).
29 definition rebase_spec_simpl ≝
30 λstart.λl1,l2:list bar.λp:(list bar) × (list bar).
32 (same_bases (mk_q_f start (\fst p)) (mk_q_f start (\snd p)))
33 (same_values (mk_q_f start l1) (mk_q_f start (\fst p)))
34 (same_values (mk_q_f start l2) (mk_q_f start (\snd p))).
36 (* a local letin makes russell fail *)
37 definition cb0h : list bar → list bar ≝
38 λl.mk_list (λi.〈\fst (nth l ▭ i),OQ〉) (len l).
41 λP.λp:∃x:(list bar) × (list bar).P x.match p with [ex_introT p _ ⇒ p].
43 definition inject ≝ λP.λp:(list bar) × (list bar).λh:P p. ex_introT ? P p h.
44 coercion inject with 0 1 nocomposites.
46 definition rebase: rebase_spec.
47 intros 2 (f1 f2); cases f1 (s1 l1); cases f2 (s2 l2); clear f1 f2;
49 λs.λl1,l2.λm.λz.len l1 + len l2 < m → rebase_spec_simpl s l1 l2 z);
50 alias symbol "pi1" (instance 34) = "exT \fst".
51 alias symbol "pi1" (instance 21) = "exT \fst".
53 let rec aux (l1,l2:list bar) (n:nat) on n : (list bar) × (list bar) ≝
55 [ O ⇒ 〈 nil ? , nil ? 〉
63 let base1 ≝ Qpos (\fst he1) in
64 let base2 ≝ Qpos (\fst he2) in
65 let height1 ≝ (\snd he1) in
66 let height2 ≝ (\snd he2) in
67 match q_cmp base1 base2 with
69 let rc ≝ aux tl1 tl2 m in
70 〈he1 :: \fst rc,he2 :: \snd rc〉
72 let rest ≝ base2 - base1 in
73 let rc ≝ aux tl1 (〈\fst (unpos rest ?),height2〉 :: tl2) m in
74 〈〈\fst he1,height1〉 :: \fst rc,〈\fst he1,height2〉 :: \snd rc〉
76 let rest ≝ base1 - base2 in
77 let rc ≝ aux (〈\fst (unpos rest ?),height1〉 :: tl1) tl2 m in
78 〈〈\fst he2,height1〉 :: \fst rc,〈\fst he2,height2〉 :: \snd rc〉
80 in aux : ∀l1,l2,m.∃z.∀s.spec s l1 l2 m z); unfold spec;
81 [9: clearbody aux; unfold spec in aux; clear spec;
83 [1: cases (aux l1 l2 (S (len l1 + len l2)));
84 cases (H1 s1 (le_n ?)); clear H1;
85 exists [apply 〈mk_q_f s1 (\fst w), mk_q_f s2 (\snd w)〉] split;
87 |3: intro; apply (H3 input);
88 |4: intro; rewrite > H in H4;
89 rewrite > (H4 input); reflexivity;]
90 |2: letin l2' ≝ (〈\fst (unpos (s2-s1) ?),OQ〉::l2);[
91 apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
93 cases (aux l1 l2' (S (len l1 + len l2')));
94 cases (H1 s1 (le_n ?)); clear H1 aux;
95 exists [apply 〈mk_q_f s1 (\fst w), mk_q_f s1 (\snd w)〉] split;
99 |4: intro; rewrite > (initial_shift_same_values (mk_q_f s2 l2) s1 H input);
100 rewrite < (H4 input); reflexivity;]
101 |3: letin l1' ≝ (〈\fst (unpos (s1-s2) ?),OQ〉::l1);[
102 apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
104 cases (aux l1' l2 (S (len l1' + len l2)));
105 cases (H1 s2 (le_n ?)); clear H1 aux;
106 exists [apply 〈mk_q_f s2 (\fst w), mk_q_f s2 (\snd w)〉] split;
110 |3: intro; rewrite > (initial_shift_same_values (mk_q_f s1 l1) s2 H input);
111 rewrite < (H3 input); reflexivity;]]
112 |1,2: unfold rest; apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
114 |8: intros; cases (?:False); apply (not_le_Sn_O ? H1);
115 |3: intros; generalize in match (unpos ??); intro X; cases X; clear X;
116 simplify in ⊢ (???? (??? (??? (??? (?? (? (?? (??? % ?) ?) ??)))) ?));
117 simplify in ⊢ (???? (???? (??? (??? (?? (? (?? (??? % ?) ?) ??))))));
118 clear H4; cases (aux (〈w,\snd b〉::l4) l5 n1); clear aux;
119 cut (len (〈w,\snd b〉::l4) + len l5 < n1) as K;[2:
120 simplify in H5; simplify; rewrite > sym_plus in H5; simplify in H5;
121 rewrite > sym_plus in H5; apply le_S_S_to_le; apply H5;]
123 [1: simplify in ⊢ (? % ?); simplify in ⊢ (? ? %);
124 cases (H4 s K); clear K H4; intro input; cases input; [reflexivity]
126 |2: simplify in ⊢ (? ? %); cases (H4 s K); clear H4 K H5 spec;
128 (* input < s + b1 || input >= s + b1 *)
129 |3: simplify in ⊢ (? ? %);]
130 |4: intros; generalize in match (unpos ??); intro X; cases X; clear X;
132 |5: intros; (* triviale, caso in cui non fa nulla *)
133 |6,7: (* casi base in cui allunga la lista più corta *)