(** * SF_seq for Chasles *)
Fixpoint seq_cut_down (s : seq (R*R)) (x : R) : seq (R*R) :=
match s with
| [::] => [:: (x,x)]
| h :: t =>
match Rle_dec (fst h) x with
| right _ => [:: (x,Rmin (snd h) x)]
| left _ => h :: (seq_cut_down t x)
end
end.
Fixpoint seq_cut_up (s : seq (R*R)) (x : R) : seq (R*R) :=
match s with
| [::] => [:: (x,x)]
| h :: t =>
match Rle_dec (fst h) x with
| right _ => (x,x)::(fst h,Rmax (snd h) x)::t
| left _ => seq_cut_up t x
end
end.
Definition SF_cut_down (sf : @SF_seq R) (x : R) :=
let s := seq_cut_down ((SF_h sf,SF_h sf) :: (SF_t sf)) x in
mkSF_seq (fst (head (SF_h sf,SF_h sf) s)) (behead s).
Definition SF_cut_up (sf : @SF_seq R) (x : R) :=
let s := seq_cut_up ((SF_h sf,SF_h sf) :: (SF_t sf)) x in
mkSF_seq (fst (head (SF_h sf,SF_h sf) s)) (behead s).

Lemma SF_cut_down_step s x eps :
SF_h s <= x <= last (SF_h s) (SF_lx s) ->
seq_step (SF_lx s) < eps
-> seq_step (SF_lx (SF_cut_down s x)) < eps.