Function Repository Resource:

CombinatorConvert

Source Notebook

Convert between different combinator formats

Contributed by: Mano Namuduri and Jan Mangaldan

ResourceFunction["CombinatorConvert"][cmb,format]

converts a combinator expression cmb to the specified format.

ResourceFunction["CombinatorConvert"][transform]

interconverts a combinator transformation rule transform between the RuleDelayed and Function formats.

ResourceFunction["CombinatorConvert"][transform,name]

interconverts a combinator transformation rule transform using the symbol name to designate the combinator on the left-hand side when converting to RuleDelayed.

Details

The following settings for format are supported:
"Application"combinator represented in terms of Application,S(K(SI))(S(KK)I)xy
"List"combinator represented as a list, {{{{S, {K, {S,I}}}, {{S, {K,K}}, I}}, x}, y}
"Nested"combinator in nested bracket format, S[K[S[I]]][S[K[K]][I]][x][y]
"String"combinator represented as a left-associative string, "S(K(SI))(S(KK)I)xy"
Accordingly, the argument cmb can be given in any of the above formats.
If transform is given as a RuleDelayed (lhsrhs), then ResourceFunction["CombinatorConvert"] will return a pure Function. If transform is given as a Function (arg body), then ResourceFunction["CombinatorConvert"] will return a RuleDelayed.
The argument name, if specified, should be given as a Symbol (default is λ).

Examples

Basic Examples (5) 

Convert a combinator expression in application format to each of the possible formats:

In[1]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS\[Application](CombinatorK\[Application]CombinatorS)\[Application]CombinatorK, "Application"]
Out[1]=
In[2]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS\[Application](CombinatorK\[Application]CombinatorS)\[Application]CombinatorK, "List"]
Out[2]=
In[3]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS\[Application](CombinatorK\[Application]CombinatorS)\[Application]CombinatorK, "Nested"]
Out[3]=
In[4]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS\[Application](CombinatorK\[Application]CombinatorS)\[Application]CombinatorK, "String"]
Out[4]=

Convert a combinator expression in nested bracket format to each of the possible formats:

In[5]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS[
  CombinatorS[CombinatorK[CombinatorS]][CombinatorK]], "Application"]
Out[5]=
In[6]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS[
  CombinatorS[CombinatorK[CombinatorS]][CombinatorK]], "List"]
Out[6]=
In[7]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS[
  CombinatorS[CombinatorK[CombinatorS]][CombinatorK]], "Nested"]
Out[7]=
In[8]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS[
  CombinatorS[CombinatorK[CombinatorS]][CombinatorK]], "String"]
Out[8]=

Convert a combinator expression in list format to each of the possible formats:

In[9]:=
ResourceFunction[
 "CombinatorConvert"][{{CombinatorS, {CombinatorK, {CombinatorS, {{CombinatorS, CombinatorK}, CombinatorK}}}}, CombinatorK}, "Application"]
Out[9]=
In[10]:=
ResourceFunction[
 "CombinatorConvert"][{{CombinatorS, {CombinatorK, {CombinatorS, {{CombinatorS, CombinatorK}, CombinatorK}}}}, CombinatorK}, "List"]
Out[10]=
In[11]:=
ResourceFunction[
 "CombinatorConvert"][{{CombinatorS, {CombinatorK, {CombinatorS, {{CombinatorS, CombinatorK}, CombinatorK}}}}, CombinatorK}, "Nested"]
Out[11]=
In[12]:=
ResourceFunction[
 "CombinatorConvert"][{{CombinatorS, {CombinatorK, {CombinatorS, {{CombinatorS, CombinatorK}, CombinatorK}}}}, CombinatorK}, "String"]
Out[12]=

Convert a combinator expression in list format to each of the possible formats (note that the conversion from string format only allows single-character symbols, so combinator glyphs would need to be inserted retroactively):

In[13]:=
ResourceFunction["CombinatorConvert"]["S(SS)S(SK)", "Application"] /. {S -> CombinatorS, K -> CombinatorK}
Out[13]=
In[14]:=
ResourceFunction["CombinatorConvert"]["S(SS)S(SK)", "List"] /. {S -> CombinatorS, K -> CombinatorK}
Out[14]=
In[15]:=
ResourceFunction["CombinatorConvert"]["S(SS)S(SK)", "Nested"] /. {S -> CombinatorS, K -> CombinatorK}
Out[15]=
In[16]:=
ResourceFunction["CombinatorConvert"]["S(SS)S(SK)", "String"]
Out[16]=

Convert between the RuleDelayed and Function formats of the CombinatorB transformation:

In[17]:=
ResourceFunction["CombinatorConvert"][
 CombinatorB[a_][b_][c_] :> a[b[c]]]
Out[17]=
In[18]:=
ResourceFunction["CombinatorConvert"][{a, b, c} |-> a[b[c]]]
Out[18]=

When converting from Function to RuleDelayed, a second argument must be supplied for the correct symbol to appear on the left-hand side:

In[19]:=
ResourceFunction[
 "CombinatorConvert"][{a, b, c} |-> a[b[c]], CombinatorB]
Out[19]=

Possible Issues (3) 

Input strings containing any symbol other than letters, digits or parentheses are currently not supported:

In[20]:=
ResourceFunction["CombinatorConvert"][
   "S\[Application](S\[Application]S)\[Application]S\[Application](S\[Application]K)", #] & /@ {"Application", "List", "Nested", "String"}
Out[20]=

Input strings must be in left-associative format:

In[21]:=
ResourceFunction["CombinatorConvert"][
   "((SSS)S)SK", #] & /@ {"Application", "List", "Nested", "String"}
Out[21]=

A combinator transformation must be a RuleDelayed or Function object:

In[22]:=
ResourceFunction["CombinatorConvert"][
 CombinatorS[CombinatorS[CombinatorK]]]
Out[22]=

Version History

  • 1.0.0 – 10 March 2021

Related Resources

License Information