{- | Cover maps `ℝⁿ -> ℝ` with compact support and the embedding {iota} to the Lebesgue integral `L¹(ℝⁿ)`.
-
- An approximant of `g` is a rational step function close to `g` at rational points, see {IsApprox}.
- Approximants exist by uniform continuity, and {iota} is their limit.
-}
\import Algebra.Group
\import Algebra.Group.GroupHom
\import Algebra.Meta
\import Algebra.Monoid
\import Algebra.Ordered
\import Algebra.StrictlyOrdered
\import Algebra.Pointed
\import Analysis.Integration.IntegrationSpace
\import Analysis.Integration.MeasureIntegrationSpace
\import Analysis.Measure.Lebesgue
\import Analysis.Measure.MeasureRing
\import Analysis.Measure.SimpleFunctions
\import Analysis.Measure.RatSFunc
\import Arith.Rat
\import Arith.Real
\import Arith.Real.Field
\import Arith.Real.UpperReal
\import Data.Array
\import Data.Bool
\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.Fin
\import Set.Set
\import Topology.Compact
\import Topology.Compact.CompactSupport
\import Topology.CoverSpace
\import Topology.CoverSpace.Complete
\import Topology.MetricSpace
\import Topology.MetricSpace.Complete
\import Topology.NormedAbGroup
\import Topology.NormedAbGroup.NormedProduct
\import Topology.NormedAbGroup.Real
\import Topology.CoverSpace.Product
\open SFunc (inSF)
\open SFuncRepr (IsReduced)
-- | The radius of a ball containing the cube `[-R,R)ⁿ`.
\func cubeRad (n : Nat) (R : Rat) : Rat
=> RatField.natCoef n * R
\lemma cube-in {n : Nat} {R : Rat} {z : Array Rat n} (h : lebPts n (ratCube n R) z = true) : lnorm {RealN n} (ratPt z) <= cubeRad n R
=> \have b (j : Fin n) : RealAbGroup.abs (Real.fromRat (z j)) <= Real.fromRat R
=> \have (c1,c2) => ratCube-char.1 h j
\in rewrite RealAbGroup.abs-rat $ rat_real_<=.1 $ RatField.join-univ (<=-less c2) linarith
\in RealAbGroup.BigSum_<= {n} {\lam j => RealAbGroup.abs (Real.fromRat (z j))} {replicate n (Real.fromRat R)} b <=∘ =_<= (RealField.BigSum_replicate *> RealField.*-rat)
\lemma cube-out {n : Nat} {R : Rat} {z : Array Rat n} (h : lebPts n (ratCube n R) z = false) : Real.fromRat R <= lnorm {RealN n} (ratPt z)
=> \lam (q : lnorm {RealN n} (ratPt z) < Real.fromRat R) => \case inv h *> ratCube-char.2 (\lam j =>
\have | i : RealAbGroup.abs (Real.fromRat (z j)) <= lnorm {RealN n} (ratPt z)
=> RealAbGroup.BigSum_>=index {\lam j => RealAbGroup.abs (Real.fromRat (z j))} (\lam j => lnorm>=0 {RealNormed}) j
| a : RatField.abs (z j) < R => rat_real_<.2 $ transport (< _) RealAbGroup.abs-rat (i <∘r q)
| a1 : z j <= RatField.abs (z j) => RatField.abs>=id
| a2 : negative (z j) <= RatField.abs (z j) => RatField.abs>=neg
\in (linarith, linarith)) \with {}
-- | A function in `C_c(ℝⁿ)` vanishes outside a ball.
\lemma ball-support {n : Nat} (g : CompactCoverMap (RealN n)) : ∃ (R : Rat) ∀ {x : RealN n} (Real.fromRat R < lnorm x) (g x = 0)
=> \case g.support \with {
| inP (K,Ktb,gK) => \case totallyBoundedSet-bounded Ktb 0 \with {
| inP (B,h) => inP (B, \lam {x} r => IsSupported.vanish gK \lam Kx =>
<-irreflexive $ r <∘ transport (__ < _) (ldist_zro-left {RealN n}) (real_<_U.2 (h Kx)))
}
}
-- | A function on `ℝⁿ` vanishing outside a ball has totally bounded support.
\lemma ball-supported {n : Nat} {g : RealN n -> Real} (h : ∃ (R : Rat) ∀ {x : RealN n} (Real.fromRat R < lnorm x) (g x = 0))
: ∃ (K : Set (RealN n)) (IsTotallyBoundedSet K) (IsSupported g K) \elim h
| inP (R,g0) => inP (OBall {RealN n} (R + 1) 0, ballsTB-totallyBounded (RealN-ballsTB n) (inP (0, R + 1, \lam p => p)), \lam {x} gx>0 =>
\case Real.LU-located {lnorm x} {R} {R + 1} linarith \with {
| byLeft l => absurd $ <-irreflexive $ transport (\lam y => 0 < RealAbGroup.abs y) (g0 (real_<_L.2 l)) gx>0 <∘l =_<= RealAbGroup.abs_zro
| byRight u => real_<_U.1 $ transportInv (< _) (ldist_zro-left {RealN n}) (real_<_U.2 u)
})
-- | {s} is {e}-close to {g} at the rational points of {K} and equal to {g} at other rational points.
\type IsApprox {n : Nat} (g : RealN n -> Real) (K : LebesgueRing0 n) (e : Rat) (s : SFuncIntegrationSpace (LebesgueRing0 n)) : \Prop
=> \Pi (z : Array Rat n) -> RealAbGroup.abs (g (ratPt z) - stepEval z s) <= if (lebPts n K z) e 0
-- | Approximants of a cover map with compact support exist.
\lemma approx-exists {n : Nat} (g : CoverMap (RealN n) RealNormed) {R : Rat} (gR : \Pi {x : RealN n} -> Real.fromRat R < lnorm x -> g x = 0) {e : Rat} (e>0 : 0 < e)
: ∃ (s : SFuncIntegrationSpace (LebesgueRing0 n)) (IsApprox g (ratCube n (R + 1)) e s)
=> \let | R' : Rat => R + 1
| M : Rat => (cubeRad n R' ∨ 0) + 2
\in \have | j1 : cubeRad n R' <= cubeRad n R' ∨ 0 => join-left
| j2 : 0 <= cubeRad n R' ∨ 0 => join-right
| M>0 : 0 < M => linarith
| e2>0 : 0 < e * ratio 1 2 => positivity
\in \case cover-uniform-ball (RealN-ballsTB n) g 0 M>0 e2>0 \with {
| inP (d,d>0,gu) =>
\have d'>0 : 0 < d ∧ 1 => <_meet-univ d>0 RatField.zro<ide
\in \case cubeCells n R' d'>0 \with {
| inP (l,l1,l2,l3) => \case FinSet.finiteAC (\lam (i : Fin l.len) => rat-approx (g (l i).1) e2>0) \with {
| inP c =>
\let | arr : Array (\Sigma RatIntegrationSpace (LebesgueRing0 n)) l.len => mkArray \lam i => ((c i).1, (l i).2)
\in \have ar : IsReduced arr => disjoint-reduced {n} {arr} l1
\in inP (inSF arr, \lam z => cases (lebPts n (ratCube n (R + 1)) z arg addPath) \with {
| true, zK => \case l3 zK \with {
| inP (i,q) =>
\have | (q1,_) => l2 q
| se : stepEval z (inSF arr) = (c i).1 => (lebPoint z).evalL-index {_} {arr} ar q
| ci : RealAbGroup.abs (g (l i).1 - Real.fromRat (c i).1) < Real.fromRat (e * ratio 1 2) => (c i).2
| z<A : (dist {RealN n} 0 (ratPt z)).U ((cubeRad n R' ∨ 0) + 1) => real_<_U.1 $ transportInv (< _) (ldist_zro-left {RealN n} {ratPt z}) $ cube-in zK <∘r rat_real_<.1 linarith
| cz<1 : (dist (l i).1 (ratPt z)).U 1 => ExUpperReal.U_<= (real_<_U.1 q1) meet-right
| cz<d : (dist (l i).1 (ratPt z)).U d => ExUpperReal.U_<= (real_<_U.1 q1) meet-left
| gcz : RealAbGroup.abs (g (l i).1 - g (ratPt z)) < Real.fromRat (e * ratio 1 2)
=> real_<_U.2 (gu ((RealN n).halving-right {0} {ratPt z} {(l i).1} z<A cz<1 linarith) (ExUpperReal.U_<= z<A linarith) cz<d)
\in rewrite se (real-abs-triangle gcz ci (RealAbGroup.+-rat *> pmap Real.fromRat linarith))
}
| false, zK =>
\have | g0 : g (ratPt z) = 0 => gR $ (rat_real_< {R} {R'}).1 linarith <∘l cube-out zK
| s0 : stepEval z (inSF arr) = 0 => (lebPoint z).evalL-false {_} {arr} \lam j => cases (lebPts n (l j).2 z arg addPath) \with {
| true, q => absurd $ \case inv zK *> (l2 q).2 \with {}
| false, q => idp
}
\in rewrite (g0, s0) $ =_<= $ pmap RealAbGroup.abs negative-right *> RealAbGroup.abs_zro
})
}
}
}
\where
\lemma real-abs-triangle {a b c h h' e : Real} (p : RealAbGroup.abs (a - b) < h) (q : RealAbGroup.abs (a - c) < h') (r : h RealAbGroup.+ h' = e) : RealAbGroup.abs (b - c) <= e
=> \have | a1 : a - b <= RealAbGroup.abs (a - b) => RealAbGroup.abs>=id
| a2 : negative (a - b) <= RealAbGroup.abs (a - b) => RealAbGroup.abs>=neg
| b1 : a - c <= RealAbGroup.abs (a - c) => RealAbGroup.abs>=id
| b2 : negative (a - c) <= RealAbGroup.abs (a - c) => RealAbGroup.abs>=neg
\in <=-less (RealAbGroup.abs_-_< linarith linarith)
-- | The inclusion of step functions to `L¹(ℝⁿ)`.
\func stepL1 {n : Nat} (s : SFuncIntegrationSpace (LebesgueRing0 n)) : LebesgueL1 n
=> integrationCompletion s
\lemma stepL1-dist {n : Nat} {s t : SFuncIntegrationSpace (LebesgueRing0 n)}
: ldist (stepL1 s) (stepL1 t) = integral (LatticeAbGroup.abs {SFuncIntegrationSpace (LebesgueRing0 n)} (s - t))
=> Real.=-upper.2 $ integrationCompletion.func-isometry *> norm-dist {SFuncIntegrationSpace (LebesgueRing0 n)}
\lemma approx-triangle {a : Real} {b c e e' : Rat} (p : RealAbGroup.abs (a - b) <= e) (q : RealAbGroup.abs (a - c) <= e')
: RatField.abs (b - c) <= e + e'
=> \have | a1 : a - b <= RealAbGroup.abs (a - b) => RealAbGroup.abs>=id
| a2 : negative (a - b) <= RealAbGroup.abs (a - b) => RealAbGroup.abs>=neg
| b1 : a - c <= RealAbGroup.abs (a - c) => RealAbGroup.abs>=id
| b2 : negative (a - c) <= RealAbGroup.abs (a - c) => RealAbGroup.abs>=neg
| h : Real.fromRat (e + e') = e RealAbGroup.+ e' => inv RealAbGroup.+-rat
| m : Real.fromRat (b - c) = Real.fromRat b - c => inv (pmap (_ +) RealAbGroup.negative-rat *> RealAbGroup.+-rat)
| u : Real.fromRat b - c <= e + e' => linarith
| v : negative (Real.fromRat b - c) <= e + e' => linarith
| r : RealAbGroup.abs (Real.fromRat b - c) <= (e + e') => RealAbGroup.join-univ u v
\in rat_real_<=.2 $ transport (<= _) (pmap RealAbGroup.abs (inv m) *> RealAbGroup.abs-rat) r
-- | Approximants are close.
\lemma approx-close {n : Nat} {g : RealN n -> Real} {K K' : LebesgueRing0 n} {e e' : Rat} {s s' : SFuncIntegrationSpace (LebesgueRing0 n)} (a : IsApprox g K e s) (a' : IsApprox g K' e' s')
: ldist (stepL1 s) (stepL1 s') <= e RealField.* meas K + e' RealField.* meas K'
=> \have h : integral (stepChar e K + stepChar e' K') = e RealField.* meas K RealAbGroup.+ e' RealField.* meas K'
=> IntegrationSpace.integral_+ {_} {stepChar e K} {stepChar e' K'} *> pmap2 (RealAbGroup.+) integral-stepChar integral-stepChar
\in rewrite stepL1-dist $ transport (_ <=) h $ step-norm-bound {n} {_} {stepChar e K + stepChar e' K'} \lam z =>
transportInv (_ <=) (stepEval_+ {n} {z} {stepChar e K} {stepChar e' K'} *> pmap2 (+) stepEval-char stepEval-char) $
transportInv (\lam x => RatField.abs x <= _) (stepEval_+ *> pmap (_ +) stepEval_negative) (approx-triangle (a z) (a' z))
-- | Approximants on the cube can be arbitrarily close to {g} in norm.
\lemma approx-small {n : Nat} (g : CoverMap (RealN n) RealNormed) {R : Rat} (gR : \Pi {x : RealN n} -> Real.fromRat R < lnorm x -> g x = 0) {d : Rat} (d>0 : 0 < d)
: ∃ (e : Rat) (s : SFuncIntegrationSpace (LebesgueRing0 n)) (IsApprox g (ratCube n (R + 1)) e s) (e RealField.* meas (ratCube n (R + 1)) < d)
=> \case Real.U-inh_>0 {meas (ratCube n (R + 1))} \with {
| inP (V,mV,V>0) =>
\have | e>0 : 0 < d * RatField.finv V => positivity
| ee : (d * RatField.finv V) * V = d => *-assoc *> pmap (d *) (RatField.finv-left (/=-sym (StrictPoset.<_/= V>0))) *> ide-right
\in \case approx-exists g gR e>0 \with {
| inP (s,a) => inP (d * RatField.finv V, s, a, transport (_ <) (RealField.*-rat *> pmap Real.fromRat ee) $ gcongr (real_<_U.2 mV))
}
}
-- | {u} is the limit of approximants of {g}.
\type IsIota {n : Nat} (g : RealN n -> Real) (u : LebesgueL1 n) : \Prop
=> \Pi {K : LebesgueRing0 n} {e : Rat} {s : SFuncIntegrationSpace (LebesgueRing0 n)} -> IsApprox g K e s -> ldist u (stepL1 s) <= e RealField.* meas K
\lemma iota-unique {n : Nat} (g : CoverMap (RealN n) RealNormed) {R : Rat} (gR : \Pi {x : RealN n} -> Real.fromRat R < lnorm x -> g x = 0) {u u' : LebesgueL1 n} (p : IsIota g u) (q : IsIota g u') : u = u'
=> dist-ext {LebesgueL1 n} $ Real.=-upper.1 $ <=-antisymmetric (real_<=-eps \lam {d} d>0 =>
\have d2>0 : 0 < d * ratio 1 2 => positivity
\in \case approx-small g gR d2>0 \with {
| inP (e,s,ap,em) =>
\have | a => p ap
| b => q ap
| t : ldist {LebesgueL1 n} u u' <= ldist {LebesgueL1 n} u (stepL1 s) RealAbGroup.+ ldist {LebesgueL1 n} (stepL1 s) u' => ldist-triang {LebesgueL1 n}
| sy : ldist {LebesgueL1 n} (stepL1 s) u' = ldist {LebesgueL1 n} u' (stepL1 s) => ldist-symm {LebesgueL1 n}
| h : Real.fromRat (d * ratio 1 2) RealAbGroup.+ Real.fromRat (d * ratio 1 2) = Real.fromRat d => RealAbGroup.+-rat *> pmap Real.fromRat linarith
\in eps-triangle a em (b <∘r em) t sy h
}) (ldist>=0 {LebesgueL1 n})
\where
\lemma eps-triangle {R : OrderedRing} {uv us sv vs m e d : R} (a : us <= m) (em : m < e) (vs<e : vs < e) (t : uv <= us + sv) (sy : sv = vs) (r : e + e = d) : uv < 0 + d
=> linarith
\sfunc iota-exists {n : Nat} (g : CoverMap (RealN n) RealNormed) {R : Rat} (gR : \Pi {x : RealN n} -> Real.fromRat R < lnorm x -> g x = 0) : \Sigma (u : LebesgueL1 n) (IsIota g u)
=> (family-limit P Pi Pc, \lam {K'} {e'} {s'} ap' => real_<=-eps \lam {d} d>0 =>
\have d4>0 : 0 < d * ratio 1 4 => positivity
\in \case approx-small g gR d4>0 \with {
| inP (e,s,ap,em) =>
\let L => family-limit P Pi Pc
\in \have | l : ldist {LebesgueL1 n} L (stepL1 s) < Real.fromRat (d * ratio 1 2) => real_<_U.2 (family-limit.char {LebesgueL1 n} {P} {Pi} {Pc} d4>0 (inP (e, s, ap, em, idp)) linarith)
| c => approx-close {n} {g} ap ap'
| t : ldist {LebesgueL1 n} L (stepL1 s') <= ldist {LebesgueL1 n} L (stepL1 s) RealAbGroup.+ ldist {LebesgueL1 n} (stepL1 s) (stepL1 s') => ldist-triang {LebesgueL1 n}
| h : Real.fromRat (d * ratio 1 2) RealAbGroup.+ Real.fromRat (d * ratio 1 4) RealAbGroup.+ Real.fromRat (d * ratio 1 4) = Real.fromRat d
=> pmap (RealAbGroup.+ _) RealAbGroup.+-rat *> RealAbGroup.+-rat *> pmap Real.fromRat linarith
| d4' : 0 < Real.fromRat (d * ratio 1 4) => rat_real_<.1 d4>0
\in limit-triangle l c em t h d4'
})
\where \private {
\lemma limit-triangle {R : OrderedRing} {x1 x2 x3 m m' e2 e4 d : R} (l : x2 < e2) (c : x3 <= m + m') (em : m < e4) (t : x1 <= x2 + x3) (h : e2 + e4 + e4 = d) (e4>0 : 0 < e4) : x1 < m' + d
=> linarith
\type P (a : Rat) (x : LebesgueL1 n) : \Prop
=> ∃ (e : Rat) (s : SFuncIntegrationSpace (LebesgueRing0 n)) (IsApprox g (ratCube n (R + 1)) e s) (e RealField.* meas (ratCube n (R + 1)) < a) (x = stepL1 s)
\lemma Pi {a : Rat} (a>0 : 0 < a) : ∃ (x : LebesgueL1 n) (P a x)
=> \case approx-small g gR a>0 \with {
| inP (e,s,ap,em) => inP (stepL1 s, inP (e, s, ap, em, idp))
}
\lemma Pc {a b : Rat} {x y : LebesgueL1 n} (a>0 : 0 < a) (b>0 : 0 < b) (Px : P a x) (Py : P b y) : dist x y ExUpperReal.<= a RatField.+ b
=> \lam {c} (ab<c : a + b < c) => \case \elim x, \elim y, Px, Py \with {
| x, y, inP (e,s,ap,em,idp), inP (e',s',ap',em',idp) => real_<_U.1 $
\have | t => approx-close {n} {g} ap ap'
| h : Real.fromRat a RealAbGroup.+ Real.fromRat b < Real.fromRat c => transportInv (< _) RealAbGroup.+-rat (rat_real_<.1 ab<c)
\in linarith
}
}
-- | The embedding `ι : C_c(ℝⁿ) -> L¹(ℝⁿ)`.
\sfunc iota {n : Nat} (g : CompactCoverMap (RealN n)) : LebesgueL1 n
=> (iota-pair g).1
\where {
\private \lemma iota-pair {n : Nat} (g : CompactCoverMap (RealN n)) : \Sigma (u : LebesgueL1 n) (IsIota g u)
\level \lam u v => \case ball-support g \with {
| inP (R,gR) => ext (iota-unique g gR u.2 v.2)
}
=> \case ball-support g \with {
| inP (R,gR) => iota-exists g gR
}
\protected \lemma char {n : Nat} {g : CompactCoverMap (RealN n)} : IsIota g (iota g)
=> rewrite (\peval iota g) (iota-pair g).2
}
-- | Pointwise operations on real-valued cover maps.
\lemma cover2 {X : CoverSpace} (op : CoverMap (ProductCoverSpace RealNormed RealNormed) RealNormed) (f g : CoverMap X RealNormed) : CoverMap X RealNormed (\lam x => op (f x, g x))
=> op CoverMap.∘ ProductCoverSpace.tuple f g
\lemma approx_+ {n : Nat} {g h : RealN n -> Real} {K : LebesgueRing0 n} {e e' : Rat} {s t : SFuncIntegrationSpace (LebesgueRing0 n)} (a : IsApprox g K e s) (b : IsApprox h K e' t)
: IsApprox (\lam x => g x RealAbGroup.+ h x) K (e + e') (s + t)
=> \lam z =>
\have | p : Real.fromRat (stepEval z (s + t)) = Real.fromRat (stepEval z s) RealAbGroup.+ Real.fromRat (stepEval z t) => pmap Real.fromRat stepEval_+ *> inv RealAbGroup.+-rat
| q : (g (ratPt z) RealAbGroup.+ h (ratPt z)) - Real.fromRat (stepEval z (s + t)) = (g (ratPt z) - Real.fromRat (stepEval z s)) RealAbGroup.+ (h (ratPt z) - Real.fromRat (stepEval z t))
=> rewrite p equation.abGroup
\in rewrite q $ RealAbGroup.abs_+ <=∘ transport (_ <=) (if-add _ e e') (RealAbGroup.<=_+ (a z) (b z))
\where {
\lemma if-add (b : Bool) (e e' : Rat) : if b e 0 RealAbGroup.+ if b e' 0 = Real.fromRat (if b (e + e') 0) \elim b
| true => RealAbGroup.+-rat
| false => RealAbGroup.+-rat *> pmap Real.fromRat zro-left
}
\lemma approx_negative {n : Nat} {g : RealN n -> Real} {K : LebesgueRing0 n} {e : Rat} {s : SFuncIntegrationSpace (LebesgueRing0 n)} (a : IsApprox g K e s)
: IsApprox (\lam x => negative (g x)) K e (negative s)
=> \lam z =>
\have | p : Real.fromRat (stepEval z (negative s)) = negative (Real.fromRat (stepEval z s)) => pmap Real.fromRat stepEval_negative *> inv RealAbGroup.negative-rat
| q : negative (g (ratPt z)) - Real.fromRat (stepEval z (negative s)) = negative (g (ratPt z) - Real.fromRat (stepEval z s)) => rewrite p equation.abGroup
\in rewrite (q, RealAbGroup.abs_negative) (a z)
\lemma approx_abs {n : Nat} {g : RealN n -> Real} {K : LebesgueRing0 n} {e : Rat} {s : SFuncIntegrationSpace (LebesgueRing0 n)} (a : IsApprox g K e s)
: IsApprox (\lam x => RealAbGroup.abs (g x)) K e (LatticeAbGroup.abs {SFuncIntegrationSpace (LebesgueRing0 n)} s)
=> \lam z =>
\have p : Real.fromRat (stepEval z (LatticeAbGroup.abs {SFuncIntegrationSpace (LebesgueRing0 n)} s)) = RealAbGroup.abs (Real.fromRat (stepEval z s)) => pmap Real.fromRat stepEval_abs *> inv RealAbGroup.abs-rat
\in rewrite p $ RealAbGroup.abs-univ RealAbGroup.abs_-left RealAbGroup.abs_-right <=∘ a z
\lemma stepL1_+ {n : Nat} {s t : SFuncIntegrationSpace (LebesgueRing0 n)} : stepL1 (s + t) = stepL1 s + stepL1 t
=> integrationCompletion.func-+
\lemma stepL1_negative {n : Nat} {s : SFuncIntegrationSpace (LebesgueRing0 n)} : stepL1 (negative s) = negative (stepL1 s)
=> integrationCompletion.func-negative
\lemma stepL1_abs {n : Nat} {s : SFuncIntegrationSpace (LebesgueRing0 n)} : stepL1 (LatticeAbGroup.abs {SFuncIntegrationSpace (LebesgueRing0 n)} s) = LatticeAbGroup.abs {LebesgueL1 n} (stepL1 s)
=> integrationCompletion.func-join *> pmap (_ ∨) stepL1_negative
-- | A criterion for an element to be equal to the image of a function under {iota}.
\lemma iota-eq {n : Nat} {g : CompactCoverMap (RealN n)} {v : LebesgueL1 n}
(h : \Pi {d : Rat} -> 0 < d -> ∃ (K : LebesgueRing0 n) (e : Rat) (s : SFuncIntegrationSpace (LebesgueRing0 n)) (IsApprox g K e s) (e RealField.* meas K < d) (ldist {LebesgueL1 n} v (stepL1 s) < d))
: iota g = v
=> dist-ext {LebesgueL1 n} $ Real.=-upper.1 $ <=-antisymmetric (real_<=-eps \lam {d} d>0 =>
\have d2>0 : 0 < d * ratio 1 2 => positivity
\in \case h d2>0 \with {
| inP (K,e,s,ap,em,vs) =>
\have | a => iota.char {n} {g} ap
| t : ldist {LebesgueL1 n} (iota g) v <= ldist {LebesgueL1 n} (iota g) (stepL1 s) RealAbGroup.+ ldist {LebesgueL1 n} (stepL1 s) v => ldist-triang {LebesgueL1 n}
| sy : ldist {LebesgueL1 n} (stepL1 s) v = ldist {LebesgueL1 n} v (stepL1 s) => ldist-symm {LebesgueL1 n}
| r : Real.fromRat (d * ratio 1 2) RealAbGroup.+ Real.fromRat (d * ratio 1 2) = Real.fromRat d => RealAbGroup.+-rat *> pmap Real.fromRat linarith
\in iota-unique.eps-triangle a em vs t sy r
}) (ldist>=0 {LebesgueL1 n})
\lemma CompactCoverMap-common {n : Nat} (g h : CompactCoverMap (RealN n)) : ∃ (R : Rat) (\Pi {x : RealN n} -> Real.fromRat R < lnorm x -> g x = 0) (\Pi {x : RealN n} -> Real.fromRat R < lnorm x -> h x = 0)
=> \case ball-support g, ball-support h \with {
| inP (R1,g0), inP (R2,h0) => inP (R1 ∨ R2,
\lam r => g0 (rat_real_<=.1 join-left <∘r r),
\lam r => h0 (rat_real_<=.1 join-right <∘r r))
}
-- | {iota} is additive.
\lemma iota_+ {n : Nat} {g h : CompactCoverMap (RealN n)} : iota (g + h) = iota g + iota h
=> iota-eq \lam {d} d>0 =>
\have | d4>0 : 0 < d * ratio 1 4 => positivity
| (inP (R,g0,h0)) => CompactCoverMap-common g h
| (inP (e,s,a,em)) => approx-small g g0 d4>0
| (inP (e',t,b,em')) => approx-small h h0 d4>0
| c1 => iota.char {n} {g} a
| c2 => iota.char {n} {h} b
| r : Real.fromRat (d * ratio 1 4) RealAbGroup.+ Real.fromRat (d * ratio 1 4) RealAbGroup.+ Real.fromRat (d * ratio 1 4) RealAbGroup.+ Real.fromRat (d * ratio 1 4) = Real.fromRat d
=> pmap (RealAbGroup.+ _) (pmap (RealAbGroup.+ _) RealAbGroup.+-rat *> RealAbGroup.+-rat) *> RealAbGroup.+-rat *> pmap Real.fromRat linarith
| d4' : 0 < Real.fromRat (d * ratio 1 4) => rat_real_<.1 d4>0
| m : (e + e') RealField.* meas (ratCube n (R + 1)) = e RealField.* meas (ratCube n (R + 1)) RealAbGroup.+ e' RealField.* meas (ratCube n (R + 1))
=> pmap (RealField.* _) (inv RealAbGroup.+-rat) *> RealField.rdistr
| t1 : ldist {LebesgueL1 n} (iota g + iota h) (stepL1 s + stepL1 t) <= ldist {LebesgueL1 n} (iota g) (stepL1 s) RealAbGroup.+ ldist {LebesgueL1 n} (iota h) (stepL1 t) => ldist_+ {LebesgueL1 n}
\in inP (ratCube n (R + 1), e + e', s + t, approx_+ {n} {g} {h} a b, rewrite m (sum2 em em' r d4'), rewrite stepL1_+ (sum4 t1 c1 c2 em em' r d4'))
\where {
\lemma sum2 {R : OrderedRing} {m m' e d : R} (em : m < e) (em' : m' < e) (r : e + e + e + e = d) (e>0 : 0 < e) : m + m' < d
=> linarith
\lemma sum4 {R : OrderedRing} {x a b m m' e d : R} (t : x <= a + b) (c1 : a <= m) (c2 : b <= m') (em : m < e) (em' : m' < e) (r : e + e + e + e = d) (e>0 : 0 < e) : x < d
=> linarith
}
-- | {iota} preserves negation.
\lemma iota_negative {n : Nat} {g : CompactCoverMap (RealN n)} : iota (negative g) = negative (iota g)
=> iota-eq \lam {d} d>0 =>
\have | (inP (R,g0)) => ball-support g
| (inP (e,s,a,em)) => approx-small g g0 d>0
| c => iota.char {n} {g} a
| e' : ldist {LebesgueL1 n} (negative (iota g)) (negative (stepL1 s)) = ldist {LebesgueL1 n} (iota g) (stepL1 s) => ldist_negative {LebesgueL1 n}
\in inP (ratCube n (R + 1), e, negative s, approx_negative {n} {g} a, em, rewrite stepL1_negative linarith)
-- | {iota} preserves the absolute value.
\lemma iota_abs {n : Nat} {g : CompactCoverMap (RealN n)} : iota (CompactCoverMap.absolute g) = LatticeAbGroup.abs {LebesgueL1 n} (iota g)
=> iota-eq \lam {d} d>0 => \case ball-support g \with {
| inP (R,g0) => \case approx-small g g0 d>0 \with {
| inP (e,s,a,em) =>
\have | c => iota.char {n} {g} a
| e' : ldist {LebesgueL1 n} (LatticeAbGroup.abs {LebesgueL1 n} (iota g)) (LatticeAbGroup.abs {LebesgueL1 n} (stepL1 s)) <= ldist {LebesgueL1 n} (iota g) (stepL1 s) => (LebesgueL1 n).ldist_abs
\in inP (ratCube n (R + 1), e, LatticeAbGroup.abs {SFuncIntegrationSpace (LebesgueRing0 n)} s, approx_abs {n} {g} a, em, rewrite stepL1_abs linarith)
}
}
-- | The bound of `∫ |ι g|` by a bound of `g` at rational points.
\lemma iota-bound {n : Nat} {g : CompactCoverMap (RealN n)} {a : LebesgueRing0 n} {M : Rat} (h : \Pi (z : Array Rat n) -> RealAbGroup.abs (g (ratPt z)) <= Real.fromRat (if (lebPts n a z) M 0))
: integral {LebesgueL1 n} (LatticeAbGroup.abs {LebesgueL1 n} (iota g)) <= M RealField.* meas a
=> real_<=-eps \lam {d} d>0 =>
\have d2>0 : 0 < d * ratio 1 2 => positivity
\in \case ball-support g \with {
| inP (R,g0) => \case approx-small g g0 d2>0 \with {
| inP (e,s,ap,em) =>
\let | K => ratCube n (R + 1)
| t => stepChar M a + stepChar e K
| X => iota g
| S => stepL1 s
\in \have | pt (z : Array Rat n) : RatField.abs (stepEval z s) <= stepEval z t =>
\have | e1 : Real.fromRat (RatField.abs (stepEval z s)) = RealAbGroup.abs (Real.fromRat (stepEval z s)) => inv RealAbGroup.abs-rat
| e2 : Real.fromRat (stepEval z t) = Real.fromRat (if (lebPts n a z) M 0) RealAbGroup.+ Real.fromRat (if (lebPts n K z) e 0)
=> pmap Real.fromRat (stepEval_+ {n} {z} {stepChar M a} {stepChar e K} *> pmap2 (+) stepEval-char stepEval-char) *> inv RealAbGroup.+-rat
| u : RealAbGroup.abs (Real.fromRat (stepEval z s)) <= RealAbGroup.abs (g (ratPt z)) RealAbGroup.+ RealAbGroup.abs (g (ratPt z) - Real.fromRat (stepEval z s))
=> transport (\lam w => RealAbGroup.abs w <= _) (equation.abGroup : g (ratPt z) + negative (g (ratPt z) - Real.fromRat (stepEval z s)) = Real.fromRat (stepEval z s))
(RealAbGroup.abs_+ <=∘ transport (\lam w => _ RealAbGroup.+ w <= _) (inv RealAbGroup.abs_negative) <=-refl)
\in (rat_real_<= {RatField.abs (stepEval z s)} {stepEval z t}).2 $ transport2 (<=) (inv e1) (inv e2) (u <=∘ RealAbGroup.<=_+ (h z) (ap z))
| s1 : integral (LatticeAbGroup.abs {SFuncIntegrationSpace (LebesgueRing0 n)} s) <= integral {SFuncIntegrationSpace (LebesgueRing0 n)} t => step-norm-bound {n} {_} {t} pt
| s2 : integral {SFuncIntegrationSpace (LebesgueRing0 n)} t = M RealField.* meas a RealAbGroup.+ e RealField.* meas K
=> IntegrationSpace.integral_+ {SFuncIntegrationSpace (LebesgueRing0 n)} {stepChar M a} {stepChar e K} *> pmap2 (RealAbGroup.+) integral-stepChar integral-stepChar
| s3 : integral {LebesgueL1 n} (LatticeAbGroup.abs {LebesgueL1 n} S) = integral (LatticeAbGroup.abs {SFuncIntegrationSpace (LebesgueRing0 n)} s)
=> pmap (integral {LebesgueL1 n}) (inv stepL1_abs) *> integrationCompletion.func-integral
| c : ldist {LebesgueL1 n} X S <= e RealField.* meas K => iota.char {n} {g} ap
| c' : ldist {LebesgueL1 n} X S = integral {LebesgueL1 n} (LatticeAbGroup.abs {LebesgueL1 n} (X - S)) => lnorm-ldist {LebesgueL1 n}
| tr : integral {LebesgueL1 n} (LatticeAbGroup.abs {LebesgueL1 n} X) <= integral {LebesgueL1 n} (LatticeAbGroup.abs {LebesgueL1 n} (X - S)) RealAbGroup.+ integral {LebesgueL1 n} (LatticeAbGroup.abs {LebesgueL1 n} S)
=> transportInv (_ <=) (inv (IntegrationSpace.integral_+ {LebesgueL1 n})) $ IntegrationSpace.integral-mono {LebesgueL1 n} $
transport (\lam w => LatticeAbGroup.abs {LebesgueL1 n} w <= {LebesgueL1 n} _) (+-assoc {LebesgueL1 n} *> pmap (X +) (negative-left {LebesgueL1 n}) *> zro-right {LebesgueL1 n}) (LatticeAbGroup.abs_+ {LebesgueL1 n})
| r : Real.fromRat (d * ratio 1 2) RealAbGroup.+ Real.fromRat (d * ratio 1 2) = Real.fromRat d => RealAbGroup.+-rat *> pmap Real.fromRat linarith
\in bound-eps s1 s2 s3 c c' tr em r
}
}
\where
\lemma bound-eps {R : OrderedRing} {iX iXS iS is it Ma eK lXS e d : R} (s1 : is <= it) (s2 : it = Ma + eK) (s3 : iS = is) (c : lXS <= eK) (c' : lXS = iXS)
(tr : iX <= iXS + iS) (em : eK < e) (r : e + e = d) : iX < Ma + d
=> linarith
-- | A pointwise bound of `g - s` by a step function {t} bounds the distance from `ι g` to {s}.
\lemma iota-near {n : Nat} {g : CompactCoverMap (RealN n)} {s t : SFuncIntegrationSpace (LebesgueRing0 n)}
(h : \Pi (z : Array Rat n) -> RealAbGroup.abs (g (ratPt z) - stepEval z s) <= stepEval z t)
: ldist (iota g) (stepL1 s) <= integral t
=> real_<=-eps \lam {d} d>0 =>
\have d2>0 : 0 < d * ratio 1 2 => positivity
\in \case ball-support g \with {
| inP (R,g0) => \case approx-small g g0 d2>0 \with {
| inP (e,s',ap,em) =>
\let | K => ratCube n (R + 1)
| u => stepChar e K + t
\in \have | pt (z : Array Rat n) : RatField.abs (stepEval z (s' - s)) <= stepEval z u
=> transportInv (\lam x => RatField.abs x <= _) (stepEval_+ *> pmap (_ +) stepEval_negative) $
transportInv (_ <=) (stepEval_+ {n} {z} {stepChar e K} {t} *> pmap (+ _) stepEval-char) (approx-triangle (ap z) (h z))
| b1 : integral (LatticeAbGroup.abs (s' - s)) <= integral u => step-norm-bound {n} {_} {u} pt
| b2 : integral u = e RealField.* meas K RealAbGroup.+ integral t
=> IntegrationSpace.integral_+ {SFuncIntegrationSpace (LebesgueRing0 n)} {stepChar e K} {t} *> pmap (RealAbGroup.+ _) integral-stepChar
| c : ldist {LebesgueL1 n} (iota g) (stepL1 s') <= e RealField.* meas K => iota.char {n} {g} ap
| c' : ldist {LebesgueL1 n} (stepL1 s') (stepL1 s) = integral (LatticeAbGroup.abs (s' - s)) => stepL1-dist
| tr : ldist {LebesgueL1 n} (iota g) (stepL1 s) <= ldist {LebesgueL1 n} (iota g) (stepL1 s') RealAbGroup.+ ldist {LebesgueL1 n} (stepL1 s') (stepL1 s) => ldist-triang {LebesgueL1 n}
| r : Real.fromRat (d * ratio 1 2) RealAbGroup.+ Real.fromRat (d * ratio 1 2) = Real.fromRat d => RealAbGroup.+-rat *> pmap Real.fromRat linarith
\in near-eps tr c c' b1 b2 em r
}
}
\where
\lemma near-eps {R : OrderedRing} {x x1 x2 i iu ek it d2 d : R} (tr : x <= x1 + x2) (c : x1 <= ek) (c' : x2 = i) (b1 : i <= iu) (b2 : iu = ek + it)
(em : ek < d2) (r : d2 + d2 = d) : x < it + d
=> linarith
-- | A pointwise bound of `g - s` by a step function {t} bounds the difference of the integrals.
\lemma iota-integral-near {n : Nat} {g : CompactCoverMap (RealN n)} {s t : SFuncIntegrationSpace (LebesgueRing0 n)}
(h : \Pi (z : Array Rat n) -> RealAbGroup.abs (g (ratPt z) - stepEval z s) <= stepEval z t)
: RealAbGroup.abs (integral (iota g) - integral s) <= integral t
=> \have e : integral (iota g - stepL1 s) = integral (iota g) - integral s
=> (LebesgueL1 n).integral_+ *> pmap (_ RealAbGroup.+) ((LebesgueL1 n).integral-hom.func-negative *> pmap negative integrationCompletion.func-integral)
\in transport (\lam x => RealAbGroup.abs x <= _) e $ (LebesgueL1 n).integral_abs <=∘ transport (<= _) (lnorm-ldist {LebesgueL1 n}) (iota-near h)
-- | Maps with compact support are uniformly continuous.
\lemma CompactCoverMap-uniform {n : Nat} (g : CompactCoverMap (RealN n)) {eps : Rat} (eps>0 : 0 < eps)
: ∃ (d : Rat) (0 < d) ∀ {x y} ((dist x y).U d) (RealAbGroup.abs (g x - g y) < eps)
=> \have | (inP (R,g0)) => ball-support g
| j0 : 0 <= R ∨ 0 => join-right
| j1 : R <= R ∨ 0 => join-left
| B>0 : 0 < (R ∨ 0) + 3 => linarith
| (inP (d,d>0,gu)) => cover-uniform-ball (RealN-ballsTB n) g 0 B>0 eps>0
| dm>0 : 0 < d ∧ 1 => <_meet-univ d>0 RatField.zro<ide
\in inP (d ∧ 1, dm>0, \lam {x} {y} xy => \case Real.LU-located {lnorm x} {(R ∨ 0) + 1} {(R ∨ 0) + 2} linarith \with {
| byRight u =>
\have u' : (dist {RealN n} 0 x).U ((R ∨ 0) + 2) => real_<_U.1 $ transportInv (< _) (ldist_zro-left {RealN n}) (real_<_U.2 u)
\in real_<_U.2 $ gu (ExUpperReal.U_<= u' linarith) ((RealN n).halving {0} {x} {y} u' (ExUpperReal.U_<= xy meet-right) linarith) (ExUpperReal.U_<= xy meet-left)
| byLeft l =>
\have | l' : Real.fromRat ((R ∨ 0) + 1) < lnorm x => real_<_L.2 l
| xy1 : ldist {RealN n} x y < 1 => real_<_U.2 (ExUpperReal.U_<= xy meet-right)
| t : lnorm x - lnorm y <= ldist {RealN n} x y => transportInv (_ <=) (lnorm-ldist {RealN n}) (lnorm_-left {RealN n})
| rr : Real.fromRat ((R ∨ 0) + 1) = Real.fromRat (R ∨ 0) RealAbGroup.+ 1 => inv RealAbGroup.+-rat
| rj : Real.fromRat R <= Real.fromRat (R ∨ 0) => rat_real_<=.1 j1
| x0 : g x = 0 => g0 (linarith : Real.fromRat R < lnorm x)
| y0 : g y = 0 => g0 (linarith : Real.fromRat R < lnorm y)
\in rewrite (x0, y0) $ transportInv (< _) (pmap RealAbGroup.abs negative-right *> RealAbGroup.abs_zro) (rat_real_<.1 eps>0)
})
-- | The integral is monotone on functions with compact support.
\lemma CompactCoverMap-integral-mono {n : Nat} {g h : CompactCoverMap (RealN n)} (p : \Pi (x : RealN n) -> g x <= h x)
: integral {LebesgueL1 n} (iota g) <= integral {LebesgueL1 n} (iota h)
=> \let d => h - g
\in \have | e : CompactCoverMap.absolute d = d => CompactCoverMap.ext {RealN n} {CompactCoverMap.absolute d} {d} (\lam x => RealAbGroup.abs-ofPos (RealAbGroup.to>=0 (p x)))
| e1 : iota d = LatticeAbGroup.abs {LebesgueL1 n} (iota d) => inv (pmap iota e) *> iota_abs {n} {d}
| e2 : iota d = iota h - iota g => iota_+ {n} {h} {negative g} *> pmap (_ +) (iota_negative {n} {g})
| e3 : integral {LebesgueL1 n} (iota d) = integral {LebesgueL1 n} (iota h) - integral {LebesgueL1 n} (iota g)
=> pmap (integral {LebesgueL1 n}) e2 *> IntegrationSpace.integral_+ {LebesgueL1 n} *> pmap (_ RealAbGroup.+) (AddGroupHom.func-negative {IntegrationSpace.integral-hom {LebesgueL1 n}})
| pos : 0 <= integral {LebesgueL1 n} (iota d) => transportInv (\lam w => 0 <= integral {LebesgueL1 n} w) e1 (IntegrationSpace.integral>=0 {LebesgueL1 n} (LatticeAbGroup.abs>=0 {LebesgueL1 n}))
\in linarith