(************************************************************************)
(*         *   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)         *)
(************************************************************************)
(*********************************************************)
(**          Definition of the limit                     *)
(*                                                       *)
(*********************************************************)
Local Open Scope R_scope.
(*********)
Definition mul_factor (l l':R) := / (1 + (Rabs l + Rabs l')).
intros; apply Rmin_Rgt_r; split.
exact Rlt_0_1.
exact (mul_factor_gt eps l l' H).
Qed.
(*******************************)
(** *   Metric space           *)
(*******************************)
(*********)
Record Metric_Space : Type :=
{Base : Type;
dist : Base -> Base -> R;
dist_pos : forall x y:Base, dist x y >= 0;
dist_sym : forall x y:Base, dist x y = dist y x;
dist_refl : forall x y:Base, dist x y = 0 <-> x = y;
dist_tri : forall x y z:Base, dist x y <= dist x z + dist z y}.
(*******************************)
(** ** Limit in Metric space   *)
(*******************************)
(*********)
Definition limit_in (X X':Metric_Space) (f:Base X -> Base X')
(D:Base X -> Prop) (x0:Base X) (l:Base X') :=
forall eps:R,
eps > 0 ->
exists alp : R,
alp > 0 /\
(forall x:Base X, D x /\ (dist X) x x0 < alp -> (dist X') (f x) l < eps).
(*******************************)
(** **  R is a metric space    *)
(*******************************)
(*********)
Definition R_met : Metric_Space :=
Build_Metric_Space R R_dist R_dist_pos R_dist_sym R_dist_refl R_dist_tri.
Declare Equivalent Keys dist R_dist.
(*******************************)
(** *      Limit 1 arg         *)
(*******************************)
(*********)
Definition Dgf (Df Dg:R -> Prop) (f:R -> R) (x:R) := Df x /\ Dg (f x).
(*********)
Definition limit1_in (f:R -> R) (D:R -> Prop) (l x0:R) : Prop :=
limit_in R_met R_met f D x0 l.
(*********)
Definition adhDa (D:R -> Prop) (a:R) : Prop :=
forall alp:R, alp > 0 ->  exists x : R, D x /\ R_dist x a < alp.

(*********)
Lemma limit_comp :
forall (f g:R -> R) (Df Dg:R -> Prop) (l l' x0:R),
limit1_in f Df l x0 ->
limit1_in g Dg l' l -> limit1_in (fun x:R => g (f x)) (Dgf Df Dg f) l' x0.