I made an implementation of Newton's method (starting at $x=\pi$) for polynomials in the programming language Uiua (here it is if you are interested, but be warned that Uiua looks weird). It works fine for most polynomials but there are a few that it gets stuck on. I tried [12 ¯9 ¯21 37 ¯41 ¯10 31 49], (a degree 7 polynomial with coefficients listed from lowest degree to highest) and the execution time ran out. Inspecting further, it seems to be oscillating somewhat randomly in the range $[0.3,0.7]$, even after 500+ iterations, when the actual answer is $-0.568$. Another online implementation also fails to converge when starting at $x=\pi$.
My question is whether Newton's method should be working in this case or if I should expect to find there is some problem in my code or in the way that Uiua handles floats. Does Newton's method always converge for polynomials?



Here is a plot of the function $$f(x) = 49 x^7+31 x^6-10 x^5-41 x^4+37 x^3-21 x^2-9 x+12$$ in the region of interest. The blue curve is $f$. The orange lines represent the forward orbit of $x_0 = \pi$ under $x \mapsto x - f(x)/f'(x)$, connecting $(x_i, f(x_i))$ to the next iterate $(x_{i+1}, 0)$, then to $(x_{i+1}, f(x_{i+1}))$, and so forth. Note that the initial iterations are not shown because the value of the function at these points is large.
The thick red line shows the steady-state behavior of the orbit, and we can see this will converge to a $3$-cycle of values, which are approximately $$S = \{0.355634, 0.796309, 0.680185\}.$$
This suggests that for any $x \in S$, the rational function $$g(x) = x - \frac{f(x)}{f'(x)} = \frac{294 x^7+155 x^6-40 x^5-123 x^4+74 x^3-21 x^2-12}{343 x^6+186 x^5-50 x^4-164 x^3+111 x^2-42 x-9}$$ satisfies $$g(g(g(x))) = x.$$
Indeed, we can hypothesize that whenever $f$ has a neighborhood with a local minimum but no root, then there is the possibility of an initial choice $x_0$ for which the forward orbit does not converge to a root.