]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/contribs/dama/dama/models/q_function.ma
shifting done, merge attacked
[helm.git] / helm / software / matita / contribs / dama / dama / models / q_function.ma
index df368bf9065b169e76bf598163fcdf6201b7e39d..e2187b51014799aed94ac412bef1ac57f24056d9 100644 (file)
 (*                                                                        *)
 (**************************************************************************)
 
-include "Q/q/q.ma".
-include "list/list.ma".
-include "cprop_connectives.ma". 
-
-notation "\rationals" non associative with precedence 99 for @{'q}.
-interpretation "Q" 'q = Q. 
-
-record q_f : Type ≝ {
- start : ℚ;
- bars: list (ℚ × ℚ) (* base, height *)
-}.
-
-axiom qp : ℚ → ℚ → ℚ.
-
-interpretation "Q plus" 'plus x y = (qp x y).
-
-axiom qm : ℚ → ℚ → ℚ.
-
-interpretation "Q minus" 'minus x y = (qm x y).
-
-axiom qlt : ℚ → ℚ → CProp.
-
-interpretation "Q less than" 'lt x y = (qlt x y).
-
-inductive q_comparison (a,b:ℚ) : CProp ≝
- | q_eq : a = b → q_comparison a b 
- | q_lt : a < b → q_comparison a b
- | q_gt : b < a → q_comparison a b.
-
-axiom q_cmp:∀a,b:ℚ.q_comparison a b.
-
-definition qle ≝ λa,b:ℚ.a = b ∨ a < b.
-
-interpretation "Q less or equal than" 'le x y = (qle x y).
-
-notation "'nth'" left associative with precedence 70 for @{'nth}.
-notation < "\nth \nbsp l \nbsp d \nbsp i" left associative with precedence 70 for @{'nth_appl $l $d $i}.
-interpretation "list nth" 'nth = (cic:/matita/list/list/nth.con _).
-interpretation "list nth" 'nth_appl l d i = (cic:/matita/list/list/nth.con _ l d i).
-
-notation < "\rationals \sup 2" non associative with precedence 40 for @{'q2}.
-interpretation "Q x Q" 'q2 = (product Q Q).
-
-let rec mk_list (A:Type) (def:nat→A) (n:nat) on n ≝
-  match n with
-  [ O ⇒ []
-  | S m ⇒ def m :: mk_list A def m].
-
-interpretation "mk_list appl" 'mk_list f n = (mk_list f n).
-interpretation "mk_list" 'mk_list = mk_list.   
-notation < "\mk_list \nbsp f \nbsp n" left associative with precedence 70 for @{'mk_list_appl $f $n}.
-notation "'mk_list'" left associative with precedence 70 for @{'mk_list}.
-
-alias symbol "pair" = "pair".
-definition q00 : ℚ × ℚ ≝ 〈OQ,OQ〉.
+include "nat_ordered_set.ma".
+include "models/q_shift.ma".
 
 alias symbol "pi2" = "pair pi2".
 alias symbol "pi1" = "pair pi1".
-alias symbol "pair" = "pair".
-definition rebase: 
-  q_f → q_f → 
-    ∃p:q_f × q_f.∀i.
-     fst (nth (bars (fst p)) q00 i) = 
-     fst (nth (bars (snd p)) q00 i).   
-intros (f1 f2); cases f1 (s1 l1); cases f2 (s2 l2); clear f1 f2;
-letin aux ≝ (
-let rec aux (l1,l2:list (ℚ × ℚ)) on l1 : (list (ℚ × ℚ)) × (list (ℚ × ℚ)) ≝
+definition rebase_spec ≝ 
+ ∀l1,l2:q_f.∃p:q_f × q_f.
+   And4
+    (*len (bars (\fst p)) = len (bars (\snd p))*)
+    (start (\fst p) = start (\snd p))
+    (same_bases (\fst p) (\snd p))
+    (same_values l1 (\fst p)) 
+    (same_values l2 (\snd p)).
+
+definition rebase_spec_simpl ≝ 
+ λstart.λl1,l2:list bar.λp:(list bar) × (list bar).
+   And3
+    (same_bases (mk_q_f start (\fst p)) (mk_q_f start (\snd p)))
+    (same_values (mk_q_f start l1) (mk_q_f start (\fst p))) 
+    (same_values (mk_q_f start l2) (mk_q_f start (\snd p))).
+
+(* a local letin makes russell fail *)
+definition cb0h : list bar → list bar ≝ 
+  λl.mk_list (λi.〈\fst (nth l ▭ i),OQ〉) (len l).
+
+definition eject ≝
+  λP.λp:∃x:(list bar) × (list bar).P x.match p with [ex_introT p _ ⇒ p].
+coercion eject.
+definition inject ≝ λP.λp:(list bar) × (list bar).λh:P p. ex_introT ? P p h.
+coercion inject with 0 1 nocomposites.
+        
+definition rebase: rebase_spec.
+intros 2 (f1 f2); cases f1 (s1 l1); cases f2 (s2 l2); clear f1 f2;
+letin spec ≝ (
+  λs.λl1,l2.λm.λz.len l1 + len l2 < m → rebase_spec_simpl s l1 l2 z);
+alias symbol "pi1" (instance 34) = "exT \fst".
+alias symbol "pi1" (instance 21) = "exT \fst".
+letin aux ≝ ( 
+let rec aux (l1,l2:list bar) (n:nat) on n : (list bar) × (list bar) ≝
+match n with
+[ O ⇒ 〈 nil ? , nil ? 〉
+| S m ⇒ 
   match l1 with
-  [ nil ⇒ 〈mk_list (λi.〈fst (nth l2 q00 i),OQ〉) (length ? l2),l2〉
-  | cons he tl ⇒ 〈[],[]〉] in aux); 
-  
-cases (q_cmp s1 s2);
-[1: apply (mk_q_f s1);
-|2: apply (mk_q_f s1); cases l2;
-    [1: letin l2' ≝ (
-[1: (* offset: the smallest one *)
-    cases 
+  [ nil ⇒ 〈cb0h l2, l2〉
+  | cons he1 tl1 ⇒
+     match l2 with
+     [ nil ⇒ 〈l1, cb0h l1〉
+     | cons he2 tl2 ⇒  
+         let base1 ≝ Qpos (\fst he1) in
+         let base2 ≝ Qpos (\fst he2) in
+         let height1 ≝ (\snd he1) in
+         let height2 ≝ (\snd he2) in
+         match q_cmp base1 base2 with
+         [ q_eq _ ⇒ 
+             let rc ≝ aux tl1 tl2 m in 
+             〈he1 :: \fst rc,he2 :: \snd rc〉 
+         | q_lt Hp ⇒
+             let rest ≝ base2 - base1 in
+             let rc ≝ aux tl1 (〈\fst (unpos rest ?),height2〉 :: tl2) m in
+             〈〈\fst he1,height1〉 :: \fst rc,〈\fst he1,height2〉 :: \snd rc〉 
+         | q_gt Hp ⇒ 
+             let rest ≝ base1 - base2 in
+             let rc ≝ aux (〈\fst (unpos rest ?),height1〉 :: tl1) tl2 m in
+             〈〈\fst he2,height1〉 :: \fst rc,〈\fst he2,height2〉 :: \snd rc〉
+]]]]
+in aux : ∀l1,l2,m.∃z.∀s.spec s l1 l2 m z); unfold spec;
+[9: clearbody aux; unfold spec in aux; clear spec;
+    cases (q_cmp s1 s2);
+    [1: cases (aux l1 l2 (S (len l1 + len l2)));
+        cases (H1 s1 (le_n ?)); clear H1;
+        exists [apply 〈mk_q_f s1 (\fst w), mk_q_f s2 (\snd w)〉] split;
+        [1,2: assumption;
+        |3: intro; apply (H3 input);
+        |4: intro; rewrite > H in H4; 
+            rewrite > (H4 input); reflexivity;]
+    |2: letin l2' ≝ (〈\fst (unpos (s2-s1) ?),OQ〉::l2);[
+          apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
+          assumption]
+        cases (aux l1 l2' (S (len l1 + len l2')));
+        cases (H1 s1 (le_n ?)); clear H1 aux;
+        exists [apply 〈mk_q_f s1 (\fst w), mk_q_f s1 (\snd w)〉] split;
+        [1: reflexivity
+        |2: assumption;
+        |3: assumption;
+        |4: intro; rewrite > (initial_shift_same_values (mk_q_f s2 l2) s1 H input);
+            rewrite < (H4 input); reflexivity;]
+    |3: letin l1' ≝ (〈\fst (unpos (s1-s2) ?),OQ〉::l1);[
+          apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
+          assumption]
+        cases (aux l1' l2 (S (len l1' + len l2)));
+        cases (H1 s2 (le_n ?)); clear H1 aux;
+        exists [apply 〈mk_q_f s2 (\fst w), mk_q_f s2 (\snd w)〉] split;
+        [1: reflexivity
+        |2: assumption;
+        |4: assumption;
+        |3: intro; rewrite > (initial_shift_same_values (mk_q_f s1 l1) s2 H input);
+            rewrite < (H3 input); reflexivity;]]
+|1,2: unfold rest; apply q_lt_minus; rewrite > q_plus_sym; rewrite > q_plus_OQ;
+      assumption;        
+|8: intros; cases (?:False); apply (not_le_Sn_O ? H1);
+|3: intros; generalize in match (unpos ??); intro X; cases X; clear X;
+    simplify in ⊢ (???? (??? (??? (??? (?? (? (?? (??? % ?) ?) ??)))) ?));
+    simplify in ⊢ (???? (???? (??? (??? (?? (? (?? (??? % ?) ?) ??)))))); 
+    clear H4; cases (aux (〈w,\snd b〉::l4) l5 n1); clear aux;
+    cut (len (〈w,\snd b〉::l4) + len l5 < n1) as K;[2:
+      simplify in H5; simplify; rewrite > sym_plus in H5; simplify in H5;
+      rewrite > sym_plus in H5; apply le_S_S_to_le; apply H5;] 
+    split;
+    [1: simplify in ⊢ (? % ?); simplify in ⊢ (? ? %); 
+        cases (H4 s K); clear K H4; intro input; cases input; [reflexivity]
+        simplify; apply H7; 
+    |2: simplify in ⊢ (? ? %); cases (H4 s K); clear H4 K H5 spec;
+        intro; 
+        (* input < s + b1 || input >= s + b1 *)
+    |3: simplify in ⊢ (? ? %);]   
+|4: intros; generalize in match (unpos ??); intro X; cases X; clear X;
+    (* duale del 3 *)
+|5: intros; (* triviale, caso in cui non fa nulla *)
+|6,7: (* casi base in cui allunga la lista più corta *) 
+]
+qed.