Thanks a lot for the detailed answer. I changed a bit your macro, introducing conj() instead of ' and splicing the Kronecker sum to get a functional version:
macro M(m,n, ε1,ε2,ε3, X1,X2,X3, A1,A2,A3)
ε = [ε1,ε2,ε3]
X = [X1,X2,X3]
A = [A1,A2,A3]
Asum = {:+}
for q=1:3, t=1:3
if m+q == n+t
push!(Asum, :(conj($(A[q])) * $(A[t])))
:($(ε[m]) + 2*abs2($(X[m])) * $(Expr(:call, Asum...)))
else
:(2 * conj($(X[m])) * $(X[n]) * $(Expr(:call, Asum...)))
end
end
I also defined a macro for the elements of Q:
macro Q(m,n, X1,X2,X3, A1,A2,A3)
X = [X1,X2,X3]
A = [A1,A2,A3]
Asum = {:+}
for q=1:3, t=1:3
if m+n == q+t
push!(Asum, :($(A[q]) * $(A[t])))
end
end
:(conj($(X[m])) * conj($(X[n])) * $(Expr(:call, Asum...)))
end
and now I'm a bit stuck on putting it all together to get the full L matrix. Im trying to calculated L(i,j) based on M and Q for the 4 separate blocks. I only implemented the upper left block but I get an error
macro L(i,j, ε1,ε2,ε3, X1,X2,X3, A1,A2,A3)
if i<4
if j<4
@M(i,j, ε1,ε2,ε3, X1,X2,X3, A1,A2,A3)
end
end
end
`+` has no method matching +(::Symbol, ::Int64)
It seems that the @M macro needs a value for the m,n indices for the comparison
if m+q == n+t
Any ideas how to solve this? The end-result I want is a function L(k, A1, A2, A3, etc) which would return the full 6x6 matrix.
//A