2010-11-05 47 views
6

以下代碼創建了某個計算的圖表。我的問題是,儘管分母中的術語順序很好,但在應用Plus之後,它們會被任意地重新排列。任何建議如何強制原始訂單被保留?防止「Plus」重新排列東西

http://yaroslavvb.com/upload/ind-sets-grid.png

 
r[i_] := Floor[(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 = Function[{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); 
denominator = 
    twoColorGraph[g, #, weight[#]] & /@ 
    Join @@ (indsets[#] & /@ Range[2]); 
numerator = twoColorGraph[g, {1}, weight[{1}]]; 
Style[numerator/(Plus @@ denominator), FontSize -> 30] 
+0

這是一個重複,意圖,如果不是形式,另一個問題(http://stackoverflow.com/questions/3947071/controllingorder-of-variables-in-an-expression)。否則,我會給你一個單獨的圖形+1。什麼是計算? – rcollyer 2010-11-05 19:38:36

+0

是的,這是相似的。那裏的建議是定義像「myPlus」這樣的不是無序的自己的功能,但是我怎樣才能讓它與「Plus」一樣呈現? – 2010-11-05 19:42:07

+0

計算是在有限網格(即具有硬核自排斥和硬核對相互作用的宏規範氣體)上找到每個現場佔據核心排斥性局部氣體的概率 – 2010-11-05 20:12:19

回答

5

訣竅格式化像myPlus看起來像Plus輸出是使用Format。這裏有一個簡單的例子,讓你開始:

然後,你會直觀地看到在筆記本電腦是什麼:

In[7]:= x = myPlus[3, 2, 1] 
Out[7]= 3+2+1 

...但x仍會有頭myPlus

下面是從進入更多詳細的格式化輸出,運算符優先級本文檔的tutorial

希望幫助!

+1

+1,我試圖用'Notation'做到這一點,並且它失敗了。我忘了直接看'格式'。 – rcollyer 2010-11-05 20:52:55

+0

我試圖將'Interpretation'與您的答案結合起來,以便它可以被正確地複製和粘貼,但遇到問題。請參閱SO問題http://stackoverflow.com/q/4112299/421225 – Simon 2010-11-06 07:18:57