# Pattern matching problem in version 11.01

Consider this simple example:

p1 = ListPlot3D[
Table[Sin[j^2 + i], {i, 0, Pi, Pi/5}, {j, 0, Pi, Pi/5}],
Mesh -> None, Axes -> False, Boxed -> False, ColorFunction -> Hue];
p2 = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
ColorFunction -> Hue, Mesh -> None, PlotPoints -> 50, Mesh -> None,
Axes -> False, Boxed -> False];

p1[[1, 2, 1, 1]]


Cases[p1[[1, 2, 1, 1]], GraphicsGroup[{Polygon[x__], ___}] :> x, ∞]


p2[[1, 2, 1, 1]]


Cases[p2[[1, 2, 1, 1]], GraphicsGroup[{Polygon[x__], ___}] :> x, ∞]
(*{}*)


So why does the last pattern match fail?

I'm using version 11.01 on macOS 10.12.

• I'm filing a bug report on this. – Daniel Lichtblau Oct 8 '16 at 23:47
• @DanielLichtblau I don't think this is a bug, at least not a bug in pattern matching. Take the subexpression which looks like the list inside of GraphicsGroup: list = p2[[1, 2, 1, 1, 3, 1]];. It's not a list. Head[list] gives Annotation. Annotation formats the same way as its first argument, so this is all very confusing. The second argument in Annotation is "ChartingPrivateTag\$4433#1" on my machine, which looks a bit weird, but that's a different issue. – Szabolcs Oct 9 '16 at 12:16
• This will work: Cases[p2[[1, 2, 1, 1]], GraphicsGroup[Annotation[{Polygon[x__], ___}, ___]] :> x, \[Infinity]] – Szabolcs Oct 9 '16 at 12:16
• @Szabolcs This example definitely changed behavior recently. Maybe you are correct and this is simply due to a change in the structure of the ListPlot3D result, so I need to double check on that. The timing specifics of the onset of the change is what made me suspect a bug in pattern matching. Believe me, I would be delighted to find out I have assessed this one incorrectly. – Daniel Lichtblau Oct 9 '16 at 19:05

This particular case is a good illustration of why it would be very useful to have a built-in analog of my shortInputForm function:

Import["http://raw.github.com/AlexeyPopkov/shortInputForm/master/shortInputForm.m"]


Let us compare p1 and p2 using shortInputForm:

p1[[1, 2, 1, 1]] // shortInputForm
p2[[1, 2, 1, 1]] // shortInputForm


From the output we immediately see that in the case of p2 the first argument of GraphicsGroup is wrapped by Annotation. That's why the pattern doesn't work for p2.

Knowing this we can pre-process the output and remove Annotation, then the pattern will work:

Cases[p2 /. Annotation -> (#1 &),
GraphicsGroup[{Polygon[x__], ___}, ___] :> x, ∞]