In [16]:
(<=)
Out[16]:
In [5]:
1+(1:3)
Out[5]:
In [ ]:
In [ ]:
In [24]:
a = @operator (j,k,N,M) -> sqrt(j)*π(j∈1:M)*δ(j,k-1)
A single (off-)diagonal operator can be decomposed as
$$ A _ {jk} = \tilde{f(j;I)} \delta _ {j,k+s} = f(j;I) \pi(j;I) \pi(j-s;I) \delta _ {j,k+s} $$where each projector $\pi(j;I)=\mathbf{1}_{j\in I}$ is one iff $j$ is in the range of valid state labels. Given any coefficient generating function $f(j)$
In [27]:
?inf
Out[27]:
In [29]:
module Experiments
abstract TAlgebra
abstract LTerm <: TAlgebra
abstract LDiag <: LTerm
type LIdentity
end
type LDGenerated <: LDiag
fn
end
type LIndicator <: LDiag
l::Int
u::Int
end
type LShift <: LDiag
op::LDiag
s::Int
end
type LConj <: LDiag
op::LDiag
end
type LDiagShift <: LTerm
factors::Vector{LDiag}
s::Int
end
type TProduct{D} <: TAlgebra
dfactors::NTuple{D,LDiag}
ss::NTuple{D,Int}
end
import Base: (.*), (*), conj, transpose, ctranspose
fss(x::LDiag) = [x], 0
fss(x::LTerm) = x.factors, x.s
(.*)(x::LIdentity, y::LIdentity) = x
(.*)(x::LIdentity, y::LTerm) = y
(.*)(x::LTerm, y::LIdentity) = x
conj(x::LIdentity) = x
conj(x::LDiag) = LConj(x)
conj(x::LDiagShift) = LDiagShift([conj(f) for f in x.factors], x.s)
transpose(x::LDiag) = x
transpose(x::LDiagShift) = LDiagShift([LShift(f,-x.s) for f in x.factors], -x.s)
ctranspose(x::LTerm) = transpose(conj(x))
lshift(op::LDiag, s) = s ==0 ? op : LShift(op, s)
function (.*)(x::LTerm, y::LTerm)
fx, sx = fss(x)
fy, sy = fss(y)
fxy = filter(z->~isa(z, LIdentity), [fx; [lshift(op, sx) for op=fy]])
LDiagShift(fxy, sx+sy)
end
function rcoeffs(T, li::LIndicator, states)
if li.upper >= li.lower
return [one(T)*(s∈(li.lower:li.upper)) for s=states]
else
return [one(T)*(s>=li.lower) for s=states]
end
end
function rcoeffs(T, lc::LShift, states)
rcoeffs(T, lc.op, states-lc.s)
end
function rcoeffs(T, lc::LConj, states)
conj(rcoeffs(T, lc.op, states))
end
function rcoeffs(T, lc::LShift, states)
rcoeffs(T, lc.op, states-lc.s)
end
function rcoeffs(T, lg::LDGenerated, states)
convert(Vector{T}, [lg.fn(s) for s=states])
end
function rcoeffs(T, lds::LDiagShift, states)
(.*)([rcoeffs(T, d, states) for d=lds.factors]...), lds.s
end
end
create = Experiments.LDiagShift([Experiments.LDGenerated(k->sqrt(k))], 1)
destroy = ctranspose(create)
Out[29]:
In [30]:
Experiments.rcoeffs(Float64, create, 0:20), Experiments.rcoeffs(Float64, destroy, 0:20)
Out[30]:
In [31]:
Experiments.rcoeffs(Float64, create.*destroy,0:20)
Out[31]:
In [35]:
Experiments.rcoeffs(Float64, destroy.*create,0:20)
Experiments.rcoeffs(Float64, create.*create.*destroy.*destroy,0:20)
In [2]:
comm
In [ ]: