Section SF_fun.
Context {T : Type}.
Fixpoint SF_fun_aux (h : R*T) (s : seq (R*T)) (y0 : T) (x : R) :=
match s with
| [::] => match Rle_dec x (fst h) with
| left _ => snd h
| right _ => y0
end
| h0 :: s0 => match Rlt_dec x (fst h) with
| left _ => snd h
| right _ => SF_fun_aux h0 s0 y0 x
end
end.
Definition SF_fun (s : SF_seq) (y0 : T) (x : R) :=
SF_fun_aux (SF_h s,y0) (SF_t s) y0 x.

Lemma SF_fun_incr (s : SF_seq) (y0 : T) (x : R) Hs Hx :
SF_fun s y0 x =
match (sorted_dec (SF_lx s) 0 x Hs Hx) with
| inleft H => nth y0 (SF_ly s) (proj1_sig H)
| inright _ =>  nth y0 (SF_ly s) (SF_size s -1)%nat
end.