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.
End SF_fun.
(** * Particular SF_seq *)
Definition SF_seq_f1 {T : Type} (f1 : R -> T) (P : seq R) : SF_seq :=
mkSF_seq (head 0 P) (pairmap (fun x y => (y, f1 x)) (head 0 P) (behead P)).
Definition SF_seq_f2 {T : Type} (f2 : R -> R -> T) (P : seq R) : SF_seq :=
mkSF_seq (head 0 P) (pairmap (fun x y => (y, f2 x y)) (head 0 P) (behead P)).
(** ** SF_fun *)
Definition SF_fun_f1 {T : Type} (f1 : R -> T) (P : seq R) x : T :=
SF_fun (SF_seq_f1 f1 P) (f1 0) x.
Definition SF_fun_f2 {T : Type} (f2 : R -> R -> T) (P : seq R) x :=
SF_fun (SF_seq_f2 f2 P) (f2 0 0) x.
(** * Uniform partition *)
Definition unif_part (a b : R) (n : nat) : seq R :=
mkseq (fun i => a + (INR i) * (b - a) / (INR n + 1)) (S (S n)).

Lemma unif_part_nat (a b : R) (n : nat) (x : R) : (a <= x <= b) ->
{i : nat |
nth 0 (unif_part a b n) i <= x < nth 0 (unif_part a b n) (S i) /\
(S (S i) < size (unif_part a b n))%nat} +
{nth 0 (unif_part a b n) (n) <= x <=
nth 0 (unif_part a b n) (S n)}.