Message Boards Message Boards

0
|
4433 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Inconsistency of TreeForm symbol depending on argument?

Posted 6 years ago

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

Attachment

Attachments:
POSTED BY: Roman Kozak
4 Replies

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.

POSTED BY: Szabolcs Horvát

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.

POSTED BY: Gianluca Gorni
Posted 6 years 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]]]]
POSTED BY: Roman Kozak

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 BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract