Wolfram Research

Function Repository Resource:

TokenEventGraph (2.2.0) current version: 3.0.0 »

Source Notebook

Generate a token-event graph for multicomputational evolution according to particular rules

Contributed by: Stephen Wolfram and Nikolay Murzin

ResourceFunction["TokenEventGraph"][rules, init, t]

generates a token-event graph for t steps of evolution according to rules from init.

Details and Options

ResourceFunction["TokenEventGraph"] accepts the following options:
"Mode""Tuples"how to match multiple tokens: "Tuples", "OrderedTuples" or "Subsets"
"TokenDeduplication"Truewhether to deduplicate tokens, False deduplicates across time steps, None turn off deduplication completely
"EventDeduplication"Falsewhether to deduplicate events
"EdgeDeduplication"Falsewhether to remove multiedges
"RemoveEventLoops"Truewhether to remove event edge loops
"RemoveEmptyEvents"Truewheter to remove events with no outputs
"TokenDecompositionFunction"Automaticfunction to decompose a state into a list of tokens
"TokenRecombinationFunction"Automaticfunction to combine a list of output tokens into list of states
"MultiOutputEvents"Truewhether to allow multi-output events
"StateVertices"Falsewheter to include additional vertices indicating states
"TokenLabeling"Truehow to label token vertices
"EventLabeling"Nonehow to label event vertices
"TokenRenderingFunction"Identityhow to render tokens inside boxes
"TokenStyleOptions"Automaticoptions for token box Style
"TokenFrameOptions"Automaticoptions for token box Frame
"TokenLabeling"Automatic uses ordinary vertex labels; "TokenLabeling"True uses boxes for each vertex.
"EventLabeling"Automatic uses ordinarily placed vertex labels; "EventLabeling"True uses in-circle labeling for each vertex; "EventLabeling""Colors" uses a different color for each rule index.
Event vertices have the form {"Event", timeStep, ruleIndex, positions, eventIndex}.
Edges are tagged by list indices. Rules with associations produce tagged edges with keys as tags.

Examples

Basic Examples (2) 

Make a token-event graph of a simple rule:

In[1]:=
ResourceFunction["TokenEventGraph"][n_ :> {n + 1, n + 2}, {1, 2}, 2]
Out[1]=

Multiple rules:

In[2]:=
ResourceFunction["TokenEventGraph"][{n_ :> n + 1, n_ :> 2 n}, {1, 2},
  2]
Out[2]=

Scope (3) 

Make a WolframModel-like TokenEventGraph:

In[3]:=
Module[{w = 0}, ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{{{x_, y_}, {y_, z_}} :> {{w++, y}, {y, z}, {z, w}, {x, w}}}, {{0, 0}}, 3, AspectRatio -> 1/2]]
Out[3]=

Edges are tagged by corresponding input or output list index:

In[4]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_, m_} :> {n - m, m - n}, {1, 2}, 2, EdgeLabels -> "EdgeTag"]
Out[4]=

Tag edges with keys by having associations on both sides of a rule:

In[5]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][<|"left" -> n_, "right" :> m_|> :> <|"-" -> n - m,
    "+" -> n + m|>, {1, 2}, 1, EdgeLabels -> "EdgeTag"]
Out[5]=

Options (15) 

Mode (1) 

Mode of picking tokens can be one of: "Tuples" (default), "OrderedTuples", "Subsets":

In[6]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_, m_} :> n + m, {1, 2, 3, 4}, 1, "Mode" -> "Tuples"]
Out[6]=
In[7]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_, m_} :> n + m, {1, 2, 3, 4}, 1, "Mode" -> "OrderedTuples"]
Out[7]=
In[8]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_, m_} :> n + m, {1, 2, 3, 4}, 1, "Mode" -> "Subsets"]
Out[8]=

TokenDeduplication (3) 

Every token is deduplicated by default:

In[9]:=
ResourceFunction["TokenEventGraph"][
 f[n_] /; n > 2 :> {f[n - 1], f[n - 2]}, {f[7]}, 4, "TokenDeduplication" -> True]
Out[9]=

"TokenDeduplication"False turns off deduplication across time steps:

In[10]:=
ResourceFunction["TokenEventGraph"][
 f[n_] /; n > 2 :> {f[n - 1], f[n - 2]}, {f[7]}, 4, "TokenDeduplication" -> False]
Out[10]=

"TokenDeduplication"None turns off any deduplication:

In[11]:=
ResourceFunction["TokenEventGraph"][
 f[n_] /; n > 2 :> {f[n - 1], f[n - 2]}, {f[7]}, 4, "TokenDeduplication" -> None]
Out[11]=

EdgeDeduplication (1) 

Remove multiedges:

In[12]:=
ResourceFunction["TokenEventGraph"][{n_, m_} :> n + m, {1, 2}, 2, "EdgeDeduplication" -> False]
Out[12]=
In[13]:=
ResourceFunction["TokenEventGraph"][{n_, m_} :> n + m, {1, 2}, 2, "EdgeDeduplication" -> True]
Out[13]=

EventDeduplication (1) 

Keep or remove duplicate events:

In[14]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_ :> n + 1, n_ :> 2 n}, {1, 2}, 2, "EventDeduplication" -> False]
Out[14]=
In[15]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_ :> n + 1, n_ :> 2 n}, {1, 2}, 2, "EventDeduplication" -> True]
Out[15]=

StateVertices (1) 

Include state vertices:

In[16]:=
ResourceFunction["TokenEventGraph"][{n_, m_} :> {n m, n + m}, {3}, 2, "StateVertices" -> False]
Out[16]=
In[17]:=
ResourceFunction["TokenEventGraph"][{n_, m_} :> {n m, n + m}, {3}, 2, "StateVertices" -> True]
Out[17]=

TokenDecompositionFunction (1) 

Specify how states are decomposed into a list of tokens:

In[18]:=
ResourceFunction["TokenEventGraph"][{n_, m_} :> {n m, n + m}, {3}, 2, "TokenDecompositionFunction" -> Select[OddQ]@*Echo, "StateVertices" -> True]
Out[18]=

TokenRecombinationFunction (1) 

Specify how tokens are recombined into states, default is a single state containing union of all output tokens. Here is an example of making a separate state from each token:

In[19]:=
ResourceFunction["TokenEventGraph"][{n_, m_} :> {n m, n + m}, {3}, 3, "TokenRecombinationFunction" -> Map[List]@*Catenate@*Echo, "StateVertices" -> True]
Out[19]=

MultiOutputEvents (1) 

Split each event with multiple outputs into separate events:

In[20]:=
ResourceFunction["TokenEventGraph"][n_ :> {n + 1, n + 2}, {1, 2}, 2, "MultiOutputEvents" -> True]
Out[20]=
In[21]:=
ResourceFunction["TokenEventGraph"][n_ :> {n + 1, n + 2}, {1, 2}, 2, "MultiOutputEvents" -> False]
Out[21]=

TokenLabeling (1) 

Disable custom token labeling:

In[22]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_ :> n + 1, n_ :> 2 n}, {1, 2}, 2, "TokenLabeling" -> None]
Out[22]=

EventLabeling (1) 

Label events by its rule index:

In[23]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_ :> n + 1, n_ :> 2 n}, {1, 2}, 2, "EventDeduplication" -> False, "EventLabeling" -> "Colors"]
Out[23]=

TokenRenderingFunction (1) 

Specify rendering for the token:

In[24]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_ :> n + 1, n_ :> 2 n}, {1, 2}, 2, "TokenRenderingFunction" -> (Style[#, 12, Bold, Red] &)]
Out[24]=

TokenStyleOptions (1) 

Provide style options for token boxes:

In[25]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_ :> n + 1, n_ :> 2 n}, {1, 2}, 2, "TokenStyleOptions" -> {FontFamily -> "Helvetica", FontColor -> Orange}]
Out[25]=

TokenFrameOptions (1) 

Provide frame options for token boxes:

In[26]:=
ResourceFunction["TokenEventGraph", ResourceVersion->"2.2.0"][{n_ :> n + 1, n_ :> 2 n}, {1, 2}, 2, "TokenFrameOptions" -> {FrameMargins -> 0, Background -> Green}]
Out[26]=

Version History

  • 3.0.0 – 22 April 2024
  • 2.2.0 – 14 March 2022
  • 2.1.0 – 07 March 2022
  • 2.0.0 – 23 February 2022
  • 1.2.0 – 15 February 2022
  • 1.1.2 – 19 January 2022

Related Resources

License Information