1 | initial version |
Hi!
7-8 times out of 10 in Sage you don't want to use range, which is a Python function, and returns Python ints. All the fun stuff lives in the Sage Integer type, and only some functions coerce. You can get a Sage Integer by using srange/sxrange instead of range/xrange:
sage: map(type, range(2))
[<type 'int'>, <type 'int'>]
sage: map(type, srange(2))
[<type 'sage.rings.integer.Integer'>, <type 'sage.rings.integer.Integer'>]
sage: int(2).mod(4)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[...]
AttributeError: 'int' object has no attribute 'mod'
sage: Integer(2).mod(4)
2
so that
z = var("z")
maxdeg = 5
maxord = maxdeg
for m in srange(maxord + 1):
for l in srange(m, maxdeg + 1):
print l, m, gen_legendre_P(l, m, z)
produces
0 0 1
1 0 z
2 0 3/2*(z - 1)^2 + 3*z - 2
3 0 5/2*(z - 1)^3 + 15/2*(z - 1)^2 + 6*z - 5
4 0 35/8*(z - 1)^4 + 35/2*(z - 1)^3 + 45/2*(z - 1)^2 + 10*z - 9
5 0 63/8*(z - 1)^5 + 315/8*(z - 1)^4 + 70*(z - 1)^3 + 105/2*(z - 1)^2 + 15*z - 14
[.. etc]