# Definite integral of real function outputting complex values

I'm trying to integrate the function $$f(\omega)$$ from $$-\infty$$ to $$\infty$$, where

$$f(\omega) = \begin{cases} \frac{(1-2 \omega )^2}{64 \cos (\tau (-\omega +\phi +1))-80} & 0<\omega \leq 1 \\ \frac{(2 \omega +1)^2}{80-64 \cos (\tau (\omega -\phi +1))} & -1<\omega \leq 0\\ 0 & |\omega| >= 1 \end{cases}$$

using Mathematica. All the parameters are real, therefore the function is real. There seem to be many similar questions in stack, most of them seem to be related to indefinite integrals, singularities or numerical instabilities. Here none of these apply, as Mathematica gives an output for the analytic integral, yet it's a complex function (output is too big to include here). Here is the code I'm using to Integrate

Integrate[
((1 + 2 ω)^2/(80 -
64 Cos[τ (1 - ϕ + ω)]) UnitBox[ω +
1/2] + (1 - 2 ω)^2/(-80 +
64 Cos[τ (1 + ϕ - ω)]) UnitBox[ω - 1/2])
, {ω, -∞, ∞}, Assumptions -> {τ ∈ Reals, -1/2 < ϕ < 12, ω ∈ Reals}]


For example, the output applied to $$\phi = 1/10$$ and $$\tau = 1/4$$ is $$15.7655 - 4.64552 I$$.

I've attempted changing the assumptions with no success, and other small changes to the function, like changing UnitBox to how Mathematica handles piecewise functions like the first equation in this question (I failed to include the code like that here).

I'm not interested in numerical integration of this function, it's important that it's the analytical expression, though of course, it could just not be possible which is fine.

Is this a bug in Mathematica? Seems like it gives an answer, but it's wrong. Am I missing something, and is this integral doable?

• I apologize for the ridiculous formatting of the LaTeX equation, but this is the only way I found such that the question could be accepted as "properly formatted".
– peep
Commented Nov 3, 2023 at 12:11

## 1 Answer

Too long for a comment. First, I confirm it in 13.3.1 on Windows 10. Second, this is a complicated integral. If we split the integral into two ones, then

j1 = Integrate[(1 + 2 \[Omega])^2/(80 -  64 Cos[\[Tau] (1 - \[Phi] + \[Omega])]) ,
{\[Omega], -1, 0}, Assumptions -> {\[Tau] \[Element] Reals, -1/2 < \[Phi] < 12}]


ConditionalExpression[ 1/(48 \[Tau]^3) I (\[Tau]^2 Log[1 - 2 E^(I \[Tau] (-1 + \[Phi]))] - \[Tau]^2 Log[ 2 - E^(I \[Tau] (-1 + \[Phi]))] - \[Tau]^2 Log[ 1 - 2 E^(I \[Tau] \[Phi])] + \[Tau]^2 Log[ 2 - E^(I \[Tau] \[Phi])] - 4 I \[Tau] PolyLog[2, 1/2 E^(I \[Tau] (-1 + \[Phi]))] + 4 I \[Tau] PolyLog[2, 2 E^(I \[Tau] (-1 + \[Phi]))] - 4 I \[Tau] PolyLog[2, 1/2 E^(I \[Tau] \[Phi])] + 4 I \[Tau] PolyLog[2, 2 E^(I \[Tau] \[Phi])] - 8 PolyLog[3, 1/2 E^(I \[Tau] (-1 + \[Phi]))] + 8 PolyLog[3, 2 E^(I \[Tau] (-1 + \[Phi]))] + 8 PolyLog[3, 1/2 E^(I \[Tau] \[Phi])] - 8 PolyLog[3, 2 E^(I \[Tau] \[Phi])]), (\[Phi] >= 1 || \[Phi] <= 0) && 2 Cos[\[Tau] (-1 + \[Phi])] <= 1]

and j1 fails for \[Phi]==1/10. Third,

NIntegrate[((1 + 2 \[Omega])^2/(80 -
64 Cos[\[Tau] (1 - \[Phi] + \[Omega])]) UnitBox[\[Omega] +
1/2] + (1 - 2 \[Omega])^2/(-80 +
64 Cos[\[Tau] (1 + \[Phi] - \[Omega])]) UnitBox[\[Omega] -
1/2]) /. {\[Phi] -> 1/10, \[Tau] ->
1/4}, {\[Omega], -\[Infinity], \[Infinity]}]


works well, resulting in 0.000438183 as well as the integral from -2 to 2.

• Integrate[((1 + 2 \[Omega])^2/(80 - 64 Cos[\[Tau] (1 - \[Phi] + \[Omega])]) UnitBox[\[Omega] + 1/2] + (1 - 2 \[Omega])^2/(-80 + 64 Cos[\[Tau] (1 + \[Phi] - \[Omega])]) UnitBox[\[Omega] - 1/2]) /. {\[Phi] -> 1/10, \[Tau] -> 1/4}, {\[Omega], -2, 2}] // N performs 0.000438183 + 1.57646*10^-14 I Commented Nov 3, 2023 at 13:45
• tried with some other values as well, mathematica can apparently solve this in some regions, but for some reason it's giving the output as if it's the solution everywhere, where probably there are conditions in the variables that it's not saying. Annoying, likely a bug.
– peep
Commented Nov 3, 2023 at 18:45