module HLearn.Algebra.Structures.Groups
(
Group(..)
, Abelian (..)
, FreeInverse(..)
, Invertible(..)
, module Data.Monoid
)
where
import Control.DeepSeq
import Data.Monoid
import GHC.Exts (Constraint)
class (Monoid m) => Abelian m
class (Monoid g) => Group g where
inverse :: g -> g
data FreeInverse a = FreeInverse !a
| Negate !a
deriving (Read,Show,Eq)
instance (Ord a) => Ord (FreeInverse a) where
compare (FreeInverse x) (FreeInverse y) = compare x y
compare (Negate x) (Negate y) = compare x y
compare (FreeInverse x) (Negate y) = case compare x y of
LT -> LT
GT -> GT
EQ -> LT
compare (Negate x) (FreeInverse y) = case compare x y of
LT -> LT
GT -> GT
EQ -> GT
class Invertible a where
mkinverse :: a -> a
isInverse :: a -> a -> Bool
instance (Eq a) => Invertible (FreeInverse a) where
mkinverse (FreeInverse x) = Negate x
mkinverse (Negate x) = FreeInverse x
isInverse (FreeInverse x) (FreeInverse y) = False
isInverse (Negate x) (Negate y) = False
isInverse (FreeInverse x) (Negate y) = x==y
isInverse (Negate x) (FreeInverse y) = x==y