-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Position and momentum, Spin operators, Related Tests.
- Loading branch information
1 parent
62145d3
commit 285bbec
Showing
7 changed files
with
114 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
include("arraymath.jl") | ||
include("constructors.jl") | ||
include("ladderops.jl") | ||
|
||
include("spinops.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
######################### | ||
# Spin Operator Methods # | ||
######################### | ||
|
||
immutable HalfSpin{S} | ||
function HalfSpin() | ||
S > 0 ? new() : error("Spin must be positive") | ||
end | ||
end | ||
|
||
# The below function `spin` takes in a value and converts its to a type parameter | ||
# i.e., from value domain to type domain making it type unstable. | ||
|
||
spin(j::Integer) = j > 0 ? HalfSpin{j}() : error("Spin must be positive") | ||
|
||
function spin(j::Float64) | ||
if (j > 0) && isinteger(j) | ||
spin(int(j)) | ||
elseif (j > 0) && isinteger(2*j) | ||
spin(int(2*j)) | ||
else | ||
error("Spin must be positive and a multiple of 1/2.") | ||
end | ||
end | ||
|
||
spin_value{S}(::HalfSpin{S}) = S/2 | ||
|
||
##################### | ||
# Auxiliary methods # | ||
##################### | ||
|
||
function mat_coeffs_1(j::Float64) | ||
m = [j-1:-1:-j] | ||
N = length(m)+1 | ||
m_coeffs = [sqrt(j*(j+1.0) - (x+1.0)*x) for x in m] | ||
return spdiagm(m_coeffs,1,N,N) | ||
end | ||
|
||
function mat_coeffs_2(j::Float64) | ||
m = [j:-1:-j] | ||
N = length(m) | ||
return spdiagm(m,0,N,N) | ||
end | ||
|
||
function spin_h1(k::HalfSpin) | ||
j = spin_value(k) | ||
return mat_coeffs_1(j) | ||
end | ||
|
||
function spin_h2(k::HalfSpin) | ||
j = spin_value(k) | ||
return mat_coeffs_2(j) | ||
end | ||
|
||
################################ | ||
# Jx, Jy, Jz, Jp, Jm operators # | ||
################################ | ||
|
||
spin_Jx(j) = QuArray(0.5*(spin_h1(spin(j))+spin_h1(spin(j))')) | ||
spin_Jy(j) = QuArray(-0.5*im*(spin_h1(spin(j))-spin_h1(spin(j))')) | ||
spin_Jz(j) = QuArray(spin_h2(spin(j))) | ||
spin_Jp(j) = QuArray(spin_h1(spin(j))) | ||
spin_Jm(j) = QuArray(spin_h1(spin(j))') | ||
|
||
############################ | ||
# Pauli spin 1/2 matrices # | ||
############################ | ||
|
||
const sigma_x = 2.0 * spin_Jx(1/2) | ||
const sigma_y = 2.0 * spin_Jy(1/2) | ||
const sigma_z = 2.0 * spin_Jz(1/2) | ||
|
||
# TODO : unicode sigma_y, sigma_z | ||
const σₓ = sigma_x | ||
|
||
export spin_Jx, | ||
spin_Jy, | ||
spin_Jz, | ||
spin_Jp, | ||
spin_Jm, | ||
sigma_x, | ||
sigma_y, | ||
sigma_z, | ||
σₓ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
####################### | ||
# Spin Operators Test # | ||
####################### | ||
|
||
@assert commutator(sigma_x, sigma_y) == 2*im*sigma_z | ||
@assert commutator(sigma_y, sigma_z) == 2*im*sigma_x | ||
@assert commutator(sigma_z, sigma_x) == 2*im*sigma_y | ||
@assert coeffs(commutator(sigma_x, sigma_x)) == spzeros(2,2) | ||
|
||
###################################### | ||
# Position & Momentum Operators Test # | ||
###################################### | ||
|
||
p = positionop(2) | ||
m = momentumop(2) | ||
@assert coeffs(commutator(sigma_x, p)) == spzeros(2,2) | ||
@assert coeffs(commutator(sigma_y, m)) == spzeros(2,2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters