X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fmatita%2Fcontribs%2Fdama%2Fdama%2Fmodels%2Fq_bars.ma;h=65066590f4baef3f754305ba709df1353d149bae;hb=591ffe6f23ec9d2a4d368d2c1e7b213986189e44;hp=2aae66a5bc05555ac2f5e7bee7703a26d739ea57;hpb=d34d7101ba59a19fa030fe9a5c6b3d563efc8f3d;p=helm.git diff --git a/helm/software/matita/contribs/dama/dama/models/q_bars.ma b/helm/software/matita/contribs/dama/dama/models/q_bars.ma index 2aae66a5b..65066590f 100644 --- a/helm/software/matita/contribs/dama/dama/models/q_bars.ma +++ b/helm/software/matita/contribs/dama/dama/models/q_bars.ma @@ -14,7 +14,7 @@ include "nat_ordered_set.ma". include "models/q_support.ma". -include "models/list_support.ma". +include "models/list_support.ma". include "cprop_connectives.ma". definition bar â â à â. @@ -29,146 +29,151 @@ interpretation "q0" 'empty_bar = empty_bar. notation < "\ldots\rect\square\EmptySmallSquare\ldots" with precedence 90 for @{'lq2}. interpretation "lq2" 'lq2 = (list bar). -inductive sorted : list bar â Prop â -| sorted_nil : sorted [] -| sorted_one : âx. sorted [x] -| sorted_cons : âx,y,tl. \fst x < \fst y â sorted (y::tl) â sorted (x::y::tl). +definition q2_lt := mk_rel bar (λx,y:bar.\fst x < \fst y). -definition nth_base â λf,n. \fst (nth f â n). -definition nth_height â λf,n. \snd (nth f â n). +interpretation "bar lt" 'lt x y = (rel_op _ q2_lt x y). + +lemma q2_trans : âa,b,c:bar. a < b â b < c â a < c. +intros 3; cases a; cases b; cases c; unfold q2_lt; simplify; intros; +apply (q_lt_trans ??? H H1); +qed. + +definition q2_trel := mk_trans_rel bar q2_lt q2_trans. + +interpretation "bar lt" 'lt x y = (FunClass_2_OF_trans_rel q2_trel x y). + +definition canonical_q_lt : rel bar â trans_rel â λx:rel bar.q2_trel. + +coercion canonical_q_lt with nocomposites. + +interpretation "bar lt" 'lt x y = (FunClass_2_OF_trans_rel (canonical_q_lt _) x y). + +definition nth_base â λf,n. \fst (\nth f â n). +definition nth_height â λf,n. \snd (\nth f â n). record q_f : Type â { bars: list bar; - increasing_bars : sorted bars; + bars_sorted : sorted q2_lt bars; bars_begin_OQ : nth_base bars O = OQ; - bars_tail_OQ : nth_height bars (pred (len bars)) = OQ + bars_end_OQ : nth_height bars (pred (\len bars)) = OQ }. -lemma nth_nil: âT,i.âdef:T. nth [] def i = def. -intros; elim i; simplify; [reflexivity;] assumption; qed. - -lemma all_bases_positives : âf:q_f.âi.i < len (bars f) â OQ < nth_base (bars f) i. -intro f; elim (increasing_bars f); -[1: unfold nth_base; rewrite > nth_nil; apply (q_pos_OQ one); -|2: cases i in H; [2: cases (?:False); +lemma len_bases_gt_O: âf.O < \len (bars f). +intros; generalize in match (bars_begin_OQ f); cases (bars f); intros; +[2: simplify; apply le_S_S; apply le_O_n; +|1: normalize in H; destruct H;] +qed. + +lemma all_bases_positive : âf:q_f.âi. OQ < nth_base (bars f) (S i). +intro f; generalize in match (bars_begin_OQ f); generalize in match (bars_sorted f); +cases (len_gt_non_empty ?? (len_bases_gt_O f)); intros; +cases (cmp_nat (\len l) i); +[2: lapply (sorted_tail_bigger q2_lt ?? â H ? H2) as K; + simplify in H1; rewrite < H1; apply K; +|1: simplify; elim l in i H2;[simplify; rewrite > nth_nil; apply (q_pos_OQ one)] + cases n in H3; intros; [simplify in H3; cases (not_le_Sn_O ? H3)] + apply (H2 n1); simplify in H3; apply (le_S_S_to_le ?? H3);] qed. -definition eject_Q â - λP.λp:âx:â.P x.match p with [ex_introT p _ â p]. -coercion eject_Q. -definition inject_Q â λP.λp:â.λh:P p. ex_introT ? P p h. -coercion inject_Q with 0 1 nocomposites. - -definition value_spec : q_f â â â â â Prop â - λf,i,q. - âj. q = nth_height (bars f) j ⧠- (nth_base (bars f) j < i ⧠- ân.j < n â n < len (bars f) â i ⤠nth_base (bars f) n). +(* +lemma lt_n_plus_n_Sm : ân,m:nat.n < n + S m. +intros; rewrite > sym_plus; apply (le_S_S n (m+n)); apply (le_plus_n m n); qed. +*) + +(* +lemma all_bigger_can_concat_bigger: + âl1,l2,start,b,x,n. + (âi.i< len l1 â nth_base l1 i < \fst b) â + (âi.i< len l2 â \fst b ⤠nth_base l2 i) â + (âi.i< len l1 â start ⤠i â x ⤠nth_base l1 i) â + start ⤠n â n < len (l1@b::l2) â x ⤠\fst b â x ⤠nth_base (l1@b::l2) n. +intros; cases (cmp_nat n (len l1)); +[1: unfold nth_base; rewrite > (nth_concat_lt_len ????? H6); + apply (H2 n); assumption; +|2: rewrite > H6; unfold nth_base; rewrite > nth_len; assumption; +|3: unfold nth_base; rewrite > nth_concat_ge_len; [2: apply lt_to_le; assumption] + rewrite > len_concat in H4; simplify in H4; rewrite < plus_n_Sm in H4; + lapply linear le_S_S_to_le to H4 as K; rewrite > sym_plus in K; + lapply linear le_plus_to_minus to K as X; + generalize in match X; generalize in match (n - len l1); intro W; cases W; clear W X; + [intros; assumption] intros; + apply (q_le_trans ??? H5); apply (H1 n1); assumption;] +qed. +*) + + +inductive value_spec (f : q_f) (i : â) : â â nat â CProp â + value_of : âq,j. + nth_height (bars f) j = q â + nth_base (bars f) j < i â + (ân.j < n â n < \len (bars f) â i ⤠nth_base (bars f) n) â value_spec f i q j. + + +inductive break_spec (T : Type) (n : nat) (l : list T) : list T â CProp â +| break_to: âl1,x,l2. \len l1 = n â l = l1 @ [x] @ l2 â break_spec T n l l. + +lemma list_break: âT,n,l. n < \len l â break_spec T n l l. +intros 2; elim n; +[1: elim l in H; [cases (not_le_Sn_O ? H)] + apply (break_to ?? ? [] a l1); reflexivity; +|2: cases (H l); [2: apply lt_S_to_lt; assumption;] cases l2 in H3; intros; + [1: rewrite < H2 in H1; rewrite > H3 in H1; rewrite > append_nil in H1; + rewrite > len_append in H1; rewrite > plus_n_SO in H1; + cases (not_le_Sn_n ? H1); + |2: apply (break_to ?? ? (l1@[x]) t l3); + [2: simplify; rewrite > associative_append; assumption; + |1: rewrite < H2; rewrite > len_append; rewrite > plus_n_SO; reflexivity]]] +qed. -definition value : âf:q_f.âi:ratio.âp:â.value_spec f (Qpos i) p. +definition value : âf:q_f.âi:ratio.âp:â.âj.value_spec f (Qpos i) p j. intros; -alias symbol "lt" (instance 5) = "Q less than". -alias symbol "leq" = "Q less or equal than". -letin value_spec_aux â ( - λf,i,q.âj. q = nth_height f j ⧠- (nth_base f j < i ⧠ân.j < n â n < len f â i ⤠nth_base f n)); -letin value â ( - let rec value (acc: â) (l : list bar) on l : â â - match l with - [ nil â acc - | cons x tl â - match q_cmp (\fst x) (Qpos i) with - [ q_leq _ â value (\snd x) tl - | q_gt _ â acc]] - in value : - âacc,l.âp:â. OQ ⤠acc â value_spec_aux l (Qpos i) p); -[4: clearbody value; cases (value OQ (bars f)) (p Hp); exists[apply p]; - cases (Hp (q_le_n ?)) (j Hj); cases Hj (Hjp H); cases H (Hin Hmax); - clear Hp value value_spec_aux Hj H; exists [apply j]; split[2:split;intros;] - try apply Hmax; assumption; -|1: intro Hacc; clear H2; cases (value (\snd b) l1) (j Hj); - cases (q_cmp (\snd b) (Qpos i)) (Hib Hib); - [1: cases (Hj Hib) (w Hw); simplify in ⢠(? ? ? %); clear Hib Hj; - exists [apply (S w)] cases Hw; cases H3; clear Hw H3; - split; try assumption; split; try assumption; intros; - apply (q_le_trans ??? (H5 (pred n) ??)); [3: apply q_le_n] - - - - -[5: clearbody value; - cases (q_cmp i (start f)); - [2: exists [apply â©O,OQâª] simplify; constructor 1; split; try assumption; - try reflexivity; apply q_lt_to_le; assumption; - |1: cases (bars f); [exists [apply â©O,OQâª] simplify; constructor 3; split;try assumption;reflexivity;] - cases (value â [i,start f] (b::l)) (p Hp); - cases (Hp (q_dist_ge_OQ ? ?)); clear Hp value; [cases H1; destruct H2] - cases H1; clear H1; lapply (sum_bases_O (b::l) (\fst p)) as H1; - [2: apply (q_le_trans ??? H2); rewrite > H; apply q_eq_to_le; - rewrite > q_d_x_x; reflexivity; - |1: exists [apply p] simplify; constructor 4; rewrite > H1; split; - try split; try rewrite > q_d_x_x; try autobatch depth=2; - [1: rewrite > H; rewrite > q_plus_sym; apply q_lt_plus; - rewrite > q_plus_minus; apply q_lt_plus_trans; [apply sum_bases_ge_OQ] - apply q_pos_lt_OQ; - |2: rewrite > H; rewrite > q_d_x_x; apply q_eq_to_le; reflexivity; - |3: rewrite > H; rewrite > q_d_x_x; apply q_lt_plus_trans; - try apply sum_bases_ge_OQ; apply q_pos_lt_OQ;]] - |3: cases (q_cmp i (start f+sum_bases (bars f) (len (bars f)))); - [1: exists [apply â©O,OQâª] simplify; constructor 2; split; try assumption; - try reflexivity; rewrite > H1; apply q_eq_to_le; reflexivity; - |3: exists [apply â©O,OQâª] simplify; constructor 2; split; try assumption; - try reflexivity; apply q_lt_to_le; assumption; - |2: generalize in match (refl_eq ? (bars f): bars f = bars f); - generalize in match (bars f) in ⢠(??? % â %); intro X; cases X; clear X; - intros; - [1: exists [apply â©O,OQâª] simplify; constructor 3; split; reflexivity; - |2: cases (value â [i,start f] (b::l)) (p Hp); - cases (Hp (q_dist_ge_OQ ? ?)); clear Hp value; [cases H3;destruct H4] - cases H3; clear H3; - exists [apply p]; constructor 4; split; try split; try assumption; - [1: intro X; destruct X; - |2: apply q_lt_to_le; assumption; - |3: rewrite < H2; assumption; - |4: cases (cmp_nat (\fst p) (len (bars f))); - [1:apply lt_to_le;rewrite