(**
This file is part of the Coquelicot formalization of real
analysis in Coq: http://coquelicot.saclay.inria.fr/

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Copyright (C) 2011-2015 Sylvie Boldo
#<br />#
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Copyright (C) 2011-2015 Catherine Lelay
#<br />#
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
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.
*)

Require Import Reals mathcomp.ssreflect.ssreflect.
Require Import Rcomplements Rbar Markov Iter Lub.

(** This file first describes [Filter]s that are predicates of type
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
[(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 *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Class Filter {T : Type} (F : (T -> Prop) -> Prop) := {
  filter_true : F (fun _ => True) ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_and : forall P Q : T -> Prop, F P -> F Q -> F (fun x => P x /\ Q x) ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_imp : forall P Q : T -> Prop, (forall x, P x -> Q x) -> F P -> F Q
}.

Global Hint Mode Filter + + : typeclass_instances.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Class ProperFilter' {T : Type} (F : (T -> Prop) -> Prop) := {
  filter_not_empty : not (F (fun _ => False)) ;
  filter_filter' :> Filter F
}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Class ProperFilter {T : Type} (F : (T -> Prop) -> Prop) := {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_ex : forall P, F P -> exists x, P x ;
  filter_filter :> Filter F
}.

Global Instance Proper_StrongProper :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T : Type} (F : (T -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter F -> ProperFilter' F.
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F), @ProperFilter' T F *)
intros T F [H1 H2].
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
intros H.
(* Goal: False *)
(* Goal: @Filter T F *)
now destruct (H1 _ H) as [x Hx].
(* Goal: @Filter T F *)
exact H2.
Qed.

Lemma filter_forall :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T : Type} {F} {FF: @Filter T F} (P : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, P x) -> F P.
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F) (P : Prop) (_ : F (fun _ : T => P)), P *)
intros T F FF P H.
(* Goal: F P *)
apply filter_imp with (fun _ => True).
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
easy.
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
apply filter_true.
Qed.

Lemma filter_const :
  forall {T : Type} {F} {FF: @ProperFilter T F} (P : Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun _ => P) -> P.
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F) (P : Prop) (_ : F (fun _ : T => P)), P *)
intros T F FF P H.
(* Goal: P *)
destruct (filter_ex (fun _ => P) H) as [_ H'].
(* Goal: P *)
exact H'.
Qed.

(** ** Limits expressed with filters *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition filter_le {T : Type} (F G : (T -> Prop) -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall P, G P -> F P.

Lemma filter_le_refl :
  forall T F, @filter_le T F F.
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop), @filter_le T F F *)
now intros T F P.
Qed.

Lemma filter_le_trans :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T F G H, @filter_le T F G -> filter_le G H -> filter_le F H.
Proof.
(* Goal: forall (T : Type) (F G H : forall _ : forall _ : T, Prop, Prop) (_ : @filter_le T F G) (_ : @filter_le T G H), @filter_le T F H *)
intros T F G H FG GH P K.
(* Goal: F P *)
now apply FG, GH.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition filtermap {T U : Type} (f : T -> U) (F : (T -> Prop) -> Prop) :=
  fun P => F (fun x => P (f x)).

Global Instance filtermap_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U (f : T -> U) (F : (T -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Filter F -> Filter (filtermap f F).
Proof.
(* Goal: forall (T U : Type) (f : forall _ : T, U) (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F), @ProperFilter U (@filtermap T U f F) *)
intros T U f F FF.
(* Goal: @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) (f x) (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
unfold filtermap.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
- apply filter_true.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q HP HQ.
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : D x, Q x)) *)
(* Goal: forall (P Q : forall _ : T, Prop) (_ : forall (x : T) (_ : P x), Q x) (_ : F (fun x : T => forall _ : D x, P x)), F (fun x : T => forall _ : D x, Q x) *)
  now apply filter_and.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H HP.
(* Goal: F (fun x : T => Q (f x)) *)
  apply (filter_imp (fun x => P (f x))).
(* Goal: closed (fun _ : UniformSpace.sort T => False) *)
  intros x Hx.
(* Goal: Q (@exist T (fun x : T => dom x) x H0) *)
  now apply H.
(* Goal: P y *)
(* Goal: P y *)
  exact HP.
Qed.

Global Instance filtermap_proper_filter' :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U (f : T -> U) (F : (T -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter' F -> ProperFilter' (filtermap f F).
Proof.
(* Goal: forall (T U : Type) (f : forall _ : T, U) (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F), @ProperFilter U (@filtermap T U f F) *)
intros T U f F FF.
(* Goal: @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) (f x) (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
unfold filtermap.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply filter_not_empty.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply filtermap_filter.
(* Goal: @Filter T F *)
  apply filter_filter'.
Qed.

Global Instance filtermap_proper_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U (f : T -> U) (F : (T -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter F -> ProperFilter (filtermap f F).
Proof.
(* Goal: forall (T U : Type) (f : forall _ : T, U) (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F), @ProperFilter U (@filtermap T U f F) *)
intros T U f F FF.
(* Goal: @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) (f x) (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
unfold filtermap.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P FP.
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun x : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
  destruct (filter_ex _ FP) as [x Hx].
(* Goal: @ex U (fun x : U => P x) *)
(* Goal: @Filter U (fun P : forall _ : U, Prop => F (fun x : T => P (f x))) *)
  now exists (f x).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply filtermap_filter.
(* Goal: @Filter T F *)
  apply filter_filter.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition filtermapi {T U : Type} (f : T -> U -> Prop) (F : (T -> Prop) -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  fun P : U -> Prop => F (fun x => exists y, f x y /\ P y).

Global Instance filtermapi_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U (f : T -> U -> Prop) (F : (T -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => (exists y, f x y) /\ forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Filter F -> Filter (filtermapi f F).
Proof.
intros T U f F H FF.
(* Goal: @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) fx (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
unfold filtermapi.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply: filter_imp H => x [[y Hy] H].
(* Goal: @ex U (fun y : U => and (g x y) (P y)) *)
  exists y.
  exact (conj Hy I).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q HP HQ.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
  apply: filter_imp (filter_and _ _ (filter_and _ _ HP HQ) H).
  intros x [[[y1 [Hy1 Py]] [y2 [Hy2 Qy]]] [[y Hy] Hf]].
(* Goal: @ex U (fun y : U => and (g x y) (P y)) *)
  exists y.
  apply (conj Hy).
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
  now rewrite (Hf y y1).
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
  now rewrite (Hf y y2).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q HPQ HP.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
  apply: filter_imp HP.
  intros x [y [Hf Py]].
(* Goal: @ex U (fun y : U => and (g x y) (P y)) *)
  exists y.
  apply (conj Hf).
  now apply HPQ.
Qed.

Global Instance filtermapi_proper_filter' :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U (f : T -> U -> Prop) (F : (T -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => (exists y, f x y) /\ forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter' F -> ProperFilter' (filtermapi f F).
Proof.
(* Goal: forall (T U : Type) (f : forall (_ : T) (_ : U), Prop) (F : forall _ : forall _ : T, Prop, Prop) (_ : F (fun x : T => and (@ex U (fun y : U => f x y)) (forall (y1 y2 : U) (_ : f x y1) (_ : f x y2), @eq U y1 y2))) (_ : @ProperFilter T F), @ProperFilter U (@filtermapi T U f F) *)
intros T U f F HF FF.
(* Goal: @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) fx (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
unfold filtermapi.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intro H.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply filter_not_empty.
(* Goal: F (fun _ : T => False) *)
(* Goal: @Filter U (fun P : forall _ : U, Prop => F (fun x : T => @ex U (fun y : U => and (f x y) (P y)))) *)
  apply filter_imp with (2 := H).
(* Goal: forall (x : T) (_ : @ex U (fun y : U => and (f x y) False)), False *)
(* Goal: @Filter U (fun P : forall _ : U, Prop => F (fun x : T => @ex U (fun y : U => and (f x y) (P y)))) *)
  now intros x [y [_ Hy]].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply filtermapi_filter.
(* Goal: F (fun x : T => and (@ex U (fun y : U => f x y)) (forall (y1 y2 : U) (_ : f x y1) (_ : f x y2), @eq U y1 y2)) *)
(* Goal: @Filter T F *)
  exact HF.
(* Goal: @Filter T F *)
  apply filter_filter'.
Qed.

Global Instance filtermapi_proper_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U (f : T -> U -> Prop) (F : (T -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => (exists y, f x y) /\ forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter F -> ProperFilter (filtermapi f F).
Proof.
(* Goal: forall (T U : Type) (f : forall (_ : T) (_ : U), Prop) (F : forall _ : forall _ : T, Prop, Prop) (_ : F (fun x : T => and (@ex U (fun y : U => f x y)) (forall (y1 y2 : U) (_ : f x y1) (_ : f x y2), @eq U y1 y2))) (_ : @ProperFilter T F), @ProperFilter U (@filtermapi T U f F) *)
intros T U f F HF FF.
(* Goal: @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) fx (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
unfold filtermapi.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P FP.
(* Goal: @ex U (fun x : U => P x) *)
(* Goal: @Filter U (fun P : forall _ : U, Prop => F (fun x : T => @ex U (fun y : U => and (f x y) (P y)))) *)
  destruct (filter_ex _ FP) as [x [y [_ Hy]]].
(* Goal: @ex U (fun y : U => and (g x y) (P y)) *)
  now exists y.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply filtermapi_filter.
(* Goal: F (fun x : T => and (@ex U (fun y : U => f x y)) (forall (y1 y2 : U) (_ : f x y1) (_ : f x y2), @eq U y1 y2)) *)
(* Goal: @Filter T F *)
  exact HF.
(* Goal: @Filter T F *)
  apply filter_filter.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition filterlim {T U : Type} (f : T -> U) F G :=
  filter_le (filtermap f F) G.

Lemma filterlim_id :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T (F : (T -> Prop) -> Prop), filterlim (fun x => x) F F.
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop), @filterlim T T (fun x : T => x) F F *)
now intros T F P HP.
Qed.

Lemma filterlim_comp :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U V (f : T -> U) (g : U -> V) F G H,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G -> filterlim g G H ->
  filterlim (fun x => g (f x)) F H.
Proof.
(* Goal: forall (T U V : Type) (f : forall _ : T, U) (g : forall (_ : U) (_ : V), Prop) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (H : forall _ : forall _ : V, Prop, Prop) (_ : @filterlim T U f F G) (_ : @filterlimi U V g G H), @filterlimi T V (fun x : T => g (f x)) F H *)
intros T U V f g F G H FG GH P HP.
(* Goal: @filtermap T V (fun x : T => g (f x)) F P *)
apply (FG (fun x => P (g x))).
(* Goal: G (fun x : U => @ex V (fun y : V => and (g x y) (P y))) *)
now apply GH.
Qed.

Lemma filterlim_ext_loc :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G} {FF : Filter F} (f g : T -> U),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => f x = g x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G ->
  filterlim g F G.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter T F) (f g : forall (_ : T) (_ : U), Prop) (_ : F (fun x : T => forall y : U, iff (f x y) (g x y))) (_ : @filterlimi T U f F G), @filterlimi T U g F G *)
intros T U F G FF f g Efg Lf P GP.
(* Goal: @filtermapi T U g F P *)
specialize (Lf P GP).
(* Goal: @filtermap T U g F P *)
generalize (filter_and _ (fun x : T => P (f x)) Efg Lf).
(* Goal: @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) (f x) (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
unfold filtermap.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
apply filter_imp.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
now intros x [-> H].
Qed.

Lemma filterlim_ext :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G} {FF : Filter F} (f g : T -> U),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, f x = g x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G ->
  filterlim g F G.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter T F) (f g : forall (_ : T) (_ : U), Prop) (_ : forall (x : T) (y : U), iff (f x y) (g x y)) (_ : @filterlimi T U f F G), @filterlimi T U g F G *)
intros T U F G FF f g Efg.
(* Goal: forall _ : @filterlim T U f (@within T D F) G, @filterlim T U g (@within T D F) G *)
apply filterlim_ext_loc.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
now apply filter_forall.
Qed.

Lemma filterlim_filter_le_1 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G H} (f : T -> U),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le G F ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F H ->
  filterlim f G H.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G H : forall _ : forall _ : U, Prop, Prop) (f : forall (_ : T) (_ : U), Prop) (_ : @filter_le U G H) (_ : @filterlimi T U f F G), @filterlimi T U f F H *)
intros T U F G H f K Hf P HP.
(* Goal: @filtermapi T U f G P *)
apply K.
(* Goal: F (fun x : T => @ex U (fun y : U => and (f x y) (P y))) *)
now apply Hf.
Qed.

Lemma filterlim_filter_le_2 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G H} (f : T -> U),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le G H ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G ->
  filterlim f F H.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G H : forall _ : forall _ : U, Prop, Prop) (f : forall (_ : T) (_ : U), Prop) (_ : @filter_le U G H) (_ : @filterlimi T U f F G), @filterlimi T U f F H *)
intros T U F G H f K Hf P HP.
(* Goal: @filtermapi T U f F P *)
apply Hf.
(* Goal: @filtermapi T U f G P *)
now apply K.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition filterlimi {T U : Type} (f : T -> U -> Prop) F G :=
  filter_le (filtermapi f F) G.

Lemma filterlimi_comp :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U V (f : T -> U) (g : U -> V -> Prop) F G H,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G -> filterlimi g G H ->
  filterlimi (fun x => g (f x)) F H.
Proof.
(* Goal: forall (T U V : Type) (f : forall _ : T, U) (g : forall (_ : U) (_ : V), Prop) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (H : forall _ : forall _ : V, Prop, Prop) (_ : @filterlim T U f F G) (_ : @filterlimi U V g G H), @filterlimi T V (fun x : T => g (f x)) F H *)
intros T U V f g F G H FG GH P HP.
(* Goal: @filtermapi T V (fun x : T => g (f x)) F P *)
apply (FG (fun x => exists y, g x y /\ P y)).
(* Goal: G (fun x : U => @ex V (fun y : V => and (g x y) (P y))) *)
now apply GH.
Qed.

Lemma filterlimi_ext_loc :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G} {FF : Filter F} (f g : T -> U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => forall y, f x y <-> g x y) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F G ->
  filterlimi g F G.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter T F) (f g : forall (_ : T) (_ : U), Prop) (_ : F (fun x : T => forall y : U, iff (f x y) (g x y))) (_ : @filterlimi T U f F G), @filterlimi T U g F G *)
intros T U F G FF f g Efg Lf P GP.
(* Goal: @filtermapi T U g F P *)
specialize (Lf P GP).
(* Goal: @filtermapi T U g F P *)
generalize (filter_and _ _ Efg Lf).
(* Goal: @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) fx (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
unfold filtermapi.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
apply filter_imp.
(* Goal: forall (x : T) (_ : and (forall y : U, iff (f x y) (g x y)) (@ex U (fun y : U => and (f x y) (P y)))), @ex U (fun y : U => and (g x y) (P y)) *)
intros x [H [y [Hy1 Hy2]]].
(* Goal: @ex U (fun y : U => and (g x y) (P y)) *)
exists y.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: conj Hy2.
(* Goal: Q (@exist T (fun x : T => dom x) x H0) *)
now apply H.
Qed.

Lemma filterlimi_ext :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G} {FF : Filter F} (f g : T -> U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x y, f x y <-> g x y) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F G ->
  filterlimi g F G.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter T F) (f g : forall (_ : T) (_ : U), Prop) (_ : forall (x : T) (y : U), iff (f x y) (g x y)) (_ : @filterlimi T U f F G), @filterlimi T U g F G *)
intros T U F G FF f g Efg.
(* Goal: forall _ : @filterlimi T U f F G, @filterlimi T U g F G *)
apply filterlimi_ext_loc.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
now apply filter_forall.
Qed.

Lemma filterlimi_filter_le_1 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G H} (f : T -> U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le G F ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F H ->
  filterlimi f G H.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G H : forall _ : forall _ : U, Prop, Prop) (f : forall (_ : T) (_ : U), Prop) (_ : @filter_le U G H) (_ : @filterlimi T U f F G), @filterlimi T U f F H *)
intros T U F G H f K Hf P HP.
(* Goal: @filtermapi T U f G P *)
apply K.
(* Goal: F (fun x : T => @ex U (fun y : U => and (f x y) (P y))) *)
now apply Hf.
Qed.

Lemma filterlimi_filter_le_2 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G H} (f : T -> U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le G H ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F G ->
  filterlimi f F H.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G H : forall _ : forall _ : U, Prop, Prop) (f : forall (_ : T) (_ : U), Prop) (_ : @filter_le U G H) (_ : @filterlimi T U f F G), @filterlimi T U f F H *)
intros T U F G H f K Hf P HP.
(* Goal: @filtermapi T U f F P *)
apply Hf.
(* Goal: @filtermapi T U f G P *)
now apply K.
Qed.

(** ** Specific filters *)

(** Filters for pairs *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Inductive filter_prod {T U : Type} (F G : _ -> Prop) (P : T * U -> Prop) : Prop :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Filter_prod (Q : T -> Prop) (R : U -> Prop) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    F Q -> G R -> (forall x y, Q x -> R y -> P (x, y)) -> filter_prod F G P.

Global Instance filter_prod_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T U (F : (T -> Prop) -> Prop) (G : (U -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Filter F -> Filter G -> Filter (filter_prod F G).
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter T F) (_ : @Filter U G), @Filter (prod T U) (@filter_prod T U F G) *)
intros T U F G FF FG.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- exists (fun _ => True) (fun _ => True).
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
  apply filter_true.
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
  apply filter_true.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  easy.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q [AP BP P1 P2 P3] [AQ BQ Q1 Q2 Q3].
(* Goal: @filter_prod T U F G (fun x : prod T U => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : prod T U, Prop) (_ : forall (x : prod T U) (_ : P x), Q x) (_ : @filter_prod T U F G P), @filter_prod T U F G Q *)
  exists (fun x => AP x /\ AQ x) (fun x => BP x /\ BQ x).
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : D x, Q x)) *)
(* Goal: forall (P Q : forall _ : T, Prop) (_ : forall (x : T) (_ : P x), Q x) (_ : F (fun x : T => forall _ : D x, P x)), F (fun x : T => forall _ : D x, Q x) *)
  now apply filter_and.
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : D x, Q x)) *)
(* Goal: forall (P Q : forall _ : T, Prop) (_ : forall (x : T) (_ : P x), Q x) (_ : F (fun x : T => forall _ : D x, P x)), F (fun x : T => forall _ : D x, Q x) *)
  now apply filter_and.
(* Goal: forall (x : T) (y : U) (_ : and (AP x) (AQ x)) (_ : and (BP y) (BQ y)), and (P (@pair T U x y)) (Q (@pair T U x y)) *)
(* Goal: forall (P Q : forall _ : prod T U, Prop) (_ : forall (x : prod T U) (_ : P x), Q x) (_ : @filter_prod T U F G P), @filter_prod T U F G Q *)
  intros x y [Px Qx] [Py Qy].
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P (@pair T U x y) *)
  now apply P3.
(* Goal: Q (@pair T U x y) *)
(* Goal: forall (P Q : forall _ : prod T U, Prop) (_ : forall (x : prod T U) (_ : P x), Q x) (_ : @filter_prod T U F G P), @filter_prod T U F G Q *)
  now apply Q3.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q HI [AP BP P1 P2 P3].
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists AP BP ; try easy.
(* Goal: forall (x : T) (y : U) (_ : AP x) (_ : BP y), Q (@pair T U x y) *)
  intros x y Hx Hy.
(* Goal: Q (@pair T U x y) *)
  apply HI.
(* Goal: P (@pair T U x y) *)
  now apply P3.
Qed.

Global Instance filter_prod_proper' {T1 T2 : Type}
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  {F : (T1 -> Prop) -> Prop} {G : (T2 -> Prop) -> Prop}
  {FF : ProperFilter' F} {FG : ProperFilter' G} :
  ProperFilter' (filter_prod F G).
Proof.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: not (@filter_prod T1 T2 F G (fun _ : prod T1 T2 => False)) *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  unfold not.
(* Goal: forall _ : @filter_prod T1 T2 F G (fun _ : prod T1 T2 => False), False *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  apply filter_prod_ind.
(* Goal: forall (Q : forall _ : T1, Prop) (R : forall _ : T2, Prop) (_ : F Q) (_ : G R) (_ : forall (x : T1) (y : T2) (_ : Q x) (_ : R y), False), False *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  intros Q R HQ HR HQR.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply filter_not_empty.
(* Goal: G (fun _ : T2 => False) *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  apply filter_imp with (2 := HR).
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: forall _ : Fr t P, Fr t P' *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
  apply FF.
(* Goal: F (fun _ : T1 => False) *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  apply filter_imp with (2 := HQ).
(* Goal: closed (fun _ : UniformSpace.sort T => False) *)
  intros x Hx.
(* Goal: False *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  now apply (HQR x y).
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  apply filter_prod_filter.
(* Goal: forall _ : Fr t P, Fr t P' *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
  apply FF.
(* Goal: @Filter T2 G *)
  apply FG.
Qed.

Global Instance filter_prod_proper {T1 T2 : Type}
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  {F : (T1 -> Prop) -> Prop} {G : (T2 -> Prop) -> Prop}
  {FF : ProperFilter F} {FG : ProperFilter G} :
  ProperFilter (filter_prod F G).
Proof.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: forall (P : forall _ : prod T1 T2, Prop) (_ : @filter_prod T1 T2 F G P), @ex (prod T1 T2) (fun x : prod T1 T2 => P x) *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  intros P [Q1 Q2 H1 H2 HP].
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (filter_ex _ H1) => x1 Hx1.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (filter_ex _ H2) => x2 Hx2.
(* Goal: @ex (prod T1 T2) (fun x : prod T1 T2 => P x) *)
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  exists (x1,x2).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply HP.
(* Goal: @Filter (prod T1 T2) (@filter_prod T1 T2 F G) *)
  apply filter_prod_filter.
(* Goal: forall _ : Fr t P, Fr t P' *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
  apply FF.
(* Goal: @Filter T2 G *)
  apply FG.
Qed.

Lemma filterlim_fst :
  forall {T U F G} {FG : Filter G},
  filterlim (@fst T U) (filter_prod F G) F.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter U G), @filterlim (prod T U) T (@fst T U) (@filter_prod T U F G) F *)
intros T U F G FG P HP.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
exists P (fun _ => True) ; try easy.
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
apply filter_true.
Qed.

Lemma filterlim_snd :
  forall {T U F G} {FF : Filter F},
  filterlim (@snd T U) (filter_prod F G) G.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter T F), @filterlim (prod T U) U (@snd T U) (@filter_prod T U F G) G *)
intros T U F G FF P HP.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
exists (fun _ => True) P ; try easy.
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
apply filter_true.
Qed.

Lemma filterlim_pair :
  forall {T U V F G H} {FF : Filter F},
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (f : T -> U) (g : T -> V),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim g F H ->
  filterlim (fun x => (f x, g x)) F (filter_prod G H).
Proof.
(* Goal: forall (T U V : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (H : forall _ : forall _ : V, Prop, Prop) (_ : @Filter T F) (f : forall _ : T, U) (g : forall _ : T, V) (_ : @filterlim T U f F G) (_ : @filterlim T V g F H), @filterlim T (prod U V) (fun x : T => @pair U V (f x) (g x)) F (@filter_prod U V G H) *)
intros T U V F G H FF f g Cf Cg P [A B GA HB HP].
(* Goal: @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) (f x) (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
unfold filtermap.
(* Goal: F (fun x : T => P (@pair U V (f x) (g x))) *)
apply (filter_imp (fun x => A (f x) /\ B (g x))).
(* Goal: forall (x : T) (_ : and (A (f x)) (B (g x))), P (@pair U V (f x) (g x)) *)
(* Goal: F (fun x : T => and (A (f x)) (B (g x))) *)
intros x [Af Bg].
(* Goal: P y *)
now apply HP.
(* Goal: @locally T x (fun x : UniformSpace.sort T => and (D x) (E x)) *)
apply filter_and.
(* Goal: @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => P (f x)) *)
now apply Cf.
(* Goal: F (fun x : T => B (g x)) *)
now apply Cg.
Qed.

Lemma filterlim_comp_2 :
  forall {T U V W F G H I} {FF : Filter F},
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (f : T -> U) (g : T -> V) (h : U -> V -> W),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim g F H ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim (fun x => h (fst x) (snd x)) (filter_prod G H) I ->
  filterlim (fun x => h (f x) (g x)) F I.
Proof.
(* Goal: forall (T U V W : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (H : forall _ : forall _ : V, Prop, Prop) (I : forall _ : forall _ : W, Prop, Prop) (_ : @Filter T F) (f : forall _ : T, U) (g : forall _ : T, V) (h : forall (_ : U) (_ : V) (_ : W), Prop) (_ : @filterlim T U f F G) (_ : @filterlim T V g F H) (_ : @filterlimi (prod U V) W (fun x : prod U V => h (@fst U V x) (@snd U V x)) (@filter_prod U V G H) I), @filterlimi T W (fun x : T => h (f x) (g x)) F I *)
intros T U V W F G H I FF f g h Cf Cg Ch.
(* Goal: @filterlimi T W (fun x : T => h (f x) (g x)) F I *)
change (fun x => h (f x) (g x)) with (fun x => h (fst (f x, g x)) (snd (f x, g x))).
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filterlim_comp Ch.
(* Goal: @filterlim T (prod U V) (fun x : T => @pair U V (f x) (g x)) F (@filter_prod U V G H) *)
now apply filterlim_pair.
Qed.

Lemma filterlimi_comp_2 :
  forall {T U V W F G H I} {FF : Filter F},
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (f : T -> U) (g : T -> V) (h : U -> V -> W -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F G ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim g F H ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi (fun x => h (fst x) (snd x)) (filter_prod G H) I ->
  filterlimi (fun x => h (f x) (g x)) F I.
Proof.
(* Goal: forall (T U V W : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (H : forall _ : forall _ : V, Prop, Prop) (I : forall _ : forall _ : W, Prop, Prop) (_ : @Filter T F) (f : forall _ : T, U) (g : forall _ : T, V) (h : forall (_ : U) (_ : V) (_ : W), Prop) (_ : @filterlim T U f F G) (_ : @filterlim T V g F H) (_ : @filterlimi (prod U V) W (fun x : prod U V => h (@fst U V x) (@snd U V x)) (@filter_prod U V G H) I), @filterlimi T W (fun x : T => h (f x) (g x)) F I *)
intros T U V W F G H I FF f g h Cf Cg Ch.
(* Goal: @filterlimi T W (fun x : T => h (f x) (g x)) F I *)
change (fun x => h (f x) (g x)) with (fun x => h (fst (f x, g x)) (snd (f x, g x))).
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filterlimi_comp Ch.
(* Goal: @filterlim T (prod U V) (fun x : T => @pair U V (f x) (g x)) F (@filter_prod U V G H) *)
now apply filterlim_pair.
Qed.

(** Restriction of a filter to a domain *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition within {T : Type} D (F : (T -> Prop) -> Prop) (P : T -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => D x -> P x).

Global Instance within_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T D F, Filter F -> Filter (@within T D F).
Proof.
(* Goal: forall (T : Type) (D : forall _ : T, Type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @Filter T F), @Filter T (@within T D F) *)
intros T D F FF.
(* Goal: @within T D F (fun x : T => @eq U (f x) (g x)) *)
unfold within.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now apply filter_forall.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q WP WQ.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  apply filter_imp with (fun x => (D x -> P x) /\ (D x -> Q x)).
(* Goal: forall (x : T) (_ : and (forall _ : D x, P x) (forall _ : D x, Q x)) (_ : D x), and (P x) (Q x) *)
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : D x, Q x)) *)
(* Goal: forall (P Q : forall _ : T, Prop) (_ : forall (x : T) (_ : P x), Q x) (_ : F (fun x : T => forall _ : D x, P x)), F (fun x : T => forall _ : D x, Q x) *)
  intros x [HP HQ] HD.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P y *)
  now apply HP.
(* Goal: Q x *)
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : D x, Q x)) *)
(* Goal: forall (P Q : forall _ : T, Prop) (_ : forall (x : T) (_ : P x), Q x) (_ : F (fun x : T => forall _ : D x, P x)), F (fun x : T => forall _ : D x, Q x) *)
  now apply HQ.
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : D x, Q x)) *)
(* Goal: forall (P Q : forall _ : T, Prop) (_ : forall (x : T) (_ : P x), Q x) (_ : F (fun x : T => forall _ : D x, P x)), F (fun x : T => forall _ : D x, Q x) *)
  now apply filter_and.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H FP.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  apply filter_imp with (fun x => (D x -> P x) /\ (P x -> Q x)).
(* Goal: forall (x : T) (_ : and (forall _ : D x, P x) (forall _ : P x, Q x)) (_ : D x), Q x *)
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : P x, Q x)) *)
  intros x [H1 H2] HD.
(* Goal: Q x *)
(* Goal: F (fun x : T => and (forall _ : D x, P x) (forall _ : P x, Q x)) *)
  apply H2, H1, HD.
(* Goal: @locally T x (fun x : UniformSpace.sort T => and (D x) (E x)) *)
  apply filter_and.
(* Goal: F (fun x : T => forall _ : D x, P x) *)
(* Goal: F (fun x : T => forall _ : P x, Q x) *)
  exact FP.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  now apply filter_forall.
Qed.

Lemma filter_le_within :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T} {F : (T -> Prop) -> Prop} {FF : Filter F} D,
  filter_le (within D F) F.
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @Filter T F) (D : forall _ : T, Type), @filter_le T (@within T D F) F *)
intros T F D P HP.
(* Goal: @within T D F (fun x : T => @eq U (f x) (g x)) *)
unfold within.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
now apply filter_imp.
Qed.

Lemma filterlim_within_ext :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U F G} {FF : Filter F} D (f g : T -> U),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, D x -> f x = g x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f (within D F) G ->
  filterlim g (within D F) G.
Proof.
(* Goal: forall (T U : Type) (F : forall _ : forall _ : T, Prop, Prop) (G : forall _ : forall _ : U, Prop, Prop) (_ : @Filter T F) (D : forall _ : T, Type) (f g : forall _ : T, U) (_ : forall (x : T) (_ : D x), @eq U (f x) (g x)) (_ : @filterlim T U f (@within T D F) G), @filterlim T U g (@within T D F) G *)
intros T U F G FF D f g Efg.
(* Goal: forall _ : @filterlim T U f (@within T D F) G, @filterlim T U g (@within T D F) G *)
apply filterlim_ext_loc.
(* Goal: @within T D F (fun x : T => @eq U (f x) (g x)) *)
unfold within.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
now apply filter_forall.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition subset_filter {T} (F : (T -> Prop) -> Prop) (dom : T -> Prop) (P : {x|dom x} -> Prop) : Prop :=
  F (fun x => forall H : dom x, P (exist _ x H)).

Global Instance subset_filter_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T F (dom : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Filter F ->
  Filter (subset_filter F dom).
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop) (dom : forall _ : T, Prop) (_ : @Filter T F), @Filter (@sig T (fun x : T => dom x)) (@subset_filter T F dom) *)
intros T F dom FF.
(* Goal: @Filter (@sig T (fun x : T => dom x)) (@subset_filter T F dom) *)
constructor ; unfold subset_filter.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now apply filter_imp with (2 := filter_true).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q HP HQ.
(* Goal: F (fun x : T => forall H : dom x, and (P (@exist T (fun x0 : T => dom x0) x H)) (Q (@exist T (fun x0 : T => dom x0) x H))) *)
(* Goal: forall (P Q : forall _ : @sig T (fun x : T => dom x), Prop) (_ : forall (x : @sig T (fun x : T => dom x)) (_ : P x), Q x) (_ : F (fun x : T => forall H : dom x, P (@exist T (fun x0 : T => dom x0) x H))), F (fun x : T => forall H : dom x, Q (@exist T (fun x0 : T => dom x0) x H)) *)
  generalize (filter_and _ _ HP HQ).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  apply filter_imp.
(* Goal: forall (x : T) (_ : and (forall H : dom x, P (@exist T (fun x0 : T => dom x0) x H)) (forall H : dom x, Q (@exist T (fun x0 : T => dom x0) x H))) (H : dom x), and (P (@exist T (fun x0 : T => dom x0) x H)) (Q (@exist T (fun x0 : T => dom x0) x H)) *)
(* Goal: forall (P Q : forall _ : @sig T (fun x : T => dom x), Prop) (_ : forall (x : @sig T (fun x : T => dom x)) (_ : P x), Q x) (_ : F (fun x : T => forall H : dom x, P (@exist T (fun x0 : T => dom x0) x H))), F (fun x : T => forall H : dom x, Q (@exist T (fun x0 : T => dom x0) x H)) *)
  intros x [H1 H2] H.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  now split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  apply filter_imp.
(* Goal: forall (x : T) (_ : forall H : dom x, P (@exist T (fun x0 : T => dom x0) x H)) (H : dom x), Q (@exist T (fun x0 : T => dom x0) x H) *)
  intros x H' H0.
(* Goal: Q (@exist T (fun x : T => dom x) x H0) *)
  now apply H.
Qed.

Lemma subset_filter_proper' :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T F} {FF : Filter F} (dom : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall P, F P -> ~ ~ exists x, dom x /\ P x) ->
  ProperFilter' (subset_filter F dom).
Proof.
intros T F FF dom.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
2: now apply subset_filter_filter.
intro H1.
unfold subset_filter in H1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
specialize (H (fun x : T => dom x -> False)).
apply H in H1.
(* Goal: Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) *)
apply H1.
clear H ; clear H1.
intro H2.
destruct H2 as (x, Hx).
destruct Hx as (Hx1, Hx2) ; now apply Hx2.
Qed.

Lemma subset_filter_proper :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T F} {FF : Filter F} (dom : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall P, F P -> exists x, dom x /\ P x) ->
  ProperFilter (subset_filter F dom).
Proof.
(* Goal: forall (T : Type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @Filter T F) (dom : forall _ : T, Prop) (_ : forall (P : forall _ : T, Prop) (_ : F P), @ex T (fun x : T => and (dom x) (P x))), @ProperFilter (@sig T (fun x : T => dom x)) (@subset_filter T F dom) *)
intros T F dom FF H.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- unfold subset_filter.
(* Goal: forall (P : forall _ : @sig T (fun x : T => FF x), Prop) (_ : F (fun x : T => forall H : FF x, P (@exist T (fun x0 : T => FF x0) x H))), @ex (@sig T (fun x : T => FF x)) (fun x : @sig T (fun x : T => FF x) => P x) *)
(* Goal: @Filter (@sig T (fun x : T => FF x)) (@subset_filter T F FF) *)
  intros P HP.
(* Goal: @ex (@sig T (fun x : T => FF x)) (fun x : @sig T (fun x : T => FF x) => P x) *)
(* Goal: @Filter (@sig T (fun x : T => FF x)) (@subset_filter T F FF) *)
  destruct (H _ HP) as [x [H1 H2]].
(* Goal: @ex (@sig T (fun x : T => FF x)) (fun x : @sig T (fun x : T => FF x) => P x) *)
(* Goal: @Filter (@sig T (fun x : T => FF x)) (@subset_filter T F FF) *)
  exists (exist _ x H1).
(* Goal: P (@exist T FF x H1) *)
(* Goal: @Filter (@sig T (fun x : T => FF x)) (@subset_filter T F FF) *)
  now apply H2.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now apply subset_filter_filter.
Qed.

(** * Algebraic spaces *)
(** ** Abelian groups *)

Module AbelianGroup.

Record mixin_of (G : Type) := Mixin {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  plus : G -> G -> G ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  opp : G -> G ;
  zero : G ;
  ax1 : forall x y, plus x y = plus y x ;
  ax2 : forall x y z, plus x (plus y z) = plus (plus x y) z ;
  ax3 : forall x, plus x zero = x ;
  ax4 : forall x, plus x (opp x) = zero
}.

Notation class_of := mixin_of (only parsing).

Section ClassDef.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.
Definition class (cT : type) := let: Pack _ c _ := cT return class_of cT in c.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
Notation AbelianGroup := type.

End Exports.

End AbelianGroup.

Export AbelianGroup.Exports.

(** Arithmetic operations *)

Section AbelianGroup1.

Context {G : AbelianGroup}.

Definition zero := AbelianGroup.zero _ (AbelianGroup.class G).
Definition plus := AbelianGroup.plus _ (AbelianGroup.class G).
Definition opp := AbelianGroup.opp _ (AbelianGroup.class G).
Definition minus x y := (plus x (opp y)).

Lemma plus_comm :
  forall x y : G,
  plus x y = plus y x.
Proof.
(* Goal: forall x y : AbelianGroup.sort G, @eq (AbelianGroup.sort G) (plus x y) (plus y x) *)
apply AbelianGroup.ax1.
Qed.

Lemma plus_assoc :
  forall x y z : G,
  plus x (plus y z) = plus (plus x y) z.
Proof.
(* Goal: forall x y z : AbelianGroup.sort G, @eq (AbelianGroup.sort G) (plus x (plus y z)) (plus (plus x y) z) *)
apply AbelianGroup.ax2.
Qed.

Lemma plus_zero_r :
  forall x : G,
  plus x zero = x.
Proof.
(* Goal: forall x : AbelianGroup.sort G, @eq (AbelianGroup.sort G) (plus x zero) x *)
apply AbelianGroup.ax3.
Qed.

Lemma plus_opp_r :
  forall x : G,
  plus x (opp x) = zero.
Proof.
(* Goal: forall x : AbelianGroup.sort G, @eq (AbelianGroup.sort G) (plus x (opp x)) zero *)
apply AbelianGroup.ax4.
Qed.

Lemma plus_zero_l :
  forall x : G,
  plus zero x = x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_comm plus_zero_r.
Qed.

Lemma plus_opp_l :
  forall x : G,
  plus (opp x) x = zero.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_comm.
(* Goal: @eq (AbelianGroup.sort G) (minus x x) zero *)
apply plus_opp_r.
Qed.

Lemma opp_zero :
  opp zero = zero.
Proof.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- (plus_zero_r (opp zero)).
(* Goal: @eq (AbelianGroup.sort G) (plus (opp (opp x)) (opp x)) zero *)
apply plus_opp_l.
Qed.

Lemma minus_zero_r :
  forall x : G,
  minus x zero = x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq (AbelianGroup.sort G) (minus x zero) x *)
unfold minus.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite opp_zero.
(* Goal: @eq (AbelianGroup.sort G) (plus x zero) x *)
apply plus_zero_r.
Qed.

Lemma minus_eq_zero (x : G) :
  minus x x = zero.
Proof.
(* Goal: @eq (AbelianGroup.sort G) (minus x x) zero *)
  apply plus_opp_r.
Qed.

Lemma plus_reg_l :
  forall r x y : G,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  plus r x = plus r y -> x = y.
Proof.
(* Goal: forall (r x y : AbelianGroup.sort G) (_ : @eq (AbelianGroup.sort G) (plus r x) (plus r y)), @eq (AbelianGroup.sort G) x y *)
intros r x y H.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite -(plus_zero_l x) -(plus_opp_l r) -plus_assoc.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite H.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_assoc plus_opp_l plus_zero_l.
Qed.
Lemma plus_reg_r :
  forall r x y : G,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  plus x r = plus y r -> x = y.
Proof.
(* Goal: forall (r x y : AbelianGroup.sort G) (_ : @eq (AbelianGroup.sort G) (plus x r) (plus y r)), @eq (AbelianGroup.sort G) x y *)
intros z x y.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite !(plus_comm _ z).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by apply plus_reg_l.
Qed.

Lemma opp_opp :
  forall x : G,
  opp (opp x) = x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq (AbelianGroup.sort G) (opp (opp x)) x *)
apply plus_reg_r with (opp x).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_r.
(* Goal: @eq (AbelianGroup.sort G) (plus (opp (opp x)) (opp x)) zero *)
apply plus_opp_l.
Qed.

Lemma opp_plus :
  forall x y : G,
  opp (plus x y) = plus (opp x) (opp y).
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
intros x y.
(* Goal: @eq (AbelianGroup.sort G) (opp (plus x y)) (plus (opp x) (opp y)) *)
apply plus_reg_r with (plus x y).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_assoc.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite (plus_comm (opp x)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- (plus_assoc (opp y)).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_zero_r.
(* Goal: @eq (AbelianGroup.sort G) zero (plus (opp y) y) *)
apply sym_eq, plus_opp_l.
Qed.
Lemma opp_minus (x y : G) :
  opp (minus x y) = minus y x.
Proof.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /minus opp_plus opp_opp.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply plus_comm.
Qed.

Lemma minus_trans (r x y : G) :
  minus x y = plus (minus x r) (minus r y).
Proof.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite /minus -!plus_assoc.
(* Goal: @eq (Ring.sort T) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@coeff_mat (Ring.sort T) (S m) l (@zero (Ring.AbelianGroup T)) (@mk_matrix (Ring.sort T) (S m) l (fun i j : nat => @sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B i l0) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l0 j)) (Init.Nat.pred k))) m' l')) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
  apply f_equal.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite plus_assoc plus_opp_l plus_zero_l.
Qed.

End AbelianGroup1.

(** Sum *)

Section Sums.

Context {G : AbelianGroup}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition sum_n_m (a : nat -> G) n m :=
  iter_nat plus zero a n m.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition sum_n (a : nat -> G) n :=
  sum_n_m a O n.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_Chasles (a : nat -> G) (n m k : nat) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (n <= S m)%nat -> (m <= k)%nat
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    -> sum_n_m a n k = plus (sum_n_m a n m) (sum_n_m a (S m) k).
Proof.
(* Goal: forall (_ : le n (S m)) (_ : le m k), @eq (AbelianGroup.sort G) (sum_n_m a n k) (@plus G (sum_n_m a n m) (sum_n_m a (S m) k)) *)
  intros Hnm Hmk.
(* Goal: @eq (AbelianGroup.sort G) (sum_n_m a n k) (@plus G (sum_n_m a n m) (sum_n_m a (S m) k)) *)
  apply iter_nat_Chasles.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply plus_zero_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply plus_assoc.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_n (a : nat -> G) (n : nat) :
  sum_n_m a n n = a n.
Proof.
(* Goal: @eq (AbelianGroup.sort G) (sum_n_m a n n) (a n) *)
  apply iter_nat_point.
(* Goal: @eq (AbelianGroup.sort G) (plus x zero) x *)
  by apply plus_zero_r.
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_O (a : nat -> G) : sum_n a 0 = a O.
Proof.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sum_n_n.
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_Sm (a : nat -> G) (n m : nat) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (n <= S m)%nat -> sum_n_m a n (S m) = plus (sum_n_m a n m) (a (S m)).
Proof.
(* Goal: forall _ : le n m, @eq (AbelianGroup.sort G) (sum_n_m a n m) (@plus G (a n) (sum_n_m a (S n) m)) *)
  intros Hnmk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (sum_n_m_Chasles _ _ m).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite sum_n_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_n_Sn.
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_Sn_m (a : nat -> G) (n m : nat) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (n <= m)%nat -> sum_n_m a n m = plus (a n) (sum_n_m a (S n) m).
Proof.
(* Goal: forall _ : le n m, @eq (AbelianGroup.sort G) (sum_n_m a n m) (@plus G (a n) (sum_n_m a (S n) m)) *)
  intros Hnmk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (sum_n_m_Chasles _ _ n).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite sum_n_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_n_Sn.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_S (a : nat -> G) (n m : nat) :
  sum_n_m (fun n => a (S n)) n m = sum_n_m a (S n) (S m).
Proof.
(* Goal: @eq (AbelianGroup.sort G) (sum_n_m (fun n : nat => a (S n)) n m) (sum_n_m a (S n) (S m)) *)
  apply iter_nat_S.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_Sn (a : nat -> G) (n : nat) :
  sum_n a (S n) = plus (sum_n a n) (a (S n)).
Proof.
(* Goal: @eq (AbelianGroup.sort G) (sum_n a (S n)) (@plus G (sum_n a n) (a (S n))) *)
  apply sum_n_Sm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_zero (a : nat -> G) (n m : nat) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (m < n)%nat -> sum_n_m a n m = zero.
Proof.
(* Goal: forall _ : le n m, @eq (AbelianGroup.sort G) (sum_n_m a (S n) m) (@minus G (sum_n a m) (sum_n a n)) *)
  intros Hnm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n_m.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: n m a Hnm => [ | n IH] m a Hnm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply lt_n_O in Hnm.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: m Hnm => [|m] Hnm //.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -iter_nat_S.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => scal a (u (S n))) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => u (S n)) n m)) *)
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  apply IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply lt_S_n.
Qed.
Lemma sum_n_m_const_zero (n m : nat) :
  sum_n_m (fun _ => zero) n m = zero.
Proof.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n_m /iter_nat.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  elim: (seq.iota n (S m - n)) => //= h t ->.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply plus_zero_l.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_ext_loc (a b : nat -> G) (n m : nat) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall k, (n <= k <= m)%nat -> a k = b k) ->
  sum_n_m a n m = sum_n_m b n m.
Proof.
(* Goal: forall _ : forall (k : nat) (_ : and (le n k) (le k m)), @eq (AbelianGroup.sort G) (a k) (b k), @eq (AbelianGroup.sort G) (sum_n_m a n m) (sum_n_m b n m) *)
  intros.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply iter_nat_ext_loc.
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_ext (a b : nat -> G) n m :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall n, a n = b n) ->
  sum_n_m a n m = sum_n_m b n m.
Proof.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  intros H.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sum_n_m_ext_loc.
Qed.

Lemma sum_n_ext_loc :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (a b : nat -> G) N,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall n, (n <= N)%nat -> a n = b n) ->
  sum_n a N = sum_n b N.
Proof.
(* Goal: forall (a b : forall _ : nat, AbelianGroup.sort G) (N : nat) (_ : forall n : nat, @eq (AbelianGroup.sort G) (a n) (b n)), @eq (AbelianGroup.sort G) (sum_n a N) (sum_n b N) *)
  intros a b N H.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply sum_n_m_ext_loc => k [ _ Hk].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply H.
Qed.
Lemma sum_n_ext :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (a b : nat -> G) N,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall n, a n = b n) ->
  sum_n a N = sum_n b N.
Proof.
(* Goal: forall (a b : forall _ : nat, AbelianGroup.sort G) (N : nat) (_ : forall n : nat, @eq (AbelianGroup.sort G) (a n) (b n)), @eq (AbelianGroup.sort G) (sum_n a N) (sum_n b N) *)
  intros a b N H.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sum_n_ext_loc.
Qed.

Lemma sum_n_m_plus :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (u v : nat -> G) (n m : nat),
  sum_n_m (fun k => plus (u k) (v k)) n m = plus (sum_n_m u n m) (sum_n_m v n m).
Proof.
(* Goal: forall (u v : forall _ : nat, AbelianGroup.sort G) (n m : nat), @eq (AbelianGroup.sort G) (sum_n_m (fun k : nat => @plus G (u k) (v k)) n m) (@plus G (sum_n_m u n m) (sum_n_m v n m)) *)
  intros u v n m.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (le_dec n m) => Hnm.
  elim: m n u v Hnm => [ | m IH] ;
  case => [ | n] u v Hnm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite !sum_n_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_Sn_O in Hnm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_Sm ; try by apply le_O_n.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite IH.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -2!plus_assoc.
(* Goal: @eq (Ring.sort T) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@coeff_mat (Ring.sort T) (S m) l (@zero (Ring.AbelianGroup T)) (@mk_matrix (Ring.sort T) (S m) l (fun i j : nat => @sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B i l0) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l0 j)) (Init.Nat.pred k))) m' l')) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
  apply f_equal.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite plus_comm -plus_assoc.
(* Goal: @eq (AbelianGroup.sort G) (@plus G (u (S m)) (@plus G (v (S m)) (sum_n_m v O m))) (@plus G (u (S m)) (@plus G (sum_n_m v O m) (v (S m)))) *)
(* Goal: le O m *)
(* Goal: @eq (AbelianGroup.sort G) (sum_n_m (fun k : nat => @plus G (u k) (v k)) (S n) (S m)) (@plus G (sum_n_m u (S n) (S m)) (sum_n_m v (S n) (S m))) *)
(* Goal: @eq (AbelianGroup.sort G) (sum_n_m (fun k : nat => @plus G (u k) (v k)) n m) (@plus G (sum_n_m u n m) (sum_n_m v n m)) *)
  apply f_equal, plus_comm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite /sum_n_m -!iter_nat_S -!/(sum_n_m _ n m).
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => scal a (u (S n))) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => u (S n)) n m)) *)
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  apply IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_S_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  apply not_le in Hnm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_m_zero //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite plus_zero_l.
Qed.

Lemma sum_n_plus :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (u v : nat -> G) (n : nat),
  sum_n (fun k => plus (u k) (v k)) n = plus (sum_n u n) (sum_n v n).
Proof.
(* Goal: forall (u v : forall _ : nat, AbelianGroup.sort G) (n : nat), @eq (AbelianGroup.sort G) (sum_n (fun k : nat => @plus G (u k) (v k)) n) (@plus G (sum_n u n) (sum_n v n)) *)
  intros u v n.
(* Goal: @eq (AbelianGroup.sort G) (sum_n (fun k : nat => @plus G (u k) (v k)) n) (@plus G (sum_n u n) (sum_n v n)) *)
  apply sum_n_m_plus.
Qed.

Lemma sum_n_switch :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (u : nat -> nat -> G) (m n : nat),
  sum_n (fun i => sum_n (u i) n) m = sum_n (fun j => sum_n (fun i => u i j) m) n.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (or (Rlt x y) (Rlt y x)) (not (@eq R x y)) *)
(* Goal: @open R_UniformSpace (fun u : UniformSpace.sort R_UniformSpace => or (Rlt u y) (Rlt y u)) *)
  intros u.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n.
(* Goal: forall m n : nat, @eq (AbelianGroup.sort G) (sum_n_m (fun i : nat => sum_n_m (u i) O n) O m) (sum_n_m (fun j : nat => sum_n_m (fun i : nat => u i j) O m) O n) *)
  induction m ; simpl ; intros n.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_n.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply iter_nat_ext_loc => k Hk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_Sm.
(* Goal: @eq (AbelianGroup.sort G) (@plus G (sum_n_m (fun i : nat => sum_n_m (u i) O n) O m) (sum_n_m (u (S m)) O n)) (sum_n_m (fun j : nat => sum_n_m (fun i : nat => u i j) O (S m)) O n) *)
(* Goal: le O (S m) *)
  rewrite IHm ; clear IHm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -sum_n_m_plus.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply sum_n_m_ext_loc => k Hk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_Sm //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_sum_n (a:nat -> G) (n m : nat) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (n <= m)%nat -> sum_n_m a (S n) m = minus (sum_n a m) (sum_n a n).
Proof.
(* Goal: forall _ : le n m, @eq (AbelianGroup.sort G) (sum_n_m a (S n) m) (@minus G (sum_n a m) (sum_n a n)) *)
  intros Hnm.
(* Goal: @eq (AbelianGroup.sort G) (sum_n_m a (S n) m) (@minus G (sum_n a m) (sum_n a n)) *)
  apply plus_reg_l with (sum_n a n).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite (plus_comm _ (minus _ _)) /minus -plus_assoc plus_opp_l plus_zero_r.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n /sum_n_m.
(* Goal: @eq (AbelianGroup.sort G) (@plus G (@iter_nat (AbelianGroup.sort G) (@plus G) (@zero G) a O n) (@iter_nat (AbelianGroup.sort G) (@plus G) (@zero G) a (S n) m)) (@iter_nat (AbelianGroup.sort G) (@plus G) (@zero G) a O m) *)
  apply sym_eq, sum_n_m_Chasles.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
Qed.

End Sums.

(** ** Noncommutative rings *)

Module Ring.

Record mixin_of (K : AbelianGroup) := Mixin {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  mult : K -> K -> K ;
  one : K ;
  ax1 : forall x y z, mult x (mult y z) = mult (mult x y) z ;
  ax2 : forall x, mult x one = x ;
  ax3 : forall x, mult one x = x ;
  ax4 : forall x y z, mult (plus x y) z = plus (mult x z) (mult y z) ;
  ax5 : forall x y z, mult x (plus y z) = plus (mult x y) (mult x z)
}.

Section ClassDef.

Record class_of (K : Type) := Class {
  base : AbelianGroup.class_of K ;
  mixin : mixin_of (AbelianGroup.Pack _ base K)
}.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base : class_of >-> AbelianGroup.class_of.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.

Variable cT : type.

Definition class := let: Pack _ c _ := cT return class_of cT in c.

Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of xT).

Definition AbelianGroup := AbelianGroup.Pack cT xclass xT.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base : class_of >-> AbelianGroup.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion mixin : class_of >-> mixin_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion AbelianGroup : type >-> AbelianGroup.type.
Canonical AbelianGroup.
Notation Ring := type.

End Exports.

End Ring.

Export Ring.Exports.

(** Arithmetic operations *)

Section Ring1.

Context {K : Ring}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition mult : K -> K -> K := Ring.mult _ (Ring.class K).
Definition one : K := Ring.one _ (Ring.class K).

Lemma mult_assoc :
  forall x y z : K,
  mult x (mult y z) = mult (mult x y) z.
Proof.
(* Goal: forall x y z : Ring.sort K, @eq (Ring.sort K) (mult x (mult y z)) (mult (mult x y) z) *)
apply Ring.ax1.
Qed.

Lemma mult_one_r :
  forall x : K,
  mult x one = x.
Proof.
(* Goal: forall x : Ring.sort K, @eq (Ring.sort K) (mult x one) x *)
apply Ring.ax2.
Qed.

Lemma mult_one_l :
  forall x : K,
  mult one x = x.
Proof.
(* Goal: forall x : Ring.sort K, @eq (Ring.sort K) (mult one x) x *)
apply Ring.ax3.
Qed.

Lemma mult_distr_r :
  forall x y z : K,
  mult (plus x y) z = plus (mult x z) (mult y z).
Proof.
(* Goal: forall x y z : Ring.sort K, @eq (Ring.sort K) (mult (@plus (Ring.AbelianGroup K) x y) z) (@plus (Ring.AbelianGroup K) (mult x z) (mult y z)) *)
apply Ring.ax4.
Qed.

Lemma mult_distr_l :
  forall x y z : K,
  mult x (plus y z) = plus (mult x y) (mult x z).
Proof.
(* Goal: forall x y z : Ring.sort K, @eq (Ring.sort K) (mult x (@plus (Ring.AbelianGroup K) y z)) (@plus (Ring.AbelianGroup K) (mult x y) (mult x z)) *)
apply Ring.ax5.
Qed.

Lemma mult_zero_r :
  forall x : K,
  mult x zero = zero.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq (Ring.sort K) (mult x (@zero (Ring.AbelianGroup K))) (@zero (Ring.AbelianGroup K)) *)
apply plus_reg_r with (mult x zero).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- mult_distr_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_zero_r.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_zero_l.
Qed.

Lemma mult_zero_l :
  forall x : K,
  mult zero x = zero.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq (Ring.sort K) (mult (@zero (Ring.AbelianGroup K)) x) (@zero (Ring.AbelianGroup K)) *)
apply plus_reg_r with (mult zero x).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- mult_distr_r.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_zero_r.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_zero_l.
Qed.

Lemma opp_mult_r :
  forall x y : K,
  opp (mult x y) = mult x (opp y).
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
intros x y.
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup K)) (@opp (Ring.AbelianGroup K) (mult x y)) (mult (@opp (Ring.AbelianGroup K) x) y) *)
apply plus_reg_l with (mult x y).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite plus_opp_r -mult_distr_l.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_opp_r mult_zero_r.
Qed.

Lemma opp_mult_l :
  forall x y : K,
  opp (mult x y) = mult (opp x) y.
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
intros x y.
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup K)) (@opp (Ring.AbelianGroup K) (mult x y)) (mult (@opp (Ring.AbelianGroup K) x) y) *)
apply plus_reg_l with (mult x y).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite plus_opp_r -mult_distr_r.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_opp_r mult_zero_l.
Qed.

Lemma opp_mult_m1 :
  forall x : K,
  opp x = mult (opp one) x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
  intros x.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -opp_mult_l opp_mult_r.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite mult_one_l.
Qed.

Lemma sum_n_m_mult_r :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
 forall (a : K) (u : nat -> K) (n m : nat),
  sum_n_m (fun k => mult (u k) a) n m = mult (sum_n_m u n m) a.
Proof.
(* Goal: forall (a : Ring.sort K) (u : forall _ : nat, ModuleSpace.sort K V) (n m : nat), @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  intros a u n m.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (le_dec n m) => Hnm.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: m n u Hnm => [ | m IH] n u Hnm.
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n O) (sum_f n O a) *)
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n (S m)) (sum_f n (S m) a) *)
  apply le_n_O_eq in Hnm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite -Hnm !sum_n_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n (S m)) (@sum_n_m R_AbelianGroup b n (S m)) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  destruct n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_Sm ; try by apply le_O_n.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sym_eq, mult_distr_r.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -!sum_n_m_S.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => scal a (u (S n))) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => u (S n)) n m)) *)
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  apply IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_S_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  apply not_le in Hnm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_m_zero //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite mult_zero_l.
Qed.

Lemma sum_n_m_mult_l :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
 forall (a : K) (u : nat -> K) (n m : nat),
  sum_n_m (fun k => mult a (u k)) n m = mult a (sum_n_m u n m).
Proof.
(* Goal: forall (a : Ring.sort K) (u : forall _ : nat, ModuleSpace.sort K V) (n m : nat), @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  intros a u n m.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (le_dec n m) => Hnm.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: m n u Hnm => [ | m IH] n u Hnm.
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n O) (sum_f n O a) *)
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n (S m)) (sum_f n (S m) a) *)
  apply le_n_O_eq in Hnm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite -Hnm !sum_n_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n (S m)) (@sum_n_m R_AbelianGroup b n (S m)) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  destruct n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_Sm ; try by apply le_O_n.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sym_eq, mult_distr_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -!sum_n_m_S.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => scal a (u (S n))) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => u (S n)) n m)) *)
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  apply IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_S_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  apply not_le in Hnm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_m_zero //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite mult_zero_r.
Qed.

Lemma sum_n_mult_r :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
 forall (a : K) (u : nat -> K) (n : nat),
  sum_n (fun k => mult (u k) a) n = mult (sum_n u n) a.
Proof.
(* Goal: forall (a : Ring.sort K) (u : forall _ : nat, Ring.sort K) (n : nat), @eq (AbelianGroup.sort (Ring.AbelianGroup K)) (@sum_n (Ring.AbelianGroup K) (fun k : nat => mult a (u k)) n) (mult a (@sum_n (Ring.AbelianGroup K) u n)) *)
  intros ; by apply sum_n_m_mult_r.
Qed.

Lemma sum_n_mult_l :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
 forall (a : K) (u : nat -> K) (n : nat),
  sum_n (fun k => mult a (u k)) n = mult a (sum_n u n).
Proof.
(* Goal: forall (a : Ring.sort K) (u : forall _ : nat, Ring.sort K) (n : nat), @eq (AbelianGroup.sort (Ring.AbelianGroup K)) (@sum_n (Ring.AbelianGroup K) (fun k : nat => mult a (u k)) n) (mult a (@sum_n (Ring.AbelianGroup K) u n)) *)
  intros ; by apply sum_n_m_mult_l.
Qed.

(** pow_n *)

Fixpoint pow_n (x : K) (N : nat) {struct N} : K :=
  match N with
   | 0%nat => one
   | S i => mult x (pow_n x i)
  end.

Lemma pow_n_plus :
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  forall (x : K) (n m : nat), pow_n x (n+m) = mult (pow_n x n) (pow_n x m).
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
  intros x.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim => /= [ | n IH] m.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite mult_one_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite IH mult_assoc.
Qed.

Lemma pow_n_comm_1 :
  forall (x : K) (n : nat), mult (pow_n x n) x = mult x (pow_n x n).
Proof.
(* Goal: forall (x : Ring.sort K) (n : nat), @eq (Ring.sort K) (mult (pow_n x n) x) (mult x (pow_n x n)) *)
  intros x n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: n => /= [ | n IH].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite mult_one_l mult_one_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite -(mult_assoc _ (pow_n x n)) IH.
Qed.

Lemma pow_n_comm :
  forall (x : K) n m, mult (pow_n x n) (pow_n x m) = mult (pow_n x m) (pow_n x n).
Proof.
(* Goal: forall (x : Ring.sort K) (n m : nat), @eq (Ring.sort K) (mult (pow_n x n) (pow_n x m)) (mult (pow_n x m) (pow_n x n)) *)
  intros x n m.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -2!pow_n_plus.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply f_equal, Plus.plus_comm.
Qed.

End Ring1.

(** ** Rings with absolute value *)

Module AbsRing.

Record mixin_of (K : Ring) := Mixin {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  abs : K -> R ;
  ax1 : abs zero = 0 ;
  ax2 : abs (opp one) = 1 ;
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  ax3 : forall x y : K, abs (plus x y) <= abs x + abs y ;
  ax4 : forall x y : K, abs (mult x y) <= abs x * abs y ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax5 : forall x : K, abs x = 0 -> x = zero
}.

Section ClassDef.

Record class_of (K : Type) := Class {
  base : Ring.class_of K ;
  mixin : mixin_of (Ring.Pack _ base K)
}.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base : class_of >-> Ring.class_of.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.

Variable cT : type.

Definition class := let: Pack _ c _ := cT return class_of cT in c.

Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of xT).

Definition AbelianGroup := AbelianGroup.Pack cT xclass xT.
Definition Ring := Ring.Pack cT xclass xT.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base : class_of >-> Ring.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion mixin : class_of >-> mixin_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion AbelianGroup : type >-> AbelianGroup.type.
Canonical AbelianGroup.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion Ring : type >-> Ring.type.
Canonical Ring.
Notation AbsRing := type.

End Exports.

End AbsRing.

Export AbsRing.Exports.

(** Usual properties *)

Section AbsRing1.

Context {K : AbsRing}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition abs : K -> R := AbsRing.abs _ (AbsRing.class K).

Lemma abs_zero :
  abs zero = 0.
Proof.
(* Goal: @eq R (abs (@zero (AbsRing.AbelianGroup K))) (IZR Z0) *)
apply AbsRing.ax1.
Qed.

Lemma abs_opp_one :
  abs (opp one) = 1.
Proof.
(* Goal: @eq R (abs (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (IZR (Zpos xH)) *)
apply AbsRing.ax2.
Qed.

Lemma abs_triangle :
  forall x y : K,
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  abs (plus x y) <= abs x + abs y.
Proof.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: AbsRing.ax3.
Qed.

Lemma abs_mult :
  forall x y : K,
  abs (mult x y) <= abs x * abs y.
Proof.
(* Goal: forall x y : AbsRing.sort K, Rle (abs (@mult (AbsRing.Ring K) x y)) (Rmult (abs x) (abs y)) *)
apply AbsRing.ax4.
Qed.

Lemma abs_eq_zero :
  forall x : K,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  abs x = 0 -> x = zero.
Proof.
(* Goal: forall (x : AbsRing.sort K) (_ : @eq R (abs x) (IZR Z0)), @eq (AbsRing.sort K) x (@zero (AbsRing.AbelianGroup K)) *)
apply AbsRing.ax5.
Qed.

Lemma abs_opp :
  forall x, abs (opp x) = abs x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq R (Rabs (Rminus u x)) (IZR Z0) *)
apply Rle_antisym.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- rewrite opp_mult_m1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rmult_1_l (abs x)) -abs_opp_one.
(* Goal: Rle (abs (@mult (AbsRing.Ring K) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) (@opp (AbsRing.AbelianGroup K) x))) (Rmult (abs (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (abs (@opp (AbsRing.AbelianGroup K) x))) *)
  apply abs_mult.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- rewrite -{1}[x]opp_opp.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite opp_mult_m1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rmult_1_l (abs (opp x))) -abs_opp_one.
(* Goal: Rle (abs (@mult (AbsRing.Ring K) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) (@opp (AbsRing.AbelianGroup K) x))) (Rmult (abs (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (abs (@opp (AbsRing.AbelianGroup K) x))) *)
  apply abs_mult.
Qed.

Lemma abs_minus :
  forall x y : K, abs (minus x y) = abs (minus y x).
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
intros x y.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
by rewrite /minus -abs_opp opp_plus opp_opp plus_comm.
Qed.

Lemma abs_one :
  abs one = 1.
Proof.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite -abs_opp.
(* Goal: @eq R (abs (@opp (AbsRing.AbelianGroup K) (@one (AbsRing.Ring K)))) (IZR (Zpos xH)) *)
exact abs_opp_one.
Qed.

Lemma abs_ge_0 :
  forall x, 0 <= abs x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
  intros x.
(* Goal: Rle (IZR Z0) (norm x) *)
  apply Rmult_le_reg_l with 2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rlt_0_2.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite Rmult_0_r -abs_zero -(plus_opp_l x).
(* Goal: Rle (abs (@plus (AbsRing.AbelianGroup K) (@opp (AbsRing.AbelianGroup K) x) x)) (Rmult (IZR (Zpos (xO xH))) (abs x)) *)
  apply Rle_trans with (1 := abs_triangle _ _).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite abs_opp.
(* Goal: Rle (Rplus (abs x) (abs x)) (Rmult (IZR (Zpos (xO xH))) (abs x)) *)
  apply Req_le ; ring.
Qed.

Lemma abs_pow_n :
  forall (x : K) n,
  abs (pow_n x n) <= (abs x)^n.
Proof.
induction n.
apply Req_le, abs_one.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
simpl.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: Rle_trans (abs_mult _ _) _.
apply Rmult_le_compat_l with (2 := IHn).
apply abs_ge_0.
Qed.

End AbsRing1.

(** * Uniform spaces defined using balls *)

Module UniformSpace.

Record mixin_of (M : Type) := Mixin {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ball : M -> R -> M -> Prop ;
  ax1 : forall x (e : posreal), ball x e x ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax2 : forall x y e, ball x e y -> ball y e x ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax3 : forall x y z e1 e2, ball x e1 y -> ball y e2 z -> ball x (e1 + e2) z
}.

Notation class_of := mixin_of (only parsing).

Section ClassDef.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.
Definition class (cT : type) := let: Pack _ c _ := cT return class_of cT in c.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
Notation UniformSpace := type.

End Exports.

End UniformSpace.

Export UniformSpace.Exports.

Section UniformSpace1.

Context {M : UniformSpace}.

Definition ball := UniformSpace.ball _ (UniformSpace.class M).

Lemma ball_center :
  forall (x : M) (e : posreal),
  ball x e x.
Proof.
(* Goal: forall (x : UniformSpace.sort M) (e : posreal), ball x (pos e) x *)
apply UniformSpace.ax1.
Qed.

Lemma ball_sym :
  forall (x y : M) (e : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ball x e y -> ball y e x.
Proof.
(* Goal: forall (x y : UniformSpace.sort M) (e : R) (_ : ball x e y), ball y e x *)
apply UniformSpace.ax2.
Qed.

Lemma ball_triangle :
  forall (x y z : M) (e1 e2 : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ball x e1 y -> ball y e2 z -> ball x (e1 + e2) z.
Proof.
(* Goal: forall (x y z : UniformSpace.sort M) (e1 e2 : R) (_ : ball x e1 y) (_ : ball y e2 z), ball x (Rplus e1 e2) z *)
apply UniformSpace.ax3.
Qed.

Lemma ball_le :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : M) (e1 e2 : R), e1 <= e2 ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (y : M), ball x e1 y -> ball x e2 y.
Proof.
(* Goal: forall (x : UniformSpace.sort M) (e1 e2 : R) (_ : Rle e1 e2) (y : UniformSpace.sort M) (_ : ball x e1 y), ball x e2 y *)
intros x e1 e2 H y H1.
(* Goal: ball x e2 y *)
destruct H.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
assert (e2 - e1 > 0).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by apply Rgt_minus.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
assert (ball y {| pos := (e2-e1); cond_pos := (H0) |} y).
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
apply ball_center.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace e2 with (e1 + (e2 - e1)).
(* Goal: ball x (Rplus e1 (Rminus e2 e1)) y *)
(* Goal: @eq R (Rplus e1 (Rminus e2 e1)) e2 *)
(* Goal: ball x e2 y *)
apply ball_triangle with y ; assumption.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by apply Rplus_minus.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
by rewrite <- H.
Qed.

Definition close (x y : M) : Prop := forall eps : posreal, ball x eps y.

Lemma close_refl (x : M) : close x x.
Proof.
(* Goal: @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
intros eps.
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
apply ball_center.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma close_sym (x y : M) : close x y -> close y x.
Proof.
(* Goal: forall (_ : continuity_pt f x) (eps : posreal), @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
intros H eps.
(* Goal: @ball (CompleteSpace.UniformSpace U) (f v y) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (h v) *)
(* Goal: forall (x : UniformSpace.sort (CompleteSpace.UniformSpace U)) (_ : @filterlim T1 (CompleteSpace.sort U) h F1 (@locally (CompleteSpace.UniformSpace U) x)), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) *)
now apply ball_sym.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma close_trans (x y z : M) : close x y -> close y z -> close x z.
Proof.
(* Goal: forall (_ : close x y) (_ : close y z), close x z *)
intros H1 H2 eps.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite (double_var eps) -[eps / 2]/(pos (pos_div_2 eps)).
(* Goal: ball x (Rplus (pos (pos_div_2 eps)) (pos (pos_div_2 eps))) z *)
now eapply ball_triangle.
Qed.

End UniformSpace1.

(** ** Specific uniform spaces *)

(** Rings with absolute value *)

Section AbsRing_UniformSpace.

Variable K : AbsRing.

Definition AbsRing_ball (x : K) (eps : R) (y : K) := abs (minus y x) < eps.

Lemma AbsRing_ball_center :
  forall (x : K) (e : posreal),
  AbsRing_ball x e x.
Proof.
(* Goal: forall (x : AbsRing.sort K) (e : posreal), AbsRing_ball x (pos e) x *)
  intros x e.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /AbsRing_ball /minus plus_opp_r abs_zero.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
  apply cond_pos.
Qed.

Lemma AbsRing_ball_sym :
  forall (x y : K) (e : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  AbsRing_ball x e y -> AbsRing_ball y e x.
Proof.
(* Goal: forall (x y : AbsRing.sort K) (e : R) (_ : AbsRing_ball x e y), AbsRing_ball y e x *)
  intros x y e.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite /AbsRing_ball abs_minus.
Qed.

Lemma AbsRing_ball_triangle :
  forall (x y z : K) (e1 e2 : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  AbsRing_ball x e1 y -> AbsRing_ball y e2 z ->
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  AbsRing_ball x (e1 + e2) z.
Proof.
intros x y z e1 e2 H1 H2.
unfold AbsRing_ball.
replace (minus z x) with (plus (minus y x) (minus z y)).
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: Rle_lt_trans (abs_triangle _ _) _.
now apply Rplus_lt_compat.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_comm /minus plus_assoc.
apply (f_equal (fun y => plus y _)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- plus_assoc.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_opp_l plus_zero_r.
Qed.


Definition AbsRing_UniformSpace_mixin :=
  UniformSpace.Mixin _ _ AbsRing_ball_center AbsRing_ball_sym AbsRing_ball_triangle.

Canonical AbsRing_UniformSpace :=
  UniformSpace.Pack K AbsRing_UniformSpace_mixin K.

End AbsRing_UniformSpace.

(** Functional metric spaces *)

Section fct_UniformSpace.

Variable (T : Type) (U : UniformSpace).

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition fct_ball (x : T -> U) (eps : R) (y : T -> U) :=
  forall t : T, ball (x t) eps (y t).

Lemma fct_ball_center :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : T -> U) (e : posreal),
  fct_ball x e x.
Proof.
(* Goal: forall (x : forall _ : T, UniformSpace.sort U) (e : posreal), fct_ball x (pos e) x *)
  intros x e t.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  exact: ball_center.
Qed.

Lemma fct_ball_sym :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x y : T -> U) (e : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  fct_ball x e y -> fct_ball y e x.
Proof.
(* Goal: forall (x y : forall _ : T, UniformSpace.sort U) (e : R) (_ : fct_ball x e y), fct_ball y e x *)
  intros x y e H t.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  exact: ball_sym.
Qed.

Lemma fct_ball_triangle :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x y z : T -> U) (e1 e2 : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  fct_ball x e1 y -> fct_ball y e2 z -> fct_ball x (e1 + e2) z.
Proof.
(* Goal: forall (x y z : forall _ : T, UniformSpace.sort U) (e1 e2 : R) (_ : fct_ball x e1 y) (_ : fct_ball y e2 z), fct_ball x (Rplus e1 e2) z *)
  intros x y z e1 e2 H1 H2 t.
(* Goal: @ball U (x t) (Rplus e1 e2) (z t) *)
  now apply ball_triangle with (y t).
Qed.


Definition fct_UniformSpace_mixin :=
  UniformSpace.Mixin _ _ fct_ball_center fct_ball_sym fct_ball_triangle.

Canonical fct_UniformSpace :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  UniformSpace.Pack (T -> U) fct_UniformSpace_mixin (T -> U).

End fct_UniformSpace.

(** ** Local predicates *)
(** locally_dist *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition locally_dist {T : Type} (d : T -> R) (P : T -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists delta : posreal, forall y, d y < delta -> P y.

Global Instance locally_dist_filter :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T (d : T -> R), Filter (locally_dist d).
Proof.
(* Goal: forall (T : Type) (d : forall _ : T, R), @Filter T (@locally_dist T d) *)
intros T d.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now exists (mkposreal _ Rlt_0_1).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q [dP HP] [dQ HQ].
(* Goal: Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  exists (mkposreal _ (Rmin_stable_in_posreal dP dQ)).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  simpl.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: Rlt y MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le_trans with (1 := Hy).
(* Goal: Rle (Rmin MP MQ) MP *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_l.
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HQ.
(* Goal: Rlt y MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le_trans with (1 := Hy).
(* Goal: Rle (Rmin MP MQ) MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H [dP HP].
(* Goal: Rbar_locally' m_infty Q *)
  exists dP.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: P y *)
  now apply HP.
Qed.

(** locally *)

Section Locally.

Context {T : UniformSpace}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition locally (x : T) (P : T -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists eps : posreal, forall y, ball x eps y -> P y.

Global Instance locally_filter :
  forall x : T, ProperFilter (locally x).
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @ProperFilter (UniformSpace.sort T) (locally x) *)
constructor ; [idtac|constructor].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P [eps H].
(* Goal: @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps))) *)
  exists x.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
  apply ball_center.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now exists (mkposreal _ Rlt_0_1).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q [dP HP] [dQ HQ].
(* Goal: Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  exists (mkposreal _ (Rmin_stable_in_posreal dP dQ)).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  simpl.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: @ball T x z y *)
  apply ball_le with (2 := Hy).
(* Goal: Rle (Rmin MP MQ) MP *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_l.
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HQ.
(* Goal: @ball T x z y *)
  apply ball_le with (2 := Hy).
(* Goal: Rle (Rmin MP MQ) MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H [dP HP].
(* Goal: Rbar_locally' m_infty Q *)
  exists dP.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: P y *)
  now apply HP.
Qed.

Lemma locally_locally :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : T) (P : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally x P -> locally x (fun y => locally y P).
Proof.
(* Goal: forall (x : UniformSpace.sort T) (P : forall _ : UniformSpace.sort T, Prop) (_ : locally x P), locally x (fun y : UniformSpace.sort T => locally y P) *)
intros x P [dp Hp].
(* Goal: locally x (fun y : UniformSpace.sort T => locally y P) *)
exists (pos_div_2 dp).
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
intros y Hy.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists (pos_div_2 dp) => /= z Hz.
(* Goal: P (Ropp (INR n)) *)
apply Hp.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite (double_var dp).
(* Goal: @ball T x (Rplus (Rdiv (pos dp) (IZR (Zpos (xO xH)))) (Rdiv (pos dp) (IZR (Zpos (xO xH))))) z *)
now apply ball_triangle with y.
Qed.

Lemma locally_singleton :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : T) (P : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally x P -> P x.
Proof.
(* Goal: forall (x : UniformSpace.sort T) (P : forall _ : UniformSpace.sort T, Prop) (_ : locally x P), P x *)
intros x P [dp H].
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
apply H.
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
by apply ball_center.
Qed.

Lemma locally_ball :
  forall (x : T) (eps : posreal), locally x (ball x eps).
Proof.
(* Goal: forall (x : prod (UniformSpace.sort U) (UniformSpace.sort V)) (eps : posreal), prod_ball x (pos eps) x *)
  intros x eps.
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
  now exists eps.
Qed.

Lemma locally_not' :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : T) (P : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  not (forall eps : posreal, not (forall y, ball x eps y -> not (P y))) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  {d : posreal | forall y, ball x d y -> not (P y)}.
Proof.
(* Goal: forall (x : UniformSpace.sort T) (P : forall _ : UniformSpace.sort T, Prop) (_ : locally x (fun y : UniformSpace.sort T => not (P y))), @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
intros x P H.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
set (Q := fun z => z <= 1 /\ forall y, ball x z y -> not (P y)).
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
destruct (completeness Q) as [d [H1 H2]].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- exists 1.
(* Goal: is_upper_bound Q (IZR (Zpos xH)) *)
(* Goal: @ex R (fun x : R => Q x) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  now intros y [Hy _].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- exists 0.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: Rle (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall (y : UniformSpace.sort T) (_ : @ball T x (IZR Z0) y), not (P y) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply Rle_0_1.
(* Goal: forall (y : UniformSpace.sort T) (_ : @ball T x (IZR Z0) y), not (P y) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  intros y Hy Py.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: forall eps : posreal, not (forall (y : UniformSpace.sort T) (_ : @ball T x (pos eps) y), not (P y)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  intros eps He.
(* Goal: False *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply He with (2 := Py).
(* Goal: @ball T x z y *)
  apply ball_le with (2 := Hy).
(* Goal: Rle (IZR Z0) (pos eps) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply Rlt_le, eps.
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
assert (Zd : 0 < d).
(* Goal: Rlt (IZR Z0) d *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply Rnot_le_lt.
(* Goal: not (Rle d (IZR Z0)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  intros Hd.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: forall eps : posreal, not (forall (y : UniformSpace.sort T) (_ : @ball T x (pos eps) y), not (P y)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  intros eps He.
(* Goal: False *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply (Rlt_irrefl (Rmin 1 eps)).
(* Goal: Rlt (Rmin (IZR (Zpos xH)) (pos eps)) (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply Rle_lt_trans with d.
(* Goal: Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) *)
  apply H1.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: Rle (Rmin MP MQ) MP *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_l.
(* Goal: forall (y : NormedModule.sort K V) (_ : ball_norm x (pos eps) y), P y *)
  intros y By.
(* Goal: not (P y) *)
(* Goal: Rlt d (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply He.
(* Goal: @ball T x (pos eps) y *)
(* Goal: Rlt d (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply ball_le with (2 := By).
(* Goal: Rle (Rmin MP MQ) MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_r.
(* Goal: Rlt d (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply Rle_lt_trans with (1 := Hd).
(* Goal: Rlt (IZR Z0) (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply Rmin_case.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: Rlt (IZR Z0) (pos eps) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply Rlt_0_1.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
  apply cond_pos.
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
exists (mkposreal _ (is_pos_div_2 (mkposreal _ Zd))).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
simpl.
(* Goal: forall (y : UniformSpace.sort T) (_ : @ball T x (Rdiv d (IZR (Zpos (xO xH)))) y), not (P y) *)
intros y Hy HP.
(* Goal: False *)
apply (Rlt_not_le _ _ (Rlt_eps2_eps _ Zd)).
(* Goal: Rle d (Rmult d (Rinv (IZR (Zpos (xO xH))))) *)
apply H2.
(* Goal: is_upper_bound Q (Rmult d (Rinv (IZR (Zpos (xO xH))))) *)
intros z Hz.
(* Goal: forall _ : not (Rlt x y), Rle y x *)
(* Goal: forall _ : Rle y x, not (Rlt x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (Rlt u y)) *)
apply Rnot_lt_le.
(* Goal: not (Rlt (Rmult d (Rinv (IZR (Zpos (xO xH))))) z) *)
contradict HP.
(* Goal: @ball T x (Rdiv (pos eps) (IZR (Zpos (xO xH)))) z *)
(* Goal: @ball T z (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
apply Hz.
(* Goal: @ball T x z y *)
apply ball_le with (2 := Hy).
(* Goal: Rle (Rabs (Rminus z t)) (pos d2) *)
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now apply Rlt_le.
Qed.

Lemma locally_not :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : T) (P : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  not (forall eps : posreal, not (forall y, ball x eps y -> not (P y))) ->
  locally x (fun y => not (P y)).
Proof.
(* Goal: forall (x : UniformSpace.sort T) (P : forall _ : UniformSpace.sort T, Prop) (_ : locally x (fun y : UniformSpace.sort T => not (P y))), @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
intros x P H.
(* Goal: locally x (fun y : UniformSpace.sort T => not (P y)) *)
destruct (locally_not' x P H) as [eps He].
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
now exists eps.
Qed.

Lemma locally_ex_not :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : T) (P : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally x (fun y => not (P y)) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  {d : posreal | forall y, ball x d y -> not (P y)}.
Proof.
(* Goal: forall (x : UniformSpace.sort T) (P : forall _ : UniformSpace.sort T, Prop) (_ : locally x (fun y : UniformSpace.sort T => not (P y))), @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
intros x P H.
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
apply locally_not'.
(* Goal: not (forall eps : posreal, not (forall (y : UniformSpace.sort T) (_ : @ball T x (pos eps) y), not (P y))) *)
destruct H as [eps He].
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
intros H.
(* Goal: False *)
now apply (H eps).
Qed.

Lemma locally_ex_dec :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : T) (P : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, P x \/ ~P x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally x P ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  {d : posreal | forall y, ball x d y -> P y}.
Proof.
(* Goal: forall (x : UniformSpace.sort T) (P : forall _ : UniformSpace.sort T, Prop) (_ : forall x0 : UniformSpace.sort T, or (P x0) (not (P x0))) (_ : locally x P), @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), P y) *)
intros x P P_dec H.
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), P y) *)
destruct (locally_ex_not x (fun y => not (P y))) as [d Hd].
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp H.
(* Goal: forall (x : UniformSpace.sort T) (_ : P x), not (not (P x)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), P y) *)
intros y Py HP.
(* Goal: P y *)
now apply HP.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
exists d.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
intros y Hy.
(* Goal: P y *)
destruct (P_dec y) as [HP|HP].
(* Goal: P y *)
(* Goal: P y *)
exact HP.
(* Goal: P y *)
exfalso.
(* Goal: False *)
now apply (Hd y).
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition is_filter_lim (F : (T -> Prop) -> Prop) (x : T) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall P, locally x P -> F P.

Lemma is_filter_lim_filter_le :
  forall {F G} (x : T),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le G F ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  is_filter_lim F x -> is_filter_lim G x.
Proof.
(* Goal: forall (F G : forall _ : forall _ : UniformSpace.sort T, Prop, Prop) (x : UniformSpace.sort T) (_ : @filter_le (UniformSpace.sort T) G F) (_ : is_filter_lim F x), is_filter_lim G x *)
intros F G x L Fx P HP.
(* Goal: G P *)
apply L.
(* Goal: @filtermap (UniformSpace.sort T) (UniformSpace.sort U) f F P *)
now apply Fx.
Qed.

Lemma is_filter_lim_close {F} {FF : ProperFilter F} (x y : T) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  is_filter_lim F x -> is_filter_lim F y -> close x y.
Proof.
(* Goal: forall (_ : is_filter_lim F x) (_ : is_filter_lim F y), @close T x y *)
  intros Hx Hy eps.
(* Goal: @ball T x (pos eps) y *)
  specialize (Hy _ (locally_ball y (pos_div_2 eps))).
(* Goal: @ball T x (pos eps) y *)
  specialize (Hx _ (locally_ball x (pos_div_2 eps))).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  generalize (filter_and _ _ Hx Hy) => {Hx Hy} H.
(* Goal: @ball T x (pos eps) y *)
  destruct (filter_ex _ H) as [z Hz].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var eps).
(* Goal: @ball T x (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) y *)
  apply ball_triangle with z.
(* Goal: @ball T x (Rdiv (pos eps) (IZR (Zpos (xO xH)))) z *)
(* Goal: @ball T z (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
  apply Hz.
(* Goal: @ball T z (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
  apply ball_sym, Hz.
Qed.

Lemma is_filter_lim_locally_close (x y : T) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  is_filter_lim (locally x) y -> close x y.
Proof.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply is_filter_lim_close.
Qed.

End Locally.

Lemma filterlim_const :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T} {U : UniformSpace} {F : (T -> Prop) -> Prop} {FF : Filter F},
  forall a : U, filterlim (fun _ => a) F (locally a).
Proof.
(* Goal: forall (T : Type) (U : UniformSpace.type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @Filter T F) (a : UniformSpace.sort U), @filterlim T (UniformSpace.sort U) (fun _ : T => a) F (@locally U a) *)
intros T U F FF a P [eps HP].
(* Goal: @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) (f x) (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
unfold filtermap.
(* Goal: F (fun _ : T => P a) *)
apply filter_forall.
(* Goal: forall _ : T, P a *)
intros _.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply HP.
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
apply ball_center.
Qed.

Section Locally_fct.

Context {T : Type} {U : UniformSpace}.

Lemma filterlim_locally :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF : Filter F} (f : T -> U) y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F (locally y) <->
  forall eps : posreal, F (fun x => ball y eps (f x)).
Proof.
intros F FF f y.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros Cf eps.
  apply (Cf (fun x => ball y eps x)).
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
  now exists eps.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros Cf P [eps He].
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
  apply: filter_imp (Cf eps).
  intros t.
(* Goal: not (P y) *)
(* Goal: Rlt d (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply He.
Qed.

Lemma filterlimi_locally :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF : Filter F} (f : T -> U -> Prop) y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F (locally y) <->
  forall eps : posreal, F (fun x => exists z, f x z /\ ball y eps z).
Proof.
intros F FF f y.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros Cf eps.
  apply (Cf (fun x => ball y eps x)).
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
  now exists eps.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros Cf P [eps He].
(* Goal: @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) fx (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
  unfold filtermapi.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
  apply: filter_imp (Cf eps).
  intros t [z [Hz1 Hz2]].
  exists z.
  apply (conj Hz1).
(* Goal: not (P y) *)
(* Goal: Rlt d (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  now apply He.
Qed.

Lemma filterlim_locally_close :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF: ProperFilter F} (f : T -> U) l l',
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F (locally l) ->  filterlim f F (locally l') ->
  close l l'.
Proof.
(* Goal: forall (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F) (f : forall _ : T, UniformSpace.sort U) (l l' : UniformSpace.sort U) (_ : @filterlim T (UniformSpace.sort U) f F (@locally U l)) (_ : @filterlim T (UniformSpace.sort U) f F (@locally U l')), @close U l l' *)
intros F FF f l l' Hl Hl' eps.
(* Goal: @ball U l (pos eps) l' *)
assert (locally l (ball l (pos_div_2 eps))).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply locally_ball.
(* Goal: @ball U l (pos eps) l' *)
specialize (Hl (ball l (pos_div_2 eps)) H).
(* Goal: @ball U l (pos eps) l' *)
assert (locally l' (ball l' (pos_div_2 eps))).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply locally_ball.
(* Goal: @ball U l (pos eps) l' *)
specialize (Hl' (ball l' (pos_div_2 eps)) H0).
(* Goal: @ball U l (pos eps) l' *)
unfold filtermap in Hl, Hl'.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
generalize (filter_and _ _ Hl Hl') => {H H0} H.
(* Goal: @ball U l (pos eps) l' *)
apply filter_ex in H.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
case: H => x H.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite (double_var eps).
(* Goal: @ball U l (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) l' *)
apply ball_triangle with (f x).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by apply H.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by apply ball_sym, H.
Qed.

Lemma filterlimi_locally_close :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF: ProperFilter F} (f : T -> U -> Prop) l l',
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F (locally l) ->  filterlimi f F (locally l') ->
  close l l'.
Proof.
(* Goal: forall (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F) (f : forall (_ : T) (_ : UniformSpace.sort U), Prop) (l l' : UniformSpace.sort U) (_ : F (fun x : T => forall (y1 y2 : UniformSpace.sort U) (_ : f x y1) (_ : f x y2), @eq (UniformSpace.sort U) y1 y2)) (_ : @filterlimi T (UniformSpace.sort U) f F (@locally U l)) (_ : @filterlimi T (UniformSpace.sort U) f F (@locally U l')), @close U l l' *)
intros F FF f l l' Hf Hl Hl' eps.
(* Goal: @ball U l (pos eps) l' *)
assert (H: locally l (ball l (pos_div_2 eps))).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply locally_ball.
(* Goal: @ball U l (pos eps) l' *)
specialize (Hl (ball l (pos_div_2 eps)) H).
(* Goal: @ball U l (pos eps) l' *)
assert (H': locally l' (ball l' (pos_div_2 eps))).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply locally_ball.
(* Goal: @ball U l (pos eps) l' *)
specialize (Hl' (ball l' (pos_div_2 eps)) H').
(* Goal: @ball U l (pos eps) l' *)
unfold filtermapi in Hl, Hl'.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
generalize (filter_and _ _ Hf (filter_and _ _ Hl Hl')) => {H H' Hl Hl' Hf} H.
(* Goal: @ball U l (pos eps) l' *)
apply filter_ex in H.
(* Goal: @ball U l (pos eps) l' *)
destruct H as [x [Hf [[y [H1 H1']] [y' [H2 H2']]]]].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite (double_var eps).
(* Goal: @ball (CompleteSpace.UniformSpace U) fu (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) fv *)
apply ball_triangle with y.
(* Goal: @ball U l (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
(* Goal: @ball U y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) l' *)
exact H1'.
(* Goal: @ball (CompleteSpace.UniformSpace U) fu (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) fv *)
apply ball_sym.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite (Hf _ _ H1 H2).
(* Goal: @ball U l' (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y' *)
exact H2'.
Qed.

End Locally_fct.

Lemma is_filter_lim_filtermap {T: UniformSpace} {U : UniformSpace} :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
forall F x (f : T -> U),
  filterlim f (locally x) (locally (f x))
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  -> is_filter_lim F x
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  -> is_filter_lim (filtermap f F) (f x).
Proof.
(* Goal: forall (F : forall _ : forall _ : UniformSpace.sort T, Prop, Prop) (x : UniformSpace.sort T) (f : forall _ : UniformSpace.sort T, UniformSpace.sort U) (_ : @filterlim (UniformSpace.sort T) (UniformSpace.sort U) f (@locally T x) (@locally U (f x))) (_ : @is_filter_lim T F x), @is_filter_lim U (@filtermap (UniformSpace.sort T) (UniformSpace.sort U) f F) (f x) *)
  intros F x f Cf Fx P HP.
(* Goal: @filtermap (UniformSpace.sort T) (UniformSpace.sort U) f F P *)
  apply Cf in HP.
(* Goal: @filtermap (UniformSpace.sort T) (UniformSpace.sort U) f F P *)
  now apply Fx.
Qed.

(** locally' *)

Definition locally' {T : UniformSpace} (x : T) :=
  within (fun y => y <> x) (locally x).

Global Instance locally'_filter :
  forall {T : UniformSpace} (x : T), Filter (locally' x).
Proof.
(* Goal: forall (T : UniformSpace.type) (x : UniformSpace.sort T), @Filter (UniformSpace.sort T) (@locally' T x) *)
intros T x.
(* Goal: @Filter (UniformSpace.sort T) (@locally' T x) *)
apply within_filter.
(* Goal: @ProperFilter R (Rbar_locally (Finite x)) *)
(* Goal: @ProperFilter R (Rbar_locally p_infty) *)
(* Goal: @ProperFilter R (Rbar_locally m_infty) *)
apply locally_filter.
Qed.

(** Pointed filter *)

Section at_point.

Context {T : UniformSpace}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition at_point (a : T) (P : T -> Prop) : Prop := P a.

Global Instance at_point_filter (a : T) :
  ProperFilter (at_point a).
Proof.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Pa.
(* Goal: @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => P x) *)
(* Goal: @Filter (UniformSpace.sort T) (at_point a) *)
  now exists a.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- split ; try easy.
(* Goal: forall (P Q : forall _ : UniformSpace.sort T, Prop) (_ : forall (x : UniformSpace.sort T) (_ : P x), Q x) (_ : at_point a P), at_point a Q *)
  intros P Q PQ Ha.
(* Goal: at_point a Q *)
  now apply PQ.
Qed.

End at_point.

(** ** Open sets in uniform spaces *)

Section Open.

Context {T : UniformSpace}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition open (D : T -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall x, D x -> locally x D.

Lemma locally_open :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (D E : T -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  open D ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x : T, D x -> E x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall x : T, D x ->
  locally x E.
Proof.
(* Goal: forall (D E : forall _ : UniformSpace.sort T, Prop) (_ : open D) (_ : forall (x : UniformSpace.sort T) (_ : D x), E x) (x : UniformSpace.sort T) (_ : D x), @locally T x E *)
intros D E OD H x Dx.
(* Goal: F (@ball T x (pos eps)) *)
apply filter_imp with (1 := H).
(* Goal: @locally U (f x) D *)
now apply OD.
Qed.

Lemma open_ext :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D E : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, D x <-> E x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  open D -> open E.
Proof.
(* Goal: forall (D E : forall _ : UniformSpace.sort T, Prop) (_ : forall x : UniformSpace.sort T, iff (D x) (E x)) (_ : open D), open E *)
intros D E H OD x Ex.
(* Goal: @locally T x E *)
generalize (OD x (proj2 (H x) Ex)).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
apply filter_imp.
(* Goal: forall y : R, @closed R_UniformSpace (fun u : R => @eq R u y) *)
intros y.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
apply H.
Qed.

Lemma open_and :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D E : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  open D -> open E ->
  open (fun x => D x /\ E x).
Proof.
(* Goal: forall (D E : forall _ : UniformSpace.sort T, Prop) (_ : open D) (_ : open E), open (fun x : UniformSpace.sort T => and (D x) (E x)) *)
intros D E OD OE x [Dx Ex].
(* Goal: @locally T x (fun x : UniformSpace.sort T => and (D x) (E x)) *)
apply filter_and.
(* Goal: @locally U (f x) D *)
now apply OD.
(* Goal: @locally T x E *)
now apply OE.
Qed.

Lemma open_or :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D E : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  open D -> open E ->
  open (fun x => D x \/ E x).
Proof.
(* Goal: forall (D E : forall _ : UniformSpace.sort T, Prop) (_ : open D) (_ : open E), open (fun x : UniformSpace.sort T => or (D x) (E x)) *)
intros D E OD OE x [Dx|Ex].
(* Goal: @locally T x (fun x : UniformSpace.sort T => or (D x) (E x)) *)
(* Goal: @locally T x (fun x : UniformSpace.sort T => or (D x) (E x)) *)
generalize (OD x Dx).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
apply filter_imp.
(* Goal: forall (x : UniformSpace.sort T) (_ : D x), or (D x) (E x) *)
(* Goal: @locally T x (fun x : UniformSpace.sort T => or (D x) (E x)) *)
intros y Dy.
(* Goal: or (D y) (E y) *)
(* Goal: @locally T x (fun x : UniformSpace.sort T => or (D x) (E x)) *)
now left.
(* Goal: @locally T x (fun x : UniformSpace.sort T => or (D x) (E x)) *)
generalize (OE x Ex).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
apply filter_imp.
(* Goal: forall (x : UniformSpace.sort T) (_ : E x), or (D x) (E x) *)
intros y Ey.
(* Goal: or (D y) (E y) *)
now right.
Qed.

Lemma open_true :
  open (fun x : T => True).
Proof.
(* Goal: open (fun _ : UniformSpace.sort T => True) *)
intros x _.
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
apply filter_true.
Qed.

Lemma open_false :
  open (fun x : T => False).
Proof.
(* Goal: closed (fun _ : UniformSpace.sort T => False) *)
now intros x Hx.
Qed.

End Open.

Lemma open_comp :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U : UniformSpace} (f : T -> U) (D : U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, D (f x) -> filterlim f (locally x) (locally (f x))) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  open D -> open (fun x : T => D (f x)).
Proof.
(* Goal: forall (T U : UniformSpace.type) (f : forall _ : UniformSpace.sort T, UniformSpace.sort U) (D : forall _ : UniformSpace.sort U, Prop) (_ : forall (x : UniformSpace.sort T) (_ : D (f x)), @filterlim (UniformSpace.sort T) (UniformSpace.sort U) f (@locally T x) (@locally U (f x))) (_ : @open U D), @open T (fun x : UniformSpace.sort T => D (f x)) *)
intros T U f D Cf OD x Dfx.
(* Goal: @locally T x (fun x : UniformSpace.sort T => D (f x)) *)
apply Cf.
(* Goal: D (f x) *)
(* Goal: @locally U (f x) D *)
exact Dfx.
(* Goal: @locally U (f x) D *)
now apply OD.
Qed.

(** ** Closed sets in uniform spaces *)

Section Closed.

Context {T : UniformSpace}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition closed (D : T -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall x, not (locally x (fun x : T => not (D x))) -> D x.

Lemma open_not :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  closed D -> open (fun x => not (D x)).
Proof.
(* Goal: forall (D : forall _ : UniformSpace.sort T, Prop) (_ : closed D), @open T (fun x : UniformSpace.sort T => not (D x)) *)
intros D CD x Dx.
(* Goal: @locally T x (fun x : UniformSpace.sort T => not (D x)) *)
apply locally_not.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
intros H.
(* Goal: False *)
apply Dx, CD.
(* Goal: not (@locally T x (fun x : UniformSpace.sort T => not (D x))) *)
intros [eps He].
(* Goal: False *)
now apply (H eps).
Qed.

Lemma closed_not :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  open D -> closed (fun x => not (D x)).
Proof.
intros D OD x Lx Dx.
apply Lx.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp (OD _ Dx).
intros t Dt nDt.
now apply nDt.
Qed.

Lemma closed_ext :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D E : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, D x <-> E x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  closed D -> closed E.
Proof.
(* Goal: forall (D E : forall _ : UniformSpace.sort T, Prop) (_ : forall x : UniformSpace.sort T, iff (D x) (E x)) (_ : closed D), closed E *)
intros D E DE CD x Hx.
(* Goal: E x *)
apply DE, CD.
(* Goal: not (@locally T x (fun x : UniformSpace.sort T => not (E x))) *)
contradict Hx.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp Hx.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
move => {x} x Dx Ex.
(* Goal: False *)
now apply Dx, DE.
Qed.

Lemma closed_and :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D E : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  closed D -> closed E ->
  closed (fun x => D x /\ E x).
Proof.
(* Goal: forall (D E : forall _ : UniformSpace.sort T, Prop) (_ : closed D) (_ : closed E), closed (fun x : UniformSpace.sort T => and (D x) (E x)) *)
intros D E CD CE x Hx.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: D (f x) *)
apply CD.
(* Goal: not (@locally T x (fun x : UniformSpace.sort T => not (E x))) *)
contradict Hx.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp Hx.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
move => {x} x nDx [Dx _].
(* Goal: False *)
(* Goal: E x *)
now apply nDx.
(* Goal: E x *)
apply CE.
(* Goal: not (@locally T x (fun x : UniformSpace.sort T => not (E x))) *)
contradict Hx.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp Hx.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
move => {x} x nEx [_ Ex].
(* Goal: False *)
now apply nEx.
Qed.

(*
Lemma closed_or :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall D E : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  closed D -> closed E ->
  closed (fun x => D x \/ E x).
Proof.
(* Goal: forall (D E : forall _ : UniformSpace.sort T, Prop) (_ : closed D) (_ : closed E), closed (fun x : UniformSpace.sort T => and (D x) (E x)) *)
intros D E CD CE x Hx.
generalize (open_and _ _ CD CE).
apply open_ext.
clear ; intuition.
Qed.
*)

Lemma closed_true :
  closed (fun x : T => True).
Proof.
(* Goal: closed (fun _ : UniformSpace.sort T => True) *)
now intros _ _.
Qed.

Lemma closed_false :
  closed (fun x : T => False).
Proof.
(* Goal: closed (fun _ : UniformSpace.sort T => False) *)
intros x Hx.
(* Goal: False *)
apply Hx.
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
now exists (mkposreal _ Rlt_0_1).
Qed.

End Closed.

Lemma closed_comp :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T U : UniformSpace} (f : T -> U) (D : U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, filterlim f (locally x) (locally (f x))) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  closed D -> closed (fun x : T => D (f x)).
Proof.
(* Goal: forall (T U : UniformSpace.type) (f : forall _ : UniformSpace.sort T, UniformSpace.sort U) (D : forall _ : UniformSpace.sort U, Prop) (_ : forall x : UniformSpace.sort T, @filterlim (UniformSpace.sort T) (UniformSpace.sort U) f (@locally T x) (@locally U (f x))) (_ : @closed U D), @closed T (fun x : UniformSpace.sort T => D (f x)) *)
intros T U f D Cf CD x Dfx.
(* Goal: D (f x) *)
apply CD.
(* Goal: not (@locally U (f x) (fun x : UniformSpace.sort U => not (D x))) *)
contradict Dfx.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
exact: Cf Dfx.
Qed.

Lemma closed_filterlim_loc :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T} {U : UniformSpace} {F} {FF : ProperFilter' F} (f : T -> U) (D : U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall y, filterlim f F (locally y) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => D (f x)) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  closed D -> D y.
Proof.
intros T U F FF f D y Ffy Df CD.
(* Goal: D (f x) *)
apply CD.
intros LD.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
apply filter_not_empty.
specialize (Ffy _ LD).
unfold filtermap in Ffy.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp (filter_and _ _ Df Ffy).
intros x Dfx.
now apply Dfx.
Qed.

Lemma closed_filterlim :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {T} {U : UniformSpace} {F} {FF : ProperFilter' F} (f : T -> U) (D : U -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall y, filterlim f F (locally y) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, D (f x)) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  closed D -> D y.
Proof.
(* Goal: forall (T : Type) (U : UniformSpace.type) (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter' T F) (f : forall _ : T, UniformSpace.sort U) (D : forall _ : UniformSpace.sort U, Prop) (y : UniformSpace.sort U) (_ : @filterlim T (UniformSpace.sort U) f F (@locally U y)) (_ : forall x : T, D (f x)) (_ : @closed U D), D y *)
intros T U F FF f D y Ffy Df.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: closed_filterlim_loc Ffy _.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
now apply filter_forall.
Qed.

(** ** Complete uniform spaces *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition cauchy {T : UniformSpace} (F : (T -> Prop) -> Prop) :=
  forall eps : posreal, exists x, F (ball x eps).

Module CompleteSpace.

Record mixin_of (T : UniformSpace) := Mixin {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  lim : ((T -> Prop) -> Prop) -> T ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax1 : forall F, ProperFilter F -> cauchy F -> forall eps : posreal, F (ball (lim F) eps) ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax2 : forall F1 F2, filter_le F1 F2 -> filter_le F2 F1 -> close (lim F1) (lim F2)
}.

Section ClassDef.

Record class_of (T : Type) := Class {
  base : UniformSpace.class_of T ;
  mixin : mixin_of (UniformSpace.Pack _ base T)
}.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base : class_of >-> UniformSpace.class_of.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.

Variable cT : type.

Definition class := let: Pack _ c _ := cT return class_of cT in c.

Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of xT).

Definition UniformSpace := UniformSpace.Pack cT xclass xT.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base : class_of >-> UniformSpace.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion mixin : class_of >-> mixin_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion UniformSpace : type >-> UniformSpace.type.
Canonical UniformSpace.
Notation CompleteSpace := type.

End Exports.

End CompleteSpace.

Export CompleteSpace.Exports.

Section CompleteSpace1.

Context {T : CompleteSpace}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition lim : ((T -> Prop) -> Prop) -> T := CompleteSpace.lim _ (CompleteSpace.class T).

Lemma complete_cauchy :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall F : (T -> Prop) -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter F -> cauchy F ->
  forall eps : posreal,
  F (ball (lim F) eps).
Proof.
(* Goal: forall (F : forall _ : forall _ : CompleteSpace.sort T, Prop, Prop) (_ : @ProperFilter (CompleteSpace.sort T) F) (_ : @cauchy (CompleteSpace.UniformSpace T) F) (eps : posreal), F (@ball (CompleteSpace.UniformSpace T) (lim F) (pos eps)) *)
apply CompleteSpace.ax1.
Qed.

Lemma close_lim :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall F1 F2 : (T -> Prop) -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le F1 F2 -> filter_le F2 F1 ->
  close (lim F1) (lim F2).
Proof.
(* Goal: forall (F1 F2 : forall _ : forall _ : CompleteSpace.sort T, Prop, Prop) (_ : @filter_le (CompleteSpace.sort T) F1 F2) (_ : @filter_le (CompleteSpace.sort T) F2 F1), @close (CompleteSpace.UniformSpace T) (lim F1) (lim F2) *)
apply CompleteSpace.ax2.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition iota (P : T -> Prop) := lim (fun A => (forall x, P x -> A x)).

Lemma iota_correct_weak :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall P : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x y, P x -> P y -> close x y) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall x, P x -> close (iota P) x.
Proof.
(* Goal: forall (P : forall _ : CompleteSpace.sort T, Prop) (_ : forall (x y : CompleteSpace.sort T) (_ : P x) (_ : P y), @close (CompleteSpace.UniformSpace T) x y) (x : CompleteSpace.sort T) (_ : P x), @close (CompleteSpace.UniformSpace T) (iota P) x *)
intros P HP x Hx eps.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
set (F := fun A : T -> Prop => forall t : T, P t -> A t).
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
assert (forall eps : posreal, F (ball (lim F) eps)) as HF.
(* Goal: forall eps : posreal, Fr t (fun x : CompleteSpace.sort U => @ball (CompleteSpace.UniformSpace U) (lim_fct F t) (pos eps) x) *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
apply complete_cauchy.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: forall (P : forall _ : CompleteSpace.sort T, Prop) (_ : F P), @ex (CompleteSpace.sort T) (fun x : CompleteSpace.sort T => P x) *)
(* Goal: @Filter (CompleteSpace.sort T) F *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
intros Q FQ.
(* Goal: @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps))) *)
exists x.
(* Goal: Q x *)
(* Goal: @Filter (CompleteSpace.sort T) F *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
now apply FQ.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: F (fun _ : CompleteSpace.sort T => True) *)
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : F P) (_ : F Q), F (fun x : CompleteSpace.sort T => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : forall (x : CompleteSpace.sort T) (_ : P x), Q x) (_ : F P), F Q *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
now intro x0.
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : F P) (_ : F Q), F (fun x : CompleteSpace.sort T => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : forall (x : CompleteSpace.sort T) (_ : P x), Q x) (_ : F P), F Q *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
intros A B HA HB x0 Hx0.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: A x0 *)
(* Goal: B x0 *)
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : forall (x : CompleteSpace.sort T) (_ : P x), Q x) (_ : F P), F Q *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
now apply HA.
(* Goal: B x0 *)
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : forall (x : CompleteSpace.sort T) (_ : P x), Q x) (_ : F P), F Q *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
now apply HB.
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : forall (x : CompleteSpace.sort T) (_ : P x), Q x) (_ : F P), F Q *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
intros A B HAB HA x0 Hx0.
(* Goal: A x0 *)
(* Goal: B x0 *)
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : forall (x : CompleteSpace.sort T) (_ : P x), Q x) (_ : F P), F Q *)
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
apply HAB ; now apply HA.
(* Goal: @cauchy (CompleteSpace.UniformSpace T) F *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
intro e.
(* Goal: @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps))) *)
exists x.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
intros y Hy.
(* Goal: P y *)
now apply HP.
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
assert (F (ball (lim F) eps)) as Heps.
(* Goal: F (@ball (CompleteSpace.UniformSpace T) (lim F) (pos eps)) *)
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
apply HF.
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
clear HF.
(* Goal: @ball (CompleteSpace.UniformSpace T) (iota P) (pos eps) x *)
now apply Heps.
Qed.

Lemma close_iota :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall P Q : T -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, P x <-> Q x) ->
  close (iota P) (iota Q).
Proof.
(* Goal: forall (P Q : forall _ : CompleteSpace.sort T, Prop) (_ : forall x : CompleteSpace.sort T, iff (P x) (Q x)), @close (CompleteSpace.UniformSpace T) (iota P) (iota Q) *)
intros P Q H.
(* Goal: @close (CompleteSpace.UniformSpace T) (iota P) (iota Q) *)
apply close_lim ; intros R HR x Hx ; apply HR, H, Hx.
Qed.

End CompleteSpace1.

Lemma cauchy_distance :
  forall {T : UniformSpace} {F} {FF : ProperFilter F},
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall eps : posreal, exists x, F (ball x eps)) <->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall eps : posreal, exists P, F P /\ forall u v : T, P u -> P v -> ball u eps v).
Proof.
(* Goal: forall (T : UniformSpace.type) (F : forall _ : forall _ : UniformSpace.sort T, Prop, Prop) (_ : @ProperFilter (UniformSpace.sort T) F), iff (forall eps : posreal, @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps)))) (forall eps : posreal, @ex (forall _ : UniformSpace.sort T, Prop) (fun P : forall _ : UniformSpace.sort T, Prop => and (F P) (forall (u v : UniformSpace.sort T) (_ : P u) (_ : P v), @ball T u (pos eps) v))) *)
intros T F FF.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros H eps.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (H (pos_div_2 eps)) => {H} x Hx.
(* Goal: @ex (forall _ : UniformSpace.sort T, Prop) (fun P : forall _ : UniformSpace.sort T, Prop => and (F P) (forall (u v : UniformSpace.sort T) (_ : P u) (_ : P v), @ball T u (pos eps) v)) *)
(* Goal: forall (_ : forall eps : posreal, @ex (forall _ : UniformSpace.sort T, Prop) (fun P : forall _ : UniformSpace.sort T, Prop => and (F P) (forall (u v : UniformSpace.sort T) (_ : P u) (_ : P v), @ball T u (pos eps) v))) (eps : posreal), @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps))) *)
  exists (ball x (pos_div_2 eps)).
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => u v Hu Hv.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var eps).
(* Goal: @ball T u (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) v *)
(* Goal: forall (_ : forall eps : posreal, @ex (forall _ : UniformSpace.sort T, Prop) (fun P : forall _ : UniformSpace.sort T, Prop => and (F P) (forall (u v : UniformSpace.sort T) (_ : P u) (_ : P v), @ball T u (pos eps) v))) (eps : posreal), @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps))) *)
  apply ball_triangle with x.
(* Goal: @ball (CompleteSpace.UniformSpace U) fu (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) fv *)
  by apply ball_sym.
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (f v) *)
  exact Hv.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros H eps.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (H eps) => {H} P [HP H].
(* Goal: @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps))) *)
  destruct (filter_ex P HP) as [x Hx].
(* Goal: @ex (UniformSpace.sort T) (fun x : UniformSpace.sort T => F (@ball T x (pos eps))) *)
  exists x.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (fun v => H x v Hx) => {H} H.
(* Goal: F (@ball T x (pos eps)) *)
  apply filter_imp with (1 := H).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
Qed.

Section fct_CompleteSpace.

Context {T : Type} {U : CompleteSpace}.

Lemma filterlim_locally_cauchy :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF : ProperFilter F} (f : T -> U),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall eps : posreal, exists P, F P /\ forall u v : T, P u -> P v -> ball (f u) eps (f v)) <->
  exists y, filterlim f F (locally y).
Proof.
(* Goal: forall (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F) (f : forall _ : T, CompleteSpace.sort U), iff (forall eps : posreal, @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v)))) (@ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) *)
intros F FF f.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
- intros H.
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
  exists (lim (filtermap f F)).
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  intros P [eps HP].
(* Goal: @filtermap T (CompleteSpace.sort U) f F P *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
  refine (_ (complete_cauchy (filtermap f F) _ _ eps)).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  + now apply filter_imp.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  + clear eps P HP.
(* Goal: @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
    intros eps.
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun x : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
    destruct (H eps) as [P [FP H']].
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun x : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
    destruct (filter_ex _ FP) as [x Hx].
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun x : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
    exists (f x).
(* Goal: @filtermap T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) (f x) (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
    unfold filtermap.
(* Goal: F (fun x0 : T => @ball (CompleteSpace.UniformSpace U) (f x) (pos eps) (f x0)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
    generalize FP.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
    apply filter_imp.
(* Goal: forall (x0 : T) (_ : P x0), @ball (CompleteSpace.UniformSpace U) (f x) (pos eps) (f x0) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
    intros x' Hx'.
(* Goal: @ball (CompleteSpace.UniformSpace U) (f x) (pos eps) (f x') *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlim T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
    now apply H'.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros [y Hy] eps.
(* Goal: @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v))) *)
  exists (fun x => ball y (pos_div_2 eps) (f x)).
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: F (fun x : T => @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f x)) *)
(* Goal: forall (u v : T) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f u)) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f v)), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v) *)
  apply Hy.
(* Goal: @locally (CompleteSpace.UniformSpace U) y (@ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps))) *)
(* Goal: F (fun x : T => forall (fx : CompleteSpace.sort U) (_ : f x fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) *)
(* Goal: forall (u v : T) (_ : forall (fx : CompleteSpace.sort U) (_ : f u fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (_ : forall (fx : CompleteSpace.sort U) (_ : f v fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v' *)
  now exists (pos_div_2 eps).
(* Goal: forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v *)
  intros u v Hu Hv.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var eps).
(* Goal: @ball (CompleteSpace.UniformSpace U) fu (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) fv *)
  apply ball_triangle with y.
(* Goal: @ball (CompleteSpace.UniformSpace U) fu (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) fv *)
  apply ball_sym.
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (f u) *)
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (f v) *)
  exact Hu.
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (f v) *)
  exact Hv.
Qed.

Lemma filterlimi_locally_cauchy :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF : ProperFilter F} (f : T -> U -> Prop),
  F (fun x => (exists y, f x y) /\
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    (forall y1 y2, f x y1 -> f x y2 -> y1 = y2)) ->
  ((forall eps : posreal, exists P, F P /\
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
   forall u v : T, P u -> P v -> forall u' v': U, f u u' -> f v v' -> ball u' eps v') <->
  exists y, filterlimi f F (locally y)).
Proof.
(* Goal: forall (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter T F) (f : forall (_ : T) (_ : CompleteSpace.sort U), Prop) (_ : F (fun x : T => and (@ex (CompleteSpace.sort U) (fun y : CompleteSpace.sort U => f x y)) (forall (y1 y2 : CompleteSpace.sort U) (_ : f x y1) (_ : f x y2), @eq (CompleteSpace.sort U) y1 y2))), iff (forall eps : posreal, @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v'))) (@ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) *)
intros F FF f Hf.
(* Goal: iff (forall eps : posreal, @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v'))) (@ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) *)
assert (FF': ProperFilter (filtermapi f F)).
(* Goal: @ProperFilter (CompleteSpace.sort U) (@filtermapi T (CompleteSpace.sort U) f F) *)
(* Goal: iff (forall eps : posreal, @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v'))) (@ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) *)
  apply filtermapi_proper_filter.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  exact: filter_imp Hf.
(* Goal: @ProperFilter T F *)
(* Goal: iff (forall eps : posreal, @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v'))) (@ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) *)
  exact FF.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
- intros H.
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
  exists (lim (filtermapi f F)).
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  intros P [eps HP].
(* Goal: @filtermapi T (CompleteSpace.sort U) f F P *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
  refine (_ (complete_cauchy (filtermapi f F) _ _ eps)).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  + now apply filter_imp.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  + clear eps P HP.
(* Goal: @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
    intros eps.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
    case: (H eps) => {H} [P [FP H]].
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun x : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
    assert (FfP := filter_and _ _ Hf FP).
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun x : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
    destruct (filter_ex _ FfP) as [x [[[fx Hfx] _] Px]].
(* Goal: @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun x : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
    exists fx.
(* Goal: @filtermapi T (CompleteSpace.sort U) f F (@ball (CompleteSpace.UniformSpace U) fx (pos eps)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
    unfold filtermapi.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
    apply: filter_imp FfP.
(* Goal: forall (x : T) (_ : and (and (@ex (CompleteSpace.sort U) (fun y : CompleteSpace.sort U => f x y)) (forall (y1 y2 : CompleteSpace.sort U) (_ : f x y1) (_ : f x y2), @eq (CompleteSpace.sort U) y1 y2)) (P x)), @ex (CompleteSpace.sort U) (fun y : CompleteSpace.sort U => and (f x y) (@ball (CompleteSpace.UniformSpace U) fx (pos eps) y)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
    intros x' [[[fx' Hfx'] _] Px'].
(* Goal: @ex (CompleteSpace.sort U) (fun y : CompleteSpace.sort U => and (f x' y) (@ball (CompleteSpace.UniformSpace U) fx (pos eps) y)) *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
    exists fx'.
(* Goal: and (f x' fx') (@ball (CompleteSpace.UniformSpace U) fx (pos eps) fx') *)
(* Goal: forall (_ : @ex (UniformSpace.sort (CompleteSpace.UniformSpace U)) (fun y : UniformSpace.sort (CompleteSpace.UniformSpace U) => @filterlimi T (CompleteSpace.sort U) f F (@locally (CompleteSpace.UniformSpace U) y))) (eps : posreal), @ex (forall _ : T, Prop) (fun P : forall _ : T, Prop => and (F P) (forall (u v : T) (_ : P u) (_ : P v) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v')) *)
    apply (conj Hfx').
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
    exact: H Hfx Hfx'.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros [y Hy] eps.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists (fun x => forall fx, f x fx -> ball y (pos_div_2 eps) fx).
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: F (fun x : T => forall (fx : CompleteSpace.sort U) (_ : f x fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) *)
(* Goal: forall (u v : T) (_ : forall (fx : CompleteSpace.sort U) (_ : f u fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (_ : forall (fx : CompleteSpace.sort U) (_ : f v fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v' *)
    assert (Hb: locally y (ball y (pos_div_2 eps))).
(* Goal: @locally (CompleteSpace.UniformSpace U) y (@ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps))) *)
(* Goal: F (fun x : T => forall (fx : CompleteSpace.sort U) (_ : f x fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) *)
(* Goal: forall (u v : T) (_ : forall (fx : CompleteSpace.sort U) (_ : f u fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (_ : forall (fx : CompleteSpace.sort U) (_ : f v fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v' *)
      now exists (pos_div_2 eps).
(* Goal: F (fun x : T => forall (fx : CompleteSpace.sort U) (_ : f x fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) *)
(* Goal: forall (u v : T) (_ : forall (fx : CompleteSpace.sort U) (_ : f u fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (_ : forall (fx : CompleteSpace.sort U) (_ : f v fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v' *)
    assert (H := filter_and _ _ Hf (Hy _ Hb)).
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
    apply: filter_imp H.
(* Goal: forall (x : T) (_ : and (and (@ex (CompleteSpace.sort U) (fun y : CompleteSpace.sort U => f x y)) (forall (y1 y2 : CompleteSpace.sort U) (_ : f x y1) (_ : f x y2), @eq (CompleteSpace.sort U) y1 y2)) (@ex (CompleteSpace.sort U) (fun y0 : CompleteSpace.sort U => and (f x y0) (@ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) y0)))) (fx : CompleteSpace.sort U) (_ : f x fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx *)
(* Goal: forall (u v : T) (_ : forall (fx : CompleteSpace.sort U) (_ : f u fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (_ : forall (fx : CompleteSpace.sort U) (_ : f v fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v' *)
    intros x [[_ H] [fx2 [Hfx2 H']]] fx Hfx.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    now rewrite <- (H fx2).
(* Goal: forall (u v : T) (_ : forall (fx : CompleteSpace.sort U) (_ : f u fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (_ : forall (fx : CompleteSpace.sort U) (_ : f v fx), @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) fx) (u' v' : CompleteSpace.sort U) (_ : f u u') (_ : f v v'), @ball (CompleteSpace.UniformSpace U) u' (pos eps) v' *)
  intros u v Hu Hv fu fv Hfu Hfv.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var eps).
(* Goal: @ball (CompleteSpace.UniformSpace U) fu (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) fv *)
  apply ball_triangle with y.
(* Goal: @ball (CompleteSpace.UniformSpace U) fu (Rdiv (pos eps) (IZR (Zpos (xO xH)))) y *)
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) fv *)
  apply ball_sym.
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) fu *)
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) fv *)
  now apply Hu.
(* Goal: @ball (CompleteSpace.UniformSpace U) y (Rdiv (pos eps) (IZR (Zpos (xO xH)))) fv *)
  now apply Hv.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition lim_fct (F : ((T -> U) -> Prop) -> Prop) (t : T) :=
  lim (fun P => F (fun g => P (g t))).

Lemma complete_cauchy_fct :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (F : ((T -> U) -> Prop) -> Prop),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter F ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall eps : posreal, exists f : T -> U, F (ball f eps)) ->
  forall eps : posreal, F (ball (lim_fct F) eps).
Proof.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => F FF HFc.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  set Fr := fun (t : T) (P : U -> Prop) => F (fun g => P (g t)).
(* Goal: F2 (fun x : T2 => @ball U l (pos eps) (g x)) *)
  have FFr : forall t, ProperFilter (Fr t).
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
    case: FF => HF FF t.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
    split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    - move => P Hp.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
      case: (HF _ Hp) => f Hf.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
      by exists (f t).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    - split.
(* Goal: forall _ : Fr t P, Fr t P' *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
      + by apply FF.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
      + move => P P' Hp Hp'.
(* Goal: forall _ : Fr t P, Fr t P' *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
      by apply FF.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
      + move => P P' Hpp'.
(* Goal: forall _ : Fr t P, Fr t P' *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
      apply FF.
(* Goal: forall (x : forall _ : T, CompleteSpace.sort U) (_ : P (x t)), P' (x t) *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
      move => f ; by apply Hpp'.
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
  assert (HFrc : forall t, forall eps : posreal, exists x : U, Fr t (ball x eps)).
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
    move => t eps.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
    case: (HFc eps) => f Hf.
(* Goal: @ex (CompleteSpace.sort U) (fun x : CompleteSpace.sort U => Fr t (@ball (CompleteSpace.UniformSpace U) x (pos eps))) *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
    exists (f t).
(* Goal: @ball (CompleteSpace.UniformSpace U) (lim_fct F t) (pos eps) (g t) *)
    move: Hf ; apply FF => g.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by [].
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
  assert (forall t (eps : posreal), (Fr t) (fun x => ball (lim_fct F t) eps x)).
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
    move => t.
(* Goal: forall eps : posreal, Fr t (fun x : CompleteSpace.sort U => @ball (CompleteSpace.UniformSpace U) (lim_fct F t) (pos eps) x) *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
    apply complete_cauchy.
(* Goal: @ProperFilter (CompleteSpace.sort U) (fun P : forall _ : CompleteSpace.sort U, Prop => F (fun g : forall _ : T, CompleteSpace.sort U => P (g t))) *)
(* Goal: @cauchy (CompleteSpace.UniformSpace U) (fun P : forall _ : CompleteSpace.sort U, Prop => F (fun g : forall _ : T, CompleteSpace.sort U => P (g t))) *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
    apply FFr.
(* Goal: @cauchy (CompleteSpace.UniformSpace U) (fun P : forall _ : CompleteSpace.sort U, Prop => F (fun g : forall _ : T, CompleteSpace.sort U => P (g t))) *)
(* Goal: forall eps : posreal, F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
    exact (HFrc t).

(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => eps.

(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  generalize (proj1 cauchy_distance HFc) => {HFc} HFc.

(* Goal: F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
  case: (HFc (pos_div_2 eps)) => {HFc} P ; simpl ; case => HP H0.
(* Goal: F (@ball (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F) (pos eps)) *)
  apply filter_imp with (2 := HP).
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => g Hg t.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (fun h => H0 g h Hg) => {H0} H0.
(* Goal: @ball (CompleteSpace.UniformSpace U) (lim_fct F t) (pos eps) (g t) *)
  move: (H t (pos_div_2 eps)) ; simpl => {H} H.
(* Goal: @ball (CompleteSpace.UniformSpace U) (lim_fct F t) (pos eps) (g t) *)
  unfold Fr in H ; generalize (filter_and _ _ H HP) => {H} H.
(* Goal: @ball (CompleteSpace.UniformSpace U) (lim_fct F t) (pos eps) (g t) *)
  apply filter_ex in H ; case: H => h H.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var eps).
(* Goal: @ball (CompleteSpace.UniformSpace U) (lim_fct F t) (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) (g t) *)
  apply ball_triangle with (h t).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply H.
(* Goal: @ball (CompleteSpace.UniformSpace U) (h t) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (g t) *)
  apply ball_sym, H0.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply H.
Qed.

Lemma close_lim_fct :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall F1 F2 : ((T -> U) -> Prop) -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le F1 F2 -> filter_le F2 F1 ->
  close (lim_fct F1) (lim_fct F2).
Proof.
(* Goal: forall (F1 F2 : forall _ : forall _ : forall _ : T, CompleteSpace.sort U, Prop, Prop) (_ : @filter_le (forall _ : T, CompleteSpace.sort U) F1 F2) (_ : @filter_le (forall _ : T, CompleteSpace.sort U) F2 F1), @close (fct_UniformSpace T (CompleteSpace.UniformSpace U)) (lim_fct F1) (lim_fct F2) *)
intros F1 F2 H12 H21 eps t.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
apply close_lim => P.
(* Goal: forall _ : F2 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))), F1 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))) *)
apply H12.
(* Goal: forall _ : F1 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))), F2 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))) *)
(* Goal: forall _ : F2 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))), F1 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))) *)
apply H21.
Qed.

Definition fct_CompleteSpace_mixin :=
  CompleteSpace.Mixin _ lim_fct complete_cauchy_fct close_lim_fct.

Canonical fct_CompleteSpace :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  CompleteSpace.Pack (T -> U) (CompleteSpace.Class _ _ fct_CompleteSpace_mixin) (T -> U).

End fct_CompleteSpace.

(** ** Limit switching *)

Section Filterlim_switch.

Context {T1 T2 : Type}.

Lemma filterlim_switch_1 {U : UniformSpace}
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F1 (FF1 : ProperFilter F1) F2 (FF2 : Filter F2) (f : T1 -> T2 -> U) g h (l : U) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F1 (locally g) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, filterlim (f x) F2 (locally (h x))) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim h F1 (locally l) -> filterlim g F2 (locally l).
Proof.
(* Goal: forall (_ : @filterlim T1 (forall _ : T2, UniformSpace.sort U) f F1 (@locally (fct_UniformSpace T2 U) g)) (_ : forall x : T1, @filterlim T2 (UniformSpace.sort U) (f x) F2 (@locally U (h x))) (_ : @filterlim T1 (UniformSpace.sort U) h F1 (@locally U l)), @filterlim T2 (UniformSpace.sort U) g F2 (@locally U l) *)
  intros Hfg Hfh Hhl P.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: FF1 => HF1 FF1.
(* Goal: forall _ : @locally U l P, @filtermap T2 (UniformSpace.sort U) g F2 P *)
  apply filterlim_locally.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => eps.

(* Goal: F2 (fun x : T2 => @ball U l (pos eps) (g x)) *)
  have FF := (filter_prod_filter _ _ F1 F2 FF1 FF2).

(* Goal: F2 (fun x : T2 => @ball U l (pos eps) (g x)) *)
  assert (filter_prod F1 F2 (fun x => ball (g (snd x)) (eps / 2 / 2) (f (fst x) (snd x)))).
(* Goal: @filter_prod T1 T2 F1 F2 (fun x : prod T1 T2 => @ball U (g (@snd T1 T2 x)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (f (@fst T1 T2 x) (@snd T1 T2 x))) *)
(* Goal: F2 (fun x : T2 => @ball U l (pos eps) (g x)) *)
    apply Filter_prod with (fun x : T1 => ball g (eps / 2 / 2) (f x)) (fun _ => True).
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
    move: (proj1 (@filterlim_locally _ _ F1 FF1 f g) Hfg (pos_div_2 (pos_div_2 eps))) => {Hfg} /= Hfg.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by [].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply FF2.
(* Goal: forall _ : forall (k : nat) (_ : and (le n k) (le k m)), @eq (AbelianGroup.sort G) (a k) (b k), @eq (AbelianGroup.sort G) (sum_n_m a n m) (sum_n_m b n m) *)
    simpl ; intros.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
    apply H.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: H => {Hfg} Hfg.

(* Goal: F2 (fun x : T2 => @ball U l (pos eps) (g x)) *)
  assert (filter_prod F1 F2 (fun x : T1 * T2 => ball l (eps / 2) (h (fst x)))).
(* Goal: @filter_prod T1 T2 F1 F2 (fun x : prod T1 T2 => @ball U l (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (h (@fst T1 T2 x))) *)
(* Goal: F2 (fun x : T2 => @ball U l (pos eps) (g x)) *)
    apply Filter_prod with (fun x : T1 => ball l (eps / 2) (h x)) (fun _ => True).
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
    move: (proj1 (@filterlim_locally _ _ F1 FF1 h l) Hhl (pos_div_2 eps)) => {Hhl} /= Hhl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by [].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply FF2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by [].
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: H => {Hhl} Hhl.

(* Goal: forall _ : forall (k : nat) (_ : and (le n k) (le k m)), @eq (AbelianGroup.sort G) (a k) (b k), @eq (AbelianGroup.sort G) (sum_n_m a n m) (sum_n_m b n m) *)
  case: (@filter_and _ _ FF _ _ Hhl Hfg) => {Hhl Hfg} /= ; intros.

(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (fun x => proj1 (@filterlim_locally _ _ F2 FF2 (f x) (h x)) (Hfh x) (pos_div_2 (pos_div_2 eps))) => {Hfh} /= Hfh.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (HF1 Q f0) => x Hx.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (@filter_and _ _ FF2 _ _ (Hfh x) g0) => {Hfh}.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply filter_imp => y Hy.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var eps).
(* Goal: @ball U l (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) (g y) *)
  apply ball_triangle with (h x).
(* Goal: @ball U l (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (h x) *)
(* Goal: @ball U (h x) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (g y) *)
  apply (p x y).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: F (fun x : T => @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f x)) *)
(* Goal: forall (u v : T) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f u)) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f v)), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v) *)
  by apply Hy.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var (eps / 2)).
(* Goal: @ball U (h x) (Rplus (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) (g y) *)
  apply ball_triangle with (f x y).
(* Goal: F (fun x : T => @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f x)) *)
(* Goal: forall (u v : T) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f u)) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f v)), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v) *)
  by apply Hy.
(* Goal: @ball U (f x y) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (g y) *)
  apply ball_sym, p.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: F (fun x : T => @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f x)) *)
(* Goal: forall (u v : T) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f u)) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f v)), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v) *)
  by apply Hy.
Qed.

Lemma filterlim_switch_2 {U : CompleteSpace}
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F1 (FF1 : ProperFilter F1) F2 (FF2 : ProperFilter F2) (f : T1 -> T2 -> U) g h :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F1 (locally g) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, filterlim (f x) F2 (locally (h x))) ->
  exists l : U, filterlim h F1 (locally l).
Proof.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => Hfg Hfh.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case : (proj1 (filterlim_locally_cauchy h)).
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => eps.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  generalize (proj2 (filterlim_locally_cauchy f)) => Hf.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  assert (exists y : T2 -> U, filterlim f F1 (locally y)).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    exists g => P Hp.
(* Goal: @filtermap T1 (forall _ : T2, CompleteSpace.sort U) f F1 P *)
(* Goal: @ex (forall _ : T1, Prop) (fun P : forall _ : T1, Prop => and (F1 P) (forall (u v : T1) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (h u) (pos eps) (h v))) *)
(* Goal: forall (x : UniformSpace.sort (CompleteSpace.UniformSpace U)) (_ : @filterlim T1 (CompleteSpace.sort U) h F1 (@locally (CompleteSpace.UniformSpace U) x)), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) *)
    apply Hfg.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
    case: Hp => d Hp.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    exists d => y Hy.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
    apply: Hp.
(* Goal: F (fun x : T => @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f x)) *)
(* Goal: forall (u v : T) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f u)) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f v)), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v) *)
    by apply Hy.

(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: H => {Hfg} Hfg.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (Hf Hfg (pos_div_2 eps)) => {Hf Hfg} /= Hf.

(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: FF2 => HF2 FF2.
  generalize (fun x => proj1 (filterlim_locally (f x) (h x)) (Hfh x) (pos_div_2 (pos_div_2 eps)))
    => {Hfh} Hfh.

(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: Hf => P [Hp Hf].
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  exists P ; split.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => u v Hu Hv.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (Hfh u) => /= Hu'.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (Hfh v) => /= Hv'.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (@filter_and _ F2 FF2 _ _ Hu' Hv') => {Hu' Hv' Hfh} Hfh.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (HF2 _ Hfh) => {Hfh} y Hy.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  replace (pos eps) with (eps / 2 / 2 + (eps / 2 + eps / 2 / 2)) by field.
(* Goal: @ball (CompleteSpace.UniformSpace U) (h u) (Rplus (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))))) (h v) *)
(* Goal: forall (x : UniformSpace.sort (CompleteSpace.UniformSpace U)) (_ : @filterlim T1 (CompleteSpace.sort U) h F1 (@locally (CompleteSpace.UniformSpace U) x)), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) *)
  apply ball_triangle with (f u y).
(* Goal: F (fun x : T => @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f x)) *)
(* Goal: forall (u v : T) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f u)) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f v)), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v) *)
  by apply Hy.
(* Goal: @ball (CompleteSpace.UniformSpace U) (f u y) (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) (h v) *)
(* Goal: forall (x : UniformSpace.sort (CompleteSpace.UniformSpace U)) (_ : @filterlim T1 (CompleteSpace.sort U) h F1 (@locally (CompleteSpace.UniformSpace U) x)), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) *)
  apply ball_triangle with (f v y).
(* Goal: @filtermapi T U f F P *)
  by apply Hf.
(* Goal: @ball (CompleteSpace.UniformSpace U) (f v y) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (h v) *)
(* Goal: forall (x : UniformSpace.sort (CompleteSpace.UniformSpace U)) (_ : @filterlim T1 (CompleteSpace.sort U) h F1 (@locally (CompleteSpace.UniformSpace U) x)), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) *)
  now apply ball_sym.

(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => l Hl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by exists l.
Qed.

Lemma filterlim_switch {U : CompleteSpace}
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F1 (FF1 : ProperFilter F1) F2 (FF2 : ProperFilter F2) (f : T1 -> T2 -> U) g h :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F1 (locally g) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, filterlim (f x) F2 (locally (h x))) ->
  exists l : U, filterlim h F1 (locally l) /\ filterlim g F2 (locally l).
Proof.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => Hfg Hfh.
(* Goal: @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => and (@filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) (@filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g F2 (@locally (CompleteSpace.UniformSpace U) l))) *)
  destruct (filterlim_switch_2 F1 FF1 F2 FF2 f g h Hfg Hfh) as [l Hhl].
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  exists l ; split.
(* Goal: @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l) *)
(* Goal: @filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g F2 (@locally (CompleteSpace.UniformSpace U) l) *)
  exact Hhl.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: FF2 => HF2 FF2.
(* Goal: @filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g F2 (@locally (CompleteSpace.UniformSpace U) l) *)
  now apply (filterlim_switch_1 F1 FF1 F2 FF2 f g h l).
Qed.

End Filterlim_switch.

Lemma filterlim_switch_dom {T1 T2 : Type} {U : CompleteSpace}
  F1 (FF1 : ProperFilter F1) F2 (FF2 : Filter F2)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (dom : T2 -> Prop) (HF2 : forall P, F2 P -> exists x, dom x /\ P x)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (f : T1 -> T2 -> U) g h :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim (fun x (y : {z : T2 | dom z}) => f x (proj1_sig y)) F1 (locally (T := fct_UniformSpace _ _) (fun y : {z : T2 | dom z} => g (proj1_sig y))) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x, filterlim (f x) (within dom F2) (locally (h x))) ->
  exists l : U, filterlim h F1 (locally l) /\ filterlim g (within dom F2) (locally l).
Proof.
(* Goal: forall (_ : @filterlim T1 (forall _ : @sig T2 (fun z : T2 => dom z), CompleteSpace.sort U) (fun (x : T1) (y : @sig T2 (fun z : T2 => dom z)) => f x (@proj1_sig T2 (fun z : T2 => dom z) y)) F1 (@locally (fct_UniformSpace (@sig T2 (fun z : T2 => dom z)) (CompleteSpace.UniformSpace U)) (fun y : @sig T2 (fun z : T2 => dom z) => g (@proj1_sig T2 (fun z : T2 => dom z) y)))) (_ : forall x : T1, @filterlim T2 (CompleteSpace.sort U) (f x) (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) (h x))), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => and (@filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) (@filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) l))) *)
set (T2' := { y : T2 | dom y }).
(* Goal: forall (_ : @filterlim T1 (forall _ : T2', CompleteSpace.sort U) (fun (x : T1) (y : T2') => f x (@proj1_sig T2 (fun z : T2 => dom z) y)) F1 (@locally (fct_UniformSpace T2' (CompleteSpace.UniformSpace U)) (fun y : T2' => g (@proj1_sig T2 (fun z : T2 => dom z) y)))) (_ : forall x : T1, @filterlim T2 (CompleteSpace.sort U) (f x) (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) (h x))), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => and (@filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) (@filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) l))) *)
set (f' := fun x (y : T2') => f x (proj1_sig y)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
set (F2' := fun P : T2' -> Prop => F2 (fun x => forall (H:dom x), P (exist _ x H))).
(* Goal: forall (_ : @filterlim T1 (forall _ : T2', CompleteSpace.sort U) f' F1 (@locally (fct_UniformSpace T2' (CompleteSpace.UniformSpace U)) (fun y : T2' => g (@proj1_sig T2 (fun z : T2 => dom z) y)))) (_ : forall x : T1, @filterlim T2 (CompleteSpace.sort U) (f x) (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) (h x))), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => and (@filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) (@filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) l))) *)
set (g' := fun y : T2' => g (proj1_sig y)).
(* Goal: forall (_ : @filterlim T1 (forall _ : T2', CompleteSpace.sort U) f' F1 (@locally (fct_UniformSpace T2' (CompleteSpace.UniformSpace U)) g')) (_ : forall x : T1, @filterlim T2 (CompleteSpace.sort U) (f x) (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) (h x))), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => and (@filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) (@filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) l))) *)
intros Hfg Hfh.
(* Goal: @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => and (@filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) (@filterlim T2 (UniformSpace.sort (CompleteSpace.UniformSpace U)) g (@within T2 dom F2) (@locally (CompleteSpace.UniformSpace U) l))) *)
refine (filterlim_switch F1 FF1 F2' _ f' g' h _ _).
(* Goal: @ProperFilter T2' F2' *)
(* Goal: @filterlim T1 (forall _ : T2', CompleteSpace.sort U) f' F1 (@locally (fct_UniformSpace T2' (CompleteSpace.UniformSpace U)) g') *)
(* Goal: forall x : T1, @filterlim T2' (CompleteSpace.sort U) (f' x) F2' (@locally (CompleteSpace.UniformSpace U) (h x)) *)
now apply subset_filter_proper.
(* Goal: @filterlim T1 (forall _ : T2', CompleteSpace.sort U) f' F1 (@locally (fct_UniformSpace T2' (CompleteSpace.UniformSpace U)) g') *)
(* Goal: forall x : T1, @filterlim T2' (CompleteSpace.sort U) (f' x) F2' (@locally (CompleteSpace.UniformSpace U) (h x)) *)
intros H P.
(* Goal: @filtermap T1 (forall _ : T2, CompleteSpace.sort U) f F1 P *)
(* Goal: @ex (forall _ : T1, Prop) (fun P : forall _ : T1, Prop => and (F1 P) (forall (u v : T1) (_ : P u) (_ : P v), @ball (CompleteSpace.UniformSpace U) (h u) (pos eps) (h v))) *)
(* Goal: forall (x : UniformSpace.sort (CompleteSpace.UniformSpace U)) (_ : @filterlim T1 (CompleteSpace.sort U) h F1 (@locally (CompleteSpace.UniformSpace U) x)), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) *)
now apply Hfg.
(* Goal: forall x : T1, @filterlim T2' (CompleteSpace.sort U) (f' x) F2' (@locally (CompleteSpace.UniformSpace U) (h x)) *)
intros x P HP.
(* Goal: @filtermap T2' (CompleteSpace.sort U) (f' x) F2' P *)
now apply Hfh.
Qed.

(** * Modules *)

Module ModuleSpace.

Record mixin_of (K : Ring) (V : AbelianGroup) := Mixin {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  scal : K -> V -> V ;
  ax1 : forall x y u, scal x (scal y u) = scal (mult x y) u ;
  ax2 : forall u, scal one u = u ;
  ax3 : forall x u v, scal x (plus u v) = plus (scal x u) (scal x v) ;
  ax4 : forall x y u, scal (plus x y) u = plus (scal x u) (scal y u)
}.

Section ClassDef.

Variable K : Ring.

Record class_of (V : Type) := Class {
  base : AbelianGroup.class_of V ;
  mixin : mixin_of K (AbelianGroup.Pack _ base V)
}.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base : class_of >-> AbelianGroup.class_of.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.

Variable cT : type.

Definition class := let: Pack _ c _ := cT return class_of cT in c.

Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of xT).

Definition AbelianGroup := AbelianGroup.Pack cT xclass xT.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base : class_of >-> AbelianGroup.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion mixin : class_of >-> mixin_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion AbelianGroup : type >-> AbelianGroup.type.
Canonical AbelianGroup.
Notation ModuleSpace := type.

End Exports.

End ModuleSpace.

Export ModuleSpace.Exports.

Section ModuleSpace1.

Context {K : Ring} {V : ModuleSpace K}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition scal : K -> V -> V := ModuleSpace.scal _ _ (ModuleSpace.class K V).

Lemma scal_assoc :
  forall (x y : K) (u : V),
  scal x (scal y u) = scal (mult x y) u.
Proof.
(* Goal: forall (x y : Ring.sort K) (u : ModuleSpace.sort K V), @eq (ModuleSpace.sort K V) (scal x (scal y u)) (scal (@mult K x y) u) *)
apply ModuleSpace.ax1.
Qed.

Lemma scal_one :
  forall (u : V), scal one u = u.
Proof.
(* Goal: forall u : ModuleSpace.sort K V, @eq (ModuleSpace.sort K V) (scal (@one K) u) u *)
apply ModuleSpace.ax2.
Qed.

Lemma scal_distr_l :
  forall (x : K) (u v : V),
  scal x (plus u v) = plus (scal x u) (scal x v).
Proof.
(* Goal: forall (x : Ring.sort K) (u v : ModuleSpace.sort K V), @eq (ModuleSpace.sort K V) (scal x (@plus (ModuleSpace.AbelianGroup K V) u v)) (@plus (ModuleSpace.AbelianGroup K V) (scal x u) (scal x v)) *)
apply ModuleSpace.ax3.
Qed.

Lemma scal_distr_r :
  forall (x y : K) (u : V),
  scal (plus x y) u = plus (scal x u) (scal y u).
Proof.
(* Goal: forall (x y : Ring.sort K) (u : ModuleSpace.sort K V), @eq (ModuleSpace.sort K V) (scal (@plus (Ring.AbelianGroup K) x y) u) (@plus (ModuleSpace.AbelianGroup K V) (scal x u) (scal y u)) *)
apply ModuleSpace.ax4.
Qed.

Lemma scal_zero_r :
  forall x : K,
  scal x zero = zero.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq (ModuleSpace.sort K V) (scal x (@zero (ModuleSpace.AbelianGroup K V))) (@zero (ModuleSpace.AbelianGroup K V)) *)
apply plus_reg_r with (scal x zero).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- scal_distr_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_zero_r.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite plus_zero_l.
Qed.

Lemma scal_zero_l :
  forall u : V,
  scal zero u = zero.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (or (Rlt x y) (Rlt y x)) (not (@eq R x y)) *)
(* Goal: @open R_UniformSpace (fun u : UniformSpace.sort R_UniformSpace => or (Rlt u y) (Rlt y u)) *)
intros u.
(* Goal: @eq (ModuleSpace.sort K V) (scal (@zero (Ring.AbelianGroup K)) u) (@zero (ModuleSpace.AbelianGroup K V)) *)
apply plus_reg_r with (r := scal zero u).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_zero_l.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- scal_distr_r.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
now rewrite plus_zero_r.
Qed.

Lemma scal_opp_l :
  forall (x : K) (u : V),
  scal (opp x) u = opp (scal x u).
Proof.
(* Goal: forall (x : Ring.sort K) (u : ModuleSpace.sort K V), @eq (ModuleSpace.sort K V) (scal x (@opp (ModuleSpace.AbelianGroup K V) u)) (@opp (ModuleSpace.AbelianGroup K V) (scal x u)) *)
intros x u.
(* Goal: @eq (ModuleSpace.sort K V) (scal x (@opp (ModuleSpace.AbelianGroup K V) u)) (@opp (ModuleSpace.AbelianGroup K V) (scal x u)) *)
apply plus_reg_r with (r := (scal x u)).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_l.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- scal_distr_r.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_l.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (scal (@zero (Ring.AbelianGroup K)) u) (@zero (ModuleSpace.AbelianGroup K V)) *)
apply scal_zero_l.
Qed.

Lemma scal_opp_r :
  forall (x : K) (u : V),
  scal x (opp u) = opp (scal x u).
Proof.
(* Goal: forall (x : Ring.sort K) (u : ModuleSpace.sort K V), @eq (ModuleSpace.sort K V) (scal x (@opp (ModuleSpace.AbelianGroup K V) u)) (@opp (ModuleSpace.AbelianGroup K V) (scal x u)) *)
intros x u.
(* Goal: @eq (ModuleSpace.sort K V) (scal x (@opp (ModuleSpace.AbelianGroup K V) u)) (@opp (ModuleSpace.AbelianGroup K V) (scal x u)) *)
apply plus_reg_r with (r := (scal x u)).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_l.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- scal_distr_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_l.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (scal x (@zero (ModuleSpace.AbelianGroup K V))) (@zero (ModuleSpace.AbelianGroup K V)) *)
apply scal_zero_r.
Qed.

Lemma scal_opp_one :
  forall u : V,
  scal (opp one) u = opp u.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (or (Rlt x y) (Rlt y x)) (not (@eq R x y)) *)
(* Goal: @open R_UniformSpace (fun u : UniformSpace.sort R_UniformSpace => or (Rlt u y) (Rlt y u)) *)
intros u.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite scal_opp_l.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite scal_one.
Qed.

Lemma scal_minus_distr_l (x : K) (u v : V) :
   scal x (minus u v) = minus (scal x u) (scal x v).
Proof.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite /minus scal_distr_l scal_opp_r.
Qed.
Lemma scal_minus_distr_r (x y : K) (u : V) :
   scal (minus x y) u = minus (scal x u) (scal y u).
Proof.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite /minus scal_distr_r scal_opp_l.
Qed.

Lemma sum_n_m_scal_l :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (a : K) (u : nat -> V) (n m : nat),
  sum_n_m (fun k => scal a (u k)) n m = scal a (sum_n_m u n m).
Proof.
(* Goal: forall (a : Ring.sort K) (u : forall _ : nat, ModuleSpace.sort K V) (n m : nat), @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  intros a u n m.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (le_dec n m) => Hnm.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: m n u Hnm => [ | m IH] n u Hnm.
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n O) (sum_f n O a) *)
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n (S m)) (sum_f n (S m) a) *)
  apply le_n_O_eq in Hnm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite -Hnm !sum_n_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n (S m)) (@sum_n_m R_AbelianGroup b n (S m)) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  destruct n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_Sm ; try by apply le_O_n.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sym_eq, scal_distr_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -!sum_n_m_S.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => scal a (u (S n))) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => u (S n)) n m)) *)
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  apply IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_S_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  apply not_le in Hnm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_m_zero //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite scal_zero_r.
Qed.

Lemma sum_n_scal_l :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (a : K) (u : nat -> V) (n : nat),
  sum_n (fun k => scal a (u k)) n = scal a (sum_n u n).
Proof.
(* Goal: forall (a : Ring.sort K) (u : forall _ : nat, ModuleSpace.sort K V) (n : nat), @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n) (scal a (@sum_n (ModuleSpace.AbelianGroup K V) u n)) *)
  intros a u n.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n) (scal a (@sum_n (ModuleSpace.AbelianGroup K V) u n)) *)
  apply sum_n_m_scal_l.
Qed.

End ModuleSpace1.

(** Rings are modules *)

Section Ring_ModuleSpace.

Variable (K : Ring).

Definition Ring_ModuleSpace_mixin :=
  ModuleSpace.Mixin K _ _ mult_assoc mult_one_l mult_distr_l mult_distr_r.

Canonical Ring_ModuleSpace :=
  ModuleSpace.Pack K K (ModuleSpace.Class _ _ _ Ring_ModuleSpace_mixin) K.

End Ring_ModuleSpace.

Section AbsRing_ModuleSpace.

Variable (K : AbsRing).

Definition AbsRing_ModuleSpace_mixin :=
  ModuleSpace.Mixin K _ _ mult_assoc mult_one_l mult_distr_l mult_distr_r.

Canonical AbsRing_ModuleSpace :=
  ModuleSpace.Pack K K (ModuleSpace.Class _ _ _ AbsRing_ModuleSpace_mixin) K.

End AbsRing_ModuleSpace.

(** ** Modules with a norm *)

Module NormedModuleAux.

Section ClassDef.

Variable K : AbsRing.

Record class_of (T : Type) := Class {
  base : ModuleSpace.class_of K T ;
  mixin : UniformSpace.mixin_of T
}.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base : class_of >-> ModuleSpace.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion mixin : class_of >-> UniformSpace.class_of.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.

Variable cT : type.

Definition class := let: Pack _ c _ := cT return class_of cT in c.

Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of xT).

Definition AbelianGroup := AbelianGroup.Pack cT xclass xT.
Definition ModuleSpace := ModuleSpace.Pack _ cT xclass xT.
Definition UniformSpace := UniformSpace.Pack cT xclass xT.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base : class_of >-> ModuleSpace.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion mixin : class_of >-> UniformSpace.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion AbelianGroup : type >-> AbelianGroup.type.
Canonical AbelianGroup.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion ModuleSpace : type >-> ModuleSpace.type.
Canonical ModuleSpace.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion UniformSpace : type >-> UniformSpace.type.
Canonical UniformSpace.
Notation NormedModuleAux := type.

End Exports.

End NormedModuleAux.

Export NormedModuleAux.Exports.

Module NormedModule.

Record mixin_of (K : AbsRing) (V : NormedModuleAux K) := Mixin {
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  norm : V -> R ;
  norm_factor : R ;
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  ax1 : forall (x y : V), norm (plus x y) <= norm x + norm y ;
  ax2 : forall (l : K) (x : V), norm (scal l x) <= abs l * norm x ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax3 : forall (x y : V) (eps : R), norm (minus y x) < eps -> ball x eps y ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax4 : forall (x y : V) (eps : posreal), ball x eps y -> norm (minus y x) < norm_factor * eps ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ax5 : forall x : V, norm x = 0 -> x = zero
}.

Section ClassDef.

Variable K : AbsRing.

Record class_of (T : Type) := Class {
  base : NormedModuleAux.class_of K T ;
  mixin : mixin_of K (NormedModuleAux.Pack K T base T)
}.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base : class_of >-> NormedModuleAux.class_of.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.

Variable cT : type.

Definition class := let: Pack _ c _ := cT return class_of cT in c.

Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of xT).

Definition AbelianGroup := AbelianGroup.Pack cT xclass xT.
Definition ModuleSpace := ModuleSpace.Pack _ cT xclass xT.
Definition UniformSpace := UniformSpace.Pack cT xclass xT.
Definition NormedModuleAux := NormedModuleAux.Pack _ cT xclass xT.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base : class_of >-> NormedModuleAux.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion mixin : class_of >-> mixin_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion AbelianGroup : type >-> AbelianGroup.type.
Canonical AbelianGroup.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion ModuleSpace : type >-> ModuleSpace.type.
Canonical ModuleSpace.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion UniformSpace : type >-> UniformSpace.type.
Canonical UniformSpace.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion NormedModuleAux : type >-> NormedModuleAux.type.
Canonical NormedModuleAux.
Notation NormedModule := type.

End Exports.

End NormedModule.

Export NormedModule.Exports.

Section NormedModule1.

Context {K : AbsRing} {V : NormedModule K}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition norm : V -> R := NormedModule.norm K _ (NormedModule.class K V).

Definition norm_factor : R := NormedModule.norm_factor K _ (NormedModule.class K V).

Lemma norm_triangle :
  forall x y : V,
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  norm (plus x y) <= norm x + norm y.
Proof.
(* Goal: forall x y : NormedModule.sort K V, Rle (norm (@plus (NormedModule.AbelianGroup K V) x y)) (Rplus (norm x) (norm y)) *)
apply NormedModule.ax1.
Qed.

Lemma norm_scal :
  forall (l : K) (x : V),
  norm (scal l x) <= abs l * norm x.
Proof.
(* Goal: forall (l : AbsRing.sort K) (x : NormedModule.sort K V), Rle (norm (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) l x)) (Rmult (@abs K l) (norm x)) *)
apply NormedModule.ax2.
Qed.

Lemma norm_compat1 :
  forall (x y : V) (eps : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  norm (minus y x) < eps -> ball x eps y.
Proof.
(* Goal: forall (x y : NormedModule.sort K V) (eps : R) (_ : Rlt (norm (@minus (NormedModule.AbelianGroup K V) y x)) eps), @ball (NormedModule.UniformSpace K V) x eps y *)
apply NormedModule.ax3.
Qed.

Lemma norm_compat2 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x y : V) (eps : posreal), ball x eps y -> norm (minus y x) < norm_factor * eps.
Proof.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: NormedModule.ax4.
Qed.

Lemma norm_eq_zero :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall x : V, norm x = 0 -> x = zero.
Proof.
(* Goal: forall (x : NormedModule.sort K V) (_ : @eq R (norm x) (IZR Z0)), @eq (NormedModule.sort K V) x (@zero (NormedModule.AbelianGroup K V)) *)
apply NormedModule.ax5.
Qed.

Lemma norm_zero :
  norm zero = 0.
Proof.
(* Goal: @eq R (Rabs (Rminus u x)) (IZR Z0) *)
apply Rle_antisym.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- rewrite -(scal_zero_l zero).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rmult_0_l (norm zero)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(@abs_zero K).
(* Goal: Rle (norm (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (@abs K (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
  apply norm_scal.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply Rplus_le_reg_r with (norm zero).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rplus_0_l.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -{1}[zero]plus_zero_r.
(* Goal: Rle (norm (@plus (NormedModule.AbelianGroup K V) (@zero (NormedModule.AbelianGroup K V)) (@zero (NormedModule.AbelianGroup K V)))) (Rplus (norm (@zero (NormedModule.AbelianGroup K V))) (norm (@zero (NormedModule.AbelianGroup K V)))) *)
  exact (norm_triangle zero zero).
Qed.

Lemma norm_factor_gt_0 :
  0 < norm_factor.
Proof.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- (Rmult_1_r norm_factor).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- norm_zero.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite <- (plus_opp_r zero).
(* Goal: Rlt (norm (@plus (NormedModule.AbelianGroup K V) (@zero (NormedModule.AbelianGroup K V)) (@opp (NormedModule.AbelianGroup K V) (@zero (NormedModule.AbelianGroup K V))))) (Rmult norm_factor (IZR (Zpos xH))) *)
apply (norm_compat2 _ _ (mkposreal _ Rlt_0_1)).
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
apply ball_center.
Qed.

Lemma norm_opp :
  forall x : V,
  norm (opp x) = norm x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq R (Rabs (Rminus u x)) (IZR Z0) *)
apply Rle_antisym.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- rewrite -scal_opp_one.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rmult_1_l (norm x)) -(@abs_opp_one K).
(* Goal: Rle (norm (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (@abs K (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
  apply norm_scal.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- rewrite -{1}[x]opp_opp -scal_opp_one.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rmult_1_l (norm (opp x))) -(@abs_opp_one K).
(* Goal: Rle (norm (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (@abs K (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
  apply norm_scal.
Qed.

Lemma norm_ge_0 :
  forall x : V,
  0 <= norm x.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
  intros x.
(* Goal: Rle (IZR Z0) (norm x) *)
  apply Rmult_le_reg_l with 2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rlt_0_2.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite Rmult_0_r -norm_zero -(plus_opp_r x).
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  apply Rle_trans with (norm x + norm (opp x)).
(* Goal: Rle (norm (@plus (NormedModule.AbelianGroup K V) x (@opp (NormedModule.AbelianGroup K V) x))) (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
(* Goal: Rle (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
  apply norm_triangle.
(* Goal: Rle (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
  apply Req_le ; rewrite norm_opp.
(* Goal: @eq R (Rplus (norm x) (norm x)) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
  ring.
Qed.

Lemma norm_triangle_inv :
  forall x y : V,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Rabs (norm x - norm y) <= norm (minus x y).
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
  intros x y.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  apply Rabs_le_between' ; split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(norm_opp (minus _ _)).
  apply Rle_minus_l ; eapply Rle_trans.
(* Goal: Rle (norm (@plus (NormedModule.AbelianGroup K V) x (@opp (NormedModule.AbelianGroup K V) x))) (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
(* Goal: Rle (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
  2 : apply norm_triangle.
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) u v) (@plus (NormedModule.AbelianGroup K V) x y))) (@norm K V (@plus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) u x) (@minus (NormedModule.AbelianGroup K V) v y))) *)
  apply Req_le, f_equal.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite /minus opp_plus plus_assoc plus_opp_r plus_zero_l opp_opp.
  eapply Rle_trans.
(* Goal: Rle (norm (@plus (NormedModule.AbelianGroup K V) x (@opp (NormedModule.AbelianGroup K V) x))) (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
(* Goal: Rle (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
  2 : apply norm_triangle.
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) u v) (@plus (NormedModule.AbelianGroup K V) x y))) (@norm K V (@plus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) u x) (@minus (NormedModule.AbelianGroup K V) v y))) *)
  apply Req_le, f_equal.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite /minus plus_comm -plus_assoc plus_opp_l plus_zero_r.
Qed.

Lemma eq_close :
  forall x y : V,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  close x y -> x = y.
Proof.
(* Goal: forall (x y : NormedModule.sort K V) (_ : @is_filter_lim (NormedModule.UniformSpace K V) (@locally (NormedModule.UniformSpace K V) x) y), @eq (NormedModule.sort K V) x y *)
intros x y H.
(* Goal: @eq (AbelianGroup.sort G) (opp (opp x)) x *)
apply plus_reg_r with (opp x).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_r.
apply eq_sym, norm_eq_zero.
(* Goal: @eq R (Rabs (Rminus u x)) (IZR Z0) *)
apply Rle_antisym.
2: apply norm_ge_0.
apply prop_eps.
(* Goal: forall eps : posreal, not (forall (y : UniformSpace.sort T) (_ : @ball T x (pos eps) y), not (P y)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
intros eps He.
assert (He' : 0 < eps / norm_factor).
  apply Rdiv_lt_0_compat with (1 := He).
(* Goal: Rgt norm_factor (IZR Z0) *)
  apply norm_factor_gt_0.
specialize (H (mkposreal _ He')).
replace eps with (norm_factor * (eps / norm_factor)).
apply norm_compat2 with (1 := H).
field.
apply Rgt_not_eq, norm_factor_gt_0.
Qed.

Definition ball_norm (x : V) (eps : R) (y : V) := norm (minus y x) < eps.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition locally_norm (x : V) (P : V -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists eps : posreal, forall y, ball_norm x eps y -> P y.

Lemma locally_le_locally_norm :
  forall x, filter_le (locally x) (locally_norm x).
Proof.
(* Goal: forall x : NormedModule.sort K V, @filter_le (NormedModule.sort K V) (locally_norm x) (@locally (NormedModule.UniformSpace K V) x) *)
intros x P [eps H].
(* Goal: @locally (NormedModule.UniformSpace K V) x P *)
assert (He : 0 < / norm_factor * eps).
(* Goal: Rlt (IZR Z0) (Rmult (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: Rlt (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: not (@eq R (pos delta) (IZR Z0)) *)
(* Goal: Rle (IZR Z0) (Rinv (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  apply Rmult_lt_0_compat.
(* Goal: Rlt (IZR Z0) (Rinv (pos delta)) *)
(* Goal: Rlt (IZR Z0) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: Rlt (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: not (@eq R (pos delta) (IZR Z0)) *)
(* Goal: Rle (IZR Z0) (Rinv (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  apply Rinv_0_lt_compat.
(* Goal: Rgt norm_factor (IZR Z0) *)
  apply norm_factor_gt_0.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
  apply cond_pos.
(* Goal: @locally (NormedModule.UniformSpace K V) x P *)
exists (mkposreal _ He).
(* Goal: forall (y : NormedModule.sort K V) (_ : ball_norm x (pos eps) y), P y *)
intros y By.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
apply H.
(* Goal: ball_norm y (pos eps) x *)
unfold ball_norm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite -(Rmult_1_l eps) -(Rinv_r norm_factor).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Rmult_assoc.
(* Goal: Rlt (norm (@minus (NormedModule.AbelianGroup K V) y x)) (Rmult norm_factor (Rmult (Rinv norm_factor) (pos eps))) *)
(* Goal: not (@eq R norm_factor (IZR Z0)) *)
apply norm_compat2 with (1 := By).
(* Goal: not (@eq R norm_factor (IZR Z0)) *)
apply Rgt_not_eq.
(* Goal: Rgt norm_factor (IZR Z0) *)
apply norm_factor_gt_0.
Qed.

Lemma locally_norm_le_locally :
  forall x, filter_le (locally_norm x) (locally x).
Proof.
(* Goal: forall x : NormedModule.sort K V, @filter_le (NormedModule.sort K V) (locally_norm x) (@locally (NormedModule.UniformSpace K V) x) *)
intros x P [eps H].
(* Goal: locally_norm x P *)
exists eps.
(* Goal: forall (y : NormedModule.sort K V) (_ : ball_norm x (pos eps) y), P y *)
intros y By.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
apply H.
(* Goal: @ball (NormedModule.UniformSpace K V) x (pos eps) y *)
now apply norm_compat1.
Qed.

Lemma locally_norm_ball_norm :
  forall (x : V) (eps : posreal),
  locally_norm x (ball_norm x eps).
Proof.
(* Goal: forall (x : prod (UniformSpace.sort U) (UniformSpace.sort V)) (eps : posreal), prod_ball x (pos eps) x *)
intros x eps.
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
now exists eps.
Qed.

Lemma locally_norm_ball :
  forall (x : V) (eps : posreal),
  locally_norm x (ball x eps).
Proof.
(* Goal: forall (x : prod (UniformSpace.sort U) (UniformSpace.sort V)) (eps : posreal), prod_ball x (pos eps) x *)
intros x eps.
(* Goal: @filter_le (NormedModule.sort K V) (@locally_norm K V (@plus (NormedModule.AbelianGroup K V) x y)) (@locally (NormedModule.UniformSpace K V) (@plus (NormedModule.AbelianGroup K V) x y)) *)
(* Goal: @filterlim (prod (NormedModule.sort K V) (NormedModule.sort K V)) (NormedModule.sort K V) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) (@locally_norm K V (@plus (NormedModule.AbelianGroup K V) x y)) *)
apply locally_norm_le_locally.
(* Goal: @locally (NormedModule.UniformSpace K V) x (@ball (NormedModule.UniformSpace K V) x (pos eps)) *)
apply locally_ball.
Qed.

Lemma locally_ball_norm :
  forall (x : V) (eps : posreal),
  locally x (ball_norm x eps).
Proof.
(* Goal: forall (x : prod (UniformSpace.sort U) (UniformSpace.sort V)) (eps : posreal), prod_ball x (pos eps) x *)
intros x eps.
(* Goal: @locally (NormedModule.UniformSpace K V) x (ball_norm x (pos eps)) *)
apply locally_le_locally_norm.
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
apply locally_norm_ball_norm.
Qed.

Lemma ball_norm_triangle (x y z : V) (e1 e2 : R) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ball_norm x e1 y -> ball_norm y e2 z -> ball_norm x (e1 + e2) z.
Proof.
  intros H1 H2.
  eapply Rle_lt_trans, Rplus_lt_compat.
(* Goal: Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) *)
  2: by apply H1.
(* Goal: Rle d (Rmult d (Rinv (IZR (Zpos (xO xH))))) *)
  2: by apply H2.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rplus_comm.
  eapply Rle_trans, norm_triangle.
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) u v) (@plus (NormedModule.AbelianGroup K V) x y))) (@norm K V (@plus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) u x) (@minus (NormedModule.AbelianGroup K V) v y))) *)
  apply Req_le, f_equal.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite /minus -!plus_assoc.
(* Goal: @eq (Ring.sort T) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@coeff_mat (Ring.sort T) (S m) l (@zero (Ring.AbelianGroup T)) (@mk_matrix (Ring.sort T) (S m) l (fun i j : nat => @sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B i l0) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l0 j)) (Init.Nat.pred k))) m' l')) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
  apply f_equal.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite plus_assoc plus_opp_l plus_zero_l.
Qed.

Lemma ball_norm_center (x : V) (e : posreal) :
  ball_norm x e x.
Proof.
(* Goal: ball_norm x (pos e) x *)
  eapply Rle_lt_trans, e.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite minus_eq_zero norm_zero.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Req_le.
Qed.

Lemma ball_norm_dec : forall (x y : V) (eps : posreal),
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  {ball_norm x eps y} + {~ ball_norm x eps y}.
Proof.
(* Goal: forall (x y : NormedModule.sort K V) (eps : posreal), sumbool (ball_norm x (pos eps) y) (not (ball_norm x (pos eps) y)) *)
  intros x y eps.
(* Goal: sumbool (ball_norm x (pos eps) y) (not (ball_norm x (pos eps) y)) *)
  apply Rlt_dec.
Qed.

Lemma ball_norm_sym :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x y : V) (eps : posreal), ball_norm x eps y -> ball_norm y eps x.
Proof.
(* Goal: forall (x y : NormedModule.sort K V) (eps : posreal) (_ : ball_norm x (pos eps) y), ball_norm y (pos eps) x *)
  intros x y eps Hxy.
(* Goal: ball_norm y (pos eps) x *)
  unfold ball_norm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite <- norm_opp.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite opp_minus.
(* Goal: Rlt (norm (@minus (NormedModule.AbelianGroup K V) y x)) (pos eps) *)
  apply Hxy.
Qed.

Lemma ball_norm_le :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (x : V) (e1 e2 : posreal), e1 <= e2 ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall y, ball_norm x e1 y -> ball_norm x e2 y.
Proof.
(* Goal: forall (x : NormedModule.sort K V) (e1 e2 : posreal) (_ : Rle (pos e1) (pos e2)) (y : NormedModule.sort K V) (_ : ball_norm x (pos e1) y), ball_norm x (pos e2) y *)
  intros x e1 e2 He y H1.
(* Goal: ball_norm x (pos e2) y *)
  now apply Rlt_le_trans with e1.
Qed.

Lemma ball_norm_eq :
  forall x y : V,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall eps : posreal, ball_norm x eps y) -> x = y.
Proof.
(* Goal: forall (x y : NormedModule.sort K V) (_ : @is_filter_lim (NormedModule.UniformSpace K V) (@locally (NormedModule.UniformSpace K V) x) y), @eq (NormedModule.sort K V) x y *)
intros x y H.
(* Goal: @eq (AbelianGroup.sort G) (opp (opp x)) x *)
apply plus_reg_r with (opp x).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite plus_opp_r.
apply eq_sym, norm_eq_zero.
(* Goal: @eq R (Rabs (Rminus u x)) (IZR Z0) *)
apply Rle_antisym.
2: apply norm_ge_0.
apply prop_eps.
(* Goal: forall eps : posreal, not (forall (y : UniformSpace.sort T) (_ : @ball T x (pos eps) y), not (P y)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
intros eps He.
exact (H (mkposreal eps He)).
Qed.

Lemma is_filter_lim_unique :
  forall {F} {FF : ProperFilter' F} (x y : V),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  is_filter_lim F x -> is_filter_lim F y -> x = y.
Proof.
intros F FF x y Hx Hy.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
apply ball_norm_eq => eps.
assert (Hx': F (ball_norm x (pos_div_2 eps))).
(* Goal: False *)
  apply Hx.
  apply locally_ball_norm.
assert (Hy': F (ball_norm y (pos_div_2 eps))).
(* Goal: F (fun x : T => @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f x)) *)
(* Goal: forall (u v : T) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f u)) (_ : @ball (CompleteSpace.UniformSpace U) y (pos (pos_div_2 eps)) (f v)), @ball (CompleteSpace.UniformSpace U) (f u) (pos eps) (f v) *)
  apply Hy.
  apply locally_ball_norm.
(* Goal: Rlt (IZR Z0) d *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
apply Rnot_le_lt.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
intros H.
apply (@filter_not_empty V F FF).
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp (filter_and _ _ Hx' Hy').
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
clear -H.
intros z [Bx By].
revert H.
apply Rlt_not_le.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite (double_var eps).
change (eps / 2) with (pos (pos_div_2 eps)).
apply ball_norm_triangle with (1 := Bx).
now apply ball_norm_sym.
Qed.

Lemma is_filter_lim_locally_unique :
  forall (x y : V),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  is_filter_lim (locally x) y -> x = y.
Proof.
(* Goal: forall (x y : NormedModule.sort K V) (_ : @is_filter_lim (NormedModule.UniformSpace K V) (@locally (NormedModule.UniformSpace K V) x) y), @eq (NormedModule.sort K V) x y *)
intros x y H.
(* Goal: @eq (CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V)) (@iota (CompleteNormedModule.CompleteSpace K V) P) x *)
apply eq_close.
(* Goal: @close (NormedModule.UniformSpace K V) x y *)
now apply is_filter_lim_locally_close.
Qed.

End NormedModule1.

Section NormedModule2.

Context {T : Type} {K : AbsRing} {V : NormedModule K}.

Lemma filterlim_locally_unique :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF : ProperFilter' F} (f : T -> V) (x y : V),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F (locally x) -> filterlim f F (locally y) ->
  x = y.
Proof.
(* Goal: forall (F : forall _ : forall _ : T, Prop, Prop) (_ : @ProperFilter' T F) (f : forall _ : T, NormedModule.sort K V) (x y : NormedModule.sort K V) (_ : @filterlim T (NormedModule.sort K V) f F (@locally (NormedModule.UniformSpace K V) x)) (_ : @filterlim T (NormedModule.sort K V) f F (@locally (NormedModule.UniformSpace K V) y)), @eq (NormedModule.sort K V) x y *)
intros F FF f x y.
(* Goal: forall (_ : @filterlim T (NormedModule.sort K V) f F (@locally (NormedModule.UniformSpace K V) x)) (_ : @filterlim T (NormedModule.sort K V) f F (@locally (NormedModule.UniformSpace K V) y)), @eq (NormedModule.sort K V) x y *)
apply is_filter_lim_unique.
Qed.

Lemma filterlimi_locally_unique :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {F} {FF : ProperFilter' F} (f : T -> V -> Prop) (x y : V),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F (locally x) -> filterlimi f F (locally y) ->
  x = y.
Proof.
intros F FF f x y Hf Hx Hy.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
apply ball_norm_eq => eps.
specialize (Hx (ball_norm x (pos_div_2 eps)) (locally_ball_norm _ _)).
specialize (Hy (ball_norm y (pos_div_2 eps)) (locally_ball_norm _ _)).
unfold filtermapi in Hx, Hy.
(* Goal: Rlt (IZR Z0) d *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
apply Rnot_le_lt.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
intros H.
apply (@filter_not_empty _ F FF).
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: filter_imp (filter_and _ _ (filter_and _ _ Hx Hy) Hf).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
clear -H.
intros z [[[x' [Hx Bx]] [y' [Hy By]]] Hf].
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: Rlt_not_le H.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite (double_var eps).
change (eps / 2) with (pos (pos_div_2 eps)).
apply ball_norm_triangle with (1 := Bx).
apply ball_norm_sym.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite (Hf _ _ Hx Hy).
Qed.

End NormedModule2.

(** Rings with absolute values are normed modules *)

Section AbsRing_NormedModule.

Variable (K : AbsRing).

Canonical AbsRing_NormedModuleAux :=
  NormedModuleAux.Pack K K (NormedModuleAux.Class _ _ (ModuleSpace.class _ (AbsRing_ModuleSpace K)) (UniformSpace.class (AbsRing_UniformSpace K))) K.

Lemma AbsRing_norm_compat2 :
  forall (x y : AbsRing_NormedModuleAux) (eps : posreal),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ball x eps y -> abs (minus y x) < 1 * eps.
Proof.
(* Goal: forall (x y : NormedModuleAux.sort K AbsRing_NormedModuleAux) (eps : posreal) (_ : @ball (NormedModuleAux.UniformSpace K AbsRing_NormedModuleAux) x (pos eps) y), Rlt (@abs K (@minus (NormedModuleAux.AbelianGroup K AbsRing_NormedModuleAux) y x)) (Rmult (IZR (Zpos xH)) (pos eps)) *)
  intros x y eps H.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
  now rewrite Rmult_1_l.
Qed.

Definition AbsRing_NormedModule_mixin :=
  NormedModule.Mixin K _ abs 1 abs_triangle abs_mult (fun x y e H => H) AbsRing_norm_compat2 abs_eq_zero.

Canonical AbsRing_NormedModule :=
  NormedModule.Pack K _ (NormedModule.Class _ _ _ AbsRing_NormedModule_mixin) K.

End AbsRing_NormedModule.

(** Normed vector spaces have some continuous functions *)

Section NVS_continuity.

Context {K : AbsRing} {V : NormedModule K}.

Lemma filterlim_plus :
  forall x y : V,
  filterlim (fun z : V * V => plus (fst z) (snd z)) (filter_prod (locally x) (locally y)) (locally (plus x y)).
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
intros x y.
(* Goal: @filterlim (prod (NormedModule.sort K V) (NormedModule.sort K V)) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) (@locally (NormedModule.UniformSpace K V) x) (@locally (NormedModule.UniformSpace K V) y)) (@locally (NormedModule.UniformSpace K V) (@plus (NormedModule.AbelianGroup K V) x y)) *)
apply (filterlim_filter_le_1 (F := filter_prod (locally_norm x) (locally_norm y))).
(* Goal: @filter_le (prod (NormedModule.sort K V) (NormedModule.sort K V)) (@filter_prod (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) (@locally (NormedModule.UniformSpace K V) x) (@locally (NormedModule.UniformSpace K V) y)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) *)
(* Goal: @filterlim (prod (NormedModule.sort K V) (NormedModule.sort K V)) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) (@locally (NormedModule.UniformSpace K V) (@plus (NormedModule.AbelianGroup K V) x y)) *)
  intros P [Q R LQ LR H].
(* Goal: @filter_prod (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) (@locally (NormedModule.UniformSpace K V) x) (@locally (NormedModule.UniformSpace K V) y) P *)
(* Goal: @filterlim (prod (NormedModule.sort K V) (NormedModule.sort K V)) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) (@locally (NormedModule.UniformSpace K V) (@plus (NormedModule.AbelianGroup K V) x y)) *)
  exists Q R.
(* Goal: @locally (NormedModule.UniformSpace K V) x (ball_norm x (pos eps)) *)
  now apply locally_le_locally_norm.
(* Goal: @locally (NormedModule.UniformSpace K V) x (ball_norm x (pos eps)) *)
  now apply locally_le_locally_norm.
(* Goal: forall (x y : NormedModule.sort K V) (_ : Q x) (_ : R y), P (@pair (NormedModule.sort K V) (NormedModule.sort K V) x y) *)
(* Goal: @filterlim (prod (NormedModule.sort K V) (NormedModule.sort K V)) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) (@locally (NormedModule.UniformSpace K V) (@plus (NormedModule.AbelianGroup K V) x y)) *)
  exact H.
(* Goal: @filterlim (prod (NormedModule.sort K V) (NormedModule.sort K V)) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) (@locally (NormedModule.UniformSpace K V) (@plus (NormedModule.AbelianGroup K V) x y)) *)
apply (filterlim_filter_le_2 (G := locally_norm (plus x y))).
(* Goal: @filter_le (NormedModule.sort K V) (@locally_norm K V (@plus (NormedModule.AbelianGroup K V) x y)) (@locally (NormedModule.UniformSpace K V) (@plus (NormedModule.AbelianGroup K V) x y)) *)
(* Goal: @filterlim (prod (NormedModule.sort K V) (NormedModule.sort K V)) (NormedModule.sort K V) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) (@locally_norm K V (@plus (NormedModule.AbelianGroup K V) x y)) *)
  apply locally_norm_le_locally.
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
intros P [eps HP].
(* Goal: @filtermap (prod (NormedModule.sort K V) (NormedModule.sort K V)) (NormedModule.sort K V) (fun z : prod (NormedModule.sort K V) (NormedModule.sort K V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) z) (@snd (NormedModule.sort K V) (NormedModule.sort K V) z)) (@filter_prod (NormedModule.sort K V) (NormedModule.sort K V) (@locally_norm K V x) (@locally_norm K V y)) P *)
exists (ball_norm x (pos_div_2 eps)) (ball_norm y (pos_div_2 eps)).
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
by apply locally_norm_ball_norm.
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
by apply locally_norm_ball_norm.
(* Goal: forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v *)
intros u v Hu Hv.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply HP.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /ball_norm /= (double_var eps).
(* Goal: Rlt (@norm K V (@minus (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) u v) (@plus (NormedModule.AbelianGroup K V) x y))) (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) *)
apply Rle_lt_trans with (2 := Rplus_lt_compat _ _ _ _ Hu Hv).
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) u v) (@plus (NormedModule.AbelianGroup K V) x y))) (Rplus (@norm K V (@minus (NormedModule.AbelianGroup K V) u x)) (@norm K V (@minus (NormedModule.AbelianGroup K V) v y))) *)
apply Rle_trans with (2 := norm_triangle _ _).
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) u v) (@plus (NormedModule.AbelianGroup K V) x y))) (@norm K V (@plus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) u x) (@minus (NormedModule.AbelianGroup K V) v y))) *)
apply Req_le, f_equal.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite /minus /= opp_plus -2!plus_assoc.
(* Goal: @eq (Ring.sort T) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@coeff_mat (Ring.sort T) (S m) l (@zero (Ring.AbelianGroup T)) (@mk_matrix (Ring.sort T) (S m) l (fun i j : nat => @sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B i l0) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l0 j)) (Init.Nat.pred k))) m' l')) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
apply f_equal.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite 2!plus_assoc.
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@mult T (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m (S k) (@zero (Ring.AbelianGroup T)) B l1 k')) (Init.Nat.pred m)) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) (@mult T (@coeff_mat (Ring.sort T) n (S k) (@zero (Ring.AbelianGroup T)) (@Mmult n m (S k) A B) n' k') (@coeff_mat (Ring.sort T) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) *)
apply f_equal2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by apply plus_comm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by [].
Qed.

Lemma filterlim_scal (k : K) (x : V) :
  filterlim (fun z => scal (fst z) (snd z)) (filter_prod (locally k) (locally x)) (locally (scal k x)).
Proof.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply filterlim_locally => /= eps.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  eapply filter_imp.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => /= u Hu.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (double_var eps).
  apply ball_triangle with (scal (fst u) x).
  apply norm_compat1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -scal_minus_distr_r.
  eapply Rle_lt_trans.
(* Goal: Rle (norm (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (@abs K (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
  apply norm_scal.
  eapply Rle_lt_trans.
(* Goal: Rle (Rmult (IZR (Zpos (xO xH))) (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv)))) (Rmult (IZR (Zpos (xO xH))) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv)))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rmult_le_compat_l.
  by apply abs_ge_0.
  apply Rlt_le, Rlt_plus_1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  apply <- Rlt_div_r.
  2: apply Rle_lt_0_plus_1, norm_ge_0.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by eapply (proj1 Hu).
  apply norm_compat1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -scal_minus_distr_l.
  eapply Rle_lt_trans.
(* Goal: Rle (norm (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (@abs K (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K)))) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
  apply norm_scal.
  eapply Rle_lt_trans.
  apply Rmult_le_compat_r.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply norm_ge_0.
  replace (fst u) with (plus k (minus (fst u) k)).
  eapply Rle_trans.
  apply abs_triangle.
  apply Rplus_le_compat_l.
(* Goal: Rle (Rabs (Rplus x (Ropp (Rminus y (IZR (Zpos xH)))))) (IZR (Zpos (xO xH))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Rlt_le.
  instantiate (1 := 1).
  eapply (proj1 (proj2 Hu)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite plus_comm -plus_assoc plus_opp_l plus_zero_r.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rmult_comm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  apply <- Rlt_div_r.
  2: apply Rle_lt_0_plus_1, abs_ge_0.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply (proj2 (proj2 Hu)).

(* Goal: @locally T x (fun x : UniformSpace.sort T => and (D x) (E x)) *)
  repeat apply filter_and.

(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  assert (Hd : 0 < eps / 2 / (norm x + 1)).
    apply Rdiv_lt_0_compat.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply is_pos_div_2.
    apply Rle_lt_0_plus_1, norm_ge_0.
  eexists.
  apply (locally_ball_norm (V := AbsRing_NormedModule K) _ (mkposreal _ Hd)).
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
  apply filter_true.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].

  eexists.
  apply (locally_ball_norm (V := AbsRing_NormedModule K) _ (mkposreal _ Rlt_0_1)).
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
  apply filter_true.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].

(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  assert (Hd : 0 < eps / 2 / (abs k + 1)).
    apply Rdiv_lt_0_compat.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply is_pos_div_2.
    apply Rle_lt_0_plus_1, abs_ge_0.
  eexists.
(* Goal: @locally T x (fun _ : UniformSpace.sort T => True) *)
  apply filter_true.
  apply (locally_ball_norm _ (mkposreal _ Hd)).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
Qed.
Lemma filterlim_scal_r (k : K) (x : V) :
  filterlim (fun z : V => scal k z) (locally x) (locally (scal k x)).
Proof.
  eapply filterlim_comp_2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply filterlim_const.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply filterlim_id.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply filterlim_scal.
Qed.
Lemma filterlim_scal_l (k : K) (x : V) :
  filterlim (fun z => scal z x) (locally k) (locally (scal k x)).
Proof.
  eapply filterlim_comp_2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply filterlim_id.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply filterlim_const.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply filterlim_scal.
Qed.

Lemma filterlim_opp :
  forall x : V,
  filterlim opp (locally x) (locally (opp x)).
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite -scal_opp_one.
(* Goal: @filterlim (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@opp (NormedModule.AbelianGroup K V)) (@locally (NormedModule.UniformSpace K V) x) (@locally (NormedModule.UniformSpace K V) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (@opp (Ring.AbelianGroup (AbsRing.Ring K)) (@one (AbsRing.Ring K))) x)) *)
apply filterlim_ext with (2 := filterlim_scal_r _ _).
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: scal_opp_one.
Qed.

End NVS_continuity.

Lemma filterlim_mult {K : AbsRing} (x y : K) :
  filterlim (fun z => mult (fst z) (snd z)) (filter_prod (locally x) (locally y)) (locally (mult x y)).
Proof.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply @filterlim_scal.
Qed.

Lemma filterlim_locally_ball_norm :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall {K : AbsRing} {T} {U : NormedModule K} {F : (T -> Prop) -> Prop} {FF : Filter F} (f : T -> U) (y : U),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F (locally y) <-> forall eps : posreal, F (fun x => ball_norm y eps (f x)).
Proof.
intros K T U F FF f y.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros Cf eps.
  apply (Cf (fun x => ball_norm y eps x)).
(* Goal: @locally (NormedModule.UniformSpace K V) x (ball_norm x (pos eps)) *)
  apply locally_le_locally_norm.
(* Goal: locally_norm x (ball_norm x (pos eps)) *)
  apply locally_norm_ball_norm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros Cf.
  apply (filterlim_filter_le_2 _ (locally_norm_le_locally y)).
  intros P [eps He].
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
  apply: filter_imp (Cf eps).
  intros t.
(* Goal: not (P y) *)
(* Goal: Rlt d (Rmin (IZR (Zpos xH)) (pos eps)) *)
(* Goal: @sig posreal (fun d : posreal => forall (y : UniformSpace.sort T) (_ : @ball T x (pos d) y), not (P y)) *)
  apply He.
Qed.

(** ** Complete Normed Modules *)

Module CompleteNormedModule.

Section ClassDef.

Variable K : AbsRing.

Record class_of (T : Type) := Class {
  base : NormedModule.class_of K T ;
  mixin : CompleteSpace.mixin_of (UniformSpace.Pack T base T)
}.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base : class_of >-> NormedModule.class_of.
Definition base2 T (cT : class_of T) : CompleteSpace.class_of T :=
  CompleteSpace.Class _ (base T cT) (mixin T cT).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion base2 : class_of >-> CompleteSpace.class_of.

Structure type := Pack { sort; _ : class_of sort ; _ : Type }.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Local Coercion sort : type >-> Sortclass.

Variable cT : type.

Definition class := let: Pack _ c _ := cT return class_of cT in c.

Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of xT).

Definition AbelianGroup := AbelianGroup.Pack cT xclass xT.
Definition ModuleSpace := ModuleSpace.Pack _ cT xclass xT.
Definition NormedModuleAux := NormedModuleAux.Pack _ cT xclass xT.
Definition NormedModule := NormedModule.Pack _ cT xclass xT.
Definition UniformSpace := UniformSpace.Pack cT xclass xT.
Definition CompleteSpace := CompleteSpace.Pack cT xclass xT.

End ClassDef.

Module Exports.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base : class_of >-> NormedModule.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion mixin : class_of >-> CompleteSpace.mixin_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion base2 : class_of >-> CompleteSpace.class_of.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion sort : type >-> Sortclass.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion AbelianGroup : type >-> AbelianGroup.type.
Canonical AbelianGroup.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion ModuleSpace : type >-> ModuleSpace.type.
Canonical ModuleSpace.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion NormedModuleAux : type >-> NormedModuleAux.type.
Canonical NormedModuleAux.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion NormedModule : type >-> NormedModule.type.
Canonical NormedModule.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion UniformSpace : type >-> UniformSpace.type.
Canonical UniformSpace.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Coercion CompleteSpace : type >-> CompleteSpace.type.
Canonical CompleteSpace.
Notation CompleteNormedModule := type.

End Exports.

End CompleteNormedModule.

Export CompleteNormedModule.Exports.

Section CompleteNormedModule1.

Context {K : AbsRing} {V : CompleteNormedModule K}.

Lemma iota_unique :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P : V -> Prop) (x : V),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall y, P y -> y = x) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  P x ->
  iota P = x.
Proof.
(* Goal: forall (P : forall _ : CompleteNormedModule.sort K V, Prop) (x : CompleteNormedModule.sort K V) (_ : forall (y : CompleteNormedModule.sort K V) (_ : P y), @eq (CompleteNormedModule.sort K V) y x) (_ : P x), @eq (CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V)) (@iota (CompleteNormedModule.CompleteSpace K V) P) x *)
intros P x HP Px.
(* Goal: @eq (CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V)) (@iota (CompleteNormedModule.CompleteSpace K V) P) x *)
apply eq_close.
(* Goal: @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
intros eps.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: iota_correct_weak Px eps.
(* Goal: forall (x y : CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V)) (_ : P x) (_ : P y), @close (CompleteSpace.UniformSpace (CompleteNormedModule.CompleteSpace K V)) x y *)
intros x' y Px' Py eps.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite (HP _ Py) -(HP _ Px').
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
apply ball_center.
Qed.

Lemma iota_correct :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall P : V -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (exists! x : V, P x) ->
  P (iota P).
Proof.
(* Goal: forall (P : forall _ : CompleteNormedModule.sort K V, Prop) (_ : @ex (CompleteNormedModule.sort K V) (@unique (CompleteNormedModule.sort K V) (fun x : CompleteNormedModule.sort K V => P x))), P (@iota (CompleteNormedModule.CompleteSpace K V) P) *)
intros P [x [Px HP]].
(* Goal: P (@iota (CompleteNormedModule.CompleteSpace K V) P) *)
rewrite (iota_unique _ x) ; try exact Px.
(* Goal: forall (y : CompleteNormedModule.sort K V) (_ : P y), @eq (CompleteNormedModule.sort K V) y x *)
intros y Py.
(* Goal: @eq (CompleteNormedModule.sort K V) y x *)
now apply sym_eq, HP.
Qed.

Lemma iota_is_filter_lim {F} {FF : ProperFilter' F} (l : V) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  is_filter_lim F l ->
  iota (is_filter_lim F) = l.
Proof.
(* Goal: forall _ : @is_filter_lim (CompleteNormedModule.UniformSpace K V) F l, @eq (CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V)) (@iota (CompleteNormedModule.CompleteSpace K V) (@is_filter_lim (CompleteNormedModule.UniformSpace K V) F)) l *)
intros Hl.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: iota_unique (Hl) => l' Hl'.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
exact: is_filter_lim_unique Hl' Hl.
Qed.

Context {T : Type}.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma iota_filterlim_locally {F} {FF : ProperFilter' F} (f : T -> V) l :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlim f F (locally l) ->
  iota (fun x => filterlim f F (locally x)) = l.
Proof.
(* Goal: forall _ : @filterlim T (CompleteNormedModule.sort K V) f F (@locally (CompleteNormedModule.UniformSpace K V) l), @eq (CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V)) (@iota (CompleteNormedModule.CompleteSpace K V) (fun x : CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V) => @filterlim T (CompleteNormedModule.sort K V) f F (@locally (CompleteSpace.UniformSpace (CompleteNormedModule.CompleteSpace K V)) x))) l *)
apply iota_is_filter_lim.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma iota_filterlimi_locally {F} {FF : ProperFilter' F} (f : T -> V -> Prop) l :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  F (fun x => forall y1 y2, f x y1 -> f x y2 -> y1 = y2) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filterlimi f F (locally l) ->
  iota (fun x => filterlimi f F (locally x)) = l.
Proof.
(* Goal: forall (_ : F (fun x : T => forall (y1 y2 : CompleteNormedModule.sort K V) (_ : f x y1) (_ : f x y2), @eq (CompleteNormedModule.sort K V) y1 y2)) (_ : @filterlimi T (CompleteNormedModule.sort K V) f F (@locally (CompleteNormedModule.UniformSpace K V) l)), @eq (CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V)) (@iota (CompleteNormedModule.CompleteSpace K V) (fun x : CompleteSpace.sort (CompleteNormedModule.CompleteSpace K V) => @filterlimi T (CompleteNormedModule.sort K V) f F (@locally (CompleteSpace.UniformSpace (CompleteNormedModule.CompleteSpace K V)) x))) l *)
intros Hf Hl.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: iota_unique (Hl) => l' Hl'.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
exact: filterlimi_locally_unique Hf Hl' Hl.
Qed.

End CompleteNormedModule1.

(** * Extended Types *)

(** ** Pairs *)

Section prod_AbelianGroup.

Context {U V : AbelianGroup}.

Definition prod_plus (x y : U * V) :=
  (plus (fst x) (fst y), plus (snd x) (snd y)).

Definition prod_opp (x : U * V) :=
  (opp (fst x), opp (snd x)).

Definition prod_zero : U * V := (zero, zero).

Lemma prod_plus_comm :
  forall x y : U * V,
  prod_plus x y = prod_plus y x.
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
intros x y.
(* Goal: @eq (prod (AbelianGroup.sort U) (AbelianGroup.sort V)) (prod_plus x y) (prod_plus y x) *)
apply (f_equal2 pair) ; apply plus_comm.
Qed.

Lemma prod_plus_assoc :
  forall x y z : U * V,
  prod_plus x (prod_plus y z) = prod_plus (prod_plus x y) z.
Proof.
(* Goal: forall x y z : prod (AbelianGroup.sort U) (AbelianGroup.sort V), @eq (prod (AbelianGroup.sort U) (AbelianGroup.sort V)) (prod_plus x (prod_plus y z)) (prod_plus (prod_plus x y) z) *)
intros x y z.
(* Goal: @eq (prod (AbelianGroup.sort U) (AbelianGroup.sort V)) (prod_plus x (prod_plus y z)) (prod_plus (prod_plus x y) z) *)
apply (f_equal2 pair) ; apply plus_assoc.
Qed.

Lemma prod_plus_zero_r :
  forall x : U * V,
  prod_plus x prod_zero = x.
Proof.
(* Goal: forall u : prod (ModuleSpace.sort K U) (ModuleSpace.sort K V), @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal (@one K) u) u *)
intros [u v].
(* Goal: @eq (AbelianGroup.sort G) (plus x zero) x *)
apply (f_equal2 pair) ; apply plus_zero_r.
Qed.

Lemma prod_plus_opp_r :
  forall x : U * V,
  prod_plus x (prod_opp x) = prod_zero.
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: @eq (AbelianGroup.sort G) (minus x x) zero *)
apply (f_equal2 pair) ; apply plus_opp_r.
Qed.

End prod_AbelianGroup.

Definition prod_AbelianGroup_mixin (U V : AbelianGroup) :=
  AbelianGroup.Mixin (U * V) _ _ _ prod_plus_comm prod_plus_assoc prod_plus_zero_r prod_plus_opp_r.

Canonical prod_AbelianGroup (U V : AbelianGroup) :=
  AbelianGroup.Pack (U * V) (prod_AbelianGroup_mixin U V) (U * V).

Section prod_UniformSpace.

Context {U V : UniformSpace}.

Definition prod_ball (x : U * V) (eps : R) (y : U * V) :=
  ball (fst x) eps (fst y) /\ ball (snd x) eps (snd y).

Lemma prod_ball_center :
  forall (x : U * V) (eps : posreal),
  prod_ball x eps x.
Proof.
(* Goal: forall (x : prod (UniformSpace.sort U) (UniformSpace.sort V)) (eps : posreal), prod_ball x (pos eps) x *)
intros x eps.
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
split ; apply ball_center.
Qed.

Lemma prod_ball_sym :
  forall (x y : U * V) (eps : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  prod_ball x eps y -> prod_ball y eps x.
Proof.
(* Goal: forall (x y : prod (UniformSpace.sort U) (UniformSpace.sort V)) (eps : R) (_ : prod_ball x eps y), prod_ball y eps x *)
intros x y eps [H1 H2].
(* Goal: @ball (CompleteSpace.UniformSpace U) (f v y) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (h v) *)
(* Goal: forall (x : UniformSpace.sort (CompleteSpace.UniformSpace U)) (_ : @filterlim T1 (CompleteSpace.sort U) h F1 (@locally (CompleteSpace.UniformSpace U) x)), @ex (CompleteSpace.sort U) (fun l : CompleteSpace.sort U => @filterlim T1 (UniformSpace.sort (CompleteSpace.UniformSpace U)) h F1 (@locally (CompleteSpace.UniformSpace U) l)) *)
split ; now apply ball_sym.
Qed.

Lemma prod_ball_triangle :
  forall (x y z : U * V) (e1 e2 : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  prod_ball x e1 y -> prod_ball y e2 z ->
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  prod_ball x (e1 + e2) z.
Proof.
(* Goal: forall (x y z : prod (UniformSpace.sort U) (UniformSpace.sort V)) (e1 e2 : R) (_ : prod_ball x e1 y) (_ : prod_ball y e2 z), prod_ball x (Rplus e1 e2) z *)
intros x y z e1 e2 [H1 H2] [H3 H4].
(* Goal: prod_ball x (Rplus e1 e2) z *)
split ; eapply ball_triangle ; eassumption.
Qed.


End prod_UniformSpace.

Definition prod_UniformSpace_mixin (U V : UniformSpace) :=
  UniformSpace.Mixin (U * V) _ prod_ball_center prod_ball_sym prod_ball_triangle.

Canonical prod_UniformSpace (U V : UniformSpace) :=
  UniformSpace.Pack (U * V) (prod_UniformSpace_mixin U V) (U * V).

Section prod_ModuleSpace.

Context {K : Ring} {U V : ModuleSpace K}.

Definition prod_scal (x : K) (u : U * V) :=
  (scal x (fst u), scal x (snd u)).

Lemma prod_scal_assoc :
  forall (x y : K) (u : U * V),
  prod_scal x (prod_scal y u) = prod_scal (mult x y) u.
Proof.
(* Goal: forall (x y : Ring.sort K) (u : prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)), @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal (@plus (Ring.AbelianGroup K) x y) u) (@prod_plus (ModuleSpace.AbelianGroup K U) (ModuleSpace.AbelianGroup K V) (prod_scal x u) (prod_scal y u)) *)
intros x y u.
(* Goal: @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal x (prod_scal y u)) (prod_scal (@mult K x y) u) *)
apply (f_equal2 pair) ; apply scal_assoc.
Qed.

Lemma prod_scal_one :
  forall u : U * V,
  prod_scal one u = u.
Proof.
(* Goal: forall u : prod (ModuleSpace.sort K U) (ModuleSpace.sort K V), @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal (@one K) u) u *)
intros [u v].
(* Goal: @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal (@one K) (@pair (ModuleSpace.sort K U) (ModuleSpace.sort K V) u v)) (@pair (ModuleSpace.sort K U) (ModuleSpace.sort K V) u v) *)
apply (f_equal2 pair) ; apply scal_one.
Qed.

Lemma prod_scal_distr_l :
  forall (x : K) (u v : U * V),
  prod_scal x (prod_plus u v) = prod_plus (prod_scal x u) (prod_scal x v).
Proof.
(* Goal: forall (x : Ring.sort K) (u v : prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)), @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal x (@prod_plus (ModuleSpace.AbelianGroup K U) (ModuleSpace.AbelianGroup K V) u v)) (@prod_plus (ModuleSpace.AbelianGroup K U) (ModuleSpace.AbelianGroup K V) (prod_scal x u) (prod_scal x v)) *)
intros x u v.
(* Goal: @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal x (@prod_plus (ModuleSpace.AbelianGroup K U) (ModuleSpace.AbelianGroup K V) u v)) (@prod_plus (ModuleSpace.AbelianGroup K U) (ModuleSpace.AbelianGroup K V) (prod_scal x u) (prod_scal x v)) *)
apply (f_equal2 pair) ; apply scal_distr_l.
Qed.

Lemma prod_scal_distr_r :
  forall (x y : K) (u : U * V),
  prod_scal (plus x y) u = prod_plus (prod_scal x u) (prod_scal y u).
Proof.
(* Goal: forall (x y : Ring.sort K) (u : prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)), @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal (@plus (Ring.AbelianGroup K) x y) u) (@prod_plus (ModuleSpace.AbelianGroup K U) (ModuleSpace.AbelianGroup K V) (prod_scal x u) (prod_scal y u)) *)
intros x y u.
(* Goal: @eq (prod (ModuleSpace.sort K U) (ModuleSpace.sort K V)) (prod_scal (@plus (Ring.AbelianGroup K) x y) u) (@prod_plus (ModuleSpace.AbelianGroup K U) (ModuleSpace.AbelianGroup K V) (prod_scal x u) (prod_scal y u)) *)
apply (f_equal2 pair) ; apply scal_distr_r.
Qed.

End prod_ModuleSpace.

Definition prod_ModuleSpace_mixin (K : Ring) (U V : ModuleSpace K) :=
  ModuleSpace.Mixin K _ _ (@prod_scal_assoc K U V) prod_scal_one prod_scal_distr_l prod_scal_distr_r.

Canonical prod_ModuleSpace (K : Ring) (U V : ModuleSpace K) :=
  ModuleSpace.Pack K (U * V) (ModuleSpace.Class _ _ _ (prod_ModuleSpace_mixin K U V)) (U * V).

Canonical prod_NormedModuleAux (K : AbsRing) (U V : NormedModuleAux K) :=
  NormedModuleAux.Pack K (U * V) (NormedModuleAux.Class _ _ (ModuleSpace.class K _) (UniformSpace.class (prod_UniformSpace U V))) (U * V).

Lemma sqrt_plus_sqr :
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  forall x y : R, Rmax (Rabs x) (Rabs y) <= sqrt (x ^ 2 + y ^ 2) <= sqrt 2 * Rmax (Rabs x) (Rabs y).
Proof.
(* Goal: forall x y : R, and (Rle (Rmax (Rabs x) (Rabs y)) (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O)))))) (Rle (sqrt (Rplus (pow x (S (S O))) (pow y (S (S O))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs x) (Rabs y)))) *)
intros x y.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- rewrite -!sqrt_Rsqr_abs.
  apply Rmax_case ; apply sqrt_le_1_alt, Rminus_le_0 ;
(* Goal: Rle (IZR Z0) (pow (Rminus (Rmult (@norm K U xu) (@norm K V yv)) (Rmult (@norm K V xv) (@norm K U yu))) (S (S O))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K U yu) (S (S O)))) (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K V yv) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K U yu) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K V yv) (S (S O))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  rewrite /Rsqr /= ; ring_simplify ; by apply pow2_ge_0.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply Rmax_case_strong ; intros H0 ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -!sqrt_Rsqr_abs ;
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -?sqrt_mult ;
  try (by apply Rle_0_sqr) ;
  try (by apply Rlt_le, Rlt_0_2) ;
  apply sqrt_le_1_alt ; simpl ; [ rewrite Rplus_comm | ] ;
  rewrite /Rsqr ; apply Rle_minus_r ; ring_simplify ;
  apply Rsqr_le_abs_1 in H0 ; by rewrite /pow !Rmult_1_r.
Qed.

Section prod_NormedModule.

Context {K : AbsRing} {U V : NormedModule K}.

Definition prod_norm (x : U * V) :=
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  sqrt (norm (fst x) ^ 2 + norm (snd x) ^ 2).

Lemma prod_norm_triangle :
  forall x y : U * V,
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  prod_norm (plus x y) <= prod_norm x + prod_norm y.
Proof.
(* Goal: forall x y : prod (NormedModule.sort K U) (NormedModule.sort K V), Rle (prod_norm (@plus (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V)) x y)) (Rplus (prod_norm x) (prod_norm y)) *)
intros [xu xv] [yu yv].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /prod_norm /= !Rmult_1_r.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
apply Rle_trans with (sqrt (Rsqr (norm xu + norm yu) + Rsqr (norm xv + norm yv))).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply sqrt_le_1_alt.
(* Goal: Rle (Rplus (Rabs (Rminus z t)) (Rabs t)) (Rplus (pos d2) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
  apply Rplus_le_compat.
(* Goal: Rle (Rmult (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rsqr_le_abs_1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -> 2!Rabs_pos_eq.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
  apply: norm_triangle.
(* Goal: Rle (IZR Z0) (Rplus (@norm K V xv) (@norm K V yv)) *)
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply norm_ge_0.
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply norm_ge_0.
(* Goal: Rle (Rmult (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rsqr_le_abs_1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -> 2!Rabs_pos_eq.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
  apply: norm_triangle.
(* Goal: Rle (IZR Z0) (Rplus (@norm K V xv) (@norm K V yv)) *)
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply norm_ge_0.
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply norm_ge_0.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply Rsqr_incr_0_var.
(* Goal: Rle (Rsqr (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv)))) (Rsqr (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv)))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rminus_le_0.
(* Goal: Rle (IZR Z0) (Rminus (Rsqr (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv)))))) (Rsqr (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  unfold Rsqr ; simpl ; ring_simplify.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /pow ?Rmult_1_r.
(* Goal: Rle (IZR Z0) (Rminus (Rsqr (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv)))))) (Rsqr (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  rewrite ?sqrt_sqrt ; ring_simplify.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  replace (-2 * norm xu * norm yu - 2 * norm xv * norm yv)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    with (-(2 * (norm xu * norm yu + norm xv * norm yv))) by ring.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite Rmult_assoc -sqrt_mult.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rplus_comm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  apply -> Rminus_le_0.
(* Goal: Rle (Rmult (IZR (Zpos (xO xH))) (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv)))) (Rmult (IZR (Zpos (xO xH))) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv)))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (IZR (Zpos (xO xH))) *)
(* Goal: Rle (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv))) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rlt_le, Rlt_0_2.
(* Goal: Rle (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv))) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rsqr_incr_0_var.
(* Goal: Rle (Rsqr (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv)))) (Rsqr (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv)))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rminus_le_0.
(* Goal: Rle (IZR Z0) (Rminus (Rsqr (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv)))))) (Rsqr (Rplus (Rmult (@norm K U xu) (@norm K U yu)) (Rmult (@norm K V xv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  rewrite /Rsqr ?sqrt_sqrt ; ring_simplify.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  replace (norm xu ^ 2 * norm yv ^ 2 - 2 * norm xu * norm xv * norm yu * norm yv + norm xv ^ 2 * norm yu ^ 2)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    with ((norm xu * norm yv - norm xv * norm yu) ^ 2) by ring.
(* Goal: Rle (IZR Z0) (pow (Rminus (Rmult (@norm K U xu) (@norm K V yv)) (Rmult (@norm K V xv) (@norm K U yu))) (S (S O))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K U yu) (S (S O)))) (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K V yv) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K U yu) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K V yv) (S (S O))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply pow2_ge_0.
(* Goal: Rle (IZR Z0) (pow (Rminus (Rmult (@norm K U xu) (@norm K V yv)) (Rmult (@norm K V xv) (@norm K U yu))) (S (S O))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K U yu) (S (S O)))) (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K V yv) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K U yu) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K V yv) (S (S O))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  repeat apply Rplus_le_le_0_compat ; apply Rmult_le_pos ; apply pow2_ge_0.
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply sqrt_pos.
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply Rle_0_sqr.
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply Rle_0_sqr.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  replace (norm xu ^ 2 + 2 * norm xu * norm yu + norm yu ^ 2 + norm xv ^ 2 + 2 * norm xv * norm yv + norm yv ^ 2)
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
    with ((norm xu + norm yu) ^ 2 + (norm xv + norm yv) ^ 2) by ring.
(* Goal: Rle (IZR Z0) (pow (Rminus (Rmult (@norm K U xu) (@norm K V yv)) (Rmult (@norm K V xv) (@norm K U yu))) (S (S O))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K U yu) (S (S O)))) (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K V yv) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K U yu) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K V yv) (S (S O))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply pow2_ge_0.
(* Goal: Rle (IZR Z0) (pow (Rminus (Rmult (@norm K U xu) (@norm K V yv)) (Rmult (@norm K V xv) (@norm K U yu))) (S (S O))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K U yu) (S (S O)))) (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K V yv) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K U yu) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K V yv) (S (S O))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply pow2_ge_0.
(* Goal: Rle (IZR Z0) (pow (Rminus (Rmult (@norm K U xu) (@norm K V yv)) (Rmult (@norm K V xv) (@norm K U yu))) (S (S O))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K U yu) (S (S O)))) (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K V yv) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K U yu) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K V yv) (S (S O))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply pow2_ge_0.
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
  apply Rplus_le_le_0_compat ; apply sqrt_pos.
Qed.

Lemma prod_norm_scal :
  forall (l : K) (x : U * V),
  prod_norm (scal l x) <= abs l * prod_norm x.
Proof.
intros l [xu xv].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite /prod_norm /= -(sqrt_Rsqr (abs l)).
2: apply abs_ge_0.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite !Rmult_1_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite -sqrt_mult.
2: apply Rle_0_sqr.
(* Goal: Rle (sqrt (Rplus (Rmult (@norm K U (@plus (NormedModule.AbelianGroup K U) xu yu)) (@norm K U (@plus (NormedModule.AbelianGroup K U) xu yu))) (Rmult (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv))))) (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
apply sqrt_le_1_alt.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Rmult_plus_distr_l.
unfold Rsqr.
(* Goal: Rle (Rplus (Rabs (Rminus z t)) (Rabs t)) (Rplus (pos d2) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rplus_le_compat.
(* Goal: @eq R (Rplus (norm x) (norm x)) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
replace (abs l * abs l * (norm xu * norm xu)) with ((abs l * norm xu) * (abs l * norm xu)) by ring.
(* Goal: Rle (Rmult (Rabs (Rplus (Rminus z t) t)) (Rabs (Rminus v y))) (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
apply norm_ge_0.
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
apply norm_ge_0.
exact (norm_scal l xu).
exact (norm_scal l xu).
(* Goal: @eq R (Rplus (norm x) (norm x)) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
replace (abs l * abs l * (norm xv * norm xv)) with ((abs l * norm xv) * (abs l * norm xv)) by ring.
(* Goal: Rle (Rmult (Rabs (Rplus (Rminus z t) t)) (Rabs (Rminus v y))) (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
apply norm_ge_0.
(* Goal: Rle (IZR Z0) (@norm K V (@plus (NormedModule.AbelianGroup K V) xv yv)) *)
(* Goal: Rle (sqrt (Rplus (Rsqr (Rplus (@norm K U xu) (@norm K U yu))) (Rsqr (Rplus (@norm K V xv) (@norm K V yv))))) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
apply norm_ge_0.
exact (norm_scal l xv).
exact (norm_scal l xv).
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
apply Rplus_le_le_0_compat ; apply Rle_0_sqr.
Qed.

Lemma prod_norm_compat1 :
  forall (x y : U * V) (eps : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  prod_norm (minus y x) < eps -> ball x eps y.
Proof.
(* Goal: forall (x y : prod (NormedModule.sort K U) (NormedModule.sort K V)) (eps : R) (_ : Rlt (prod_norm (@minus (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V)) y x)) eps), @ball (prod_UniformSpace (NormedModule.UniformSpace K U) (NormedModule.UniformSpace K V)) x eps y *)
intros [xu xv] [yu yv] eps H.
(* Goal: @ball (prod_UniformSpace (NormedModule.UniformSpace K U) (NormedModule.UniformSpace K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) eps (@pair (NormedModule.sort K U) (NormedModule.sort K V) yu yv) *)
generalize (Rle_lt_trans _ _ _ (proj1 (sqrt_plus_sqr _ _)) H).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite -> !Rabs_pos_eq by apply norm_ge_0.
(* Goal: forall _ : Rlt (Rmax (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) (@minus (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) yu yv) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv)))) (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) (@minus (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) yu yv) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))))) eps, @ball (prod_UniformSpace (NormedModule.UniformSpace K U) (NormedModule.UniformSpace K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) eps (@pair (NormedModule.sort K U) (NormedModule.sort K V) yu yv) *)
intros H'.
split ;
  apply norm_compat1 ;
  apply Rle_lt_trans with (2 := H').
(* Goal: Rle MP (Rmax MP MQ) *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply Rmax_l.
(* Goal: Rle MQ (Rmax MP MQ) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply Rmax_r.
Qed.

Definition prod_norm_factor :=
  sqrt 2 * Rmax (@norm_factor K U) (@norm_factor K V).

Lemma prod_norm_compat2 :
  forall (x y : U * V) (eps : posreal),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ball x eps y ->
  prod_norm (minus y x) < prod_norm_factor * eps.
Proof.
(* Goal: forall (x y : prod (NormedModule.sort K U) (NormedModule.sort K V)) (eps : posreal) (_ : @ball (prod_UniformSpace (NormedModule.UniformSpace K U) (NormedModule.UniformSpace K V)) x (pos eps) y), Rlt (prod_norm (@minus (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V)) y x)) (Rmult prod_norm_factor (pos eps)) *)
intros [xu xv] [yu yv] eps [Bu Bv].
(* Goal: Rlt (prod_norm (@minus (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) yu yv) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (Rmult prod_norm_factor (pos eps)) *)
apply Rle_lt_trans with (1 := proj2 (sqrt_plus_sqr _ _)).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
simpl.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Rmult_assoc.
(* Goal: Rlt (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs (@norm K U (@plus (NormedModule.AbelianGroup K U) yu (@opp (NormedModule.AbelianGroup K U) xu)))) (Rabs (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv)))))) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmult (Rmax (@norm_factor K U) (@norm_factor K V)) (pos eps))) *)
apply Rmult_lt_compat_l.
(* Goal: Rlt (IZR Z0) (sqrt (IZR (Zpos (xO xH)))) *)
(* Goal: Rlt (Rmax (Rabs (@norm K U (@plus (NormedModule.AbelianGroup K U) yu (@opp (NormedModule.AbelianGroup K U) xu)))) (Rabs (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv))))) (Rmult (Rmax (@norm_factor K U) (@norm_factor K V)) (pos eps)) *)
apply sqrt_lt_R0.
(* Goal: Rlt (IZR Z0) (IZR (Zpos (xO xH))) *)
(* Goal: Rlt (Rmax (Rabs (@norm K U (@plus (NormedModule.AbelianGroup K U) yu (@opp (NormedModule.AbelianGroup K U) xu)))) (Rabs (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv))))) (Rmult (Rmax (@norm_factor K U) (@norm_factor K V)) (pos eps)) *)
apply Rlt_0_2.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
rewrite -> !Rabs_pos_eq by apply norm_ge_0.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Rmax_mult.
(* Goal: Rlt (Rmax (@norm K U (@plus (NormedModule.AbelianGroup K U) yu (@opp (NormedModule.AbelianGroup K U) xu))) (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv)))) (Rmax (Rmult (@norm_factor K U) (pos eps)) (Rmult (@norm_factor K V) (pos eps))) *)
(* Goal: Rle (IZR Z0) (pos eps) *)
apply Rmax_case.
(* Goal: Rlt (@norm K U (@plus (NormedModule.AbelianGroup K U) yu (@opp (NormedModule.AbelianGroup K U) xu))) (Rmax (Rmult (@norm_factor K U) (pos eps)) (Rmult (@norm_factor K V) (pos eps))) *)
(* Goal: Rlt (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv))) (Rmax (Rmult (@norm_factor K U) (pos eps)) (Rmult (@norm_factor K V) (pos eps))) *)
(* Goal: Rle (IZR Z0) (pos eps) *)
apply Rlt_le_trans with (2 := Rmax_l _ _).
(* Goal: Rlt (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv))) (Rmult (@norm_factor K V) (pos eps)) *)
(* Goal: Rle (IZR Z0) (pos eps) *)
now apply norm_compat2.
(* Goal: Rlt (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv))) (Rmax (Rmult (@norm_factor K U) (pos eps)) (Rmult (@norm_factor K V) (pos eps))) *)
(* Goal: Rle (IZR Z0) (pos eps) *)
apply Rlt_le_trans with (2 := Rmax_r _ _).
(* Goal: Rlt (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv))) (Rmult (@norm_factor K V) (pos eps)) *)
(* Goal: Rle (IZR Z0) (pos eps) *)
now apply norm_compat2.
(* Goal: Rle (Rabs (Rplus x (Ropp (Rminus y (IZR (Zpos xH)))))) (IZR (Zpos (xO xH))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
apply Rlt_le.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
apply cond_pos.
Qed.

Lemma prod_norm_eq_zero :
  forall x : U * V,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  prod_norm x = 0 -> x = zero.
Proof.
(* Goal: forall (x : prod (NormedModule.sort K U) (NormedModule.sort K V)) (_ : @eq R (prod_norm x) (IZR Z0)), @eq (prod (NormedModule.sort K U) (NormedModule.sort K V)) x (@zero (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V))) *)
intros [xu xv] H.
(* Goal: @eq (prod (NormedModule.sort K U) (NormedModule.sort K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) (@zero (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V))) *)
apply sqrt_eq_0 in H.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite !(pow_Rsqr _ 1) !pow_1 in H.
(* Goal: @eq (prod (NormedModule.sort K U) (NormedModule.sort K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) (@zero (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O))) (pow (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O)))) *)
apply Rplus_sqr_eq_0 in H.
(* Goal: @eq (prod (NormedModule.sort K U) (NormedModule.sort K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) (@zero (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O))) (pow (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O)))) *)
destruct H as [H1 H2].
(* Goal: @eq (prod (NormedModule.sort K U) (NormedModule.sort K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) (@zero (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O))) (pow (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O)))) *)
apply norm_eq_zero in H1.
(* Goal: @eq (prod (NormedModule.sort K U) (NormedModule.sort K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) (@zero (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O))) (pow (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O)))) *)
apply norm_eq_zero in H2.
(* Goal: @eq (prod (NormedModule.sort K U) (NormedModule.sort K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv) (@zero (prod_AbelianGroup (NormedModule.AbelianGroup K U) (NormedModule.AbelianGroup K V))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O))) (pow (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) xu xv))) (S (S O)))) *)
simpl in H1, H2.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite H1 H2.
(* Goal: Rle (IZR Z0) (pow (Rminus (Rmult (@norm K U xu) (@norm K V yv)) (Rmult (@norm K V xv) (@norm K U yu))) (S (S O))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K U yu) (S (S O)))) (Rmult (pow (@norm K U xu) (S (S O))) (pow (@norm K V yv) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K U yu) (S (S O))))) (Rmult (pow (@norm K V xv) (S (S O))) (pow (@norm K V yv) (S (S O))))) *)
(* Goal: Rle (IZR Z0) (sqrt (Rmult (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))) *)
(* Goal: Rle (IZR Z0) (Rplus (Rplus (Rplus (Rplus (Rplus (pow (@norm K U xu) (S (S O))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K U xu)) (@norm K U yu))) (pow (@norm K U yu) (S (S O)))) (pow (@norm K V xv) (S (S O)))) (Rmult (Rmult (IZR (Zpos (xO xH))) (@norm K V xv)) (@norm K V yv))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U yu) (S (S O))) (pow (@norm K V yv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (pow (@norm K U xu) (S (S O))) (pow (@norm K V xv) (S (S O)))) *)
(* Goal: Rle (IZR Z0) (Rplus (sqrt (Rplus (Rmult (@norm K U xu) (@norm K U xu)) (Rmult (@norm K V xv) (@norm K V xv)))) (sqrt (Rplus (Rmult (@norm K U yu) (@norm K U yu)) (Rmult (@norm K V yv) (@norm K V yv))))) *)
apply Rplus_le_le_0_compat ; apply pow2_ge_0.
Qed.

End prod_NormedModule.

Definition prod_NormedModule_mixin (K : AbsRing) (U V : NormedModule K) :=
  NormedModule.Mixin K _ (@prod_norm K U V) prod_norm_factor prod_norm_triangle
  prod_norm_scal prod_norm_compat1 prod_norm_compat2 prod_norm_eq_zero.

Canonical prod_NormedModule (K : AbsRing) (U V : NormedModule K) :=
  NormedModule.Pack K (U * V) (NormedModule.Class K (U * V) _ (prod_NormedModule_mixin K U V)) (U * V).

Lemma norm_prod {K : AbsRing}
  {U : NormedModule K} {V : NormedModule K}
  (x : U) (y : V) :
  Rmax (norm x) (norm y) <= norm (x,y) <= sqrt 2 * Rmax (norm x) (norm y).
Proof.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rabs_pos_eq (norm x)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rabs_pos_eq (norm y)).
(* Goal: and (Rle (Rmax (Rabs (@norm K U x)) (Rabs (@norm K V y))) (@norm K (prod_NormedModule K U V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) x y))) (Rle (@norm K (prod_NormedModule K U V) (@pair (NormedModule.sort K U) (NormedModule.sort K V) x y)) (Rmult (sqrt (IZR (Zpos (xO xH)))) (Rmax (Rabs (@norm K U x)) (Rabs (@norm K V y))))) *)
(* Goal: Rle (IZR Z0) (@norm K V y) *)
(* Goal: Rle (IZR Z0) (@norm K U x) *)
  apply sqrt_plus_sqr.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply norm_ge_0.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply norm_ge_0.
Qed.

(** ** Iterated Products *)

Fixpoint Tn (n : nat) (T : Type) : Type :=
  match n with
  | O => unit
  | S n => prod T (Tn n T)
  end.

Notation "[ x1 , .. , xn ]" := (pair x1 .. (pair xn tt) .. ).

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Fixpoint mk_Tn {T} (n : nat) (u : nat -> T) : Tn n T :=
  match n with
    | O => (tt : Tn O T)
    | S n => (u O, mk_Tn n (fun n => u (S n)))
  end.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Fixpoint coeff_Tn {T} {n : nat} (x0 : T) : (Tn n T) -> nat -> T :=
  match n with
  | O => fun (_ : Tn O T) (_ : nat) => x0
  | S n' => fun (v : Tn (S n') T) (i : nat) => match i with
           | O => fst v
           | S i => coeff_Tn x0 (snd v) i
           end
  end.
Lemma mk_Tn_bij {T} {n : nat} (x0 : T) (v : Tn n T) :
  mk_Tn n (coeff_Tn x0 v) = v.
Proof.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  induction n ; simpl.
(* Goal: @eq unit tt v *)
(* Goal: @eq (prod T (Tn n T)) (@pair T (Tn n T) (@fst T ((fix Tn (n : nat) (T : Type) {struct n} : Type := match n with | O => unit | S n0 => prod T (Tn n0 T) end) n T) v) (@mk_Tn T n (fun n0 : nat => @coeff_Tn T n x0 (@snd T ((fix Tn (n : nat) (T : Type) {struct n} : Type := match n with | O => unit | S n1 => prod T (Tn n1 T) end) n T) v) n0))) v *)
  now apply unit_ind.
(* Goal: Rle (Rplus (INR N) (IZR (Zpos xH))) (INR n) *)
  rewrite IHn ; by destruct v.
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma coeff_Tn_bij {T} {n : nat} (x0 : T) (u : nat -> T) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall i, (i < n)%nat -> coeff_Tn x0 (mk_Tn n u) i = u i.
Proof.
(* Goal: forall (i : nat) (_ : lt i n), @eq T (@coeff_Tn T n x0 (@mk_Tn T n u) i) (u i) *)
  revert u ; induction n => /= u i Hi.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply lt_n_O in Hi.
(* Goal: @eq T (u1 i) (u2 i) *)
  destruct i.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: @eq T (@coeff_Tn T n x0 (@mk_Tn T n (fun n : nat => u (S n))) i) (u (S i)) *)
  now apply (IHn (fun n => u (S n))), lt_S_n.
Qed.
Lemma coeff_Tn_ext {T} {n : nat} (x1 x2 : T) (v1 v2 : Tn n T) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  v1 = v2 <-> forall i, (i < n)%nat -> coeff_Tn x1 v1 i = coeff_Tn x2 v2 i.
Proof.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  + move => -> {v1}.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    induction n => i Hi.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply lt_n_O in Hi.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
    destruct i ; simpl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by [].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply IHn, lt_S_n.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  + induction n => H.
(* Goal: @eq unit tt v *)
(* Goal: @eq (prod T (Tn n T)) (@pair T (Tn n T) (@fst T ((fix Tn (n : nat) (T : Type) {struct n} : Type := match n with | O => unit | S n0 => prod T (Tn n0 T) end) n T) v) (@mk_Tn T n (fun n0 : nat => @coeff_Tn T n x0 (@snd T ((fix Tn (n : nat) (T : Type) {struct n} : Type := match n with | O => unit | S n1 => prod T (Tn n1 T) end) n T) v) n0))) v *)
    apply unit_ind ; move: (v1) ; now apply unit_ind.
(* Goal: @eq (Tn (S n) T) v1 v2 *)
    apply injective_projections.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply (H O), lt_O_Sn.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    apply IHn => i Hi.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply (H (S i)), lt_n_S.
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma mk_Tn_ext {T} (n : nat) (u1 u2 : nat -> T) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall i, (i < n)%nat -> (u1 i) = (u2 i))
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    <-> (mk_Tn n u1) = (mk_Tn n u2).
Proof.
(* Goal: forall _ : forall (k : nat) (_ : and (le n k) (le k m)), @eq (AbelianGroup.sort G) (a k) (b k), @eq (AbelianGroup.sort G) (sum_n_m a n m) (sum_n_m b n m) *)
  move: u1 u2 ; induction n ; simpl ; split ; intros.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply lt_n_O in H0.
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@mult T (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m (S k) (@zero (Ring.AbelianGroup T)) B l1 k')) (Init.Nat.pred m)) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) (@mult T (@coeff_mat (Ring.sort T) n (S k) (@zero (Ring.AbelianGroup T)) (@Mmult n m (S k) A B) n' k') (@coeff_mat (Ring.sort T) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) *)
  apply f_equal2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply H, lt_O_Sn.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply IHn => i Hi.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply H, lt_n_S.
(* Goal: @eq T (u1 i) (u2 i) *)
  destruct i.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply (f_equal (@fst _ _)) in H.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: i {H0} (lt_S_n _ _ H0).
(* Goal: forall (i : nat) (_ : lt i n), @eq T (u1 (S i)) (u2 (S i)) *)
  apply IHn.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply (f_equal (@snd _ _)) in H.
Qed.

(*
Global Instance AbelianGroup_Tn {T} :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  AbelianGroup T -> forall n, AbelianGroup (Tn n T) | 10.
Proof.
  intro GT.
  elim => /= [ | n IH].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  - apply Build_AbelianGroup with (fun _ _ => tt) (fun _ => tt) tt ; auto.
    by apply unit_ind.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  - by apply AbelianGroup_prod.
Defined.

Global Instance MetricBall_Tn :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall T, MetricBall T -> forall n, MetricBall (Tn n T) | 10.
Proof.
intros T MT n.
elim: n => [ | n MTn].
by apply Build_MetricBall with (fun _ _ _ => True).
by apply MetricBall_prod.
Defined.

Global Instance VectorSpace_mixin_Tn {T} {K} {FK : Ring K} :
  forall GT : AbelianGroup T,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  VectorSpace_mixin T K GT ->
  forall n, VectorSpace_mixin (Tn n T) K (AbelianGroup_Tn GT n) | 10.
Proof.
  intros GT VV.
  elim => [ | n VVn].
  apply Build_VectorSpace_mixin with (fun _ _ => tt) ; by apply unit_ind.
  by apply VectorSpace_mixin_prod.
Defined.

Global Instance VectorSpace_Tn {T} {K} {FK : Ring K} :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  VectorSpace T K -> forall n, VectorSpace (Tn n T) K | 10.
Proof.
  intros VV n.
  apply Build_VectorSpace with (AbelianGroup_Tn _ n).
  now apply VectorSpace_mixin_Tn, VV.
Defined.

Global Instance NormedVectorSpace_Tn {T} {K} {FK : AbsRing K} :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  NormedVectorSpace T K ->
  forall n, NormedVectorSpace (Tn n T) K | 10.
Proof.
  move => VT.
  elim => [ | n NVTn].
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
  - econstructor.
    apply Build_NormedVectorSpace_mixin with (fun _ => 0).
    move => _ _.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    rewrite Rplus_0_l ; by apply Rle_refl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    move => l _ ; rewrite Rmult_0_r ; by apply Rle_refl.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    easy.
    exists (mkposreal _ Rlt_0_1).
    intros x y eps _.
    rewrite Rmult_1_l.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
    apply cond_pos.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  - by apply NormedVectorSpace_prod.
Defined.
*)

(** *)

Fixpoint Fn (n : nat) (T U : Type) : Type :=
  match n with
  | O => U
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  | S n => T -> Fn n T U
  end.

(*
Global Instance MetricBall_Fn {T M} (n : nat) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  MetricBall M -> MetricBall (Fn n T M) | 10.
Proof.
  intros MM.
  elim: n => /= [ | n IHn].
  exact MM.
  exact (MetricBall_fct IHn).
Defined.
*)

(** ** Matrices *)

Section Matrices.

Context {T : Type}.

Definition matrix (m n : nat) := Tn m (Tn n T).

Definition coeff_mat {m n : nat} (x0 : T) (A : matrix m n) (i j : nat) :=
  coeff_Tn x0 (coeff_Tn (mk_Tn _ (fun _ => x0)) A i) j.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition mk_matrix (m n : nat) (U : nat -> nat -> T) : matrix m n :=
  mk_Tn m (fun i => (mk_Tn n (U i))).

Lemma mk_matrix_bij {m n : nat} (x0 : T) (A : matrix m n) :
  mk_matrix m n (coeff_mat x0 A) = A.
Proof.
(* Goal: @eq T (@coeff_mat m n x0 (mk_matrix m n u) i j) (u i j) *)
  unfold mk_matrix, coeff_mat.
(* Goal: @eq (matrix m n) (@mk_Tn (Tn n T) m (fun i : nat => @mk_Tn T n (fun j : nat => @coeff_Tn T n x0 (@coeff_Tn (Tn n T) m (@mk_Tn T n (fun _ : nat => x0)) A i) j))) A *)
  unfold matrix in A.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -{2}(mk_Tn_bij (mk_Tn _ (fun _ => x0)) A).
(* Goal: @eq (matrix m n) (@mk_Tn (Tn n T) m (fun i : nat => @mk_Tn T n (fun j : nat => @coeff_Tn T n x0 (@coeff_Tn (Tn n T) m (@mk_Tn T n (fun _ : nat => x0)) A i) j))) (@mk_Tn (Tn n T) m (@coeff_Tn (Tn n T) m (@mk_Tn T n (fun _ : nat => x0)) A)) *)
  apply mk_Tn_ext.
(* Goal: forall (i : nat) (_ : lt i m), @eq (Tn n T) (@mk_Tn T n (fun j : nat => @coeff_Tn T n x0 (@coeff_Tn (Tn n T) m (@mk_Tn T n (fun _ : nat => x0)) A i) j)) (@coeff_Tn (Tn n T) m (@mk_Tn T n (fun _ : nat => x0)) A i) *)
  intros i Hi.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite mk_Tn_bij.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma coeff_mat_bij {m n : nat} (x0 : T) (u : nat -> nat -> T) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall i j, (i < m)%nat -> (j < n)%nat -> coeff_mat x0 (mk_matrix m n u) i j = u i j.
Proof.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  intros i j Hi Hj.
(* Goal: @eq T (@coeff_mat m n x0 (mk_matrix m n u) i j) (u i j) *)
  unfold mk_matrix, coeff_mat.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite 2?coeff_Tn_bij .
Qed.

Lemma coeff_mat_ext_aux {m n : nat} (x1 x2 : T) (v1 v2 : matrix m n) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  v1 = v2 <-> forall i j, (i < m)%nat -> (j < n)%nat -> (coeff_mat x1 v1 i j) = (coeff_mat x2 v2 i j).
Proof.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  split => Hv.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  + move => i j Hi Hj.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by repeat apply coeff_Tn_ext.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  + unfold matrix in v1, v2.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    rewrite -(mk_matrix_bij x1 v1) -(mk_matrix_bij x2 v2).
(* Goal: @eq (matrix m n) (mk_matrix m n (@coeff_mat m n x1 v1)) (mk_matrix m n (@coeff_mat m n x2 v2)) *)
    unfold mk_matrix.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    apply mk_Tn_ext => i Hi.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    apply mk_Tn_ext => j Hj.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply Hv.
Qed.

Lemma coeff_mat_ext {m n : nat} (x0 : T) (v1 v2 : matrix m n) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  v1 = v2 <-> forall i j, (coeff_mat x0 v1 i j) = (coeff_mat x0 v2 i j).
Proof.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by move => ->.
(* Goal: forall _ : forall i j : nat, @eq T (@coeff_mat m n x0 v1 i j) (@coeff_mat m n x0 v2 i j), @eq (matrix m n) v1 v2 *)
  intro H.
(* Goal: @eq (matrix m n) v1 v2 *)
  now apply (coeff_mat_ext_aux x0 x0 v1 v2).
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma mk_matrix_ext (m n : nat) (u1 u2 : nat -> nat -> T) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall i j, (i < m)%nat -> (j < n)%nat -> (u1 i j) = (u2 i j))
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    <-> (mk_matrix m n u1) = (mk_matrix m n u2).
Proof.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  split => H.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  + apply (mk_Tn_ext m) => i Hi.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    apply (mk_Tn_ext n) => j Hj.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply H.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  + intros i j Hi Hj.
(* Goal: @eq T (u1 i j) (u2 i j) *)
    apply (mk_Tn_ext n).
(* Goal: @eq (Tn n T) (@mk_Tn T n (u1 i)) (@mk_Tn T n (u2 i)) *)
(* Goal: lt j n *)
    apply (mk_Tn_ext m (fun i => mk_Tn n (u1 i)) (fun i => mk_Tn n (u2 i))).
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
    apply H.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by [].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by [].
Qed.

End Matrices.

Section MatrixGroup.

Context {G : AbelianGroup} {m n : nat}.

Definition Mzero := mk_matrix m n (fun i j => @zero G).

Definition Mplus (A B : @matrix G m n) :=
  mk_matrix m n (fun i j => plus (coeff_mat zero A i j) (coeff_mat zero B i j)).

Definition Mopp (A : @matrix G m n) :=
  mk_matrix m n (fun i j => opp (coeff_mat zero A i j)).

Lemma Mplus_comm :
  forall A B : @matrix G m n,
  Mplus A B = Mplus B A.
Proof.
(* Goal: forall A B : @matrix (AbelianGroup.sort G) m n, @eq (@matrix (AbelianGroup.sort G) m n) (Mplus A B) (Mplus B A) *)
  intros A B.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply mk_matrix_ext => i j Hi Hj.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply plus_comm.
Qed.

Lemma Mplus_assoc :
  forall A B C : @matrix G m n,
  Mplus A (Mplus B C) = Mplus (Mplus A B) C.
Proof.
(* Goal: forall (A : @matrix (Ring.sort T) m n) (B C : @matrix (Ring.sort T) n k), @eq (@matrix (AbelianGroup.sort (Ring.AbelianGroup T)) m k) (@Mmult m n k A (@Mplus (Ring.AbelianGroup T) n k B C)) (@Mplus (Ring.AbelianGroup T) m k (@Mmult m n k A B) (@Mmult m n k A C)) *)
  intros A B C.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply mk_matrix_ext => /= i j Hi Hj.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite ?coeff_mat_bij => //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply plus_assoc.
Qed.

Lemma Mplus_zero_r :
  forall A : @matrix G m n,
  Mplus A Mzero = A.
Proof.
(* Goal: forall A : @matrix (AbelianGroup.sort G) m n, @eq (@matrix (AbelianGroup.sort G) m n) (Mplus A (Mopp A)) Mzero *)
  intros A.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply (coeff_mat_ext_aux zero zero) => i j Hi Hj.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite ?coeff_mat_bij => //=.
(* Goal: @eq (AbelianGroup.sort G) (plus x zero) x *)
  by apply plus_zero_r.
Qed.

Lemma Mplus_opp_r :
  forall A : @matrix G m n,
  Mplus A (Mopp A) = Mzero.
Proof.
(* Goal: forall A : @matrix (AbelianGroup.sort G) m n, @eq (@matrix (AbelianGroup.sort G) m n) (Mplus A (Mopp A)) Mzero *)
  intros A.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply (coeff_mat_ext_aux zero zero) => i j Hi Hj.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite ?coeff_mat_bij => //=.
(* Goal: @eq (AbelianGroup.sort G) (minus x x) zero *)
  by apply plus_opp_r.
Qed.

Definition matrix_AbelianGroup_mixin :=
  AbelianGroup.Mixin _ _ _ _ Mplus_comm Mplus_assoc Mplus_zero_r Mplus_opp_r.

Canonical matrix_AbelianGroup :=
  AbelianGroup.Pack _ matrix_AbelianGroup_mixin (@matrix G m n).

End MatrixGroup.

Section MatrixRing.

Context {T : Ring}.

Fixpoint Mone_seq i j : T :=
  match i,j with
    | O, O => one
    | O, S _ | S _, O => zero
    | S i, S j => Mone_seq i j end.

Definition Mone {n} : matrix n n :=
  mk_matrix n n Mone_seq.

Lemma Mone_seq_diag :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall i j : nat, i = j -> Mone_seq i j = @one T.
Proof.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  move => i j <- {j}.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by induction i.
Qed.
Lemma Mone_seq_not_diag :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall i j : nat, i <> j -> Mone_seq i j = @zero T.
Proof.
  elim => //= [ | i IHi] j Hij ;
  destruct j => //=.
(* Goal: @eq (Ring.sort T) (Mone_seq i j) (@zero (Ring.AbelianGroup T)) *)
  apply IHi.
(* Goal: not (@eq nat i j) *)
  contradict Hij.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite Hij.
Qed.

Definition Mmult {n m k} (A : @matrix T n m) (B : @matrix T m k) :=
  mk_matrix n k (fun i j => sum_n (fun l => mult (coeff_mat zero A i l) (coeff_mat zero B l j)) (pred m)).

Lemma Mmult_assoc {n m k l} :
  forall (A : matrix n m) (B : matrix m k) (C : matrix k l),
  Mmult A (Mmult B C) = Mmult (Mmult A B) C.
Proof.
(* Goal: forall (A : @matrix (Ring.sort T) m n) (B C : @matrix (Ring.sort T) n k), @eq (@matrix (AbelianGroup.sort (Ring.AbelianGroup T)) m k) (@Mmult m n k A (@Mplus (Ring.AbelianGroup T) n k B C)) (@Mplus (Ring.AbelianGroup T) m k (@Mmult m n k A B) (@Mmult m n k A C)) *)
  intros A B C.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply mk_matrix_ext => n' l' Hn' Hl'.
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m l (@zero (Ring.AbelianGroup T)) (@Mmult m k l B C) l0 l')) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
  unfold Mmult at 1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  - transitivity (sum_n (fun l0 : nat => mult (coeff_mat zero A n' l0)
      (sum_n (fun l1 : nat => mult (coeff_mat zero B l0 l1) (coeff_mat zero C l1 l')) (pred k))) (pred m)).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
    destruct m ; simpl.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
    unfold coeff_mat ; simpl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by rewrite 2!mult_zero_l.
(* Goal: @eq (Ring.sort T) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) m) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' l0) (@mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l'))) (Init.Nat.pred k)) m) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l'))) (Init.Nat.pred k)) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
    apply sum_n_m_ext_loc ; simpl => m' [ _ Hm'].
(* Goal: @eq (Ring.sort T) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@coeff_mat (Ring.sort T) (S m) l (@zero (Ring.AbelianGroup T)) (@mk_matrix (Ring.sort T) (S m) l (fun i j : nat => @sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B i l0) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l0 j)) (Init.Nat.pred k))) m' l')) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
    apply f_equal.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    rewrite coeff_mat_bij //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply le_lt_n_Sm, Hm'.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  - transitivity (sum_n (fun l0 : nat => sum_n
      (fun l1 : nat => mult (coeff_mat zero A n' l0) (mult (coeff_mat zero B l0 l1) (coeff_mat zero C l1 l'))) (pred k)) (pred m)).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
    destruct m ; simpl.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    rewrite /sum_n !sum_n_n.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
    unfold coeff_mat ; simpl.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    rewrite mult_zero_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    rewrite sum_n_m_mult_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by rewrite mult_zero_l.
(* Goal: @eq (Ring.sort T) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) m) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' l0) (@mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l'))) (Init.Nat.pred k)) m) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l'))) (Init.Nat.pred k)) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
    apply sum_n_m_ext_loc ; simpl => m' [_ Hm'].
(* Goal: @eq (Ring.sort T) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l'))) (Init.Nat.pred k)) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l'))) (Init.Nat.pred k)) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
    apply sym_eq, sum_n_m_mult_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_switch.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  destruct k ; simpl.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  unfold coeff_mat ; simpl.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite mult_zero_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n sum_n_m_mult_r.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite mult_zero_r.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply sum_n_m_ext_loc => k' [_ Hk'].
  transitivity (mult (sum_n (fun l1 : nat => mult (coeff_mat zero A n' l1) (coeff_mat zero B l1 k')) (pred m))
    (coeff_mat zero C k' l')).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -sum_n_m_mult_r.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply sum_n_m_ext_loc => m' [_ Hm'].
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@mult T (@coeff_mat (Ring.sort T) n m (@zero (Ring.AbelianGroup T)) A n' m') (@mult T (@coeff_mat (Ring.sort T) m (S k) (@zero (Ring.AbelianGroup T)) B m' k') (@coeff_mat (Ring.sort T) (S k) l (@zero (Ring.AbelianGroup T)) C k' l'))) (@mult T (@mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' m') (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m (S k) (@zero (Ring.AbelianGroup T)) B m' k')) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@mult T (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m (S k) (@zero (Ring.AbelianGroup T)) B l1 k')) (Init.Nat.pred m)) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) (@mult T (@coeff_mat (Ring.sort T) n (S k) (@zero (Ring.AbelianGroup T)) (@Mmult n m (S k) A B) n' k') (@coeff_mat (Ring.sort T) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) *)
  apply mult_assoc.
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@mult T (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m (S k) (@zero (Ring.AbelianGroup T)) B l1 k')) (Init.Nat.pred m)) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) (@mult T (@coeff_mat (Ring.sort T) n (S k) (@zero (Ring.AbelianGroup T)) (@Mmult n m (S k) A B) n' k') (@coeff_mat (Ring.sort T) (S k) l (@zero (Ring.AbelianGroup T)) C k' l')) *)
  apply f_equal2.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  unfold Mmult ; rewrite coeff_mat_bij //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_lt_n_Sm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
Qed.

Lemma Mmult_one_r {m n} :
  forall x : matrix m n, Mmult x Mone = x.
Proof.
(* Goal: forall A : @matrix (AbelianGroup.sort G) m n, @eq (@matrix (AbelianGroup.sort G) m n) (Mplus A (Mopp A)) Mzero *)
  intros A.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -{2}(mk_matrix_bij zero A).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply mk_matrix_ext => /= i j Hi Hj.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  destruct n ; simpl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply lt_n_O in Hj.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (coeff_mat zero A) => {A} A.
  erewrite sum_n_ext_loc ; last first.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => /= k Hk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /Mone coeff_mat_bij //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_lt_n_Sm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n (sum_n_m_Chasles _ _ j) //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  2: by apply le_O_n.
  2: by apply lt_n_Sm_le.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (sum_n_m_ext_loc _ (fun _ => zero) (S j)).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_m_const_zero plus_zero_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -/(sum_n _ _).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  destruct j => //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite sum_O Mone_seq_diag // mult_one_r.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_Sn.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (sum_n_ext_loc _ (fun _ => zero)).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n sum_n_m_const_zero plus_zero_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite Mone_seq_diag // mult_one_r.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => k Hk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Mone_seq_not_diag.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply mult_zero_r.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply MyNat.lt_neq, le_lt_n_Sm.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => k [Hk _].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Mone_seq_not_diag.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply mult_zero_r.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sym_not_eq, MyNat.lt_neq.
Qed.

Lemma Mmult_one_l {m n} :
  forall x : matrix m n, Mmult Mone x = x.
Proof.
(* Goal: forall A : @matrix (AbelianGroup.sort G) m n, @eq (@matrix (AbelianGroup.sort G) m n) (Mplus A (Mopp A)) Mzero *)
  intros A.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -{2}(mk_matrix_bij zero A).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply mk_matrix_ext => /= i j Hi Hj.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  destruct m ; simpl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply lt_n_O in Hi.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move: (coeff_mat zero A) => {A} A.
  erewrite sum_n_ext_loc ; last first.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => /= k Hk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /Mone coeff_mat_bij //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_lt_n_Sm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n (sum_n_m_Chasles _ _ i) //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  2: by apply le_O_n.
  2: by apply lt_n_Sm_le.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (sum_n_m_ext_loc _ (fun _ => zero) (S i)).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_m_const_zero plus_zero_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -/(sum_n _ _).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  destruct i => //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite sum_O Mone_seq_diag // mult_one_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_Sn.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite (sum_n_ext_loc _ (fun _ => zero)).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n sum_n_m_const_zero plus_zero_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite Mone_seq_diag // mult_one_l.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => k Hk.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Mone_seq_not_diag.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply mult_zero_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply sym_not_eq, MyNat.lt_neq, le_lt_n_Sm.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => k [Hk _].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Mone_seq_not_diag.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply mult_zero_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply MyNat.lt_neq.
Qed.

Lemma Mmult_distr_r {m n k} :
  forall (A B : @matrix T m n) (C : @matrix T n k),
  Mmult (Mplus A B) C = Mplus (Mmult A C) (Mmult B C).
Proof.
(* Goal: forall (A : @matrix (Ring.sort T) m n) (B C : @matrix (Ring.sort T) n k), @eq (@matrix (AbelianGroup.sort (Ring.AbelianGroup T)) m k) (@Mmult m n k A (@Mplus (Ring.AbelianGroup T) n k B C)) (@Mplus (Ring.AbelianGroup T) m k (@Mmult m n k A B) (@Mmult m n k A C)) *)
  intros A B C.
(* Goal: @eq (@matrix (AbelianGroup.sort (Ring.AbelianGroup T)) m k) (@Mmult m n k A (@Mplus (Ring.AbelianGroup T) n k B C)) (@Mplus (Ring.AbelianGroup T) m k (@Mmult m n k A B) (@Mmult m n k A C)) *)
  unfold Mmult, plus ; simpl ; unfold Mplus.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply mk_matrix_ext => i j Hi Hj.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite ?coeff_mat_bij => //=.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -sum_n_m_plus.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  destruct n ; simpl.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  unfold coeff_mat ; simpl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite ?mult_zero_l plus_zero_l.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply sum_n_m_ext_loc => l [_ Hl].
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite ?coeff_mat_bij => //=.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply mult_distr_r.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_lt_n_Sm.
Qed.

Lemma Mmult_distr_l {m n k} :
  forall (A : @matrix T m n) (B C : @matrix T n k),
  Mmult A (Mplus B C) = Mplus (Mmult A B) (Mmult A C).
Proof.
(* Goal: forall (A : @matrix (Ring.sort T) m n) (B C : @matrix (Ring.sort T) n k), @eq (@matrix (AbelianGroup.sort (Ring.AbelianGroup T)) m k) (@Mmult m n k A (@Mplus (Ring.AbelianGroup T) n k B C)) (@Mplus (Ring.AbelianGroup T) m k (@Mmult m n k A B) (@Mmult m n k A C)) *)
  intros A B C.
(* Goal: @eq (@matrix (AbelianGroup.sort (Ring.AbelianGroup T)) m k) (@Mmult m n k A (@Mplus (Ring.AbelianGroup T) n k B C)) (@Mplus (Ring.AbelianGroup T) m k (@Mmult m n k A B) (@Mmult m n k A C)) *)
  unfold Mmult, plus ; simpl ; unfold Mplus.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply mk_matrix_ext => i j Hi Hj.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite ?coeff_mat_bij => //=.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -sum_n_m_plus.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  destruct n ; simpl.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  unfold coeff_mat ; simpl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite ?mult_zero_l plus_zero_l.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply sum_n_m_ext_loc => l [_ Hl].
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite ?coeff_mat_bij => //=.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply mult_distr_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_lt_n_Sm.
Qed.

Definition matrix_Ring_mixin {n} :=
  Ring.Mixin _ _ _ (@Mmult_assoc n n n n) Mmult_one_r Mmult_one_l Mmult_distr_r Mmult_distr_l.

Canonical matrix_Ring {n} :=
  Ring.Pack (@matrix T n n) (Ring.Class _ _ matrix_Ring_mixin) (@matrix T n n).

Definition matrix_ModuleSpace_mixin {m n} :=
  ModuleSpace.Mixin (@matrix_Ring m) (@matrix_AbelianGroup T m n) Mmult
    Mmult_assoc Mmult_one_l Mmult_distr_l Mmult_distr_r.

Canonical matrix_ModuleSpace {m n} :=
  ModuleSpace.Pack _ (@matrix T m n) (ModuleSpace.Class _ _ _ matrix_ModuleSpace_mixin) (@matrix T m n).

End MatrixRing.

(** * The topology on natural numbers *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition eventually (P : nat -> Prop) :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists N : nat, forall n, (N <= n)%nat -> P n.

Global Instance eventually_filter : ProperFilter eventually.
Proof.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: forall (P : forall _ : nat, Prop) (_ : eventually P), @ex nat (fun x : nat => P x) *)
(* Goal: @Filter nat eventually *)
  intros P [N H].
(* Goal: @ex nat (fun x : nat => P x) *)
(* Goal: @Filter nat eventually *)
  exists N.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: le N N *)
(* Goal: @Filter nat eventually *)
  apply le_refl.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
constructor.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now exists 0%nat.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q [NP HP] [NQ HQ].
(* Goal: eventually (fun x : nat => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : nat, Prop) (_ : forall (x : nat) (_ : P x), Q x) (_ : eventually P), eventually Q *)
  exists (max NP NQ).
(* Goal: forall (n : nat) (_ : le NP n), Q n *)
  intros n Hn.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: le NQ n *)
(* Goal: forall (P Q : forall _ : nat, Prop) (_ : forall (x : nat) (_ : P x), Q x) (_ : eventually P), eventually Q *)
  apply le_trans with (2 := Hn).
(* Goal: le NP (Init.Nat.max NP NQ) *)
(* Goal: Q n *)
(* Goal: forall (P Q : forall _ : nat, Prop) (_ : forall (x : nat) (_ : P x), Q x) (_ : eventually P), eventually Q *)
  apply Max.le_max_l.
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HQ.
(* Goal: le NQ n *)
(* Goal: forall (P Q : forall _ : nat, Prop) (_ : forall (x : nat) (_ : P x), Q x) (_ : eventually P), eventually Q *)
  apply le_trans with (2 := Hn).
(* Goal: le NQ (Init.Nat.max NP NQ) *)
(* Goal: forall (P Q : forall _ : nat, Prop) (_ : forall (x : nat) (_ : P x), Q x) (_ : eventually P), eventually Q *)
  apply Max.le_max_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H [NP HP].
(* Goal: eventually Q *)
  exists NP.
(* Goal: forall (n : nat) (_ : le NP n), Q n *)
  intros n Hn.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: P y *)
  now apply HP.
Qed.

(** * The topology on real numbers *)

Definition R_AbelianGroup_mixin :=
  AbelianGroup.Mixin _ _ _ _ Rplus_comm (fun x y z => sym_eq (Rplus_assoc x y z)) Rplus_0_r Rplus_opp_r.

Canonical R_AbelianGroup :=
  AbelianGroup.Pack _ R_AbelianGroup_mixin R.

Definition R_Ring_mixin :=
  Ring.Mixin _ _ _ (fun x y z => sym_eq (Rmult_assoc x y z)) Rmult_1_r Rmult_1_l Rmult_plus_distr_r Rmult_plus_distr_l.

Canonical R_Ring :=
  Ring.Pack R (Ring.Class _ _ R_Ring_mixin) R.

Lemma Rabs_m1 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Rabs (-1) = 1.
Proof.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rabs_Ropp.
(* Goal: @eq R (Rabs (IPR xH)) (IZR (Zpos xH)) *)
  exact Rabs_R1.
Qed.

Definition R_AbsRing_mixin :=
  AbsRing.Mixin _ _ Rabs_R0 Rabs_m1 Rabs_triang (fun x y => Req_le _ _ (Rabs_mult x y)) Rabs_eq_0.

Canonical R_AbsRing :=
  AbsRing.Pack R (AbsRing.Class _ _ R_AbsRing_mixin) R.

Definition R_UniformSpace_mixin :=
  AbsRing_UniformSpace_mixin R_AbsRing.

Canonical R_UniformSpace :=
  UniformSpace.Pack R R_UniformSpace_mixin R.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition R_complete_lim (F : (R -> Prop) -> Prop) : R :=
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  Lub_Rbar (fun x : R => F (ball (x + 1) (mkposreal _ Rlt_0_1))).

Lemma R_complete_ax1 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall F : (R -> Prop) -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter' F ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall eps : posreal, exists x : R, F (ball x eps)) ->
  forall eps : posreal, F (ball (R_complete_lim F) eps).
Proof.
(* Goal: forall (F : forall _ : forall _ : R, Prop, Prop) (_ : @ProperFilter' R F) (_ : forall eps : posreal, @ex R (fun x : R => F (@ball R_UniformSpace x (pos eps)))) (eps : posreal), F (@ball R_UniformSpace (R_complete_lim F) (pos eps)) *)
intros F FF HF eps.
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
unfold R_complete_lim.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
generalize (Lub_Rbar_correct (fun x : R => F (ball (x + 1) (mkposreal _ Rlt_0_1)))).
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
generalize (Lub_Rbar (fun x : R => F (ball (x + 1) (mkposreal _ Rlt_0_1)))).
(* Goal: forall (r : Rbar) (_ : is_lub_Rbar (fun x : R => F (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)))) r), F (@ball R_UniformSpace (real r) (pos eps)) *)
intros [x| |] [Hx1 Hx2].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
-
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
set (eps' := pos_div_2 (mkposreal _ (Rmin_case _ _ _ Rlt_R0_R2 (cond_pos eps)))).
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
destruct (HF eps') as [z Hz].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
assert (H1 : z - Rmin 2 eps / 2 + 1 <= x + 1).
(* Goal: Rle (Rplus x (IZR (Zpos xH))) (Rplus (Rplus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Rplus_le_compat_r.
(* Goal: Rle (Rminus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) x *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Hx1.
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  revert Hz.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  apply filter_imp.
(* Goal: forall (x : R) (_ : @ball R_UniformSpace z (pos eps') x), @ball R_UniformSpace (Rplus (Rminus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)) x *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  unfold ball ; simpl ; intros u Bu.
(* Goal: AbsRing_ball R_AbsRing (Rplus (Rminus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) (IZR (Zpos xH)) u *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply (Rabs_lt_between' u z) in Bu.
(* Goal: Rlt (Rminus x (Rminus x y)) z *)
  apply Rabs_lt_between'.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  clear -Bu.
(* Goal: and (Rlt (Rminus (Rplus (Rminus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) (IZR (Zpos xH))) u) (Rlt u (Rplus (Rplus (Rminus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) (IZR (Zpos xH)))) *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  destruct Bu as [Bu1 Bu2].
(* Goal: and (Rlt (Rminus (Rplus (Rminus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) (IZR (Zpos xH))) u) (Rlt u (Rplus (Rplus (Rminus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) (IZR (Zpos xH)))) *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  assert (H := Rmin_l 2 eps).
(* Goal: and (Rlt (Rminus x (pos eps)) u) (Rlt u (Rplus x (pos eps))) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  split ; Fourier.fourier.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
assert (H2 : x + 1 <= z + Rmin 2 eps / 2 + 1).
(* Goal: Rle (Rplus x (IZR (Zpos xH))) (Rplus (Rplus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) (IZR (Zpos xH))) *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Rplus_le_compat_r.
(* Goal: Rle x (Rplus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH))))) *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply (Hx2 (Finite _)).
(* Goal: is_ub_Rbar (fun x : R => F (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)))) (Finite (Rplus z (Rdiv (Rmin (IZR (Zpos (xO xH))) (pos eps)) (IZR (Zpos (xO xH)))))) *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  intros v Hv.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply Rbar_not_lt_le => Hlt.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply filter_not_empty.
(* Goal: F (fun _ : R => False) *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  generalize (filter_and _ _ Hz Hv).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  apply filter_imp.
(* Goal: forall (x : R) (_ : and (@ball R_UniformSpace z (pos eps') x) (@ball R_UniformSpace (Rplus v (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)) x)), False *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  unfold ball ; simpl ; intros w [Hw1 Hw2].
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply (Rabs_lt_between' w z) in Hw1.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  destruct Hw1 as [_ Hw1].
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  apply (Rabs_lt_between' w (v + 1)) in Hw2.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  destruct Hw2 as [Hw2 _].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  clear -Hw1 Hw2 Hlt.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  simpl in Hw1, Hw2, Hlt.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  Fourier.fourier.
(* Goal: F (@ball R_UniformSpace (real (Finite x)) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
revert Hz.
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
apply filter_imp.
(* Goal: forall (x0 : R) (_ : @ball R_UniformSpace z (pos eps') x0), @ball R_UniformSpace (real (Finite x)) (pos eps) x0 *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
unfold ball ; simpl ; intros u Hu.
(* Goal: AbsRing_ball R_AbsRing x (pos eps) u *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
apply (Rabs_lt_between' u z) in Hu.
(* Goal: Rlt (Rminus x (Rminus x y)) z *)
apply Rabs_lt_between'.
(* Goal: and (Rlt (Rminus x (pos eps)) u) (Rlt u (Rplus x (pos eps))) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
assert (H3 := Rmin_l 2 eps).
(* Goal: and (Rlt (Rminus x (pos eps)) u) (Rlt u (Rplus x (pos eps))) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
assert (H4 := Rmin_r 2 eps).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
clear -H1 H2 Hu H3 H4.
(* Goal: and (Rlt (Rminus x (pos eps)) u) (Rlt u (Rplus x (pos eps))) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
destruct Hu.
(* Goal: and (Rlt (Rminus x (pos eps)) u) (Rlt u (Rplus x (pos eps))) *)
(* Goal: F (@ball R_UniformSpace (real p_infty) (pos eps)) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
split ; Fourier.fourier.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
-
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  destruct (HF (mkposreal _ Rlt_0_1)) as [y Fy].
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  elim (Hx2 (y + 1)).
(* Goal: is_ub_Rbar (fun x : R => F (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)))) (Finite (Rplus y (IZR (Zpos xH)))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  intros x Fx.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply Rbar_not_lt_le => Hlt.
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply filter_not_empty.
(* Goal: F (fun _ : R => False) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  generalize (filter_and _ _ Fy Fx).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
  apply filter_imp.
(* Goal: forall (x0 : R) (_ : and (@ball R_UniformSpace y (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)) x0) (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)) x0)), False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  intros z [Hz1 Hz2].
(* Goal: False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  revert Hlt.
(* Goal: forall _ : Rbar_lt (Finite (Rplus y (IZR (Zpos xH)))) (Finite x), False *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Rbar_le_not_lt.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  apply Rplus_le_reg_r with (-(y - 1)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  replace (y + 1 + -(y - 1)) with 2 by ring.
(* Goal: Rle (Rplus x (Ropp (Rminus y (IZR (Zpos xH))))) (IZR (Zpos (xO xH))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Rabs_le_between.
(* Goal: Rle (Rabs (Rplus x (Ropp (Rminus y (IZR (Zpos xH)))))) (IZR (Zpos (xO xH))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Rlt_le.
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  generalize (ball_triangle y z (x + 1) 1 1) => /= H.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  replace (x + -(y - 1)) with ((x + 1) - y) by ring.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: @ball R_UniformSpace y (IZR (Zpos xH)) z *)
(* Goal: @ball R_UniformSpace z (IZR (Zpos xH)) (Rplus x (IZR (Zpos xH))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Hz1.
(* Goal: @ball R_UniformSpace z (IZR (Zpos xH)) (Rplus x (IZR (Zpos xH))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply ball_sym in Hz2.
(* Goal: @ball R_UniformSpace z (IZR (Zpos xH)) (Rplus x (IZR (Zpos xH))) *)
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  apply Hz2.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
-
(* Goal: F (@ball R_UniformSpace (real m_infty) (pos eps)) *)
  destruct (HF (mkposreal _ Rlt_0_1)) as [y Fy].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  elim (Hx1 (y - 1)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  now replace (y - 1 + 1) with y by ring.
Qed.

Lemma R_complete :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall F : (R -> Prop) -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ProperFilter F ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall eps : posreal, exists x : R, F (ball x eps)) ->
  forall eps : posreal, F (ball (R_complete_lim F) eps).
Proof.
(* Goal: forall (F : forall _ : forall _ : R, Prop, Prop) (_ : @ProperFilter R F) (_ : forall eps : posreal, @ex R (fun x : R => F (@ball R_UniformSpace x (pos eps)))) (eps : posreal), F (@ball R_UniformSpace (R_complete_lim F) (pos eps)) *)
intros F FF.
(* Goal: forall (_ : forall eps : posreal, @ex R (fun x : R => F (@ball R_UniformSpace x (pos eps)))) (eps : posreal), F (@ball R_UniformSpace (R_complete_lim F) (pos eps)) *)
apply R_complete_ax1.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
by apply Proper_StrongProper.
Qed.

Lemma R_complete_ax2 :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall F1 F2 : (R -> Prop) -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le F1 F2 -> filter_le F2 F1 ->
  R_complete_lim F1 = R_complete_lim F2.
Proof.
(* Goal: forall (F1 F2 : forall _ : forall _ : R, Prop, Prop) (_ : @filter_le R F1 F2) (_ : @filter_le R F2 F1), @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F2) *)
intros F1 F2 H12 H21.
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
unfold R_complete_lim.
(* Goal: @eq R (real (Lub_Rbar (fun x : R => F1 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)))))) (real (Lub_Rbar (fun x : R => F2 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1)))))) *)
apply f_equal, Lub_Rbar_eqset.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall _ : F1 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))), F2 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))) *)
(* Goal: forall _ : F2 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))), F1 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))) *)
apply H21.
(* Goal: forall _ : F2 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))), F1 (@ball R_UniformSpace (Rplus x (IZR (Zpos xH))) (pos (mkposreal (IZR (Zpos xH)) Rlt_0_1))) *)
apply H12.
Qed.

Lemma R_complete_close :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall F1 F2 : (R -> Prop) -> Prop,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  filter_le F1 F2 -> filter_le F2 F1 ->
  close (R_complete_lim F1) (R_complete_lim F2).
Proof.
(* Goal: forall (F1 F2 : forall _ : forall _ : R, Prop, Prop) (_ : @filter_le R F1 F2) (_ : @filter_le R F2 F1), @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F2) *)
intros F1 F2 H12 H21.
(* Goal: @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F2) *)
replace (R_complete_lim F2) with (R_complete_lim F1).
(* Goal: @close R_UniformSpace (R_complete_lim F1) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
intros eps.
(* Goal: @ball R_UniformSpace (R_complete_lim F1) (pos eps) (R_complete_lim F1) *)
(* Goal: @eq R (R_complete_lim F1) (R_complete_lim F2) *)
apply ball_center.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
exact: R_complete_ax2.
Qed.

Definition R_CompleteSpace_mixin :=
  CompleteSpace.Mixin _ R_complete_lim R_complete R_complete_close.

Canonical R_CompleteSpace :=
  CompleteSpace.Pack R (CompleteSpace.Class _ _ R_CompleteSpace_mixin) R.

Definition R_ModuleSpace_mixin :=
  AbsRing_ModuleSpace_mixin R_AbsRing.

Canonical R_ModuleSpace :=
  ModuleSpace.Pack _ R (ModuleSpace.Class _ _ _ R_ModuleSpace_mixin) R.

Canonical R_NormedModuleAux :=
  NormedModuleAux.Pack _ R (NormedModuleAux.Class _ _ (ModuleSpace.class _ R_ModuleSpace) (UniformSpace.class R_UniformSpace)) R.

Definition R_NormedModule_mixin :=
  AbsRing_NormedModule_mixin R_AbsRing.

Canonical R_NormedModule :=
  NormedModule.Pack _ R (NormedModule.Class _ _ _ R_NormedModule_mixin) R.

Canonical R_CompleteNormedModule :=
  CompleteNormedModule.Pack _ R (CompleteNormedModule.Class R_AbsRing _ (NormedModule.class _ R_NormedModule) R_CompleteSpace_mixin) R.

Definition at_left x := within (fun u : R => Rlt u x) (locally x).
Definition at_right x := within (fun u : R => Rlt x u) (locally x).

Global Instance at_right_proper_filter : forall (x : R),
  ProperFilter (at_right x).
Proof.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
  constructor.
(* Goal: forall (P : forall _ : R, Prop) (_ : at_left x P), @ex R (fun x : R => P x) *)
(* Goal: @Filter R (at_left x) *)
  intros P [d Hd].
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  exists (x + d / 2).
(* Goal: P z y *)
  apply Hd.
(* Goal: @ball R_UniformSpace x (pos d) (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) *)
(* Goal: Rlt (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) x *)
(* Goal: @Filter R (at_left x) *)
  apply @norm_compat1 ; rewrite /norm /minus /plus /opp /= /abs /=.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ring_simplify (x + d / 2 + - x).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rabs_pos_eq.
(* Goal: Rlt (Rdiv (pos d) (IZR (Zpos (xO xH)))) (pos d) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos d) (IZR (Zpos (xO xH)))) *)
(* Goal: Rlt (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) x *)
(* Goal: @Filter R (at_left x) *)
  apply Rlt_div_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rlt_0_2.
(* Goal: Rlt (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) x *)
(* Goal: @Filter R (at_left x) *)
  apply Rminus_lt_0 ; ring_simplify ; by apply d.
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) (Rplus x (Rdiv (pos eps) (IZR (Zpos (xO xH))))) x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le, is_pos_div_2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply Rminus_lt_0 ; ring_simplify ; by apply is_pos_div_2.
(* Goal: @Filter R (at_left x) *)
  apply within_filter, locally_filter.
Qed.
Global Instance at_left_proper_filter : forall (x : R),
  ProperFilter (at_left x).
Proof.
(* Goal: forall x : R, @ProperFilter R (at_left x) *)
  constructor.
(* Goal: forall (P : forall _ : R, Prop) (_ : at_left x P), @ex R (fun x : R => P x) *)
(* Goal: @Filter R (at_left x) *)
  intros P [d Hd].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists (x - d / 2).
(* Goal: P z y *)
  apply Hd.
(* Goal: @ball R_UniformSpace x (pos d) (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) *)
(* Goal: Rlt (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) x *)
(* Goal: @Filter R (at_left x) *)
  apply @norm_compat1 ; rewrite /norm /minus /plus /opp /= /abs /=.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ring_simplify (x - d / 2 + - x).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rabs_Ropp Rabs_pos_eq.
(* Goal: Rlt (Rdiv (pos d) (IZR (Zpos (xO xH)))) (pos d) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos d) (IZR (Zpos (xO xH)))) *)
(* Goal: Rlt (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) x *)
(* Goal: @Filter R (at_left x) *)
  apply Rlt_div_l.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rlt_0_2.
(* Goal: Rlt (Rminus x (Rdiv (pos d) (IZR (Zpos (xO xH))))) x *)
(* Goal: @Filter R (at_left x) *)
  apply Rminus_lt_0 ; ring_simplify ; by apply d.
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) (Rplus x (Rdiv (pos eps) (IZR (Zpos (xO xH))))) x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le, is_pos_div_2.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply Rminus_lt_0 ; ring_simplify ; by apply is_pos_div_2.
(* Goal: @Filter R (at_left x) *)
  apply within_filter, locally_filter.
Qed.

(* *)

Lemma sum_n_Reals : forall a N, sum_n a N = sum_f_R0 a N.
Proof.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  intros a; induction N; simpl.
(* Goal: @eq R (@sum_n R_AbelianGroup a O) (a O) *)
(* Goal: @eq R (@sum_n R_AbelianGroup a (S N)) (Rplus (sum_f_R0 a N) (a (S N))) *)
  apply sum_n_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite sum_Sn IHN.
Qed.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_Reals a n m : (n <= m)%nat -> sum_n_m a n m = sum_f n m a.
Proof.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  induction m => //= Hnm.
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n O) (sum_f n O a) *)
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n (S m)) (sum_f n (S m) a) *)
  apply le_n_O_eq in Hnm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite -Hnm sum_n_n /=.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (le_dec n m) => H.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_Sm // IHm //.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_f_n_Sm //.
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n (S m)) (sum_f n (S m) a) *)
  replace n with (S m).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite sum_n_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by rewrite /sum_f minus_diag /=.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply le_antisym => //.
(* Goal: le (S m) n *)
  apply not_le in H.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply lt_le_S.
Qed.

Lemma sum_n_m_const (n m : nat) (a : R) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  sum_n_m (fun _ => a) n m = INR (S m - n) * a.
Proof.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n_m /iter_nat (iter_const _ a).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite -{2}(seq.size_iota n (S m - n)).
Qed.
Lemma sum_n_const (n : nat) (a : R) :
  sum_n (fun _ => a) n = INR (S n) * a.
Proof.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  by rewrite /sum_n sum_n_m_const -minus_n_O.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma norm_sum_n_m {K : AbsRing} {V : NormedModule K} (a : nat -> V) (n m : nat) :
  norm (sum_n_m a n m) <= sum_n_m (fun n => norm (a n)) n m.
Proof.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (le_dec n m) => Hnm.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: m n a Hnm => /= [ | m IH] n a Hnm.
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n O) (sum_f n O a) *)
(* Goal: @eq R (@sum_n_m R_AbelianGroup a n (S m)) (sum_f n (S m) a) *)
  apply le_n_O_eq in Hnm.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -Hnm !sum_n_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rle_refl.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n (S m)) (@sum_n_m R_AbelianGroup b n (S m)) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  destruct n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /sum_n !sum_n_Sm ; try by apply le_O_n.
  eapply Rle_trans.
(* Goal: Rle (norm (@plus (NormedModule.AbelianGroup K V) x (@opp (NormedModule.AbelianGroup K V) x))) (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) *)
(* Goal: Rle (Rplus (norm x) (norm (@opp (NormedModule.AbelianGroup K V) x))) (Rmult (IZR (Zpos (xO xH))) (norm x)) *)
  apply norm_triangle.
  apply Rplus_le_compat_r, IH, le_O_n.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -!sum_n_m_S.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => scal a (u (S n))) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => u (S n)) n m)) *)
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  apply IH.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_S_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  apply not_le in Hnm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_m_zero // norm_zero.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rle_refl.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma sum_n_m_le (a b : nat -> R) (n m : nat) :
  (forall k, a k <= b k)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  -> sum_n_m a n m <= sum_n_m b n m.
Proof.
(* Goal: forall _ : forall k : nat, Rle (a k) (b k), Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  intros H.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (le_dec n m) => Hnm.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: m n a b Hnm H => /= [ | m IH] n a b Hnm H.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  apply le_n_O_eq in Hnm ; rewrite -Hnm.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_n ; by apply H.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n (S m)) (@sum_n_m R_AbelianGroup b n (S m)) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  destruct n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_Sm ; try by apply le_O_n.
(* Goal: Rle (Rplus (Rabs (Rminus z t)) (Rabs t)) (Rplus (pos d2) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
  apply Rplus_le_compat.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply IH => // ; by apply le_O_n.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply H.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -!sum_n_m_S.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply IH => //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_S_n.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  apply not_le in Hnm.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !sum_n_m_zero //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rle_refl.
Qed.

Lemma pow_n_pow :
  forall (x : R) k, pow_n x k = x^k.
Proof.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
intros x; induction k; simpl.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
easy.
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now rewrite IHk.
Qed.

(** Continuity of norm *)

Lemma filterlim_norm {K : AbsRing} {V : NormedModule K} :
  forall (x : V), filterlim norm (locally x) (locally (norm x)).
Proof.
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
  intros x.
(* Goal: @filterlim (NormedModule.sort K V) R (@norm K V) (@locally (NormedModule.UniformSpace K V) x) (@locally R_UniformSpace (@norm K V x)) *)
  apply (filterlim_filter_le_1 _ (locally_le_locally_norm x)).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply filterlim_locally => eps /=.
(* Goal: @locally_norm K V x (fun x0 : NormedModule.sort K V => @ball R_UniformSpace (@norm K V x) (pos eps) (@norm K V x0)) *)
  exists eps ; move => /= y Hy.
(* Goal: Rlt MQ y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rle_lt_trans with (2 := Hy).
(* Goal: Rle (@abs R_AbsRing (@minus (AbsRing.AbelianGroup R_AbsRing) (@norm K V y) (@norm K V x))) (@norm K V (@minus (NormedModule.AbelianGroup K V) y x)) *)
  apply norm_triangle_inv.
Qed.

Lemma filterlim_norm_zero {U} {K : AbsRing} {V : NormedModule K}
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  {F : (U -> Prop) -> Prop} {FF : Filter F} (f : U -> V) :
  filterlim (fun x => norm (f x)) F (locally 0)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  -> filterlim f F (locally (zero (G := V))).
Proof.
(* Goal: forall _ : @filterlim U R (fun x : U => @norm K V (f x)) F (@locally R_UniformSpace (IZR Z0)), @filterlim U (NormedModule.sort K V) f F (@locally (NormedModule.UniformSpace K V) (@zero (NormedModule.AbelianGroup K V))) *)
  intros Hf.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply filterlim_locally_ball_norm => eps.
  generalize (proj1 (filterlim_locally_ball_norm _ _) Hf eps) ;
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  unfold ball_norm ; simpl.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply filter_imp => /= x.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite !minus_zero_r {1}/norm /= /abs /= Rabs_pos_eq //.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply norm_ge_0.
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma filterlim_bounded {K : AbsRing} {V : NormedModule K} (a : nat -> V) :
  (exists x, filterlim a eventually (locally x))
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
 -> {M : R | forall n, norm (a n) <= M}.
Proof.
  intros Ha.
  assert (exists x : R, filterlim (fun n => norm (a n)) eventually (locally x)).
    destruct Ha as [l Hl].
    exists (norm l).
    eapply filterlim_comp.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply Hl.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
    by apply filterlim_norm.
  clear Ha.

  destruct (LPO_ub_dec (fun n => norm (a n))) as [[M HM]|HM].
  now exists M.
  elimtype False.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: H => l Hl.
  assert (H := proj1 (filterlim_locally (F := eventually) _ l) Hl (mkposreal _ Rlt_0_1)).
  clear Hl ; simpl in H ; rewrite /ball /= /AbsRing_ball in H.
  destruct H as [N HN].
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  specialize (HM (seq.foldr Rmax (1 + norm l) (seq.map (fun n => norm (a n)) (seq.iota 0 N)))).
  destruct HM as [n Hn].
  revert Hn.
(* Goal: forall _ : Rle y x, not (Rlt x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (Rlt u y)) *)
  apply Rle_not_lt.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: N a n HN => /=[ |N IH] a n HN.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rplus_comm.
  apply Rlt_le, Rabs_lt_between'.
  eapply Rle_lt_trans, HN.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /abs /=.
  eapply Rle_trans, (norm_triangle_inv (norm (a n)) l).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  apply Req_le, f_equal, f_equal2 => //.
  apply sym_eq, Rabs_pos_eq, norm_ge_0.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_O_n.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: n => [ | n].
(* Goal: Rle MP (Rmax MP MQ) *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmax_l.
  eapply Rle_trans, Rmax_r.
  eapply Rle_trans.
  apply (IH (fun n => a (S n))).
  intros k Hk.
  apply HN.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply le_n_S.
  clear.
  apply Req_le.
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
(* Goal: Rle (@sum_n_m R_AbelianGroup a n m) (@sum_n_m R_AbelianGroup b n m) *)
  elim: N 0%nat => /=[ |N IH] n0.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by [].
(* Goal: @eq (Ring.sort T) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@coeff_mat (Ring.sort T) (S m) l (@zero (Ring.AbelianGroup T)) (@mk_matrix (Ring.sort T) (S m) l (fun i j : nat => @sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B i l0) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l0 j)) (Init.Nat.pred k))) m' l')) (@mult T (@coeff_mat (Ring.sort T) n (S m) (@zero (Ring.AbelianGroup T)) A n' m') (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (Ring.sort T) (S m) k (@zero (Ring.AbelianGroup T)) B m' l1) (@coeff_mat (Ring.sort T) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) *)
(* Goal: @eq (AbelianGroup.sort (Ring.AbelianGroup T)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n m (@zero (Ring.AbelianGroup T)) A n' l0) (@sum_n (Ring.AbelianGroup T) (fun l1 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) m k (@zero (Ring.AbelianGroup T)) B l0 l1) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l1 l')) (Init.Nat.pred k))) (Init.Nat.pred m)) (@sum_n (Ring.AbelianGroup T) (fun l0 : nat => @mult T (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) n k (@zero (Ring.AbelianGroup T)) (@Mmult n m k A B) n' l0) (@coeff_mat (AbelianGroup.sort (Ring.AbelianGroup T)) k l (@zero (Ring.AbelianGroup T)) C l0 l')) (Init.Nat.pred k)) *)
  apply f_equal.
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => scal a (u (S n))) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun n : nat => u (S n)) n m)) *)
(* Goal: @eq (AbelianGroup.sort (ModuleSpace.AbelianGroup K V)) (@sum_n_m (ModuleSpace.AbelianGroup K V) (fun k : nat => scal a (u k)) n m) (scal a (@sum_n_m (ModuleSpace.AbelianGroup K V) u n m)) *)
  apply IH.
Qed.

(** Some open sets of [R] *)

Lemma open_lt :
  forall y : R, open (fun u : R => u < y).
Proof.
(* Goal: forall y : R, @open R_UniformSpace (fun u : R => Rlt y u) *)
intros y x Hxy.
(* Goal: @locally R_UniformSpace x (fun u : R => Rlt y u) *)
apply Rminus_lt_0 in Hxy.
(* Goal: @locally R_UniformSpace x (fun u : R => Rlt y u) *)
exists (mkposreal _ Hxy).
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rminus x y) Hxy)) y0), Rlt y y0 *)
intros z Bz.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace y with (x + (y - x)) by ring.
(* Goal: Rlt (Rminus x (Rminus x y)) z *)
apply Rabs_lt_between'.
(* Goal: Rlt (Rabs (Rminus z x)) (Rminus x y) *)
apply Bz.
Qed.

Lemma open_gt :
  forall y : R, open (fun u : R => y < u).
Proof.
(* Goal: forall y : R, @open R_UniformSpace (fun u : R => Rlt y u) *)
intros y x Hxy.
(* Goal: @locally R_UniformSpace x (fun u : R => Rlt y u) *)
apply Rminus_lt_0 in Hxy.
(* Goal: @locally R_UniformSpace x (fun u : R => Rlt y u) *)
exists (mkposreal _ Hxy).
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rminus x y) Hxy)) y0), Rlt y y0 *)
intros z Bz.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace y with (x - (x - y)) by ring.
(* Goal: Rlt (Rminus x (Rminus x y)) z *)
apply Rabs_lt_between'.
(* Goal: Rlt (Rabs (Rminus z x)) (Rminus x y) *)
apply Bz.
Qed.

Lemma open_neq :
  forall y : R, open (fun u : R => u <> y).
Proof.
(* Goal: forall y : R, @closed R_UniformSpace (fun u : R => @eq R u y) *)
intros y.
(* Goal: @open R_UniformSpace (fun u : R => not (@eq R u y)) *)
apply (open_ext (fun u => u < y \/ y < u)).
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (or (Rlt x y) (Rlt y x)) (not (@eq R x y)) *)
(* Goal: @open R_UniformSpace (fun u : UniformSpace.sort R_UniformSpace => or (Rlt u y) (Rlt y u)) *)
intros u.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall _ : or (Rlt u y) (Rlt y u), not (@eq R u y) *)
(* Goal: forall _ : not (@eq R u y), or (Rlt u y) (Rlt y u) *)
(* Goal: @open R_UniformSpace (fun u : UniformSpace.sort R_UniformSpace => or (Rlt u y) (Rlt y u)) *)
apply Rlt_dichotomy_converse.
(* Goal: forall _ : not (@eq R u y), or (Rlt u y) (Rlt y u) *)
(* Goal: @open R_UniformSpace (fun u : UniformSpace.sort R_UniformSpace => or (Rlt u y) (Rlt y u)) *)
apply Rdichotomy.
(* Goal: @open R_UniformSpace (fun u : UniformSpace.sort R_UniformSpace => or (Rlt u y) (Rlt y u)) *)
apply open_or.
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite u) (Finite y)) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite u) p_infty) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite u) m_infty) *)
apply open_lt.
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite y) (Finite u)) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt m_infty (Finite u)) *)
apply open_gt.
Qed.

(** Some closed sets of [R] *)

Lemma closed_le :
  forall y : R, closed (fun u : R => u <= y).
Proof.
(* Goal: forall y : R, @closed R_UniformSpace (fun u : R => @eq R u y) *)
intros y.
(* Goal: @closed R_UniformSpace (fun u : R => Rle u y) *)
apply closed_ext with (fun u => not (Rlt y u)).
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall _ : not (Rlt x y), Rle y x *)
(* Goal: forall _ : Rle y x, not (Rlt x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (Rlt u y)) *)
apply Rnot_lt_le.
(* Goal: forall _ : Rle y x, not (Rlt x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (Rlt u y)) *)
apply Rle_not_lt.
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
apply closed_not.
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite y) (Finite u)) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt m_infty (Finite u)) *)
apply open_gt.
Qed.

Lemma closed_ge :
  forall y : R, closed (fun u : R => y <= u).
Proof.
(* Goal: forall y : R, @closed R_UniformSpace (fun u : R => @eq R u y) *)
intros y.
(* Goal: @closed R_UniformSpace (fun u : R => Rle y u) *)
apply closed_ext with (fun u => not (Rlt u y)).
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall _ : not (Rlt x y), Rle y x *)
(* Goal: forall _ : Rle y x, not (Rlt x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (Rlt u y)) *)
apply Rnot_lt_le.
(* Goal: forall _ : Rle y x, not (Rlt x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (Rlt u y)) *)
apply Rle_not_lt.
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
apply closed_not.
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite u) (Finite y)) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite u) p_infty) *)
(* Goal: @open R_UniformSpace (fun u : R => Rbar_lt (Finite u) m_infty) *)
apply open_lt.
Qed.

Lemma closed_eq :
  forall y : R, closed (fun u : R => u = y).
Proof.
(* Goal: forall y : R, @closed R_UniformSpace (fun u : R => @eq R u y) *)
intros y.
(* Goal: @closed R_UniformSpace (fun u : R => @eq R u y) *)
apply closed_ext with (fun u => not (u <> y)).
(* Goal: forall x : UniformSpace.sort R_UniformSpace, iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
intros x.
(* Goal: iff (not (not (@eq R x y))) (@eq R x y) *)
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
destruct (Req_dec x y) ; intuition.
(* Goal: @closed R_UniformSpace (fun u : R => not (not (@eq R u y))) *)
apply closed_not.
(* Goal: @open R_UniformSpace (fun x : UniformSpace.sort R_UniformSpace => not (@eq R x y)) *)
apply open_neq.
Qed.

(** Local properties in [R] *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma locally_interval (P : R -> Prop) (x : R) (a b : Rbar) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  Rbar_lt a x -> Rbar_lt x b ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall (y : R), Rbar_lt a y -> Rbar_lt y b -> P y) ->
  locally x P.
Proof.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
  move => Hax Hxb Hp.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (Rbar_lt_locally _ _ _ Hax Hxb) => d Hd.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  exists d => y Hy.
(* Goal: P z y *)
  now apply Hp ; apply Hd.
Qed.

(** * Topology on [R]² *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition locally_2d (P : R -> R -> Prop) x y :=
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists delta : posreal, forall u v, Rabs (u - x) < delta -> Rabs (v - y) < delta -> P u v.

Lemma locally_2d_locally :
  forall P x y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y <-> locally (x,y) (fun z => P (fst z) (snd z)).
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d P x y), locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y))))) x y *)
intros P x y.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
split ; intros [d H] ; exists d.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- simpl.
(* Goal: forall (y0 : prod R R) (_ : @ball (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (pos d) y0), P (@fst R R y0) (@snd R R y0) *)
(* Goal: forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v *)
  intros [u v] H'.
(* Goal: P (@fst R R (@pair R R u v)) (@snd R R (@pair R R u v)) *)
(* Goal: forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v *)
  now apply H ; apply H'.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros u v Hu Hv.
(* Goal: P u v *)
  apply (H (u,v)).
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  by split.
Qed.

Lemma locally_2d_impl_strong :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P Q : R -> R -> Prop) x y, locally_2d (fun u v => locally_2d P u v -> Q u v) x y ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y -> locally_2d Q x y.
Proof.
(* Goal: forall (P Q : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d (fun u v : R => forall _ : locally_2d P u v, Q u v) x y) (_ : locally_2d P x y), locally_2d Q x y *)
intros P Q x y Li LP.
(* Goal: locally_2d Q x y *)
apply locally_2d_locally in Li.
(* Goal: P x y *)
apply locally_2d_locally in LP.
(* Goal: locally_2d Q x y *)
apply locally_locally in LP.
(* Goal: locally_2d Q x y *)
apply locally_2d_locally.
(* Goal: @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
generalize (filter_and _ _ Li LP).
(* Goal: forall _ : @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
apply filter_imp.
(* Goal: forall (x : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace)) (_ : and (forall _ : locally_2d P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x)) (@locally (prod_UniformSpace R_UniformSpace R_UniformSpace) x (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)))), Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) x) *)
intros [u v] [H1 H2].
(* Goal: Q (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) *)
apply H1.
(* Goal: locally_2d Q x y *)
now apply locally_2d_locally.
Qed.

Lemma locally_2d_singleton :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P : R -> R -> Prop) x y, locally_2d P x y -> P x y.
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d P x y), P x y *)
intros P x y LP.
(* Goal: P x y *)
apply locally_2d_locally in LP.
(* Goal: P x y *)
apply locally_singleton with (1 := LP).
Qed.

Lemma locally_2d_impl :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P Q : R -> R -> Prop) x y, locally_2d (fun u v => P u v -> Q u v) x y ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y -> locally_2d Q x y.
Proof.
(* Goal: forall (P Q : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d (fun u v : R => forall _ : P u v, Q u v) x y) (_ : locally_2d P x y), locally_2d Q x y *)
intros P Q x y (d,H).
(* Goal: forall _ : locally_2d P x y, locally_2d Q x y *)
apply locally_2d_impl_strong.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists d => u v Hu Hv Hp.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
apply H => //.
(* Goal: P u v *)
now apply locally_2d_singleton.
Qed.

Lemma locally_2d_forall :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P : R -> R -> Prop) x y, (forall u v, P u v) -> locally_2d P x y.
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : forall u v : R, P u v), locally_2d P x y *)
intros P x y Hp.
(* Goal: locally_2d P x y *)
now exists (mkposreal _ Rlt_0_1) => u v _ _.
Qed.

Lemma locally_2d_and :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P Q : R -> R -> Prop) x y, locally_2d P x y -> locally_2d Q x y ->
  locally_2d (fun u v => P u v /\ Q u v) x y.
Proof.
intros P Q x y H.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: locally_2d_impl.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: locally_2d_impl H.
apply locally_2d_forall.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
now split.
Qed.

Lemma locally_2d_align :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P Q : R -> R -> Prop) x y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ( forall eps : posreal, (forall u v, Rabs (u - x) < eps -> Rabs (v - y) < eps -> P u v) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    forall u v, Rabs (u - x) < eps -> Rabs (v - y) < eps -> Q u v ) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y -> locally_2d Q x y.
Proof.
(* Goal: forall (P Q : forall (_ : R) (_ : R), Prop) (x y : R) (_ : forall (eps : posreal) (_ : forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos eps)) (_ : Rlt (Rabs (Rminus v y)) (pos eps)), P u v) (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos eps)) (_ : Rlt (Rabs (Rminus v y)) (pos eps)), Q u v) (_ : locally_2d P x y), locally_2d Q x y *)
intros P Q x y K (d,H).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists d => u v Hu Hv.
(* Goal: Q u v *)
now apply (K d).
Qed.

Lemma locally_2d_1d_const_x :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P : R -> R -> Prop) x y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y ->
  locally y (fun t => P x t).
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d P x y), @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => P t y) *)
intros P x y (d,Hd).
(* Goal: is_upper_bound Q (Rmult d (Rinv (IZR (Zpos (xO xH))))) *)
exists d; intros z Hz.
(* Goal: P z y *)
apply Hd.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
rewrite Rminus_eq_0 Rabs_R0; apply cond_pos.
(* Goal: Rlt (Rabs (Rminus z x)) (pos d) *)
(* Goal: Rlt (Rabs (Rminus y y)) (pos d) *)
exact Hz.
Qed.

Lemma locally_2d_1d_const_y :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P : R -> R -> Prop) x y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y ->
  locally x (fun t => P t y).
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d P x y), @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => P t y) *)
intros P x y (d,Hd).
(* Goal: is_upper_bound Q (Rmult d (Rinv (IZR (Zpos (xO xH))))) *)
exists d; intros z Hz.
(* Goal: P z y *)
apply Hd.
(* Goal: Rlt (Rabs (Rminus z x)) (pos d) *)
(* Goal: Rlt (Rabs (Rminus y y)) (pos d) *)
exact Hz.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
rewrite Rminus_eq_0 Rabs_R0; apply cond_pos.
Qed.

Lemma locally_2d_1d_strong :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P : R -> R -> Prop) x y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d (fun u v => forall t, 0 <= t <= 1 ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    locally t (fun z => locally_2d P (x + z * (u - x)) (y + z * (v - y)))) x y.
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d P x y), locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y))))) x y *)
intros P x y.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
apply locally_2d_align => eps HP u v Hu Hv t Ht.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
assert (Zm: 0 <= Rmax (Rabs (u - x)) (Rabs (v - y))).
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rmax_case ; apply Rabs_pos.
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
destruct Zm as [Zm|Zm].
(* *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
assert (H1: Rmax (Rabs (u - x)) (Rabs (v - y)) < eps).
(* Goal: Rlt (Rmax (@norm K U (@plus (NormedModule.AbelianGroup K U) yu (@opp (NormedModule.AbelianGroup K U) xu))) (@norm K V (@plus (NormedModule.AbelianGroup K V) yv (@opp (NormedModule.AbelianGroup K V) xv)))) (Rmax (Rmult (@norm_factor K U) (pos eps)) (Rmult (@norm_factor K V) (pos eps))) *)
(* Goal: Rle (IZR Z0) (pos eps) *)
now apply Rmax_case.
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
set (d1 := mkposreal _ (Rlt_Rminus _ _ H1)).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
assert (H2: 0 < pos_div_2 d1 / Rmax (Rabs (u - x)) (Rabs (v - y))).
(* Goal: Rlt (IZR Z0) (Rmult (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: Rlt (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: not (@eq R (pos delta) (IZR Z0)) *)
(* Goal: Rle (IZR Z0) (Rinv (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
apply Rmult_lt_0_compat.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
apply cond_pos.
(* Goal: Rlt (IZR Z0) (Rinv (pos delta)) *)
(* Goal: Rlt (IZR Z0) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: Rlt (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: not (@eq R (pos delta) (IZR Z0)) *)
(* Goal: Rle (IZR Z0) (Rinv (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
now apply Rinv_0_lt_compat.
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
set (d2 := mkposreal _ H2).
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists d2 => z Hz.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists (pos_div_2 d1) => p q Hp Hq.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply HP.
(* . *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace (p - x) with (p - (x + z * (u - x)) + (z - t + t) * (u - x)) by ring.
(* Goal: Rlt (Rabs (Rplus (Rminus q (Rplus y (Rmult z (Rminus v y)))) (Rmult (Rplus (Rminus z t) t) (Rminus v y)))) (pos eps) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rle_lt_trans with (1 := Rabs_triang _ _).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace (pos eps) with (pos_div_2 d1 + (eps - pos_div_2 d1)) by ring.
(* Goal: Rlt (Rplus (Rabs (Rminus p (Rplus x (Rmult z (Rminus u x))))) (Rabs (Rmult (Rplus (Rminus z t) t) (Rminus u x)))) (Rplus (pos (pos_div_2 d1)) (Rminus (pos eps) (pos (pos_div_2 d1)))) *)
(* Goal: Rlt (Rabs (Rminus q y)) (pos eps) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rplus_lt_le_compat with (1 := Hp).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Rabs_mult.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
apply Rle_trans with ((d2 + 1) * Rmax (Rabs (u - x)) (Rabs (v - y))).
(* Goal: Rle (Rmult (Rabs (Rplus (Rminus z t) t)) (Rabs (Rminus v y))) (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs (Rminus u x)) *)
apply Rabs_pos.
(* Goal: Rle (IZR Z0) (Rabs (Rminus u x)) *)
apply Rabs_pos.
(* Goal: Rle (Rabs (Rplus (Rminus z t) t)) (Rplus (pos d2) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rle_trans with (1 := Rabs_triang _ _).
(* Goal: Rle (Rplus (Rabs (Rminus z t)) (Rabs t)) (Rplus (pos d2) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rplus_le_compat.
(* Goal: Rle (Rabs (Rminus z t)) (pos d2) *)
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now apply Rlt_le.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
now rewrite Rabs_pos_eq.
(* Goal: Rle MP (Rmax MP MQ) *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply Rmax_l.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /d2 /d1 /=.
(* Goal: Rle (Rmult (Rplus (Rdiv (Rdiv (Rminus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (Rdiv (Rminus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH))))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
field_simplify.
(* Goal: Rle (Rdiv (Rplus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH)))) (Rdiv (Rplus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH)))) *)
(* Goal: not (@eq R (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) (IZR Z0)) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rle_refl.
(* Goal: not (@eq R norm_factor (IZR Z0)) *)
now apply Rgt_not_eq.
(* . *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace (q - y) with (q - (y + z * (v - y)) + (z - t + t) * (v - y)) by ring.
(* Goal: Rlt (Rabs (Rplus (Rminus q (Rplus y (Rmult z (Rminus v y)))) (Rmult (Rplus (Rminus z t) t) (Rminus v y)))) (pos eps) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rle_lt_trans with (1 := Rabs_triang _ _).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace (pos eps) with (pos_div_2 d1 + (eps - pos_div_2 d1)) by ring.
(* Goal: Rlt (Rplus (Rabs (Rminus q (Rplus y (Rmult z (Rminus v y))))) (Rabs (Rmult (Rplus (Rminus z t) t) (Rminus v y)))) (Rplus (pos (pos_div_2 d1)) (Rminus (pos eps) (pos (pos_div_2 d1)))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rplus_lt_le_compat with (1 := Hq).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Rabs_mult.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
apply Rle_trans with ((d2 + 1) * Rmax (Rabs (u - x)) (Rabs (v - y))).
(* Goal: Rle (Rmult (Rabs (Rplus (Rminus z t) t)) (Rabs (Rminus v y))) (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs (Rminus u x)) *)
apply Rabs_pos.
(* Goal: Rle (IZR Z0) (Rabs (Rminus u x)) *)
apply Rabs_pos.
(* Goal: Rle (Rabs (Rplus (Rminus z t) t)) (Rplus (pos d2) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rle_trans with (1 := Rabs_triang _ _).
(* Goal: Rle (Rplus (Rabs (Rminus z t)) (Rabs t)) (Rplus (pos d2) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rplus_le_compat.
(* Goal: Rle (Rabs (Rminus z t)) (pos d2) *)
(* Goal: Rle (Rabs t) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rminus v y)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
(* Goal: Rle (Rmult (Rplus (pos d2) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (pos (pos_div_2 d1))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
now apply Rlt_le.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
now rewrite Rabs_pos_eq.
(* Goal: Rle MQ (Rmax MP MQ) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply Rmax_r.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /d2 /d1 /=.
(* Goal: Rle (Rmult (Rplus (Rdiv (Rdiv (Rminus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos xH))) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (Rminus (pos eps) (Rdiv (Rminus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH))))) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
field_simplify.
(* Goal: Rle (Rdiv (Rplus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH)))) (Rdiv (Rplus (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) (IZR (Zpos (xO xH)))) *)
(* Goal: not (@eq R (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) (IZR Z0)) *)
(* Goal: @locally R_UniformSpace t (fun z : UniformSpace.sort R_UniformSpace => locally_2d P (Rplus x (Rmult z (Rminus u x))) (Rplus y (Rmult z (Rminus v y)))) *)
apply Rle_refl.
(* Goal: not (@eq R norm_factor (IZR Z0)) *)
now apply Rgt_not_eq.
(* *)
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
apply filter_forall => z.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists eps => p q.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace (u - x) with 0.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
replace (v - y) with 0.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Rmult_0_r 2!Rplus_0_r.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply HP.
(* Goal: @eq R (IZR Z0) (Rminus u x) *)
apply sym_eq.
(* Goal: @eq R (Rminus u x) (IZR Z0) *)
apply Rabs_eq_0.
(* Goal: @eq R (Rabs (Rminus u x)) (IZR Z0) *)
apply Rle_antisym.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Zm.
(* Goal: Rle MQ (Rmax MP MQ) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply Rmax_r.
(* Goal: Rle (IZR Z0) (Rabs (Rminus u x)) *)
apply Rabs_pos.
(* Goal: @eq R (IZR Z0) (Rminus u x) *)
apply sym_eq.
(* Goal: @eq R (Rminus u x) (IZR Z0) *)
apply Rabs_eq_0.
(* Goal: @eq R (Rabs (Rminus u x)) (IZR Z0) *)
apply Rle_antisym.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite Zm.
(* Goal: Rle MP (Rmax MP MQ) *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
apply Rmax_l.
(* Goal: Rle (IZR Z0) (Rabs (Rminus u x)) *)
apply Rabs_pos.
Qed.

Lemma locally_2d_1d :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (P : R -> R -> Prop) x y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d (fun u v => forall t, 0 <= t <= 1 -> locally_2d P (x + t * (u - x)) (y + t * (v - y))) x y.
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : locally_2d P x y), locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
intros P x y H.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply locally_2d_1d_strong in H.
(* Goal: locally_2d (fun u v : R => forall (t : R) (_ : and (Rle (IZR Z0) t) (Rle t (IZR (Zpos xH)))), locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y)))) x y *)
apply: locally_2d_impl H.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
apply locally_2d_forall => u v H t Ht.
(* Goal: locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y))) *)
specialize (H t Ht).
(* Goal: locally_2d P (Rplus x (Rmult t (Rminus u x))) (Rplus y (Rmult t (Rminus v y))) *)
apply locally_singleton with (1 := H).
Qed.

Lemma locally_2d_ex_dec :
  forall P x y,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  (forall x y, P x y \/ ~P x y) ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally_2d P x y ->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  {d : posreal | forall u v, Rabs (u-x) < d -> Rabs (v-y) < d -> P u v}.
Proof.
(* Goal: forall (P : forall (_ : R) (_ : R), Prop) (x y : R) (_ : forall x0 y0 : R, or (P x0 y0) (not (P x0 y0))) (_ : locally_2d P x y), @sig posreal (fun d : posreal => forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v) *)
intros P x y P_dec H.
(* Goal: @sig posreal (fun d : posreal => forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v) *)
destruct (locally_ex_dec (x, y) (fun z => P (fst z) (snd z))) as [d Hd].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now intros [u v].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- destruct H as [e H].
(* Goal: @locally (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (fun z : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace) => P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) z)) *)
(* Goal: @sig posreal (fun d : posreal => forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v) *)
  exists e.
(* Goal: forall (y0 : UniformSpace.sort (prod_UniformSpace R_UniformSpace R_UniformSpace)) (_ : @ball (prod_UniformSpace R_UniformSpace R_UniformSpace) (@pair R R x y) (pos e) y0), P (@fst (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) y0) (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) y0) *)
(* Goal: @sig posreal (fun d : posreal => forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v) *)
  intros [u v] Huv.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: Rlt (Rabs (Rminus (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) y)) (pos e) *)
(* Goal: @sig posreal (fun d : posreal => forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v) *)
  apply Huv.
(* Goal: Rlt (Rabs (Rminus (@snd (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) (@pair (UniformSpace.sort R_UniformSpace) (UniformSpace.sort R_UniformSpace) u v)) y)) (pos e) *)
(* Goal: @sig posreal (fun d : posreal => forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v) *)
  apply Huv.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
exists d.
(* Goal: forall (u v : R) (_ : Rlt (Rabs (Rminus u x)) (pos d)) (_ : Rlt (Rabs (Rminus v y)) (pos d)), P u v *)
intros u v Hu Hv.
(* Goal: P u v *)
apply (Hd (u, v)).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
simpl.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
now split.
Qed.

(** * Some Topology on [Rbar] *)

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition Rbar_locally' (a : Rbar) (P : R -> Prop) :=
  match a with
    | Finite a => locally' a P
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    | p_infty => exists M : R, forall x, M < x -> P x
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    | m_infty => exists M : R, forall x, x < M -> P x
  end.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Definition Rbar_locally (a : Rbar) (P : R -> Prop) :=
  match a with
    | Finite a => locally a P
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    | p_infty => exists M : R, forall x, M < x -> P x
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    | m_infty => exists M : R, forall x, x < M -> P x
  end.

Global Instance Rbar_locally'_filter :
  forall x, ProperFilter (Rbar_locally' x).
Proof.
(* Goal: forall x : Rbar, @ProperFilter R (Rbar_locally' x) *)
intros [x| |] ; (constructor ; [idtac | constructor]).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P [eps HP].
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  exists (x + eps / 2).
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /ball /= /AbsRing_ball /abs /minus /plus /opp /=.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ring_simplify (x + eps / 2 + - x).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rabs_pos_eq.
(* Goal: Rlt (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (pos eps) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) (Rplus x (Rdiv (pos eps) (IZR (Zpos (xO xH))))) x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rminus_lt_0.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  replace (eps - eps / 2) with (eps / 2) by field.
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply is_pos_div_2.
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) (Rplus x (Rdiv (pos eps) (IZR (Zpos (xO xH))))) x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le, is_pos_div_2.
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) (Rplus x (Rdiv (pos eps) (IZR (Zpos (xO xH))))) x) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rgt_not_eq, Rminus_lt_0 ; ring_simplify.
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: Rbar_locally' (Finite x) (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' (Finite x) P) (_ : Rbar_locally' (Finite x) Q), Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply is_pos_div_2.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now exists (mkposreal _ Rlt_0_1).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q [dP HP] [dQ HQ].
(* Goal: Rbar_locally' (Finite x) (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  exists (mkposreal _ (Rmin_stable_in_posreal dP dQ)).
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  simpl.
(* Goal: forall (y : R) (_ : @ball R_UniformSpace x (Rmin (pos dP) (pos dQ)) y) (_ : not (@eq R y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  intros y Hy H.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP with (2 := H).
(* Goal: Rlt y MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le_trans with (1 := Hy).
(* Goal: Rle (Rmin MP MQ) MP *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_l.
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HQ with (2 := H).
(* Goal: Rlt y MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le_trans with (1 := Hy).
(* Goal: Rle (Rmin MP MQ) MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H [dP HP].
(* Goal: Rbar_locally' m_infty Q *)
  exists dP.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos dP) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), Q y *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  intros y Hy H'.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: P y *)
  now apply HP.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P [N HP].
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
  exists (N + 1).
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: Rlt N (Rplus N (IZR (Zpos xH))) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_plus_1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now exists 0.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q [MP HP] [MQ HQ].
(* Goal: Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  exists (Rmax MP MQ).
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: Rlt MQ y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rle_lt_trans with (2 := Hy).
(* Goal: Rle MP (Rmax MP MQ) *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmax_l.
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HQ.
(* Goal: Rlt MQ y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rle_lt_trans with (2 := Hy).
(* Goal: Rle MQ (Rmax MP MQ) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmax_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H [dP HP].
(* Goal: Rbar_locally' m_infty Q *)
  exists dP.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: P y *)
  now apply HP.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P [N HP].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  exists (N - 1).
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: Rlt (Rminus N (IZR (Zpos xH))) N *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_minus_l, Rlt_plus_1.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now exists 0.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q [MP HP] [MQ HQ].
(* Goal: Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  exists (Rmin MP MQ).
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
  split.
(* Goal: P y *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HP.
(* Goal: Rlt y MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le_trans with (1 := Hy).
(* Goal: Rle (Rmin MP MQ) MP *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_l.
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply HQ.
(* Goal: Rlt y MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rlt_le_trans with (1 := Hy).
(* Goal: Rle (Rmin MP MQ) MQ *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Rmin_r.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- intros P Q H [dP HP].
(* Goal: Rbar_locally' m_infty Q *)
  exists dP.
(* Goal: forall (x : R) (_ : Rlt x dP), Q x *)
  intros y Hy.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  apply H.
(* Goal: P y *)
  now apply HP.
Qed.

Global Instance Rbar_locally_filter :
  forall x, ProperFilter (Rbar_locally x).
Proof.
(* Goal: forall x : Rbar, @ProperFilter R (Rbar_locally x) *)
intros [x| |].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply locally_filter.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- exact (Rbar_locally'_filter p_infty).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- exact (Rbar_locally'_filter m_infty).
Qed.

(** Open sets in [Rbar] *)

Lemma open_Rbar_lt :
  forall y, open (fun u : R => Rbar_lt u y).
Proof.
(* Goal: forall y : Rbar, @open R_UniformSpace (fun u : R => Rbar_lt y (Finite u)) *)
intros [y| |].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply open_lt.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply open_true.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply open_false.
Qed.

Lemma open_Rbar_gt :
  forall y, open (fun u : R => Rbar_lt y u).
Proof.
(* Goal: forall y : Rbar, @open R_UniformSpace (fun u : R => Rbar_lt y (Finite u)) *)
intros [y| |].
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply open_gt.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply open_false.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- apply open_true.
Qed.

Lemma open_Rbar_lt' :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall x y, Rbar_lt x y -> Rbar_locally x (fun u => Rbar_lt u y).
Proof.
(* Goal: forall (x y : Rbar) (_ : Rbar_lt y x), Rbar_locally x (fun u : R => Rbar_lt y (Finite u)) *)
intros [x| |] y Hxy.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now apply open_Rbar_lt.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- easy.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- destruct y as [y| |].
(* Goal: @ex U (fun y : U => and (g x y) (P y)) *)
  now exists y.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  now apply filter_forall.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  easy.
Qed.

Lemma open_Rbar_gt' :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall x y, Rbar_lt y x -> Rbar_locally x (fun u => Rbar_lt y u).
Proof.
(* Goal: forall (x y : Rbar) (_ : Rbar_lt y x), Rbar_locally x (fun u : R => Rbar_lt y (Finite u)) *)
intros [x| |] y Hxy.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now apply open_Rbar_gt.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- destruct y as [y| |].
(* Goal: @ex U (fun y : U => and (g x y) (P y)) *)
  now exists y.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt p_infty (Finite u)) *)
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  easy.
(* Goal: Rbar_locally p_infty (fun u : R => Rbar_lt m_infty (Finite u)) *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  now apply filter_forall.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
- now destruct y as [y| |].
Qed.

Lemma Rbar_locally'_le :
  forall x, filter_le (Rbar_locally' x) (Rbar_locally x).
Proof.
(* Goal: P y *)
intros [x| |] P [eps HP] ; exists eps ; intros ; now apply HP.
Qed.

Lemma Rbar_locally'_le_finite :
  forall x : R, filter_le (Rbar_locally' x) (locally x).
Proof.
(* Goal: P y *)
intros x P [eps HP] ; exists eps ; intros ; now apply HP.
Qed.

(** * Some limits on real functions *)

Definition Rbar_loc_seq (x : Rbar) (n : nat) := match x with
(* Goal: forall (i j : nat) (_ : lt i m) (_ : lt j n), @eq T (u1 i j) (u2 i j) *)
    | Finite x => x + / (INR n + 1)
    | p_infty => INR n
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
    | m_infty => - INR n
  end.

Lemma filterlim_Rbar_loc_seq :
  forall x, filterlim (Rbar_loc_seq x) eventually (Rbar_locally' x).
Proof.
(* Goal: forall x : Rbar, @filterlim nat R (Rbar_loc_seq x) eventually (Rbar_locally' x) *)
  intros x P.
(* Goal: forall _ : Rbar_locally' x P, @filtermap nat R (Rbar_loc_seq x) eventually P *)
  unfold Rbar_loc_seq.
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: x => /= [x | | ] [delta Hp].
(* x \in R *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (nfloor_ex (/delta)) => [ | N [_ HN]].
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rlt_le, Rinv_0_lt_compat, delta.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  exists N => n Hn.
(* Goal: forall (y : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos (mkposreal (Rmin (pos dP) (pos dQ)) (Rmin_stable_in_posreal dP dQ))) y) (_ : not (@eq (UniformSpace.sort R_UniformSpace) y x)), and (P y) (Q y) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' (Finite x) P), Rbar_locally' (Finite x) Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' p_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' p_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' p_infty P) (_ : Rbar_locally' p_infty Q), Rbar_locally' p_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  apply Hp ; simpl.
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite /ball /= /AbsRing_ball /abs /minus /plus /opp /=.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  ring_simplify (x + / (INR n + 1) + - x).
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  rewrite Rabs_pos_eq.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Rinv_involutive delta).
(* Goal: Rlt (Rinv (Rplus (INR n) (IZR (Zpos xH)))) (Rinv (Rinv (pos delta))) *)
(* Goal: not (@eq R (pos delta) (IZR Z0)) *)
(* Goal: Rle (IZR Z0) (Rinv (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  apply Rinv_lt_contravar.
(* Goal: Rlt (IZR Z0) (Rmult (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: Rlt (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: not (@eq R (pos delta) (IZR Z0)) *)
(* Goal: Rle (IZR Z0) (Rinv (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  apply Rmult_lt_0_compat.
(* Goal: Rlt (IZR Z0) (Rinv (pos delta)) *)
(* Goal: Rlt (IZR Z0) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: Rlt (Rinv (pos delta)) (Rplus (INR n) (IZR (Zpos xH))) *)
(* Goal: not (@eq R (pos delta) (IZR Z0)) *)
(* Goal: Rle (IZR Z0) (Rinv (Rplus (INR n) (IZR (Zpos xH)))) *)
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  apply Rinv_0_lt_compat.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply delta.
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
  exact: INRp1_pos.
(* Goal: Rlt (Rmax (IZR Z0) (Ropp delta)) (INR n) *)
  apply Rlt_le_trans with (1 := HN).
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rplus_le_compat_r, le_INR.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rgt_not_eq, delta.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply Rlt_le, RinvN_pos.
(* Goal: not (@eq R (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  apply Rgt_not_eq, Rminus_lt_0.
(* Goal: Rlt (IZR Z0) (Rminus (Rplus x (Rinv (Rplus (INR n) (IZR (Zpos xH))))) x) *)
(* Goal: @filtermap nat R (fun n : nat => INR n) eventually P *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  ring_simplify.
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  by apply RinvN_pos.
(* x = p_infty *)
(* Goal: @filtermap nat R (fun n : nat => Ropp (INR n)) eventually P *)
  case: (nfloor_ex (Rmax 0 delta)) => [ | N [_ HN]].
(* Goal: Rle MP (Rmax MP MQ) *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  by apply Rmax_l.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  exists (S N) => n Hn.
(* Goal: P (Ropp (INR n)) *)
  apply Hp.
(* Goal: Rlt (Ropp delta) (INR n) *)
  apply Rle_lt_trans with (1 := Rmax_r 0 _).
(* Goal: Rlt (Rmax (IZR Z0) (Ropp delta)) (INR n) *)
  apply Rlt_le_trans with (1 := HN).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -S_INR ; by apply le_INR.
(* x = m_infty *)
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  case: (nfloor_ex (Rmax 0 (-delta))) => [ | N [_ HN]].
(* Goal: Rle MP (Rmax MP MQ) *)
(* Goal: Q y *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' p_infty P), Rbar_locally' p_infty Q *)
(* Goal: forall (P : forall _ : R, Prop) (_ : Rbar_locally' m_infty P), @ex R (fun x : R => P x) *)
(* Goal: Rbar_locally' m_infty (fun _ : R => True) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : Rbar_locally' m_infty P) (_ : Rbar_locally' m_infty Q), Rbar_locally' m_infty (fun x : R => and (P x) (Q x)) *)
(* Goal: forall (P Q : forall _ : R, Prop) (_ : forall (x : R) (_ : P x), Q x) (_ : Rbar_locally' m_infty P), Rbar_locally' m_infty Q *)
  by apply Rmax_l.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
  exists (S N) => n Hn.
(* Goal: P (Ropp (INR n)) *)
  apply Hp.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -(Ropp_involutive delta).
(* Goal: Rlt (Ropp (INR n)) (Ropp (Ropp delta)) *)
  apply Ropp_lt_contravar.
(* Goal: Rlt (Ropp delta) (INR n) *)
  apply Rle_lt_trans with (1 := Rmax_r 0 _).
(* Goal: Rlt (Rmax (IZR Z0) (Ropp delta)) (INR n) *)
  apply Rlt_le_trans with (1 := HN).
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  rewrite -S_INR ; by apply le_INR.
Qed.

Lemma continuity_pt_locally :
  forall f x,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  continuity_pt f x <->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall eps : posreal, locally x (fun u => Rabs (f u - f x) < eps).
Proof.
(* Goal: forall (f : forall _ : R, R) (x : R), iff (continuity_pt f x) (forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps))) *)
intros f x.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall (_ : continuity_pt f x) (eps : posreal), @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
intros H eps.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
move: (H eps (cond_pos eps)) => {H} [d [H1 H2]].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /= /R_dist /D_x /no_cond in H2.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists (mkposreal d H1) => y H.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
destruct (Req_dec x y) as [<-|Hxy].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
apply cond_pos.
(* Goal: Rle d (Rmult d (Rinv (IZR (Zpos (xO xH))))) *)
by apply H2.
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
intros H eps He.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
move: (H (mkposreal _ He)) => {H} [d H].
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
exists d.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
apply cond_pos.
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
intros h [Zh Hh].
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
exact: H.
Qed.

Lemma continuity_pt_locally' :
  forall f x,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  continuity_pt f x <->
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall eps : posreal, locally' x (fun u => Rabs (f u - f x) < eps).
Proof.
(* Goal: forall (f : forall _ : R, R) (x : R), iff (continuity_pt f x) (forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps))) *)
intros f x.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: forall (_ : continuity_pt f x) (eps : posreal), @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
intros H eps.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
move: (H eps (cond_pos eps)) => {H} [d [H1 H2]].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /= /R_dist /D_x /no_cond in H2.
(* Goal: @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
exists (mkposreal d H1) => y H H'.
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
destruct (Req_dec x y) as [<-|Hxy].
(* Goal: Rlt (Rabs (Rminus (f x) (f x))) (pos eps) *)
(* Goal: Rlt (Rabs (Rminus (f y) (f x))) (pos eps) *)
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
apply cond_pos.
(* Goal: Rle d (Rmult d (Rinv (IZR (Zpos (xO xH))))) *)
by apply H2.
(* Goal: forall _ : forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps)), continuity_pt f x *)
intros H eps He.
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
move: (H (mkposreal _ He)) => {H} [d H].
(* Goal: @ex R (fun alp : R => and (Rgt alp (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) alp)), Rlt (dist R_met (f x0) (f x)) eps)) *)
exists d.
(* Goal: and (Rgt (pos d) (IZR Z0)) (forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps) *)
split.
(* Goal: Rgt (pos d) (IZR Z0) *)
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
apply cond_pos.
(* Goal: forall (x0 : Base R_met) (_ : and (D_x no_cond x x0) (Rlt (dist R_met x0 x) (pos d))), Rlt (dist R_met (f x0) (f x)) eps *)
intros h [Zh Hh].
(* Goal: Rlt (dist R_met (f h) (f x)) eps *)
apply H.
(* Goal: @ball R_UniformSpace x (pos d) h *)
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) h x) *)
exact Hh.
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) h x) *)
apply proj2 in Zh.
(* Goal: not (@eq (UniformSpace.sort R_UniformSpace) h x) *)
now contradict Zh.
Qed.

Lemma continuity_pt_filterlim :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  forall (f : R -> R) (x : R),
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  continuity_pt f x <->
  filterlim f (locally x) (locally (f x)).
Proof.
(* Goal: forall (f : forall _ : R, R) (x : R), iff (continuity_pt f x) (forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps))) *)
intros f x.
eapply iff_trans.
apply continuity_pt_locally.
apply iff_sym.
exact (filterlim_locally f (f x)).
Qed.

Lemma continuity_pt_filterlim' :
  forall f x,
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  continuity_pt f x <->
  filterlim f (locally' x) (locally (f x)).
Proof.
(* Goal: forall (f : forall _ : R, R) (x : R), iff (continuity_pt f x) (forall eps : posreal, @locally' R_UniformSpace x (fun u : UniformSpace.sort R_UniformSpace => Rlt (Rabs (Rminus (f u) (f x))) (pos eps))) *)
intros f x.
eapply iff_trans.
apply continuity_pt_locally'.
apply iff_sym.
exact (filterlim_locally f (f x)).
Qed.

(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
Lemma locally_pt_comp (P : R -> Prop) (f : R -> R) (x : R) :
(* Goal: Rbar_locally m_infty (fun u : R => Rbar_lt y (Finite u)) *)
  locally (f x) P -> continuity_pt f x ->
  locally x (fun x => P (f x)).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (f x) P) (_ : continuity_pt f x), @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => P (f x)) *)
intros Lf Cf.
(* Goal: @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => P (f x)) *)
apply continuity_pt_filterlim in Cf.
(* Goal: @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => P (f x)) *)
now apply Cf.
Qed.
