16
$\begingroup$

Bug introduced in 10.2, and persisting through 11.1

Bug resolved in 12.0


This is strange:

ClearAll[x, y, a, b];
a[{{_Integer, _Integer, _Integer | PatternSequence[]} ..}] := c;
(*this is a match:*)
a[{{1, 1}}]
(*this too:*)
a[{{1, 1, 1}}]

b = CoordinateBoundsArray /@ {{{1, 1}, {1, 1}}};

x = First@b;
y = {{{1, 1}}};

x === y(*True*)

a /@ x(*{a[{{1,1}}]}*)(* this does not finish evaluating?!*)
a /@ y(*{c}*)

If[Not[
  a /@ x === a /@ y(*False*)
  ], "something is wrong"]

Everything works fine if I change a to

a[{{_Integer, _Integer} ..}] := c;

or if assign the result of CoordinateBoundsArray /@ {{{1, 1}, {1, 1}}} to b

b = {{{{1, 1}}}};

Can someone confirm this?

$\endgroup$
  • $\begingroup$ I get the same answer both in V11.0.0 and in V10.4. I can't see any explanation. $\endgroup$ – mikado Aug 25 '16 at 20:11
  • 12
    $\begingroup$ It's a bug in pattern matching for packed arrays. I have filed a report. $\endgroup$ – ilian Aug 25 '16 at 20:18
  • $\begingroup$ Behavior reproduced in 10.3 $\endgroup$ – QuantumDot Sep 17 '16 at 22:30
  • $\begingroup$ I do not reproduce the problem with versions 11.3 and 12.0. $\endgroup$ – Alexey Popkov Oct 24 '19 at 15:58
11
$\begingroup$

Not a proper answer, but we can see that there is a significant internal difference between the two:

Needs["Developer`"]

PackedArrayQ[x]
(* True *)

PackedArrayQ[y]
(* False *)
$\endgroup$
  • 1
    $\begingroup$ And I was thinking of some even more fancy optimizations in the interpreter. Nice find! $\endgroup$ – masterxilo Aug 25 '16 at 20:22

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.