On Fri, Oct 30, 2009 at 2:54 AM, Dirk <[email protected]> wrote:
>
> Before trying the code below, open a system monitor window showing CPU
> and memory use.
>
> $ sage
> ----------------------------------------------------------------------
> | Sage Version 4.1.1, Release Date: 2009-08-14 |
> | Type notebook() for the GUI, and license() for information. |
> ----------------------------------------------------------------------
> sage: t=pari('t'); s=1+t+t^2
> sage: list(s.Vec())
> [1, 1, 1]
> sage: list(s)
> ^C---------------------------------------------------------------------------
> KeyboardInterrupt Traceback (most recent call
> last)
If there is no __iter__ method, then I think Python's "list" method
just calls __getitem__ with input 0, 1, 2, 3, etc., until it hits an
exception. The semantics of Pari's getitem for polynomials are
established I think by polcoeff, which returns 0 for coefficients
above the degree:
? polcoeff(1+t+t^2,100)
%1 = 0
So
sage: t=pari('t'); s=1+t+t^2
sage: s[10]
0
sage: s[100]
0
And notice that there is no __iter__ method.
sage: s.__iter__
---------------------------------------------------------------------------
AttributeError
Thus the fix is easy -- just implement an __iter__ method for every
possible Pari object (well just do a few for starters), by adding code
to SAGE_ROOT/devel/sage/sage/libs/gen.pyx
Thanks,
-- William
>
> /home/dirk/.sage/temp/rondloper/29109/_home_dirk__sage_init_sage_0.py
> in <module>()
>
> /opt/sage/local/lib/python2.6/site-packages/sage/libs/pari/gen.so in
> sage.libs.pari.gen.gen.__getitem__ (sage/libs/pari/gen.c:6324)()
>
> KeyboardInterrupt:
>
>
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---