I would like to automatically determine whether given object is Combinatorica or Mathematica 8.0 Graph.
It doesn't seem that FullForm has enough information to tell which one is which
(* output of Combinatorica`CompleteGraph[1] *)
Graph[List[],List[List[List[0,0]]]]
(* output of System`CompleteGraph[1] *)
Graph[List[1],List[]]
Mathematica, however, is able to tell them apart and renders one as a text string and another as visual object. Is there
- Way to view "hidden" information in expressions that doesn't show in FullFo开发者_开发百科rm
- Way to look at the rules Mathematica uses to render expressions?
Update: It seems that Head gives different result for two graphs even though displayed heads are identical. Defining function as f[a_System'Graph] and f[a_Combinatorica'Graph] results in correct version being called
Head returns different values for the two types of graphs:
In[1]:= g1 = Combinatorica`CompleteGraph[1];
In[2]:= g2 = System`CompleteGraph[1];
In[3]:= Combinatorica`Graph === Head[#] & /@ {g1, g2}
Out[3]= {True, False}
In[4]:= System`Graph === Head[#] & /@ {g1, g2}
Out[4]= {False, True}
As for question 1, you have limited options for viewing the "hidden" information in non-symbolic objects like graphs, images, etc. You can call built-in Mathematica functions that have access to the native object representation. There are functions specific to the object types (like VertextCount or ImageDimensions) or more generic (like CurrentValue or PropertyValue). You are at the mercy of the MMA documentation to find comprehensive listings of such functions. Alternatively, you can sometimes glean useful information by inspecting the cell expression of an output cell containing such an object. But that can be hit or miss.
As for question 2, WRI typically protects the rendering rules for built-in functionality. Also, some functionality (like the drawing tools and graph editors) appears to be built directly into the notebook interface itself. You might get lucky inspecting the up-values or down-values on rendering functions such as MakeBoxes and Format, etc. Again, it is a bit hit or miss.
精彩评论