Hey,
I am currently in chapter 27 of the Wolfram Language Book and can’t seem to grasp the list creation and handling in the NestGraph function.
NestGraph[{2 #, 2 # + 1} &, 0, 4, VertexLabels -> All]
To understand what the above does step by step I “extracted” a part:
In[1]:= {2 #, 2 # + 1} &@{2, 3}
Out[1]= {{4, 6}, {5, 7}}
My questions:
- Shouldn’t the output be
{{4, 5}, {6, 7}}? Why is it the way it is?
- How does NestGraph handle the above output internally to construct the correct graph?
Thank you very much!!!
Tim
The argument to the pure function is {2, 3}, which is assigned to #
2 {2, 3}
(* {4, 6} *)
2 {2, 3} + 1
(* {5, 7} *)
Compare the output of the following for different values of n
NestList[{2 #, 2 # + 1} &, 0, n]
NestGraph[{2 #, 2 # + 1} &, 0, n, VertexLabels -> All]
and you should be able to see how the graph “grows”.
Hey!
Sorry to bother you again, but I’m still having problems understanding how NestGraph[] builds the tree.
I understand the function and how it generates the lists, I just don’t get how NestGraph[] traverses the lists?!
Please find attached a note I created to understand the flow.
My questions (please see attached image):
- How does
NetGraph[] figure out to go from {1,3} to {2,6}?
- Are the list entries I tagged with a question mark not evaluated at all?
I think I’m having problems seeing something obvious and in the end it’s probably easy, but I really like to understand.
Thank you very much!