Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/operators/spinoperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function spinmatrices(s::Union{Rational{Int},Int}, elt=ComplexF64)
N = Int(2 * s)

Sx = zeros(elt, N + 1, N + 1)
Sy = zeros(elt, N + 1, N + 1)
Sy = zeros(complex(elt), N + 1, N + 1)
Sz = zeros(elt, N + 1, N + 1)

for row in 1:(N + 1)
Expand Down Expand Up @@ -417,13 +417,13 @@ S_exchange(elt::Type{<:Number}; kwargs...) = S_exchange(elt, Trivial; kwargs...)
function S_exchange(symmetry::Type{<:Sector}; kwargs...)
return S_exchange(ComplexF64, symmetry; kwargs...)
end

function S_exchange(elt::Type{<:Number}, ::Type{Trivial}; spin=1 // 2)
return S_xx(elt, Trivial; spin=spin) +
S_yy(elt, Trivial; spin=spin) +
S_zz(elt, Trivial; spin=spin)
function S_exchange(elt::Type{<:Number}, symmetry::Type{<:Sector}; spin=1 // 2)
elt_complex = complex(elt)
SS = (S_plusmin(elt_complex, symmetry; spin=spin) +
S_minplus(elt_complex, symmetry; spin=spin)) / 2 +
S_zz(elt_complex, symmetry; spin=spin)
return elt <: Real ? real(SS) : SS
end

function S_exchange(elt::Type{<:Number}, ::Type{SU2Irrep}; spin=1 // 2)
pspace = SU2Space(spin => 1)
aspace = SU2Space(1 => 1)
Expand All @@ -435,11 +435,6 @@ function S_exchange(elt::Type{<:Number}, ::Type{SU2Irrep}; spin=1 // 2)
return SS
end

function S_exchange(elt::Type{<:Number}, symmetry::Type{<:Sector}; spin=1 // 2)
return (S_plusmin(elt, symmetry; spin=spin) + S_minplus(elt, symmetry; spin=spin)) / 2 +
S_zz(elt, symmetry; spin=spin)
end

const SS = S_exchange

"""Pauli exchange operator."""
Expand Down
6 changes: 3 additions & 3 deletions test/hubbardoperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ implemented_symmetries = [(Trivial, Trivial), (U1Irrep, U1Irrep), (U1Irrep, SU2I
end
end

function hamiltonian(particle_symmetry, spin_symmetry; t, U, mu, L)
function hubbard_hamiltonian(particle_symmetry, spin_symmetry; t, U, mu, L)
hopping = t * (e_plusmin(particle_symmetry, spin_symmetry) +
e_minplus(particle_symmetry, spin_symmetry))
interaction = U * e_number_updown(particle_symmetry, spin_symmetry)
Expand All @@ -65,7 +65,7 @@ end
U = randn()
mu = randn()

H_triv = hamiltonian(Trivial, Trivial; t, U, mu, L)
H_triv = hubbard_hamiltonian(Trivial, Trivial; t, U, mu, L)
vals_triv = mapreduce(vcat, eigvals(H_triv)) do (c, v)
return repeat(real.(v), dim(c))
end
Expand All @@ -75,7 +75,7 @@ end
if (particle_symmetry, spin_symmetry) == (Trivial, Trivial)
continue
end
H_symm = hamiltonian(particle_symmetry, spin_symmetry; t, U, mu, L)
H_symm = hubbard_hamiltonian(particle_symmetry, spin_symmetry; t, U, mu, L)
vals_symm = mapreduce(vcat, eigvals(H_symm)) do (c, v)
return repeat(real.(v), dim(c))
end
Expand Down
9 changes: 9 additions & 0 deletions test/spinoperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ end
S_xx(U1Irrep; spin=spin) + S_yy(U1Irrep; spin=spin) + S_zz(U1Irrep; spin=spin) rtol = 1e-3
end

@testset "Real eltype" begin
for operator in (S_x, S_z, S_xx, S_zz, S_plusmin, S_minplus, S_exchange),
symmetry in (Trivial, Z2Irrep, U1Irrep)

@test real(operator(ComplexF64, symmetry)) ≈ operator(Float64, symmetry)
end
@test real(S_exchange(ComplexF64, SU2Irrep)) ≈ S_exchange(Float64, SU2Irrep)
end

# potts_ZZ test?
@testset "non-symmetric Q-state potts operators" for Q in 3:5
# inferrability
Expand Down
8 changes: 4 additions & 4 deletions test/tjoperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ implemented_symmetries = [(Trivial, Trivial),
end
end

function hamiltonian(particle_symmetry, spin_symmetry; t, J, mu, L, slave_fermion)
function tjhamiltonian(particle_symmetry, spin_symmetry; t, J, mu, L, slave_fermion)
num = tJ.e_number(particle_symmetry, spin_symmetry; slave_fermion)
hop_heis = (-t) * (tJ.e_plusmin(particle_symmetry, spin_symmetry; slave_fermion) +
tJ.e_minplus(particle_symmetry, spin_symmetry; slave_fermion)) +
Expand All @@ -98,7 +98,7 @@ end
mu = randn()

for slave_fermion in (false, true)
H_triv = hamiltonian(Trivial, Trivial; t, J, mu, L, slave_fermion)
H_triv = tjhamiltonian(Trivial, Trivial; t, J, mu, L, slave_fermion)
vals_triv = mapreduce(vcat, eigvals(H_triv)) do (c, v)
return repeat(real.(v), dim(c))
end
Expand All @@ -108,8 +108,8 @@ end
if (particle_symmetry, spin_symmetry) == (Trivial, Trivial)
continue
end
H_symm = hamiltonian(particle_symmetry, spin_symmetry; t, J, mu, L,
slave_fermion)
H_symm = tjhamiltonian(particle_symmetry, spin_symmetry; t, J, mu, L,
slave_fermion)
vals_symm = mapreduce(vcat, eigvals(H_symm)) do (c, v)
return repeat(real.(v), dim(c))
end
Expand Down
Loading