Skip to content

Commit 375a9e9

Browse files
committed
WIP : Spin operators.
1 parent d9574c2 commit 375a9e9

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

src/arrays/ladderops.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,46 @@ function momentumop(n::Int)
3737
return scale(im/sqrt(2.), cop-cop')
3838
end
3939

40+
function spin_h1(j)
41+
m = reverse([-j:j-1])
42+
N = length(m)+1
43+
m_coeffs = [sqrt(j*(j+1.0) - (x+1.0)*x) for x in m]
44+
return spdiagm(m_coeffs,1,N,N)
45+
end
46+
47+
function spin_h2(j)
48+
m = reverse([-j:j])
49+
N = length(m)
50+
return spdiagm(m,0,N,N)
51+
end
52+
53+
function spin_jx(j)
54+
return QuArray(0.5*(spin_h1(j)+spin_h1(j)'))
55+
end
56+
57+
function spin_jy(j)
58+
return QuArray(-0.5*im*(spin_h1(j)-spin_h1(j)'))
59+
end
60+
61+
function spin_jz(j)
62+
return QuArray(spin_h2(j))
63+
end
64+
65+
function spin_jp(j)
66+
return QuArray(spin_h1(j))
67+
end
68+
69+
function spin_jm(j)
70+
return QuArray(spin_h1(j)')
71+
end
72+
4073
export raiseop,
4174
lowerop,
4275
positionop,
43-
momentumop
76+
momentumop,
77+
spin_jx,
78+
spin_jy,
79+
spin_jz,
80+
spin_jplus,
81+
spin_jminus
82+

src/arrays/quarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
rawbases(qarr::QuArray, i) = qarr.bases[i]
3737
bases(qarr::QuArray, i) = rawbases(qarr, i)
38-
38+
3939
# works generally as long as the single index form is defined
4040
rawbases(qarr::AbstractQuArray) = ntuple(ndims(qarr), i->rawbases(qarr, i))
4141
bases(qarr::AbstractQuArray) = ntuple(ndims(qarr), i->bases(qarr, i))
@@ -105,11 +105,11 @@
105105
# LabelQuArray #
106106
################
107107
typealias LabelQuArray{B<:LabelBasis,T,N,A} QuArray{B,T,N,A}
108-
typealias TupleArray{T<:Tuple,N} Array{T,N}
108+
typealias TupleArray{T<:Tuple,N} Array{T,N}
109109

110110
Base.getindex(larr::LabelQuArray, tups::Union(Tuple,TupleArray)...) = getindex(larr, map(getindex, bases(larr), tups)...)
111111
Base.setindex!(larr::LabelQuArray, x, tups::Union(Tuple,TupleArray)...) = setindex!(larr, x, map(getindex, bases(larr), tups)...)
112-
112+
113113
######################
114114
# Printing Functions #
115115
######################

0 commit comments

Comments
 (0)