Ticket #13687: trac_13687_review.patch

File trac_13687_review.patch, 85.6 KB (added by Volker Braun, 10 years ago)

Improved patch

  • doc/de/tutorial/tour_groups.rst

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1352926175 28800
    # Node ID 4bdd74b9ec2c632936a450ccfde6566d8c2028c7
    # Parent  e81c304f74e45fa17f1630e1f298e235458dacc9
    Addressing the reviewer comments
    
    diff --git a/doc/de/tutorial/tour_groups.rst b/doc/de/tutorial/tour_groups.rst
    a b  
    8282    sage: d * b**2 * c**3
    8383    b^2*c^3*d
    8484    sage: F = AbelianGroup(3,[2]*3); F
    85     Multiplicative Abelian Group isomorphic to C2 x C2 x C2
     85    Multiplicative Abelian group isomorphic to C2 x C2 x C2
    8686    sage: H = AbelianGroup([2,3], names="xy"); H
    87     Multiplicative Abelian Group isomorphic to C2 x C3
     87    Multiplicative Abelian group isomorphic to C2 x C3
    8888    sage: AbelianGroup(5)
    89     Multiplicative Abelian Group isomorphic to Z x Z x Z x Z x Z
     89    Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z
    9090    sage: AbelianGroup(5).order()
    9191    +Infinity
  • doc/en/tutorial/tour_groups.rst

    diff --git a/doc/en/tutorial/tour_groups.rst b/doc/en/tutorial/tour_groups.rst
    a b  
    8080    sage: d * b**2 * c**3
    8181    b^2*c^3*d
    8282    sage: F = AbelianGroup(3,[2]*3); F
    83     Multiplicative Abelian Group isomorphic to C2 x C2 x C2
     83    Multiplicative Abelian group isomorphic to C2 x C2 x C2
    8484    sage: H = AbelianGroup([2,3], names="xy"); H
    85     Multiplicative Abelian Group isomorphic to C2 x C3
     85    Multiplicative Abelian group isomorphic to C2 x C3
    8686    sage: AbelianGroup(5)
    87     Multiplicative Abelian Group isomorphic to Z x Z x Z x Z x Z
     87    Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z
    8888    sage: AbelianGroup(5).order()
    8989    +Infinity
  • doc/fr/tutorial/tour_groups.rst

    diff --git a/doc/fr/tutorial/tour_groups.rst b/doc/fr/tutorial/tour_groups.rst
    a b  
    8383    sage: d * b**2 * c**3
    8484    b^2*c^3*d
    8585    sage: F = AbelianGroup(3,[2]*3); F
    86     Multiplicative Abelian Group isomorphic to C2 x C2 x C2
     86    Multiplicative Abelian group isomorphic to C2 x C2 x C2
    8787    sage: H = AbelianGroup([2,3], names="xy"); H
    88     Multiplicative Abelian Group isomorphic to C2 x C3
     88    Multiplicative Abelian group isomorphic to C2 x C3
    8989    sage: AbelianGroup(5)
    90     Multiplicative Abelian Group isomorphic to Z x Z x Z x Z x Z
     90    Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z
    9191    sage: AbelianGroup(5).order()
    9292    +Infinity
  • doc/ru/tutorial/tour_groups.rst

    diff --git a/doc/ru/tutorial/tour_groups.rst b/doc/ru/tutorial/tour_groups.rst
    a b  
    8080    sage: d * b**2 * c**3
    8181    b^2*c^3*d
    8282    sage: F = AbelianGroup(3,[2]*3); F
    83     Multiplicative Abelian Group isomorphic to C2 x C2 x C2
     83    Multiplicative Abelian group isomorphic to C2 x C2 x C2
    8484    sage: H = AbelianGroup([2,3], names="xy"); H
    85     Multiplicative Abelian Group isomorphic to C2 x C3
     85    Multiplicative Abelian group isomorphic to C2 x C3
    8686    sage: AbelianGroup(5)
    87     Multiplicative Abelian Group isomorphic to Z x Z x Z x Z x Z
     87    Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z
    8888    sage: AbelianGroup(5).order()
    8989    +Infinity
  • sage/categories/category.py

    diff --git a/sage/categories/category.py b/sage/categories/category.py
    a b  
    2323    sage: Sets()
    2424    Category of sets
    2525    sage: GSets(AbelianGroup([2,4,9]))
    26     Category of G-sets for Multiplicative Abelian Group isomorphic to C2 x C4 x C9
     26    Category of G-sets for Multiplicative Abelian group isomorphic to C2 x C4 x C9
    2727    sage: Semigroups()
    2828    Category of semigroups
    2929    sage: VectorSpaces(FiniteField(11))
  • sage/groups/abelian_gps/abelian_group.py

    diff --git a/sage/groups/abelian_gps/abelian_group.py b/sage/groups/abelian_gps/abelian_group.py
    a b  
    2121generators::
    2222
    2323    sage: AbelianGroup([0,0,0,2,3])
    24     Multiplicative Abelian Group isomorphic to Z x Z x Z x C2 x C3
     24    Multiplicative Abelian group isomorphic to Z x Z x Z x C2 x C3
    2525    sage: AbelianGroup(5, [2,3])
    26     Multiplicative Abelian Group isomorphic to Z x Z x Z x C2 x C3
     26    Multiplicative Abelian group isomorphic to Z x Z x Z x C2 x C3
    2727
    2828It is also legal to specify `1` as the order. The corresponding
    2929generator will be the neutral element, but it will still take up an
     
    4141:meth:`~AbelianGroup_class.gens_orders` instead::
    4242
    4343   sage: J = AbelianGroup([2,0,3,2,4]);  J
    44    Multiplicative Abelian Group isomorphic to C2 x Z x C3 x C2 x C4
     44   Multiplicative Abelian group isomorphic to C2 x Z x C3 x C2 x C4
    4545   sage: J.gens_orders()            # use this instead
    4646   (2, 0, 3, 2, 4)
    4747   sage: J.invariants()             # deprecated
     
    126126
    127127    sage: T = AbelianGroup(0,[])
    128128    sage: T
    129     Trivial Abelian Group
     129    Trivial Abelian group
    130130    sage: T.gens()
    131131    ()
    132132    sage: T(1)
     
    139139
    140140    sage: F = AbelianGroup(5,[3,4,5,5,7],names = list("abcde"))
    141141    sage: F
    142     Multiplicative Abelian Group isomorphic to C3 x C4 x C5 x C5 x C7
     142    Multiplicative Abelian group isomorphic to C3 x C4 x C5 x C5 x C7
    143143    sage: (a,b,c,d,e) = F.gens()
    144144    sage: a*b^2*e*d
    145145    a*b^2*d*e
     
    250250    EXAMPLE::
    251251   
    252252        sage: G.<a,b,c> = AbelianGroup(3,[2,3,4]); G
    253         Multiplicative Abelian Group isomorphic to C2 x C3 x C4
     253        Multiplicative Abelian group isomorphic to C2 x C3 x C4
    254254        sage: w = word_problem([a*b,a*c], b*c); w #random
    255255        [[a*b, 1], [a*c, 1]] 
    256256        sage: prod([x^i for x,i in w]) == b*c
     
    330330    """
    331331    Helper function for :func:`AbelianGroup`. Beat some sense into the
    332332    arguments.
    333     """
     333
     334    This function is also used by some descendents of
     335    :class:`AbelianGroup_class`.
     336
     337    INPUT:
     338
     339    See :func:`AbelianGroup`
     340
     341    OUTPUT:
     342
     343    Unique data for defining a :class:`AbelianGroup_class`. Raises an
     344    exception if the input is invalid.
     345
     346    EXAMPLES::
     347
     348        sage: from sage.groups.abelian_gps.abelian_group import _normalize
     349        sage: _normalize(5, [2,1,0], names='abc')
     350        ((0, 0, 2, 1, 0), 'abc')
     351        sage: _normalize(5, (2.0, 1.0, 0/1), names=list('abc'))
     352        ((0, 0, 2, 1, 0), ('a', 'b', 'c'))
     353        sage: _normalize([0,2,1,0], names='a')
     354        ((0, 2, 1, 0), 'a')
     355
     356    TESTS::
     357
     358        sage: _normalize(5, (2.0, 1.5, 0/1), names=list('abc'))
     359        Traceback (most recent call last):
     360        ...
     361        TypeError: Attempt to coerce non-integral RealNumber to Integer
     362        sage: _normalize('1', '[2]', names='a')
     363        Traceback (most recent call last):
     364        ...
     365        TypeError: unable to convert x (=[) to an integer
     366        sage: _normalize(3, 'str', names='a')
     367        Traceback (most recent call last):
     368        ...
     369        TypeError: unable to convert x (=s) to an integer
     370   """
    334371    if gens_orders is None:
    335372        if isinstance(n, (list, tuple)):
    336373            gens_orders = n
    337374            n = len(n)
    338375        else:
    339376            gens_orders = []
     377    n = ZZ(n)
    340378    if len(gens_orders) < n:
    341         gens_orders = [0] * (n - len(gens_orders)) + gens_orders
    342     elif len(gens_orders) > n:
     379        gens_orders = [0] * (n - len(gens_orders)) + list(gens_orders)
     380    gens_orders = tuple(ZZ(i) for i in gens_orders)
     381    if len(gens_orders) > n:
    343382        raise ValueError('gens_orders (='+str(gens_orders)+') must have length n (='+str(n)+')')
    344     gens_orders = tuple(gens_orders)
    345383    if isinstance(names, list):
    346384        names = tuple(names)
    347385    return (gens_orders, names)
     
    384422        sage: d * b**2 * c**3
    385423        b^2*c^3*d
    386424        sage: F = AbelianGroup(3,[2]*3); F
    387         Multiplicative Abelian Group isomorphic to C2 x C2 x C2
     425        Multiplicative Abelian group isomorphic to C2 x C2 x C2
    388426        sage: H = AbelianGroup([2,3], names="xy"); H
    389         Multiplicative Abelian Group isomorphic to C2 x C3
     427        Multiplicative Abelian group isomorphic to C2 x C3
    390428        sage: AbelianGroup(5)
    391         Multiplicative Abelian Group isomorphic to Z x Z x Z x Z x Z
     429        Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z
    392430        sage: AbelianGroup(5).order()
    393431        +Infinity
    394432   
    395433    Notice that `0`'s are prepended if necessary::
    396434   
    397435        sage: G = AbelianGroup(5, [2,3,4]);  G
    398         Multiplicative Abelian Group isomorphic to Z x Z x C2 x C3 x C4
     436        Multiplicative Abelian group isomorphic to Z x Z x C2 x C3 x C4
    399437        sage: G.gens_orders()
    400438        (0, 0, 2, 3, 4)
    401439
     
    404442        sage: AbelianGroup(2, [2,3,4])
    405443        Traceback (most recent call last):
    406444        ...
    407         ValueError: gens_orders (=[2, 3, 4]) must have length n (=2)
     445        ValueError: gens_orders (=(2, 3, 4)) must have length n (=2)
    408446    """
    409447    gens_orders, names = _normalize(n, gens_orders, names)
    410448    M = AbelianGroup_class(gens_orders, names)
     
    418456   
    419457        sage: from sage.groups.abelian_gps.abelian_group import is_AbelianGroup
    420458        sage: F = AbelianGroup(5,[5,5,7,8,9],names = list("abcde")); F
    421         Multiplicative Abelian Group isomorphic to C5 x C5 x C7 x C8 x C9
     459        Multiplicative Abelian group isomorphic to C5 x C5 x C7 x C8 x C9
    422460        sage: is_AbelianGroup(F)
    423461        True
    424462        sage: is_AbelianGroup(AbelianGroup(7, [3]*7))
     
    451489        True
    452490
    453491        sage: F = AbelianGroup(5,[5,5,7,8,9],names = list("abcde")); F
    454         Multiplicative Abelian Group isomorphic to C5 x C5 x C7 x C8 x C9
     492        Multiplicative Abelian group isomorphic to C5 x C5 x C7 x C8 x C9
    455493        sage: F = AbelianGroup(5,[2, 4, 12, 24, 120],names = list("abcde")); F
    456         Multiplicative Abelian Group isomorphic to C2 x C4 x C12 x C24 x C120
     494        Multiplicative Abelian group isomorphic to C2 x C4 x C12 x C24 x C120
    457495        sage: F.elementary_divisors()
    458496        (2, 4, 12, 24, 120)
    459497
    460498        sage: F.category()
    461499        Category of groups
    462500
    463         sage: G = AbelianGroup([0,5,0,7],names = list("abcd")); G
    464         Multiplicative Abelian Group isomorphic to Z x C5 x Z x C7
    465         sage: TestSuite(G).run()
    466 
    467501    TESTS::
    468502
    469503        sage: AbelianGroup([]).gens_orders()
     
    478512    Element = AbelianGroupElement
    479513
    480514    def __init__(self, generator_orders, names):
     515        """
     516        The Python constructor
     517
     518        TESTS::
     519
     520            sage: G = AbelianGroup([0,5,0,7],names = list("abcd")); G
     521            Multiplicative Abelian group isomorphic to Z x C5 x Z x C7
     522            sage: TestSuite(G).run()
     523        """
     524        assert isinstance(names, (basestring, tuple))
     525        assert isinstance(generator_orders, tuple)
     526        assert all(isinstance(order,Integer) for order in generator_orders)
     527        self._gens_orders = generator_orders
    481528        n = ZZ(len(generator_orders))
    482         if n < 0:
    483             raise ValueError, "n (=%s) must be nonnegative."%n
    484         self._gens_orders = tuple(ZZ(i) for i in generator_orders)
    485 
    486         # *now* define ngens
    487529        names = self.normalize_names(n, names)
    488530        self._assign_names(names)
    489531        AbelianGroupBase.__init__(self) # TODO: category=CommutativeGroups()
    490532
    491     def _an_element_(self):
    492         """
    493         Return a random element
    494 
    495         EXAMPLES:
    496 
    497             sage: G = AbelianGroup([2,3,4,5])
    498             sage: G.an_element()
    499             f0*f1*f2*f3
    500         """
    501         return prod(self.gens())
    502 
    503533    def is_isomorphic(left, right):
    504534        """
    505535        Check whether ``left`` and ``right`` are isomorphic
     
    528558    __eq__ = is_isomorphic
    529559
    530560    def __ne__(left, right):
     561        """
     562        Check whether ``left`` and ``right`` are not isomorphic
     563
     564        OUTPUT:
     565
     566        Boolean.
     567
     568        EXAMPLES::
     569
     570            sage: G1 = AbelianGroup([2,3,4,5])
     571            sage: G2 = AbelianGroup([2,3,4,5,1])
     572            sage: G1 != G2
     573            False
     574            sage: G1.__ne__(G2)
     575            False
     576        """
    531577        return not left.is_isomorphic(right)
    532578
    533579    def is_subgroup(left, right):
     
    557603    __le__ = is_subgroup
    558604
    559605    def __ge__(left, right):
     606        """
     607        Test whether ``right`` is a subgroup of ``left``
     608
     609        EXAMPLE::
     610
     611            sage: G.<a, b> = AbelianGroup(2)
     612            sage: H.<c> = AbelianGroup(1)
     613            sage: G >= H
     614            False
     615        """
    560616        return right.__le__(left)
    561617   
    562618    def __lt__(left, right):
     
    573629        return left <= right and left != right
    574630   
    575631    def __gt__(left, right):
     632        """
     633        Test whether ``right`` is a strict subgroup of ``left``
     634
     635        EXAMPLE::
     636
     637            sage: G.<a, b> = AbelianGroup(2)
     638            sage: H.<c> = AbelianGroup(1)
     639            sage: G > H
     640            False
     641        """
    576642        return left >= right and left != right
    577643   
    578644    def is_trivial(self):
     
    689755            (6,)
    690756            sage: G = AbelianGroup(2,[2,6])
    691757            sage: G
    692             Multiplicative Abelian Group isomorphic to C2 x C6
     758            Multiplicative Abelian group isomorphic to C2 x C6
    693759            sage: G.gens_orders()
    694760            (2, 6)
    695761            sage: G.elementary_divisors()
     
    715781        EXAMPLES::
    716782       
    717783            sage: G = AbelianGroup([2,3,7]); G
    718             Multiplicative Abelian Group isomorphic to C2 x C3 x C7
     784            Multiplicative Abelian group isomorphic to C2 x C3 x C7
    719785            sage: G.exponent()
    720786            42
    721787            sage: G = AbelianGroup([2,4,6]); G
    722             Multiplicative Abelian Group isomorphic to C2 x C4 x C6
     788            Multiplicative Abelian group isomorphic to C2 x C4 x C6
    723789            sage: G.exponent()
    724790            12
    725791        """
     
    744810        return self(1)
    745811   
    746812    def _group_notation(self, eldv):
     813        """
     814        Return abstract group notation for generator orders ``eldv``
     815
     816        INPUT:
     817
     818        - ``eldv`` -- iterable of integers.
     819
     820        OUTPUT:
     821
     822        String.
     823
     824        EXAMPLES::
     825
     826            sage: G = AbelianGroup([2,2])
     827            sage: G._group_notation([0,1,2,3])
     828            'Z x C1 x C2 x C3'
     829        """
    747830        v = []
    748831        for x in eldv:
    749832            if x:
     
    780863        Only works for finite groups::
    781864       
    782865            sage: G = AbelianGroup(3,[0,3,4],names="abc"); G
    783             Multiplicative Abelian Group isomorphic to Z x C3 x C4
     866            Multiplicative Abelian group isomorphic to Z x C3 x C4
    784867            sage: G._gap_init_()
    785868            Traceback (most recent call last):
    786869            ...
     
    890973        factors of the group. Use :meth:`gens_orders` instead::
    891974
    892975            sage: J = AbelianGroup([2,0,3,2,4]);  J
    893             Multiplicative Abelian Group isomorphic to C2 x Z x C3 x C2 x C4
     976            Multiplicative Abelian group isomorphic to C2 x Z x C3 x C2 x C4
    894977            sage: J.invariants()    # deprecated
    895978            (2, 0, 3, 2, 4)
    896979            sage: J.gens_orders()   # use this instead
     
    9631046            sage: T.is_cyclic()
    9641047            True           
    9651048            sage: T = AbelianGroup(1,[0]); T
    966             Multiplicative Abelian Group isomorphic to Z
     1049            Multiplicative Abelian group isomorphic to Z
    9671050            sage: T.is_cyclic()
    9681051            True
    9691052            sage: B = AbelianGroup([3,4,5])
     
    10161099        EXAMPLES::
    10171100       
    10181101            sage: G = AbelianGroup(2,[2,3]); G
    1019             Multiplicative Abelian Group isomorphic to C2 x C3
     1102            Multiplicative Abelian group isomorphic to C2 x C3
    10201103            sage: G.permutation_group()
    10211104            Permutation Group with generators [(3,4,5), (1,2)]
    10221105        """
     
    10451128        EXAMPLES::
    10461129       
    10471130            sage: G = AbelianGroup([2,3,9])
    1048             sage: G.random_element()   # random output
    1049             f0*f1^2*f2
     1131            sage: G.random_element()
     1132            f1^2
    10501133        """
    10511134        from sage.misc.prandom import randint
    10521135        result = self.one()
     
    10601143    def _repr_(self):
    10611144        """
    10621145        Return a string representation of ``self``.
    1063         """
     1146
     1147        EXAMPLES::
     1148
     1149            sage: G = AbelianGroup([2,3,9])
     1150            sage: G._repr_()
     1151            'Multiplicative Abelian group isomorphic to C2 x C3 x C9'
     1152       """
    10641153        eldv = self.gens_orders()
    10651154        if len(eldv) == 0:
    1066             return "Trivial Abelian Group"
     1155            return "Trivial Abelian group"
    10671156        g = self._group_notation(eldv)
    1068         return "Multiplicative Abelian Group isomorphic to " + g
     1157        return "Multiplicative Abelian group isomorphic to " + g
    10691158
    10701159    def subgroup(self, gensH, names="f"):
    10711160        """
     
    10801169         EXAMPLES::
    10811170         
    10821171             sage: G.<a,b,c> = AbelianGroup(3, [2,3,4]); G
    1083              Multiplicative Abelian Group isomorphic to C2 x C3 x C4
     1172             Multiplicative Abelian group isomorphic to C2 x C3 x C4
    10841173             sage: H = G.subgroup([a*b,a]); H
    1085              Multiplicative Abelian Group isomorphic to C2 x C3, which is the subgroup of
    1086              Multiplicative Abelian Group isomorphic to C2 x C3 x C4
    1087              generated by a*b, a
     1174             Multiplicative Abelian subgroup isomorphic to C2 x C3 generated by {a*b, a}
    10881175             sage: H < G
    10891176             True
    10901177             sage: F = G.subgroup([a,b^2])
    10911178             sage: F
    1092              Multiplicative Abelian Group isomorphic to C2 x C3, which is the subgroup of
    1093              Multiplicative Abelian Group isomorphic to C2 x C3 x C4
    1094              generated by a, b^2
     1179             Multiplicative Abelian subgroup isomorphic to C2 x C3 generated by {a, b^2}
    10951180             sage: F.gens()
    10961181             (a, b^2)
    10971182             sage: F = AbelianGroup(5,[30,64,729],names = list("abcde"))
    10981183             sage: a,b,c,d,e = F.gens()
    10991184             sage: F.subgroup([a,b])
    1100              Multiplicative Abelian Group isomorphic to Z x Z, which is
    1101              the subgroup of Multiplicative Abelian Group isomorphic to
    1102              Z x Z x C30 x C64 x C729 generated by a, b
     1185             Multiplicative Abelian subgroup isomorphic to Z x Z generated by {a, b}
    11031186             sage: F.subgroup([c,e])
    1104              Multiplicative Abelian Group isomorphic to C2 x C3 x C5 x
    1105              C729, which is the subgroup of Multiplicative Abelian
    1106              Group isomorphic to Z x Z x C30 x C64 x C729 generated by c, e
     1187             Multiplicative Abelian subgroup isomorphic to C2 x C3 x C5 x C729 generated by {c, e}
    11071188         """
    11081189        G = self
    11091190        gensH = tuple(gensH)
     
    11141195                raise TypeError('Subgroup generators must belong to the given group.')
    11151196        return AbelianGroup_subgroup(self, gensH, names)
    11161197
     1198    @cached_method
    11171199    def list(self):
    11181200        """
    1119         Return list of all elements of this group.
     1201        Return tuple of all elements of this group.
    11201202       
    11211203        EXAMPLES::
    11221204       
    11231205            sage: G = AbelianGroup([2,3], names = "ab")
    11241206            sage: G.list()
    1125             [1, b, b^2, a, a*b, a*b^2]
     1207            (1, b, b^2, a, a*b, a*b^2)
    11261208       
    11271209        ::
    11281210       
    11291211            sage: G = AbelianGroup([]); G
    1130             Trivial Abelian Group
     1212            Trivial Abelian group
    11311213            sage: G.list()
    1132             [1]
     1214            (1,)
    11331215        """
    1134         try:
    1135             return list(self._list)
    1136         except AttributeError:
    1137             pass
    11381216        if not(self.is_finite()):
    11391217           raise NotImplementedError, "Group must be finite"
    1140         self._list = list(self.__iter__())
    1141         return list(self._list)
     1218        return tuple(self.__iter__())
    11421219     
    11431220    def __iter__(self):
    11441221        """
     
    11631240            [1]
    11641241            sage: G = AbelianGroup([])
    11651242            sage: G.list()
    1166             [1]
     1243            (1,)
    11671244            sage: list(G)
    11681245            [1]
    11691246        """
     
    11991276        EXAMPLES::
    12001277
    12011278            sage: AbelianGroup([2,3]).subgroups()
    1202             [Multiplicative Abelian Group isomorphic to C2 x C3, which is the subgroup of
    1203              Multiplicative Abelian Group isomorphic to C2 x C3
    1204              generated by f0*f1^2,
    1205              Multiplicative Abelian Group isomorphic to C2, which is the subgroup of
    1206              Multiplicative Abelian Group isomorphic to C2 x C3
    1207              generated by f0,
    1208              Multiplicative Abelian Group isomorphic to C3, which is the subgroup of
    1209              Multiplicative Abelian Group isomorphic to C2 x C3
    1210              generated by f1,
    1211              Trivial Abelian Group, which is the subgroup of
    1212              Multiplicative Abelian Group isomorphic to C2 x C3
    1213              generated by 1]
    1214 
     1279            [Multiplicative Abelian subgroup isomorphic to C2 x C3 generated by {f0*f1^2},
     1280             Multiplicative Abelian subgroup isomorphic to C2 generated by {f0},
     1281             Multiplicative Abelian subgroup isomorphic to C3 generated by {f1},
     1282             Trivial Abelian subgroup]
    12151283            sage: len(AbelianGroup([2,4,8]).subgroups())
    12161284            81
    12171285
    12181286        TESTS::
    12191287
    12201288            sage: AbelianGroup([]).subgroups()
    1221             [Trivial Abelian Group]
     1289            [Trivial Abelian group]
    12221290        """
    12231291        if not self.is_finite(): raise ValueError, "Group must be finite"
    12241292        from sage.misc.misc import verbose
     
    12761344
    12771345            sage: G = AbelianGroup([4,4])
    12781346            sage: G.subgroup( [ G([1,0]), G([1,2]) ])
    1279             Multiplicative Abelian Group isomorphic to C2 x C4, which is the subgroup of
    1280             Multiplicative Abelian Group isomorphic to C4 x C4
    1281             generated by f0, f0*f1^2
     1347            Multiplicative Abelian subgroup isomorphic to C2 x C4
     1348            generated by {f0, f0*f1^2}
    12821349            sage: AbelianGroup([4,4]).subgroup_reduced( [ [1,0], [1,2] ])
    1283             Multiplicative Abelian Group isomorphic to C2 x C4, which is the subgroup of
    1284             Multiplicative Abelian Group isomorphic to C4 x C4
    1285             generated by f1^2, f0
     1350            Multiplicative Abelian subgroup isomorphic to C2 x C4
     1351            generated by {f1^2, f0}
    12861352        """
    12871353        from sage.matrix.constructor import matrix
    12881354        d = self.ngens()
     
    13181384            sage: F = AbelianGroup(5,[30,64,729],names = list("abcde"))
    13191385            sage: a,b,c,d,e = F.gens()
    13201386            sage: F.subgroup([a^3,b])
    1321             Multiplicative Abelian Group isomorphic to Z x Z, which is the subgroup of
    1322             Multiplicative Abelian Group isomorphic to Z x Z x C30 x C64 x C729
    1323             generated by a^3, b
    1324        
     1387            Multiplicative Abelian subgroup isomorphic to Z x Z generated by {a^3, b}
    13251388            sage: F.subgroup([c])
    1326             Multiplicative Abelian Group isomorphic to C2 x C3 x C5, which is the subgroup of
    1327             Multiplicative Abelian Group isomorphic to Z x Z x C30 x C64 x C729
    1328             generated by c
    1329        
    1330             sage: F.subgroup([a,c])
    1331             Multiplicative Abelian Group isomorphic to C2 x C3 x C5 x
    1332             Z, which is the subgroup of Multiplicative Abelian Group
    1333             isomorphic to Z x Z x C30 x C64 x C729 generated by a, c
    1334        
    1335             sage: F.subgroup([a,b*c])
    1336             Multiplicative Abelian Group isomorphic to Z x Z, which is
    1337             the subgroup of Multiplicative Abelian Group isomorphic to
    1338             Z x Z x C30 x C64 x C729 generated by a, b*c
    1339        
    1340             sage: F.subgroup([b*c,d])
    1341             Multiplicative Abelian Group isomorphic to C64 x Z, which
    1342             is the subgroup of Multiplicative Abelian Group isomorphic
    1343             to Z x Z x C30 x C64 x C729 generated by b*c, d
    1344        
    1345             sage: F.subgroup([a*b,c^6,d],names = list("xyz"))
    1346             Multiplicative Abelian Group isomorphic to C5 x C64 x Z,
    1347             which is the subgroup of Multiplicative Abelian Group
    1348             isomorphic to Z x Z x C30 x C64 x C729 generated by a*b,
    1349             c^6, d
    1350        
     1389            Multiplicative Abelian subgroup isomorphic to C2 x C3 x C5 generated by {c}
     1390            sage: F.subgroup([a, c])
     1391            Multiplicative Abelian subgroup isomorphic to C2 x C3 x C5 x Z generated by {a, c}
     1392            sage: F.subgroup([a, b*c])
     1393            Multiplicative Abelian subgroup isomorphic to Z x Z generated by {a, b*c}
     1394            sage: F.subgroup([b*c, d])
     1395            Multiplicative Abelian subgroup isomorphic to C64 x Z generated by {b*c, d}
     1396            sage: F.subgroup([a*b, c^6, d],names=list("xyz"))
     1397            Multiplicative Abelian subgroup isomorphic to C5 x C64 x Z generated by {a*b, c^6, d}
    13511398            sage: H.<x,y,z> = F.subgroup([a*b, c^6, d]); H
    1352             Multiplicative Abelian Group isomorphic to C5 x C64 x Z,
    1353             which is the subgroup of Multiplicative Abelian Group
    1354             isomorphic to Z x Z x C30 x C64 x C729 generated by a*b,
    1355             c^6, d
    1356        
    1357             sage: G = F.subgroup([a*b,c^6,d],names = list("xyz")); G
    1358             Multiplicative Abelian Group isomorphic to C5 x C64 x Z,
    1359             which is the subgroup of Multiplicative Abelian Group
    1360             isomorphic to Z x Z x C30 x C64 x C729 generated by a*b,
    1361             c^6, d
     1399            Multiplicative Abelian subgroup isomorphic to C5 x C64 x Z generated by {a*b, c^6, d}
     1400            sage: G = F.subgroup([a*b, c^6, d],names = list("xyz")); G
     1401            Multiplicative Abelian subgroup isomorphic to C5 x C64 x Z generated by {a*b, c^6, d}
    13621402            sage: x,y,z = G.gens()
    13631403            sage: x.order()
    13641404            +Infinity
     
    13691409            sage: A = AbelianGroup(5,[3, 5, 5, 7, 8], names = "abcde")
    13701410            sage: a,b,c,d,e = A.gens()
    13711411            sage: A.subgroup([a,b])
    1372             Multiplicative Abelian Group isomorphic to C3 x C5, which is the subgroup of
    1373             Multiplicative Abelian Group isomorphic to C3 x C5 x C5 x C7 x C8
    1374             generated by a, b
     1412            Multiplicative Abelian subgroup isomorphic to C3 x C5 generated by {a, b}
    13751413            sage: A.subgroup([a,b,c,d^2,e])
    1376             Multiplicative Abelian Group isomorphic to C3 x C5 x C5 x C7 x C8, which is the subgroup of
    1377             Multiplicative Abelian Group isomorphic to C3 x C5 x C5 x C7 x C8
    1378             generated by a, b, c, d^2, e
    1379             sage: A.subgroup([a,b,c,d^2,e^2])
    1380             Multiplicative Abelian Group isomorphic to C3 x C4 x C5 x C5 x C7, which is the subgroup of
    1381             Multiplicative Abelian Group isomorphic to C3 x C5 x C5 x C7 x C8
    1382             generated by a, b, c, d^2, e^2
    1383             sage: B = A.subgroup([a^3,b,c,d,e^2]); B
    1384             Multiplicative Abelian Group isomorphic to C4 x C5 x C5 x C7, which is the subgroup of
    1385             Multiplicative Abelian Group isomorphic to C3 x C5 x C5 x C7 x C8
    1386             generated by b, c, d, e^2
     1414            Multiplicative Abelian subgroup isomorphic to C3 x C5 x C5 x C7 x C8 generated by {a, b, c, d^2, e}
     1415            sage: A.subgroup([a, b, c, d^2, e^2])
     1416            Multiplicative Abelian subgroup isomorphic to C3 x C4 x C5 x C5 x C7 generated by {a, b, c, d^2, e^2}
     1417            sage: B = A.subgroup([a^3, b, c, d, e^2]); B
     1418            Multiplicative Abelian subgroup isomorphic to C4 x C5 x C5 x C7 generated by {b, c, d, e^2}
    13871419            sage: B.gens_orders()
    13881420            (4, 5, 5, 7)
    13891421            sage: A = AbelianGroup(4,[1009, 2003, 3001, 4001], names = "abcd")
     
    13981430            sage: A = AbelianGroup(4,[1008, 2003, 3001, 4001], names = "abcd")
    13991431            sage: a,b,c,d = A.gens()
    14001432            sage: B = A.subgroup([a^3,b,c,d]); B
    1401             Multiplicative Abelian Group isomorphic to C3 x C7 x C16 x
    1402             C2003 x C3001 x C4001, which is the subgroup of
    1403             Multiplicative Abelian Group isomorphic to C1008 x C2003 x
    1404             C3001 x C4001 generated by a^3, b, c, d
     1433            Multiplicative Abelian subgroup isomorphic
     1434            to C3 x C7 x C16 x C2003 x C3001 x C4001 generated by {a^3, b, c, d}
    14051435       
    14061436        Infinite groups can also be handled::
    14071437       
    14081438            sage: G = AbelianGroup([3,4,0], names = "abc")
    14091439            sage: a,b,c = G.gens()
    1410             sage: F = G.subgroup([a,b^2,c]); F
    1411             Multiplicative Abelian Group isomorphic to C2 x C3 x Z,
    1412             which is the subgroup of Multiplicative Abelian Group
    1413             isomorphic to C3 x C4 x Z generated by a, b^2, c
     1440            sage: F = G.subgroup([a, b^2, c]); F
     1441            Multiplicative Abelian subgroup isomorphic to C2 x C3 x Z generated by {a, b^2, c}
    14141442       
    14151443            sage: F.gens_orders()
    14161444            (2, 3, 0)
     
    14731501        if Hgens0 != []:
    14741502            for x in Hgens0:
    14751503               invs.append(0)
    1476         #print Hgensf, invs, invs0
     1504        invs = tuple(ZZ(i) for i in invs)
    14771505        AbelianGroup_class.__init__(self, invs, names)
    14781506
    14791507    def __contains__(self, x):
     
    15201548    def ambient_group(self):
    15211549        """
    15221550        Return the ambient group related to self.
     1551
     1552        OUTPUT:
     1553
     1554        A multiplicative Abelian group.
     1555
     1556        EXAMPLES::
     1557
     1558            sage: G.<a,b,c> = AbelianGroup([2,3,4])
     1559            sage: H = G.subgroup([a, b^2])
     1560            sage: H.ambient_group() is G
     1561            True
    15231562        """
    15241563        return self._ambient_group
    15251564
    15261565    def equals(left, right):
    15271566        """
    1528         Check whether ``left`` and ``right`` are the same subgroup.
     1567        Check whether ``left`` and ``right`` are the same (sub)group.
    15291568
    15301569        INPUT:
    15311570
     
    15331572
    15341573        OUTPUT:
    15351574
    1536         Boolean. Whether ``left`` and ``right`` are isomorphic as abelian groups.
     1575        Boolean. If ``right`` is a subgroup, test whether ``left`` and
     1576        ``right`` are the same subset of the ambient group. If
     1577        ``right`` is not a subgroup, test whether they are isomorphic
     1578        groups, see :meth:`~AbelianGroup_class.is_isomorphic`.
    15371579
    15381580        EXAMPLES::
    15391581       
    15401582            sage: G = AbelianGroup(3, [2,3,4], names="abc"); G
    1541             Multiplicative Abelian Group isomorphic to C2 x C3 x C4
     1583            Multiplicative Abelian group isomorphic to C2 x C3 x C4
    15421584            sage: a,b,c = G.gens()
    1543             sage: F=G.subgroup([a,b^2]); F
    1544             Multiplicative Abelian Group isomorphic to C2 x C3, which is the subgroup of
    1545             Multiplicative Abelian Group isomorphic to C2 x C3 x C4
    1546             generated by a, b^2
     1585            sage: F = G.subgroup([a,b^2]); F
     1586            Multiplicative Abelian subgroup isomorphic to C2 x C3 generated by {a, b^2}
    15471587            sage: F<G
    15481588            True
    15491589       
     
    15651605        try:
    15661606            right_ambient = right.ambient_group()
    15671607        except AttributeError:
    1568             try:
    1569                 return right.__eq__(left)
    1570             except AttributeError:
    1571                 return False
     1608            # right is not a subgroup
     1609            return left.is_isomorphic(right)
    15721610        if left_ambient is not right_ambient:
    15731611            return False
    15741612        return left <= right and right <= left
     
    15821620        EXAMPLES::
    15831621
    15841622            sage: G.<a,b> = AbelianGroup(2)
     1623            sage: G._repr_()
     1624            'Multiplicative Abelian group isomorphic to Z x Z'
    15851625            sage: A = G.subgroup([a])
    15861626            sage: A._repr_()
    1587             'Multiplicative Abelian Group isomorphic to Z, which is the subgroup of\nMultiplicative Abelian Group isomorphic to Z x Z\ngenerated by a'
     1627            'Multiplicative Abelian subgroup isomorphic to Z generated by {a}'
    15881628       """
    1589         s = AbelianGroup_class._repr_(self)
    1590         s += ', which is the subgroup of\n'
    1591         s += self.ambient_group()._repr_()
    1592         s += '\ngenerated by '
     1629        eldv = self.gens_orders()
    15931630        if self.is_trivial():
    1594             s += '1'
    1595         else:
    1596             s += ', '.join(map(str, self.gens()))
     1631            return "Trivial Abelian subgroup"
     1632        s = 'Multiplicative Abelian subgroup isomorphic to '
     1633        s += self._group_notation(eldv)
     1634        s += ' generated by '
     1635        s += '{' + ', '.join(map(str, self.gens())) + '}'
    15971636        return s
    15981637       
    1599     def invs(self):
    1600         """
    1601         Return the invariants for this subgroup.
    1602         """
    1603         G = self.ambient_group()
    1604         invsG = G.invariants()
    1605         Hgap = self._gap_init_()
    1606         raise Exception # WTF?
    1607        
    16081638    def gens(self):
    16091639        """
    16101640        Return the generators for this subgroup.
     1641
     1642        OUTPUT:
     1643
     1644        A tuple of group elements generating the subgroup.
     1645
     1646        EXAMPLES::
     1647
     1648            sage: G.<a,b> = AbelianGroup(2)
     1649            sage: A = G.subgroup([a])
     1650            sage: G.gens()
     1651            (a, b)
     1652            sage: A.gens()
     1653            (a,)
    16111654        """
    16121655        return self._gens
    16131656
  • sage/groups/abelian_gps/abelian_group_element.py

    diff --git a/sage/groups/abelian_gps/abelian_group_element.py b/sage/groups/abelian_gps/abelian_group_element.py
    a b  
    102102        EXAMPLES::
    103103       
    104104            sage: G = AbelianGroup(3,[2,3,4],names="abc"); G
    105             Multiplicative Abelian Group isomorphic to C2 x C3 x C4
     105            Multiplicative Abelian group isomorphic to C2 x C3 x C4
    106106            sage: a,b,c=G.gens()
    107107            sage: Gp = G.permutation_group(); Gp
    108108            Permutation Group with generators [(6,7,8,9), (3,4,5), (1,2)]
     
    132132        gp = Gp(pg)
    133133        return gp
    134134
    135     def random_element(self):
    136         """
    137         Return a random element of this dual group.
    138         """
    139         if not(self.is_finite()):
    140             raise NotImplementedError, "Only implemented for finite groups"
    141         gens = self.gens()
    142         g = gens[0]**0
    143         for i in range(len(gens)):
    144             g = g*gens[i]**(random(gens[i].order()))
    145         return g
    146 
    147135    def word_problem(self, words):
    148136        """
    149137        TODO - this needs a rewrite - see stuff in the matrix_grp
  • sage/groups/abelian_gps/abelian_group_morphism.py

    diff --git a/sage/groups/abelian_gps/abelian_group_morphism.py b/sage/groups/abelian_gps/abelian_group_morphism.py
    a b  
    3535    A set-theoretic map between AbelianGroups.
    3636    """
    3737    def __init__(self, parent):
     38        """
     39        The Python constructor.
     40        """
    3841        Morphism.__init__(self, parent)
    3942
    4043    def _repr_type(self):
     
    5255    def _repr_defn(self):
    5356        return "Identity map of "+str(X)
    5457
    55 class AbelianGroupMorphism:
     58class AbelianGroupMorphism(Morphism):
    5659    """
    5760    Some python code for wrapping GAP's GroupHomomorphismByImages
    5861    function for abelian groups. Returns "fail" if gens does not
     
    6265    EXAMPLES::
    6366   
    6467        sage: G = AbelianGroup(3,[2,3,4],names="abc"); G
    65         Multiplicative Abelian Group isomorphic to C2 x C3 x C4
     68        Multiplicative Abelian group isomorphic to C2 x C3 x C4
    6669        sage: a,b,c = G.gens()
    6770        sage: H = AbelianGroup(2,[2,3],names="xy"); H
    68         Multiplicative Abelian Group isomorphic to C2 x C3
     71        Multiplicative Abelian group isomorphic to C2 x C3
    6972        sage: x,y = H.gens()
    7073   
    7174    ::
     
    97100#TypeError: Sorry, the list [a*b, c^2] must generate G.
    98101
    99102    def __init__(self, G, H, genss, imgss ):
     103        from sage.categories.homset import Hom
     104        Morphism.__init__(self, Hom(G, H))
    100105        if len(genss) != len(imgss):
    101106            raise TypeError, "Sorry, the lengths of %s, %s must be equal."%(genss,imgss)
    102107        self._domain = G
     
    124129        EXAMPLES::
    125130       
    126131            sage: G = AbelianGroup(3,[2,3,4],names="abc"); G
    127             Multiplicative Abelian Group isomorphic to C2 x C3 x C4
     132            Multiplicative Abelian group isomorphic to C2 x C3 x C4
    128133            sage: a,b,c = G.gens()
    129134            sage: H = AbelianGroup(2,[2,3],names="xy"); H
    130             Multiplicative Abelian Group isomorphic to C2 x C3
     135            Multiplicative Abelian group isomorphic to C2 x C3
    131136            sage: x,y = H.gens()
    132137            sage: phi = AbelianGroupMorphism(H,G,[x,y],[a,b])
    133138            sage: phi._gap_init_()
    134139            'phi := GroupHomomorphismByImages(G,H,[x, y],[a, b])'
    135140        """
    136141        G  = (self.domain())._gap_init_()
    137         H  = (self.range())._gap_init_()
     142        H  = (self.codomain())._gap_init_()
    138143        # print G,H
    139144        s3 = 'G:=%s; H:=%s'%(G,H)
    140145        #print s3,"\n"
    141146        gap.eval(s3)
    142147        gensG = self.domain().variable_names()                    ## the Sage group generators
    143         gensH = self.range().variable_names()
     148        gensH = self.codomain().variable_names()
    144149        #print gensG, gensH
    145150        s1 = "gensG := GeneratorsOfGroup(G)"          ## the GAP group generators
    146151        gap.eval(s1)
     
    163168    def _repr_type(self):
    164169        return "AbelianGroup"
    165170
    166     def domain(self):
    167         return self._domain
    168 
    169     def range(self):
    170         return self._codomain
    171 
    172     def codomain(self):
    173         return self._codomain
    174 
    175171    def kernel(self):
    176172        """
    177173        Only works for finite groups.
     
    182178        EXAMPLES::
    183179       
    184180            sage: H = AbelianGroup(3,[2,3,4],names="abc"); H
    185             Multiplicative Abelian Group isomorphic to C2 x C3 x C4
     181            Multiplicative Abelian group isomorphic to C2 x C3 x C4
    186182            sage: a,b,c = H.gens()
    187183            sage: G = AbelianGroup(2,[2,3],names="xy"); G
    188             Multiplicative Abelian Group isomorphic to C2 x C3
     184            Multiplicative Abelian group isomorphic to C2 x C3
    189185            sage: x,y = G.gens()
    190186            sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])
    191187            sage: phi.kernel()
     
    218214        L = [self(g) for g in gensJ]
    219215        return G.subgroup(L)
    220216
    221     def __call__( self, g ):
     217    def _call_( self, g ):
    222218        """
    223219        Some python code for wrapping GAP's Images function but only for
    224220        permutation groups. Returns an error if g is not in G.
  • sage/groups/abelian_gps/all.py

    diff --git a/sage/groups/abelian_gps/all.py b/sage/groups/abelian_gps/all.py
    a b  
    2424from abelian_group import AbelianGroup, is_AbelianGroup, word_problem
    2525from values import AbelianGroupWithValues
    2626
    27 from abelian_group_morphism import is_AbelianGroupMorphism,AbelianGroupMap,AbelianGroupMorphism_id,AbelianGroupMorphism,AbelianGroupMorphism
    28 
     27# TODO:
     28# Implement group homset, conversion of generator images to morphism
     29from abelian_group_morphism import AbelianGroupMorphism
  • sage/groups/abelian_gps/dual_abelian_group.py

    diff --git a/sage/groups/abelian_gps/dual_abelian_group.py b/sage/groups/abelian_gps/dual_abelian_group.py
    a b  
    2929    sage: Fd.base_ring()
    3030    Cyclotomic Field of order 2520 and degree 576
    3131    sage: A,B,C,D,E = Fd.gens()
    32     sage: A(a)    ## random
    33     -1.0000000000000000 + 0.00000000000000013834419720915037*I
     32    sage: A(a)
     33    -1
    3434    sage: A(b), A(c), A(d), A(e)
    3535    (1, 1, 1, 1)
    3636
    3737    sage: Fd = F.dual_group(names='ABCDE', base_ring=CC)
    3838    sage: A,B,C,D,E = Fd.gens()
    39     sage: A(a)    ## random
    40     -1.0000000000000000 + 0.00000000000000013834419720915037*I
     39    sage: A(a)    # abs tol 1e-8
     40    -1.00000000000000 + 0.00000000000000*I
    4141    sage: A(b); A(c); A(d); A(e)
    4242    1.00000000000000
    4343    1.00000000000000
     
    130130    def group(self):
    131131        """
    132132        Return the group that ``self`` is the dual of.
     133
     134        EXAMPLES::
     135
     136            sage: F = AbelianGroup(3,[5,64,729], names=list("abc"))
     137            sage: Fd = F.dual_group(base_ring=CC)
     138            sage: Fd.group() is F
     139            True
    133140        """
    134141        return self._group
    135142   
     
    137144        """
    138145        Return the scalars over which the group is dualized.
    139146
     147        EXAMPLES::
     148
    140149            sage: F = AbelianGroup(3,[5,64,729], names=list("abc"))
    141150            sage: Fd = F.dual_group(base_ring=CC)
    142151            sage: Fd.base_ring()
     
    160169
    161170    def _repr_(self):
    162171        """
     172        Return a string representation.
     173
    163174        EXAMPLES::
    164175       
    165176            sage: F = AbelianGroup(5, [2,5,7,8,9], names='abcde')
    166177            sage: Fd = F.dual_group(names='ABCDE', base_ring=CyclotomicField(2*5*7*8*9))
    167             sage: Fd
     178            sage: Fd   # indirect doctest
    168179            Dual of Abelian Group isomorphic to Z/2Z x Z/5Z x Z/7Z x Z/8Z x Z/9Z
    169180            over Cyclotomic Field of order 5040 and degree 1152
    170181            sage: Fd = F.dual_group(names='ABCDE', base_ring=CC)
     
    207218            sage: G = AbelianGroup([2,3,9])
    208219            sage: Gd = G.dual_group(base_ring=CC)
    209220            sage: Gd.random_element()
    210             X0*X1^2*X2
     221            X1^2
     222
    211223            sage: N = 43^2-1
    212224            sage: G = AbelianGroup([N],names="a")
    213225            sage: Gd = G.dual_group(names="A", base_ring=CC)
    214226            sage: a, = G.gens()
    215227            sage: A, = Gd.gens()
    216228            sage: x = a^(N/4); y = a^(N/3); z = a^(N/14)
    217             sage: X = Gd.random_element(); X
     229            sage: X = A*Gd.random_element(); X
    218230            A^615
    219231            sage: len([a for a in [x,y,z] if abs(X(a)-1)>10^(-8)])
    220232            2
    221233        """
    222234        from sage.misc.prandom import randint
    223         gens = self.gens()
    224         g = gens[0]**0
    225         for i in range(len(gens)):
    226             g = g*gens[i]**(randint(1,gens[i].order()))
    227         return g
     235        result = self.one()
     236        for g in self.gens():
     237            order = g.order()
     238            result *= g**(randint(0,order))
     239        return result
    228240
    229241    def gen(self, i=0):
    230242        """
     
    251263
    252264    def gens(self):
    253265        """
    254         Return the generators for this subgroup.
     266        Return the generators for the group.
    255267
     268        OUTPUT:
     269
     270        A tuple of group elements generating the group.
     271
     272        EXAMPLES::
     273
     274            sage: F = AbelianGroup([7,11]).dual_group()
     275            sage: F.gens()
     276            (X0, X1)
    256277        """
    257278        n = self.group().ngens()
    258279        return tuple(self.gen(i) for i in range(n))
  • sage/groups/abelian_gps/dual_abelian_group_element.py

    diff --git a/sage/groups/abelian_gps/dual_abelian_group_element.py b/sage/groups/abelian_gps/dual_abelian_group_element.py
    a b  
    66
    77    sage: F = AbelianGroup([2,3,5,7,8], names="abcde")
    88    sage: F
    9     Multiplicative Abelian Group isomorphic to C2 x C3 x C5 x C7 x C8
     9    Multiplicative Abelian group isomorphic to C2 x C3 x C5 x C7 x C8
    1010
    1111    sage: Fd = F.dual_group(names="ABCDE")
    1212    sage: Fd
     
    1919    sage: A,B,C,D,E = Fd.gens()
    2020    sage: A*B^2*D^7
    2121    A*B^2
    22     sage: A(a)    ## random last few digits
     22    sage: A(a)
    2323    -1
    2424    sage: B(b)
    2525    zeta840^140 - 1
    26     sage: CC(_)    ## random last few digits
     26    sage: CC(_)     # abs tol 1e-8
    2727    -0.499999999999995 + 0.866025403784447*I
    2828    sage: A(a*b)
    2929    -1
     
    9898
    9999
    100100def is_DualAbelianGroupElement(x):
     101    """
     102    Test whether ``x`` is a dual Abelian group element.
     103
     104    INPUT:
     105
     106    - ``x`` -- anything.
     107
     108    OUTPUT:
     109
     110    Boolean.
     111
     112    EXAMPLES::
     113
     114        sage: from sage.groups.abelian_gps.dual_abelian_group import is_DualAbelianGroupElement
     115        sage: F = AbelianGroup(5,[5,5,7,8,9],names = list("abcde")).dual_group()
     116        sage: is_DualAbelianGroupElement(F)
     117        False
     118        sage: is_DualAbelianGroupElement(F.an_element())
     119        True
     120    """
    101121    return isinstance(x, DualAbelianGroupElement)
    102122
    103123
     
    127147            -1
    128148            sage: B(b)
    129149            zeta840^140 - 1
    130             sage: CC(B(b))      ## random last few digits
     150            sage: CC(B(b))    # abs tol 1e-8
    131151            -0.499999999999995 + 0.866025403784447*I
    132152            sage: A(a*b)
    133153            -1
  • sage/groups/abelian_gps/element_base.py

    diff --git a/sage/groups/abelian_gps/element_base.py b/sage/groups/abelian_gps/element_base.py
    a b  
    7979
    8080        OUTPUT:
    8181
    82         A tuple of integers for an abelian group element, or a tuple
    83         of base ring elements for an element of the dual abelian
    84         group.
     82        A tuple of integers for an abelian group element. The integer
     83        can be arbitrary if the corresponding generator has infinite
     84        order. If the generator is of finite order, the integer is in
     85        the range from 0 (inclusive) to the order (exclusive).
    8586
    8687        EXAMPLES::
    8788
     
    194195            72
    195196
    196197            sage: F = AbelianGroup(3,[7,8,9]); F
    197             Multiplicative Abelian Group isomorphic to C7 x C8 x C9
     198            Multiplicative Abelian group isomorphic to C7 x C8 x C9
    198199            sage: F.gens()[2].order()
    199200            9
    200201            sage: a,b,c = F.gens()
     
    224225            sage: G.<a,b> = AbelianGroup(2)
    225226            sage: a/b
    226227            a*b^-1
     228            sage: a._div_(b)
     229            a*b^-1
    227230        """
    228231        G = left.parent()
    229232        assert G is right.parent()
     
    241244            sage: G.<a,b> = AbelianGroup(2)
    242245            sage: a*b
    243246            a*b
     247            sage: a._mul_(b)
     248            a*b
    244249        """
    245250        G = left.parent()
    246251        assert G is right.parent()
     
    293298        return G.element_class(exponents, G)
    294299
    295300    __invert__ = inverse
     301
     302    def is_trivial(self):
     303        """
     304        Test whether ``self`` is the trivial group element ``1``.
     305
     306        OUTPUT:
     307
     308        Boolean.
     309
     310        EXAMPLES::
     311
     312            sage: G.<a,b> = AbelianGroup([0,5])
     313            sage: (a^5).is_trivial()
     314            False
     315            sage: (b^5).is_trivial()
     316            True
     317        """
     318        return all(e==0 for e in self._exponents)
  • sage/groups/abelian_gps/values.py

    diff --git a/sage/groups/abelian_gps/values.py b/sage/groups/abelian_gps/values.py
    a b  
    33
    44Often, one ends up with a set that forms an Abelian group. It would be
    55nice if one could return an Abelian group class to encapsulate the
    6 data. However, :mod:`abelian_group` is an abstract Abelian group
    7 defined by generators and relations. This module implements
    8 :class:`AbelianGroupWithValues` that allows the group elements to be
    9 decorated with values.
     6data. However,
     7:func:`~sage.groups.abelian_gps.abelian_group.AbelianGroup` is an
     8abstract Abelian group defined by generators and relations. This
     9module implements :class:`AbelianGroupWithValues` that allows the
     10group elements to be decorated with values.
    1011
    1112An example where this module is used is the unit group of a number
    1213field, see :mod:`sage.rings.number_field.unit_group`. The units form a
     
    4445    6 1 1
    4546
    4647The elements come with a coercion embedding into the
    47 :meth:`values_group`, so you can use the group elements instead of the
    48 values::
     48:meth:`~AbelianGroupWithValues_class.values_group`, so you can use the
     49group elements instead of the values::
    4950
    5051    sage: CF3.<zeta> = CyclotomicField(3)
    5152    sage: Z3.<g> = AbelianGroupWithValues([zeta], [3])
     
    7273
    7374from sage.misc.misc import prod
    7475from sage.rings.integer import Integer
    75 from sage.categories.morphism import CallMorphism
     76from sage.categories.morphism import Morphism
    7677from sage.groups.abelian_gps.abelian_group import AbelianGroup_class, _normalize
    7778from sage.groups.abelian_gps.abelian_group_element import AbelianGroupElement
    7879
     
    8283    """
    8384    Construct an Abelian group with values associated to the generators.
    8485
    85 
    8686    INPUT:
    8787
    8888    - ``values`` -- a list/tuple/iterable of values that you want to
     
    9999
    100100    -  ``names`` -- (optional) names of generators
    101101
    102     - ``values_group`` -- a group or ``None`` (default). The group
    103       that the values live in. If ``None`` it will be derived from the
    104       values.
     102    - ``values_group`` -- a parent or ``None`` (default). The common
     103      parent of the values. This might be a group, but can also just
     104      contain the values. For example, if the values are units in a
     105      ring then the ``values_group`` would be the whole ring. If
     106      ``None`` it will be derived from the values.
    105107
    106108    EXAMPLES::
    107109
     
    116118        4 f^4 1
    117119        5 f^5 -1
    118120        6 1 1
     121        sage: G.values_group()
     122        Integer Ring
     123
     124    The group elements come with a coercion embedding into the
     125    :meth:`values_group`, so you can use them like their
     126    :meth:`~sage.groups.abelian_gps.value.AbelianGroupWithValuesElement.value`
     127    ::
     128
     129        sage: G.values_embedding()
     130        Generic morphism:
     131          From: Multiplicative Abelian group isomorphic to C6
     132          To:   Integer Ring
     133        sage: g.value()
     134        -1
     135        sage: 0 + g
     136        -1
     137        sage: 1 + 2*g
     138        -1
    119139    """
    120140    if check:
    121141        raise NotImplementedError('checking that the values are a homomorphism is not implemented')
     
    128148    return M
    129149
    130150
    131 class AbelianGroupWithValuesEmbedding(CallMorphism):
     151class AbelianGroupWithValuesEmbedding(Morphism):
    132152    """
    133153    The morphism embedding the Abelian group with values in its values group.
    134154
     
    143163
    144164        sage: Z4.<g> = AbelianGroupWithValues([I], [4])
    145165        sage: embedding = Z4.values_embedding();  embedding
    146         Call morphism:
    147           From: Multiplicative Abelian Group isomorphic to C4
     166        Generic morphism:
     167          From: Multiplicative Abelian group isomorphic to C4
    148168          To:   Symbolic Ring
    149169        sage: embedding(1)
    150170        1
     
    163183            sage: Z4 = AbelianGroupWithValues([I], [4])
    164184            sage: from sage.groups.abelian_gps.values import AbelianGroupWithValuesEmbedding
    165185            sage: AbelianGroupWithValuesEmbedding(Z4, Z4.values_group())
    166             Call morphism:
    167               From: Multiplicative Abelian Group isomorphic to C4
     186            Generic morphism:
     187              From: Multiplicative Abelian group isomorphic to C4
    168188              To:   Symbolic Ring
    169189        """
    170190        assert domain.values_group() is codomain
    171191        from sage.categories.homset import Hom
    172         CallMorphism.__init__(self, Hom(domain, codomain))
     192        Morphism.__init__(self, Hom(domain, codomain))
    173193
    174194    def _call_(self, x):
    175195        """
     
    369389        TESTS::
    370390
    371391            sage: G = AbelianGroupWithValues([2,-1], [0,4]); G
    372             Multiplicative Abelian Group isomorphic to Z x C4
     392            Multiplicative Abelian group isomorphic to Z x C4
    373393
    374394            sage: cm = sage.structure.element.get_coercion_model()
    375395            sage: cm.explain(G, ZZ, operator.add)
    376396            Coercion on left operand via
    377                 Call morphism:
    378                   From: Multiplicative Abelian Group isomorphic to Z x C4
     397                Generic morphism:
     398                  From: Multiplicative Abelian group isomorphic to Z x C4
    379399                  To:   Integer Ring
    380400            Arithmetic performed after coercions.
    381401            Result lives in Integer Ring
     
    442462        """
    443463        The common parent of the values.
    444464
     465        The values need to form a multiplicative group, but can be
     466        embedded in a larger structure. For example, if the values are
     467        units in a ring then the :meth:`values_group` would be the
     468        whole ring.
     469
    445470        OUTPUT:
    446471
    447         The values need to form a multiplicative group. This
     472        The common parent of the values, containing the group
     473        generated by all values.
    448474
    449475        EXAMPLES::
    450476
     
    470496
    471497            sage: Z4 = AbelianGroupWithValues([I], [4])
    472498            sage: Z4.values_embedding()
    473             Call morphism:
    474               From: Multiplicative Abelian Group isomorphic to C4
     499            Generic morphism:
     500              From: Multiplicative Abelian group isomorphic to C4
    475501              To:   Symbolic Ring
    476502        """
    477503        return AbelianGroupWithValuesEmbedding(self, self.values_group())
  • sage/groups/group.pyx

    diff --git a/sage/groups/group.pyx b/sage/groups/group.pyx
    a b  
    3939        _test_an_element, _test_associativity, _test_elements,
    4040        _test_elements_eq, _test_inverse, _test_one,
    4141        _test_pickling, _test_prod, _test_some_elements
    42    """
     42    """
    4343    def __init__(self, gens=None, category=None):
    4444        """
    4545        The Python constructor
     
    5858            ...
    5959            AssertionError: Category of commutative additive groups is not a subcategory of Category of groups
    6060
    61          Check for #8119::
     61        Check for #8119::
    6262
    6363            sage: G = SymmetricGroup(2)
    6464            sage: h = hash(G)
     
    194194        """
    195195        return True
    196196
     197    def _an_element_(self):
     198        """
     199        Return an element
     200
     201        OUTPUT:
     202
     203        An element of the group.
     204
     205        EXAMPLES:
     206
     207            sage: G = AbelianGroup([2,3,4,5])
     208            sage: G.an_element()
     209            f0*f1*f2*f3
     210        """
     211        from sage.misc.misc import prod
     212        return prod(self.gens())
     213
    197214    def random_element(self, bound=None):
    198215        """
    199216        Return a random element of this group.
  • sage/groups/perm_gps/permgroup.py

    diff --git a/sage/groups/perm_gps/permgroup.py b/sage/groups/perm_gps/permgroup.py
    a b  
    19271927       
    19281928            sage: G = SymmetricGroup(4)
    19291929            sage: G.cohomology(1,2)                            # optional - gap_packages
    1930             Multiplicative Abelian Group isomorphic to C2
     1930            Multiplicative Abelian group isomorphic to C2
    19311931            sage: G = SymmetricGroup(3)
    19321932            sage: G.cohomology(5)                              # optional - gap_packages
    1933             Trivial Abelian Group
     1933            Trivial Abelian group
    19341934            sage: G.cohomology(5,2)                            # optional - gap_packages
    1935             Multiplicative Abelian Group isomorphic to C2
     1935            Multiplicative Abelian group isomorphic to C2
    19361936            sage: G.homology(5,3)                              # optional - gap_packages
    1937             Trivial Abelian Group
     1937            Trivial Abelian group
    19381938            sage: G.homology(5,4)                              # optional - gap_packages
    19391939            Traceback (most recent call last):
    19401940            ...
     
    19771977       
    19781978            sage: G = SymmetricGroup(5)
    19791979            sage: G.cohomology_part(7,2)                   # optional - gap_packages
    1980             Multiplicative Abelian Group isomorphic to C2 x C2 x C2
     1980            Multiplicative Abelian group isomorphic to C2 x C2 x C2
    19811981            sage: G = SymmetricGroup(3)
    19821982            sage: G.cohomology_part(2,3)                   # optional - gap_packages
    1983             Multiplicative Abelian Group isomorphic to C3
     1983            Multiplicative Abelian group isomorphic to C3
    19841984       
    19851985        AUTHORS:
    19861986
     
    20212021       
    20222022            sage: G = SymmetricGroup(5)
    20232023            sage: G.homology(7)                              # optional - gap_packages
    2024             Multiplicative Abelian Group isomorphic to C2 x C2 x C4 x C3 x C5
     2024            Multiplicative Abelian group isomorphic to C2 x C2 x C4 x C3 x C5
    20252025            sage: G.homology(7,2)                              # optional - gap_packages
    2026             Multiplicative Abelian Group isomorphic to C2 x C2 x C2 x C2 x C2
     2026            Multiplicative Abelian group isomorphic to C2 x C2 x C2 x C2 x C2
    20272027            sage: G.homology(7,3)                              # optional - gap_packages
    2028             Multiplicative Abelian Group isomorphic to C3
     2028            Multiplicative Abelian group isomorphic to C3
    20292029            sage: G.homology(7,5)                              # optional - gap_packages
    2030             Multiplicative Abelian Group isomorphic to C5
     2030            Multiplicative Abelian group isomorphic to C5
    20312031       
    20322032        REFERENCES:
    20332033
     
    20592059       
    20602060            sage: G = SymmetricGroup(5)
    20612061            sage: G.homology_part(7,2)                              # optional - gap_packages
    2062             Multiplicative Abelian Group isomorphic to C2 x C2 x C2 x C2 x C4
     2062            Multiplicative Abelian group isomorphic to C2 x C2 x C2 x C2 x C4
    20632063       
    20642064        AUTHORS:
    20652065
  • sage/groups/perm_gps/permgroup_named.py

    diff --git a/sage/groups/perm_gps/permgroup_named.py b/sage/groups/perm_gps/permgroup_named.py
    a b  
    454454            True
    455455            sage: C = CyclicPermutationGroup(10)
    456456            sage: C.as_AbelianGroup()
    457             Multiplicative Abelian Group isomorphic to C2 x C5
     457            Multiplicative Abelian group isomorphic to C2 x C5
    458458        """
    459459        n = Integer(n)
    460460        if n < 1:
     
    496496        """
    497497        Returns the corresponding Abelian Group instance.
    498498       
    499         EXAMPLES:
     499        EXAMPLES::
     500
    500501            sage: C = CyclicPermutationGroup(8)
    501502            sage: C.as_AbelianGroup()
    502             Multiplicative Abelian Group isomorphic to C8
    503 
     503            Multiplicative Abelian group isomorphic to C8
    504504        """
    505505        n = self.order()
    506506        a = list(factor(n))
  • sage/gsl/dft.py

    diff --git a/sage/gsl/dft.py b/sage/gsl/dft.py
    a b  
    224224            sage: s = IndexedSequence([1,2,3,4,5,6],J)
    225225            sage: s.dft()   # the precision of output is somewhat random and architecture dependent.
    226226            Indexed sequence: [21.0000000000000, -2.99999999999997 - 1.73205080756885*I, -2.99999999999999 + 1.73205080756888*I, -9.00000000000000 + 0.0000000000000485744257349999*I, -0.00000000000000976996261670137 - 0.0000000000000159872115546022*I, -0.00000000000000621724893790087 - 0.0000000000000106581410364015*I]                       
    227                 indexed by Multiplicative Abelian Group isomorphic to C2 x C3
     227                indexed by Multiplicative Abelian group isomorphic to C2 x C3
    228228            sage: J = CyclicPermutationGroup(6)
    229229            sage: s = IndexedSequence([1,2,3,4,5,6],J)
    230230            sage: s.dft()   # the precision of output is somewhat random and architecture dependent.
  • sage/homology/chain_complex.py

    diff --git a/sage/homology/chain_complex.py b/sage/homology/chain_complex.py
    a b  
    11851185
    11861186        sage: from sage.homology.chain_complex import HomologyGroup
    11871187        sage: G = AbelianGroup(5,[5,5,7,8,9]); G
    1188         Multiplicative Abelian Group isomorphic to C5 x C5 x C7 x C8 x C9
     1188        Multiplicative Abelian group isomorphic to C5 x C5 x C7 x C8 x C9
    11891189        sage: H = HomologyGroup(5,[5,5,7,8,9]); H
    11901190        C5 x C5 x C7 x C8 x C9
    11911191        sage: G == loads(dumps(G))
    11921192        True
    11931193        sage: AbelianGroup(4)
    1194         Multiplicative Abelian Group isomorphic to Z x Z x Z x Z
     1194        Multiplicative Abelian group isomorphic to Z x Z x Z x Z
    11951195        sage: HomologyGroup(4)
    11961196        Z x Z x Z x Z
    11971197        sage: HomologyGroup(100)
     
    12961296
    12971297        sage: from sage.homology.chain_complex import HomologyGroup
    12981298        sage: G = AbelianGroup(5,[5,5,7,8,9]); G
    1299         Multiplicative Abelian Group isomorphic to C5 x C5 x C7 x C8 x C9
     1299        Multiplicative Abelian group isomorphic to C5 x C5 x C7 x C8 x C9
    13001300        sage: H = HomologyGroup(5,[5,5,7,8,9]); H
    13011301        C5 x C5 x C7 x C8 x C9
    13021302        sage: AbelianGroup(4)
    1303         Multiplicative Abelian Group isomorphic to Z x Z x Z x Z
     1303        Multiplicative Abelian group isomorphic to Z x Z x Z x Z
    13041304        sage: HomologyGroup(4)
    13051305        Z x Z x Z x Z
    13061306        sage: HomologyGroup(100)
  • sage/rings/number_field/class_group.py

    diff --git a/sage/rings/number_field/class_group.py b/sage/rings/number_field/class_group.py
    a b  
    55An element of a class group is stored as a pair consisting of both an explicit
    66ideal in that ideal class, and a list of exponents giving that ideal class in
    77terms of the generators of the parent class group. These can be accessed with
    8 the ``ideal()`` and ``list()`` methods respectively.
     8the ``ideal()`` and ``exponents()`` methods respectively.
    99
    1010EXAMPLES::
    1111
    1212    sage: K.<a> = NumberField(x^2 + 23)
    1313    sage: I = K.class_group().gen(); I
    1414    Fractional ideal class (2, 1/2*a - 1/2)
    15     sage: J = I * I; J
     15    sage: I.ideal()
     16    Fractional ideal (2, 1/2*a - 1/2)
     17    sage: I.exponents()
     18    (1,)
     19
     20    sage: I.ideal() * I.ideal()
     21    Fractional ideal (4, 1/2*a + 3/2)
     22    sage: (I.ideal() * I.ideal()).reduce_equiv()
     23    Fractional ideal (2, 1/2*a + 1/2)
     24    sage: J = I * I; J    # class group multiplication is automatically reduced
    1625    Fractional ideal class (2, 1/2*a + 1/2)
     26    sage: J.ideal()
     27    Fractional ideal (2, 1/2*a + 1/2)
    1728    sage: J.exponents()
    1829    (2,)
     30
     31    sage: I * I.ideal()   # ideal classes coerce to their representative ideal
     32    Fractional ideal (4, 1/2*a + 3/2)
     33
    1934    sage: O = K.OK(); O
    2035    Maximal Order in Number Field in a with defining polynomial x^2 + 23
    2136    sage: O*(2, 1/2*a + 1/2)
     
    2641    Fractional ideal (1/2*a - 3/2)
    2742"""
    2843
    29 from sage.groups.abelian_gps.abelian_group import AbelianGroup_class
     44from sage.groups.abelian_gps.values import AbelianGroupWithValues_class, AbelianGroupWithValuesElement
     45from sage.groups.abelian_gps.abelian_group_element import AbelianGroupElement
    3046from sage.structure.sequence import Sequence
    3147from sage.structure.element import MonoidElement
    32 from sage.groups.abelian_gps.abelian_group_element import AbelianGroupElement
    3348from sage.groups.old import Group
    3449from sage.rings.arith import LCM
     50from sage.rings.all import ZZ
    3551
    3652
    37 
    38 class FractionalIdealClass(AbelianGroupElement):
     53class FractionalIdealClass(AbelianGroupWithValuesElement):
    3954    r"""
    4055    A fractional ideal class in a number field.
    4156   
     
    4560        Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23
    4661        sage: I = G.0; I
    4762        Fractional ideal class (2, 1/2*a - 1/2)
     63        sage: I.ideal()
     64        Fractional ideal (2, 1/2*a - 1/2)
     65
     66        EXAMPLES::
     67
     68            sage: K.<w>=QuadraticField(-23)
     69            sage: OK=K.ring_of_integers()
     70            sage: C=OK.class_group()
     71            sage: P2a,P2b=[P for P,e in (2*OK).factor()]
     72            sage: c = C(P2a); c
     73            Fractional ideal class (2, 1/2*w - 1/2)
     74            sage: c.gens()
     75            (2, 1/2*w - 1/2)
    4876    """
    4977    def __init__(self, element, parent, ideal=None):
    5078        """
     
    5684            sage: G(K.ideal(13, a + 4))
    5785            Fractional ideal class (13, 1/2*a + 17/2)
    5886        """
    59         self._ideal = ideal
    6087        if element is None:
    61             element = map(int, ideal.ideal_class_log(proof=parent._proof_flag))
    62         AbelianGroupElement.__init__(self, element, parent)
     88            element = parent._ideal_log(ideal)
     89        AbelianGroupWithValuesElement.__init__(self, element, parent, ideal)
    6390
    6491    def _repr_(self):
    6592        r"""
     
    75102        """
    76103        if self.is_principal():
    77104            return 'Trivial principal fractional ideal class'
    78         return 'Fractional ideal class %s'%self._ideal._repr_short()
     105        return 'Fractional ideal class %s'%self._value._repr_short()
    79106
    80107    def _mul_(self, other):
    81108        r"""
    82         Multiplication of two ideal classes.
     109        Multiplication of two (S-)ideal classes.
     110
     111        EXAMPLE::
     112
     113            sage: G = NumberField(x^2 + 23,'a').class_group(); G
     114            Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23
     115            sage: I = G.0; I
     116            Fractional ideal class (2, 1/2*a - 1/2)
     117            sage: I*I # indirect doctest
     118            Fractional ideal class (2, 1/2*a + 1/2)
     119            sage: I*I*I # indirect doctest
     120            Trivial principal fractional ideal class
     121
     122            sage: K.<a> = QuadraticField(-14)
     123            sage: I = K.ideal(2,a)
     124            sage: S = (I,)
     125            sage: CS = K.S_class_group(S)
     126            sage: G = K.ideal(3,a+1)
     127            sage: CS(G)*CS(G)
     128            Trivial S-ideal class
     129        """
     130        m = AbelianGroupElement._mul_(self, other)
     131        m._value = (self.ideal() * other.ideal()).reduce_equiv()
     132        return m
     133
     134    def _div_(self, other):
     135        r"""
     136        Division of two ideal classes.
    83137
    84138        EXAMPLE::
    85139
     
    92146            sage: I*I*I # indirect doctest
    93147            Trivial principal fractional ideal class
    94148        """
    95         m = AbelianGroupElement._mul_(self, other)
    96         m._ideal = (self._ideal * other._ideal).reduce_equiv()
     149        m = AbelianGroupElement._div_(self, other)
     150        m._value = (self.ideal() / other.ideal()).reduce_equiv()
    97151        return m
    98152
    99153    def __pow__(self, n):
     
    116170        """
    117171        # We use MonoidElement's __pow__ routine, since that does
    118172        # repeated squaring, and hence the ideal gets reduced as
    119         # we go along; actually computing self._ideal ** n would
     173        # we go along; actually computing self._value ** n would
    120174        # be disastrous.
    121175        n = n % self.order()
    122176        return MonoidElement.__pow__(self, n)
     
    134188            Fractional ideal class (2, a^2 + 2*a - 1)
    135189        """
    136190        m = AbelianGroupElement.inverse(self)
    137         m._ideal = (~self._ideal).reduce_equiv()
     191        m._value = (~self.ideal()).reduce_equiv()
    138192        return m
    139193
    140194    __invert__ = inverse
     
    167221        EXAMPLES::
    168222
    169223            sage: k.<a> = NumberField(x^2 + 20072); G = k.class_group(); G
    170             Class group of order 76 with structure C38 x C2 of Number Field in a with defining polynomial x^2 + 20072
     224            Class group of order 76 with structure C38 x C2
     225            of Number Field in a with defining polynomial x^2 + 20072
    171226            sage: I = (G.0)^35; I
    172227            Fractional ideal class (41, 1/2*a + 5)
    173228            sage: J = G(I.ideal()^5); J
     
    177232            sage: J == I^5
    178233            True
    179234        """
    180         return self.parent()(self._ideal.reduce_equiv())
     235        return self.parent()(self.ideal().reduce_equiv())
    181236
    182237    def ideal(self):
    183238        r"""
     
    194249            sage: c.ideal()
    195250            Fractional ideal (2, 1/2*w - 1/2)
    196251        """
    197         return self._ideal
     252        return self.value()
    198253
    199254    def gens(self):
    200255        r"""
    201256        Return generators for a representative ideal in this
    202         ideal class.
     257        (S-)ideal class.
    203258
    204259        EXAMPLES::
    205260
    206261            sage: K.<w>=QuadraticField(-23)
    207             sage: OK=K.ring_of_integers()
    208             sage: C=OK.class_group()
     262            sage: OK = K.ring_of_integers()
     263            sage: C = OK.class_group()
    209264            sage: P2a,P2b=[P for P,e in (2*OK).factor()]
    210             sage: c=C(P2a); c
     265            sage: c = C(P2a); c
    211266            Fractional ideal class (2, 1/2*w - 1/2)
    212267            sage: c.gens()
    213268            (2, 1/2*w - 1/2)
    214         """
     269       """
    215270        return self.ideal().gens()
    216271
    217272
     
    220275    r"""
    221276    An S-fractional ideal class in a number field for a tuple of primes S.
    222277
     278        EXAMPLES::
     279
     280            sage: K.<a> = QuadraticField(-14)
     281            sage: I = K.ideal(2,a)
     282            sage: S = (I,)
     283            sage: CS = K.S_class_group(S)
     284            sage: J = K.ideal(7,a)
     285            sage: G = K.ideal(3,a+1)
     286            sage: CS(I)
     287            Trivial S-ideal class
     288            sage: CS(J)
     289            Trivial S-ideal class
     290            sage: CS(G)
     291            Fractional S-ideal class (3, a + 1)
     292
     293        EXAMPLES::
     294
     295            sage: K.<a> = QuadraticField(-14)
     296            sage: I = K.ideal(2,a)
     297            sage: S = (I,)
     298            sage: CS = K.S_class_group(S)
     299            sage: J = K.ideal(7,a)
     300            sage: G = K.ideal(3,a+1)
     301            sage: CS(I).ideal()
     302            Fractional ideal (2, a)
     303            sage: CS(J).ideal()
     304            Fractional ideal (7, a)
     305            sage: CS(G).ideal()
     306            Fractional ideal (3, a + 1)
     307
     308
     309        EXAMPLES::
     310
     311            sage: K.<a> = QuadraticField(-14)
     312            sage: I = K.ideal(2,a)
     313            sage: S = (I,)
     314            sage: CS = K.S_class_group(S)
     315            sage: G = K.ideal(3,a+1)
     316            sage: CS(G).inverse()
     317            Fractional S-ideal class (3, a + 2)
     318
    223319    TESTS::
    224320
    225321        sage: K.<a> = QuadraticField(-14)
     
    235331        sage: CS(G).order()
    236332        2
    237333    """
    238     Element = FractionalIdealClass
    239 
    240     def __init__(self, element, parent, ideal=None):
    241         r"""
    242         Returns the S-ideal class of this fractional ideal.
    243 
    244         EXAMPLES::
    245 
    246             sage: K.<a> = QuadraticField(-14)
    247             sage: I = K.ideal(2,a)
    248             sage: S = (I,)
    249             sage: CS = K.S_class_group(S)
    250             sage: J = K.ideal(7,a)
    251             sage: G = K.ideal(3,a+1)
    252             sage: CS(I)
    253             Trivial S-ideal class
    254             sage: CS(J)
    255             Trivial S-ideal class
    256             sage: CS(G)
    257             Fractional S-ideal class (3, a + 1)
    258         """
    259         self._ideal = ideal
    260         if element is None:
    261             element = ideal.S_ideal_class_log(parent.S())
    262         AbelianGroupElement.__init__(self, element, parent)
    263334
    264335    def _repr_(self):
    265336        r"""
     
    277348            sage: CS(J^2)
    278349            Trivial S-ideal class
    279350        """
    280         if not any(self.exponents()):
     351        if self.is_trivial():
    281352            return 'Trivial S-ideal class'
    282         return 'Fractional S-ideal class %s' % self._ideal._repr_short()
     353        return 'Fractional S-ideal class %s' % self._value._repr_short()
    283354
    284     def ideal(self):
    285         r"""
    286         Returns a representative ideal for this S-ideal class.
    287355
    288         EXAMPLES::
    289356
    290             sage: K.<a> = QuadraticField(-14)
    291             sage: I = K.ideal(2,a)
    292             sage: S = (I,)
    293             sage: CS = K.S_class_group(S)
    294             sage: J = K.ideal(7,a)
    295             sage: G = K.ideal(3,a+1)
    296             sage: CS(I).ideal()
    297             Fractional ideal (2, a)
    298             sage: CS(J).ideal()
    299             Fractional ideal (7, a)
    300             sage: CS(G).ideal()
    301             Fractional ideal (3, a + 1)
    302         """
    303         return self._ideal
    304 
    305     def _mul_(self, other):
    306         r"""
    307         Multiplies together two S-ideal classes.
    308 
    309         EXAMPLES::
    310 
    311             sage: K.<a> = QuadraticField(-14)
    312             sage: I = K.ideal(2,a)
    313             sage: S = (I,)
    314             sage: CS = K.S_class_group(S)
    315             sage: G = K.ideal(3,a+1)
    316             sage: CS(G)*CS(G)
    317             Trivial S-ideal class
    318         """
    319         m = AbelianGroupElement._mul_(self, other)
    320         m._ideal = (self.ideal() * other.ideal()).reduce_equiv()
    321         return m
    322 
    323     def inverse(self):
    324         r"""
    325         Finds the inverse of the given S-ideal class.
    326 
    327         EXAMPLES::
    328 
    329             sage: K.<a> = QuadraticField(-14)
    330             sage: I = K.ideal(2,a)
    331             sage: S = (I,)
    332             sage: CS = K.S_class_group(S)
    333             sage: G = K.ideal(3,a+1)
    334             sage: CS(G).inverse()
    335             Fractional S-ideal class (3, a + 2)
    336         """
    337         m = AbelianGroupElement.inverse(self)
    338         m._ideal = self.parent().number_field().class_group()(self.ideal()).inverse().ideal()
    339         return m
    340 
    341 
    342 
    343 class ClassGroup(AbelianGroup_class):
     357class ClassGroup(AbelianGroupWithValues_class):
    344358    r"""
    345359    The class group of a number field.
     360
     361    EXAMPLES::
     362
     363        sage: K.<a> = NumberField(x^2 + 23)
     364        sage: G = K.class_group(); G
     365        Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23
     366        sage: G.category()
     367        Category of groups
     368
     369    Note the distinction between abstract generators, their ideal, and
     370    exponents::
     371
     372        sage: C = NumberField(x^2 + 120071, 'a').class_group(); C
     373        Class group of order 500 with structure C250 x C2
     374        of Number Field in a with defining polynomial x^2 + 120071
     375        sage: c = C.gen(0)
     376        sage: c  # random
     377        Fractional ideal class (5, 1/2*a + 3/2)
     378        sage: c.ideal()  # random
     379        Fractional ideal (5, 1/2*a + 3/2)
     380        sage: c.ideal() is c.value()   # alias
     381        True
     382        sage: c.exponents()
     383        (1, 0)
    346384    """
    347385    Element = FractionalIdealClass
    348386
     
    350388        r"""
    351389        Create a class group.
    352390
    353         Note that the error in the test suite below is caused by the fact that
    354         there is no category of additive abelian groups.
    355 
    356         EXAMPLES::
     391        TESTS::
    357392
    358393            sage: K.<a> = NumberField(x^2 + 23)
    359             sage: G = K.class_group(); G
    360             Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23
    361 
    362             sage: G.category()
    363             Category of groups
     394            sage: G = K.class_group()
    364395            sage: TestSuite(G).run()
    365396        """
    366         AbelianGroup_class.__init__(self, gens_orders, names)
     397        AbelianGroupWithValues_class.__init__(self, gens_orders, names, gens,
     398                                              values_group=number_field.ideal_monoid())
    367399        self._proof_flag = proof
    368         self.__number_field = number_field
    369         self.__gens = Sequence([self(x) for x in gens], immutable=True,
    370                                universe=self, check=False)
     400        self._number_field = number_field
    371401
    372402    def _element_constructor_(self, *args, **kwds):
    373403        r"""
     
    396426            [(0,), (2,), (4,)]
    397427        """
    398428        if isinstance(args[0], FractionalIdealClass):
    399             return self.element_class(None, self, self.__number_field.ideal(args[0].ideal()))
     429            return self.element_class(None, self, self._number_field.ideal(args[0].ideal()))
    400430        else:
    401             I = self.__number_field.ideal(*args, **kwds)
     431            I = self._number_field.ideal(*args, **kwds)
    402432            if I.is_zero(): raise TypeError, "The zero ideal is not a fractional ideal"
    403433            return self.element_class(None, self, I)
    404434
    405     def gens(self):
     435    def _ideal_log(self, ideal):
     436        """
     437        Compute the exponents from the ``ideal``.
     438
     439        Used by the element constructor if necessary.
     440
     441        EXAMPLES::
     442
     443            sage: K.<a> = NumberField(x^2 + 23,'a')
     444            sage: G = K.class_group()
     445            sage: g = G.an_element()
     446            sage: G._ideal_log(g.ideal())
     447            (1,)
     448            sage: g.exponents()
     449            (1,)
     450        """
     451        return tuple(ZZ(order) for order in ideal.ideal_class_log(proof=self._proof_flag))
     452
     453    def gens_ideals(self):
    406454        r"""
    407         Return generators for the class group.
     455        Return generating ideals for the (S-)class group.
     456
     457        This is an alias for :meth:`gens_values`.
     458
     459        OUTPUT:
     460
     461        A tuple of ideals, one for each abstract Abelian group generator.
    408462
    409463        EXAMPLES::
    410464
     
    416470            Class group of order 68 with structure C34 x C2 of Number Field
    417471            in a with defining polynomial x^2 + x + 23899
    418472            sage: C.gens()
    419             [Fractional ideal class (23, a + 14), Fractional ideal class (5, a + 3)]
     473            (Fractional ideal class (23, a + 14), Fractional ideal class (5, a + 3))
    420474            sage: C.ngens()
    421475            2
    422476        """
    423         return self.__gens
    424 
    425     def gen(self, i=0):
    426         r"""
    427         Return the i-th generator for this class group.
    428 
    429         EXAMPLES::
    430 
    431             sage: C = NumberField(x^2 + 120071, 'a').class_group(); C
    432             Class group of order 500 with structure C250 x C2 of Number Field in a with defining polynomial x^2 + 120071
    433             sage: C.gen(0) # random
    434             Fractional ideal class (130, 1/2*a + 137/2)
    435             sage: C.gen(1) # random
    436             Fractional ideal class (7, a)
    437         """
    438         return self.__gens[i]
     477        return self.gens_values()
    439478
    440479    def __iter__(self):
    441480        r"""
     
    453492             Fractional ideal class (2, 1/4*a^3 - 1/4*a^2 + 1/4*a - 1/4),
    454493             Fractional ideal class (2, 1/2*a^2 + 1/2)]
    455494            sage: G.list()
    456             [Trivial principal fractional ideal class,
     495            (Trivial principal fractional ideal class,
    457496             Fractional ideal class (2, 1/4*a^3 - 1/4*a^2 + 1/4*a - 1/4),
    458              Fractional ideal class (2, 1/2*a^2 + 1/2)]
     497             Fractional ideal class (2, 1/2*a^2 + 1/2))
    459498
    460499        TESTS::
    461500
     
    466505            sage: list(G)
    467506            [Trivial principal fractional ideal class]
    468507            sage: G.list()
    469             [Trivial principal fractional ideal class]
     508            (Trivial principal fractional ideal class,)
    470509        """
    471510        from sage.misc.mrange import mrange
    472511        orders = self.gens_orders()
     
    498537
    499538    def number_field(self):
    500539        r"""
    501         Return the number field that this class group is attached to.
     540        Return the number field that this (S-)class group is attached to.
    502541
    503542        EXAMPLES::
    504543
     
    506545            Class group of order 3 with structure C3 of Number Field in w with defining polynomial x^2 + 23
    507546            sage: C.number_field()
    508547            Number Field in w with defining polynomial x^2 + 23
     548
     549            sage: K.<a> = QuadraticField(-14)
     550            sage: CS = K.S_class_group(K.primes_above(2))
     551            sage: CS.number_field()
     552            Number Field in a with defining polynomial x^2 + 14
    509553        """
    510         return self.__number_field
     554        return self._number_field
    511555
    512556
    513557
     
    516560class SClassGroup(ClassGroup):
    517561    r"""
    518562    The S-class group of a number field.
     563
     564    EXAMPLES::
     565
     566        sage: K.<a> = QuadraticField(-14)
     567        sage: S = K.primes_above(2)
     568        sage: K.S_class_group(S).gens()   # random gens (platform dependent)
     569        (Fractional S-ideal class (3, a + 2),)
     570
     571        sage: K.<a> = QuadraticField(-974)
     572        sage: CS = K.S_class_group(K.primes_above(2)); CS
     573        S-class group of order 18 with structure C6 x C3
     574        of Number Field in a with defining polynomial x^2 + 974
     575        sage: CS.gen(0) # random
     576        Fractional S-ideal class (3, a + 2)
     577        sage: CS.gen(1) # random
     578        Fractional S-ideal class (31, a + 24)
    519579    """
    520580    Element = SFractionalIdealClass
    521581
     
    534594            sage: K.S_class_group([K.ideal(13, a + 8)])
    535595            S-class group of order 4 with structure C2 x C2 of Number Field in a with defining polynomial x^2 + 105
    536596        """
    537         AbelianGroup_class.__init__(self, gens_orders, names)
     597        AbelianGroupWithValues_class.__init__(self, gens_orders, names, gens,
     598                                              values_group=number_field.ideal_monoid())
    538599        self._proof_flag = proof
    539         self.__number_field = number_field
    540         self.__S = S
    541         self.__gens = Sequence([self(x) for x in gens], immutable=True,
    542                                universe=self, check=False)
     600        self._number_field = number_field
     601        self._S = S
    543602
    544603    def S(self):
    545604        r"""
     
    560619            sage: CT.S()
    561620            ()
    562621        """
    563         return self.__S
     622        return self._S
     623
     624    def _ideal_log(self, ideal):
     625        """
     626        Compute the exponents from the ``ideal``.
     627
     628        Used by the element constructor if necessary.
     629
     630        EXAMPLES::
     631
     632            sage: K.<a> = QuadraticField(-14)
     633            sage: I = K.ideal(2,a)
     634            sage: S = (I,)
     635            sage: CS = K.S_class_group(S)
     636            sage: s = CS.an_element()
     637            sage: CS._ideal_log(s.ideal())
     638            (1,)
     639            sage: s.exponents()
     640            (1,)
     641        """
     642        return tuple(ZZ(order) for order in ideal.S_ideal_class_log(self.S()))
    564643
    565644    def _element_constructor_(self, *args, **kwds):
    566645        r"""
     
    588667            if I.is_zero(): raise TypeError, "The zero ideal is not a fractional ideal"
    589668            return self.element_class(None, self, I)
    590669
    591     def gens(self):
    592         r"""
    593         Return generators for the S-class group.
    594 
    595         EXAMPLES::
    596 
    597             sage: K.<a> = QuadraticField(-14)
    598             sage: S = K.primes_above(2)
    599             sage: K.S_class_group(S).gens()   # random gens (platform dependent)
    600             [Fractional S-ideal class (3, a + 2)]
    601         """
    602         return self.__gens
    603 
    604     def gen(self, i=0):
    605         r"""
    606         Return the i-th generator for this class group.
    607 
    608         EXAMPLES::
    609 
    610             sage: K.<a> = QuadraticField(-974)
    611             sage: CS = K.S_class_group(K.primes_above(2)); CS
    612             S-class group of order 18 with structure C6 x C3 of Number Field in a with defining polynomial x^2 + 974
    613             sage: CS.gen(0) # random
    614             Fractional S-ideal class (3, a + 2)
    615             sage: CS.gen(1) # random
    616             Fractional S-ideal class (31, a + 24)
    617         """
    618         return self.__gens[i]
    619 
    620670    def _repr_(self):
    621671        r"""
    622672        Return string representation of this S-class group.
     
    633683            s += 'with structure %s ' % self._group_notation(self.gens_orders())
    634684        s += 'of %s' % self.number_field()
    635685        return s
    636 
    637     def number_field(self):
    638         r"""
    639         Return the number field that this S-class group is attached to.
    640        
    641         EXAMPLES::
    642 
    643             sage: K.<a> = QuadraticField(-14)
    644             sage: CS = K.S_class_group(K.primes_above(2))
    645             sage: CS.number_field()
    646             Number Field in a with defining polynomial x^2 + 14
    647         """
    648         return self.__number_field
  • sage/rings/number_field/number_field.py

    diff --git a/sage/rings/number_field/number_field.py b/sage/rings/number_field/number_field.py
    a b  
    32243224            sage: G.0
    32253225            Fractional ideal class (2, 1/2*a - 1/2)
    32263226            sage: G.gens()
    3227             [Fractional ideal class (2, 1/2*a - 1/2)]
     3227            (Fractional ideal class (2, 1/2*a - 1/2),)
    32283228       
    32293229        ::
    32303230       
     
    32353235            sage: G is K.class_group(proof=False)
    32363236            False
    32373237            sage: G.gens()
    3238             [Fractional ideal class (2, 1/2*a - 1/2)]
     3238            (Fractional ideal class (2, 1/2*a - 1/2),)
    32393239       
    32403240        There can be multiple generators::
    32413241       
     
    47654765        EXAMPLES::
    47664766       
    47674767            sage: NumberField(x^3+x+9, 'a').narrow_class_group()
    4768             Multiplicative Abelian Group isomorphic to C2
     4768            Multiplicative Abelian group isomorphic to C2
    47694769        """
    47704770        proof = proof_flag(proof)       
    47714771        try:
  • sage/rings/number_field/number_field_ideal.py

    diff --git a/sage/rings/number_field/number_field_ideal.py b/sage/rings/number_field/number_field_ideal.py
    a b  
    24522452            sage: k.<a> = NumberField(x^3 - 11)
    24532453            sage: A = k.ideal(5)
    24542454            sage: G = A.idealstar(); G
    2455             Multiplicative Abelian Group isomorphic to C24 x C4
     2455            Multiplicative Abelian group isomorphic to C24 x C4
    24562456            sage: G.gens()
    24572457            (f0, f1)
    24582458
    24592459            sage: G = A.idealstar(2)
    24602460            sage: G.gens()
    24612461            (f0, f1)
    2462             sage: G.gens_values()
    2463             (-a^2 + 2*a, 2*a^2 + 2*a - 2)
     2462            sage: G.gens_values()   # random output
     2463            (2*a^2 - 1, 2*a^2 + 2*a - 2)
    24642464            sage: all([G.gen(i).value() in k for i in range(G.ngens())])
    24652465            True
    24662466
     
    24682468
    24692469            sage: k.<a> = NumberField(x^2 + 1)
    24702470            sage: k.ideal(a+1).idealstar(2)
    2471             Trivial Abelian Group
     2471            Trivial Abelian group
    24722472
    24732473        ALGORITHM: Uses Pari function ``idealstar``
    24742474        """
  • sage/rings/number_field/unit_group.py

    diff --git a/sage/rings/number_field/unit_group.py b/sage/rings/number_field/unit_group.py
    a b  
    4141
    4242    sage: UK.fundamental_units() # random
    4343    [1/24*a^3 + 1/4*a^2 - 1/12*a - 1]
    44     sage: UK.torsion_generator()
     44    sage: torsion_gen = UK.torsion_generator();  torsion_gen
    4545    u0
    46     sage: _.value()
     46    sage: torsion_gen.value()
    4747    -1/12*a^3 + 1/6*a
    4848    sage: UK.zeta_order()
    4949    4
     
    133133        sage: x = polygen(QQ)
    134134        sage: K.<a> = NumberField(x^4 + 23)
    135135        sage: UK = K.unit_group()
    136         sage: UK.an_element()
     136        sage: u = UK.an_element();  u
    137137        u0*u1
    138         sage: _.value()
     138        sage: u.value()
    139139        -1/4*a^3 - 7/4*a^2 - 17/4*a - 19/4
    140140
    141141        sage: x = polygen(QQ)
     
    232232        gens = [z] + fu
    233233        values = Sequence(gens, immutable=True, universe=self, check=False)
    234234        # Construct the abtract group:       
    235         AbelianGroupWithValues_class.__init__(self, tuple([n]+[0]*len(fu)), 'u', values, number_field)
     235        gens_orders = tuple([ZZ(n)]+[ZZ(0)]*len(fu))
     236        AbelianGroupWithValues_class.__init__(self, gens_orders, 'u', values, number_field)
    236237
    237238    def _element_constructor_(self, u):
    238239        """
     
    283284        m.insert(0,m.pop())
    284285        return self.element_class(m, self)
    285286
    286         """
    287         """
    288 
    289287    def rank(self):
    290288        """
    291289        Return the rank of the unit group.
     
    295293            sage: K.<z> = CyclotomicField(13)
    296294            sage: UnitGroup(K).rank()
    297295            5
    298 
    299296        """
    300297        return self.ngens()-1
    301298
    302         """
    303         Return the `i`'th generator for this unit group.
    304 
    305         .. note::
    306 
    307            `i=0` gives the torsion generator, i.e. a primitive root of unity.
    308 
    309         EXAMPLES::
    310 
    311         """
    312 
    313299    def _repr_(self):
    314300        """
    315301        Return string representation of this unit group.
  • sage/rings/ring.pyx

    diff --git a/sage/rings/ring.pyx b/sage/rings/ring.pyx
    a b  
    18571857        EXAMPLES::
    18581858
    18591859            sage: QQ.class_group()
    1860             Trivial Abelian Group
     1860            Trivial Abelian group
    18611861        """
    18621862        from sage.groups.abelian_gps.abelian_group import AbelianGroup
    18631863        return AbelianGroup([])
  • sage/schemes/elliptic_curves/ell_finite_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_finite_field.py b/sage/schemes/elliptic_curves/ell_finite_field.py
    a b  
    13771377            sage: Emod = E.change_ring(OKmodP); Emod
    13781378            Elliptic Curve defined by y^2  = x^3 + ibar*x + (ibar+3) over Residue field in ibar of Fractional ideal (10007)             
    13791379            sage: Emod.abelian_group() #random generators
    1380             (Multiplicative Abelian Group isomorphic to C50067594 x C2,
     1380            (Multiplicative Abelian group isomorphic to C50067594 x C2,
    13811381            ((3152*ibar + 7679 : 7330*ibar + 7913 : 1), (8466*ibar + 1770 : 0 : 1)))
    13821382        """
    13831383        if not debug: