Optimal evaluation of polynomials / rational functions
In Knuth Vol II Theorem E on page 494 he presents an algorithm that can evaluate a polynomial using $\frac{n}{2} + 2$ multiplications. The theoretical minimum is $\frac{n}{2}$, assuming generic polynomials. The algorithm requires factoring polynomials. There is another algorithm from Rabin &amp; Winograd that only requires division, but runs in $\frac{n}{2} + \log n$.

Your question is about automatically identifying special structure that can be exploited to optimize further, which these algorithms do not do.

Square-free factorization can be used to efficiently find repeated terms like $p(x)\cdot (q(x))^7$. It won't find your sum example.

If $n$ is not too big, it might actually be feasible to iterate through all circuits with $\frac{n}{2} + 1$ multiplication gates and arbitrary addition/subtraction gates. Reduce them symbolically to coefficient form and try to solve the resulting set of polynomial equations. I guess this last step would the hardest.