def test_racah(): assert racah(3, 3, 3, 3, 3, 3) == Rational(-1, 14) assert racah(2, 2, 2, 2, 2, 2) == Rational(-3, 70) assert racah(7, 8, 7, 1, 7, 7, prec=4).is_Float assert racah(5.5, 7.5, 9.5, 6.5, 8, 9) == -719 * sqrt(598) / 1158924 assert abs(racah(5.5, 7.5, 9.5, 6.5, 8, 9, prec=4) - (-0.01517)) < S('1e-4')
def safe_racah(a, b, c, d, ee, ff): """ Avoid the ValueError whenever the arguments don't fulfill the triangle relation. """ try: return float(racah(a, b, c, d, ee, ff, prec=None)) except ValueError or AttributeError: return 0
def F(k, jf, l1, l2, ji): verbose = False # cg_coeff_homebrew = float(clebsch_gordan(l1, 1, l2, -1, k, 0)) # works, but takes arguments in different order compared to the sympy version cg_coeff = float(wg.clebsch_gordan(l1, l2, k, 1, -1, 0)) if cg_coeff == 0: return 0 w = float(wg.racah(ji, ji, l1, l2, k, jf)) # w = racah_w(ji, ji, l1, l2, k, jf) # returning strange values if w == 0: return 0 if verbose: print(f'GC: {cg_coeff} W: {w}') return pow( (-1), (jf - ji - 1)) * (pow((2 * l1 + 1) * (2 * l2 + 1) * (2 * ji + 1), (1.0 / 2.0))) * cg_coeff * w
def BM_Bracket00(n,l,N,L, l1,l2, lamda): # Limit of the recurrence relation const = ((fact[l1] + fact[l2] + fact[n+l] + fact[N+L]) - (fact[2*l1] + fact[2*l2] + fact[n] + fact[N] + fact[2*(n+l)+1] + fact[2*(N+L)+1])) const += ((np.log(2*l+1)+np.log(2*L+1)) - ((l+L)*np.log(2))) aux_sum = 0. major = min((l+l1),(L+l2)) minor = max(abs(l-l1),abs(L-l2)) for x in range(minor, major+1): try: racah_aux = racah(l,L,l1,l2, lamda,x).evalf() except AttributeError: racah_aux = 0 aux_sum += ((2*x+1)*A_coeff(l1,l,l2,L, x)*racah_aux) return np.exp(0.5*const) * aux_sum * ((-1)**(n+l+L-lamda))
def matrix_r2(n,l,N,L, n_q,l_q,N_q,L_q, lamda): if((n_q<0) or (l_q<0) or (N_q<0) or(L_q<0)): return 0 if(n_q == (n-1)): # relations 1,3,4 if(l_q == l): if(N_q == N): if(L_q == L): # rel 1 return 0.5*np.sqrt(n*(n+l+0.5)) else: return 0 else: return 0 elif(l_q == (l+1)): if(N_q == (N-1)): if(L_q == (L+1)): # rel 3 try: racah_aux = (racah(l,(l+1),L,(L+1),1,lamda)).evalf() except AttributeError: racah_aux = 0 return (((-1)**(lamda+L+l))* np.sqrt(n*N*(l+1)*(L+1)) * racah_aux) else: return 0 elif(N_q == N): if(L_q == (L-1)): # rel 4 try: racah_aux = (racah(l,(l+1),L,(L-1),1,lamda)).evalf() except AttributeError: racah_aux = 0 return (((-1)**(lamda+L+l))* np.sqrt(n*L*(l+1)*(N+L+0.5)) * racah_aux) else: return 0 else: return 0 else: return 0 elif(n_q == n): # relations 2,5,6 if(l_q == (l-1)): if(N_q == (N-1)): if(L_q == (L+1)): # rel 5 try: racah_aux = (racah(l,(l-1),L,(L+1),1,lamda)).evalf() except AttributeError: racah_aux = 0 return (((-1)**(lamda+L+l))* np.sqrt(N*l*(n+l+0.5)*(L+1))*racah_aux) else: return 0 elif(N_q == N): if(L_q == (L-1)): # rel 6 try: racah_aux = (racah(l,(l-1),L,(L-1),1,lamda)).evalf() except AttributeError: racah_aux = 0 return (((-1)**(lamda+L+l))* np.sqrt(L*l*(n+l+0.5)*(N+L+0.5))*racah_aux) else: return 0 else: return 0 elif(l_q == l): if(N_q == (N-1)): if(L_q == L): # rel 2 return 0.5*np.sqrt(N*(N+L+0.5)) else: return 0 else: return 0 else: return 0 else: return 0 return ValueError
def test_racah(): assert racah(3,3,3,3,3,3) == Rational(-1,14) assert racah(2,2,2,2,2,2) == Rational(-3,70) assert racah(7,8,7,1,7,7, prec=4).is_Float assert racah(5.5,7.5,9.5,6.5,8,9) == -719*sqrt(598)/1158924 assert abs(racah(5.5,7.5,9.5,6.5,8,9, prec=4) - (-0.01517)) < S('1e-4')