Why do the following bits of code give different outputs? (Note the use of Integer() for the second example):

from sage.functions.wigner import gaunt as gauntsage

for l1, l2, l3, m1, m2, m3 in [(l1, l2, l3, m1, m2, m3) for l1 in range(0,2) for l2 in range(0,2) for l3 in range(0,2)     for m1 in range(-3,4) for m2 in range(-3,4) for m3 in range(-3,4)]:
g = gauntsage(l1, l2, l3, m1, m2, m3)

if abs(g) > 1e-12:
print "    GC_table(%d,%d,%d,%d,%d,%d) = %.12f_dp ! %s" % (l1, m1, l2, m2, l3, m3, g, repr(g))


outputs

GC_table(0,0,0,0,0,0) = 0.282094791774_dp ! 1/2/sqrt(pi)
GC_table(0,0,1,-1,1,1) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(0,0,1,0,1,0) = 0.282094791774_dp ! 1/2/sqrt(pi)
GC_table(0,0,1,1,1,-1) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(1,-1,0,0,1,1) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(1,0,0,0,1,0) = 0.282094791774_dp ! 1/2/sqrt(pi)
GC_table(1,1,0,0,1,-1) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(1,-1,1,1,0,0) = -0.282094791774_dp ! -0.5/sqrt(pi)
GC_table(1,0,1,0,0,0) = 0.282094791774_dp ! 1/2/sqrt(pi)
GC_table(1,1,1,-1,0,0) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(1,-1,1,0,1,1) = 0.488602511903_dp ! 1/2*sqrt(3)/sqrt(pi)
GC_table(1,-1,1,1,1,0) = -0.488602511903_dp ! -1/2*sqrt(3)/sqrt(pi)
GC_table(1,0,1,-1,1,1) = -0.488602511903_dp ! -1/2*sqrt(3)/sqrt(pi)
GC_table(1,0,1,1,1,-1) = 0.488602511903_dp ! 1/2*sqrt(3)/sqrt(pi)
GC_table(1,1,1,-1,1,0) = 0.488602511903_dp ! 1/2*sqrt(3)/sqrt(pi)
GC_table(1,1,1,0,1,-1) = -0.488602511903_dp ! -1/2*sqrt(3)/sqrt(pi)


and

from sage.functions.wigner import gaunt as gauntsage

for l1, l2, l3, m1, m2, m3 in [(Integer(l1), Integer(l2), Integer(l3), Integer(m1), Integer(m2), Integer(m3)) for l1 in range(0,2) for l2 in range(0,2) for l3 in range(0,2)     for m1 in range(-3,4) for m2 in range(-3,4) for m3 in range(-3,4)]:
g = gauntsage(l1, l2, l3, m1, m2, m3)

if abs(g) > 1e-12:
print "    GC_table(%d,%d,%d,%d,%d,%d) = %.12f_dp ! %s" % (l1, m1, l2, m2, l3, m3, g, repr(g))


outputs

GC_table(0,0,0,0,0,0) = 0.282094791774_dp ! 1/2/sqrt(pi)
GC_table(0,0,1,-1,1,1) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(0,0,1,0,1,0) = 0.282094791774_dp ! 1/2/sqrt(pi)
GC_table(0,0,1,1,1,-1) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(1,-1,0,0,1,1) = -0.282094791774_dp ! -1/2/sqrt(pi)
GC_table(1,0,0,0,1,0) = 0.282094791774_dp ...
edit retag close merge delete

Sort by ยป oldest newest most voted

Definitely some kind of bug.

sage: gaunt(1,1,1,0,1,-1)
0
sage: gaunt(int(1),int(1),int(1),int(0),int(1),int(-1))
1/2*sqrt(3)/sqrt(pi)


(Notice you don't have to actually import it to use it.)

The problem is that there is some division going on that doesn't check types.

bigL = (l_1 + l_2 + l_3) / 2


and

sage: (int(1)+int(1)+int(1))/int(2)
1
sage: (1+1+1)/2
3/2


For now you can get around this by using srange (Sage range, as it were):

sage: type(range(0,2)[0])
int
sage: type(srange(0,2)[0])
sage.rings.integer.Integer


This is now ticket 14735.

more

Ok, thanks! It did seem odd and wasn't expected behaviour, but I wasn't sure if it was just a known caveat for sage.

( 2013-06-12 12:56:29 +0200 )edit