# How can I do a faster integration?

I have this part of my code, which takes forever to run. Does anybody know how to make it faster?

Using NIntegrate I face error: "NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained 7.38363*10^-15-7.76592*10^-15 I and 5.976982225106196*^-10 for the integral and error estimates."

ℓ0 = 3;
dvec = {Sin[2 Pi/2 Sin[θ]] Cos[ϕ - Pi/2],
Sin[2 Pi/2 Sin[θ]] Sin[ϕ - Pi/2],
Cos[2 Pi/2 Sin[θ]]}

σvec = {PauliMatrix, PauliMatrix, PauliMatrix}

bhat = 1000 Abs[dvec].σvec

F = Table[
Integrate[
1.*Conjugate[SphericalHarmonicY[ℓ0, i, θ, ϕ]] bhat SphericalHarmonicY[ℓ0, j, θ, ϕ],
{ϕ, 0, 2 π}, {θ, 0, π}
],
{i, -ℓ0, ℓ0}, {j, -ℓ0, ℓ0}
];

• Try NIntegrate . – Ulrich Neumann Jan 30 at 19:27
• There are two problems here: (i) spherical harmonics oscillate quite a lot and (ii) they are extraordinary slow in Mathematica... – Henrik Schumacher Jan 30 at 19:29
• even when I try NIntegrate it give me thie error: 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. – Delaram Nematollahi Jan 30 at 19:32
• If I compare Length[Union[Flatten[Simplify[Table[withoutintegrating],0<=ϕ<=2 π&&0<=θ<=π]]]] with Length[Flatten[Simplify[Table[withoutintegrating],0<=ϕ<=2 π&&0<=θ<=π]]] I see 30% of your integrands are duplicates. Might be even more if I removed constant multiples. Perhaps you might be able to take advantage of this to speed your problem up – Bill Jan 30 at 22:39
• You can replace Conjugate[SphericalHarmonicY[ℓ0, i, θ, ϕ]] with SphericalHarmonicY[ℓ0, i, θ, -ϕ]`. – Roman Feb 7 at 18:01