Function Repository Resource:

TokenEventGraph

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", "Subsets” or "OrderlessSubsets"
"TokenDeduplication"Truewhether to deduplicate tokens, False deduplicates across time steps, None turn off deduplication completely
"EventDeduplication"Falsewhether to deduplicate events: False,True, "Inputs", "Outputs”, All
"EdgeDeduplication"Falsewhether to remove multiedges
"RemoveEventLoops"Falsewhether to remove event edge loops
"RemoveEmptyEvents"Truewhether to remove events with no outputs
"TokenDecompositionFunction"Automaticfunction to decompose a state into a list of tokens
"TokenRecombinationFunction"({Union@@#1}&)function to combine a list of output tokens into list of states
“TokenEquivalenceFunction"SameQfunction to merge equivalent tokens
"EventStoreFunction"Splice[{#1,#2,#3,#4}] &what part of an event to store inside an event vertex
"MultiOutputEvents"Truewhether to allow multi-output events
"EventVertices"Truewhether to include event vertices
"StateVertices"Falsewhether to include state vertices
"TokenVertices"Truewhether to include token vertices
"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 by default have the form {"Event", timeStep, ruleIndex, positions, eventIndex}, which can be changed with the option "EventStoreFunction", whose value should be a function which takes {timeStep, ruleIndex, eventIndex, positions, inputs, outputs} as arguments.
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", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][n_ :> {n + 1, n + 2}, {{1, 2}}, 2]
Out[1]=

Multiple rules:

In[2]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2]
Out[2]=

Scope (3) 

Make a Wolfram Model-like TokenEventGraph:

In[3]:=
Module[{w = 0}, ResourceFunction[
  "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.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", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.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", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][<|"left" -> n_, "right" :> m_|> :> <|
   "-" -> n - m, "+" -> n + m|>, {{1, 2}}, 1, "Mode" -> "Tuples", EdgeLabels -> "EdgeTag"]
Out[5]=

Options (22) 

Mode (1) 

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

In[6]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> EchoLabel[{n, m}][n + m], {{1, 2}}, 1, "Mode" -> "Tuples"]
Out[6]=
In[7]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> EchoLabel[{n, m}][n + m], {{1, 2}}, 1, "Mode" -> "OrderedTuples"]
Out[7]=
In[8]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> EchoLabel[{n, m}][n + m], {{1, 2}}, 1, "Mode" -> "Subsets"]
Out[8]=
In[9]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> EchoLabel[{n, m}][n + m], {{1, 2}}, 1, "Mode" -> "OrderlessSubsets"]
Out[9]=

TokenDeduplication (3) 

Every token is deduplicated by default:

In[10]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
 f[n_] /; n > 2 :> {f[n - 1], f[n - 2]}, {{f[7]}}, 4]
Out[10]=

"TokenDeduplication"False turns off deduplication across time steps:

In[11]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
 f[n_] /; n > 2 :> {f[n - 1], f[n - 2]}, {{f[7]}}, 4, "TokenDeduplication" -> False]
Out[11]=

"TokenDeduplication"None turns off any deduplication:

In[12]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
 f[n_] /; n > 2 :> {f[n - 1], f[n - 2]}, {{f[7]}}, 4, "TokenDeduplication" -> None]
Out[12]=

EdgeDeduplication (1) 

Remove multiedges:

In[13]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> n + m, {{1, 2}}, 2, "EdgeDeduplication" -> True]
Out[13]=

EventDeduplication (3) 

Deduplicate events based on a rule:

In[14]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "EventDeduplication" -> True, VertexLabels -> {"Event", _, id_, ___} :> id]
Out[14]=

Deduplicate events based on its "Inputs", "Outputs" or both:

In[15]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "EventDeduplication" -> "Inputs"]
Out[15]=
In[16]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "EventDeduplication" -> "Outputs"]
Out[16]=

Deduplicate all events:

In[17]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "EventDeduplication" -> All]
Out[17]=

EventVertices (1) 

Exclude event vertices:

In[18]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{3}}, 2, "EventVertices" -> False]
Out[18]=

StateVertices (1) 

Include state vertices:

In[19]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{3}}, 2, "StateVertices" -> True]
Out[19]=

TokenVertices (1) 

Exclude token vertices:

In[20]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{3}}, 2, "TokenVertices" -> False]
Out[20]=

TokenDecompositionFunction (1) 

Specify how states are decomposed into a list of tokens:

In[21]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{3}}, 3, "TokenDecompositionFunction" -> Select[OddQ]@*Echo, "StateVertices" -> True]
Out[21]=

TokenRecombinationFunction (1) 

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

In[22]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{3}}, 3, "TokenRecombinationFunction" -> ({outputs, inputs, stateTokens} |-> Flatten[outputs]), "StateVertices" -> True]
Out[22]=

TokenEquivalenceFunction (1) 

Specify an equivalence function for tokens:

In[23]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{1}}, 3, "TokenEquivalenceFunction" -> (Mod[#1, 3] == Mod[#2, 3] &)]
Out[23]=

EventStoreFunction (2) 

Change what is stored inside "Event" vertices:

In[24]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{2, 3}}, 1, "EventStoreFunction" -> ({stepId, ruleId, eventId, pos, inputs, ouputs} |-> Splice[{inputs, ouputs}]), VertexLabels -> {"Event", ___} -> Placed[Automatic, Center]]
Out[24]=

By default, only stepId, ruleId, eventId and positions are stored:

In[25]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_, m_} :> {n m, n + m}, {{2, 3}}, 1, VertexLabels -> {"Event", ___} -> Placed[Automatic, Center]]
Out[25]=

MultiOutputEvents (1) 

Whether to split each event with multiple outputs into separate events:

In[26]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][n_ :> {n + 1, n + 2}, {{1, 2}}, 2, "MultiOutputEvents" -> True]
Out[26]=
In[27]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][n_ :> {n + 1, n + 2}, {{1, 2}}, 2, "MultiOutputEvents" -> False]
Out[27]=

TokenLabeling (1) 

Disable custom token labeling:

In[28]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "TokenLabeling" -> None]
Out[28]=

EventLabeling (1) 

Label events by its rule index:

In[29]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "EventDeduplication" -> False, "EventLabeling" -> "Colors"]
Out[29]=

TokenRenderingFunction (1) 

Specify rendering for the tokens:

In[30]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "TokenRenderingFunction" -> (Style[#, 12, Bold, Red] &)]
Out[30]=

TokenStyleOptions (1) 

Provide style options for token boxes:

In[31]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "TokenStyleOptions" -> {FontFamily -> "Helvetica", FontColor -> Orange}]
Out[31]=

TokenFrameOptions (1) 

Provide frame options for token boxes:

In[32]:=
ResourceFunction[
 "TokenEventGraph", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{n_ :> n + 1, n_ :> 2 n}, {{1, 2}}, 2, "TokenFrameOptions" -> {FrameMargins -> 0, Background -> Green}]
Out[32]=

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 3.1.0 – 23 October 2024
  • 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

Author Notes

Changes in 3.0.0: - Init now takes an additional level of list, which makes it possible to start from multiple states, with each state having multiple tokens - bugfix and generalize EventDeduplication Changes in 3.1.0: - Fix Condition and PatternTest - Support "OrderlessSubsets" mode, as in MultiReplace

License Information