Skip to content

Commit

Permalink
Implementing an iterator for absolute number fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Mar 31, 2024
1 parent b693ea9 commit 3dc65b5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -8474,6 +8474,27 @@ def base_field(self):
"""
return QQ

def __iter__(self):
r"""
Iterate over ``self``.
EXAMPLES::
sage: K = CyclotomicField(5)
sage: it = iter(K)
sage: [next(it) for _ in range(20)]
[0, 1, zeta5, zeta5^2, zeta5^3, -1, zeta5 + 1, zeta5^2 + 1,
zeta5^3 + 1, -zeta5, zeta5^2 + zeta5, zeta5^3 + zeta5, -zeta5^2,
zeta5^3 + zeta5^2, -zeta5^3, 1/2, zeta5 - 1, zeta5^2 - 1,
zeta5^3 - 1, -zeta5 + 1]
"""
from sage.categories.sets_cat import cartesian_product
M, f, g = self.free_module()
# We iterate over the Cartesian product since the free module does
# not iterate using the diagonal embedding.
for v in cartesian_product([M.base_ring()] * M.dimension()):
yield f(M(list(v)))

def is_absolute(self):
r"""
Return ``True`` since ``self`` is an absolute field.
Expand Down

0 comments on commit 3dc65b5

Please sign in to comment.