4
$\begingroup$

Bug introduced in 12.1 or earlier and persisting through 13.2


Consider the following region:

region = BooleanRegion[#1 || #2 &, {Circle[{0, 0}, 
   63.01771474209481`, {-0.3085423746716913`, 0}], 
  Circle[{0, 0}, 63.01771474209481`, {0, 0.3085423746716913`}]}]

Why in Mathematica 12.1 RegionMeasure[region] returns a complex value, and how to avoid it without dealing with explicit calculations (despite the fact that it is possible to make this easily)?

RegionMeasure[region]

38.8873 + 0.0000128693 I

$\endgroup$
3
  • $\begingroup$ Machine precision calculations neither track nor control precision. You get what you get. Arbitrary precision will track and attempt to control precision. Exact numbers will give exact results. $\endgroup$
    – Bob Hanlon
    Commented Feb 4, 2022 at 15:50
  • $\begingroup$ Per the tag wiki for bugs: "Please do not use this tag for new questions." -- Now, does the community think it's a bug? $\endgroup$
    – Michael E2
    Commented Feb 4, 2022 at 18:00
  • $\begingroup$ I think it is a bug. Worth reporting to the support. Added the BUG header and the tag. $\endgroup$ Commented Feb 5, 2022 at 4:03

1 Answer 1

5
$\begingroup$

This is numerical inaccuracy stemming from your machine precision inputs. Setting a WorkingPrecision for RegionMeasure takes care of the problem:

RegionMeasure[region, WorkingPrecision -> 10]

(* Out: 38.88727071 *)
```
$\endgroup$
3
  • 1
    $\begingroup$ Why not WorkingPrecision -> $MachinePrecision? (Why so much less than?) -- Oh, bizarre. It makes no difference. But I usually use WorkingPrecision -> 16 because it's shorter to type, and that works. -- Oh, wow, WorkingPrecision -> 10. fails, too. That's wierd. $\endgroup$
    – Michael E2
    Commented Feb 4, 2022 at 18:00
  • 3
    $\begingroup$ Hmm, WorkingPrecision -> p seems to work only if p is an integer (fails for Real and Rational). $\endgroup$
    – Michael E2
    Commented Feb 4, 2022 at 18:07
  • $\begingroup$ @MichaelE2 This looks like a bug in WorkingPrecision functionality. Worth reporting to support. $\endgroup$ Commented Feb 5, 2022 at 3:58

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.