0

Main Question

Is there an efficient way to output a tree of values similar to the output of TreeForm?

Something like

TreeForm[1[2, 3[4[1, 2], 5[3, 4], 6[1, 2, 3, 4, 5[6]]]]]

Why do I want this?

My purpose is to analyze the output of my lab classes. For that, I need to "structure" my data to do the calculations, using partitions etc. I have an example here. I would like to be able to get a graphic output of the "structure" created.

Imagine, however, that I need to add a level to this tree with some functions. It doesn't seem very practical. And using numbers as heads is a little disturbing for me.

Community
  • 1
  • 1

2 Answers2

0

Having looked at your referenced example, I would suggest arraging your information in a 2D (at least at the outermost level) array. With appropriate care, this could make your computational expressions simple and you might gererate a tree from it uing TreePlot, using index information and a priori definitions to number nodes and edges.

stuartw
  • 120
  • 4
0

TreeForm represent Mathematica expressions as trees (every mathematica expression can be represented as a tree). However, in your example different vertices have the same labels thus generating cycles which are not allowed in trees. So, any "fancy" mathematica code that will convert such data structure to another representation will not be able to result with a data structure that is a tree. As for tree traversal, ReplaceAll, Replace etc. are practically DFS with patterns so maybe you can use this to process your data, but IMHO modifying the representation is crucial here.

Yehuda
  • 88
  • 4