|2: whd in ⊢ (% → ?); intro; rewrite > H8; clear H8 H4;
rewrite > H7; clear H7; rewrite > (?:\fst w1 = O); [reflexivity]
symmetry; apply le_n_O_to_eq;
- rewrite > (sum_bases_O (mk_q_f init (〈w,OQ〉::bars l1)) (\fst w1)); [apply le_n]
+ rewrite > (sum_bases_O (〈w,OQ〉::bars l1) (\fst w1)); [apply le_n]
clear H6 w2; simplify in H5:(? ? (? ? %));
destruct H3; rewrite > q_d_x_x in H5; assumption;]
|2: intros; cases (value l1 input); simplify in ⊢ (? ? (? ? ? %) ?);
simplify in ⊢ (? ? ? (? ? ? (? ? % ? ?)));
cut (\fst w1 = S (\fst w2)) as Key; [rewrite > Key; reflexivity;]
cut (\fst w2 = O); [2: clear H10;
- symmetry; apply le_n_O_to_eq; rewrite > (sum_bases_O l1 (\fst w2)); [apply le_n]
+ symmetry; apply le_n_O_to_eq; rewrite > (sum_bases_O (bars l1) (\fst w2)); [apply le_n]
apply (q_le_trans ??? H9); rewrite < H4; rewrite > q_d_x_x;
apply q_eq_to_le; reflexivity;]
rewrite > Hcut; clear Hcut H10 H9; simplify in H5 H6;
axiom nth_nil: ∀T,n.∀d:T. nth [] d n = d.
+
+lemma case1 :
+ ∀init,st,input,l.
+ init<st → st<input →
+ ⅆ[input,init] < sum_bases l O + (st-init) → False.
+intros 6; rewrite > q_d_sym; rewrite > q_d_noabs; [2:
+ apply (q_le_trans ? st); apply q_lt_to_le; assumption]
+do 2 rewrite > q_elim_minus; rewrite > q_plus_assoc;
+intro X; lapply (q_lt_canc_plus_r ??? X) as Y;
+simplify in Y; cases (?:False);
+apply (q_lt_corefl st); apply (q_lt_trans ??? H1);
+apply (q_lt_le_trans ??? Y); rewrite > q_plus_sym; rewrite > q_plus_OQ;
+apply q_eq_to_le; reflexivity;
+qed.
+
+lemma case2:
+ ∀a,l1,init,st,input,n.
+ init < st → st < input →
+ sum_bases (a::l1) n + (st-init) ≤ ⅆ[input,init] →
+ ⅆ[input,st] < sum_bases l1 O + Qpos (\fst a) →
+ n = O.
+intros; cut (input - st < Qpos (\fst a)) as H6';[2:
+ rewrite < q_d_noabs;[2:apply q_lt_to_le; assumption]
+ rewrite > q_d_sym; apply (q_lt_le_trans ??? H3);
+ rewrite > q_plus_sym; rewrite > q_plus_OQ;
+ apply q_eq_to_le; reflexivity] clear H3;
+generalize in match H2; rewrite > q_d_sym; rewrite > q_d_noabs;
+ [2: apply (q_le_trans ? st); apply q_lt_to_le; assumption]
+do 2 rewrite > q_elim_minus; rewrite > q_plus_assoc; intro X;
+lapply (q_le_canc_plus_r ??? X) as Y; clear X;
+lapply (q_le_inj_plus_r ?? (Qopp st) Y) as X; clear Y;
+cut (input + Qopp st < Qpos (\fst a)) as H6'';
+ [2: rewrite < q_elim_minus; assumption;] clear H6';
+generalize in match (q_le_lt_trans ??? X H6''); clear X H6'';
+rewrite < q_plus_assoc; rewrite < q_elim_minus;
+rewrite > q_plus_minus; rewrite > q_plus_OQ; cases n; intro X; [reflexivity]
+cases (?:False);
+apply (q_lt_le_incompat (sum_bases l1 n1) OQ);[2: apply sum_bases_ge_OQ;]
+apply (q_lt_canc_plus_r ?? (Qpos (\fst a)));
+rewrite >(q_plus_sym OQ); rewrite > q_plus_OQ; apply X;
+qed.
+
+lemma case3:
+ ∀init,st,input,l1,a,n.
+ init<st → st<input →
+ ⅆ[input,init]<OQ+Qpos a+(st-init) →
+ sum_bases l1 n+Qpos a≤ⅆ[input,st] → False.
+intros;
+cut (sum_bases l1 n - ⅆ[input,st] < Qopp ⅆ[input,init] + (st - init)); [2:
+ cut (sum_bases l1 n≤ⅆ[input,st]-Qpos a) as H7';[2:
+ apply (q_le_canc_plus_r ?? (Qpos a));
+ apply (q_le_trans ??? H3); rewrite > q_elim_minus;
+ rewrite < q_plus_assoc; rewrite > (q_plus_sym (Qopp ?));
+ rewrite < q_elim_minus; rewrite > q_plus_minus; rewrite > q_plus_OQ;
+ apply q_eq_to_le; reflexivity;] clear H3;
+ rewrite > q_elim_minus; apply (q_lt_canc_plus_r ?? ⅆ[input,st]);
+ rewrite < q_plus_assoc; rewrite > (q_plus_sym (Qopp ?));
+ rewrite < q_elim_minus; rewrite > q_plus_minus; rewrite > q_plus_OQ;
+ apply (q_le_lt_trans ??? H7'); clear H7'; rewrite > q_elim_minus;
+ rewrite > q_plus_sym; apply q_lt_inj_plus_r;
+ rewrite > q_plus_sym; apply q_lt_plus; rewrite > q_elim_opp;
+ rewrite > q_plus_sym; apply (q_lt_canc_plus_r ?? (Qpos a));
+ rewrite < q_plus_assoc; rewrite > (q_plus_sym (Qopp ?));
+ rewrite < q_elim_minus; rewrite > q_plus_minus; rewrite > q_plus_OQ;
+ apply (q_lt_le_trans ??? H2); rewrite > (q_plus_sym OQ); rewrite > q_plus_OQ;
+ rewrite > q_plus_sym; apply q_eq_to_le; reflexivity;]
+generalize in match Hcut; clear H2 H3 Hcut;
+rewrite > q_d_sym; rewrite > q_d_noabs; [2:apply q_lt_to_le; assumption]
+rewrite > q_d_sym; rewrite > q_d_noabs; [2: apply (q_le_trans ? st); apply q_lt_to_le; assumption]
+rewrite < q_plus_sym; rewrite < q_elim_minus;
+rewrite > (q_elim_minus input init);
+rewrite > q_minus_distrib; rewrite > q_elim_opp;
+rewrite > (q_elim_minus input st);
+rewrite > q_minus_distrib; rewrite > q_elim_opp;
+repeat rewrite > q_elim_minus;
+rewrite < q_plus_assoc in ⊢ (??% → ?);
+rewrite > (q_plus_sym (Qopp input) init);
+rewrite > q_plus_assoc;
+rewrite < q_plus_assoc in ⊢ (??(?%?) → ?);
+rewrite > (q_plus_sym (Qopp init) init);
+rewrite < (q_elim_minus init); rewrite >q_plus_minus;
+rewrite > q_plus_OQ; rewrite > (q_plus_sym st);
+rewrite < q_plus_assoc;
+rewrite < (q_plus_OQ (Qopp input + st)) in ⊢ (??% → ?);
+rewrite > (q_plus_sym ? OQ); intro X;
+lapply (q_lt_canc_plus_r ??? X) as Y; clear X;
+apply (q_lt_le_incompat ?? Y); apply sum_bases_ge_OQ;
+qed.
+
lemma key:
∀init,input,l1,w1,w2,w.
Qpos w = start l1 - init →
sum_bases (bars l1) w2 ≤ ⅆ[input,start l1] →
ⅆ[input,start l1] < sum_bases (bars l1) (S w2) →
\snd (nth (bars l1) ▭ w2) = \snd (nth (〈w,OQ〉::bars l1) ▭ w1).
-intros 4 (init input l); cases l (st l);
+intros 3 (init input l); cases l (st l);
change in match (start (mk_q_f st l)) with st;
change in match (bars (mk_q_f st l)) with l;
-elim l;
+elim l; clear l;
[1: rewrite > nth_nil; cases w1 in H4;
- [1: rewrite > q_d_sym; rewrite > q_d_noabs; [2:
- apply (q_le_trans ? st); apply q_lt_to_le; assumption]
- do 2 rewrite > q_elim_minus; rewrite > q_plus_assoc;
- intro X; lapply (q_lt_canc_plus_r ??? X) as Y;
- simplify in Y; cases (?:False);
- apply (q_lt_corefl st); apply (q_lt_trans ??? H2);
- apply (q_lt_le_trans ??? Y); rewrite > q_plus_sym; rewrite > q_plus_OQ;
- apply q_eq_to_le; reflexivity;
+ [1: intro X; cases (case1 ?????? X); assumption;
|2: intros; simplify; rewrite > nth_nil; reflexivity;]
-|2: FACTORIZE w1>0
-
- (* interesting case: init < start < input *)
- intro; cases H8; clear H8; rewrite > H11; rewrite > H7; clear H11 H7;
- simplify in H5 H6 ⊢ (? ? ? (? ? ? (? ? % ? ?)));
- elim (\fst w2) in H9 H10;
- [1: elim (\fst w1) in H5 H6;
- [1: cases (?:False); clear H5 H8 H7;
- apply (q_lt_antisym input (start l1)); [2: assumption]
- rewrite > q_d_sym in H6; rewrite > q_d_noabs in H6;
- [2: apply q_lt_to_le; assumption]
- rewrite > q_plus_sym in H6; rewrite > q_plus_OQ in H6;
- rewrite > H2 in H6; apply (q_lt_canc_plus_r ?? (Qopp init));
- do 2 rewrite < q_elim_minus; assumption;
- |2:
-
- cut (\fst w1 = S (\fst w2)) as Key; [rewrite > Key; reflexivity;]
- cases (\fst w1) in H5 H6; intros; [1:
- cases (?:False); clear H5 H9 H10;
- apply (q_lt_antisym input (start l1)); [2: assumption]
- rewrite > q_d_sym in H6; rewrite > q_d_noabs in H6;
- [2: apply q_lt_to_le; assumption]
- rewrite > q_plus_sym in H6; rewrite > q_plus_OQ in H6;
- rewrite > H2 in H6; apply (q_lt_canc_plus_r ?? (Qopp init));
- do 2 rewrite < q_elim_minus; assumption;]
- apply eq_f;
- cut (sum_bases (bars l1) (\fst w2) < sum_bases (bars l1) (S n));[2:
- apply (q_le_lt_trans ??? H9);
- apply (q_lt_trans ??? ? H6);
- rewrite > q_d_sym; rewrite > q_d_noabs; [2:apply q_lt_to_le;assumption]
- rewrite > q_d_sym; rewrite > q_d_noabs; [2:apply q_lt_to_le;assumption]
- do 2 rewrite > q_elim_minus; rewrite > (q_plus_sym ? (Qopp init));
- apply q_lt_plus; rewrite > q_plus_sym;
- rewrite > q_elim_minus; rewrite < q_plus_assoc;
- rewrite < q_elim_minus; rewrite > q_plus_minus;
- rewrite > q_plus_OQ; apply q_lt_opp_opp; assumption]
- clear H9 H6;
- cut (ⅆ[input,init] - Qpos w = ⅆ[input,start l1]);[2:
- rewrite > q_d_sym; rewrite > q_d_noabs; [2:apply q_lt_to_le;assumption]
- rewrite > q_d_sym; rewrite > q_d_noabs; [2:apply q_lt_to_le;assumption]
- rewrite > H2; rewrite > (q_elim_minus (start ?));
- rewrite > q_minus_distrib; rewrite > q_elim_opp;
- do 2 rewrite > q_elim_minus;
- do 2 rewrite < q_plus_assoc;
- rewrite > (q_plus_sym ? init);
- rewrite > (q_plus_assoc ? init);
- rewrite > (q_plus_sym ? init);
- rewrite < (q_elim_minus init); rewrite > q_plus_minus;
- rewrite > (q_plus_sym OQ); rewrite > q_plus_OQ;
- rewrite < q_elim_minus; reflexivity;]
- cut (sum_bases (bars l1) n < sum_bases (bars l1) (S (\fst w2)));[2:
- apply (q_le_lt_trans ???? H10); rewrite < Hcut1;
- rewrite > q_elim_minus; apply q_le_minus_r; rewrite > q_elim_opp;
- assumption;] clear Hcut1 H5 H10;
- generalize in match Hcut;generalize in match Hcut2;clear Hcut Hcut2;
- apply (nat_elim2 ???? n (\fst w2));
- [3: intros (x y); apply eq_f; apply H5; clear H5;
- [1: clear H7; apply sum_bases_lt_canc; assumption;
- |2: clear H6; ]
- |2: intros; cases (?:False); clear H6;
- cases n1 in H5; intro;
- [1: apply (q_lt_corefl ? H5);
- |2: cases (bars l1) in H5; intro;
- [1: simplify in H5;
- apply (q_lt_le_incompat ?? (q_lt_canc_plus_r ??? H5));
- apply q_le_plus_trans; [apply sum_bases_ge_OQ]
- apply q_le_OQ_Qpos;
- |2: simplify in H5:(??%);
- lapply (q_lt_canc_plus_r (sum_bases l (S n2)) ?? H5) as X;
- apply (q_lt_le_incompat ?? X); apply sum_bases_ge_OQ]]
- |1: intro; cases n1 [intros; reflexivity] intros; cases (?:False);
- elim n2 in H5 H6;
-
-
- elim (bars l1) 0;
- [1: intro; elim n1; [reflexivity] cases (?:False);
-
-
- intros; clear H5;
- elim n1 in H6; [reflexivity] cases (?:False);
- [1: apply (q_lt_corefl ? H5);
- |2: cases (bars l1) in H5; intro;
- [1: simplify in H5;
- apply (q_lt_le_incompat ?? (q_lt_canc_plus_r ??? H5));
- apply q_le_plus_trans; [apply sum_bases_ge_OQ]
- apply q_le_OQ_Qpos;
- |2: simplify in H5:(??%);
- lapply (q_lt_canc_plus_r (sum_bases l (S n2)) ?? H5) as X;
- apply (q_lt_le_incompat ?? X); apply sum_bases_ge_OQ]]
+|2: cases w1 in H4 H5; clear w1;
+ [1: intros (Y X); cases (case1 ?????? X); assumption;
+ |2: intros; simplify in H4 H5 H7 ⊢ %;
+ generalize in match H6; generalize in match H7;
+ generalize in match H4; generalize in match H5; clear H4 H5 H6 H7;
+ apply (nat_elim2 ???? w2 n); clear w2 n; intros;
+ [1: rewrite > (case2 a l1 init st input n); [reflexivity]
+ try rewrite < H1; assumption;
+ |2: simplify in H4 H7; cases (case3 ???????? H4 H7); assumption;
+ |3: (* dipende se vanno oltre la lunghezza di l1,
+ forse dovevo gestire il caso prima dell'induzione *)
+ simplify in ⊢ (? ? (? ? ? %) ?);
+ rewrite > (H (S m) ? w); [reflexivity] try assumption;
+STOP
+
qed.