diff --git a/src/QuantumOpticsBase.jl b/src/QuantumOpticsBase.jl index f289952e..3fb9bf54 100644 --- a/src/QuantumOpticsBase.jl +++ b/src/QuantumOpticsBase.jl @@ -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 diff --git a/src/fock.jl b/src/fock.jl index 240b4c76..bf26b9d0 100644 --- a/src/fock.jl +++ b/src/fock.jl @@ -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)) \ No newline at end of file