rings-0.1.3: Ring-like objects.

Safe HaskellSafe
LanguageHaskell2010

Data.Semimodule.Free

Contents

Synopsis

Types

Vectors

newtype Vec a b Source #

A vector in a vector space or free semimodule.

Equivalent to Op.

Vectors transform contravariantly as a function of their bases.

See https://en.wikipedia.org/wiki/Covariance_and_contravariance_of_vectors#Definition.

Constructors

Vec 

Fields

Instances
Bisemimodule a a a => Bisemimodule a a (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: a -> a -> Vec a b -> Vec a b Source #

Semiring a => RightSemimodule a (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: a -> Vec a b -> Vec a b Source #

Semiring a => LeftSemimodule a (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: a -> Vec a b -> Vec a b Source #

(Additive - Semigroup) a => Semigroup (Additive (Vec a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(<>) :: Additive (Vec a b) -> Additive (Vec a b) -> Additive (Vec a b) #

sconcat :: NonEmpty (Additive (Vec a b)) -> Additive (Vec a b) #

stimes :: Integral b0 => b0 -> Additive (Vec a b) -> Additive (Vec a b) #

(Additive - Monoid) a => Monoid (Additive (Vec a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

mempty :: Additive (Vec a b) #

mappend :: Additive (Vec a b) -> Additive (Vec a b) -> Additive (Vec a b) #

mconcat :: [Additive (Vec a b)] -> Additive (Vec a b) #

Contravariant (Vec a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

contramap :: (a0 -> b) -> Vec a b -> Vec a a0 #

(>$) :: b -> Vec a b -> Vec a a0 #

(Additive - Group) a => Group (Additive (Vec a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

inv :: Additive (Vec a b) -> Additive (Vec a b) #

greplicate :: Integer -> Additive (Vec a b) -> Additive (Vec a b) #

(Additive - Group) a => Loop (Additive (Vec a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lempty :: Additive (Vec a b) #

lreplicate :: Natural -> Additive (Vec a b) -> Additive (Vec a b) #

(Additive - Group) a => Quasigroup (Additive (Vec a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(//) :: Additive (Vec a b) -> Additive (Vec a b) -> Additive (Vec a b) #

(\\) :: Additive (Vec a b) -> Additive (Vec a b) -> Additive (Vec a b) #

(Additive - Group) a => Magma (Additive (Vec a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(<<) :: Additive (Vec a b) -> Additive (Vec a b) -> Additive (Vec a b) #

Category Vec Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

id :: Vec a a #

(.) :: Vec b c -> Vec a b -> Vec a c #

Semiring a => RightSemimodule (End a b) (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: End a b -> Vec a b -> Vec a b Source #

Semiring a => LeftSemimodule (End a b) (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: End a b -> Vec a b -> Vec a b Source #

Semiring a => Bisemimodule (End a b) (End a b) (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: End a b -> End a b -> Vec a b -> Vec a b Source #

vmap :: Lin a b c -> Vec a c -> Vec a b Source #

Use a linear transformation to map over a vector space.

Note that the basis transforms https://en.wikipedia.org/wiki/Covariant_transformation#Contravariant_transformation contravariantly.

join :: Algebra a b => Vec a (b, b) -> Vec a b Source #

Obtain a vector from a vector on the tensor product space.

init :: Unital a b => a -> Vec a b Source #

Obtain a vector from the unit of a unital algebra.

init a = vmap initial (Vec $ _ -> a)

(!*) :: Vec a b -> Cov a b -> a infixr 7 Source #

Apply a covector to a vector on the right.

(*!) :: Cov a b -> Vec a b -> a infixl 7 Source #

Apply a covector to a vector on the left.

(!*!) :: Algebra a b => Vec a b -> Vec a b -> Vec a b infixr 7 Source #

Multiplication operator on an algebra over a free semimodule.

>>> flip runVec E22 $ (vec $ V2 1 2) !*! (vec $ V2 7 4)
8

Caution in general mult needn't be commutative, nor associative.

Covectors

newtype Cov a c Source #

Linear functionals from elements of a free semimodule to a scalar.

f !* (x + y) = (f !* x) + (f !* y)
f !* (x .* a) = a * (f !* x)

Caution: You must ensure these laws hold when using the default constructor.

Co-vectors transform covariantly as a function of their bases.

See https://en.wikipedia.org/wiki/Covariance_and_contravariance_of_vectors#Definition.

Constructors

Cov 

Fields

Instances
Bisemimodule a a a => Bisemimodule a a (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: a -> a -> Cov a b -> Cov a b Source #

Semiring a => RightSemimodule a (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: a -> Cov a b -> Cov a b Source #

Semiring a => LeftSemimodule a (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: a -> Cov a b -> Cov a b Source #

Monad (Cov a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(>>=) :: Cov a a0 -> (a0 -> Cov a b) -> Cov a b #

(>>) :: Cov a a0 -> Cov a b -> Cov a b #

return :: a0 -> Cov a a0 #

fail :: String -> Cov a a0 #

Functor (Cov a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

fmap :: (a0 -> b) -> Cov a a0 -> Cov a b #

(<$) :: a0 -> Cov a b -> Cov a a0 #

Applicative (Cov a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

pure :: a0 -> Cov a a0 #

(<*>) :: Cov a (a0 -> b) -> Cov a a0 -> Cov a b #

liftA2 :: (a0 -> b -> c) -> Cov a a0 -> Cov a b -> Cov a c #

(*>) :: Cov a a0 -> Cov a b -> Cov a b #

(<*) :: Cov a a0 -> Cov a b -> Cov a a0 #

(Additive - Semigroup) a => Semigroup (Additive (Cov a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(<>) :: Additive (Cov a b) -> Additive (Cov a b) -> Additive (Cov a b) #

sconcat :: NonEmpty (Additive (Cov a b)) -> Additive (Cov a b) #

stimes :: Integral b0 => b0 -> Additive (Cov a b) -> Additive (Cov a b) #

(Additive - Monoid) a => Monoid (Additive (Cov a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

mempty :: Additive (Cov a b) #

mappend :: Additive (Cov a b) -> Additive (Cov a b) -> Additive (Cov a b) #

mconcat :: [Additive (Cov a b)] -> Additive (Cov a b) #

(Additive - Monoid) a => Alternative (Cov a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

empty :: Cov a a0 #

(<|>) :: Cov a a0 -> Cov a a0 -> Cov a a0 #

some :: Cov a a0 -> Cov a [a0] #

many :: Cov a a0 -> Cov a [a0] #

(Additive - Monoid) a => MonadPlus (Cov a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

mzero :: Cov a a0 #

mplus :: Cov a a0 -> Cov a a0 -> Cov a a0 #

(Additive - Group) a => Group (Additive (Cov a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

inv :: Additive (Cov a b) -> Additive (Cov a b) #

greplicate :: Integer -> Additive (Cov a b) -> Additive (Cov a b) #

(Additive - Group) a => Loop (Additive (Cov a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lempty :: Additive (Cov a b) #

lreplicate :: Natural -> Additive (Cov a b) -> Additive (Cov a b) #

(Additive - Group) a => Quasigroup (Additive (Cov a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(//) :: Additive (Cov a b) -> Additive (Cov a b) -> Additive (Cov a b) #

(\\) :: Additive (Cov a b) -> Additive (Cov a b) -> Additive (Cov a b) #

(Additive - Group) a => Magma (Additive (Cov a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(<<) :: Additive (Cov a b) -> Additive (Cov a b) -> Additive (Cov a b) #

Sieve (Lin a) (Cov a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

sieve :: Lin a a0 b -> a0 -> Cov a b #

Counital a b => RightSemimodule (End a b) (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: End a b -> Cov a b -> Cov a b Source #

Counital a b => LeftSemimodule (End a b) (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: End a b -> Cov a b -> Cov a b Source #

Counital a b => Bisemimodule (End a b) (End a b) (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: End a b -> End a b -> Cov a b -> Cov a b Source #

images :: Semiring a => Foldable f => f (a, c) -> Cov a c Source #

Obtain a covector from a linear combination of basis elements.

>>> images [(2, E31),(3, E32)] !* vec (V3 1 1 1) :: Int
5

cmap :: Lin a b c -> Cov a b -> Cov a c Source #

Use a linear transformation to map over a dual space.

Note that the basis transforms covariantly.

cojoin :: Coalgebra a c => Cov a (c, c) -> Cov a c Source #

Obtain a covector from a covector on the tensor product space.

coinit :: Counital a c => Cov a c Source #

Obtain a covector from the counit of a counital coalgebra.

coinit = cmap coinitial (Cov $ f -> f ())

comult :: Coalgebra a c => Cov a c -> Cov a c -> Cov a c infixr 7 Source #

Multiplication operator on a coalgebra over a free semimodule.

>>> flip runCov (e2 1 1) $ comult (cov $ V2 1 2) (cov $ V2 7 4)
11

Caution in general comult needn't be commutative, nor coassociative.

Linear transformations

newtype Lin a b c Source #

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)

Caution: You must ensure these laws hold when using the default constructor.

Prefer image or tran where appropriate.

Constructors

Lin 

Fields

  • runLin :: (c -> a) -> b -> a
     
Instances
Bisemimodule a a a => Bisemimodule a a (Lin a b c) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: a -> a -> Lin a b c -> Lin a b c Source #

Semiring a => RightSemimodule a (Lin a b m) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: a -> Lin a b m -> Lin a b m Source #

Semiring a => LeftSemimodule a (Lin a b c) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: a -> Lin a b c -> Lin a b c Source #

Presemiring a => Semigroup (Multiplicative (End a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

(Additive - Semigroup) a => Semigroup (Additive (Lin a b c)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(<>) :: Additive (Lin a b c) -> Additive (Lin a b c) -> Additive (Lin a b c) #

sconcat :: NonEmpty (Additive (Lin a b c)) -> Additive (Lin a b c) #

stimes :: Integral b0 => b0 -> Additive (Lin a b c) -> Additive (Lin a b c) #

Semiring a => Monoid (Multiplicative (End a b)) Source # 
Instance details

Defined in Data.Semimodule.Free

(Additive - Monoid) a => Monoid (Additive (Lin a b c)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

mempty :: Additive (Lin a b c) #

mappend :: Additive (Lin a b c) -> Additive (Lin a b c) -> Additive (Lin a b c) #

mconcat :: [Additive (Lin a b c)] -> Additive (Lin a b c) #

Arrow (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

arr :: (b -> c) -> Lin a b c #

first :: Lin a b c -> Lin a (b, d) (c, d) #

second :: Lin a b c -> Lin a (d, b) (d, c) #

(***) :: Lin a b c -> Lin a b' c' -> Lin a (b, b') (c, c') #

(&&&) :: Lin a b c -> Lin a b c' -> Lin a b (c, c') #

ArrowChoice (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

left :: Lin a b c -> Lin a (Either b d) (Either c d) #

right :: Lin a b c -> Lin a (Either d b) (Either d c) #

(+++) :: Lin a b c -> Lin a b' c' -> Lin a (Either b b') (Either c c') #

(|||) :: Lin a b d -> Lin a c d -> Lin a (Either b c) d #

ArrowApply (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

app :: Lin a (Lin a b c, b) c #

(Additive - Group) a => Group (Additive (Lin a b c)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

inv :: Additive (Lin a b c) -> Additive (Lin a b c) #

greplicate :: Integer -> Additive (Lin a b c) -> Additive (Lin a b c) #

(Additive - Group) a => Loop (Additive (Lin a b c)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lempty :: Additive (Lin a b c) #

lreplicate :: Natural -> Additive (Lin a b c) -> Additive (Lin a b c) #

(Additive - Group) a => Quasigroup (Additive (Lin a b c)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(//) :: Additive (Lin a b c) -> Additive (Lin a b c) -> Additive (Lin a b c) #

(\\) :: Additive (Lin a b c) -> Additive (Lin a b c) -> Additive (Lin a b c) #

(Additive - Group) a => Magma (Additive (Lin a b c)) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(<<) :: Additive (Lin a b c) -> Additive (Lin a b c) -> Additive (Lin a b c) #

Representable (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

Associated Types

type Rep (Lin a) :: Type -> Type #

Methods

tabulate :: (d -> Rep (Lin a) c) -> Lin a d c #

Choice (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

left' :: Lin a a0 b -> Lin a (Either a0 c) (Either b c) #

right' :: Lin a a0 b -> Lin a (Either c a0) (Either c b) #

Strong (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

first' :: Lin a a0 b -> Lin a (a0, c) (b, c) #

second' :: Lin a a0 b -> Lin a (c, a0) (c, b) #

Profunctor (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

dimap :: (a0 -> b) -> (c -> d) -> Lin a b c -> Lin a a0 d #

lmap :: (a0 -> b) -> Lin a b c -> Lin a a0 c #

rmap :: (b -> c) -> Lin a a0 b -> Lin a a0 c #

(#.) :: Coercible c b => q b c -> Lin a a0 b -> Lin a a0 c #

(.#) :: Coercible b a0 => Lin a b c -> q a0 b -> Lin a a0 c #

Category (Lin a :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

id :: Lin a a0 a0 #

(.) :: Lin a b c -> Lin a a0 b -> Lin a a0 c #

Sieve (Lin a) (Cov a) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

sieve :: Lin a a0 b -> a0 -> Cov a b #

Monad (Lin a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(>>=) :: Lin a b a0 -> (a0 -> Lin a b b0) -> Lin a b b0 #

(>>) :: Lin a b a0 -> Lin a b b0 -> Lin a b b0 #

return :: a0 -> Lin a b a0 #

fail :: String -> Lin a b a0 #

Functor (Lin a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

fmap :: (a0 -> b0) -> Lin a b a0 -> Lin a b b0 #

(<$) :: a0 -> Lin a b b0 -> Lin a b a0 #

Applicative (Lin a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

pure :: a0 -> Lin a b a0 #

(<*>) :: Lin a b (a0 -> b0) -> Lin a b a0 -> Lin a b b0 #

liftA2 :: (a0 -> b0 -> c) -> Lin a b a0 -> Lin a b b0 -> Lin a b c #

(*>) :: Lin a b a0 -> Lin a b b0 -> Lin a b b0 #

(<*) :: Lin a b a0 -> Lin a b b0 -> Lin a b a0 #

Apply (Lin a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

(<.>) :: Lin a b (a0 -> b0) -> Lin a b a0 -> Lin a b b0 #

(.>) :: Lin a b a0 -> Lin a b b0 -> Lin a b b0 #

(<.) :: Lin a b a0 -> Lin a b b0 -> Lin a b a0 #

liftF2 :: (a0 -> b0 -> c) -> Lin a b a0 -> Lin a b b0 -> Lin a b c #

Ring a => Ring (End a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Semiring a => Semiring (End a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Presemiring a => Presemiring (End a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Counital a b => RightSemimodule (End a b) (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: End a b -> Cov a b -> Cov a b Source #

Semiring a => RightSemimodule (End a b) (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: End a b -> Vec a b -> Vec a b Source #

Counital a b => LeftSemimodule (End a b) (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: End a b -> Cov a b -> Cov a b Source #

Semiring a => LeftSemimodule (End a b) (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: End a b -> Vec a b -> Vec a b Source #

Counital a b => Bisemimodule (End a b) (End a b) (Cov a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: End a b -> End a b -> Cov a b -> Cov a b Source #

Semiring a => Bisemimodule (End a b) (End a b) (Vec a b) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: End a b -> End a b -> Vec a b -> Vec a b Source #

Counital a c => RightSemimodule (Lin a c c) (Lin a b c) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

rscale :: Lin a c c -> Lin a b c -> Lin a b c Source #

Counital a b => LeftSemimodule (Lin a b b) (Lin a b c) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

lscale :: Lin a b b -> Lin a b c -> Lin a b c Source #

(Counital a b, Counital a c) => Bisemimodule (Lin a b b) (Lin a c c) (Lin a b c) Source # 
Instance details

Defined in Data.Semimodule.Free

Methods

discale :: Lin a b b -> Lin a c c -> Lin a b c -> Lin a b c Source #

type Rep (Lin a) Source # 
Instance details

Defined in Data.Semimodule.Free

type Rep (Lin a) = Cov a

type End a b = Lin a b b Source #

An endomorphism over a free semimodule.

>>> one + two !# V2 1 2 :: V2 Double
V2 3.0 6.0

image :: Semiring a => (b -> [(a, c)]) -> Lin a b c Source #

Create a Lin from a linear combination of basis vectors.

>>> image (e2 [(2, E31),(3, E32)] [(1, E33)]) !# V3 1 1 1 :: V2 Int
V2 5 1

invmap :: (a1 -> a2) -> (a2 -> a1) -> Lin a1 b c -> Lin a2 b c Source #

Lin is an invariant functor.

See also http://comonad.com/reader/2008/rotten-bananas/.

augment :: Semiring a => Lin a b c -> b -> a Source #

The augmentation ring homomorphism.

(!#) :: Free f => Free g => Lin a (Rep f) (Rep g) -> g a -> f a infixr 2 Source #

Apply a transformation to a vector.

(#!) :: Free f => Free g => g a -> Lin a (Rep f) (Rep g) -> f a infixl 2 Source #

Apply a transformation to a vector.

(!#!) :: Lin a c d -> Lin a b c -> Lin a b d infixr 2 Source #

Compose two transformations.

!#! = <<<

Dimensional transforms

braid :: Lin a (b, c) (c, b) Source #

Swap components of a tensor product.

This is equivalent to a matrix transpose.

cobraid :: Lin a (b + c) (c + b) Source #

Swap components of a direct sum.

split :: (b -> (b1, b2)) -> Lin a b1 c -> Lin a b2 c -> Lin a b c Source #

TODO: Document

cosplit :: ((c1 + c2) -> c) -> Lin a b c1 -> Lin a b c2 -> Lin a b c Source #

TODO: Document

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 => Lin 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 => Lin 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 => Lin a (Rep f1) (Rep f2) -> Lin a (Rep g1) (Rep g2) -> (f2 ** g2) a -> (f1 ** g1) a Source #

Left and right composition with a linear transformation.

 complr f g = compl f >>> compr g

Algebraic transforms

diagonal :: Algebra a b => Lin a b (b, b) Source #

rmap (((c1,()),(c2,())) -> (c1,c2)) $ (id *** initial) . diagonal = id
rmap ((((),c1),((),c2)) -> (c1,c2)) $ (initial *** id) . diagonal = id

codiagonal :: Coalgebra a c => Lin a (c, c) c Source #

lmap ((c1,c2) -> ((c1,()),(c2,()))) $ (id *** coinitial) . codiagonal = id
lmap ((c1,c2) -> (((),c1),((),c2))) $ (coinitial *** id) . codiagonal = id

initial :: Unital a b => Lin a b () Source #

TODO: Document

coinitial :: Counital a c => Lin a () c Source #

TODO: Document

convolve :: Algebra a b => Coalgebra a c => Lin a b c -> Lin a b c -> Lin a b c Source #

Convolution with an associative algebra and coassociative coalgebra