I want to factorize the following polynomial in MATHEMATICA: $1 - 2 r + r^2 - 2 s + 2 r s + s^2 - 2 t + 2 r t + 2 s t - 4 r s t + t^2$.
1 - 2 r + r^2 - 2 s + 2 r s + s^2 - 2 t + 2 r t + 2 s t - 4 r s t + t^2
If done by hand it is easy to see that the above expression can be written in the form of (a+b)(a-b) as: $(-1 + r + s + t)^2 - (2 \sqrt{r s t})^2$.
I tried using the "Factor" command in MATHEMATICA but it doesn't help, so if there is any command or any code that can help me with the same is appreciated.
Edit: This specific factorization is required as I want the degree of each factored part to be 1. And also if there is any general algorithm so as to obtain factorization for such polynomials in $(a-b)(a+b)$ form so that it can be used with other such polynomials too.
Factor[poly + 4 r s t] - 4 r s t
works. There's also a polynomial in r,FullSimplify[poly]
givingr^2 + (-1 + s + t)^2 + 2 r (-1 + s + t - 2 s t)
$\endgroup$Solve[(a - b) (a + b) == poly, {a, b}]
$\endgroup$Solve[1-2 r+r^2-2 s+2 r s+s^2-2 t+2 r t+2 s t-4 r s t+t^2==0,{r}]/.{Rule->Subtract,List->Times}
$\endgroup$