Actually, the title says it all. I am a little confused why such a complicated object as Graph, with many different parts, was designed to be atomic in Mathematica language such that, for example, function Part cannot be used on it.
- 124,525
- 11
- 401
- 574
- 1,037
- 10
- 19
2 Answers
Graph may be atomic to allow an optimized internal form. Graph operations are often computationally intensive and it makes sense to keep Graph data in a form that can be operated upon quickly, perhaps by external libraries, without the overhead of converting from a plain Mathematica expression every time. This is the case with Image I believe, which also is atomic.
- 271,378
- 34
- 587
- 1,371
-
Thank you, but do not you think that similar explanation would work for many other objects (say, RandomFunction), which, however, are not atomic? – Artem Sep 30 '16 at 23:49
-
1@Artem by
RandomFunctiondo you mean theTemporalDataexpression it returns? If so I believe most of the processing that is done onTemporalDataexpressions is top-level Mathematica code, not C library level as I think a fair amount of theGraphfunctionality is. – Mr.Wizard Oct 02 '16 at 10:47
Graph being AtomQ has about the same implications as doing lots of overloadings of the type Part[_Graph,___] := Error[]; Replace[_Graph,___] := Error[]; .... It signifies that it is an "abstract data type" whose API (in the form of functions like VertexList) shall be the only way to interface with its contents. It would actually be nice to be able to do this type of thing automatically for user-defined "types" (heads of data structures), to ensure no-one relies on the current representation of the data as an expression.
Things are AtomQ for the same reason as internal data is declared private in the OO-world: Information hiding.
- 5,739
- 17
- 39
-
Following the logic of Artem's comment under my answer above if this were the primary reason I would expect a number of other expressions like
TemportalData,InterpolatingFunction, andTimeSeriesto also be atomic as these have API's of this sort as well, but these are not atomic. Perhaps this is nothing more than inconsistency but I favor a different explanation. – Mr.Wizard Oct 02 '16 at 10:54
PartonGraph? There is aSubgraphfor subgraphs. – m0nhawk Sep 29 '16 at 15:37Graphfunctions. You could rephrase the question to be on topic. What do you want to get out of aGraphby usingPart? You can get the vertices and edges through other means – Jason B. Sep 30 '16 at 01:20Partdoes not work onGraphis different from why it is atomic. Packed arrays are also atomic, but none of the functionality lets you see this. This is because they assume the interface to packed arrays (mainlyPartandExtractand arithmetic operations with other packed arrays) to remain stable. However, I think it would be foolish to pretendGraphis also just an ordinary expression withParts that can beExtracted. IMO this doesn't make sense for any data structure consisting of parts of different types of data. – masterxilo Sep 30 '16 at 17:47First@Plot[x, {x, -2, 2}]-Graphicsis not atomic, but its parts are of wildly different types. I can understand the motivation for wantingGraphto be non-atomic, I have often wished to get the coordinates list from aMeshRegionusingFirst. But I can get all the data I need from aMeshRegionusingMeshCoordinates,MeshPrimitives,MeshCells, etc. – Jason B. Sep 30 '16 at 18:37Graphusing built in functions, likeVertexList,GraphEmbedding, etc. So if there is a particular property of aGraphthat OP can't access, then that would be an on-topic question, IMO. – Jason B. Sep 30 '16 at 18:38