Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/QuantumOpticsBase.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module QuantumOpticsBase

using SparseArrays, LinearAlgebra, LRUCache, Strided, UnsafeArrays, FillArrays
using SparseArrays, LinearAlgebra, LRUCache, Strided, UnsafeArrays, FillArrays, SpecialFunctions
import LinearAlgebra: mul!, rmul!
import RecursiveArrayTools

Expand Down
18 changes: 7 additions & 11 deletions src/fock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,14 @@ function coherentstate!(ket::Ket, b::FockBasis, alpha::Number)
T = real(C)
alpha = C(alpha)
data = ket.data
data[1] = exp(-abs2(alpha)/2)

# Compute coefficient up to offset
λ = abs2(alpha)
ϕ = angle(alpha)
offset = b.offset
@inbounds for n=1:offset
data[1] *= alpha/sqrt(T(n))
end

# Write coefficients to state
@inbounds for n=1:b.N-offset
data[n+1] = data[n]*alpha/sqrt(T(n+offset))
display(b.N)
@inbounds for n=offset:b.N
i=n-offset+1
data[i] = sqrt(poisson(n,λ))*exp(1im*ϕ*n)
end

return ket
end
poisson(k,λ) = exp(k*log(λ) - λ - loggamma(k+1))
Loading