module Math.Algebras.Structures where
import Math.Algebras.VectorSpace
import Math.Algebras.TensorProduct
class Mon m where
munit :: m
mmult :: m -> m -> m
class Algebra k b where
unit :: k -> Vect k b
mult :: Vect k (Tensor b b) -> Vect k b
class Coalgebra k b where
counit :: Vect k b -> k
comult :: Vect k b -> Vect k (Tensor b b)
class (Algebra k b, Coalgebra k b) => Bialgebra k b where {}
class Bialgebra k b => HopfAlgebra k b where
antipode :: Vect k b -> Vect k b
instance (Num k, Eq b, Ord b, Show b, Algebra k b) => Num (Vect k b) where
x+y = add x y
negate (V ts) = V $ map (\(b,x) -> (b, negate x)) ts
x*y = mult (x `te` y)
fromInteger n = unit (fromInteger n)
abs _ = error "Prelude.Num.abs: inappropriate abstraction"
signum _ = error "Prelude.Num.signum: inappropriate abstraction"
instance Num k => Algebra k () where
unit 0 = zero
unit x = V [( (),x)]
mult (V [(T () (),x)]) = V [( (),x)]
instance Num k => Coalgebra k () where
counit (V []) = 0
counit (V [( (),x)]) = x
comult (V [( (),x)]) = V [(T () (),x)]
type Trivial k = Vect k ()
unit' :: (Num k, Algebra k b) => Trivial k -> Vect k b
unit' = unit . unwrap where unwrap = counit :: Num k => Trivial k -> k
counit' :: (Num k, Coalgebra k b) => Vect k b -> Trivial k
counit' = wrap . counit where wrap = unit :: Num k => k -> Trivial k
instance (Num k, Ord a, Ord b, Algebra k a, Algebra k b) => Algebra k (Tensor a b) where
unit 0 = V []
unit x = x `smultL` (unit 1 `te` unit 1)
mult = linear m where
m (T (T a b) (T a' b')) = (mult $ return $ T a a') `te` (mult $ return $ T b b')
instance (Num k, Ord a, Ord b, Coalgebra k a, Coalgebra k b) => Coalgebra k (Tensor a b) where
counit = counit . (counit' `tf` counit')
comult = assocL . (id `tf` assocR) . (id `tf` (twist `tf` id))
. (id `tf` assocL) . assocR . (comult `tf` comult)
newtype SetCoalgebra b = SC b deriving (Eq,Ord,Show)
instance Num k => Coalgebra k (SetCoalgebra b) where
counit (V ts) = sum [x | (m,x) <- ts]
comult = fmap (\m -> T m m)
newtype MonoidCoalgebra m = MC m deriving (Eq,Ord,Show)
instance (Num k, Ord m, Mon m) => Coalgebra k (MonoidCoalgebra m) where
counit (V ts) = sum [if m == MC munit then x else 0 | (m,x) <- ts]
comult = linear cm
where cm m = if m == MC munit then return (T m m) else return (T m (MC munit)) <+> return (T (MC munit) m)
class Algebra k a => Module k a m where
action :: Vect k (Tensor a m) -> Vect k m
r *. m = action (r `te` m)
class Coalgebra k c => Comodule k c n where
coaction :: Vect k n -> Vect k (Tensor c n)
instance Algebra k a => Module k a a where
action = mult
instance Coalgebra k c => Comodule k c c where
coaction = comult
instance (Num k, Ord a, Ord u, Ord v, Algebra k a, Module k a u, Module k a v)
=> Module k (Tensor a a) (Tensor u v) where
action = linear action'
where action' (T (T a a') (T u v)) = (action $ return $ T a u) `te` (action $ return $ T a' v)
instance (Num k, Ord a, Ord u, Ord v, Bialgebra k a, Module k a u, Module k a v)
=> Module k a (Tensor u v) where
action = linear action'
where action' (T a (T u v)) = action $ (comult $ return a) `te` (return $ T u v)
instance (Num k, Ord a, Ord m, Ord n, Bialgebra k a, Comodule k a m, Comodule k a n)
=> Comodule k a (Tensor m n) where
coaction = (mult `tf` id) . twistm . (coaction `tf` coaction)
where twistm x = nf $ fmap (\(T (T h m) (T h' n)) -> T (T h h') (T m n)) x