+(* Fact 2.5 *)
+lemma supremum_is_upper_bound:
+ ∀C:ordered_set.∀a:sequence C.∀u:C.
+ u is_supremum a → ∀v.v is_upper_bound a → u ≤ v.
+intros 7 (C s u Hu v Hv H); cases Hu (_ H1); clear Hu;
+cases (H1 ? H) (w Hw); apply Hv; assumption;
+qed.
+
+(* Lemma 2.6 *)
+definition strictly_increasing ≝
+ λC:ordered_set.λa:sequence C.∀n:nat.a (S n) ≰ a n.
+definition strictly_decreasing ≝
+ λC:ordered_set.λa:sequence C.∀n:nat.a n ≰ a (S n).
+
+
+notation < "s \nbsp 'is_strictly_increasing'" non associative with precedence 50
+ for @{'strictly_increasing $s}.
+notation > "s 'is_strictly_increasing'" non associative with precedence 50
+ for @{'strictly_increasing $s}.
+interpretation "Ordered set strict increasing" 'strictly_increasing s =
+ (cic:/matita/dama/supremum/strictly_increasing.con _ s).
+notation < "s \nbsp 'is_strictly_decreasing'" non associative with precedence 50
+ for @{'strictly_decreasing $s}.
+notation > "s 'is_strictly_decreasing'" non associative with precedence 50
+ for @{'strictly_decreasing $s}.
+interpretation "Ordered set strict decreasing" 'strictly_decreasing s =
+ (cic:/matita/dama/supremum/strictly_decreasing.con _ s).
+
+notation "a \uparrow u" non associative with precedence 50 for @{'sup_inc $a $u}.
+interpretation "Ordered set supremum of increasing" 'sup_inc s u =
+ (cic:/matita/dama/cprop_connectives/And.ind#xpointer(1/1)
+ (cic:/matita/dama/supremum/increasing.con _ s)
+ (cic:/matita/dama/supremum/supremum.con _ s u)).
+notation "a \downarrow u" non associative with precedence 50 for @{'inf_dec $a $u}.
+interpretation "Ordered set supremum of increasing" 'inf_dec s u =
+ (cic:/matita/dama/cprop_connectives/And.ind#xpointer(1/1)
+ (cic:/matita/dama/supremum/decreasing.con _ s)
+ (cic:/matita/dama/supremum/infimum.con _ s u)).
+
+include "nat/plus.ma".
+include "nat_ordered_set.ma".
+
+alias symbol "nleq" = "Ordered set excess".
+alias symbol "leq" = "Ordered set less or equal than".
+lemma trans_increasing:
+ ∀C:ordered_set.∀a:sequence C.a is_increasing → ∀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 (os_coreflexive ?? X);]
+cases (le_to_or_lt_eq ?? (not_lt_to_le (S n1) n H1)); clear H1;
+[2: rewrite > H2; intro; cases (os_coreflexive ?? H1);
+|1: apply (le_transitive ???? (H ?) (Hs ?));
+ intro; whd in H1; apply (not_le_Sn_n n); apply (transitive_le ??? H2 H1);]
+qed.
+
+lemma trans_increasing_exc:
+ ∀C:ordered_set.∀a:sequence C.a is_increasing → ∀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 (os_carr nat_ordered_set); (* canonical structures *)
+ change with (n<n1); (* is sort elimination not allowed preserved by delta? *)
+ cases (le_to_or_lt_eq ?? H1); [apply le_S_S_to_le;assumption]
+ cases (Hs n); rewrite < H3 in H2; assumption (* ogni goal di tipo Prop non è anche di tipo CProp *)
+|2: cases (os_cotransitive ??? (a n1) H2); [assumption]
+ cases (Hs n1); assumption;]
+qed.
+
+lemma strictly_increasing_reaches:
+ ∀C:ordered_set.∀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 selection:
+ ∀C:ordered_set.∀m:sequence nat_ordered_set.m is_strictly_increasing →
+ ∀a:sequence C.∀u.a ↑ u → (λ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 trans_increasing_exc; [assumption] apply (Hm n);
+|2: intro n; simplify; apply Uu;
+|3: intros (y Hy); simplify; cases (Hu ? Hy);
+ cases (strictly_increasing_reaches C ? Hm w);
+ exists [apply w1]; cases (os_cotransitive ??? (a (m w1)) H); [2:assumption]
+ cases (trans_increasing_exc C ? Ia ?? H1); assumption;]
+qed.
+
+(* Definition 2.7 *)
+alias symbol "exists" = "CProp exists".
+alias symbol "and" = "constructive and".
+definition order_converge ≝
+ λO:ordered_set.λa:sequence O.λx:O.
+ ∃l:sequence O.∃u:sequence O.
+ l is_increasing ∧ u is_decreasing ∧ l ↑ x ∧ u ↓ x ∧
+ ∀i:nat. (l i) is_infimum (λw.a (w+i)) ∧ (u i) is_supremum (λw.a (w+i)).
+
+notation < "a \nbsp (\circ \atop (\horbar\triangleright)) \nbsp x" non associative with precedence 50
+ for @{'order_converge $a $x}.
+notation > "a 'order_converges' x" non associative with precedence 50
+ for @{'order_converge $a $x}.
+interpretation "Order convergence" 'order_converge s u =
+ (cic:/matita/dama/supremum/order_converge.con _ s u).
+
+(* Definition 2.8 *)
+
+definition segment ≝ λO:ordered_set.λa,b:O.λx:O.
+ (cic:/matita/logic/connectives/And.ind#xpointer(1/1) (x ≤ b) (a ≤ x)).
+
+notation "[a,b]" non associative with precedence 50
+ for @{'segment $a $b}.
+interpretation "Ordered set sergment" 'segment a b =
+ (cic:/matita/dama/supremum/segment.con _ a b).
+
+notation "hvbox(x \in break [a,b])" non associative with precedence 50
+ for @{'segment2 $a $b $x}.
+interpretation "Ordered set sergment in" 'segment2 a b x=
+ (cic:/matita/dama/supremum/segment.con _ a b x).
+
+coinductive sigma (A:Type) (P:A→Prop) : Type ≝ sig_in : ∀x.P x → sigma A P.
+
+definition pi1 : ∀A.∀P.sigma A P → A ≝ λA,P,s.match s with [sig_in x _ ⇒ x].
+
+notation < "'fst' \nbsp x" non associative with precedence 50 for @{'pi1 $x}.
+notation < "'snd' \nbsp x" non associative with precedence 50 for @{'pi2 $x}.
+notation > "'fst' x" non associative with precedence 50 for @{'pi1 $x}.
+notation > "'snd' x" non associative with precedence 50 for @{'pi2 $x}.
+interpretation "sigma pi1" 'pi1 x =
+ (cic:/matita/dama/supremum/pi1.con _ _ x).
+
+interpretation "Type exists" 'exists \eta.x =
+ (cic:/matita/dama/supremum/sigma.ind#xpointer(1/1) _ x).
+
+lemma segment_ordered_set:
+ ∀O:ordered_set.∀u,v:O.ordered_set.
+intros (O u v); apply (mk_ordered_set (∃x.x ∈ [u,v]));
+[1: intros (x y); apply (fst x ≰ fst y);
+|2: intro x; cases x; simplify; apply os_coreflexive;
+|3: intros 3 (x y z); cases x; cases y ; cases z; simplify; apply os_cotransitive]
+qed.
+
+notation "hvbox({[a, break b]})" non associative with precedence 90
+ for @{'segment_set $a $b}.
+interpretation "Ordered set segment" 'segment_set a b =
+ (cic:/matita/dama/supremum/segment_ordered_set.con _ a b).
+
+(* Lemma 2.9 *)
+lemma segment_preserves_supremum:
+ ∀O:ordered_set.∀l,u:O.∀a:sequence {[l,u]}.∀x:{[l,u]}.
+ (λn.fst (a n)) is_increasing ∧
+ (fst x) is_supremum (λn.fst (a n)) → a ↑ x.
+intros; split; cases H; clear H;
+[1: apply H1;
+|2: cases H2; split; clear H2;
+ [1: apply H;
+ |2: clear H; intro y0; apply (H3 (fst y0));]]
+qed.
+
+(* Definition 2.10 *)
+coinductive pair (A,B:Type) : Type ≝ prod : ∀a:A.∀b:B.pair A B.
+definition first : ∀A.∀P.pair A P → A ≝ λA,P,s.match s with [prod x _ ⇒ x].
+definition second : ∀A.∀P.pair A P → P ≝ λA,P,s.match s with [prod _ y ⇒ y].
+
+interpretation "pair pi1" 'pi1 x =
+ (cic:/matita/dama/supremum/first.con _ _ x).
+interpretation "pair pi2" 'pi2 x =
+ (cic:/matita/dama/supremum/second.con _ _ x).