# Evaluating $\int_0^\infty \frac{dx}{\sqrt{x}[x^2+(1+2\sqrt{2})x+1][1-x+x^2-x^3+…+x^{50}]}$

My brother’s friend gave me the following wicked integral with a beautiful result

$$\begin{equation} {\Large\int_0^\infty} \frac{dx}{\sqrt{x} \bigg[x^2+\left(1+2\sqrt{2}\right)x+1\bigg] \bigg[1-x+x^2-x^3+\cdots+x^{50}\bigg]}={\large\left(\sqrt{2}-1\right)\pi} \end{equation}$$

He claimed the above integral can be generalised to the following form
$$\begin{equation} {\Large\int_0^\infty} \frac{dx}{\sqrt{x} \bigg[x^2+ax+1\bigg] \bigg[1-x+x^2-x^3+\cdots+(-x)^{n}\bigg]}=\ldots \end{equation}$$
This is a challenging problem. How to prove it and what is the closed-form of the general integral?

$$I(n,a)=\int_0^\infty\frac{dx}{\sqrt{x}(1+ax+x^2)(\sum_{k=0}^n(-x)^k)}$$
The change of variables $x\leftarrow 1/x$ yields
$$I(n,a)=\int_0^\infty\frac{(-1)^nx^{n+1}dx}{ \sqrt{x}(1+ax+x^2)(\sum_{k=0}^n(-x)^k)}$$
$$2I(n,a)=\int_0^\infty\frac{1+x}{\sqrt{x}(1+ax+x^2)}dx= 2\int_0^\infty\frac{1+t^2}{ 1+at^2+t^4}dt$$
Or equivalently, setting $u=t-1/t$,
$$I(n,a)= \int_{-\infty}^\infty\frac{du}{ 2+a+u^2} =\frac{\pi}{\sqrt{2+a}}.$$