Message Boards Message Boards


Inconsistency of TreeForm symbol depending on argument?

Posted 9 days ago
4 Replies
3 Total Likes

Hi, It seems TreeForm has different visual representation depending on arguments.

TreeForm[Graphics[{Circle[{0,0}],Disk[{2,2}]}]] works as it has to be.
TreeForm[Graph[{1->2,3->2}]] works completly differently.

Is it ok? Why TreeForm doesn't show Head and atoms in a second case as it does in the first one?

Two calls of TreeForm symbol


4 Replies

It seems that Graph objects are treated as atoms:

In[14]:= AtomQ[Graph[{1 -> 2, 3 -> 2}]]

Out[14]= True

You can look inside them with FullForm.

Posted 8 days ago

It's strange. If Graph is an atom than why we can browse Graph in FullForm?

In[57]:= FullForm@Graph[{1->2,3->2}]
Out[57]= Graph[List[1,2,3],List[DirectedEdge[1,2],DirectedEdge[3,2]]]

On the other hand, we can't change Head for Graph symbol also. So, is it Graph treated in a special way in Wolfram Language? If it's true then It may explain why TreeForm behaves in such a way.

In[58]:= FullForm[ Apply[f,Graph[{1->2,3->2}]] ]
Out[58]= Graph[List[1,2,3],List[DirectedEdge[1,2],DirectedEdge[3,2]]]

In[59]:= FullForm[ Apply[f,Graphics[{Circle[{0,0}],Disk[{2,2}]}]] ]
Out[59]= f[List[Circle[List[0,0]],Disk[List[2,2]]]]

I suppose the situation is similar to the rational numbers: AtomQ[2/3] is True, but FullForm[2/3] is Rational[2, 3]. It feels like an inconsistency, and the matter was raised in the past in the forum. My vague recollection is that there must be a serious design issue behind it, but I don't know what it is.

It's strange. If Graph is an atom than why we can browse Graph in FullForm?

I believe this is because certain critical operations that Mathematica must do, such as serializing (think Compress, using WSTP or WXF or just Save) an expression, either requires (1) special and separate treatment of each and every atomic type or (2) a means to convert an atomic expression into an equivalent compound one, and back.

(1) is unfeasible. There are too many atomic types. Many exist for performance reasons. Thus most of the time (2) is used.

See here:

and other answers in the same thread.

Don't be fooled by Graph having a compound form. It really is an atom, and its compound representation would only be equivalent to its true internal representation in an ideal world. It's fairly common for bugs in Graph to reveal differences between the two ...

E.g. Graph3D[KaryTree[5], PlotTheme -> "CoolColor"] fails. Graph3D[Uncompress@Compress@KaryTree[5], PlotTheme -> "CoolColor"] works. I used Compress to effectively cycle the graph through its compound representation.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract