-- |
-- 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 FunctionalDependencies     #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE InstanceSigs               #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE UnicodeSyntax              #-}
{-# LANGUAGE CPP                        #-}
{-# LANGUAGE TupleSections              #-}
{-# LANGUAGE EmptyCase                  #-}
{-# LANGUAGE TypeApplications           #-}

module Math.LinearMap.Category.Instances where

import Math.VectorSpace.DimensionAware
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.Proxy

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 Control.Monad.ST (ST)

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

import Math.LinearMap.Asserted
import Math.VectorSpace.ZeroDimensional
import qualified Math.VectorSpace.DimensionAware.Theorems.MaybeNat as Maybe

import qualified Test.QuickCheck as QC

import GHC.TypeNats (natVal)
import qualified GHC.Exts as GHC
import qualified GHC.Generics as GHC

import Data.Singletons (SingI, sing, Sing)
#if MIN_VERSION_singletons(3,0,0)
import GHC.TypeLits.Singletons (withKnownNat)
#else
import Data.Singletons.TypeLits (withKnownNat)
#endif


#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 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 .-~! :: HasCallStack => 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<.>^ :: forall v. LinearSpace v => DualVector v -> v -> Scalar v
<.>^v
v = (Bilinear (DualVector v) v (Scalar v)
forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorBilinear (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 :: forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
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 = LinearFunction $ \(Tensor v) -> Tensor (negateV v); \
  toFlatTensor = LinearFunction $ follow Tensor; \
  fromFlatTensor = LinearFunction $ flout Tensor; \
  tensorProduct = bilinearFunction $ \μ \
           -> follow Tensor . getLinearFunction (scaleWith μ); \
  transposeTensor = toFlatTensor . LinearFunction (flout Tensor); \
  fmapTensor = bilinearFunction $ \f (Tensor t) -> Tensor (f-+$>t); \
  fzipTensorWith = bilinearFunction \
                   $ \(LinearFunction f) -> follow Tensor <<< f <<< flout Tensor *** flout Tensor; \
  tensorUnsafeFromArrayWithOffset i ar \
    = Tensor (unsafeFromArrayWithOffset i ar); \
  tensorUnsafeWriteArrayWithOffset ar i (Tensor v) \
    = unsafeWriteArrayWithOffset ar i v; \
  coerceFmapTensorProduct _ VSCCoercion = Coercion; \
  wellDefinedTensor (Tensor w) = Tensor <$> wellDefinedVector w }; \
instance LinearSpace (S) where { \
  type DualVector (S) = (S); \
  dualSpaceWitness = DualSpaceWitness; \
  linearId = LinearMap 1; \
  tensorId = uncurryLinearMap $ LinearMap $ fmap (LinearFunction $ follow Tensor) -+$> id; \
  idTensor = Tensor 1; \
  fromLinearForm = LinearFunction $ flout LinearMap; \
  coerceDoubleDual = VSCCoercion; \
  contractTensorMap = LinearFunction $ flout Tensor . flout LinearMap; \
  contractMapTensor = LinearFunction $ 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)

{-# INLINE tensorUnsafeFromArrayWithOffsetViaList #-}
tensorUnsafeFromArrayWithOffsetViaList
          ::  v w n m α . ( n`Dimensional`v
                           , m`Dimensional`w
                           , Scalar v ~ Scalar w
                           , GArr.Vector α (Scalar v) )
   => ([w] -> TensorProduct v w) -> Int -> α (Scalar v) -> (vw)
tensorUnsafeFromArrayWithOffsetViaList :: forall v w (n :: Nat) (m :: Nat) (α :: * -> *).
(Dimensional n v, Dimensional m w, Scalar v ~ Scalar w,
 Vector α (Scalar v)) =>
([w] -> TensorProduct v w) -> Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffsetViaList [w] -> TensorProduct v w
l2v Int
i α (Scalar v)
ar
   = TensorProduct v w -> Tensor (Scalar w) v w
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (TensorProduct v w -> Tensor (Scalar w) v w)
-> TensorProduct v w -> Tensor (Scalar w) v w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [w] -> TensorProduct v w
l2v [ Int -> α (Scalar w) -> w
forall (n :: Nat) v (α :: * -> *).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
forall (α :: * -> *).
Vector α (Scalar w) =>
Int -> α (Scalar w) -> w
unsafeFromArrayWithOffset
                      (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
* forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @w) α (Scalar v)
α (Scalar w)
ar
                  | Int
j <- [Int
0 .. forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ]

{-# INLINE tensorUnsafeWriteArrayWithOffsetViaList #-}
tensorUnsafeWriteArrayWithOffsetViaList
        ::  v w n m α σ . ( n`Dimensional`v
                           , m`Dimensional`w
                           , Scalar v ~ Scalar w
                           , GArr.Vector α (Scalar v) )
   => (TensorProduct v w -> [w]) -> GArr.Mutable α σ (Scalar v)
          -> Int -> (vw) -> ST σ ()
tensorUnsafeWriteArrayWithOffsetViaList :: forall v w (n :: Nat) (m :: Nat) (α :: * -> *) σ.
(Dimensional n v, Dimensional m w, Scalar v ~ Scalar w,
 Vector α (Scalar v)) =>
(TensorProduct v w -> [w])
-> Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffsetViaList TensorProduct v w -> [w]
v2l Mutable α σ (Scalar v)
ar Int
i (Tensor TensorProduct v w
t)
   = [(Int, w)] -> ((Int, w) -> ST σ ()) -> ST σ (UnitObject (->))
forall (t :: * -> *) (k :: * -> * -> *) (l :: * -> * -> *)
       (f :: * -> *) a b uk ul.
(Foldable t k l, Monoidal f l l, Monoidal f k k, Function l,
 Arrow k (->), Arrow l (->), ul ~ UnitObject l, uk ~ UnitObject k,
 uk ~ ul, ObjectPair l ul ul, ObjectPair l (f ul) (f ul),
 ObjectPair l (f ul) (t a), ObjectPair l ul (t a),
 ObjectPair l (t a) ul, ObjectPair l (f ul) a, ObjectPair k b (f b),
 ObjectPair k b ul, ObjectPair k uk uk, ObjectPair k (f uk) a,
 ObjectPair k (f uk) (f uk)) =>
t a -> k a (f b) -> f uk
forM_ ([Int] -> [w] -> [(Int, w)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] ([w] -> [(Int, w)]) -> [w] -> [(Int, w)]
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct v w -> [w]
v2l TensorProduct v w
t) (((Int, w) -> ST σ ()) -> ST σ ())
-> ((Int, w) -> ST σ ()) -> ST σ ()
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Int
j, w
v)
       -> Mutable α σ (Scalar w) -> Int -> w -> ST σ ()
forall (n :: Nat) v (α :: * -> *) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
forall (α :: * -> *) σ.
Vector α (Scalar w) =>
Mutable α σ (Scalar w) -> Int -> w -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar v)
Mutable α σ (Scalar w)
ar
                      (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
* forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @w) w
v

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

#define FreeLinearSpace( V, d, LV, tp \
                       , tenspl, tenid, dspan \
                       , contraction, contraaction \
                       , frls, tols )  \
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) => DimensionAware (V s) where {                     \
  type StaticDimension (V s) = 'Just (d);       \
  dimensionalityWitness = IsStaticDimensional };                               \
instance ∀ s . (Num' s, Eq s) => (d)`Dimensional`V (s) where {                     \
  unsafeFromArrayWithOffset \
     = unsafeFromArrayWithOffsetViaList (frls); \
  unsafeWriteArrayWithOffset \
     = unsafeWriteArrayWithOffsetViaList (tols) \
   };                               \
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 -> LinearFunction $ follow Tensor}; \
  fromFlatTensor = case closedScalarWitness :: ClosedScalarWitness s of{ \
                         ClosedScalarWitness -> LinearFunction $ 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; \
  tensorUnsafeFromArrayWithOffset \
     = tensorUnsafeFromArrayWithOffsetViaList (frls); \
  tensorUnsafeWriteArrayWithOffset \
     = tensorUnsafeWriteArrayWithOffsetViaList (tols); \
  coerceFmapTensorProduct _ VSCCoercion = 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 = VSCCoercion; \
  fromLinearForm = case closedScalarWitness :: ClosedScalarWitness s of{ \
                         ClosedScalarWitness -> LinearFunction $ 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 ((fromTensor-+$=>) >>> \
                         getLinearFunction . getLinearFunction applyLinear) f t; \
  composeLinear = bilinearFunction $   \
         \f (LinearMap g) -> LinearMap $ fmap ((applyLinear-+$>f)-+$>) g; \
  useTupleLinearSpaceComponents _ = usingNonTupleTypeAsTupleError }
FreeLinearSpace( V0, 0
               , LinearMap
               , \(Tensor V0) -> zeroV
               , \_ -> LinearMap V0
               , V0
               , LinearMap V0
               , \V0 -> zeroV
               , \V0 _ -> 0
               , \[] -> V0
               , \V0 -> []
               )
FreeLinearSpace( V1, 1
               , 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
               , \[x] -> V1 x
               , \(V1 x) -> [x]
               )
FreeLinearSpace( V2, 2
               , 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
               , \(x:y:[]) -> V2 x y
               , \(V2 x y) -> (x:y:[])
               )
FreeLinearSpace( V3, 3
               , 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
               , \(x:y:z:[]) -> V3 x y z
               , \(V3 x y z) -> x:y:z:[]
               )
FreeLinearSpace( V4, 4
               , 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
               , \(x:y:z:w:[]) -> V4 x y z w
               , \(V4 x y z w) -> x:y:z: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
TensorProduct (DualVector 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
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
TensorProduct (DualVector 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
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
TensorProduct (DualVector 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
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
TensorProduct (DualVector 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
TensorProduct (DualVector 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
TensorProduct (DualVector n) 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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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
TensorProduct (DualVector 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
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
TensorProduct (DualVector 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
TensorProduct (DualVector n) 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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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 -> Diff (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; .-~! :: HasCallStack =>
FinSuppSeq n -> FinSuppSeq n -> Needle (FinSuppSeq n)
(.-~!) = FinSuppSeq n -> FinSuppSeq n -> Diff (FinSuppSeq n)
FinSuppSeq n -> FinSuppSeq n -> Needle (FinSuppSeq n)
forall p. AffineSpace p => p -> p -> Diff p
(.-.)

instance (Num' n, UArr.Unbox n) => DimensionAware (FinSuppSeq n) where
  type StaticDimension (FinSuppSeq n) = 'Nothing
  dimensionalityWitness :: DimensionalityWitness (FinSuppSeq n)
dimensionalityWitness = DimensionalityWitness (FinSuppSeq n)
forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
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
TensorProduct (FinSuppSeq n) 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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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]
Tensor n (FinSuppSeq n) n -> TensorProduct (FinSuppSeq n) n
forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(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
TensorProduct (FinSuppSeq n) 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 a. (a -> a -> a) -> [a] -> [a] -> [a]
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 :: forall w.
(TensorSpace (FinSuppSeq n), TensorSpace w,
 Scalar w ~ Scalar (FinSuppSeq n)) =>
(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
TensorProduct (FinSuppSeq n) 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 a. (a -> a -> a) -> [a] -> [a] -> [a]
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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
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
TensorProduct (FinSuppSeq n) 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(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
TensorProduct (FinSuppSeq n) 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
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))
(FinSuppSeq n -> w -> Tensor n (FinSuppSeq n) w)
-> Bilinear (FinSuppSeq 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
TensorProduct (FinSuppSeq n) 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) -+> (w ⊗ FinSuppSeq n)
transposeTensor = (Tensor n (FinSuppSeq n) w -> Tensor n w (FinSuppSeq n))
-> LinearFunction
     n (Tensor n (FinSuppSeq n) w) (Tensor n w (FinSuppSeq n))
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (FinSuppSeq n) w -> Tensor n w (FinSuppSeq n))
 -> LinearFunction
      n (Tensor n (FinSuppSeq n) w) (Tensor n w (FinSuppSeq n)))
-> (Tensor n (FinSuppSeq n) w -> Tensor n w (FinSuppSeq n))
-> LinearFunction
     n (Tensor n (FinSuppSeq n) w) (Tensor n 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 a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [w]
TensorProduct (FinSuppSeq n) w
a
       in (Tensor n w (FinSuppSeq n)
 -> Tensor n w (FinSuppSeq n) -> Tensor n w (FinSuppSeq n))
-> Tensor n w (FinSuppSeq n)
-> [Tensor n w (FinSuppSeq n)]
-> Tensor n w (FinSuppSeq n)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Tensor n w (FinSuppSeq n)
-> Tensor n w (FinSuppSeq n) -> Tensor n w (FinSuppSeq n)
forall v. AdditiveGroup v => v -> v -> v
(^+^) Tensor n w (FinSuppSeq n)
forall v. AdditiveGroup v => v
zeroV
        ([Tensor n w (FinSuppSeq n)] -> Tensor n w (FinSuppSeq n))
-> [Tensor n w (FinSuppSeq n)] -> Tensor n w (FinSuppSeq n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Int -> w -> Tensor n w (FinSuppSeq n))
-> [Int] -> [w] -> [Tensor n w (FinSuppSeq n)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ( \Int
i w
w -> LinearFunction
  (Scalar w)
  w
  (LinearFunction
     (Scalar w) (FinSuppSeq n) (Tensor n w (FinSuppSeq n)))
-> w
-> LinearFunction
     (Scalar w) (FinSuppSeq n) (Tensor n w (FinSuppSeq n))
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  (Scalar w)
  w
  (LinearFunction
     (Scalar w) (FinSuppSeq n) (Tensor n w (FinSuppSeq n)))
Bilinear w (FinSuppSeq n) (Tensor (Scalar w) w (FinSuppSeq n))
forall w.
(TensorSpace w, Scalar w ~ Scalar w) =>
Bilinear w w (w ⊗ w)
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProduct w
w LinearFunction
  (Scalar w) (FinSuppSeq n) (Tensor n w (FinSuppSeq n))
-> FinSuppSeq n -> Tensor 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 :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (FinSuppSeq n),
 Scalar x ~ Scalar (FinSuppSeq n)) =>
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
     n
     (LinearFunction n w x)
     (LinearFunction
        n (Tensor n (FinSuppSeq n) w) (Tensor n (FinSuppSeq n) x))
(LinearFunction n w x
 -> Tensor n (FinSuppSeq n) w -> Tensor n (FinSuppSeq n) x)
-> Bilinear
     (LinearFunction n w 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
      n
      (LinearFunction n w x)
      (LinearFunction
         n (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
     n
     (LinearFunction n w x)
     (LinearFunction
        n (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
TensorProduct (FinSuppSeq n) 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 :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (FinSuppSeq n), Scalar w ~ Scalar (FinSuppSeq n),
 Scalar x ~ Scalar (FinSuppSeq n)) =>
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
     n
     (LinearFunction n (w, x) u)
     (LinearFunction
        n
        (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)
-> Bilinear
     (LinearFunction n (w, x) 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
      n
      (LinearFunction n (w, x) u)
      (LinearFunction
         n
         (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
     n
     (LinearFunction n (w, x) u)
     (LinearFunction
        n
        (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
TensorProduct (FinSuppSeq n) 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 a b c.
(ObjectPair (->) a b, ObjectMorphism (->) b c) =>
((a, b) -> c) -> a -> b -> c
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 b c.
(Object (LinearFunction n) b, Object (LinearFunction n) c,
 Object (->) b, Object (->) c) =>
LinearFunction n b c -> b -> c
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
  tensorUnsafeFromArrayWithOffset :: forall w (α :: * -> *) (n :: Nat) (m :: Nat).
(Dimensional n (FinSuppSeq n), TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar (FinSuppSeq n),
 Vector α (Scalar (FinSuppSeq n))) =>
Int -> α (Scalar (FinSuppSeq n)) -> FinSuppSeq n ⊗ w
tensorUnsafeFromArrayWithOffset
      = forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
forall v (n :: Any) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(FinSuppSeq n)
  tensorUnsafeWriteArrayWithOffset :: forall w (α :: * -> *) σ (n :: Nat) (m :: Nat).
(Dimensional n (FinSuppSeq n), TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar (FinSuppSeq n),
 Vector α (Scalar (FinSuppSeq n))) =>
Mutable α σ (Scalar (FinSuppSeq n))
-> Int -> (FinSuppSeq n ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
      = forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
forall v (n :: Any) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(FinSuppSeq n)
  coerceFmapTensorProduct :: forall (p :: * -> *) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (FinSuppSeq n),
 TensorSpace b, Scalar b ~ Scalar (FinSuppSeq n)) =>
p (FinSuppSeq n)
-> VSCCoercion (Scalar (FinSuppSeq n)) a b
-> Coercion
     (TensorProduct (FinSuppSeq n) a) (TensorProduct (FinSuppSeq n) b)
coerceFmapTensorProduct p (FinSuppSeq n)
_ VSCCoercion (Scalar (FinSuppSeq n)) a b
VSCCoercion = Coercion [a] [b]
Coercion
  (TensorProduct (FinSuppSeq n) a) (TensorProduct (FinSuppSeq n) b)
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) -> Maybe (FinSuppSeq n ⊗ w)
wellDefinedTensor (Tensor TensorProduct (FinSuppSeq n) w
a) = [w] -> Tensor n (FinSuppSeq n) w
TensorProduct (FinSuppSeq n) 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)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [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 -> Diff (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; .-~! :: HasCallStack => Sequence n -> Sequence n -> Needle (Sequence n)
(.-~!) = Sequence n -> Sequence n -> Diff (Sequence n)
Sequence n -> Sequence n -> Needle (Sequence n)
forall p. AffineSpace p => p -> p -> Diff p
(.-.)

instance (Num' n, UArr.Unbox n) => DimensionAware (Sequence n) where
  type StaticDimension (Sequence n) = 'Nothing
  dimensionalityWitness :: DimensionalityWitness (Sequence n)
dimensionalityWitness = DimensionalityWitness (Sequence n)
forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
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 a b.
(ObjectMorphism (->) a b, ObjectMorphism (->) (Maybe a) (Maybe b),
 Object (->) (Maybe a -> Maybe b), ObjectPair (->) (a -> b) a,
 ObjectPair (->) (Maybe (a -> b)) (Maybe a), Object (->) a,
 Object (->) b) =>
Maybe (a -> b) -> Maybe a -> Maybe b
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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) -> Maybe (Sequence n ⊗ w)
wellDefinedTensor (Tensor TensorProduct (Sequence n) w
a) = [w] -> Tensor n (Sequence n) w
TensorProduct (Sequence n) 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)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
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
TensorProduct (Sequence n) 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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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]
Sequence n -> [Item (Sequence 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
[Item (Sequence 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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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]
Tensor n (Sequence n) n -> TensorProduct (Sequence n) n
forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(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
TensorProduct (Sequence n) 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 a. (a -> a -> a) -> [a] -> [a] -> [a]
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 :: forall w.
(TensorSpace (Sequence n), TensorSpace w,
 Scalar w ~ Scalar (Sequence n)) =>
(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
TensorProduct (Sequence n) 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 a. (a -> a -> a) -> [a] -> [a] -> [a]
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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
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
TensorProduct (Sequence n) 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(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
TensorProduct (Sequence n) 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
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))
(Sequence n -> w -> Tensor n (Sequence n) w)
-> Bilinear (Sequence 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
TensorProduct (Sequence n) 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) -+> (w ⊗ Sequence n)
transposeTensor = (Tensor n (Sequence n) w -> Tensor n w (Sequence n))
-> LinearFunction
     n (Tensor n (Sequence n) w) (Tensor n w (Sequence n))
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor n (Sequence n) w -> Tensor n w (Sequence n))
 -> LinearFunction
      n (Tensor n (Sequence n) w) (Tensor n w (Sequence n)))
-> (Tensor n (Sequence n) w -> Tensor n w (Sequence n))
-> LinearFunction
     n (Tensor n (Sequence n) w) (Tensor n 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 a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [w]
TensorProduct (Sequence n) w
a
       in (Tensor n w (Sequence n)
 -> Tensor n w (Sequence n) -> Tensor n w (Sequence n))
-> Tensor n w (Sequence n)
-> [Tensor n w (Sequence n)]
-> Tensor n w (Sequence n)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Tensor n w (Sequence n)
-> Tensor n w (Sequence n) -> Tensor n w (Sequence n)
forall v. AdditiveGroup v => v -> v -> v
(^+^) Tensor n w (Sequence n)
forall v. AdditiveGroup v => v
zeroV
        ([Tensor n w (Sequence n)] -> Tensor n w (Sequence n))
-> [Tensor n w (Sequence n)] -> Tensor n w (Sequence n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Int -> w -> Tensor n w (Sequence n))
-> [Int] -> [w] -> [Tensor n w (Sequence n)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Int
i w
w -> (LinearFunction
  (Scalar w)
  w
  (LinearFunction (Scalar w) (Sequence n) (Tensor n w (Sequence n)))
-> w
-> LinearFunction (Scalar w) (Sequence n) (Tensor n w (Sequence n))
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  (Scalar w)
  w
  (LinearFunction (Scalar w) (Sequence n) (Tensor n w (Sequence n)))
Bilinear w (Sequence n) (Tensor (Scalar w) w (Sequence n))
forall w.
(TensorSpace w, Scalar w ~ Scalar w) =>
Bilinear w w (w ⊗ w)
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProduct w
w) LinearFunction (Scalar w) (Sequence n) (Tensor n w (Sequence n))
-> Sequence n -> Tensor 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 :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (Sequence n),
 Scalar x ~ Scalar (Sequence n)) =>
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
     n
     (LinearFunction n w x)
     (LinearFunction
        n (Tensor n (Sequence n) w) (Tensor n (Sequence n) x))
(LinearFunction n w x
 -> Tensor n (Sequence n) w -> Tensor n (Sequence n) x)
-> Bilinear
     (LinearFunction n w 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
      n
      (LinearFunction n w x)
      (LinearFunction
         n (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
     n
     (LinearFunction n w x)
     (LinearFunction
        n (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
TensorProduct (Sequence n) 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 :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (Sequence n), Scalar w ~ Scalar (Sequence n),
 Scalar x ~ Scalar (Sequence n)) =>
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
     n
     (LinearFunction n (w, x) u)
     (LinearFunction
        n
        (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)
-> Bilinear
     (LinearFunction n (w, x) 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
      n
      (LinearFunction n (w, x) u)
      (LinearFunction
         n
         (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
     n
     (LinearFunction n (w, x) u)
     (LinearFunction
        n
        (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
TensorProduct (Sequence n) 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 a b c.
(ObjectPair (->) a b, ObjectMorphism (->) b c) =>
((a, b) -> c) -> a -> b -> c
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 b c.
(Object (LinearFunction n) b, Object (LinearFunction n) c,
 Object (->) b, Object (->) c) =>
LinearFunction n b c -> b -> c
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
  tensorUnsafeFromArrayWithOffset :: forall w (α :: * -> *) (n :: Nat) (m :: Nat).
(Dimensional n (Sequence n), TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar (Sequence n), Vector α (Scalar (Sequence n))) =>
Int -> α (Scalar (Sequence n)) -> Sequence n ⊗ w
tensorUnsafeFromArrayWithOffset
      = forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
forall v (n :: Any) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(Sequence n)
  tensorUnsafeWriteArrayWithOffset :: forall w (α :: * -> *) σ (n :: Nat) (m :: Nat).
(Dimensional n (Sequence n), TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar (Sequence n), Vector α (Scalar (Sequence n))) =>
Mutable α σ (Scalar (Sequence n))
-> Int -> (Sequence n ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
      = forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
forall v (n :: Any) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(Sequence n)
  coerceFmapTensorProduct :: forall (p :: * -> *) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (Sequence n),
 TensorSpace b, Scalar b ~ Scalar (Sequence n)) =>
p (Sequence n)
-> VSCCoercion (Scalar (Sequence n)) a b
-> Coercion
     (TensorProduct (Sequence n) a) (TensorProduct (Sequence n) b)
coerceFmapTensorProduct p (Sequence n)
_ VSCCoercion (Scalar (Sequence n)) a b
VSCCoercion = Coercion [a] [b]
Coercion
  (TensorProduct (Sequence n) a) (TensorProduct (Sequence n) b)
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion

instance  n . (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,
 StaticDimension (DualVector v) ~ StaticDimension 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 :: forall w.
(LinearSpace w, Scalar w ~ Scalar (Sequence n)) =>
(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 [VSCCoercion
  n
  (LinearMap n w (Tensor n (Sequence n) w))
  (Tensor n (DualVector w) (Tensor n (Sequence n) w))
forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor VSCCoercion
  n
  (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 s a b. VSCCoercion s 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 a b.
(Object (LinearFunction n) a,
 Object (LinearFunction n) (LinearMap n w a),
 Object (LinearFunction n) b,
 Object (LinearFunction n) (LinearMap n w b)) =>
LinearFunction n a b
-> LinearFunction n (LinearMap n w a) (LinearMap n w 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 ((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
TensorProduct (Sequence n) 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 a. Object (LinearMap n) a => LinearMap n a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id | Int
i<-[Int
0..]]
  applyDualVector :: LinearSpace (Sequence n) =>
Bilinear
  (DualVector (Sequence n)) (Sequence n) (Scalar (Sequence n))
applyDualVector = (FinSuppSeq n -> Sequence n -> n)
-> LinearFunction
     n (FinSuppSeq n) (LinearFunction n (Sequence n) n)
(FinSuppSeq n -> Sequence n -> n)
-> Bilinear (FinSuppSeq 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
Bilinear (Sequence n +> w) (Sequence n) w
applyLinear = (LinearMap n (Sequence n) w -> Sequence n -> w)
-> LinearFunction
     n (LinearMap n (Sequence n) w) (LinearFunction n (Sequence n) w)
(LinearMap n (Sequence n) w -> Sequence n -> w)
-> Bilinear (LinearMap n (Sequence n) w) (Sequence n) w
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((LinearMap n (Sequence n) w -> Sequence n -> w)
 -> LinearFunction
      n (LinearMap n (Sequence n) w) (LinearFunction n (Sequence n) w))
-> (LinearMap n (Sequence n) w -> Sequence n -> w)
-> LinearFunction
     n (LinearMap n (Sequence n) w) (LinearFunction n (Sequence n) 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 {v} {w} {c} {s}.
(TensorProduct (DualVector v) w ~ [c], VectorSpace c,
 Unbox (Scalar 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 a. [a] -> 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 b a. (b -> a -> b) -> b -> [a] -> b
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 :: forall u.
(LinearSpace u, Scalar u ~ Scalar (Sequence n)) =>
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)
(LinearMap n (Sequence n) (DualVector u)
 -> Tensor n (Sequence n) u -> n)
-> Bilinear
     (LinearMap n (Sequence n) (DualVector u))
     (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 a. Num a => [a] -> a
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
DualVector u -> u -> Scalar u
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 :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (Sequence n),
 Scalar w ~ Scalar (Sequence n)) =>
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)
(LinearMap n (Tensor n (Sequence n) u) w
 -> Tensor n (Sequence n) u -> w)
-> Bilinear
     (LinearMap n (Tensor n (Sequence n) u) w)
     (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
$ VSCCoercion
  n
  (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 b c.
(Object (VSCCoercion n) b, Object (VSCCoercion n) c, Object (->) b,
 Object (->) c) =>
VSCCoercion n b c -> b -> c
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 VSCCoercion
  n
  (LinearMap n (Tensor n (Sequence n) u) w)
  (LinearMap n (Sequence n) (LinearMap n u w))
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (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 (Scalar u) u w -> u -> w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (LinearFunction (Scalar u) u w -> u -> w)
-> (LinearMap (Scalar u) u w -> LinearFunction (Scalar u) u w)
-> LinearMap (Scalar u) u w
-> u
-> w
forall a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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 u)
  (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
  (Scalar u)
  (LinearMap (Scalar u) u w)
  (LinearFunction (Scalar u) u w)
Bilinear (LinearMap (Scalar u) u w) u w
forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
forall w.
(TensorSpace w, Scalar w ~ Scalar u) =>
Bilinear (u +> w) u w
applyLinear) [LinearMap (Scalar u) u w]
TensorProduct (DualVector (Sequence n)) (LinearMap n u w)
m [u]
TensorProduct (Sequence n) u
t
  useTupleLinearSpaceComponents :: forall x y φ.
(Sequence n ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = φ
forall a. a
usingNonTupleTypeAsTupleError
  coerceDoubleDual :: VSCCoercion
  (Scalar (Sequence n))
  (Sequence n)
  (DualVector (DualVector (Sequence n)))
coerceDoubleDual = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @n of
     ScalarSpaceWitness n
ScalarSpaceWitness -> VSCCoercion n (Sequence n) (Sequence n)
VSCCoercion
  (Scalar (Sequence n))
  (Sequence n)
  (DualVector (DualVector (Sequence n)))
forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
instance  n . (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,
 StaticDimension (DualVector v) ~ StaticDimension 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 :: forall w.
(LinearSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(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 [VSCCoercion
  n
  (LinearMap n w (Tensor n (FinSuppSeq n) w))
  (Tensor n (DualVector w) (Tensor n (FinSuppSeq n) w))
forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor VSCCoercion
  n
  (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 s a b. VSCCoercion s 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 a b.
(Object (LinearFunction n) a,
 Object (LinearFunction n) (LinearMap n w a),
 Object (LinearFunction n) b,
 Object (LinearFunction n) (LinearMap n w b)) =>
LinearFunction n a b
-> LinearFunction n (LinearMap n w a) (LinearMap n w 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 ((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
TensorProduct (FinSuppSeq n) 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 a. Object (LinearMap n) a => LinearMap n a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id | Int
i<-[Int
0..]]
  applyDualVector :: LinearSpace (FinSuppSeq n) =>
Bilinear
  (DualVector (FinSuppSeq n)) (FinSuppSeq n) (Scalar (FinSuppSeq n))
applyDualVector = (Sequence n -> FinSuppSeq n -> n)
-> LinearFunction
     n (Sequence n) (LinearFunction n (FinSuppSeq n) n)
(Sequence n -> FinSuppSeq n -> n)
-> Bilinear (Sequence n) (FinSuppSeq n) n
forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction ((Sequence n -> FinSuppSeq n -> n)
 -> LinearFunction
      n (Sequence n) (LinearFunction n (FinSuppSeq n) n))
-> (Sequence n -> FinSuppSeq n -> n)
-> LinearFunction
     n (Sequence n) (LinearFunction n (FinSuppSeq n) n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> Sequence 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
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)
(LinearMap n (FinSuppSeq n) w -> FinSuppSeq n -> w)
-> Bilinear (LinearMap n (FinSuppSeq n) w) (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 b a. (b -> a -> b) -> b -> [a] -> b
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
Scalar w -> 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 :: forall u.
(LinearSpace u, Scalar u ~ Scalar (FinSuppSeq n)) =>
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)
(LinearMap n (FinSuppSeq n) (DualVector u)
 -> Tensor n (FinSuppSeq n) u -> n)
-> Bilinear
     (LinearMap n (FinSuppSeq n) (DualVector u))
     (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 a. Num a => [a] -> a
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
DualVector u -> u -> Scalar u
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 :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (FinSuppSeq n),
 Scalar w ~ Scalar (FinSuppSeq n)) =>
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)
(LinearMap n (Tensor n (FinSuppSeq n) u) w
 -> Tensor n (FinSuppSeq n) u -> w)
-> Bilinear
     (LinearMap n (Tensor n (FinSuppSeq n) u) w)
     (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
$ VSCCoercion
  n
  (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 b c.
(Object (VSCCoercion n) b, Object (VSCCoercion n) c, Object (->) b,
 Object (->) c) =>
VSCCoercion n b c -> b -> c
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 VSCCoercion
  n
  (LinearMap n (Tensor n (FinSuppSeq n) u) w)
  (LinearMap n (FinSuppSeq n) (LinearMap n u w))
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (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 (Scalar u) u w -> u -> w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (LinearFunction (Scalar u) u w -> u -> w)
-> (LinearMap (Scalar u) u w -> LinearFunction (Scalar u) u w)
-> LinearMap (Scalar u) u w
-> u
-> w
forall a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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 u)
  (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
  (Scalar u)
  (LinearMap (Scalar u) u w)
  (LinearFunction (Scalar u) u w)
Bilinear (LinearMap (Scalar u) u w) u w
forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
forall w.
(TensorSpace w, Scalar w ~ Scalar u) =>
Bilinear (u +> w) u w
applyLinear) [LinearMap (Scalar u) u w]
TensorProduct (DualVector (FinSuppSeq n)) (LinearMap n u w)
m [u]
TensorProduct (FinSuppSeq n) u
t
  useTupleLinearSpaceComponents :: forall x y φ.
(FinSuppSeq n ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = φ
forall a. a
usingNonTupleTypeAsTupleError
  coerceDoubleDual :: VSCCoercion
  (Scalar (FinSuppSeq n))
  (FinSuppSeq n)
  (DualVector (DualVector (FinSuppSeq n)))
coerceDoubleDual = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @n of
     ScalarSpaceWitness n
ScalarSpaceWitness -> VSCCoercion n (FinSuppSeq n) (FinSuppSeq n)
VSCCoercion
  (Scalar (FinSuppSeq n))
  (FinSuppSeq n)
  (DualVector (DualVector (FinSuppSeq n)))
forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
  


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
TensorProduct (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)]
Tensor s (Sequence s) v -> TensorProduct (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
TensorProduct (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)]
Tensor s (FinSuppSeq s) v -> TensorProduct (FinSuppSeq s) v
forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct



newtype SymmetricTensor s v
           = SymTensor { forall s v. 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
SymmetricTensor s v -> 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)
SymmetricTensor s v -> SymmetricTensor s v -> 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
SymmetricTensor s v -> 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
  .-~! :: HasCallStack =>
SymmetricTensor s v
-> SymmetricTensor s v -> Needle (SymmetricTensor s v)
(.-~!) = SymmetricTensor s v
-> SymmetricTensor s v -> Needle (SymmetricTensor s v)
SymmetricTensor s v -> SymmetricTensor s v -> 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 a. (Object (->) a, Object (->) (Maybe a)) => a -> Maybe a
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  s v . (Num' s, TensorSpace v, Scalar v ~ s)
            => DimensionAware (SymmetricTensor s v) where
  type StaticDimension (SymmetricTensor s v) 
          = Maybe.FmapTriangularNum (StaticDimension v)
  dimensionalityWitness :: DimensionalityWitness (SymmetricTensor s v)
dimensionalityWitness = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v of
     DimensionalityWitness v
IsFlexibleDimensional -> DimensionalityWitness (SymmetricTensor s v)
forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
     DimensionalityWitness v
IsStaticDimensional
        -> SNat (Div (n * (n + 1)) 2)
-> (KnownNat (Div (n * (n + 1)) 2) =>
    DimensionalityWitness (SymmetricTensor s v))
-> DimensionalityWitness (SymmetricTensor s v)
forall (n :: Nat) r. SNat n -> (KnownNat n => r) -> r
withKnownNat (Sing n -> Sing (Div (n * (n + 1)) 2)
forall (a :: Nat). Sing a -> Sing (TriangularNum a)
Maybe.triangularNumSing (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v))
              DimensionalityWitness (SymmetricTensor s v)
KnownNat (Div (n * (n + 1)) 2) =>
DimensionalityWitness (SymmetricTensor s v)
forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
instance  s v n m . ( Num' s, n`Dimensional`v, TensorSpace v, Scalar v ~ s
                     , m ~ Maybe.TriangularNum n )
                => m`Dimensional`(SymmetricTensor s v) where
  knownDimensionalitySing :: Sing m
knownDimensionalitySing = SNat n -> SNat m
Sing n -> Sing (TriangularNum n)
forall (a :: Nat). Sing a -> Sing (TriangularNum a)
Maybe.triangularNumSing (SNat n -> SNat m) -> SNat n -> SNat m
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v
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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
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 Tensor s v (Tensor s v w)
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 s v s) -> Tensor s (SymmetricTensor s v) s
TensorProduct (SymmetricTensor s v) s
-> Tensor s (SymmetricTensor s v) s
forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor s v (Tensor s v s) -> Tensor s (SymmetricTensor s v) s)
-> Tensor s v (Tensor s v s) -> Tensor s (SymmetricTensor s v) s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction s v (Tensor s v s)
-> LinearFunction s (Tensor s v v) (Tensor s v (Tensor s v s))
forall a b.
(Object (LinearFunction s) a,
 Object (LinearFunction s) (Tensor s v a),
 Object (LinearFunction s) b,
 Object (LinearFunction s) (Tensor s v b)) =>
LinearFunction s a b
-> LinearFunction s (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 LinearFunction s v (Tensor s v s)
v -+> (v ⊗ Scalar v)
forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor LinearFunction s (Tensor s v v) (Tensor s v (Tensor s v s))
-> Tensor s v v -> Tensor s v (Tensor s v s)
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 s (Tensor s v s) v
-> LinearFunction s (Tensor s v (Tensor s v s)) (Tensor s v v)
forall a b.
(Object (LinearFunction s) a,
 Object (LinearFunction s) (Tensor s v a),
 Object (LinearFunction s) b,
 Object (LinearFunction s) (Tensor s v b)) =>
LinearFunction s a b
-> LinearFunction s (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 LinearFunction s (Tensor s v s) v
(v ⊗ Scalar v) -+> v
forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor LinearFunction s (Tensor s v (Tensor s v s)) (Tensor s v v)
-> Tensor s v (Tensor s v s) -> 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 s v s)
TensorProduct (SymmetricTensor s v) s
t
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(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
TensorProduct (SymmetricTensor 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 :: forall w.
(TensorSpace (SymmetricTensor s v), TensorSpace w,
 Scalar w ~ Scalar (SymmetricTensor s v)) =>
(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
TensorProduct (SymmetricTensor 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(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
TensorProduct (SymmetricTensor 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
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
TensorProduct (SymmetricTensor 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 :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
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))
(SymmetricTensor s v -> w -> Tensor s (SymmetricTensor s v) w)
-> Bilinear
     (SymmetricTensor s v) 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 s v w) -> Tensor s (SymmetricTensor s v) w
TensorProduct (SymmetricTensor 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
$ LinearFunction s v (Tensor s v w)
-> LinearFunction s (Tensor s v v) (Tensor s v (Tensor s v w))
forall a b.
(Object (LinearFunction s) a,
 Object (LinearFunction s) (Tensor s v a),
 Object (LinearFunction s) b,
 Object (LinearFunction s) (Tensor s v b)) =>
LinearFunction s a b
-> LinearFunction s (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 ((v -> Tensor s v w) -> LinearFunction s v (Tensor s v w)
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (v -> w -> 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 s v w))
-> Tensor s v v -> 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 v v
t
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w) -+> (w ⊗ SymmetricTensor s v)
transposeTensor = (Tensor s (SymmetricTensor s v) w
 -> Tensor s w (SymmetricTensor s v))
-> LinearFunction
     s
     (Tensor s (SymmetricTensor s v) w)
     (Tensor s w (SymmetricTensor s v))
forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction ((Tensor s (SymmetricTensor s v) w
  -> Tensor s w (SymmetricTensor s v))
 -> LinearFunction
      s
      (Tensor s (SymmetricTensor s v) w)
      (Tensor s w (SymmetricTensor s v)))
-> (Tensor s (SymmetricTensor s v) w
    -> Tensor s w (SymmetricTensor s v))
-> LinearFunction
     s
     (Tensor s (SymmetricTensor s v) w)
     (Tensor s 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
  (Scalar (Tensor (Scalar w) v v))
  (Tensor
     (Scalar (Tensor (Scalar w) v v))
     v
     (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
  (Tensor s w (SymmetricTensor s v))
-> Tensor
     (Scalar (Tensor (Scalar w) v v))
     v
     (Tensor (Scalar (Tensor (Scalar w) v v)) v w)
-> Tensor s w (SymmetricTensor s v)
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (
                            LinearFunction
  (Scalar (Tensor (Scalar w) v v))
  (Tensor (Scalar w) w (Tensor (Scalar w) v v))
  (Tensor s w (SymmetricTensor s v))
forall a. HasCallStack => a
undefined -- arr (fmap VSCCoercion)
                            LinearFunction
  (Scalar (Tensor (Scalar w) v v))
  (Tensor (Scalar w) w (Tensor (Scalar w) v v))
  (Tensor s w (SymmetricTensor s v))
-> LinearFunction
     (Scalar (Tensor (Scalar w) v v))
     (Tensor
        (Scalar (Tensor (Scalar w) v v))
        v
        (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
     (Tensor (Scalar w) w (Tensor (Scalar w) v v))
-> LinearFunction
     (Scalar (Tensor (Scalar w) v v))
     (Tensor
        (Scalar (Tensor (Scalar w) v v))
        v
        (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
     (Tensor s w (SymmetricTensor s v))
forall a b c.
(Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) a,
 Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) b,
 Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) c) =>
LinearFunction (Scalar (Tensor (Scalar w) v v)) b c
-> LinearFunction (Scalar (Tensor (Scalar w) v v)) a b
-> LinearFunction (Scalar (Tensor (Scalar w) v v)) a c
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 (Tensor (Scalar w) v v))
  (Tensor
     (Scalar (Tensor (Scalar w) v v))
     (Tensor (Scalar (Tensor (Scalar w) v v)) v v)
     w)
  (Tensor (Scalar w) w (Tensor (Scalar w) v v))
(Tensor (Scalar w) v v ⊗ w)
-+> Tensor (Scalar w) w (Tensor (Scalar w) v v)
forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor (Scalar w) v v)) =>
(Tensor (Scalar w) v v ⊗ w) -+> (w ⊗ Tensor (Scalar w) v v)
forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor LinearFunction
  (Scalar (Tensor (Scalar w) v v))
  (Tensor
     (Scalar (Tensor (Scalar w) v v))
     (Tensor (Scalar (Tensor (Scalar w) v v)) v v)
     w)
  (Tensor (Scalar w) w (Tensor (Scalar w) v v))
-> LinearFunction
     (Scalar (Tensor (Scalar w) v v))
     (Tensor
        (Scalar (Tensor (Scalar w) v v))
        v
        (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
     (Tensor
        (Scalar (Tensor (Scalar w) v v))
        (Tensor (Scalar (Tensor (Scalar w) v v)) v v)
        w)
-> LinearFunction
     (Scalar (Tensor (Scalar w) v v))
     (Tensor
        (Scalar (Tensor (Scalar w) v v))
        v
        (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
     (Tensor (Scalar w) w (Tensor (Scalar w) v v))
forall a b c.
(Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) a,
 Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) b,
 Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) c) =>
LinearFunction (Scalar (Tensor (Scalar w) v v)) b c
-> LinearFunction (Scalar (Tensor (Scalar w) v v)) a b
-> LinearFunction (Scalar (Tensor (Scalar w) v v)) a c
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
. VSCCoercion
  (Scalar (Tensor (Scalar w) v v))
  (Tensor
     (Scalar (Tensor (Scalar w) v v))
     v
     (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
  (Tensor
     (Scalar (Tensor (Scalar w) v v))
     (Tensor (Scalar (Tensor (Scalar w) v v)) v v)
     w)
-> LinearFunction
     (Scalar (Tensor (Scalar w) v v))
     (Tensor
        (Scalar (Tensor (Scalar w) v v))
        v
        (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
     (Tensor
        (Scalar (Tensor (Scalar w) v v))
        (Tensor (Scalar (Tensor (Scalar w) v v)) v v)
        w)
forall b c.
(Object (VSCCoercion (Scalar (Tensor (Scalar w) v v))) b,
 Object (VSCCoercion (Scalar (Tensor (Scalar w) v v))) c,
 Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) b,
 Object (LinearFunction (Scalar (Tensor (Scalar w) v v))) c) =>
VSCCoercion (Scalar (Tensor (Scalar w) v v)) b c
-> LinearFunction (Scalar (Tensor (Scalar w) v v)) b c
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 VSCCoercion
  (Scalar (Tensor (Scalar w) v v))
  (Tensor
     (Scalar (Tensor (Scalar w) v v))
     v
     (Tensor (Scalar (Tensor (Scalar w) v v)) v w))
  (Tensor
     (Scalar (Tensor (Scalar w) v v))
     (Tensor (Scalar (Tensor (Scalar w) v v)) v v)
     w)
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
lassocTensor) Tensor
  (Scalar (Tensor (Scalar w) v v))
  v
  (Tensor (Scalar (Tensor (Scalar w) v v)) v w)
TensorProduct (SymmetricTensor s v) w
f
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x,
 Scalar w ~ Scalar (SymmetricTensor s v),
 Scalar x ~ Scalar (SymmetricTensor s v)) =>
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
     s
     (LinearFunction s w x)
     (LinearFunction
        s
        (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)
-> Bilinear
     (LinearFunction s w 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
      s
      (LinearFunction s w x)
      (LinearFunction
         s
         (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
     s
     (LinearFunction s w x)
     (LinearFunction
        s
        (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
TensorProduct (SymmetricTensor 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 a b.
(Object (LinearFunction s) a,
 Object (LinearFunction s) (Tensor s v a),
 Object (LinearFunction s) b,
 Object (LinearFunction s) (Tensor s v b)) =>
LinearFunction s a b
-> LinearFunction s (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 (LinearFunction s w x
-> LinearFunction s (Tensor s v w) (Tensor s v x)
forall a b.
(Object (LinearFunction s) a,
 Object (LinearFunction s) (Tensor s v a),
 Object (LinearFunction s) b,
 Object (LinearFunction s) (Tensor s v b)) =>
LinearFunction s a b
-> LinearFunction s (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 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 :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (SymmetricTensor s v),
 Scalar w ~ Scalar (SymmetricTensor s v),
 Scalar x ~ Scalar (SymmetricTensor s v)) =>
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
     s
     (LinearFunction s (w, x) u)
     (LinearFunction
        s
        (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)
-> Bilinear
     (LinearFunction s (w, x) 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
      s
      (LinearFunction s (w, x) u)
      (LinearFunction
         s
         (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
     s
     (LinearFunction s (w, x) u)
     (LinearFunction
        s
        (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
TensorProduct (SymmetricTensor 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 a b c.
(ObjectPair (LinearFunction s) a b, Object (LinearFunction s) c,
 ObjectPair (LinearFunction s) (Tensor s v a) (Tensor s v b),
 Object (LinearFunction s) (Tensor s v c)) =>
LinearFunction s (a, b) c
-> LinearFunction s (Tensor s v a, Tensor s v b) (Tensor s v c)
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 a b c.
(ObjectPair (LinearFunction s) a b, Object (LinearFunction s) c,
 ObjectPair (LinearFunction s) (Tensor s v a) (Tensor s v b),
 Object (LinearFunction s) (Tensor s v c)) =>
LinearFunction s (a, b) c
-> LinearFunction s (Tensor s v a, Tensor s v b) (Tensor s v c)
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 :: forall (p :: * -> *) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (SymmetricTensor s v),
 TensorSpace b, Scalar b ~ Scalar (SymmetricTensor s v)) =>
p (SymmetricTensor s v)
-> VSCCoercion (Scalar (SymmetricTensor s v)) a b
-> Coercion
     (TensorProduct (SymmetricTensor s v) a)
     (TensorProduct (SymmetricTensor s v) b)
coerceFmapTensorProduct p (SymmetricTensor s v)
_ VSCCoercion (Scalar (SymmetricTensor s v)) a b
crc = Coercion (Tensor s v (Tensor s v a)) (Tensor s v (Tensor s v b))
Coercion
  (TensorProduct (SymmetricTensor s v) a)
  (TensorProduct (SymmetricTensor s v) b)
forall a. HasCallStack => a
undefined -- case fmap (fmap crc) :: VSCCoercion of
      -- VSCCoercion -> Coercion
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(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
TensorProduct (SymmetricTensor 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  s v . (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,
 StaticDimension (DualVector v) ~ StaticDimension 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 -> TensorProduct
  (DualVector (SymmetricTensor s 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))
TensorProduct
  (DualVector (SymmetricTensor s v)) (SymmetricTensor s v)
forall a. HasCallStack => a
undefined
                         -- LinearMap $ rassocTensor . asTensor
                         -- . fmap (unsafeFollowVSC SymTensor . asTensor) $ id
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w) +> (SymmetricTensor s v ⊗ w)
tensorId = TensorProduct
  (DualVector (Tensor s (SymmetricTensor s v) 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)))
TensorProduct
  (DualVector (Tensor s (SymmetricTensor s v) w))
  (Tensor s (SymmetricTensor s v) w)
forall a. HasCallStack => a
undefined
                   -- LinearMap $ asTensor . fmap asTensor . curryLinearMap
                   --  . fmap asTensor
                   --  . curryLinearMap
                   --  . fmap (unsafeFollowVSC $ \t -> Tensor $ rassocTensor $ t)
                   --  $ id
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
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)
(LinearMap s (SymmetricTensor s v) w -> SymmetricTensor s v -> w)
-> Bilinear
     (LinearMap s (SymmetricTensor s v) w) (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
  (Scalar (Tensor s v v))
  (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
  (LinearFunction s (Tensor s v v) w)
-> LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w
-> LinearFunction s (Tensor s v v) w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  (Scalar (Tensor s v v))
  (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
  (LinearFunction s (Tensor s v v) w)
Bilinear
  (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
  (Tensor s v v)
  w
forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s v v)) =>
Bilinear (Tensor s v v +> w) (Tensor s v v) w
applyLinear
                         (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w
 -> LinearFunction s (Tensor s v v) w)
-> LinearMap (Scalar (Tensor s v v)) (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
$ VSCCoercion
  (Scalar (Tensor s v v))
  (Tensor
     (Scalar (Tensor s v v))
     (LinearMap (Scalar (Tensor s v v)) v (DualVector v))
     w)
  (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
VSCCoercion
  (Scalar (Tensor s v v))
  (Tensor (Scalar (Tensor s v v)) (DualVector (Tensor s v v)) w)
  (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor VSCCoercion
  (Scalar (Tensor s v v))
  (Tensor
     (Scalar (Tensor s v v))
     (LinearMap (Scalar (Tensor s v v)) v (DualVector v))
     w)
  (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
-> VSCCoercion
     (Scalar (Tensor s v v))
     (Tensor
        (Scalar (Tensor s v v))
        (DualVector v)
        (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
     (Tensor
        (Scalar (Tensor s v v))
        (LinearMap (Scalar (Tensor s v v)) v (DualVector v))
        w)
-> VSCCoercion
     (Scalar (Tensor s v v))
     (Tensor
        (Scalar (Tensor s v v))
        (DualVector v)
        (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
     (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
forall a b c.
(Object (VSCCoercion (Scalar (Tensor s v v))) a,
 Object (VSCCoercion (Scalar (Tensor s v v))) b,
 Object (VSCCoercion (Scalar (Tensor s v v))) c) =>
VSCCoercion (Scalar (Tensor s v v)) b c
-> VSCCoercion (Scalar (Tensor s v v)) a b
-> VSCCoercion (Scalar (Tensor s v v)) a c
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
. VSCCoercion
  (Scalar (Tensor s v v))
  (LinearMap
     (Scalar (Tensor s v v))
     v
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
  (Tensor
     (Scalar (Tensor s v v))
     (LinearMap (Scalar (Tensor s v v)) v (DualVector v))
     w)
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
deferLinearMap VSCCoercion
  (Scalar (Tensor s v v))
  (LinearMap
     (Scalar (Tensor s v v))
     v
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
  (Tensor
     (Scalar (Tensor s v v))
     (LinearMap (Scalar (Tensor s v v)) v (DualVector v))
     w)
-> VSCCoercion
     (Scalar (Tensor s v v))
     (Tensor
        (Scalar (Tensor s v v))
        (DualVector v)
        (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
     (LinearMap
        (Scalar (Tensor s v v))
        v
        (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
-> VSCCoercion
     (Scalar (Tensor s v v))
     (Tensor
        (Scalar (Tensor s v v))
        (DualVector v)
        (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
     (Tensor
        (Scalar (Tensor s v v))
        (LinearMap (Scalar (Tensor s v v)) v (DualVector v))
        w)
forall a b c.
(Object (VSCCoercion (Scalar (Tensor s v v))) a,
 Object (VSCCoercion (Scalar (Tensor s v v))) b,
 Object (VSCCoercion (Scalar (Tensor s v v))) c) =>
VSCCoercion (Scalar (Tensor s v v)) b c
-> VSCCoercion (Scalar (Tensor s v v)) a b
-> VSCCoercion (Scalar (Tensor s v v)) a c
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
. VSCCoercion
  (Scalar (Tensor s v v))
  (Tensor
     (Scalar (Tensor s v v))
     (DualVector v)
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
  (LinearMap
     (Scalar (Tensor s v v))
     v
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
VSCCoercion
  (Scalar (Tensor s v v))
  (Tensor
     (Scalar (Tensor s v v))
     (DualVector v)
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
  (LinearMap
     (Scalar (Tensor s v v))
     (DualVector (DualVector v))
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap VSCCoercion
  (Scalar (Tensor s v v))
  (Tensor
     (Scalar (Tensor s v v))
     (DualVector v)
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w))
  (LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w)
-> Tensor
     (Scalar (Tensor s v v))
     (DualVector v)
     (Tensor (Scalar (Tensor s v v)) (DualVector v) w)
-> LinearMap (Scalar (Tensor s v v)) (Tensor s v v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor
  (Scalar (Tensor s v v))
  (DualVector v)
  (Tensor (Scalar (Tensor s v v)) (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 :: LinearSpace (SymmetricTensor s v) =>
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)
(SymmetricTensor s (DualVector v) -> SymmetricTensor s v -> s)
-> Bilinear
     (SymmetricTensor s (DualVector v)) (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
  (Scalar (DualVector (Tensor s v v)))
  (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
  (Scalar (DualVector (Tensor s v v)))
  (LinearMap s v (DualVector v))
  (LinearFunction s (Tensor s v v) s)
Bilinear
  (DualVector (Tensor s v v)) (Tensor s v v) (Scalar (Tensor s v v))
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
$ VSCCoercion
  s
  (Tensor s (DualVector v) (DualVector v))
  (LinearMap s v (DualVector v))
forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor VSCCoercion
  s
  (Tensor s (DualVector v) (DualVector v))
  (LinearMap s v (DualVector v))
-> Tensor s (DualVector v) (DualVector v)
-> LinearMap s v (DualVector v)
forall s a b. VSCCoercion s a b -> a -> b
-+$=> Tensor s (DualVector v) (DualVector v)
f) Tensor s v v
v
  applyTensorFunctional ::  u . (LinearSpace u, Scalar u ~ s)
       => LinearFunction s
               (LinearMap s (SymmetricTensor s v) (DualVector u))
               (LinearFunction s (Tensor s (SymmetricTensor s v) u) s)
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ s) =>
LinearFunction
  s
  (LinearMap s (SymmetricTensor s v) (DualVector u))
  (LinearFunction s (Tensor s (SymmetricTensor s v) u) s)
applyTensorFunctional = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u) of
    (DualSpaceWitness v
DualSpaceWitness, DualSpaceWitness u
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)
(LinearMap s (SymmetricTensor s v) (DualVector u)
 -> Tensor s (SymmetricTensor s v) u -> s)
-> Bilinear
     (LinearMap s (SymmetricTensor s v) (DualVector u))
     (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 (Scalar v) (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
  (Scalar v)
  (LinearMap (Scalar v) v (DualVector (Tensor s v u)))
  (LinearFunction (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) s)
-> LinearMap (Scalar v) v (DualVector (Tensor s v u))
-> LinearFunction (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) s
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  (Scalar v)
  (LinearMap (Scalar v) v (DualVector (Tensor s v u)))
  (LinearFunction (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) s)
Bilinear
  (DualVector (Tensor (Scalar v) v (Tensor s v u)))
  (Tensor (Scalar v) v (Tensor s v u))
  (Scalar v)
forall u.
(LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (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 (Scalar v) v (DualVector (Tensor s v u))
 -> LinearFunction
      (Scalar v) (Tensor (Scalar v) v (Tensor s v u)) s)
-> LinearMap (Scalar v) v (DualVector (Tensor s v u))
-> LinearFunction (Scalar v) (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
$ VSCCoercion
  (Scalar v)
  (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
  (LinearMap (Scalar v) v (DualVector (Tensor s v u)))
VSCCoercion
  (Scalar v)
  (Tensor (Scalar v) (DualVector v) (DualVector (Tensor s v u)))
  (LinearMap (Scalar v) v (DualVector (Tensor s v u)))
forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor VSCCoercion
  (Scalar v)
  (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
  (LinearMap (Scalar v) v (DualVector (Tensor s v u)))
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
     (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
     (LinearMap (Scalar v) v (DualVector (Tensor s v u)))
forall a b c.
(Object (VSCCoercion (Scalar v)) a,
 Object (VSCCoercion (Scalar v)) b,
 Object (VSCCoercion (Scalar v)) c) =>
VSCCoercion (Scalar v) b c
-> VSCCoercion (Scalar v) a b -> VSCCoercion (Scalar v) a c
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
. VSCCoercion
  s
  (Tensor s (DualVector v) (DualVector u))
  (LinearMap s v (DualVector u))
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
     (Tensor s (DualVector v) (LinearMap s v (DualVector u)))
forall a b.
(Object (VSCCoercion s) a,
 Object (VSCCoercion (Scalar v)) (Tensor s (DualVector v) a),
 Object (VSCCoercion s) b,
 Object (VSCCoercion (Scalar v)) (Tensor s (DualVector v) b)) =>
VSCCoercion s a b
-> VSCCoercion
     (Scalar v) (Tensor s (DualVector v) a) (Tensor s (DualVector 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 VSCCoercion
  s
  (Tensor s (DualVector v) (DualVector u))
  (LinearMap s v (DualVector u))
forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor VSCCoercion
  (Scalar v)
  (Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u)))
  (LinearMap (Scalar v) v (DualVector (Tensor s v u)))
-> Tensor s (DualVector v) (Tensor s (DualVector v) (DualVector u))
-> LinearMap (Scalar v) v (DualVector (Tensor s v u))
forall s a b. VSCCoercion s 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 ::  u w . ( LinearSpace u, Scalar u ~ s
                               , TensorSpace w, Scalar w ~ s )
       => LinearFunction s
               (LinearMap s (Tensor s (SymmetricTensor s v) u) w)
               (LinearFunction s (Tensor s (SymmetricTensor s v) u) w)
  applyTensorLinMap :: forall u w.
(LinearSpace u, Scalar u ~ s, TensorSpace w, Scalar w ~ s) =>
LinearFunction
  s
  (LinearMap s (Tensor s (SymmetricTensor s v) u) w)
  (LinearFunction s (Tensor s (SymmetricTensor s v) u) w)
applyTensorLinMap = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u) of
    (DualSpaceWitness v
DualSpaceWitness, DualSpaceWitness u
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)
(LinearMap s (Tensor s (SymmetricTensor s v) u) w
 -> Tensor s (SymmetricTensor s v) u -> w)
-> Bilinear
     (LinearMap s (Tensor s (SymmetricTensor s v) u) w)
     (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 TensorProduct
  (DualVector v)
  (Tensor s (DualVector v) (Tensor s (DualVector u) w))
f)) (Tensor TensorProduct (SymmetricTensor s v) u
t)
                   -> LinearFunction
  (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w
-> Tensor (Scalar v) v (Tensor (Scalar v) v u) -> w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (LinearFunction
  (Scalar v)
  (LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
  (LinearFunction
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
-> LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w
-> LinearFunction
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w
forall s v w. LinearFunction s v w -> v -> w
getLinearFunction LinearFunction
  (Scalar v)
  (LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
  (LinearFunction
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
Bilinear
  (Tensor (Scalar v) v (Tensor (Scalar v) v u) +> w)
  (Tensor (Scalar v) v (Tensor (Scalar v) 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
forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar v,
 Scalar w ~ Scalar v) =>
Bilinear ((v ⊗ u) +> w) (v ⊗ u) w
applyTensorLinMap
                             (LinearMap
   (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w
 -> LinearFunction
      (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
-> LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w
-> LinearFunction
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ VSCCoercion
  (Scalar v)
  (LinearMap
     (Scalar v) v (LinearMap (Scalar v) (Tensor (Scalar v) v u) w))
  (LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap
                                VSCCoercion
  (Scalar v)
  (LinearMap
     (Scalar v) v (LinearMap (Scalar v) (Tensor (Scalar v) v u) w))
  (LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
-> VSCCoercion
     (Scalar v)
     (LinearMap
        (Scalar v) v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
     (LinearMap
        (Scalar v) v (LinearMap (Scalar v) (Tensor (Scalar v) v u) w))
-> VSCCoercion
     (Scalar v)
     (LinearMap
        (Scalar v) v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
     (LinearMap
        (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
forall a b c.
(Object (VSCCoercion (Scalar v)) a,
 Object (VSCCoercion (Scalar v)) b,
 Object (VSCCoercion (Scalar v)) c) =>
VSCCoercion (Scalar v) b c
-> VSCCoercion (Scalar v) a b -> VSCCoercion (Scalar v) a c
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
. VSCCoercion
  (Scalar v)
  (Tensor s (DualVector v) (Tensor s (DualVector u) w))
  (LinearMap (Scalar v) (Tensor (Scalar v) v u) w)
-> VSCCoercion
     (Scalar v)
     (LinearMap
        (Scalar v) v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
     (LinearMap
        (Scalar v) v (LinearMap (Scalar v) (Tensor (Scalar v) v u) w))
forall a b.
(Object (VSCCoercion (Scalar v)) a,
 Object (VSCCoercion (Scalar v)) (LinearMap (Scalar v) v a),
 Object (VSCCoercion (Scalar v)) b,
 Object (VSCCoercion (Scalar v)) (LinearMap (Scalar v) v b)) =>
VSCCoercion (Scalar v) a b
-> VSCCoercion
     (Scalar v) (LinearMap (Scalar v) v a) (LinearMap (Scalar v) 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 (VSCCoercion
  (Scalar v)
  (LinearMap (Scalar v) v (LinearMap (Scalar v) u w))
  (LinearMap (Scalar v) (Tensor (Scalar v) v u) w)
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap VSCCoercion
  (Scalar v)
  (LinearMap (Scalar v) v (LinearMap (Scalar v) u w))
  (LinearMap (Scalar v) (Tensor (Scalar v) v u) w)
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (LinearMap (Scalar v) v (LinearMap (Scalar v) u w))
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (LinearMap (Scalar v) (Tensor (Scalar v) v u) w)
forall a b c.
(Object (VSCCoercion (Scalar v)) a,
 Object (VSCCoercion (Scalar v)) b,
 Object (VSCCoercion (Scalar v)) c) =>
VSCCoercion (Scalar v) b c
-> VSCCoercion (Scalar v) a b -> VSCCoercion (Scalar v) a c
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
. VSCCoercion
  (Scalar v)
  (Tensor s (DualVector v) (LinearMap s u w))
  (LinearMap (Scalar v) v (LinearMap (Scalar v) u w))
VSCCoercion
  (Scalar v)
  (Tensor (Scalar v) (DualVector v) (LinearMap (Scalar v) u w))
  (LinearMap (Scalar v) v (LinearMap (Scalar v) u w))
forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor VSCCoercion
  (Scalar v)
  (Tensor s (DualVector v) (LinearMap s u w))
  (LinearMap (Scalar v) v (LinearMap (Scalar v) u w))
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (Tensor s (DualVector v) (LinearMap s u w))
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (LinearMap (Scalar v) v (LinearMap (Scalar v) u w))
forall a b c.
(Object (VSCCoercion (Scalar v)) a,
 Object (VSCCoercion (Scalar v)) b,
 Object (VSCCoercion (Scalar v)) c) =>
VSCCoercion (Scalar v) b c
-> VSCCoercion (Scalar v) a b -> VSCCoercion (Scalar v) a c
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
. VSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
-> VSCCoercion
     (Scalar v)
     (Tensor s (DualVector v) (Tensor s (DualVector u) w))
     (Tensor s (DualVector v) (LinearMap s u w))
forall a b.
(Object (VSCCoercion s) a,
 Object (VSCCoercion (Scalar v)) (Tensor s (DualVector v) a),
 Object (VSCCoercion s) b,
 Object (VSCCoercion (Scalar v)) (Tensor s (DualVector v) b)) =>
VSCCoercion s a b
-> VSCCoercion
     (Scalar v) (Tensor s (DualVector v) a) (Tensor s (DualVector 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 VSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor)
                                       VSCCoercion
  (Scalar v)
  (LinearMap
     (Scalar v) v (Tensor s (DualVector v) (Tensor s (DualVector u) w)))
  (LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w)
-> LinearMap
     (Scalar v) v (Tensor s (DualVector v) (Tensor s (DualVector u) w))
-> LinearMap
     (Scalar v) (Tensor (Scalar v) v (Tensor (Scalar v) v u)) w
forall s a b. VSCCoercion s a b -> a -> b
-+$=> TensorProduct
  (DualVector v)
  (Tensor s (DualVector v) (Tensor s (DualVector u) w))
-> LinearMap
     (Scalar v) 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 (Scalar v) v u)
TensorProduct (SymmetricTensor s v) u
t  
  useTupleLinearSpaceComponents :: forall x y φ.
(SymmetricTensor s v ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = φ
forall a. a
usingNonTupleTypeAsTupleError
  coerceDoubleDual :: VSCCoercion
  (Scalar (SymmetricTensor s v))
  (SymmetricTensor s v)
  (DualVector (DualVector (SymmetricTensor s v)))
coerceDoubleDual = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v, forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @s) of
     (DualSpaceWitness v
DualSpaceWitness, ScalarSpaceWitness s
ScalarSpaceWitness) -> VSCCoercion s (SymmetricTensor s v) (SymmetricTensor s v)
VSCCoercion
  (Scalar (SymmetricTensor s v))
  (SymmetricTensor s v)
  (DualVector (DualVector (SymmetricTensor s v)))
forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion




squareV :: (Num' s, s ~ Scalar v)
          => TensorSpace v => v -> SymmetricTensor s v
squareV :: forall s v.
(Num' s, s ~ Scalar v, TensorSpace v) =>
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 :: forall s v.
(Num' s, s ~ Scalar v, TensorSpace v) =>
[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 w. (TensorSpace w, Scalar w ~ Scalar v) => [(v, w)] -> v ⊗ w
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 :: forall v w. LinearSpace v => (v ⊗〃+> w) -+> (v +> (v +> w))
currySymBilin = LinearFunction
  (Scalar v)
  (LinearMap (Scalar v) (SymmetricTensor (Scalar v) v) w)
  (LinearMap (Scalar v) v (LinearMap (Scalar v) v w))
LinearFunction
  (Scalar (LinearMap (Scalar v) v (LinearMap (Scalar v) v w)))
  (LinearMap (Scalar v) (SymmetricTensor (Scalar v) v) w)
  (LinearMap (Scalar v) v (LinearMap (Scalar v) v w))
forall a. HasCallStack => a
undefined -- LinearFunction . arr $ fmap fromTensor . fromTensor . VSCCoercion





newtype LinearApplicativeSpace f y
    = LinearApplicativeSpace { forall (f :: * -> *) y. 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
LinearApplicativeSpace f y
-> 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)
LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> 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 a b.
(Object (LinearFunction (Scalar y)) a,
 Object (LinearFunction (Scalar y)) (f a),
 Object (LinearFunction (Scalar y)) b,
 Object (LinearFunction (Scalar y)) (f b)) =>
LinearFunction (Scalar y) a b
-> LinearFunction (Scalar y) (f a) (f 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 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 a b c.
(Object (LinearFunction (Scalar y)) a,
 Object (LinearFunction (Scalar y)) b,
 Object (LinearFunction (Scalar y)) c) =>
LinearFunction (Scalar y) b c
-> LinearFunction (Scalar y) a b -> LinearFunction (Scalar y) a c
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)
  (UnitObject (LinearFunction (Scalar y)))
  (f (UnitObject (LinearFunction (Scalar y))))
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 a b c.
(ObjectPair (LinearFunction (Scalar y)) a b,
 Object (LinearFunction (Scalar y)) c,
 ObjectPair (LinearFunction (Scalar y)) (f a) (f b),
 Object (LinearFunction (Scalar y)) (f c)) =>
LinearFunction (Scalar y) (a, b) c
-> LinearFunction (Scalar y) (f a, f b) (f c)
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 a b c.
(ObjectPair (->) a b, ObjectMorphism (->) b c) =>
(a -> b -> c) -> (a, b) -> c
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 a b c.
(ObjectPair (LinearFunction (Scalar y)) a b,
 Object (LinearFunction (Scalar y)) c,
 ObjectPair (LinearFunction (Scalar y)) (f a) (f b),
 Object (LinearFunction (Scalar y)) (f c)) =>
LinearFunction (Scalar y) (a, b) c
-> LinearFunction (Scalar y) (f a, f b) (f c)
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 a b c.
(ObjectPair (->) a b, ObjectMorphism (->) b c) =>
(a -> b -> c) -> (a, b) -> c
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 a b.
(Object (LinearFunction (Scalar y)) a,
 Object (LinearFunction (Scalar y)) (f a),
 Object (LinearFunction (Scalar y)) b,
 Object (LinearFunction (Scalar y)) (f b)) =>
LinearFunction (Scalar y) a b
-> LinearFunction (Scalar y) (f a) (f 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 (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 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
LinearApplicativeSpace f y
-> 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
  .-~! :: HasCallStack =>
LinearApplicativeSpace f y
-> LinearApplicativeSpace f y
-> Needle (LinearApplicativeSpace f y)
(.-~!) = LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> Diff (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 a. (Object (->) a, Object (->) (Maybe a)) => a -> Maybe a
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 ( TensorSpace u, TensorSpace v, TensorSpace w
         , Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
         , InnerSpace (Tensor s u w), InnerSpace (Tensor s v w) )
              => InnerSpace (Tensor s (u,v) w) where
  Tensor (Tensor s u w
uw,Tensor s v w
vw) <.> :: Tensor s (u, v) w
-> Tensor s (u, v) w -> Scalar (Tensor s (u, v) w)
<.> Tensor (Tensor s u w
uw',Tensor s v w
vw') = Tensor s u w
uwTensor s u w -> Tensor s u w -> Scalar (Tensor s u w)
forall v. InnerSpace v => v -> v -> Scalar v
<.>Tensor s u w
uw' s -> s -> s
forall a. Num a => a -> a -> a
+ Tensor s v w
vwTensor s v w -> Tensor s v w -> Scalar (Tensor s v w)
forall v. InnerSpace v => v -> v -> Scalar v
<.>Tensor s v w
vw'
instance ( LinearSpace u, LinearSpace v, TensorSpace w
         , Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
         , InnerSpace (LinearMap s u w), InnerSpace (LinearMap s v w) )
              => InnerSpace (LinearMap s (u,v) w) where
  <.> :: LinearMap s (u, v) w
-> LinearMap s (u, v) w -> Scalar (LinearMap s (u, v) w)
(<.>) = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
    (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
      -> \(LinearMap (Tensor s (DualVector u) w
uw,Tensor s (DualVector v) w
vw)) (LinearMap (Tensor s (DualVector u) w
uw',Tensor s (DualVector v) w
vw'))
            -> (VSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
VSCCoercion
  s
  (Tensor s (DualVector u) w)
  (LinearMap s (DualVector (DualVector u)) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapVSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
-> Tensor s (DualVector u) w -> LinearMap s u w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector u) w
uw)LinearMap s u w -> LinearMap s u w -> Scalar (LinearMap s u w)
forall v. InnerSpace v => v -> v -> Scalar v
<.>(VSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
VSCCoercion
  s
  (Tensor s (DualVector u) w)
  (LinearMap s (DualVector (DualVector u)) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapVSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
-> Tensor s (DualVector u) w -> LinearMap s u w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector u) w
uw')
                 s -> s -> s
forall a. Num a => a -> a -> a
+ (VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
VSCCoercion
  s
  (Tensor s (DualVector v) w)
  (LinearMap s (DualVector (DualVector v)) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapVSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
-> Tensor s (DualVector v) w -> LinearMap s v w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector v) w
vw)LinearMap s v w -> LinearMap s v w -> Scalar (LinearMap s v w)
forall v. InnerSpace v => v -> v -> Scalar v
<.>(VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
VSCCoercion
  s
  (Tensor s (DualVector v) w)
  (LinearMap s (DualVector (DualVector v)) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapVSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
-> Tensor s (DualVector v) w -> LinearMap s v w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector v) w
vw')

instance ( TensorSpace u, TensorSpace v, TensorSpace w
         , AdditiveGroup s, Num s
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
         , InnerSpace (Tensor s u (Tensor s v w)) )
              => InnerSpace (Tensor s (Tensor s u v) w) where
  Tensor s (Tensor s u v) w
s <.> :: Tensor s (Tensor s u v) w
-> Tensor s (Tensor s u v) w -> Scalar (Tensor s (Tensor s u v) w)
<.> Tensor s (Tensor s u v) w
t = (VSCCoercion
  s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
rassocTensorVSCCoercion
  s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
-> Tensor s (Tensor s u v) w -> Tensor s u (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 u v) w
s)Tensor s u (Tensor s v w)
-> Tensor s u (Tensor s v w) -> Scalar (Tensor s u (Tensor s v w))
forall v. InnerSpace v => v -> v -> Scalar v
<.>(VSCCoercion
  s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
rassocTensorVSCCoercion
  s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
-> Tensor s (Tensor s u v) w -> Tensor s u (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 u v) w
t)
instance ( LinearSpace u, TensorSpace v, TensorSpace w
         , AdditiveGroup s, Num s
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
         , InnerSpace (LinearMap s u (Tensor s v w)) )
              => InnerSpace (Tensor s (LinearMap s u v) w) where
  Tensor s (LinearMap s u v) w
s <.> :: Tensor s (LinearMap s u v) w
-> Tensor s (LinearMap s u v) w
-> Scalar (Tensor s (LinearMap s u v) w)
<.> Tensor s (LinearMap s u v) w
t = (VSCCoercion
  s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
hasteLinearMapVSCCoercion
  s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
-> Tensor s (LinearMap s u v) w -> LinearMap s u (Tensor s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (LinearMap s u v) w
s)LinearMap s u (Tensor s v w)
-> LinearMap s u (Tensor s v w)
-> Scalar (LinearMap s u (Tensor s v w))
forall v. InnerSpace v => v -> v -> Scalar v
<.>(VSCCoercion
  s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
hasteLinearMapVSCCoercion
  s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
-> Tensor s (LinearMap s u v) w -> LinearMap s u (Tensor s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (LinearMap s u v) w
t)
instance ( LinearSpace u, LinearSpace v, TensorSpace w
         , AdditiveGroup s, Num s
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
         , InnerSpace (LinearMap s u (LinearMap s v w)) )
              => InnerSpace (LinearMap s (Tensor s u v) w) where
  LinearMap s (Tensor s u v) w
s <.> :: LinearMap s (Tensor s u v) w
-> LinearMap s (Tensor s u v) w
-> Scalar (LinearMap s (Tensor s u v) w)
<.> LinearMap s (Tensor s u v) w
t = (VSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMapVSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
-> LinearMap s (Tensor s u v) w -> LinearMap s u (LinearMap s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (Tensor s u v) w
s)LinearMap s u (LinearMap s v w)
-> LinearMap s u (LinearMap s v w)
-> Scalar (LinearMap s u (LinearMap s v w))
forall v. InnerSpace v => v -> v -> Scalar v
<.>(VSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMapVSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
-> LinearMap s (Tensor s u v) w -> LinearMap s u (LinearMap s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (Tensor s u v) w
t)
instance ( LinearSpace u, LinearSpace v, TensorSpace w
         , AdditiveGroup s, Num s
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
         , InnerSpace (Tensor s u (LinearMap s v w)) )
              => InnerSpace (LinearMap s (LinearMap s u v) w) where
  LinearMap s (LinearMap s u v) w
s <.> :: LinearMap s (LinearMap s u v) w
-> LinearMap s (LinearMap s u v) w
-> Scalar (LinearMap s (LinearMap s u v) w)
<.> LinearMap s (LinearMap s u v) w
t = (VSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
 TensorSpace w, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
coCurryLinearMapVSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
-> LinearMap s (LinearMap s u v) w -> Tensor s u (LinearMap s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (LinearMap s u v) w
s)Tensor s u (LinearMap s v w)
-> Tensor s u (LinearMap s v w)
-> Scalar (Tensor s u (LinearMap s v w))
forall v. InnerSpace v => v -> v -> Scalar v
<.>(VSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
 TensorSpace w, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
coCurryLinearMapVSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
-> LinearMap s (LinearMap s u v) w -> Tensor s u (LinearMap s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (LinearMap s u v) w
t)

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 a b c.
(Object (->) a, Object (->) b, Object (->) c) =>
(b -> c) -> (a -> b) -> a -> c
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
TensorProduct ℝ 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
TensorProduct ℝ 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
TensorProduct (DualVector ℝ) 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
TensorProduct (DualVector ℝ) 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)

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

instance ( LinearSpace u, LinearSpace v, TensorSpace w
         , QC.Arbitrary (LinearMap s u w), QC.Arbitrary (LinearMap s v w)
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
          => QC.Arbitrary (LinearMap s (u,v) w) where
  arbitrary :: Gen (LinearMap s (u, v) w)
arbitrary = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
   (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> (Tensor s (DualVector u) w, Tensor s (DualVector v) w)
-> LinearMap s (u, v) w
TensorProduct (DualVector (u, v)) w -> LinearMap s (u, v) w
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap ((Tensor s (DualVector u) w, Tensor s (DualVector v) w)
 -> LinearMap s (u, v) w)
-> Gen (Tensor s (DualVector u) w, Tensor s (DualVector v) w)
-> Gen (LinearMap s (u, v) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> do
     (,) (Tensor s (DualVector u) w
 -> Tensor s (DualVector v) w
 -> (Tensor s (DualVector u) w, Tensor s (DualVector v) w))
-> Gen (Tensor s (DualVector u) w)
-> Gen
     (Tensor s (DualVector v) w
      -> (Tensor s (DualVector u) w, Tensor s (DualVector v) w))
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> (VSCCoercion s (LinearMap s u w) (Tensor s (DualVector u) w)
-> LinearMap s u w -> Tensor s (DualVector u) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion s (LinearMap s u w) (Tensor s (DualVector u) w)
VSCCoercion
  s
  (LinearMap s (DualVector (DualVector u)) w)
  (Tensor s (DualVector u) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap (LinearMap s u w -> Tensor s (DualVector u) w)
-> Gen (LinearMap s u w) -> Gen (Tensor s (DualVector u) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen (LinearMap s u w)
forall a. Arbitrary a => Gen a
QC.arbitrary)
         Gen
  (Tensor s (DualVector v) w
   -> (Tensor s (DualVector u) w, Tensor s (DualVector v) w))
-> Gen (Tensor s (DualVector v) w)
-> Gen (Tensor s (DualVector u) w, Tensor s (DualVector v) w)
forall a b.
(ObjectMorphism (->) a b, ObjectMorphism (->) (Gen a) (Gen b),
 Object (->) (Gen a -> Gen b), ObjectPair (->) (a -> b) a,
 ObjectPair (->) (Gen (a -> b)) (Gen a), Object (->) a,
 Object (->) b) =>
Gen (a -> b) -> Gen a -> Gen b
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))
<*> (VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
-> LinearMap s v w -> Tensor s (DualVector v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
VSCCoercion
  s
  (LinearMap s (DualVector (DualVector v)) w)
  (Tensor s (DualVector v) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap (LinearMap s v w -> Tensor s (DualVector v) w)
-> Gen (LinearMap s v w) -> Gen (Tensor s (DualVector v) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen (LinearMap s v w)
forall a. Arbitrary a => Gen a
QC.arbitrary)
  shrink :: LinearMap s (u, v) w -> [LinearMap s (u, v) w]
shrink = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
   (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> \(LinearMap (Tensor s (DualVector u) w
x,Tensor s (DualVector v) w
y)) -> (Tensor s (DualVector u) w, Tensor s (DualVector v) w)
-> LinearMap s (u, v) w
TensorProduct (DualVector (u, v)) w -> LinearMap s (u, v) w
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap ((Tensor s (DualVector u) w, Tensor s (DualVector v) w)
 -> LinearMap s (u, v) w)
-> [(Tensor s (DualVector u) w, Tensor s (DualVector v) w)]
-> [LinearMap s (u, v) w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> do
     (LinearMap s u w
x',LinearMap s v w
y') <- (LinearMap s u w, LinearMap s v w)
-> [(LinearMap s u w, LinearMap s v w)]
forall a. Arbitrary a => a -> [a]
QC.shrink (VSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
VSCCoercion
  s
  (Tensor s (DualVector u) w)
  (LinearMap s (DualVector (DualVector u)) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap VSCCoercion s (Tensor s (DualVector u) w) (LinearMap s u w)
-> Tensor s (DualVector u) w -> LinearMap s u w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (DualVector u) w
x, VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
VSCCoercion
  s
  (Tensor s (DualVector v) w)
  (LinearMap s (DualVector (DualVector v)) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
-> Tensor s (DualVector v) w -> LinearMap s v w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (DualVector v) w
y)
     (Tensor s (DualVector u) w, Tensor s (DualVector v) w)
-> [(Tensor s (DualVector u) w, Tensor s (DualVector v) w)]
forall (m :: * -> *) a. Monad m (->) => a -> m a
return (VSCCoercion s (LinearMap s u w) (Tensor s (DualVector u) w)
VSCCoercion
  s
  (LinearMap s (DualVector (DualVector u)) w)
  (Tensor s (DualVector u) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap VSCCoercion s (LinearMap s u w) (Tensor s (DualVector u) w)
-> LinearMap s u w -> Tensor s (DualVector u) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s u w
x', VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
VSCCoercion
  s
  (LinearMap s (DualVector (DualVector v)) w)
  (Tensor s (DualVector v) w)
forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
-> LinearMap s v w -> Tensor s (DualVector v) w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s v w
y')

instance ( TensorSpace u, TensorSpace v, TensorSpace w
         , QC.Arbitrary (u(vw))
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
          => QC.Arbitrary (Tensor s (Tensor s u v) w) where
  arbitrary :: Gen (Tensor s (Tensor s u v) w)
arbitrary = VSCCoercion
  s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
-> Tensor s u (Tensor s v w) -> Tensor s (Tensor s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
lassocTensor (Tensor s u (Tensor s v w) -> Tensor s (Tensor s u v) w)
-> Gen (Tensor s u (Tensor s v w))
-> Gen (Tensor s (Tensor s u v) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen (Tensor s u (Tensor s v w))
forall a. Arbitrary a => Gen a
QC.arbitrary
  shrink :: Tensor s (Tensor s u v) w -> [Tensor s (Tensor s u v) w]
shrink (Tensor TensorProduct (Tensor s u v) w
t) = VSCCoercion
  s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
-> Tensor s u (Tensor s v w) -> Tensor s (Tensor s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
lassocTensor (Tensor s u (Tensor s v w) -> Tensor s (Tensor s u v) w)
-> [Tensor s u (Tensor s v w)] -> [Tensor s (Tensor s u 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 u (Tensor s v w) -> [Tensor s u (Tensor s v w)]
forall a. Arbitrary a => a -> [a]
QC.shrink (TensorProduct u (Tensor s v w) -> Tensor s u (Tensor s v w)
forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct u (Tensor s v w)
TensorProduct (Tensor s u v) w
t)

instance ( LinearSpace u, LinearSpace v, TensorSpace w
         , QC.Arbitrary (u+>(v+>w))
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
          => QC.Arbitrary (LinearMap s (Tensor s u v) w) where
  arbitrary :: Gen (LinearMap s (Tensor s u v) w)
arbitrary = VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
-> LinearMap s u (LinearMap s v w) -> LinearMap s (Tensor s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap (LinearMap s u (LinearMap s v w) -> LinearMap s (Tensor s u v) w)
-> Gen (LinearMap s u (LinearMap s v w))
-> Gen (LinearMap s (Tensor s u v) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen (LinearMap s u (LinearMap s v w))
forall a. Arbitrary a => Gen a
QC.arbitrary
  shrink :: LinearMap s (Tensor s u v) w -> [LinearMap s (Tensor s u v) w]
shrink LinearMap s (Tensor s u v) w
f = VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
-> LinearMap s u (LinearMap s v w) -> LinearMap s (Tensor s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap (LinearMap s u (LinearMap s v w) -> LinearMap s (Tensor s u v) w)
-> [LinearMap s u (LinearMap s v w)]
-> [LinearMap s (Tensor s u v) w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> LinearMap s u (LinearMap s v w)
-> [LinearMap s u (LinearMap s v w)]
forall a. Arbitrary a => a -> [a]
QC.shrink (VSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap VSCCoercion
  s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
-> LinearMap s (Tensor s u v) w -> LinearMap s u (LinearMap s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (Tensor s u v) w
f)

instance ( LinearSpace u, TensorSpace v, TensorSpace w
         , QC.Arbitrary (u+>(vw))
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
          => QC.Arbitrary (Tensor s (LinearMap s u v) w) where
  arbitrary :: Gen (Tensor s (LinearMap s u v) w)
arbitrary = VSCCoercion
  s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
-> LinearMap s u (Tensor s v w) -> Tensor s (LinearMap s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
deferLinearMap (LinearMap s u (Tensor s v w) -> Tensor s (LinearMap s u v) w)
-> Gen (LinearMap s u (Tensor s v w))
-> Gen (Tensor s (LinearMap s u v) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen (LinearMap s u (Tensor s v w))
forall a. Arbitrary a => Gen a
QC.arbitrary
  shrink :: Tensor s (LinearMap s u v) w -> [Tensor s (LinearMap s u v) w]
shrink (Tensor TensorProduct (LinearMap s u v) w
t) = VSCCoercion
  s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
-> LinearMap s u (Tensor s v w) -> Tensor s (LinearMap s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
  s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
deferLinearMap (LinearMap s u (Tensor s v w) -> Tensor s (LinearMap s u v) w)
-> [LinearMap s u (Tensor s v w)] -> [Tensor s (LinearMap s u v) w]
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> LinearMap s u (Tensor s v w) -> [LinearMap s u (Tensor s v w)]
forall a. Arbitrary a => a -> [a]
QC.shrink (TensorProduct (DualVector u) (Tensor s v w)
-> LinearMap s u (Tensor s v w)
forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (LinearMap s u v) w
TensorProduct (DualVector u) (Tensor s v w)
t)

instance ( LinearSpace u, LinearSpace v, TensorSpace w
         , QC.Arbitrary (u(v+>w))
         , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
          => QC.Arbitrary (LinearMap s (LinearMap s u v) w) where
  arbitrary :: Gen (LinearMap s (LinearMap s u v) w)
arbitrary = VSCCoercion
  s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
-> Tensor s u (LinearMap s v w) -> LinearMap s (LinearMap s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
 TensorSpace w, Scalar w ~ s) =>
VSCCoercion
  s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
coUncurryLinearMap (Tensor s u (LinearMap s v w) -> LinearMap s (LinearMap s u v) w)
-> Gen (Tensor s u (LinearMap s v w))
-> Gen (LinearMap s (LinearMap s u v) w)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Gen (Tensor s u (LinearMap s v w))
forall a. Arbitrary a => Gen a
QC.arbitrary
  shrink :: LinearMap s (LinearMap s u v) w
-> [LinearMap s (LinearMap s u v) w]
shrink LinearMap s (LinearMap s u v) w
f = VSCCoercion
  s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
-> Tensor s u (LinearMap s v w) -> LinearMap s (LinearMap s u v) w
forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
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 VSCCoercion
  s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
 TensorSpace w, Scalar w ~ s) =>
VSCCoercion
  s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
coUncurryLinearMap (Tensor s u (LinearMap s v w) -> LinearMap s (LinearMap s u v) w)
-> [Tensor s u (LinearMap s v w)]
-> [LinearMap s (LinearMap s u 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 u (LinearMap s v w) -> [Tensor s u (LinearMap s v w)]
forall a. Arbitrary a => a -> [a]
QC.shrink (VSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
 TensorSpace w, Scalar w ~ s) =>
VSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
coCurryLinearMap VSCCoercion
  s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
-> LinearMap s (LinearMap s u v) w -> Tensor s u (LinearMap s v w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (LinearMap s u v) w
f)