apply (H2 n1); simplify in H3; apply (le_S_S_to_le ?? H3);]
qed.
+alias symbol "lt" (instance 9) = "Q less than".
+alias symbol "lt" (instance 7) = "natural 'less than'".
+alias symbol "lt" (instance 6) = "natural 'less than'".
alias symbol "lt" (instance 5) = "Q less than".
alias symbol "lt" (instance 4) = "natural 'less than'".
alias symbol "lt" (instance 2) = "natural 'less than'".
alias symbol "leq" = "Q less or equal than".
-alias symbol "Q" = "Rationals".
-coinductive value_spec (f : q_f) (i : ℚ) : ℚ × ℚ → CProp ≝
+coinductive value_spec (f : list bar) (i : ℚ) : ℚ × ℚ → CProp ≝
| value_of : ∀j,q.
- 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.
+ nth_height f j = q → nth_base f j < i → j < \len f →
+ (∀n.n<j → nth_base f n < i) →
+ (∀n.j < n → n < \len f → i ≤ nth_base f n) → value_spec f i q.
-definition value_lemma : ∀f:q_f.∀i:ratio.∃p:ℚ×ℚ.value_spec f (Qpos i) p.
-intros;
+alias symbol "lt" (instance 5) = "Q less than".
+alias symbol "lt" (instance 6) = "natural 'less than'".
+definition value_lemma :
+ ∀f:list bar.sorted q2_lt f → O < length bar f →
+ ∀i:ratio.nth_base f O < Qpos i → ∃p:ℚ×ℚ.value_spec f (Qpos i) p.
+intros (f bars_sorted_f len_bases_gt_O_f i bars_begin_OQ_f);
letin P ≝
(λx:bar.match q_cmp (Qpos i) (\fst x) with[ q_leq _ ⇒ true| q_gt _ ⇒ false]);
-exists [apply (nth_height (bars f) (pred (find ? P (bars f) ▭)));]
-apply (value_of ?? (pred (find ? P (bars f) ▭)));
+exists [apply (nth_height f (pred (find ? P f ▭)));]
+apply (value_of ?? (pred (find ? P f ▭)));
[1: reflexivity
-|2: cases (cases_find bar P (bars f) ▭);
+|2: cases (cases_find bar P f ▭);
[1: cases i1 in H H1 H2 H3; simplify; intros;
- [1: generalize in match (bars_begin_OQ f);
- cases (len_gt_non_empty ?? (len_bases_gt_O f)); simplify; intros;
- rewrite > H4; apply q_pos_OQ;
- |2: cases (len_gt_non_empty ?? (len_bases_gt_O f)) in H3;
+ [1: generalize in match (bars_begin_OQ_f);
+ cases (len_gt_non_empty ?? (len_bases_gt_O_f)); simplify; intros;
+ assumption;
+ |2: cases (len_gt_non_empty ?? (len_bases_gt_O_f)) in H3;
intros; lapply (H3 n (le_n ?)) as K; unfold P in K;
cases (q_cmp (Qpos i) (\fst (\nth (x::l) ▭ n))) in K;
simplify; intros; [destruct H5] assumption]
- |2: destruct H; cases (len_gt_non_empty ?? (len_bases_gt_O f)) in H2;
+ |2: destruct H; cases (len_gt_non_empty ?? (len_bases_gt_O_f)) in H2;
simplify; intros; lapply (H (\len l) (le_n ?)) as K; clear H;
unfold P in K; cases (q_cmp (Qpos i) (\fst (\nth (x::l) ▭ (\len l)))) in K;
simplify; intros; [destruct H2] assumption;]
-|3: intro; cases (cases_find bar P (bars f) ▭); intros;
- [1: generalize in match (bars_sorted f);
+|5: intro; cases (cases_find bar P f ▭); intros;
+ [1: generalize in match (bars_sorted_f);
cases (list_break ??? H) in H1; rewrite > H6;
rewrite < H1; simplify; rewrite > nth_len; unfold P;
cases (q_cmp (Qpos i) (\fst x)); simplify;
apply lt_to_le; assumption;]
unfold nth_base; rewrite > (nth_append_ge_len ????? Hn);
cut (n - \len l1 < \len (x::l2)) as K; [2:
- simplify; rewrite > H1; rewrite > (?:\len l2 = \len (bars f) - \len (l1 @ [x]));[2:
+ simplify; rewrite > H1; rewrite > (?:\len l2 = \len f - \len (l1 @ [x]));[2:
rewrite > H6; repeat rewrite > len_append; simplify;
repeat rewrite < plus_n_Sm; rewrite < plus_n_O; simplify;
rewrite > sym_plus; rewrite < minus_plus_m_m; reflexivity;]
rewrite > len_append; rewrite > H1; simplify; rewrite < plus_n_SO;
- apply le_S_S; clear H1 H6 H7 Hs H8 H9 Hn x l2 l1 H4 H3 H2 H P i;
- elim (\len (bars f)) in i1 n H5; [cases (not_le_Sn_O ? H);]
+ apply le_S_S; clear H1 H6 H7 Hs H8 H9 Hn x l2 l1 H4 H3 H2 H P;
+ elim (\len f) in i1 n H5; [cases (not_le_Sn_O ? H);]
simplify; cases n2; [ repeat rewrite < minus_n_O; apply le_S_S_to_le; assumption]
cases n1 in H1; [intros; rewrite > eq_minus_n_m_O; apply le_O_n]
intros; simplify; apply H; apply le_S_S_to_le; assumption;]
apply q_lt_to_le; apply W;
|2: cases (not_le_Sn_n i1); rewrite > H in ⊢ (??%);
apply (trans_le ??? ? H4); cases i1 in H3; intros; apply le_S_S;
- [ apply le_O_n; | assumption]]]
+ [ apply le_O_n; | assumption]]
+|3: cases (cases_find bar P f ▭); [
+ cases i1 in H; intros; simplify; [assumption]
+ apply lt_S_to_lt; assumption;]
+ rewrite > H; cases (\len f) in len_bases_gt_O_f; intros; [cases (not_le_Sn_O ? H3)]
+ simplify; apply le_n;
+|4: intros; cases (cases_find bar P f ▭) in H; simplify; intros;
+ [1: lapply (H3 n); [2: cases i1 in H4; intros [assumption] apply le_S; assumption;]
+ unfold P in Hletin; cases (q_cmp (Qpos i) (\fst (\nth f ▭ n))) in Hletin;
+ simplify; intros; [destruct H6] assumption;
+ |2: destruct H; cases f in len_bases_gt_O_f H2 H3; clear H1; simplify; intros;
+ [cases (not_le_Sn_O ? H)] lapply (H1 n); [2: apply le_S; assumption]
+ unfold P in Hletin; cases (q_cmp (Qpos i) (\fst (\nth (b::l) ▭ n))) in Hletin;
+ simplify; intros; [destruct H4] assumption;]]
qed.
+lemma bars_begin_lt_Qpos : ∀q,r. nth_base (bars q) O<Qpos r.
+intros; rewrite > bars_begin_OQ; apply q_pos_OQ;
+qed.
+
lemma value : q_f → ratio → ℚ × ℚ.
-intros; cases (value_lemma q r); apply w; qed.
+intros; cases (value_lemma (bars q) ?? r);
+[ apply bars_sorted.
+| apply len_bases_gt_O;
+| apply w;
+| apply bars_begin_lt_Qpos;]
+qed.
+
+alias symbol "lt" (instance 5) = "natural 'less than'".
+alias symbol "lt" (instance 4) = "Q less than".
+lemma value_simpl:
+ ∀f:list bar.sorted q2_lt f → O < (length bar f) →
+ ∀i:ratio.nth_base f O < Qpos i → ℚ × ℚ.
+intros; cases (value_lemma f H H1 i H2); assumption;
+qed.
+
+lemma cases_value : ∀f,i. value_spec (bars f) (Qpos i) (value f i).
+intros; unfold value;
+cases (value_lemma (bars f) (bars_sorted f) (len_bases_gt_O f) i (bars_begin_lt_Qpos f i));
+assumption;
+qed.
-lemma cases_value : ∀f,i. value_spec f (Qpos i) (value f i).
-intros; unfold value; cases (value_lemma f i); assumption; qed.
+lemma cases_value_simpl :
+ ∀f,H1,H2,i,Hi.value_spec f (Qpos i) (value_simpl f H1 H2 i Hi).
+intros; unfold value_simpl; cases (value_lemma f H1 H2 i Hi);
+assumption;
+qed.
definition same_values ≝ λl1,l2:q_f.∀input. value l1 input = value l2 input.
+definition same_values_simpl ≝
+ λl1,l2:list bar.∀H1,H2,H3,H4,input,Hi1,Hi2.
+ value_simpl l1 H1 H2 input Hi1 = value_simpl l2 H3 H4 input Hi2.
+
+lemma value_head :
+ ∀x,y,l,H1,H2,i,H3.
+ Qpos i ≤ \fst x → value_simpl (y::x::l) H1 H2 i H3 = \snd y.
+intros; cases (cases_value_simpl ? H1 H2 i H3);
+cases j in H4 H5 H6 H7 H8 (j); simplify; intros;
+[1: symmetry; assumption;
+|2: cases (?:False); cases j in H4 H5 H6 H7 H8; intros;
+ [1: lapply (q_le_lt_trans ??? H H5) as K;cases (q_lt_corefl ? K);
+ |2: lapply (H7 1); [2: do 2 apply le_S_S; apply le_O_n;]
+ simplify in Hletin;
+ lapply (q_le_lt_trans ??? H Hletin) as K;cases (q_lt_corefl ? K);]]
+qed.
+
+lemma same_values_simpl_to_same_values:
+ ∀b1,b2,Hs1,Hs2,Hb1,Hb2,He1,He2,input.
+ same_values_simpl b1 b2 →
+ value (mk_q_f b1 Hs1 Hb1 He1) input =
+ value (mk_q_f b2 Hs2 Hb2 He2) input.
+intros;
+lapply (len_bases_gt_O (mk_q_f b1 Hs1 Hb1 He1));
+lapply (len_bases_gt_O (mk_q_f b2 Hs2 Hb2 He2));
+lapply (H ???? input) as K; try assumption;
+[2: rewrite > Hb1; apply q_pos_OQ;
+|3: rewrite > Hb2; apply q_pos_OQ;
+|1: apply K;]
+qed.
+include "russell_support.ma".
+
+lemma value_tail :
+ ∀x,y,l,H1,H2,i,H3.
+ \fst x < Qpos i →
+ value_simpl (y::x::l) H1 H2 i H3 =
+ value_simpl (x::l) ?? i ?.
+[1: apply hide; apply (sorted_tail q2_lt); [apply y| assumption]
+|2: apply hide; simplify; apply le_S_S; apply le_O_n;
+|3: apply hide; assumption;]
+intros;cases (cases_value_simpl ? H1 H2 i H3);
+generalize in ⊢ (? ? ? (? ? % ? ? ?)); intro;
+generalize in ⊢ (? ? ? (? ? ? % ? ?)); intro;
+generalize in ⊢ (? ? ? (? ? ? ? ? %)); intro;
+cases (cases_value_simpl (x::l) H9 H10 i H11);
+cut (j = S j1) as E; [ destruct E; destruct H12; reflexivity;]
+clear H12 H4; cases j in H8 H5 H6 H7;
+[1: intros;cases (?:False); lapply (H7 1 (le_n ?)); [2: simplify; do 2 apply le_S_S; apply le_O_n]
+ simplify in Hletin; apply (q_lt_corefl (\fst x));
+ apply (q_lt_le_trans ??? H Hletin);
+|2: simplify; intros; clear q q1 j H11 H10 H1 H2; simplify in H3 H14; apply eq_f;
+ cases (cmp_nat n j1); [cases (cmp_nat j1 n);[apply le_to_le_to_eq; assumption]]
+ [1: clear H1; cases (?:False);
+ lapply (H7 (S j1)); [2: cases j1 in H2; intros[cases (not_le_Sn_O ? H1)] apply le_S_S; assumption]
+ [2: apply le_S_S; assumption;] simplify in Hletin;
+ apply (q_lt_corefl ? (q_le_lt_trans ??? Hletin H13));
+ |2: cases (?:False);
+ lapply (H16 n); [2: assumption|3:simplify; apply le_S_S_to_le; assumption]
+ apply (q_lt_corefl ? (q_le_lt_trans ??? Hletin H4));]]
+qed.
+
definition same_bases ≝ λl1,l2:list bar. ∀i.\fst (\nth l1 ▭ i) = \fst (\nth l2 ▭ i).
+lemma same_bases_cons: ∀a,b,l1,l2.
+ same_bases l1 l2 → \fst a = \fst b → same_bases (a::l1) (b::l2).
+intros; intro; cases i; simplify; [assumption;] apply (H n);
+qed.
+
alias symbol "lt" = "Q less than".
lemma unpos: ∀x:ℚ.OQ < x → ∃r:ratio.Qpos r = x.
intro; cases x; intros; [2:exists [apply r] reflexivity]
--- /dev/null
+(**************************************************************************)
+(* ___ *)
+(* ||M|| *)
+(* ||A|| A project by Andrea Asperti *)
+(* ||T|| *)
+(* ||I|| Developers: *)
+(* ||T|| The HELM team. *)
+(* ||A|| http://helm.cs.unibo.it *)
+(* \ / *)
+(* \ / This file is distributed under the terms of the *)
+(* v GNU General Public License Version 2 *)
+(* *)
+(**************************************************************************)
+
+include "models/q_bars.ma".
+
+(* move in nat/minus *)
+lemma minus_lt : ∀i,j. i < j → j - i = S (j - S i).
+intros 2;
+apply (nat_elim2 ???? i j); simplify; intros;
+[1: cases n in H; intros; rewrite < minus_n_O; [cases (not_le_Sn_O ? H);]
+ simplify; rewrite < minus_n_O; reflexivity;
+|2: cases (not_le_Sn_O ? H);
+|3: apply H; apply le_S_S_to_le; assumption;]
+qed.
+
+definition copy ≝
+ λl:list bar.make_list ? (λn.〈nth_base l (\len l - S n),〈OQ,OQ〉〉) (\len l).
+
+lemma sorted_copy:
+ ∀l:list bar.sorted q2_lt l → sorted q2_lt (copy l).
+intros 2; unfold copy; generalize in match (le_n (\len l));
+elim (\len l) in ⊢ (?%?→? ? (? ? ? %));
+simplify; [apply (sorted_nil q2_lt);] cases n in H1 H2;
+simplify; intros; [apply (sorted_one q2_lt);]
+apply (sorted_cons q2_lt);
+[2: apply H1; apply lt_to_le; apply H2;
+|1: elim l in H2 H; simplify; [simplify in H2; cases (not_le_Sn_O ? H2)]
+ simplify in H3; unfold nth_base;
+ unfold canonical_q_lt; unfold q2_trel; unfold q2_lt; simplify;
+ change with (q2_lt (\nth (a::l1) ▭ (\len l1-S n1)) (\nth (a::l1) ▭ (\len l1-n1)));
+ cut (∃w.w = \len l1 - S n1); [2: exists[apply (\len l1 - S n1)] reflexivity]
+ cases Hcut; rewrite < H4; rewrite < (?:S w = \len l1 - n1);
+ [1: apply (sorted_near q2_lt (a::l1) H2); rewrite > H4;
+ simplify; apply le_S_S; elim (\len l1) in H3; simplify;
+ [ cases (not_le_Sn_O ? (le_S_S_to_le ?? H3));
+ | lapply le_S_S_to_le to H5 as H6;
+ lapply le_S_S_to_le to H6 as H7; clear H5 H6;
+ cases H7 in H3; intros; [rewrite < minus_n_n; apply le_S_S; apply le_O_n]
+ simplify in H5; apply le_S_S; apply (trans_le ???? (H5 ?));
+ [2: apply le_S_S; apply le_S_S; assumption;
+ |1: apply (lt_minus_S_n_to_le_minus_n n1 (S m) (S (minus m n1)) ?).
+ apply (not_le_to_lt (S (minus m n1)) (minus (S m) (S n1)) ?).
+ apply (not_le_Sn_n (minus (S m) (S n1))).]]
+ |2: rewrite > H4; lapply le_S_S_to_le to H3 as K;
+ clear H4 Hcut H3 H H1 H2; generalize in match K; clear K;
+ apply (nat_elim2 ???? n1 (\len l1)); simplify; intros;
+ [1: rewrite < minus_n_O; cases n2 in H; [intro; cases (not_le_Sn_O ? H)]
+ intros; cases n3; simplify; reflexivity;
+ |2: cases (not_le_Sn_O ? H);
+ |3: apply H; apply le_S_S_to_le; apply H1;]]]
+qed.
+
+lemma len_copy: ∀l. \len (copy l) = \len l.
+intro; unfold copy; apply len_mk_list;
+qed.
+
+lemma copy_same_bases: ∀l. same_bases l (copy l).
+intro; unfold copy; elim l using list_elim_with_len; [1: intro;reflexivity]
+simplify; rewrite < minus_n_n;
+simplify in ⊢ (? ? (? ? (? ? ? % ?) ?));
+apply same_bases_cons; [2: reflexivity]
+cases l1 in H; [intros 2; reflexivity]
+simplify in ⊢ (? ? (? ? (λ_:?.? ? ? (? ? %) ?) ?)→?);
+simplify in ⊢ (?→? ? (? ? (λ_:?.? ? ? (? ? (? % ?)) ?) ?));
+intro; rewrite > (mk_list_ext ?? (λn:nat.〈nth_base (b::l2) (\len l2-n),〈OQ,OQ〉〉));[assumption]
+intro; elim x; [simplify; rewrite < minus_n_O; reflexivity]
+simplify in ⊢ (? ? (? ? ? (? ? %) ?) ?);
+simplify in H2:(? ? %); rewrite > minus_lt; [reflexivity] apply le_S_S_to_le;
+assumption;
+qed.
+
+lemma rewrite_ext_nth_height : ∀n,m,f,f1,g,g1. (∀t.g t = g1 t) →
+nth_height (\mk_list (λn.〈f n,g n〉) m) n = nth_height (\mk_list (λn.〈f1 n,g1 n〉) m) n.
+intros; generalize in match n; clear n; elim m; [reflexivity] simplify;
+cases n1; [simplify;apply H;] simplify; apply (H1 n2);
+qed.
+
+lemma copy_OQ : ∀l,n.nth_height (copy l) n = 〈OQ,OQ〉.
+intro; elim l; [cases n; [reflexivity] simplify; rewrite > nth_nil; reflexivity]
+cases n; simplify [reflexivity]
+change with (nth_height (\mk_list (λn:ℕ.〈nth_base (a::l1) (\len l1-n),〈OQ,OQ〉〉) (\len l1)) n1 = 〈OQ,OQ〉);
+rewrite > (rewrite_ext_nth_height ??? (λ_.OQ) ? (λ_.〈OQ,OQ〉)); [2: intros; reflexivity]
+generalize in match n1;
+elim (\len l1); simplify; unfold nth_height; [rewrite > nth_nil; reflexivity]
+cases n3; simplify; [reflexivity] apply (H1 n4);
+qed.
+
+lemma prepend_sorted_with_same_head:
+ ∀r,x,l1,l2,d1,d2.
+ sorted r (x::l1) → sorted r l2 →
+ (r x (\nth l1 d1 O) → r x (\nth l2 d2 O)) → (l1 = [] → r x d1) →
+ sorted r (x::l2).
+intros 8 (R x l1 l2 d1 d2 Sl1 Sl2); inversion Sl1; inversion Sl2;
+intros; destruct; try assumption; [3: apply (sorted_one R);]
+[1: apply sorted_cons;[2:assumption] apply H2; apply H3; reflexivity;
+|2: apply sorted_cons;[2: assumption] apply H5; apply H6; reflexivity;
+|3: apply sorted_cons;[2: assumption] apply H5; assumption;
+|4: apply sorted_cons;[2: assumption] apply H8; apply H4;]
+qed.
+
+lemma move_head_sorted: ∀x,l1,l2.
+ sorted q2_lt (x::l1) → sorted q2_lt l2 → nth_base l2 O = nth_base l1 O →
+ l1 ≠ [] → sorted q2_lt (x::l2).
+intros; apply (prepend_sorted_with_same_head q2_lt x l1 l2 ▭ ▭);
+try assumption; intros; unfold nth_base in H2; whd in H4;
+[1: rewrite < H2 in H4; assumption;
+|2: cases (H3 H4);]
+qed.
+
+alias symbol "lt" = "bar lt".
+lemma inversion_sorted:
+ ∀a,l. sorted q2_lt (a::l) → Or (a < \hd ▭ l) (l = []).
+intros 2; elim l; [right;reflexivity] left; inversion H1; intros;
+[1,2:destruct H2| destruct H5; assumption]
+qed.
+
+lemma inversion_sorted2:
+ ∀a,b,l. sorted q2_lt (a::b::l) → a < b.
+intros; inversion H; intros; [1,2:destruct H1] destruct H4; assumption;
+qed.
+
+lemma sort_q2lt_same_base:
+ ∀b,h1,h2,l. sorted q2_lt (〈b,h1〉::l) → sorted q2_lt (〈b,h2〉::l).
+intros; cases (inversion_sorted ?? H); [2: rewrite > H1; apply (sorted_one q2_lt)]
+lapply (sorted_tail q2_lt ?? H) as K; clear H; cases l in H1 K; simplify; intros;
+[apply (sorted_one q2_lt);|apply (sorted_cons q2_lt);[2: assumption] apply H]
+qed.
+
(**************************************************************************)
include "russell_support.ma".
-include "models/q_bars.ma".
+include "models/q_copy.ma".
-(* move in nat/minus *)
-lemma minus_lt : ∀i,j. i < j → j - i = S (j - S i).
-intros 2;
-apply (nat_elim2 ???? i j); simplify; intros;
-[1: cases n in H; intros; rewrite < minus_n_O; [cases (not_le_Sn_O ? H);]
- simplify; rewrite < minus_n_O; reflexivity;
-|2: cases (not_le_Sn_O ? H);
-|3: apply H; apply le_S_S_to_le; assumption;]
-qed.
-
-definition copy ≝
- λl:list bar.make_list ? (λn.〈nth_base l (\len l - S n),〈OQ,OQ〉〉) (\len l).
-
-lemma sorted_copy:
- ∀l:list bar.sorted q2_lt l → sorted q2_lt (copy l).
-intros 2; unfold copy; generalize in match (le_n (\len l));
-elim (\len l) in ⊢ (?%?→? ? (? ? ? %));
-simplify; [apply (sorted_nil q2_lt);] cases n in H1 H2;
-simplify; intros; [apply (sorted_one q2_lt);]
-apply (sorted_cons q2_lt);
-[2: apply H1; apply lt_to_le; apply H2;
-|1: elim l in H2 H; simplify; [simplify in H2; cases (not_le_Sn_O ? H2)]
- simplify in H3; unfold nth_base;
- unfold canonical_q_lt; unfold q2_trel; unfold q2_lt; simplify;
- change with (q2_lt (\nth (a::l1) ▭ (\len l1-S n1)) (\nth (a::l1) ▭ (\len l1-n1)));
- cut (∃w.w = \len l1 - S n1); [2: exists[apply (\len l1 - S n1)] reflexivity]
- cases Hcut; rewrite < H4; rewrite < (?:S w = \len l1 - n1);
- [1: apply (sorted_near q2_lt (a::l1) H2); rewrite > H4;
- simplify; apply le_S_S; elim (\len l1) in H3; simplify;
- [ cases (not_le_Sn_O ? (le_S_S_to_le ?? H3));
- | lapply le_S_S_to_le to H5 as H6;
- lapply le_S_S_to_le to H6 as H7; clear H5 H6;
- cases H7 in H3; intros; [rewrite < minus_n_n; apply le_S_S; apply le_O_n]
- simplify in H5; apply le_S_S; apply (trans_le ???? (H5 ?));
- [2: apply le_S_S; apply le_S_S; assumption;
- |1: apply (lt_minus_S_n_to_le_minus_n n1 (S m) (S (minus m n1)) ?).
- apply (not_le_to_lt (S (minus m n1)) (minus (S m) (S n1)) ?).
- apply (not_le_Sn_n (minus (S m) (S n1))).]]
- |2: rewrite > H4; lapply le_S_S_to_le to H3 as K;
- clear H4 Hcut H3 H H1 H2; generalize in match K; clear K;
- apply (nat_elim2 ???? n1 (\len l1)); simplify; intros;
- [1: rewrite < minus_n_O; cases n2 in H; [intro; cases (not_le_Sn_O ? H)]
- intros; cases n3; simplify; reflexivity;
- |2: cases (not_le_Sn_O ? H);
- |3: apply H; apply le_S_S_to_le; apply H1;]]]
-qed.
-
-lemma len_copy: ∀l. \len (copy l) = \len l.
-intro; unfold copy; apply len_mk_list;
-qed.
-
-lemma same_bases_cons: ∀a,b,l1,l2.
- same_bases l1 l2 → \fst a = \fst b → same_bases (a::l1) (b::l2).
-intros; intro; cases i; simplify; [assumption;] apply (H n);
-qed.
-
-lemma copy_same_bases: ∀l. same_bases l (copy l).
-intro; unfold copy; elim l using list_elim_with_len; [1: intro;reflexivity]
-simplify; rewrite < minus_n_n;
-simplify in ⊢ (? ? (? ? (? ? ? % ?) ?));
-apply same_bases_cons; [2: reflexivity]
-cases l1 in H; [intros 2; reflexivity]
-simplify in ⊢ (? ? (? ? (λ_:?.? ? ? (? ? %) ?) ?)→?);
-simplify in ⊢ (?→? ? (? ? (λ_:?.? ? ? (? ? (? % ?)) ?) ?));
-intro; rewrite > (mk_list_ext ?? (λn:nat.〈nth_base (b::l2) (\len l2-n),〈OQ,OQ〉〉));[assumption]
-intro; elim x; [simplify; rewrite < minus_n_O; reflexivity]
-simplify in ⊢ (? ? (? ? ? (? ? %) ?) ?);
-simplify in H2:(? ? %); rewrite > minus_lt; [reflexivity] apply le_S_S_to_le;
-assumption;
-qed.
-
-lemma prepend_sorted_with_same_head:
- ∀r,x,l1,l2,d1,d2.
- sorted r (x::l1) → sorted r l2 →
- (r x (\nth l1 d1 O) → r x (\nth l2 d2 O)) → (l1 = [] → r x d1) →
- sorted r (x::l2).
-intros 8 (R x l1 l2 d1 d2 Sl1 Sl2); inversion Sl1; inversion Sl2;
-intros; destruct; try assumption; [3: apply (sorted_one R);]
-[1: apply sorted_cons;[2:assumption] apply H2; apply H3; reflexivity;
-|2: apply sorted_cons;[2: assumption] apply H5; apply H6; reflexivity;
-|3: apply sorted_cons;[2: assumption] apply H5; assumption;
-|4: apply sorted_cons;[2: assumption] apply H8; apply H4;]
-qed.
-
-lemma move_head_sorted: ∀x,l1,l2.
- sorted q2_lt (x::l1) → sorted q2_lt l2 → nth_base l2 O = nth_base l1 O →
- l1 ≠ [] → sorted q2_lt (x::l2).
-intros; apply (prepend_sorted_with_same_head q2_lt x l1 l2 ▭ ▭);
-try assumption; intros; unfold nth_base in H2; whd in H4;
-[1: rewrite < H2 in H4; assumption;
-|2: cases (H3 H4);]
-qed.
-
definition rebase_spec ≝
λl1,l2:q_f.λp:q_f × q_f.
And3
(same_values l1 (\fst p))
(same_values l2 (\snd p)).
-definition last ≝
- λT:Type.λd.λl:list T. \nth l d (pred (\len l)).
-
-notation > "\last" non associative with precedence 90 for @{'last}.
-notation < "\last d l" non associative with precedence 70 for @{'last2 $d $l}.
-interpretation "list last" 'last = (last _).
-interpretation "list last applied" 'last2 d l = (last _ d l).
-
-definition head ≝
- λT:Type.λd.λl:list T.\nth l d O.
-
-notation > "\hd" non associative with precedence 90 for @{'hd}.
-notation < "\hd d l" non associative with precedence 70 for @{'hd2 $d $l}.
-interpretation "list head" 'hd = (head _).
-interpretation "list head applied" 'hd2 d l = (head _ d l).
-
-alias symbol "lt" = "bar lt".
-lemma inversion_sorted:
- ∀a,l. sorted q2_lt (a::l) → a < \hd ▭ l ∨ l = [].
-intros 2; elim l; [right;reflexivity] left; inversion H1; intros;
-[1,2:destruct H2| destruct H5; assumption]
-qed.
-
-lemma inversion_sorted2:
- ∀a,b,l. sorted q2_lt (a::b::l) → a < b.
-intros; inversion H; intros; [1,2:destruct H1] destruct H4; assumption;
-qed.
-
-definition same_values_simpl ≝
- λl1,l2.∀p1,p2,p3,p4,p5,p6.
- same_values (mk_q_f l1 p1 p2 p3) (mk_q_f l2 p4 p5 p6).
-
inductive rebase_cases : list bar → list bar → (list bar) × (list bar) → Prop ≝
-| rb_fst_full : ∀b,h1,h2,xs,ys,r1,r2. 〈b,h1〉 < \hd ▭ ys →
- \snd(\last ▭ (〈b,h1〉::xs)) = \snd(\last ▭ (〈b,h1〉::r1)) →
- \snd(\last ▭ (〈b,h1〉::xs)) = \snd(\last ▭ (〈b,h2〉::r2)) →
- rebase_cases (〈b,h1〉::xs) ys 〈〈b,h1〉::r1,〈b,h2〉::r2〉
-| rb_snd_full : ∀b,h1,h2,xs,ys,r1,r2. 〈b,h1〉 < \hd ▭ xs →
- \snd(\last ▭ (〈b,h1〉::ys)) = \snd(\last ▭ (〈b,h1〉::r2)) →
- \snd(\last ▭ (〈b,h1〉::ys)) = \snd(\last ▭ (〈b,h2〉::r1)) →
- rebase_cases xs (〈b,h1〉::ys) 〈〈b,h2〉::r1,〈b,h1〉::r2〉
+| rb_fst_full : ∀b,h1,xs. (*〈b,h1〉 < \hd ▭ ys → *)
+(* \snd(\last ▭ (〈b,h1〉::xs)) = \snd(\last ▭ (〈b,h1〉::r1)) →
+ \snd(\last ▭ (〈b,h1〉::xs)) = \snd(\last ▭ (〈b,h2〉::r2)) →*)
+ rebase_cases (〈b,h1〉::xs) [] 〈〈b,h1〉::xs,〈b,〈OQ,OQ〉〉::copy xs〉
+| rb_snd_full : ∀b,h1,ys. (*〈b,h1〉 < \hd ▭ xs →*)
+ (* \snd(\last ▭ (〈b,h1〉::ys)) = \snd(\last ▭ (〈b,h1〉::r2)) →
+ \snd(\last ▭ (〈b,h1〉::ys)) = \snd(\last ▭ (〈b,h2〉::r1)) →*)
+ rebase_cases [] (〈b,h1〉::ys) 〈〈b,〈OQ,OQ〉〉::copy ys,〈b,h1〉::ys〉
| rb_all_full : ∀b,h1,h2,h3,h4,xs,ys,r1,r2.
\snd(\last ▭ (〈b,h1〉::xs)) = \snd(\last ▭ (〈b,h3〉::r1)) →
\snd(\last ▭ (〈b,h2〉::ys)) = \snd(\last ▭ (〈b,h4〉::r2)) →
- rebase_cases (〈b,h1〉::xs) (〈b,h2〉::ys) 〈〈b,h3〉::r1,〈b,h4〉::r2〉
+ rebase_cases (〈b,h1〉::xs) (〈b,h2〉::ys) 〈〈b,h3〉::r1,〈b,h4〉::r2〉
+| rb_all_full_l : ∀b1,b2,h1,h2,xs,ys,r1,r2.
+ \snd(\last ▭ (〈b1,h1〉::xs)) = \snd(\last ▭ (〈b1,h1〉::r1)) →
+ \snd(\last ▭ (〈b2,h2〉::ys)) = \snd(\last ▭ (〈b1,h2〉::r2)) →
+ b1 < b2 →
+ rebase_cases (〈b1,h1〉::xs) (〈b2,h2〉::ys) 〈〈b1,h1〉::r1,〈b1,h2〉::r2〉
+| rb_all_full_r : ∀b1,b2,h1,h2,xs,ys,r1,r2.
+ \snd(\last ▭ (〈b1,h1〉::xs)) = \snd(\last ▭ (〈b2,h1〉::r1)) →
+ \snd(\last ▭ (〈b2,h2〉::ys)) = \snd(\last ▭ (〈b2,h2〉::r2)) →
+ b2 < b1 →
+ rebase_cases (〈b1,h1〉::xs) (〈b2,h2〉::ys) 〈〈b2,h1〉::r1,〈b2,h2〉::r2〉
| rb_all_empty : rebase_cases [] [] 〈[],[]〉.
alias symbol "pi2" = "pair pi2".
(*\len (\fst p) = \len (\snd p) → *)
rebase_spec_aux_p l1 l2 p.
-lemma sort_q2lt_same_base:
- ∀b,h1,h2,l. sorted q2_lt (〈b,h1〉::l) → sorted q2_lt (〈b,h2〉::l).
-intros; cases (inversion_sorted ?? H); [2: rewrite > H1; apply (sorted_one q2_lt)]
-lapply (sorted_tail q2_lt ?? H) as K; clear H; cases l in H1 K; simplify; intros;
-[apply (sorted_one q2_lt);|apply (sorted_cons q2_lt);[2: assumption] apply H]
-qed.
-
lemma aux_preserves_sorting:
∀b,b3,l2,l3,w. rebase_cases l2 l3 w →
sorted q2_lt (b::l2) → sorted q2_lt (b3::l3) → \fst b3 = \fst b →
- sorted q2_lt (\fst w) → sorted q2_lt (\snd w) → same_bases (\fst w) (\snd w) →
- sorted q2_lt (b :: \fst w).
-intros 6; cases H; simplify; intros;
-[ apply (sorted_cons q2_lt); [2:assumption] apply (inversion_sorted2 ??? H4);
-| apply (sorted_cons q2_lt); [2:apply (sort_q2lt_same_base ???? H7);]
+ sorted q2_lt (\fst w) → sorted q2_lt (\snd w) →
+ same_bases (\fst w) (\snd w) →
+ sorted q2_lt (b :: \fst w).
+intros 6; cases H; simplify; intros; clear H;
+[ apply (sorted_cons q2_lt); [2:assumption] apply (inversion_sorted2 ??? H1);
+| apply (sorted_cons q2_lt); [2:assumption]
+ whd; rewrite < H3; apply (inversion_sorted2 ??? H2);
+| apply (sorted_cons q2_lt); [2:assumption] apply (inversion_sorted2 ??? H3);
+| apply (sorted_cons q2_lt); [2:assumption] apply (inversion_sorted2 ??? H4);
+| apply (sorted_cons q2_lt); [2:assumption]
whd; rewrite < H6; apply (inversion_sorted2 ??? H5);
-| apply (sorted_cons q2_lt); [2: assumption] apply (inversion_sorted2 ??? H3);
| apply (sorted_one q2_lt);]
qed.
sorted q2_lt (b::l2) → sorted q2_lt (b3::l3) → \fst b3 = \fst b →
sorted q2_lt (\fst w) → sorted q2_lt (\snd w) → same_bases (\fst w) (\snd w) →
sorted q2_lt (b :: \snd w).
-intros 6; cases H; simplify; intros;
-[ apply (sorted_cons q2_lt); [2:assumption] apply (inversion_sorted2 ??? H4);
+intros 6; cases H; simplify; intros; clear H;
+[ apply (sorted_cons q2_lt); [2:assumption] apply (inversion_sorted2 ??? H1);
| apply (sorted_cons q2_lt); [2:assumption]
- whd; rewrite < H6; apply (inversion_sorted2 ??? H5);
+ whd; rewrite < H3; apply (inversion_sorted2 ??? H2);
| apply (sorted_cons q2_lt); [2: assumption] apply (inversion_sorted2 ??? H3);
+| apply (sorted_cons q2_lt); [2: assumption] apply (inversion_sorted2 ??? H4);
+| apply (sorted_cons q2_lt); [2: assumption]
+ whd; rewrite < H6; apply (inversion_sorted2 ??? H5);
| apply (sorted_one q2_lt);]
-qed.
+qed.
definition rebase_spec_aux ≝
λl1,l2:list bar.λp:(list bar) × (list bar).
sorted q2_lt l1 → (\snd (\last ▭ l1) = 〈OQ,OQ〉) →
sorted q2_lt l2 → (\snd (\last ▭ l2) = 〈OQ,OQ〉) →
rebase_spec_aux_p l1 l2 p.
-
-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: ∀l1,l2:q_f.∃p:q_f × q_f.rebase_spec l1 l2 p.
-intros 2 (f1 f2); cases f1 (b1 Hs1 Hb1 He1); cases f2 (b2 Hs2 Hb2 He2); clear f1 f2;
-alias symbol "leq" = "natural 'less or equal to'".
-alias symbol "minus" = "Q minus".
-letin aux ≝ (
-let rec aux (l1,l2:list bar) (n : nat) on n : (list bar) × (list bar) ≝
-match n with
-[ O ⇒ 〈[], []〉
-| S m ⇒
- match l1 with
- [ nil ⇒ 〈copy l2, l2〉
- | cons he1 tl1 ⇒
- match l2 with
- [ nil ⇒ 〈l1, copy l1〉
- | cons he2 tl2 ⇒
- let base1 ≝ \fst he1 in
- let base2 ≝ \fst he2 in
- let height1 ≝ \snd he1 in
- let height2 ≝ \snd he2 in
- match q_cmp base1 base2 with
- [ q_leq Hp1 ⇒
- match q_cmp base2 base1 with
- [ q_leq Hp2 ⇒
- let rc ≝ aux tl1 tl2 m in
- 〈he1 :: \fst rc,he2 :: \snd rc〉
- | q_gt Hp ⇒
- let rest ≝ base2 - base1 in
- let rc ≝ aux tl1 (〈rest,height2〉 :: tl2) m in
- 〈〈base1,height1〉 :: \fst rc,〈base1,height2〉 :: \snd rc〉]
- | q_gt Hp ⇒
- let rest ≝ base1 - base2 in
- let rc ≝ aux (〈rest,height1〉 :: tl1) tl2 m in
- 〈〈base2,height1〉 :: \fst rc,〈base2,height2〉 :: \snd rc〉]]]]
-in aux : ∀l1,l2,m.∃z.\len l1 + \len l2 ≤ m → rebase_spec_aux l1 l2 z);
-[7: clearbody aux; cases (aux b1 b2 (\len b1 + \len b2)) (res Hres);
- exists; [split; constructor 1; [apply (\fst res)|5:apply (\snd res)]]
- [1,4: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); assumption;
- |2,5: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); lapply (H5 O) as K;
- clear H1 H2 H3 H4 H5 H6 H7 Hres aux; unfold nth_base;
- cases H in K He1 He2 Hb1 Hb2; simplify; intros; assumption;
- |3,6: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2);
- cases H in He1 He2; simplify; intros;
- [4,8: assumption;
- |1,6,7: rewrite < H9; assumption;
- |2,3,5: rewrite < H10; [2: symmetry] assumption;]]
- split; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); unfold same_values; intros;
- [1: assumption
- |2: simplify in match (\snd 〈?,?〉); simplify in match (\fst 〈?,?〉); apply H6;
- |3: simplify in match (\snd 〈?,?〉); simplify in match (\fst 〈?,?〉); apply H7]
-|3: cut (\fst b3 = \fst b) as E; [2: apply q_le_to_le_to_eq; assumption]
- clear H6 H5 H4 H3 He2 Hb2 Hs2 b2 He1 Hb1 Hs1 b1; cases (aux l2 l3 n1);
- clear aux; intro K; simplify in K; rewrite <plus_n_Sm in K;
- lapply le_S_S_to_le to K as W; lapply lt_to_le to W as R;
- simplify in match (? ≪w,H3≫); intros; cases (H3 R); clear H3 R W K;
- [2,4: apply (sorted_tail q2_lt);[apply b|3:apply b3]assumption;
- |3: cases l2 in H5; simplify; intros; try reflexivity; assumption;
- |5: cases l3 in H7; simplify; intros; try reflexivity; assumption;]
- constructor 1; simplify in match (\fst 〈?,?〉); simplify in match (\snd 〈?,?〉);
- [1: cases b in E H5 H7 H11 H14; cases b3; intros (E H5 H7 H11 H14); simplify in E;
- destruct E; constructor 3;
- [ cases H8 in H5 H7; intros; [1,3:assumption] simplify;
- [ rewrite > H16; rewrite < H7; symmetry; apply H17; | reflexivity]
- | cases H8 in H5 H7; simplify; intros; [2,3: assumption]
- [ rewrite < H7; rewrite > H16; apply H17; | reflexivity]]
- |2: apply (aux_preserves_sorting ? b3 ??? H8); assumption;
- |3: apply (aux_preserves_sorting2 ? b3 ??? H8); try assumption;
- try reflexivity; cases (inversion_sorted ?? H4);[2:rewrite >H3; apply (sorted_one q2_lt);]
- cases l2 in H3 H4; intros; [apply (sorted_one q2_lt)]
- apply (sorted_cons q2_lt);[2:apply (sorted_tail q2_lt ?? H3);] whd;
- rewrite > E; assumption;
- |4: apply I
- |5: apply I
- |6: intro; elim i; intros; simplify; solve [symmetry;assumption|apply H13]
- |7: unfold; intros; apply H14;
- |8:
-
- clear H15 H14 H11 H12 H7 H5; cases H8; clear H8; cases H3; clear H3;
- [1: apply (move_head ?? H4 H5 ?? H9); symmetry; assumption;
- |2: apply (move_head ??? H5 ?? H9); [apply (soted_q2lt_rewrite_hd ??? E H6)]
- symmetry; rewrite > (H13 O); assumption;
- |3: apply (soted_q2lt_rewrite_hd ??? E); apply (move_head ?? H6 H7); [symmetry;] assumption;
- |4: rewrite > H8; apply (sorted_one q2_lt);]
-
-
- cases l2 in H4 H8 H16; cases l3 in H6;
- intros; cases H5; clear H5; cases H7; clear H7;
- [1,2: cases (q_lt_corefl ? H5);
- |3: rewrite >(?:\fst w = []); [apply (sorted_one q2_lt)]
- simplify in H6; lapply (le_n_O_to_eq ? H6) as K;
- cases (\fst w) in K; simplify; intro X [reflexivity|destruct X]
- |4:
-
- rewrite >H8 in H5; cases (\fst w) in H9 H5; intros [apply (sorted_one q2_lt)]
-
-
-
-
-
-
-
-
-
-
-definition same_values_simpl ≝
- λl1,l2.∀p1,p2,p3,p4,p5,p6.same_values (mk_q_f l1 p1 p2 p3) (mk_q_f l2 p4 p5 p6).
-
-alias symbol "pi2" = "pair pi2".
-alias symbol "pi1" = "pair pi1".
-definition rebase_spec_aux ≝
- λl1,l2:list bar.λp:(list bar) × (list bar).
- sorted q2_lt l1 → sorted q2_lt l2 →
- (l1 ≠ [] → \snd (\nth l1 ▭ (pred (\len l1))) = 〈OQ,OQ〉) →
- (l2 ≠ [] → \snd (\nth l2 ▭ (pred (\len l2))) = 〈OQ,OQ〉) →
- And4
- (nth_base l1 O = nth_base (\fst p) O ∨
- nth_base l2 O = nth_base (\fst p) O)
- (sorted q2_lt (\fst p) ∧ sorted q2_lt (\snd p))
- ((l1 ≠ [] → \snd (\nth (\fst p) ▭ (pred (\len (\fst p)))) = 〈OQ,OQ〉) ∧
- (l2 ≠ [] → \snd (\nth (\snd p) ▭ (pred (\len (\snd p)))) = 〈OQ,OQ〉))
- (And3
- (same_bases (\fst p) (\snd p))
- (same_values_simpl l1 (\fst p))
- (same_values_simpl l2 (\snd p))).
-
-lemma copy_rebases:
- ∀l1.rebase_spec_aux l1 [] 〈l1, copy l1〉.
-intros; elim l1; intros 4;
-[1: split; [left; reflexivity]; split; try assumption; unfold; intros;
- unfold same_values; intros; reflexivity;
-|2: rewrite > H3; [2: intro X; destruct X]
- split; [left; reflexivity] split;
- unfold same_values_simpl; unfold same_values; intros; try reflexivity;
- try assumption; [4: normalize in p2; destruct p2|2: cases H5; reflexivity;]
- [1: apply (sorted_copy ? H1);
- |2: apply (copy_same_bases (a::l));]]
-qed.
-
-lemma copy_rebases_r:
- ∀l1.rebase_spec_aux [] l1 〈copy l1, l1〉.
-intros; elim l1; intros 4;
-[1: split; [left; reflexivity]; split; try assumption; unfold; intros;
- unfold same_values; intros; reflexivity;
-|2: rewrite > H4; [2: intro X; destruct X]
- split; [right; simplify; rewrite < minus_n_n; reflexivity] split;
- unfold same_values_simpl; unfold same_values; intros; try reflexivity;
- try assumption; [4: normalize in p2; destruct p2|2: cases H5; reflexivity;]
- [1: apply (sorted_copy ? H2);
- |2: intro; symmetry; apply (copy_same_bases (a::l));]]
-qed.
-
-
-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: ∀l1,l2:q_f.∃p:q_f × q_f.rebase_spec l1 l2 p.
-intros 2 (f1 f2); cases f1 (b1 Hs1 Hb1 He1); cases f2 (b2 Hs2 Hb2 He2); clear f1 f2;
-alias symbol "leq" = "natural 'less or equal to'".
-alias symbol "minus" = "Q minus".
-letin aux ≝ (
-let rec aux (l1,l2:list bar) (n : nat) on n : (list bar) × (list bar) ≝
-match n with
-[ O ⇒ 〈[], []〉
-| S m ⇒
- match l1 with
- [ nil ⇒ 〈copy l2, l2〉
- | cons he1 tl1 ⇒
- match l2 with
- [ nil ⇒ 〈l1, copy l1〉
- | cons he2 tl2 ⇒
- let base1 ≝ \fst he1 in
- let base2 ≝ \fst he2 in
- let height1 ≝ \snd he1 in
- let height2 ≝ \snd he2 in
- match q_cmp base1 base2 with
- [ q_leq Hp1 ⇒
- match q_cmp base2 base1 with
- [ q_leq Hp2 ⇒
- let rc ≝ aux tl1 tl2 m in
- 〈he1 :: \fst rc,he2 :: \snd rc〉
- | q_gt Hp ⇒
- let rest ≝ base2 - base1 in
- let rc ≝ aux tl1 (〈rest,height2〉 :: tl2) m in
- 〈〈base1,height1〉 :: \fst rc,〈base1,height2〉 :: \snd rc〉]
- | q_gt Hp ⇒
- let rest ≝ base1 - base2 in
- let rc ≝ aux (〈rest,height1〉 :: tl1) tl2 m in
- 〈〈base2,height1〉 :: \fst rc,〈base2,height2〉 :: \snd rc〉]]]]
-in aux : ∀l1,l2,m.∃z.\len l1 + \len l2 ≤ m → rebase_spec_aux l1 l2 z);
-[7: clearbody aux; cases (aux b1 b2 (\len b1 + \len b2)) (w Hw); clear aux;
- cases (Hw (le_n ?) Hs1 Hs2 (λ_.He1) (λ_.He2)); clear Hw; cases H1; cases H2; cases H3; clear H3 H1 H2;
- exists [constructor 1;constructor 1;[apply (\fst w)|5:apply (\snd w)]] try assumption;
- [1,3: apply hide; cases H (X X); try rewrite < (H8 O); try rewrite < X; assumption
- |2,4: apply hide;[apply H6|apply H7]intro X;[rewrite > X in Hb1|rewrite > X in Hb2]
- normalize in Hb1 Hb2; [destruct Hb1|destruct Hb2]]
- unfold; unfold same_values; simplify in ⊢ (? (? % %) ? ?);
- simplify in match (\snd 〈?,?〉); simplify in match (\fst 〈?,?〉);
- split; [assumption; |apply H9;|apply H10]
-|6: intro ABS; unfold; intros 4; clear H1 H2;
- cases l in ABS H3; intros 1; [2: simplify in H1; cases (not_le_Sn_O ? H1)]
- cases l1 in H4 H1; intros; [2: simplify in H2; cases (not_le_Sn_O ? H2)]
- split; [ left; reflexivity|split; apply (sorted_nil q2_lt);|split; assumption;]
- split; unfold; intros; unfold same_values; intros; reflexivity;
-|5: intros; apply copy_rebases_r;
-|4: intros; rewrite < H1; apply copy_rebases;
-|3: cut (\fst b = \fst b3) as K; [2: apply q_le_to_le_to_eq; assumption] clear H6 H5 H4 H3;
- intros; cases (aux l2 l3 n1); cases w in H4 (w1 w2); clear w;
- intros 5;
- simplify in match (\fst 〈?,?〉); simplify in match (\snd 〈?,?〉);
- cases H5;
- [2: apply le_S_S_to_le; apply (trans_le ???? H3); simplify;
- rewrite < plus_n_Sm; apply le_S; apply le_n;
- |3,4: apply (sorted_tail q2_lt); [2: apply H4|4:apply H6]
- |5: intro; cases l2 in H7 H9; intros; [cases H9; reflexivity]
- simplify in H7 ⊢ %; apply H7; intro; destruct H10;
- |6: intro; cases l3 in H8 H9; intros; [cases H9; reflexivity]
- simplify in H8 ⊢ %; apply H8; intro; destruct H10;]
- clear aux H5;
- simplify in match (\fst 〈?,?〉) in H9 H10 H11 H12;
- simplify in match (\snd 〈?,?〉) in H9 H10 H11 H12;
- split;
- [1: left; reflexivity;
- |2: cases H10; cases H12; clear H15 H16 H12 H7 H8 H11 H10;
- cases H9; clear H9;
- [1: lapply (H14 O) as K1; clear H14; change in K1 with (nth_base w1 O = nth_base w2 O);
- split;
- [1: apply (move_head_sorted ??? H4 H5 H7); STOP
-
-
-
- unfold rebase_spec_aux; intros; cases l1 in H2 H4 H6; intros; [ simplify in H2; destruct H2;]
- lapply H6 as H7; [2: intro X; destruct X] clear H6 H5;
- rewrite > H7; split; [right; simplify;
-
- split; [left;reflexivity]
- split;
-
-,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 *)
-]
-elim devil;
-qed.
-
-include "Q/q/qtimes.ma".
-
-let rec area (l:list bar) on l ≝
- match l with
- [ nil ⇒ OQ
- | cons he tl ⇒ area tl + Qpos (\fst he) * ⅆ[OQ,\snd he]].
-
-alias symbol "pi1" = "exT \fst".
-alias symbol "minus" = "Q minus".
-alias symbol "exists" = "CProp exists".
-definition minus_spec_bar ≝
- λf,g,h:list bar.
- same_bases f g → len f = len g →
- ∀s,i:ℚ. \snd (\fst (value (mk_q_f s h) i)) =
- \snd (\fst (value (mk_q_f s f) i)) - \snd (\fst (value (mk_q_f s g) i)).
-
-definition minus_spec ≝
- λf,g:q_f.
- ∃h:q_f.
- ∀i:ℚ. \snd (\fst (value h i)) =
- \snd (\fst (value f i)) - \snd (\fst (value g i)).
-
-definition eject_bar : ∀P:list bar → CProp.(∃l:list bar.P l) → list bar ≝
- λP.λp.match p with [ex_introT x _ ⇒ x].
-definition inject_bar ≝ ex_introT (list bar).
-
-coercion inject_bar with 0 1 nocomposites.
-coercion eject_bar with 0 0 nocomposites.
-
-lemma minus_q_f : ∀f,g. minus_spec f g.
-intros;
-letin aux ≝ (
- let rec aux (l1, l2 : list bar) on l1 ≝
- match l1 with
- [ nil ⇒ []
- | cons he1 tl1 ⇒
- match l2 with
- [ nil ⇒ []
- | cons he2 tl2 ⇒ 〈\fst he1, \snd he1 - \snd he2〉 :: aux tl1 tl2]]
- in aux : ∀l1,l2 : list bar.∃h.minus_spec_bar l1 l2 h);
-[2: intros 4; simplify in H3; destruct H3;
-|3: intros 4; simplify in H3; cases l1 in H2; [2: intro X; simplify in X; destruct X]
- intros; rewrite > (value_OQ_e (mk_q_f s []) i); [2: reflexivity]
- rewrite > q_elim_minus; rewrite > q_plus_OQ; reflexivity;
-|1: cases (aux l2 l3); unfold in H2; intros 4;
- simplify in ⊢ (? ? (? ? ? (? ? ? (? % ?))) ?);
- cases (q_cmp i (s + Qpos (\fst b)));
-
-
-
-definition excess ≝
- λf,g.∃i.\snd (\fst (value f i)) < \snd (\fst (value g i)).
-
--- /dev/null
+(**************************************************************************)
+(* ___ *)
+(* ||M|| *)
+(* ||A|| A project by Andrea Asperti *)
+(* ||T|| *)
+(* ||I|| Developers: *)
+(* ||T|| The HELM team. *)
+(* ||A|| http://helm.cs.unibo.it *)
+(* \ / *)
+(* \ / This file is distributed under the terms of the *)
+(* v GNU General Public License Version 2 *)
+(* *)
+(**************************************************************************)
+
+include "models/q_function.ma".
+
+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: ∀l1,l2:q_f.∃p:q_f × q_f.rebase_spec l1 l2 p.
+intros 2 (f1 f2); cases f1 (b1 Hs1 Hb1 He1); cases f2 (b2 Hs2 Hb2 He2); clear f1 f2;
+alias symbol "leq" = "natural 'less or equal to'".
+alias symbol "minus" = "Q minus".
+letin aux ≝ (
+let rec aux (l1,l2:list bar) (n : nat) on n : (list bar) × (list bar) ≝
+match n with
+[ O ⇒ 〈[], []〉
+| S m ⇒
+ match l1 with
+ [ nil ⇒ 〈copy l2, l2〉
+ | cons he1 tl1 ⇒
+ match l2 with
+ [ nil ⇒ 〈l1, copy l1〉
+ | cons he2 tl2 ⇒
+ let base1 ≝ \fst he1 in
+ let base2 ≝ \fst he2 in
+ let height1 ≝ \snd he1 in
+ let height2 ≝ \snd he2 in
+ match q_cmp base1 base2 with
+ [ q_leq Hp1 ⇒
+ match q_cmp base2 base1 with
+ [ q_leq Hp2 ⇒
+ let rc ≝ aux tl1 tl2 m in
+ 〈he1 :: \fst rc,he2 :: \snd rc〉
+ | q_gt Hp ⇒
+ let rest ≝ base2 - base1 in
+ let rc ≝ aux tl1 (〈rest,height2〉 :: tl2) m in
+ 〈〈base1,height1〉 :: \fst rc,〈base1,height2〉 :: \snd rc〉]
+ | q_gt Hp ⇒
+ let rest ≝ base1 - base2 in
+ let rc ≝ aux (〈rest,height1〉 :: tl1) tl2 m in
+ 〈〈base2,height1〉 :: \fst rc,〈base2,height2〉 :: \snd rc〉]]]]
+in aux : ∀l1,l2,m.∃z.\len l1 + \len l2 ≤ m → rebase_spec_aux l1 l2 z);
+[7: clearbody aux; cases (aux b1 b2 (\len b1 + \len b2)) (res Hres);
+ exists; [split; constructor 1; [apply (\fst res)|5:apply (\snd res)]]
+ [1,4: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); assumption;
+ |2,5: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); lapply (H5 O) as K;
+ clear H1 H2 H3 H4 H5 H6 H7 Hres aux; unfold nth_base;
+ cases H in K He1 He2 Hb1 Hb2; simplify; intros; assumption;
+ |3,6: apply hide; cases (Hres (le_n ?) Hs1 He1 Hs2 He2);
+ cases H in He1 He2; simplify; intros;
+ [1,6,8,12: assumption;
+ |2,7: rewrite > len_copy; generalize in match (\len ?); intro X;
+ cases X; [1,3: reflexivity] simplify;
+ [apply (copy_OQ ys n);|apply (copy_OQ xs n);]
+ |3,4,5: rewrite < H8; assumption;
+ |9,10,11: rewrite < H9; assumption]]
+ split; cases (Hres (le_n ?) Hs1 He1 Hs2 He2); unfold same_values; intros;
+ [1: assumption
+ |2,3: simplify in match (\snd 〈?,?〉); simplify in match (\fst 〈?,?〉);
+ apply same_values_simpl_to_same_values; assumption]
+|3: cut (\fst b3 = \fst b) as E; [2: apply q_le_to_le_to_eq; assumption]
+ clear H6 H5 H4 H3 He2 Hb2 Hs2 b2 He1 Hb1 Hs1 b1; cases (aux l2 l3 n1);
+ clear aux; intro K; simplify in K; rewrite <plus_n_Sm in K;
+ lapply le_S_S_to_le to K as W; lapply lt_to_le to W as R;
+ simplify in match (? ≪w,H3≫); intros; cases (H3 R); clear H3 R W K;
+ [2,4: apply (sorted_tail q2_lt);[apply b|3:apply b3]assumption;
+ |3: cases l2 in H5; simplify; intros; try reflexivity; assumption;
+ |5: cases l3 in H7; simplify; intros; try reflexivity; assumption;]
+ constructor 1; simplify in match (\fst 〈?,?〉); simplify in match (\snd 〈?,?〉);
+ [1: cases b in E H5 H7 H11 H14; cases b3; intros (E H5 H7 H11 H14); simplify in E;
+ destruct E; constructor 3;
+ [ cases H8 in H5 H7; intros; [1,6:reflexivity|3,4,5: assumption;]
+ simplify; rewrite > H3; rewrite > len_copy; elim (\len ys); [reflexivity]
+ symmetry; apply (copy_OQ ys n2);
+ | cases H8 in H5 H7; simplify; intros; [2,6:reflexivity|3,4,5: assumption]
+ simplify; rewrite > H5; rewrite > len_copy; elim (\len xs); [reflexivity]
+ symmetry; apply (copy_OQ xs n2);]
+ |2: apply (aux_preserves_sorting ? b3 ??? H8); assumption;
+ |3: apply (aux_preserves_sorting2 ? b3 ??? H8); try assumption;
+ try reflexivity; cases (inversion_sorted ?? H4);[2:rewrite >H3; apply (sorted_one q2_lt);]
+ cases l2 in H3 H4; intros; [apply (sorted_one q2_lt)]
+ apply (sorted_cons q2_lt);[2:apply (sorted_tail q2_lt ?? H3);] whd;
+ rewrite > E; assumption;
+ |4: apply I
+ |5: apply I
+ |6: intro; elim i; intros; simplify; solve [symmetry;assumption|apply H13]
+ |7: unfold; intros; cases H8 in H13 H14 H15 Hi1 Hi2 H17 H18 H3 H16; intros;
+ [1: simplify in match (\fst 〈?,?〉) in H16 H17 H20 H21 H22 H23 ⊢ %;
+ cases (q_cmp (Qpos input) b1);
+ [1: do 2 (rewrite > value_head; [id|assumption]); reflexivity;
+ |2: do 2 (rewrite > value_tail;[id|assumption]); apply H16;]
+ |2: simplify in match (\fst 〈?,?〉) in H16 H17 H20 H21 H22 H23 ⊢ %;
+ cases (q_cmp (Qpos input) b1);
+ [1: rewrite > value_head; [2:assumption]
+ |2: rewrite > value_tail;[2:assumption]
+ simplify in H15;
+ ]
+ |8:
+
+
+include "Q/q/qtimes.ma".
+
+let rec area (l:list bar) on l ≝
+ match l with
+ [ nil ⇒ OQ
+ | cons he tl ⇒ area tl + Qpos (\fst he) * ⅆ[OQ,\snd he]].
+
+alias symbol "pi1" = "exT \fst".
+alias symbol "minus" = "Q minus".
+alias symbol "exists" = "CProp exists".
+definition minus_spec_bar ≝
+ λf,g,h:list bar.
+ same_bases f g → len f = len g →
+ ∀s,i:ℚ. \snd (\fst (value (mk_q_f s h) i)) =
+ \snd (\fst (value (mk_q_f s f) i)) - \snd (\fst (value (mk_q_f s g) i)).
+
+definition minus_spec ≝
+ λf,g:q_f.
+ ∃h:q_f.
+ ∀i:ℚ. \snd (\fst (value h i)) =
+ \snd (\fst (value f i)) - \snd (\fst (value g i)).
+
+definition eject_bar : ∀P:list bar → CProp.(∃l:list bar.P l) → list bar ≝
+ λP.λp.match p with [ex_introT x _ ⇒ x].
+definition inject_bar ≝ ex_introT (list bar).
+
+coercion inject_bar with 0 1 nocomposites.
+coercion eject_bar with 0 0 nocomposites.
+
+lemma minus_q_f : ∀f,g. minus_spec f g.
+intros;
+letin aux ≝ (
+ let rec aux (l1, l2 : list bar) on l1 ≝
+ match l1 with
+ [ nil ⇒ []
+ | cons he1 tl1 ⇒
+ match l2 with
+ [ nil ⇒ []
+ | cons he2 tl2 ⇒ 〈\fst he1, \snd he1 - \snd he2〉 :: aux tl1 tl2]]
+ in aux : ∀l1,l2 : list bar.∃h.minus_spec_bar l1 l2 h);
+[2: intros 4; simplify in H3; destruct H3;
+|3: intros 4; simplify in H3; cases l1 in H2; [2: intro X; simplify in X; destruct X]
+ intros; rewrite > (value_OQ_e (mk_q_f s []) i); [2: reflexivity]
+ rewrite > q_elim_minus; rewrite > q_plus_OQ; reflexivity;
+|1: cases (aux l2 l3); unfold in H2; intros 4;
+ simplify in ⊢ (? ? (? ? ? (? ? ? (? % ?))) ?);
+ cases (q_cmp i (s + Qpos (\fst b)));
+
+
+
+definition excess ≝
+ λf,g.∃i.\snd (\fst (value f i)) < \snd (\fst (value g i)).
+