\(P=\frac{2x^5-x^4-2x+1}{4x^2-1}+\frac{8x^2-4x+2}{8x^3+1}\)
\(=\frac{x^4\left(2x-1\right)-\left(2x-1\right)}{\left(2x-1\right)\left(2x+1\right)}+\frac{2\left(4x^2-2x+1\right)}{\left(2x+1\right)\left(4x^2-2x+1\right)}\)
\(=\frac{\left(x^4-1\right)\left(2x-1\right)}{\left(2x-1\right)\left(2x+1\right)}+\frac{2\left(4x^2-2x+1\right)}{\left(2x+1\right)\left(4x^2-2x+1\right)}\)
\(=\frac{\left(x^4-1\right)\left(2x-1\right)\left(4x^2-2x+1\right)+2\left(2x-1\right)\left(4x^2+2x+1\right)}{\left(2x-1\right)\left(2x+1\right)\left(4x^2-2x+1\right)}\)
\(=\frac{\left(2x-1\right)\left(4x^2-2x+1\right)\left(x^4-1+2\right)}{\left(2x-1\right)\left(2x+1\right)\left(4x^2-2x+1\right)}\)
\(=\frac{x^4+1}{2x+1}\)