Relation between the roots of a function
I have this question from my exam where it's asked to find the sum: $$S=\sum_{k=1}^n \frac{1}{(1-r_k)^2}$$ where $r_k$ are the roots of $$f(x)=x^n-2x+2\quad,n\ge3$$ I recalled this relation $$\frac{f'(x)}{f(x)}=\sum_{k=1}^n \frac{1}{x-r_k}$$ and quickly realised that $$\frac{d}{dx}\frac{1}{x}=-\frac{1}{x^2}$$ and using derivative would easily produce my answer. Indeed $$\frac{d}{dx}\left( \frac{f'(x)}{f(x)} \right)=\frac{f''(x)f(x)-(f'(x))^2}{f(x)^2}=-\sum_{k=1}^n \frac{1}{(x-r_k)^2}$$ Evaluating at $x=1$ gives $$S=\frac{(n-2)^2-n(n-1)}{1^2}=4-3n$$ However after the exam I realised that I have no ideea why $$\frac{f'(x)}{f(x)}=\sum_{k=1}^n \frac{1}{x-r_k}$$ and I just memorized it, is there a nice way to show it? And of course maybe a more elegant solution to this exam question?
$$f(x)=(x-r_1)(x-r_2)\cdots(x-r_n)$$
Using logarithm,
$$\ln (f(x))=\ln (x-r_1)+\ln(x-r_2)+\cdots +\ln(x-r_n)$$
Taking derivative,
$$\frac{f'(x)}{f(x)}= \frac{1}{(x-r_1)}+\frac{1}{(x-r_2)} +\cdots +\frac{1}{(x-r_n)}$$
Done!
While Jaideep Khare's computation with the logarithm gives a good quick way to memorize or derive the result, there is an issue: The logarithms of negative numbers are not defined if one works over the reals, and care must be taken with branches if one moves to the complex plane. When $r_k$ is fixed and $x$ ranges through all the reals, $x-r_k$ will inevitably get negative values.
Here is a way to prove the desired result without resorting to logarithms: By the fundamental theorem of algebra a polynomial can be written in terms of its roots and a coefficient $a\in\mathbb C$ as $$ f(x) = a(x-r_1)\cdots(x-r_n). $$ The coefficient of $x^n$ is $a$ and in your case you know it to be $1$, but it is unimportant. The derivative can be computed by differentiating each term in the product in turn: $$ f'(x) = a(x-r_2)\cdots(x-r_n) + a(x-r_1)(x-r_3)\cdots(x-r_n) + \dots + a(x-r_1)\cdots(x-r_{n-1}), $$ where in the $n$th term of the sum the $n$th term of the product has been dropped. When $f(x)\neq0$, it is easy to divide each term of $f'(x)$ by $f(x)$, and we get $$ \frac{f'(x)}{f(x)} = \frac{1}{x-r_1} + \frac{1}{x-r_2} +\dots+ \frac{1}{x-r_n}. $$
The result and the proof are also applicable to complex polynomials, whereas with logarithms $f(z)$ will always hit the branching set of the logarithm, no matter how you choose it. Also, $\log(ab)=\log(a)+\log(b)$ is not true in general for complex $a$ and $b$.
Finally, let me emphasize that this result holds for a polynomial function $f$ (with roots counted with multiplicity), not for all functions in general. In your question you are working with polynomials but you speak about "functions", so beware of generalizing the result beyond what's true.