My go-to programming language for studying tensor states and interacting many-body spin systems used to be octave because of the intuitive way in which it handles tensor products, but I have found that julia is even closer to the way in which physicists work on paper with tensor states.
Tensors and tensor products
We represent spin objects as either kets or with a vector space column
matrix that is a smultaneous eigenstate of and : in units with
The basis of the space of spin- wavefunctions is therefore
since
and
In julia we will represent these as
# "B" is for basis...
B=[[1;0],[0;1]]
# ie B[1]=[1;0]=|1/2,1/2> and B[2]=[0;1]=|1/2,-1/2>
Projection operators in julia. Transpose (hermitian conjugate for real arrays) is denoted with a prime, so we can make a progection operator this way:
# first look at B[1]'
B[1]'
# 1x2 adjoint(::Vector{Int64}) with eltype Int64:
# 1 0
# projector
P=B[1]*B[1]'
P
#2x2 Matrix{Int64}:
# 1 0
# 0 0
psi=[2;3]
P*psi
#2-element Vector{Int64}:
# 2
# 0
What about inner products?
B[1]'*B[1]
# 1 as expected, the scalar <u(1)|u(1)>
so you can see that the way julia handles kets (vectors) is exactly the way physics do.
Tensors and tensor products are handled using the Kronecker package. In a multi particle system we can use the uncoupled tensor product basis
and the same for operators
and so forth. Basic rules for tensor products: let be a basis for the first slot, a basis for the second slot
because and scalars can pass through tensor products. This is a vector in the “A” space.
This is a vector in the “B” space.
which is a scalar.
How are these done in julia? After defining vectors and a unit matrix
# make a vector in each space
A=[1;2]
B=[1;-1]
# create basis "a" for the first slot and "b" for the second
a=[[1;0],[0;1]]
b=[[1/sqrt(2);1/sqrt(2)],[-1/sqrt(2);1/sqrt(2)]]
One=[1 0; 0 1]
# project the second slot
(One⊗b[1]')*(A⊗B)
# 0.0
# 0.0
# since you can see that B is in the b[2] state
(a[1]'⊗ One)*(A⊗ B)
Density matrices
Let’s construct the Hamiltonian
H=real.(sx⊗sx+sy⊗sy+sz⊗sz)
eigvals(H)
#4-element Vector{Float64}:
# -0.75
# 0.25
# 0.25
# 0.25
# and get the ground state wavefunction
psi0=eigvecs(H)[:,1]
# it's energy expectation value
psi0'*H*psi0
# -0.75
Remember this is . Create its density matrix
rho=psi0⊗psi0';
# and finally construct the reduced density matrix for spin one, by
# tracing out all of the states of spin number 2
rho01=sum( ((One⊗ b[j]')*psi0)⊗ ((One⊗ b[j]')*psi0)' for j in 1:2)
# What is the expectation value of s_z for the first spin when
# the two spin system is in the ground state?
prob=tr(rho01*sz)
# 0 of course
# What is the probability that spin one will be found in the
# "up" eigenstate when the two spin system is in the ground state?
# I will use my "a" basis above... to creat a projection operator
prob=tr(rho01*(a[1]⊗a[1]'))
# 0.5, of course
This is because
(a maximally entangled Bell state)
As another example let’s study a -spin chain with
and regard the leftmost two spins () as the “system” and the third and forth spin as an “environment” . The second term in the Hamiltonian couples to . We will find the ground state (again the largest magnitude energy eigenvalue), and compute the reduced density matrix for by “integrating out” the environment states.
Hamiltonian=function(N::Int64)
sx=[0 1;1 0]
sy=[0 -im; im 0]
sz=[1 0; 0 -1]
u=[1 0; 0 1]
P=real.(sx⊗sx +sy⊗sy+sz⊗sz);
H=P;
Lend=P
for k=1:(N-2)
H=H⊗u+u⊗Lend;
Lend=u⊗Lend;
end
H/4.0
end
h=Heisenberg(4)
eigvals(h)
#16-element Vector{Float64}:
# -1.6160254037844382
# -0.9571067811865477
# -0.9571067811865477
# -0.9571067811865475
#-0.2500000000000001
# ... and so forth. It is the largest mag. one we want
psi0=eigvecs(h)[:,1];
psi0'*h*psi0
# -1.6160254037844384 expectation of the energy for the gs,
# Make a basis for E
U=[[1;0]⊗[1;0],[1;0]⊗[0;1],[0;1]⊗[1;0],[0;1]⊗[0;1]]
# make a unit matrix for S
u4=One⊗One
# make the reduced density matrix
rho_S=round.(sum(((u4⊗U[j]')*psi0)⊗((u4⊗U[j]')*psi0)' for j in 1:4),digits=8)
#4×4 Matrix{Float64}:
# 0.0223291 -0.0 0.0 0.0
# -0.0 0.477671 -0.455342 0.0
# 0.0 -0.455342 0.477671 -0.0
# 0.0 0.0 -0.0 0.0223291
# note that its trace is one.
Suppose that there exists a new set of basis states for the system such that in this new basis the matrix of is diagonal, then
in this new basis of and then
What are the properties of ?
Let (the unit operator on ) then
(we used this previously to compute probabilities).
Let a projection operator for . Extend it to act on the universe , and call a basis for
since the right side is a sum of squares. Note that I wrote our ground state as an entangled tensor of and states.
Let be an eigenvector of ;
insert unity (sum over the entire complete set);
According to the postulates of quantum mechanics we interpret as the probability that the system is in state .