Finding $\int\frac{x^2-1}{\sqrt{x^4+x^2+1}}$

Elliptic integral of the first kind is $$E_1(\varphi, k) = \int\limits_0^\varphi \dfrac{d\theta}{\sqrt{1-k^2\sin^2\theta}} = \int\limits_0^{\sin\varphi}\dfrac{1}{\sqrt{(1-t^2)(1-k^2t^2)}}\,dt.$$

Elliptic integral of the second kind is $$E_2(\varphi, k) = \int\limits_0^\varphi \sqrt{1-k^2\sin^2\theta}\,d\theta = \int\limits_0^{\sin\varphi}\sqrt{\dfrac{1-k^2t^2}{1-t^2}}\,dt.$$

At first, $$1 + x^2 + x^4 = \left(1 + \dfrac12 x^2\right)^2 - \left(i\dfrac{\sqrt3}{2}\right)^2x^4$$ $$ = \left(1 + \left(\cos\dfrac{\pi}3 - i\sin\dfrac{\pi}3\right)x^2\right)\left(1 + \left(\cos\dfrac{\pi}3 + i\sin\dfrac{\pi}3\right)x^2\right)$$ $$ = \left(1 + e{\large{^{-\frac{\pi}3i}}}x^2\right)\left(1 + e{\large{^{\frac{2\pi}3i}}}e{\large{^{-\frac{\pi}3i}}}x^2\right) = \left(1 - e{\large{^{\frac{2\pi}3i}}}x^2\right)\left(1 - e{\large{^{\frac{2\pi}3i}}}e{\large{^{\frac{2\pi}3i}}}x^2\right)$$ $$ = \left(1 - \bigl(e{\large{^{\frac{\pi}3i}}}x\bigr)^2\right)\left(1 - \bigl(e{\large{^{\frac{\pi}3i}}}\bigr)^2\bigl(e{\large{^{\frac{\pi}3i}}}x\bigr)^2\right).$$

Let $$k = e{\large{^{\frac{\pi}3i}}},\quad t = kx,$$ then $$I = \int\dfrac{x^2 - 1}{\sqrt{x^4 + x^2 + 1}}dx = \frac1{k^3}\int\dfrac{t^2 - k^2}{\sqrt{(1-t^2)(1-k^2t^2)}}dt.$$

The ratio can be presented in the form of $$\dfrac{t^2 - k^2}{\sqrt{(1-t^2)(1-k^2t^2)}} = \dfrac{A}{\sqrt{(1-t^2)(1-k^2t^2)}} + B\,\sqrt{\dfrac{1-k^2t^2}{1-t^2}},$$ where $$t^2 - k^2 = A + B(1 - k^2t^2),\quad A + B = -k^2,\quad -k^2B = 1,$$ $$B = -\frac1{k^2},\quad A = \frac{1 - k^4}{k^2}.$$

Since $k^6 = 1,$ then $$I = \left(k - \dfrac1k\right)\int\dfrac{dt}{\sqrt{(1-t^2)(1-k^2t^2)}} - k\int\,\sqrt{\dfrac{1-k^2t^2}{1-t^2}}\,dt = {\left(k - \dfrac1k\right)E_1(\arcsin t, k) - kE_2(\arcsin t, k) + const},$$


$$\int\dfrac{x^2 - 1}{\sqrt{x^4 + x^2 + 1}}dx = \left(k - \dfrac1k\right)E_1\left(\arcsin \left(\frac{x}{k}\right), k\right) - kE_2\left(\arcsin\left(\frac{x}{k}\right), k\right) + const,\quad \text{ where } k = e^{\large{\frac\pi3i}}.$$

Differentiation shows the result is correct.