9
$\begingroup$

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]]

enter image description here

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

enter image description here

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

enter image description here

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.

$\endgroup$
  • 7
    $\begingroup$ I'm filing a bug report on this. $\endgroup$ – Daniel Lichtblau Oct 8 '16 at 23:47
  • 2
    $\begingroup$ @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 "Charting`Private`Tag$4433#1" on my machine, which looks a bit weird, but that's a different issue. $\endgroup$ – Szabolcs Oct 9 '16 at 12:16
  • 1
    $\begingroup$ This will work: Cases[p2[[1, 2, 1, 1]], GraphicsGroup[Annotation[{Polygon[x__], ___}, ___]] :> x, \[Infinity]] $\endgroup$ – Szabolcs Oct 9 '16 at 12:16
  • 2
    $\begingroup$ @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. $\endgroup$ – Daniel Lichtblau Oct 9 '16 at 19:05
4
$\begingroup$

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

screenshot

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, ∞]

screenshot

$\endgroup$

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.