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)).
Definition SF_val_seq {T} (f : R -> T) (a b : R) (n : nat) : SF_seq :=
SF_seq_f2 (fun x y => f ((x+y)/2)) (unif_part a b n).
Definition SF_val_fun {T} (f : R -> T) (a b : R) (n : nat) (x : R) : T :=
SF_fun_f2 (fun x y => f ((x+y)/2)) (unif_part a b n) x.
Definition SF_val_ly {T} (f : R -> T) (a b : R) (n : nat) : seq T :=
behead (pairmap (fun x y => f ((x+y)/2)) 0 (unif_part a b n)).
(** ** A proper filter on SF_seq *)

Lemma Riemann_fine_unif_part :
forall (f : R -> R -> R) (a b : R) (n : nat),
(forall a b, a <= b -> a <= f a b <= b) ->
a <= b ->
seq_step (SF_lx (SF_seq_f2 f (unif_part a b n))) <= (b - a) / (INR n + 1) /\
pointed_subdiv (SF_seq_f2 f (unif_part a b n)) /\
SF_h (SF_seq_f2 f (unif_part a b n)) = a /\
last (SF_h (SF_seq_f2 f (unif_part a b n))) (SF_lx (SF_seq_f2 f (unif_part a b n))) = b.