0
$\begingroup$

Bug introduced in 12.3.1 or earlier [CASE:4853257]


I encountered a strange problem with RegionDistanceFunction. Consider this list of points (I'm forced to use Compress, because with direct input the problem doesn't reproduce):

pts = Uncompress@"1:eJx11l1Ik1EYB3BNAwsqDLqwomZ+lCvNPtA+Bp0wuihvKr14T5lQtlzFClYxLWd+\
VfYJkVBZpF1ILMoIgojUi6n50dbMLZtZqQsv+hCDdtMH9p6HPWcHfHpBj/B75/u85/\
lzniXuO7rTbI6KirLF6r9yLbbjB6L1P6bpP607el31Fs4O/zlh3erTmATf3ecNATNnG/L1y6/\
A4hsz2os4Z4liHVRgnbgzn7Prc7c0zxpSIM7K6zu2cVboap6YP6xAcFK/\
NnE20OP02IIKlDpydm03cZaaNv43NKbASF/\
d3rZszq469euLAoaK243tmXpVYp1Q4Iq408jZrSJrdF5IgcvHOu3dyZwFOxZ4Fv1SIP9ncfb+hZx9FtVNKtAScm+\
8lsBZcYN9zBTLI7BevPg8zr6xH69K4hTob7mf5ZjDGa4S8E78pAT83/gsCVgNVhfZxHD9+\
D4S6sNvjDsgAfcI90wC7irusgTsA/ZFAnYOOykBe429l4DpwLREqgrnCfMlAROIiZSAmcUMS/\
D7mo509etbIt7nkPrwJMPBeI/GTJ6e+Bd2Bbzur4bSHo2NivcoV2Bi+oWSe90a+\
y7WWgWqyvJGeZfGskV1dQo4qkeePXipMW8ga3b0HQUazA83p3Rq7JKoyqlAzZPW340dGltRYGnKfaxCb6F/\
wKX3Q1TVRkAFrARkwZ4R8Nbw1JgeIOAi9J6A5SdnnqkcJ2AYEkmAUXwiY/dU+\
AQpIaBcrDkErIWUEOAT76ERUAs9JyBNVGUl4CP0nACHWKsIWAM9J6BfVHWTgPPQcwKWiaoeEfABek5AGawErIaeE/\
AGek7AOeg5AUuh5wQMQc8JOC3WmD1TYRWccAT0iaoSCDgL5xUBqZArAt5Drgg4BbkiIBNyRYAXckVADeSKgBTIFQGD\
kCsCSiFXBKyEXBHwGnJFQDXkioBkyBUBAciVAtVhsMNKQAbkigA35IqAKsgV8fAkyBUB7yBXBEBVMQVTIR1yRQBUlU\
BAJeSKgCWQKwIGIFcK4NGNR3lkfoQPezz8JeB4wHEhAQcKDhgJOIJwJEnAoYVDLPJNJjzmcOz998vdP0c/e4c=";

Now create a RegionDistanceFunction and apply it to the points:

df = RegionDistance[Line[pts[[{1, -1}]]]];

df /@ pts[[2 ;; -2]]

I get two RegionDistanceFunction::regp messages during the evaluation of this code:

RegionDistanceFunction::regp: A correctly specified region expected at position 1 of RegionDistanceFunction[Line[{Compile`$4,Compile`$4}],2,Sqrt[(-105.65+Subscript[Slot[<<1>>], <<1>>])^2+(-103.317+Subscript[Slot[<<1>>], <<1>>])^2]&].

What is even more strange, I don't get these messages when I use the RegionDistanceFunction inside of a Function:

df[#] & /@ pts[[2 ;; -2]]

Why does this happen? How can it be explained?

I'm using Mathematica 12.3.1 on Windows 10 x64. The problem persists after restarting Mathematica.


UPDATE

I've found that the problem is related to auto-compilation performed by Map, and can be boiled down to

df = RegionDistance[
   Line[Uncompress[
     "1:eJxTTMoPSmNiYGAoZgESPpnFJamMQAZIZF/g6cOzM6Mcsv+U5rldiXTAKQEAX1wVAA=="]]];

SetSystemOptions["CompileOptions" -> {"MapCompileLength" -> 1}];

df /@ {{105., 103.}}
RegionDistanceFunction::regp: A correctly specified region expected at position 1 of RegionDistanceFunction[Line[{Compile`$1,Compile`$1}],2,Sqrt[(-105.65+Subscript[Slot[<<1>>], <<1>>])^2+(-103.317+Subscript[Slot[<<1>>], <<1>>])^2]&].
RegionDistanceFunction::regp: A correctly specified region expected at position 1 of RegionDistanceFunction[Line[{Compile`$1,Compile`$1}],2,Sqrt[(-105.65+Subscript[Slot[<<1>>], <<1>>])^2+(-103.317+Subscript[Slot[<<1>>], <<1>>])^2]&].
{0.72321}

Is it a bug? Is there a workaround?

$\endgroup$
1
$\begingroup$

Looks something is going wrong with the automatic compilation process. You observe:

df /@ pts[[2 ;; -2]];

RegionDistanceFunction::regp: A correctly specified region expected at position 1 of RegionDistanceFunction[Line[{Compile$8,Compile$8}],2,Sqrt[(-105.65+Subscript[Slot[<<1>>], <<1>>])^2+(-103.317+Subscript[Slot[<<1>>], <<1>>])^2]&].

RegionDistanceFunction::regp: A correctly specified region expected at position 1 of RegionDistanceFunction[Line[{Compile$8,Compile$8}],2.,Sqrt[(-105.65+Subscript[Slot[<<1>>], <<1>>])^2+(-103.317+Subscript[Slot[<<1>>], <<1>>])^2]&].

Increase the length to start automatic compilation:

SetSystemOptions["CompileOptions" -> "MapCompileLength" -> 111];
df /@ pts[[2 ;; -2]];

I think this is worth reporting to support as a bug.

$\endgroup$
2
  • $\begingroup$ Why does wrapping the RegionDistanceFunction by Function prevent the bug to appear? $\endgroup$ Aug 29 at 4:07
  • $\begingroup$ Reported to support as [CASE:4853257]. $\endgroup$ Aug 29 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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