-- |
-- Module      : Math.LinearMap.Category.Class
-- Copyright   : (c) Justus Sagemüller 2016-2022
-- License     : GPL v3
-- 
-- Maintainer  : (@) jsag $ hvl.no
-- Stability   : experimental
-- Portability : portable
-- 
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE ConstraintKinds            #-}
{-# LANGUAGE UndecidableInstances       #-}
{-# LANGUAGE FunctionalDependencies     #-}
{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE NoStarIsType               #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE AllowAmbiguousTypes        #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE Rank2Types                 #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE InstanceSigs               #-}
{-# LANGUAGE PatternSynonyms            #-}
{-# LANGUAGE ViewPatterns               #-}
{-# LANGUAGE UnicodeSyntax              #-}
{-# LANGUAGE TupleSections              #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GADTs                      #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DefaultSignatures          #-}
{-# LANGUAGE CPP                        #-}

module Math.LinearMap.Category.Class where

import Data.VectorSpace
import Math.VectorSpace.DimensionAware
import Data.AffineSpace

import Prelude ()
import qualified Prelude as Hask

import Control.Category.Constrained.Prelude hiding (type (+))
import Control.Arrow.Constrained

import Data.Coerce
import Data.Type.Coercion
import Data.Tagged
import Data.Proxy(Proxy(..))

import qualified Data.Vector.Generic as GArr

import Math.Manifold.Core.PseudoAffine
import Math.LinearMap.Asserted
import Math.VectorSpace.ZeroDimensional
import Data.VectorSpace.Free

import Control.Monad.ST (ST)

import Data.Singletons (sing, withSingI)
#if MIN_VERSION_singletons(3,0,0)
import Prelude.Singletons (SNum(..))
import Data.Maybe.Singletons (SMaybe(..))
import GHC.TypeLits.Singletons (withKnownNat, SNat(..))
#else
import Data.Singletons.Prelude.Num (SNum(..))
import Data.Singletons.Prelude.Maybe (SMaybe(..))
import Data.Singletons.TypeLits (withKnownNat, SNat(..))
#endif
import Data.Kind (Type)
import GHC.TypeLits (Nat, type (+), type (*), KnownNat, natVal)
import qualified GHC.Generics as Gnrx
import GHC.Generics (Generic, (:*:)((:*:)))

import qualified Math.VectorSpace.DimensionAware.Theorems.MaybeNat as Maybe

data ClosedScalarWitness s where
  ClosedScalarWitness :: (Scalar s ~ s, DualVector s ~ s) => ClosedScalarWitness s
data TrivialTensorWitness s w where
  TrivialTensorWitness :: w ~ TensorProduct s w => TrivialTensorWitness s w

class (Num s, LinearSpace s, FreeVectorSpace s, 1`Dimensional`s)
          => Num' s where
  closedScalarWitness :: ClosedScalarWitness s
  default closedScalarWitness :: (Scalar s ~ s, DualVector s ~ s) => ClosedScalarWitness s
  closedScalarWitness = forall s. (Scalar s ~ s, DualVector s ~ s) => ClosedScalarWitness s
ClosedScalarWitness
  trivialTensorWitness :: TrivialTensorWitness s w
  default trivialTensorWitness :: (w ~ TensorProduct s w) => TrivialTensorWitness s w
  trivialTensorWitness = forall w s. (w ~ TensorProduct s w) => TrivialTensorWitness s w
TrivialTensorWitness

data ScalarSpaceWitness v where
  ScalarSpaceWitness :: (Num' (Scalar v), Scalar (Scalar v) ~ Scalar v)
                          => ScalarSpaceWitness v
data LinearManifoldWitness v where
  LinearManifoldWitness :: (Needle v ~ v, AffineSpace v, Diff v ~ v)
                         =>
#if !MIN_VERSION_manifolds_core(0,6,0)
                           BoundarylessWitness v ->
#endif
                           LinearManifoldWitness v

-- | A coercion that is compatible with the vector space structure of the types.
--   Intended to be used for lossless conversion between newtype wrappers around
--   vector spaces, under the requirement that they internally use the same basis
--   (if any). Note that this does not mean they also need to have the same inner
--   product / dual space.
data VSCCoercion s a b where
  VSCCoercion :: (Coercible a b, StaticDimension a ~ StaticDimension b)
     => VSCCoercion s a b

getVSCCoercion :: VSCCoercion s a b -> Coercion a b
getVSCCoercion :: forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion VSCCoercion s a b
VSCCoercion = forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion

symVSC :: VSCCoercion s a b -> VSCCoercion s b a
symVSC :: forall s a b. VSCCoercion s a b -> VSCCoercion s b a
symVSC VSCCoercion s a b
VSCCoercion = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

firstVSC :: VSCCoercion s a b -> VSCCoercion s (a,c) (b,c)
firstVSC :: forall s a b c. VSCCoercion s a b -> VSCCoercion s (a, c) (b, c)
firstVSC VSCCoercion s a b
VSCCoercion = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

secondVSC :: VSCCoercion s a b -> VSCCoercion s (c,a) (c,b)
secondVSC :: forall s a b c. VSCCoercion s a b -> VSCCoercion s (c, a) (c, b)
secondVSC VSCCoercion s a b
VSCCoercion = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

unsafeFollowVSC :: (Coercible a b, StaticDimension a ~ StaticDimension b)
      => c a b -> VSCCoercion s a b
unsafeFollowVSC :: forall a b (c :: Type -> Type -> Type) s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
c a b -> VSCCoercion s a b
unsafeFollowVSC c a b
_ = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

unsafeFloutVSC :: (Coercible a b, StaticDimension a ~ StaticDimension b)
      => c b a -> VSCCoercion s a b
unsafeFloutVSC :: forall a b (c :: Type -> Type -> Type) s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
c b a -> VSCCoercion s a b
unsafeFloutVSC c b a
_ = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

instance Category (VSCCoercion s) where
  type Object (VSCCoercion s) v = (TensorSpace v, Scalar v ~ s)
  id :: forall a. Object (VSCCoercion s) a => VSCCoercion s a a
id = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
  VSCCoercion s b c
VSCCoercion . :: forall a b c.
(Object (VSCCoercion s) a, Object (VSCCoercion s) b,
 Object (VSCCoercion s) c) =>
VSCCoercion s b c -> VSCCoercion s a b -> VSCCoercion s a c
. VSCCoercion s a b
VSCCoercion = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
instance EnhancedCat Coercion (VSCCoercion s) where
  arr :: forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c,
 Object Coercion b, Object Coercion c) =>
VSCCoercion s b c -> Coercion b c
arr = forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion
instance EnhancedCat (->) (VSCCoercion s) where
  arr :: forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c, Object (->) b,
 Object (->) c) =>
VSCCoercion s b c -> b -> c
arr VSCCoercion s b c
VSCCoercion b
x = coerce :: forall a b. Coercible a b => a -> b
coerce b
x

infixr 0 -+$=>
(-+$=>) :: VSCCoercion s a b -> a -> b
VSCCoercion s a b
VSCCoercion -+$=> :: forall s a b. VSCCoercion s a b -> a -> b
-+$=> a
x = coerce :: forall a b. Coercible a b => a -> b
coerce a
x

class (DimensionAware v, PseudoAffine v) => TensorSpace v where
  
  -- | The internal representation of a 'Tensor' product.
  -- 
  -- For Euclidean spaces, this is generally constructed by replacing each @s@
  -- scalar field in the @v@ vector with an entire @w@ vector. I.e., you have
  -- then a “nested vector” or, if @v@ is a @DualVector@ / “row vector”, a matrix.
  type TensorProduct v w :: Type
  
  scalarSpaceWitness :: ScalarSpaceWitness v
  linearManifoldWitness :: LinearManifoldWitness v
  zeroTensor :: (TensorSpace w, Scalar w ~ Scalar v)
                => v  w
  toFlatTensor :: v -+> (v  Scalar v)
  fromFlatTensor :: (v  Scalar v) -+> v
  addTensors :: (TensorSpace w, Scalar w ~ Scalar v)
                => (v  w) -> (v  w) -> v  w
  default addTensors :: AdditiveGroup (TensorProduct v w) => (v  w) -> (v  w) -> v  w
  addTensors (Tensor TensorProduct v w
vw₀) (Tensor TensorProduct v w
vw₁) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct v w
vw₀ forall v. AdditiveGroup v => v -> v -> v
^+^ TensorProduct v w
vw₁
  subtractTensors :: (TensorSpace v, TensorSpace w, Scalar w ~ Scalar v)
                => (v  w) -> (v  w) -> v  w
  default subtractTensors :: AdditiveGroup (TensorProduct v w) => (v  w) -> (v  w) -> v  w
  subtractTensors (Tensor TensorProduct v w
vw₀) (Tensor TensorProduct v w
vw₁) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct v w
vw₀ forall v. AdditiveGroup v => v -> v -> v
^-^ TensorProduct v w
vw₁
  scaleTensor :: (TensorSpace w, Scalar w ~ Scalar v)
                => Bilinear (Scalar v) (v  w) (v  w)
  default scaleTensor
      :: (VectorSpace (TensorProduct v w), Scalar (TensorProduct v w) ~ Scalar v)
           => Bilinear (Scalar v) (v  w) (v  w)
  scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar v
μ (Tensor TensorProduct v w
vw) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Scalar v
μforall v. VectorSpace v => Scalar v -> v -> v
*^TensorProduct v w
vw
  negateTensor :: (TensorSpace w, Scalar w ~ Scalar v)
                => (v  w) -+> (v  w)
  default negateTensor :: AdditiveGroup (TensorProduct v w) => (v  w) -+> (v  w)
  negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct v w
vw) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. AdditiveGroup v => v -> v
negateV TensorProduct v w
vw
  tensorProduct :: (TensorSpace w, Scalar w ~ Scalar v)
                => Bilinear v w (v  w)
  tensorProducts :: (TensorSpace w, Scalar w ~ Scalar v)
                => [(v,w)] -> (v  w)
  tensorProducts [(v, w)]
vws = forall (f :: Type -> Type) v.
(Foldable f, AdditiveGroup v) =>
f v -> v
sumV [ forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (
                              forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProduct v
v) w
w
                            | (v
v,w
w) <- [(v, w)]
vws ]
  transposeTensor :: (TensorSpace w, Scalar w ~ Scalar v)
                => (v  w) -+> (w  v)
  fmapTensor :: (TensorSpace w, TensorSpace x, Scalar w ~ Scalar v, Scalar x ~ Scalar v)
           => Bilinear (w -+> x) (vw) (vx)
  fzipTensorWith :: ( TensorSpace u, TensorSpace w, TensorSpace x
                    , Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v )
           => Bilinear ((w,x) -+> u) (vw, vx) (vu)
  tensorUnsafeFromArrayWithOffset ::  w α n m
          . ( n`Dimensional`v
            , TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar v
            , GArr.Vector α (Scalar v) )
           => Int -> α (Scalar v) -> (vw)
  tensorUnsafeWriteArrayWithOffset ::  w α σ n m
          . ( n`Dimensional`v
            , TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar v
            , GArr.Vector α (Scalar v) )
           => GArr.Mutable α σ (Scalar v) -> Int -> (vw) -> ST σ ()
  coerceFmapTensorProduct :: ( Hask.Functor p
                             , TensorSpace a, Scalar a ~ Scalar v
                             , TensorSpace b, Scalar b ~ Scalar v )
       => p v -> VSCCoercion (Scalar v) a b
              -> Coercion (TensorProduct v a) (TensorProduct v b)
  -- | “Sanity-check” a vector. This typically amounts to detecting any NaN components,
  --   which should trigger a @Nothing@ result. Otherwise, the result should be @Just@
  --   the input, but may also be optimised / memoised if applicable (i.e. for
  --   function spaces).
  wellDefinedVector :: v -> Maybe v
  default wellDefinedVector :: Eq v => v -> Maybe v
  wellDefinedVector v
v = if v
vforall a. Eq a => a -> a -> Bool
==v
v then forall a. a -> Maybe a
Just v
v else forall a. Maybe a
Nothing
  wellDefinedTensor :: (TensorSpace w, Scalar w ~ Scalar v) => vw -> Maybe (vw)

infixl 7 

-- | Infix version of 'tensorProduct'.
(⊗) ::  v w . (TensorSpace v, TensorSpace w, Scalar w ~ Scalar v, Num' (Scalar v))
                => v -> w -> v  w
v
v⊗ :: forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
 Num' (Scalar v)) =>
v -> w -> v ⊗ w
w
w = (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>v
v)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w

data DualSpaceWitness v where
  DualSpaceWitness :: ( 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
  
-- | The class of vector spaces @v@ for which @'LinearMap' s v w@ is well-implemented.
class (TensorSpace v, Num (Scalar v)) => LinearSpace v where
  -- | Suitable representation of a linear map from the space @v@ to its field.
  -- 
  --   For the usual euclidean spaces, you can just define @'DualVector' v = v@.
  --   (In this case, a dual vector will be just a “row vector” if you consider
  --   @v@-vectors as “column vectors”. 'LinearMap' will then effectively have
  --   a matrix layout.)
  type DualVector v :: Type
  
  dualSpaceWitness :: DualSpaceWitness v
 
  linearId :: v +> v
  
  idTensor :: v  DualVector v
  idTensor = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
               DualSpaceWitness v
DualSpaceWitness -> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensorforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. LinearSpace v => LinearMap (Scalar v) v v
linearId
  
  sampleLinearFunction :: (TensorSpace w, Scalar v ~ Scalar w)
                             => (v-+>w) -+> (v+>w)
  sampleLinearFunction = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v
                              , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
        (ScalarSpaceWitness v
ScalarSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction
                               forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \v -+> w
f -> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 -+> w
f) forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
  
  toLinearForm :: DualVector v -+> (v+>Scalar v)
  toLinearForm = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v
                      , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
    (ScalarSpaceWitness v
ScalarSpaceWitness,DualSpaceWitness v
DualSpaceWitness) -> forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor
  
  fromLinearForm :: (v+>Scalar v) -+> DualVector v
  fromLinearForm = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v
                        , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
    (ScalarSpaceWitness v
ScalarSpaceWitness,DualSpaceWitness v
DualSpaceWitness) -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
  
  -- | This will probably be removed in the future, since infinite-dimensional
  --   (e.g. Banach-) spaces may be not isomorphic to their double dual.
  coerceDoubleDual :: VSCCoercion (Scalar v) v (DualVector (DualVector v))
  coerceDoubleDual = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
  
  trace :: (v+>v) -+> Scalar v
  trace = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v of
      ScalarSpaceWitness v
ScalarSpaceWitness -> forall v w y. Bilinear v w y -> Bilinear w v y
flipBilin forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) (w -+> v) (Scalar v)
contractLinearMapAgainstforall s v w. LinearFunction s v w -> v -> w
-+$>forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
  
  contractTensorMap :: (TensorSpace w, Scalar w ~ Scalar v)
           => (v+>(vw)) -+> w
  contractTensorMap = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v of
           ScalarSpaceWitness v
ScalarSpaceWitness -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                                  forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v. LinearSpace v => LinearMap (Scalar v) v v -+> Scalar v
trace forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
  contractMapTensor :: (TensorSpace w, Scalar w ~ Scalar v)
           => (v(v+>w)) -+> w
  contractMapTensor = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v
                           , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
        (ScalarSpaceWitness v
ScalarSpaceWitness,DualSpaceWitness v
DualSpaceWitness)
              -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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)
coUncurryLinearMapforall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor)
                       forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. LinearSpace v => LinearMap (Scalar v) v v -+> Scalar v
trace)
                                forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
  contractTensorFn ::  w . (TensorSpace w, Scalar w ~ Scalar v)
           => (v-+>(vw)) -+> w
  contractTensorFn = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction
                                        forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v +> (v ⊗ w)) -+> w
contractTensorMap
  contractLinearMapAgainst :: (LinearSpace w, Scalar w ~ Scalar v)
           => Bilinear (v+>w) (w-+>v) (Scalar v)
  contractLinearMapAgainst = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v
                                  , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
      (ScalarSpaceWitness v
ScalarSpaceWitness,DualSpaceWitness v
DualSpaceWitness) -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                         forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVector forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction)
  
  applyDualVector :: LinearSpace v
                => Bilinear (DualVector v) v (Scalar v)
  
  applyLinear :: (TensorSpace w, Scalar w ~ Scalar v)
                => Bilinear (v+>w) v w
  composeLinear :: ( LinearSpace w, TensorSpace x
                   , Scalar w ~ Scalar v, Scalar x ~ Scalar v )
           => Bilinear (w+>x) (v+>w) (v+>x)
  composeLinear = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v of
            ScalarSpaceWitness v
ScalarSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap (Scalar v) w x
f -> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar v) w x
f)
  
  tensorId :: (LinearSpace w, Scalar w ~ Scalar v)
                 => (vw)+>(vw)
  
  applyTensorFunctional :: ( LinearSpace u, Scalar u ~ Scalar v )
               => Bilinear (DualVector (vu)) (vu) (Scalar v)
  
  applyTensorLinMap :: ( LinearSpace u, TensorSpace w
                       , Scalar u ~ Scalar v, Scalar w ~ Scalar v )
               => Bilinear ((vu)+>w) (vu) w 
  
  useTupleLinearSpaceComponents :: (v ~ (x,y))
         => ((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
  

fmapLinearMap ::  s v w x . ( LinearSpace v, TensorSpace w, TensorSpace x
                             , Scalar v ~ s, Scalar w ~ s, Scalar x ~ s )
                 => Bilinear (LinearFunction s w x) (v+>w) (v+>x)
fmapLinearMap :: forall s v w x.
(LinearSpace v, TensorSpace w, TensorSpace x, Scalar v ~ s,
 Scalar w ~ s, Scalar x ~ s) =>
Bilinear (LinearFunction s w x) (v +> w) (v +> x)
fmapLinearMap = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
   DualSpaceWitness v
DualSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
          forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s w x
f -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction s w x
f) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor


instance DimensionAware (ZeroDim s) where
  type StaticDimension (ZeroDim s) = 'Just 0
  dimensionalityWitness :: DimensionalityWitness (ZeroDim s)
dimensionalityWitness = forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
instance 0`Dimensional`ZeroDim s where
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (ZeroDim s)) =>
Int -> α (Scalar (ZeroDim s)) -> ZeroDim s
unsafeFromArrayWithOffset Int
_ α (Scalar (ZeroDim s))
_ = forall s. ZeroDim s
Origin
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (ZeroDim s)) =>
Mutable α σ (Scalar (ZeroDim s)) -> Int -> ZeroDim s -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (ZeroDim s))
_ Int
_ ZeroDim s
_ = forall (m :: Type -> Type) a. Monad m (->) => a -> m a
return ()

instance Num' s => TensorSpace (ZeroDim s) where
  type TensorProduct (ZeroDim s) v = ZeroDim s
  scalarSpaceWitness :: ScalarSpaceWitness (ZeroDim s)
scalarSpaceWitness = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
                ClosedScalarWitness s
ClosedScalarWitness -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (ZeroDim s)
linearManifoldWitness = forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
                                BoundarylessWitness
#endif
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
ZeroDim s ⊗ w
zeroTensor = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall s. ZeroDim s
Origin
  toFlatTensor :: ZeroDim s -+> (ZeroDim s ⊗ Scalar (ZeroDim s))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \ZeroDim s
Origin -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall s. ZeroDim s
Origin
  fromFlatTensor :: (ZeroDim s ⊗ Scalar (ZeroDim s)) -+> ZeroDim s
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor ZeroDim s
TensorProduct (ZeroDim s) s
Origin) -> forall s. ZeroDim s
Origin
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s ⊗ w) -+> (ZeroDim s ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
Bilinear (Scalar (ZeroDim s)) (ZeroDim s ⊗ w) (ZeroDim s ⊗ w)
scaleTensor = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s ⊗ w) -> (ZeroDim s ⊗ w) -> ZeroDim s ⊗ w
addTensors (Tensor ZeroDim s
TensorProduct (ZeroDim s) w
Origin) (Tensor ZeroDim s
TensorProduct (ZeroDim s) w
Origin) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall s. ZeroDim s
Origin
  subtractTensors :: forall w.
(TensorSpace (ZeroDim s), TensorSpace w,
 Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s ⊗ w) -> (ZeroDim s ⊗ w) -> ZeroDim s ⊗ w
subtractTensors (Tensor ZeroDim s
TensorProduct (ZeroDim s) w
Origin) (Tensor ZeroDim s
TensorProduct (ZeroDim s) w
Origin) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall s. ZeroDim s
Origin
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
Bilinear (ZeroDim s) w (ZeroDim s ⊗ w)
tensorProduct = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s ⊗ w) -+> (w ⊗ ZeroDim s)
transposeTensor = forall w s v. AdditiveGroup w => LinearFunction s v w
const0
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (ZeroDim s),
 Scalar x ~ Scalar (ZeroDim s)) =>
Bilinear (w -+> x) (ZeroDim s ⊗ w) (ZeroDim s ⊗ x)
fmapTensor = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (ZeroDim s), Scalar w ~ Scalar (ZeroDim s),
 Scalar x ~ Scalar (ZeroDim s)) =>
Bilinear
  ((w, x) -+> u) (ZeroDim s ⊗ w, ZeroDim s ⊗ x) (ZeroDim s ⊗ u)
fzipTensorWith = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  tensorUnsafeFromArrayWithOffset :: forall w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(Dimensional n (ZeroDim s), TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar (ZeroDim s), Vector α (Scalar (ZeroDim s))) =>
Int -> α (Scalar (ZeroDim s)) -> ZeroDim s ⊗ w
tensorUnsafeFromArrayWithOffset Int
_ α (Scalar (ZeroDim s))
_ = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall s. ZeroDim s
Origin
  tensorUnsafeWriteArrayWithOffset :: forall w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(Dimensional n (ZeroDim s), TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar (ZeroDim s), Vector α (Scalar (ZeroDim s))) =>
Mutable α σ (Scalar (ZeroDim s))
-> Int -> (ZeroDim s ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset Mutable α σ (Scalar (ZeroDim s))
_ Int
_ (Tensor ZeroDim s
TensorProduct (ZeroDim s) w
Origin) = forall (m :: Type -> Type) a. Monad m (->) => a -> m a
return ()
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (ZeroDim s),
 TensorSpace b, Scalar b ~ Scalar (ZeroDim s)) =>
p (ZeroDim s)
-> VSCCoercion (Scalar (ZeroDim s)) a b
-> Coercion
     (TensorProduct (ZeroDim s) a) (TensorProduct (ZeroDim s) b)
coerceFmapTensorProduct p (ZeroDim s)
_ VSCCoercion (Scalar (ZeroDim s)) a b
VSCCoercion = forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
  wellDefinedVector :: ZeroDim s -> Maybe (ZeroDim s)
wellDefinedVector ZeroDim s
Origin = forall a. a -> Maybe a
Just forall s. ZeroDim s
Origin
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s ⊗ w) -> Maybe (ZeroDim s ⊗ w)
wellDefinedTensor (Tensor ZeroDim s
TensorProduct (ZeroDim s) w
Origin) = forall a. a -> Maybe a
Just (forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall s. ZeroDim s
Origin)
instance Num' s => LinearSpace (ZeroDim s) where
  type DualVector (ZeroDim s) = ZeroDim s
  dualSpaceWitness :: DualSpaceWitness (ZeroDim s)
dualSpaceWitness = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
                ClosedScalarWitness s
ClosedScalarWitness -> 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 :: ZeroDim s +> ZeroDim s
linearId = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall s. ZeroDim s
Origin
  idTensor :: ZeroDim s ⊗ DualVector (ZeroDim s)
idTensor = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall s. ZeroDim s
Origin
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s ⊗ w) +> (ZeroDim s ⊗ w)
tensorId = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall s. ZeroDim s
Origin
  toLinearForm :: DualVector (ZeroDim s) -+> (ZeroDim s +> Scalar (ZeroDim s))
toLinearForm = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall s. ZeroDim s
Origin
  fromLinearForm :: (ZeroDim s +> Scalar (ZeroDim s)) -+> DualVector (ZeroDim s)
fromLinearForm = forall w s v. AdditiveGroup w => LinearFunction s v w
const0
  coerceDoubleDual :: VSCCoercion
  (Scalar (ZeroDim s))
  (ZeroDim s)
  (DualVector (DualVector (ZeroDim s)))
coerceDoubleDual = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
  contractTensorMap :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s +> (ZeroDim s ⊗ w)) -+> w
contractTensorMap = forall w s v. AdditiveGroup w => LinearFunction s v w
const0
  contractMapTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
(ZeroDim s ⊗ (ZeroDim s +> w)) -+> w
contractMapTensor = forall w s v. AdditiveGroup w => LinearFunction s v w
const0
  contractLinearMapAgainst :: forall w.
(LinearSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
Bilinear (ZeroDim s +> w) (w -+> ZeroDim s) (Scalar (ZeroDim s))
contractLinearMapAgainst = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  applyDualVector :: LinearSpace (ZeroDim s) =>
Bilinear (DualVector (ZeroDim s)) (ZeroDim s) (Scalar (ZeroDim s))
applyDualVector = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (ZeroDim s)) =>
Bilinear (ZeroDim s +> w) (ZeroDim s) w
applyLinear = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (ZeroDim s)) =>
Bilinear
  (DualVector (ZeroDim s ⊗ u)) (ZeroDim s ⊗ u) (Scalar (ZeroDim s))
applyTensorFunctional = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (ZeroDim s),
 Scalar w ~ Scalar (ZeroDim s)) =>
Bilinear ((ZeroDim s ⊗ u) +> w) (ZeroDim s ⊗ u) w
applyTensorLinMap = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  composeLinear :: forall w x.
(LinearSpace w, TensorSpace x, Scalar w ~ Scalar (ZeroDim s),
 Scalar x ~ Scalar (ZeroDim s)) =>
Bilinear (w +> x) (ZeroDim s +> w) (ZeroDim s +> x)
composeLinear = forall v a b. AdditiveGroup v => Bilinear a b v
biConst0
  useTupleLinearSpaceComponents :: forall x y φ.
(ZeroDim s ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = forall a. a
usingNonTupleTypeAsTupleError


-- | The tensor product between one space's dual space and another space is the
-- space spanned by vector–dual-vector pairs, in
-- <https://en.wikipedia.org/wiki/Bra%E2%80%93ket_notationa bra-ket notation>
-- written as
-- 
-- @
-- m = ∑ |w⟩⟨v|
-- @
-- 
-- Any linear mapping can be written as such a (possibly infinite) sum. The
-- 'TensorProduct' data structure only stores the linear independent parts
-- though; for simple finite-dimensional spaces this means e.g. @'LinearMap' ℝ ℝ³ ℝ³@
-- effectively boils down to an ordinary matrix type, namely an array of
-- column-vectors @|w⟩@.
-- 
-- (The @⟨v|@ dual-vectors are then simply assumed to come from the canonical basis.)
-- 
-- For bigger spaces, the tensor product may be implemented in a more efficient
-- sparse structure; this can be defined in the 'TensorSpace' instance.
newtype LinearMap s v w = LinearMap {forall s v w. LinearMap s v w -> TensorProduct (DualVector v) w
getLinearMap :: TensorProduct (DualVector v) w}

-- | Tensor products are most interesting because they can be used to implement
--   linear mappings, but they also form a useful vector space on their own right.
newtype Tensor s v w = Tensor {forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct :: TensorProduct v w}

asTensor ::  s v w . LinearSpace v
     => VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor :: forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v of
  DualSpaceWitness v
DualSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
fromTensor ::  s v w . LinearSpace v
     => VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor :: forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v of
  DualSpaceWitness v
DualSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

asLinearMap ::  s v w . (LinearSpace v, Scalar v ~ s)
           => VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap :: forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
                DualSpaceWitness v
DualSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
fromLinearMap ::  s v w . (LinearSpace v, Scalar v ~ s)
           => VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap :: forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
                DualSpaceWitness v
DualSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion


pseudoFmapTensorLHS :: ( TensorProduct v w ~ TensorProduct v' w
                       , StaticDimension v ~ StaticDimension v' )
           => c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS :: forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS c v v'
_ = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

pseudoPrecomposeLinmap
      :: ( TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w
         , StaticDimension v ~ StaticDimension v' )
           => c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap :: forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap c v' v
_ = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

envTensorLHSCoercion :: ( TensorProduct v w ~ TensorProduct v' w
                        , TensorProduct v w' ~ TensorProduct v' w' )
           => c v v' -> LinearFunction s' (Tensor s v w) (Tensor s v w')
                     -> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion :: forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion c v v'
i (LinearFunction Tensor s v w -> Tensor s v w'
f) = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce Tensor s v w -> Tensor s v w'
f

envLinmapPrecomposeCoercion
       :: ( TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w
          , TensorProduct (DualVector v) w' ~ TensorProduct (DualVector v') w' )
           => c v' v -> LinearFunction s' (LinearMap s v w) (LinearMap s v w')
                     -> LinearFunction s' (LinearMap s v' w) (LinearMap s v' w')
envLinmapPrecomposeCoercion :: forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 TensorProduct (DualVector v) w'
 ~ TensorProduct (DualVector v') w') =>
c v' v
-> LinearFunction s' (LinearMap s v w) (LinearMap s v w')
-> LinearFunction s' (LinearMap s v' w) (LinearMap s v' w')
envLinmapPrecomposeCoercion c v' v
i (LinearFunction LinearMap s v w -> LinearMap s v w'
f) = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce LinearMap s v w -> LinearMap s v w'
f

-- | Infix synonym for 'LinearMap', without explicit mention of the scalar type.
type v +> w = LinearMap (Scalar v) v w

-- | Infix synonym for 'Tensor', without explicit mention of the scalar type.
type v  w = Tensor (Scalar v) v w

-- | The workhorse of this package: most functions here work on vector
--   spaces that fulfill the @'LSpace' v@ constraint.
-- 
--   In summary, this is a 'VectorSpace' with an implementation for @'TensorProduct' v w@,
--   for any other space @w@, and with a 'DualVector' space. This fulfills
--   @'DualVector' ('DualVector' v) ~ v@ (this constraint is encapsulated in
--   'DualSpaceWitness').
-- 
--   To make a new space of yours an 'LSpace', you must define instances of
--   'TensorSpace' and 'LinearSpace'. In fact, 'LSpace' is equivalent to
--   'LinearSpace', but makes the condition explicit that the scalar and dual vectors
--   also form a linear space. 'LinearSpace' only stores that constraint in
--   'dualSpaceWitness' (to avoid UndecidableSuperclasses).
type LSpace v = ( LinearSpace v, Num' (Scalar v) )

instance (LinearSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => AdditiveGroup (LinearMap s v w) where
  zeroV :: LinearMap s v w
zeroV = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
            DualSpaceWitness v
DualSpaceWitness -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  LinearMap s v w
m^+^ :: LinearMap s v w -> LinearMap s v w -> LinearMap s v w
^+^LinearMap s v w
n = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
            DualSpaceWitness v
DualSpaceWitness -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s v w
m) forall v. AdditiveGroup v => v -> v -> v
^+^ (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s v w
n)
  LinearMap s v w
m^-^ :: LinearMap s v w -> LinearMap s v w -> LinearMap s v w
^-^LinearMap s v w
n = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
            DualSpaceWitness v
DualSpaceWitness -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s v w
m) forall v. AdditiveGroup v => v -> v -> v
^-^ (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s v w
n)
  negateV :: LinearMap s v w -> LinearMap s v w
negateV = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
            DualSpaceWitness v
DualSpaceWitness -> (forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$) forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v. AdditiveGroup v => v -> v
negateV forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$)
instance  v w s . (LinearSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => VectorSpace (LinearMap s v w) where
  type Scalar (LinearMap s v w) = s
  Scalar (LinearMap s v w)
μ*^ :: Scalar (LinearMap s v w) -> LinearMap s v w -> LinearMap s v w
*^LinearMap s v w
v = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v
              , forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness w ) of
            (DualSpaceWitness v
DualSpaceWitness, ScalarSpaceWitness w
ScalarSpaceWitness)
                -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar (LinearMap s v w)
μ) forall s v w. LinearFunction s v w -> v -> w
-+$> forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s v w
v
instance  v w s . (LinearSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => Semimanifold (LinearMap s v w) where
  type Needle (LinearMap s v w) = LinearMap s v w
#if !MIN_VERSION_manifolds_core(0,6,0)
  toInterior = pure
  fromInterior = id
  translateP = Tagged (^+^)
#endif
  .+~^ :: LinearMap s v w -> Needle (LinearMap s v w) -> LinearMap s v w
(.+~^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
instance  v w s . (LinearSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => PseudoAffine (LinearMap s v w) where
  LinearMap s v w
f.-~. :: LinearMap s v w
-> LinearMap s v w -> Maybe (Needle (LinearMap s v w))
.-~.LinearMap s v w
g = forall (m :: Type -> Type) a. Monad m (->) => a -> m a
return forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s v w
fforall v. AdditiveGroup v => v -> v -> v
^-^LinearMap s v w
g
  .-~! :: HasCallStack =>
LinearMap s v w -> LinearMap s v w -> Needle (LinearMap s v w)
(.-~!) = forall v. AdditiveGroup v => v -> v -> v
(^-^)

instance (TensorSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => AdditiveGroup (Tensor s v w) where
  zeroV :: Tensor s v w
zeroV = forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  ^+^ :: Tensor s v w -> Tensor s v w -> Tensor s v w
(^+^) = forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
addTensors
  ^-^ :: Tensor s v w -> Tensor s v w -> Tensor s v w
(^-^) = forall v w.
(TensorSpace v, TensorSpace v, TensorSpace w,
 Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
subtractTensors
  negateV :: Tensor s v w -> Tensor s v w
negateV = forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensor
instance (TensorSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => VectorSpace (Tensor s v w) where
  type Scalar (Tensor s v w) = s
  Scalar (Tensor s v w)
μ*^ :: Scalar (Tensor s v w) -> Tensor s v w -> Tensor s v w
*^Tensor s v w
t = (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar (Tensor s v w)
μ)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor s v w
t
instance (TensorSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => Semimanifold (Tensor s v w) where
  type Needle (Tensor s v w) = Tensor s v w
#if !MIN_VERSION_manifolds_core(0,6,0)
  toInterior = pure
  fromInterior = id
  translateP = Tagged (^+^)
#endif
  .+~^ :: Tensor s v w -> Needle (Tensor s v w) -> Tensor s v w
(.+~^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
instance (TensorSpace v, TensorSpace w, Scalar v~s, Scalar w~s)
               => PseudoAffine (Tensor s v w) where
  Tensor s v w
f.-~. :: Tensor s v w -> Tensor s v w -> Maybe (Needle (Tensor s v w))
.-~.Tensor s v w
g = forall (m :: Type -> Type) a. Monad m (->) => a -> m a
return forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v w
fforall v. AdditiveGroup v => v -> v -> v
^-^Tensor s v w
g
  .-~! :: HasCallStack =>
Tensor s v w -> Tensor s v w -> Needle (Tensor s v w)
(.-~!) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
  
infixr 6 , >+<, <⊕

(<⊕) :: (uw) -> (vw) -> (u,v)w
Tensor (Scalar u) u w
m <⊕ :: forall u w v. (u ⊗ w) -> (v ⊗ w) -> (u, v) ⊗ w
<⊕ Tensor (Scalar v) v w
n = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Tensor (Scalar u) u w
m, Tensor (Scalar v) v w
n)

-- | The dual operation to the tuple constructor, or rather to the
--   '&&&' fanout operation: evaluate two (linear) functions in parallel
--   and sum up the results.
--   The typical use is to concatenate “row vectors” in a matrix definition.
(⊕) :: (u+>w) -> (v+>w) -> (u,v)+>w
LinearMap TensorProduct (DualVector u) w
m ⊕ :: forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 LinearMap TensorProduct (DualVector v) w
n = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (DualVector u) w
m, forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (DualVector v) w
n)

-- | ASCII version of '⊕'
(>+<) :: (u+>w) -> (v+>w) -> (u,v)+>w
>+< :: forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
(>+<) = forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
(⊕)


instance Category (LinearMap s) where
  type Object (LinearMap s) v = (LinearSpace v, Scalar v ~ s)
  id :: forall a. Object (LinearMap s) a => LinearMap s a a
id = forall v. LinearSpace v => LinearMap (Scalar v) v v
linearId
  . :: forall a b c.
(Object (LinearMap s) a, Object (LinearMap s) b,
 Object (LinearMap s) c) =>
LinearMap s b c -> LinearMap s a b -> LinearMap s a c
(.) = forall v w x.
(LinearSpace v, Scalar v ~ s, LinearSpace w, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
DualSpaceWitness v
-> LinearMap s w x -> LinearMap s v w -> LinearMap s v x
lmc forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where lmc ::  v w x . ( LinearSpace v, Scalar v ~ s
                          , LinearSpace w, Scalar w ~ s
                          , TensorSpace x, Scalar x ~ s )
              => DualSpaceWitness v
                   -> LinearMap s w x -> LinearMap s v w -> LinearMap s v x
         lmc :: forall v w x.
(LinearSpace v, Scalar v ~ s, LinearSpace w, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
DualSpaceWitness v
-> LinearMap s w x -> LinearMap s v w -> LinearMap s v x
lmc DualSpaceWitness v
DualSpaceWitness = forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w x.
(LinearSpace v, LinearSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w +> x) (v +> w) (v +> x)
composeLinear
instance Num' s => Cartesian (LinearMap s) where
  type UnitObject (LinearMap s) = ZeroDim s
  swap :: forall a b.
(ObjectPair (LinearMap s) a b, ObjectPair (LinearMap s) b a) =>
LinearMap s (a, b) (b, a)
swap = (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall w s v. AdditiveGroup w => LinearFunction s v w
const0forall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id) forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
idforall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&forall w s v. AdditiveGroup w => LinearFunction s v w
const0) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id)
  attachUnit :: forall unit a.
(unit ~ UnitObject (LinearMap s),
 ObjectPair (LinearMap s) a unit) =>
LinearMap s a (a, unit)
attachUnit = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
idforall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&forall w s v. AdditiveGroup w => LinearFunction s v w
const0) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
  detachUnit :: forall unit a.
(unit ~ UnitObject (LinearMap s),
 ObjectPair (LinearMap s) a unit) =>
LinearMap s (a, unit) a
detachUnit = forall (a :: Type -> Type -> Type) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst
  regroup :: forall a b c.
(ObjectPair (LinearMap s) a b, ObjectPair (LinearMap s) b c,
 ObjectPair (LinearMap s) a (b, c),
 ObjectPair (LinearMap s) (a, b) c) =>
LinearMap s (a, (b, c)) ((a, b), c)
regroup = forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (k :: Type -> Type -> Type) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k (a, (b, c)) ((a, b), c)
regroup
  regroup' :: forall a b c.
(ObjectPair (LinearMap s) a b, ObjectPair (LinearMap s) b c,
 ObjectPair (LinearMap s) a (b, c),
 ObjectPair (LinearMap s) (a, b) c) =>
LinearMap s ((a, b), c) (a, (b, c))
regroup' = forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (k :: Type -> Type -> Type) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k ((a, b), c) (a, (b, c))
regroup'
instance Num' s => Morphism (LinearMap s) where
  LinearMap s b c
f *** :: forall b b' c c'.
(ObjectPair (LinearMap s) b b', ObjectPair (LinearMap s) c c') =>
LinearMap s b c -> LinearMap s b' c' -> LinearMap s (b, b') (c, c')
*** LinearMap s b' c'
g = (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
idforall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&forall w s v. AdditiveGroup w => LinearFunction s v w
const0) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s b c
f) forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall w s v. AdditiveGroup w => LinearFunction s v w
const0forall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s b' c'
g)
instance  s . Num' s => PreArrow (LinearMap s) where
  &&& :: forall b c c'.
(Object (LinearMap s) b, ObjectPair (LinearMap s) c c') =>
LinearMap s b c -> LinearMap s b c' -> LinearMap s b (c, c')
(&&&) = forall u v w.
(LinearSpace u, LinearSpace v, LinearSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
LinearMap s u v -> LinearMap s u w -> LinearMap s u (v, w)
lmFanout
   where lmFanout ::  u v w . ( LinearSpace u, LinearSpace v, LinearSpace w
                               , Scalar u~s, Scalar v~s, Scalar w~s )
           => LinearMap s u v -> LinearMap s u w -> LinearMap s u (v,w)
         lmFanout :: forall u v w.
(LinearSpace u, LinearSpace v, LinearSpace w, Scalar u ~ s,
 Scalar v ~ s, Scalar w ~ s) =>
LinearMap s u v -> LinearMap s u w -> LinearMap s u (v, w)
lmFanout LinearMap s u v
f LinearMap s u w
g = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                             , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v
                             , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness w ) of
             (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness, DualSpaceWitness w
DualSpaceWitness)
                 -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s u v
f, forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s u w
g)
  terminal :: forall b.
Object (LinearMap s) b =>
LinearMap s b (UnitObject (LinearMap s))
terminal = forall v. AdditiveGroup v => v
zeroV
  fst :: forall x y. ObjectPair (LinearMap s) x y => LinearMap s (x, y) x
fst = forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 forall v. AdditiveGroup v => v
zeroV
  snd :: forall x y. ObjectPair (LinearMap s) x y => LinearMap s (x, y) y
snd = forall v. AdditiveGroup v => v
zeroV forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
instance Num' s => EnhancedCat (->) (LinearMap s) where
  arr :: forall b c.
(Object (LinearMap s) b, Object (LinearMap s) c, Object (->) b,
 Object (->) c) =>
LinearMap s b c -> b -> c
arr LinearMap s b c
m = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s b c
m
instance Num' s => EnhancedCat (LinearFunction s) (LinearMap s) where
  arr :: forall b c.
(Object (LinearMap s) b, Object (LinearMap s) c,
 Object (LinearFunction s) b, Object (LinearFunction s) c) =>
LinearMap s b c -> LinearFunction s b c
arr LinearMap s b c
m = forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s b c
m
instance Num' s => EnhancedCat (LinearMap s) (LinearFunction s) where
  arr :: forall b c.
(Object (LinearFunction s) b, Object (LinearFunction s) c,
 Object (LinearMap s) b, Object (LinearMap s) c) =>
LinearFunction s b c -> LinearMap s b c
arr LinearFunction s b c
m = forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction s b c
m





  
instance  u v . ( TensorSpace u, TensorSpace v, Scalar u ~ Scalar v )
                       => TensorSpace (u,v) where
  type TensorProduct (u,v) w = (uw, vw)
  scalarSpaceWitness :: ScalarSpaceWitness (u, v)
scalarSpaceWitness = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                            , forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, ScalarSpaceWitness v
ScalarSpaceWitness) -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (u, v)
linearManifoldWitness = case ( forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness u
                            , forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness v ) of
       ( LinearManifoldWitness u
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
          BoundarylessWitness
#endif
        ,LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
          BoundarylessWitness
#endif
        )
         -> forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
             BoundarylessWitness
#endif
  zeroTensor :: forall w. (TensorSpace w, Scalar w ~ Scalar (u, v)) => (u, v) ⊗ w
zeroTensor = forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor forall u w v. (u ⊗ w) -> (v ⊗ w) -> (u, v) ⊗ w
<⊕ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (u, v)) =>
Bilinear (Scalar (u, v)) ((u, v) ⊗ w) ((u, v) ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar v
μ (Tensor (Tensor (Scalar v) u w
v,Tensor (Scalar v) v w
w)) ->
                 forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar v
μ)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) u w
v, (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar v
μ)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) v w
w )
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (u, v)) =>
((u, v) ⊗ w) -+> ((u, v) ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (Tensor (Scalar v) u w
v,Tensor (Scalar v) v w
w))
          -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) u w
v, forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) v w
w)
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (u, v)) =>
((u, v) ⊗ w) -> ((u, v) ⊗ w) -> (u, v) ⊗ w
addTensors (Tensor (Tensor (Scalar v) u w
fu, Tensor (Scalar v) v w
fv)) (Tensor (Tensor (Scalar v) u w
fu', Tensor (Scalar v) v w
fv')) = (Tensor (Scalar v) u w
fu forall v. AdditiveGroup v => v -> v -> v
^+^ Tensor (Scalar v) u w
fu') forall u w v. (u ⊗ w) -> (v ⊗ w) -> (u, v) ⊗ w
<⊕ (Tensor (Scalar v) v w
fv forall v. AdditiveGroup v => v -> v -> v
^+^ Tensor (Scalar v) v w
fv')
  subtractTensors :: forall w.
(TensorSpace (u, v), TensorSpace w, Scalar w ~ Scalar (u, v)) =>
((u, v) ⊗ w) -> ((u, v) ⊗ w) -> (u, v) ⊗ w
subtractTensors (Tensor (Tensor (Scalar v) u w
fu, Tensor (Scalar v) v w
fv)) (Tensor (Tensor (Scalar v) u w
fu', Tensor (Scalar v) v w
fv'))
          = (Tensor (Scalar v) u w
fu forall v. AdditiveGroup v => v -> v -> v
^-^ Tensor (Scalar v) u w
fu') forall u w v. (u ⊗ w) -> (v ⊗ w) -> (u, v) ⊗ w
<⊕ (Tensor (Scalar v) v w
fv forall v. AdditiveGroup v => v -> v -> v
^-^ Tensor (Scalar v) v w
fv')
  toFlatTensor :: (u, v) -+> ((u, v) ⊗ Scalar (u, v))
toFlatTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
     ScalarSpaceWitness u
ScalarSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction coerce :: forall a b. Coercible a b => a -> b
coerce
                          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor forall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor
  fromFlatTensor :: ((u, v) ⊗ Scalar (u, v)) -+> (u, v)
fromFlatTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
     ScalarSpaceWitness u
ScalarSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction coerce :: forall a b. Coercible a b => a -> b
coerce
                          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor forall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (u, v)) =>
Bilinear (u, v) w ((u, v) ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(u
u,v
v) w
w ->
                    forall s v w. TensorProduct v w -> Tensor s v w
Tensor ((forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>u
u)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w, (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>v
v)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w)
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (u, v)) =>
((u, v) ⊗ w) -+> (w ⊗ (u, v))
transposeTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (Tensor (Scalar v) u w
uw,Tensor (Scalar v) v w
vw))
              -> (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id)forall s v w. LinearFunction s v w -> v -> w
-+$>(forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) u w
uw,forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) v w
vw)
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (u, v),
 Scalar x ~ Scalar (u, v)) =>
Bilinear (w -+> x) ((u, v) ⊗ w) ((u, v) ⊗ x)
fmapTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
     \LinearFunction (Scalar v) w x
f (Tensor (Tensor (Scalar v) u w
uw,Tensor (Scalar v) v w
vw)) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ((forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar v) w x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) u w
uw, (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar v) w x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) v w
vw)
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (u, v), Scalar w ~ Scalar (u, v),
 Scalar x ~ Scalar (u, v)) =>
Bilinear ((w, x) -+> u) ((u, v) ⊗ w, (u, v) ⊗ x) ((u, v) ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
               forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction (Scalar v) (w, x) u
f (Tensor (Tensor (Scalar v) u w
uw, Tensor (Scalar v) v w
vw), Tensor (Tensor (Scalar v) u x
ux, Tensor (Scalar v) v x
vx))
                      -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar v) (w, x) u
f)forall s v w. LinearFunction s v w -> v -> w
-+$>(Tensor (Scalar v) u w
uw,Tensor (Scalar v) u x
ux)
                                , (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar v) (w, x) u
f)forall s v w. LinearFunction s v w -> v -> w
-+$>(Tensor (Scalar v) v w
vw,Tensor (Scalar v) v x
vx) )
  tensorUnsafeFromArrayWithOffset ::  nm w o α
          . ( nm`Dimensional`(u,v)
            , TensorSpace w, o`Dimensional`w, Scalar w ~ Scalar v
            , GArr.Vector α (Scalar u) )
           => Int -> α (Scalar u) -> ((u,v)w)
  tensorUnsafeFromArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type).
(Dimensional nm (u, v), TensorSpace w, Dimensional o w,
 Scalar w ~ Scalar v, Vector α (Scalar u)) =>
Int -> α (Scalar u) -> (u, v) ⊗ w
tensorUnsafeFromArrayWithOffset
     = case ( forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u, forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u
            , forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v, forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v ) of
        ( SJust Sing n
sn, DimensionalityWitness u
IsStaticDimensional
         ,SJust Sing n
sm, DimensionalityWitness v
IsStaticDimensional )
          -> let sno :: Sing (Apply (Apply (*@#@$) n) o)
sno = Sing n
sn forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w
                 smo :: Sing (Apply (Apply (*@#@$) n) o)
smo = Sing n
sm forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w
             in forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat Sing (Apply (Apply (*@#@$) n) o)
sno (forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat Sing (Apply (Apply (*@#@$) n) o)
smo (
                 \Int
i α (Scalar (Tensor (Scalar v) u w))
arr -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset Int
i α (Scalar (Tensor (Scalar v) u w))
arr
                                  , forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset
                                        (Int
i forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall (n :: Nat) (proxy :: Nat -> Type).
KnownNat n =>
proxy n -> Integer
natVal Sing (Apply (Apply (*@#@$) n) o)
sno)) α (Scalar (Tensor (Scalar v) u w))
arr )))
  tensorUnsafeWriteArrayWithOffset ::  nm w o α σ
          . ( nm`Dimensional`(u,v)
            , TensorSpace w, o`Dimensional`w, Scalar w ~ Scalar v
            , GArr.Vector α (Scalar u) )
           => GArr.Mutable α σ (Scalar u) -> Int -> ((u,v)w) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type) σ.
(Dimensional nm (u, v), TensorSpace w, Dimensional o w,
 Scalar w ~ Scalar v, Vector α (Scalar u)) =>
Mutable α σ (Scalar u) -> Int -> ((u, v) ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
     = case ( forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u, forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u
            , forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v, forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v ) of
        ( SJust Sing n
sn, DimensionalityWitness u
IsStaticDimensional
         ,SJust Sing n
sm, DimensionalityWitness v
IsStaticDimensional )
          -> let sno :: Sing (Apply (Apply (*@#@$) n) o)
sno = Sing n
sn forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w
                 smo :: Sing (Apply (Apply (*@#@$) n) o)
smo = Sing n
sm forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w
             in forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat Sing (Apply (Apply (*@#@$) n) o)
sno (forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat Sing (Apply (Apply (*@#@$) n) o)
smo (
                 \Mutable α σ (Scalar (Tensor (Scalar v) u w))
arr Int
i (Tensor (Tensor (Scalar v) u w
x,Tensor (Scalar v) v w
y)) -> do
                   forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (Tensor (Scalar v) u w))
arr Int
i Tensor (Scalar v) u w
x
                   forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (Tensor (Scalar v) u w))
arr (Int
i forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall (n :: Nat) (proxy :: Nat -> Type).
KnownNat n =>
proxy n -> Integer
natVal Sing (Apply (Apply (*@#@$) n) o)
sno)) Tensor (Scalar v) v w
y ))
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (u, v), TensorSpace b,
 Scalar b ~ Scalar (u, v)) =>
p (u, v)
-> VSCCoercion (Scalar (u, v)) a b
-> Coercion (TensorProduct (u, v) a) (TensorProduct (u, v) b)
coerceFmapTensorProduct p (u, v)
p VSCCoercion (Scalar (u, v)) a b
cab = case
             ( forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct (forall (a :: Type -> Type -> Type) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fstforall (f :: Type -> Type) (r :: Type -> Type -> Type) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>p (u, v)
p) VSCCoercion (Scalar (u, v)) a b
cab
             , forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct (forall (a :: Type -> Type -> Type) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
sndforall (f :: Type -> Type) (r :: Type -> Type -> Type) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>p (u, v)
p) VSCCoercion (Scalar (u, v)) a b
cab ) of
          (Coercion (TensorProduct u a) (TensorProduct u b)
Coercion, Coercion (TensorProduct v a) (TensorProduct v b)
Coercion) -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
  wellDefinedVector :: (u, v) -> Maybe (u, v)
wellDefinedVector (u
u,v
v) = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 (,) (forall v. TensorSpace v => v -> Maybe v
wellDefinedVector u
u) (forall v. TensorSpace v => v -> Maybe v
wellDefinedVector v
v)
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (u, v)) =>
((u, v) ⊗ w) -> Maybe ((u, v) ⊗ w)
wellDefinedTensor (Tensor (Tensor (Scalar v) u w
u,Tensor (Scalar v) v w
v))
         = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 ((forall s v w. TensorProduct v w -> Tensor s v w
Tensorforall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.) forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (,)) (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor Tensor (Scalar v) u w
u) (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor Tensor (Scalar v) v w
v)
instance  u v . ( LinearSpace u, LinearSpace v, Scalar u ~ Scalar v )
                       => LinearSpace (u,v) where
  type DualVector (u,v) = (DualVector u, DualVector v)
  
  dualSpaceWitness :: DualSpaceWitness (u, v)
dualSpaceWitness = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
       (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> 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 :: (u, v) +> (u, v)
linearId = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                  , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                  , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
             -> (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
idforall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&forall w s v. AdditiveGroup w => LinearFunction s v w
const0)forall s v w. LinearFunction s v w -> v -> w
-+$>forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id) forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall w s v. AdditiveGroup w => LinearFunction s v w
const0forall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id)forall s v w. LinearFunction s v w -> v -> w
-+$>forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id)
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (u, v)) =>
((u, v) ⊗ w) +> ((u, v) ⊗ w)
tensorId = forall w.
(LinearSpace w, Scalar w ~ Scalar v) =>
ScalarSpaceWitness u
-> DualSpaceWitness u
-> DualSpaceWitness v
-> DualSpaceWitness w
-> ((u, v) ⊗ w) +> ((u, v) ⊗ w)
tI forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where tI ::  w . (LinearSpace w, Scalar w ~ Scalar v)
                 => ScalarSpaceWitness u -> DualSpaceWitness u
                     -> DualSpaceWitness v -> DualSpaceWitness w
                       -> ((u,v)w)+>((u,v)w)
         tI :: forall w.
(LinearSpace w, Scalar w ~ Scalar v) =>
ScalarSpaceWitness u
-> DualSpaceWitness u
-> DualSpaceWitness v
-> DualSpaceWitness w
-> ((u, v) ⊗ w) +> ((u, v) ⊗ w)
tI ScalarSpaceWitness u
ScalarSpaceWitness DualSpaceWitness u
DualSpaceWitness DualSpaceWitness v
DualSpaceWitness DualSpaceWitness w
DualSpaceWitness 
              = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap
            ( 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))
rassocTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w x.
(LinearSpace v, LinearSpace w, Scalar v ~ s, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
VSCCoercion
  s
  (LinearMap s (Tensor s (DualVector v) w) x)
  (LinearMap s (LinearMap s v w) x)
argFromTensor
                 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Tensor (Scalar v) u w
t -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor (Scalar v) u w
t,forall v. AdditiveGroup v => v
zeroV)) forall s v w. LinearFunction s v w -> v -> w
-+$> forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
            , 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))
rassocTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w x.
(LinearSpace v, LinearSpace w, Scalar v ~ s, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
VSCCoercion
  s
  (LinearMap s (Tensor s (DualVector v) w) x)
  (LinearMap s (LinearMap s v w) x)
argFromTensor
                 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Tensor (Scalar v) v w
t -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall v. AdditiveGroup v => v
zeroV,Tensor (Scalar v) v w
t)) forall s v w. LinearFunction s v w -> v -> w
-+$> forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId )
  sampleLinearFunction :: forall w.
(TensorSpace w, Scalar (u, v) ~ Scalar w) =>
((u, v) -+> w) -+> ((u, v) +> w)
sampleLinearFunction = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                              , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                              , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
              -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(u, v) -+> w
f -> (forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall s v w. LinearFunction s v w -> v -> w
-+$> (u, v) -+> w
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall w s v. AdditiveGroup w => LinearFunction s v (v, w)
lCoFst)
                                              forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 (forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall s v w. LinearFunction s v w -> v -> w
-+$> (u, v) -+> w
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v s w. AdditiveGroup v => LinearFunction s w (v, w)
lCoSnd)
  applyDualVector :: LinearSpace (u, v) =>
Bilinear (DualVector (u, v)) (u, v) (Scalar (u, v))
applyDualVector = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                         , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                         , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
              -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(DualVector u
du,DualVector v
dv)
                      -> (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$DualVector u
du) forall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$DualVector v
dv) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall w s. AdditiveGroup w => LinearFunction s (w, w) w
addV
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (u, v)) =>
Bilinear ((u, v) +> w) (u, v) w
applyLinear = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                     , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                     , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
              -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap (Tensor (Scalar v) (DualVector u) w
fu, Tensor (Scalar v) (DualVector v) w
fv)) ->
           (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear forall s v w. LinearFunction s v w -> v -> w
-+$> (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (DualVector u) w
fu)) forall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear forall s v w. LinearFunction s v w -> v -> w
-+$> (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (DualVector v) w
fv))
             forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall w s. AdditiveGroup w => LinearFunction s (w, w) w
addV
  composeLinear :: forall w x.
(LinearSpace w, TensorSpace x, Scalar w ~ Scalar (u, v),
 Scalar x ~ Scalar (u, v)) =>
Bilinear (w +> x) ((u, v) +> w) ((u, v) +> x)
composeLinear = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                       , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
       (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
              -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \w +> x
f (LinearMap (Tensor (Scalar (DualVector u)) (DualVector u) w
fu, Tensor (Scalar (DualVector v)) (DualVector v) w
fv))
                    -> ((forall v w x.
(LinearSpace v, LinearSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w +> x) (v +> w) (v +> x)
composeLinearforall s v w. LinearFunction s v w -> v -> w
-+$>w +> x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (DualVector u)) (DualVector u) w
fu)
                       forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
 ((forall v w x.
(LinearSpace v, LinearSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w +> x) (v +> w) (v +> x)
composeLinearforall s v w. LinearFunction s v w -> v -> w
-+$>w +> x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (DualVector v)) (DualVector v) w
fv)
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (u, v)) =>
Bilinear (DualVector ((u, v) ⊗ u)) ((u, v) ⊗ u) (Scalar (u, v))
applyTensorFunctional = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v ) of
     (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                  \(LinearMap (Tensor (Scalar v) (DualVector u) (DualVector u)
fu,Tensor (Scalar v) (DualVector v) (DualVector u)
fv)) (Tensor (Tensor (Scalar v) u u
tu,Tensor (Scalar v) v u
tv))
                           -> ((forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional
                                  forall s v w. LinearFunction s v w -> v -> w
-+$>forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor (Scalar v) (DualVector u) (DualVector u)
fu)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) u u
tu)
                            forall a. Num a => a -> a -> a
+ ((forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional
                                  forall s v w. LinearFunction s v w -> v -> w
-+$>forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor (Scalar v) (DualVector v) (DualVector u)
fv)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) v u
tv)
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (u, v),
 Scalar w ~ Scalar (u, v)) =>
Bilinear (((u, v) ⊗ u) +> w) ((u, v) ⊗ u) w
applyTensorLinMap = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                           , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
     (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`
             \LinearMap (Scalar v) (Tensor (Scalar v) (u, v) u) w
f (Tensor (Tensor (Scalar v) u u
tu,Tensor (Scalar v) v u
tv)) -> let LinearMap (Tensor (Scalar v) (DualVector u) (LinearMap (Scalar v) u w)
fu,Tensor (Scalar v) (DualVector v) (LinearMap (Scalar v) u w)
fv) = 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar v) (Tensor (Scalar v) (u, v) u) w
f
                   in ( (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
applyTensorLinMapforall s v w. LinearFunction s v w -> 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)
uncurryLinearMapforall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (DualVector u) (LinearMap (Scalar v) u w)
fu)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) u u
tu )
                   forall v. AdditiveGroup v => v -> v -> v
^+^ ( (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
applyTensorLinMapforall s v w. LinearFunction s v w -> 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)
uncurryLinearMapforall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (DualVector v) (LinearMap (Scalar v) u w)
fv)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar v) v u
tv )
  useTupleLinearSpaceComponents :: forall x y φ.
((u, v) ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
r = (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
r
  coerceDoubleDual :: VSCCoercion (Scalar (u, v)) (u, v) (DualVector (DualVector (u, v)))
coerceDoubleDual = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v ) of
     (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion  

lfstBlock :: ( LSpace u, LSpace v, LSpace w
             , Scalar u ~ Scalar v, Scalar v ~ Scalar w )
          => (u+>w) -+> ((u,v)+>w)
lfstBlock :: forall u v w.
(LSpace u, LSpace v, LSpace w, Scalar u ~ Scalar v,
 Scalar v ~ Scalar w) =>
(u +> w) -+> ((u, v) +> w)
lfstBlock = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (forall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
forall v. AdditiveGroup v => v
zeroV)
lsndBlock :: ( LSpace u, LSpace v, LSpace w
            , Scalar u ~ Scalar v, Scalar v ~ Scalar w )
          => (v+>w) -+> ((u,v)+>w)
lsndBlock :: forall u v w.
(LSpace u, LSpace v, LSpace w, Scalar u ~ Scalar v,
 Scalar v ~ Scalar w) =>
(v +> w) -+> ((u, v) +> w)
lsndBlock = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (forall v. AdditiveGroup v => v
zeroVforall u w v. (u +> w) -> (v +> w) -> (u, v) +> w
)


-- | @((v'⊗w)+>x) -> ((v+>w)+>x)
argFromTensor ::  s v w x . ( LinearSpace v, LinearSpace w
                             , Scalar v ~ s, Scalar w ~ s
                             , TensorSpace x, Scalar x ~ s
                             )
                 => VSCCoercion s (LinearMap s (Tensor s (DualVector v) w) x)
                             (LinearMap s (LinearMap s v w) x)
argFromTensor :: forall s v w x.
(LinearSpace v, LinearSpace w, Scalar v ~ s, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
VSCCoercion
  s
  (LinearMap s (Tensor s (DualVector v) w) x)
  (LinearMap s (LinearMap s v w) x)
argFromTensor = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
     DualSpaceWitness v
DualSpaceWitness -> 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> 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

-- | @((v+>w)+>x) -> ((v'⊗w)+>x)@
argAsTensor ::  s v w x . ( LinearSpace v, LinearSpace w
                           , Scalar v ~ s, Scalar w ~ s
                           , TensorSpace x, Scalar x ~ s
                           )
                 => VSCCoercion s (LinearMap s (LinearMap s v w) x)
                             (LinearMap s (Tensor s (DualVector v) w) x)
argAsTensor :: forall s v w x.
(LinearSpace v, LinearSpace w, Scalar v ~ s, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
VSCCoercion
  s
  (LinearMap s (LinearMap s v w) x)
  (LinearMap s (Tensor s (DualVector v) w) x)
argAsTensor = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
     DualSpaceWitness v
DualSpaceWitness -> 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< 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

tensorDimensionAssoc ::  u v w s r . (TensorSpace u, TensorSpace v, TensorSpace w)
 => (( Maybe.ZipWithTimes (Maybe.ZipWithTimes (StaticDimension u) (StaticDimension v))
                          (StaticDimension w)
     ~ Maybe.ZipWithTimes (StaticDimension u)
                          (Maybe.ZipWithTimes (StaticDimension v) (StaticDimension w))
     ) => r) -> r
tensorDimensionAssoc :: forall u v w s r.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
((ZipWithTimes
    (ZipWithTimes (StaticDimension u) (StaticDimension v))
    (StaticDimension w)
  ~ ZipWithTimes
      (StaticDimension u)
      (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
 r)
-> r
tensorDimensionAssoc (ZipWithTimes
   (ZipWithTimes (StaticDimension u) (StaticDimension v))
   (StaticDimension w)
 ~ ZipWithTimes
     (StaticDimension u)
     (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
r
φ
  = forall (a :: Maybe Nat) (b :: Maybe Nat) (c :: Maybe Nat) r.
Sing a
-> Sing b
-> Sing c
-> ((ZipWithTimes a (ZipWithTimes b c)
     ~ ZipWithTimes (ZipWithTimes a b) c) =>
    r)
-> r
Maybe.zipWithTimesAssoc (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u)
                            (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v)
                            (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @w) (ZipWithTimes
   (ZipWithTimes (StaticDimension u) (StaticDimension v))
   (StaticDimension w)
 ~ ZipWithTimes
     (StaticDimension u)
     (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
r
φ

-- | @(u+>(v⊗w)) -> (u+>v)⊗w@
deferLinearMap ::  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 :: 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
  = forall u v w s r.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
((ZipWithTimes
    (ZipWithTimes (StaticDimension u) (StaticDimension v))
    (StaticDimension w)
  ~ ZipWithTimes
      (StaticDimension u)
      (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
 r)
-> r
tensorDimensionAssoc @u @v @w forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

-- | @(u+>v)⊗w -> u+>(v⊗w)@
hasteLinearMap ::  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))
hasteLinearMap :: 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))
hasteLinearMap = forall u v w s r.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
((ZipWithTimes
    (ZipWithTimes (StaticDimension u) (StaticDimension v))
    (StaticDimension w)
  ~ ZipWithTimes
      (StaticDimension u)
      (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
 r)
-> r
tensorDimensionAssoc @u @v @w forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion


lassocTensor ::  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 :: 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 = forall u v w s r.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
((ZipWithTimes
    (ZipWithTimes (StaticDimension u) (StaticDimension v))
    (StaticDimension w)
  ~ ZipWithTimes
      (StaticDimension u)
      (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
 r)
-> r
tensorDimensionAssoc @u @v @w forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
rassocTensor ::  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))
rassocTensor :: 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))
rassocTensor = forall u v w s r.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
((ZipWithTimes
    (ZipWithTimes (StaticDimension u) (StaticDimension v))
    (StaticDimension w)
  ~ ZipWithTimes
      (StaticDimension u)
      (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
 r)
-> r
tensorDimensionAssoc @u @v @w forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion


instance  s u v . ( LinearSpace u, TensorSpace v, Scalar u ~ s, Scalar v ~ s )
                       => DimensionAware (LinearMap s u v) where
  type StaticDimension (LinearMap s u v)
          = Maybe.ZipWithTimes (StaticDimension u) (StaticDimension v)
  dimensionalityWitness :: DimensionalityWitness (LinearMap s u v)
dimensionalityWitness = case (forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v) of
    (DimensionalityWitness u
IsStaticDimensional, DimensionalityWitness v
IsStaticDimensional)
        -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @u forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v)
              forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    (DimensionalityWitness u
IsFlexibleDimensional, DimensionalityWitness v
_) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
    (DimensionalityWitness u
_, DimensionalityWitness v
IsFlexibleDimensional) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  s n u m v nm . ( n`Dimensional`u, m`Dimensional`v
                          , LinearSpace u, TensorSpace v, Scalar u ~ s, Scalar v ~ s
                          , nm ~ (n*m) )
                   => nm`Dimensional`(LinearMap s u v) where
  knownDimensionalitySing :: Sing nm
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @u forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (LinearMap s u v)) =>
Int -> α (Scalar (LinearMap s u v)) -> LinearMap s u v
unsafeFromArrayWithOffset Int
i α (Scalar (LinearMap s u v))
arr = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u of
    DualSpaceWitness u
DualSpaceWitness -> case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector u) of
      DimensionalityWitness (DualVector u)
IsStaticDimensional
       -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset Int
i α (Scalar (LinearMap s u v))
arr
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (LinearMap s u v)) =>
Mutable α σ (Scalar (LinearMap s u v))
-> Int -> LinearMap s u v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (LinearMap s u v))
arr Int
i LinearMap s u v
lm = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u of
    DualSpaceWitness u
DualSpaceWitness -> case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector u) of
      DimensionalityWitness (DualVector u)
IsStaticDimensional
       -> forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (LinearMap s u v))
arr Int
i (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s u v
lm)

instance  s u v . ( LinearSpace u, TensorSpace v, Scalar u ~ s, Scalar v ~ s )
                       => TensorSpace (LinearMap s u v) where
  type TensorProduct (LinearMap s u v) w = TensorProduct (DualVector u) (Tensor s v w)
  scalarSpaceWitness :: ScalarSpaceWitness (LinearMap s u v)
scalarSpaceWitness = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                            , forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, ScalarSpaceWitness v
_ScalarSpaceWitness) -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (LinearMap s u v)
linearManifoldWitness = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                               , forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness u
                               , forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness v ) of
       ( ScalarSpaceWitness u
ScalarSpaceWitness
        ,LinearManifoldWitness u
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
           BoundarylessWitness
#endif
        ,LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
           BoundarylessWitness
#endif
        )
         -> forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
             BoundarylessWitness
#endif
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
LinearMap s u v ⊗ w
zeroTensor = 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. AdditiveGroup v => v
zeroV
  toFlatTensor :: LinearMap s u v -+> (LinearMap s u v ⊗ Scalar (LinearMap s u v))
toFlatTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
       ScalarSpaceWitness u
ScalarSpaceWitness -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor
  fromFlatTensor :: (LinearMap s u v ⊗ Scalar (LinearMap s u v)) -+> LinearMap s u v
fromFlatTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
       ScalarSpaceWitness u
ScalarSpaceWitness -> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
hasteLinearMap
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
(LinearMap s u v ⊗ w)
-> (LinearMap s u v ⊗ w) -> LinearMap s u v ⊗ w
addTensors LinearMap s u v ⊗ w
t₁ LinearMap s u v ⊗ w
t₂ = 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (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))
hasteLinearMapforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s u v ⊗ w
t₁) forall v. AdditiveGroup v => v -> v -> v
^+^ (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))
hasteLinearMapforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s u v ⊗ w
t₂)
  subtractTensors :: forall w.
(TensorSpace (LinearMap s u v), TensorSpace w,
 Scalar w ~ Scalar (LinearMap s u v)) =>
(LinearMap s u v ⊗ w)
-> (LinearMap s u v ⊗ w) -> LinearMap s u v ⊗ w
subtractTensors LinearMap s u v ⊗ w
t₁ LinearMap s u v ⊗ w
t₂ = 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (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))
hasteLinearMapforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s u v ⊗ w
t₁) forall v. AdditiveGroup v => v -> v -> v
^-^ (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))
hasteLinearMapforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s u v ⊗ w
t₂)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
Bilinear
  (Scalar (LinearMap s u v))
  (LinearMap s u v ⊗ w)
  (LinearMap s u v ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \s
μ Tensor s (LinearMap s u v) w
t
            -> 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v s.
(VectorSpace v, Scalar v ~ s) =>
s -> LinearFunction s v v
scaleWith s
μ forall s v w. LinearFunction s v w -> 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))
hasteLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (LinearMap s u v) w
t
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
(LinearMap s u v ⊗ w) -+> (LinearMap s u v ⊗ w)
negateTensor = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall w s. AdditiveGroup w => LinearFunction s w w
lNegateV forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
hasteLinearMap
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
(LinearMap s u v ⊗ w) -+> (w ⊗ LinearMap s u v)
transposeTensor = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                         , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u ) of
    (ScalarSpaceWitness u
ScalarSpaceWitness,DualSpaceWitness u
DualSpaceWitness)-> --(u +> v) ⊗ w
              forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
hasteLinearMap     --  u +> (v ⊗ w)
          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor   --  u +> (w ⊗ v)
          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor           --  u' ⊗ (w ⊗ v)
          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor        --  (w ⊗ v) ⊗ u'
          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor       --  w ⊗ (v ⊗ u')
          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor   --  w ⊗ (u' ⊗ v)
          forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor)  --  w ⊗ (u +> v)
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
Bilinear (LinearMap s u v) w (LinearMap s u v ⊗ w)
tensorProduct = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
     ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap s u v
f w
s
                   -> 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w y. Bilinear v w y -> Bilinear w v y
flipBilin forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>w
s)forall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap s u v
f
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (LinearMap s u v),
 Scalar x ~ Scalar (LinearMap s u v)) =>
Bilinear (w -+> x) (LinearMap s u v ⊗ w) (LinearMap s u v ⊗ x)
fmapTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
     ScalarSpaceWitness u
ScalarSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s w x
f
                -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
hasteLinearMap
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (LinearMap s u v),
 Scalar w ~ Scalar (LinearMap s u v),
 Scalar x ~ Scalar (LinearMap s u v)) =>
Bilinear
  ((w, x) -+> u)
  (LinearMap s u v ⊗ w, LinearMap s u v ⊗ x)
  (LinearMap s u v ⊗ u)
fzipTensorWith = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
     ScalarSpaceWitness u
ScalarSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s (w, x) u
f
                -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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)
                     forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
hasteLinearMap forall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
hasteLinearMap
  tensorUnsafeFromArrayWithOffset ::  nm w o α
          . ( nm`Dimensional`LinearMap s u v
            , TensorSpace w, o`Dimensional`w, Scalar w ~ s
            , GArr.Vector α s )
           => Int -> α s -> (LinearMap s u vw)
  tensorUnsafeFromArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type).
(Dimensional nm (LinearMap s u v), TensorSpace w, Dimensional o w,
 Scalar w ~ s, Vector α s) =>
Int -> α s -> LinearMap s u v ⊗ w
tensorUnsafeFromArrayWithOffset
     = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u
            , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v ) of
        ( DimensionalityWitness u
IsStaticDimensional, SJust Sing n
sn
         ,DimensionalityWitness v
IsStaticDimensional, SJust Sing n
sm )
           -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w) (
              forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
snforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*(Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w)) (
               \Int
i -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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 @s @u @v @w)
                                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset Int
i))
  tensorUnsafeWriteArrayWithOffset ::  nm w o α σ
          . ( nm`Dimensional`LinearMap s u v
            , TensorSpace w, o`Dimensional`w, Scalar w ~ s
            , GArr.Vector α s )
           => GArr.Mutable α σ s -> Int -> (LinearMap s u vw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type) σ.
(Dimensional nm (LinearMap s u v), TensorSpace w, Dimensional o w,
 Scalar w ~ s, Vector α s) =>
Mutable α σ s -> Int -> (LinearMap s u v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
     = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u
            , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v ) of
        ( DimensionalityWitness u
IsStaticDimensional, SJust Sing n
sn
         ,DimensionalityWitness v
IsStaticDimensional, SJust Sing n
sm )
           -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w) (
              forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
snforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*(Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w)) (
               \Mutable α σ s
ar Int
i -> forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ s
ar Int
i
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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))
hasteLinearMap @s @u @v @w) ))
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (LinearMap s u v),
 TensorSpace b, Scalar b ~ Scalar (LinearMap s u v)) =>
p (LinearMap s u v)
-> VSCCoercion (Scalar (LinearMap s u v)) a b
-> Coercion
     (TensorProduct (LinearMap s u v) a)
     (TensorProduct (LinearMap s u v) b)
coerceFmapTensorProduct = forall a b (p :: Type -> Type).
(TensorSpace a, Scalar a ~ s, TensorSpace b, Scalar b ~ s) =>
DualSpaceWitness u
-> p (LinearMap s u v)
-> VSCCoercion s a b
-> Coercion
     (TensorProduct (DualVector u) (Tensor s v a))
     (TensorProduct (DualVector u) (Tensor s v b))
cftlp forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where cftlp ::  a b p . ( TensorSpace a, Scalar a ~ s
                            , TensorSpace b, Scalar b ~ s )
                   => DualSpaceWitness u -> p (LinearMap s u v) -> VSCCoercion s a b
                   -> Coercion (TensorProduct (DualVector u) (Tensor s v a))
                               (TensorProduct (DualVector u) (Tensor s v b))
         cftlp :: forall a b (p :: Type -> Type).
(TensorSpace a, Scalar a ~ s, TensorSpace b, Scalar b ~ s) =>
DualSpaceWitness u
-> p (LinearMap s u v)
-> VSCCoercion s a b
-> Coercion
     (TensorProduct (DualVector u) (Tensor s v a))
     (TensorProduct (DualVector u) (Tensor s v b))
cftlp DualSpaceWitness u
DualSpaceWitness p (LinearMap s u v)
_ VSCCoercion s a b
c
                   = forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ([]::[DualVector u])
                                             (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 a b
c :: VSCCoercion s (va) (vb))
  wellDefinedVector :: LinearMap s u v -> Maybe (LinearMap s u v)
wellDefinedVector = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u of
      DualSpaceWitness u
DualSpaceWitness -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor))
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
(LinearMap s u v ⊗ w) -> Maybe (LinearMap s u v ⊗ w)
wellDefinedTensor
      = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
hasteLinearMap forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. TensorSpace v => v -> Maybe v
wellDefinedVector forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion 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))

-- | @((u+>v)+>w) -> u⊗(v+>w)@
coCurryLinearMap ::  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 :: 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 = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                        , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
     (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
             -> forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> 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))
rassocTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap

-- | @(u⊗(v+>w)) -> (u+>v)+>w@
coUncurryLinearMap ::  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 :: 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 = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
     (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
             -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap

-- | @((u⊗v)+>w) -> (u+>(v+>w))@
curryLinearMap ::  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 :: 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 = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
    (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
        -> forall u v w s r.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
((ZipWithTimes
    (ZipWithTimes (StaticDimension u) (StaticDimension v))
    (StaticDimension w)
  ~ ZipWithTimes
      (StaticDimension u)
      (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
 r)
-> r
tensorDimensionAssoc @u @(DualVector v) @w
                (forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion :: VSCCoercion s ((uv)+>w)
                                     ((DualVector u)(Tensor s (DualVector v) w)) )
                                 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor

-- | @(u+>(v+>w)) -> ((u⊗v)+>w)@
uncurryLinearMap ::  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 :: 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 = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
    (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
         -> forall u v w s r.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
((ZipWithTimes
    (ZipWithTimes (StaticDimension u) (StaticDimension v))
    (StaticDimension w)
  ~ ZipWithTimes
      (StaticDimension u)
      (ZipWithTimes (StaticDimension v) (StaticDimension w))) =>
 r)
-> r
tensorDimensionAssoc @u @(DualVector v) @w
               (forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion :: VSCCoercion s
                                     ((DualVector u)(Tensor s (DualVector v) w))
                                     ((uv)+>w) )
                                 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor

uncurryLinearFn :: ( Num' s, LSpace u, LSpace v, LSpace w
                   , Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
           => LinearFunction s u (LinearMap s v w) -+> LinearFunction s (Tensor s u v) w
uncurryLinearFn :: forall s u v w.
(Num' s, LSpace u, LSpace v, LSpace w, Scalar u ~ s, Scalar v ~ s,
 Scalar w ~ s) =>
LinearFunction s u (LinearMap s v w)
-+> LinearFunction s (Tensor s u v) w
uncurryLinearFn = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
         forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s u (LinearMap s v w)
f Tensor s u v
t -> forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ (v +> w)) -+> w
contractMapTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 u (LinearMap s v w)
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s u v
t

instance  s u v . (LinearSpace u, LinearSpace v, Scalar u ~ s, Scalar v ~ s)
                       => LinearSpace (LinearMap s u v) where
  type DualVector (LinearMap s u v) = Tensor s u (DualVector v)
  dualSpaceWitness :: DualSpaceWitness (LinearMap s u v)
dualSpaceWitness = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
      (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> 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 :: LinearMap s u v +> LinearMap s u v
linearId = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
     (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
          -> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor
                            forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
(LinearMap s u v ⊗ w) +> (LinearMap s u v ⊗ w)
tensorId = 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 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
               forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
  coerceDoubleDual :: VSCCoercion
  (Scalar (LinearMap s u v))
  (LinearMap s u v)
  (DualVector (DualVector (LinearMap s u v)))
coerceDoubleDual = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
     DualSpaceWitness v
DualSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearMap s u v)) =>
Bilinear (LinearMap s u v +> w) (LinearMap s u v) w
applyLinear = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u of
    DualSpaceWitness u
DualSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap s (LinearMap s u v) w
f LinearMap s u v
g
                  -> let tf :: LinearMap s (Tensor s (DualVector u) v) w
tf = forall s v w x.
(LinearSpace v, LinearSpace w, Scalar v ~ s, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
VSCCoercion
  s
  (LinearMap s (LinearMap s v w) x)
  (LinearMap s (Tensor s (DualVector v) w) x)
argAsTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (LinearMap s u v) w
f
                     in (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
applyTensorLinMapforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap s (Tensor s (DualVector u) v) w
tf)forall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s u v
g
  applyDualVector :: LinearSpace (LinearMap s u v) =>
Bilinear
  (DualVector (LinearMap s u v))
  (LinearMap s u v)
  (Scalar (LinearMap s u v))
applyDualVector = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> forall v w y. Bilinear v w y -> Bilinear w v y
flipBilin forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (LinearMap s u v)) =>
Bilinear
  (DualVector (LinearMap s u v ⊗ u))
  (LinearMap s u v ⊗ u)
  (Scalar (LinearMap s u v))
applyTensorFunctional = forall w.
(LinearSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness u
-> DualSpaceWitness w
-> Bilinear ((u +> v) +> DualVector w) ((u +> v) ⊗ w) s
atf forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where atf ::  w . (LinearSpace w, Scalar w ~ s)
                   => ScalarSpaceWitness u -> DualSpaceWitness u -> DualSpaceWitness w
                       -> Bilinear ((u+>v)+>DualVector w) ((u+>v)w) s
         atf :: forall w.
(LinearSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness u
-> DualSpaceWitness w
-> Bilinear ((u +> v) +> DualVector w) ((u +> v) ⊗ w) s
atf ScalarSpaceWitness u
ScalarSpaceWitness DualSpaceWitness u
DualSpaceWitness DualSpaceWitness w
DualSpaceWitness
              = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap)
                           forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`\LinearFunction s (Tensor s (DualVector u) (Tensor s v w)) s
f Tensor s (LinearMap s u v) w
t
                     -> LinearFunction s (Tensor s (DualVector u) (Tensor s v w)) s
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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))
hasteLinearMap) forall s v w. LinearFunction s v w -> v -> w
-+$> Tensor s (LinearMap s u v) w
t
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (LinearMap s u v),
 Scalar w ~ Scalar (LinearMap s u v)) =>
Bilinear ((LinearMap s u v ⊗ u) +> w) (LinearMap s u v ⊗ u) w
applyTensorLinMap = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u of
    DualSpaceWitness u
DualSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                 forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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))
curryLinearMapforall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>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
                             forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 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)
uncurryLinearMapforall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>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)
coUncurryLinearMapforall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>forall s v w x.
(LinearSpace v, LinearSpace w, Scalar v ~ s, Scalar w ~ s,
 TensorSpace x, Scalar x ~ s) =>
VSCCoercion
  s
  (LinearMap s (LinearMap s v w) x)
  (LinearMap s (Tensor s (DualVector v) w) x)
argAsTensor)
                  forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> \LinearMap
  (Scalar (DualVector u))
  (Tensor
     (Scalar (DualVector u))
     (DualVector u)
     (Tensor (Scalar (DualVector u)) v u))
  w
f -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Tensor
  (Scalar (DualVector u)) (LinearMap (Scalar (DualVector u)) u v) u
g
                               -> (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
applyTensorLinMapforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap
  (Scalar (DualVector u))
  (Tensor
     (Scalar (DualVector u))
     (DualVector u)
     (Tensor (Scalar (DualVector u)) v u))
  w
f)
                                   forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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))
hasteLinearMap) forall s v w. LinearFunction s v w -> v -> w
-+$> Tensor
  (Scalar (DualVector u)) (LinearMap (Scalar (DualVector u)) u v) u
g
  useTupleLinearSpaceComponents :: forall x y φ.
(LinearMap s u v ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = forall a. a
usingNonTupleTypeAsTupleError


instance  s u v . (TensorSpace u, TensorSpace v, Scalar u ~ s, Scalar v ~ s)
                       => DimensionAware (Tensor s u v) where
  type StaticDimension (Tensor s u v)
          = Maybe.ZipWithTimes (StaticDimension u) (StaticDimension v)
  dimensionalityWitness :: DimensionalityWitness (Tensor s u v)
dimensionalityWitness = case (forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v) of
    (DimensionalityWitness u
IsStaticDimensional, DimensionalityWitness v
IsStaticDimensional)
        -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @u forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v)
              forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    (DimensionalityWitness u
IsFlexibleDimensional, DimensionalityWitness v
_) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
    (DimensionalityWitness u
_, DimensionalityWitness v
IsFlexibleDimensional) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  s n u m v nm . ( n`Dimensional`u, m`Dimensional`v
                          , TensorSpace u, TensorSpace v, Scalar u ~ s, Scalar v ~ s
                          , nm ~ (n*m) )
                   => nm`Dimensional`(Tensor s u v) where
  knownDimensionalitySing :: Sing nm
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @u forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (Tensor s u v)) =>
Int -> α (Scalar (Tensor s u v)) -> Tensor s u v
unsafeFromArrayWithOffset = forall v w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffset
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (Tensor s u v)) =>
Mutable α σ (Scalar (Tensor s u v))
-> Int -> Tensor s u v -> ST σ ()
unsafeWriteArrayWithOffset = forall v w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset

instance  s u v . (TensorSpace u, TensorSpace v, Scalar u ~ s, Scalar v ~ s)
                       => TensorSpace (Tensor s u v) where
  type TensorProduct (Tensor s u v) w = TensorProduct u (Tensor s v w)
  scalarSpaceWitness :: ScalarSpaceWitness (Tensor s u v)
scalarSpaceWitness = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                            , forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, ScalarSpaceWitness v
ScalarSpaceWitness) -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (Tensor s u v)
linearManifoldWitness = case ( forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness u
                             , forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness v ) of
       ( LinearManifoldWitness u
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
            BoundarylessWitness
#endif
        ,LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
            BoundarylessWitness
#endif
        )
         -> forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
             BoundarylessWitness
#endif
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
Tensor s u v ⊗ w
zeroTensor = 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  toFlatTensor :: Tensor s u v -+> (Tensor s u v ⊗ Scalar (Tensor s u v))
toFlatTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor
  fromFlatTensor :: (Tensor s u v ⊗ Scalar (Tensor s u v)) -+> Tensor s u v
fromFlatTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v ⊗ w) -> (Tensor s u v ⊗ w) -> Tensor s u v ⊗ w
addTensors Tensor s u v ⊗ w
t₁ Tensor s u v ⊗ w
t₂ = 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (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))
rassocTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s u v ⊗ w
t₁) forall v. AdditiveGroup v => v -> v -> v
^+^ (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))
rassocTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s u v ⊗ w
t₂)
  subtractTensors :: forall w.
(TensorSpace (Tensor s u v), TensorSpace w,
 Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v ⊗ w) -> (Tensor s u v ⊗ w) -> Tensor s u v ⊗ w
subtractTensors Tensor s u v ⊗ w
t₁ Tensor s u v ⊗ w
t₂ = 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (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))
rassocTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s u v ⊗ w
t₁) forall v. AdditiveGroup v => v -> v -> v
^-^ (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))
rassocTensorforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s u v ⊗ w
t₂)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
Bilinear
  (Scalar (Tensor s u v)) (Tensor s u v ⊗ w) (Tensor s u v ⊗ w)
scaleTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness ->
        forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \s
μ -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v s.
(VectorSpace v, Scalar v ~ s) =>
s -> LinearFunction s v v
scaleWith s
μ forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v ⊗ w) -+> (Tensor s u v ⊗ w)
negateTensor = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall w s. AdditiveGroup w => LinearFunction s w w
lNegateV forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
Bilinear (Tensor s u v) w (Tensor s u v ⊗ w)
tensorProduct = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w y. Bilinear v w y -> Bilinear w v y
flipBilin forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \w
w
             -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w y. Bilinear v w y -> Bilinear w v y
flipBilin forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>w
w)
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v ⊗ w) -+> (w ⊗ Tensor s u v)
transposeTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (Tensor s u v),
 Scalar x ~ Scalar (Tensor s u v)) =>
Bilinear (w -+> x) (Tensor s u v ⊗ w) (Tensor s u v ⊗ x)
fmapTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s w x
f
                -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (Tensor s u v), Scalar w ~ Scalar (Tensor s u v),
 Scalar x ~ Scalar (Tensor s u v)) =>
Bilinear
  ((w, x) -+> u)
  (Tensor s u v ⊗ w, Tensor s u v ⊗ x)
  (Tensor s u v ⊗ u)
fzipTensorWith = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s (w, x) u
f
                -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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)
                     forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor forall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  tensorUnsafeFromArrayWithOffset ::  nm w o α
          . ( nm`Dimensional`Tensor s u v
            , TensorSpace w, o`Dimensional`w, Scalar w ~ s
            , GArr.Vector α s )
           => Int -> α s -> (Tensor s u vw)
  tensorUnsafeFromArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type).
(Dimensional nm (Tensor s u v), TensorSpace w, Dimensional o w,
 Scalar w ~ s, Vector α s) =>
Int -> α s -> Tensor s u v ⊗ w
tensorUnsafeFromArrayWithOffset
     = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u
            , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v ) of
        ( DimensionalityWitness u
IsStaticDimensional, SJust Sing n
sn
         ,DimensionalityWitness v
IsStaticDimensional, SJust Sing n
sm )
           -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w) (
              forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
snforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*(Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w)) (
               \Int
i -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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 @s @u @v @w)
                                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset Int
i))
  tensorUnsafeWriteArrayWithOffset ::  nm w o α σ
          . ( nm`Dimensional`Tensor s u v
            , TensorSpace w, o`Dimensional`w, Scalar w ~ s
            , GArr.Vector α s )
           => GArr.Mutable α σ s -> Int -> (Tensor s u vw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type) σ.
(Dimensional nm (Tensor s u v), TensorSpace w, Dimensional o w,
 Scalar w ~ s, Vector α s) =>
Mutable α σ s -> Int -> (Tensor s u v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
     = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u
            , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v ) of
        ( DimensionalityWitness u
IsStaticDimensional, SJust Sing n
sn
         ,DimensionalityWitness v
IsStaticDimensional, SJust Sing n
sm )
           -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w) (
              forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
snforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*(Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w)) (
               \Mutable α σ s
ar Int
i -> forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ s
ar Int
i
                         forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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))
rassocTensor @s @u @v @w) ))
  coerceFmapTensorProduct ::  a b p . ( TensorSpace a, Scalar a ~ s
                                       , TensorSpace b, Scalar b ~ s )
                   => p (Tensor s u v) -> VSCCoercion s a b
                   -> Coercion (TensorProduct u (Tensor s v a))
                               (TensorProduct u (Tensor s v b))
  coerceFmapTensorProduct :: forall a b (p :: Type -> Type).
(TensorSpace a, Scalar a ~ s, TensorSpace b, Scalar b ~ s) =>
p (Tensor s u v)
-> VSCCoercion s a b
-> Coercion
     (TensorProduct u (Tensor s v a)) (TensorProduct u (Tensor s v b))
coerceFmapTensorProduct p (Tensor s u v)
_ VSCCoercion s a b
c = forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ([]::[u])
                                             (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 a b
c :: VSCCoercion s (va) (vb))
  wellDefinedVector :: Tensor s u v -> Maybe (Tensor s u v)
wellDefinedVector = forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v ⊗ w) -> Maybe (Tensor s u v ⊗ w)
wellDefinedTensor = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion 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))
rassocTensor)
                       forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion 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))
instance  s u v . (LinearSpace u, LinearSpace v, Scalar u ~ s, Scalar v ~ s)
                       => LinearSpace (Tensor s u v) where
  type DualVector (Tensor s u v) = LinearMap s u (DualVector v)
  linearId :: Tensor s u v +> Tensor s u v
linearId = forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v ⊗ w) +> (Tensor s u v ⊗ w)
tensorId = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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
               forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
  coerceDoubleDual :: VSCCoercion
  (Scalar (Tensor s u v))
  (Tensor s u v)
  (DualVector (DualVector (Tensor s u v)))
coerceDoubleDual = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
    (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
  dualSpaceWitness :: DualSpaceWitness (Tensor s u v)
dualSpaceWitness = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
    (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> 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
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
Bilinear (Tensor s u v +> w) (Tensor s u v) w
applyLinear = forall v u w.
(LinearSpace v, LinearSpace u, TensorSpace w, Scalar u ~ Scalar v,
 Scalar w ~ Scalar v) =>
Bilinear ((v ⊗ u) +> w) (v ⊗ u) w
applyTensorLinMap
  applyDualVector :: LinearSpace (Tensor s u v) =>
Bilinear
  (DualVector (Tensor s u v)) (Tensor s u v) (Scalar (Tensor s u v))
applyDualVector = forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (Tensor s u v)) =>
Bilinear
  (DualVector (Tensor s u v ⊗ u))
  (Tensor s u v ⊗ u)
  (Scalar (Tensor s u v))
applyTensorFunctional = forall w.
(LinearSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness w
-> Bilinear
     (LinearMap s (Tensor s u v) (DualVector w))
     (Tensor s (Tensor s u v) w)
     s
atf forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where atf ::  w . (LinearSpace w, Scalar w ~ s)
               => ScalarSpaceWitness u -> DualSpaceWitness w
                  -> Bilinear (LinearMap s (Tensor s u v) (DualVector w))
                              (Tensor s (Tensor s u v) w)
                              s
         atf :: forall w.
(LinearSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness w
-> Bilinear
     (LinearMap s (Tensor s u v) (DualVector w))
     (Tensor s (Tensor s u v) w)
     s
atf ScalarSpaceWitness u
ScalarSpaceWitness DualSpaceWitness w
DualSpaceWitness
             = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional
                           forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`\LinearFunction s (Tensor s u (Tensor s v w)) s
f -> LinearFunction s (Tensor s u (Tensor s v w)) s
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (Tensor s u v),
 Scalar w ~ Scalar (Tensor s u v)) =>
Bilinear ((Tensor s u v ⊗ u) +> w) (Tensor s u v ⊗ u) w
applyTensorLinMap = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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))
curryLinearMapforall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>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
                            forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 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)
uncurryLinearMapforall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>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)
                        forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> \LinearMap
  (Scalar u) (Tensor (Scalar u) u (Tensor (Scalar u) v u)) w
f -> (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
applyTensorLinMapforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap
  (Scalar u) (Tensor (Scalar u) u (Tensor (Scalar u) v u)) w
f) forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  composeLinear :: forall w x.
(LinearSpace w, TensorSpace x, Scalar w ~ Scalar (Tensor s u v),
 Scalar x ~ Scalar (Tensor s u v)) =>
Bilinear (w +> x) (Tensor s u v +> w) (Tensor s u v +> x)
composeLinear = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap s w x
f LinearMap s (Tensor s u v) w
g
        -> 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap s w x
f) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (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))
curryLinearMapforall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (Tensor s u v) w
g)
  contractTensorMap :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v +> (Tensor s u v ⊗ w)) -+> w
contractTensorMap = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v +> (v ⊗ w)) -+> w
contractTensorMap
      forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v +> (v ⊗ w)) -+> w
contractTensorMap
                 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor))
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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
  contractMapTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Tensor s u v)) =>
(Tensor s u v ⊗ (Tensor s u v +> w)) -+> w
contractMapTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
    ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v +> (v ⊗ w)) -+> w
contractTensorMap forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ (v +> w)) -+> w
contractMapTensor
                 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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))
hasteLinearMap) forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor)
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr 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))
rassocTensor
  useTupleLinearSpaceComponents :: forall x y φ.
(Tensor s u v ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = forall a. a
usingNonTupleTypeAsTupleError



type DualSpace v = v+>Scalar v

type Fractional' s = (Num' s, Fractional s, Eq s, VectorSpace s)



instance (TensorSpace v, Num' s, Scalar v ~ s)
            => Functor (Tensor s v) (LinearFunction s) (LinearFunction s) where
  fmap :: 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)
fmap LinearFunction s a b
f = forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensor LinearFunction s a b
f
instance (Num' s, TensorSpace v, Scalar v ~ s)
            => Monoidal (Tensor s v) (LinearFunction s) (LinearFunction s) where
  pureUnit :: LinearFunction
  s
  (UnitObject (LinearFunction s))
  (Tensor s v (UnitObject (LinearFunction s)))
pureUnit = forall w s v. AdditiveGroup w => LinearFunction s v w
const0
  fzipWith :: 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)
fzipWith LinearFunction s (a, b) c
f = forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWith LinearFunction s (a, b) c
f

instance (LinearSpace v, Num' s, Scalar v ~ s)
            => Functor (LinearMap s v) (LinearFunction s) (LinearFunction s) where
  fmap :: forall a b.
(Object (LinearFunction s) a,
 Object (LinearFunction s) (LinearMap s v a),
 Object (LinearFunction s) b,
 Object (LinearFunction s) (LinearMap s v b)) =>
LinearFunction s a b
-> LinearFunction s (LinearMap s v a) (LinearMap s v b)
fmap = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> \LinearFunction s a b
f -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 a b
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor
instance (Num' s, LinearSpace v, Scalar v ~ s)
            => Monoidal (LinearMap s v) (LinearFunction s) (LinearFunction s) where
  pureUnit :: LinearFunction
  s
  (UnitObject (LinearFunction s))
  (LinearMap s v (UnitObject (LinearFunction s)))
pureUnit = forall w s v. AdditiveGroup w => LinearFunction s v w
const0
  fzipWith :: forall a b c.
(ObjectPair (LinearFunction s) a b, Object (LinearFunction s) c,
 ObjectPair (LinearFunction s) (LinearMap s v a) (LinearMap s v b),
 Object (LinearFunction s) (LinearMap s v c)) =>
LinearFunction s (a, b) c
-> LinearFunction
     s (LinearMap s v a, LinearMap s v b) (LinearMap s v c)
fzipWith = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
    DualSpaceWitness v
DualSpaceWitness -> \LinearFunction s (a, b) c
f -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (a, b) c
f forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor

instance  v s . (TensorSpace v, Scalar v ~ s)
            => Functor (Tensor s v) (VSCCoercion s) (VSCCoercion s) where
  fmap ::  a b . ( TensorSpace a, Scalar a ~ s
                  , TensorSpace b, Scalar b ~ s )
              => VSCCoercion s a b -> VSCCoercion s (Tensor s v a) (Tensor s v b)
  fmap :: forall a b.
(TensorSpace a, Scalar a ~ s, TensorSpace b, Scalar b ~ s) =>
VSCCoercion s a b -> VSCCoercion s (Tensor s v a) (Tensor s v b)
fmap f :: VSCCoercion s a b
f@VSCCoercion s a b
VSCCoercion = case forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct @v [] VSCCoercion s a b
f of
                       Coercion (TensorProduct v a) (TensorProduct v b)
Coercion -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

instance  v s . (LinearSpace v, Scalar v ~ s)
            => Functor (LinearMap s v) (VSCCoercion s) (VSCCoercion s) where
  fmap ::  a b . ( TensorSpace a, Scalar a ~ s
                  , TensorSpace b, Scalar b ~ s )
    => VSCCoercion s a b -> VSCCoercion s (LinearMap s v a) (LinearMap s v b)
  fmap :: forall a b.
(TensorSpace a, Scalar a ~ s, TensorSpace b, Scalar b ~ s) =>
VSCCoercion s a b
-> VSCCoercion s (LinearMap s v a) (LinearMap s v b)
fmap f :: VSCCoercion s a b
f@VSCCoercion s a b
VSCCoercion = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v of
        DualSpaceWitness v
DualSpaceWitness -> case forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct @(DualVector v) [] VSCCoercion s a b
f of
         Coercion
  (TensorProduct (DualVector v) a) (TensorProduct (DualVector v) b)
Coercion -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

instance Category (LinearFunction s) where
  type Object (LinearFunction s) v = (TensorSpace v, Scalar v ~ s)
  id :: forall a. Object (LinearFunction s) a => LinearFunction s a a
id = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
  LinearFunction b -> c
f . :: forall a b c.
(Object (LinearFunction s) a, Object (LinearFunction s) b,
 Object (LinearFunction s) c) =>
LinearFunction s b c
-> LinearFunction s a b -> LinearFunction s a c
. LinearFunction a -> b
g = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ b -> c
fforall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.a -> b
g
instance Num' s => Cartesian (LinearFunction s) where
  type UnitObject (LinearFunction s) = ZeroDim s
  swap :: forall a b.
(ObjectPair (LinearFunction s) a b,
 ObjectPair (LinearFunction s) b a) =>
LinearFunction s (a, b) (b, a)
swap = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (k :: Type -> Type -> Type) a b.
(Cartesian k, ObjectPair k a b, ObjectPair k b a) =>
k (a, b) (b, a)
swap
  attachUnit :: forall unit a.
(unit ~ UnitObject (LinearFunction s),
 ObjectPair (LinearFunction s) a unit) =>
LinearFunction s a (a, unit)
attachUnit = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (, forall s. ZeroDim s
Origin)
  detachUnit :: forall unit a.
(unit ~ UnitObject (LinearFunction s),
 ObjectPair (LinearFunction s) a unit) =>
LinearFunction s (a, unit) a
detachUnit = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (a :: Type -> Type -> Type) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst
  regroup :: forall a b c.
(ObjectPair (LinearFunction s) a b,
 ObjectPair (LinearFunction s) b c,
 ObjectPair (LinearFunction s) a (b, c),
 ObjectPair (LinearFunction s) (a, b) c) =>
LinearFunction s (a, (b, c)) ((a, b), c)
regroup = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (k :: Type -> Type -> Type) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k (a, (b, c)) ((a, b), c)
regroup
  regroup' :: forall a b c.
(ObjectPair (LinearFunction s) a b,
 ObjectPair (LinearFunction s) b c,
 ObjectPair (LinearFunction s) a (b, c),
 ObjectPair (LinearFunction s) (a, b) c) =>
LinearFunction s ((a, b), c) (a, (b, c))
regroup' = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (k :: Type -> Type -> Type) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k ((a, b), c) (a, (b, c))
regroup'
instance Num' s => Morphism (LinearFunction s) where
  LinearFunction b -> c
f*** :: forall b b' c c'.
(ObjectPair (LinearFunction s) b b',
 ObjectPair (LinearFunction s) c c') =>
LinearFunction s b c
-> LinearFunction s b' c' -> LinearFunction s (b, b') (c, c')
***LinearFunction b' -> c'
g = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ b -> c
fforall (a :: Type -> Type -> Type) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
***b' -> c'
g
instance Num' s => PreArrow (LinearFunction s) where
  LinearFunction b -> c
f&&& :: forall b c c'.
(Object (LinearFunction s) b,
 ObjectPair (LinearFunction s) c c') =>
LinearFunction s b c
-> LinearFunction s b c' -> LinearFunction s b (c, c')
&&&LinearFunction b -> c'
g = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ b -> c
fforall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&b -> c'
g
  fst :: forall x y.
ObjectPair (LinearFunction s) x y =>
LinearFunction s (x, y) x
fst = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (a :: Type -> Type -> Type) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst; snd :: forall x y.
ObjectPair (LinearFunction s) x y =>
LinearFunction s (x, y) y
snd = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (a :: Type -> Type -> Type) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd
  terminal :: forall b.
Object (LinearFunction s) b =>
LinearFunction s b (UnitObject (LinearFunction s))
terminal = forall w s v. AdditiveGroup w => LinearFunction s v w
const0
instance EnhancedCat (->) (LinearFunction s) where
  arr :: forall b c.
(Object (LinearFunction s) b, Object (LinearFunction s) c,
 Object (->) b, Object (->) c) =>
LinearFunction s b c -> b -> c
arr = forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
instance EnhancedCat (LinearFunction s) (VSCCoercion s) where
  arr :: forall b c.
(Object (VSCCoercion s) b, Object (VSCCoercion s) c,
 Object (LinearFunction s) b, Object (LinearFunction s) c) =>
VSCCoercion s b c -> LinearFunction s b c
arr VSCCoercion s b c
VSCCoercion = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction coerce :: forall a b. Coercible a b => a -> b
coerce

instance (LinearSpace w, Num' s, Scalar w ~ s)
     => Functor (LinearFunction s w) (LinearFunction s) (LinearFunction s) where
  fmap :: forall a b.
(Object (LinearFunction s) a,
 Object (LinearFunction s) (LinearFunction s w a),
 Object (LinearFunction s) b,
 Object (LinearFunction s) (LinearFunction s w b)) =>
LinearFunction s a b
-> LinearFunction s (LinearFunction s w a) (LinearFunction s w b)
fmap LinearFunction s a b
f = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (LinearFunction s a b
fforall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.)


sampleLinearFunctionFn :: ( LinearSpace u, LinearSpace v, TensorSpace w
                          , Scalar u ~ Scalar v, Scalar v ~ Scalar w)
                           => ((u-+>v)-+>w) -+> ((u+>v)+>w)
sampleLinearFunctionFn :: forall u v w.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ Scalar v,
 Scalar v ~ Scalar w) =>
((u -+> v) -+> w) -+> ((u +> v) +> w)
sampleLinearFunctionFn = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                \LinearFunction (Scalar w) (LinearFunction (Scalar w) u v) w
f -> forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall s v w. LinearFunction s v w -> v -> w
-+$> LinearFunction (Scalar w) (LinearFunction (Scalar w) u v) w
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear

fromLinearFn ::  s u v w . (DimensionAware u, DimensionAware v, DimensionAware w)
     => VSCCoercion s (LinearFunction s (LinearFunction s u v) w)
                      (Tensor s (LinearFunction s v u) w)
fromLinearFn :: forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn
 = forall (a :: Maybe Nat) (b :: Maybe Nat) r.
Sing a
-> Sing b -> ((ZipWithTimes a b ~ ZipWithTimes b a) => r) -> r
Maybe.zipWithTimesCommu (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u) (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v) forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

asLinearFn ::  s u v w . (DimensionAware u, DimensionAware v, DimensionAware w)
     => VSCCoercion s (Tensor s (LinearFunction s u v) w)
                       (LinearFunction s (LinearFunction s v u) w)
asLinearFn :: forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFn
 = forall (a :: Maybe Nat) (b :: Maybe Nat) r.
Sing a
-> Sing b -> ((ZipWithTimes a b ~ ZipWithTimes b a) => r) -> r
Maybe.zipWithTimesCommu (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u) (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v) forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion


instance  s u v . ( LinearSpace u, LinearSpace v
                   , DimensionAware u, DimensionAware v
                   , Scalar u ~ s, Scalar v ~ s)
     => DimensionAware (LinearFunction s u v) where
  type StaticDimension (LinearFunction s u v)
          = Maybe.ZipWithTimes (StaticDimension u) (StaticDimension v)
  dimensionalityWitness :: DimensionalityWitness (LinearFunction s u v)
dimensionalityWitness = case (forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v) of
    (DimensionalityWitness u
IsStaticDimensional, DimensionalityWitness v
IsStaticDimensional)
        -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @u forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v)
              forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    (DimensionalityWitness u
IsFlexibleDimensional, DimensionalityWitness v
_) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
    (DimensionalityWitness u
_, DimensionalityWitness v
IsFlexibleDimensional) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  s n u m v nm . ( n`Dimensional`u, m`Dimensional`v
                          , LinearSpace u, LinearSpace v, Scalar u ~ s, Scalar v ~ s
                          , nm ~ (n*m) )
                   => nm`Dimensional`(LinearFunction s u v) where
  knownDimensionalitySing :: Sing nm
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @u forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%* forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (LinearFunction s u v)) =>
Int -> α (Scalar (LinearFunction s u v)) -> LinearFunction s u v
unsafeFromArrayWithOffset Int
i α (Scalar (LinearFunction s u v))
ar
     = forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>(forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset Int
i α (Scalar (LinearFunction s u v))
ar :: LinearMap s u v)
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (LinearFunction s u v)) =>
Mutable α σ (Scalar (LinearFunction s u v))
-> Int -> LinearFunction s u v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (LinearFunction s u v))
ar Int
i
     = forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (LinearFunction s u v))
ar Int
i forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunctionforall s v w. LinearFunction s v w -> v -> w
-+$>)


instance  s u v . (LinearSpace u, LinearSpace v, Scalar u ~ s, Scalar v ~ s)
     => TensorSpace (LinearFunction s u v) where
  type TensorProduct (LinearFunction s u v) w = LinearFunction s (LinearFunction s v u) w
  scalarSpaceWitness :: ScalarSpaceWitness (LinearFunction s u v)
scalarSpaceWitness = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                            , forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness v ) of
       (ScalarSpaceWitness u
ScalarSpaceWitness, ScalarSpaceWitness v
ScalarSpaceWitness) -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (LinearFunction s u v)
linearManifoldWitness = case ( forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness u
                             , forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness v ) of
       ( LinearManifoldWitness u
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
          BoundarylessWitness
#endif
        ,LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
          BoundarylessWitness
#endif
        )
         -> forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
             BoundarylessWitness
#endif
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
LinearFunction s u v ⊗ w
zeroTensor = forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall w s v. AdditiveGroup w => LinearFunction s v w
const0
  toFlatTensor :: LinearFunction s u v
-+> (LinearFunction s u v ⊗ Scalar (LinearFunction s u v))
toFlatTensor = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
     ScalarSpaceWitness u
ScalarSpaceWitness -> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVector
  fromFlatTensor :: (LinearFunction s u v ⊗ Scalar (LinearFunction s u v))
-+> LinearFunction s u v
fromFlatTensor = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u
                        , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u ) of
     (ScalarSpaceWitness u
ScalarSpaceWitness, DualSpaceWitness u
DualSpaceWitness)
            -> forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFn forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`
                     \LinearFunction s (LinearFunction s v u) s
f -> let t :: Tensor (Scalar (DualVector u)) (DualVector u) v
t = forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>forall v. LinearSpace v => (v +> Scalar v) -+> DualVector v
fromLinearForm)
                                 forall s v w. LinearFunction s v w -> 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
                                  forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunctionforall s v w. LinearFunction s v w -> v -> w
-+$> LinearFunction s (LinearFunction s v u) s
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear
                           in forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (DualVector u)) (DualVector u) v
t
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
(LinearFunction s u v ⊗ w)
-> (LinearFunction s u v ⊗ w) -> LinearFunction s u v ⊗ w
addTensors LinearFunction s u v ⊗ w
t LinearFunction s u v ⊗ w
s = forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn forall s a b. VSCCoercion s a b -> a -> b
-+$=> (forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>LinearFunction s u v ⊗ w
t)forall v. AdditiveGroup v => v -> v -> v
^+^(forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>LinearFunction s u v ⊗ w
s)
  subtractTensors :: forall w.
(TensorSpace (LinearFunction s u v), TensorSpace w,
 Scalar w ~ Scalar (LinearFunction s u v)) =>
(LinearFunction s u v ⊗ w)
-> (LinearFunction s u v ⊗ w) -> LinearFunction s u v ⊗ w
subtractTensors LinearFunction s u v ⊗ w
t LinearFunction s u v ⊗ w
s = forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn forall s a b. VSCCoercion s a b -> a -> b
-+$=> (forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>LinearFunction s u v ⊗ w
t)forall v. AdditiveGroup v => v -> v -> v
^-^(forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>LinearFunction s u v ⊗ w
s)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
Bilinear
  (Scalar (LinearFunction s u v))
  (LinearFunction s u v ⊗ w)
  (LinearFunction s u v ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \s
μ (Tensor TensorProduct (LinearFunction s u v) w
f) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s
μ forall v. VectorSpace v => Scalar v -> v -> v
*^ TensorProduct (LinearFunction s u v) w
f
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
(LinearFunction s u v ⊗ w) -+> (LinearFunction s u v ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (LinearFunction s u v) w
f) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. AdditiveGroup v => v -> v
negateV TensorProduct (LinearFunction s u v) w
f
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
Bilinear (LinearFunction s u v) w (LinearFunction s u v ⊗ w)
tensorProduct = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
        ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s u v
uv w
w -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                     (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction s u v
uv) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v s.
(VectorSpace v, Scalar v ~ s) =>
v -> LinearFunction s s v
scaleV w
w
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
(LinearFunction s u v ⊗ w) -+> (w ⊗ LinearFunction s u v)
transposeTensor = forall w.
(TensorSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness u
-> Tensor s (LinearFunction s u v) w
   -+> Tensor s w (LinearFunction s u v)
tt forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where tt ::  w . (TensorSpace w, Scalar w ~ s)
                   => ScalarSpaceWitness u -> DualSpaceWitness u
                        -> Tensor s (LinearFunction s u v) w
                           -+> Tensor s w (LinearFunction s u v)
         tt :: forall w.
(TensorSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness u
-> Tensor s (LinearFunction s u v) w
   -+> Tensor s w (LinearFunction s u v)
tt ScalarSpaceWitness u
ScalarSpaceWitness DualSpaceWitness u
DualSpaceWitness
           = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> \LinearFunction (Scalar w) (LinearFunction (Scalar u) v u) w
f
               -> (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear)
                          forall s v w. LinearFunction s v w -> v -> w
-+$> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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))
rassocTensor
                           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                          forall s v w. LinearFunction s v w -> v -> w
-+$> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. 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
                            forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall u v w.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ Scalar v,
 Scalar v ~ Scalar w) =>
((u -+> v) -+> w) -+> ((u +> v) +> w)
sampleLinearFunctionFn forall s v w. LinearFunction s v w -> v -> w
-+$> LinearFunction (Scalar w) (LinearFunction (Scalar u) v u) w
f
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x,
 Scalar w ~ Scalar (LinearFunction s u v),
 Scalar x ~ Scalar (LinearFunction s u v)) =>
Bilinear
  (w -+> x) (LinearFunction s u v ⊗ w) (LinearFunction s u v ⊗ x)
fmapTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s w x
f -> (forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>)
                 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> \LinearFunction s (LinearFunction s v u) w
g -> forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn forall s a b. VSCCoercion s a b -> a -> b
-+$=> LinearFunction s w x
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction s (LinearFunction s v u) w
g
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (LinearFunction s u v),
 Scalar w ~ Scalar (LinearFunction s u v),
 Scalar x ~ Scalar (LinearFunction s u v)) =>
Bilinear
  ((w, x) -+> u)
  (LinearFunction s u v ⊗ w, LinearFunction s u v ⊗ x)
  (LinearFunction s u v ⊗ u)
fzipTensorWith = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
     ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s (w, x) u
f (Tensor s (LinearFunction s u v) w
g,Tensor s (LinearFunction s u v) x
h)
                    -> forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn forall s a b. VSCCoercion s a b -> a -> b
-+$=>
                          LinearFunction s (w, x) u
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. ((forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>Tensor s (LinearFunction s u v) w
g)forall (a :: Type -> Type -> Type) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&(forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>Tensor s (LinearFunction s u v) x
h))
  tensorUnsafeFromArrayWithOffset ::  nm w o α
          . ( nm`Dimensional`LinearFunction s u v
            , TensorSpace w, o`Dimensional`w, Scalar w ~ s
            , GArr.Vector α s )
           => Int -> α s -> (LinearFunction s u vw)
  tensorUnsafeFromArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type).
(Dimensional nm (LinearFunction s u v), TensorSpace w,
 Dimensional o w, Scalar w ~ s, Vector α s) =>
Int -> α s -> LinearFunction s u v ⊗ w
tensorUnsafeFromArrayWithOffset
     = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u
            , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v ) of
        ( DimensionalityWitness u
IsStaticDimensional, SJust Sing n
sn
         ,DimensionalityWitness v
IsStaticDimensional, SJust Sing n
sm )
           -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*Sing n
sn) (
              forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat ((Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*Sing n
sn)forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w) (
               \Int
i -> (forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFn @s @v @u @w forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>)
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset Int
i ))
  tensorUnsafeWriteArrayWithOffset ::  nm w o α σ
          . ( nm`Dimensional`LinearFunction s u v
            , TensorSpace w, o`Dimensional`w, Scalar w ~ s
            , GArr.Vector α s )
           => GArr.Mutable α σ s -> Int -> (LinearFunction s u vw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall (nm :: Nat) w (o :: Nat) (α :: Type -> Type) σ.
(Dimensional nm (LinearFunction s u v), TensorSpace w,
 Dimensional o w, Scalar w ~ s, Vector α s) =>
Mutable α σ s -> Int -> (LinearFunction s u v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
     = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @u, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u
            , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v, forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @v ) of
        ( DimensionalityWitness u
IsStaticDimensional, SJust Sing n
sn
         ,DimensionalityWitness v
IsStaticDimensional, SJust Sing n
sm )
           -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*Sing n
sn) (
              forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat ((Sing n
smforall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*Sing n
sn)forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (*@#@$) t1) t2)
%*forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @w) (
               \Mutable α σ (Scalar (LinearMap s (LinearFunction s v u) w))
ar Int
i -> forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (LinearMap s (LinearFunction s v u) w))
ar Int
i
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunctionforall s v w. LinearFunction s v w -> v -> w
-+$>)
                       forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFn @s @u @v @w forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
                       ))
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a,
 Scalar a ~ Scalar (LinearFunction s u v), TensorSpace b,
 Scalar b ~ Scalar (LinearFunction s u v)) =>
p (LinearFunction s u v)
-> VSCCoercion (Scalar (LinearFunction s u v)) a b
-> Coercion
     (TensorProduct (LinearFunction s u v) a)
     (TensorProduct (LinearFunction s u v) b)
coerceFmapTensorProduct p (LinearFunction s u v)
_ VSCCoercion (Scalar (LinearFunction s u v)) a b
VSCCoercion = forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
  wellDefinedVector :: LinearFunction s u v -> Maybe (LinearFunction s u v)
wellDefinedVector = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. TensorSpace v => v -> Maybe v
wellDefinedVector
                       forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear)
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
(LinearFunction s u v ⊗ w) -> Maybe (LinearFunction s u v ⊗ w)
wellDefinedTensor = (forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> (forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear)
                       forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction
                       forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall v. TensorSpace v => v -> Maybe v
wellDefinedVector
                       forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 ((forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (LinearFunction s (LinearFunction s u v) w)
  (Tensor s (LinearFunction s v u) w)
fromLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>) forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< \LinearMap (Scalar v) (LinearMap (Scalar v) v u) w
m
                                   -> forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction
                                      forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear LinearMap (Scalar v) (LinearMap (Scalar v) v u) w
m)

exposeLinearFn :: VSCCoercion s (LinearMap s (LinearFunction s u v) w)
                                (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn :: forall s u v w.
VSCCoercion
  s
  (LinearMap s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

instance (LinearSpace u, LinearSpace v, Scalar u ~ s, Scalar v ~ s)
     => LinearSpace (LinearFunction s u v) where
  type DualVector (LinearFunction s u v) = LinearFunction s v u
  dualSpaceWitness :: DualSpaceWitness (LinearFunction s u v)
dualSpaceWitness = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness u
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
      (DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
        -> forall (a :: Maybe Nat) (b :: Maybe Nat) r.
Sing a
-> Sing b -> ((ZipWithTimes a b ~ ZipWithTimes b a) => r) -> r
Maybe.zipWithTimesCommu (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @u) (forall v. DimensionAware v => Sing (StaticDimension v)
staticDimensionSing @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 :: LinearFunction s u v +> LinearFunction s u v
linearId = forall s a b. VSCCoercion s a b -> VSCCoercion s b a
symVSC forall s u v w.
VSCCoercion
  s
  (LinearMap s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
id
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
(LinearFunction s u v ⊗ w) +> (LinearFunction s u v ⊗ w)
tensorId = 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s a b. VSCCoercion s a b -> VSCCoercion s b a
symVSC forall s u v w.
VSCCoercion
  s
  (LinearMap s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn
               forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s u v
f -> forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunctionforall s v w. LinearFunction s v w -> v -> w
-+$>forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction s u v
f
  coerceDoubleDual :: VSCCoercion
  (Scalar (LinearFunction s u v))
  (LinearFunction s u v)
  (DualVector (DualVector (LinearFunction s u v)))
coerceDoubleDual = forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
  sampleLinearFunction :: forall w.
(TensorSpace w, Scalar (LinearFunction s u v) ~ Scalar w) =>
(LinearFunction s u v -+> w) -+> (LinearFunction s u v +> w)
sampleLinearFunction = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s a b. VSCCoercion s a b -> a -> b
(-+$=>) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s a b. VSCCoercion s a b -> VSCCoercion s b a
symVSC forall s u v w.
VSCCoercion
  s
  (LinearMap s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn
  applyDualVector :: LinearSpace (LinearFunction s u v) =>
Bilinear
  (DualVector (LinearFunction s u v))
  (LinearFunction s u v)
  (Scalar (LinearFunction s u v))
applyDualVector = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
       ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                      \LinearFunction s v u
f LinearFunction s u v
g -> forall v. LinearSpace v => LinearMap (Scalar v) v v -+> Scalar v
trace forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall s v w. LinearFunction s v w -> v -> w
-+$> LinearFunction s v u
f forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction s u v
g
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (LinearFunction s u v)) =>
Bilinear (LinearFunction s u v +> w) (LinearFunction s u v) w
applyLinear = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap s (LinearFunction s u v) w
f LinearFunction s u v
g -> (forall s u v w.
VSCCoercion
  s
  (LinearMap s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn forall s a b. VSCCoercion s a b -> a -> b
-+$=> LinearMap s (LinearFunction s u v) w
f) forall s v w. LinearFunction s v w -> v -> w
-+$> LinearFunction s u v
g
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (LinearFunction s u v)) =>
Bilinear
  (DualVector (LinearFunction s u v ⊗ u))
  (LinearFunction s u v ⊗ u)
  (Scalar (LinearFunction s u v))
applyTensorFunctional = forall w.
(LinearSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness w
-> LinearFunction
     s
     (LinearMap s (LinearFunction s u v) (DualVector w))
     (LinearFunction s (Tensor s (LinearFunction s u v) w) s)
atf forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where atf ::  w . (LinearSpace w, Scalar w ~ s)
                => ScalarSpaceWitness u -> DualSpaceWitness w
                -> LinearFunction s
                    (LinearMap s (LinearFunction s u v) (DualVector w))
                    (LinearFunction s (Tensor s (LinearFunction s u v) w) s)
         atf :: forall w.
(LinearSpace w, Scalar w ~ s) =>
ScalarSpaceWitness u
-> DualSpaceWitness w
-> LinearFunction
     s
     (LinearMap s (LinearFunction s u v) (DualVector w))
     (LinearFunction s (Tensor s (LinearFunction s u v) w) s)
atf ScalarSpaceWitness u
ScalarSpaceWitness DualSpaceWitness w
DualSpaceWitness = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap s (LinearFunction s u v) (DualVector w)
f Tensor s (LinearFunction s u v) w
g
                  -> forall v. LinearSpace v => LinearMap (Scalar v) v v -+> Scalar v
trace forall s v w. LinearFunction s v w -> v -> w
-+$> forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                      forall s v w. LinearFunction s v w -> v -> w
-+$> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 ((forall s u v w.
VSCCoercion
  s
  (LinearMap s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (LinearFunction s u v) (DualVector w)
f) forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear)
                          forall s v w. LinearFunction s v w -> v -> w
-+$> ( forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                              forall s v w. LinearFunction s v w -> 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
                              forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                              forall s v w. LinearFunction s v w -> 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))
hasteLinearMap
                              forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                              forall s v w. LinearFunction s v w -> 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
                              forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall u v w.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ Scalar v,
 Scalar v ~ Scalar w) =>
((u -+> v) -+> w) -+> ((u +> v) +> w)
sampleLinearFunctionFn
                              forall s v w. LinearFunction s v w -> v -> w
-+$> forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFn forall s a b. VSCCoercion s a b -> a -> b
-+$=> Tensor s (LinearFunction s u v) w
g )
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w,
 Scalar u ~ Scalar (LinearFunction s u v),
 Scalar w ~ Scalar (LinearFunction s u v)) =>
Bilinear
  ((LinearFunction s u v ⊗ u) +> w) (LinearFunction s u v ⊗ u) w
applyTensorLinMap = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness u of
         ScalarSpaceWitness u
ScalarSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap s (Tensor s (LinearFunction s u v) u) w
f Tensor s (LinearFunction s u v) u
g
                 -> forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ (v +> w)) -+> w
contractMapTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                   forall s v w. LinearFunction s v w -> v -> w
-+$> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 ((forall s u v w.
(DimensionAware u, DimensionAware v, DimensionAware w) =>
VSCCoercion
  s
  (Tensor s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s v u) w)
asLinearFnforall s a b. VSCCoercion s a b -> a -> b
-+$=>Tensor s (LinearFunction s u v) u
g) forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear)
                    forall s v w. LinearFunction s v w -> v -> w
-+$> ( forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                      forall s v w. LinearFunction s v w -> 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
                      forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                      forall s v w. LinearFunction s v w -> 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))
hasteLinearMap
                      forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
                      forall s v w. LinearFunction s v w -> 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
                      forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall u v w.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ Scalar v,
 Scalar v ~ Scalar w) =>
((u -+> v) -+> w) -+> ((u +> v) +> w)
sampleLinearFunctionFn
                      forall s v w. LinearFunction s v w -> v -> w
-+$> forall s u v w.
VSCCoercion
  s
  (LinearMap s (LinearFunction s u v) w)
  (LinearFunction s (LinearFunction s u v) w)
exposeLinearFn
                      forall s a b. VSCCoercion s a b -> a -> b
-+$=> 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 forall s a b. VSCCoercion s a b -> a -> b
-+$=> LinearMap s (Tensor s (LinearFunction s u v) u) w
f )
  useTupleLinearSpaceComponents :: forall x y φ.
(LinearFunction s u v ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = forall a. a
usingNonTupleTypeAsTupleError


instance (TensorSpace u, TensorSpace v, s~Scalar u, s~Scalar v)
                      => AffineSpace (Tensor s u v) where
  type Diff (Tensor s u v) = Tensor s u v
  .-. :: Tensor s u v -> Tensor s u v -> Diff (Tensor s u v)
(.-.) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
  .+^ :: Tensor s u v -> Diff (Tensor s u v) -> Tensor s u v
(.+^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
instance (LinearSpace u, TensorSpace v, s~Scalar u, s~Scalar v)
                      => AffineSpace (LinearMap s u v) where
  type Diff (LinearMap s u v) = LinearMap s u v
  .-. :: LinearMap s u v -> LinearMap s u v -> Diff (LinearMap s u v)
(.-.) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
  .+^ :: LinearMap s u v -> Diff (LinearMap s u v) -> LinearMap s u v
(.+^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
instance (TensorSpace u, TensorSpace v, s~Scalar u, s~Scalar v)
                      => AffineSpace (LinearFunction s u v) where
  type Diff (LinearFunction s u v) = LinearFunction s u v
  .-. :: LinearFunction s u v
-> LinearFunction s u v -> Diff (LinearFunction s u v)
(.-.) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
  .+^ :: LinearFunction s u v
-> Diff (LinearFunction s u v) -> LinearFunction s u v
(.+^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)

  
-- | Use a function as a linear map. This is only well-defined if the function /is/
--   linear (this condition is not checked).
lfun :: ( EnhancedCat f (LinearFunction s)
        , LinearSpace u, TensorSpace v, Scalar u ~ s, Scalar v ~ s
        , Object f u, Object f v ) => (u->v) -> f u v
lfun :: forall (f :: Type -> Type -> Type) s u v.
(EnhancedCat f (LinearFunction s), LinearSpace u, TensorSpace v,
 Scalar u ~ s, Scalar v ~ s, Object f u, Object f v) =>
(u -> v) -> f u v
lfun = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction


genericTensorspaceError :: a
genericTensorspaceError :: forall a. a
genericTensorspaceError = forall a. HasCallStack => [Char] -> a
error [Char]
"GHC.Generics types can not be used as tensor spaces."

usingNonTupleTypeAsTupleError :: a
usingNonTupleTypeAsTupleError :: forall a. a
usingNonTupleTypeAsTupleError = forall a. HasCallStack => [Char] -> a
error [Char]
"This is not a tuple type, the method should not be callable."

instance  v s . DimensionAware v => DimensionAware (Gnrx.Rec0 v s) where
  type StaticDimension (Gnrx.Rec0 v s) = StaticDimension v
  dimensionalityWitness :: DimensionalityWitness (Rec0 v s)
dimensionalityWitness = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v of
    DimensionalityWitness v
IsStaticDimensional -> forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    DimensionalityWitness v
IsFlexibleDimensional -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  n v s . n`Dimensional`v => n`Dimensional`(Gnrx.Rec0 v s) where
  knownDimensionalitySing :: Sing n
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (Rec0 v s)) =>
Int -> α (Scalar (Rec0 v s)) -> Rec0 v s
unsafeFromArrayWithOffset Int
i α (Scalar (Rec0 v s))
ar
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset @n @v Int
i α (Scalar (Rec0 v s))
ar)
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (Rec0 v s)) =>
Mutable α σ (Scalar (Rec0 v s)) -> Int -> Rec0 v s -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (Rec0 v s))
i Int
ar
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset @n @v Mutable α σ (Scalar (Rec0 v s))
i Int
ar)

instance  v s . TensorSpace v => TensorSpace (Gnrx.Rec0 v s) where
  type TensorProduct (Gnrx.Rec0 v s) w = TensorProduct v w
  wellDefinedVector :: Rec0 v s -> Maybe (Rec0 v s)
wellDefinedVector = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall k i c (p :: k). c -> K1 i c p
Gnrx.K1 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v. TensorSpace v => v -> Maybe v
wellDefinedVector forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
(Rec0 v s ⊗ w) -> Maybe (Rec0 v s ⊗ w)
wellDefinedTensor = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1)
                         forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1)
  scalarSpaceWitness :: ScalarSpaceWitness (Rec0 v s)
scalarSpaceWitness = forall a. a
genericTensorspaceError
  linearManifoldWitness :: LinearManifoldWitness (Rec0 v s)
linearManifoldWitness = forall a. a
genericTensorspaceError
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
Rec0 v s ⊗ w
zeroTensor = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  toFlatTensor :: Rec0 v s -+> (Rec0 v s ⊗ Scalar (Rec0 v s))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor
                   forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  fromFlatTensor :: (Rec0 v s ⊗ Scalar (Rec0 v s)) -+> Rec0 v s
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall k i c (p :: k). c -> K1 i c p
Gnrx.K1 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
                   forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
(Rec0 v s ⊗ w) -> (Rec0 v s ⊗ w) -> Rec0 v s ⊗ w
addTensors (Tensor TensorProduct (Rec0 v s) w
s) (Tensor TensorProduct (Rec0 v s) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
addTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (Rec0 v s) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (Rec0 v s) w
t)
  subtractTensors :: forall w.
(TensorSpace (Rec0 v s), TensorSpace w,
 Scalar w ~ Scalar (Rec0 v s)) =>
(Rec0 v s ⊗ w) -> (Rec0 v s ⊗ w) -> Rec0 v s ⊗ w
subtractTensors (Tensor TensorProduct (Rec0 v s) w
s) (Tensor TensorProduct (Rec0 v s) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace v, TensorSpace w,
 Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
subtractTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (Rec0 v s) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (Rec0 v s) w
t)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
Bilinear (Scalar (Rec0 v s)) (Rec0 v s ⊗ w) (Rec0 v s ⊗ w)
scaleTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar v
μ -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall k i c (p :: k). c -> K1 i c p
Gnrx.K1
                                         forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar v
μ
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
(Rec0 v s ⊗ w) -+> (Rec0 v s ⊗ w)
negateTensor = forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall k i c (p :: k). c -> K1 i c p
Gnrx.K1 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensor
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
Bilinear (Rec0 v s) w (Rec0 v s ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Gnrx.K1 v
v) w
w
                      -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1
                           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>v
v)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
(Rec0 v s ⊗ w) -+> (w ⊗ Rec0 v s)
transposeTensor = forall w.
(TensorSpace w, Scalar w ~ Scalar v) =>
(Rec0 v s ⊗ w) -+> (w ⊗ Rec0 v s)
tT
   where tT ::  w . (TensorSpace w, Scalar w ~ Scalar v)
                => (Gnrx.Rec0 v s  w) -+> (w  Gnrx.Rec0 v s)
         tT :: forall w.
(TensorSpace w, Scalar w ~ Scalar v) =>
(Rec0 v s ⊗ w) -+> (w ⊗ Rec0 v s)
tT = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction
           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct @w []
                               (forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion :: VSCCoercion (Scalar v) v (Gnrx.Rec0 v s))
                           forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion)
              forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (Rec0 v s),
 Scalar x ~ Scalar (Rec0 v s)) =>
Bilinear (w -+> x) (Rec0 v s ⊗ w) (Rec0 v s ⊗ x)
fmapTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar v) w x
f -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall k i c (p :: k). c -> K1 i c p
Gnrx.K1 (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar v) w x
f)
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (Rec0 v s), Scalar w ~ Scalar (Rec0 v s),
 Scalar x ~ Scalar (Rec0 v s)) =>
Bilinear ((w, x) -+> u) (Rec0 v s ⊗ w, Rec0 v s ⊗ x) (Rec0 v s ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar v) (w, x) u
f (Tensor (Scalar v) (Rec0 v s) w
wt, Tensor (Scalar v) (Rec0 v s) x
xt) -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1
                        forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar v) (w, x) u
f)
                         forall s v w. LinearFunction s v w -> v -> w
-+$>( forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (Rec0 v s) w
wt
                             , forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (Rec0 v s) x
xt )
  tensorUnsafeFromArrayWithOffset
   ::  w m a . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar v
                , GArr.Vector a (Scalar v) )
           => Int -> a (Scalar v) -> (Gnrx.Rec0 v sw)
  tensorUnsafeFromArrayWithOffset :: forall w (m :: Nat) (a :: Type -> Type).
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar v,
 Vector a (Scalar v)) =>
Int -> a (Scalar v) -> Rec0 v s ⊗ w
tensorUnsafeFromArrayWithOffset = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v of
    DimensionalityWitness v
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `v` is static-dimensional."
    DimensionalityWitness v
IsStaticDimensional -> \Int
i a (Scalar v)
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffset @v @w Int
i a (Scalar v)
ar)
  tensorUnsafeWriteArrayWithOffset
   ::  w m α σ . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar v
                , GArr.Vector α (Scalar v) )
           => GArr.Mutable α σ (Scalar v) -> Int -> (Gnrx.Rec0 v sw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall w (m :: Nat) (α :: Type -> Type) σ.
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar v,
 Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (Rec0 v s ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v of
    DimensionalityWitness v
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `v` is static-dimensional."
    DimensionalityWitness v
IsStaticDimensional -> \Mutable α σ (Scalar v)
ar -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset @v @w Mutable α σ (Scalar v)
ar)
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (Rec0 v s),
 TensorSpace b, Scalar b ~ Scalar (Rec0 v s)) =>
p (Rec0 v s)
-> VSCCoercion (Scalar (Rec0 v s)) a b
-> Coercion
     (TensorProduct (Rec0 v s) a) (TensorProduct (Rec0 v s) b)
coerceFmapTensorProduct = forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar v, TensorSpace b,
 Scalar b ~ Scalar v) =>
p (Rec0 v s)
-> VSCCoercion (Scalar v) a b
-> Coercion
     (TensorProduct (Rec0 v s) a) (TensorProduct (Rec0 v s) b)
cmtp
   where cmtp ::  p a b . ( Hask.Functor p
                           , TensorSpace a, Scalar a ~ Scalar v
                           , TensorSpace b, Scalar b ~ Scalar v )
             => p (Gnrx.Rec0 v s) -> VSCCoercion (Scalar v) a b
               -> Coercion (TensorProduct (Gnrx.Rec0 v s) a)
                           (TensorProduct (Gnrx.Rec0 v s) b)
         cmtp :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar v, TensorSpace b,
 Scalar b ~ Scalar v) =>
p (Rec0 v s)
-> VSCCoercion (Scalar v) a b
-> Coercion
     (TensorProduct (Rec0 v s) a) (TensorProduct (Rec0 v s) b)
cmtp p (Rec0 v s)
p VSCCoercion (Scalar v) a b
crc = case forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct @v [] VSCCoercion (Scalar v) a b
crc of
                  Coercion (TensorProduct v a) (TensorProduct v b)
Coercion -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion

instance  i c f p . DimensionAware (f p) => DimensionAware (Gnrx.M1 i c f p) where
  type StaticDimension (Gnrx.M1 i c f p) = StaticDimension (f p)
  dimensionalityWitness :: DimensionalityWitness (M1 i c f p)
dimensionalityWitness = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(f p) of
    DimensionalityWitness (f p)
IsStaticDimensional -> forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    DimensionalityWitness (f p)
IsFlexibleDimensional -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  n i c f p . n`Dimensional`f p => n`Dimensional`Gnrx.M1 i c f p where
  knownDimensionalitySing :: Sing n
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(f p)
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (M1 i c f p)) =>
Int -> α (Scalar (M1 i c f p)) -> M1 i c f p
unsafeFromArrayWithOffset Int
i α (Scalar (M1 i c f p))
ar
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset @n @(f p) Int
i α (Scalar (M1 i c f p))
ar)
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (M1 i c f p)) =>
Mutable α σ (Scalar (M1 i c f p)) -> Int -> M1 i c f p -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (M1 i c f p))
i Int
ar
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset @n @(f p) Mutable α σ (Scalar (M1 i c f p))
i Int
ar)

instance  i c f p . TensorSpace (f p) => TensorSpace (Gnrx.M1 i c f p) where
  type TensorProduct (Gnrx.M1 i c f p) w = TensorProduct (f p) w
  wellDefinedVector :: M1 i c f p -> Maybe (M1 i c f p)
wellDefinedVector = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v. TensorSpace v => v -> Maybe v
wellDefinedVector forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
(M1 i c f p ⊗ w) -> Maybe (M1 i c f p ⊗ w)
wellDefinedTensor = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1)
                         forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1)
  scalarSpaceWitness :: ScalarSpaceWitness (M1 i c f p)
scalarSpaceWitness = forall a. a
genericTensorspaceError
  linearManifoldWitness :: LinearManifoldWitness (M1 i c f p)
linearManifoldWitness = forall a. a
genericTensorspaceError
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
M1 i c f p ⊗ w
zeroTensor = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  toFlatTensor :: M1 i c f p -+> (M1 i c f p ⊗ Scalar (M1 i c f p))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor
                   forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  fromFlatTensor :: (M1 i c f p ⊗ Scalar (M1 i c f p)) -+> M1 i c f p
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1 forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
                   forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
(M1 i c f p ⊗ w) -> (M1 i c f p ⊗ w) -> M1 i c f p ⊗ w
addTensors (Tensor TensorProduct (M1 i c f p) w
s) (Tensor TensorProduct (M1 i c f p) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
addTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (M1 i c f p) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (M1 i c f p) w
t)
  subtractTensors :: forall w.
(TensorSpace (M1 i c f p), TensorSpace w,
 Scalar w ~ Scalar (M1 i c f p)) =>
(M1 i c f p ⊗ w) -> (M1 i c f p ⊗ w) -> M1 i c f p ⊗ w
subtractTensors (Tensor TensorProduct (M1 i c f p) w
s) (Tensor TensorProduct (M1 i c f p) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace v, TensorSpace w,
 Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
subtractTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (M1 i c f p) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (M1 i c f p) w
t)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
Bilinear (Scalar (M1 i c f p)) (M1 i c f p ⊗ w) (M1 i c f p ⊗ w)
scaleTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar (f p)
μ -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1
                                         forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar (f p)
μ
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
(M1 i c f p ⊗ w) -+> (M1 i c f p ⊗ w)
negateTensor = forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1 forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensor
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
Bilinear (M1 i c f p) w (M1 i c f p ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Gnrx.M1 f p
v) w
w
                      -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1
                           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>f p
v)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
(M1 i c f p ⊗ w) -+> (w ⊗ M1 i c f p)
transposeTensor = forall w.
(TensorSpace w, Scalar w ~ Scalar (f p)) =>
(M1 i c f p ⊗ w) -+> (w ⊗ M1 i c f p)
tT
   where tT ::  w . (TensorSpace w, Scalar w ~ Scalar (f p))
                => (Gnrx.M1 i c f p  w) -+> (w  Gnrx.M1 i c f p)
         tT :: forall w.
(TensorSpace w, Scalar w ~ Scalar (f p)) =>
(M1 i c f p ⊗ w) -+> (w ⊗ M1 i c f p)
tT = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction
           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ([]::[w])
                                (forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion :: VSCCoercion s (f p) (Gnrx.M1 i c f p))
                           forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion)
              forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (M1 i c f p),
 Scalar x ~ Scalar (M1 i c f p)) =>
Bilinear (w -+> x) (M1 i c f p ⊗ w) (M1 i c f p ⊗ x)
fmapTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar (f p)) w x
f -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1 (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (f p)) w x
f)
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (M1 i c f p), Scalar w ~ Scalar (M1 i c f p),
 Scalar x ~ Scalar (M1 i c f p)) =>
Bilinear
  ((w, x) -+> u) (M1 i c f p ⊗ w, M1 i c f p ⊗ x) (M1 i c f p ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar (f p)) (w, x) u
f (Tensor (Scalar (f p)) (M1 i c f p) w
wt, Tensor (Scalar (f p)) (M1 i c f p) x
xt) -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1
                        forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (f p)) (w, x) u
f)
                         forall s v w. LinearFunction s v w -> v -> w
-+$>( forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (f p)) (M1 i c f p) w
wt
                             , forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (f p)) (M1 i c f p) x
xt )
  tensorUnsafeFromArrayWithOffset
   ::  w m a . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar (f p)
                , GArr.Vector a (Scalar (f p)) )
           => Int -> a (Scalar (f p)) -> (Gnrx.M1 i c f pw)
  tensorUnsafeFromArrayWithOffset :: forall w (m :: Nat) (a :: Type -> Type).
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar (f p),
 Vector a (Scalar (f p))) =>
Int -> a (Scalar (f p)) -> M1 i c f p ⊗ w
tensorUnsafeFromArrayWithOffset = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(f p) of
    DimensionalityWitness (f p)
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `f p` is static-dimensional."
    DimensionalityWitness (f p)
IsStaticDimensional -> \Int
i a (Scalar (f p))
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffset @(f p) @w Int
i a (Scalar (f p))
ar)
  tensorUnsafeWriteArrayWithOffset
   ::  w m α σ . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar (f p)
                  , GArr.Vector α (Scalar (f p)) )
           => GArr.Mutable α σ (Scalar (f p)) -> Int -> (Gnrx.M1 i c f pw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall w (m :: Nat) (α :: Type -> Type) σ.
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar (f p),
 Vector α (Scalar (f p))) =>
Mutable α σ (Scalar (f p)) -> Int -> (M1 i c f p ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(f p) of
    DimensionalityWitness (f p)
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `f p` is static-dimensional."
    DimensionalityWitness (f p)
IsStaticDimensional -> \Mutable α σ (Scalar (f p))
ar ->
       coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset @(f p) @w Mutable α σ (Scalar (f p))
ar)
  coerceFmapTensorProduct ::   a b
         . (Hask.Functor , TensorSpace a, Scalar a ~ Scalar (f p)
                           , TensorSpace b, Scalar b ~ Scalar (f p) ) 
             =>  (Gnrx.M1 i c f p) -> VSCCoercion (Scalar (f p)) a b
               -> Coercion (TensorProduct (Gnrx.M1 i c f p) a)
                           (TensorProduct (Gnrx.M1 i c f p) b)
  coerceFmapTensorProduct :: forall (ぴ :: Type -> Type) a b.
(Functor ぴ, TensorSpace a, Scalar a ~ Scalar (f p), TensorSpace b,
 Scalar b ~ Scalar (f p)) =>
ぴ (M1 i c f p)
-> VSCCoercion (Scalar (f p)) a b
-> Coercion
     (TensorProduct (M1 i c f p) a) (TensorProduct (M1 i c f p) b)
coerceFmapTensorProduct ぴ (M1 i c f p)
p VSCCoercion (Scalar (f p)) a b
crc = case forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ([]::[f p]) VSCCoercion (Scalar (f p)) a b
crc of
                  Coercion (TensorProduct (f p) a) (TensorProduct (f p) b)
Coercion -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion

instance  f g p . ( DimensionAware (f p), DimensionAware (g p)
                   , Scalar (f p) ~ Scalar (g p) )
                       => DimensionAware ((f:*:g) p) where
  type StaticDimension ((f:*:g) p)
           = Maybe.ZipWithPlus (StaticDimension (f p)) (StaticDimension (g p))
  dimensionalityWitness :: DimensionalityWitness ((:*:) f g p)
dimensionalityWitness = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(f p)
                               , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(g p) ) of
    (DimensionalityWitness (f p)
IsStaticDimensional, DimensionalityWitness (g p)
IsStaticDimensional)
        -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(f p) forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(g p))
              forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    (DimensionalityWitness (f p)
IsFlexibleDimensional, DimensionalityWitness (g p)
_) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
    (DimensionalityWitness (f p)
_, DimensionalityWitness (g p)
IsFlexibleDimensional) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  n f m g p nm . ( n`Dimensional`(f p), m`Dimensional`(g p)
                          , Scalar (f p) ~ Scalar (g p)
                          , nm ~ (n+m) )
                   => nm`Dimensional`((f:*:g) p) where
  knownDimensionalitySing :: Sing nm
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(f p) forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(g p)
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar ((:*:) f g p)) =>
Int -> α (Scalar ((:*:) f g p)) -> (:*:) f g p
unsafeFromArrayWithOffset Int
i α (Scalar ((:*:) f g p))
ar
      = forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset Int
i α (Scalar ((:*:) f g p))
ar
        forall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset (Int
i forall a. Num a => a -> a -> a
+ forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @(f p)) α (Scalar ((:*:) f g p))
ar
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar ((:*:) f g p)) =>
Mutable α σ (Scalar ((:*:) f g p)) -> Int -> (:*:) f g p -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar ((:*:) f g p))
ar Int
i (f p
x:*:g p
y) = do
      forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar ((:*:) f g p))
ar Int
i f p
x
      forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar ((:*:) f g p))
ar (Int
i forall a. Num a => a -> a -> a
+ forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @(f p)) g p
y

instance  f g p . ( TensorSpace (f p), TensorSpace (g p), Scalar (f p) ~ Scalar (g p) )
                       => TensorSpace ((f:*:g) p) where
  type TensorProduct ((f:*:g) p) w = (f pw, g pw)
  scalarSpaceWitness :: ScalarSpaceWitness ((:*:) f g p)
scalarSpaceWitness = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                            , forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, ScalarSpaceWitness (g p)
ScalarSpaceWitness) -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness ((:*:) f g p)
linearManifoldWitness = forall a. a
genericTensorspaceError
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
(:*:) f g p ⊗ w
zeroTensor = forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor, forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
Bilinear (Scalar ((:*:) f g p)) ((:*:) f g p ⊗ w) ((:*:) f g p ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar (g p)
μ (Tensor (Tensor (Scalar (g p)) (f p) w
v,Tensor (Scalar (g p)) (g p) w
w)) ->
                 forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar (g p)
μ)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) w
v, (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar (g p)
μ)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (g p) w
w )
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
((:*:) f g p ⊗ w) -+> ((:*:) f g p ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (Tensor (Scalar (g p)) (f p) w
v,Tensor (Scalar (g p)) (g p) w
w))
          -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) w
v, forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (g p) w
w)
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
((:*:) f g p ⊗ w) -> ((:*:) f g p ⊗ w) -> (:*:) f g p ⊗ w
addTensors (Tensor (Tensor (Scalar (g p)) (f p) w
fu, Tensor (Scalar (g p)) (g p) w
fv)) (Tensor (Tensor (Scalar (g p)) (f p) w
fu', Tensor (Scalar (g p)) (g p) w
fv'))
           = forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor (Scalar (g p)) (f p) w
fu forall v. AdditiveGroup v => v -> v -> v
^+^ Tensor (Scalar (g p)) (f p) w
fu', Tensor (Scalar (g p)) (g p) w
fv forall v. AdditiveGroup v => v -> v -> v
^+^ Tensor (Scalar (g p)) (g p) w
fv')
  subtractTensors :: forall w.
(TensorSpace ((:*:) f g p), TensorSpace w,
 Scalar w ~ Scalar ((:*:) f g p)) =>
((:*:) f g p ⊗ w) -> ((:*:) f g p ⊗ w) -> (:*:) f g p ⊗ w
subtractTensors (Tensor (Tensor (Scalar (g p)) (f p) w
fu, Tensor (Scalar (g p)) (g p) w
fv)) (Tensor (Tensor (Scalar (g p)) (f p) w
fu', Tensor (Scalar (g p)) (g p) w
fv'))
          = forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Tensor (Scalar (g p)) (f p) w
fu forall v. AdditiveGroup v => v -> v -> v
^-^ Tensor (Scalar (g p)) (f p) w
fu', Tensor (Scalar (g p)) (g p) w
fv forall v. AdditiveGroup v => v -> v -> v
^-^ Tensor (Scalar (g p)) (g p) w
fv')
  toFlatTensor :: (:*:) f g p -+> ((:*:) f g p ⊗ Scalar ((:*:) f g p))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction
      forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(f p
u:*:g p
v) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensorforall s v w. LinearFunction s v w -> v -> w
-+$>f p
u, forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensorforall s v w. LinearFunction s v w -> v -> w
-+$>g p
v)
  fromFlatTensor :: ((:*:) f g p ⊗ Scalar ((:*:) f g p)) -+> (:*:) f g p
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction
      forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (Tensor (Scalar (g p)) (f p) (Scalar (g p))
u,Tensor (Scalar (g p)) (g p) (Scalar (g p))
v)) -> (forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) (Scalar (g p))
u)forall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
:*:(forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (g p) (Scalar (g p))
v)
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
Bilinear ((:*:) f g p) w ((:*:) f g p ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(f p
u:*:g p
v) w
w ->
      forall s v w. TensorProduct v w -> Tensor s v w
Tensor ((forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>f p
u)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w, (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>g p
v)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w)
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
((:*:) f g p ⊗ w) -+> (w ⊗ (:*:) f g p)
transposeTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (Tensor (Scalar (g p)) (f p) w
uw,Tensor (Scalar (g p)) (g p) w
vw))
        -> (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (\(f p
u,g p
v)->f p
uforall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
:*:g p
v))
             forall s v w. LinearFunction s v w -> v -> w
-+$>(forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) w
uw,forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (g p) w
vw)
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar ((:*:) f g p),
 Scalar x ~ Scalar ((:*:) f g p)) =>
Bilinear (w -+> x) ((:*:) f g p ⊗ w) ((:*:) f g p ⊗ x)
fmapTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
     \LinearFunction (Scalar (g p)) w x
f (Tensor (Tensor (Scalar (g p)) (f p) w
uw,Tensor (Scalar (g p)) (g p) w
vw)) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ((forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (g p)) w x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) w
uw, (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (g p)) w x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (g p) w
vw)
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar ((:*:) f g p), Scalar w ~ Scalar ((:*:) f g p),
 Scalar x ~ Scalar ((:*:) f g p)) =>
Bilinear
  ((w, x) -+> u) ((:*:) f g p ⊗ w, (:*:) f g p ⊗ x) ((:*:) f g p ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
               forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction (Scalar (g p)) (w, x) u
f (Tensor (Tensor (Scalar (g p)) (f p) w
uw, Tensor (Scalar (g p)) (g p) w
vw), Tensor (Tensor (Scalar (g p)) (f p) x
ux, Tensor (Scalar (g p)) (g p) x
vx))
                      -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (g p)) (w, x) u
f)forall s v w. LinearFunction s v w -> v -> w
-+$>(Tensor (Scalar (g p)) (f p) w
uw,Tensor (Scalar (g p)) (f p) x
ux)
                                , (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (g p)) (w, x) u
f)forall s v w. LinearFunction s v w -> v -> w
-+$>(Tensor (Scalar (g p)) (g p) w
vw,Tensor (Scalar (g p)) (g p) x
vx) )
  tensorUnsafeFromArrayWithOffset
   ::  w m α . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar (f p)
                , GArr.Vector α (Scalar (f p)) )
           => Int -> α (Scalar (f p)) -> ((f:*:g) pw)
  tensorUnsafeFromArrayWithOffset :: forall w (m :: Nat) (α :: Type -> Type).
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar (f p),
 Vector α (Scalar (f p))) =>
Int -> α (Scalar (f p)) -> (:*:) f g p ⊗ w
tensorUnsafeFromArrayWithOffset
   = case (forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(f p), forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(g p)) of
    (DimensionalityWitness (f p)
IsFlexibleDimensional, DimensionalityWitness (g p)
_) -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `f p` is static-dimensional."
    (DimensionalityWitness (f p)
_, DimensionalityWitness (g p)
IsFlexibleDimensional) -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `g p` is static-dimensional."
    (DimensionalityWitness (f p)
IsStaticDimensional, DimensionalityWitness (g p)
IsStaticDimensional)
     -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(f p) forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(g p))
      (\Int
i α (Scalar (g p))
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffset @(f p, g p) @w Int
i α (Scalar (g p))
ar) )
  tensorUnsafeWriteArrayWithOffset
   ::  w m α σ . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar (f p)
                , GArr.Vector α (Scalar (f p)) )
           => GArr.Mutable α σ (Scalar (f p)) -> Int -> ((f:*:g) pw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall w (m :: Nat) (α :: Type -> Type) σ.
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar (f p),
 Vector α (Scalar (f p))) =>
Mutable α σ (Scalar (f p)) -> Int -> ((:*:) f g p ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
   = case (forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(f p), forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(g p)) of
    (DimensionalityWitness (f p)
IsFlexibleDimensional, DimensionalityWitness (g p)
_) -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `f p` is static-dimensional."
    (DimensionalityWitness (f p)
_, DimensionalityWitness (g p)
IsFlexibleDimensional) -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `g p` is static-dimensional."
    (DimensionalityWitness (f p)
IsStaticDimensional, DimensionalityWitness (g p)
IsStaticDimensional)
     -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(f p) forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(g p))
      (\Mutable α σ (Scalar (g p))
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset @(f p, g p) @w Mutable α σ (Scalar (g p))
ar) )
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar ((:*:) f g p),
 TensorSpace b, Scalar b ~ Scalar ((:*:) f g p)) =>
p ((:*:) f g p)
-> VSCCoercion (Scalar ((:*:) f g p)) a b
-> Coercion
     (TensorProduct ((:*:) f g p) a) (TensorProduct ((:*:) f g p) b)
coerceFmapTensorProduct p ((:*:) f g p)
p VSCCoercion (Scalar ((:*:) f g p)) a b
cab = case
             ( forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ((\(f p
u:*:g p
_)->f p
u)forall (f :: Type -> Type) (r :: Type -> Type -> Type) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>p ((:*:) f g p)
p) VSCCoercion (Scalar ((:*:) f g p)) a b
cab
             , forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ((\(f p
_:*:g p
v)->g p
v)forall (f :: Type -> Type) (r :: Type -> Type -> Type) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>p ((:*:) f g p)
p) VSCCoercion (Scalar ((:*:) f g p)) a b
cab ) of
          (Coercion (TensorProduct (f p) a) (TensorProduct (f p) b)
Coercion, Coercion (TensorProduct (g p) a) (TensorProduct (g p) b)
Coercion) -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
  wellDefinedVector :: (:*:) f g p -> Maybe ((:*:) f g p)
wellDefinedVector (f p
u:*:g p
v) = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 forall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (forall v. TensorSpace v => v -> Maybe v
wellDefinedVector f p
u) (forall v. TensorSpace v => v -> Maybe v
wellDefinedVector g p
v)
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
((:*:) f g p ⊗ w) -> Maybe ((:*:) f g p ⊗ w)
wellDefinedTensor (Tensor (Tensor (Scalar (g p)) (f p) w
u,Tensor (Scalar (g p)) (g p) w
v))
         = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 ((forall s v w. TensorProduct v w -> Tensor s v w
Tensorforall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.) forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (,)) (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor Tensor (Scalar (g p)) (f p) w
u) (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor Tensor (Scalar (g p)) (g p) w
v)


instance  m . ( Semimanifold m, DimensionAware (Needle (VRep m))
               , Scalar (Needle m) ~ Scalar (Needle (VRep m)) )
                  => DimensionAware (GenericNeedle m) where
  type StaticDimension (GenericNeedle m) = StaticDimension (Needle (VRep m))
  dimensionalityWitness :: DimensionalityWitness (GenericNeedle m)
dimensionalityWitness = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(Needle (VRep m)) of
    DimensionalityWitness (Needle (VRep m))
IsStaticDimensional -> forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    DimensionalityWitness (Needle (VRep m))
IsFlexibleDimensional -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  n m . ( Semimanifold m, n`Dimensional`Needle (VRep m)
                 , Scalar (Needle m) ~ Scalar (Needle (VRep m)) )
                  => n`Dimensional`GenericNeedle m where
  knownDimensionalitySing :: Sing n
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(Needle (VRep m))
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (GenericNeedle m)) =>
Int -> α (Scalar (GenericNeedle m)) -> GenericNeedle m
unsafeFromArrayWithOffset Int
i α (Scalar (GenericNeedle m))
ar
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset @n @(Needle (VRep m)) Int
i α (Scalar (GenericNeedle m))
ar)
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (GenericNeedle m)) =>
Mutable α σ (Scalar (GenericNeedle m))
-> Int -> GenericNeedle m -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (GenericNeedle m))
ar Int
i
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset @n @(Needle (VRep m)) Mutable α σ (Scalar (GenericNeedle m))
ar Int
i)

instance  m . ( Semimanifold m, TensorSpace (Needle (VRep m))
                               , Scalar (Needle m) ~ Scalar (Needle (VRep m)) )
                  => TensorSpace (GenericNeedle m) where
  type TensorProduct (GenericNeedle m) w = TensorProduct (Needle (VRep m)) w
  wellDefinedVector :: GenericNeedle m -> Maybe (GenericNeedle m)
wellDefinedVector = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v. TensorSpace v => v -> Maybe v
wellDefinedVector forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
(GenericNeedle m ⊗ w) -> Maybe (GenericNeedle m ⊗ w)
wellDefinedTensor = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle)
                         forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor
                         forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedleforall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  scalarSpaceWitness :: ScalarSpaceWitness (GenericNeedle m)
scalarSpaceWitness = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness
                               :: ScalarSpaceWitness (Needle (VRep m)) of
          ScalarSpaceWitness (Needle (VRep m))
ScalarSpaceWitness -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (GenericNeedle m)
linearManifoldWitness = case forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness
                               :: LinearManifoldWitness (Needle (VRep m)) of
          LinearManifoldWitness (Needle (VRep m))
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
           BoundarylessWitness
#endif
              -> forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
                  BoundarylessWitness
#endif
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
GenericNeedle m ⊗ w
zeroTensor = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  toFlatTensor :: GenericNeedle m -+> (GenericNeedle m ⊗ Scalar (GenericNeedle m))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedleforall s a b. VSCCoercion s a b -> a -> b
-+$=>)
                             forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor
                             forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle
  fromFlatTensor :: (GenericNeedle m ⊗ Scalar (GenericNeedle m)) -+> GenericNeedle m
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedleforall s a b. VSCCoercion s a b -> a -> b
-+$=>)
                             forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
                             forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
(GenericNeedle m ⊗ w)
-> (GenericNeedle m ⊗ w) -> GenericNeedle m ⊗ w
addTensors (Tensor TensorProduct (GenericNeedle m) w
s) (Tensor TensorProduct (GenericNeedle m) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
addTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle m) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle m) w
t)
  subtractTensors :: forall w.
(TensorSpace (GenericNeedle m), TensorSpace w,
 Scalar w ~ Scalar (GenericNeedle m)) =>
(GenericNeedle m ⊗ w)
-> (GenericNeedle m ⊗ w) -> GenericNeedle m ⊗ w
subtractTensors (Tensor TensorProduct (GenericNeedle m) w
s) (Tensor TensorProduct (GenericNeedle m) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace v, TensorSpace w,
 Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
subtractTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle m) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle m) w
t)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
Bilinear
  (Scalar (GenericNeedle m))
  (GenericNeedle m ⊗ w)
  (GenericNeedle m ⊗ w)
scaleTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar (Needle (VRep m))
μ -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle
                                         forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar (Needle (VRep m))
μ
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
(GenericNeedle m ⊗ w) -+> (GenericNeedle m ⊗ w)
negateTensor = forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensor
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
Bilinear (GenericNeedle m) w (GenericNeedle m ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(GenericNeedle Needle (VRep m)
v) w
w
                      -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle
                           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>Needle (VRep m)
v)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
(GenericNeedle m ⊗ w) -+> (w ⊗ GenericNeedle m)
transposeTensor = forall w.
(TensorSpace w, Scalar w ~ Scalar (Needle m)) =>
(GenericNeedle m ⊗ w) -+> (w ⊗ GenericNeedle m)
tT
   where tT ::  w . (TensorSpace w, Scalar w ~ Scalar (Needle m))
                => (GenericNeedle m  w) -+> (w  GenericNeedle m)
         tT :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Needle m)) =>
(GenericNeedle m ⊗ w) -+> (w ⊗ GenericNeedle m)
tT = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction
           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ([]::[w])
                              (forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion :: VSCCoercion (Scalar (Needle m))
                                                          (Needle (VRep m))
                                                          (GenericNeedle m))
                           forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion)
              forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
              forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedleforall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (GenericNeedle m),
 Scalar x ~ Scalar (GenericNeedle m)) =>
Bilinear (w -+> x) (GenericNeedle m ⊗ w) (GenericNeedle m ⊗ x)
fmapTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar (Needle (VRep m))) w x
f -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (Needle (VRep m))) w x
f)
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (GenericNeedle m),
 Scalar w ~ Scalar (GenericNeedle m),
 Scalar x ~ Scalar (GenericNeedle m)) =>
Bilinear
  ((w, x) -+> u)
  (GenericNeedle m ⊗ w, GenericNeedle m ⊗ x)
  (GenericNeedle m ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar (Needle (VRep m))) (w, x) u
f (Tensor (Scalar (Needle (VRep m))) (GenericNeedle m) w
wt, Tensor (Scalar (Needle (VRep m))) (GenericNeedle m) x
xt) -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle
                        forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (Needle (VRep m))) (w, x) u
f)
                         forall s v w. LinearFunction s v w -> v -> w
-+$>( forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (Needle (VRep m))) (GenericNeedle m) w
wt
                             , forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (Needle (VRep m))) (GenericNeedle m) x
xt )
  tensorUnsafeFromArrayWithOffset
   ::  w nn α . ( TensorSpace w, nn`Dimensional`w
                , Scalar w ~ (Scalar (Needle (VRep m)))
                , GArr.Vector α (Scalar (Needle (VRep m))) )
           => Int -> α (Scalar (Needle (VRep m)))
                -> (GenericNeedle mw)
  tensorUnsafeFromArrayWithOffset :: forall w (nn :: Nat) (α :: Type -> Type).
(TensorSpace w, Dimensional nn w,
 Scalar w ~ Scalar (Needle (VRep m)),
 Vector α (Scalar (Needle (VRep m)))) =>
Int -> α (Scalar (Needle (VRep m))) -> GenericNeedle m ⊗ w
tensorUnsafeFromArrayWithOffset
   = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(Needle (VRep m)) of
    DimensionalityWitness (Needle (VRep m))
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `Needle (VRep m)` is static-dimensional."
    DimensionalityWitness (Needle (VRep m))
IsStaticDimensional -> \Int
i α (Scalar (Needle (VRep m)))
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffset @(Needle (VRep m)) @w Int
i α (Scalar (Needle (VRep m)))
ar)
  tensorUnsafeWriteArrayWithOffset
   ::  w nn α σ . ( TensorSpace w, nn`Dimensional`w
                , Scalar w ~ (Scalar (Needle (VRep m)))
                , GArr.Vector α (Scalar (Needle (VRep m))) )
           => GArr.Mutable α σ (Scalar (Needle (VRep m)))
                -> Int -> (GenericNeedle mw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall w (nn :: Nat) (α :: Type -> Type) σ.
(TensorSpace w, Dimensional nn w,
 Scalar w ~ Scalar (Needle (VRep m)),
 Vector α (Scalar (Needle (VRep m)))) =>
Mutable α σ (Scalar (Needle (VRep m)))
-> Int -> (GenericNeedle m ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
   = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(Needle (VRep m)) of
    DimensionalityWitness (Needle (VRep m))
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `Needle (VRep m)` is static-dimensional."
    DimensionalityWitness (Needle (VRep m))
IsStaticDimensional -> \Mutable α σ (Scalar (Needle (VRep m)))
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset @(Needle (VRep m)) @w Mutable α σ (Scalar (Needle (VRep m)))
ar)
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (GenericNeedle m),
 TensorSpace b, Scalar b ~ Scalar (GenericNeedle m)) =>
p (GenericNeedle m)
-> VSCCoercion (Scalar (GenericNeedle m)) a b
-> Coercion
     (TensorProduct (GenericNeedle m) a)
     (TensorProduct (GenericNeedle m) b)
coerceFmapTensorProduct = forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (Needle (VRep m)),
 TensorSpace b, Scalar b ~ Scalar (Needle (VRep m))) =>
p (GenericNeedle m)
-> VSCCoercion (Scalar a) a b
-> Coercion
     (TensorProduct (GenericNeedle m) a)
     (TensorProduct (GenericNeedle m) b)
cmtp
   where cmtp ::  p a b . ( Hask.Functor p
                           , TensorSpace a, Scalar a ~ Scalar (Needle (VRep m))
                           , TensorSpace b, Scalar b ~ Scalar (Needle (VRep m)) )
             => p (GenericNeedle m) -> VSCCoercion (Scalar a) a b
               -> Coercion (TensorProduct (GenericNeedle m) a)
                           (TensorProduct (GenericNeedle m) b)
         cmtp :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (Needle (VRep m)),
 TensorSpace b, Scalar b ~ Scalar (Needle (VRep m))) =>
p (GenericNeedle m)
-> VSCCoercion (Scalar a) a b
-> Coercion
     (TensorProduct (GenericNeedle m) a)
     (TensorProduct (GenericNeedle m) b)
cmtp p (GenericNeedle m)
p VSCCoercion (Scalar a) a b
crc = case forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct @(Needle (VRep m)) [] VSCCoercion (Scalar a) a b
crc of
                  Coercion
  (TensorProduct (Needle (VRep m)) a)
  (TensorProduct (Needle (VRep m)) b)
Coercion -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion

instance  v s . (LinearSpace v, Num (Scalar v)) => LinearSpace (Gnrx.Rec0 v s) where
  type DualVector (Gnrx.Rec0 v s) = DualVector v
  dualSpaceWitness :: DualSpaceWitness (Rec0 v s)
dualSpaceWitness = forall a. a
genericTensorspaceError
  linearId :: Rec0 v s +> Rec0 v s
linearId = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1
                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
                forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. LinearSpace v => LinearMap (Scalar v) v v
linearId
  applyDualVector :: LinearSpace (Rec0 v s) =>
Bilinear (DualVector (Rec0 v s)) (Rec0 v s) (Scalar (Rec0 v s))
applyDualVector = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \DualVector v
dv (Gnrx.K1 v
v) -> (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>DualVector v
dv)forall s v w. LinearFunction s v w -> v -> w
-+$>v
v
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
Bilinear (Rec0 v s +> w) (Rec0 v s) w
applyLinear = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Rec0 v s)) w
f) (Gnrx.K1 v
v)
                      -> (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (Rec0 v s)) w
f)forall s v w. LinearFunction s v w -> v -> w
-+$>v
v
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (Rec0 v s)) =>
(Rec0 v s ⊗ w) +> (Rec0 v s ⊗ w)
tensorId = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1)
                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). c -> K1 i c p
Gnrx.K1) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (Rec0 v s)) =>
Bilinear
  (DualVector (Rec0 v s ⊗ u)) (Rec0 v s ⊗ u) (Scalar (Rec0 v s))
applyTensorFunctional = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Rec0 v s)) (DualVector u)
f) Tensor (Scalar v) (Rec0 v s) u
t ->
              (forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctionalforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (Rec0 v s)) (DualVector u)
f)forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (Rec0 v s) u
t
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (Rec0 v s),
 Scalar w ~ Scalar (Rec0 v s)) =>
Bilinear ((Rec0 v s ⊗ u) +> w) (Rec0 v s ⊗ u) w
applyTensorLinMap = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Tensor (Scalar v) (Rec0 v s) u)) w
f) Tensor (Scalar v) (Rec0 v s) u
t
                -> (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
applyTensorLinMapforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (Tensor (Scalar v) (Rec0 v s) u)) w
f)forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i c (p :: k). K1 i c p -> c
Gnrx.unK1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar v) (Rec0 v s) u
t
  useTupleLinearSpaceComponents :: forall x y φ.
(Rec0 v s ~ (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 (Rec0 v s)) (Rec0 v s) (DualVector (DualVector (Rec0 v s)))
coerceDoubleDual = case forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @v of
    VSCCoercion (Scalar v) v (DualVector (DualVector v))
VSCCoercion -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

instance (LinearSpace (f p), Num (Scalar (f p))) => LinearSpace (Gnrx.M1 i c f p) where
  type DualVector (Gnrx.M1 i c f p) = DualVector (f p)
  dualSpaceWitness :: DualSpaceWitness (M1 i c f p)
dualSpaceWitness = forall a. a
genericTensorspaceError
  linearId :: M1 i c f p +> M1 i c f p
linearId = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1
                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
                forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. LinearSpace v => LinearMap (Scalar v) v v
linearId
  applyDualVector :: LinearSpace (M1 i c f p) =>
Bilinear
  (DualVector (M1 i c f p)) (M1 i c f p) (Scalar (M1 i c f p))
applyDualVector = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \DualVector (f p)
dv (Gnrx.M1 f p
v) -> (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>DualVector (f p)
dv)forall s v w. LinearFunction s v w -> v -> w
-+$>f p
v
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
Bilinear (M1 i c f p +> w) (M1 i c f p) w
applyLinear = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (M1 i c f p)) w
f) (Gnrx.M1 f p
v)
                      -> (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (M1 i c f p)) w
f)forall s v w. LinearFunction s v w -> v -> w
-+$>f p
v
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (M1 i c f p)) =>
(M1 i c f p ⊗ w) +> (M1 i c f p ⊗ w)
tensorId = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1)
                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). f p -> M1 i c f p
Gnrx.M1) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (M1 i c f p)) =>
Bilinear
  (DualVector (M1 i c f p ⊗ u))
  (M1 i c f p ⊗ u)
  (Scalar (M1 i c f p))
applyTensorFunctional = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (M1 i c f p)) (DualVector u)
f) Tensor (Scalar (f p)) (M1 i c f p) u
t ->
              (forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctionalforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (M1 i c f p)) (DualVector u)
f)forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (f p)) (M1 i c f p) u
t
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (M1 i c f p),
 Scalar w ~ Scalar (M1 i c f p)) =>
Bilinear ((M1 i c f p ⊗ u) +> w) (M1 i c f p ⊗ u) w
applyTensorLinMap = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Tensor (Scalar (f p)) (M1 i c f p) u)) w
f) Tensor (Scalar (f p)) (M1 i c f p) u
t
                -> (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
applyTensorLinMapforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (Tensor (Scalar (f p)) (M1 i c f p) u)) w
f)forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
Gnrx.unM1 forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (f p)) (M1 i c f p) u
t
  useTupleLinearSpaceComponents :: forall x y φ.
(M1 i c f p ~ (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 (M1 i c f p))
  (M1 i c f p)
  (DualVector (DualVector (M1 i c f p)))
coerceDoubleDual = case forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @(f p) of
    VSCCoercion (Scalar (f p)) (f p) (DualVector (DualVector (f p)))
VSCCoercion -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

data GenericTupleDual f g p
    = GenericTupleDual !(DualVector (f p)) !(DualVector (g p)) deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (f :: Type -> Type) (g :: Type -> Type) p x.
Rep (GenericTupleDual f g p) x -> GenericTupleDual f g p
forall (f :: Type -> Type) (g :: Type -> Type) p x.
GenericTupleDual f g p -> Rep (GenericTupleDual f g p) x
$cto :: forall (f :: Type -> Type) (g :: Type -> Type) p x.
Rep (GenericTupleDual f g p) x -> GenericTupleDual f g p
$cfrom :: forall (f :: Type -> Type) (g :: Type -> Type) p x.
GenericTupleDual f g p -> Rep (GenericTupleDual f g p) x
Generic)
instance (AdditiveGroup (DualVector (f p)), AdditiveGroup (DualVector (g p)))
    => AdditiveGroup (GenericTupleDual f g p)
instance ( VectorSpace (DualVector (f p)), VectorSpace (DualVector (g p))
         , Scalar (DualVector (f p)) ~ Scalar (DualVector (g p)) )
    => VectorSpace (GenericTupleDual f g p)
instance ( InnerSpace (DualVector (f p)), InnerSpace (DualVector (g p))
         , Scalar (DualVector (f p)) ~ Scalar (DualVector (g p))
         , Num (Scalar (DualVector (f p))) )
    => InnerSpace (GenericTupleDual f g p)
instance (AdditiveGroup (DualVector (f p)), AdditiveGroup (DualVector (g p)))
    => AffineSpace (GenericTupleDual f g p) where
  type Diff (GenericTupleDual f g p) = GenericTupleDual f g p
  .+^ :: GenericTupleDual f g p
-> Diff (GenericTupleDual f g p) -> GenericTupleDual f g p
(.+^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
  .-. :: GenericTupleDual f g p
-> GenericTupleDual f g p -> Diff (GenericTupleDual f g p)
(.-.) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
instance (AdditiveGroup (DualVector (f p)), AdditiveGroup (DualVector (g p)))
    => Semimanifold (GenericTupleDual f g p) where
  type Needle (GenericTupleDual f g p) = GenericTupleDual f g p
  .+~^ :: GenericTupleDual f g p
-> Needle (GenericTupleDual f g p) -> GenericTupleDual f g p
(.+~^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
#if !MIN_VERSION_manifolds_core(0,6,0)
  fromInterior = id
  toInterior = pure
  translateP = Tagged (^+^)
#endif
instance (AdditiveGroup (DualVector (f p)), AdditiveGroup (DualVector (g p)))
    => PseudoAffine (GenericTupleDual f g p) where
  GenericTupleDual f g p
p.-~. :: GenericTupleDual f g p
-> GenericTupleDual f g p
-> Maybe (Needle (GenericTupleDual f g p))
.-~.GenericTupleDual f g p
q = forall a. a -> Maybe a
Just forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ GenericTupleDual f g p
pforall p. AffineSpace p => p -> p -> Diff p
.-.GenericTupleDual f g p
q
  .-~! :: HasCallStack =>
GenericTupleDual f g p
-> GenericTupleDual f g p -> Needle (GenericTupleDual f g p)
(.-~!) = forall p. AffineSpace p => p -> p -> Diff p
(.-.)


instance ( DimensionAware (f p), DimensionAware (g p)
         , VectorSpace (DualVector (f p)), VectorSpace (DualVector (g p))
         , Scalar (f p) ~ Scalar (g p)
         , Scalar (f p) ~ Scalar (DualVector (f p))
         , Scalar (g p) ~ Scalar (DualVector (g p)) )
    => DimensionAware (GenericTupleDual f g p) where
  type StaticDimension (GenericTupleDual f g p)
           = Maybe.ZipWithPlus (StaticDimension (f p)) (StaticDimension (g p))
  dimensionalityWitness :: DimensionalityWitness (GenericTupleDual f g p)
dimensionalityWitness = case ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(f p)
                               , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(g p) ) of
    (DimensionalityWitness (f p)
IsStaticDimensional, DimensionalityWitness (g p)
IsStaticDimensional)
        -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(f p) forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(g p))
              forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    (DimensionalityWitness (f p)
IsFlexibleDimensional, DimensionalityWitness (g p)
_) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
    (DimensionalityWitness (f p)
_, DimensionalityWitness (g p)
IsFlexibleDimensional) -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  n f m g p nm .
              ( n`Dimensional`f p, m`Dimensional`g p
              , VectorSpace (DualVector (f p)), VectorSpace (DualVector (g p))
              , Scalar (f p) ~ Scalar (g p)
              , Scalar (f p) ~ Scalar (DualVector (f p))
              , Scalar (g p) ~ Scalar (DualVector (g p))
              , nm ~ (n+m) )
                   => nm`Dimensional`GenericTupleDual f g p where
  knownDimensionalitySing :: Sing nm
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(f p) forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(g p)
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (GenericTupleDual f g p)) =>
Int
-> α (Scalar (GenericTupleDual f g p)) -> GenericTupleDual f g p
unsafeFromArrayWithOffset Int
i α (Scalar (GenericTupleDual f g p))
ar
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset @nm @(GenericTupleDual f g p) Int
i α (Scalar (GenericTupleDual f g p))
ar)
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (GenericTupleDual f g p)) =>
Mutable α σ (Scalar (GenericTupleDual f g p))
-> Int -> GenericTupleDual f g p -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (GenericTupleDual f g p))
i Int
ar
     = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset @nm @(GenericTupleDual f g p) Mutable α σ (Scalar (GenericTupleDual f g p))
i Int
ar)

instance ( LinearSpace (f p), LinearSpace (g p)
         , VectorSpace (DualVector (f p)), VectorSpace (DualVector (g p))
         , Scalar (f p) ~ Scalar (DualVector (f p))
         , Scalar (g p) ~ Scalar (DualVector (g p))
         , Scalar (DualVector (f p)) ~ Scalar (DualVector (g p)) )
    => TensorSpace (GenericTupleDual f g p) where
  type TensorProduct (GenericTupleDual f g p) w = (f p+>w, g p+>w)
  wellDefinedVector :: GenericTupleDual f g p -> Maybe (GenericTupleDual f g p)
wellDefinedVector = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                           , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
      (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
       -> \(GenericTupleDual DualVector (f p)
fv DualVector (g p)
gv)
           -> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 forall (f :: Type -> Type) (g :: Type -> Type) p.
DualVector (f p) -> DualVector (g p) -> GenericTupleDual f g p
GenericTupleDual (forall v. TensorSpace v => v -> Maybe v
wellDefinedVector DualVector (f p)
fv) (forall v. TensorSpace v => v -> Maybe v
wellDefinedVector DualVector (g p)
gv)
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericTupleDual f g p)) =>
(GenericTupleDual f g p ⊗ w) -> Maybe (GenericTupleDual f g p ⊗ w)
wellDefinedTensor = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                           , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
      (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
       -> \(Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
ft, LinearMap (Scalar (DualVector (g p))) (g p) w
gt))
        -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: Type -> Type) (r :: Type -> Type -> Type) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 (,) (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor)
                                    forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (f p) w
ft))
                                 (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor)
                                    forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (g p) w
gt))
  scalarSpaceWitness :: ScalarSpaceWitness (GenericTupleDual f g p)
scalarSpaceWitness = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p) of
        ScalarSpaceWitness (f p)
ScalarSpaceWitness -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (GenericTupleDual f g p)
linearManifoldWitness = forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
                           BoundarylessWitness
#endif
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericTupleDual f g p)) =>
GenericTupleDual f g p ⊗ w
zeroTensor = case ( forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness (f p)
                    , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                    , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       ( LinearManifoldWitness (f p)
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
          BoundarylessWitness
#endif
        ,DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness )
           -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor, forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor)
  toFlatTensor :: GenericTupleDual f g p
-+> (GenericTupleDual f g p ⊗ Scalar (GenericTupleDual f g p))
toFlatTensor = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                      , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                      , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
          -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(GenericTupleDual DualVector (f p)
tf DualVector (g p)
tg)
            -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( forall v. LinearSpace v => DualVector v -+> (v +> Scalar v)
toLinearForm forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ DualVector (f p)
tf, forall v. LinearSpace v => DualVector v -+> (v +> Scalar v)
toLinearForm forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ DualVector (g p)
tg )
  fromFlatTensor :: (GenericTupleDual f g p ⊗ Scalar (GenericTupleDual f g p))
-+> GenericTupleDual f g p
fromFlatTensor = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                        , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                        , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
          -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (LinearMap
  (Scalar (DualVector (g p))) (f p) (Scalar (DualVector (g p)))
tf,LinearMap
  (Scalar (DualVector (g p))) (g p) (Scalar (DualVector (g p)))
tg))
            -> forall (f :: Type -> Type) (g :: Type -> Type) p.
DualVector (f p) -> DualVector (g p) -> GenericTupleDual f g p
GenericTupleDual (forall v. LinearSpace v => (v +> Scalar v) -+> DualVector v
fromLinearForm forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap
  (Scalar (DualVector (g p))) (f p) (Scalar (DualVector (g p)))
tf) (forall v. LinearSpace v => (v +> Scalar v) -+> DualVector v
fromLinearForm forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap
  (Scalar (DualVector (g p))) (g p) (Scalar (DualVector (g p)))
tg)
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericTupleDual f g p)) =>
(GenericTupleDual f g p ⊗ w)
-> (GenericTupleDual f g p ⊗ w) -> GenericTupleDual f g p ⊗ w
addTensors (Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
sf,LinearMap (Scalar (DualVector (g p))) (g p) w
sg)) (Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
tf,LinearMap (Scalar (DualVector (g p))) (g p) w
tg)) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
sfforall v. AdditiveGroup v => v -> v -> v
^+^LinearMap (Scalar (DualVector (g p))) (f p) w
tf, LinearMap (Scalar (DualVector (g p))) (g p) w
sgforall v. AdditiveGroup v => v -> v -> v
^+^LinearMap (Scalar (DualVector (g p))) (g p) w
tg)
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericTupleDual f g p)) =>
(GenericTupleDual f g p ⊗ w) -+> (GenericTupleDual f g p ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
tf,LinearMap (Scalar (DualVector (g p))) (g p) w
tg))
                   -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall v. AdditiveGroup v => v -> v
negateV LinearMap (Scalar (DualVector (g p))) (f p) w
tf, forall v. AdditiveGroup v => v -> v
negateV LinearMap (Scalar (DualVector (g p))) (g p) w
tg)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericTupleDual f g p)) =>
Bilinear
  (Scalar (GenericTupleDual f g p))
  (GenericTupleDual f g p ⊗ w)
  (GenericTupleDual f g p ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar (DualVector (g p))
μ (Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
tf,LinearMap (Scalar (DualVector (g p))) (g p) w
tg)) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (Scalar (DualVector (g p))
μforall v. VectorSpace v => Scalar v -> v -> v
*^LinearMap (Scalar (DualVector (g p))) (f p) w
tf, Scalar (DualVector (g p))
μforall v. VectorSpace v => Scalar v -> v -> v
*^LinearMap (Scalar (DualVector (g p))) (g p) w
tg)
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericTupleDual f g p)) =>
Bilinear (GenericTupleDual f g p) w (GenericTupleDual f g p ⊗ w)
tensorProduct = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                       , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                       , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
          -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(GenericTupleDual DualVector (f p)
fw DualVector (g p)
gw) w
x
                   -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ DualVector (f p)
fwforall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
 Num' (Scalar v)) =>
v -> w -> v ⊗ w
w
x, forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ DualVector (g p)
gwforall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
 Num' (Scalar v)) =>
v -> w -> v ⊗ w
w
x)
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericTupleDual f g p)) =>
(GenericTupleDual f g p ⊗ w) -+> (w ⊗ GenericTupleDual f g p)
transposeTensor = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                         , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                         , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
          -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
fw, LinearMap (Scalar (DualVector (g p))) (g p) w
gw))
                     -> (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. (v -> w) -> LinearFunction s v w
LinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`forall (k :: Type -> Type -> Type) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k a (k b c) -> k (a, b) c
uncurry forall (f :: Type -> Type) (g :: Type -> Type) p.
DualVector (f p) -> DualVector (g p) -> GenericTupleDual f g p
GenericTupleDual)
                       forall s v w. LinearFunction s v w -> v -> w
-+$> ( forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensorforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (f p) w
fw
                            , forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensorforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (g p) w
gw )
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x,
 Scalar w ~ Scalar (GenericTupleDual f g p),
 Scalar x ~ Scalar (GenericTupleDual f g p)) =>
Bilinear
  (w -+> x) (GenericTupleDual f g p ⊗ w) (GenericTupleDual f g p ⊗ x)
fmapTensor = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                    , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                    , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
          -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction (Scalar (DualVector (g p))) w x
f (Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
fw, LinearMap (Scalar (DualVector (g p))) (g p) w
gw))
                 -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (DualVector (g p))) w x
f) forall s v w. LinearFunction s v w -> v -> w
-+$> forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (f p) w
fw
                           , forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (DualVector (g p))) w x
f) forall s v w. LinearFunction s v w -> v -> w
-+$> forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (g p) w
gw )
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (GenericTupleDual f g p),
 Scalar w ~ Scalar (GenericTupleDual f g p),
 Scalar x ~ Scalar (GenericTupleDual f g p)) =>
Bilinear
  ((w, x) -+> u)
  (GenericTupleDual f g p ⊗ w, GenericTupleDual f g p ⊗ x)
  (GenericTupleDual f g p ⊗ u)
fzipTensorWith = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                        , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                        , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
          -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction (Scalar (DualVector (g p))) (w, x) u
f (Tensor (LinearMap (Scalar (DualVector (g p))) (f p) w
fw, LinearMap (Scalar (DualVector (g p))) (g p) w
gw), Tensor (LinearMap (Scalar (DualVector (g p))) (f p) x
fx, LinearMap (Scalar (DualVector (g p))) (g p) x
gx))
                 -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor ( forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (DualVector (g p))) (w, x) u
f) forall s v w. LinearFunction s v w -> v -> w
-+$> ( forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (f p) w
fw
                                                                     , forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (f p) x
fx )
                           , forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (DualVector (g p))) (w, x) u
f) forall s v w. LinearFunction s v w -> v -> w
-+$> ( forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (g p) w
gw
                                                                     , forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (DualVector (g p))) (g p) x
gx ) )
  tensorUnsafeFromArrayWithOffset
   ::  w m α . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar (f p)
                , GArr.Vector α (Scalar (f p)) )
           => Int -> α (Scalar (f p)) -> (GenericTupleDual f g pw)
  tensorUnsafeFromArrayWithOffset :: forall w (m :: Nat) (α :: Type -> Type).
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar (f p),
 Vector α (Scalar (f p))) =>
Int -> α (Scalar (f p)) -> GenericTupleDual f g p ⊗ w
tensorUnsafeFromArrayWithOffset
   = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(f p), forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(g p) ) of
    (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness) -> case
          ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector (f p))
          , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector (g p)) ) of
     (DimensionalityWitness (DualVector (f p))
IsFlexibleDimensional, DimensionalityWitness (DualVector (g p))
_)
       -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `f p` is static-dimensional."
     (DimensionalityWitness (DualVector (f p))
_, DimensionalityWitness (DualVector (g p))
IsFlexibleDimensional) -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `g p` is static-dimensional."
     (DimensionalityWitness (DualVector (f p))
IsStaticDimensional, DimensionalityWitness (DualVector (g p))
IsStaticDimensional)
      -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(DualVector (f p))
                        forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(DualVector (g p)))
       (\Int
i α (Scalar (DualVector (g p)))
ar
        -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffset
                    @(DualVector (f p), DualVector (g p)) @w Int
i α (Scalar (DualVector (g p)))
ar) )
  tensorUnsafeWriteArrayWithOffset
   ::  w m α σ . ( TensorSpace w, m`Dimensional`w, Scalar w ~ Scalar (f p)
                , GArr.Vector α (Scalar (f p)) )
           => GArr.Mutable α σ (Scalar (f p)) -> Int -> (GenericTupleDual f g pw)
                 -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall w (m :: Nat) (α :: Type -> Type) σ.
(TensorSpace w, Dimensional m w, Scalar w ~ Scalar (f p),
 Vector α (Scalar (f p))) =>
Mutable α σ (Scalar (f p))
-> Int -> (GenericTupleDual f g p ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
   = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(f p), forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(g p) ) of
    (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness) -> case
          ( forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector (f p))
          , forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector (g p)) ) of
     (DimensionalityWitness (DualVector (f p))
IsFlexibleDimensional, DimensionalityWitness (DualVector (g p))
_)
       -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `f p` is static-dimensional."
     (DimensionalityWitness (DualVector (f p))
_, DimensionalityWitness (DualVector (g p))
IsFlexibleDimensional) -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `g p` is static-dimensional."
     (DimensionalityWitness (DualVector (f p))
IsStaticDimensional, DimensionalityWitness (DualVector (g p))
IsStaticDimensional)
      -> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(DualVector (f p))
                        forall a (t1 :: a) (t2 :: a).
SNum a =>
Sing t1 -> Sing t2 -> Sing (Apply (Apply (+@#@$) t1) t2)
%+ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(DualVector (g p)))
       (\Mutable α σ (Scalar (DualVector (g p)))
ar
        -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
                    @(DualVector (f p), DualVector (g p)) @w Mutable α σ (Scalar (DualVector (g p)))
ar) )
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a,
 Scalar a ~ Scalar (GenericTupleDual f g p), TensorSpace b,
 Scalar b ~ Scalar (GenericTupleDual f g p)) =>
p (GenericTupleDual f g p)
-> VSCCoercion (Scalar (GenericTupleDual f g p)) a b
-> Coercion
     (TensorProduct (GenericTupleDual f g p) a)
     (TensorProduct (GenericTupleDual f g p) b)
coerceFmapTensorProduct p (GenericTupleDual f g p)
p VSCCoercion (Scalar (GenericTupleDual f g p)) a b
cab = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                                       , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness) -> case
             ( forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ((\(GenericTupleDual DualVector (f p)
u DualVector (g p)
_)->DualVector (f p)
u)forall (f :: Type -> Type) (r :: Type -> Type -> Type) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>p (GenericTupleDual f g p)
p) VSCCoercion (Scalar (GenericTupleDual f g p)) a b
cab
             , forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ((\(GenericTupleDual DualVector (f p)
_ DualVector (g p)
v)->DualVector (g p)
v)forall (f :: Type -> Type) (r :: Type -> Type -> Type) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>p (GenericTupleDual f g p)
p) VSCCoercion (Scalar (GenericTupleDual f g p)) a b
cab ) of
          (Coercion
  (TensorProduct (DualVector (f p)) a)
  (TensorProduct (DualVector (f p)) b)
Coercion, Coercion
  (TensorProduct (DualVector (g p)) a)
  (TensorProduct (DualVector (g p)) b)
Coercion) -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
  


instance  f g p . ( LinearSpace (f p), LinearSpace (g p), Scalar (f p) ~ Scalar (g p) )
                       => LinearSpace ((f:*:g) p) where
  type DualVector ((f:*:g) p) = GenericTupleDual f g p
  
  dualSpaceWitness :: DualSpaceWitness ((:*:) f g p)
dualSpaceWitness = forall a. a
genericTensorspaceError
  linearId :: (:*:) f g p +> (:*:) f g p
linearId = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                  , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                  , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
             -> forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap ( forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (\f p
vf->(f p
vfforall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
:*:forall v. AdditiveGroup v => v
zeroV))
                          , forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (\g p
vg->(forall v. AdditiveGroup v => v
zeroVforall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
:*:g p
vg)) )
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
((:*:) f g p ⊗ w) +> ((:*:) f g p ⊗ w)
tensorId = forall w.
(LinearSpace w, Scalar w ~ Scalar (f p)) =>
ScalarSpaceWitness (f p)
-> DualSpaceWitness (f p)
-> DualSpaceWitness (g p)
-> DualSpaceWitness w
-> ((:*:) f g p ⊗ w) +> ((:*:) f g p ⊗ w)
tI forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
   where tI ::  w . (LinearSpace w, Scalar w ~ Scalar (f p))
                 => ScalarSpaceWitness (f p) -> DualSpaceWitness (f p)
                     -> DualSpaceWitness (g p) -> DualSpaceWitness w
                       -> (((f:*:g) p)w)+>(((f:*:g) p)w)
         tI :: forall w.
(LinearSpace w, Scalar w ~ Scalar (f p)) =>
ScalarSpaceWitness (f p)
-> DualSpaceWitness (f p)
-> DualSpaceWitness (g p)
-> DualSpaceWitness w
-> ((:*:) f g p ⊗ w) +> ((:*:) f g p ⊗ w)
tI ScalarSpaceWitness (f p)
ScalarSpaceWitness DualSpaceWitness (f p)
DualSpaceWitness DualSpaceWitness (g p)
DualSpaceWitness DualSpaceWitness w
DualSpaceWitness 
              = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap
            ( forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (\f p
vf -> forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor
             forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \w
w -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (f p
vfforall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
 Num' (Scalar v)) =>
v -> w -> v ⊗ w
w
w, forall v. AdditiveGroup v => v
zeroV)))
            , forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (\g p
vg -> forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor
             forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \w
w -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor (forall v. AdditiveGroup v => v
zeroV, g p
vgforall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
 Num' (Scalar v)) =>
v -> w -> v ⊗ w
w
w))) )
  sampleLinearFunction :: forall w.
(TensorSpace w, Scalar ((:*:) f g p) ~ Scalar w) =>
((:*:) f g p -+> w) -+> ((:*:) f g p +> w)
sampleLinearFunction = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                              , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                              , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
              -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(:*:) f g p -+> w
f -> forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap
                   ( forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall s v w. LinearFunction s v w -> v -> w
-+$> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`
                       \f p
vf -> (:*:) f g p -+> w
f forall s v w. LinearFunction s v w -> v -> w
-+$> (f p
vfforall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
:*:forall v. AdditiveGroup v => v
zeroV)
                   , forall v w.
(LinearSpace v, TensorSpace w, Scalar v ~ Scalar w) =>
(v -+> w) -+> (v +> w)
sampleLinearFunction forall s v w. LinearFunction s v w -> v -> w
-+$> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`
                       \g p
vg -> (:*:) f g p -+> w
f forall s v w. LinearFunction s v w -> v -> w
-+$> (forall v. AdditiveGroup v => v
zeroVforall k (f :: k -> Type) (g :: k -> Type) (p :: k).
f p -> g p -> (:*:) f g p
:*:g p
vg) )
  applyDualVector :: LinearSpace ((:*:) f g p) =>
Bilinear
  (DualVector ((:*:) f g p)) ((:*:) f g p) (Scalar ((:*:) f g p))
applyDualVector = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                         , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                         , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
              -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(GenericTupleDual DualVector (f p)
du DualVector (g p)
dv) (f p
u:*:g p
v)
                      -> ((forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>DualVector (f p)
du)forall s v w. LinearFunction s v w -> v -> w
-+$>f p
u) forall v. AdditiveGroup v => v -> v -> v
^+^ ((forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>DualVector (g p)
dv)forall s v w. LinearFunction s v w -> v -> w
-+$>g p
v)
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar ((:*:) f g p)) =>
Bilinear ((:*:) f g p +> w) ((:*:) f g p) w
applyLinear = case ( forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness :: ScalarSpaceWitness (f p)
                     , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                     , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (ScalarSpaceWitness (f p)
ScalarSpaceWitness, DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
              -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap (LinearMap (Scalar (g p)) (f p) w
fu, LinearMap (Scalar (g p)) (g p) w
fv)) (f p
u:*:g p
v)
                      -> ((forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) (f p) w
fu)forall s v w. LinearFunction s v w -> v -> w
-+$>f p
u) forall v. AdditiveGroup v => v -> v -> v
^+^ ((forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) (g p) w
fv)forall s v w. LinearFunction s v w -> v -> w
-+$>g p
v)
  composeLinear :: forall w x.
(LinearSpace w, TensorSpace x, Scalar w ~ Scalar ((:*:) f g p),
 Scalar x ~ Scalar ((:*:) f g p)) =>
Bilinear (w +> x) ((:*:) f g p +> w) ((:*:) f g p +> x)
composeLinear = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                       , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
       (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness)
              -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearMap (Scalar (g p)) w x
f (LinearMap (LinearMap (Scalar (g p)) (f p) w
fu, LinearMap (Scalar (g p)) (g p) w
fv))
                    -> forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap ( (forall v w x.
(LinearSpace v, LinearSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w +> x) (v +> w) (v +> x)
composeLinearforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) w x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) (f p) w
fu
                                 , (forall v w x.
(LinearSpace v, LinearSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w +> x) (v +> w) (v +> x)
composeLinearforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) w x
f)forall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) (g p) w
fv )
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar ((:*:) f g p)) =>
Bilinear
  (DualVector ((:*:) f g p ⊗ u))
  ((:*:) f g p ⊗ u)
  (Scalar ((:*:) f g p))
applyTensorFunctional = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (f p)
                               , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (g p) ) of
     (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness) -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                  \(LinearMap (LinearMap (Scalar (g p)) (f p) (DualVector u)
fu,LinearMap (Scalar (g p)) (g p) (DualVector u)
fv)) (Tensor (Tensor (Scalar (g p)) (f p) u
tu,Tensor (Scalar (g p)) (g p) u
tv))
          -> ((forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctionalforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) (f p) (DualVector u)
fu)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) u
tu) forall a. Num a => a -> a -> a
+ ((forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctionalforall s v w. LinearFunction s v w -> v -> w
-+$>LinearMap (Scalar (g p)) (f p) (DualVector u)
fu)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) u
tu)
  applyTensorLinMap ::  u w . ( LinearSpace u, TensorSpace w
                               , Scalar u ~ Scalar (g p), Scalar w ~ Scalar (g p) )
      => LinearFunction (Scalar (g p))
           (LinearMap (Scalar (g p)) (Tensor (Scalar (g p)) ((:*:) f g p) u) w)
           (LinearFunction (Scalar (g p)) (Tensor (Scalar (g p)) ((:*:) f g p) u) w)
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (g p),
 Scalar w ~ Scalar (g p)) =>
LinearFunction
  (Scalar (g p))
  (LinearMap
     (Scalar (g p)) (Tensor (Scalar (g p)) ((:*:) f g p) u) w)
  (LinearFunction
     (Scalar (g p)) (Tensor (Scalar (g p)) ((:*:) f g p) u) w)
applyTensorLinMap = case ( forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(f p)
                           , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(g p)
                           , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u ) of
     (DualSpaceWitness (f p)
DualSpaceWitness, DualSpaceWitness (g p)
DualSpaceWitness, DualSpaceWitness u
DualSpaceWitness) -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunctionforall κ (k :: κ -> κ -> Type) (a :: κ).
(Category k, Object k a) =>
k a a
`id`
             \(LinearMap (LinearMap
  (Scalar (g p)) (f p) (Tensor (Scalar (g p)) (DualVector u) w)
fu,LinearMap
  (Scalar (g p)) (g p) (Tensor (Scalar (g p)) (DualVector u) w)
fv)) (Tensor (Tensor (Scalar (g p)) (f p) u
tu,Tensor (Scalar (g p)) (g p) u
tv))
          -> ((forall v u w.
(LinearSpace v, LinearSpace u, TensorSpace w, Scalar u ~ Scalar v,
 Scalar w ~ Scalar v) =>
Bilinear ((v ⊗ u) +> w) (v ⊗ u) w
applyTensorLinMap forall s v w. LinearFunction s v w -> 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 forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall s a b. VSCCoercion s a b -> a -> b
-+$=> LinearMap
  (Scalar (g p)) (f p) (Tensor (Scalar (g p)) (DualVector u) w)
fu)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (f p) u
tu)
           forall v. AdditiveGroup v => v -> v -> v
^+^ ((forall v u w.
(LinearSpace v, LinearSpace u, TensorSpace w, Scalar u ~ Scalar v,
 Scalar w ~ Scalar v) =>
Bilinear ((v ⊗ u) +> w) (v ⊗ u) w
applyTensorLinMap forall s v w. LinearFunction s v w -> 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 forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall s a b. VSCCoercion s a b -> a -> b
-+$=> LinearMap
  (Scalar (g p)) (g p) (Tensor (Scalar (g p)) (DualVector u) w)
fv)forall s v w. LinearFunction s v w -> v -> w
-+$>Tensor (Scalar (g p)) (g p) u
tv)
  useTupleLinearSpaceComponents :: forall x y φ.
((:*:) f g p ~ (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 ((:*:) f g p))
  ((:*:) f g p)
  (DualVector (DualVector ((:*:) f g p)))
coerceDoubleDual = case ( forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @(f p), forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(f p)
                          , forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @(g p), forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(g p)) of
    (VSCCoercion (Scalar (g p)) (f p) (DualVector (DualVector (f p)))
VSCCoercion, DualSpaceWitness (f p)
DualSpaceWitness, VSCCoercion (Scalar (g p)) (g p) (DualVector (DualVector (g p)))
VSCCoercion, DualSpaceWitness (g p)
DualSpaceWitness) -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

instance ( LinearSpace (f p), LinearSpace (g p)
         , VectorSpace (DualVector (f p)), VectorSpace (DualVector (g p))
         , Scalar (f p) ~ Scalar (DualVector (f p))
         , Scalar (g p) ~ Scalar (DualVector (g p))
         , Scalar (DualVector (f p)) ~ Scalar (DualVector (g p)) )
    => LinearSpace (GenericTupleDual f g p) where
  type DualVector (GenericTupleDual f g p) = (f:*:g) p
  coerceDoubleDual :: VSCCoercion
  (Scalar (GenericTupleDual f g p))
  (GenericTupleDual f g p)
  (DualVector (DualVector (GenericTupleDual f g p)))
coerceDoubleDual = case ( forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @(f p), forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(f p)
                          , forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @(g p), forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(g p)) of
    (VSCCoercion
  (Scalar (DualVector (g p))) (f p) (DualVector (DualVector (f p)))
VSCCoercion, DualSpaceWitness (f p)
DualSpaceWitness, VSCCoercion
  (Scalar (DualVector (g p))) (g p) (DualVector (DualVector (g p)))
VSCCoercion, DualSpaceWitness (g p)
DualSpaceWitness) -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

newtype GenericNeedle' m
    = GenericNeedle' { forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle' :: DualVector (Needle (VRep m)) }
        deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall m x. Rep (GenericNeedle' m) x -> GenericNeedle' m
forall m x. GenericNeedle' m -> Rep (GenericNeedle' m) x
$cto :: forall m x. Rep (GenericNeedle' m) x -> GenericNeedle' m
$cfrom :: forall m x. GenericNeedle' m -> Rep (GenericNeedle' m) x
Generic)
instance AdditiveGroup (DualVector (Needle (VRep m)))
      => AdditiveGroup (GenericNeedle' m)
instance ( VectorSpace (DualVector (Needle (VRep m)))
         , Scalar (Needle m) ~ Scalar (DualVector (Needle (VRep m))) )
      => VectorSpace (GenericNeedle' m) where
  type Scalar (GenericNeedle' m) = Scalar (Needle m)
instance AdditiveGroup (DualVector (Needle (VRep m)))
      => AffineSpace (GenericNeedle' m) where
  type Diff (GenericNeedle' m) = GenericNeedle' m
  .-. :: GenericNeedle' m -> GenericNeedle' m -> Diff (GenericNeedle' m)
(.-.) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
  .+^ :: GenericNeedle' m -> Diff (GenericNeedle' m) -> GenericNeedle' m
(.+^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
instance AdditiveGroup (DualVector (Needle (VRep m)))
    => Semimanifold (GenericNeedle' m) where
  type Needle (GenericNeedle' m) = GenericNeedle' m
#if !MIN_VERSION_manifolds_core(0,6,0)
  type Interior (GenericNeedle' m) = GenericNeedle' m
  toInterior = pure
  fromInterior = id
  translateP = Tagged (^+^)
#endif
  .+~^ :: GenericNeedle' m -> Needle (GenericNeedle' m) -> GenericNeedle' m
(.+~^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
instance AdditiveGroup (DualVector (Needle (VRep m)))
    => PseudoAffine (GenericNeedle' m) where
  GenericNeedle' m
p.-~. :: GenericNeedle' m
-> GenericNeedle' m -> Maybe (Needle (GenericNeedle' m))
.-~.GenericNeedle' m
q = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (GenericNeedle' m
pforall v. AdditiveGroup v => v -> v -> v
^-^GenericNeedle' m
q)
  .-~! :: HasCallStack =>
GenericNeedle' m -> GenericNeedle' m -> Needle (GenericNeedle' m)
(.-~!) = forall v. AdditiveGroup v => v -> v -> v
(^-^)


instance  m . ( Semimanifold m, DimensionAware (DualVector (Needle (VRep m)))
               , Scalar (Needle m) ~ Scalar (DualVector (Needle (VRep m))) )
                  => DimensionAware (GenericNeedle' m) where
  type StaticDimension (GenericNeedle' m)
         = StaticDimension (DualVector (Needle (VRep m)))
  dimensionalityWitness :: DimensionalityWitness (GenericNeedle' m)
dimensionalityWitness = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness
                                 @(DualVector (Needle (VRep m))) of
    DimensionalityWitness (DualVector (Needle (VRep m)))
IsStaticDimensional -> forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
    DimensionalityWitness (DualVector (Needle (VRep m)))
IsFlexibleDimensional -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance  n m . ( Semimanifold m, n`Dimensional`DualVector (Needle (VRep m))
                 , Scalar (Needle m) ~ Scalar (DualVector (Needle (VRep m))) )
                  => n`Dimensional`GenericNeedle' m where
  knownDimensionalitySing :: Sing n
knownDimensionalitySing = forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @(DualVector (Needle (VRep m)))
  unsafeFromArrayWithOffset :: forall (α :: Type -> Type).
Vector α (Scalar (GenericNeedle' m)) =>
Int -> α (Scalar (GenericNeedle' m)) -> GenericNeedle' m
unsafeFromArrayWithOffset Int
i α (Scalar (GenericNeedle' m))
ar
      = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset @n @(DualVector (Needle (VRep m))) Int
i α (Scalar (GenericNeedle' m))
ar)
  unsafeWriteArrayWithOffset :: forall (α :: Type -> Type) σ.
Vector α (Scalar (GenericNeedle' m)) =>
Mutable α σ (Scalar (GenericNeedle' m))
-> Int -> GenericNeedle' m -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar (GenericNeedle' m))
ar
      = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat) v (α :: Type -> Type) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset @n @(DualVector (Needle (VRep m))) Mutable α σ (Scalar (GenericNeedle' m))
ar)

instance  m . ( Semimanifold m, TensorSpace (DualVector (Needle (VRep m)))
               , Scalar (Needle m) ~ Scalar (DualVector (Needle (VRep m))) )
                  => TensorSpace (GenericNeedle' m) where
  type TensorProduct (GenericNeedle' m) w
         = TensorProduct (DualVector (Needle (VRep m))) w
  wellDefinedVector :: GenericNeedle' m -> Maybe (GenericNeedle' m)
wellDefinedVector = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle' forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v. TensorSpace v => v -> Maybe v
wellDefinedVector forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle'
  wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
(GenericNeedle' m ⊗ w) -> Maybe (GenericNeedle' m ⊗ w)
wellDefinedTensor = forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s a b. VSCCoercion s a b -> Coercion a b
getVSCCoercion forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle')
                         forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> Maybe (v ⊗ w)
wellDefinedTensor forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle'forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  scalarSpaceWitness :: ScalarSpaceWitness (GenericNeedle' m)
scalarSpaceWitness = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness
                    :: ScalarSpaceWitness (DualVector (Needle (VRep m))) of
          ScalarSpaceWitness (DualVector (Needle (VRep m)))
ScalarSpaceWitness -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
  linearManifoldWitness :: LinearManifoldWitness (GenericNeedle' m)
linearManifoldWitness = case forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness
                    :: LinearManifoldWitness (DualVector (Needle (VRep m))) of
          LinearManifoldWitness (DualVector (Needle (VRep m)))
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
           BoundarylessWitness
#endif
              -> forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
                  BoundarylessWitness
#endif
  zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
GenericNeedle' m ⊗ w
zeroTensor = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
v ⊗ w
zeroTensor
  toFlatTensor :: GenericNeedle' m -+> (GenericNeedle' m ⊗ Scalar (GenericNeedle' m))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle'forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
                             forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor
                             forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle'
  fromFlatTensor :: (GenericNeedle' m ⊗ Scalar (GenericNeedle' m)) -+> GenericNeedle' m
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle'forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
                             forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor
                             forall (k :: Type -> Type -> Type) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle'
  addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
(GenericNeedle' m ⊗ w)
-> (GenericNeedle' m ⊗ w) -> GenericNeedle' m ⊗ w
addTensors (Tensor TensorProduct (GenericNeedle' m) w
s) (Tensor TensorProduct (GenericNeedle' m) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
addTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle' m) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle' m) w
t)
  subtractTensors :: forall w.
(TensorSpace (GenericNeedle' m), TensorSpace w,
 Scalar w ~ Scalar (GenericNeedle' m)) =>
(GenericNeedle' m ⊗ w)
-> (GenericNeedle' m ⊗ w) -> GenericNeedle' m ⊗ w
subtractTensors (Tensor TensorProduct (GenericNeedle' m) w
s) (Tensor TensorProduct (GenericNeedle' m) w
t)
       = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace v, TensorSpace w,
 Scalar w ~ Scalar v) =>
(v ⊗ w) -> (v ⊗ w) -> v ⊗ w
subtractTensors (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle' m) w
s) (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (GenericNeedle' m) w
t)
  scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
Bilinear
  (Scalar (GenericNeedle' m))
  (GenericNeedle' m ⊗ w)
  (GenericNeedle' m ⊗ w)
scaleTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar (DualVector (Needle (VRep m)))
μ -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle'
                                         forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (Scalar v) (v ⊗ w) (v ⊗ w)
scaleTensorforall s v w. LinearFunction s v w -> v -> w
-+$>Scalar (DualVector (Needle (VRep m)))
μ
  negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
(GenericNeedle' m ⊗ w) -+> (GenericNeedle' m ⊗ w)
negateTensor = forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle' forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (v ⊗ w)
negateTensor
  tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
Bilinear (GenericNeedle' m) w (GenericNeedle' m ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(GenericNeedle' DualVector (Needle (VRep m))
v) w
w
                      -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle'
                           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProductforall s v w. LinearFunction s v w -> v -> w
-+$>DualVector (Needle (VRep m))
v)forall s v w. LinearFunction s v w -> v -> w
-+$>w
w
  transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
(GenericNeedle' m ⊗ w) -+> (w ⊗ GenericNeedle' m)
transposeTensor = forall w.
(TensorSpace w, Scalar w ~ Scalar (Needle m)) =>
(GenericNeedle' m ⊗ w) -+> (w ⊗ GenericNeedle' m)
tT
   where tT ::  w . (TensorSpace w, Scalar w ~ Scalar (Needle m))
                => (GenericNeedle' m  w) -+> (w  GenericNeedle' m)
         tT :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Needle m)) =>
(GenericNeedle' m ⊗ w) -+> (w ⊗ GenericNeedle' m)
tT = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction
           forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: Type -> Type -> Type) (k :: Type -> Type -> Type) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct ([]::[w])
                              (forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion :: VSCCoercion
                                                    (Scalar (Needle m))
                                                    (DualVector (Needle (VRep m)))
                                                    (GenericNeedle' m))
                           forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion)
              forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor
              forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle'forall s a b. VSCCoercion s a b -> a -> b
-+$=>)
  fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x,
 Scalar w ~ Scalar (GenericNeedle' m),
 Scalar x ~ Scalar (GenericNeedle' m)) =>
Bilinear (w -+> x) (GenericNeedle' m ⊗ w) (GenericNeedle' m ⊗ x)
fmapTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar (DualVector (Needle (VRep m)))) w x
f -> forall v w v' w' (c :: Type -> Type -> Type) s' s.
(TensorProduct v w ~ TensorProduct v' w,
 TensorProduct v w' ~ TensorProduct v' w') =>
c v v'
-> LinearFunction s' (Tensor s v w) (Tensor s v w')
-> LinearFunction s' (Tensor s v' w) (Tensor s v' w')
envTensorLHSCoercion forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle' (forall v w x.
(TensorSpace v, TensorSpace w, TensorSpace x, Scalar w ~ Scalar v,
 Scalar x ~ Scalar v) =>
Bilinear (w -+> x) (v ⊗ w) (v ⊗ x)
fmapTensorforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (DualVector (Needle (VRep m)))) w x
f)
  fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar (GenericNeedle' m),
 Scalar w ~ Scalar (GenericNeedle' m),
 Scalar x ~ Scalar (GenericNeedle' m)) =>
Bilinear
  ((w, x) -+> u)
  (GenericNeedle' m ⊗ w, GenericNeedle' m ⊗ x)
  (GenericNeedle' m ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
         \LinearFunction (Scalar (DualVector (Needle (VRep m)))) (w, x) u
f (Tensor (Scalar (DualVector (Needle (VRep m)))) (GenericNeedle' m) w
wt, Tensor (Scalar (DualVector (Needle (VRep m)))) (GenericNeedle' m) x
xt) -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle'
                        forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v u w x.
(TensorSpace v, TensorSpace u, TensorSpace w, TensorSpace x,
 Scalar u ~ Scalar v, Scalar w ~ Scalar v, Scalar x ~ Scalar v) =>
Bilinear ((w, x) -+> u) (v ⊗ w, v ⊗ x) (v ⊗ u)
fzipTensorWithforall s v w. LinearFunction s v w -> v -> w
-+$>LinearFunction (Scalar (DualVector (Needle (VRep m)))) (w, x) u
f)
                         forall s v w. LinearFunction s v w -> v -> w
-+$>( forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (DualVector (Needle (VRep m)))) (GenericNeedle' m) w
wt
                             , forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor (Scalar (DualVector (Needle (VRep m)))) (GenericNeedle' m) x
xt )
  tensorUnsafeFromArrayWithOffset
   ::  w nn α . ( TensorSpace w, nn`Dimensional`w
                , Scalar w ~ (Scalar (DualVector (Needle (VRep m))))
                , GArr.Vector α (Scalar (DualVector (Needle (VRep m)))) )
           => Int -> α (Scalar (DualVector (Needle (VRep m))))
                -> (GenericNeedle' mw)
  tensorUnsafeFromArrayWithOffset :: forall w (nn :: Nat) (α :: Type -> Type).
(TensorSpace w, Dimensional nn w,
 Scalar w ~ Scalar (DualVector (Needle (VRep m))),
 Vector α (Scalar (DualVector (Needle (VRep m))))) =>
Int
-> α (Scalar (DualVector (Needle (VRep m))))
-> GenericNeedle' m ⊗ w
tensorUnsafeFromArrayWithOffset
   = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector (Needle (VRep m))) of
    DimensionalityWitness (DualVector (Needle (VRep m)))
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `Needle (VRep m)` is static-dimensional."
    DimensionalityWitness (DualVector (Needle (VRep m)))
IsStaticDimensional -> \Int
i α (Scalar (DualVector (Needle (VRep m))))
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffset
                   @(DualVector (Needle (VRep m))) @w Int
i α (Scalar (DualVector (Needle (VRep m))))
ar)
  tensorUnsafeWriteArrayWithOffset
   ::  w nn α σ . ( TensorSpace w, nn`Dimensional`w
                , Scalar w ~ (Scalar (DualVector (Needle (VRep m))))
                , GArr.Vector α (Scalar (DualVector (Needle (VRep m)))) )
           => GArr.Mutable α σ (Scalar (DualVector (Needle (VRep m))))
                -> Int -> (GenericNeedle' mw) -> ST σ ()
  tensorUnsafeWriteArrayWithOffset :: forall w (nn :: Nat) (α :: Type -> Type) σ.
(TensorSpace w, Dimensional nn w,
 Scalar w ~ Scalar (DualVector (Needle (VRep m))),
 Vector α (Scalar (DualVector (Needle (VRep m))))) =>
Mutable α σ (Scalar (DualVector (Needle (VRep m))))
-> Int -> (GenericNeedle' m ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
   = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @(DualVector (Needle (VRep m))) of
    DimensionalityWitness (DualVector (Needle (VRep m)))
IsFlexibleDimensional -> forall a. HasCallStack => [Char] -> a
error [Char]
"This is impossible, since this can only be evaluated if `Needle (VRep m)` is static-dimensional."
    DimensionalityWitness (DualVector (Needle (VRep m)))
IsStaticDimensional -> \Mutable α σ (Scalar (DualVector (Needle (VRep m))))
ar
       -> coerce :: forall a b. Coercible a b => a -> b
coerce (forall v w (α :: Type -> Type) σ (n :: Nat) (m :: Nat).
(TensorSpace v, Dimensional n v, TensorSpace w, Dimensional m w,
 Scalar w ~ Scalar v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
                   @(DualVector (Needle (VRep m))) @w Mutable α σ (Scalar (DualVector (Needle (VRep m))))
ar)
  coerceFmapTensorProduct ::  p a b
         . ( Hask.Functor p
           , TensorSpace a, Scalar a ~ Scalar (DualVector (Needle (VRep m)))
           , TensorSpace b, Scalar b ~ Scalar (DualVector (Needle (VRep m))) )
             => p (GenericNeedle' m) -> VSCCoercion (Scalar a) a b
               -> Coercion (TensorProduct (GenericNeedle' m) a)
                           (TensorProduct (GenericNeedle' m) b)
  coerceFmapTensorProduct :: forall (p :: Type -> Type) a b.
(Functor p, TensorSpace a,
 Scalar a ~ Scalar (DualVector (Needle (VRep m))), TensorSpace b,
 Scalar b ~ Scalar (DualVector (Needle (VRep m)))) =>
p (GenericNeedle' m)
-> VSCCoercion (Scalar a) a b
-> Coercion
     (TensorProduct (GenericNeedle' m) a)
     (TensorProduct (GenericNeedle' m) b)
coerceFmapTensorProduct p (GenericNeedle' m)
p VSCCoercion (Scalar a) a b
crc = case forall v (p :: Type -> Type) a b.
(TensorSpace v, Functor p, TensorSpace a, Scalar a ~ Scalar v,
 TensorSpace b, Scalar b ~ Scalar v) =>
p v
-> VSCCoercion (Scalar v) a b
-> Coercion (TensorProduct v a) (TensorProduct v b)
coerceFmapTensorProduct
                              ([]::[DualVector (Needle (VRep m))]) VSCCoercion (Scalar a) a b
crc of
                  Coercion
  (TensorProduct (DualVector (Needle (VRep m))) a)
  (TensorProduct (DualVector (Needle (VRep m))) b)
Coercion -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion


instance  s m . ( Num' s
                 , Semimanifold m, LinearSpace (Needle (VRep m))
                 , Scalar (Needle m) ~ s
                 , Scalar (Needle (VRep m)) ~ s )
                  => LinearSpace (GenericNeedle m) where
  type DualVector (GenericNeedle m) = GenericNeedle' m
  linearId :: GenericNeedle m +> GenericNeedle m
linearId = forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
              forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle
               forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. LinearSpace v => LinearMap (Scalar v) v v
linearId
  dualSpaceWitness :: DualSpaceWitness (GenericNeedle m)
dualSpaceWitness = case ( forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) ) of
              (ClosedScalarWitness s
ClosedScalarWitness, DualSpaceWitness (Needle (VRep m))
DualSpaceWitness) -> 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
  applyDualVector :: LinearSpace (GenericNeedle m) =>
Bilinear
  (DualVector (GenericNeedle m))
  (GenericNeedle m)
  (Scalar (GenericNeedle m))
applyDualVector = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(GenericNeedle' DualVector (Needle (VRep m))
dv) (GenericNeedle Needle (VRep m)
v)
                        -> (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>DualVector (Needle (VRep m))
dv)forall s v w. LinearFunction s v w -> v -> w
-+$>Needle (VRep m)
v
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
Bilinear (GenericNeedle m +> w) (GenericNeedle m) w
applyLinear = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (GenericNeedle m)) w
f) (GenericNeedle Needle (VRep m)
v)
                      -> (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (GenericNeedle m)) w
f)forall s v w. LinearFunction s v w -> v -> w
-+$>Needle (VRep m)
v
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (GenericNeedle m)) =>
(GenericNeedle m ⊗ w) +> (GenericNeedle m ⊗ w)
tensorId = forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle)
                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. Needle (VRep x) -> GenericNeedle x
GenericNeedle) forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (GenericNeedle m)) =>
Bilinear
  (DualVector (GenericNeedle m ⊗ u))
  (GenericNeedle m ⊗ u)
  (Scalar (GenericNeedle m))
applyTensorFunctional = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (GenericNeedle m)) (DualVector u)
f) Tensor s (GenericNeedle m) u
t ->
              (forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctionalforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (GenericNeedle m)) (DualVector u)
f)
                 forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (GenericNeedle m) u
t
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (GenericNeedle m),
 Scalar w ~ Scalar (GenericNeedle m)) =>
Bilinear ((GenericNeedle m ⊗ u) +> w) (GenericNeedle m ⊗ u) w
applyTensorLinMap = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Tensor s (GenericNeedle m) u)) w
f) Tensor s (GenericNeedle m) u
t
                -> (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
applyTensorLinMapforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (Tensor s (GenericNeedle m) u)) w
f)
                    forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall x. GenericNeedle x -> Needle (VRep x)
getGenericNeedle forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (GenericNeedle m) u
t
  useTupleLinearSpaceComponents :: forall x y φ.
(GenericNeedle m ~ (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 (GenericNeedle m))
  (GenericNeedle m)
  (DualVector (DualVector (GenericNeedle m)))
coerceDoubleDual = case forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @(Needle (VRep m)) of
    VSCCoercion
  (Scalar (Needle (VRep m)))
  (Needle (VRep m))
  (DualVector (DualVector (Needle (VRep m))))
VSCCoercion -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion

instance  s m . ( Num' s
                 , Semimanifold m
                 , LinearSpace (Needle (VRep m))
                 , TensorSpace (DualVector (Needle (VRep m)))
                 , Scalar (Needle m) ~ s
                 , Scalar (Needle (VRep m)) ~ s
                 , Scalar (DualVector (Needle (VRep m))) ~ s )
                  => LinearSpace (GenericNeedle' m) where
  type DualVector (GenericNeedle' m) = GenericNeedle m
  linearId :: GenericNeedle' m +> GenericNeedle' m
linearId = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) of
       DualSpaceWitness (Needle (VRep m))
DualSpaceWitness -> forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
                         forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. LinearSpace v => LinearMap (Scalar v) v v
linearId
  dualSpaceWitness :: DualSpaceWitness (GenericNeedle' m)
dualSpaceWitness = case ( forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s
                          , forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) ) of
              (ClosedScalarWitness s
ClosedScalarWitness, DualSpaceWitness (Needle (VRep m))
DualSpaceWitness) -> 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
  applyDualVector :: LinearSpace (GenericNeedle' m) =>
Bilinear
  (DualVector (GenericNeedle' m))
  (GenericNeedle' m)
  (Scalar (GenericNeedle' m))
applyDualVector = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) of
       DualSpaceWitness (Needle (VRep m))
DualSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(GenericNeedle Needle (VRep m)
dv) (GenericNeedle' DualVector (Needle (VRep m))
v)
                        -> (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>Needle (VRep m)
dv)forall s v w. LinearFunction s v w -> v -> w
-+$>DualVector (Needle (VRep m))
v
  applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
Bilinear (GenericNeedle' m +> w) (GenericNeedle' m) w
applyLinear = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) of
       DualSpaceWitness (Needle (VRep m))
DualSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (GenericNeedle' m)) w
f) (GenericNeedle' DualVector (Needle (VRep m))
v)
                      -> (forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinearforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (GenericNeedle' m)) w
f)forall s v w. LinearFunction s v w -> v -> w
-+$>DualVector (Needle (VRep m))
v
  tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (GenericNeedle' m)) =>
(GenericNeedle' m ⊗ w) +> (GenericNeedle' m ⊗ w)
tensorId = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) of
       DualSpaceWitness (Needle (VRep m))
DualSpaceWitness -> forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct (DualVector v) w ~ TensorProduct (DualVector v') w,
 StaticDimension v ~ StaticDimension v') =>
c v' v -> VSCCoercion s (LinearMap s v w) (LinearMap s v' w)
pseudoPrecomposeLinmap (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle')
                forall κ (k :: κ -> κ -> Type) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: Type -> Type) (r :: Type -> Type -> Type)
       (t :: Type -> Type -> Type) 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 (forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. DualVector (Needle (VRep m)) -> GenericNeedle' m
GenericNeedle') forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(LinearSpace v, LinearSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) +> (v ⊗ w)
tensorId
  applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (GenericNeedle' m)) =>
Bilinear
  (DualVector (GenericNeedle' m ⊗ u))
  (GenericNeedle' m ⊗ u)
  (Scalar (GenericNeedle' m))
applyTensorFunctional = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) of
       DualSpaceWitness (Needle (VRep m))
DualSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (GenericNeedle' m)) (DualVector u)
f) Tensor s (GenericNeedle' m) u
t ->
              (forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctionalforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (GenericNeedle' m)) (DualVector u)
f)
                 forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (GenericNeedle' m) u
t
  applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w,
 Scalar u ~ Scalar (GenericNeedle' m),
 Scalar w ~ Scalar (GenericNeedle' m)) =>
Bilinear ((GenericNeedle' m ⊗ u) +> w) (GenericNeedle' m ⊗ u) w
applyTensorLinMap = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness (Needle (VRep m)) of
       DualSpaceWitness (Needle (VRep m))
DualSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Tensor s (GenericNeedle' m) u)) w
f) Tensor s (GenericNeedle' m) u
t
                -> (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
applyTensorLinMapforall s v w. LinearFunction s v w -> v -> w
-+$>forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (DualVector (Tensor s (GenericNeedle' m) u)) w
f)
                    forall s v w. LinearFunction s v w -> v -> w
-+$>forall v w v' (c :: Type -> Type -> Type) s.
(TensorProduct v w ~ TensorProduct v' w,
 StaticDimension v ~ StaticDimension v') =>
c v v' -> VSCCoercion s (Tensor s v w) (Tensor s v' w)
pseudoFmapTensorLHS forall m. GenericNeedle' m -> DualVector (Needle (VRep m))
getGenericNeedle' forall (f :: Type -> Type -> Type) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (GenericNeedle' m) u
t
  useTupleLinearSpaceComponents :: forall x y φ.
(GenericNeedle' m ~ (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 (GenericNeedle' m))
  (GenericNeedle' m)
  (DualVector (DualVector (GenericNeedle' m)))
coerceDoubleDual = case forall v.
LinearSpace v =>
VSCCoercion (Scalar v) v (DualVector (DualVector v))
coerceDoubleDual @(Needle (VRep m)) of
    VSCCoercion
  (Scalar (Needle (VRep m)))
  (Needle (VRep m))
  (DualVector (DualVector (Needle (VRep m))))
VSCCoercion -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion