Iterating over finite fields

36 views
Skip to first unread message

Rob Beezer

unread,
Oct 31, 2009, 4:47:27 PM10/31/09
to sage-devel
The list() method does not seem to work properly for (givaro) finite
fields:

sage: K.<a>=GF(4)
sage: [x for x in K]
[0, a, a + 1, 1]
sage: hasattr(K, '__iter__')
True
sage: K.list()
...
TypeError:
'sage.rings.finite_field_givaro.FiniteField_givaro_iterator' object is
not iterable

The culprit looks to me to be in sage/rings/finite_field_givaro.pyx
starting at:

cdef class FiniteField_givaro_iterator:

With some guidance I can probably fix this. Does the iterator need to
inherit from some more general iterator object? Should it be a Python
generator (ie w/ a yield) and then not cdef'ed? Or?

For example, the iterator for a ring of integers mod n seems to be off
in its own pure Python file with a true Python generator.

Suggestions on the nature of a fix (ie the "right" way to do this)
would be appreciated.

Thanks,
Rob

Martin Albrecht

unread,
Oct 31, 2009, 8:11:59 PM10/31/09
to sage-...@googlegroups.com
FiniteField_givaro_iterator should have an __iter__() function which just
returns itself:

def __iter__(self):
return self

This fixes the problem, see:

http://trac.sagemath.org/sage_trac/ticket/7366

Cheers,
Martin

--
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF
_www: http://www.informatik.uni-bremen.de/~malb
_jab: martinr...@jabber.ccc.de

Rob Beezer

unread,
Oct 31, 2009, 8:23:25 PM10/31/09
to sage-devel
Thanks, Martin! That was simple. ;-)

I'll give the patch a review later this evening.

Rob

On Oct 31, 5:11 pm, Martin Albrecht <m...@informatik.uni-bremen.de>
wrote:
> _jab: martinralbre...@jabber.ccc.de

YannLC

unread,
Nov 1, 2009, 10:10:01 AM11/1/09
to sage-devel
Nice, but I think Givaro fields were not the only ones broken:

K = Loading Sage library. Current Mercurial branch is: minpoly
sage: K.<a> = GF(17^5)
sage: K.list()
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
...
TypeError: 'sage.rings.ring.FiniteFieldIterator' object is not
iterable

Rob Beezer

unread,
Nov 1, 2009, 7:08:23 PM11/1/09
to sage-devel
Reply all
Reply to author
Forward
0 new messages