-- |
-- Module      : Math.LinearMap.Category.Instances
-- Copyright   : (c) Justus Sagemüller 2016-2019
-- License     : GPL v3
-- 
-- Maintainer  : (@) jsag $ hvl.no
-- Stability   : experimental
-- Portability : portable
-- 
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE ConstraintKinds            #-}
{-# LANGUAGE UndecidableInstances       #-}
{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE UnicodeSyntax              #-}
{-# LANGUAGE CPP                        #-}
{-# LANGUAGE TupleSections              #-}
{-# LANGUAGE EmptyCase                  #-}
{-# LANGUAGE TypeApplications           #-}

module Math.LinearMap.Category.Instances where

import Math.LinearMap.Category.Class

import Data.VectorSpace
import Data.Basis

#if MIN_VERSION_manifolds_core(0,6,0)
import Math.Manifold.Core.Types (EmptyMfd)
#endif
import Math.Manifold.Core.PseudoAffine

import Prelude ()
import qualified Prelude as Hask

import Control.Category.Constrained.Prelude
import Control.Arrow.Constrained

import Data.Coerce
import Data.Type.Coercion
import Data.Tagged

import Data.Foldable (foldl')

import Data.VectorSpace.Free
import Data.VectorSpace.Free.FiniteSupportedSequence
import Data.VectorSpace.Free.Sequence as Seq
import qualified Linear.Matrix as Mat
import qualified Linear.Vector as Mat
import qualified Linear.Metric as Mat
import Linear ( V0(V0), V1(V1), V2(V2), V3(V3), V4(V4)
              , _x, _y, _z, _w )
import Control.Lens ((^.))

import qualified Data.Vector as Arr
import qualified Data.Vector.Unboxed as UArr

import Math.LinearMap.Asserted
import Math.VectorSpace.ZeroDimensional

import qualified Test.QuickCheck as QC

import qualified GHC.Exts as GHC
import qualified GHC.Generics as GHC


#if MIN_VERSION_manifolds_core(0,6,0)
instance LinearSpace v => Semimanifold (EmptyMfd v) where
  type Needle (EmptyMfd v) = v
  EmptyMfd v
p .+~^ :: EmptyMfd v -> Needle (EmptyMfd v) -> EmptyMfd v
.+~^ Needle (EmptyMfd v)
_ = case EmptyMfd v
p of {}
  EmptyMfd v
p .-~^ :: EmptyMfd v -> Needle (EmptyMfd v) -> EmptyMfd v
.-~^ Needle (EmptyMfd v)
_ = case EmptyMfd v
p of {}
  semimanifoldWitness :: SemimanifoldWitness (EmptyMfd v)
semimanifoldWitness = case TensorSpace v => LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @v of
    LinearManifoldWitness v
LinearManifoldWitness -> SemimanifoldWitness (EmptyMfd v)
forall x.
(Semimanifold (Needle x), Needle (Needle x) ~ Needle x) =>
SemimanifoldWitness x
SemimanifoldWitness
instance LinearSpace v => PseudoAffine (EmptyMfd v) where
  EmptyMfd v
p .-~. :: EmptyMfd v -> EmptyMfd v -> Maybe (Needle (EmptyMfd v))
.-~. EmptyMfd v
_ = case EmptyMfd v
p of {}
  EmptyMfd v
p .-~! :: EmptyMfd v -> EmptyMfd v -> Needle (EmptyMfd v)
.-~! EmptyMfd v
_ = case EmptyMfd v
p of {}
#endif


infixr 7 <.>^
(<.>^) :: LinearSpace v => DualVector v -> v -> Scalar v
DualVector v
f<.>^ :: DualVector v -> v -> Scalar v
<.>^v
v = (LinearFunction
  (Scalar (DualVector v))
  (DualVector v)
  (LinearFunction (Scalar (DualVector v)) v (Scalar v))
forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorLinearFunction
  (Scalar (DualVector v))
  (DualVector v)
  (LinearFunction (Scalar (DualVector v)) v (Scalar v))
-> DualVector v
-> LinearFunction (Scalar (DualVector v)) v (Scalar v)
forall s v w. LinearFunction s v w -> v -> w
-+$>DualVector v
f)LinearFunction (Scalar (DualVector v)) v (Scalar v)
-> v -> Scalar v
forall s v w. LinearFunction s v w -> v -> w
-+$>v
v

type  = Double

autoLinearManifoldWitness :: (Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v
#if !MIN_VERSION_manifolds_core(0,6,0)
                             , v ~ Interior v
#endif
                             )
                                 => LinearManifoldWitness v
autoLinearManifoldWitness :: LinearManifoldWitness v
autoLinearManifoldWitness = LinearManifoldWitness v
forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
                             BoundarylessWitness
#endif

#define LinearScalarSpace(S) \
instance Num' (S) where {closedScalarWitness = ClosedScalarWitness}; \
instance TensorSpace (S) where { \
  type TensorProduct (S) w = w; \
  scalarSpaceWitness = ScalarSpaceWitness; \
  linearManifoldWitness = autoLinearManifoldWitness; \
  zeroTensor = Tensor zeroV; \
  scaleTensor = bilinearFunction $ \μ (Tensor t) -> Tensor $ μ*^t; \
  addTensors (Tensor v) (Tensor w) = Tensor $ v ^+^ w; \
  subtractTensors (Tensor v) (Tensor w) = Tensor $ v ^-^ w; \
  negateTensor = pretendLike Tensor lNegateV; \
  toFlatTensor = follow Tensor; \
  fromFlatTensor = flout Tensor; \
  tensorProduct = LinearFunction $ \μ -> follow Tensor . scaleWith μ; \
  transposeTensor = toFlatTensor . flout Tensor; \
  fmapTensor = LinearFunction $ pretendLike Tensor; \
  fzipTensorWith = LinearFunction \
                   $ \f -> follow Tensor <<< f <<< flout Tensor *** flout Tensor; \
  coerceFmapTensorProduct _ Coercion = Coercion; \
  wellDefinedTensor (Tensor w) = Tensor <$> wellDefinedVector w }; \
instance LinearSpace (S) where { \
  type DualVector (S) = (S); \
  dualSpaceWitness = DualSpaceWitness; \
  linearId = LinearMap 1; \
  tensorId = uncurryLinearMap $ LinearMap $ fmap (follow Tensor) -+$> id; \
  idTensor = Tensor 1; \
  fromLinearForm = flout LinearMap; \
  coerceDoubleDual = Coercion; \
  contractTensorMap = flout Tensor . flout LinearMap; \
  contractMapTensor = flout LinearMap . flout Tensor; \
  applyDualVector = scale; \
  applyLinear = LinearFunction $ \(LinearMap w) -> scaleV w; \
  applyTensorFunctional = bilinearFunction $ \(LinearMap du) (Tensor u) -> du<.>^u; \
  applyTensorLinMap = bilinearFunction $ \fℝuw (Tensor u) \
                        -> let LinearMap fuw = curryLinearMap $ fℝuw \
                           in (applyLinear-+$>fuw) -+$> u; \
  composeLinear = bilinearFunction $ \f (LinearMap g) \
                     -> LinearMap $ (applyLinear-+$>f)-+$>g; \
  useTupleLinearSpaceComponents _ = usingNonTupleTypeAsTupleError }

LinearScalarSpace()
LinearScalarSpace(Float)
LinearScalarSpace(Rational)


#if MIN_VERSION_manifolds_core(0,6,0)
#define FreeLinSpaceInteriorDecls
#else
#define FreeLinSpaceInteriorDecls \
  toInterior = pure; fromInterior = id; translateP = Tagged (^+^);
#endif

#define FreeLinearSpace(V, LV, tp, tenspl, tenid, dspan, contraction, contraaction)  \
instance Num s => Semimanifold (V s) where {  \
  type Needle (V s) = V s;                      \
  FreeLinSpaceInteriorDecls                      \
  (.+~^) = (^+^) };                               \
instance Num s => PseudoAffine (V s) where {         \
  v.-~.w = pure (v^-^w); (.-~!) = (^-^) };              \
instance ∀ s . (Num' s, Eq s) => TensorSpace (V s) where {                     \
  type TensorProduct (V s) w = V w;                               \
  scalarSpaceWitness = case closedScalarWitness :: ClosedScalarWitness s of{ \
                         ClosedScalarWitness -> ScalarSpaceWitness};        \
  linearManifoldWitness = autoLinearManifoldWitness;   \
  zeroTensor = Tensor $ pure zeroV;                                \
  addTensors (Tensor m) (Tensor n) = Tensor $ liftA2 (^+^) m n;     \
  subtractTensors (Tensor m) (Tensor n) = Tensor $ liftA2 (^-^) m n; \
  negateTensor = LinearFunction $ Tensor . fmap negateV . getTensorProduct;  \
  scaleTensor = bilinearFunction   \
          $ \μ -> Tensor . fmap (μ*^) . getTensorProduct; \
  toFlatTensor = case closedScalarWitness :: ClosedScalarWitness s of{ \
                         ClosedScalarWitness -> follow Tensor}; \
  fromFlatTensor = case closedScalarWitness :: ClosedScalarWitness s of{ \
                         ClosedScalarWitness -> flout Tensor}; \
  tensorProduct = bilinearFunction $ \w v -> Tensor $ fmap (*^v) w; \
  transposeTensor = LinearFunction (tp); \
  fmapTensor = bilinearFunction $       \
          \(LinearFunction f) -> pretendLike Tensor $ fmap f; \
  fzipTensorWith = bilinearFunction $ \
          \(LinearFunction f) (Tensor vw, Tensor vx) \
                  -> Tensor $ liftA2 (curry f) vw vx; \
  coerceFmapTensorProduct _ Coercion = Coercion; \
  wellDefinedTensor = getTensorProduct >>> Hask.traverse wellDefinedVector \
                       >>> fmap Tensor };                  \
instance ∀ s . (Num' s, Eq s) => LinearSpace (V s) where {                  \
  type DualVector (V s) = V s;                                 \
  dualSpaceWitness = case closedScalarWitness :: ClosedScalarWitness s of \
         {ClosedScalarWitness -> DualSpaceWitness};                    \
  linearId = LV Mat.identity;                                   \
  idTensor = Tensor Mat.identity; \
  tensorId = ti dualSpaceWitness where     \
   { ti :: ∀ w . (LinearSpace w, Scalar w ~ s) => DualSpaceWitness w -> (V s⊗w)+>(V s⊗w) \
   ; ti DualSpaceWitness = LinearMap $ \
          fmap (\f -> fmap (LinearFunction $ Tensor . f)-+$>asTensor $ id) \
               (tenid :: V (w -> V w)) }; \
  coerceDoubleDual = Coercion; \
  fromLinearForm = case closedScalarWitness :: ClosedScalarWitness s of{ \
                         ClosedScalarWitness -> flout LinearMap}; \
  contractTensorMap = LinearFunction $ (contraction) . coerce . getLinearMap;      \
  contractMapTensor = LinearFunction $ (contraction) . coerce . getTensorProduct;      \
{-contractTensorWith = bilinearFunction $ \
            \(Tensor wv) dw -> fmap (arr $ applyDualVector $ dw) wv;  -}    \
  contractLinearMapAgainst = bilinearFunction $ getLinearMap >>> (contraaction); \
  applyDualVector = bilinearFunction Mat.dot;           \
  applyLinear = bilinearFunction $ \(LV m)                        \
                  -> foldl' (^+^) zeroV . liftA2 (^*) m;           \
  applyTensorFunctional = bilinearFunction $ \(LinearMap f) (Tensor t) \
             -> sum $ liftA2 (<.>^) f t; \
  applyTensorLinMap = bilinearFunction $ \(LinearMap f) (Tensor t) \
             -> foldl' (^+^) zeroV $ liftA2 (arr fromTensor >>> \
                         getLinearFunction . getLinearFunction applyLinear) f t; \
  composeLinear = bilinearFunction $   \
         \f (LinearMap g) -> LinearMap $ fmap ((applyLinear-+$>f)-+$>) g; \
  useTupleLinearSpaceComponents _ = usingNonTupleTypeAsTupleError }
FreeLinearSpace( V0
               , LinearMap
               , \(Tensor V0) -> zeroV
               , \_ -> LinearMap V0
               , V0
               , LinearMap V0
               , \V0 -> zeroV
               , \V0 _ -> 0 )
FreeLinearSpace( V1
               , LinearMap
               , \(Tensor (V1 w₀)) -> w₀V1 1
               , \w -> LinearMap $ V1 (Tensor $ V1 w)
               , V1 V1
               , LinearMap . V1 . blockVectSpan $ V1 1
               , \(V1 (V1 w)) -> w
               , \(V1 x) f -> (f$x)^._x )
FreeLinearSpace( V2
               , LinearMap
               , \(Tensor (V2 w₀ w₁)) -> w₀V2 1 0
                                     ^+^ w₁V2 0 1
               , \w -> LinearMap $ V2 (Tensor $ V2 w zeroV)
                                      (Tensor $ V2 zeroV w)
               , V2 (`V2`zeroV) (V2 zeroV)
               , LinearMap $ V2 (blockVectSpan $ V2 1 0)
                                (blockVectSpan $ V2 0 1)
               , \(V2 (V2 w₀ _)
                      (V2 _ w₁)) -> w₀^+^w₁
               , \(V2 x y) f -> (f$x)^._x + (f$y)^._y )
FreeLinearSpace( V3
               , LinearMap
               , \(Tensor (V3 w₀ w₁ w₂)) -> w₀V3 1 0 0
                                        ^+^ w₁V3 0 1 0
                                        ^+^ w₂V3 0 0 1
               , \w -> LinearMap $ V3 (Tensor $ V3 w zeroV zeroV)
                                      (Tensor $ V3 zeroV w zeroV)
                                      (Tensor $ V3 zeroV zeroV w)
               , V3 (\w -> V3 w zeroV zeroV)
                    (\w -> V3 zeroV w zeroV)
                    (\w -> V3 zeroV zeroV w)
               , LinearMap $ V3 (blockVectSpan $ V3 1 0 0)
                                (blockVectSpan $ V3 0 1 0)
                                (blockVectSpan $ V3 0 0 1)
               , \(V3 (V3 w₀ _ _)
                      (V3 _ w₁ _)
                      (V3 _ _ w₂)) -> w₀^+^w₁^+^w₂
               , \(V3 x y z) f -> (f$x)^._x + (f$y)^._y + (f$z)^._z )
FreeLinearSpace( V4
               , LinearMap
               , \(Tensor (V4 w₀ w₁ w₂ w₃)) -> w₀V4 1 0 0 0
                                           ^+^ w₁V4 0 1 0 0
                                           ^+^ w₂V4 0 0 1 0
                                           ^+^ w₃V4 0 0 0 1
               , \w -> V4 (LinearMap $ V4 w zeroV zeroV zeroV)
                          (LinearMap $ V4 zeroV w zeroV zeroV)
                          (LinearMap $ V4 zeroV zeroV w zeroV)
                          (LinearMap $ V4 zeroV zeroV zeroV w)
               , V4 (\w -> V4 w zeroV zeroV zeroV)
                    (\w -> V4 zeroV w zeroV zeroV)
                    (\w -> V4 zeroV zeroV w zeroV)
                    (\w -> V4 zeroV zeroV zeroV w)
               , LinearMap $ V4 (blockVectSpan $ V4 1 0 0 0)
                                (blockVectSpan $ V4 0 1 0 0)
                                (blockVectSpan $ V4 0 0 1 0)
                                (blockVectSpan $ V4 0 0 0 1)
               , \(V4 (V4 w₀ _ _ _)
                      (V4 _ w₁ _ _)
                      (V4 _ _ w₂ _)
                      (V4 _ _ _ w₃)) -> w₀^+^w₁^+^w₂^+^w₃
               , \(V4 x y z w) f -> (f$x)^._x + (f$y)^._y + (f$z)^._z + (f$w)^._w )



instance (Num' n, TensorProduct (DualVector n) n ~ n) => Num (LinearMap n n n) where
  LinearMap TensorProduct (DualVector n) n
n + :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
+ LinearMap TensorProduct (DualVector n) n
m = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n) -> n -> LinearMap n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
TensorProduct (DualVector n) n
n n -> n -> n
forall a. Num a => a -> a -> a
+ n
TensorProduct (DualVector n) n
m
  LinearMap TensorProduct (DualVector n) n
n - :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
- LinearMap TensorProduct (DualVector n) n
m = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n) -> n -> LinearMap n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
TensorProduct (DualVector n) n
n n -> n -> n
forall a. Num a => a -> a -> a
- n
TensorProduct (DualVector n) n
m
  LinearMap TensorProduct (DualVector n) n
n * :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
* LinearMap TensorProduct (DualVector n) n
m = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n) -> n -> LinearMap n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
TensorProduct (DualVector n) n
n n -> n -> n
forall a. Num a => a -> a -> a
* n
TensorProduct (DualVector n) n
m
  abs :: LinearMap n n n -> LinearMap n n n
abs (LinearMap TensorProduct (DualVector n) n
n) = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n) -> n -> LinearMap n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n -> n
forall a. Num a => a -> a
abs n
TensorProduct (DualVector n) n
n
  signum :: LinearMap n n n -> LinearMap n n n
signum (LinearMap TensorProduct (DualVector n) n
n) = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n) -> n -> LinearMap n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n -> n
forall a. Num a => a -> a
signum n
TensorProduct (DualVector n) n
n
  fromInteger :: Integer -> LinearMap n n n
fromInteger = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n)
-> (Integer -> n) -> Integer -> LinearMap n n n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Integer -> n
forall a. Num a => Integer -> a
fromInteger
   
instance (Fractional' n, TensorProduct (DualVector n) n ~ n)
                           => Fractional (LinearMap n n n) where
  LinearMap TensorProduct (DualVector n) n
n / :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
/ LinearMap TensorProduct (DualVector n) n
m = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n) -> n -> LinearMap n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
TensorProduct (DualVector n) n
n n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
TensorProduct (DualVector n) n
m
  recip :: LinearMap n n n -> LinearMap n n n
recip (LinearMap TensorProduct (DualVector n) n
n) = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n) -> n -> LinearMap n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n -> n
forall a. Fractional a => a -> a
recip n
TensorProduct (DualVector n) n
n
  fromRational :: Rational -> LinearMap n n n
fromRational = n -> LinearMap n n n
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (n -> LinearMap n n n)
-> (Rational -> n) -> Rational -> LinearMap n n n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Rational -> n
forall a. Fractional a => Rational -> a
fromRational



instance (Num' n, UArr.Unbox n) => Semimanifold (FinSuppSeq n) where
  type Needle (FinSuppSeq n) = FinSuppSeq n
  .+~^ :: FinSuppSeq n -> Needle (FinSuppSeq n) -> FinSuppSeq n
(.+~^) = FinSuppSeq n -> Needle (FinSuppSeq n) -> FinSuppSeq n
forall p. AffineSpace p => p -> Diff p -> p
(.+^)
#if !MIN_VERSION_manifolds_core(0,6,0)
  translateP = Tagged (.+^); toInterior = pure; fromInterior = id
#endif

instance (Num' n, UArr.Unbox n) => PseudoAffine (FinSuppSeq n) where
  FinSuppSeq n
v.-~. :: FinSuppSeq n -> FinSuppSeq n -> Maybe (Needle (FinSuppSeq n))
.-~.FinSuppSeq n
w = FinSuppSeq n -> Maybe (FinSuppSeq n)
forall a. a -> Maybe a
Just (FinSuppSeq n -> Maybe (FinSuppSeq n))
-> FinSuppSeq n -> Maybe (FinSuppSeq n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ FinSuppSeq n
vFinSuppSeq n -> FinSuppSeq n -> Diff (FinSuppSeq n)
forall p. AffineSpace p => p -> p -> Diff p
.-.FinSuppSeq n
w; .-~! :: FinSuppSeq n -> FinSuppSeq n -> Needle (FinSuppSeq n)
(.-~!) = FinSuppSeq n -> FinSuppSeq n -> Needle (FinSuppSeq n)
forall p. AffineSpace p => p -> p -> Diff p
(.-.)

instance (Num' n, UArr.Unbox n) => TensorSpace (FinSuppSeq n) where
  type TensorProduct (FinSuppSeq n) v = [v]
  wellDefinedVector :: FinSuppSeq n -> Maybe (FinSuppSeq n)
wellDefinedVector (FinSuppSeq Vector n
v) = Vector n -> FinSuppSeq n
forall n. Vector n -> FinSuppSeq n
FinSuppSeq (Vector n -> FinSuppSeq n)
-> Maybe (Vector n) -> Maybe (FinSuppSeq n)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> (n -> Maybe n) -> Vector n -> Maybe (Vector n)
forall (m :: * -> *) a b.
(Monad m, Unbox a, Unbox b) =>
(a -> m b) -> Vector a -> m (Vector b)
UArr.mapM n -> Maybe n
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Vector n
v
  scalarSpaceWitness :: ScalarSpaceWitness (FinSuppSeq n)
scalarSpaceWitness = case ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
        ClosedScalarWitness n
ClosedScalarWitness -> ScalarSpaceWitness (FinSuppSeq n)
forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (FinSuppSeq n)
linearManifoldWitness = LinearManifoldWitness (FinSuppSeq n)
forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
LinearManifoldWitness v
autoLinearManifoldWitness
  zeroTensor :: FinSuppSeq n ⊗ w
zeroTensor = TensorProduct (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor []
  toFlatTensor :: FinSuppSeq n -+> (FinSuppSeq n ⊗ Scalar (FinSuppSeq n))
toFlatTensor = (FinSuppSeq n -> Tensor n (FinSuppSeq n) n)
-> LinearFunction n (FinSuppSeq n) (Tensor n (FinSuppSeq n) n)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((FinSuppSeq n -> Tensor n (FinSuppSeq n) n)
 -> LinearFunction n (FinSuppSeq n) (Tensor n (FinSuppSeq n) n))
-> (FinSuppSeq n -> Tensor n (FinSuppSeq n) n)
-> LinearFunction n (FinSuppSeq n) (Tensor n (FinSuppSeq n) n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [n] -> Tensor n (FinSuppSeq n) n
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([n] -> Tensor n (FinSuppSeq n) n)
-> (FinSuppSeq n -> [n])
-> FinSuppSeq n
-> Tensor n (FinSuppSeq n) n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Vector n -> [n]
forall a. Unbox a => Vector a -> [a]
UArr.toList (Vector n -> [n])
-> (FinSuppSeq n -> Vector n) -> FinSuppSeq n -> [n]
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. FinSuppSeq n -> Vector n
forall n. FinSuppSeq n -> Vector n
getFiniteSeq
  fromFlatTensor :: (FinSuppSeq n ⊗ Scalar (FinSuppSeq n)) -+> FinSuppSeq n
fromFlatTensor = (Tensor n (FinSuppSeq n) n -> FinSuppSeq n)
-> LinearFunction n (Tensor n (FinSuppSeq n) n) (FinSuppSeq n)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (FinSuppSeq n) n -> FinSuppSeq n)
 -> LinearFunction n (Tensor n (FinSuppSeq n) n) (FinSuppSeq n))
-> (Tensor n (FinSuppSeq n) n -> FinSuppSeq n)
-> LinearFunction n (Tensor n (FinSuppSeq n) n) (FinSuppSeq n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Vector n -> FinSuppSeq n
forall n. Vector n -> FinSuppSeq n
FinSuppSeq (Vector n -> FinSuppSeq n)
-> (Tensor n (FinSuppSeq n) n -> Vector n)
-> Tensor n (FinSuppSeq n) n
-> FinSuppSeq n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. [n] -> Vector n
forall a. Unbox a => [a] -> Vector a
UArr.fromList ([n] -> Vector n)
-> (Tensor n (FinSuppSeq n) n -> [n])
-> Tensor n (FinSuppSeq n) n
-> Vector n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Tensor n (FinSuppSeq n) n -> [n]
forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
  addTensors :: (FinSuppSeq n ⊗ w) -> (FinSuppSeq n ⊗ w) -> FinSuppSeq n ⊗ w
addTensors (Tensor TensorProduct (FinSuppSeq n) w
s) (Tensor TensorProduct (FinSuppSeq n) w
t) = [w] -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (FinSuppSeq n) w)
-> [w] -> Tensor n (FinSuppSeq n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> w -> w) -> [w] -> [w] -> [w]
forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 w -> w -> w
forall v. AdditiveGroup v => v -> v -> v
(^+^) [w]
TensorProduct (FinSuppSeq n) w
s [w]
TensorProduct (FinSuppSeq n) w
t
  subtractTensors :: (FinSuppSeq n ⊗ w) -> (FinSuppSeq n ⊗ w) -> FinSuppSeq n ⊗ w
subtractTensors (Tensor TensorProduct (FinSuppSeq n) w
s) (Tensor TensorProduct (FinSuppSeq n) w
t) = [w] -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (FinSuppSeq n) w)
-> [w] -> Tensor n (FinSuppSeq n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> w -> w) -> [w] -> [w] -> [w]
forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 w -> w -> w
forall v. AdditiveGroup v => v -> v -> v
(^-^) [w]
TensorProduct (FinSuppSeq n) w
s [w]
TensorProduct (FinSuppSeq n) w
t
  scaleTensor :: Bilinear
  (Scalar (FinSuppSeq n)) (FinSuppSeq n ⊗ w) (FinSuppSeq n ⊗ w)
scaleTensor = (n -> Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction
     (Scalar n)
     n
     (LinearFunction
        (Scalar n) (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) w))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((n -> Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) w)
 -> LinearFunction
      (Scalar n)
      n
      (LinearFunction
         (Scalar n)
         (Tensor n (FinSuppSeq n) w)
         (Tensor n (FinSuppSeq n) w)))
-> (n -> Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction
     (Scalar n)
     n
     (LinearFunction
        (Scalar n) (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) w))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
μ (Tensor TensorProduct (FinSuppSeq n) w
t) -> [w] -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (FinSuppSeq n) w)
-> [w] -> Tensor n (FinSuppSeq n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (n
Scalar w
μScalar w -> w -> w
forall v. VectorSpace v => Scalar v -> v -> v
*^)(w -> w) -> [w] -> [w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>[w]
TensorProduct (FinSuppSeq n) w
t
  negateTensor :: (FinSuppSeq n ⊗ w) -+> (FinSuppSeq n ⊗ w)
negateTensor = (Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction
     n (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) w)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) w)
 -> LinearFunction
      n (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) w))
-> (Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction
     n (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (FinSuppSeq n) w
t) -> [w] -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (FinSuppSeq n) w)
-> [w] -> Tensor n (FinSuppSeq n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ w -> w
forall v. AdditiveGroup v => v -> v
negateV(w -> w) -> [w] -> [w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>[w]
TensorProduct (FinSuppSeq n) w
t
  tensorProduct :: Bilinear (FinSuppSeq n) w (FinSuppSeq n ⊗ w)
tensorProduct = (FinSuppSeq n -> w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction
     n (FinSuppSeq n) (LinearFunction n w (Tensor n (FinSuppSeq n) w))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
                    ((FinSuppSeq n -> w -> Tensor n (FinSuppSeq n) w)
 -> LinearFunction
      n (FinSuppSeq n) (LinearFunction n w (Tensor n (FinSuppSeq n) w)))
-> (FinSuppSeq n -> w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction
     n (FinSuppSeq n) (LinearFunction n w (Tensor n (FinSuppSeq n) w))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(FinSuppSeq Vector n
v) w
w -> [w] -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (FinSuppSeq n) w)
-> [w] -> Tensor n (FinSuppSeq n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Scalar w -> w -> w
forall v. VectorSpace v => Scalar v -> v -> v
*^w
w)(n -> w) -> [n] -> [w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>Vector n -> [n]
forall a. Unbox a => Vector a -> [a]
UArr.toList Vector n
v
  transposeTensor :: (FinSuppSeq n ⊗ w) -+> (w ⊗ FinSuppSeq n)
transposeTensor = (Tensor n (FinSuppSeq n) w -> w ⊗ FinSuppSeq n)
-> LinearFunction n (Tensor n (FinSuppSeq n) w) (w ⊗ FinSuppSeq n)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (FinSuppSeq n) w -> w ⊗ FinSuppSeq n)
 -> LinearFunction n (Tensor n (FinSuppSeq n) w) (w ⊗ FinSuppSeq n))
-> (Tensor n (FinSuppSeq n) w -> w ⊗ FinSuppSeq n)
-> LinearFunction n (Tensor n (FinSuppSeq n) w) (w ⊗ FinSuppSeq n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (FinSuppSeq n) w
a)
    -> let n :: Int
n = [w] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [w]
TensorProduct (FinSuppSeq n) w
a
       in ((w ⊗ FinSuppSeq n) -> (w ⊗ FinSuppSeq n) -> w ⊗ FinSuppSeq n)
-> (w ⊗ FinSuppSeq n) -> [w ⊗ FinSuppSeq n] -> w ⊗ FinSuppSeq n
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (w ⊗ FinSuppSeq n) -> (w ⊗ FinSuppSeq n) -> w ⊗ FinSuppSeq n
forall v. AdditiveGroup v => v -> v -> v
(^+^) w ⊗ FinSuppSeq n
forall v. AdditiveGroup v => v
zeroV
        ([w ⊗ FinSuppSeq n] -> w ⊗ FinSuppSeq n)
-> [w ⊗ FinSuppSeq n] -> w ⊗ FinSuppSeq n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Int -> w -> w ⊗ FinSuppSeq n)
-> [Int] -> [w] -> [w ⊗ FinSuppSeq n]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ( \Int
i w
w -> LinearFunction
  n w (LinearFunction (Scalar w) (FinSuppSeq n) (w ⊗ FinSuppSeq n))
-> w -> LinearFunction (Scalar w) (FinSuppSeq n) (w ⊗ FinSuppSeq n)
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  n w (LinearFunction (Scalar w) (FinSuppSeq n) (w ⊗ FinSuppSeq n))
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProduct w
w LinearFunction (Scalar w) (FinSuppSeq n) (w ⊗ FinSuppSeq n)
-> FinSuppSeq n -> w ⊗ FinSuppSeq n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Basis (FinSuppSeq n) -> FinSuppSeq n
forall v. HasBasis v => Basis v -> v
basisValue Int
Basis (FinSuppSeq n)
i )
             [Int
0..] [w]
TensorProduct (FinSuppSeq n) w
a
  fmapTensor :: Bilinear (w -+> x) (FinSuppSeq n ⊗ w) (FinSuppSeq n ⊗ x)
fmapTensor = (LinearFunction n w x
 -> Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) x)
-> LinearFunction
     (Scalar x)
     (LinearFunction n w x)
     (LinearFunction
        (Scalar x) (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) x))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearFunction n w x
  -> Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) x)
 -> LinearFunction
      (Scalar x)
      (LinearFunction n w x)
      (LinearFunction
         (Scalar x)
         (Tensor n (FinSuppSeq n) w)
         (Tensor n (FinSuppSeq n) x)))
-> (LinearFunction n w x
    -> Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) x)
-> LinearFunction
     (Scalar x)
     (LinearFunction n w x)
     (LinearFunction
        (Scalar x) (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) x))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n w x
f (Tensor TensorProduct (FinSuppSeq n) w
a) -> [x] -> Tensor n (FinSuppSeq n) x
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([x] -> Tensor n (FinSuppSeq n) x)
-> [x] -> Tensor n (FinSuppSeq n) x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> x) -> [w] -> [x]
forall a b. (a -> b) -> [a] -> [b]
map (LinearFunction n w x
fLinearFunction n w x -> w -> x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$) [w]
TensorProduct (FinSuppSeq n) w
a
  fzipTensorWith :: Bilinear
  ((w, x) -+> u)
  (FinSuppSeq n ⊗ w, FinSuppSeq n ⊗ x)
  (FinSuppSeq n ⊗ u)
fzipTensorWith = (LinearFunction n (w, x) u
 -> (Tensor n (FinSuppSeq n) w, Tensor n (FinSuppSeq n) x)
 -> Tensor n (FinSuppSeq n) u)
-> LinearFunction
     (Scalar u)
     (LinearFunction n (w, x) u)
     (LinearFunction
        (Scalar u)
        (Tensor n (FinSuppSeq n) w, Tensor n (FinSuppSeq n) x)
        (Tensor n (FinSuppSeq n) u))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearFunction n (w, x) u
  -> (Tensor n (FinSuppSeq n) w, Tensor n (FinSuppSeq n) x)
  -> Tensor n (FinSuppSeq n) u)
 -> LinearFunction
      (Scalar u)
      (LinearFunction n (w, x) u)
      (LinearFunction
         (Scalar u)
         (Tensor n (FinSuppSeq n) w, Tensor n (FinSuppSeq n) x)
         (Tensor n (FinSuppSeq n) u)))
-> (LinearFunction n (w, x) u
    -> (Tensor n (FinSuppSeq n) w, Tensor n (FinSuppSeq n) x)
    -> Tensor n (FinSuppSeq n) u)
-> LinearFunction
     (Scalar u)
     (LinearFunction n (w, x) u)
     (LinearFunction
        (Scalar u)
        (Tensor n (FinSuppSeq n) w, Tensor n (FinSuppSeq n) x)
        (Tensor n (FinSuppSeq n) u))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n (w, x) u
f (Tensor TensorProduct (FinSuppSeq n) w
a, Tensor TensorProduct (FinSuppSeq n) x
b)
                     -> [u] -> Tensor n (FinSuppSeq n) u
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([u] -> Tensor n (FinSuppSeq n) u)
-> [u] -> Tensor n (FinSuppSeq n) u
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> x -> u) -> [w] -> [x] -> [u]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (((w, x) -> u) -> w -> x -> u
forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k (a, b) c -> k a (k b c)
curry (((w, x) -> u) -> w -> x -> u) -> ((w, x) -> u) -> w -> x -> u
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction n (w, x) u -> (w, x) -> u
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr LinearFunction n (w, x) u
f) [w]
TensorProduct (FinSuppSeq n) w
a [x]
TensorProduct (FinSuppSeq n) x
b
  coerceFmapTensorProduct :: p (FinSuppSeq n)
-> Coercion a b
-> Coercion
     (TensorProduct (FinSuppSeq n) a) (TensorProduct (FinSuppSeq n) b)
coerceFmapTensorProduct p (FinSuppSeq n)
_ Coercion a b
Coercion = Coercion
  (TensorProduct (FinSuppSeq n) a) (TensorProduct (FinSuppSeq n) b)
forall k (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
  wellDefinedTensor :: (FinSuppSeq n ⊗ w) -> Maybe (FinSuppSeq n ⊗ w)
wellDefinedTensor (Tensor TensorProduct (FinSuppSeq n) w
a) = [w] -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (FinSuppSeq n) w)
-> Maybe [w] -> Maybe (Tensor n (FinSuppSeq n) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> (w -> Maybe w) -> [w] -> Maybe [w]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
Hask.traverse w -> Maybe w
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector [w]
TensorProduct (FinSuppSeq n) w
a
  

instance (Num' n, UArr.Unbox n) => Semimanifold (Sequence n) where
  type Needle (Sequence n) = Sequence n
  .+~^ :: Sequence n -> Needle (Sequence n) -> Sequence n
(.+~^) = Sequence n -> Needle (Sequence n) -> Sequence n
forall p. AffineSpace p => p -> Diff p -> p
(.+^)
#if !MIN_VERSION_manifolds_core(0,6,0)
  translateP = Tagged (.+^); toInterior = pure; fromInterior = id
#endif

instance (Num' n, UArr.Unbox n) => PseudoAffine (Sequence n) where
  Sequence n
v.-~. :: Sequence n -> Sequence n -> Maybe (Needle (Sequence n))
.-~.Sequence n
w = Sequence n -> Maybe (Sequence n)
forall a. a -> Maybe a
Just (Sequence n -> Maybe (Sequence n))
-> Sequence n -> Maybe (Sequence n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Sequence n
vSequence n -> Sequence n -> Diff (Sequence n)
forall p. AffineSpace p => p -> p -> Diff p
.-.Sequence n
w; .-~! :: Sequence n -> Sequence n -> Needle (Sequence n)
(.-~!) = Sequence n -> Sequence n -> Needle (Sequence n)
forall p. AffineSpace p => p -> p -> Diff p
(.-.)

instance (Num' n, UArr.Unbox n) => TensorSpace (Sequence n) where
  type TensorProduct (Sequence n) v = [v]
  wellDefinedVector :: Sequence n -> Maybe (Sequence n)
wellDefinedVector (SoloChunk Int
n Vector n
c) = Int -> Vector n -> Sequence n
forall (array :: * -> *) n. Int -> array n -> GSequence array n
SoloChunk Int
n (Vector n -> Sequence n) -> Maybe (Vector n) -> Maybe (Sequence n)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> (n -> Maybe n) -> Vector n -> Maybe (Vector n)
forall (m :: * -> *) a b.
(Monad m, Unbox a, Unbox b) =>
(a -> m b) -> Vector a -> m (Vector b)
UArr.mapM n -> Maybe n
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Vector n
c
  wellDefinedVector (Sequence Vector n
h Sequence n
r) = Vector n -> Sequence n -> Sequence n
forall (array :: * -> *) n.
array n -> GSequence array n -> GSequence array n
Sequence (Vector n -> Sequence n -> Sequence n)
-> Maybe (Vector n) -> Maybe (Sequence n -> Sequence n)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> (n -> Maybe n) -> Vector n -> Maybe (Vector n)
forall (m :: * -> *) a b.
(Monad m, Unbox a, Unbox b) =>
(a -> m b) -> Vector a -> m (Vector b)
UArr.mapM n -> Maybe n
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Vector n
h
                                              Maybe (Sequence n -> Sequence n)
-> Maybe (Sequence n) -> Maybe (Sequence n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Applicative f r t, ObjectMorphism r a b,
 ObjectMorphism t (f a) (f b), Object t (t (f a) (f b)),
 ObjectPair r (r a b) a, ObjectPair t (f (r a b)) (f a), Object r a,
 Object r b) =>
t (f (r a b)) (t (f a) (f b))
<*> Sequence n -> Maybe (Sequence n)
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Sequence n
r
  wellDefinedTensor :: (Sequence n ⊗ w) -> Maybe (Sequence n ⊗ w)
wellDefinedTensor (Tensor TensorProduct (Sequence n) w
a) = [w] -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (Sequence n) w)
-> Maybe [w] -> Maybe (Tensor n (Sequence n) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> (w -> Maybe w) -> [w] -> Maybe [w]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
Hask.traverse w -> Maybe w
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector [w]
TensorProduct (Sequence n) w
a
  scalarSpaceWitness :: ScalarSpaceWitness (Sequence n)
scalarSpaceWitness = case ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
        ClosedScalarWitness n
ClosedScalarWitness -> ScalarSpaceWitness (Sequence n)
forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (Sequence n)
linearManifoldWitness = LinearManifoldWitness (Sequence n)
forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
LinearManifoldWitness v
autoLinearManifoldWitness
  zeroTensor :: Sequence n ⊗ w
zeroTensor = TensorProduct (Sequence n) w -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor []
  toFlatTensor :: Sequence n -+> (Sequence n ⊗ Scalar (Sequence n))
toFlatTensor = (Sequence n -> Tensor n (Sequence n) n)
-> LinearFunction n (Sequence n) (Tensor n (Sequence n) n)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Sequence n -> Tensor n (Sequence n) n)
 -> LinearFunction n (Sequence n) (Tensor n (Sequence n) n))
-> (Sequence n -> Tensor n (Sequence n) n)
-> LinearFunction n (Sequence n) (Tensor n (Sequence n) n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [n] -> Tensor n (Sequence n) n
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([n] -> Tensor n (Sequence n) n)
-> (Sequence n -> [n]) -> Sequence n -> Tensor n (Sequence n) n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Sequence n -> [n]
forall l. IsList l => l -> [Item l]
GHC.toList
  fromFlatTensor :: (Sequence n ⊗ Scalar (Sequence n)) -+> Sequence n
fromFlatTensor = (Tensor n (Sequence n) n -> Sequence n)
-> LinearFunction n (Tensor n (Sequence n) n) (Sequence n)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (Sequence n) n -> Sequence n)
 -> LinearFunction n (Tensor n (Sequence n) n) (Sequence n))
-> (Tensor n (Sequence n) n -> Sequence n)
-> LinearFunction n (Tensor n (Sequence n) n) (Sequence n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [n] -> Sequence n
forall l. IsList l => [Item l] -> l
GHC.fromList ([n] -> Sequence n)
-> (Tensor n (Sequence n) n -> [n])
-> Tensor n (Sequence n) n
-> Sequence n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Tensor n (Sequence n) n -> [n]
forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
  addTensors :: (Sequence n ⊗ w) -> (Sequence n ⊗ w) -> Sequence n ⊗ w
addTensors (Tensor TensorProduct (Sequence n) w
s) (Tensor TensorProduct (Sequence n) w
t) = [w] -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (Sequence n) w) -> [w] -> Tensor n (Sequence n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> w -> w) -> [w] -> [w] -> [w]
forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 w -> w -> w
forall v. AdditiveGroup v => v -> v -> v
(^+^) [w]
TensorProduct (Sequence n) w
s [w]
TensorProduct (Sequence n) w
t
  subtractTensors :: (Sequence n ⊗ w) -> (Sequence n ⊗ w) -> Sequence n ⊗ w
subtractTensors (Tensor TensorProduct (Sequence n) w
s) (Tensor TensorProduct (Sequence n) w
t) = [w] -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (Sequence n) w) -> [w] -> Tensor n (Sequence n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> w -> w) -> [w] -> [w] -> [w]
forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 w -> w -> w
forall v. AdditiveGroup v => v -> v -> v
(^-^) [w]
TensorProduct (Sequence n) w
s [w]
TensorProduct (Sequence n) w
t
  scaleTensor :: Bilinear (Scalar (Sequence n)) (Sequence n ⊗ w) (Sequence n ⊗ w)
scaleTensor = (n -> Tensor n (Sequence n) w -> Tensor n (Sequence n) w)
-> LinearFunction
     (Scalar n)
     n
     (LinearFunction
        (Scalar n) (Tensor n (Sequence n) w) (Tensor n (Sequence n) w))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((n -> Tensor n (Sequence n) w -> Tensor n (Sequence n) w)
 -> LinearFunction
      (Scalar n)
      n
      (LinearFunction
         (Scalar n) (Tensor n (Sequence n) w) (Tensor n (Sequence n) w)))
-> (n -> Tensor n (Sequence n) w -> Tensor n (Sequence n) w)
-> LinearFunction
     (Scalar n)
     n
     (LinearFunction
        (Scalar n) (Tensor n (Sequence n) w) (Tensor n (Sequence n) w))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
μ (Tensor TensorProduct (Sequence n) w
t) -> [w] -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (Sequence n) w) -> [w] -> Tensor n (Sequence n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (n
Scalar w
μScalar w -> w -> w
forall v. VectorSpace v => Scalar v -> v -> v
*^)(w -> w) -> [w] -> [w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>[w]
TensorProduct (Sequence n) w
t
  negateTensor :: (Sequence n ⊗ w) -+> (Sequence n ⊗ w)
negateTensor = (Tensor n (Sequence n) w -> Tensor n (Sequence n) w)
-> LinearFunction
     n (Tensor n (Sequence n) w) (Tensor n (Sequence n) w)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (Sequence n) w -> Tensor n (Sequence n) w)
 -> LinearFunction
      n (Tensor n (Sequence n) w) (Tensor n (Sequence n) w))
-> (Tensor n (Sequence n) w -> Tensor n (Sequence n) w)
-> LinearFunction
     n (Tensor n (Sequence n) w) (Tensor n (Sequence n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (Sequence n) w
t) -> [w] -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (Sequence n) w) -> [w] -> Tensor n (Sequence n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ w -> w
forall v. AdditiveGroup v => v -> v
negateV(w -> w) -> [w] -> [w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>[w]
TensorProduct (Sequence n) w
t
  tensorProduct :: Bilinear (Sequence n) w (Sequence n ⊗ w)
tensorProduct = (Sequence n -> w -> Tensor n (Sequence n) w)
-> LinearFunction
     n (Sequence n) (LinearFunction n w (Tensor n (Sequence n) w))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
                    ((Sequence n -> w -> Tensor n (Sequence n) w)
 -> LinearFunction
      n (Sequence n) (LinearFunction n w (Tensor n (Sequence n) w)))
-> (Sequence n -> w -> Tensor n (Sequence n) w)
-> LinearFunction
     n (Sequence n) (LinearFunction n w (Tensor n (Sequence n) w))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Sequence n
v w
w -> [w] -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (Sequence n) w) -> [w] -> Tensor n (Sequence n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Scalar w -> w -> w
forall v. VectorSpace v => Scalar v -> v -> v
*^w
w)(n -> w) -> [n] -> [w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>Sequence n -> [Item (Sequence n)]
forall l. IsList l => l -> [Item l]
GHC.toList Sequence n
v
  transposeTensor :: (Sequence n ⊗ w) -+> (w ⊗ Sequence n)
transposeTensor = (Tensor n (Sequence n) w -> w ⊗ Sequence n)
-> LinearFunction n (Tensor n (Sequence n) w) (w ⊗ Sequence n)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (Sequence n) w -> w ⊗ Sequence n)
 -> LinearFunction n (Tensor n (Sequence n) w) (w ⊗ Sequence n))
-> (Tensor n (Sequence n) w -> w ⊗ Sequence n)
-> LinearFunction n (Tensor n (Sequence n) w) (w ⊗ Sequence n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (Sequence n) w
a)
    -> let n :: Int
n = [w] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [w]
TensorProduct (Sequence n) w
a
       in ((w ⊗ Sequence n) -> (w ⊗ Sequence n) -> w ⊗ Sequence n)
-> (w ⊗ Sequence n) -> [w ⊗ Sequence n] -> w ⊗ Sequence n
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (w ⊗ Sequence n) -> (w ⊗ Sequence n) -> w ⊗ Sequence n
forall v. AdditiveGroup v => v -> v -> v
(^+^) w ⊗ Sequence n
forall v. AdditiveGroup v => v
zeroV
        ([w ⊗ Sequence n] -> w ⊗ Sequence n)
-> [w ⊗ Sequence n] -> w ⊗ Sequence n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Int -> w -> w ⊗ Sequence n) -> [Int] -> [w] -> [w ⊗ Sequence n]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Int
i w
w -> (LinearFunction
  n w (LinearFunction (Scalar w) (Sequence n) (w ⊗ Sequence n))
-> w -> LinearFunction (Scalar w) (Sequence n) (w ⊗ Sequence n)
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  n w (LinearFunction (Scalar w) (Sequence n) (w ⊗ Sequence n))
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProduct w
w) LinearFunction (Scalar w) (Sequence n) (w ⊗ Sequence n)
-> Sequence n -> w ⊗ Sequence n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Basis (Sequence n) -> Sequence n
forall v. HasBasis v => Basis v -> v
basisValue Int
Basis (Sequence n)
i)
             [Int
0..] [w]
TensorProduct (Sequence n) w
a
  fmapTensor :: Bilinear (w -+> x) (Sequence n ⊗ w) (Sequence n ⊗ x)
fmapTensor = (LinearFunction n w x
 -> Tensor n (Sequence n) w -> Tensor n (Sequence n) x)
-> LinearFunction
     (Scalar x)
     (LinearFunction n w x)
     (LinearFunction
        (Scalar x) (Tensor n (Sequence n) w) (Tensor n (Sequence n) x))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearFunction n w x
  -> Tensor n (Sequence n) w -> Tensor n (Sequence n) x)
 -> LinearFunction
      (Scalar x)
      (LinearFunction n w x)
      (LinearFunction
         (Scalar x) (Tensor n (Sequence n) w) (Tensor n (Sequence n) x)))
-> (LinearFunction n w x
    -> Tensor n (Sequence n) w -> Tensor n (Sequence n) x)
-> LinearFunction
     (Scalar x)
     (LinearFunction n w x)
     (LinearFunction
        (Scalar x) (Tensor n (Sequence n) w) (Tensor n (Sequence n) x))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n w x
f (Tensor TensorProduct (Sequence n) w
a) -> [x] -> Tensor n (Sequence n) x
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([x] -> Tensor n (Sequence n) x) -> [x] -> Tensor n (Sequence n) x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> x) -> [w] -> [x]
forall a b. (a -> b) -> [a] -> [b]
map (LinearFunction n w x
fLinearFunction n w x -> w -> x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$) [w]
TensorProduct (Sequence n) w
a
  fzipTensorWith :: Bilinear
  ((w, x) -+> u) (Sequence n ⊗ w, Sequence n ⊗ x) (Sequence n ⊗ u)
fzipTensorWith = (LinearFunction n (w, x) u
 -> (Tensor n (Sequence n) w, Tensor n (Sequence n) x)
 -> Tensor n (Sequence n) u)
-> LinearFunction
     (Scalar u)
     (LinearFunction n (w, x) u)
     (LinearFunction
        (Scalar u)
        (Tensor n (Sequence n) w, Tensor n (Sequence n) x)
        (Tensor n (Sequence n) u))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearFunction n (w, x) u
  -> (Tensor n (Sequence n) w, Tensor n (Sequence n) x)
  -> Tensor n (Sequence n) u)
 -> LinearFunction
      (Scalar u)
      (LinearFunction n (w, x) u)
      (LinearFunction
         (Scalar u)
         (Tensor n (Sequence n) w, Tensor n (Sequence n) x)
         (Tensor n (Sequence n) u)))
-> (LinearFunction n (w, x) u
    -> (Tensor n (Sequence n) w, Tensor n (Sequence n) x)
    -> Tensor n (Sequence n) u)
-> LinearFunction
     (Scalar u)
     (LinearFunction n (w, x) u)
     (LinearFunction
        (Scalar u)
        (Tensor n (Sequence n) w, Tensor n (Sequence n) x)
        (Tensor n (Sequence n) u))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n (w, x) u
f (Tensor TensorProduct (Sequence n) w
a, Tensor TensorProduct (Sequence n) x
b)
                     -> [u] -> Tensor n (Sequence n) u
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([u] -> Tensor n (Sequence n) u) -> [u] -> Tensor n (Sequence n) u
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (w -> x -> u) -> [w] -> [x] -> [u]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (((w, x) -> u) -> w -> x -> u
forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k (a, b) c -> k a (k b c)
curry (((w, x) -> u) -> w -> x -> u) -> ((w, x) -> u) -> w -> x -> u
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction n (w, x) u -> (w, x) -> u
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr LinearFunction n (w, x) u
f) [w]
TensorProduct (Sequence n) w
a [x]
TensorProduct (Sequence n) x
b
  coerceFmapTensorProduct :: p (Sequence n)
-> Coercion a b
-> Coercion
     (TensorProduct (Sequence n) a) (TensorProduct (Sequence n) b)
coerceFmapTensorProduct p (Sequence n)
_ Coercion a b
Coercion = Coercion
  (TensorProduct (Sequence n) a) (TensorProduct (Sequence n) b)
forall k (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion

instance (Num' n, UArr.Unbox n) => LinearSpace (Sequence n) where
  type DualVector (Sequence n) = FinSuppSeq n
  dualSpaceWitness :: DualSpaceWitness (Sequence n)
dualSpaceWitness = case ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
            ClosedScalarWitness n
ClosedScalarWitness -> DualSpaceWitness (Sequence n)
forall v.
(LinearSpace (Scalar v), DualVector (Scalar v) ~ Scalar v,
 LinearSpace (DualVector v), Scalar (DualVector v) ~ Scalar v,
 DualVector (DualVector v) ~ v) =>
DualSpaceWitness v
DualSpaceWitness
  linearId :: Sequence n +> Sequence n
linearId = TensorProduct (DualVector (Sequence n)) (Sequence n)
-> LinearMap n (Sequence n) (Sequence n)
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [Basis (Sequence n) -> Sequence n
forall v. HasBasis v => Basis v -> v
basisValue Int
Basis (Sequence n)
i | Int
i<-[Int
0..]]
  tensorId :: (Sequence n ⊗ w) +> (Sequence n ⊗ w)
tensorId = TensorProduct
  (DualVector (Tensor n (Sequence n) w)) (Tensor n (Sequence n) w)
-> LinearMap n (Tensor n (Sequence n) w) (Tensor n (Sequence n) w)
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [Coercion
  (LinearMap n w (Tensor n (Sequence n) w))
  (Tensor n (DualVector w) (Tensor n (Sequence n) w))
forall s v w.
Coercion (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor Coercion
  (LinearMap n w (Tensor n (Sequence n) w))
  (Tensor n (DualVector w) (Tensor n (Sequence n) w))
-> LinearMap n w (Tensor n (Sequence n) w)
-> Tensor n (DualVector w) (Tensor n (Sequence n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction n w (Tensor n (Sequence n) w)
-> LinearFunction
     n (LinearMap n w w) (LinearMap n w (Tensor n (Sequence n) w))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap ((w -> Tensor n (Sequence n) w)
-> LinearFunction n w (Tensor n (Sequence n) w)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((w -> Tensor n (Sequence n) w)
 -> LinearFunction n w (Tensor n (Sequence n) w))
-> (w -> Tensor n (Sequence n) w)
-> LinearFunction n w (Tensor n (Sequence n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                           \w
w -> [w] -> Tensor n (Sequence n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (Sequence n) w) -> [w] -> Tensor n (Sequence n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> w -> [w]
forall a. Int -> a -> [a]
replicate (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) w
forall v. AdditiveGroup v => v
zeroV [w] -> [w] -> [w]
forall a. [a] -> [a] -> [a]
++ [w
w]) LinearFunction
  n (LinearMap n w w) (LinearMap n w (Tensor n (Sequence n) w))
-> LinearMap n w w -> LinearMap n w (Tensor n (Sequence n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap n w w
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id | Int
i<-[Int
0..]]
  applyDualVector :: Bilinear
  (DualVector (Sequence n)) (Sequence n) (Scalar (Sequence n))
applyDualVector = (FinSuppSeq n -> Sequence n -> n)
-> LinearFunction
     n (FinSuppSeq n) (LinearFunction n (Sequence n) n)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((FinSuppSeq n -> Sequence n -> n)
 -> LinearFunction
      n (FinSuppSeq n) (LinearFunction n (Sequence n) n))
-> (FinSuppSeq n -> Sequence n -> n)
-> LinearFunction
     n (FinSuppSeq n) (LinearFunction n (Sequence n) n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> FinSuppSeq n -> Sequence n -> n
forall c.
(Unbox c, Num c) =>
Int -> FinSuppSeq c -> GSequence Vector c -> c
adv Int
Seq.minimumChunkSize
   where adv :: Int -> FinSuppSeq c -> GSequence Vector c -> c
adv Int
_ (FinSuppSeq Vector c
v) (Seq.SoloChunk Int
o Vector c
q)
               = Vector c -> c
forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum (Vector c -> c) -> Vector c -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (c -> c -> c) -> Vector c -> Vector c -> Vector c
forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith c -> c -> c
forall a. Num a => a -> a -> a
(*) (Int -> Vector c -> Vector c
forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
o Vector c
v) Vector c
q
         adv Int
chunkSize (FinSuppSeq Vector c
v) (Sequence Vector c
c GSequence Vector c
r)
          | Vector c -> Int
forall a. Unbox a => Vector a -> Int
UArr.length Vector c
v Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
chunkSize
                       = Vector c -> c
forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum ((c -> c -> c) -> Vector c -> Vector c -> Vector c
forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith c -> c -> c
forall a. Num a => a -> a -> a
(*) Vector c
v Vector c
c)
                            c -> c -> c
forall a. Num a => a -> a -> a
+ Int -> FinSuppSeq c -> GSequence Vector c -> c
adv (Int
chunkSizeInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
2) (Vector c -> FinSuppSeq c
forall n. Vector n -> FinSuppSeq n
FinSuppSeq (Vector c -> FinSuppSeq c) -> Vector c -> FinSuppSeq c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> Vector c -> Vector c
forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
chunkSize Vector c
v) GSequence Vector c
r
          | Bool
otherwise  = Vector c -> c
forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum (Vector c -> c) -> Vector c -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (c -> c -> c) -> Vector c -> Vector c -> Vector c
forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith c -> c -> c
forall a. Num a => a -> a -> a
(*) Vector c
v Vector c
c
  applyLinear :: Bilinear (Sequence n +> w) (Sequence n) w
applyLinear = (LinearMap n (Sequence n) w -> GSequence Vector (Scalar w) -> w)
-> LinearFunction
     n
     (LinearMap n (Sequence n) w)
     (LinearFunction n (GSequence Vector (Scalar w)) w)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap n (Sequence n) w -> GSequence Vector (Scalar w) -> w)
 -> LinearFunction
      n
      (LinearMap n (Sequence n) w)
      (LinearFunction n (GSequence Vector (Scalar w)) w))
-> (LinearMap n (Sequence n) w -> GSequence Vector (Scalar w) -> w)
-> LinearFunction
     n
     (LinearMap n (Sequence n) w)
     (LinearFunction n (GSequence Vector (Scalar w)) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int
-> LinearMap n (Sequence n) w -> GSequence Vector (Scalar w) -> w
forall c v w s.
(VectorSpace c, Unbox (Scalar c),
 TensorProduct (DualVector v) w ~ [c]) =>
Int -> LinearMap s v w -> GSequence Vector (Scalar c) -> c
apl Int
Seq.minimumChunkSize
   where apl :: Int -> LinearMap s v w -> GSequence Vector (Scalar c) -> c
apl Int
_ (LinearMap TensorProduct (DualVector v) w
m) (Seq.SoloChunk Int
o Vector (Scalar c)
q)
               = [c] -> c
forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV ([c] -> c) -> [c] -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Scalar c -> c -> c) -> [Scalar c] -> [c] -> [c]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Scalar c -> c -> c
forall v. VectorSpace v => Scalar v -> v -> v
(*^) (Vector (Scalar c) -> [Scalar c]
forall a. Unbox a => Vector a -> [a]
UArr.toList Vector (Scalar c)
q) (Int -> [c] -> [c]
forall a. Int -> [a] -> [a]
drop Int
o [c]
TensorProduct (DualVector v) w
m)
         apl Int
chunkSize (LinearMap TensorProduct (DualVector v) w
m) (Sequence Vector (Scalar c)
c GSequence Vector (Scalar c)
r)
          | [c] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [c]
mr    = [c] -> c
forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV ([c] -> c) -> [c] -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Scalar c -> c -> c) -> [Scalar c] -> [c] -> [c]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Scalar c -> c -> c
forall v. VectorSpace v => Scalar v -> v -> v
(*^) (Vector (Scalar c) -> [Scalar c]
forall a. Unbox a => Vector a -> [a]
UArr.toList Vector (Scalar c)
c) [c]
mc
          | Bool
otherwise  = (c -> c -> c) -> c -> [c] -> c
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' c -> c -> c
forall v. AdditiveGroup v => v -> v -> v
(^+^) (Int -> LinearMap s v w -> GSequence Vector (Scalar c) -> c
apl (Int
chunkSizeInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
2) (TensorProduct (DualVector v) w -> LinearMap s v w
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [c]
TensorProduct (DualVector v) w
mr) GSequence Vector (Scalar c)
r)
                                      ((Scalar c -> c -> c) -> [Scalar c] -> [c] -> [c]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Scalar c -> c -> c
forall v. VectorSpace v => Scalar v -> v -> v
(*^) (Vector (Scalar c) -> [Scalar c]
forall a. Unbox a => Vector a -> [a]
UArr.toList Vector (Scalar c)
c) [c]
mc)
          where ([c]
mc, [c]
mr) = Int -> [c] -> ([c], [c])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
chunkSize [c]
TensorProduct (DualVector v) w
m
  applyTensorFunctional :: Bilinear
  (DualVector (Sequence n ⊗ u))
  (Sequence n ⊗ u)
  (Scalar (Sequence n))
applyTensorFunctional = (LinearMap n (Sequence n) (DualVector u)
 -> Tensor n (Sequence n) u -> n)
-> LinearFunction
     n
     (LinearMap n (Sequence n) (DualVector u))
     (LinearFunction n (Tensor n (Sequence n) u) n)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
       ((LinearMap n (Sequence n) (DualVector u)
  -> Tensor n (Sequence n) u -> n)
 -> LinearFunction
      n
      (LinearMap n (Sequence n) (DualVector u))
      (LinearFunction n (Tensor n (Sequence n) u) n))
-> (LinearMap n (Sequence n) (DualVector u)
    -> Tensor n (Sequence n) u -> n)
-> LinearFunction
     n
     (LinearMap n (Sequence n) (DualVector u))
     (LinearFunction n (Tensor n (Sequence n) u) n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Sequence n)) (DualVector u)
m) (Tensor TensorProduct (Sequence n) u
t) -> [n] -> n
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([n] -> n) -> [n] -> n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (DualVector u -> u -> n) -> [DualVector u] -> [u] -> [n]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith DualVector u -> u -> n
forall v. LinearSpace v => DualVector v -> v -> Scalar v
(<.>^) [DualVector u]
TensorProduct (DualVector (Sequence n)) (DualVector u)
m [u]
TensorProduct (Sequence n) u
t
  applyTensorLinMap :: Bilinear ((Sequence n ⊗ u) +> w) (Sequence n ⊗ u) w
applyTensorLinMap = (LinearMap n (Tensor n (Sequence n) u) w
 -> Tensor n (Sequence n) u -> w)
-> LinearFunction
     n
     (LinearMap n (Tensor n (Sequence n) u) w)
     (LinearFunction n (Tensor n (Sequence n) u) w)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap n (Tensor n (Sequence n) u) w
  -> Tensor n (Sequence n) u -> w)
 -> LinearFunction
      n
      (LinearMap n (Tensor n (Sequence n) u) w)
      (LinearFunction n (Tensor n (Sequence n) u) w))
-> (LinearMap n (Tensor n (Sequence n) u) w
    -> Tensor n (Sequence n) u -> w)
-> LinearFunction
     n
     (LinearMap n (Tensor n (Sequence n) u) w)
     (LinearFunction n (Tensor n (Sequence n) u) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (LinearMap n (Tensor n (Sequence n) u) w)
  (LinearMap n (Sequence n) (LinearMap n u w))
-> LinearMap n (Tensor n (Sequence n) u) w
-> LinearMap n (Sequence n) (LinearMap n u w)
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr Coercion
  (LinearMap n (Tensor n (Sequence n) u) w)
  (LinearMap n (Sequence n) (LinearMap n u w))
forall u v w s.
(LinearSpace u, Scalar u ~ s) =>
Coercion
  (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap (LinearMap n (Tensor n (Sequence n) u) w
 -> LinearMap n (Sequence n) (LinearMap n u w))
-> (LinearMap n (Sequence n) (LinearMap n u w)
    -> Tensor n (Sequence n) u -> w)
-> LinearMap n (Tensor n (Sequence n) u) w
-> Tensor n (Sequence n) u
-> w
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 TensorProduct (DualVector (Sequence n)) (LinearMap n u w)
m) (Tensor TensorProduct (Sequence n) u
t)
             -> [w] -> w
forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV ([w] -> w) -> [w] -> w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (LinearMap (Scalar u) u w -> u -> w)
-> [LinearMap (Scalar u) u w] -> [u] -> [w]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (LinearFunction n u w -> u -> w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (LinearFunction n u w -> u -> w)
-> (LinearMap (Scalar u) u w -> LinearFunction n u w)
-> LinearMap (Scalar u) u w
-> u
-> w
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction
  n (LinearMap (Scalar u) u w) (LinearFunction (Scalar u) u w)
-> LinearMap (Scalar u) u w -> LinearFunction (Scalar u) u w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  n (LinearMap (Scalar u) u w) (LinearFunction (Scalar u) u w)
forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear) [LinearMap (Scalar u) u w]
TensorProduct (DualVector (Sequence n)) (LinearMap n u w)
m [u]
TensorProduct (Sequence n) u
t
  useTupleLinearSpaceComponents :: ((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = φ
forall a. a
usingNonTupleTypeAsTupleError
instance (Num' n, UArr.Unbox n) => LinearSpace (FinSuppSeq n) where
  type DualVector (FinSuppSeq n) = Sequence n
  dualSpaceWitness :: DualSpaceWitness (FinSuppSeq n)
dualSpaceWitness = case ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
            ClosedScalarWitness n
ClosedScalarWitness -> DualSpaceWitness (FinSuppSeq n)
forall v.
(LinearSpace (Scalar v), DualVector (Scalar v) ~ Scalar v,
 LinearSpace (DualVector v), Scalar (DualVector v) ~ Scalar v,
 DualVector (DualVector v) ~ v) =>
DualSpaceWitness v
DualSpaceWitness
  linearId :: FinSuppSeq n +> FinSuppSeq n
linearId = TensorProduct (DualVector (FinSuppSeq n)) (FinSuppSeq n)
-> LinearMap n (FinSuppSeq n) (FinSuppSeq n)
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [Basis (FinSuppSeq n) -> FinSuppSeq n
forall v. HasBasis v => Basis v -> v
basisValue Int
Basis (FinSuppSeq n)
i | Int
i<-[Int
0..]]
  tensorId :: (FinSuppSeq n ⊗ w) +> (FinSuppSeq n ⊗ w)
tensorId = TensorProduct
  (DualVector (Tensor n (FinSuppSeq n) w))
  (Tensor n (FinSuppSeq n) w)
-> LinearMap
     n (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) w)
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [Coercion
  (LinearMap n w (Tensor n (FinSuppSeq n) w))
  (Tensor n (DualVector w) (Tensor n (FinSuppSeq n) w))
forall s v w.
Coercion (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor Coercion
  (LinearMap n w (Tensor n (FinSuppSeq n) w))
  (Tensor n (DualVector w) (Tensor n (FinSuppSeq n) w))
-> LinearMap n w (Tensor n (FinSuppSeq n) w)
-> Tensor n (DualVector w) (Tensor n (FinSuppSeq n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction n w (Tensor n (FinSuppSeq n) w)
-> LinearFunction
     n (LinearMap n w w) (LinearMap n w (Tensor n (FinSuppSeq n) w))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap ((w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction n w (Tensor n (FinSuppSeq n) w)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((w -> Tensor n (FinSuppSeq n) w)
 -> LinearFunction n w (Tensor n (FinSuppSeq n) w))
-> (w -> Tensor n (FinSuppSeq n) w)
-> LinearFunction n w (Tensor n (FinSuppSeq n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                           \w
w -> [w] -> Tensor n (FinSuppSeq n) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor ([w] -> Tensor n (FinSuppSeq n) w)
-> [w] -> Tensor n (FinSuppSeq n) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> w -> [w]
forall a. Int -> a -> [a]
replicate (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) w
forall v. AdditiveGroup v => v
zeroV [w] -> [w] -> [w]
forall a. [a] -> [a] -> [a]
++ [w
w]) LinearFunction
  n (LinearMap n w w) (LinearMap n w (Tensor n (FinSuppSeq n) w))
-> LinearMap n w w -> LinearMap n w (Tensor n (FinSuppSeq n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap n w w
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id | Int
i<-[Int
0..]]
  applyDualVector :: Bilinear
  (DualVector (FinSuppSeq n)) (FinSuppSeq n) (Scalar (FinSuppSeq n))
applyDualVector = (GSequence Vector n -> FinSuppSeq n -> n)
-> LinearFunction
     n (GSequence Vector n) (LinearFunction n (FinSuppSeq n) n)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((GSequence Vector n -> FinSuppSeq n -> n)
 -> LinearFunction
      n (GSequence Vector n) (LinearFunction n (FinSuppSeq n) n))
-> (GSequence Vector n -> FinSuppSeq n -> n)
-> LinearFunction
     n (GSequence Vector n) (LinearFunction n (FinSuppSeq n) n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> GSequence Vector n -> FinSuppSeq n -> n
forall c.
(Unbox c, Num c) =>
Int -> GSequence Vector c -> FinSuppSeq c -> c
adv Int
Seq.minimumChunkSize
   where adv :: Int -> GSequence Vector c -> FinSuppSeq c -> c
adv Int
_ (Seq.SoloChunk Int
o Vector c
q) (FinSuppSeq Vector c
v)
               = Vector c -> c
forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum (Vector c -> c) -> Vector c -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (c -> c -> c) -> Vector c -> Vector c -> Vector c
forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith c -> c -> c
forall a. Num a => a -> a -> a
(*) Vector c
q (Int -> Vector c -> Vector c
forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
o Vector c
v)
         adv Int
chunkSize (Sequence Vector c
c GSequence Vector c
r) (FinSuppSeq Vector c
v)
          | Vector c -> Int
forall a. Unbox a => Vector a -> Int
UArr.length Vector c
v Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
chunkSize
                       = Vector c -> c
forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum ((c -> c -> c) -> Vector c -> Vector c -> Vector c
forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith c -> c -> c
forall a. Num a => a -> a -> a
(*) Vector c
c Vector c
v)
                            c -> c -> c
forall a. Num a => a -> a -> a
+ Int -> GSequence Vector c -> FinSuppSeq c -> c
adv (Int
chunkSizeInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
2) GSequence Vector c
r (Vector c -> FinSuppSeq c
forall n. Vector n -> FinSuppSeq n
FinSuppSeq (Vector c -> FinSuppSeq c) -> Vector c -> FinSuppSeq c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> Vector c -> Vector c
forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
chunkSize Vector c
v)
          | Bool
otherwise  = Vector c -> c
forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum (Vector c -> c) -> Vector c -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (c -> c -> c) -> Vector c -> Vector c -> Vector c
forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith c -> c -> c
forall a. Num a => a -> a -> a
(*) Vector c
c Vector c
v
  applyLinear :: Bilinear (FinSuppSeq n +> w) (FinSuppSeq n) w
applyLinear = (LinearMap n (FinSuppSeq n) w -> FinSuppSeq n -> w)
-> LinearFunction
     n
     (LinearMap n (FinSuppSeq n) w)
     (LinearFunction n (FinSuppSeq n) w)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap n (FinSuppSeq n) w -> FinSuppSeq n -> w)
 -> LinearFunction
      n
      (LinearMap n (FinSuppSeq n) w)
      (LinearFunction n (FinSuppSeq n) w))
-> (LinearMap n (FinSuppSeq n) w -> FinSuppSeq n -> w)
-> LinearFunction
     n
     (LinearMap n (FinSuppSeq n) w)
     (LinearFunction n (FinSuppSeq n) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (FinSuppSeq n)) w
m) (FinSuppSeq Vector n
v)
                   -> (w -> w -> w) -> w -> [w] -> w
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' w -> w -> w
forall v. AdditiveGroup v => v -> v -> v
(^+^) w
forall v. AdditiveGroup v => v
zeroV ([w] -> w) -> [w] -> w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (n -> w -> w) -> [n] -> [w] -> [w]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith n -> w -> w
forall v. VectorSpace v => Scalar v -> v -> v
(*^) (Vector n -> [n]
forall a. Unbox a => Vector a -> [a]
UArr.toList Vector n
v) [w]
TensorProduct (DualVector (FinSuppSeq n)) w
m
  applyTensorFunctional :: Bilinear
  (DualVector (FinSuppSeq n ⊗ u))
  (FinSuppSeq n ⊗ u)
  (Scalar (FinSuppSeq n))
applyTensorFunctional = (LinearMap n (FinSuppSeq n) (DualVector u)
 -> Tensor n (FinSuppSeq n) u -> n)
-> LinearFunction
     n
     (LinearMap n (FinSuppSeq n) (DualVector u))
     (LinearFunction n (Tensor n (FinSuppSeq n) u) n)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
       ((LinearMap n (FinSuppSeq n) (DualVector u)
  -> Tensor n (FinSuppSeq n) u -> n)
 -> LinearFunction
      n
      (LinearMap n (FinSuppSeq n) (DualVector u))
      (LinearFunction n (Tensor n (FinSuppSeq n) u) n))
-> (LinearMap n (FinSuppSeq n) (DualVector u)
    -> Tensor n (FinSuppSeq n) u -> n)
-> LinearFunction
     n
     (LinearMap n (FinSuppSeq n) (DualVector u))
     (LinearFunction n (Tensor n (FinSuppSeq n) u) n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (FinSuppSeq n)) (DualVector u)
m) (Tensor TensorProduct (FinSuppSeq n) u
t) -> [n] -> n
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([n] -> n) -> [n] -> n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (DualVector u -> u -> n) -> [DualVector u] -> [u] -> [n]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith DualVector u -> u -> n
forall v. LinearSpace v => DualVector v -> v -> Scalar v
(<.>^) [DualVector u]
TensorProduct (DualVector (FinSuppSeq n)) (DualVector u)
m [u]
TensorProduct (FinSuppSeq n) u
t
  applyTensorLinMap :: Bilinear ((FinSuppSeq n ⊗ u) +> w) (FinSuppSeq n ⊗ u) w
applyTensorLinMap = (LinearMap n (Tensor n (FinSuppSeq n) u) w
 -> Tensor n (FinSuppSeq n) u -> w)
-> LinearFunction
     n
     (LinearMap n (Tensor n (FinSuppSeq n) u) w)
     (LinearFunction n (Tensor n (FinSuppSeq n) u) w)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap n (Tensor n (FinSuppSeq n) u) w
  -> Tensor n (FinSuppSeq n) u -> w)
 -> LinearFunction
      n
      (LinearMap n (Tensor n (FinSuppSeq n) u) w)
      (LinearFunction n (Tensor n (FinSuppSeq n) u) w))
-> (LinearMap n (Tensor n (FinSuppSeq n) u) w
    -> Tensor n (FinSuppSeq n) u -> w)
-> LinearFunction
     n
     (LinearMap n (Tensor n (FinSuppSeq n) u) w)
     (LinearFunction n (Tensor n (FinSuppSeq n) u) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (LinearMap n (Tensor n (FinSuppSeq n) u) w)
  (LinearMap n (FinSuppSeq n) (LinearMap n u w))
-> LinearMap n (Tensor n (FinSuppSeq n) u) w
-> LinearMap n (FinSuppSeq n) (LinearMap n u w)
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr Coercion
  (LinearMap n (Tensor n (FinSuppSeq n) u) w)
  (LinearMap n (FinSuppSeq n) (LinearMap n u w))
forall u v w s.
(LinearSpace u, Scalar u ~ s) =>
Coercion
  (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap (LinearMap n (Tensor n (FinSuppSeq n) u) w
 -> LinearMap n (FinSuppSeq n) (LinearMap n u w))
-> (LinearMap n (FinSuppSeq n) (LinearMap n u w)
    -> Tensor n (FinSuppSeq n) u -> w)
-> LinearMap n (Tensor n (FinSuppSeq n) u) w
-> Tensor n (FinSuppSeq n) u
-> w
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 TensorProduct (DualVector (FinSuppSeq n)) (LinearMap n u w)
m) (Tensor TensorProduct (FinSuppSeq n) u
t)
             -> [w] -> w
forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV ([w] -> w) -> [w] -> w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (LinearMap (Scalar u) u w -> u -> w)
-> [LinearMap (Scalar u) u w] -> [u] -> [w]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (LinearFunction n u w -> u -> w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (LinearFunction n u w -> u -> w)
-> (LinearMap (Scalar u) u w -> LinearFunction n u w)
-> LinearMap (Scalar u) u w
-> u
-> w
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction
  n (LinearMap (Scalar u) u w) (LinearFunction (Scalar u) u w)
-> LinearMap (Scalar u) u w -> LinearFunction (Scalar u) u w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  n (LinearMap (Scalar u) u w) (LinearFunction (Scalar u) u w)
forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear) [LinearMap (Scalar u) u w]
TensorProduct (DualVector (FinSuppSeq n)) (LinearMap n u w)
m [u]
TensorProduct (FinSuppSeq n) u
t
  useTupleLinearSpaceComponents :: ((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = φ
forall a. a
usingNonTupleTypeAsTupleError
  


instance GHC.IsList (Tensor s (Sequence s) v) where
  type Item (Tensor s (Sequence s) v) = v
  fromList :: [Item (Tensor s (Sequence s) v)] -> Tensor s (Sequence s) v
fromList = [Item (Tensor s (Sequence s) v)] -> Tensor s (Sequence s) v
forall s v w. TensorProduct v w -> Tensor s v w
Tensor
  toList :: Tensor s (Sequence s) v -> [Item (Tensor s (Sequence s) v)]
toList = Tensor s (Sequence s) v -> [Item (Tensor s (Sequence s) v)]
forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct

instance GHC.IsList (Tensor s (FinSuppSeq s) v) where
  type Item (Tensor s (FinSuppSeq s) v) = v
  fromList :: [Item (Tensor s (FinSuppSeq s) v)] -> Tensor s (FinSuppSeq s) v
fromList = [Item (Tensor s (FinSuppSeq s) v)] -> Tensor s (FinSuppSeq s) v
forall s v w. TensorProduct v w -> Tensor s v w
Tensor
  toList :: Tensor s (FinSuppSeq s) v -> [Item (Tensor s (FinSuppSeq s) v)]
toList = Tensor s (FinSuppSeq s) v -> [Item (Tensor s (FinSuppSeq s) v)]
forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct



newtype SymmetricTensor s v
           = SymTensor { SymmetricTensor s v -> Tensor s v v
getSymmetricTensor :: Tensor s v v }
deriving instance (Show (Tensor s v v)) => Show (SymmetricTensor s v)

instance (TensorSpace v, Scalar v ~ s) => AffineSpace (SymmetricTensor s v) where
  type Diff (SymmetricTensor s v) = SymmetricTensor s v
  .+^ :: SymmetricTensor s v
-> Diff (SymmetricTensor s v) -> SymmetricTensor s v
(.+^) = SymmetricTensor s v
-> Diff (SymmetricTensor s v) -> SymmetricTensor s v
forall v. AdditiveGroup v => v -> v -> v
(^+^)
  .-. :: SymmetricTensor s v
-> SymmetricTensor s v -> Diff (SymmetricTensor s v)
(.-.) = SymmetricTensor s v
-> SymmetricTensor s v -> Diff (SymmetricTensor s v)
forall v. AdditiveGroup v => v -> v -> v
(^-^)
instance (TensorSpace v, Scalar v ~ s) => AdditiveGroup (SymmetricTensor s v) where
  SymTensor Tensor s v v
s ^+^ :: SymmetricTensor s v -> SymmetricTensor s v -> SymmetricTensor s v
^+^ SymTensor Tensor s v v
t = Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor (Tensor s v v -> SymmetricTensor s v)
-> Tensor s v v -> SymmetricTensor s v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
s Tensor s v v -> Tensor s v v -> Tensor s v v
forall v. AdditiveGroup v => v -> v -> v
^+^ Tensor s v v
t
  zeroV :: SymmetricTensor s v
zeroV = Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor Tensor s v v
forall v. AdditiveGroup v => v
zeroV
  negateV :: SymmetricTensor s v -> SymmetricTensor s v
negateV (SymTensor Tensor s v v
t) = Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor (Tensor s v v -> SymmetricTensor s v)
-> Tensor s v v -> SymmetricTensor s v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v -> Tensor s v v
forall v. AdditiveGroup v => v -> v
negateV Tensor s v v
t

instance (TensorSpace v, Scalar v ~ s)
             => VectorSpace (SymmetricTensor s v) where
  type Scalar (SymmetricTensor s v) = s
  Scalar (SymmetricTensor s v)
μ *^ :: Scalar (SymmetricTensor s v)
-> SymmetricTensor s v -> SymmetricTensor s v
*^ SymTensor Tensor s v v
f = Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor (Tensor s v v -> SymmetricTensor s v)
-> Tensor s v v -> SymmetricTensor s v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Scalar (Tensor s v v)
Scalar (SymmetricTensor s v)
μScalar (Tensor s v v) -> Tensor s v v -> Tensor s v v
forall v. VectorSpace v => Scalar v -> v -> v
*^Tensor s v v
f

instance (TensorSpace v, Scalar v ~ s) => Semimanifold (SymmetricTensor s v) where
  type Needle (SymmetricTensor s v) = SymmetricTensor s v
  .+~^ :: SymmetricTensor s v
-> Needle (SymmetricTensor s v) -> SymmetricTensor s v
(.+~^) = SymmetricTensor s v
-> Needle (SymmetricTensor s v) -> SymmetricTensor s v
forall v. AdditiveGroup v => v -> v -> v
(^+^)
#if !MIN_VERSION_manifolds_core(0,6,0)
  fromInterior = id
  toInterior = pure
  translateP = Tagged (^+^)
#endif
instance (TensorSpace v, Scalar v ~ s) => PseudoAffine (SymmetricTensor s v) where
  .-~! :: SymmetricTensor s v
-> SymmetricTensor s v -> Needle (SymmetricTensor s v)
(.-~!) = SymmetricTensor s v
-> SymmetricTensor s v -> Needle (SymmetricTensor s v)
forall v. AdditiveGroup v => v -> v -> v
(^-^)
  SymmetricTensor s v
p.-~. :: SymmetricTensor s v
-> SymmetricTensor s v -> Maybe (Needle (SymmetricTensor s v))
.-~.SymmetricTensor s v
q = SymmetricTensor s v -> Maybe (SymmetricTensor s v)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (SymmetricTensor s v
pSymmetricTensor s v -> SymmetricTensor s v -> SymmetricTensor s v
forall v. AdditiveGroup v => v -> v -> v
^-^SymmetricTensor s v
q)
instance (Num' s, TensorSpace v, Scalar v ~ s) => TensorSpace (SymmetricTensor s v) where
  type TensorProduct (SymmetricTensor s v) x = Tensor s v (Tensor s v x)
  wellDefinedVector :: SymmetricTensor s v -> Maybe (SymmetricTensor s v)
wellDefinedVector (SymTensor Tensor s v v
t) = Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor (Tensor s v v -> SymmetricTensor s v)
-> Maybe (Tensor s v v) -> Maybe (SymmetricTensor s v)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Tensor s v v -> Maybe (Tensor s v v)
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Tensor s v v
t
  scalarSpaceWitness :: ScalarSpaceWitness (SymmetricTensor s v)
scalarSpaceWitness = case ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
        ClosedScalarWitness s
ClosedScalarWitness -> ScalarSpaceWitness (SymmetricTensor s v)
forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (SymmetricTensor s v)
linearManifoldWitness = LinearManifoldWitness (SymmetricTensor s v)
forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
LinearManifoldWitness v
autoLinearManifoldWitness
  zeroTensor :: SymmetricTensor s v ⊗ w
zeroTensor = TensorProduct (SymmetricTensor s v) w
-> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (SymmetricTensor s v) w
forall v. AdditiveGroup v => v
zeroV
  toFlatTensor :: SymmetricTensor s v
-+> (SymmetricTensor s v ⊗ Scalar (SymmetricTensor s v))
toFlatTensor = case ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
        ClosedScalarWitness s
ClosedScalarWitness -> (SymmetricTensor s v -> Tensor s (SymmetricTensor s v) s)
-> LinearFunction
     s (SymmetricTensor s v) (Tensor s (SymmetricTensor s v) s)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((SymmetricTensor s v -> Tensor s (SymmetricTensor s v) s)
 -> LinearFunction
      s (SymmetricTensor s v) (Tensor s (SymmetricTensor s v) s))
-> (SymmetricTensor s v -> Tensor s (SymmetricTensor s v) s)
-> LinearFunction
     s (SymmetricTensor s v) (Tensor s (SymmetricTensor s v) s)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(SymTensor Tensor s v v
t)
                                 -> Tensor s v (Tensor (Scalar v) v (Scalar v))
-> Tensor s (SymmetricTensor s v) s
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor (Scalar v) v (Scalar v))
 -> Tensor s (SymmetricTensor s v) s)
-> Tensor s v (Tensor (Scalar v) v (Scalar v))
-> Tensor s (SymmetricTensor s v) s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar v) v (Tensor (Scalar v) v (Scalar v))
-> LinearFunction
     s (Tensor s v v) (Tensor s v (Tensor (Scalar v) v (Scalar v)))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap LinearFunction (Scalar v) v (Tensor (Scalar v) v (Scalar v))
forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor LinearFunction
  s (Tensor s v v) (Tensor s v (Tensor (Scalar v) v (Scalar v)))
-> Tensor s v v -> Tensor s v (Tensor (Scalar v) v (Scalar v))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
t
  fromFlatTensor :: (SymmetricTensor s v ⊗ Scalar (SymmetricTensor s v))
-+> SymmetricTensor s v
fromFlatTensor = case ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
        ClosedScalarWitness s
ClosedScalarWitness -> (Tensor s (SymmetricTensor s v) s -> SymmetricTensor s v)
-> LinearFunction
     s (Tensor s (SymmetricTensor s v) s) (SymmetricTensor s v)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor s (SymmetricTensor s v) s -> SymmetricTensor s v)
 -> LinearFunction
      s (Tensor s (SymmetricTensor s v) s) (SymmetricTensor s v))
-> (Tensor s (SymmetricTensor s v) s -> SymmetricTensor s v)
-> LinearFunction
     s (Tensor s (SymmetricTensor s v) s) (SymmetricTensor s v)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (SymmetricTensor s v) s
t)
                     -> Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor (Tensor s v v -> SymmetricTensor s v)
-> Tensor s v v -> SymmetricTensor s v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar v) (Tensor (Scalar v) v (Scalar v)) v
-> LinearFunction
     s (Tensor s v (Tensor (Scalar v) v (Scalar v))) (Tensor s v v)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap LinearFunction (Scalar v) (Tensor (Scalar v) v (Scalar v)) v
forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor LinearFunction
  s (Tensor s v (Tensor (Scalar v) v (Scalar v))) (Tensor s v v)
-> Tensor s v (Tensor (Scalar v) v (Scalar v)) -> Tensor s v v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v (Tensor (Scalar v) v (Scalar v))
TensorProduct (SymmetricTensor s v) s
t
  addTensors :: (SymmetricTensor s v ⊗ w)
-> (SymmetricTensor s v ⊗ w) -> SymmetricTensor s v ⊗ w
addTensors (Tensor TensorProduct (SymmetricTensor s v) w
f) (Tensor TensorProduct (SymmetricTensor s v) w
g) = Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w)
-> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
fTensor s v (Tensor s v w)
-> Tensor s v (Tensor s v w) -> Tensor s v (Tensor s v w)
forall v. AdditiveGroup v => v -> v -> v
^+^Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
g
  subtractTensors :: (SymmetricTensor s v ⊗ w)
-> (SymmetricTensor s v ⊗ w) -> SymmetricTensor s v ⊗ w
subtractTensors (Tensor TensorProduct (SymmetricTensor s v) w
f) (Tensor TensorProduct (SymmetricTensor s v) w
g) = Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w)
-> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
fTensor s v (Tensor s v w)
-> Tensor s v (Tensor s v w) -> Tensor s v (Tensor s v w)
forall v. AdditiveGroup v => v -> v -> v
^-^Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
g
  negateTensor :: (SymmetricTensor s v ⊗ w) -+> (SymmetricTensor s v ⊗ w)
negateTensor = (Tensor s (SymmetricTensor s v) w
 -> Tensor s (SymmetricTensor s v) w)
-> LinearFunction
     s
     (Tensor s (SymmetricTensor s v) w)
     (Tensor s (SymmetricTensor s v) w)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor s (SymmetricTensor s v) w
  -> Tensor s (SymmetricTensor s v) w)
 -> LinearFunction
      s
      (Tensor s (SymmetricTensor s v) w)
      (Tensor s (SymmetricTensor s v) w))
-> (Tensor s (SymmetricTensor s v) w
    -> Tensor s (SymmetricTensor s v) w)
-> LinearFunction
     s
     (Tensor s (SymmetricTensor s v) w)
     (Tensor s (SymmetricTensor s v) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (SymmetricTensor s v) w
f) -> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w)
-> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v (Tensor s v w) -> Tensor s v (Tensor s v w)
forall v. AdditiveGroup v => v -> v
negateV Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
f
  scaleTensor :: Bilinear
  (Scalar (SymmetricTensor s v))
  (SymmetricTensor s v ⊗ w)
  (SymmetricTensor s v ⊗ w)
scaleTensor = (s
 -> Tensor s (SymmetricTensor s v) w
 -> Tensor s (SymmetricTensor s v) w)
-> LinearFunction
     (Scalar s)
     s
     (LinearFunction
        (Scalar s)
        (Tensor s (SymmetricTensor s v) w)
        (Tensor s (SymmetricTensor s v) w))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((s
  -> Tensor s (SymmetricTensor s v) w
  -> Tensor s (SymmetricTensor s v) w)
 -> LinearFunction
      (Scalar s)
      s
      (LinearFunction
         (Scalar s)
         (Tensor s (SymmetricTensor s v) w)
         (Tensor s (SymmetricTensor s v) w)))
-> (s
    -> Tensor s (SymmetricTensor s v) w
    -> Tensor s (SymmetricTensor s v) w)
-> LinearFunction
     (Scalar s)
     s
     (LinearFunction
        (Scalar s)
        (Tensor s (SymmetricTensor s v) w)
        (Tensor s (SymmetricTensor s v) w))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \s
μ (Tensor TensorProduct (SymmetricTensor s v) w
f) -> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w)
-> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s
Scalar (Tensor s v (Tensor s v w))
μ Scalar (Tensor s v (Tensor s v w))
-> Tensor s v (Tensor s v w) -> Tensor s v (Tensor s v w)
forall v. VectorSpace v => Scalar v -> v -> v
*^ Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
f
  tensorProduct :: Bilinear (SymmetricTensor s v) w (SymmetricTensor s v ⊗ w)
tensorProduct = (SymmetricTensor s v -> w -> Tensor s (SymmetricTensor s v) w)
-> LinearFunction
     s
     (SymmetricTensor s v)
     (LinearFunction s w (Tensor s (SymmetricTensor s v) w))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((SymmetricTensor s v -> w -> Tensor s (SymmetricTensor s v) w)
 -> LinearFunction
      s
      (SymmetricTensor s v)
      (LinearFunction s w (Tensor s (SymmetricTensor s v) w)))
-> (SymmetricTensor s v -> w -> Tensor s (SymmetricTensor s v) w)
-> LinearFunction
     s
     (SymmetricTensor s v)
     (LinearFunction s w (Tensor s (SymmetricTensor s v) w))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(SymTensor Tensor s v v
t) w
g
                    -> Tensor s v (Tensor (Scalar v) v w)
-> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor (Scalar v) v w)
 -> Tensor s (SymmetricTensor s v) w)
-> Tensor s v (Tensor (Scalar v) v w)
-> Tensor s (SymmetricTensor s v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction s v (Tensor (Scalar v) v w)
-> LinearFunction
     s (Tensor s v v) (Tensor s v (Tensor (Scalar v) v w))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap ((v -> Tensor (Scalar v) v w)
-> LinearFunction s v (Tensor (Scalar v) v w)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (v -> w -> Tensor (Scalar v) v w
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
 Num' (Scalar v)) =>
v -> w -> v ⊗ w
w
g)) LinearFunction
  s (Tensor s v v) (Tensor s v (Tensor (Scalar v) v w))
-> Tensor s v v -> Tensor s v (Tensor (Scalar v) v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
t
  transposeTensor :: (SymmetricTensor s v ⊗ w) -+> (w ⊗ SymmetricTensor s v)
transposeTensor = (Tensor s (SymmetricTensor s v) w -> w ⊗ SymmetricTensor s v)
-> LinearFunction
     s (Tensor s (SymmetricTensor s v) w) (w ⊗ SymmetricTensor s v)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor s (SymmetricTensor s v) w -> w ⊗ SymmetricTensor s v)
 -> LinearFunction
      s (Tensor s (SymmetricTensor s v) w) (w ⊗ SymmetricTensor s v))
-> (Tensor s (SymmetricTensor s v) w -> w ⊗ SymmetricTensor s v)
-> LinearFunction
     s (Tensor s (SymmetricTensor s v) w) (w ⊗ SymmetricTensor s v)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (SymmetricTensor s v) w
f) -> LinearFunction
  s (Tensor s v (Tensor s v w)) (w ⊗ SymmetricTensor s v)
-> Tensor s v (Tensor s v w) -> w ⊗ SymmetricTensor s v
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (
                            Coercion
  (Tensor (Scalar w) w (Tensor s v v)) (w ⊗ SymmetricTensor s v)
-> LinearFunction
     s (Tensor (Scalar w) w (Tensor s v v)) (w ⊗ SymmetricTensor s v)
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (Coercion (Tensor s v v) (SymmetricTensor s v)
-> Coercion
     (Tensor (Scalar w) w (Tensor s v v)) (w ⊗ SymmetricTensor s v)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Coercion (Tensor s v v) (SymmetricTensor s v)
forall k (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion) LinearFunction
  s (Tensor (Scalar w) w (Tensor s v v)) (w ⊗ SymmetricTensor s v)
-> LinearFunction
     s (Tensor s v (Tensor s v w)) (Tensor (Scalar w) w (Tensor s v v))
-> LinearFunction
     s (Tensor s v (Tensor s v w)) (w ⊗ SymmetricTensor s v)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction
  s (Tensor s (Tensor s v v) w) (Tensor (Scalar w) w (Tensor s v v))
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor LinearFunction
  s (Tensor s (Tensor s v v) w) (Tensor (Scalar w) w (Tensor s v v))
-> LinearFunction
     s (Tensor s v (Tensor s v w)) (Tensor s (Tensor s v v) w)
-> LinearFunction
     s (Tensor s v (Tensor s v w)) (Tensor (Scalar w) w (Tensor s v v))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion (Tensor s v (Tensor s v w)) (Tensor s (Tensor s v v) w)
-> LinearFunction
     s (Tensor s v (Tensor s v w)) (Tensor s (Tensor s v v) w)
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr Coercion (Tensor s v (Tensor s v w)) (Tensor s (Tensor s v v) w)
forall s u v w.
Coercion (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
lassocTensor) Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
f
  fmapTensor :: Bilinear
  (w -+> x) (SymmetricTensor s v ⊗ w) (SymmetricTensor s v ⊗ x)
fmapTensor = (LinearFunction s w x
 -> Tensor s (SymmetricTensor s v) w
 -> Tensor s (SymmetricTensor s v) x)
-> LinearFunction
     (Scalar x)
     (LinearFunction s w x)
     (LinearFunction
        (Scalar x)
        (Tensor s (SymmetricTensor s v) w)
        (Tensor s (SymmetricTensor s v) x))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearFunction s w x
  -> Tensor s (SymmetricTensor s v) w
  -> Tensor s (SymmetricTensor s v) x)
 -> LinearFunction
      (Scalar x)
      (LinearFunction s w x)
      (LinearFunction
         (Scalar x)
         (Tensor s (SymmetricTensor s v) w)
         (Tensor s (SymmetricTensor s v) x)))
-> (LinearFunction s w x
    -> Tensor s (SymmetricTensor s v) w
    -> Tensor s (SymmetricTensor s v) x)
-> LinearFunction
     (Scalar x)
     (LinearFunction s w x)
     (LinearFunction
        (Scalar x)
        (Tensor s (SymmetricTensor s v) w)
        (Tensor s (SymmetricTensor s v) x))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s w x
f (Tensor TensorProduct (SymmetricTensor s v) w
t) -> Tensor s v (Tensor s v x) -> Tensor s (SymmetricTensor s v) x
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v x) -> Tensor s (SymmetricTensor s v) x)
-> Tensor s v (Tensor s v x) -> Tensor s (SymmetricTensor s v) x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction s (Tensor s v w) (Tensor s v x)
-> LinearFunction
     s (Tensor s v (Tensor s v w)) (Tensor s v (Tensor s v x))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (LinearFunction s w x
-> LinearFunction s (Tensor s v w) (Tensor s v x)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap LinearFunction s w x
f) LinearFunction
  s (Tensor s v (Tensor s v w)) (Tensor s v (Tensor s v x))
-> Tensor s v (Tensor s v w) -> Tensor s v (Tensor s v x)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
t
  fzipTensorWith :: Bilinear
  ((w, x) -+> u)
  (SymmetricTensor s v ⊗ w, SymmetricTensor s v ⊗ x)
  (SymmetricTensor s v ⊗ u)
fzipTensorWith = (LinearFunction s (w, x) u
 -> (Tensor s (SymmetricTensor s v) w,
     Tensor s (SymmetricTensor s v) x)
 -> Tensor s (SymmetricTensor s v) u)
-> LinearFunction
     (Scalar u)
     (LinearFunction s (w, x) u)
     (LinearFunction
        (Scalar u)
        (Tensor s (SymmetricTensor s v) w,
         Tensor s (SymmetricTensor s v) x)
        (Tensor s (SymmetricTensor s v) u))
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearFunction s (w, x) u
  -> (Tensor s (SymmetricTensor s v) w,
      Tensor s (SymmetricTensor s v) x)
  -> Tensor s (SymmetricTensor s v) u)
 -> LinearFunction
      (Scalar u)
      (LinearFunction s (w, x) u)
      (LinearFunction
         (Scalar u)
         (Tensor s (SymmetricTensor s v) w,
          Tensor s (SymmetricTensor s v) x)
         (Tensor s (SymmetricTensor s v) u)))
-> (LinearFunction s (w, x) u
    -> (Tensor s (SymmetricTensor s v) w,
        Tensor s (SymmetricTensor s v) x)
    -> Tensor s (SymmetricTensor s v) u)
-> LinearFunction
     (Scalar u)
     (LinearFunction s (w, x) u)
     (LinearFunction
        (Scalar u)
        (Tensor s (SymmetricTensor s v) w,
         Tensor s (SymmetricTensor s v) x)
        (Tensor s (SymmetricTensor s v) u))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s (w, x) u
f (Tensor TensorProduct (SymmetricTensor s v) w
s, Tensor TensorProduct (SymmetricTensor s v) x
t)
                 -> Tensor s v (Tensor s v u) -> Tensor s (SymmetricTensor s v) u
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v u) -> Tensor s (SymmetricTensor s v) u)
-> Tensor s v (Tensor s v u) -> Tensor s (SymmetricTensor s v) u
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction s (Tensor s v w, Tensor s v x) (Tensor s v u)
-> LinearFunction
     s
     (Tensor s v (Tensor s v w), Tensor s v (Tensor s v x))
     (Tensor s v (Tensor s v u))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
 ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith (LinearFunction s (w, x) u
-> LinearFunction s (Tensor s v w, Tensor s v x) (Tensor s v u)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
 ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith LinearFunction s (w, x) u
f) LinearFunction
  s
  (Tensor s v (Tensor s v w), Tensor s v (Tensor s v x))
  (Tensor s v (Tensor s v u))
-> (Tensor s v (Tensor s v w), Tensor s v (Tensor s v x))
-> Tensor s v (Tensor s v u)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
s,Tensor s v (Tensor s v x)
TensorProduct (SymmetricTensor s v) x
t)
  coerceFmapTensorProduct :: p (SymmetricTensor s v)
-> Coercion a b
-> Coercion
     (TensorProduct (SymmetricTensor s v) a)
     (TensorProduct (SymmetricTensor s v) b)
coerceFmapTensorProduct p (SymmetricTensor s v)
_ Coercion a b
crc = Coercion (Tensor s v a) (Tensor s v b)
-> Coercion (Tensor s v (Tensor s v a)) (Tensor s v (Tensor s v b))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (Coercion a b -> Coercion (Tensor s v a) (Tensor s v b)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Coercion a b
crc)
  wellDefinedTensor :: (SymmetricTensor s v ⊗ w) -> Maybe (SymmetricTensor s v ⊗ w)
wellDefinedTensor (Tensor TensorProduct (SymmetricTensor s v) w
t) = Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w)
-> Maybe (Tensor s v (Tensor s v w))
-> Maybe (Tensor s (SymmetricTensor s v) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Tensor s v (Tensor s v w) -> Maybe (Tensor s v (Tensor s v w))
forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Tensor s v (Tensor s v w)
TensorProduct (SymmetricTensor s v) w
t

instance (Num' s, LinearSpace v, Scalar v ~ s) => LinearSpace (SymmetricTensor s v) where
  type DualVector (SymmetricTensor s v) = SymmetricTensor s (DualVector v)
  dualSpaceWitness :: DualSpaceWitness (SymmetricTensor s v)
dualSpaceWitness = case ( ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s
                          , DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of 
          (ClosedScalarWitness s
ClosedScalarWitness, DualSpaceWitness v
DualSpaceWitness) -> DualSpaceWitness (SymmetricTensor s v)
forall v.
(LinearSpace (Scalar v), DualVector (Scalar v) ~ Scalar v,
 LinearSpace (DualVector v), Scalar (DualVector v) ~ Scalar v,
 DualVector (DualVector v) ~ v) =>
DualSpaceWitness v
DualSpaceWitness
  linearId :: SymmetricTensor s v +> SymmetricTensor s v
linearId = case DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> Tensor
  s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v))
-> LinearMap s (SymmetricTensor s v) (SymmetricTensor s v)
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (Tensor
   s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v))
 -> LinearMap s (SymmetricTensor s v) (SymmetricTensor s v))
-> Tensor
     s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v))
-> LinearMap s (SymmetricTensor s v) (SymmetricTensor s v)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (Tensor
     s (Tensor s (DualVector v) (DualVector v)) (SymmetricTensor s v))
  (Tensor
     s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v)))
forall s u v w.
Coercion (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
rassocTensor Coercion
  (Tensor
     s (Tensor s (DualVector v) (DualVector v)) (SymmetricTensor s v))
  (Tensor
     s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v)))
-> Coercion
     (LinearMap
        s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v))
     (Tensor
        s (Tensor s (DualVector v) (DualVector v)) (SymmetricTensor s v))
-> Coercion
     (LinearMap
        s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v))
     (Tensor
        s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v)))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (LinearMap s (LinearMap s (DualVector v) v) (SymmetricTensor s v))
  (Tensor
     s (Tensor s (DualVector v) (DualVector v)) (SymmetricTensor s v))
forall s v w.
Coercion (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor
                          Coercion
  (LinearMap s (LinearMap s (DualVector v) v) (SymmetricTensor s v))
  (Tensor
     s (Tensor s (DualVector v) (DualVector v)) (SymmetricTensor s v))
-> Coercion
     (LinearMap
        s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v))
     (LinearMap s (LinearMap s (DualVector v) v) (SymmetricTensor s v))
-> Coercion
     (LinearMap
        s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v))
     (Tensor
        s (Tensor s (DualVector v) (DualVector v)) (SymmetricTensor s v))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion (LinearMap s (DualVector v) v) (SymmetricTensor s v)
-> Coercion
     (LinearMap
        s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v))
     (LinearMap s (LinearMap s (DualVector v) v) (SymmetricTensor s v))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap ((Tensor s v v -> SymmetricTensor s v)
-> Coercion (Tensor s v v) (SymmetricTensor s v)
forall (k :: * -> * -> *) a b (p :: * -> * -> *).
(EnhancedCat k Coercion, Coercible a b, Object k a, Object k b) =>
p a b -> k a b
follow Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor Coercion (Tensor s v v) (SymmetricTensor s v)
-> Coercion (LinearMap s (DualVector v) v) (Tensor s v v)
-> Coercion (LinearMap s (DualVector v) v) (SymmetricTensor s v)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion (LinearMap s (DualVector v) v) (Tensor s v v)
forall s v w.
Coercion (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor) Coercion
  (LinearMap
     s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v))
  (Tensor
     s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v)))
-> LinearMap
     s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v)
-> Tensor
     s (DualVector v) (Tensor s (DualVector v) (SymmetricTensor s v))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap
  s (LinearMap s (DualVector v) v) (LinearMap s (DualVector v) v)
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
  tensorId :: (SymmetricTensor s v ⊗ w) +> (SymmetricTensor s v ⊗ w)
tensorId = Tensor
  s
  (DualVector v)
  (Tensor
     s
     (DualVector v)
     (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
-> LinearMap
     s
     (Tensor s (SymmetricTensor s v) w)
     (Tensor s (SymmetricTensor s v) w)
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (Tensor
   s
   (DualVector v)
   (Tensor
      s
      (DualVector v)
      (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
 -> LinearMap
      s
      (Tensor s (SymmetricTensor s v) w)
      (Tensor s (SymmetricTensor s v) w))
-> Tensor
     s
     (DualVector v)
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
-> LinearMap
     s
     (Tensor s (SymmetricTensor s v) w)
     (Tensor s (SymmetricTensor s v) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (LinearMap
     s
     v
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
  (Tensor
     s
     (DualVector v)
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
forall s v w.
Coercion (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor Coercion
  (LinearMap
     s
     v
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
  (Tensor
     s
     (DualVector v)
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        v
        (Tensor
           s
           (DualVector v)
           (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (Tensor
        s
        (DualVector v)
        (Tensor
           s
           (DualVector v)
           (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (LinearMap
     s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
  (Tensor
     s
     (DualVector v)
     (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
-> Coercion
     (LinearMap
        s
        v
        (LinearMap
           s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
     (LinearMap
        s
        v
        (Tensor
           s
           (DualVector v)
           (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Coercion
  (LinearMap
     s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
  (Tensor
     s
     (DualVector v)
     (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
forall s v w.
Coercion (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor Coercion
  (LinearMap
     s
     v
     (LinearMap
        s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
  (LinearMap
     s
     v
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        v
        (LinearMap
           s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        v
        (Tensor
           s
           (DualVector v)
           (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (LinearMap
     s
     (Tensor s v v)
     (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
  (LinearMap
     s
     v
     (LinearMap
        s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
forall u v w s.
(LinearSpace u, Scalar u ~ s) =>
Coercion
  (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap
                           Coercion
  (LinearMap
     s
     (Tensor s v v)
     (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
  (LinearMap
     s
     v
     (LinearMap
        s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        (Tensor s v v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        v
        (LinearMap
           s v (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (LinearMap s w (Tensor s (SymmetricTensor s v) w))
  (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))
-> Coercion
     (LinearMap
        s
        (Tensor s v v)
        (LinearMap s w (Tensor s (SymmetricTensor s v) w)))
     (LinearMap
        s
        (Tensor s v v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Coercion
  (LinearMap s w (Tensor s (SymmetricTensor s v) w))
  (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))
forall s v w.
Coercion (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor
                           Coercion
  (LinearMap
     s
     (Tensor s v v)
     (LinearMap s w (Tensor s (SymmetricTensor s v) w)))
  (LinearMap
     s
     (Tensor s v v)
     (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        (Tensor s v v)
        (LinearMap s w (Tensor s (SymmetricTensor s v) w)))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        (Tensor s v v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (LinearMap
     s (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w))
  (LinearMap
     s
     (Tensor s v v)
     (LinearMap s w (Tensor s (SymmetricTensor s v) w)))
forall u v w s.
(LinearSpace u, Scalar u ~ s) =>
Coercion
  (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap
                           Coercion
  (LinearMap
     s (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w))
  (LinearMap
     s
     (Tensor s v v)
     (LinearMap s w (Tensor s (SymmetricTensor s v) w)))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w))
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s
        (Tensor s v v)
        (LinearMap s w (Tensor s (SymmetricTensor s v) w)))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w)
-> Coercion
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
     (LinearMap
        s (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap ((Tensor s (Tensor s v v) w -> Tensor s (SymmetricTensor s v) w)
-> Coercion
     (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w)
forall (k :: * -> * -> *) a b (p :: * -> * -> *).
(EnhancedCat k Coercion, Coercible a b, Object k a, Object k b) =>
p a b -> k a b
follow ((Tensor s (Tensor s v v) w -> Tensor s (SymmetricTensor s v) w)
 -> Coercion
      (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w))
-> (Tensor s (Tensor s v v) w -> Tensor s (SymmetricTensor s v) w)
-> Coercion
     (Tensor s (Tensor s v v) w) (Tensor s (SymmetricTensor s v) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Tensor s (Tensor s v v) w
t -> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w)
-> Tensor s v (Tensor s v w) -> Tensor s (SymmetricTensor s v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion (Tensor s (Tensor s v v) w) (Tensor s v (Tensor s v w))
forall s u v w.
Coercion (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
rassocTensor Coercion (Tensor s (Tensor s v v) w) (Tensor s v (Tensor s v w))
-> Tensor s (Tensor s v v) w -> Tensor s v (Tensor s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (Tensor s v v) w
t)
                           Coercion
  (LinearMap
     s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w))
  (Tensor
     s
     (DualVector v)
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w))))
-> LinearMap
     s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w)
-> Tensor
     s
     (DualVector v)
     (Tensor
        s
        (DualVector v)
        (Tensor s (DualVector w) (Tensor s (SymmetricTensor s v) w)))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (Tensor s (Tensor s v v) w) (Tensor s (Tensor s v v) w)
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
  applyLinear :: Bilinear (SymmetricTensor s v +> w) (SymmetricTensor s v) w
applyLinear = case DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> (LinearMap s (SymmetricTensor s v) w -> SymmetricTensor s v -> w)
-> LinearFunction
     s
     (LinearMap s (SymmetricTensor s v) w)
     (LinearFunction s (SymmetricTensor s v) w)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap s (SymmetricTensor s v) w -> SymmetricTensor s v -> w)
 -> LinearFunction
      s
      (LinearMap s (SymmetricTensor s v) w)
      (LinearFunction s (SymmetricTensor s v) w))
-> (LinearMap s (SymmetricTensor s v) w
    -> SymmetricTensor s v -> w)
-> LinearFunction
     s
     (LinearMap s (SymmetricTensor s v) w)
     (LinearFunction s (SymmetricTensor s v) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (SymmetricTensor s v)) w
f) (SymTensor Tensor s v v
t)
                   -> (LinearFunction
  s
  (LinearMap s (Tensor s v v) w)
  (LinearFunction s (Tensor s v v) w)
-> LinearMap s (Tensor s v v) w
-> LinearFunction s (Tensor s v v) w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  s
  (LinearMap s (Tensor s v v) w)
  (LinearFunction s (Tensor s v v) w)
forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear
                         (LinearMap s (Tensor s v v) w -> LinearFunction s (Tensor s v v) w)
-> LinearMap s (Tensor s v v) w
-> LinearFunction s (Tensor s v v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (Tensor s (LinearMap s v (DualVector v)) w)
  (LinearMap s (Tensor s v v) w)
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor Coercion
  (Tensor s (LinearMap s v (DualVector v)) w)
  (LinearMap s (Tensor s v v) w)
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector v) w))
     (Tensor s (LinearMap s v (DualVector v)) w)
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector v) w))
     (LinearMap s (Tensor s v v) w)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (LinearMap s v (Tensor s (DualVector v) w))
  (Tensor s (LinearMap s v (DualVector v)) w)
forall s u v w.
Coercion
  (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
deferLinearMap Coercion
  (LinearMap s v (Tensor s (DualVector v) w))
  (Tensor s (LinearMap s v (DualVector v)) w)
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector v) w))
     (LinearMap s v (Tensor s (DualVector v) w))
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector v) w))
     (Tensor s (LinearMap s v (DualVector v)) w)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (Tensor s (DualVector v) (Tensor s (DualVector v) w))
  (LinearMap s v (Tensor s (DualVector v) w))
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
Coercion (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap Coercion
  (Tensor s (DualVector v) (Tensor s (DualVector v) w))
  (LinearMap s (Tensor s v v) w)
-> Tensor s (DualVector v) (Tensor s (DualVector v) w)
-> LinearMap s (Tensor s v v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (DualVector v) (Tensor s (DualVector v) w)
TensorProduct (DualVector (SymmetricTensor s v)) w
f) LinearFunction s (Tensor s v v) w -> Tensor s v v -> w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
t
  applyDualVector :: Bilinear
  (DualVector (SymmetricTensor s v))
  (SymmetricTensor s v)
  (Scalar (SymmetricTensor s v))
applyDualVector = (SymmetricTensor s (DualVector v) -> SymmetricTensor s v -> s)
-> LinearFunction
     s
     (SymmetricTensor s (DualVector v))
     (LinearFunction s (SymmetricTensor s v) s)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((SymmetricTensor s (DualVector v) -> SymmetricTensor s v -> s)
 -> LinearFunction
      s
      (SymmetricTensor s (DualVector v))
      (LinearFunction s (SymmetricTensor s v) s))
-> (SymmetricTensor s (DualVector v) -> SymmetricTensor s v -> s)
-> LinearFunction
     s
     (SymmetricTensor s (DualVector v))
     (LinearFunction s (SymmetricTensor s v) s)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(SymTensor Tensor s (DualVector v) (DualVector v)
f) (SymTensor Tensor s v v
v)
                      -> LinearFunction s (Tensor s v v) s -> Tensor s v v -> s
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
                           (LinearFunction
  s
  (LinearMap s v (DualVector v))
  (LinearFunction s (Tensor s v v) s)
-> LinearMap s v (DualVector v)
-> LinearFunction s (Tensor s v v) s
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  s
  (LinearMap s v (DualVector v))
  (LinearFunction s (Tensor s v v) s)
forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVector (LinearMap s v (DualVector v) -> LinearFunction s (Tensor s v v) s)
-> LinearMap s v (DualVector v)
-> LinearFunction s (Tensor s v v) s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (Tensor s (DualVector v) (DualVector v))
  (LinearMap s v (DualVector v))
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor Coercion
  (Tensor s (DualVector v) (DualVector v))
  (LinearMap s v (DualVector v))
-> Tensor s (DualVector v) (DualVector v)
-> LinearMap s v (DualVector v)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (DualVector v) (DualVector v)
f) Tensor s v v
v
  applyTensorFunctional :: Bilinear
  (DualVector (SymmetricTensor s v ⊗ u))
  (SymmetricTensor s v ⊗ u)
  (Scalar (SymmetricTensor s v))
applyTensorFunctional = case DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> (LinearMap s (SymmetricTensor s v) (DualVector u)
 -> Tensor s (SymmetricTensor s v) u -> s)
-> LinearFunction
     s
     (LinearMap s (SymmetricTensor s v) (DualVector u))
     (LinearFunction s (Tensor s (SymmetricTensor s v) u) s)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap s (SymmetricTensor s v) (DualVector u)
  -> Tensor s (SymmetricTensor s v) u -> s)
 -> LinearFunction
      s
      (LinearMap s (SymmetricTensor s v) (DualVector u))
      (LinearFunction s (Tensor s (SymmetricTensor s v) u) s))
-> (LinearMap s (SymmetricTensor s v) (DualVector u)
    -> Tensor s (SymmetricTensor s v) u -> s)
-> LinearFunction
     s
     (LinearMap s (SymmetricTensor s v) (DualVector u))
     (LinearFunction s (Tensor s (SymmetricTensor s v) u) s)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (SymmetricTensor s v)) (DualVector u)
f) (Tensor TensorProduct (SymmetricTensor s v) u
t)
                   -> LinearFunction s (Tensor (Scalar v) v (Tensor s v u)) s
-> Tensor (Scalar v) v (Tensor s v u) -> s
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
                        (LinearFunction
  s
  (LinearMap s v (LinearMap s v (DualVector u)))
  (LinearFunction
     (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) (Scalar v))
-> LinearMap s v (LinearMap s v (DualVector u))
-> LinearFunction
     (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) (Scalar v)
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  s
  (LinearMap s v (LinearMap s v (DualVector u)))
  (LinearFunction
     (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) (Scalar v))
forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional
                             (LinearMap s v (LinearMap s v (DualVector u))
 -> LinearFunction s (Tensor (Scalar v) v (Tensor s v u)) s)
-> LinearMap s v (LinearMap s v (DualVector u))
-> LinearFunction s (Tensor (Scalar v) v (Tensor s v u)) s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
  (LinearMap s v (LinearMap s v (DualVector u)))
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor Coercion
  (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
  (LinearMap s v (LinearMap s v (DualVector u)))
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
     (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
     (LinearMap s v (LinearMap s v (DualVector u)))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (Tensor s (DualVector v) (DualVector u))
  (LinearMap s v (DualVector u))
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
     (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Coercion
  (Tensor s (DualVector v) (DualVector u))
  (LinearMap s v (DualVector u))
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor Coercion
  (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
  (LinearMap s v (LinearMap s v (DualVector u)))
-> Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u))
-> LinearMap s v (LinearMap s v (DualVector u))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u))
TensorProduct (DualVector (SymmetricTensor s v)) (DualVector u)
f) Tensor (Scalar v) v (Tensor s v u)
TensorProduct (SymmetricTensor s v) u
t
  applyTensorLinMap :: Bilinear
  ((SymmetricTensor s v ⊗ u) +> w) (SymmetricTensor s v ⊗ u) w
applyTensorLinMap = case DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> (LinearMap s (Tensor s (SymmetricTensor s v) u) w
 -> Tensor s (SymmetricTensor s v) u -> w)
-> LinearFunction
     s
     (LinearMap s (Tensor s (SymmetricTensor s v) u) w)
     (LinearFunction s (Tensor s (SymmetricTensor s v) u) w)
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap s (Tensor s (SymmetricTensor s v) u) w
  -> Tensor s (SymmetricTensor s v) u -> w)
 -> LinearFunction
      s
      (LinearMap s (Tensor s (SymmetricTensor s v) u) w)
      (LinearFunction s (Tensor s (SymmetricTensor s v) u) w))
-> (LinearMap s (Tensor s (SymmetricTensor s v) u) w
    -> Tensor s (SymmetricTensor s v) u -> w)
-> LinearFunction
     s
     (LinearMap s (Tensor s (SymmetricTensor s v) u) w)
     (LinearFunction s (Tensor s (SymmetricTensor s v) u) w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap (Tensor f)) (Tensor TensorProduct (SymmetricTensor s v) u
t)
                   -> LinearFunction s (Tensor (Scalar v) v (Tensor s v u)) w
-> Tensor (Scalar v) v (Tensor s v u) -> w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (LinearFunction
  s
  (LinearMap (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) w)
  (LinearFunction (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) w)
-> LinearMap (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) w
-> LinearFunction (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  s
  (LinearMap (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) w)
  (LinearFunction (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) w)
forall v u w.
(LinearSpace v, LinearSpace u, TensorSpace w, Scalar u ~ Scalar v,
 Scalar w ~ Scalar v) =>
Bilinear ((v ⊗ u) +> w) (v ⊗ u) w
applyTensorLinMap
                             (LinearMap s (Tensor s v (Tensor s v u)) w
 -> LinearFunction s (Tensor (Scalar v) v (Tensor s v u)) w)
-> LinearMap s (Tensor s v (Tensor s v u)) w
-> LinearFunction s (Tensor (Scalar v) v (Tensor s v u)) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion
  (LinearMap s v (LinearMap s (Tensor s v u) w))
  (LinearMap s (Tensor s v (Tensor s v u)) w)
forall u v w s.
(LinearSpace u, Scalar u ~ s) =>
Coercion
  (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap
                                Coercion
  (LinearMap s v (LinearMap s (Tensor s v u) w))
  (LinearMap s (Tensor s v (Tensor s v u)) w)
-> Coercion
     (LinearMap
        s v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
     (LinearMap s v (LinearMap s (Tensor s v u) w))
-> Coercion
     (LinearMap
        s v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
     (LinearMap s (Tensor s v (Tensor s v u)) w)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (Tensor s (DualVector v) (Tensor s (DualVector u) w))
  (LinearMap s (Tensor s v u) w)
-> Coercion
     (LinearMap
        s v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
     (LinearMap s v (LinearMap s (Tensor s v u) w))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (Coercion
  (LinearMap s v (LinearMap s u w)) (LinearMap s (Tensor s v u) w)
forall u v w s.
(LinearSpace u, Scalar u ~ s) =>
Coercion
  (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap Coercion
  (LinearMap s v (LinearMap s u w)) (LinearMap s (Tensor s v u) w)
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (LinearMap s v (LinearMap s u w))
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (LinearMap s (Tensor s v u) w)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (Tensor s (DualVector v) (LinearMap s u w))
  (LinearMap s v (LinearMap s u w))
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor Coercion
  (Tensor s (DualVector v) (LinearMap s u w))
  (LinearMap s v (LinearMap s u w))
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (Tensor s (DualVector v) (LinearMap s u w))
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (LinearMap s v (LinearMap s u w))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion (Tensor s (DualVector u) w) (LinearMap s u w)
-> Coercion
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (Tensor s (DualVector v) (LinearMap s u w))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Coercion (Tensor s (DualVector u) w) (LinearMap s u w)
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor)
                                       Coercion
  (LinearMap
     s v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
  (LinearMap s (Tensor s v (Tensor s v u)) w)
-> LinearMap
     s v (Tensor s (DualVector v) (Tensor s (DualVector u) w))
-> LinearMap s (Tensor s v (Tensor s v u)) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct
  (DualVector v)
  (Tensor s (DualVector v) (Tensor s (DualVector u) w))
-> LinearMap
     s v (Tensor s (DualVector v) (Tensor s (DualVector u) w))
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct
  (DualVector v)
  (Tensor s (DualVector v) (Tensor s (DualVector u) w))
f) Tensor (Scalar v) v (Tensor s v u)
TensorProduct (SymmetricTensor s v) u
t  
  useTupleLinearSpaceComponents :: ((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = φ
forall a. a
usingNonTupleTypeAsTupleError




squareV :: (Num' s, s ~ Scalar v)
          => TensorSpace v => v -> SymmetricTensor s v
squareV :: v -> SymmetricTensor s v
squareV v
v = Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor (Tensor s v v -> SymmetricTensor s v)
-> Tensor s v v -> SymmetricTensor s v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ v
vv -> v -> v ⊗ v
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
 Num' (Scalar v)) =>
v -> w -> v ⊗ w
v
v

squareVs :: (Num' s, s ~ Scalar v)
          => TensorSpace v => [v] -> SymmetricTensor s v
squareVs :: [v] -> SymmetricTensor s v
squareVs [v]
vs = Tensor s v v -> SymmetricTensor s v
forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor (Tensor s v v -> SymmetricTensor s v)
-> Tensor s v v -> SymmetricTensor s v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [(v, v)] -> v ⊗ v
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
[(v, w)] -> v ⊗ w
tensorProducts [(v
v,v
v) | v
v<-[v]
vs]


type v⊗〃+>w = LinearMap (Scalar v) (SymmetricTensor (Scalar v) v) w

currySymBilin :: LinearSpace v => (v⊗〃+>w) -+> (v+>(v+>w))
currySymBilin :: (v ⊗〃+> w) -+> (v +> (v +> w))
currySymBilin = ((v ⊗〃+> w) -> v +> (v +> w))
-> LinearFunction (Scalar v) (v ⊗〃+> w) (v +> (v +> w))
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (((v ⊗〃+> w) -> v +> (v +> w))
 -> LinearFunction (Scalar v) (v ⊗〃+> w) (v +> (v +> w)))
-> (Coercion (v ⊗〃+> w) (v +> (v +> w))
    -> (v ⊗〃+> w) -> v +> (v +> w))
-> Coercion (v ⊗〃+> w) (v +> (v +> w))
-> LinearFunction (Scalar v) (v ⊗〃+> w) (v +> (v +> w))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion (v ⊗〃+> w) (v +> (v +> w)) -> (v ⊗〃+> w) -> v +> (v +> w)
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (Coercion (v ⊗〃+> w) (v +> (v +> w))
 -> LinearFunction (Scalar v) (v ⊗〃+> w) (v +> (v +> w)))
-> Coercion (v ⊗〃+> w) (v +> (v +> w))
-> LinearFunction (Scalar v) (v ⊗〃+> w) (v +> (v +> w))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Coercion (Tensor (Scalar v) (DualVector v) w) (v +> w)
-> Coercion
     (LinearMap (Scalar v) v (Tensor (Scalar v) (DualVector v) w))
     (v +> (v +> w))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Coercion (Tensor (Scalar v) (DualVector v) w) (v +> w)
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor Coercion
  (LinearMap (Scalar v) v (Tensor (Scalar v) (DualVector v) w))
  (v +> (v +> w))
-> Coercion
     (v ⊗〃+> w)
     (LinearMap (Scalar v) v (Tensor (Scalar v) (DualVector v) w))
-> Coercion (v ⊗〃+> w) (v +> (v +> w))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Coercion
  (Tensor
     (Scalar v) (DualVector v) (Tensor (Scalar v) (DualVector v) w))
  (LinearMap (Scalar v) v (Tensor (Scalar v) (DualVector v) w))
forall s v w.
Coercion (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor Coercion
  (Tensor
     (Scalar v) (DualVector v) (Tensor (Scalar v) (DualVector v) w))
  (LinearMap (Scalar v) v (Tensor (Scalar v) (DualVector v) w))
-> Coercion
     (v ⊗〃+> w)
     (Tensor
        (Scalar v) (DualVector v) (Tensor (Scalar v) (DualVector v) w))
-> Coercion
     (v ⊗〃+> w)
     (LinearMap (Scalar v) v (Tensor (Scalar v) (DualVector v) w))
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (Tensor
   (Scalar v) (DualVector v) (Tensor (Scalar v) (DualVector v) w)
 -> v ⊗〃+> w)
-> Coercion
     (v ⊗〃+> w)
     (Tensor
        (Scalar v) (DualVector v) (Tensor (Scalar v) (DualVector v) w))
forall (k :: * -> * -> *) b a (p :: * -> * -> *).
(EnhancedCat k Coercion, Coercible b a, Object k a, Object k b) =>
p a b -> k b a
flout Tensor
  (Scalar v) (DualVector v) (Tensor (Scalar v) (DualVector v) w)
-> v ⊗〃+> w
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap





newtype LinearApplicativeSpace f y
    = LinearApplicativeSpace { LinearApplicativeSpace f y -> f y
getLinearApplicativeSpace :: f y }

instance ( GHC.Generic1 f, TensorSpace y
         , TensorSpace (f y), Scalar (f y) ~ Scalar y
         , Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
     => AffineSpace (LinearApplicativeSpace f y) where
  type Diff (LinearApplicativeSpace f y) = LinearApplicativeSpace f y
  .+^ :: LinearApplicativeSpace f y
-> Diff (LinearApplicativeSpace f y) -> LinearApplicativeSpace f y
(.+^) = LinearApplicativeSpace f y
-> Diff (LinearApplicativeSpace f y) -> LinearApplicativeSpace f y
forall v. AdditiveGroup v => v -> v -> v
(^+^)
  .-. :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> Diff (LinearApplicativeSpace f y)
(.-.) = LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> Diff (LinearApplicativeSpace f y)
forall v. AdditiveGroup v => v -> v -> v
(^-^)

instance  f y . ( GHC.Generic1 f, TensorSpace y
                 , TensorSpace (f y), Scalar (f y) ~ Scalar y
                 , Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
     => AdditiveGroup (LinearApplicativeSpace f y) where
  zeroV :: LinearApplicativeSpace f y
zeroV = f y -> LinearApplicativeSpace f y
forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace (f y -> LinearApplicativeSpace f y)
-> f y -> LinearApplicativeSpace f y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar y) (ZeroDim (Scalar y)) (f y)
-> ZeroDim (Scalar y) -> f y
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
             ( LinearFunction (Scalar y) (ZeroDim (Scalar y)) y
-> LinearFunction (Scalar y) (f (ZeroDim (Scalar y))) (f y)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap LinearFunction (Scalar y) (ZeroDim (Scalar y)) y
forall v. AdditiveGroup v => v
zeroV
              LinearFunction (Scalar y) (f (ZeroDim (Scalar y))) (f y)
-> LinearFunction
     (Scalar y) (ZeroDim (Scalar y)) (f (ZeroDim (Scalar y)))
-> LinearFunction (Scalar y) (ZeroDim (Scalar y)) (f y)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (LinearFunction
  (Scalar y) (ZeroDim (Scalar y)) (f (ZeroDim (Scalar y)))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *).
Monoidal f r t =>
t (UnitObject t) (f (UnitObject r))
pureUnit :: LinearFunction (Scalar y) (ZeroDim (Scalar y))
                                                       (f (ZeroDim (Scalar y)))) ) ZeroDim (Scalar y)
forall v. AdditiveGroup v => v
zeroV
  LinearApplicativeSpace f y
a^+^ :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> LinearApplicativeSpace f y
^+^LinearApplicativeSpace f y
b
    = f y -> LinearApplicativeSpace f y
forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace
     (f y -> LinearApplicativeSpace f y)
-> f y -> LinearApplicativeSpace f y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar y) (f y, f y) (f y) -> (f y, f y) -> f y
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
           (LinearFunction (Scalar y) (y, y) y
-> LinearFunction (Scalar y) (f y, f y) (f y)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
 ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith (((y, y) -> y) -> LinearFunction (Scalar y) (y, y) y
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (((y, y) -> y) -> LinearFunction (Scalar y) (y, y) y)
-> ((y, y) -> y) -> LinearFunction (Scalar y) (y, y) y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (y -> y -> y) -> (y, y) -> y
forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k a (k b c) -> k (a, b) c
uncurry y -> y -> y
forall v. AdditiveGroup v => v -> v -> v
(^+^)))
           (f y
a,f y
b)
  LinearApplicativeSpace f y
a^-^ :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> LinearApplicativeSpace f y
^-^LinearApplicativeSpace f y
b
    = f y -> LinearApplicativeSpace f y
forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace
     (f y -> LinearApplicativeSpace f y)
-> f y -> LinearApplicativeSpace f y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar y) (f y, f y) (f y) -> (f y, f y) -> f y
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
           (LinearFunction (Scalar y) (y, y) y
-> LinearFunction (Scalar y) (f y, f y) (f y)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
 ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith (((y, y) -> y) -> LinearFunction (Scalar y) (y, y) y
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (((y, y) -> y) -> LinearFunction (Scalar y) (y, y) y)
-> ((y, y) -> y) -> LinearFunction (Scalar y) (y, y) y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (y -> y -> y) -> (y, y) -> y
forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k a (k b c) -> k (a, b) c
uncurry y -> y -> y
forall v. AdditiveGroup v => v -> v -> v
(^-^)))
           (f y
a,f y
b)
  negateV :: LinearApplicativeSpace f y -> LinearApplicativeSpace f y
negateV (LinearApplicativeSpace f y
a) = f y -> LinearApplicativeSpace f y
forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace
       (f y -> LinearApplicativeSpace f y)
-> f y -> LinearApplicativeSpace f y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar y) (f y) (f y) -> f y -> f y
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (LinearFunction (Scalar y) y y
-> LinearFunction (Scalar y) (f y) (f y)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (LinearFunction (Scalar y) y y
 -> LinearFunction (Scalar y) (f y) (f y))
-> LinearFunction (Scalar y) y y
-> LinearFunction (Scalar y) (f y) (f y)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (y -> y) -> LinearFunction (Scalar y) y y
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction y -> y
forall v. AdditiveGroup v => v -> v
negateV) f y
a

instance ( GHC.Generic1 f, TensorSpace y
         , TensorSpace (f y), Scalar (f y) ~ Scalar y
         , Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
     => VectorSpace (LinearApplicativeSpace f y) where
  type Scalar (LinearApplicativeSpace f y) = Scalar y
  *^ :: Scalar (LinearApplicativeSpace f y)
-> LinearApplicativeSpace f y -> LinearApplicativeSpace f y
(*^) = Scalar (LinearApplicativeSpace f y)
-> LinearApplicativeSpace f y -> LinearApplicativeSpace f y
forall a. HasCallStack => a
undefined

instance ( GHC.Generic1 f, TensorSpace y
         , TensorSpace (f y), Scalar (f y) ~ Scalar y
         , Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
     => Semimanifold (LinearApplicativeSpace f y) where
  type Needle (LinearApplicativeSpace f y) = LinearApplicativeSpace f y
#if !MIN_VERSION_manifolds_core(0,6,0)
  type Interior (LinearApplicativeSpace f y) = LinearApplicativeSpace f y
  toInterior = Just; fromInterior = id
  translateP = Tagged (^+^)
#endif
  .+~^ :: LinearApplicativeSpace f y
-> Needle (LinearApplicativeSpace f y)
-> LinearApplicativeSpace f y
(.+~^) = LinearApplicativeSpace f y
-> Needle (LinearApplicativeSpace f y)
-> LinearApplicativeSpace f y
forall v. AdditiveGroup v => v -> v -> v
(^+^)

instance ( GHC.Generic1 f, TensorSpace y
         , TensorSpace (f y), Scalar (f y) ~ Scalar y
         , Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
     => PseudoAffine (LinearApplicativeSpace f y) where
  .-~! :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y
-> Needle (LinearApplicativeSpace f y)
(.-~!) = LinearApplicativeSpace f y
-> LinearApplicativeSpace f y
-> Needle (LinearApplicativeSpace f y)
forall p. AffineSpace p => p -> p -> Diff p
(.-.)
  LinearApplicativeSpace f y
p.-~. :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y
-> Maybe (Needle (LinearApplicativeSpace f y))
.-~.LinearApplicativeSpace f y
q = LinearApplicativeSpace f y -> Maybe (LinearApplicativeSpace f y)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (LinearApplicativeSpace f y
pLinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> Diff (LinearApplicativeSpace f y)
forall p. AffineSpace p => p -> p -> Diff p
.-.LinearApplicativeSpace f y
q)



instance (InnerSpace v, Scalar v ~ , TensorSpace v)
              => InnerSpace (Tensor   v) where
  Tensor TensorProduct ℝ v
t <.> :: Tensor ℝ ℝ v -> Tensor ℝ ℝ v -> Scalar (Tensor ℝ ℝ v)
<.> Tensor TensorProduct ℝ v
u = v
TensorProduct ℝ v
t v -> v -> Scalar v
forall v. InnerSpace v => v -> v -> Scalar v
<.> v
TensorProduct ℝ v
u
instance (InnerSpace v, TensorSpace v, Scalar v ~ )
   => InnerSpace (LinearMap   v) where
  LinearMap TensorProduct (DualVector ℝ) v
f <.> :: LinearMap ℝ ℝ v -> LinearMap ℝ ℝ v -> Scalar (LinearMap ℝ ℝ v)
<.> LinearMap TensorProduct (DualVector ℝ) v
g = v
TensorProduct (DualVector ℝ) v
fv -> v -> Scalar v
forall v. InnerSpace v => v -> v -> Scalar v
<.>v
TensorProduct (DualVector ℝ) v
g

instance (Show v) => Show (Tensor   v) where
  showsPrec :: Int -> Tensor ℝ ℝ v -> ShowS
showsPrec Int
p (Tensor TensorProduct ℝ v
t) = Bool -> ShowS -> ShowS
showParen (Int
pInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>Int
9) (ShowS -> ShowS) -> ShowS -> ShowS
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (String
"Tensor "String -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> ShowS -> ShowS
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Int -> v -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
10 v
TensorProduct ℝ v
t

instance (QC.Arbitrary v, Scalar v ~ ) => QC.Arbitrary (Tensor   v) where
  arbitrary :: Gen (Tensor ℝ ℝ v)
arbitrary = v -> Tensor ℝ ℝ v
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (v -> Tensor ℝ ℝ v) -> Gen v -> Gen (Tensor ℝ ℝ v)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen v
forall a. Arbitrary a => Gen a
QC.arbitrary
  shrink :: Tensor ℝ ℝ v -> [Tensor ℝ ℝ v]
shrink (Tensor TensorProduct ℝ v
t) = v -> Tensor ℝ ℝ v
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (v -> Tensor ℝ ℝ v) -> [v] -> [Tensor ℝ ℝ v]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> v -> [v]
forall a. Arbitrary a => a -> [a]
QC.shrink v
TensorProduct ℝ v
t

instance (QC.Arbitrary v, Scalar v ~ ) => QC.Arbitrary (LinearMap   v) where
  arbitrary :: Gen (LinearMap ℝ ℝ v)
arbitrary = v -> LinearMap ℝ ℝ v
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (v -> LinearMap ℝ ℝ v) -> Gen v -> Gen (LinearMap ℝ ℝ v)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen v
forall a. Arbitrary a => Gen a
QC.arbitrary
  shrink :: LinearMap ℝ ℝ v -> [LinearMap ℝ ℝ v]
shrink (LinearMap TensorProduct (DualVector ℝ) v
t) = v -> LinearMap ℝ ℝ v
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap (v -> LinearMap ℝ ℝ v) -> [v] -> [LinearMap ℝ ℝ v]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> v -> [v]
forall a. Arbitrary a => a -> [a]
QC.shrink v
TensorProduct (DualVector ℝ) v
t

#define FreeArbitrarySpace(S) \
instance (QC.Arbitrary v, Scalar v ~ ℝ) => QC.Arbitrary (Tensor ℝ (S ℝ) v) where { \
  arbitrary = Tensor <$> Hask.traverse (const QC.arbitrary) zeroV };  \
instance (QC.Arbitrary v, Scalar v ~ ℝ) => QC.Arbitrary (LinearMap ℝ (S ℝ) v) where { \
  arbitrary = LinearMap <$> Hask.traverse (const QC.arbitrary) zeroV }

FreeArbitrarySpace(V0)
FreeArbitrarySpace(V1)
FreeArbitrarySpace(V2)
FreeArbitrarySpace(V3)
FreeArbitrarySpace(V4)