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
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?
--
Mariah
The file misc.py has this line:
sxrange = xsrange
Any chance you could post a patch with a statement that they are
aliases added to the docs?
Yes, I think that is a bug given the point of xrange, caused by an optimization.
> Is there a better way to do what I want?
Here is a way to do what you want:
e = 1
while true:
print Integer(10^e)
i = Integer(2)
while i < Integer(10^e):
if i == 3:
break
print type(i)
i += 1
e += 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
Yes, you can put an .hgrc file in your home directory.
- Robert
Thanks,
-d
On that new thread :), can you give an example of exactly what you
mean, i.e., give the output you want and describe what you have for input?
I think this will be very easy to do, but we have to see exactly what
you mean. For example, for a list:
f(x)=cos(x)-x
values=[(i, n(f(i))) for i in [0..2*pi,step=0.1]]
print values
or for a pretty output:
html.table(values)
Jason
Try:
f(x)=(e^(2*x) - 1)/(x)
[n(f(i)) for i in [.1, .01, .001, .0001]]
Jason
sage: f(x) = (e^(2*x)-1)/x
sage: for t in [1..10]:
print 10^-t, f(10^-t).n()
1/10 2.21402758160170
1/100 2.02013400267558
1/1000 2.00200133400028
1/10000 2.00020001333542
1/100000 2.00002000012319
1/1000000 2.00000200001523
1/10000000 2.00000020116568
1/100000000 2.00000001490116
1/1000000000 2.00000000000000
1/10000000000 2.00000000000000
You should definitely check out the Mercurial website, if you haven't
already: http://www.selenic.com/mercurial/ and also the Mercurial book:
http://hgbook.red-bean.com/
You sound like you're pretty comfortable with the basic diff and patch
utilities, so I'm sure you'll figure out Mercurial very quickly.
Dan
--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------