Function Repository Resource:

CombinatorGlocalMultiwaySystem

Source Notebook

Simulate the evaluation of a combinator expression as a "glocal" (hybrid of global and local) multiway system

Contributed by: Jonathan Gorard

ResourceFunction["CombinatorGlocalMultiwaySystem"][rules,init,n]

generates the results of n steps in the glocal multiway evaluation of a combinator expression with the specified rules, starting from initial conditions init.

ResourceFunction["CombinatorGlocalMultiwaySystem"][rulessel,init,n]

uses the function sel to select which of the events obtained at each step to include in the evaluation.

Details and Options

Glocal multiway systems combine the global events (and the corresponding causal structure) of ordinary multiway systems with the individual token philosophy of local multiway systems. A single event vertex in the evolution causal graph (or token event graph) will, in general, have many incoming and outgoing evolution edges, corresponding to the fact that several tokens must be assembled together in order to reconstruct a single global input or output state for the event.
Argument and option patterns for ResourceFunction["CombinatorGlocalMultiwaySystem"] match those of the resource function MultiwayCombinator (and, to a lesser extent, the resource function MultiwaySystem).
Rule and state specifications for ResourceFunction["CombinatorGlocalMultiwaySystem"] are rules and expressions of some combinatory calculus.
ResourceFunction["CombinatorGlocalMultiwaySystem"] accepts both individual rules of combinatory calculus and lists of rules, and likewise for initial conditions. ResourceFunction["CombinatorGlocalMultiwaySystem"][rules,init,n] is interpreted as ResourceFunction["CombinatorGlocalMultiwaySystem"][rules,{init},n] etc.
The event selection function sel in ResourceFunction["CombinatorGlocalMultiwaySystem"][rulessel,] can have the following special forms:
"Sequential"applies the first possible replacement (sequential substitution system)
"Random"applies a random replacement
{"Random",n}applies n randomly chosen replacements
Duplicated tokens are displayed separately at each time step by default, although this can be overridden by setting "DeduplicateTokens"True.
Events are represented in the form {rule,input,rest}, where rule is the rule used in the updating event, input is the part of the state to which the rule is applied and rest is the remainder of the state. For substitution systems, rest is given in the form {prefix,suffix}.
Options for ResourceFunction["CombinatorGlocalMultiwaySystem"] include:
"DeduplicateTokens"Falsewhether to merge all instances of equivalent tokens that appear at each time step
"VertexRendering"Truewhether to use special rendering for state/token and event vertices
"IncludeInitializationEvents"Falsewhether to include pseudoevents that set up initial conditions
"StateRenderingFunction"Automatichow to label states/tokens that appear in the evolution causal graph/token event graph
"EventRenderingFunction"Automatichow to label events that appear in the evolution causal graph/token event graph
All of the standard options for the Graph function can also be applied to ResourceFunction["CombinatorGlocalMultiwaySystem"].
Possible settings for "StateRenderingFunction" and "EventRenderingFunction" include:
Automaticmake a label from the name of the vertex
Inheriteduse the explicit vertex name as the label
Noneuse no label for the vertex
"string"use a shape from the VertexShapeFunction collection
funcapply the function func to the name of the vertex

Examples

Basic Examples (3) 

Generate evolution causal graphs (token event graphs) for two simple glocal multiway combinator evaluations for the fixed-point combinator (i.e. the Y combinator):

In[1]:=
ResourceFunction["CombinatorGlocalMultiwaySystem"][y[f_] :> f[y[f]], y[y[f]], 2]
Out[1]=
In[2]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]}, y[f][y[x]], 2]
Out[2]=

Show just the structure of the graphs, without labels:

In[3]:=
ResourceFunction["CombinatorGlocalMultiwaySystem"][y[f_] :> f[y[f]], y[y[f]], 2, "VertexRendering" -> False]
Out[3]=
In[4]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]}, y[f][y[x]], 2, "VertexRendering" -> False]
Out[4]=

Generate an evolution causal graph (token event graph) for a more complicated glocal multiway combinator evaluation for the S-K calculus:

In[5]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3]
Out[5]=

Show just the structure of the graph, without labels:

In[6]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3, "VertexRendering" -> False]
Out[6]=

Merge all instances of equivalent tokens that appear at each time step:

In[7]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3, "DeduplicateTokens" -> True]
Out[7]=

Run the system for more steps:

In[8]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 5, "DeduplicateTokens" -> True]
Out[8]=

Show just the structure of the graphs, without labels:

In[9]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3, "VertexRendering" -> False, "DeduplicateTokens" -> True]
Out[9]=
In[10]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 5, "VertexRendering" -> False, "DeduplicateTokens" -> True]
Out[10]=

Specify an event selection function that picks only up to two events at each step:

In[11]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]} -> (Take[#, UpTo[2]] &), y[f][y[x]], 3]
Out[11]=

Scope (7) 

Combinatory calculi (2) 

CombinatorGlocalMultiwaySystem supports all forms of combinatory calculi, including the single-variable fixed-point (Y) combinator:

In[12]:=
ResourceFunction["CombinatorGlocalMultiwaySystem"][y[f_] :> f[y[f]], y[f], 3]
Out[12]=

The two-variable fixed-point (Y) combinator:

In[13]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]}, y[f][y[x]], 3]
Out[13]=

The S-K calculus:

In[14]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[s[s[s]]][s][s][k], 6]
Out[14]=

The S-K-I calculus:

In[15]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3]
Out[15]=

Schönfinkel's B and C combinators:

In[16]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{c[f_][g_][x_] :> (f[x])[g], b[f_][g_][x_] :> f[g[x]], i[x_] :> x}, c[i][b[x][i][z]][y], 4]
Out[16]=

Due to the undecidability of the S-K-I combinatory calculus, the following evaluation does not terminate at a normal form:

In[17]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[i][i][s[i][i]], 4]
Out[17]=

Rules and initial conditions (2) 

CombinatorGlocalMultiwaySystem accepts both individual combinator rules and lists of combinator rules:

In[18]:=
ResourceFunction["CombinatorGlocalMultiwaySystem"][
 s[x_][y_][z_] :> x[z][y[z]], s[s[s[s]]][s][s][k], 5]
Out[18]=
In[19]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[s[s[s]]][s][s][k], 6]
Out[19]=

CombinatorGlocalMultiwaySystem accepts both individual initial conditions and lists of initial conditions:

In[20]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3]
Out[20]=
In[21]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, {s[k[s][i]][s[k][k][i]][x][y], s[k[s][i]][s[k][k][i]][y][x]}, 3]
Out[21]=

Event selection functions (3) 

Apply only the first possible event at each step:

In[22]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]} -> "Sequential", y[f][y[x]], 3]
Out[22]=

Apply the first and last possible events at each step:

In[23]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]} -> ({First[#], Last[#]} &), y[f][y[x]], 3]
Out[23]=

Compare this to the full evolution causal graph (token event graph):

In[24]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]}, y[f][y[x]], 3]
Out[24]=

Options (19) 

Token deduplication (2) 

By default, equivalent tokens remain unmerged at each time step:

In[25]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]}, y[f][y[x]], 3]
Out[25]=

Merging of equivalent tokens at each time step can be enforced using the option "DeduplicateTokens":

In[26]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]}, y[f][y[x]], 3, "DeduplicateTokens" -> True]
Out[26]=

Vertex rendering (2) 

By default, state/token vertices and event vertices use special rendering (inherited from the MultiwayCombinator resource function):

In[27]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[s[s[s]]][s][s][k], 6]
Out[27]=

This rendering can be disabled using the option "VertexRendering":

In[28]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x}, s[s[s[s]]][s][s][k], 6, "VertexRendering" -> False]
Out[28]=

State/Token vertex rendering (4) 

By default, states/tokens are labeled by their contents:

In[29]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3]
Out[29]=

Use no labeling for states/tokens:

In[30]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3, "StateRenderingFunction" -> None]
Out[30]=

Use raw state/token names as vertex labels:

In[31]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3, "StateRenderingFunction" -> Inherited]
Out[31]=

Use a named shape as each state/token label:

In[32]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3, "StateRenderingFunction" -> "Square"]
Out[32]=

Event vertex rendering (5) 

By default, both states/tokens and events are labeled by their contents:

In[33]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{c[f_][g_][x_] :> (f[x])[g], b[f_][g_][x_] :> f[g[x]], i[x_] :> x}, c[i][b[x][i][z]][y], 3]
Out[33]=

Use no labeling for states/tokens:

In[34]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{c[f_][g_][x_] :> (f[x])[g], b[f_][g_][x_] :> f[g[x]], i[x_] :> x}, c[i][b[x][i][z]][y], 3, "StateRenderingFunction" -> None]
Out[34]=

Also use no labeling for events:

In[35]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{c[f_][g_][x_] :> (f[x])[g], b[f_][g_][x_] :> f[g[x]], i[x_] :> x}, c[i][b[x][i][z]][y], 3, "StateRenderingFunction" -> None, "EventRenderingFunction" -> None]
Out[35]=

Disabling vertex rendering yields an equivalent result:

In[36]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{c[f_][g_][x_] :> (f[x])[g], b[f_][g_][x_] :> f[g[x]], i[x_] :> x}, c[i][b[x][i][z]][y], 3, "VertexRendering" -> False]
Out[36]=

Use raw event expressions as their labels:

In[37]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{c[f_][g_][x_] :> (f[x])[g], b[f_][g_][x_] :> f[g[x]], i[x_] :> x}, c[i][b[x][i][z]][y], 3, "StateRenderingFunction" -> None, "EventRenderingFunction" -> Inherited]
Out[37]=

Initialization events (3) 

By default, combinator glocal multiway systems do not include initialization events:

In[38]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, {s[k[s][i]][s[k][k][i]][x][y], s[k[s][i]][s[k][k][i]][y][x]}, 2]
Out[38]=

The option "IncludeInitializationEvents" allows one to override this default (note that initialization events have special default rendering):

In[39]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, {s[k[s][i]][s[k][k][i]][x][y], s[k[s][i]][s[k][k][i]][y][x]}, 2, "IncludeInitializationEvents" -> True]
Out[39]=

Disable vertex rendering:

In[40]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, {s[k[s][i]][s[k][k][i]][x][y], s[k[s][i]][s[k][k][i]][y][x]}, 2, "VertexRendering" -> False, "IncludeInitializationEvents" -> True]
Out[40]=

Graph layout options (3) 

Place arrows in the middle of edges:

In[41]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{y[f_] :> f[y[f]], y[f_][x_] :> f[y[f]][x]}, y[f][y[x]], 2, EdgeShapeFunction -> GraphElementData["ShortFilledArrow", "ArrowSize" -> 0.03]]
Out[41]=

Generate an example of glocal multiway combinator evaluation:

In[42]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3]
Out[42]=

Force a layered digraph embedding (with the initial state/tokens at the top):

In[43]:=
ResourceFunction[
 "CombinatorGlocalMultiwaySystem"][{s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, i[x_] :> x}, s[k[s][i]][s[k][k][i]][x][y], 3, GraphLayout -> "LayeredDigraphEmbedding", AspectRatio -> 1/4]
Out[43]=

Publisher

Jonathan Gorard

Version History

  • 1.0.0 – 03 January 2022

Source Metadata

Related Resources

License Information