Help to understand an AttributeError in a polynomial ring
F. Chapoton recently wrote a program the behaviour of which I do not understand.
def fermat(n):
q = polygen(ZZ, 'q')
return sum(n ** j * binomial(n, j) * (-1) ** (i + n + j) *
binomial(n - 2 - j + 1, i + 1) * q ** i
for j in range(n - 1)
for i in range(n - 1 - j))
Now consider:
v = fermat(5)
print v.parent()
print v.list()
This outputs
Univariate Polynomial Ring in q over Integer Ring
[821, 181, 21, 1]
which is fine. However the loop
for n in (1..9):
v = fermat(n)
print v.parent()
print v.list()
gives the errors:
AttributeError: 'int' object has no attribute 'parent'
AttributeError: 'int' object has no attribute 'list'
What happens here?
For n=1, the sum is empty and by default this gives a python int. That is because I simplified my program for oeis. If you care, you need to add R=q.parent() and then use R.sum(...)
Thanks Frédéric. If you write your comment as an answer I will accept it. So all this has nothing to do with the preparser or range formats as suggested in kcrisman's answer.