Corrected bugs in Spinors.jl & pmul and dmul defined for general ns and output fixed for dmul

parent 08745620
......@@ -50,12 +50,37 @@ Returns the scalar product of two spinors.
sum = :(dot(a.s[1],b.s[1]))
for i in 2:NS
sum = :($sum + norm2(a.s[$i]))
sum = :($sum + dot(a.s[$i],b.s[$i]))
end
return :($sum)
end
#=
"""
Diracdot(a::Spinor,b::Spinor)
Returns the scalar product of the dirac adjoint of the first spinor times the second spinor.
"""
function Diracdot(a::Spinor{NS,G},b::Spinor{NS,G}) where {NS,G}
S = dot(dag(a).s[3], b[1]) + dot(dag(a).s[4], b[2])
+ dot(dag(a).s[1], b[3]) + dot(dag(a).s[2], b[4])
return -S
end
#"""
# dag(a::Spinor)
#Returns a^+
#"""
#function dag(a::Spinor{NS,G}) where {NS,G}
# return Spinor{NS,G}(ntuple(i -> dag(a.s[i]),Val(NS))) # Need dag function for G, export it from SU3fund.jl
#end
=#
"""
*(g::SU3{T},b::Spinor)
......@@ -75,15 +100,15 @@ Base.:\(g::S,b::Spinor{NS,G}) where {S <: Group,NS,G} = Spinor{NS,G}(ntuple(i->g
Base.:+(a::Spinor{NS,G},b::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->a.s[i]+b.s[i], NS))
Base.:-(a::Spinor{NS,G},b::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->a.s[i]-b.s[i], NS))
Base.:+(a::Spinor{NS,G}) where {NS,G} = a
Base.:-(a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->-b.s[i], NS))
imm(a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->imm(b.s[i]), NS))
mimm(a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->mimm(b.s[i]), NS))
Base.:-(a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->-a.s[i], NS))
imm(a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->imm(a.s[i]), NS))
mimm(a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->mimm(a.s[i]), NS))
# Operations with numbers
Base.:*(a::Spinor{NS,G},b::Number) where {NS,G} = Spinor{NS,G}(ntuple(i->b*a.s[i], NS))
Base.:*(b::Number,a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->b*a.s[i], NS))
Base.:/(a::Spinor{NS,G},b::Number) where {NS,G} = Spinor{NS,G}(ntuple(i->a.s[i]/b, NS))
Base.:*(a::Spinor{NS,G},b::Number) where {NS,G} = Spinor{NS,G}(ntuple(i->b*a.s[i], NS)) # For some reason, these are type instable(?)
Base.:*(b::Number,a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(ntuple(i->b*a.s[i], NS)) # when the number is a ComplexF64 and I try to
Base.:/(a::Spinor{NS,G},b::Number) where {NS,G} = Spinor{NS,G}(ntuple(i->a.s[i]/b, NS)) # run .* with CuArray. Cannot get the length of th tuple.
##
......@@ -100,56 +125,56 @@ end
Returns ``(1+s\\gamma_N)a``.
"""
@inline function pmul(::Type{Pgamma{4,1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{4,1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]+a.s[3]
r2 = a.s[2]+a.s[4]
return Spinor{4,G}((r1,r2,r1,r2))
return Spinor{NS,G}((r1,r2,r1,r2))
end
@inline function pmul(::Type{Pgamma{4,-1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{4,-1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]-a.s[3]
r2 = a.s[2]-a.s[4]
return Spinor{4,G}((r1,r2,-r1,-r2))
return Spinor{NS,G}((r1,r2,-r1,-r2))
end
@inline function pmul(::Type{Pgamma{1,1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{1,1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]+imm(a.s[4])
r2 = a.s[2]+imm(a.s[3])
return Spinor{4,G}((r1,r2,mimm(r2),mimm(r1)))
return Spinor{NS,G}((r1,r2,mimm(r2),mimm(r1)))
end
@inline function pmul(::Type{Pgamma{1,-1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{1,-1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]-imm(a.s[4])
r2 = a.s[2]-imm(a.s[3])
return Spinor{4,G}((r1,r2,imm(r2),imm(r1)))
return Spinor{NS,G}((r1,r2,imm(r2),imm(r1)))
end
@inline function pmul(::Type{Pgamma{2,1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{2,1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]+a.s[4]
r2 = a.s[2]-a.s[3]
return Spinor{4,G}((r1,r2,-r2,r1))
return Spinor{NS,G}((r1,r2,-r2,r1))
end
@inline function pmul(::Type{Pgamma{2,-1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{2,-1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]-a.s[4]
r2 = a.s[2]+a.s[3]
return Spinor{4,G}((r1,r2,r2,-r1))
return Spinor{NS,G}((r1,r2,r2,-r1))
end
@inline function pmul(::Type{Pgamma{3,1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{3,1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]+imm(a.s[3])
r2 = a.s[2]-imm(a.s[4])
return Spinor{4,G}((r1,r2,mimm(r1),imm(r2)))
return Spinor{NS,G}((r1,r2,mimm(r1),imm(r2)))
end
@inline function pmul(::Type{Pgamma{3,-1}}, a::Spinor{4,G}) where {NS,G}
@inline function pmul(::Type{Pgamma{3,-1}}, a::Spinor{NS,G}) where {NS,G}
r1 = a.s[1]-imm(a.s[3])
r2 = a.s[2]+imm(a.s[4])
return Spinor{4,G}((r1,r2,imm(r1),mimm(r2)))
return Spinor{NS,G}((r1,r2,imm(r1),mimm(r2)))
end
......@@ -158,56 +183,56 @@ end
Returns ``g(1+s\\gamma_N)a``
"""
@inline function gpmul(::Type{Pgamma{4,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{4,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]+a.s[3])
r2 = g*(a.s[2]+a.s[4])
return Spinor{4,G}((r1,r2,r1,r2))
return Spinor{NS,G}((r1,r2,r1,r2))
end
@inline function gpmul(::Type{Pgamma{4,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{4,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]-a.s[3])
r2 = g*(a.s[2]-a.s[4])
return Spinor{4,G}((r1,r2,-r1,-r2))
return Spinor{NS,G}((r1,r2,-r1,-r2))
end
@inline function gpmul(::Type{Pgamma{1,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{1,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]+imm(a.s[4]))
r2 = g*(a.s[2]+imm(a.s[3]))
return Spinor{4,G}((r1,r2,mimm(r2),mimm(r1)))
return Spinor{NS,G}((r1,r2,mimm(r2),mimm(r1)))
end
@inline function gpmul(::Type{Pgamma{1,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{1,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]-imm(a.s[4]))
r2 = g*(a.s[2]-imm(a.s[3]))
return Spinor{4,G}((r1,r2,imm(r2),imm(r1)))
return Spinor{NS,G}((r1,r2,imm(r2),imm(r1)))
end
@inline function gpmul(::Type{Pgamma{2,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{2,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]+a.s[4])
r2 = g*(a.s[2]-a.s[3])
return Spinor{4,G}((r1,r2,-r2,r1))
return Spinor{NS,G}((r1,r2,-r2,r1))
end
@inline function gpmul(::Type{Pgamma{2,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{2,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]-a.s[4])
r2 = g*(a.s[2]+a.s[3])
return Spinor{4,G}((r1,r2,r2,-r1))
return Spinor{NS,G}((r1,r2,r2,-r1))
end
@inline function gpmul(::Type{Pgamma{3,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{3,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]+imm(a.s[3]))
r2 = g*(a.s[2]-imm(a.s[4]))
return Spinor{4,G}((r1,r2,mimm(r1),imm(r2)))
return Spinor{NS,G}((r1,r2,mimm(r1),imm(r2)))
end
@inline function gpmul(::Type{Pgamma{3,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gpmul(::Type{Pgamma{3,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g*(a.s[1]-imm(a.s[3]))
r2 = g*(a.s[2]+imm(a.s[4]))
return Spinor{4,G}((r1,r2,imm(r1),mimm(r2)))
return Spinor{NS,G}((r1,r2,imm(r1),mimm(r2)))
end
"""
......@@ -215,56 +240,56 @@ end
Returns ``g^+ (1+s\\gamma_N)a``
"""
@inline function gdagpmul(::Type{Pgamma{4,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{4,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]+a.s[3])
r2 = g\(a.s[2]+a.s[4])
return Spinor{4,G}((r1,r2,r1,r2))
return Spinor{NS,G}((r1,r2,r1,r2))
end
@inline function gdagpmul(::Type{Pgamma{4,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{4,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]-a.s[3])
r2 = g\(a.s[2]-a.s[4])
return Spinor{4,G}((r1,r2,-r1,-r2))
return Spinor{NS,G}((r1,r2,-r1,-r2))
end
@inline function gdagpmul(::Type{Pgamma{1,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{1,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]+imm(a.s[4]))
r2 = g\(a.s[2]+imm(a.s[3]))
return Spinor{4,G}((r1,r2,mimm(r2),mimm(r1)))
return Spinor{NS,G}((r1,r2,mimm(r2),mimm(r1)))
end
@inline function gdagpmul(::Type{Pgamma{1,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{1,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]-imm(a.s[4]))
r2 = g\(a.s[2]-imm(a.s[3]))
return Spinor{4,G}((r1,r2,imm(r2),imm(r1)))
return Spinor{NS,G}((r1,r2,imm(r2),imm(r1)))
end
@inline function gdagpmul(::Type{Pgamma{2,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{2,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]+a.s[4])
r2 = g\(a.s[2]-a.s[3])
return Spinor{4,G}((r1,r2,-r2,r1))
return Spinor{NS,G}((r1,r2,-r2,r1))
end
@inline function gdagpmul(::Type{Pgamma{2,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{2,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]-a.s[4])
r2 = g\(a.s[2]+a.s[3])
return Spinor{4,G}((r1,r2,r2,-r1))
return Spinor{NS,G}((r1,r2,r2,-r1))
end
@inline function gdagpmul(::Type{Pgamma{3,1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{3,1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]+imm(a.s[3]))
r2 = g\(a.s[2]-imm(a.s[4]))
return Spinor{4,G}((r1,r2,mimm(r1),imm(r2)))
return Spinor{NS,G}((r1,r2,mimm(r1),imm(r2)))
end
@inline function gdagpmul(::Type{Pgamma{3,-1}}, g, a::Spinor{4,G}) where {NS,G}
@inline function gdagpmul(::Type{Pgamma{3,-1}}, g, a::Spinor{NS,G}) where {NS,G}
r1 = g\(a.s[1]-imm(a.s[3]))
r2 = g\(a.s[2]+imm(a.s[4]))
return Spinor{4,G}((r1,r2,imm(r1),mimm(r2)))
return Spinor{NS,G}((r1,r2,imm(r1),mimm(r2)))
end
......@@ -298,24 +323,24 @@ indexing for Dirac basis ``\\Gamma_n``:
16 identity
"""
@inline dmul(::Type{Gamma{1}}, a::Spinor{4,G}) where {G} = Spinor{4,G}(mimm(a.s[4]), mimm(a.s[3]), imm(a.s[2]), imm(a.s[1]))
@inline dmul(::Type{Gamma{2}}, a::Spinor{4,G}) where {G} = Spinor{4,G}(-a.s[4], a.s[3], a.s[2], -a.s[1])
@inline dmul(::Type{Gamma{3}}, a::Spinor{4,G}) where {G} = Spinor{4,G}(mimm(a.s[3]), imm(a.s[4]), imm(a.s[1]), mimm(a.s[2]))
@inline dmul(::Type{Gamma{4}}, a::Spinor{4,G}) where {G} = Spinor{4,G}(-a.s[3], -a.s[4], -a.s[1], -a.s[2])
@inline dmul(::Type{Gamma{5}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( a.s[1], a.s[2], -a.s[3], -a.s[4])
@inline dmul(::Type{Gamma{6}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( imm(a.s[4]), imm(a.s[3]), imm(a.s[2]), imm(a.s[1]))
@inline dmul(::Type{Gamma{7}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( a.s[4], -a.s[3], a.s[2], -a.s[1])
@inline dmul(::Type{Gamma{8}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( imm(a.s[3]), mimm(a.s[4]), imm(a.s[1]), mimm(a.s[2]))
@inline dmul(::Type{Gamma{9}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( a.s[3], a.s[4], -a.s[1], -a.s[2])
@inline dmul(::Type{Gamma{10}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( a.s[2], a.s[1], -a.s[4], -a.s[3])
@inline dmul(::Type{Gamma{11}}, a::Spinor{4,G}) where {G} = Spinor{4,G}(mimm(a.s[2]), imm(a.s[1]), imm(a.s[4]), mimm(a.s[3]))
@inline dmul(::Type{Gamma{12}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( a.s[1], -a.s[2], -a.s[3], a.s[4])
@inline dmul(::Type{Gamma{13}}, a::Spinor{4,G}) where {G} = Spinor{4,G}(-a.s[1], a.s[2], -a.s[3], a.s[4])
@inline dmul(::Type{Gamma{14}}, a::Spinor{4,G}) where {G} = Spinor{4,G}(-a.s[2], -a.s[1], -a.s[4], -a.s[3])
@inline dmul(::Type{Gamma{15}}, a::Spinor{4,G}) where {G} = Spinor{4,G}( imm(a.s[2]), mimm(a.s[1]), imm(a.s[4]), mimm(a.s[3]))
@inline dmul(::Type{Gamma{16}}, a::Spinor{4,G}) where {G} = a
export Spinor, Pgamma
@inline dmul(::Type{Gamma{1}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((mimm(a.s[4]), mimm(a.s[3]), imm(a.s[2]), imm(a.s[1])))
@inline dmul(::Type{Gamma{2}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((-a.s[4], a.s[3], a.s[2], -a.s[1]))
@inline dmul(::Type{Gamma{3}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((mimm(a.s[3]), imm(a.s[4]), imm(a.s[1]), mimm(a.s[2])))
@inline dmul(::Type{Gamma{4}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((-a.s[3], -a.s[4], -a.s[1], -a.s[2]))
@inline dmul(::Type{Gamma{5}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((a.s[1], a.s[2], -a.s[3], -a.s[4]))
@inline dmul(::Type{Gamma{6}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(( imm(a.s[4]), imm(a.s[3]), imm(a.s[2]), imm(a.s[1])))
@inline dmul(::Type{Gamma{7}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(( a.s[4], -a.s[3], a.s[2], -a.s[1]))
@inline dmul(::Type{Gamma{8}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(( imm(a.s[3]), mimm(a.s[4]), imm(a.s[1]), mimm(a.s[2])))
@inline dmul(::Type{Gamma{9}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(( a.s[3], a.s[4], -a.s[1], -a.s[2]))
@inline dmul(::Type{Gamma{10}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(( a.s[2], a.s[1], -a.s[4], -a.s[3]))
@inline dmul(::Type{Gamma{11}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((mimm(a.s[2]), imm(a.s[1]), imm(a.s[4]), mimm(a.s[3])))
@inline dmul(::Type{Gamma{12}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(( a.s[1], -a.s[2], -a.s[3], a.s[4]))
@inline dmul(::Type{Gamma{13}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((-a.s[1], a.s[2], -a.s[3], a.s[4]))
@inline dmul(::Type{Gamma{14}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}((-a.s[2], -a.s[1], -a.s[4], -a.s[3]))
@inline dmul(::Type{Gamma{15}}, a::Spinor{NS,G}) where {NS,G} = Spinor{NS,G}(( imm(a.s[2]), mimm(a.s[1]), imm(a.s[4]), mimm(a.s[3])))
@inline dmul(::Type{Gamma{16}}, a::Spinor{NS,G}) where {NS,G} = a
export Spinor, Pgamma, Gamma
export norm, norm2, dot, imm, mimm
export pmul, gpmul, gdagpmul, dmul
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment