(** * The sign function *)
Definition sign (x : R) :=
match total_order_T 0 x with
| inleft (left _) => 1
| inleft (right _) => 0
| inright _ => -1
end.

(* Specifications: *)
Lemma sign_0 : sign 0 = 0.
Lemma sign_opp (x : R) : sign (-x) = - sign x.
Lemma sign_eq_1 (x : R) : 0 < x -> sign x = 1.
Lemma sign_eq_m1 (x : R) : x < 0 -> sign x = -1.
Lemma sign_le (x y : R) : x <= y -> sign x <= sign y.
Lemma sign_ge_0 (x : R) : 0 <= x -> 0 <= sign x.
Lemma sign_le_0 (x : R) : x <= 0 -> sign x <= 0.
Lemma sign_neq_0 (x : R) : x <> 0 -> sign x <> 0.
Lemma sign_mult (x y : R) : sign (x * y) = sign x * sign y.
Lemma sign_min_max (a b : R) :
sign (b - a) * (Rmax a b - Rmin a b) = b - a.
Lemma sum_INR : forall n, sum_f_R0 INR n = INR n * (INR n + 1) / 2.
(** * ssreflect.seq *)
(** Finite subdivision *)
Lemma interval_finite_subdiv (a b : R) (eps : posreal) : (a <= b) ->
{l : seq R | head 0 l = a /\ last 0 l = b /\
forall i, (S i < size l)%nat -> nth 0 l i < nth 0 l (S i) <= nth 0 l i + eps}.
Lemma interval_finite_subdiv_between (a b : R) (eps : posreal) (Hab : a <= b) :
let l := proj1_sig (interval_finite_subdiv a b eps Hab) in
forall i, (i < size l)%nat -> a <= nth 0 l i <= b.
(** Notations *)
Lemma SSR_leq (n m : nat) : is_true (ssrnat.leq n m) <-> (n <= m)%nat.
Lemma SSR_minus (n m : nat) : ssrnat.subn n m = (n - m)%nat.
(** rcons *)
Lemma rcons_ind {T : Type} (P : seq T -> Type) :
P [::] -> (forall (s : seq T) (t : T), P s -> P (rcons s t)) -> forall s, P s.
Lemma rcons_dec {T : Type} (P : seq T -> Type) :
(P [::]) -> (forall s t, P (rcons s t)) -> forall s, P s.
Lemma size_rcons_pos {T : Type} (s : seq T) (t : T) : (0 < size (rcons s t))%nat.
Lemma foldr_rcons {T T0 : Type} : forall (f : T0 -> T -> T) x0 s t,
foldr f x0 (rcons s t) = foldr f (f t x0) s.
Lemma foldl_rcons {T T0 : Type} : forall (f : T -> T0 -> T) x0 s t,
foldl f x0 (rcons s t) = f (foldl f x0 s) t.
(* head, last, behead and belast *)
Lemma head_rcons {T : Type} (x0 : T) (s : seq T) (t : T) : head x0 (rcons s t) = head t s.
Lemma behead_rcons {T : Type} (s : seq T) (t : T) :
(0 < size s)%nat ->  behead (rcons s t) = rcons (behead s) t.