(** This file is part of the Coquelicot formalization of real analysis in Coq: http://coquelicot.saclay.inria.fr/  Copyright (C) 2011-2015 Sylvie Boldo #<br /># Copyright (C) 2011-2015 Catherine Lelay #<br /># Copyright (C) 2011-2015 Guillaume Melquiond  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the COPYING file for more details. *)
(** This file first describes [Filter]s that are predicates of type [(T -> Prop) -> Prop] used for limits and neighborhoods.  Then the algebraic hierarchy of the Coquelicot library is given: from the [AbelianGroup] to the [CompleteNormedModule]. Topologies on [R] and [R*R] are also given.  #<br/># More documentation details can be found in #<a href="Coquelicot.Coquelicot.html">Coquelicot.html</a>#. *)
Open Scope R_scope.
(** * Filters *)
(** ** Definitions *)
Class Filter {T : Type} (F : (T -> Prop) -> Prop) := {
filter_true : F (fun _ => True) ;
filter_and : forall P Q : T -> Prop, F P -> F Q -> F (fun x => P x /\ Q x) ;
filter_imp : forall P Q : T -> Prop, (forall x, P x -> Q x) -> F P -> F Q
}.
Global Hint Mode Filter + + : typeclass_instances.
Class ProperFilter' {T : Type} (F : (T -> Prop) -> Prop) := {
filter_not_empty : not (F (fun _ => False)) ;
filter_filter' :> Filter F
}.
Class ProperFilter {T : Type} (F : (T -> Prop) -> Prop) := {
filter_ex : forall P, F P -> exists x, P x ;
filter_filter :> Filter F
}.
Global Instance Proper_StrongProper :
forall {T : Type} (F : (T -> Prop) -> Prop),
ProperFilter F -> ProperFilter' F.
(** ** Limits expressed with filters *)
Definition filter_le {T : Type} (F G : (T -> Prop) -> Prop) :=
forall P, G P -> F P.
Definition filtermap {T U : Type} (f : T -> U) (F : (T -> Prop) -> Prop) :=
fun P => F (fun x => P (f x)).
Global Instance filtermap_filter :
forall T U (f : T -> U) (F : (T -> Prop) -> Prop),
Filter F -> Filter (filtermap f F).
Global Instance filtermap_proper_filter' :
forall T U (f : T -> U) (F : (T -> Prop) -> Prop),
ProperFilter' F -> ProperFilter' (filtermap f F).
Global Instance filtermap_proper_filter :
forall T U (f : T -> U) (F : (T -> Prop) -> Prop),
ProperFilter F -> ProperFilter (filtermap f F).
Definition filtermapi {T U : Type} (f : T -> U -> Prop) (F : (T -> Prop) -> Prop) :=
fun P : U -> Prop => F (fun x => exists y, f x y /\ P y).
Global Instance filtermapi_filter :
forall T U (f : T -> U -> Prop) (F : (T -> Prop) -> Prop),
F (fun x => (exists y, f x y) /\ forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
Filter F -> Filter (filtermapi f F).
Global Instance filtermapi_proper_filter' :
forall T U (f : T -> U -> Prop) (F : (T -> Prop) -> Prop),
F (fun x => (exists y, f x y) /\ forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
ProperFilter' F -> ProperFilter' (filtermapi f F).
Global Instance filtermapi_proper_filter :
forall T U (f : T -> U -> Prop) (F : (T -> Prop) -> Prop),
F (fun x => (exists y, f x y) /\ forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
ProperFilter F -> ProperFilter (filtermapi f F).
Definition filterlim {T U : Type} (f : T -> U) F G :=
filter_le (filtermap f F) G.

Lemma filterlim_ext_loc :
forall {T U F G} {FF : Filter F} (f g : T -> U),
F (fun x => f x = g x) ->
filterlim f F G ->
filterlim g F G.