Copyright | (c) 2020-2021 Reed Mullanix Emily Pillmore |
---|---|
License | BSD-style |
Maintainer | Reed Mullanix <reedmullanix@gmail.com>, Emily Pillmore <emilypi@cohomolo.gy> |
Stability | stable |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
This module provides definitions for FreeGroup
s and FreeAbelianGroup
s,
along with useful combinators.
Synopsis
- newtype FreeGroup a = FreeGroup {
- runFreeGroup :: [Either a a]
- simplify :: Eq a => FreeGroup a -> FreeGroup a
- interpret :: Group g => FreeGroup g -> g
- interpret' :: Group g => FreeGroup g -> g
- present :: Group g => FreeGroup g -> (FreeGroup g -> g) -> g
- data FreeAbelianGroup a
- pattern FreeAbelianGroup :: Ord a => Map a Integer -> FreeAbelianGroup a
- mkFreeAbelianGroup :: Ord a => Map a Integer -> FreeAbelianGroup a
- runFreeAbelianGroup :: FreeAbelianGroup a -> Map a Integer
- abfoldMap :: Abelian g => (a -> g) -> FreeAbelianGroup a -> g
- abmap :: Ord b => (a -> b) -> FreeAbelianGroup a -> FreeAbelianGroup b
- abjoin :: Ord a => FreeAbelianGroup (FreeAbelianGroup a) -> FreeAbelianGroup a
- singleton :: a -> FreeAbelianGroup a
- abInterpret :: Abelian g => FreeAbelianGroup g -> g
Free groups
A representation of a free group over an alphabet a
.
The intuition here is that Left a
represents a "negative" a
,
whereas Right a
represents "positive" a
.
Note: This does not perform simplification upon multiplication or construction.
To do this, one should use simplify
.
FreeGroup | |
|
Instances
Monad FreeGroup Source # | |
Functor FreeGroup Source # | |
Applicative FreeGroup Source # | |
Alternative FreeGroup Source # | |
Cancellative FreeGroup Source # | |
GroupFoldable FreeGroup Source # | |
Eq a => Eq (FreeGroup a) Source # | |
Ord a => Ord (FreeGroup a) Source # | |
Defined in Data.Group.Free | |
Show a => Show (FreeGroup a) Source # | |
Semigroup (FreeGroup a) Source # | |
Monoid (FreeGroup a) Source # | |
Group (FreeGroup a) Source # | |
Eq a => GroupOrder (FreeGroup a) Source # | |
Free group combinators
simplify :: Eq a => FreeGroup a -> FreeGroup a Source #
O(n) Simplifies a word in a free group.
Examples:
>>>
simplify $ FreeGroup [Right 'a', Left 'b', Right 'c', Left 'c', Right 'b', Right 'a']
FreeGroup {runFreeGroup = [Right 'a',Right 'a']}
interpret :: Group g => FreeGroup g -> g Source #
O(n) Interpret a word in a free group over some group g
as an element in a group g
.
Free abelian groups
data FreeAbelianGroup a Source #
A representation of a free abelian group over an alphabet a
.
The intuition here is group elements correspond with their positive or negative multiplicities, and as such are simplified by construction.
Examples:
>>>
let single a = MkFreeAbelianGroup $ Map.singleton a 1
>>>
a = single 'a'
>>>
b = single 'b'
>>>
a
FreeAbelianGroup $ fromList [('a',1)]>>>
a <> b
FreeAbelianGroup $ fromList [('a',1),('b',1)]>>>
a <> b == b <> a
True>>>
invert a
FreeAbelianGroup $ fromList [('a',-1)]>>>
a <> b <> invert a
FreeAbelianGroup $ fromList [('b',1)]>>>
gtimes 5 (a <> b)
FreeAbelianGroup $ fromList [('a',5),('b',5)]
Instances
pattern FreeAbelianGroup :: Ord a => Map a Integer -> FreeAbelianGroup a Source #
Bidirectional pattern synonym for the construction of
FreeAbelianGroup
s.
mkFreeAbelianGroup :: Ord a => Map a Integer -> FreeAbelianGroup a Source #
O(n) Constructs a FreeAbelianGroup
from a finite Map
from
the set of generators (a
) to its multiplicities.
runFreeAbelianGroup :: FreeAbelianGroup a -> Map a Integer Source #
O(1) Gets a representation of FreeAbelianGroup
as
Map
. The returned map contains no records with
multiplicity 0
i.e.
on the returned map
never returns lookup
aJust 0
.
Free abelian group combinators
abfoldMap :: Abelian g => (a -> g) -> FreeAbelianGroup a -> g Source #
Given a function from generators to an abelian group g
,
lift that function to a group homomorphism from FreeAbelianGroup
to g
.
In other words, it's a function analogus to foldMap
for Monoid
or
goldMap
for Group
.
abmap :: Ord b => (a -> b) -> FreeAbelianGroup a -> FreeAbelianGroup b Source #
Functorial fmap
for a FreeAbelianGroup
.
Examples:
>>>
singleton 'a' <> singleton 'A'
FreeAbelianGroup $ fromList [('A',1),('a',1)]>>>
import Data.Char (toUpper)
>>>
abmap toUpper $ singleton 'a' <> singleton 'A'
FreeAbelianGroup $ fromList [('A',2)]
abjoin :: Ord a => FreeAbelianGroup (FreeAbelianGroup a) -> FreeAbelianGroup a Source #
Monadic join
for a FreeAbelianGroup
.
singleton :: a -> FreeAbelianGroup a Source #
Lift a singular value into a FreeAbelianGroup
. Analogous to pure
.
Examples:
>>>
singleton "foo"
FreeAbelianGroup $ fromList [("foo",1)]
abInterpret :: Abelian g => FreeAbelianGroup g -> g Source #
Interpret a free group as a word in the underlying group g
.