# Factorizing a polynomial with two variables

Hi, I would like to factorize the following polynomial in $t$, with an integer indeterminate $n$,

$f_n(t) = 2^n ((n-1)t^n+1)^{n-1} - n^{n-1} t^{(n-1)(n-2)} (t^{n-1} + 1)(t+1)^{n-1}$

I expect it to have a factor of $(t-1)^2$ and hope that after division the polynomial in $t$ would have positive coefficients.

Is there any way I can verify this by Sage?

I have tried to check that $f_n(t)$ has a factor of $(t-1)^2$ by checking that $f_n(1) = f_n'(1) = 0$. I named my polynomial $f$, and let $h$ be f.derivative(t), and try to find $h(t=1)$. Here's what I got,

(n - 1)^2

2^nnn^(n - 2) - (n - 1)2^(n - 1)n^(n - 1) - 2(n - 1)2^(n - 2)n^(n - 1) - 2(n^2 - 3n + 2)2^(n - 1)n^(n - 1)

Which turns out to be 0 when I verify by hand. However it seems like Sage is unable to detect the redundance in the expression (e.g. $n \times n^{n-2} = n^{n-1}$). Did I do the computation in the "wrong way"? If so, what's the proper way to do it?

Thanks!