Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- type (**) f g = Compose f g
- type (++) f g = Product f g
- data Dual a c
- dual :: FreeCounital a f => f a -> Dual a (Rep f)
- image' :: Semiring a => Foldable f => f (a, c) -> Dual a c
- (!*) :: Free f => Dual a (Rep f) -> f a -> a
- (*!) :: Free f => f a -> Dual a (Rep f) -> a
- toTran :: (b -> Dual a c) -> Tran a b c
- fromTran :: Tran a b c -> b -> Dual a c
- type Endo a b = Tran a b b
- data Tran a b c
- arr :: Arrow a => (b -> c) -> a b c
- tran :: Free f => FreeCounital a g => (f ** g) a -> Tran a (Rep f) (Rep g)
- image :: Semiring a => (b -> [(a, c)]) -> Tran a b c
- (!#) :: Free f => Free g => Tran a (Rep f) (Rep g) -> g a -> f a
- (#!) :: Free f => Free g => g a -> Tran a (Rep f) (Rep g) -> f a
- (!#!) :: Tran a c d -> Tran a b c -> Tran a b d
- dimap :: (b1 -> b2) -> (c1 -> c2) -> Tran a b2 c1 -> Tran a b1 c2
- invmap :: (a1 -> a2) -> (a2 -> a1) -> Tran a1 b c -> Tran a2 b c
- init :: Unital a b => Tran a b ()
- init' :: Unital a b => b -> Dual a ()
- coinit :: Counital a c => Tran a () c
- coinit' :: Counital a c => Dual a c
- braid :: Tran a (b, c) (c, b)
- cobraid :: Tran a (b + c) (c + b)
- join :: Algebra a b => Tran a b (b, b)
- join' :: Algebra a b => b -> Dual a (b, b)
- cojoin :: Coalgebra a c => Tran a (c, c) c
- cojoin' :: Coalgebra a c => c -> c -> Dual a c
- split :: (b -> (b1, b2)) -> Tran a b1 c -> Tran a b2 c -> Tran a b c
- cosplit :: ((c1 + c2) -> c) -> Tran a b c1 -> Tran a b c2 -> Tran a b c
- convolve :: Algebra a b => Coalgebra a c => Tran a b c -> Tran a b c -> Tran a b c
- convolve' :: Algebra a b => Coalgebra a c => (b -> Dual a c) -> (b -> Dual a c) -> b -> Dual a c
- commutator :: (Additive - Group) a => Endo a b -> Endo a b -> Endo a b
- (.#) :: Free f => FreeCounital a g => (f ** g) a -> g a -> f a
- (#.) :: FreeCounital a f => Free g => f a -> (f ** g) a -> g a
- (.#.) :: Free f => FreeCounital a g => Free h => (f ** g) a -> (g ** h) a -> (f ** h) a
- outer :: Semiring a => Free f => Free g => f a -> g a -> (f ** g) a
- inner :: FreeCounital a f => f a -> f a -> a
- quadrance :: FreeCounital a f => f a -> a
- trace :: FreeBialgebra a f => (f ** f) a -> a
- transpose :: Free f => Free g => (f ** g) a -> (g ** f) a
- diag :: FreeCoalgebra a f => f a -> (f ** f) a
- codiag :: FreeAlgebra a f => (f ** f) a -> f a
- scalar :: FreeCoalgebra a f => a -> (f ** f) a
- identity :: FreeCoalgebra a f => (f ** f) a
- row :: Free f => Rep f -> (f ** g) a -> g a
- rows :: Free f => Free g => g a -> (f ** g) a
- col :: Free f => Free g => Rep g -> (f ** g) a -> f a
- cols :: Free f => Free g => f a -> (f ** g) a
- projl :: Free f => Free g => (f ++ g) a -> f a
- projr :: Free f => Free g => (f ++ g) a -> g a
- compl :: Free f1 => Free f2 => Free g => Tran a (Rep f1) (Rep f2) -> (f2 ** g) a -> (f1 ** g) a
- compr :: Free f => Free g1 => Free g2 => Tran a (Rep g1) (Rep g2) -> (f ** g2) a -> (f ** g1) a
- complr :: Free f1 => Free f2 => Free g1 => Free g2 => Tran a (Rep f1) (Rep f2) -> Tran a (Rep g1) (Rep g2) -> (f2 ** g2) a -> (f1 ** g1) a
- class Distributive f => Representable (f :: Type -> Type) where
Types
Linear functionals
Linear functionals from elements of a free semimodule to a scalar.
f!*
(x+
y) = (f!*
x)+
(f!*
y) f!*
(x.*
a) = a*
(f!*
x)
Instances
dual :: FreeCounital a f => f a -> Dual a (Rep f) Source #
Take the dual of a vector.
>>>
dual (V2 3 4) !% V2 1 2 :: Int
11
image' :: Semiring a => Foldable f => f (a, c) -> Dual a c Source #
Create a Dual
from a linear combination of basis vectors.
>>>
image' [(2, E31),(3, E32)] !* V3 1 1 1 :: Int
5
(!*) :: Free f => Dual a (Rep f) -> f a -> a infixr 3 Source #
Apply a linear functional to a vector.
(*!) :: Free f => f a -> Dual a (Rep f) -> a infixl 3 Source #
Apply a linear functional to a vector.
Linear transformations
type Endo a b = Tran a b b Source #
An endomorphism over a free semimodule.
>>>
one + two !# V2 1 2 :: V2 Double
V2 3.0 6.0
A linear transformation between free semimodules indexed with bases b and c.
f '!#' x '+' y = (f '!#' x) + (f '!#' y) f '!#' (r '.*' x) = r '.*' (f '!#' x)
Instances
image :: Semiring a => (b -> [(a, c)]) -> Tran a b c Source #
Create a Tran
from a linear combination of basis vectors.
>>>
image (e2 [(2, E31),(3, E32)] [(1, E33)]) !# V3 1 1 1 :: V2 Int
V2 5 1
(!#) :: Free f => Free g => Tran a (Rep f) (Rep g) -> g a -> f a infixr 2 Source #
Apply a transformation to a vector.
(#!) :: Free f => Free g => g a -> Tran a (Rep f) (Rep g) -> f a infixl 2 Source #
Apply a transformation to a vector.
dimap :: (b1 -> b2) -> (c1 -> c2) -> Tran a b2 c1 -> Tran a b1 c2 Source #
Tran
is a profunctor in the category of semimodules.
Caution: Arbitrary mapping functions may violate linearity.
>>>
dimap id (e3 True True False) (arr id) !# 4 :+ 5 :: V3 Int
V3 5 5 4
invmap :: (a1 -> a2) -> (a2 -> a1) -> Tran a1 b c -> Tran a2 b c Source #
Tran
is an invariant functor.
Common linear functionals and transformations
Other operations on linear functionals and transformations
convolve :: Algebra a b => Coalgebra a c => Tran a b c -> Tran a b c -> Tran a b c Source #
Convolution with an associative algebra and coassociative coalgebra
convolve' :: Algebra a b => Coalgebra a c => (b -> Dual a c) -> (b -> Dual a c) -> b -> Dual a c Source #
TODO: Document
commutator :: (Additive - Group) a => Endo a b -> Endo a b -> Endo a b Source #
Commutator or Lie bracket of two semimodule endomorphisms.
Matrix arithmetic
(#.) :: FreeCounital a f => Free g => f a -> (f ** g) a -> g a infixl 7 Source #
Multiply a matrix on the left by a row vector.
>>>
V2 1 2 #. m23 3 4 5 6 7 8
V3 15 18 21
>>>
V2 1 2 #. m23 3 4 5 6 7 8 #. m32 1 0 0 0 0 0 :: V2 Int
V2 15 0
(.#.) :: Free f => FreeCounital a g => Free h => (f ** g) a -> (g ** h) a -> (f ** h) a infixr 7 Source #
Multiply two matrices.
>>>
m22 1 2 3 4 .#. m22 1 2 3 4 :: M22 Int
Compose (V2 (V2 7 10) (V2 15 22))
>>>
m23 1 2 3 4 5 6 .#. m32 1 2 3 4 4 5 :: M22 Int
Compose (V2 (V2 19 25) (V2 43 58))
outer :: Semiring a => Free f => Free g => f a -> g a -> (f ** g) a Source #
Outer product.
>>>
V2 1 1 `outer` V2 1 1
Compose (V2 (V2 1 1) (V2 1 1))
inner :: FreeCounital a f => f a -> f a -> a infix 6 Source #
Inner product.
This is a variant of xmult
restricted to free functors.
>>>
V3 1 2 3 `inner` V3 1 2 3
14
quadrance :: FreeCounital a f => f a -> a Source #
Squared l2 norm of a vector.
trace :: FreeBialgebra a f => (f ** f) a -> a Source #
Trace of an endomorphism.
>>>
trace $ m22 1.0 2.0 3.0 4.0
5.0
transpose :: Free f => Free g => (f ** g) a -> (g ** f) a Source #
Transpose a matrix.
>>>
transpose $ m23 1 2 3 4 5 6 :: M32 Int
V3 (V2 1 4) (V2 2 5) (V2 3 6)
Matrix constructors and accessors
diag :: FreeCoalgebra a f => f a -> (f ** f) a Source #
Obtain a diagonal matrix from a vector.
diag
=flip
bindRep
id
.
getCompose
codiag :: FreeAlgebra a f => (f ** f) a -> f a Source #
scalar :: FreeCoalgebra a f => a -> (f ** f) a Source #
Obtain a scalar matrix from a scalar.
>>>
scalar 4.0 :: M22 Double
Compose (V2 (V2 4.0 0.0) (V2 0.0 4.0))
identity :: FreeCoalgebra a f => (f ** f) a Source #
Obtain an identity matrix.
>>>
identity :: M33 Int
Compose (V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1))
row :: Free f => Rep f -> (f ** g) a -> g a Source #
Retrieve a row of a matrix.
>>>
row E22 $ m23 1 2 3 4 5 6
V3 4 5 6
rows :: Free f => Free g => g a -> (f ** g) a Source #
Obtain a matrix by stacking rows.
>>>
rows (V2 1 2) :: M22 Int
V2 (V2 1 2) (V2 1 2)
col :: Free f => Free g => Rep g -> (f ** g) a -> f a Source #
Retrieve a column of a matrix.
>>>
elt E22 . col E31 $ m23 1 2 3 4 5 6
4
cols :: Free f => Free g => f a -> (f ** g) a Source #
Obtain a matrix by stacking columns.
>>>
cols (V2 1 2) :: M22 Int
V2 (V2 1 1) (V2 2 2)
projl :: Free f => Free g => (f ++ g) a -> f a Source #
Project onto the left-hand component of a direct sum.
projr :: Free f => Free g => (f ++ g) a -> g a Source #
Project onto the right-hand component of a direct sum.
compl :: Free f1 => Free f2 => Free g => Tran a (Rep f1) (Rep f2) -> (f2 ** g) a -> (f1 ** g) a Source #
Left (post) composition with a linear transformation.
compr :: Free f => Free g1 => Free g2 => Tran a (Rep g1) (Rep g2) -> (f ** g2) a -> (f ** g1) a Source #
Right (pre) composition with a linear transformation.
complr :: Free f1 => Free f2 => Free g1 => Free g2 => Tran a (Rep f1) (Rep f2) -> Tran a (Rep g1) (Rep g2) -> (f2 ** g2) a -> (f1 ** g1) a Source #
Reexports
class Distributive f => Representable (f :: Type -> Type) where #
A Functor
f
is Representable
if tabulate
and index
witness an isomorphism to (->) x
.
Every Distributive
Functor
is actually Representable
.
Every Representable
Functor
from Hask to Hask is a right adjoint.
tabulate
.index
≡ idindex
.tabulate
≡ idtabulate
.return
≡return
Nothing