# Numerical intergration order problem (probably)

This is a long example inspired by quantum physics. I tried to abstract the key points and write a typically similar and simpler example, however I failed. Thanks for read my naive and tedious codes in advance.

``````using HCubature,QuadGK,BenchmarkTools

chargonenergy(kx::Float64,ky::Float64)::Float64=-2*0.03*(cos(kx)+cos(-kx/2+sqrt(3)/2*ky)+cos(kx/2+sqrt(3)/2*ky)-3)+0.25

chargongf(omega::Float64,kx::Float64,ky::Float64)::ComplexF64=
(inv(omega+ 0.001*im+chargonenergy(kx,ky))-inv(omega+0.001*im-chargonenergy(kx,ky)))

chargongft(omega::Float64)::ComplexF64=Float64(sqrt(3)/2*1/(2*pi)^2)*hcubature(x->chargongf(omega,x[1],x[2])
,[0.0,0.0],[2*pi,4*pi/sqrt(3)],rtol=1e-6,atol=1e-10)[1]

gfyy(omega::Float64,u::Float64,lambda2::Float64,h2::Float64)::ComplexF64=
inv(-(omega+8e-4*im)^2/3+2*h2*(omega+8e-4*im)/3+lambda2-u^2*chargongft(omega))

sdmyy(omega::Float64,u::Float64,lambda2::Float64,h2::Float64)::Float64=
Float64(-1/pi)*imag(gfyy(omega,u,lambda2,h2))*inv(exp(omega/1e-4)-1.0)

sdmyy(1.0,1.0,1.0,1.0)

function eq3(Vin::Float64,uin::Float64,lambda20in::Float64,h2in::Float64)::Float64
V::Float64=Vin;u::Float64=uin;lambda20::Float64=lambda20in;h2::Float64=h2in;
end

@fastmath eq3(1.0,1.0,1.0,1.0)
MethodError: Cannot `convert` an object of type Tuple{Float64, Float64} to an object of type Float64
Closest candidates are:
convert(::Type{T}, ::T) where T<:Number at number.jl:6
convert(::Type{T}, ::Number) where T<:Number at number.jl:7
convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:273
...
``````

However, if I just put intergration itself with known arguments into a function, I can obtain result:

``````function test()
@fastmath quadgk(omega->sdmyy(omega,1.0,1.0,1.0), -3.0, -1e-4,rtol=1e-4,atol=1e-4)
end
@btime test()
7.577 s (95899911 allocations: 4.11 GiB)
(-0.41534592376510865, 8.444058902582155e-5)
``````

I can’t explain this problem and I can’t find the resource. Just I guess it may caused by evaluation control.