1
$\begingroup$

I am reformulating this question as it was incomplete.

I want to label vertices in a graph with expressions in infix notation.

I copy my code below. First part converts a list of expressions to infix notation. This works fine. Second part uses the same code to produce vertex labels in a graph. However the vertex labels produced do not remain in infix (instead they convert back to prefix code).

I include the code below.

Map[# /. S -> (Infix[S[##]] &) &, {S[1, 2], S[2, S[3, 4]]}]

This code produces infix code fine, yielding {1 ~ S ~ 2, 2 ~ S (3 ~ S ~ 4)}

However the following code:

HasseGraph[g_] := Fold[SetProperty[{#1, #2}, {Map[# /. S -> (Infix[S[##]] &) &, 
   VertexLabels] ->  #2}] &, g, VertexList[g]] 
HasseGraph[Graph[{S[1, 2] -> S[2, S[3, 4]]}]]

produces a graph for which the vertex labels are: S(2,(3,4)) and S(2,S(3,4)). I need these to be in infix notation as for the above example. The conversion to infix has not been preserved. Can you advise on how to make sure that the vertex labels remain in infix form?

$\endgroup$
1
  • $\begingroup$ Related question: is it possible to simply display the infix without the ~ signs that clutter up matters? $\endgroup$ Feb 13, 2019 at 22:33

2 Answers 2

1
$\begingroup$

Maybe you could do:

HasseGraph[g_] := 
 With[{vlist = VertexList[g]}, 
  Graph[g, VertexLabels -> 
    Thread[vlist -> Map[# /. S -> (Infix[S[##]] &) &, vlist]]]]
HasseGraph[Graph[{S[1, 2] -> S[2, S[3, 4]]}]]
$\endgroup$
9
  • $\begingroup$ Unfortunately this does not solve the problem. The vertex labels still appear in prefix form. $\endgroup$ Feb 13, 2019 at 16:43
  • 1
    $\begingroup$ @Mike I edited answer. $\endgroup$
    – halmir
    Feb 13, 2019 at 18:02
  • $\begingroup$ Brilliant, that dit it. Thanks, Halmir! $\endgroup$ Feb 13, 2019 at 18:10
  • $\begingroup$ Is it possible to display infix notations without the ~ signs? So a ~ S ~ b would become aSb as one would expect in infix? $\endgroup$ Feb 13, 2019 at 22:33
  • 1
    $\begingroup$ @Mike Infix[S[##], S] could be what you want. $\endgroup$
    – halmir
    Feb 13, 2019 at 22:44
1
$\begingroup$

Again, you could just define a format for S instead. In this case, Graph uses TraditionalForm for labels, so you would need to use something like:

MakeBoxes[s_S, form_] ^:= MakeBoxes[Infix[s], form]

Then:

Graph[{S[1,2] -> S[2,S[3,4]]}, VertexLabels->Automatic]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks! Will try this one out as well. $\endgroup$ Feb 13, 2019 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.