End RInt_val.
(** ** From SF_seq to StepFun *)
(** Alternative Chasles relation *)
Fixpoint seq_cut_down' (s : seq (R*R)) (x x0 : R) : seq (R*R) :=
match s with
| [::] => [:: (x,x0)]
| h :: t =>
match Rle_dec (fst h) x with
| right _ => [:: (x,snd h)]
| left _ => h :: (seq_cut_down' t x (snd h))
end
end.
Fixpoint seq_cut_up' (s : seq (R*R)) (x x0 : R) : seq (R*R) :=
match s with
| [::] => [:: (x,x0)]
| h :: t =>
match Rle_dec (fst h) x with
| right _ => (x,x0)::h::t
| left _ => seq_cut_up' t x (snd h)
end
end.
Definition SF_cut_down' (sf : @SF_seq R) (x : R) x0 :=
let s := seq_cut_down' ((SF_h sf,x0) :: (SF_t sf)) x x0 in
mkSF_seq (fst (head (SF_h sf,x0) s)) (behead s).
Definition SF_cut_up' (sf : @SF_seq R) (x : R) x0 :=
let s := seq_cut_up' ((SF_h sf,x0) :: (SF_t sf)) x x0 in
mkSF_seq (fst (head (SF_h sf,x0) s)) (behead s).

(* Specifications: *)
Lemma SF_Chasles {V : ModuleSpace R_AbsRing} (f : R -> V) (s : SF_seq) x x0 :
(SF_h s <= x <= last (SF_h s) (unzip1 (SF_t s))) ->
Riemann_sum f s =
plus (Riemann_sum f (SF_cut_down' s x x0)) (Riemann_sum f (SF_cut_up' s x x0)).
Lemma seq_cut_up_head' (s : seq (R*R)) x x0 z :
fst (head z (seq_cut_up' s x x0)) = x.