Function Repository Resource:

CombinatorExpressionGraph

Source Notebook

Show an expression graph for a combinator expression

Contributed by: Wolfram Research

ResourceFunction["CombinatorExpressionGraph"][cmb]

creates an expression graph for the combinator expression cmb.

Details and Options

The input cmb should be given in nested bracket form.
ResourceFunction["CombinatorExpressionGraph"] accepts the same options as ExpressionGraph with the following additions:
"CombinatorRules"Automatictransformation rules for combinators
"CombinatorStyles"Automatichighlight and background colors for combinator rule matches
"EvaluationScheme"{"Leftmost", "Outermost", Infinity}evaluation scheme for combinator rule matches
"ShowVertexLabels"Truewhether to display symbols of atoms in the expression graph
"UpdateHighlighting"{}show updates via "Nodes", "Numbers", and/or "Subtrees"
"MatchHighlighting"Falsewhether root node of subtree is colored according to rule match
"SKGlyphs"Automaticsymbols used to specify S and K combinators

Examples

Basic Examples (3) 

Show an expression graph for a combinator expression:

In[1]:=
ResourceFunction["CombinatorExpressionGraph"][s[x][y][z], AspectRatio -> 1/2, "SKGlyphs" -> {s, k}]
Out[1]=

Show an expression graph where the rule match is indicated:

In[2]:=
ResourceFunction["CombinatorExpressionGraph"][k[x][y], AspectRatio -> 1/2, "MatchHighlighting" -> True, DirectedEdges -> True, "SKGlyphs" -> {s, k}]
Out[2]=

Define custom rules and styles for combinator expression graph rendering:

In[3]:=
ResourceFunction["CombinatorExpressionGraph"][g[a][d][b[c]], "CombinatorRules" -> {g[a_][d_][b_[c_]] -> s[a][k[d[b[c]]]]}, "CombinatorStyles" -> <|
   g -> <|"Highlight" -> Yellow, "Background" -> Lighter[Yellow, .8]|>|>, AspectRatio -> 1/2, "MatchHighlighting" -> True, DirectedEdges -> True]
Out[3]=

Scope (2) 

Select update events by defining an evaluation scheme, and label updates with the order in which they occur:

In[4]:=
ResourceFunction["CombinatorExpressionGraph"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "EvaluationScheme" -> {"Rightmost", "Innermost", 2}, AspectRatio -> 1/2, "UpdateHighlighting" -> {"Numbers", "Subtrees"}, "MatchHighlighting" -> True, DirectedEdges -> True, "SKGlyphs" -> {s, k}]
Out[4]=

Compare the update orders imposed by each different evaluation scheme on a combinator expression:

In[5]:=
ResourceFunction["CombinatorExpressionGraph"][
   s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "EvaluationScheme" -> #, AspectRatio -> 1/2, "UpdateHighlighting" -> {"Nodes", "Numbers"}, "ShowVertexLabels" -> False, DirectedEdges -> True, "SKGlyphs" -> {s, k}] & /@ Join[Tuples[{{"Leftmost", "Rightmost"}, {"Innermost", "Outermost"}}], Tuples[{{"Innermost", "Outermost"}, {"Leftmost", "Rightmost"}}]]
Out[5]=

Version History

  • 1.0.0 – 05 December 2020

Related Resources

License Information