Skip to content

Commit

Permalink
Add methods 'isannihilation' and 'iscreation'.
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergu committed Apr 11, 2023
1 parent e84dbd7 commit aa1fd4a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/QuantumLattices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export plain, statistics, @indexes
include("QuantumSystems.jl")
using .QuantumSystems
export annihilation, creation, latexofbosons, latexoffermions, latexofparticles, @σ_str, @L_str
export Coulomb, FID, Fock, FockTerm, Hopping, Hubbard, InterOrbitalInterSpin, InterOrbitalIntraSpin, Onsite, PairHopping, Pairing, SpinFlip, isnormalordered
export Coulomb, FID, Fock, FockTerm, Hopping, Hubbard, InterOrbitalInterSpin, InterOrbitalIntraSpin, Onsite, PairHopping, Pairing, SpinFlip, isannihilation, iscreation, isnormalordered
export latexofspins, SID, Spin, SpinTerm, totalspin, @Γ_str, @DM_str, @Heisenberg_str, @Ising_str
export latexofphonons, Elastic, PID, Phonon, Kinetic, Hooke, PhononTerm

Expand Down
26 changes: 24 additions & 2 deletions src/QuantumSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import ..Toolkit: shape

# Canonical complex fermionic/bosonic systems
export annihilation, creation, latexofbosons, latexoffermions, latexofparticles, @σ_str, @L_str
export Coulomb, FID, Fock, FockTerm, Hopping, Hubbard, InterOrbitalInterSpin, InterOrbitalIntraSpin, Onsite, PairHopping, Pairing, SpinFlip, isnormalordered
export Coulomb, FID, Fock, FockTerm, Hopping, Hubbard, InterOrbitalInterSpin, InterOrbitalIntraSpin, Onsite, PairHopping, Pairing, SpinFlip, isannihilation, iscreation, isnormalordered

# SU(2) spin systems
export latexofspins, SID, Spin, SpinTerm, totalspin, @Γ_str, @DM_str, @Heisenberg_str, @Ising_str
Expand Down Expand Up @@ -81,6 +81,28 @@ end
@inline iidtype(::Type{FID}, ::Type{O}, ::Type{S}, ::Type{N}) where {O<:Union{Int, Symbol, Colon}, S<:Union{Rational{Int}, Symbol, Colon}, N<:Union{Int, Symbol, Colon}} = FID{wildcard, O, S, N}
@inline iidtype(::Type{FID{T}}, ::Type{O}, ::Type{S}, ::Type{N}) where {T, O<:Union{Int, Symbol, Colon}, S<:Union{Rational{Int}, Symbol, Colon}, N<:Union{Int, Symbol, Colon}} = FID{T, O, S, N}

"""
isannihilation(fid::FID) -> Bool
isannihilation(index::Index) -> Bool
isannihilation(index::AbstractCompositeIndex) -> Bool
Judge whether the nambu index is `annihilation`.
"""
@inline isannihilation(fid::FID) = fid.nambu==annihilation
@inline isannihilation(index::Index) = isannihilation(index.iid)
@inline isannihilation(index::AbstractCompositeIndex) = isannihilation(getcontent(index, :index))

"""
iscreation(fid::FID) -> Bool
iscreation(index::Index) -> Bool
iscreation(index::AbstractCompositeIndex) -> Bool
Judge whether the nambu index is `creation`.
"""
@inline iscreation(fid::FID) = fid.nambu==creation
@inline iscreation(index::Index) = iscreation(index.iid)
@inline iscreation(index::AbstractCompositeIndex) = iscreation(getcontent(index, :index))

## Fock
"""
Fock{T} <: SimpleInternal{FID{T, Int, Rational{Int}, Int}}
Expand Down Expand Up @@ -117,7 +139,7 @@ Get the requested script of an fid.
@inline script(::Val{:orbital}, fid::FID; kwargs...) = default(fid.orbital)
@inline script(::Val{:spin}, fid::FID; kwargs...) = default(fid.spin)
@inline script(::Val{:spinsym}, fid::FID; kwargs...) = fid.spin==-1//2 ? "" : fid.spin==1//2 ? "" : fid.spin==0 ? "" : default(fid.spin)
@inline script(::Val{:nambu}, fid::FID; kwargs...) = fid.nambu==creation ? "\\dagger" : fid.nambu==annihilation ? "" : default(fid.nambu)
@inline script(::Val{:nambu}, fid::FID; kwargs...) = iscreation(fid) ? "\\dagger" : isannihilation(fid) ? "" : default(fid.nambu)

"""
latexoffermions
Expand Down
12 changes: 9 additions & 3 deletions test/QuantumSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ using StaticArrays: SVector
@test hash(fid) == hash((:f, 1, 1//2, 1))
@test fid' == replace(fid, nambu=2)
@test isequal(fid'', replace(fid, nambu=1))
@test isannihilation(fid) && isannihilation(Index(1, fid)) && isannihilation(CompositeIndex(Index(1, fid), [0.0], [0.0]))
@test !iscreation(fid) && !iscreation(Index(1, fid)) && !iscreation(CompositeIndex(Index(1, fid), [0.0], [0.0]))

fid = FID{:b}(1, -1//2, 1)
@test string(fid) == "FID{:b}(1, -1//2, 1)"
fid = FID{:b}(1, -1//2, 2)
@test string(fid) == "FID{:b}(1, -1//2, 2)"
@test statistics(fid) == statistics(typeof(fid)) == :b
@test hash(fid) == hash((:b, 1, -1//2, 1))
@test hash(fid) == hash((:b, 1, -1//2, 2))
@test !isannihilation(fid) && !isannihilation(Index(1, fid)) && !isannihilation(CompositeIndex(Index(1, fid), [0.0], [0.0]))
@test iscreation(fid) && iscreation(Index(1, fid)) && iscreation(CompositeIndex(Index(1, fid), [0.0], [0.0]))

fid = FID(1, , :)
@test fid == FID{wildcard}(1, , :)
@test string(fid) == "FID(1, α, :)"
@test statistics(fid) == wildcard
@test hash(fid) == hash((wildcard, 1, , :))
@test !isannihilation(fid) && !isannihilation(Index(1, fid)) && !isannihilation(CompositeIndex(Index(1, fid), [0.0], [0.0]))
@test !iscreation(fid) && !iscreation(Index(1, fid)) && !iscreation(CompositeIndex(Index(1, fid), [0.0], [0.0]))

@test FID{:f}(1, 1//2, 1)FID{:b}(1, 1//2, 1)
@test isequal(FID{:f}(1, 1//2, 1), FID{:f}(1, 1//2, 1))
Expand Down

0 comments on commit aa1fd4a

Please sign in to comment.