(** sorted *)
Fixpoint sorted {T : Type} (Ord : T -> T -> Prop) (s : seq T) :=
match s with
| [::] | [:: _] => True
| h0 :: (h1 :: t1) as t0 => Ord h0 h1 /\ sorted Ord t0
end.

(* Specifications: *)
Lemma sorted_nth {T : Type} (Ord : T -> T -> Prop) (s : seq T) :
sorted Ord s <-> (forall i : nat,
(i < Peano.pred (size s))%nat -> forall x0 : T, Ord (nth x0 s i) (nth x0 s (S i))).
Lemma sorted_cat  {T : Type} (Ord : T -> T -> Prop) (s1 s2 : seq T) x0 :
sorted Ord s1 -> sorted Ord s2 -> Ord (last x0 s1)  (head x0 s2)
-> sorted Ord (s1 ++ s2).
Lemma sorted_head (s : seq R) i :
sorted Rle s -> (i < size s)%nat -> forall x0, head x0 s <= nth x0 s i.
Lemma sorted_incr (s : seq R) i j : sorted Rle s -> (i <= j)%nat -> (j < size s)%nat
-> forall x0, nth x0 s i <= nth x0 s j.
Lemma sorted_last (s : seq R) i :
sorted Rle s -> (i < size s)%nat -> forall x0, nth x0 s i <= last x0 s.
Lemma sorted_dec (s : seq R) x0 (x : R) :
sorted Rle s -> head x0 s <= x <= last x0 s ->
{i : nat | nth x0 s i <= x < nth x0 s (S i) /\ (S (S i) < size s)%nat}
+ {nth x0 s (size s - 2)%nat <= x <= nth x0 s (size s - 1)%nat}.
Lemma sorted_compat (s : seq R) :
sorted Rle s <-> ordered_Rlist (seq2Rlist s).