1
$\begingroup$

Is this a bug or I am missing something again? I ran the following code on a fresh kernel and each time it outputs randomly different result consisting of all combination {True, True}, {True, False}, {False, True}, {False, False}.

But I think it should output always {True, True}.

Do[Print[{RegionEqual[
    ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2 x}, {x, y}], 
    Line[{{1/3, -1/3}, {1/2, 0}}]], 
   RegionEqual[
    ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2 x}, {x, y}], 
    Line[{{1/2, 0}, {1/3, -1/3}}]]}], {i, 10}]

{False,True}

{True,False}

{False,True}

{False,True}

{True,True}

{False,False}

{False,False}

{False,False}

{False,False}

{False,False}

My version:

$Version

"13.0.1 for Microsoft Windows (64-bit) (January 28, 2022)"
$\endgroup$

1 Answer 1

2
$\begingroup$

It uses randomness somewhere in its internal checks. Seed the random number generator, each time, you get consistent results (e.g. {True, False} every iteration), although not necessary correct results.

Do[
 SeedRandom[20];
 Print[{RegionEqual[
    ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2  x}, {x, y}], 
    Line[{{1/3, -1/3}, {1/2, 0}}]], 
   RegionEqual[
    ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2  x}, {x, y}], 
    Line[{{1/2, 0}, {1/3, -1/3}}]]}], {i, 10}]
(*
{True,True}

{True,True}

{True,True}

{True,True}

{True,True}

{True,True}

{True,True}

{True,True}

{True,True}

{True,True}
*)

The following shows the line and its reversal are not computationally equivalent -- that is, we get different answers with the same random seed.

With[{seed = 4},
 {
  SeedRandom[seed];
  RegionEqual[
   ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2  x}, {x, y}], 
   Line[{{1/3, -1/3}, {1/2, 0}}]],
  SeedRandom[seed];
  RegionEqual[
   ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2  x}, {x, y}], 
   Line[{{1/2, 0}, {1/3, -1/3}}]]}
 ]

(* {True, False} *)

The internals can't be Trace[]-d it seems, so I think the only thing to do is to report it Wolfram.

Possible workaround for exact regions

Add a no-op condition depending on a parameter (Element[a, Reals]):

Do[Print[{
   RegionEqual[
    ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2  x && 
       Element[a, Reals]}, {x, y}],
    Line[{{1/3, -1/3}, {1/2, 0}}]], 
   RegionEqual[
    ImplicitRegion[{1/3 <= x <= 1/2 && y == -1 + 2  x && 
       Element[a, Reals]}, {x, y}],
    Line[{{1/2, 0}, {1/3, -1/3}}]]}], {i, 10}]

(* < all are {True, True} > *)
$\endgroup$
2
  • $\begingroup$ It must be a serious bug. What does it have anything with randomness? Regions are equal or are not equal. $\endgroup$ Jan 31 at 13:40
  • $\begingroup$ @azerbajdzan I'd say the output in the OP, from a user's point of view, implies it should be considered a bug. Your point, imo, is also an argument that it is a design choice, because, as you say, what does it have to with randomness? One possibility is that there does not exist a robust, deterministic, relatively quick algorithm for region equality. $\endgroup$
    – Goofy
    Jan 31 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.