Ticket #6670: trac-6670-group_algebra-6.patch

File trac-6670-group_algebra-6.patch, 24.9 KB (added by Martin Raum, 12 years ago)
  • sage/algebras/all.py

    # HG changeset patch
    # User Martin Raum <Martin.Raum@matha.rwth-aachen.de>
    # Date 1300841480 -3600
    # Node ID 5c8212195c95db9eac1e006b72741a3f9c2cd582
    # Parent  eb9456d5aff3d8725a2e9919d77f5c6654e4bb6f
    #6670: Port group algebras to the current coercion system
    
    diff -r eb9456d5aff3 -r 5c8212195c95 sage/algebras/all.py
    a b  
    3333from steenrod_algebra_element import Sq
    3434from steenrod_algebra_bases import steenrod_algebra_basis
    3535
    36 from group_algebra import GroupAlgebra, GroupAlgebraElement
     36from group_algebra_new import GroupAlgebra, GroupAlgebraElement
    3737
    3838from iwahori_hecke_algebra import IwahoriHeckeAlgebraT
    3939from affine_nil_temperley_lieb import AffineNilTemperleyLiebTypeA
  • new file sage/algebras/group_algebra_new.py

    diff -r eb9456d5aff3 -r 5c8212195c95 sage/algebras/group_algebra_new.py
    - +  
     1r"""
     2Group algebra of a group
     3
     4This module provides functionality for constructing and working with group
     5algebras of arbitrary groups (over a general commutative base ring).
     6
     7.. note::
     8
     9    It seems to be difficult to make this fit nicely with Sage's coercion
     10    model. The problem is that (for example) if G is the additive group
     11    `(\ZZ,+)`, and `R = \ZZ[G]` is its group ring, then the integer 2 can be
     12    coerced into R in two ways -- via G, or via the base ring -- and *the
     13    answers are different*. In practice we get around this by preventing
     14    elements of G coercing automatically into `\ZZ[G]`, which is a shame, but
     15    makes more sense than preventing elements of the base ring doing so.
     16
     17AUTHOR:
     18
     19- David Loeffler (2008-08-24): initial version
     20- Martin Raum (2009-08): update to use new coercion model
     21"""
     22
     23#*****************************************************************************
     24#       Copyright (C) 2009 Martin Raum <mraum@mpim-bonn.mpg.de>
     25#                     2008 William Stein <wstein@gmail.com>
     26#                     2008 David Loeffler <d.loeffler.01@cantab.net>
     27#
     28#  Distributed under the terms of the GNU General Public License (GPL)
     29#                  http://www.gnu.org/licenses/
     30#*****************************************************************************
     31
     32
     33from sage.categories.all import GroupAlgebras
     34from sage.structure.parent_gens import ParentWithGens
     35from sage.algebras.algebra import Algebra
     36from sage.algebras.algebra_element import AlgebraElement
     37from sage.rings.all import IntegerRing
     38from sage.groups.group import Group
     39from sage.structure.formal_sum import FormalSums, FormalSum
     40from sage.structure.element import Element
     41from sage.sets.set import Set
     42from sage.misc.latex import latex
     43 
     44from sage.categories.morphism import Morphism
     45from sage.categories.pushout import ConstructionFunctor
     46from sage.categories.rings import Rings
     47
     48
     49_cache = dict()
     50
     51
     52class GroupAlgebraFunctor ( ConstructionFunctor ) :
     53    r"""
     54    A functor assigning a group algebra to its base ring.
     55    """
     56    def __init__(self, group) :
     57        r"""
     58        INPUT :
     59
     60        - group -- a group that will be the module basis for the group algebras
     61          in the range.
     62 
     63         EXAMPLES::
     64 
     65
     66            sage: from sage.algebras.group_algebra import GroupAlgebraFunctor
     67            sage: F = GroupAlgebraFunctor(KleinFourGroup())
     68            sage: loads(dumps(F)) == F
     69            True
     70             sage: GroupAlgebra(SU(2, GF(4, 'a')), IntegerModRing(12)).category()
     71             Category of group algebras over Ring of integers modulo 12
     72        """
     73        self.__group = group
     74 
     75        ConstructionFunctor.__init__(self, Rings(), Rings())
     76
     77    def group(self) :
     78        r"""
     79        Return the group which is associtated to this functor.
     80
     81        EXAMPLES::
     82
     83            sage: from sage.algebras.group_algebra import GroupAlgebraFunctor
     84            sage: GroupAlgebraFunctor(CyclicPermutationGroup(17)).group() == CyclicPermutationGroup(17)
     85            True
     86         """
     87        return self.__group
     88
     89    def __call__(self, base_ring) :
     90        r""" Create the group algeba with given base ring over self.group().
     91
     92        INPUT :
     93
     94        - ``base_ring`` - the base ring of the group algebra.
     95
     96        OUTPUT:
     97
     98        A group algebra.
     99
     100        EXAMPLES::
     101
     102            sage: from sage.algebras.group_algebra import GroupAlgebraFunctor
     103            sage: F = GroupAlgebraFunctor(CyclicPermutationGroup(17))
     104            sage: F(QQ)
     105            Group algebra of group "Cyclic group of order 17 as a permutation group" over base ring Rational Field
     106        """
     107        return GroupAlgebra(self.__group, base_ring)
     108
     109def GroupAlgebra(group, base_ring = IntegerRing()) :
     110    r"""
     111    Create the given group algebra.
     112   
     113    INPUT::
     114
     115    - (Group) group: a generic group.
     116    - (Ring) base_ring: a commutative ring.
     117
     118    OUTPUT:
     119
     120    - a GroupAlgebra instance.
     121
     122    EXAMPLES::
     123
     124        sage: GroupAlgebra(GL(3, GF(7)))
     125        Group algebra of group "General Linear Group of degree 3 over Finite
     126        Field of size 7" over base ring Integer Ring
     127        sage: GroupAlgebra(1)
     128        Traceback (most recent call last):
     129        ...
     130        TypeError: "1" is not a group
     131        sage: GroupAlgebra(KleinFourGroup()) is GroupAlgebra(KleinFourGroup())
     132        True
     133    """
     134    global _cache
     135
     136    if not base_ring.is_commutative():
     137        raise NotImplementedError, "Base ring must be commutative"
     138    if not isinstance(group, Group):
     139        raise TypeError, '"%s" is not a group' % group
     140
     141
     142    key = (group, base_ring)
     143
     144    try :
     145        return _cache[key]
     146    except KeyError :
     147        A = GroupAlgebra_class(group, base_ring)
     148        _cache[key] = A
     149   
     150        return A
     151
     152class GroupAlgebra_class ( Algebra ) :
     153
     154    def __init__(self, group, base_ring):
     155        r""" Create the given group algebra.
     156        INPUT:
     157            -- (Group) group: a generic group.
     158            -- (Ring) base_ring: a commutative ring.
     159        OUTPUT:
     160            -- a GroupAlgebra instance.
     161
     162        EXAMPLES::
     163
     164            sage: GroupAlgebra(GL(3, GF(7)))
     165            Group algebra of group "General Linear Group of degree 3 over Finite
     166            Field of size 7" over base ring Integer Ring
     167            sage: GroupAlgebra(1)
     168            Traceback (most recent call last):
     169            ...
     170            TypeError: "1" is not a group
     171
     172            sage: GroupAlgebra(SU(2, GF(4, 'a')), IntegerModRing(12)).category()
     173            Category of group algebras over Ring of integers modulo 12
     174
     175        TESTS::
     176
     177            sage: A = GroupAlgebra(GL(3, GF(7)))
     178            sage: A.has_coerce_map_from(GL(3, GF(7)))
     179            True
     180            sage: G = SymmetricGroup(5)
     181            sage: x,y = G.gens()
     182            sage: A = GroupAlgebra(G)
     183            sage: A( A(x) )
     184        """
     185        if not base_ring.is_commutative():
     186            raise NotImplementedError, "Base ring must be commutative"
     187       
     188        if not isinstance(group, Group):
     189            raise TypeError, '"%s" is not a group' % group
     190
     191        ParentWithGens.__init__(self, base_ring, category = GroupAlgebras(base_ring))
     192
     193        self._formal_sum_module = FormalSums(base_ring)
     194        self._group = group
     195
     196        if not base_ring.has_coerce_map_from(group) :
     197            ## some matrix groups assume that coercion is only valid to
     198            ## other matrix groups. This is a workaround
     199            ## call _element_constructor_ to coerce group elements
     200            #try :
     201            self._populate_coercion_lists_( coerce_list = [base_ring, group] )
     202            #except TypeError :
     203            #    self._populate_coercion_lists_( coerce_list = [base_ring] )
     204        else :
     205            self._populate_coercion_lists_( coerce_list = [base_ring] )
     206
     207    def ngens(self) :
     208        r"""
     209        Return the number of generators.
     210
     211        EXAMPLES::
     212
     213            sage: A = GroupAlgebra(SL2Z)
     214            sage: A.ngens()
     215            2
     216        """
     217        return self._group.ngens()
     218
     219    def gen(self, i = 0) :
     220        r"""
     221        EXAMPLES::
     222
     223            sage: A = GroupAlgebra(GL(3, GF(7)))
     224            sage: A.gen(0)
     225            [3 0 0]
     226            [0 1 0]
     227            [0 0 1]
     228        """
     229        return self._element_constructor(self._group.gen(i), as_group_element = True)
     230
     231    def group(self):
     232        r"""
     233        Return the group of this group algebra.
     234
     235        EXAMPLES::
     236
     237            sage: GroupAlgebra(GL(3, GF(11))).group()
     238            General Linear Group of degree 3 over Finite Field of size 11
     239            sage: GroupAlgebra(SymmetricGroup(10)).group()
     240            Symmetric group of order 10! as a permutation group
     241        """
     242        return self._group
     243
     244    ###########################################################################
     245    ## GroupAlgebra_class :: mathmatical properties
     246    ###########################################################################
     247
     248    def is_commutative(self):
     249        r"""
     250        Return True if self is a commutative ring. True if and only if
     251        ``self.group()`` is abelian.
     252
     253        EXAMPLES::
     254
     255            sage: GroupAlgebra(SymmetricGroup(2)).is_commutative()
     256            True
     257            sage: GroupAlgebra(SymmetricGroup(3)).is_commutative()
     258            False
     259        """
     260        return self.group().is_abelian()
     261
     262    def is_field(self, proof = True):
     263        r"""
     264        Return True if self is a field. This is always false unless
     265        ``self.group()`` is trivial and ``self.base_ring()`` is a field.
     266       
     267        EXAMPLES::
     268
     269            sage: GroupAlgebra(SymmetricGroup(2)).is_field()
     270            False
     271            sage: GroupAlgebra(SymmetricGroup(1)).is_field()
     272            False
     273            sage: GroupAlgebra(SymmetricGroup(1), QQ).is_field()
     274            True
     275        """
     276        if not self.base_ring().is_field(proof):
     277            return False
     278        return (self.group().order() == 1)
     279
     280    def is_finite(self):
     281        r"""
     282        Return True if self is finite, which is true if and only if
     283        ``self.group()`` and ``self.base_ring()`` are both finite.
     284       
     285        EXAMPLES::
     286
     287            sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite()
     288            True
     289            sage: GroupAlgebra(SymmetricGroup(2)).is_finite()
     290            False
     291            sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite()
     292            False
     293        """
     294        return (self.base_ring().is_finite() and self.group().is_finite())
     295
     296    def is_exact(self):
     297        r"""
     298        Return True if elements of self have exact representations, which is
     299        true of self if and only if it is true of ``self.group()`` and
     300        ``self.base_ring()``.
     301
     302        EXAMPLES::
     303
     304            sage: GroupAlgebra(GL(3, GF(7))).is_exact()
     305            True
     306            sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact()
     307            False
     308            sage: GroupAlgebra(GL(3, pAdicRing(7))).is_exact() # not implemented correctly (not my fault)!
     309            False
     310        """
     311        return self.group().is_exact() and self.base_ring().is_exact()
     312
     313    def is_integral_domain(self, proof = True):
     314        r"""
     315        Return True if self is an integral domain.
     316       
     317        This is false unless ``self.base_ring()`` is an integral domain, and
     318        even then it is false unless ``self.group()`` has no nontrivial
     319        elements of finite order. I don't know if this condition suffices, but
     320        it obviously does if the group is abelian and finitely generated.
     321
     322        EXAMPLES::
     323
     324            sage: GroupAlgebra(SymmetricGroup(2)).is_integral_domain()
     325            False
     326            sage: GroupAlgebra(SymmetricGroup(1)).is_integral_domain()
     327            True
     328            sage: GroupAlgebra(SymmetricGroup(1), IntegerModRing(4)).is_integral_domain()
     329            False
     330            sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain()
     331            True
     332            sage: GroupAlgebra(AbelianGroup(2, [0,2])).is_integral_domain()
     333            False
     334            sage: GroupAlgebra(GL(2, ZZ)).is_integral_domain() # not implemented
     335            False
     336        """
     337        ans = False
     338        try:
     339            if self.base_ring().is_integral_domain():
     340                if self.group().is_finite():
     341                    if self.group().order() > 1:
     342                        ans = False
     343                    else:
     344                        ans = True
     345                else:
     346                    if self.group().is_abelian():
     347                        invs = self.group().invariants()
     348                        if Set(invs) != Set([0]):
     349                            ans = False
     350                        else:
     351                            ans = True
     352                    else:
     353                        raise NotImplementedError
     354            else:
     355                ans = False
     356        except AttributeError:
     357            if proof:
     358                raise NotImplementedError, "cannot determine whether self is an integral domain"
     359        except NotImplementedError:
     360            if proof:
     361                raise NotImplementedError, "cannot determine whether self is an integral domain"
     362       
     363        return ans
     364
     365    # I haven't written is_noetherian(), because I don't know when group
     366    # algebras are noetherian, and I haven't written is_prime_field(), because
     367    # I don't know if that means "is canonically isomorphic to a prime field"
     368    # or "is identical to a prime field".
     369
     370    ###########################################################################
     371    ## GroupAlgebra_class :: elements
     372    ###########################################################################
     373
     374    def _an_element_(self):
     375        r"""
     376        Return an element of self.
     377
     378        EXAMPLES::
     379
     380            sage: A = GroupAlgebra(GL(3, GF(7)))
     381            sage: A.an_element()
     382            [3 0 0]
     383            [0 1 0]
     384            [0 0 1]
     385        """
     386        return self(self._formal_sum_module([
     387             (self.base_ring().an_element(), self.group().an_element())
     388             ]))
     389
     390    def random_element(self) :
     391        r"""
     392        Return a random element of self.
     393
     394        EXAMPLE::
     395
     396            sage: GroupAlgebra(SU(2, 13), QQ).an_element() # random; hideous formatting!
     397            -1/95*[       9 2*a + 12]
     398            [       0        3] - 4*[      9 9*a + 2]
     399            [3*a + 5       1]
     400        """
     401        return self(self._formal_sum_module([
     402            (self.base_ring().random_element(), self.group().random_element()),
     403            (self.base_ring().random_element(), self.group().random_element()),
     404            ]))
     405
     406    def construction(self) :
     407        r"""
     408        EXAMPLES::
     409
     410            sage: A = GroupAlgebra(KleinFourGroup(), QQ)
     411            sage: A.construction()                                       
     412            (GroupAlgebraFunctor, Rational Field)
     413        """
     414        return GroupAlgebraFunctor(self._group), self.base_ring()
     415
     416    def _element_constructor_(self, x, as_group_element = False) :
     417        r"""
     418        Create an element of this group algebra.
     419       
     420        INPUT:
     421
     422        - ``x``: either a FormalSum element consisting of elements of
     423          ``self.group()``, an element of ``self.base_ring()``, or an element
     424          of ``self.group()``.
     425        - ``as_group_element``: if true and ``x`` may be considered as a basis
     426          element and a group element, consider it a group element
     427       
     428        OUTPUT:
     429
     430        - a GroupAlgebraElement instance whose parent is self.
     431
     432        EXAMPLES::
     433
     434            sage: G = KleinFourGroup()
     435            sage: f = G.gen(0)
     436            sage: ZG = GroupAlgebra(G)
     437            sage: ZG(f)
     438            (3,4)
     439            sage: ZG(1) == ZG(G(1))
     440            True
     441            sage: G = AbelianGroup(1)
     442            sage: ZG = GroupAlgebra(G)
     443            sage: f = ZG.group().gen()
     444            sage: ZG(FormalSum([(1,f), (2, f**2)]))
     445            f + 2*f^2
     446            sage: G = GL(2,7)
     447            sage: OG = GroupAlgebra(G, ZZ[sqrt(5)])
     448            sage: OG(2)
     449            2*[1 0]
     450            [0 1]
     451            sage: OG(G(2)) # conversion is not the obvious one
     452            [2 0]
     453            [0 2]
     454            sage: OG(FormalSum([ (1, G(2)), (2, RR(0.77)) ]) )
     455            Traceback (most recent call last):
     456            ...
     457            TypeError: Cannot coerce 0.770000000000000 to a 2-by-2 matrix over Finite Field of size 7
     458
     459        Ordering of elements in output unpredictable as sort order of such wildly
     460        dissimilar elements is subject to change between platforms and versions
     461        (see trac ticket \#4373).
     462       
     463        ::
     464
     465            sage: OG(OG.base_ring().gens()[1])
     466            sqrt5*[1 0]
     467            [0 1]
     468        """
     469        if isinstance(x, Element) :
     470            P = x.parent()
     471            if P is self.base_ring() and not as_group_element:
     472                return GroupAlgebraElement_class(self,
     473                 self._formal_sum_module( [(x, self.group()(1))] ) )
     474            elif P is self.group() :
     475                return GroupAlgebraElement_class(self,
     476                 self._formal_sum_module( [(self.base_ring().one_element(), x)] ) )
     477            elif P is self._formal_sum_module :
     478                return GroupAlgebraElement_class(self, x)
     479            elif isinstance(x, FormalSum) and self._formal_sum_module.has_coerce_map_from(P) :
     480                 return GroupAlgebraElement_class(self,
     481                          self._formal_sum_module(
     482                           [(self.base_ring()(c), self.group()(g)) for c,g in x] ) )
     483
     484        raise TypeError, "Don't know how to create an element of %s from %s" % \
     485                             (self, x)
     486
     487    def __cmp__(self, other) :
     488        r"""
     489        Compare two algebras self and other. They are considered equal if and only
     490        if their base rings and their groups coincide.
     491
     492        EXAMPLES::
     493
     494            sage: GroupAlgebra(AbelianGroup(1)) == GroupAlgebra(AbelianGroup(1))
     495            True
     496            sage: GroupAlgebra(AbelianGroup(1), QQ) == GroupAlgebra(AbelianGroup(1), ZZ)
     497            False
     498            sage: GroupAlgebra(AbelianGroup(2)) == GroupAlgebra(AbelianGroup(1))
     499            False
     500            sage: from sage.algebras.group_algebra import GroupAlgebra_class
     501            sage: A = GroupAlgebra_class(KleinFourGroup(), ZZ)
     502            sage: B = GroupAlgebra_class(KleinFourGroup(), QQ)
     503            sage: A == B
     504            False
     505            sage: A == A
     506            True
     507        """
     508        c = cmp(type(self), type(other))
     509
     510        if c == 0 :
     511            c = cmp(self._group, other._group)
     512        if c == 0 :
     513            c = cmp(self.base_ring(), other.base_ring())
     514
     515        return c
     516
     517    def _repr_(self):
     518        r"""
     519        String representation of self. See GroupAlgebra.__init__ for a doctest.
     520
     521        EXAMPLES::
     522
     523            sage: A = GroupAlgebra(KleinFourGroup(), ZZ)
     524            sage: A
     525            Group algebra of group "The Klein 4 group of order 4, as a permutation group" over base ring Integer Ring
     526        """
     527        return "Group algebra of group \"%s\" over base ring %s" % \
     528               (self.group(), self.base_ring())
     529
     530    def _latex_(self):
     531        r"""Latex string of self.
     532       
     533        EXAMPLES::
     534
     535            sage: A = GroupAlgebra(KleinFourGroup(), ZZ)
     536            sage: latex(A)
     537            Group algebra of group \langle (3,4), (1,2) \rangle over base ring \Bold{Z}
     538        """
     539        return "Group algebra of group %s over base ring %s" % \
     540               (latex(self.group()), latex(self.base_ring()))
     541
     542    def element_class(self):
     543        r"""
     544        The class of elements of self, which is GroupAlgebraElement.
     545
     546        EXAMPLES::
     547
     548            sage: GroupAlgebra(SU(2, GF(4,'a'))).element_class()
     549            <class 'sage.algebras.group_algebra.GroupAlgebraElement_class'>
     550        """
     551        return GroupAlgebraElement_class
     552
     553def GroupAlgebraElement(parent, x, check = True) :
     554    r"""
     555    Create an element of the group algebra parent.
     556
     557    - ``x`` -- an element of the base ring, the group or a formal sum with
     558      summand ``(a, g)``, where a is in the base ring and g is in the group
     559    - ``check`` -- determines whether the summand of a formal sum will be
     560      checked for correctness
     561   
     562    EXAMPLES::
     563
     564        sage: G = KleinFourGroup()
     565        sage: A = GroupAlgebra(G)   
     566        sage: GroupAlgebraElement(A, A.group().gen(1))
     567        (1,2)
     568        sage: GroupAlgebraElement(A, 1)               
     569        ()
     570        sage: GroupAlgebraElement(A, 10)
     571        10*()
     572    """
     573    ## Provide this for backward compatibility to the old class layout
     574 
     575    assert isinstance(parent, GroupAlgebra_class), "%s must be group algebra"
     576    if not isinstance(x, Element) :
     577        x = IntegerRing()(x)
     578   
     579    if isinstance(x, FormalSum) and check :
     580        for c,g in x :
     581            if not c in parent.base_ring() or not g in parent.group() :
     582                raise ValueError, "summands of %s must be elements of base " + \
     583                                  "ring and group respectively"
     584
     585    return parent._element_constructor(x)
     586
     587###########################################################################
     588## GroupAlgebraElement_class
     589###########################################################################
     590
     591class GroupAlgebraElement_class ( AlgebraElement ) :
     592   
     593    def __init__(self, parent, x):
     594        r"""
     595        Create an element of the parent group algebra. Not intended to be
     596        called by the user; see GroupAlgebra._element_constructor_ for examples
     597        and doctests.
     598       
     599        EXAMPLES::
     600
     601            sage: A = GroupAlgebra(KleinFourGroup(), ZZ)
     602            sage: GroupAlgebraElement(A, A._formal_sum_module([(1, KleinFourGroup().gen(0))]))
     603            (3,4)
     604        """
     605        AlgebraElement.__init__(self, parent)
     606        self._fs = x
     607       
     608    ###########################################################################
     609    ## GroupAlgebraElement_class :: Arithmetic
     610    ###########################################################################
     611
     612    def _add_(left, right):
     613        r"""
     614        Add left to right.
     615
     616        EXAMPLE::
     617
     618            sage: G = GL(3, GF(7))
     619            sage: ZG = GroupAlgebra(G)
     620            sage: g1 = ZG.group()([0,0,2,2,5,0,6,6,2])
     621            sage: s = ZG(g1)
     622            sage: s + s
     623            2*[0  0  2]
     624            [2  5  0]
     625            [6  6  2]
     626        """
     627        return left.parent()(left._fs + right._fs)
     628
     629    def _mul_(left, right):
     630        r""" Calculate left*right, where both left and right are
     631        GroupAlgebraElements_class.
     632       
     633        EXAMPLE::
     634
     635            sage: G = GL(3, GF(7))
     636            sage: ZG = GroupAlgebra(G)
     637            sage: a, b = G.random_element(), G.random_element()
     638            sage: za, zb = ZG(a), ZG(b)
     639            sage: za*ZG(2) # random
     640            2*[4,5,0]
     641            [0,5,1]
     642            [2,5,1]
     643            sage: za*2 == za*ZG(2)
     644            True
     645            sage: (ZG(1) + za)*(ZG(2) + zb) == ZG(FormalSum([ (2,G(1)), (2,a), (1, b), (1, a*b)]))
     646            True
     647            sage: za*za == za^2
     648            True
     649        """
     650        if left.parent().group().is_multiplicative() :
     651            product = [ (a1 * a2, g1 * g2)
     652                        for (a1,g1) in left._fs for (a2,g2) in right._fs ]
     653        else :
     654            product = [ (a1 * a2, g1 + g2)
     655                        for (a1,g1) in left._fs for (a2,g2) in right._fs ]
     656
     657        return left.parent()( left.parent()._formal_sum_module(product) )
     658
     659    ###########################################################################
     660    ## GroupAlgebraElement_class :: Comparision
     661    ###########################################################################
     662
     663    def __cmp__(self, other) :
     664        r""" Compare self and other.
     665
     666        EXAMPLES::
     667
     668            sage: G = AbelianGroup(1,[4])
     669            sage: ZG = GroupAlgebra(G)
     670            sage: a = ZG(1)
     671            sage: b = ZG(2)
     672            sage: a + a == b
     673            True
     674            sage: a == b
     675            False
     676            sage: a == GroupAlgebra(AbelianGroup(1, [5]))(1)
     677            False
     678        """
     679        c = cmp(type(self), type(other))
     680
     681        if c == 0 :
     682            c = cmp(self._fs, other._fs)
     683
     684        return c
     685
     686    ###########################################################################
     687    ## GroupAlgebraElement_class :: Representations
     688    ###########################################################################
     689
     690    def _repr_(self) :
     691        r"""
     692        EXAMPLES::
     693
     694            sage: G = KleinFourGroup()
     695            sage: A = GroupAlgebra(G, ZZ)
     696            sage: latex(A(1) + A(A.group().gen(0)))
     697            () + (3,4)
     698        """
     699        return self._fs._repr_()
     700
     701    def _latex_(self) :
     702        r"""
     703        EXAMPLES::
     704
     705            sage: G = KleinFourGroup()
     706            sage: A = GroupAlgebra(G, ZZ)
     707            sage: latex(A(1) + A(A.group().gen(0)))
     708            () + (3,4)
     709        """
     710        return latex(self._fs)
     711