区分不同的“图” Mathematica 8 中的对象

发布于 2024-10-07 14:54:14 字数 529 浏览 2 评论 0原文

我想自动确定给定对象是 Combinatorica 还是 Mathematica 8.0 Graph。

FullForm 似乎没有足够的信息来区分哪个是哪个

(* output of Combinatorica`CompleteGraph[1] *)
Graph[List[],List[List[List[0,0]]]]

(* output of System`CompleteGraph[1] *)
Graph[List[1],List[]]

,但是 Mathematica 能够区分它们并将一个呈现为文本字符串,另一个呈现为视觉对象。有没有

  1. 办法查看表达式中未以 FullForm
  2. 方式显示的“隐藏”信息 查看 Mathematica 用于呈现表达式的规则?

更新: 尽管显示的头部相同,但 Head 似乎为两个图表给出了不同的结果。将函数定义为 f[a_System'Graph] 和 f[a_Combinatorica'Graph] 会导致调用正确的版本

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

  1. Way to view "hidden" information in expressions that doesn't show in FullForm
  2. 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偷得浮生 2024-10-14 14:54:14

Head 对于两种类型的图形返回不同的值:

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}

对于问题 1,您在查看非符号对象(如图形、图像等)中的“隐藏”信息的选项有限。您可以调用built -in Mathematica 函数可以访问本机对象表示。有特定于对象类型的函数(如 VertextCount 或 ImageDimensions)或更通用的函数(如 CurrentValue 或 PropertyValue)。您可以通过 MMA 文档来查找此类函数的完整列表。或者,有时您可以通过检查包含此类对象的输出单元格的单元格表达式来收集有用的信息。但这可能是偶然的。

对于问题 2,WRI 通常会保护内置功能的渲染规则。此外,某些功能(如绘图工具和图形编辑器)似乎直接内置到笔记本界面本身中。您可能会幸运地检查渲染函数(例如MakeBoxesFormat等)的上值或下值。同样,这有点碰运气。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文