]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/dama/dama/models/q_bars.ma
Using Prop conjuction on Props lowers the universes.
[helm.git] / helm / software / matita / contribs / dama / dama / models / q_bars.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 "nat_ordered_set.ma".
16 include "models/q_support.ma".
17 include "models/list_support.ma". 
18 include "cprop_connectives.ma". 
19
20 definition bar ≝ ℚ × ℚ.
21
22 notation < "\rationals \sup 2" non associative with precedence 90 for @{'q2}.
23 interpretation "Q x Q" 'q2 = (Prod Q Q).
24
25 definition empty_bar : bar ≝ 〈Qpos one,OQ〉.
26 notation "\rect" with precedence 90 for @{'empty_bar}.
27 interpretation "q0" 'empty_bar = empty_bar.
28
29 notation < "\ldots\rect\square\EmptySmallSquare\ldots" with precedence 90 for @{'lq2}.
30 interpretation "lq2" 'lq2 = (list bar). 
31
32 definition q2_lt := mk_rel bar (λx,y:bar.\fst x < \fst y).
33
34 interpretation "bar lt" 'lt x y = (rel_op _ q2_lt x y).
35
36 lemma q2_trans : ∀a,b,c:bar. a < b → b < c → a < c.
37 intros 3; cases a; cases b; cases c; unfold q2_lt; simplify; intros;
38 apply (q_lt_trans ??? H H1);
39 qed. 
40
41 definition q2_trel := mk_trans_rel bar q2_lt q2_trans.
42
43 interpretation "bar lt" 'lt x y = (FunClass_2_OF_trans_rel q2_trel x y).
44
45 definition canonical_q_lt : rel bar → trans_rel ≝ λx:rel bar.q2_trel.
46
47 coercion canonical_q_lt with nocomposites.
48
49 interpretation "bar lt" 'lt x y = (FunClass_2_OF_trans_rel (canonical_q_lt _) x y).
50
51 definition nth_base ≝ λf,n. \fst (\nth f ▭ n).
52 definition nth_height ≝ λf,n. \snd (\nth f ▭ n).
53
54 record q_f : Type ≝ {
55  bars: list bar; 
56  bars_sorted : sorted q2_lt bars;
57  bars_begin_OQ : nth_base bars O = OQ;
58  bars_end_OQ : nth_height bars (pred (\len bars)) = OQ
59 }.
60
61 lemma len_bases_gt_O: ∀f.O < \len (bars f).
62 intros; generalize in match (bars_begin_OQ f); cases (bars f); intros;
63 [2: simplify; apply le_S_S; apply le_O_n;
64 |1: normalize in H; destruct H;]
65 qed. 
66
67 lemma all_bases_positive : ∀f:q_f.∀i. OQ < nth_base (bars f) (S i).
68 intro f; generalize in match (bars_begin_OQ f); generalize in match (bars_sorted f);
69 cases (len_gt_non_empty ?? (len_bases_gt_O f)); intros;
70 cases (cmp_nat (\len l) i);
71 [2: lapply (sorted_tail_bigger q2_lt ?? ▭ H ? H2) as K;  
72     simplify in H1; rewrite < H1; apply K;
73 |1: simplify; elim l in i H2;[simplify; rewrite > nth_nil; apply (q_pos_OQ one)]
74     cases n in H3; intros; [simplify in H3; cases (not_le_Sn_O ? H3)] 
75     apply (H2 n1); simplify in H3; apply (le_S_S_to_le ?? H3);]
76 qed.
77
78 (*
79 lemma lt_n_plus_n_Sm : ∀n,m:nat.n < n + S m.
80 intros; rewrite > sym_plus; apply (le_S_S n (m+n)); apply (le_plus_n m n); qed.
81 *)
82
83 (*
84 lemma all_bigger_can_concat_bigger:
85    ∀l1,l2,start,b,x,n.
86     (∀i.i< len l1 → nth_base l1 i < \fst b) →
87     (∀i.i< len l2 → \fst b ≤ nth_base l2 i) →
88     (∀i.i< len l1 → start ≤ i → x ≤ nth_base l1 i) →
89     start ≤ n → n < len (l1@b::l2) → x ≤ \fst b → x ≤ nth_base (l1@b::l2) n.
90 intros; cases (cmp_nat n (len l1));
91 [1: unfold nth_base;  rewrite > (nth_concat_lt_len ????? H6);
92     apply (H2 n); assumption;
93 |2: rewrite > H6; unfold nth_base; rewrite > nth_len; assumption;
94 |3: unfold nth_base; rewrite > nth_concat_ge_len; [2: apply lt_to_le; assumption]
95     rewrite > len_concat in H4; simplify in H4; rewrite < plus_n_Sm in H4;
96     lapply linear le_S_S_to_le to H4 as K; rewrite > sym_plus in K;
97     lapply linear le_plus_to_minus to K as X; 
98     generalize in match X; generalize in match (n - len l1); intro W; cases W; clear W X;
99     [intros; assumption] intros;
100     apply (q_le_trans ??? H5); apply (H1 n1); assumption;]
101 qed. 
102 *)
103
104
105 inductive value_spec (f : q_f) (i : ℚ) : ℚ → nat → CProp ≝
106  value_of : ∀q,j. 
107    nth_height (bars f) j = q →  
108    nth_base (bars f) j < i →
109    (∀n.j < n → n < \len (bars f) → i ≤ nth_base (bars f) n) → value_spec f i q j. 
110      
111      
112 inductive break_spec (T : Type) (n : nat) (l : list T) : list T → CProp ≝
113 | break_to: ∀l1,x,l2. \len l1 = n → l = l1 @ [x] @ l2 → break_spec T n l l.     
114
115 lemma list_break: ∀T,n,l. n < \len l → break_spec T n l l.
116 intros 2; elim n;
117 [1: elim l in H; [cases (not_le_Sn_O ? H)]
118     apply (break_to ?? ? [] a l1); reflexivity;
119 |2: cases (H l); [2: apply lt_S_to_lt; assumption;] cases l2 in H3; intros;
120     [1: rewrite < H2 in H1; rewrite > H3 in H1; rewrite > append_nil in H1;
121         rewrite > len_append in H1; rewrite > plus_n_SO in H1;
122         cases (not_le_Sn_n ? H1);
123     |2: apply (break_to ?? ? (l1@[x]) t l3); 
124         [2: simplify; rewrite > associative_append; assumption;
125         |1: rewrite < H2; rewrite > len_append; rewrite > plus_n_SO; reflexivity]]]
126 qed.
127
128 definition value :  ∀f:q_f.∀i:ratio.∃p:ℚ.∃j.value_spec f (Qpos i) p j.
129 intros;
130 letin P ≝ 
131   (λx:bar.match q_cmp (Qpos i) (\fst x) with[ q_leq _ ⇒ true| q_gt _ ⇒ false]);
132 exists [apply (nth_height (bars f) (pred (find ? P (bars f) ▭)));]
133 exists [apply (pred (find ? P (bars f) ▭))] apply value_of;
134 [1: reflexivity
135 |2: cases (cases_find bar P (bars f) ▭);
136     [1: cases i1 in H H1 H2 H3; simplify; intros;
137         [1: generalize in match (bars_begin_OQ f); 
138             cases (len_gt_non_empty ?? (len_bases_gt_O f)); simplify; intros;
139             rewrite > H4; apply q_pos_OQ;
140         |2: cases (len_gt_non_empty ?? (len_bases_gt_O f)) in H3;
141             intros; lapply (H3 n (le_n ?)) as K; unfold P in K;
142             cases (q_cmp (Qpos i) (\fst (\nth (x::l) ▭ n))) in K;
143             simplify; intros; [destruct H5] assumption] 
144     |2: destruct H; cases (len_gt_non_empty ?? (len_bases_gt_O f)) in H2;
145         simplify; intros; lapply (H (\len l) (le_n ?)) as K; clear H;
146         unfold P in K; cases (q_cmp (Qpos i) (\fst (\nth (x::l) ▭ (\len l)))) in K;
147         simplify; intros; [destruct H2] assumption;]     
148 |3: intro; cases (cases_find bar P (bars f) ▭); intros;
149     [1: generalize in match (bars_sorted f); 
150         cases (list_break ??? H) in H1; rewrite > H6;
151         rewrite < H1; simplify; rewrite > nth_len; unfold P; 
152         cases (q_cmp (Qpos i) (\fst x)); simplify; 
153         intros (X Hs); [2: destruct X] clear X;
154         cases (sorted_pivot q2_lt ??? ▭ Hs);
155         cut (\len l1 ≤ n) as Hn; [2:
156           rewrite > H1;  cases i1 in H4; simplify; intro X; [2: assumption]
157           apply lt_to_le; assumption;]
158         unfold nth_base; rewrite > (nth_append_ge_len ????? Hn);
159         cut (n - \len l1 < \len (x::l2)) as K; [2:
160           simplify; rewrite > H1; rewrite > (?:\len l2 = \len (bars f) - \len (l1 @ [x]));[2:
161             rewrite > H6; repeat rewrite > len_append; simplify;
162             repeat rewrite < plus_n_Sm; rewrite < plus_n_O; simplify;
163             rewrite > sym_plus; rewrite < minus_plus_m_m; reflexivity;]
164           rewrite > len_append; rewrite > H1; simplify; rewrite < plus_n_SO;
165           apply le_S_S; clear H1 H6 H7 Hs H8 H9 Hn x l2 l1 H4 H3 H2 H P i;
166           elim (\len (bars f)) in i1 n H5; [cases (not_le_Sn_O ? H);]
167           simplify; cases n2; [ repeat rewrite < minus_n_O; apply le_S_S_to_le; assumption]
168           cases n1 in H1; [intros; rewrite > eq_minus_n_m_O; apply le_O_n]
169           intros; simplify; apply H; apply le_S_S_to_le; assumption;]
170         cases (n - \len l1) in K; simplify; intros; [ assumption]
171         lapply (H9 ? (le_S_S_to_le ?? H10)) as W; apply (q_le_trans ??? H7);
172         apply q_lt_to_le; apply W;
173     |2: cases (not_le_Sn_n i1); rewrite > H in ⊢ (??%);
174         apply (trans_le ??? ? H4); cases i1 in H3; intros; apply le_S_S; 
175         [ apply le_O_n; | assumption]]]
176 qed.    
177
178 lemma value_OQ_l:
179   ∀l,i.i < start l → \snd (\fst (value l i)) = OQ.
180 intros; cases (value l i) (q Hq); cases Hq; clear Hq; simplify; cases H1; clear H1;
181 try assumption; cases H2; cases (?:False); apply (q_lt_le_incompat ?? H H6);
182 qed.
183     
184 lemma value_OQ_r:
185   ∀l,i.start l + sum_bases (bars l) (len (bars l)) ≤ i → \snd (\fst (value l i)) = OQ.
186 intros; cases (value l i) (q Hq); cases Hq; clear Hq; simplify; cases H1; clear H1;
187 try assumption; cases H2; cases (?:False); apply (q_lt_le_incompat ?? H7 H);
188 qed.
189     
190 lemma value_OQ_e:
191   ∀l,i.bars l = [] → \snd (\fst (value l i)) = OQ.
192 intros; cases (value l i) (q Hq); cases Hq; clear Hq; simplify; cases H1; clear H1;
193 try assumption; cases H2; cases (?:False); apply (H1 H);
194 qed.
195
196 inductive value_ok_spec (f : q_f) (i : ℚ) : nat × ℚ → Type ≝
197  | value_ok : ∀n,q. n ≤ (len (bars f)) → 
198       q = \snd (nth (bars f) ▭ n) →
199       sum_bases (bars f) n ≤ ⅆ[i,start f] →
200            ⅆ[i, start f] < sum_bases (bars f) (S n) → value_ok_spec f i 〈n,q〉.
201   
202 lemma value_ok:
203   ∀f,i.bars f ≠ [] → start f ≤ i → i < start f + sum_bases (bars f) (len (bars f)) → 
204     value_ok_spec f i (\fst (value f i)). 
205 intros; cases (value f i); simplify;   
206 cases H3; simplify; clear H3; cases H4; clear H4;
207 [1,2,3: cases (?:False); 
208   [1: apply (q_lt_le_incompat ?? H3 H1);
209   |2: apply (q_lt_le_incompat ?? H2 H3);
210   |3: apply (H H3);]
211 |4: cases H7; clear H7; cases w in H3 H4 H5 H6 H8; simplify; intros;
212     constructor 1; assumption;]
213 qed.
214
215 definition same_values ≝
216   λl1,l2:q_f.
217    ∀input.\snd (\fst (value l1 input)) = \snd (\fst (value l2 input)). 
218
219 definition same_bases ≝ 
220   λl1,l2:list bar. (∀i.\fst (nth l1 ▭ i) = \fst (nth l2 ▭ i)).
221
222 alias symbol "lt" = "Q less than".
223 lemma unpos: ∀x:ℚ.OQ < x → ∃r:ratio.Qpos r = x.
224 intro; cases x; intros; [2:exists [apply r] reflexivity]
225 cases (?:False);
226 [ apply (q_lt_corefl ? H)|apply (q_neg_gt ? H)]
227 qed.
228
229 notation < "x \blacksquare" non associative with precedence 50 for @{'unpos $x}.
230 interpretation "hide unpos proof" 'unpos x = (unpos x _).
231