qojulia / QuantumOptics.jl

Library for the numerical simulation of closed as well as open quantum systems.
http://qojulia.org
Other
518 stars 101 forks source link

Coherent spin states overflows for large spin number #326

Closed goerz closed 2 years ago

goerz commented 2 years ago
julia> using QuantumOptics
julia> b = SpinBasis(35)
julia> css = coherentspinstate(b,0,0)
ERROR: OverflowError: binomial(70, 26) overflows
Stacktrace:
 [1] binomial(n::Int64, k::Int64)
   @ Base ./intfuncs.jl:1042
 [2] coherentspinstate(b::SpinBasis{35//1, Int64}, theta::Int64, phi::Int64)
   @ QuantumOptics ~/.julia/packages/QuantumOptics/pQzS7/src/phasespace.jl:299
 [3] top-level scope
   @ REPL[6]:1

The solution is to use a recursive definition of the binomial coefficient instead of the (integer) built-in binomial function. I'll prepare a PR for this.