Section SF_map.
Context {T T0 : Type}.
Definition SF_map  (f : T -> T0) (s : SF_seq) : SF_seq :=
mkSF_seq (SF_h s) (map (fun x => (fst x,f (snd x))) (SF_t s)).
End SF_map.
(** * Pointed subvivision *)
Definition pointed_subdiv (ptd : @SF_seq R) :=
forall i : nat, (i < SF_size ptd)%nat ->
nth 0 (SF_lx ptd) i <= nth 0 (SF_ly ptd) i <= nth 0 (SF_lx ptd) (S i).
(** * 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_h s x :
SF_h s <= x -> SF_h (SF_cut_down s x) = SF_h s.