Definition Riemann_fine (a b : R) :=
within (fun ptd => pointed_subdiv ptd /\ SF_h ptd = Rmin a b /\ last (SF_h ptd) (SF_lx ptd) = Rmax a b)
(locally_dist (fun ptd => seq_step (SF_lx ptd))).
Global Instance Riemann_fine_filter :
forall a b, ProperFilter (Riemann_fine a b).
(** * Riemann sums *)
(** Riemann_sum *)
Section Riemann_sum.
Context {V : ModuleSpace R_Ring}.
Definition Riemann_sum (f : R -> V) (ptd : SF_seq) : V :=
foldr plus zero (pairmap (fun x y => (scal (fst y - fst x) (f (snd y)))) (SF_h ptd,zero) (SF_t ptd)).

Lemma Riemann_sum_rcons (f : R -> V) ptd l0 :
Riemann_sum f (SF_rcons ptd l0) =
plus (Riemann_sum f ptd) (scal (fst l0 - last (SF_h ptd) (SF_lx ptd)) (f (snd l0))).