The problem is quite easy to solve:
The error arises, because NIntegrate does some symbolic pre-Processing of the integrand. In this case here, this preprocessing introduced a branch cut and the following numeric procession part got wrong results.You can see, that the funtion h has a jump at p= +-4.3.
It can be avoided by setting SymbolicPreProcessing to False. This works both on the multivariate integral and the nested integrals.
In[164]:= NIntegrate[
f[x, p, 1*I*x]*(p^2/2), {x, -Infinity, Infinity}, {p, -Infinity,
Infinity}, Method -> {Automatic, "SymbolicProcessing" -> False}]
During evaluation of In[164]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>
Out[164]= 0.25\[VeryThinSpace]- 2.49312*10^-16 I
In[165]:=
h[p_?NumericQ] :=
NIntegrate[f[x, p, 1*I*x]*(p^2/2), {x, -Infinity, Infinity}]
NIntegrate[h[p], {p, -Infinity, Infinity}]
During evaluation of In[165]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>
During evaluation of In[165]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in p near {p} = {-5.09582}. NIntegrate obtained 0.262508\[VeryThinSpace]-0.0736375 I
and 0.003683811726300084` for the integral and error estimates. >>
Out[166]= 0.262508\[VeryThinSpace]- 0.0736375 I
In[167]:=
h2[p_?NumericQ] :=
NIntegrate[f[x, p, 1*I*x]*(p^2/2), {x, -Infinity, Infinity},
Method -> {Automatic, "SymbolicProcessing" -> False}]
NIntegrate[h2[p], {p, -Infinity, Infinity}]
Out[168]= 0.25\[VeryThinSpace]- 1.29797*10^-11 I
In[169]:= Plot[Re@h[p], {p, -10, 10}, PlotRange -> All]
In[170]:= Plot[Re@h2[p], {p, -10, 10}, PlotRange -> All]
In[171]:= Plot[Im@h[p], {p, -10, 10}, PlotRange -> All]
In[172]:= Plot[Im@h2[p], {p, -10, 10}, PlotRange -> All]
NIntegrate
has trouble figuring out where the integrand is concentrated. But I confess that's just a guess. $\endgroup$