-- |
-- Module      : Data.Manifold.Function.Quadratic
-- Copyright   : (c) Justus Sagemüller 2016
-- License     : GPL v3
-- 
-- Maintainer  : (@) jsag $ hvl.no
-- Stability   : experimental
-- Portability : portable
-- 

{-# LANGUAGE TypeFamilies             #-}
{-# LANGUAGE FlexibleContexts         #-}
{-# LANGUAGE UndecidableInstances     #-}
{-# LANGUAGE LiberalTypeSynonyms      #-}
{-# LANGUAGE GADTs                    #-}
{-# LANGUAGE TypeOperators            #-}
{-# LANGUAGE UnicodeSyntax            #-}
{-# LANGUAGE ScopedTypeVariables      #-}


module Data.Manifold.Function.Quadratic (
              Quadratic(..), evalQuadratic
            ) where



import Data.Semigroup
import qualified Data.List.NonEmpty as NE

import Data.MemoTrie
import Data.VectorSpace
import Data.AffineSpace
import Data.Tagged
import Data.Manifold.PseudoAffine
import Data.Manifold.Atlas
import Data.Manifold.Riemannian
import Data.Function.Affine

import Prelude                       hiding (id, ($), fmap, fst)
import Control.Category.Constrained.Prelude (id, ($), fmap, fst)
import Control.Arrow.Constrained ((>>>), (&&&), (***), second)

import Math.LinearMap.Category



data Quadratic s d c where
    Quadratic :: (ChartIndex d :->: ( c, ( LinearMap s (Needle d) (Needle c)
                                         , LinearMap s (SymmetricTensor s (Needle d))
                                                     (Needle c) ) )
                 )  -> Quadratic s d c

affineQuadratic :: (WithField s AffineManifold d, WithField s AffineManifold c)
        => Affine s d c -> Quadratic s d c
affineQuadratic :: Affine s d c -> Quadratic s d c
affineQuadratic (Affine ChartIndex d :->: (c, LinearMap s (Needle d) (Needle c))
f) = (ChartIndex d
 :->: (c,
       (LinearMap s (Needle d) (Needle c),
        LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
forall d c s.
(ChartIndex d
 :->: (c,
       (LinearMap s (Needle d) (Needle c),
        LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
Quadratic ((ChartIndex d
  :->: (c,
        (LinearMap s (Needle d) (Needle c),
         LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
 -> Quadratic s d c)
-> ((ChartIndex d
     -> (c,
         (LinearMap s (Needle d) (Needle c),
          LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
    -> ChartIndex d
       :->: (c,
             (LinearMap s (Needle d) (Needle c),
              LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> (ChartIndex d
    -> (c,
        (LinearMap s (Needle d) (Needle c),
         LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChartIndex d
 -> (c,
     (LinearMap s (Needle d) (Needle c),
      LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> ChartIndex d
   :->: (c,
         (LinearMap s (Needle d) (Needle c),
          LinearMap s (SymmetricTensor s (Needle d)) (Needle c)))
forall a b. HasTrie a => (a -> b) -> a :->: b
trie
                  ((ChartIndex d
  -> (c,
      (LinearMap s (Needle d) (Needle c),
       LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
 -> Quadratic s d c)
-> (ChartIndex d
    -> (c,
        (LinearMap s (Needle d) (Needle c),
         LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (ChartIndex d :->: (c, LinearMap s (Diff d) (Diff c)))
-> ChartIndex d -> (c, LinearMap s (Diff d) (Diff c))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex d :->: (c, LinearMap s (Diff d) (Diff c))
ChartIndex d :->: (c, LinearMap s (Needle d) (Needle c))
f (ChartIndex d -> (c, LinearMap s (Needle d) (Needle c)))
-> ((c, LinearMap s (Needle d) (Needle c))
    -> (c,
        (LinearMap s (Needle d) (Needle c),
         LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> ChartIndex d
-> (c,
    (LinearMap s (Needle d) (Needle c),
     LinearMap s (SymmetricTensor s (Needle d)) (Needle c)))
forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> (LinearMap s (Needle d) (Needle c)
 -> (LinearMap s (Needle d) (Needle c),
     LinearMap s (SymmetricTensor s (Needle d)) (Needle c)))
-> (c, LinearMap s (Needle d) (Needle c))
-> (c,
    (LinearMap s (Needle d) (Needle c),
     LinearMap s (SymmetricTensor s (Needle d)) (Needle c)))
forall (a :: * -> * -> *) d b c.
(Morphism a, ObjectPair a d b, ObjectPair a d c) =>
a b c -> a (d, b) (d, c)
second (LinearMap s (Needle d) (Needle c)
-> LinearMap s (Needle d) (Needle c)
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id (LinearMap s (Needle d) (Needle c)
 -> LinearMap s (Needle d) (Needle c))
-> (LinearMap s (Needle d) (Needle c)
    -> LinearMap s (SymmetricTensor s (Needle d)) (Needle c))
-> LinearMap s (Needle d) (Needle c)
-> (LinearMap s (Needle d) (Needle c),
    LinearMap s (SymmetricTensor s (Needle d)) (Needle c))
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&& LinearMap s (SymmetricTensor s (Needle d)) (Needle c)
-> LinearMap s (Needle d) (Needle c)
-> LinearMap s (SymmetricTensor s (Needle d)) (Needle c)
forall a b. a -> b -> a
const LinearMap s (SymmetricTensor s (Needle d)) (Needle c)
forall v. AdditiveGroup v => v
zeroV)

instance ( Atlas x, HasTrie (ChartIndex x), Manifold y
         , LinearManifold (Needle x), Scalar (Needle x) ~ s
         , LinearManifold (Needle y), Scalar (Needle y) ~ s
         , Needle (Needle y) ~ Needle y
         ) => Semimanifold (Quadratic s x y) where
  type Needle (Quadratic s x y) = Quadratic s x (Needle y)
  .+~^ :: Quadratic s x y -> Needle (Quadratic s x y) -> Quadratic s x y
(.+~^) = case ( SemimanifoldWitness y
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness :: SemimanifoldWitness y ) of
    (SemimanifoldWitness y
SemimanifoldWitness) -> \(Quadratic ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f) (Quadratic g)
      -> (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall d c s.
(ChartIndex d
 :->: (c,
       (LinearMap s (Needle d) (Needle c),
        LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
Quadratic ((ChartIndex x
  :->: (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> ((ChartIndex x
     -> (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
    -> ChartIndex x
       :->: (y,
             (LinearMap s (Needle x) (Needle y),
              LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChartIndex x
 -> (y,
     (LinearMap s (Needle x) (Needle y),
      LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
   :->: (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. HasTrie a => (a -> b) -> a :->: b
trie ((ChartIndex x
  -> (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \ChartIndex x
ix -> case ((ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f ChartIndex x
ix, (ChartIndex x
 :->: (Needle y,
       (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
-> (Needle y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex x
:->: (Needle y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
ChartIndex x
:->: (Needle y,
      (LinearMap s (Needle x) (Needle (Needle y)),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y))))
g ChartIndex x
ix) of
          ((y
fx₀,(LinearMap s (Needle x) (Needle y),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
f'), (Needle y
gx₀,(LinearMap s (Needle x) (Needle y),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
g')) -> (y
fx₀y -> Needle y -> y
forall x. Semimanifold x => x -> Needle x -> x
.+~^Needle y
gx₀, (LinearMap s (Needle x) (Needle y),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
f'(LinearMap s (Needle x) (Needle y),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
-> (LinearMap s (Needle x) (Needle y),
    LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
-> (LinearMap s (Needle x) (Needle y),
    LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
forall v. AdditiveGroup v => v -> v -> v
^+^(LinearMap s (Needle x) (Needle y),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
g')
  semimanifoldWitness :: SemimanifoldWitness (Quadratic s x y)
semimanifoldWitness = case SemimanifoldWitness y
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness :: SemimanifoldWitness y of
    SemimanifoldWitness y
SemimanifoldWitness -> SemimanifoldWitness (Quadratic s x y)
forall x.
(Semimanifold (Needle x), Needle (Needle x) ~ Needle x) =>
SemimanifoldWitness x
SemimanifoldWitness
instance ( Atlas x, HasTrie (ChartIndex x), Manifold y
         , LinearManifold (Needle x), Scalar (Needle x) ~ s
         , LinearManifold (Needle y), Scalar (Needle y) ~ s
         , Needle (Needle y) ~ Needle y
         ) => PseudoAffine (Quadratic s x y) where
  Quadratic s x y
p.-~. :: Quadratic s x y
-> Quadratic s x y -> Maybe (Needle (Quadratic s x y))
.-~.Quadratic s x y
q = Quadratic s x (Needle y) -> Maybe (Quadratic s x (Needle y))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Quadratic s x y
pQuadratic s x y -> Quadratic s x y -> Needle (Quadratic s x y)
forall x. (PseudoAffine x, HasCallStack) => x -> x -> Needle x
.-~!Quadratic s x y
q)
  .-~! :: Quadratic s x y -> Quadratic s x y -> Needle (Quadratic s x y)
(.-~!) = case ( SemimanifoldWitness y
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness :: SemimanifoldWitness y ) of
    (SemimanifoldWitness y
SemimanifoldWitness) -> \(Quadratic ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f) (Quadratic ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
g)
      -> (ChartIndex x
 :->: (Needle y,
       (LinearMap s (Needle x) (Needle (Needle y)),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
-> Quadratic s x (Needle y)
forall d c s.
(ChartIndex d
 :->: (c,
       (LinearMap s (Needle d) (Needle c),
        LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
Quadratic ((ChartIndex x
  :->: (Needle y,
        (LinearMap s (Needle x) (Needle (Needle y)),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
 -> Quadratic s x (Needle y))
-> ((ChartIndex x
     -> (Needle y,
         (LinearMap s (Needle x) (Needle (Needle y)),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
    -> ChartIndex x
       :->: (Needle y,
             (LinearMap s (Needle x) (Needle (Needle y)),
              LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
-> (ChartIndex x
    -> (Needle y,
        (LinearMap s (Needle x) (Needle (Needle y)),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
-> Quadratic s x (Needle y)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChartIndex x
 -> (Needle y,
     (LinearMap s (Needle x) (Needle (Needle y)),
      LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
-> ChartIndex x
   :->: (Needle y,
         (LinearMap s (Needle x) (Needle (Needle y)),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y))))
forall a b. HasTrie a => (a -> b) -> a :->: b
trie ((ChartIndex x
  -> (Needle y,
      (LinearMap s (Needle x) (Needle (Needle y)),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
 -> Quadratic s x (Needle y))
-> (ChartIndex x
    -> (Needle y,
        (LinearMap s (Needle x) (Needle (Needle y)),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
-> Quadratic s x (Needle y)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \ChartIndex x
ix -> case ((ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle (Needle y)),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) (Needle (Needle y)),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y))))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle (Needle y)),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y))))
f ChartIndex x
ix, (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle (Needle y)),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) (Needle (Needle y)),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y))))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle (Needle y)),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y))))
g ChartIndex x
ix) of
          ((y
fx₀,(LinearMap s (Needle x) (Needle (Needle y)),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))
f'), (y
gx₀,(LinearMap s (Needle x) (Needle (Needle y)),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))
g')) -> (y
fx₀y -> y -> Needle y
forall x. (PseudoAffine x, HasCallStack) => x -> x -> Needle x
.-~!y
gx₀, (LinearMap s (Needle x) (Needle (Needle y)),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))
f'(LinearMap s (Needle x) (Needle (Needle y)),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))
-> (LinearMap s (Needle x) (Needle (Needle y)),
    LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))
-> (LinearMap s (Needle x) (Needle (Needle y)),
    LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))
forall v. AdditiveGroup v => v -> v -> v
^-^(LinearMap s (Needle x) (Needle (Needle y)),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle (Needle y)))
g')
  pseudoAffineWitness :: PseudoAffineWitness (Quadratic s x y)
pseudoAffineWitness = case SemimanifoldWitness y
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness :: SemimanifoldWitness y of
    SemimanifoldWitness y
SemimanifoldWitness -> SemimanifoldWitness (Quadratic s x y)
-> PseudoAffineWitness (Quadratic s x y)
forall x.
PseudoAffine (Needle x) =>
SemimanifoldWitness x -> PseudoAffineWitness x
PseudoAffineWitness (SemimanifoldWitness (Quadratic s x y)
forall x.
(Semimanifold (Needle x), Needle (Needle x) ~ Needle x) =>
SemimanifoldWitness x
SemimanifoldWitness)
instance ( Atlas x, HasTrie (ChartIndex x), Manifold y
         , LinearManifold (Needle x), Scalar (Needle x) ~ s
         , LinearManifold (Needle y), Scalar (Needle y) ~ s
         , Needle (Needle y) ~ Needle y
         ) => AffineSpace (Quadratic s x y) where
  type Diff (Quadratic s x y) = Quadratic s x (Needle y)
  .+^ :: Quadratic s x y -> Diff (Quadratic s x y) -> Quadratic s x y
(.+^) = Quadratic s x y -> Diff (Quadratic s x y) -> Quadratic s x y
forall x. Semimanifold x => x -> Needle x -> x
(.+~^); .-. :: Quadratic s x y -> Quadratic s x y -> Diff (Quadratic s x y)
(.-.) = Quadratic s x y -> Quadratic s x y -> Diff (Quadratic s x y)
forall x. (PseudoAffine x, HasCallStack) => x -> x -> Needle x
(.-~!)
instance ( Atlas x, HasTrie (ChartIndex x)
         , LinearManifold (Needle x), Scalar (Needle x) ~ s
         , LinearManifold y, Scalar y ~ s
         , Needle y ~ y
         ) => AdditiveGroup (Quadratic s x y) where
  zeroV :: Quadratic s x y
zeroV = case LinearManifoldWitness y
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness y of
       LinearManifoldWitness y
LinearManifoldWitness -> (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall d c s.
(ChartIndex d
 :->: (c,
       (LinearMap s (Needle d) (Needle c),
        LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
Quadratic ((ChartIndex x
  :->: (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> ((ChartIndex x
     -> (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
    -> ChartIndex x
       :->: (y,
             (LinearMap s (Needle x) (Needle y),
              LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChartIndex x
 -> (y,
     (LinearMap s (Needle x) (Needle y),
      LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
   :->: (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. HasTrie a => (a -> b) -> a :->: b
trie ((ChartIndex x
  -> (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (y,
 (LinearMap s (Needle x) (Needle y),
  LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. a -> b -> a
const (y
forall v. AdditiveGroup v => v
zeroV, (LinearMap s (Needle x) (Needle y),
 LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
forall v. AdditiveGroup v => v
zeroV)
  ^+^ :: Quadratic s x y -> Quadratic s x y -> Quadratic s x y
(^+^) = case ( LinearManifoldWitness y
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness y
               , DualSpaceWitness y
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness y ) of
      (LinearManifoldWitness y
LinearManifoldWitness, DualSpaceWitness y
DualSpaceWitness) -> Quadratic s x y -> Quadratic s x y -> Quadratic s x y
forall x. Semimanifold x => x -> Needle x -> x
(.+~^)
  negateV :: Quadratic s x y -> Quadratic s x y
negateV = case LinearManifoldWitness y
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness y of
       LinearManifoldWitness y
LinearManifoldWitness -> \(Quadratic ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f) -> (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall d c s.
(ChartIndex d
 :->: (c,
       (LinearMap s (Needle d) (Needle c),
        LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
Quadratic ((ChartIndex x
  :->: (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> ((ChartIndex x
     -> (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
    -> ChartIndex x
       :->: (y,
             (LinearMap s (Needle x) (Needle y),
              LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChartIndex x
 -> (y,
     (LinearMap s (Needle x) (Needle y),
      LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
   :->: (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. HasTrie a => (a -> b) -> a :->: b
trie ((ChartIndex x
  -> (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
             (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) y,
        LinearMap s (SymmetricTensor s (Needle x)) y)))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) y,
     LinearMap s (SymmetricTensor s (Needle x)) y))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex x
:->: (y,
      (LinearMap s (Needle x) y,
       LinearMap s (SymmetricTensor s (Needle x)) y))
ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f (ChartIndex x
 -> (y,
     (LinearMap s (Needle x) y,
      LinearMap s (SymmetricTensor s (Needle x)) y)))
-> ((y,
     (LinearMap s (Needle x) y,
      LinearMap s (SymmetricTensor s (Needle x)) y))
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> y -> y
forall v. AdditiveGroup v => v -> v
negateV(y -> y)
-> ((LinearMap s (Needle x) y,
     LinearMap s (SymmetricTensor s (Needle x)) y)
    -> (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
-> (y,
    (LinearMap s (Needle x) y,
     LinearMap s (SymmetricTensor s (Needle x)) y))
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
***(LinearMap s (Needle x) y,
 LinearMap s (SymmetricTensor s (Needle x)) y)
-> (LinearMap s (Needle x) (Needle y),
    LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
forall v. AdditiveGroup v => v -> v
negateV
instance ( Atlas x, HasTrie (ChartIndex x)
         , LinearManifold (Needle x), Scalar (Needle x) ~ s
         , LinearManifold y, Scalar y ~ s
         , Needle y ~ y
         ) => VectorSpace (Quadratic s x y) where
  type Scalar (Quadratic s x y) = s
  *^ :: Scalar (Quadratic s x y) -> Quadratic s x y -> Quadratic s x y
(*^) = case LinearManifoldWitness y
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness y of
       LinearManifoldWitness y
LinearManifoldWitness -> \Scalar (Quadratic s x y)
μ (Quadratic ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f) -> (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall d c s.
(ChartIndex d
 :->: (c,
       (LinearMap s (Needle d) (Needle c),
        LinearMap s (SymmetricTensor s (Needle d)) (Needle c))))
-> Quadratic s d c
Quadratic ((ChartIndex x
  :->: (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> ((ChartIndex x
     -> (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
    -> ChartIndex x
       :->: (y,
             (LinearMap s (Needle x) (Needle y),
              LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChartIndex x
 -> (y,
     (LinearMap s (Needle x) (Needle y),
      LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
   :->: (y,
         (LinearMap s (Needle x) (Needle y),
          LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. HasTrie a => (a -> b) -> a :->: b
trie ((ChartIndex x
  -> (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
 -> Quadratic s x y)
-> (ChartIndex x
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> Quadratic s x y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
             (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) y,
        LinearMap s (SymmetricTensor s (Needle x)) y)))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) y,
     LinearMap s (SymmetricTensor s (Needle x)) y))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex x
:->: (y,
      (LinearMap s (Needle x) y,
       LinearMap s (SymmetricTensor s (Needle x)) y))
ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f (ChartIndex x
 -> (y,
     (LinearMap s (Needle x) y,
      LinearMap s (SymmetricTensor s (Needle x)) y)))
-> ((y,
     (LinearMap s (Needle x) y,
      LinearMap s (SymmetricTensor s (Needle x)) y))
    -> (y,
        (LinearMap s (Needle x) (Needle y),
         LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> (Scalar y
Scalar (Quadratic s x y)
μScalar y -> y -> y
forall v. VectorSpace v => Scalar v -> v -> v
*^)(y -> y)
-> ((LinearMap s (Needle x) y,
     LinearMap s (SymmetricTensor s (Needle x)) y)
    -> (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
-> (y,
    (LinearMap s (Needle x) y,
     LinearMap s (SymmetricTensor s (Needle x)) y))
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
***(Scalar
  (LinearMap s (Needle x) (Needle y),
   LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
Scalar (Quadratic s x y)
μScalar
  (LinearMap s (Needle x) (Needle y),
   LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
-> (LinearMap s (Needle x) (Needle y),
    LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
-> (LinearMap s (Needle x) (Needle y),
    LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
forall v. VectorSpace v => Scalar v -> v -> v
*^)

evalQuadratic ::  x y s . ( Manifold x, Atlas x, HasTrie (ChartIndex x)
                           , Manifold y
                           , s ~ Scalar (Needle x), s ~ Scalar (Needle y) )
               => Quadratic s x y -> x
                    -> (y, ( LinearMap s (Needle x) (Needle y)
                           , LinearMap s (SymmetricTensor s (Needle x)) (Needle y) ))
evalQuadratic :: Quadratic s x y
-> x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
evalQuadratic = Quadratic s x y
-> x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
ea
 where ea :: Quadratic s x y -> x -> (y, ( LinearMap s (Needle x) (Needle y)
                                            , LinearMap s (SymmetricTensor s (Needle x)) (Needle y) ))
       ea :: Quadratic s x y
-> x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
ea (Quadratic ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f) x
x = ( y
fx₀y -> Needle y -> y
forall x. Semimanifold x => x -> Needle x -> x
.+~^(LinearMap s (Needle x) (Needle y)
ðx'f₀ LinearMap s (Needle x) (Needle y) -> Needle x -> Needle y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Needle x
v)y -> Needle y -> y
forall x. Semimanifold x => x -> Needle x -> x
.+~^(LinearMap s (SymmetricTensor s (Needle x)) (Needle y)
ð²x'f LinearMap s (SymmetricTensor s (Needle x)) (Needle y)
-> SymmetricTensor s (Needle x) -> Needle y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Needle x -> SymmetricTensor s (Needle x)
forall s v.
(Num' s, s ~ Scalar v, TensorSpace v) =>
v -> SymmetricTensor s v
squareV Needle x
v)
                            , ( LinearMap s (Needle x) (Needle y)
ðx'f₀ LinearMap s (Needle x) (Needle y)
-> LinearMap s (Needle x) (Needle y)
-> LinearMap s (Needle x) (Needle y)
forall v. AdditiveGroup v => v -> v -> v
^+^ Scalar (LinearMap s (Needle x) (Needle y))
2Scalar (LinearMap s (Needle x) (Needle y))
-> LinearMap s (Needle x) (Needle y)
-> LinearMap s (Needle x) (Needle y)
forall v. VectorSpace v => Scalar v -> v -> v
*^((LinearFunction
  (Scalar (Needle x))
  (LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
  (LinearMap s (Needle x) (LinearMap s (Needle x) (Needle y)))
forall v w. LinearSpace v => (v ⊗〃+> w) -+> (v +> (v +> w))
currySymBilin LinearFunction
  (Scalar (Needle x))
  (LinearMap s (SymmetricTensor s (Needle x)) (Needle y))
  (LinearMap s (Needle x) (LinearMap s (Needle x) (Needle y)))
-> LinearMap s (SymmetricTensor s (Needle x)) (Needle y)
-> LinearMap s (Needle x) (LinearMap s (Needle x) (Needle y))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (SymmetricTensor s (Needle x)) (Needle y)
ð²x'f) LinearMap s (Needle x) (LinearMap s (Needle x) (Needle y))
-> Needle x -> LinearMap s (Needle x) (Needle y)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Needle x
v)
                              , LinearMap s (SymmetricTensor s (Needle x)) (Needle y)
ð²x'f
                              ) )
        where Just Needle x
v = x
x x -> x -> Maybe (Needle x)
forall x. PseudoAffine x => x -> x -> Maybe (Needle x)
.-~. ChartIndex x -> x
forall m. Atlas m => ChartIndex m -> m
chartReferencePoint ChartIndex x
chIx
              chIx :: ChartIndex x
chIx = x -> ChartIndex x
forall m. Atlas m => m -> ChartIndex m
lookupAtlas x
x
              (y
fx₀, (LinearMap s (Needle x) (Needle y)
ðx'f₀, LinearMap s (SymmetricTensor s (Needle x)) (Needle y)
ð²x'f)) = (ChartIndex x
 :->: (y,
       (LinearMap s (Needle x) (Needle y),
        LinearMap s (SymmetricTensor s (Needle x)) (Needle y))))
-> ChartIndex x
-> (y,
    (LinearMap s (Needle x) (Needle y),
     LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
forall a b. HasTrie a => (a :->: b) -> a -> b
untrie ChartIndex x
:->: (y,
      (LinearMap s (Needle x) (Needle y),
       LinearMap s (SymmetricTensor s (Needle x)) (Needle y)))
f ChartIndex x
chIx