-interpretation "lq2" 'lq2 = (list bar).
-
-let rec sum_bases (l:list bar) (i:nat) on i ≝
- match i with
- [ O ⇒ OQ
- | S m ⇒
- match l with
- [ nil ⇒ sum_bases l m + Qpos one
- | cons x tl ⇒ sum_bases tl m + Qpos (\fst x)]].
-
-axiom sum_bases_empty_nat_of_q_ge_OQ:
- ∀q:ℚ.OQ ≤ sum_bases [] (nat_of_q q).
-axiom sum_bases_empty_nat_of_q_le_q:
- ∀q:ℚ.sum_bases [] (nat_of_q q) ≤ q.
-axiom sum_bases_empty_nat_of_q_le_q_one:
- ∀q:ℚ.q < sum_bases [] (nat_of_q q) + Qpos one.
-
-definition eject1 ≝
- λP.λp:∃x:nat × ℚ.P x.match p with [ex_introT p _ ⇒ p].
-coercion eject1.
-definition inject1 ≝ λP.λp:nat × ℚ.λh:P p. ex_introT ? P p h.
-coercion inject1 with 0 1 nocomposites.
-
-definition value :
- ∀f:q_f.∀i:ℚ.∃p:nat × ℚ.
- match q_cmp i (start f) with
- [ q_lt _ ⇒ \snd p = OQ
- | _ ⇒
- And3
- (sum_bases (bars f) (\fst p) ≤ ⅆ[i,start f])
- (ⅆ[i, start f] < sum_bases (bars f) (S (\fst p)))
- (\snd p = \snd (nth (bars f) ▭ (\fst p)))].
+interpretation "lq2" 'lq2 = (list bar).
+
+definition q2_lt := mk_rel bar (λx,y:bar.\fst x < \fst y).
+
+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;
+ bars_sorted : sorted q2_lt bars;
+ bars_begin_OQ : nth_base bars O = OQ;
+ bars_end_OQ : nth_height bars (pred (\len bars)) = OQ
+}.
+
+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.
+
+(*
+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:ℚ.∃j.value_spec f (Qpos i) p j.