\import Algebra.Group
\import Algebra.Meta
\import Algebra.Monoid
\import Algebra.Pointed
\import Arith.Rat
\import Arith.Real
\import Arith.Real.Extremes
\import Arith.Real.UpperReal
\import Data.Array
\import Data.Or
\import Equiv
\import Function
\import Function.Meta
\import Logic
\import Logic.Meta
\import Meta
\import Order.Biordered
\import Order.Lattice
\import Order.PartialOrder
\import Order.StrictOrder
\import Paths
\import Paths.Meta
\import Set
\import Set.Fin
\import Set.Fin.Instances
\import Set.Set
\import Topology.CoverSpace
\import Topology.CoverSpace.Complete
\import Topology.MetricSpace
\import Topology.NormedAbGroup.Real
\import Topology.TopAbGroup
\import Topology.TopSpace
\import Topology.UniformSpace
\open IsTotallyBounded(IsCover,Cond)
\open ClosurePrecoverSpace
\open AddGroup (negative-isInv)
\type IsTotallyBounded (X : CoverSpace) : \Prop
=> Cond X.isCauchy IsCover
\where {
\protected \func IsCover {X : \Set} (C : Set (Set X)) => \Pi (x : X) -> ∃ (U : C) (U x)
\protected \func Cond {X : \Set} (P Q : Set (Set (Set X))) => ∀ {C : P} ∃ (U : Array (Set X)) (Q \lam V => ∃ (W : U) (W = V)) (∀ (V : U) (C V))
}
\lemma totallyBounded-uniform {X : RegularPreuniformSpace} (Xp : X.IsProperUniform) (Xtb : IsTotallyBounded X) : Cond X.isCauchy isUniform
=> \lam Cc =>
\have | (inP (D,Dc,f)) => Xtb $ X.<=*-cauchy-regular Cc
| (inP g) => FinSet.finiteAC f
| (inP h) => FinSet.finiteAC (\lam j => (g j).3)
\in inP (\lam i => (g i).1, uniform-refine (Xp $ X.uniform-inter-big (\lam j => (h j).1) (\lam j => (h j).2)) \lam {W'} (EW', inP (x,W'x)) => \case Dc x \with {
| inP (_, inP (j,idp), Dx) => inP (_, inP (j,idp), \case Refines-inter-big (\lam j => (h j).1) j EW' \with {
| inP (W,hW,W'<=W) => W'<=W <=∘ Set.Union-cond (later (hW, (x, (Dx, W'<=W W'x)))) <=∘ (h j).3
})
}, \lam i => (g i).2)
\lemma totallyBounded-cauchy-uniform {X : RegularPreuniformSpace} (Xp : X.IsProperUniform) (Xtb : IsTotallyBounded X) {C : Set (Set X)} (Cc : isCauchy C) : isUniform C
=> \case totallyBounded-uniform Xp Xtb Cc \with {
| inP (U,Uu,CU) => uniform-refine Uu \lam {_} (inP (j,idp)) => inP (U j, CU j, <=-refl)
}
\lemma totallyBounded-strong-uniform {X : StronglyRegularPreuniformSpace} (Xp : X.IsWeaklyProperUniform) (Xtb : IsTotallyBounded X) : Cond X.isCauchy isUniform
=> \lam Cc =>
\have | (inP (V,Vc,g)) => Xtb $ X.s<=*-cauchy-regular Cc
| (inP h) => FinSet.finiteAC g
\in inP (\lam i => (h i).1, Xp $ uniform-refine (X.uniform-inter-big (\lam j W => (W = Compl (V j)) || (W = (h j).1)) (\lam j => (h j).3))
\lam {W} c => \case rewrite CoverInterBig-char in c \with {
| inP (Ws,We,W=Ws) => \case FinSet.finiteAC (\lam j => ||.toOr (We j)) \with {
| inP o => \case FinSet.searchFin (\lam j => \Sigma (p : Ws j = (h j).1) (o j = inr p)) (\lam j => cases (o j) \with {
| inl _ => no \lam q => \case q.2
| inr p => yes (p,idp)
}) \with {
| inl (j,(p,_),_) => inP (_, byRight $ inP (j,idp), rewrite (W=Ws, inv p) $ TopMeetSemilattice.BigMeet-cond {_} {Ws} j)
| inr f => inP (_, byLeft idp, \lam {x} Wx => \case Vc x \with {
| inP (_, inP (j,idp), Vjx) => \case f j (cases (o j) \with {
| inl q => \case (rewrite q in TopMeetSemilattice.BigMeet-cond {_} {Ws} j (rewrite W=Ws in Wx)) Vjx
| inr p => (p,idp)
})
})
}
}
}, \lam i => (h i).2)
\lemma totallyBounded-cauchy-strong-uniform {X : StronglyRegularPreuniformSpace} (Xp : X.IsWeaklyProperUniform) (Xtb : IsTotallyBounded X) {C : Set (Set X)} (Cc : isCauchy C) : isUniform C
=> \case totallyBounded-strong-uniform Xp Xtb Cc \with {
| inP (U,Uu,CU) => uniform-refine Uu \lam {_} (inP (j,idp)) => inP (U j, CU j, <=-refl)
}
\lemma totallyBounded-uniform-char {X : RegularPreuniformSpace} (base : Cond X.isUniform IsCover) : IsTotallyBounded X
=> \lam Cc => totallyBounded-closure base (uniform-cauchy.1 Cc)
\where {
\private \lemma totallyBounded-closure {X : PreuniformSpace} (base : Cond X.isUniform IsCover) {C : Set (Set X)} (Cc : Closure isUniform C)
: ∃ (D : Array (Set X)) (IsCover \lam V => ∃ (W : D) (W = V)) ∀ (V : D) (C V) \elim Cc
| closure Cu => base Cu
| closure-top idp => inP (top :: nil, \lam x => inP (top, inP (0, idp), ()), \lam (0) => idp)
| closure-refine Dc D<C => \case totallyBounded-closure base Dc \with {
| inP (U,Uc,DU) => \case FinSet.finiteAC (\lam j => D<C (DU j)) \with {
| inP V => inP (\lam j => (V j).1, \lam x => \case Uc x \with {
| inP (_, inP (j,idp), Ux) => inP (_, inP (j, idp), (V j).3 Ux)
}, \lam j => (V j).2)
}
}
| closure-trans {D} Dc {E} Ec idp => \case totallyBounded-closure base Dc \with {
| inP (V,Vc,DV) => \case FinSet.finiteAC (\lam j => totallyBounded-closure base $ Ec (DV j)) \with {
| inP W => \have e => SigmaFin.aux {_} {\lam i => (W i).1.len} \in inP
(\lam k => V (e k).1 ∧ (W (e k).1).1 (e k).2,
\lam x => \case Vc x \with {
| inP (_, inP (i,idp), Vx) => \case (W i).2 x \with {
| inP (_, inP (j,idp), Wx) => inP (_, inP (e.ret (i,j), idp), rewrite e.f_ret (Vx,Wx))
}
},
\lam k => inP (_, _, DV (e k).1, (W _).3 (e k).2, idp))
}
}
}
\type IsCompact (X : CompleteCoverSpace) : \Prop
=> IsTotallyBounded X
\lemma makeUniformMapTB {X Y : RegularPreuniformSpace} (Xp : X.IsProperUniform) (Xtb : IsTotallyBounded X) (f : CoverMap X Y) : UniformMap X Y f \cowith
| func-uniform Eu => totallyBounded-cauchy-uniform Xp Xtb $ f.func-cover $ Y.makeCauchy Eu
\lemma makeUniformMapSTB {X : StronglyRegularUniformSpace} {Y : RegularPreuniformSpace} (Xp : X.IsWeaklyProperUniform) (Xtb : IsTotallyBounded X) (f : CoverMap X Y) : UniformMap X Y f \cowith
| func-uniform Eu => totallyBounded-cauchy-strong-uniform Xp Xtb $ f.func-cover $ Y.makeCauchy Eu
\func IsTotallyBoundedSet {X : CoverSpace} (U : Set X) : \Prop
=> IsTotallyBounded $ CoverTransfer {\Sigma (x : X) (U x)} __.1
\lemma totallyBoundedSet-char {X : CoverSpace} {U : Set X}
: IsTotallyBoundedSet U <-> ∀ {C : isCauchy} ∃ (D : Array (Set X)) (∀ {x : U} ∃ (V : D) (V x)) (∀ (V : D) (C V))
=> (\lam f Cc => \case f $ func-cover {PrecoverTransfer-map {\Sigma (x : X) (U x)} __.1} Cc \with {
| inP (D,Dc,Dp) => \case FinSet.finiteAC Dp \with {
| inP g => inP (\lam j => (g j).1, \lam {x} Ux => \case Dc (x,Ux) \with {
| inP (_, inP (j,idp), Dx) => inP (j, rewrite (g j).3 in Dx)
}, \lam j => (g j).2)
}
}, \lam f Cc => \case f Cc \with {
| inP (D,Dc,Dp) => \case FinSet.finiteAC Dp \with {
| inP g => inP (\lam j => (g j).1, \lam x => \case Dc x.2 \with {
| inP (j,Dx) => inP (_, inP (j,idp), (g j).3 Dx)
}, \lam j => (g j).2)
}
})
\lemma totallyBoundedSet-subset {X : CoverSpace} {U V : Set X} (V<=U : V ⊆ U) (Utb : IsTotallyBoundedSet U) : IsTotallyBoundedSet V
=> totallyBoundedSet-char.2 \lam Cc => \case totallyBoundedSet-char.1 Utb Cc \with {
| inP (D,DU,CD) => inP (D, \lam Vx => DU (V<=U Vx), CD)
}
-- | A transferred cover structure is totally bounded if the map lands in a totally bounded set.
\lemma transfer-totallyBounded {X : \Set} {Y : CoverSpace} {f : X -> Y} {U : Set Y} (Utb : IsTotallyBoundedSet U) (fU : \Pi (x : X) -> U (f x))
: IsTotallyBounded (CoverTransfer f)
=> \lam Cc => \case totallyBoundedSet-char.1 Utb Cc \with {
| inP (D,DU,DC) => \case FinSet.finiteAC DC \with {
| inP g => inP (\lam j => (g j).1, \lam x => \case DU (fU x) \with {
| inP (j,Dfx) => inP (_, inP (j, idp), (g j).3 Dfx)
}, \lam j => (g j).2)
}
}
\lemma totallyBoundedSet-union {X : CoverSpace} {K L : Set X} (Ktb : IsTotallyBoundedSet K) (Ltb : IsTotallyBoundedSet L)
: IsTotallyBoundedSet (\lam x => K x || L x)
=> (totallyBoundedSet-char {X} {\lam x => K x || L x}).2 \lam Cc => \case totallyBoundedSet-char.1 Ktb Cc, totallyBoundedSet-char.1 Ltb Cc \with {
| inP (D,DK,DC), inP (D',DL,D'C) => inP (D ++ D', \case __ \with {
| byLeft Kx => \case DK Kx \with {
| inP (j,Dx) => inP (++.index-left j, rewrite (++.++_index-left {_} {D} {D'} j) Dx)
}
| byRight Lx => \case DL Lx \with {
| inP (j,Dx) => inP (++.index-right j, rewrite (++.++_index-right {_} {D} {D'} {j}) Dx)
}
}, \lam j => \case ++.split-index j \with {
| inl (i,p) => rewrite (p, ++.++_index-left) (DC i)
| inr (i,p) => rewrite (p, ++.++_index-right) (D'C i)
})
}
\lemma totallyBoundedSet-Union {X : CoverSpace} {n : Nat} {K : Fin n -> Set X} (Ktb : \Pi (j : Fin n) -> IsTotallyBoundedSet (K j))
: IsTotallyBoundedSet (\lam x => ∃ (j : Fin n) (K j x)) \elim n
| 0 => (totallyBoundedSet-char {X} {\lam x => ∃ (j : Fin 0) (K j x)}).2 \lam _ => inP (nil, \lam (inP ((),_)), \case __)
| suc n => totallyBoundedSet-subset {X} {\lam x => K 0 x || ∃ (i : Fin n) (K (suc i) x)} {\lam x => ∃ (j : Fin (suc n)) (K j x)} (\lam {x} e => \case e \with {
| inP (0, Kx) => byLeft Kx
| inP (suc j, Kx) => byRight (inP (j,Kx))
}) $ totallyBoundedSet-union {X} {K 0} {\lam x => ∃ (i : Fin n) (K (suc i) x)} (Ktb 0) (totallyBoundedSet-Union \lam j => Ktb (suc j))
\lemma totallyBoundedSet-image {X Y : CoverSpace} (f : CoverMap X Y) {U : Set X} (Utb : IsTotallyBoundedSet U) : IsTotallyBoundedSet (SetIm f U)
=> totallyBoundedSet-char.2 \lam Cc => \case totallyBoundedSet-char.1 Utb (f.func-cover Cc) \with {
| inP (D,DU,DC) => \case FinSet.finiteAC DC \with {
| inP g => inP (\lam j => (g j).1, \lam {y} (s : SetIm f U y) => \case \elim y, s \with {
| _, inP ((x,Ux),idp) => \case DU Ux \with {
| inP (j,Dx) => inP (j, rewrite (g j).3 in Dx)
}
}, \lam j => (g j).2)
}
}
\lemma totallyBoundedSet-uniform-char {X : RegularPreuniformSpace} {S : Set X}
: IsTotallyBoundedSet S <-> ∀ {C : isUniform} ∃ (D : Array (Set X)) (∀ {x : S} ∃ (V : D) (V x)) (∀ (V : D) (C V))
=> (\lam tb Cu => totallyBoundedSet-char.1 tb $ uniform-cauchy.2 $ closure Cu,
\lam tb => totallyBounded-uniform-char {RegularPreuniformTransfer __.1} \lam Cu => \case tb Cu \with {
| inP (D,g,h) => \case FinSet.finiteAC h \with {
| inP f => inP (\lam j => (f j).1, \lam x => \case g x.2 \with {
| inP (j,Dx) => inP (_, inP (j, idp), (f j).3 Dx)
}, \lam j => (f j).2)
}
})
\lemma totallyBoundedSet-metric-char {X : ExPseudoMetricSpace} {S : Set X}
: IsTotallyBoundedSet S <-> ∀ {eps : Rat} (0 < eps) ∃ (D : Array X) ∀ {x : S} ∃ (y : D) ((dist y x).U eps)
=> (\lam tb eps>0 => \case totallyBoundedSet-uniform-char.1 tb (X.metricUniform eps>0) \with {
| inP (D,DS,h) => \case FinSet.finiteAC h \with {
| inP g => inP (\lam j => (g j).1, \lam Sx => \case DS Sx \with {
| inP (j,Dx) => inP (j, rewrite (g j).2 in Dx)
})
}
}, \lam tb => totallyBoundedSet-uniform-char.2 \lam Cu => \case dist-uniform.1 Cu \with {
| inP (eps,eps>0,h) => \case tb eps>0 \with {
| inP (D,g) => \case FinSet.finiteAC (\lam j => h (D j)) \with {
| inP f => inP (\lam j => (f j).1, \lam Sx => \case g Sx \with {
| inP (j,d) => inP (j, (f j).3 d)
}, \lam j => (f j).2)
}
}
})
-- | The uniform interior of {E}: the sets of points whose stars with respect to a uniform cover lie in an element of {E}.
\func UniformInterior {X : PreuniformSpace} (E : Set (Set X)) : Set (Set X)
=> \lam S => ∃ (D : Set (Set X)) (isUniform D) (W : E) (S = \lam x => \Pi {V : Set X} -> D V -> V x -> V ⊆ W)
\lemma uniformInterior-cauchy {X : UniformSpace} {E : Set (Set X)} (Ec : isCauchy E) : isCauchy (UniformInterior E)
=> uniform-cauchy.2 $ aux $ uniform-cauchy.1 Ec
\where
\private \lemma aux {X : UniformSpace} {E : Set (Set X)} (Ec : Closure isUniform E) : Closure isUniform (UniformInterior E) \elim Ec
| closure Eu => closure \case uniform-star Eu \with {
| inP (D,Du,h) => uniform-refine Du \lam {V} DV => \case h DV \with {
| inP (U,EU,g) => inP (_, inP (D, Du, U, EU, idp), \lam {x} Vx {V'} DV' V'x => g DV' (x,(Vx,V'x)))
}
}
| closure-top p => closure-refine (closure-top idp) \lam {U} q => inP (\lam x => \Pi {V : Set X} -> single top V -> V x -> V ⊆ top,
inP (single top, uniform-top, top, rewrite p idp, idp), \lam _ _ _ _ => ())
| closure-refine Dc r => closure-refine (aux Dc) \lam {_} (inP (D',D'u,W,DW,idp)) => \case r DW \with {
| inP (W',EW',W<=W') => inP (_, inP (D', D'u, W', EW', idp), \lam f DV Vx => f DV Vx <=∘ W<=W')
}
| closure-trans {D} Dc {F} Fc idp => closure-refine (closure-trans (aux Dc)
{\lam S T => ∃ (D' : Set (Set X)) (isUniform D') (W : Set X) (D W) (S = \lam x => \Pi {V : Set X} -> D' V -> V x -> V ⊆ W) (UniformInterior (F W) T)}
(\lam {_} (inP (D',D'u,W,DW,idp)) => closure-refine (aux (Fc DW)) \lam {T} IT => inP (T, inP (D', D'u, W, DW, idp, IT), <=-refl)) idp)
\lam {_} (inP (S, T, _, inP (D1,D1u,W1,DW1,p1,inP (D2,D2u,W2,FW2,p2)), idp)) =>
inP (_, inP (_, uniform-inter D1u D2u, W1 ∧ W2, inP (W1, W2, DW1, FW2, idp), idp),
\lam {x} (Sx,Tx) {_} (inP (V1,DV1,V2,DV2,idp)) (V1x,V2x) =>
\have | s1 : \Pi {V : Set X} -> D1 V -> V x -> V ⊆ W1 => transport (__ x) p1 Sx
| s2 : \Pi {V : Set X} -> D2 V -> V x -> V ⊆ W2 => transport (__ x) p2 Tx
\in MeetSemilattice.meet-monotone (s1 DV1 V1x) (s2 DV2 V2x))
-- | Lebesgue number lemma: every Cauchy cover has a uniform Lebesgue cover on a totally bounded set.
\lemma totallyBounded-lebesgue {X : UniformSpace} {T : Set X} (Ttb : IsTotallyBoundedSet T) {E : Set (Set X)} (Ec : isCauchy E)
: ∃ (D : isUniform) ∀ {t : T} ∃ (W : E) ∀ {V : D} (V t -> V ⊆ W)
=> \case totallyBoundedSet-char.1 Ttb (uniformInterior-cauchy Ec) \with {
| inP (S,ST,SI) => \case FinSet.finiteAC SI \with {
| inP g => inP (_, X.uniform-inter-big (\lam j => (g j).1) (\lam j => (g j).2), \lam {t} Tt => \case ST Tt \with {
| inP (j,Sjt) => inP ((g j).3, (g j).4, \lam {V} DV Vt => \case Refines-inter-big (\lam j => (g j).1) j DV \with {
| inP (V',DjV',V<=V') =>
\have s : \Pi {V : Set X} -> (g j).1 V -> V t -> V ⊆ (g j).3 => transport (__ t) (g j).5 Sjt
\in V<=V' <=∘ s DjV' (V<=V' Vt)
})
})
}
}
-- | A cover map which is constant outside a totally bounded set is uniform.
\lemma totallyBounded-support-uniform {X : UniformSpace} (Xp : X.IsProperUniform) {Y : PseudoMetricSpace} {y0 : Y} {K : Set X} (Ktb : IsTotallyBoundedSet K)
(f : CoverMap X Y) (fK : \Pi {x : X} -> Not (K x) -> f x = y0) : UniformMap X Y f \cowith
| func-uniform Eu => \case Y.dist-uniform.1 Eu \with {
| inP (eps,eps>0,h) => \case totallyBounded-lebesgue Ktb (f.func-cover $ Y.makeCauchy $ Y.metricUniform {eps * ratio 1 4} linarith) \with {
| inP (D,Du,g) =>
\have | close {U : Set X} (DU : D U) {u z : X} (Uu : U u) (Uz : U z) (Ku : K u) : ldist (f u) (f z) < eps * ratio 1 2
=> \case g Ku \with {
| inP (_, inP (_, inP (c,idp), idp), p) => real_<_U.2 $ Y.halving-left (p DU Uu Uu) (p DU Uu Uz) linarith
}
| diam {U : Set X} (DU : D U) {u z : X} (Uu : U u) (Uz : U z) : ldist (f u) (f z) <= eps * ratio 1 2
=> \lam d => \have | nu : Not (K u) => \lam Ku => <-irreflexive (close DU Uu Uz Ku <∘ d)
| nz : Not (K z) => \lam Kz => <-irreflexive (rewrite ldist-symm in close DU Uz Uu Kz <∘ d)
| e : ldist (f u) (f z) = 0 => pmap2 ldist (fK nu) (fK nz) *> ldist-refl
\in <-irreflexive (rat_real_<.1 positivity <∘ transport (_ <) e d)
\in uniform-refine (Xp Du) \lam {U} (DU, inP (u,Uu)) => \case h (f u) \with {
| inP (V,EV,q) => inP (_, inP (V, EV, idp), \lam {z} Uz => q {f z} $ real_<_U.1 $ diam DU Uu Uz <∘r rat_real_<.1 (linarith : eps * ratio 1 2 < eps))
}
}
}
{- | Values of a cover map on a totally bounded subset of a proper uniform space are totally bounded with net points among values:
- for every Cauchy cover {E}, every value on {K} shares an element of {E} with one of finitely many values.
-}
\lemma totallyBoundedSet-net {X : UniformSpace} (Xp : X.IsProperUniform) {K : Set X} (Ktb : IsTotallyBoundedSet K)
{Y : CoverSpace} (f : CoverMap X Y) {E : Set (Set Y)} (Ec : isCauchy E)
: ∃ (l : Array X) ∀ {x : K} ∃ (j : Fin l.len) (W : E) (W (f x)) (W (f (l j)))
=> \case totallyBounded-lebesgue Ktb (f.func-cover Ec) \with {
| inP (D,Du,DL) => \case totallyBoundedSet-uniform-char.1 Ktb (Xp Du) \with {
| inP (V,VK,VD) => \case FinSet.finiteAC (\lam j => (VD j).2) \with {
| inP g => inP (\lam j => (g j).1, \lam {x} Kx => \case VK Kx, DL Kx \with {
| inP (j,Vjx), inP (_, inP (W,EW,idp), h) =>
\have s => h (VD j).1 Vjx
\in inP (j, W, EW, s Vjx, s (g j).2)
})
}
}
}
-- | The metric version of {totallyBoundedSet-net}: finite ε-nets of values.
\lemma totallyBoundedSet-metric-net {X : UniformSpace} (Xp : X.IsProperUniform) {K : Set X} (Ktb : IsTotallyBoundedSet K)
{Y : ExPseudoMetricSpace} (f : CoverMap X Y) {eps : Rat} (eps>0 : 0 < eps)
: ∃ (l : Array X) ∀ {x : K} ∃ (j : Fin l.len) ((dist (f x) (f (l j))).U eps)
=> \case totallyBoundedSet-net Xp Ktb f (Y.makeCauchy $ Y.metricUniform {eps * ratio 1 2} linarith) \with {
| inP (l,h) => inP (l, \lam Kx => \case h Kx \with {
| inP (j, _, inP (c,idp), d1, d2) => inP (j, Y.halving-left d1 d2 linarith)
})
}
-- | A cover map from an inhabited proper totally bounded uniform space to `ℝ` has a supremum (Bishop–Bridges, Ch. 2, Prop. 4.6).
\lemma totallyBounded-hasSup {X : UniformSpace} (Xp : X.IsProperUniform) (Xtb : IsTotallyBounded X) (x0 : X) (f : CoverMap X RealNormed)
: HasSup (\lam r => ∃ (x : X) (f x = r))
=> makeSupTB {\lam r => ∃ (x : X) (f x = r)} {f x0} (inP (x0, idp)) (values-net Xp Xtb f)
\where
-- | The values of {f} admit finite ε-nets consisting of values.
\lemma values-net {X : UniformSpace} (Xp : X.IsProperUniform) (Xtb : IsTotallyBounded X) (f : CoverMap X RealNormed) {eps : Real} (eps>0 : 0 < eps)
: ∃ (l : Array Real) (∀ (r : l) ∃ (x : X) (f x = r)) ∀ {r : \lam r => ∃ (x : X) (f x = r)} ∃ (y : l) (RealAbGroup.abs (r - y) < eps)
=> \case real_<-char.1 eps>0 \with {
| inP (e,e>0,e<eps) => \case totallyBoundedSet-metric-net Xp {top} top-totallyBounded f (rat_real_<.2 e>0) \with {
| inP (l,h) => inP (\lam j => f (l j), \lam j => inP (_, idp), \lam {r} => \case \elim r, __ \with {
| _, inP (x,idp) => \case h {x} () \with {
| inP (j,d) => inP (j, real_<_U.2 d <∘ e<eps)
}
})
}
}
\where
\lemma top-totallyBounded : IsTotallyBoundedSet {X} top
=> totallyBoundedSet-char.2 \lam Cc => \case Xtb Cc \with {
| inP (U,Uc,CU) => inP (U, \lam {x} _ => \case Uc x \with {
| inP (_, inP (j,idp), Ux) => inP (j, Ux)
}, CU)
}
-- | A cover map from an inhabited proper totally bounded uniform space to `ℝ` has an infimum (Bishop–Bridges, Ch. 2, Prop. 4.6).
\lemma totallyBounded-hasInf {X : UniformSpace} (Xp : X.IsProperUniform) (Xtb : IsTotallyBounded X) (x0 : X) (f : CoverMap X RealNormed)
: HasInf (\lam r => ∃ (x : X) (f x = r))
=> makeInfTB {\lam r => ∃ (x : X) (f x = r)} {f x0} (inP (x0, idp)) (totallyBounded-hasSup.values-net Xp Xtb f)
\type IsLocallyUniform {X : PreuniformSpace} (C : Set (Set X)) (E : Set (Set X)) : \Prop
=> ∀ {U : C} (isUniform \lam V => ∃ (W : E) (U ∧ V ⊆ W))
\type IsLocallyUniformSpace (X : PreuniformSpace) : \Prop
=> ∃ (C : X.isUniform) ∀ {E : X.isCauchy} (IsLocallyUniform C E)
\lemma locallyUniform-cauchy {X : PreuniformSpace} {C : Set (Set X)} (Cc : isCauchy C) (E : Set (Set X)) (lu : IsLocallyUniform C E) : isCauchy E
=> cauchy-glue-refine Cc \lam CU => X.makeCauchy (lu CU)
\lemma locallyUniform-cover-char {X : StronglyRegularUniformSpace} {C : Set (Set X)} (Cb : ∀ {U : C} (IsTotallyBoundedSet U)) (Cp : ∀ {U : C} ∃ U) {E : Set (Set X)} (Ec : isCauchy E) : IsLocallyUniform C E
=> \lam {U} CU =>
\have Du => totallyBounded-cauchy-strong-uniform {StronglyRegularUniformTransfer {\Sigma (x : X) (U x)} __.1} (PreuniformSpace.inhabited_weaklyProper $ Cp CU) (Cb CU) (PrecoverTransfer.makeCauchy Ec)
\in uniform-subset Du \lam {V} (inP (_, inP (W,EW,idp), p)) => inP $ later (W, EW, \lam {x} (Ux,Vx) => p {x,Ux} Vx)
\lemma locallyTotallyBounded-locallyUniform {X : StronglyRegularUniformSpace} (Xltb : X.isUniform IsTotallyBoundedSet) (Xd : X.IsProperUniform) : IsLocallyUniformSpace X
=> inP (\lam U => \Sigma (IsTotallyBoundedSet U) (∃ U), Xd Xltb, locallyUniform-cover-char (later __.1) (later __.2))
\type BallsTotallyBounded (X : ExPseudoMetricSpace) : \Prop
=> \Pi (x : X) {eps : Rat} -> 0 < eps -> IsTotallyBoundedSet (OBall eps x)
-- | A surjective isometry transfers total boundedness of balls.
\lemma ballsTB-isometry (f : IsometricMap) (fs : IsSurj f) (Xb : BallsTotallyBounded f.Dom) : BallsTotallyBounded f.Cod
=> \lam y {B} B>0 => \case \elim y, fs y \with {
| y, inP (x,idp) => totallyBoundedSet-metric-char.2 \lam {eps} eps>0 => \case totallyBoundedSet-metric-char.1 (Xb x B>0) eps>0 \with {
| inP (D,h) => inP (\new Array f.Cod D.len \lam i => f (D i), \lam {z} d => \case \elim z, fs z, \elim d \with {
| z, inP (w,idp), d => \case h {w} (transport (UpperReal.U {__} B) f.func-isometry d) \with {
| inP (i,p) => inP (i, transportInv (ExUpperReal.U {__} eps) f.func-isometry p)
}
})
}
}
\lemma metric-locallyUniform {X : PseudoMetricSpace} (Xbtb : BallsTotallyBounded X) : IsLocallyUniformSpace X
=> locallyTotallyBounded-locallyUniform (uniform-subset (X.metricUniform RatField.zro<ide) $ later \lam {_} (inP (x,idp)) => Xbtb x RatField.zro<ide) X.metricProperUniform
-- | Every Cauchy cover is uniform on {T}.
\type IsCauchyUniformSet {X : PreuniformSpace} (T : Set X) : \Prop
=> ∀ {E : X.isCauchy} (isUniform \lam V => ∃ (W : E) (T ∧ V ⊆ W))
\lemma cauchyUniformSet-subset {X : PreuniformSpace} {S T : Set X} (S<=T : S ⊆ T) (Tc : IsCauchyUniformSet T) : IsCauchyUniformSet S
=> \lam Ec => uniform-subset (Tc Ec) \lam {V} (inP (W,EW,p)) => inP $ later (W, EW, \lam {x} (Sx,Vx) => p (S<=T Sx, Vx))
\lemma totallyBoundedSet-cauchyUniform {X : StronglyRegularUniformSpace} {T : Set X} (Ttb : IsTotallyBoundedSet T) (Tp : ∃ T) : IsCauchyUniformSet T
=> \lam Ec => locallyUniform-cover-char {X} {\lam U => U = T} (\lam p => rewrite p Ttb) (\lam p => rewrite p Tp) Ec idp
-- | In a metric space, totally bounded sets are Cauchy-uniform; unlike {totallyBoundedSet-cauchyUniform}, this does not require {T} to be inhabited.
\lemma totallyBoundedSet-cauchyUniform-metric {X : PseudoMetricSpace} {T : Set X} (Ttb : IsTotallyBoundedSet T) : IsCauchyUniformSet T
=> \case totallyBoundedSet-metric-char.1 Ttb RatField.zro<ide \with {
| inP (nil, g) => \lam Ec => uniform-subset (X.metricUniform RatField.zro<ide) $ later \lam {_} (inP (x,idp)) => \case cauchy-cover Ec x \with {
| inP (W,EW,_) => inP $ later (W, EW, \lam {y} (Ty,_) => \case g Ty \with {
| inP ((),_)
})
}
| inP (:: x0 _, _) => cauchyUniformSet-subset (\lam Tx => byLeft Tx) $ totallyBoundedSet-cauchyUniform {X} {\lam x => T x || (x = x0)} (insert-tb x0 Ttb) (inP (x0, byRight idp))
}
\where {
\lemma insert-tb {X : ExPseudoMetricSpace} {T : Set X} (x0 : X) (Ttb : IsTotallyBoundedSet T) : IsTotallyBoundedSet (\lam x => T x || (x = x0))
=> (totallyBoundedSet-metric-char {X} {\lam x => T x || (x = x0)}).2 \lam eps>0 => \case totallyBoundedSet-metric-char.1 Ttb eps>0 \with {
| inP (D,g) => inP (x0 :: D, \lam {x} h => \case \elim h \with {
| byLeft Tx => \case g Tx \with {
| inP (j,d) => inP (suc j, d)
}
| byRight p => inP (0, rewrite p (OBall-center eps>0))
})
}
}
-- | A totally bounded set in a pseudometric space is contained in a ball around any given point.
\lemma totallyBoundedSet-bounded {X : PseudoMetricSpace} {T : Set X} (Ttb : IsTotallyBoundedSet T) (x0 : X) : ∃ (B : Rat) ∀ {x : T} (OBall B x0 x)
=> \case totallyBoundedSet-char.1 Ttb (X.makeCauchy (X.metricUniform {1} RatField.zro<ide)) \with {
| inP (D,DT,DC) => \case FinSet.finiteAC DC \with {
| inP g => \case FinSet.finiteAC (\lam j => Real.U-inh {X.dist x0 (g j).1}) \with {
| inP b => inP (RatField.BigSum (\lam j => (b j).1 ∨ 0) + 1, \lam {x} Tx => \case DT Tx \with {
| inP (j,Djx) => X.halving (b j).2 (transport (__ x) (g j).2 Djx) $
RatField.<=_+ (join-left <=∘ RatField.BigSum_>=index {\lam j => (b j).1 ∨ 0} (\lam _ => join-right) j) <=-refl
})
}
}
}
-- | In a space with totally bounded balls, bounded sets are totally bounded.
\lemma ballsTB-totallyBounded {X : ExPseudoMetricSpace} (Xb : BallsTotallyBounded X) {T : Set X} (Tb : IsBoundedSet T) : IsTotallyBoundedSet T \elim Tb
| inP (x0,B,h) =>
\have B'>0 : 0 < B ∨ 1 => RatField.zro<ide <∘l join-right
\in totallyBoundedSet-subset (\lam Tx => ExUpperReal.U_<= (h Tx) join-left) (Xb x0 B'>0)
\lemma locallyUniformMapFromCover {X Y : RegularPreuniformSpace} (Xlu : IsLocallyUniformSpace X) (f : CoverMap X Y) : LocallyUniformMap X Y f \cowith
| func-locally-uniform Eu => \case Xlu \with {
| inP (C,Cu,h) => inP (C, Cu, \lam CU => uniform-subset (h (f.func-cover (Y.makeCauchy Eu)) CU) \lam {V} (inP (_, inP (W,EW,idp), p)) => inP $ later (W, EW, p))
}
-- | A cover map from a space with totally bounded balls is uniform on balls.
\lemma cover-uniform-ball {X : PseudoMetricSpace} {Y : ExPseudoMetricSpace} (Xb : BallsTotallyBounded X) (g : CoverMap X Y) (x0 : X) {R eps : Rat} (R>0 : 0 < R) (eps>0 : 0 < eps)
: ∃ (d : Rat) (0 < d) ∀ {x y : X} (OBall R x0 x) (OBall R x0 y) ((dist x y).U d -> (dist (g x) (g y)).U eps)
=> \have | e>0 : 0 < eps * ratio 1 2 => positivity
| Ec => g.func-cover (Y.makeCauchy (Y.metricUniform e>0))
| lu => locallyUniform-cover-char {X} {\lam U => U = OBall R x0} (\lam p => rewrite p (Xb x0 R>0)) (\lam p => rewrite p $ inP (x0, OBall-center R>0)) Ec idp
\in \case dist-uniform.1 lu \with {
| inP (d,d>0,h) => inP (d, d>0, \lam {x} {y} Bx By xy<d => \case h x \with {
| inP (V, inP (_, inP (_, inP (t,idp), idp), q), g') => Y.halving1/2 (q (Bx, g' (OBall-center {X} d>0))) (q (By, g' xy<d))
})
}
\type IsLocallyTotallyBounded (X : CoverSpace) : \Prop
=> X.isCauchy IsTotallyBoundedSet
\type IsLocallyCompact (X : CompleteCoverSpace) : \Prop
=> IsLocallyTotallyBounded X
\lemma topAddGroup-locallyTB-char {A : TopAddGroup} : IsLocallyTotallyBounded A <-> ∃ (U : Set A) (isOpen U) (U 0) (IsTotallyBoundedSet U)
=> (\lam Altb => \case A.cauchy-regular-cover Altb 0 \with {
| inP (U,Utb,x<=<U) => inP (_, A.interior, x<=<U, totallyBoundedSet-subset (<=<_<= __ idp) Utb)
}, \lam (inP (U,Uo,U0,Utb)) => cauchy-subset (uniform-cauchy.2 $ closure $ A.topAddUniform Uo U0) \lam {_} (inP (x,idp)) =>
totallyBoundedSet-subset (later \lam {y} (u,_) => inP ((negative x + y, u), simplify)) $ totallyBoundedSet-image (A.leftTranslation x) Utb)
-- | A net of a totally bounded set.
\lemma addGroup-tb-char {A : TopAddGroup} {K : Set A}
: IsTotallyBoundedSet K <-> ∀ {U : Set A} (Uo : isOpen U) (U0 : U 0) ∃ (a : Array A) ∀ {x : K} ∃ (j : Fin a.len) (A.AreClose U (a j) x)
=> (\lam Ktb Uo U0 => \case totallyBoundedSet-uniform-char.1 Ktb (A.topAddUniform Uo U0) \with {
| inP (D,DK,DC) => \case FinSet.finiteAC DC \with {
| inP g => inP (\lam j => (g j).1, \lam Kx => \case DK Kx \with {
| inP (j,Dx) => inP (j, rewrite (g j).2 in Dx)
})
}
}, \lam h => totallyBoundedSet-uniform-char.2 \lam Cu => \case A.neighborhood-uniform.1 Cu \with {
| inP (U,Uo,U0,g) => \case h Uo U0 \with {
| inP (a,ac) => \case FinSet.finiteAC (\lam j => g (a j)) \with {
| inP V => inP (\lam j => (V j).1, \lam Kx => \case ac Kx \with {
| inP (j,c) => inP (j, (V j).3 c.1 c.2)
}, \lam j => (V j).2)
}
}
})
\lemma addGroup-tb-negative {A : TopAddGroup} {K : Set A} (Ktb : IsTotallyBoundedSet K) : IsTotallyBoundedSet (\lam x => K (negative x))
=> transport IsTotallyBoundedSet
(ext \lam x => ext (SetIm-elim \lam Ka => transportInv K negative-isInv Ka,
\lam K-x => transport (SetIm negative K) negative-isInv (SetIm-con K-x)))
(totallyBoundedSet-image negative-uniform Ktb)
\lemma addGroup-tb-left {A : TopAddGroup} (a : A) {K : Set A} (Ktb : IsTotallyBoundedSet K) : IsTotallyBoundedSet (\lam x => K (a + x))
=> transport IsTotallyBoundedSet
(ext \lam x => ext (SetIm-elim \lam {y} Ky => transport K equation.addGroup Ky,
\lam Ka+x => transport (SetIm (negative a +) K) equation.addGroup (SetIm-con Ka+x)))
(totallyBoundedSet-image (A.leftTranslation (negative a)) Ktb)
-- | Conjugation by points of a totally bounded set is uniformly continuous at `0`.
\lemma addGroup-tb-conj {A : TopAddGroup} {K : Set A} (Ktb : IsTotallyBoundedSet K) {V : Set A} (Vo : isOpen V) (V0 : V 0)
: ∃ (W : isOpen) (W 0) ∀ {x : K} {w : W} (V (x + w - x))
=> \case A.shrink3 Vo V0 \with {
| inP (U,Uo,U0,Us,h) => \case addGroup-tb-char.1 Ktb Uo U0 \with {
| inP (a,ac) => \case A.neighborhood-finite (\lam j => A.neighborhood-conj (a j) Uo) (\lam j => A.neighborhood-conj0 (a j) {U} U0) \with {
| inP (W,Wo,W0,g) => inP (W, Wo, W0, \lam {x} Kx {w} Ww => \case ac Kx \with {
| inP (j,c) => transport V simplify (h c.2 (g Ww j) (Us c.2))
})
}
}
}
-- | Addition is uniformly continuous on products of totally bounded sets.
\lemma addGroup-tb-+-close {A : TopAddGroup} {K L : Set A} (Ktb : IsTotallyBoundedSet K) (Ltb : IsTotallyBoundedSet L) {V : Set A} (Vo : isOpen V) (V0 : V 0)
: ∃ (W : isOpen) (W 0) (\Pi {x : A} -> W x -> W (negative x)) ∀ {x : K} {y : L} {x' y' : A} (A.AreClose W x x') (A.AreClose W y y') (A.AreClose V (x + y) (x' + y'))
=> \case A.shrink2 Vo V0 \with {
| inP (U,Uo,U0,_,h) => \case addGroup-tb-conj Ktb Uo U0, addGroup-tb-conj (addGroup-tb-negative Ltb) Uo U0 \with {
| inP (W1,W1o,W10,g1), inP (W2,W2o,W20,g2) => \case A.neighborhood-sym (open-inter Uo (open-inter W1o W2o)) (U0,(W10,W20)) \with {
| inP (W,Wo,W0,Ws,W<=) => inP (W, Wo, W0, Ws, \lam {x} Kx {y} Ly {x'} {y'} c1 c2 =>
(transport V equation.addGroup (h (g2 (transportInv L negative-isInv Ly) (W<= c1.1).2.2) (W<= c2.1).1),
transport V equation.addGroup (h (W<= c1.2).1 (g1 Kx (W<= c2.2).2.1))))
}
}
}
-- | The set `K + L` is totally bounded.
\lemma addGroup-tb-+ {G : TopAddGroup} {K L : Set G} (Ktb : IsTotallyBoundedSet K) (Ltb : IsTotallyBoundedSet L)
: IsTotallyBoundedSet (\lam z => ∃ (x : K) (y : L) (x + y = z))
=> (addGroup-tb-char {G} {\lam z => ∃ (x : K) (y : L) (x + y = z)}).2 \lam {U} Uo U0 => \case G.neighborhood-sym Uo U0 \with {
| inP (V,Vo,V0,Vs,V<=U) => \case addGroup-tb-+-close Ktb Ltb Vo V0 \with {
| inP (W,Wo,W0,Ws,h) => \case addGroup-tb-char.1 Ktb Wo W0, addGroup-tb-char.1 Ltb Wo W0 \with {
| inP (a,ac), inP (b,bc) => inP (\lam k => a (ProdFin.prod_equiv k).1 + b (ProdFin.prod_equiv k).2, \lam {z} (inP (x,Kx,y,Ly,p)) => \case ac Kx, bc Ly \with {
| inP (i,ci), inP (j,cj) => inP (ProdFin.prod_equiv.ret (i,j), rewrite (ProdFin.prod_equiv.f_ret (i,j)) $ rewrite p in
G.close-mono V<=U (G.close-symm Vs (h Kx Ly (G.close-symm Ws ci) (G.close-symm Ws cj))))
})
}
}
}
-- | One-sided uniform continuity: if `f` vanishes outside a totally bounded set {K} and {W} is its modulus for `eps`, then `V` is a modulus for left and right translations.
\lemma addGroup-tb-translation-modulus {A : TopAddGroup} {K : Set A} (Ktb : IsTotallyBoundedSet K) {W : Set A} (Wo : isOpen W) (W0 : W 0)
: ∃ (V : isOpen) (V 0) (\Pi {v : A} -> V v -> V (negative v)) ∀ {f : A -> Real} {eps : Real}
(\Pi {x : A} -> Not (K x) -> f x = 0) (\Pi {x y : A} -> A.AreClose W x y -> RealAbGroup.abs (f x - f y) <= eps)
(\Pi (x : A) {v : A} -> V v -> \Sigma (RealAbGroup.abs (f (x + v) - f x) <= eps) (RealAbGroup.abs (f (v + x) - f x) <= eps))
=> \case addGroup-tb-conj Ktb Wo W0, addGroup-tb-conj (addGroup-tb-negative Ktb) Wo W0 \with {
| inP (W1,W1o,W10,g1), inP (W2,W2o,W20,g2) => \case A.neighborhood-sym (open-inter Wo (open-inter W1o W2o)) (W0,(W10,W20)) \with {
| inP (V,Vo,V0,Vs,V<=) => inP (V, Vo, V0, Vs, \lam {f} {eps} fK fW x {v} Vv =>
\have | e0 : 0 <= eps => transport (__ <= eps) (pmap RealAbGroup.abs negative-right *> RealAbGroup.abs_zro) (fW (A.close-refl {W} W0 {x}))
| contr {a b : A} (na : Not (K a)) (nb : Not (K b)) (d : eps < RealAbGroup.abs (f b - f a)) : Empty
=> \have q : RealAbGroup.abs (f b - f a) = 0 => rewrite (fK na, fK nb) (pmap RealAbGroup.abs negative-right *> RealAbGroup.abs_zro)
\in <-irreflexive (e0 <∘r transport (eps <) q d)
| c1-left : W (negative x + (x + v)) => transportInv W simplify (V<= Vv).1
| c2-right : W (v + x - x) => transportInv W simplify (V<= Vv).1
\in (\lam d => contr (\lam Kx => fW (c1-left, g1 Kx (V<= Vv).2.1) (rewrite RealAbGroup.abs_- in d))
(\lam Kxv => fW (c1-left, transport W equation.addGroup (g1 Kxv (V<= Vv).2.1)) (rewrite RealAbGroup.abs_- in d)) d,
\lam d => contr (\lam Kx => fW (transport W equation.addGroup (g2 (transportInv K negative-isInv Kx) (V<= Vv).2.2), c2-right) (rewrite RealAbGroup.abs_- in d))
(\lam Kvx => fW (transport W equation.addGroup (g2 (transportInv K negative-isInv Kvx) (V<= Vv).2.2), c2-right) (rewrite RealAbGroup.abs_- in d)) d))
}
}