Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'public/10184' of git://trac.sagemath.org/sage into publ…
Browse files Browse the repository at this point in the history
…ic/class_group_iter-10184
  • Loading branch information
Travis Scrimshaw committed Jun 23, 2017
2 parents afeb0d6 + 568cc95 commit f0ccaa0
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/sage/rings/number_field/class_group.py
Expand Up @@ -40,6 +40,7 @@
sage: (O*(2, 1/2*a + 1/2))^3
Fractional ideal (1/2*a - 3/2)
"""
from six.moves import range

from sage.groups.abelian_gps.values import AbelianGroupWithValues_class, AbelianGroupWithValuesElement
from sage.groups.abelian_gps.abelian_group_element import AbelianGroupElement
Expand Down Expand Up @@ -555,17 +556,35 @@ def __iter__(self):
sage: G.list()
(Trivial principal fractional ideal class,)
"""
from sage.misc.mrange import mrange
orders = self.gens_orders()
T = mrange(orders)
g = self.gens()
for t in T:
I = self(1)
for i, j in enumerate(t):
I *= g[i]**j
yield I
if not T:
yield self(1)
return self._iter_inner(self.one(), 0)

def _iter_inner(self, i0, k):
r"""
Yield all elements of the coset `i0 * \{h in H_k\}`, where
`H_k` is the subgroup of ``self`` generated by ``self.gens()[k:]``.
Each new element provided costs exactly one group operation, and is
not necessarily reduced.
EXAMPLES::
sage: x = ZZ['x'].gen()
sage: K.<v> = NumberField(x^4 + 90*x^2 + 45)
sage: OK = K.maximal_order()
sage: G = OK.class_group()
sage: iter = G._iter_inner(G.gen(0)^2,1)
sage: all(next(iter) in G for _ in range(4))
True
"""
if k == self.ngens():
yield i0
return
I = i0
for _ in range(self.invariants()[k]):
for J in self._iter_inner(I, k + 1):
yield J
I *= self.gen(k)
return

def _repr_(self):
r"""
Expand Down

0 comments on commit f0ccaa0

Please sign in to comment.