# HG changeset patch
# User Nick Alexander <ncalexander@gmail.com>
# Date 1228668289 0
# Node ID 864d8e007eb434f927394caf61a9dbbd53ba45b8
# Parent 468e3c658dbbbb41730b3f525e4f0f0a58280d88
[mq]: 3810-ncalexan-abelian-group-iter.patch
diff -r 468e3c658dbb -r 864d8e007eb4 sage/groups/abelian_gps/abelian_group.py
|
a
|
b
|
class AbelianGroup_class(group.AbelianGr |
| 775 | 775 | pass |
| 776 | 776 | if not(self.is_finite()): |
| 777 | 777 | raise NotImplementedError, "Group must be finite" |
| 778 | | if self.order()==1: |
| 779 | | L = [AbelianGroupElement(self, 1)] |
| 780 | | else: |
| 781 | | L = [AbelianGroupElement(self, t) for t in mrange(self.invariants())] |
| | 778 | self.__list = list(self.__iter__()) |
| | 779 | return list(self.__list) |
| | 780 | # if self.order()==1: |
| | 781 | # L = [AbelianGroupElement(self, 1)] |
| | 782 | # else: |
| | 783 | # L = [AbelianGroupElement(self, t) for t in mrange(self.invariants())] |
| 782 | 784 | self.__list = L |
| 783 | 785 | return list(L) |
| 784 | 786 | |
| … |
… |
class AbelianGroup_class(group.AbelianGr |
| 790 | 792 | sage: G = AbelianGroup([2,3], names = "ab") |
| 791 | 793 | sage: [a for a in G] |
| 792 | 794 | [1, b, b^2, a, a*b, a*b^2] |
| | 795 | sage: L = list(G); L |
| | 796 | [1, b, b^2, a, a*b, a*b^2] |
| | 797 | |
| | 798 | The returned list is a reference; mutating it does not allow the |
| | 799 | user to (accidentally?) alter the computed generators: |
| | 800 | |
| | 801 | sage: L[0] = 0 |
| | 802 | sage: list(G) |
| | 803 | [1, b, b^2, a, a*b, a*b^2] |
| | 804 | sage: G = AbelianGroup([1], names="a") |
| | 805 | sage: list(G) |
| | 806 | [1] |
| | 807 | sage: G = AbelianGroup([]) |
| | 808 | sage: G.list() |
| | 809 | [1] |
| | 810 | sage: list(G) |
| | 811 | [1] |
| 793 | 812 | """ |
| 794 | | for g in self.list(): |
| 795 | | yield g |
| 796 | | |
| | 813 | invs = self.invariants() |
| | 814 | if len(invs)==0: |
| | 815 | yield AbelianGroupElement(self, []) |
| | 816 | for t in mrange(invs): |
| | 817 | yield AbelianGroupElement(self, t) |
| 797 | 818 | |
| 798 | 819 | class AbelianGroup_subgroup(AbelianGroup_class): |
| 799 | 820 | """ |
# HG changeset patch
# User John Cremona <john.cremona@gmail.com>
# Date 1228669024 0
# Node ID e3f7e0b3a64ea22f46a8b1de0abce66fab4241e5
# Parent 864d8e007eb434f927394caf61a9dbbd53ba45b8
[mq]: 3810-ncalexan-class-group-list.patch
diff -r 864d8e007eb4 -r e3f7e0b3a64e sage/groups/abelian_gps/abelian_group.py
|
a
|
b
|
class AbelianGroup_class(group.AbelianGr |
| 777 | 777 | raise NotImplementedError, "Group must be finite" |
| 778 | 778 | self.__list = list(self.__iter__()) |
| 779 | 779 | return list(self.__list) |
| 780 | | # if self.order()==1: |
| 781 | | # L = [AbelianGroupElement(self, 1)] |
| 782 | | # else: |
| 783 | | # L = [AbelianGroupElement(self, t) for t in mrange(self.invariants())] |
| 784 | | self.__list = L |
| 785 | | return list(L) |
| 786 | 780 | |
| 787 | 781 | def __iter__(self): |
| 788 | 782 | """ |
diff -r 864d8e007eb4 -r e3f7e0b3a64e sage/rings/number_field/class_group.py
|
a
|
b
|
class ClassGroup(AbelianGroup_class): |
| 104 | 104 | if i < 0 or i >= len(self.__gens): |
| 105 | 105 | raise IndexError |
| 106 | 106 | return self.__gens[i] |
| | 107 | |
| | 108 | def __iter__(self): |
| | 109 | r""" |
| | 110 | Return an iterator of all ideal classes in this class group. |
| | 111 | |
| | 112 | EXAMPLES: |
| | 113 | sage: K.<a> = NumberField(x^4 + 23) |
| | 114 | sage: G = K.class_group() |
| | 115 | sage: G |
| | 116 | Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^4 + 23 |
| | 117 | sage: list(G) |
| | 118 | [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 + a - 1/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] |
| | 119 | sage: G.list() |
| | 120 | [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 + a - 1/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] |
| | 121 | |
| | 122 | TESTS: |
| | 123 | sage: K.<a> = NumberField(x^2 + 1) |
| | 124 | sage: G = K.class_group() |
| | 125 | sage: G |
| | 126 | Class group of order 1 with structure of Number Field in a with defining polynomial x^2 + 1 |
| | 127 | sage: list(G) |
| | 128 | [Trivial principal fractional ideal class] |
| | 129 | sage: G.list() |
| | 130 | [Trivial principal fractional ideal class] |
| | 131 | |
| | 132 | sage: C = NumberField(x^2 + x + 23899, 'a').class_group(); C |
| | 133 | Class group of order 68 with structure C34 x C2 of Number Field in a with defining polynomial x^2 + x + 23899 |
| | 134 | sage: len(list(C.__iter__())) |
| | 135 | 68 |
| | 136 | """ |
| | 137 | from sage.misc.mrange import mrange |
| | 138 | invs = self.invariants() |
| | 139 | T = mrange(invs) |
| | 140 | g = self.gens() |
| | 141 | for t in T: |
| | 142 | I = self(1) |
| | 143 | for i, j in enumerate(t): |
| | 144 | I *= g[i]**j |
| | 145 | yield I |
| | 146 | if not T: |
| | 147 | yield self(1) |
| 107 | 148 | |
| 108 | 149 | def _repr_(self): |
| 109 | 150 | """ |