]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/dama/dama/models/q_function.ma
new q_function representation
[helm.git] / helm / software / matita / contribs / dama / dama / models / q_function.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "models/q_bars.ma".
16
17 alias symbol "pi2" = "pair pi2".
18 alias symbol "pi1" = "pair pi1".
19 definition rebase_spec ≝ 
20  ∀l1,l2:q_f.∃p:q_f × q_f.
21    And4
22     (start (\fst p) = start (\snd p))
23     (same_bases (bars (\fst p)) (bars (\snd p)))
24     (same_values l1 (\fst p)) 
25     (same_values l2 (\snd p)).
26
27 definition rebase_spec_simpl ≝ 
28  λstart.λl1,l2:list bar.λp:(list bar) × (list bar).
29    And3
30     (same_bases (\fst p) (\snd p))
31     (same_values (mk_q_f start l1) (mk_q_f start (\fst p))) 
32     (same_values (mk_q_f start l2) (mk_q_f start (\snd p))).
33
34 (* a local letin makes russell fail *)
35 definition cb0h : list bar → list bar ≝ 
36   λl.mk_list (λi.〈\fst (nth l ▭ i),OQ〉) (len l).
37
38 definition eject ≝
39   λP.λp:∃x:(list bar) × (list bar).P x.match p with [ex_introT p _ ⇒ p].
40 coercion eject.
41 definition inject ≝ λP.λp:(list bar) × (list bar).λh:P p. ex_introT ? P p h.
42 coercion inject with 0 1 nocomposites.
43
44 axiom devil : False.
45         
46 definition rebase: rebase_spec.
47 intros 2 (f1 f2); cases f1 (s1 l1); cases f2 (s2 l2); clear f1 f2;
48 letin spec ≝ (
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".
52 letin aux ≝ ( 
53 let rec aux (l1,l2:list bar) (n:nat) on n : (list bar) × (list bar) ≝
54 match n with
55 [ O ⇒ 〈 nil ? , nil ? 〉
56 | S m ⇒ 
57   match l1 with
58   [ nil ⇒ 〈cb0h l2, l2〉
59   | cons he1 tl1 ⇒
60      match l2 with
61      [ nil ⇒ 〈l1, cb0h l1〉
62      | cons he2 tl2 ⇒  
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
68          [ q_eq _ ⇒ 
69              let rc ≝ aux tl1 tl2 m in 
70              〈he1 :: \fst rc,he2 :: \snd rc〉 
71          | q_lt Hp ⇒
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〉 
75          | q_gt Hp ⇒ 
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〉
79 ]]]]
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;
82     cases (q_cmp s1 s2);
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;
86         [1,2: assumption;
87         |3: intro; apply (H3 input);
88         |4: intro; rewrite > H in H4; 
89             rewrite > (H4 input) in ⊢ (? ? % ?); reflexivity;]
90     |2: letin l2' ≝ (〈\fst (unpos (s2-s1) ?),OQ〉::l2);[
91           apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
92           assumption]
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;
96         [1: reflexivity
97         |2: assumption;
98         |3: assumption;
99         |4: intro; 
100             rewrite > (initial_shift_same_values (mk_q_f s2 l2) s1 H input) in ⊢ (? ? % ?);
101             rewrite < (H4 input)in ⊢ (? ? ? %); reflexivity;]
102     |3: letin l1' ≝ (〈\fst (unpos (s1-s2) ?),OQ〉::l1);[
103           apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
104           assumption]
105         cases (aux l1' l2 (S (len l1' + len l2)));
106         cases (H1 s2 (le_n ?)); clear H1 aux;
107         exists [apply 〈mk_q_f s2 (\fst w), mk_q_f s2 (\snd w)〉] split;
108         [1: reflexivity
109         |2: assumption;
110         |4: assumption;
111         |3: intro; simplify in ⊢ (? ? ? (? ? ? (? ? ? (? % ?))));
112             rewrite > (initial_shift_same_values (mk_q_f s1 l1) s2 H input) in ⊢ (? ? % ?);
113             rewrite < (H3 input) in ⊢ (? ? ? %); reflexivity;]]
114 |1,2: unfold rest; apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
115       assumption;        
116 |8: intros; cases (?:False); apply (not_le_Sn_O ? H1);
117 |3: intros; generalize in match (unpos ??); intro X; cases X; clear X;
118     simplify in ⊢ (???? (??? (??? (??? (?? (? (?? (??? % ?) ?) ??)))) ?));
119     simplify in ⊢ (???? (???? (??? (??? (?? (? (?? (??? % ?) ?) ??)))))); 
120     clear H4; cases (aux (〈w,\snd b〉::l4) l5 n1); clear aux;
121     cut (len (〈w,\snd b〉::l4) + len l5 < n1) as K;[2:
122       simplify in H5; simplify; rewrite > sym_plus in H5; simplify in H5;
123       rewrite > sym_plus in H5; apply le_S_S_to_le; apply H5;] 
124     split;
125     [1: simplify in ⊢ (? % ?); simplify in ⊢ (? ? %); 
126         cases (H4 s K); clear K H4; intro input; cases input; [reflexivity]
127         simplify; apply H7; 
128     |2: simplify in ⊢ (? ? %); cases (H4 s K); clear H4 K H5 spec;
129         intro;
130         (* input < s + b1 || input >= s + b1 *)
131     |3: simplify in ⊢ (? ? %);]   
132 |4: intros; generalize in match (unpos ??); intro X; cases X; clear X;
133     (* duale del 3 *)
134 |5: intros; (* triviale, caso in cui non fa nulla *)
135 |6,7: (* casi base in cui allunga la lista più corta *) 
136 ]
137 elim devil;
138 qed.
139
140 include "Q/q/qtimes.ma".
141
142 let rec area (l:list bar) on l ≝
143   match l with 
144   [ nil ⇒ OQ
145   | cons he tl ⇒ area tl + Qpos (\fst he) * ⅆ[OQ,\snd he]].
146
147 alias symbol "pi1" = "exT \fst".
148 alias symbol "minus" = "Q minus".
149 alias symbol "exists" = "CProp exists".
150 definition minus_spec_bar ≝
151  λf,g,h:list bar.
152    same_bases f g → len f = len g →
153      ∀s,i:ℚ. \snd (\fst (value (mk_q_f s h) i)) = 
154        \snd (\fst (value (mk_q_f s f) i)) - \snd (\fst (value (mk_q_f s g) i)). 
155
156 definition minus_spec ≝
157  λf,g:q_f.
158    ∃h:q_f. 
159      ∀i:ℚ. \snd (\fst (value h i)) = 
160        \snd (\fst (value f i)) - \snd (\fst (value g i)). 
161
162 definition eject_bar : ∀P:list bar → CProp.(∃l:list bar.P l) → list bar ≝
163  λP.λp.match p with [ex_introT x _ ⇒ x].
164 definition inject_bar ≝ ex_introT (list bar).
165
166 coercion inject_bar with 0 1 nocomposites.
167 coercion eject_bar with 0 0 nocomposites.
168
169 lemma minus_q_f : ∀f,g. minus_spec f g.
170 intros;
171 letin aux ≝ (
172   let rec aux (l1, l2 : list bar) on l1 ≝
173     match l1 with
174     [ nil ⇒ []
175     | cons he1 tl1 ⇒
176         match l2 with
177         [ nil ⇒ []
178         | cons he2 tl2 ⇒ 〈\fst he1, \snd he1 - \snd he2〉 :: aux tl1 tl2]]
179   in aux : ∀l1,l2 : list bar.∃h.minus_spec_bar l1 l2 h);
180 [2: intros 4; simplify in H3; destruct H3;
181 |3: intros 4; simplify in H3; cases l1 in H2; [2: intro X; simplify in X; destruct X]    
182     intros; rewrite > (value_OQ_e (mk_q_f s []) i); [2: reflexivity]
183     rewrite > q_elim_minus; rewrite > q_plus_OQ; reflexivity;
184 |1: cases (aux l2 l3); unfold in H2; intros 4;
185     simplify in ⊢ (? ? (? ? ? (? ? ? (? % ?))) ?);
186     cases (q_cmp i (s + Qpos (\fst b)));
187     
188
189
190 definition excess ≝ 
191   λf,g.∃i.\snd (\fst (value f i)) < \snd (\fst (value g i)).
192