def xi(i): """ xi = xi(i) xi is a function that returns the independent basis for Lie algebra su(2)\equiv su(2,\mathbb{C}) of Lie group SU(2) of traceless anti-Hermitian matrices, based on msigma of sympy cf. http://docs.sympy.org/dev/_modules/sympy/physics/matrices.html#msigma """ if i not in [1,2,3]: raise IndexError("Invalid Pauli index") elif i==1: return I/Rat(2)*msigma(1) elif i==2: return -I/Rat(2)*msigma(2) elif i==3: return I/Rat(2)*msigma(3)
def test_Pauli(): #this and the following test are testing both Pauli and Dirac matrices #and also that the general Matrix class works correctly in a real world #situation sigma1 = msigma(1) sigma2 = msigma(2) sigma3 = msigma(3) assert sigma1 == sigma1 assert sigma1 != sigma2 # sigma*I -> I*sigma (see #354) assert sigma1*sigma2 == sigma3*I assert sigma3*sigma1 == sigma2*I assert sigma2*sigma3 == sigma1*I assert sigma1*sigma1 == eye(2) assert sigma2*sigma2 == eye(2) assert sigma3*sigma3 == eye(2) assert sigma1*2*sigma1 == 2*eye(2) assert sigma1*sigma3*sigma1 == -sigma3
def __init__(self, nY): self.H_0 = (C - float(4) * tD) * (I_2 | kron | I_2) + ( M - float(4) * tB) * (I_2 | kron | msigma(3)) #I*A/a*((msigma(3)|kron|msigma(1))-(I_2|kron|msigma(2))) #I*R_0/a*(TensorProduct(msigma(2),(msigma(3)+I_2)/2)-TensorProduct(msigma(1),(msigma(3)+I_2)/2)) self.V_0 = +(tD) * (I_2 | kron | I_2) + (tB) * ( I_2 | kron | msigma(3)) - I * tA * (I_2 | kron | msigma(2)) #I*R_0/a*TensorProduct(msigma(1),(msigma(3)+I_2)/2) self.W_0d = +(tD) * (I_2 | kron | I_2) + (tB) * (I_2 | kron | msigma(3)) self.W_0off = -I * tA * (msigma(3) | kron | msigma(1)) #I*A/(2*a)*(msigma(3)|kron|msigma(1)) #I*R_0/a*TensorProduct(msigma(2),(msigma(3)+I_2)/2) self.IdDown = Matrix(nY, nY, lambda i, j: int(i - j == 1)) self.IdUp = Matrix(nY, nY, lambda i, j: int(i - j == -1)) self.Id = Matrix(nY, nY, lambda i, j: int(i == j))
from sympy.physics.paulialgebra import Pauli, evaluate_pauli_product from sympy.physics.matrices import mdft, mgamma, msigma, pat_matrix mdft(4) # expression of discrete Fourier transform as a matrix multiplication mgamma(2) # Dirac gamma matrix in the Dirac representation msigma(2) # Pauli matrix with (1,2,3) pat_matrix(3, 1, 0, 0) # computer Parallel Axis Theorem matrix to translate the inertia matrix a distance of dx, dy, dz for a body of mass m. evaluate_pauli_product(4*x*Pauli(3)*Pauli(2))
from sympy import * from sympy.physics.quantum import Operator from sympy.physics.matrices import Matrix, msigma from sympy.functions.special.tensor_functions import LeviCivita x_mu=Matrix([Symbol('x'+str(i)) for i in range(3)]) epsilon_bubu=Matrix([[0,1],[-1,0]]) epsilon_blbl=Matrix([[0,-1],[1,0]]) gamma_au=[msigma(3),-1*msigma(1),-1*msigma(2)] gamma_al=gamma_au e_mlau=Matrix([[Function('e'+str(i)+str(j))(*x_mu) for i in range(3)] for j in range(3)]) #e_almu=Matrix([[Function('ei'+str(i)+str(j))(*x_mu) for i in range(3)] for j in range(3)]) e_almu=e_mlau.inv().applyfunc(simplify) epsilon_auauau=[[[LeviCivita(i,j,k) for k in range(3)] for j in range(3)] for i in range(3)] epsilon_alalal=epsilon_auauau epsilon_mumumu=[[[sum([sum([sum([e_almu[d1,i]*e_almu[d2,j]*e_almu[d3,k]*epsilon_auauau[d1][d2][d3] for d3 in range(3)]) for d2 in range(3)]) for d1 in range(3)]) for k in range(3)] for j in range(3)] for i in range(3)] epsilon_mlmlml=[[[sum([sum([sum([e_mlau[i,d1]*e_mlau[j,d2]*e_mlau[k,d3]*epsilon_alalal[d1][d2][d3] for d3 in range(3)]) for d2 in range(3)]) for d1 in range(3)]) for k in range(3)] for j in range(3)] for i in range(3)] gamma_mu=[MatAdd(*[e_almu[d,i]*gamma_au[d] for d in range(3)]).doit() for i in range(3)] gamma_ml=[MatAdd(*[e_mlau[i,d]*gamma_al[d] for d in range(3)]).doit() for i in range(3)] #g_mlml=(e_mlau*e_mlau.T).applyfunc(simplify) g_mlml=(e_mlau*e_mlau.T) #g_mumu=(e_almu.T*e_almu).applyfunc(simplify) g_mumu=(e_almu.T*e_almu) Chris_mumlml=[[[sum([Rational(1,2)*g_mumu[i,d]*(g_mlml[d,k].diff(x_mu[j]) + g_mlml[d,j].diff(x_mu[k]) - g_mlml[j,k].diff(x_mu[d])) for d in range(3)]) for k in range(3)] for j in range(3)] for i in range(3)]
from sympy.physics.paulialgebra import Pauli, evaluate_pauli_product from sympy.physics.matrices import mdft, mgamma, msigma, pat_matrix mdft(4) # expression of discrete Fourier transform as a matrix multiplication mgamma(2) # Dirac gamma matrix in the Dirac representation msigma(2) # Pauli matrix with (1,2,3) pat_matrix( 3, 1, 0, 0 ) # computer Parallel Axis Theorem matrix to translate the inertia matrix a distance of dx, dy, dz for a body of mass m. evaluate_pauli_product(4 * x * Pauli(3) * Pauli(2))
from kwant.continuum._common import position_operators, momentum_operators from kwant.continuum._common import make_commutative, sympify from kwant.continuum._common import monomials from kwant.continuum._common import lambdify com_A, com_B, com_C = sympy.symbols('A B C') fA, fB, fC = sympy.symbols('A B C', cls=sympy.Function) x_op, y_op, z_op = position_operators kx, ky, kz = momentum_operators @pytest.mark.parametrize( 'input_expr, output_expr', [('k_x * A(x) * k_x', kx * fA(x_op) * kx), ('[[k_x * A(x) * k_x]]', sympy.Matrix([kx * fA(x_op) * kx])), ('k_x * sigma_y + k_y * sigma_x', kx * msigma(2) + ky * msigma(1)), ('[[k_x*A(x)*k_x, B(x, y)*k_x], [k_x*B(x, y), C*k_y**2]]', sympy.Matrix([[kx * fA(x_op) * kx, fB(x_op, y_op) * kx], [kx * fB(x_op, y_op), com_C * ky**2]])), ('kron(sigma_x, sigma_y)', TensorProduct(msigma(1), msigma(2))), ('identity(2)', sympy.eye(2)), ('eye(2)', sympy.eye(2)), ('1 * sigma_x + 2 * sigma_y + 3 * sigma_z', msigma(1) + 2 * msigma(2) + 3 * msigma(3))]) def test_sympify(input_expr, output_expr): assert sympify(input_expr) == output_expr assert sympify(sympify(input_expr)) == output_expr @pytest.mark.parametrize('input_expr, output_expr, subs', [ ('k_x', kx + ky, {
return I/Rat(2)*msigma(3) ## check anti-Hermitian property and commutation relations with xi # xi is indeed anti-Hermitian xi(1) == -xi(1).adjoint() # True xi(2) == -xi(2).adjoint() # True xi(3) == -xi(3).adjoint() # True # xi obeys the commutation relations for i,j in product([1,2,3],repeat=2): print i,j for i,j in product([1,2,3],repeat=2): print i,j, "\t Commutator: ", commute(xi(i),xi(j)) ## check traceless Hermitian property and commutation relations with Pauli matrices # Pauli matrices i.e. msigam is indeed traceless Hermitian msigma(1) == msigma(1).adjoint() # True msigma(2) == msigma(2).adjoint() # True msigma(3) == msigma(3).adjoint() # True msigma(1).trace() == 0 # True msigma(2).trace() == 0 # True msigma(3).trace() == 0 # True # Pauli matrices obey commutation relation print "For Pauli matrices, the commutation relations are :\n" for i,j in product([1,2,3],repeat=2): print i,j, "\t Commutator: ", commute(msigma(i),msigma(j)) for i,j,k in permutations([1,2,3],3): print "Commute: ", i,j,k, msigma(i), msigma(j), ": and is 2*i of ", msigma(k), commute(msigma(i),msigma(j)) == 2*I*msigma(k)*LeviCivita(i,j,k)
from kwant.continuum._common import position_operators, momentum_operators from kwant.continuum._common import make_commutative, sympify from kwant.continuum._common import monomials from kwant.continuum._common import lambdify com_A, com_B, com_C = sympy.symbols('A B C') x_op, y_op, z_op = position_operators kx, ky, kz = momentum_operators @pytest.mark.parametrize('input_expr, output_expr', [ ('k_x * A(x) * k_x', kx * com_A(x_op) * kx), ('[[k_x * A(x) * k_x]]', sympy.Matrix([kx * com_A(x_op) * kx])), ('k_x * sigma_y + k_y * sigma_x', kx * msigma(2) + ky * msigma(1)), ('[[k_x*A(x)*k_x, B(x, y)*k_x], [k_x*B(x, y), C*k_y**2]]', sympy.Matrix([[kx*com_A(x_op)*kx, com_B(x_op, y_op)*kx], [kx*com_B(x_op, y_op), com_C*ky**2]])), ('kron(sigma_x, sigma_y)', TensorProduct(msigma(1), msigma(2))), ('identity(2)', sympy.eye(2)), ('eye(2)', sympy.eye(2)), ('1 * sigma_x + 2 * sigma_y + 3 * sigma_z', msigma(1) + 2 * msigma(2) + 3 * msigma(3)) ]) def test_sympify(input_expr, output_expr): assert sympify(input_expr) == output_expr assert sympify(sympify(input_expr)) == output_expr @pytest.mark.parametrize('input_expr, output_expr, subs', [