Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

range, xrange and ellipsis iteration.

Consider the Maple lines

r := n -> (n-(n mod 2))/2:
seq(print(seq(r(n-k) + r(n+k), k = -n..n)), n=0..5);

Output:

               0
            1, 0, 1
         2, 1, 2, 1, 2
      3, 2, 3, 2, 3, 2, 3
   4, 3, 4, 3, 4, 3, 4, 3, 4
5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5

I thought that the Sage equivalent is

r = lambda n: (n-(n%2))//2
for n in range(6):
    [r(n-k) + r(n+k) for k in (-n..n)]

Unfortunately this is not the case. I get

"AttributeError: 'xrange' object has no attribute 'next'".

Is this a bug or a feature?

range, xrange and ellipsis iteration.

Consider the Maple lines

r := n -> (n-(n mod 2))/2:
seq(print(seq(r(n-k) + r(n+k), k = -n..n)), n=0..5);

Output:

               0
            1, 0, 1
         2, 1, 2, 1, 2
      3, 2, 3, 2, 3, 2, 3
   4, 3, 4, 3, 4, 3, 4, 3, 4
5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5

I thought that the Sage equivalent is

r = lambda n: (n-(n%2))//2
for n in range(6):
    [r(n-k) + r(n+k) for k in (-n..n)]

Unfortunately this is not the case. I get

"AttributeError: 'xrange' object has no attribute 'next'".

Is this a bug or a feature?

range, xrange and ellipsis iteration.

Consider the Maple lines

r := n -> (n-(n mod 2))/2:
seq(print(seq(r(n-k) + r(n+k), k = -n..n)), n=0..5);

Output:

               0
            1, 0, 1
         2, 1, 2, 1, 2
      3, 2, 3, 2, 3, 2, 3
   4, 3, 4, 3, 4, 3, 4, 3, 4
5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5

I thought that the Sage equivalent is

r = lambda n: (n-(n%2))//2
for n in range(6):
    [r(n-k) + r(n+k) for k in (-n..n)]

Unfortunately this is not the case. I get

"AttributeError: 'xrange' object has no attribute 'next'".

Is this a bug or a feature?