Integral of $\frac{1}{x^2+x+1}$ and$\frac{1}{x^2-x+1}$ How to integrate two very similar integrals. I am looking for the simplest approach to that, it cannot be sophisticated too much as level of the textbook this was taken from is not very high. $$\int \frac{1}{x^2+x+1} dx$$ and$$\int \frac{1}{x^2-x+1} dx$$
 A: For the first one:
$$
\int { \frac { 1 }{ 1+{ x }^{ 2 }+x }  } dx\quad =\quad \quad \int { \frac { 1 }{ { x }^{ 2 }+x+\frac { 1 }{ 4 } +\frac { 3 }{ 4 }  } dx } \\ \qquad \qquad \qquad \qquad =\quad \int { \frac { 1 }{ { \left( x+\frac { 1 }{ 2 }  \right)  }^{ 2 }+\frac { 3 }{ 4 }  } dx } \\ \qquad \qquad \qquad \qquad \quad =\quad \frac { 4 }{ 3 } \int { \frac { 1 }{ 1+{ \left( \sqrt { \frac { 4 }{ 3 }  } \left( x+\frac { 1 }{ 2 }  \right)  \right)  }^{ 2 } }  } dx\\ \qquad \qquad \qquad \qquad \quad =\quad  \frac { 2 }{ \sqrt{3} }   \arctan { \left( \frac { 2 }{ \sqrt{3} }   \left( x+\frac { 1 }{ 2 }  \right)  \right)  }  +C
$$
The second one will be the same just a minus instead of a plus:
$$
 \frac { 2 }{ \sqrt{3} }   \arctan { \left( \frac { 2 }{ \sqrt{3} }   \left( x-\frac { 1 }{ 2 }  \right)  \right)  }  +C
$$
Here's a general formula for $\int \frac{1}{ax^2+bx+c}dx$, when $b^2-4ac<0$:
$$
\int { \frac { 1 }{ a{ x }^{ 2 }+bx+c }  } dx\quad =\frac { 1 }{ a } \quad \int { \frac { 1 }{ { x }^{ 2 }+\frac { b }{ a } x+\frac { c }{ a }  }  } dx\\ \qquad \qquad \qquad \qquad \quad =\quad \frac { 1 }{ a } \int { \frac { 1 }{ { x }^{ 2 }+\frac { b }{ a } x+\frac { { b }^{ 2 } }{ 4{ a }^{ 2 } } +\frac { c }{ a } -\frac { { b }^{ 2 } }{ 4{ a }^{ 2 } }  } dx } \\ \qquad \qquad \qquad \qquad \quad =\quad \frac { 1 }{ a } \int { \frac { 1 }{ { \left( x+\frac { b }{ 2a }  \right)  }^{ 2 }+\frac { c }{ a } -\frac { { b }^{ 2 } }{ 4{ a }^{ 2 } }  }  } dx\\ \qquad \qquad \qquad \qquad \quad =\quad \frac { 1 }{ a\left( \frac { c }{ a } -\frac { { b }^{ 2 } }{ 4{ a }^{ 2 } }  \right)  } \int { \frac { 1 }{ 1+{ \left( \frac { x+\frac { b }{ 2a }  }{ \sqrt { \frac { c }{ a } -\frac { { b }^{ 2 } }{ 4{ a }^{ 2 } }  }  }  \right)  }^{ 2 } } dx } \\ \qquad \qquad \qquad \quad =\quad \frac { \sqrt { \frac { c }{ a } -\frac { { b }^{ 2 } }{ 4{ a }^{ 2 } }  }  }{ c-\frac { { b }^{ 2 } }{ 4a }  } \arctan { \left( \frac { x+\frac { b }{ 2a }  }{ \sqrt { \frac { c }{ a } -\frac { { b }^{ 2 } }{ 4{ a }^{ 2 } }  }  }  \right)  } +C
$$
A: In both cases, complete the square,  substitute, and use 
$$\int\frac 1{u^2+1}\,du=\tan^{-1}u$$
Completing the square gives you
$$\int\frac 1{x^2+x+1}\,dx=\int\frac 1{\left(x+\frac 12\right)^2+\frac 34}\,dx$$
The second is similar,
$$\int\frac 1{x^2-x+1}\,dx=\int\frac 1{\left(x-\frac 12\right)^2+\frac 34}\,dx$$
A: HINT:
Write $x^2\pm x+1=\left(x\pm\frac12\right)^2+\frac34$.  Then, make use 
$$\int \frac{1}{t^2+a^2}dt=\frac1a \arctan(t/a)+C$$
for $a>0$
SPOILER ALERT: SCROLL OVER SHADED AREA TO SEE THE ANSWER

$$\int \frac{1}{x^2\pm x+1}\,dx=\int \frac{1}{\left(x\pm\frac12\right)^2+\frac34}\,dx=\frac{2\sqrt{3}}{3}\arctan\left(\frac{2\sqrt{3}}{3}\left(x\pm \frac12\right)\right)+C$$

A: For the first one write $x^2 + x + 1 = (x + 1/2)^2 + 3/4$ and the second one $x^2 - x + 1 = (x - 1/2)^2 + 3/4$ these both are arctan 
A: First recall that if $a,b,c$ are real numbers then $ax^2+bx+c$ can be factored using real numbers if and only if $b^2-4ac\ge 0$.  For your first polynomial above you have $a=b=c=1$ so $b^2-4ac=-3$, so you would need complex numbers to factor it.
Then recall that there is a standard technique in algebra for reducing a problem involving a quadratic polynomial with a first-degree term to a quadratic polynomial with no first degree term, namely completing the square.  You get
$$
x^2+x+1 = \left( x^2 + x + \frac 1 4 \right) + \frac 3 4 = \left( x + \frac 1 2 \right)^2 + \frac 3 4.
$$
Then you would like $\displaystyle \int \frac 1 {(\text{square})+1} \, dx$ so that you get an arctangent.  So write
$$
\left( x + \frac 1 2 \right)^2 + \frac 3 4 = \frac 3 4 \left( \left( \frac{2x+1}{\sqrt 3} \right)^2 + 1 \right) = \frac 3 4 (u^2 + 1) \quad\text{and}\quad dx = \frac{\sqrt 3} 2\, du.
$$
A: $$\int { \frac { dx }{ { x }^{ 2 }+x+1 } =\int { \frac { dx }{ { \left( x+\frac { 1 }{ 2 }  \right)  }^{ 2 }+\frac { 3 }{ 4 }  }  }  } =\int { \frac { d\left( x+\frac { 1 }{ 2 }  \right)  }{ { \left( x+\frac { 1 }{ 2 }  \right)  }^{ 2 }+\frac { 3 }{ 4 }  }  } =\frac { 2 }{ \sqrt { 3 }  } \arctan { \left( \frac { 2 }{ \sqrt { 3 }  } \left( x+\frac { 1 }{ 2 }  \right)  \right) \quad +C }  $$
