下面的代码创建了一个特定计算的图表。我的问题是,即使分母中的项的顺序很好,但在对其应用 Plus 后,它们会被任意重新排列。任何建议如何强制保留原始订单?
(来源:yaroslavvb.com)
r[i_] := 楼层[(i - 1)/n] + 1;
c[i_] := Mod[i, n, 1];
adj[a_, b_] := Abs[r[a] - r[b]] + Abs[c[a] - c[b]] == 1;
indsetQ[s_] := Not[Or @@ (adj @@@ Subsets[s, {2}])];
indsets[k_] := Select[Subsets[Range[n^2], {k}], indsetQ];
twoColorGraph[g_, seen_, lbl_] := Module[{radius = .22},
vcoords = # -> {c[#], n - r[#]} &/@ Range[n^2];
fv = 函数[{p, v}, {EdgeForm[Thick],
If[MemberQ[seen, v], Pink, White], Disk[p, radius]}];
GraphPlot[g, VertexLabeling -> True, VertexRenderingFunction -> fv,
PlotLabel -> Style[lbl, 20], LabelStyle -> Directive[Bold],
VertexCoordinateRules -> vcoords, ImageSize -> 80]
];
n = 2;
g = Array[Boole[adj[#1, #2]] &, {n^2, n^2}];
weight[set_] := Times @@ (Subscript[\[Lambda], c[#], r[#]] &/@ set);
分母 =
twoColorGraph[g, #, weight[#]] &/@
加入@@ (indsets[#] &/@ Range[2]);
numerator = twoColorGraph[g, {1}, weight[{1}]];
样式[分子/(加@@ 分母),字体大小 -> 30]
最佳答案
格式化类似 myPlus
的技巧至 看 喜欢 Plus
输出是使用 Format
.这是一个让您入门的简单示例:
Format[myPlus[expr__]] := Row[Riffle[{expr}, "+"]]
然后,您将在笔记本中直观地看到:
In[7]:= x = myPlus[3, 2, 1]
Out[7]= 3+2+1
... 但是
x
还是会有头myPlus
.这是一个 tutorial来自有关格式化输出、运算符优先级等更多详细信息的文档。
希望有帮助!
关于wolfram-mathematica - 防止 "Plus"重新排列东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4109306/