+notation < "s \nbsp 'is_strictly_decreasing'" non associative with precedence 45
+ for @{'strictly_decreasing $s}.
+notation > "s 'is_strictly_decreasing'" non associative with precedence 45
+ for @{'strictly_decreasing $s}.
+interpretation "Ordered set strict decreasing" 'strictly_decreasing s =
+ (strictly_increasing (os_r _) s).
+
+definition uparrow ≝
+ λC:half_ordered_set.λs:sequence C.λu:C.
+ increasing ? s ∧ supremum ? s u.
+
+interpretation "Ordered set uparrow" 'funion s u = (uparrow (os_l _) s u).
+interpretation "Ordered set downarrow" 'fintersects s u = (uparrow (os_r _) s u).
+
+lemma h_trans_increasing:
+ ∀C:half_ordered_set.∀a:sequence C.increasing ? a →
+ ∀n,m:nat_ordered_set. n ≤ m → a n ≤≤ a m.
+intros 5 (C a Hs n m); elim m; [
+ rewrite > (le_n_O_to_eq n (not_lt_to_le O n H));
+ intro X; cases (hos_coreflexive ? (a n) X);]
+cases (le_to_or_lt_eq ?? (not_lt_to_le (S n1) n H1)); clear H1;
+[2: rewrite > H2; intro; cases (hos_coreflexive ? (a (S n1)) H1);
+|1: apply (hle_transitive ???? (H ?) (Hs ?));
+ intro; whd in H1; apply (not_le_Sn_n n); apply (transitive_le ??? H2 H1);]
+qed.
+
+notation "'trans_increasing'" non associative with precedence 90 for @{'trans_increasing}.
+notation "'trans_decreasing'" non associative with precedence 90 for @{'trans_decreasing}.
+
+interpretation "trans_increasing" 'trans_increasing = (h_trans_increasing (os_l _)).
+interpretation "trans_decreasing" 'trans_decreasing = (h_trans_increasing (os_r _)).
+
+lemma hint_nat :
+ Type_of_ordered_set nat_ordered_set →
+ hos_carr (os_l (nat_ordered_set)).
+intros; assumption;
+qed.
+
+coercion hint_nat nocomposites.
+
+lemma h_trans_increasing_exc:
+ ∀C:half_ordered_set.∀a:sequence C.increasing ? a →
+ ∀n,m:nat_ordered_set. m ≰≰ n → a n ≤≤ a m.
+intros 5 (C a Hs n m); elim m; [cases (not_le_Sn_O n H);]
+intro; apply H;
+[1: change in n1 with (hos_carr (os_l nat_ordered_set));
+ change with (n<n1);
+ cases (le_to_or_lt_eq ?? H1); [apply le_S_S_to_le;assumption]
+ cases (Hs n); rewrite < H3 in H2; assumption;
+|2: cases (hos_cotransitive ? (a n) (a (S n1)) (a n1) H2); [assumption]
+ cases (Hs n1); assumption;]
+qed.
+
+notation "'trans_increasing_exc'" non associative with precedence 90 for @{'trans_increasing_exc}.
+notation "'trans_decreasing_exc'" non associative with precedence 90 for @{'trans_decreasing_exc}.
+
+interpretation "trans_increasing_exc" 'trans_increasing_exc = (h_trans_increasing_exc (os_l _)).
+interpretation "trans_decreasing_exc" 'trans_decreasing_exc = (h_trans_increasing_exc (os_r _)).
+
+alias symbol "exists" = "CProp exists".
+lemma nat_strictly_increasing_reaches:
+ ∀m:sequence nat_ordered_set.
+ m is_strictly_increasing → ∀w.∃t.m t ≰ w.
+intros; elim w;
+[1: cases (nat_discriminable O (m O)); [2: cases (not_le_Sn_n O (ltn_to_ltO ?? H1))]
+ cases H1; [exists [apply O] apply H2;]
+ exists [apply (S O)] lapply (H O) as H3; rewrite < H2 in H3; assumption
+|2: cases H1 (p Hp); cases (nat_discriminable (S n) (m p));
+ [1: cases H2; clear H2;
+ [1: exists [apply p]; assumption;
+ |2: exists [apply (S p)]; rewrite > H3; apply H;]
+ |2: cases (?:False); change in Hp with (n<m p);
+ apply (not_le_Sn_n (m p));
+ apply (transitive_le ??? H2 Hp);]]
+qed.
+
+lemma h_selection_uparrow:
+ ∀C:half_ordered_set.∀m:sequence nat_ordered_set.
+ m is_strictly_increasing →
+ ∀a:sequence C.∀u.uparrow ? a u → uparrow ? ⌊x,a (m x)⌋ u.
+intros (C m Hm a u Ha); cases Ha (Ia Su); cases Su (Uu Hu); repeat split;
+[1: intro n; simplify; apply (h_trans_increasing_exc ? a Ia); apply (Hm n);
+|2: intro n; simplify; apply Uu;
+|3: intros (y Hy); simplify; cases (Hu ? Hy);
+ cases (nat_strictly_increasing_reaches ? Hm w);
+ exists [apply w1]; cases (hos_cotransitive ? (a w) y (a (m w1)) H); [2:assumption]
+ cases (h_trans_increasing_exc ?? Ia w (m w1) H1); assumption;]
+qed.
+
+notation "'selection_uparrow'" non associative with precedence 90 for @{'selection_uparrow}.
+notation "'selection_downarrow'" non associative with precedence 90 for @{'selection_downarrow}.
+
+interpretation "selection_uparrow" 'selection_uparrow = (h_selection_uparrow (os_l _)).
+interpretation "selection_downarrow" 'selection_downarrow = (h_selection_uparrow (os_r _)).
+
+(* Definition 2.7 *)
+definition order_converge ≝
+ λO:ordered_set.λa:sequence O.λx:O.
+ exT23 (sequence O) (λl.l ↑ x) (λu.u ↓ x)
+ (λl,u:sequence O.∀i:nat. (l i) is_infimum ⌊w,a (w+i)⌋ ∧
+ (u i) is_supremum ⌊w,a (w+i)⌋).
+
+notation < "a \nbsp (\cir \atop (\horbar\triangleright)) \nbsp x" non associative with precedence 45
+ for @{'order_converge $a $x}.
+notation > "a 'order_converges' x" non associative with precedence 45
+ for @{'order_converge $a $x}.
+interpretation "Order convergence" 'order_converge s u = (order_converge _ s u).
+
+(* Definition 2.8 *)
+record segment (O : Type) : Type ≝ {
+ seg_l_ : O;
+ seg_u_ : O
+}.
+
+notation > "𝕦_term 90 s p" non associative with precedence 45 for @{'upp $s $p}.
+notation "𝕦 \sub term 90 s p" non associative with precedence 45 for @{'upp $s $p}.
+notation > "𝕝_term 90 s p" non associative with precedence 45 for @{'low $s $p}.
+notation "𝕝 \sub term 90 s p" non associative with precedence 45 for @{'low $s $p}.
+
+definition seg_u ≝
+ λO:half_ordered_set.λs:segment O.λP: O → CProp.
+ wloss O ? (λl,u.P l) (seg_u_ ? s) (seg_l_ ? s).
+definition seg_l ≝
+ λO:half_ordered_set.λs:segment O.λP: O → CProp.
+ wloss O ? (λl,u.P l) (seg_l_ ? s) (seg_u_ ? s).
+
+interpretation "uppper" 'upp s P = (seg_u (os_l _) s P).
+interpretation "lower" 'low s P = (seg_l (os_l _) s P).
+interpretation "uppper dual" 'upp s P = (seg_l (os_r _) s P).
+interpretation "lower dual" 'low s P = (seg_u (os_r _) s P).
+
+definition in_segment ≝
+ λO:half_ordered_set.λs:segment O.λx:O.
+ wloss O ? (λp1,p2.p1 ∧ p2) (seg_l ? s (λl.l ≤≤ x)) (seg_u ? s (λu.x ≤≤ u)).
+
+notation "‡O" non associative with precedence 90 for @{'segment $O}.
+interpretation "Ordered set sergment" 'segment x = (segment x).
+
+interpretation "Ordered set sergment in" 'mem x s = (in_segment _ s x).
+
+definition segment_ordered_set_carr ≝
+ λO:half_ordered_set.λs:‡O.∃x.x ∈ s.
+definition segment_ordered_set_exc ≝
+ λO:half_ordered_set.λs:‡O.
+ λx,y:segment_ordered_set_carr O s.hos_excess_ O (\fst x) (\fst y).
+lemma segment_ordered_set_corefl:
+ ∀O,s. coreflexive ? (wloss O ? (segment_ordered_set_exc O s)).
+intros 3; cases x; cases (wloss_prop O);
+generalize in match (hos_coreflexive O w);
+rewrite < (H1 ? (segment_ordered_set_exc O s));
+rewrite < (H1 ? (hos_excess_ O)); intros; assumption;
+qed.
+lemma segment_ordered_set_cotrans :
+ ∀O,s. cotransitive ? (wloss O ? (segment_ordered_set_exc O s)).
+intros 5 (O s x y z); cases x; cases y ; cases z; clear x y z;
+generalize in match (hos_cotransitive O w w1 w2);
+cases (wloss_prop O);
+do 3 rewrite < (H3 ? (segment_ordered_set_exc O s));
+do 3 rewrite < (H3 ? (hos_excess_ O)); intros; apply H4; assumption;
+qed.