On Tue, Sep 15, 2009 at 11:38 AM, Robert Bradshaw
<rober...@math.washington.edu> wrote:
> On Sep 15, 2009, at 11:28 AM, William Stein wrote:
>
>> You might have some thought about this... at least I think it might be
>> caused by your optimizations to [a..b].  This is really a question from ccr,
>> by the way...
>>
>> Forwarded conversation
>> Subject: [sage-support] sxrange / xsrange possible bug
>> ------------------------
>>
>> From: Mariah Lenox <mariah.le...@gmail.com>
>> Date: Tue, Sep 15, 2009 at 10:53 AM
>> To: sage-support@googlegroups.com
>>
>>
>>
>> Perhaps I do not understand sxrange / xsrange correctly.  The
>> reference manual entries for them seem to be similar.  Is
>> there a difference?  (If one is just an alias for the other,
>> it would be best to say so. If they are different, the reference
>> manual needs to emphasize the difference.)
>
> sage: xsrange is sxrange
>  True
>
>> Also the reference manual entry for
>>
>>   sage.misc.misc.sxrange
>>
>> has the note
>>
>> : This function is called xsrange to distinguish it from the builtin
>> Python xrange command.
>>
>> Should it say "sxrange" rather than "xsrange"?
>>
>> Finally here is my attempt to use sxrange (xsrange
>> gives similar output):
>>
>> e = 1
>> while true:
>>  print Integer(10^e)
>>  for i in sxrange(Integer(2),Integer(10^e)):
>>   if i == 3:
>>     break
>>  e += 1
>>
>> gives
>>
>> 10
>> 100
>> 1000
>> 10000
>> 100000
>> 1000000
>> 10000000
>> 100000000
>> 1000000000
>> 10000000000
>> 100000000000
>> 1000000000000
>> 10000000000000
>> 100000000000000
>> 1000000000000000
>> 10000000000000000
>> 100000000000000000
>> 1000000000000000000
>> 10000000000000000000
>> Traceback (most recent call last):
>>  File "zzzbug.py", line 7, in <module>
>>   for i in sxrange(Integer(_sage_const_2 ),Integer(_sage_const_10 **e)):
>>  File
>> "/home/mariah/sage/sage-4.1.1-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/misc/misc.py",
>> line 1059, in generic_xsrange
>>   for k in xrange(icount):
>> OverflowError: long int too large to convert to int
>
> This is because we use the Python xrange under the hood, which can't handle
> anything that big... It should probably be re-written to be an (optimized)
> while loop.
>
>> I really want an iterator for the "for i in ..." loop.
>>
>> Is this a bug?   Is there a better way to do what I want?
>
> How about
>
> sage: for a in (1..):

Using your ellipsis implementation does not actually work to fix the
problem that she had, much to my surprise:

sage: e = 1
sage: while true:
...    print Integer(10^e)
...    for i in (2..10^e):
...      if i == 3:
...        break
...    e += 1
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000
10000000000
100000000000
1000000000000
10000000000000
100000000000000
1000000000000000
10000000000000000
100000000000000000
1000000000000000000
10000000000000000000
Traceback (most recent call last):       if i == 3:
  File "", line 3, in <module>

  File 
"/Users/wstein/sage/build/64bit/sage/local/lib/python2.6/site-packages/sage/misc/misc.py",
line 1319, in ellipsis_iter
    first = more.next()
  File 
"/Users/wstein/sage/build/64bit/sage/local/lib/python2.6/site-packages/sage/misc/misc.py",
line 1059, in generic_xsrange
    for k in xrange(icount):
OverflowError: long int too large to convert to int




>   ...:     print a
>   ...:     if a > 100: break
>   ...:
> 1
> 2
> 3
> 4
> 5
> [...]
> 101
>
> - Robert
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to