module Goal.Geometry.Differential.Convex where
import Goal.Geometry.Set
import Goal.Geometry.Manifold
import Goal.Geometry.Linear
import Goal.Geometry.Differential
class (Primal c, Manifold m) => Legendre c m where
potential :: (c :#: m) -> Double
potentialDifferentials :: (c :#: m) -> Differentials :#: Tangent c m
potentialMapping :: Legendre c m => (c :#: m) -> Dual c :#: m
potentialMapping p = fromCoordinates (manifold p) . coordinates $ potentialDifferentials p
divergence :: (Primal c, Legendre c m, Legendre (Dual c) m) => (c :#: m) -> (Dual c :#: m) -> Double
divergence pp dq = potential pp + potential dq (pp <.> dq)
legendreFlat :: (Legendre c m, Riemannian c m) => c :#: m -> c :#: m -> Dual c :#: m
legendreFlat mp err = fromCoordinates (manifold mp) . coordinates . flat . fromCoordinates (Tangent mp) $ coordinates err
instance Legendre c m => Legendre c (Replicated m) where
potential ps = sum $ mapReplicated potential ps
potentialDifferentials ps =
let dps = mapReplicated potentialDifferentials ps
in fromCoordinates (Tangent ps) . coordinates $ joinReplicated dps