A_mul_B! deviates from C = A*B with complex numbers

The order of operations matters in floating point world.

julia> result3 = H * (-im*Δt*v);

julia> norm(result3 - result2)
0.0

Edit: as an extreme example:

julia> 1e16 + 1.0 - 1e16
0.0

julia> 1e16 - 1e16 + 1.0
1.0

and see PSA: floating-point arithmetic.

By the way, you may want to consider using OrdinaryDiffEq.jl (part of DifferentialEquations.jl) if you’re solving ODEs, for a vast array of integrators that are highly optimized and tested for accuracy.

2 Likes