How to make Mathematica gives the right answer for this integral $\int_{-\infty}^\infty \frac{\mathrm dx}{(a^2 - x^2)^2 + (bx)^2}$?

I'm trying to compute the following integral with Mathematica: $$\int_{-\infty}^\infty \frac{\mathrm dx}{(a^2 - x^2)^2 + (bx)^2} = \pi/ab^2$$. Source . Somehow, even if I assume $$a>0$$ and $$b>0$$, it predicts the strange answer:$$\frac{\pi \left(\sqrt{\left(a^2-4 b^2\right) \left(a \left(\sqrt{a^2-4 b^2}+a\right)-2 b^2\right)}-\sqrt{\left(a^2-4 b^2\right) \left(-a \sqrt{a^2-4 b^2}+a^2-2 b^2\right)}\right)}{\sqrt{2} b^2 \left(a^3-4 a b^2\right)}$$

which does not match the result given above. It does get it right though, if I directly replace $$a$$ and $$b$$ with real numbers.

The same thing happens for $$\int_{-\infty}^\infty \frac{\mathrm dx}{(1 - x^2)[(a^2 - x^2)^2 + (bx)^2]}$$. It again gives the right answer when $$a$$ and $$b$$ are given real values but outputs a complete mess otherwise.

Assuming the anti-derivative is continuous between the limits you gave then

integrand = 1/( (a^2 - x^2)^2 + (b*x)^2);
<< Rubi
Assuming[b > 0, Simplify[Int[integrand, {x, -Infinity, Infinity}]]]


Since this gives same answer you showed, then I assume the anti-derivative is continuous and Fundamental Theorem of Calculus can be applied, since this is what Rubi does. Rubi is meant for indefinite integrals, but can be used for definite integrals by applying FTOC, but it does not check if the anti-derivative is continuous or not. This is up to the user to do, otherwise wrong answer will result.

To install Rubi, the command is

PacletInstall["https://rulebasedintegration.org/Rubi-4.16.1.0.paclet"]

• why do you need to assume b>0? Commented Dec 9, 2023 at 22:13
• @chris without b>0, you get a little less simplified version. !Mathematica graphics so b>0 is needed just to pull b^2 out of the sqrt. Commented Dec 10, 2023 at 1:40
Integrate[1/((a^2-x^2)^2+(b x)^2),{x,-Infinity,Infinity},Assumptions->{a>0,b>0}]
Solve[Reduce[y==%,b,Reals],y,Reals]//Simplify


$$\fbox{\frac{\sqrt{2} \pi }{a^2 \left(\sqrt{b \left(b-\sqrt{b^2-4 a^2}\right)-2 a^2}+\sqrt{b \left(\sqrt{b^2-4 a^2}+b\right)-2 a^2}\right)}\text{ if }2 a\leq b}$$

$$\left\{\left\{y\to \fbox{\frac{\pi }{a^2 b}\text{ if }b>0\land 2 a+b>0\land 2 a

f[a_, b_] := Integrate[1/((a^2 - x^2)^2 + (b x)^2), {x, -Infinity, Infinity}];
list = Outer[f, Range@5, Range@5];
FindSequenceFunction[FindSequenceFunction[#, b] & /@ list, a]


$$\frac{\pi }{a^2 b}$$

The integral is undefined over the real line for a, b real. For complex coefficients the integral depends on the position of the four symmetric zeros of the denumerator in $$y=y^2$$

  zeros = x^2 /. Solve[(a^2 - x^2)^2 + (b x)^2 == 0, x] // Factor //
PowerExpand // Union


$$\left\{\frac{1}{2} \left(-i b \sqrt{4 a^2-b^2}+2 a^2-b^2\right),\quad \frac{1}{2} \left(i b \sqrt{4 a^2-b^2}+2 a^2-b^2\right)\right\}$$

The indefinite integral

     F[x_] = Integrate[(2 Sqrt[y])/((a^2 - y)^2 y + y b ^2),y] /.
{Sqrt[y] :> x} // TrigToExp
`

has a rather indefinite value

$$\frac{\log \left(1+\frac{i x}{\sqrt{-a^2+i b}}\right)}{b \sqrt{-a^2+i b}}+\frac{\log \left(1-\frac{i x}{\sqrt{-a^2-i b}}\right)}{b \sqrt{-a^2-i b}}-\frac{\log \left(1-\frac{i x}{\sqrt{-a^2+i b}}\right)}{b \sqrt{-a^2+i b}}-\frac{\log \left(1+\frac{i x}{\sqrt{-a^2-i b}}\right)}{b \sqrt{-a^2-i b}}$$

Taking the integral over $$x^2$$ its clear, the the value is $$2 F(x\to\infty)$$

Those intergrals my formally appear as solutions of differential equations in mathematical physics with real coefficients. Inthese cases limits of different paths surrounding possible real zeros on a small imaginary circle yield different modes of solutions.