+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" non associative with precedence 45 for @{'upp $s}.
+notation "𝕦 \sub term 90 s" non associative with precedence 45 for @{'upp $s}.
+notation > "𝕝_term 90 s" non associative with precedence 45 for @{'low $s}.
+notation "𝕝 \sub term 90 s" non associative with precedence 45 for @{'low $s}.
+
+definition seg_u ≝
+ λO:half_ordered_set.λs:segment O.
+ wloss O ?? (λl,u.l) (seg_u_ ? s) (seg_l_ ? s).
+definition seg_l ≝
+ λO:half_ordered_set.λs:segment O.
+ wloss O ?? (λl,u.l) (seg_l_ ? s) (seg_u_ ? s).
+
+interpretation "uppper" 'upp s = (seg_u (os_l _) s).
+interpretation "lower" 'low s = (seg_l (os_l _) s).
+interpretation "uppper dual" 'upp s = (seg_l (os_r _) s).
+interpretation "lower dual" 'low s = (seg_u (os_r _) s).
+
+definition in_segment ≝
+ λO:half_ordered_set.λs:segment O.λx:O.
+ wloss O ?? (λp1,p2.p1 ∧ p2) (seg_l ? s ≤≤ x) (x ≤≤ seg_u ? s).
+
+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.
+
+lemma half_segment_ordered_set:
+ ∀O:half_ordered_set.∀s:segment O.half_ordered_set.
+intros (O a); constructor 1;
+[ apply (segment_ordered_set_carr O a);
+| apply (wloss O);
+| apply (wloss_prop O);
+| apply (segment_ordered_set_exc O a);
+| apply (segment_ordered_set_corefl O a);
+| apply (segment_ordered_set_cotrans ??);
+]
+qed.
+
+lemma segment_ordered_set:
+ ∀O:ordered_set.∀s:‡O.ordered_set.
+intros (O s);
+apply half2full; apply (half_segment_ordered_set (os_l O) s);
+qed.
+
+notation "{[ term 19 s ]}" non associative with precedence 90 for @{'segset $s}.
+interpretation "Ordered set segment" 'segset s = (segment_ordered_set _ s).
+
+(* test :
+ ∀O:ordered_set.∀s: segment (os_l O).∀x:O.
+ in_segment (os_l O) s x
+ =
+ in_segment (os_r O) s x.
+intros; try reflexivity;
+*)
+
+lemma prove_in_segment:
+ ∀O:half_ordered_set.∀s:segment O.∀x:O.
+ (seg_l O s) ≤≤ x → x ≤≤ (seg_u O s) → x ∈ s.
+intros; unfold; cases (wloss_prop O); rewrite < H2;
+split; assumption;
+qed.
+
+lemma cases_in_segment:
+ ∀C:half_ordered_set.∀s:segment C.∀x. x ∈ s → (seg_l C s) ≤≤ x ∧ x ≤≤ (seg_u C s).
+intros; unfold in H; cases (wloss_prop C) (W W); rewrite<W in H; [cases H; split;assumption]
+cases H; split; assumption;
+qed.
+
+definition hint_sequence:
+ ∀C:ordered_set.
+ sequence (hos_carr (os_l C)) → sequence (Type_of_ordered_set C).
+intros;assumption;
+qed.
+
+definition hint_sequence1:
+ ∀C:ordered_set.
+ sequence (hos_carr (os_r C)) → sequence (Type_of_ordered_set_dual C).
+intros;assumption;
+qed.
+
+definition hint_sequence2:
+ ∀C:ordered_set.
+ sequence (Type_of_ordered_set C) → sequence (hos_carr (os_l C)).
+intros;assumption;
+qed.
+
+definition hint_sequence3:
+ ∀C:ordered_set.
+ sequence (Type_of_ordered_set_dual C) → sequence (hos_carr (os_r C)).
+intros;assumption;
+qed.
+
+coercion hint_sequence nocomposites.
+coercion hint_sequence1 nocomposites.
+coercion hint_sequence2 nocomposites.
+coercion hint_sequence3 nocomposites.
+
+(* Lemma 2.9 - non easily dualizable *)
+
+lemma x2sx:
+ ∀O:half_ordered_set.
+ ∀s:segment O.∀x,y:half_segment_ordered_set ? s.
+ \fst x ≰≰ \fst y → x ≰≰ y.
+intros 4; cases x; cases y; clear x y; simplify; unfold hos_excess;
+whd in ⊢ (?→? (% ? ?)? ? ? ? ?); simplify in ⊢ (?→%);
+cases (wloss_prop O) (E E); do 2 rewrite < E; intros; assumption;
+qed.
+
+lemma sx2x:
+ ∀O:half_ordered_set.
+ ∀s:segment O.∀x,y:half_segment_ordered_set ? s.
+ x ≰≰ y → \fst x ≰≰ \fst y.
+intros 4; cases x; cases y; clear x y; simplify; unfold hos_excess;
+whd in ⊢ (? (% ? ?) ?? ? ? ? → ?); simplify in ⊢ (% → ?);
+cases (wloss_prop O) (E E); do 2 rewrite < E; intros; assumption;
+qed.
+
+lemma h_segment_preserves_supremum:
+ ∀O:half_ordered_set.∀s:segment O.
+ ∀a:sequence (half_segment_ordered_set ? s).
+ ∀x:half_segment_ordered_set ? s.
+ increasing ? ⌊n,\fst (a n)⌋ ∧
+ supremum ? ⌊n,\fst (a n)⌋ (\fst x) → uparrow ? a x.
+intros; split; cases H; clear H;
+[1: intro n; lapply (H1 n) as K; clear H1 H2;
+ intro; apply K; clear K; apply (sx2x ???? H);
+|2: cases H2; split; clear H2;
+ [1: intro n; lapply (H n) as K; intro W; apply K;
+ apply (sx2x ???? W);
+ |2: clear H1 H; intros (y0 Hy0); cases (H3 (\fst y0));[exists[apply w]]
+ [1: change in H with (\fst (a w) ≰≰ \fst y0); apply (x2sx ???? H);
+ |2: apply (sx2x ???? Hy0);]]]
+qed.
+
+notation "'segment_preserves_supremum'" non associative with precedence 90 for @{'segment_preserves_supremum}.
+notation "'segment_preserves_infimum'" non associative with precedence 90 for @{'segment_preserves_infimum}.
+
+interpretation "segment_preserves_supremum" 'segment_preserves_supremum = (h_segment_preserves_supremum (os_l _)).
+interpretation "segment_preserves_infimum" 'segment_preserves_infimum = (h_segment_preserves_supremum (os_r _)).
+
+(*
+test segment_preserves_infimum2:
+ ∀O:ordered_set.∀s:‡O.∀a:sequence {[s]}.∀x:{[s]}.
+ ⌊n,\fst (a n)⌋ is_decreasing ∧
+ (\fst x) is_infimum ⌊n,\fst (a n)⌋ → a ↓ x.
+intros; apply (segment_preserves_infimum s a x H);
+qed.
+*)
+
+(* Definition 2.10 *)
+
+alias symbol "pi2" = "pair pi2".
+alias symbol "pi1" = "pair pi1".
+(*
+definition square_segment ≝
+ λO:half_ordered_set.λs:segment O.λx: square_half_ordered_set O.
+ in_segment ? s (\fst x) ∧ in_segment ? s (\snd x).
+*)
+definition convex ≝
+ λO:half_ordered_set.λU:square_half_ordered_set O → Prop.
+ ∀s.U s → le O (\fst s) (\snd s) →
+ ∀y.
+ le O (\fst y) (\snd s) →
+ le O (\fst s) (\fst y) →
+ le O (\snd y) (\snd s) →
+ le O (\fst y) (\snd y) →
+ U y.
+
+(* Definition 2.11 *)
+definition upper_located ≝
+ λO:half_ordered_set.λa:sequence O.∀x,y:O. y ≰≰ x →
+ (∃i:nat.a i ≰≰ x) ∨ (∃b:O.y ≰≰ b ∧ ∀i:nat.a i ≤≤ b).
+
+notation < "s \nbsp 'is_upper_located'" non associative with precedence 45
+ for @{'upper_located $s}.
+notation > "s 'is_upper_located'" non associative with precedence 45
+ for @{'upper_located $s}.
+interpretation "Ordered set upper locatedness" 'upper_located s =
+ (upper_located (os_l _) s).
+
+notation < "s \nbsp 'is_lower_located'" non associative with precedence 45
+ for @{'lower_located $s}.
+notation > "s 'is_lower_located'" non associative with precedence 45
+ for @{'lower_located $s}.
+interpretation "Ordered set lower locatedness" 'lower_located s =
+ (upper_located (os_r _) s).
+
+(* Lemma 2.12 *)
+lemma h_uparrow_upperlocated:
+ ∀C:half_ordered_set.∀a:sequence C.∀u:C.uparrow ? a u → upper_located ? a.
+intros (C a u H); cases H (H2 H3); clear H; intros 3 (x y Hxy);
+cases H3 (H4 H5); clear H3; cases (hos_cotransitive C y x u Hxy) (W W);
+[2: cases (H5 x W) (w Hw); left; exists [apply w] assumption;
+|1: right; exists [apply u]; split; [apply W|apply H4]]
+qed.
+
+notation "'uparrow_upperlocated'" non associative with precedence 90 for @{'uparrow_upperlocated}.
+notation "'downarrow_lowerlocated'" non associative with precedence 90 for @{'downarrow_lowerlocated}.
+
+interpretation "uparrow_upperlocated" 'uparrow_upperlocated = (h_uparrow_upperlocated (os_l _)).
+interpretation "downarrow_lowerlocated" 'downarrow_lowerlocated = (h_uparrow_upperlocated (os_r _)).