Wolfram Research

Function Repository Resource:

CombinatorPlot

Source Notebook

Visualize a static combinator expression

Contributed by: Wolfram Research

ResourceFunction["CombinatorPlot"][cmb,"FramedMatches"]

highlights rule matches in the combinator expression cmb.

ResourceFunction["CombinatorPlot"][cmb,{"FramedPositions",posns}]

highlights rule matches at given positions posns in the combinator expression cmb.

ResourceFunction["CombinatorPlot"][cmb,type]

displays various kinds of character-based forms or array lists of cmb, depending on the type chosen.

Details and Options

The argument cmb should be a combinator expression given in nested bracket form.
The possible valid inputs for posns can be found by using the resource function CombinatorMatches on cmb.
ResourceFunction["CombinatorPlot"] accepts the following type specifications:
"Characters" displays cmb with any specified glyphs and glyph styling
"CharactersLeftAssociative" displays cmb assuming left-associativity of application operator
"CharactersRightAssociative" displays cmb assuming right-associativity of application operator
"CharactersPolishNotation" displays cmb using parenthesis-free operator prefix notation
"CharactersReversePolishNotation" displays cmb using parenthesis-free operator postfix notation
"ArrayList" directly transforms cmb into a form usable in ArrayPlot
"ArrayListLeftAssociative" transforms left-associative form of cmb into form usable by ArrayPlot
"ArrayListRightAssociative" transforms right-associative form of cmb into form usable by ArrayPlot
"ArrayListPolishNotation" transforms Polish notation form of cmb into form usable by ArrayPlot
"ArrayListReversePolishNotation" transforms reverse Polish notation form of cmb into form usable by ArrayPlot
"ArrayListBracketsOnly" transforms bracket structure of cmb into form usable by ArrayPlot
ResourceFunction["CombinatorPlot"] has the same options as ArrayPlot, with the following additions:
"SKGlyphs" Automatic glyphs used for S and K combinators in cmb
"ApplicationGlyph" "" glyph and styles used for application operator
"ColorCombinatorNames" False whether combinator names should be colored in characters form
"CombinatorRules" Automatic combinator rules used to evolve cmb
"CombinatorStyles" Automatic highlight/detail coloring and text style for rule matches in cmb
"EvaluationScheme" {"Leftmost","Outermost",1} evaluation scheme used to evolve cmb
"FormatFunction" DisplayForm function used to format character form of cmb
"IncludeArgumentFraming" True whether combinator/arguments are separated in match highlighting
"IncludeBackgroundFraming" False whether non-highlighted matches are shown on cmb
"ParenthesisGlyphs" {"(",")"} glyphs and styles used to represent parentheses
"UseCombinatorGlyphs" None which combinators should be represented with their glyphs

Examples

Basic Examples (13) 

Show the leftmost outermost rule match in a combinator expression:

In[1]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "FramedMatches", "SKGlyphs" -> {s, k}]
Out[1]=

Show all matches in a combinator expression:

In[2]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "FramedMatches", "EvaluationScheme" -> All, "SKGlyphs" -> {s, k}]
Out[2]=

Show all the rule matches in a combinator expression without showing the separation between the combinator and its arguments:

In[3]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "FramedMatches", "EvaluationScheme" -> All, "IncludeArgumentFraming"  -> False, "SKGlyphs" -> {s, k}]
Out[3]=

Highlight matches for a selected combinator evaluation scheme:

In[4]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "FramedMatches", "EvaluationScheme" -> {"Leftmost", "Innermost", 2}, "IncludeArgumentFraming" -> False, "IncludeBackgroundFraming" -> True, "SKGlyphs" -> {s, k}]
Out[4]=

As well as highlighting all matches within a selected combinator evaluation scheme, indicate where all other rule matches occur:

In[5]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "FramedMatches", "EvaluationScheme" -> {"Leftmost", "Innermost", 2}, "IncludeArgumentFraming" -> False, "IncludeBackgroundFraming" -> True, "SKGlyphs" -> {s, k}]
Out[5]=

Highlight selected positions in a combinator expression, given that the positions correspond to rule matches:

In[6]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][
  k[x][y][z]], {"FramedPositions", {{1, 0}, {0, 0, 0, 1, 1}, {2}}}, "SKGlyphs" -> {s, k}, "IncludeBackgroundFraming" -> True]
Out[6]=

Show a combinator expression with colored combinator glyphs:

In[7]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "Characters", "SKGlyphs" -> {s, k}, "ColorCombinatorNames" -> True]
Out[7]=

Show a combinator expression with colored combinator glyphs. Note that the Automatic value for "UseCombinatorGlyphs" sets the assumption that the CombinatorS and CombinatorK glyphs should be used for the corresponding characters:

In[8]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "Characters", "SKGlyphs" -> {s, k}, "UseCombinatorGlyphs" -> Automatic, "ColorCombinatorNames" -> True]
Out[8]=

Show a combinator expression assuming that all seven built-in combinator glyphs should be used:

In[9]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "Characters", "SKGlyphs" -> {s, k}, "UseCombinatorGlyphs" -> {s, k, i, b, c, w, y}]
Out[9]=

Display a combinator expression in traditional form with the left-associative application operator, combinator glyphs, and styled parentheses:

In[10]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][
  k[x][y][z]], "CharactersLeftAssociative", "UseCombinatorGlyphs" -> Automatic, "ApplicationGlyph" -> "\[Application]", "ParenthesisGlyphs" -> {Style["(", Bold], Style[")", Bold]}, "FormatFunction" -> TraditionalForm, "SKGlyphs" -> {s, k}]
Out[10]=

Display a combinator expression in traditional form with right-associative application, combinator glyphs, and styled brackets:

In[11]:=
ResourceFunction["CombinatorPlot"][
 s[s[x][y][s[x][y][z]]][y][z][
  k[x][y][z]], "CharactersRightAssociative", "UseCombinatorGlyphs" -> Automatic,  "ApplicationGlyph" -> "", "ParenthesisGlyphs" -> {Style["(", Bold], Style[")", Bold]}, "FormatFunction" -> TraditionalForm, "SKGlyphs" -> {s, k}]
Out[11]=

Display a combinator expression in Polish (prefix) notation:

In[12]:=
ResourceFunction["CombinatorPlot"][
 s[s[s[s]][k[s[s[s]][s]][s]]][
  k[s[s[s]][s]][s][
   s[s[s]][k[s[s[s]][s]][s]]]], "CharactersPolishNotation", "ApplicationGlyph" -> "\[Application]", "SKGlyphs" -> {s, k}, "UseCombinatorGlyphs" -> Automatic]
Out[12]=

Display a combinator expression in reverse Polish (postfix) notation:

In[13]:=
ResourceFunction["CombinatorPlot"][
 s[s[s[s]][k[s[s[s]][s]][s]]][
  k[s[s[s]][s]][s][
   s[s[s]][k[s[s[s]][s]][s]]]], "CharactersReversePolishNotation", "ApplicationGlyph" -> "\[Application]", "SKGlyphs" -> {s, k}, "UseCombinatorGlyphs" -> Automatic]
Out[13]=

Scope (8) 

Define rules and styling for match highlighting in a combinator expression:

In[14]:=
ResourceFunction["CombinatorPlot"][
 g[a][d][b[
   g[a][d][b[g[s[x][y][k[x][y]]][d][b[c]]]]]], "FramedMatches", "CombinatorRules" -> {s[x_][y_][z_] :> x[z][y[z]], k[x_][y_] :> x, g[a_][d_][b_[c_]] :>  s[a][k[d[b[c]]]]}, "CombinatorStyles" -> <|
   s -> <|"Highlight" -> RGBColor[
      0.8823529411764706, 0.29411764705882354`, 0.2980392156862745], "Background" -> RGBColor[
      0.996078431372549, 0.8235294117647058, 0.8392156862745098], "MatchText" -> Bold|>, k -> <|"Highlight" -> RGBColor[
      0.13333333333333333`, 0.396078431372549, 0.7686274509803922], "Background" -> RGBColor[
      0.8, 0.8823529411764706, 0.996078431372549], "MatchText" -> Bold|>, g -> <|"Highlight" -> RGBColor[1, 1, 0], "Background" -> RGBColor[1., 1., 0.8], "MatchText" -> Bold|>|>, "EvaluationScheme" -> All, "IncludeArgumentFraming" -> True]
Out[14]=

Return information about a combinator expression usable in an ArrayPlot; the first association contains rule match expression positions and rule numbers, the second list contains character lengths of the rule matches, the third list contains character positions at which the rule matches begin and the last list contains a form of the combinator expression that can be used in ArrayPlot:

In[15]:=
ResourceFunction["CombinatorPlot"][
  s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "ArrayList", "SKGlyphs" -> {s, k}] // Column
Out[15]=

Display an array plot for a static combinator expression:

In[16]:=
ArrayPlot[{Last[
   ResourceFunction["CombinatorPlot"][
    s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "ArrayList", "SKGlyphs" -> {s, k}]]}, FrameTicks -> {True, True, False, False}, ColorRules -> {1 -> RGBColor[
    0.8823529411764706, 0.29411764705882354`, 0.2980392156862745], 2 -> RGBColor[
    0.13333333333333333`, 0.396078431372549, 0.7686274509803922], 3 -> RGBColor[1, 1, 0.85], 4 -> RGBColor[1, 1, 0.85], 5 -> RGBColor[1, 0.925, 0.925]}]
Out[16]=

Render an array plot of a left-associative combinator expression:

In[17]:=
ArrayPlot[{Last[
   ResourceFunction["CombinatorPlot"][
    s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "ArrayListLeftAssociative", "SKGlyphs" -> {s, k}]]}, FrameTicks -> {True, True, False, False}, ColorRules -> {1 -> RGBColor[
    0.8823529411764706, 0.29411764705882354`, 0.2980392156862745], 2 -> RGBColor[
    0.13333333333333333`, 0.396078431372549, 0.7686274509803922], 3 -> GrayLevel[0.9], 4 -> RGBColor[1, 1, 0.85], 5 -> RGBColor[1, 1, 0.85], 6 -> RGBColor[1, 0.925, 0.925]}]
Out[17]=

Render an array plot of a right-associative combinator expression:

In[18]:=
ArrayPlot[{Last[
   ResourceFunction["CombinatorPlot"][
    s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "ArrayListRightAssociative", "SKGlyphs" -> {s, k}]]}, FrameTicks -> {True, True, False, False}, ColorRules -> {1 -> RGBColor[
    0.8823529411764706, 0.29411764705882354`, 0.2980392156862745], 2 -> RGBColor[
    0.13333333333333333`, 0.396078431372549, 0.7686274509803922], 3 -> GrayLevel[0.9], 4 -> RGBColor[1, 1, 0.85], 5 -> RGBColor[1, 1, 0.85], 6 -> RGBColor[1, 0.925, 0.925]}]
Out[18]=

Render an array plot of a combinator expression in Polish notation:

In[19]:=
ArrayPlot[{ResourceFunction["CombinatorPlot"][
   s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "ArrayListPolishNotation", "SKGlyphs" -> {s, k}]}, FrameTicks -> {True, True, False, False}, ColorRules -> {1 -> RGBColor[
    0.8823529411764706, 0.29411764705882354`, 0.2980392156862745], 2 -> RGBColor[
    0.13333333333333333`, 0.396078431372549, 0.7686274509803922], 3 -> GrayLevel[0.9], 4 -> RGBColor[1, 0.925, 0.925]}]
Out[19]=

Render an array plot of a combinator expression in reverse Polish notation:

In[20]:=
ArrayPlot[{ResourceFunction["CombinatorPlot"][
   s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "ArrayListReversePolishNotation", "SKGlyphs" -> {s, k}]}, FrameTicks -> {True, True, False, False}, ColorRules -> {1 -> RGBColor[
    0.8823529411764706, 0.29411764705882354`, 0.2980392156862745], 2 -> RGBColor[
    0.13333333333333333`, 0.396078431372549, 0.7686274509803922], 3 -> GrayLevel[0.9], 4 -> RGBColor[1, 0.925, 0.925]}]
Out[20]=

Render an array plot of a combinator expression in brackets-only form:

In[21]:=
ArrayPlot[{Last[
   ResourceFunction["CombinatorPlot"][
    s[s[x][y][s[x][y][z]]][y][z][k[x][y][z]], "ArrayListBracketsOnly", "SKGlyphs" -> {s, k}]]}, FrameTicks -> {True, True, False, False}, ColorRules -> {1 -> GrayLevel[0], 2 -> GrayLevel[0.85]}]
Out[21]=

Resource History

Related Resources

License Information