I would want to test connectedness of semialgebraic sets with naive code like this:
With[
{r1 = y > -1 && x <= Sqrt[1 - y^2] && Sqrt[2] + 2 y <= 1 &&
x + Sqrt[1 - y^2] >= 0,
r2 = Sqrt[2] + 2 y > 1 && 4 y < 3 &&
2 x + Sqrt[1 - 4 (-1 + y) y] <= 0 && x + Sqrt[1 - y^2] >= 0},
Resolve[
Exists[
{x1, y1, x2, y2},
(r1 /. {x -> x1, y -> y1}) &&
(r2 /. {x -> x2, y -> y2}),
ForAll[
{t},
0 < t < 1,
(r1 || r2) /. {x -> (1 - t) x1 + t x2, y -> (1 - t) y1 + t y2}]],
Reals]]
Here the idea is that sets are connected if a point (x1
,y1
) exists in a region r1
and another (x2
,y2
) in r2
and that every point on a line segment between these is either in r1
or r2
.
This kind of code works for trivial regions (like half-spaces and lines/points just on their edge), but for regions listed above, it takes either unbearably long or forever. This is slightly disappointing, considering the fact it's relatively easy to work out these sets are actually trivially connected. It's obvious from the region specifications, but also visually:
RegionPlot[{y > -1 && x <= Sqrt[1 - y^2] && Sqrt[2] + 2 y <= 1 &&
x + Sqrt[1 - y^2] >= 0,
Sqrt[2] + 2 y > 1 && 4 y < 3 && 2 x + Sqrt[1 - 4 (-1 + y) y] <= 0 &&
x + Sqrt[1 - y^2] >= 0},
{x, -1, 1}, {y, -1, 1}, PlotPoints -> 200]
How to make what is relatively intuitive and straight-forward to a human at least a bit faster and more bearable for Mathematica?
Specifically I'm looking for methods which maintain the above definition of connectedness test - because it's quite easy to write tests that actually fail in cases like r1 = x < 0, r2 = x > 0
with an infinitesimal gap between regions.