Q:

Implementation of Poincaré–Miranda theorem

To test whether a continuous function has a root one simple root in a given interval [x0, x1] is relatively easy: according to Intermediate value theorem when the sign of function value at x0 is opposite to the sign at x1, there is (at least) one root.
For example, given a quadratic function:
g(x): a*x**2 + b*x + c = 0

The test looks like:
if sign of g(x0) is opposite of sign of g(x1)
then return true
else return false

For multivariate case there is Poincaré–Miranda theorem but I have a bit of difficulty to implement the test correctly from reading the linked article.
Given two quadratic bivariate functions:
g1(x, y): a1*x**2 + b1*y**2 + c1*x*y + d1*x + e1*y + f1 = 0
g2(x, y): a2*x**2 + b2*y**2 + c2*x*y + d2*x + e2*y + f2 = 0

and a rectangular region [x0, x1] x [y0, y1], how to check if there is at least one root in the region?
I mean, I assume the test should look somewhat like (this doesn't work):
if (sign of g1(x0, y0) is opposite of sign of g1(x1, y0) and
    sign of g1(x0, y1) is opposite of sign of g1(x0, y1) and
    sign of g2(x0, y0) is opposite of sign of g2(x1, y0) and
    sign of g2(x0, y1) is opposite of sign of g2(x0, y1))
then return true
else return false

Please, does anyone know what pairs of functions, interval end-points, and logical operators to check and in what order?

A:

You need to check whether your bivariate functions
g1(x, y): a1*x**2 + b1*y**2 + c1*x*y + d1*x + e1*y + f1 = 0
g2(x, y): a2*x**2 + b2*y**2 + c2*x*y + d2*x + e2*y + f2 = 0

satisfy
I).  g1(x0,y) < 0, for all y in [y0,y1]
II). g2(x,y0) < 0, for all x in [x0,x1]

and
III). g1(x1,y) > 0, for all y in [y0,y1]
IV).  g2(x,y1) > 0, for all x in [x0,x1]

Your functions are quadratic, so this can be done without sampling values along all 4 boundaries for the 4 cases. For example, for the first condition on g1(x0,y), simply plug in x0 for x, obtaining a quadratic equation in y:
G1(y) = b1*y**2 + c1*x0*y + e1*y + (f1 + d1*x0 + a1*x0**2)

We need to check whether G1 is ever positive for y in [y0,y1]. Since G1 is quadratic, its maximum either occurs where {G1' = 0, G1'' < 0} or at the endpoints. So:
a. express G1' analytically, use simple bisection to find a root in [y0,y1]
b. if there is one, say y*, express G1'' analytically and compute G1''(y*)
c. if G1''(y*) is also < 0 then you have your maximum y*
d. if G1(y*) > 0 then the condition are violated, you may break
e. if not, then test the endpoints G1(y0), G1(y1).
f. if any of those are > 0 then break.

If your function passes these tests without breaking, you have satisfied the first of the 4 conditions (I) above.  
The conditions (II-IV) can be tested in a similar manner. If all conditions hold, the Miranda test holds and you have a coincident root of the two functions. If not, then you are in the "maybe" case - the functions may still have a common root, but you'll have to use a different method to prove existence.

