How do I integrate this rational function? Evaluate this integral
$$I=∫\dfrac{1-x^2}{x^4+x^2+1}dx$$ (with $x$ is different from 0).
I tried divided both the numerator and denominator by $x^2$, and I got $$∫\dfrac{\frac{1}{x^2}-1}{x^2+\frac{1}{x^2}+1}dx.$$
I then put $t=x+1/x$ and got this $$I=∫-\dfrac{dt}{t^2-1}.$$
Finally I got the answer
$$\dfrac12{\ln|-x^2-\dfrac{1}{x^2}-1|}+C$$
or the alternative form is
$$\dfrac{\ln\left(\left|x^2+x+1\right|\right)+\ln\left(\left|x^2-x+1\right|\right)-2\ln\left(\left|x\right|\right)}{2}+C. $$ Where did I make mistake? Because when I compute the function, the result is different $$\dfrac{\ln\left(x^2+x+1\right)-\ln\left(x^2-x+1\right)}{2}+C.$$

Since xpaul answered your question. Notice that another way is using partial fraction and we get
$$\frac{1-x^2}{x^4+x^2+1}=\frac{1}2\underbrace{\left(\frac{1+2x}{1+x+x^2}\right)}_{(*)}+\frac{1}{2}\underbrace{\left(\frac{1-2x}{1-x+x^2}\right)}_{(**)}$$
For $(*)$ substitution $u(x)=1+x+x^2$ and for $(**)$ substitution $v(x)=1-x+x^2$ in the integration.
Edit:

*

*$x^4+x^2+1=(x^2+1)^2-x^2=(x^2+x+1)(x^2-x+1)$.

*In partial fraction we want find constant $A,B,C$ and $D$ such that
$$\frac{1-x^2}{x^4+x^2+1}=\frac{A+Bx}{x^2+x+1}+\frac{C+Dx}{x^2-x+1}$$ That implies logically that
$$1-x^2=(A+Bx)(x^2+x+1)+(C+Dx)(x^2-x+1)$$
Then, a way to find the constants is using roots of the polynomial (in this case it is not useful) and other way it is solving the linear system with the coefficients (expanding and grouping). The second method work here.

