\import Algebra.Group
\import Algebra.Group.GroupHom
\import Algebra.Meta
\import Algebra.Monoid
\import Algebra.Ordered
\import Algebra.Pointed
\import Algebra.Ordered.RieszSpace
\import Algebra.Ordered.TruncRieszSpace
\import Algebra.QModule
\import Algebra.Ring.Boolean
\import Algebra.StrictlyOrdered
\import Analysis.Integration.IntegrationSpace
\import Analysis.Measure.MeasureRing
\import Analysis.Measure.SimpleFunctions
\import Arith.Rat
\import Arith.Real
\import Arith.Real.Field
\import Data.Array
\import Data.Array.EPerm
\import Data.Or
\import Equiv
\import Function
\import Function.Meta
\import Logic
\import Logic.Meta
\import Order.Biordered
\import Order.Lattice
\import Order.LinearOrder
\import Order.PartialOrder
\import Order.StrictOrder
\import Paths
\import Paths.Meta
\import Relation.Equivalence \hiding (~)
\import Set.Fin
\import Topology.CoverSpace.Complete
\import Topology.MetricSpace
\import Topology.MetricSpace.Complete
\import Topology.NormedAbGroup
\import Topology.NormedRing
\import Topology.TopSpace
\open SFunc
\open SFuncRepr
\instance SFuncIntegrationSpace (B : PseudoMeasureRing) : BoundedIntegrationSpace (SFunc RatField B)
| IntegrationSpace => base
| trunc-bounded a => \case makeReduced a \with {
| inP (l,lr,p) => rewrite p $ inP (bound l, (bound>=0, inP (unit l, unit>=0 lr, unit-trunc lr, abs-bound lr)))
}
| trunc-archimedean {a} p => \case makeReduced a \with {
| inP (l,lr,q) => transportInv (\lam y => y <= 0) q $ archimedean-reduced lr \lam n => transport (\lam y => TruncRieszSpace.IsUnderUnit {base} (n base.*n y)) q (p n)
}
| integral-trunc-small {f} _ {eps} eps>0 => \case makeReduced f \with {
| inP (l,lr,q) => rewrite q $ base.integral-trunc-dominated {inSF l} {unit l} (\lam eta>0 => truncAt-dominated lr eta>0) eps>0
}
\where {
\func base : IntegrationSpace (SFunc RatField B) \cowith
| TruncRieszSpace => SFuncTruncRieszSpace RatIntegrationSpace B
| integral (f : SFunc RatField B) : Real \with {
| in~ f => sum f
| ~-equiv f g r => sum_~ r
}
| integral>=0 {a} => \case \elim a \with {
| in~ l => \lam (inP (d,dp,d>=0)) => transportInv (_ RealAbGroup.<=) (pmap integral (inv (AddGroup.minus_zro {_} {inSF l}) *> dp)) $
RealAbGroup.BigSum_>=0 {map (\lam s => s.1 RealField.* meas s.2) d} \lam j => RealField.<=_*-positive (rat_real_<=.1 (d>=0 j)) meas>=0
}
| integral_+ {a} {b} => \case \elim a, \elim b \with {
| in~ l, in~ l' => pmap RealAbGroup.BigSum (map_++ (\lam s => s.1 RealField.* meas s.2)) *> RealAbGroup.BigSum_++
}
\func sum (l : Array (\Sigma Rat B)) : Real
=> RealAbGroup.BigSum $ map (\lam s => s.1 RealField.* meas s.2) l
\lemma sum_~ {l l' : Array (\Sigma Rat B)} (r : l ~ {RatField} l') : sum l = sum l' \elim r
| ~-perm e => RealAbGroup.BigSum_EPerm (EPerm.EPerm_map (\lam (s : \Sigma Rat B) => s.1 RealField.* meas s.2) e)
| ~-sym r => inv (sum_~ r)
| ~-trans r r' => sum_~ r *> sum_~ r'
| ~-zro-left idp => pmap (+ _) RealField.zro_*-left *> RealAbGroup.zro-left
| ~-zro-right idp => pmap (\lam x => _ * x + _) meas_zro *> pmap (+ _) RealField.zro_*-right *> RealAbGroup.zro-left
| ~-+-left idp idp => inv RealAbGroup.+-assoc *> pmap (+ _) (inv RealField.rdistr *> pmap (RealField.* _) RealAbGroup.+-rat)
| ~-+-right {_} {v} idp idp => inv RealAbGroup.+-assoc *> pmap (+ _) (inv RealField.ldistr *> pmap (v RealField.*) (inv meas-modular) *> RealField.ldistr) *> RealAbGroup.+-assoc
-- | The indicator of the support of a family.
\func unit (l : Array (\Sigma Rat B)) : SFunc RatField B
=> inSF {RatIntegrationSpace} (map (\lam s => (RatField.ide, s.2)) l)
\func bound (l : Array (\Sigma Rat B)) : Rat
=> RatField.BigSum (map (\lam s => RatIntegrationSpace.abs s.1) l)
\lemma bound>=0 {l : Array (\Sigma Rat B)} : 0 <= bound l
=> RatField.BigSum_>=0 \lam j => RatIntegrationSpace.abs>=0
\lemma unit>=0 {l : Array (\Sigma Rat B)} (lr : IsReduced {RatIntegrationSpace} l) : base.zro base.<= unit l
=> (SFuncPosetQModule.>=0-reduced-char {RatIntegrationSpace} {B} {map (\lam s => (RatField.ide, s.2)) l} lr).2 \lam j => byLeft (RatField.<=-less RatField.zro<ide)
\lemma unit-trunc {l : Array (\Sigma Rat B)} (lr : IsReduced {RatIntegrationSpace} l) : base.trunc (unit l) = unit l
=> SFuncTruncRieszSpace.trunc-reduced {RatIntegrationSpace} {B} {map (\lam s => (RatField.ide, s.2)) l} lr *> pmap inSF (exts \lam j => ext (<=-antisymmetric (RatField.meet-left {1} {1}) (RatField.meet-univ <=-refl <=-refl), idp))
\lemma abs-bound {l : Array (\Sigma Rat B)} (lr : IsReduced {RatIntegrationSpace} l) : base.abs (inSF l) base.<= bound l base.*q unit l
=> rewrite (SFuncRieszSpace.abs-reduced {RatIntegrationSpace} lr, SFuncQModule.*q-char {RatIntegrationSpace}) $ (SFuncPosetQModule.<=-common-char {RatIntegrationSpace} {B} {map __.2 l} lr {\lam j => RatIntegrationSpace.abs (l j).1} {\lam j => bound l RatIntegrationSpace.*q RatField.ide}).2 \lam j =>
byLeft $ RatField.BigSum_>=index {map (\lam s => RatIntegrationSpace.abs s.1) l} (\lam j => RatIntegrationSpace.abs>=0) j <=∘ =_<= (inv RatIntegrationSpace.rat_*q)
\lemma truncAt-dominated {l : Array (\Sigma Rat B)} (lr : IsReduced {RatIntegrationSpace} l) {eta : Rat} (eta>0 : RatField.zro RatField.< eta) : base.truncAt eta (inSF l) base.<= eta base.*q unit l
=> =_<= (pmap (eta base.*q) (pmap base.trunc (SFuncQModule.*q-char {RatIntegrationSpace} {B} {RatField.finv eta} {l}) *> SFuncTruncRieszSpace.trunc-reduced {RatIntegrationSpace} {B} {map (\lam s => (RatField.finv eta RatIntegrationSpace.*q s.1, s.2)) l} lr) *> SFuncQModule.*q-char {RatIntegrationSpace})
<=∘ (SFuncPosetQModule.<=-common-char {RatIntegrationSpace} {B} {map __.2 l} lr {\lam j => eta RatIntegrationSpace.*q RatIntegrationSpace.trunc (RatField.finv eta RatIntegrationSpace.*q (l j).1)} {\lam j => eta RatIntegrationSpace.*q RatField.ide}).2
(\lam j => byLeft $ gcongr (RatField.meet-right {RatField.finv eta RatIntegrationSpace.*q (l j).1} {1}))
<=∘ =_<= (inv (SFuncQModule.*q-char {RatIntegrationSpace} {B} {eta} {map (\lam s => (RatField.ide, s.2)) l}))
\lemma archimedean-reduced {l : Array (\Sigma Rat B)} (lr : IsReduced {RatIntegrationSpace} l) (p : \Pi (n : Nat) -> base.trunc (n base.*n inSF l) = n base.*n inSF l) : inSF l base.<= base.zro
=> \have h (n : Nat) : \Pi (j : Fin l.len) -> (n RatField.*n (l j).1 <= RatIntegrationSpace.trunc (n RatField.*n (l j).1)) || ((l j).2 = 0)
=> (SFuncPosetQModule.<=-common-char {RatIntegrationSpace} {B} {map __.2 l} lr {\lam j => n RatField.*n (l j).1} {\lam j => RatIntegrationSpace.trunc (n RatField.*n (l j).1)}).1 $ =_<= $ inv $ inv (pmap base.trunc (SFuncAbMonoid.*n-char {RatIntegrationSpace}) *> SFuncTruncRieszSpace.trunc-reduced {RatIntegrationSpace} {B} {map (\lam s => (n RatField.*n s.1, s.2)) l} lr) *> p n *> SFuncAbMonoid.*n-char {RatIntegrationSpace}
\in transport (inSF l <=) (~-sfequiv $ ~-zros-left \lam _ => idp) $ (SFuncPosetQModule.<=-common-char {RatIntegrationSpace} {_} {map __.2 l} lr {map __.1 l} {\lam _ => 0}).2 \lam j =>
\case LinearOrder.dec<_<= {RatField} 0 (l j).1 \with {
| inr v<=0 => byLeft v<=0
| inl v>0 => \case h _ j \with {
| byLeft q => absurd $ <-irreflexive $ rat_*n-unbounded v>0 <∘l (q <=∘ RatField.meet-right)
| byRight q => byRight q
}
}
}
-- | `|c [a] - c [b]| = |c| [a + b]`.
\lemma SFunc-single-abs {B : PseudoMeasureRing} {c : Rat} {a b : B}
: LatticeAbGroup.abs (inSF ((c,a) :: nil) - inSF ((c,b) :: nil)) = inSF ((RatField.abs c, a + b) :: nil)
=> \let | X => SFuncIntegrationSpace B
| u : X => inSF ((c, B.diff a b) :: nil)
| v : X => inSF ((c, B.diff b a) :: nil)
| e : inSF ((c,a) :: nil) - inSF ((c,b) :: nil) = {X} u - v
=> pmap2 (\lam (x y : X) => x - y) (~-sfequiv (split1 b {c} {a} {nil}) *> pmap (\lam x => inSF ((c,x) :: nil) + u) (B.*-comm {b} {a})) (~-sfequiv (split1 a {c} {b} {nil})) *> +-minus-left {X} {inSF ((c, a * b) :: nil)} {u} {v}
\in pmap LatticeAbGroup.abs e *> SFuncRieszSpace.abs-reduced {_} {B} {(c, B.diff a b) :: (negative c, B.diff b a) :: nil} (pair-reduced BooleanRing.diff_*_diff)
*> pmap (\lam (z : Rat) => inSF ((RatField.abs c, B.diff a b) :: (z, B.diff b a) :: nil)) RatField.abs_negative
*> ~-sfequiv (merge-disjoint BooleanRing.diff_*_diff) *> pmap (\lam x => inSF ((RatField.abs c, x) :: nil)) (inv BooleanRing.+_diff)
\where {
\lemma pair-reduced {B : PseudoMeasureRing} {c c' : Rat} {x y : B} (p : x * y = 0) : IsReduced {RatIntegrationSpace} ((c,x) :: (c',y) :: nil)
=> \lam {i} {j} i/=j => \case \elim i, \elim j, i/=j \with {
| 0, 0, i/=j => absurd (i/=j idp)
| 0, 1, _ => p
| 1, 0, _ => B.*-comm *> p
| 1, 1, i/=j => absurd (i/=j idp)
}
\lemma +-minus-left {X : AbGroup} {w u v : X} : (w + u) - (w + v) = u - v
=> equation.abGroup
\lemma merge-disjoint {B : BooleanRing} {v : Rat} {x y : B} (p : x * y = 0) : (v,x) :: (v,y) :: nil ~ (v, x ∨ y) :: nil
=> \have | q : (v, x ∧ y) :: nil ~ nil => ~-zro-right (pmap (\lam z => (v,z) :: nil) p)
| r : (v, x ∨ y) :: (v, x ∧ y) :: nil ~ (v,x) :: (v,y) :: nil => ~-+-right {_} {_} {_} {_} {nil} idp idp
\in ~-sym $ ~-trans (~_:: (~-sym q)) r
}
-- | The map `a => c [a]` scales distances by `|c|`; for `c = 1` it is an isometry.
\lemma SFunc-single-dist {B : PseudoMeasureRing} {c : Rat} {a b : B}
: lnorm {SFuncIntegrationSpace B} (inSF ((c,a) :: nil) - inSF ((c,b) :: nil)) = RealAbGroup.abs c RealField.* meas (a - b)
=> pmap (SFuncIntegrationSpace B).integral SFunc-single-abs *> RealAbGroup.zro-right
*> pmap2 (RealField.*) (inv RealAbGroup.abs-rat) (pmap (\lam x => meas (a + x)) (inv BooleanRing.negative=id))
\func SFuncHom {A B : PseudoMeasureRing} (f : MeasureRingHom A B) : IntegrationSpaceHom (SFuncIntegrationSpace A) (SFuncIntegrationSpace B) \cowith
| AddGroupHom => hom f
| func-<= (inP (d,dp,d>=0)) => inP (mapB f d, inv (hom f).func-minus *> pmap (hom f) dp, d>=0)
| func-join>= => =_<= func-join
| func-trunc {x} => \case \elim x \with {
| in~ l => inv (SFuncTruncRieszSpace.trunc-reduced {_} {B} {mapB f (reduce l)} (mapB-reduced f reduce_IsReduced)) *> pmap trunc (~-sfequiv (mapB_~ f reduce_~))
}
| func-integral {x} => \case \elim x \with {
| in~ l => pmap RealAbGroup.BigSum (exts \lam j => pmap ((l j).1 RealField.*) f.func-meas)
}
\where {
\func mapB {A B : PseudoMeasureRing} (f : MeasureRingHom A B) (l : Array (\Sigma Rat A)) : Array (\Sigma Rat B)
=> map (\lam s => (s.1, f s.2)) l
\lemma func-join_B {A B : PseudoMeasureRing} {f : MeasureRingHom A B} {a b : A} : f (a ∨ b) = f a ∨ f b
=> f.func-+ *> pmap2 (+) f.func-+ f.func-*
\lemma mapB_~ {A B : PseudoMeasureRing} (f : MeasureRingHom A B) {l l' : Array (\Sigma Rat A)} (r : l ~ {RatField} l') : mapB f l ~ {RatField} mapB f l' \elim r
| ~-perm e => ~-perm (EPerm.EPerm_map (\lam (s : \Sigma Rat A) => (s.1, f s.2)) e)
| ~-sym r => ~-sym (mapB_~ f r)
| ~-trans r r' => ~-trans (mapB_~ f r) (mapB_~ f r')
| ~-zro-left idp => ~-zro-left idp
| ~-zro-right {v} idp => transportInv (\lam (x : B) => (v,x) :: mapB f l' ~ {RatField} mapB f l') f.func-zro (~-zro-right idp)
| ~-+-left idp idp => ~-+-left idp idp
| ~-+-right {l''} {v} idp idp => ~-trans (~-perm $ EPerm.eperm-= $ pmap2 (\lam x y => (v,x) :: (v,y) :: mapB f l'') func-join_B f.func-*) (~-+-right idp idp)
\lemma mapB-reduced {A B : PseudoMeasureRing} (f : MeasureRingHom A B) {l : Array (\Sigma Rat A)} (lr : IsReduced {RatIntegrationSpace} l)
: IsReduced {RatIntegrationSpace} (mapB f l)
=> \lam i/=j => inv f.func-* *> pmap f (lr i/=j) *> f.func-zro
\func hom {A B : PseudoMeasureRing} (f : MeasureRingHom A B) : AddGroupHom (SFuncIntegrationSpace A) (SFuncIntegrationSpace B) \cowith
| func (x : SFunc RatField A) : SFunc RatField B \with {
| in~ l => inSF (mapB f l)
| ~-equiv l l' r => ~-sfequiv (mapB_~ f r)
}
| func-+ {x} {y} => \case \elim x, \elim y \with {
| in~ l, in~ l' => pmap inSF (map_++ (\lam (s : \Sigma Rat A) => (s.1, f s.2)))
}
\lemma func-abs {A B : PseudoMeasureRing} {f : MeasureRingHom A B} {a : SFuncIntegrationSpace A} : hom f (LatticeAbGroup.abs a) = LatticeAbGroup.abs (hom f a)
=> \case makeReduced a \with {
| inP (l,lr,p) => rewrite p $ pmap (hom f) (SFuncRieszSpace.abs-reduced lr) *> inv (SFuncRieszSpace.abs-reduced {_} {B} {mapB f l} (mapB-reduced f lr))
}
\lemma func-join {A B : PseudoMeasureRing} {f : MeasureRingHom A B} {x y : SFuncIntegrationSpace A} : hom f (x ∨ y) = hom f x ∨ hom f y
=> pmap (hom f) RieszSpace.join_abs *> func-*q *> pmap (_ QModule.*q) ((hom f).func-+ *> pmap2 (+) (hom f).func-+ (func-abs *> pmap LatticeAbGroup.abs (hom f).func-minus)) *> inv RieszSpace.join_abs
}
\lemma SFuncHom-dense {A B : PseudoMeasureRing} {f : MeasureRingHom A B} (fd : f.IsDense)
: IsDenseSet {SFuncIntegrationSpace B} (\lam y => ∃ (x : SFunc RatField A) (SFuncHom f x = y))
=> \lam {y} Uo Uy => \case (dist_open {SFuncIntegrationSpace B}).1 Uo Uy \with {
| inP (eps,eps>0,p) => \case approx fd (rat_real_<.1 eps>0) y \with {
| inP (m,d) => inP (inSF (SFuncHom.mapB f m), inP (inSF m, idp), p $ real_<_U.1 d)
}
}
\where {
\lemma approx-elem {A B : PseudoMeasureRing} {f : MeasureRingHom A B} (fd : f.IsDense) {d : Real} (d>0 : 0 < d) (b : B)
: ∃ (a : A) (meas (b - f a) < d)
=> \let (inP (delta,delta>0,delta<d)) => real_<-char.1 d>0
\in \case fd {b} {OBall delta b} OBall-open (OBall-center (rat_real_<.2 delta>0)) \with {
| inP (y, inP (a,p), h) => inP (a, transport (< _) (lnorm-ldist {B} {b} {f a}) (real_<_U.2 (transportInv (OBall delta b) p h)) <∘ delta<d)
}
\lemma list-bound {B : PseudoMeasureRing} {n : Nat} {c : Array Rat n} {b b' : Array B n}
: lnorm {SFuncIntegrationSpace B} (inSF (\lam j => (c j, b j)) - inSF (\lam j => (c j, b' j))) <= RealAbGroup.BigSum (\lam j => RealAbGroup.abs (c j) RealField.* meas (b j - b' j)) \elim n
| 0 => =_<= (ldist-refl {SFuncIntegrationSpace B} {inSF nil})
| suc n => \let | X => SFuncIntegrationSpace B
| s : X => inSF ((c 0, b 0) :: nil)
| s' : X => inSF ((c 0, b' 0) :: nil)
| t : X => inSF (\lam (j : Fin n) => (c (suc j), b (suc j)))
| t' : X => inSF (\lam (j : Fin n) => (c (suc j), b' (suc j)))
\in =_<= (pmap lnorm (+-minus-swap {X} {s} {t} {s'} {t'})) <=∘ lnorm_+ {X} {s - s'} {t - t'} <=∘ <=_+ (=_<= SFunc-single-dist) (list-bound {B} {n} {\lam j => c (suc j)} {\lam j => b (suc j)} {\lam j => b' (suc j)})
\where {
\private \lemma +-minus-swap {X : AbGroup} {s t s' t' : X} : (s + t) - (s' + t') = (s - s') + (t - t')
=> equation.abGroup
}
\lemma approx {A B : PseudoMeasureRing} {f : MeasureRingHom A B} (fd : f.IsDense) {eps : Real} (eps>0 : 0 < eps) (y : SFunc RatField B)
: ∃ (m : Array (\Sigma Rat A)) (ldist {SFuncIntegrationSpace B} y (inSF (SFuncHom.mapB f m)) < eps) \elim y
| in~ l => approx-list fd eps>0 l
-- | For each `(c_j,b_j)` in `l`, choose `a_j` with `meas (b_j - f a_j) < d`, where `d * (Σ_j |c_j| + 1) < eps`.
\lemma approx-list {A B : PseudoMeasureRing} {f : MeasureRingHom A B} (fd : f.IsDense) {eps : Real} (eps>0 : 0 < eps) (l : Array (\Sigma Rat B))
: ∃ (m : Array (\Sigma Rat A)) (ldist {SFuncIntegrationSpace B} (inSF l) (inSF (SFuncHom.mapB f m)) < eps)
=> \let | S => RealAbGroup.BigSum (map (\lam s => RealAbGroup.abs s.1) l)
| S>=0 : 0 <= S => RealAbGroup.BigSum_>=0 \lam j => RealAbGroup.abs>=0
| (inP (d,d>0,dS<eps)) => split-eps eps>0 {S + 1} (S>=0 <∘r linarith)
\in \case FinSet.finiteAC (\lam j => approx-elem fd d>0 (l j).2) \with {
| inP h => inP (\lam j => ((l j).1, (h j).1),
(=_<= (lnorm-ldist {SFuncIntegrationSpace B} {inSF l} {inSF (\lam j => ((l j).1, f (h j).1))})
<=∘ list-bound {B} {l.len} {\lam j => (l j).1} {\lam j => (l j).2} {\lam j => f (h j).1}
<=∘ RealAbGroup.BigSum_<= {_} {\lam j => RealAbGroup.abs (l j).1 RealField.* meas ((l j).2 - f (h j).1)} {\lam j => RealAbGroup.abs (l j).1 RealField.* d} (\lam j => gcongr (<=-less (h j).2))
<=∘ =_<= (inv (RealField.BigSum-rdistr {map (\lam s => RealAbGroup.abs s.1) l} {d}) *> *-comm))
<∘r (<_*_positive-right d>0 (linarith : S < S + 1) <∘ dS<eps))
}
}
-- | A dense homomorphism of measure rings induces an isomorphism of the completions of the integration spaces of simple functions.
\lemma SFuncHom-completion-equiv {A B : PseudoMeasureRing} {f : MeasureRingHom A B} (fd : f.IsDense)
: IsEquiv (integrationCompletion-map (SFuncHom f))
=> integrationCompletion-map-equiv (SFuncHom-dense fd)
-- | If the measure of a measure ring separates points, then so does the norm on simple functions with rational coefficients.
\lemma SFunc-norm-ext {B : PseudoMeasureRing} (Bext : \Pi {e : B} -> meas e = 0 -> e = 0) {x : SFuncIntegrationSpace B} (p : lnorm x = 0) : x = 0
=> \case makeReduced x \with {
| inP (l,lr,q) => \have t => RealAbGroup.BigSum_>=0-zero {map (\lam s => RatField.abs s.1 RealField.* meas s.2) l}
(\lam j => RealField.<=_*-positive (rat_real_<=.1 RatField.abs>=0) meas>=0)
(inv (pmap (integral {SFuncIntegrationSpace B}) (SFuncRieszSpace.abs-reduced lr)) *> pmap (lnorm {SFuncIntegrationSpace B}) (inv q) *> p)
\in q *> ~-sfequiv (~-zero-terms \lam j => \case LinearOrder.dec<_<= 0 (RatField.abs (l j).1) \with {
| inl |c|>0 => byRight $ Bext $ RealAbGroup.<=-antisymmetric (\lam m>0 => RealAbGroup.<-irreflexive $ transport (0 <) (t j) $ positivity) meas>=0
| inr |c|<=0 => byLeft $ RatField.abs_zro-ext $ <=-antisymmetric |c|<=0 RatField.abs>=0
})
}
-- | The characteristic simple function `[a]` of an element of a measure ring.
\func SFunc-char {B : PseudoMeasureRing} (a : B) : SFunc RatField B
=> inSF ((1,a) :: nil)
-- | The unit of the adjunction between {PseudoMeasureRing} and {IntegrationSpace}.
\func integrationUnit (B : PseudoMeasureRing) : MeasureRingHom B (SFuncIntegrationSpace B).MeasRing \cowith
| func a => (SFunc-char a, char-boolean)
| func-+ => ext $ inv $ SFunc-single-abs *> pmap (\lam (z : Rat) => inSF ((z, _) :: nil)) abs-ide
| func-* {a} {b} => ext $ inv $ pmap2 (∧) (~-sfequiv (split1 b {1} {a} {nil}) *> pmap (\lam x => SFunc-char x + SFunc-char (B.diff a b)) B.*-comm) (~-sfequiv (split1 a {1} {b} {nil}))
*> inv (meet_+-left {SFuncIntegrationSpace B} {SFunc-char (a * b)} {SFunc-char (B.diff a b)} {SFunc-char (B.diff b a)}) *> pmap (_ +) (char-disjoint BooleanRing.diff_*_diff) *> zro-right
| func-meas => RealAbGroup.zro-right *> RealField.ide-left
\where {
\lemma single-reduced {B : BooleanRing} {c : Rat} {a : B} : IsReduced {RatIntegrationSpace} ((c,a) :: nil)
=> \lam {i} {j} i/=j => \case \elim i, \elim j, i/=j \with {
| 0, 0, i/=j => absurd (i/=j idp)
}
\lemma abs-ide : RatField.abs 1 = 1
=> RatField.abs-ofPos RatField.zro<=ide
\lemma char-boolean {B : PseudoMeasureRing} {a : B} : (SFuncIntegrationSpace B).IsBoolean (SFunc-char a)
=> pmap trunc (~-sfequiv (~-+-left {RatField} {B} {_} {_} {nil} idp idp)) *> SFuncTruncRieszSpace.trunc-reduced single-reduced
*> pmap (\lam (z : Rat) => inSF ((z,a) :: nil)) (RatField.<=-antisymmetric RatField.meet-right (RatField.meet-univ linarith RatField.<=-refl))
\lemma char-disjoint {B : PseudoMeasureRing} {x y : B} (p : x * y = 0) : SFunc-char x ∧ SFunc-char y = 0
=> RieszSpace.meet_abs {SFuncIntegrationSpace B} {SFunc-char x} {SFunc-char y} *> pmap (ratio 1 2 QModule.*q) (pmap2 (\lam u w => u - w)
(~-sfequiv (SFunc-single-abs.merge-disjoint p) *> pmap SFunc-char (inv (BooleanRing.+_join p)))
(SFunc-single-abs {B} {1} *> pmap (\lam (z : Rat) => inSF ((z, x + y) :: nil)) abs-ide) *> negative-right {SFuncIntegrationSpace B} {SFunc-char (x + y)}) *> (SFuncIntegrationSpace B).toRatModule.*c_zro-right
\lemma char-zero {B : PseudoMeasureRing} {x : B} (q : SFunc-char x = 0) : x = 0
=> \case (SFuncPosetQModule.>=0-reduced-char single-reduced).1 (transport (\lam z => 0 <= negative z) (inv q) (=_<= (inv AddGroup.negative_zro))) 0 \with {
| byLeft c => absurd linarith
| byRight r => r
}
}
{- | Every simple function `s` is within `|trunc (s + s) - s|` of a characteristic function:
- round the coefficients of a reduced representation at `1/2`.
-}
\lemma SFunc-round {B : PseudoMeasureRing} (s : SFuncIntegrationSpace B)
: ∃ (a : B) (LatticeAbGroup.abs (SFunc-char a - s) = LatticeAbGroup.abs (TruncRieszSpace.defect s))
=> \case makeReduced s \with {
| inP (l,lr,p) =>
\have coeffs : map (\lam s => (RatField.abs (chi s.1 - s.1), s.2)) l = map (\lam s => (RatField.abs ((s.1 + s.1) RatField.∧ 1 - s.1), s.2)) l
=> exts \lam j => ext (chi-defect, idp)
\in rewrite p $ inP (B.BigJoin (map round-elem l),
pmap (\lam z => LatticeAbGroup.abs (z - inSF l)) (char-join lr) *> pmap LatticeAbGroup.abs (~-sfequiv (~_+ {RatField} {B} chi negative {l})) *> SFuncRieszSpace.abs-reduced {_} {B} {map (\lam s => (chi s.1 + negative s.1, s.2)) l} lr
*> pmap inSF coeffs
*> inv (pmap LatticeAbGroup.abs (pmap (__ - inSF l) (pmap trunc (~-sfequiv (~_+ {RatField} {B} (\lam r => r) (\lam r => r) {l})) *> SFuncTruncRieszSpace.trunc-reduced {_} {B} {map (\lam s => (s.1 + s.1, s.2)) l} lr) *> ~-sfequiv (~_+ {RatField} {B} (\lam r => (r + r) RatField.∧ 1) negative {l})) *> SFuncRieszSpace.abs-reduced {_} {B} {map (\lam s => ((s.1 + s.1) RatField.∧ 1 + negative s.1, s.2)) l} lr))
}
\where {
\func Half (r : Rat) => (ratio 1 2 RatField.< r) `Or` (r RatField.<= ratio 1 2)
\func chi (r : Rat) : Rat
=> chi-dec (LinearOrder.dec<_<= (ratio 1 2) r)
\func chi-dec {r : Rat} (d : Half r) : Rat \elim d
| inl _ => 1
| inr _ => 0
\func round-elem {B : BooleanRing} (s : \Sigma Rat B) : B
=> round-elem-dec (LinearOrder.dec<_<= (ratio 1 2) s.1)
\func round-elem-dec {B : BooleanRing} {s : \Sigma Rat B} (d : Half s.1) : B \elim d
| inl _ => s.2
| inr _ => 0
\lemma round-elem<= {B : BooleanRing} {s : \Sigma Rat B} (d : Half s.1) : round-elem-dec d BooleanRing.<= s.2 \elim d
| inl _ => B.isBooleanRing
| inr _ => B.zro_*-left
\lemma round-null {B : BooleanRing} {s : \Sigma Rat B} (d : Half s.1)
: ((chi-dec d, s.2) = (1, round-elem-dec d)) || (\Sigma ((chi-dec d = 0) || (s.2 = 0)) ((1 = {Rat} 0) || (round-elem-dec d = 0))) \elim d
| inl _ => byLeft idp
| inr _ => byRight (byLeft idp, byRight idp)
\lemma chi-defect-dec {r : Rat} (d : Half r) : RatField.abs (chi-dec d - r) = RatField.abs ((r + r) RatField.∧ 1 - r) \elim d
| inl h => pmap (\lam z => RatField.abs (z - r)) (inv $ RatField.<=-antisymmetric RatField.meet-right (RatField.meet-univ linarith RatField.<=-refl))
| inr h => pmap RatField.abs RatField.zro-left *> RatField.abs_negative *> pmap RatField.abs (equation.abGroup : r = r + r - r)
*> inv (pmap (\lam z => RatField.abs (z - r)) (RatField.<=-antisymmetric RatField.meet-left (RatField.meet-univ RatField.<=-refl linarith)))
\lemma chi-defect {r : Rat} : RatField.abs (chi r - r) = RatField.abs ((r + r) RatField.∧ 1 - r)
=> chi-defect-dec (LinearOrder.dec<_<= (ratio 1 2) r)
\lemma char-join {B : PseudoMeasureRing} {l : Array (\Sigma Rat B)} (lr : IsReduced {RatIntegrationSpace} l)
: SFunc-char (B.BigJoin (map round-elem l)) = inSF (map (\lam s => (chi s.1, s.2)) l)
=> inv $ ~-sfequiv $ ~-trans (~-null-terms {RatField} {B} {map (\lam s => (chi s.1, s.2)) l} {map (\lam s => ((1 : Rat), round-elem s)) l} \lam j => round-null (LinearOrder.dec<_<= (ratio 1 2) (l j).1))
(~-+s-left {RatIntegrationSpace} {B} {map (\lam s => ((1 : Rat), round-elem s)) l} (\lam i/=j => <=-antisymmetric (B.meet-monotone (round-elem<= _) (round-elem<= _) <=∘ =_<= (lr i/=j)) bottom-univ) (\lam i => idp) idp)
}
-- | Characteristic functions approximate Boolean elements: if `f s` is close to a Boolean `e`, then so is `f [a]` for some `a`.
\lemma SFunc-char-approx {B : PseudoMeasureRing} {Y : TruncRieszSpace} (f : TruncRieszSpaceHom (SFuncIntegrationSpace B) Y) {e : Y} (eb : Y.IsBoolean e) (s : SFuncIntegrationSpace B)
: ∃ (a : B) (Y.abs (f (SFunc-char a) - e) <= Y.abs (f s - e) + Y.abs (f s - e) + Y.abs (f s - e) + Y.abs (f s - e))
=> \case SFunc-round s \with {
| inP (a,p) => inP (a, =_<= (pmap Y.abs (equation.abGroup : f (SFunc-char a) - e = f (SFunc-char a) - f s + (f s - e))) <=∘ Y.abs_+
<=∘ Y.<=_+ (=_<= (pmap Y.abs (inv f.func-minus) *> inv f.func-abs *> pmap f p *> f.func-abs *> pmap Y.abs (f.func-minus *> pmap (__ - f s) (f.func-trunc *> pmap Y.trunc f.func-+))) <=∘ Y.IsBoolean-defect eb) <=-refl)
}
-- | The unit of the adjunction between {PseudoMeasureRing} and {IntegrationSpace} is a bijection.
\lemma integrationUnit-equiv {B : PseudoMeasureRing} : IsEquiv (integrationUnit B)
=> IsEquiv.fromInjSurj (\lam {a} {a'} p => AddGroup.fromZero $ pmap (a +) BooleanRing.negative=id *> integrationUnit.char-zero (pmap __.1 $ (integrationUnit B).func-+ *> pmap (\lam z => z + integrationUnit B a') p *> (SFuncIntegrationSpace B).MeasRing.double=0 {integrationUnit B a'})) \lam y => \case SFunc-char-approx TruncRieszSpaceHom.id y.2 y.1 \with {
| inP (a,p) => inP (a, ext $ AddGroup.fromZero $ LatticeAbGroup.abs_zro-ext $ <=-antisymmetric (p <=∘ =_<= (pmap (\lam z => z + z + z + z) (pmap LatticeAbGroup.abs negative-right *> LatticeAbGroup.abs_zro) *> zro-right *> zro-right *> zro-right)) LatticeAbGroup.abs>=0)
}
-- | The unit of the adjunction between {CompleteMeasureRing} and {CompleteIntegrationSpace}.
\func completeIntegrationUnit (B : PseudoMeasureRing) : MeasureRingHom B (IntegrationSpaceCompletion (SFuncIntegrationSpace B)).MeasRing
=> (integrationCompletion.inc {SFuncIntegrationSpace B}).MeasRingHom MeasureRingHom.∘ integrationUnit B
-- | The unit of the adjunction between {CompleteMeasureRing} and {CompleteIntegrationSpace} is an equivalence.
\lemma completeIntegrationUnit-equiv {B : CompleteMeasureRing} : IsEquiv (completeIntegrationUnit B)
=> \let | Y => IntegrationSpaceCompletion (SFuncIntegrationSpace B)
| g : IsometricMap B Y => \new IsometricMap {
| func a => integrationCompletion (SFunc-char a)
| func-isometry {a} {a'} => IntegrationSpace.MeasRing.inc.func-isometry {completeIntegrationUnit B a} {completeIntegrationUnit B a'} *> (completeIntegrationUnit B).func-isometry
}
\in IsEquiv.fromInjSurj (isometric-inj (completeIntegrationUnit B)) \lam y => TruncP.map (isometric-complete-closed B.isComplete g (limit y)) \lam s => (s.1, ext s.2)
\where {
\lemma limit {B : CompleteMeasureRing} (y : (IntegrationSpaceCompletion (SFuncIntegrationSpace B)).MeasRing)
: TopSpace.IsLimitPoint {IntegrationSpaceCompletion (SFuncIntegrationSpace B)} y.1 \lam z => ∃ (a : B) (integrationCompletion (SFunc-char a) = z)
=> \let Y => IntegrationSpaceCompletion (SFuncIntegrationSpace B)
\in \lam {V} Vo Vy => \case (dist_open {Y} {V}).1 Vo Vy \with {
| inP (eps,eps>0,h) =>
\have | delta>0 : 0 < eps * ratio 1 4 => positivity
| t : Real.fromRat (eps * ratio 1 4) RealAbGroup.+ Real.fromRat (eps * ratio 1 4) RealAbGroup.+ Real.fromRat (eps * ratio 1 4) RealAbGroup.+ Real.fromRat (eps * ratio 1 4) = Real.fromRat eps
=> pmap (\lam x => x RealAbGroup.+ Real.fromRat (eps * ratio 1 4)) (pmap (\lam x => x RealAbGroup.+ Real.fromRat (eps * ratio 1 4)) RealAbGroup.+-rat *> RealAbGroup.+-rat) *> RealAbGroup.+-rat
*> pmap Real.fromRat (RatField.<=-antisymmetric linarith linarith)
\in \case integrationCompletion.inc-dense {SFuncIntegrationSpace B} {y.1} {OBall (eps * ratio 1 4) y.1} (OBall-open {Y} {eps * ratio 1 4} {y.1}) (OBall-center {Y} delta>0 {y.1}) \with {
| inP (z, inP (s,zp), zin) => \case SFunc-char-approx integrationCompletion.inc y.2 s \with {
| inP (a,q) =>
\have | n : Y.integral (Y.abs (integrationCompletion s - y.1)) < Real.fromRat (eps * ratio 1 4)
=> transport (< _) (lnorm-ldist {Y} {y.1} {integrationCompletion s} *> pmap Y.integral Y.abs_-) $ real_<_U.2 $ transportInv (OBall (eps * ratio 1 4) y.1) zp zin
\in inP (integrationCompletion (SFunc-char a), inP (a, idp), h $ real_<_U.1 $ transportInv (< _) (lnorm-ldist {Y} {y.1} {integrationCompletion (SFunc-char a)} *> pmap Y.integral Y.abs_-) $
Y.integral-mono q <∘r transportInv (< _) (Y.integral_+ *> pmap (\lam x => x RealAbGroup.+ _) (Y.integral_+ *> pmap (\lam x => x RealAbGroup.+ _) Y.integral_+)) (linarith : _ < Real.fromRat eps))
}
}
}
}
-- | The counit of the adjunction between measure rings and integration spaces.
\func integrationCounit (Z : IntegrationSpace) : IntegrationSpaceHom (SFuncIntegrationSpace Z.MeasRing) Z \cowith
| AddGroupHom => hom
| func-<= {x} {y} (inP (d,dp,d>=0)) => Z.from>=0 $ transport (0 <=) (pmap hom (inv dp) *> hom.func-minus) $
Z.BigSum_>=0 {sum.terms d} \lam j => Z.*q_>=0 (d>=0 j) (Z.IsBoolean>=0 (d j).2.2)
| func-join>= => =_<= func-join
| func-trunc {x} => \case makeReduced x \with {
| inP (l,lr,p) => rewrite p $ pmap hom (SFuncTruncRieszSpace.trunc-reduced lr) *> inv (sum-trunc lr)
}
| func-integral {x} => \case \elim x \with {
| in~ l => Z.integral-hom.func-BigSum *> pmap RealAbGroup.BigSum (exts \lam j => Z.integral_*q)
}
\where {
\func sum {Z : IntegrationSpace} (l : Array (\Sigma Rat Z.MeasRing)) : Z
=> Z.BigSum (terms l)
\where
\func terms {Z : IntegrationSpace} (l : Array (\Sigma Rat Z.MeasRing)) : Array Z
=> map (\lam s => s.1 Z.*q s.2.1) l
\lemma sum_~ {Z : IntegrationSpace} {l l' : Array (\Sigma Rat Z.MeasRing)} (r : l ~ {RatField} l') : sum l = sum l' \elim r
| ~-perm e => Z.BigSum_EPerm (EPerm.EPerm_map (\lam (s : \Sigma Rat Z.MeasRing) => s.1 Z.*q s.2.1) e)
| ~-sym r => inv (sum_~ r)
| ~-trans r r' => sum_~ r *> sum_~ r'
| ~-zro-left idp => pmap (+ _) Z.toRatModule.*c_zro-left *> Z.zro-left
| ~-zro-right idp => pmap (+ _) Z.toRatModule.*c_zro-right *> Z.zro-left
| ~-+-left idp idp => inv Z.+-assoc *> pmap (+ _) (inv Z.toRatModule.*c-rdistr)
| ~-+-right {_} {v} {a} {b} idp idp => inv Z.+-assoc *> pmap (+ _) (inv Z.toRatModule.*c-ldistr *> pmap (v Z.*q) (pmap (+ _) TruncRieszSpace.BoolRing.join-char *> inv Z.modularity) *> Z.toRatModule.*c-ldistr) *> Z.+-assoc
\func hom {Z : IntegrationSpace} : AddGroupHom (SFuncIntegrationSpace Z.MeasRing) Z \cowith
| func (x : SFunc RatField Z.MeasRing) : Z \with {
| in~ l => sum l
| ~-equiv l l' r => sum_~ r
}
| func-+ {x} {y} => \case \elim x, \elim y \with {
| in~ l, in~ l' => pmap Z.BigSum (map_++ (\lam (s : \Sigma Rat Z.MeasRing) => s.1 Z.*q s.2.1)) *> Z.BigSum_++
}
\lemma terms-disjoint {Z : IntegrationSpace} {l : Array (\Sigma Rat Z.MeasRing)} (lr : IsReduced {RatIntegrationSpace} l) {i j : Fin l.len} (i/=j : i /= j)
: Z.AreDisjoint ((l i).1 Z.*q (l i).2.1) ((l j).1 Z.*q (l j).2.1)
=> Z.disjoint_*q $ Z.pos-disjoint (Z.IsBoolean>=0 (l i).2.2) (Z.IsBoolean>=0 (l j).2.2) (pmap __.1 (lr i/=j))
\lemma sum-abs {Z : IntegrationSpace} {l : Array (\Sigma Rat Z.MeasRing)} (lr : IsReduced {RatIntegrationSpace} l)
: Z.abs (sum l) = sum (map (\lam s => (RatField.abs s.1, s.2)) l)
=> Z.disjoint_abs_BigSum {sum.terms l} (terms-disjoint lr) *> pmap Z.BigSum (exts \lam j => Z.abs_*q *> pmap (_ Z.*q) (Z.abs-ofPos (Z.IsBoolean>=0 (l j).2.2)))
\lemma sum-trunc {Z : IntegrationSpace} {l : Array (\Sigma Rat Z.MeasRing)} (lr : IsReduced {RatIntegrationSpace} l)
: Z.trunc (sum l) = sum (map (\lam s => (RatIntegrationSpace.trunc s.1, s.2)) l)
=> Z.trunc_BigSum-disjoint {sum.terms l} (terms-disjoint lr) *> pmap Z.BigSum (exts \lam j => Z.trunc_*q-boolean (l j).2.2)
\lemma func-abs {Z : IntegrationSpace} {a : SFuncIntegrationSpace Z.MeasRing} : hom (LatticeAbGroup.abs a) = Z.abs (hom a)
=> \case makeReduced a \with {
| inP (l,lr,p) => rewrite p $ pmap hom (SFuncRieszSpace.abs-reduced lr) *> inv (sum-abs lr)
}
\lemma func-join {Z : IntegrationSpace} {x y : SFuncIntegrationSpace Z.MeasRing} : hom (x ∨ y) = hom x ∨ hom y
=> pmap hom RieszSpace.join_abs *> func-*q *> pmap (_ QModule.*q) (hom.func-+ *> pmap2 (+) hom.func-+ (func-abs *> pmap Z.abs hom.func-minus)) *> inv RieszSpace.join_abs
}
-- | The counit is natural.
\lemma integrationCounit-natural {Z Z' : IntegrationSpace} (f : IntegrationSpaceHom Z Z') (x : SFuncIntegrationSpace Z.MeasRing)
: integrationCounit Z' (SFuncHom f.MeasRingHom x) = f (integrationCounit Z x) \elim x
| in~ l => inv $ f.func-BigSum *> pmap Z'.BigSum (exts \lam j => func-*q)
-- | The counit maps the characteristic function of a Boolean element to this element.
\lemma integrationCounit-char {Z : IntegrationSpace} {a : Z.MeasRing} : integrationCounit Z (SFunc-char a) = a.1
=> zro-right *> Z.ide_*q
-- | The counit of `L B` is a retraction of `L` of the unit of `B`.
\lemma integrationCounit-unit {B : PseudoMeasureRing} (x : SFuncIntegrationSpace B)
: integrationCounit (SFuncIntegrationSpace B) (SFuncHom (integrationUnit B) x) = x \elim x
| in~ l => unit-list l
\where {
\lemma unit-list {B : PseudoMeasureRing} (l : Array (\Sigma Rat B))
: integrationCounit (SFuncIntegrationSpace B) (SFuncHom (integrationUnit B) (inSF l)) = inSF l \elim l
| nil => idp
| (c,b) :: l => pmap2 (+) (SFuncQModule.*q-char {_} {_} {c} {(1,b) :: nil} *> pmap (\lam z => inSF ((z,b) :: nil)) RatIntegrationSpace.rat_*q) (unit-list l)
}
-- | For a complete integration space, the comparison map $\Phi$ is injective.
\lemma integrationCounit-inj {Z : CompleteIntegrationSpace} : IsInj (integrationCounit Z)
=> \lam {x} {y} p => AddGroup.fromZero $ SFunc-norm-ext (\lam q => Z.CompleteMeasRing.norm-ext (Real.=-upper.1 q)) $
inv (integrationCounit Z).func-integral *> pmap Z.integral ((integrationCounit Z).func-abs *> pmap Z.abs ((integrationCounit Z).func-minus *> pmap (_ -) (inv p) *> negative-right) *> Z.abs_zro) *> Z.integral-hom.func-zro
-- | The counit of the adjunction between complete measure rings and complete integration spaces.
\func completeIntegrationCounit (Z : CompleteIntegrationSpace) : IntegrationSpaceHom (IntegrationSpaceCompletion (SFuncIntegrationSpace Z.MeasRing)) Z
=> integrationCompletion-lift (integrationCounit Z)
\lemma completeIntegrationCounit-char {Z : CompleteIntegrationSpace} {x : SFuncIntegrationSpace Z.MeasRing} : completeIntegrationCounit Z (integrationCompletion x) = integrationCounit Z x
=> integrationCompletion-lift.char
\lemma completeIntegrationCounit-inj {Z : CompleteIntegrationSpace} : IsInj (completeIntegrationCounit Z)
=> isometric-inj (completeIntegrationCounit Z)
\lemma completeIntegrationCounit-closed {Z : CompleteIntegrationSpace} : Z.IsClosed \lam z => ∃ (x : IntegrationSpaceCompletion (SFuncIntegrationSpace Z.MeasRing)) (completeIntegrationCounit Z x = z)
=> isometric-complete-closed (CompleteCoverSpace.isComplete {IntegrationSpaceCompletion (SFuncIntegrationSpace Z.MeasRing)}) (completeIntegrationCounit Z)