Catalan Numbers

Charlene Chu - October 27, 2017

Objective

Construct a function Poster[n, a list of methods] to draw the poster representing the Catalan numbers.

Implementation

Backbone

The following code constructs a list of diagonals for the triangulations. We will use this code to further construct the actual triangulations, trees, and non-associative words used to construct the poster.

ts[n_Integer] := ts[Range[0,n+1]];
ts[{_,_}]={ds[]};
ts[vs_List] := Module[{l,r,k,t1,t2,tds},
Union@@Table[
l = ts[Prepend[vs[[k;;]],vs[[1]]]];
r = ts[vs[[2;;k]]];
Flatten[Table[
tds = Join[t1,t2];
If[k>3,AppendTo[tds,d[vs[[2]],vs[[k]]]]];
If[k<Length[vs],AppendTo[tds,d[vs[[1]],vs[[k]]]]];
tds,
{t1,l},{t2,r}
]],
{k,3,Length[vs]}
]
];

Triangulations

createTriangulation[t_ds,n_Integer] := Module[{diags},
diags=t/. ds[ls___] -> Graphics[{ls}] /. d[i_,j_] :> Line[{i,j}] /. j_Integer :> {Cos[((2 π j)/(n+2)) ],Sin[ ((2 π j)/(n+2))]} ;
Graphics[Join[diags[[1]],{EdgeForm[Thickness[Medium]],Transparent,RegularPolygon[{1,0},n+2]}]]
]

Trees

createTree[t_ds, n_Integer] :=TreeForm[
Last[d[0,n+1](Times@@t)(∏_(j=0)^n)e[j,j+1,p]//.e[i_,j_,t1_] e[j_,k_,t2_] d[i_,k_] :> e[i,k,p[t1,t2]]],
VertexRenderingFunction->(Inset[Text["●"],#]&)]

Non-associative Words

createSentence[t_ds,n_Integer] := Last[d[0,n+1](Times@@t)(∏_(j=0)^n)e[j,j+1,FromLetterNumber[j+1]]//. e[i_,j_,t1_] e[j_,k_,t2_] d[i_,k_] :> e[i,k,StringJoin["(",t1,t2,")"]]]

Final Product

Poster[n_Integer,methods_List]:= Module[{temp},
(* methods is a list of 3 elements that indicate whether or not to include each method: triangulations, trees, associative words, respectively *)
temp={};
If[methods[[1]]==1,
temp=Append[temp,Table[createTriangulation[item,n],{item,ts[n]}]]];
If[methods[[2]]==1,
temp=Append[temp,Table[createTree[item,n],{item,ts[n]}]]];
If[methods[[3]]==1,
temp=Append[temp,Table[createSentence[item,n],{item,ts[n]}]]];
GraphicsGrid[temp,Frame->All]
]

Example

Poster[3,{1,1,1}]