(* -*- coding: utf-8 -*- *)
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Local Open Scope R_scope.
Set Implicit Arguments.
(********************************************)
(**           Riemann's Integral            *)
(********************************************)
Definition Riemann_integrable (f:R -> R) (a b:R) : Type :=
forall eps:posreal,
{ phi:StepFun a b &
{ psi:StepFun a b |
(forall t:R,
Rmin a b <= t <= Rmax a b -> Rabs (f t - phi t) <= psi t) /\
Rabs (RiemannInt_SF psi) < eps } }.
Definition phi_sequence (un:nat -> posreal) (f:R -> R)
(a b:R) (pr:Riemann_integrable f a b) (n:nat) :=
projT1 (pr (un n)).
Definition RinvN (N:nat) : posreal := mkposreal _ (RinvN_pos N).
intros f g a b fg rif eps; destruct (rif eps) as [phi [psi [P1 P2]]].
exists phi; exists psi;split;[ | assumption ].
intros t intt; rewrite <- fg;[ | assumption].
apply P1; assumption.
Qed.
(**********)
Definition RiemannInt (f:R -> R) (a b:R) (pr:Riemann_integrable f a b) : R :=
let (a,_) := RiemannInt_exists pr RinvN RinvN_cv in a.
(***************************************)
(** C°([a,b]) is included in L1([a,b]) *)
(***************************************)
Fixpoint SubEquiN (N:nat) (x y:R) (del:posreal) : Rlist :=
match N with
| O => cons y nil
| S p => cons x (SubEquiN p (x + del) y del)
end.
Definition max_N (a b:R) (del:posreal) (h:a < b) : nat :=
let (N,_) := maxN del h in N.
Definition SubEqui (a b:R) (del:posreal) (h:a < b) : Rlist :=
SubEquiN (S (max_N del h)) a b del.

Lemma RiemannInt_P7 : forall (f:R -> R) (a:R), Riemann_integrable f a a.