(** 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.
Definition filterlimi {T U : Type} (f : T -> U -> Prop) F G :=
filter_le (filtermapi f F) G.
(** ** Specific filters *)
(** Filters for pairs *)
Inductive filter_prod {T U : Type} (F G : _ -> Prop) (P : T * U -> Prop) : Prop :=
Filter_prod (Q : T -> Prop) (R : U -> Prop) :
F Q -> G R -> (forall x y, Q x -> R y -> P (x, y)) -> filter_prod F G P.
Global Instance filter_prod_filter :
forall T U (F : (T -> Prop) -> Prop) (G : (U -> Prop) -> Prop),
Filter F -> Filter G -> Filter (filter_prod F G).
Global Instance filter_prod_proper' {T1 T2 : Type}
{F : (T1 -> Prop) -> Prop} {G : (T2 -> Prop) -> Prop}
{FF : ProperFilter' F} {FG : ProperFilter' G} :
ProperFilter' (filter_prod F G).
Global Instance filter_prod_proper {T1 T2 : Type}
{F : (T1 -> Prop) -> Prop} {G : (T2 -> Prop) -> Prop}
{FF : ProperFilter F} {FG : ProperFilter G} :
ProperFilter (filter_prod F G).

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