What is the biggest circle that is contained in the region bounded by the graph of the polynomial $f(x) = x(1-x)(2x+1)$ and the x-axis interval $[0, 1]$?
Here's what I have tried
Let's denote the center of the circle by $(c_x, c_y)$ and the points of tangency by $(x_k, y_k)$, $k=1,2$. From distance to the x-axis, we know that the radius of the circle is then $c_y$. We can express the tangency by the dot product of the vectors $(x_k-c_x, y_k-c_y)$ and $(1, f'(x_k))$ being zero. So we get the group of equations (all for $k=1,2$)
$$\begin{cases} (x_k-c_x)^2 + (y_k-c_y)^2 &=& c_y^2 \\ x_k-c_x + (y_k-c_y)f'(x_k) &=& 0 \\ f(x_k) &=& y_k \end{cases} $$
Then I tried to solve this group by using Gröbner basis and elimination ideals. I wrote this SageMath code:
f(x) = x*(1-x)(2*x+1)
fd = f.derivative()
R.<x1, y1, x2, y2, cx, cy> = PolynomialRing(QQ, order='lex')
polys1 = [(cx-xk)**2+(cy-yk)**2 - cy**2 for (xk, yk) in [(x1,y1), (x2, y2)]]
polys2 = [(xk-cx)+(yk-cy)*fd(xk) for (xk, yk) in [(x1,y1), (x2, y2)]]
polys3 = [f(xk)-yk for (xk, yk) in [(x1,y1), (x2, y2)]]
I = R.ideal(polys1+polys2+polys3)
gb = I.groebner_basis()
for poly in gb:
print (poly)
print (I.dimension())
It gave me a long list of polynomials, the last one being
$$c_x^6 - 2c_x^4c_y^2 + \frac{5}{4}c_x^4c_y + \frac{1}{64}c_x^4 + c_x^2c_y^4 + \frac{3}{4}c_x^2c_y^3 + \frac{3}{16}c_x^2c_y^2 + \frac{1}{64}c_x^2c_y$$
and said the dimension is $1$. I now realize the reason we don't get dimension $0$ has probably to do with the fact that the points $(x_1, y_1)$ and $(x_2, y_2)$ could be the same point(?) So for a solution, the point $(c_x, c_y)$ should be a zero of that polynomial? But is even that correct, since the points could be collapsed and the other side go over the curve??
How to solve this even numerically? I tried with Sage by minimizing the square sum of all those polynomials that should be zero. I also tried adding constraints for the variables to be near the solution that can be seen from the picture but that didn't work either.


We have
$$ \cases{ y = x(1-x)(2x+1)\\ (x-x_0)^2+(y-y_0)^2=y_0^2 } $$
substituting the first into the second we have
$$ p(x)=(x-x_0)^2+(x(1-x)(2x+1)-y_0)^2-y_0^2 = 0 $$
This polynomial at tangency should have the following structure
$$ p(x) = c(x-x_1)^2(x-x_2)^2((x-a)^2+b^2)\ \ \ \ (\text{Why?}) $$
now comparing coefficients we have
$$ 0=\eta = \left\{ \begin{array}{l} x_0^2-c x_1^2 x_2^2 \left(a^2+b^2\right) \\ 2 c x_1 x_2 \left(x_2 \left(a^2+b^2\right)+x_1 \left(a^2-a x_2+b^2\right)\right)-2 x_0-2 y_0 \\ 2 -c x_1^2 \left(a^2-4 a x_2+b^2+x_2^2\right)-4 c x_2 x_1 \left(a^2-a x_2+b^2\right)-c x_2^2 \left(a^2+b^2\right)-2 y_0 \\ 2 \left(c x_1 \left(a^2-4 a x_2+b^2+x_2^2\right)+c x_2 \left(a^2-a x_2+b^2\right)+c x_1^2 \left(x_2-a\right)+2 y_0+1\right) \\ c \left(a^2+b^2\right)+c \left(4 x_1 \left(x_2-a\right)+x_2 \left(x_2-4 a\right)+x_1^2\right)+3 \\ 2 c \left(x_1+x_2\right)-2 (a c+2) \\ 4-c \\ \end{array} \right. $$
and we finish by solving this nonlinear system for $x_0,y_0,x_1,x_2,a,b,c$ using a minimization procedure such as
$$ \min_{x_0,y_0,x_1,x_2,a,b,c} \eta\cdot\eta\ \ \ \text{s. t.}\ \ \ \{x_0 > 0,y_0 >0, x_1 > 0, x_2 > 0\} $$
Follows a MATHEMATICA script which materializes those computations