NOTE: This notebook conains some old fragments referring to GWFrames.Wigner3jSingleton, which was a complicated singleton that allowed me to just evaluate all the Wigner 3-j symbols once, store them, and retrieve them (memoization). As implemented, this was actually a bit slower than direct evaluation. Even worse, it seemed to be wrong for many combinations. Therefore, I have removed the singleton object.


In [1]:
import sys
from sympy import N
from sympy.physics.wigner import wigner_3j
from SphericalFunctions import Wigner3j

In [2]:
%timeit Wigner3j(14,5,10,-11,3,8)


1000000 loops, best of 3: 512 ns per loop

In [3]:
Wigner3j(3,4,1,-3,-4,0)


Out[3]:
0.0

In [4]:
from math import isnan
ellMax=16
for j_1 in range(ellMax+1):
    for m_1 in range(-j_1,j_1+1):
        for j_2 in range(ellMax+1):
            for m_2 in range(-j_2,j_2+1):
                m_3 = -m_1-m_2
                for j_3 in range(abs(j_1-j_2),min((j_1+j_2),ellMax)+1):
                    if(abs(m_3)>j_3):
                        continue
                    a=Wigner3j(j_1,j_2,j_3,m_1,m_2,m_3)
                    if(isnan(a)):
                        print(j_1,j_2,j_3,m_1,m_2,m_3)

In [ ]:


In [ ]:


In [7]:
%%time
ellMax=16
for j_1 in range(ellMax+1):
    for m_1 in range(-j_1,j_1+1):
        for j_2 in range(ellMax+1):
            for m_2 in range(-j_2,j_2+1):
                m_3 = -m_1-m_2
                for j_3 in range(max(abs(m_3),abs(j_1-j_2)),min((j_1+j_2),ellMax)+1):
                    a=Wigner3j(j_1,j_2,j_3,m_1,m_2,m_3)


CPU times: user 1.83 s, sys: 9.52 ms, total: 1.84 s
Wall time: 1.87 s
%%time for j_1 in range(ellMax+1): for m_1 in range(-j_1,j_1+1): for j_2 in range(ellMax+1): for m_2 in range(-j_2,j_2+1): m_3 = -m_1-m_2 for j_3 in range(max(abs(m_3),abs(j_1-j_2)),min((j_1+j_2),ellMax)+1): a=Wigner3j(j_1,j_2,j_3,m_1,m_2,m_3)

In [ ]:


In [ ]:

%%time i=0 i_bad=0 ellMax=4 for j_1 in range(ellMax+1): for m_1 in range(-j_1,j_1+1): for j_2 in range(ellMax+1): for m_2 in range(-j_2,j_2+1): m_3 = -m_1-m_2 for j_3 in range(max(abs(m_3),abs(j_1-j_2)),min((j_1+j_2),ellMax)+1): i = i+1 a,b = Wigner_3j(j_1,j_2,j_3,m_1,m_2,m_3),Wigner3j(j_1,j_2,j_3,m_1,m_2,m_3) if(abs(a-b)>1e-12*abs(a+b) and abs(a+b)>1e-12): print(j_1,j_2,j_3,m_1,m_2,m_3,a,b) sys.stdout.flush() i_bad=i_bad+1 print(i,i_bad)

In [ ]:
%%time
ellMax=12
i=0
i_bad=0
for j_1 in range(ellMax+1):
    for m_1 in range(-j_1,j_1+1):
        for j_2 in range(ellMax+1):
            for m_2 in range(-j_2,j_2+1):
                m_3 = -m_1-m_2
                for j_3 in range(max(abs(m_3),abs(j_1-j_2)),min((j_1+j_2),ellMax)+1):
                    i = i+1
                    a,b = N(wigner_3j(j_1,j_2,j_3,m_1,m_2,m_3)),Wigner_3j(j_1,j_2,j_3,m_1,m_2,m_3)
                    if(abs(a-b)>1e-12*abs(a+b) and abs(a+b)>1e-12):
                        print(j_1,j_2,j_3,m_1,m_2,m_3,a,b)
                        sys.stdout.flush()
                        i_bad=i_bad+1
print(i,i_bad)

In [8]:
2.34/1419857


Out[8]:
1.6480532898735576e-06

In [ ]:

Summations


In [10]:
from sympy import summation, simplify, expand, horner, symbols, N

In [2]:
L,X,T,B,S,l,x,t,b,s,Lmax = symbols('L,X,T,B,S,l,x,t,b,s,Lmax', integer=True)

In [9]:
horner(simplify((L*(24+L*(50+L*(35+L*(10+L))))/120).subs({L:L+1}).expand())*120)


Out[9]:
L*(L*(L*(L*(L + 15) + 85) + 225) + 274) + 120

In [11]:
N((L*(24+L*(50+L*(35+L*(10+L))))/120).subs({L:16}))


Out[11]:
15504.0000000000

In [12]:
N((L*(274+L*(225+L*(85+L*(15+L))))/120+1).subs(L,16))


Out[12]:
20349.0000000000

In [13]:
N((L*(274+L*(225+L*(85+L*(15+L))))/120+1).subs(L,32))


Out[13]:
435897.000000000

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: