In[]:=
nkrules={{"1+f[n-f[n-1]]",{1}},{"2+f[n-f[n-1]]",{1,1}},{"f[f[n-1]]+f[n-f[n-1]]",{1,1}},{"f[n-f[n-1]]+f[n-f[n-2]-1]",{1,1}},{"f[n-f[n-1]]+f[n-f[n-2]]",{1,1}},{"f[n-f[n-1]-1]+f[n-f[n-2]-1]",{1,1}},{"f[f[n-1]]+f[n-f[n-2]-1]",{1,1}},{"f[f[n-1]]+f[n-2f[n-1]+1]",{1,1}}};
In[]:=
SetAttributes[RecursionCallGraph,HoldFirst]
In[]:=
RecursionCallGraphNKS3[max_,id_:True,opts:___Rule]:=Graph[Flatten[Thread/@Last[Reap[Module[{f},f[n_]:=f[n]=f[Sow[f[Sow[n-1,n]],n]]+f[Sow[n-f[Sow[n-1,n]],n]];f[1]=f[2]=1;Table[f[n],{n,max}]],_,Rule]]],opts]
In[]:=
RecursionCallGraphNKS3[5,True,VertexLabels->Automatic]
Out[]=
In[]:=
RecursionCallGraphNKS3[20,True,VertexLabels->Automatic]
Out[]=
In[]:=
SimpleGraph[%]
Out[]=
In[]:=
SimpleGraph[RecursionCallGraphNKS3[100,True,GraphLayout->"LayeredDigraphEmbedding"]]
Out[]=
In[]:=
ListPlot[List@@@EdgeList[RecursionCallGraphNKS3[100,False]]]
Out[]=
In[]:=
ListPlot[List@@@EdgeList[RecursionCallGraphNKS3[500,False]]]
Out[]=
In[]:=
ListPlot[List@@@EdgeList[RecursionCallGraphNKS3[500,True]]]
Out[]=
Unmerged versions
Unmerged versions
Need to add an ID for each number; do not merge identical numbers