Function Resource

NestGraphTagged

A version of NestGraph in which edges corresponding to different outputs are tagged differently

ResourceFunction["NestGraphTagged"][f,expr,n]

gives the tagged graph obtained by starting with expr and applying f successively n times.

Details and Options

expr can be any expression.
ResourceFunction["NestGraphTagged"][f,expr] is equivalent to ResourceFunction["NestGraphTagged"][f,expr,1].
ResourceFunction["NestGraphTagged"][f,expr] gives a graph with tagged edges , where f[expr] evaluates to {expr1,,exprk}.
If function f[expr] returns values of the form exprtag, then those tags are used instead. This can be modified with "TagHead" option.
NestGraph takes the same options as Graph.
ResourceFunction["NestGraphTagged"] accepts the following options:
"StateLabeling"Falsewhether to render states as boxes
"RuleStyling"Automaticlist of styles for edges/rules
"FormattingFunction"Automatichow to format state
"PostProcessGraph"Identitypost process graph
"TagHead"Rulecustom head to associate tags with output values
Any None on the right-hand-side of the rule is dropped from the graph.
One can use integers in place of tagged directed edges to specify EdgeLabels.
PlotLegends can be used to get a legend for different edge rules.

Examples

Basic Examples (5) 

Make a nested graph with edge coloring:

In[1]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][n |-> {2 n, n + 1}, 1, 4]
Out[1]=

Use pure function:

In[2]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][{# - 1, 2 #} &, 1, 4]
Out[2]=

Use a list of initial expressions:

In[3]:=
f[n_] := {n + 1, 2 n, 3 n - 1}
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][f, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 4]
Out[4]=

Add a legend to explain colors:

In[5]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][n |-> {2 n, n + 1, n - 1}, {1}, 4, PlotLegends -> TraditionalForm /@ {2 n, n + 1, n - 1}]
Out[5]=

Label the vertex states in a nested graph:

In[6]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][{2 #, # + 1} &, {1}, 4, "StateLabeling" -> True]
Out[6]=

Scope (4) 

Edge colorings can be overridden:

In[7]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][n |-> {2 n, n + 1}, {1}, 4, "RuleStyling" -> {Black, Orange}]
Out[7]=

Add labels to edges:

In[8]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][n |-> {2 n, n + 1}, {1}, 4, EdgeLabels -> {
   DirectedEdge[_, _, t_] /; OddQ[t] :> Placed[t, {1/2, {-1, 1/2}}],
   DirectedEdge[_, _, t_] /; EvenQ[t] :> Placed[t, {1/2, {1, 1/2}}]}, EdgeLabelStyle -> Directive[12, Bold]]
Out[8]=

Add tooltips to edges:

In[9]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][n |-> {2 n, n + 1}, {1}, 4, EdgeLabels -> Placed["EdgeTag", Tooltip]]
Out[9]=

An alternate type of edge labeling:

In[10]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][n |-> {n + 2, n + 3}, 0, 4, "StateLabeling" -> True,
  EdgeLabels -> {
   1 -> Placed["+2", {.7, {-.2, 0}}], 2 -> Placed["+3", {.7, {-.2, 0}}]
   }]
Out[10]=

Make custom edge tags by constructing rule values:

In[11]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][
 s |-> # -> # & /@ StringReplaceList[s, {"A" -> "AB", "B" -> "A"}], "A", 3, "StateLabeling" -> True, EdgeLabels -> "EdgeTag"]
Out[11]=

Options (5) 

StateLabeling (1) 

Turn on special vertex shapes:

In[12]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][{2 #, # + 1} &, {1}, 4, "StateLabeling" -> True]
Out[12]=

FormattingFunction (1) 

Change the formatting for vertex 31:

In[13]:=
ResourceFunction[
 "https://www.wolframcloud.com/obj/nikm/DeployedResources/Function/\
NestGraphTagged"][n |-> Mod[{2 n + 1, 3 n + 1}, 144], {1}, 200, "StateLabeling" -> True, "FormattingFunction" -> (# /. {31 -> Style[31, Red, Bold, 16], x_ :> Style[x, Black]} &)]
Out[13]=