Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Give all possible ways to form proper brackets
ResourceFunction["DyckWords"][n] gives all possible ways to form proper sets of n pairs of brackets. |
Here is the simplest nontrivial example with two pairs of brackets:
In[1]:= | ![]() |
Out[1]= | ![]() |
Here are the ways to nest three pairs of brackets:
In[2]:= | ![]() |
Out[2]= | ![]() |
There are five ways to do that:
In[3]:= | ![]() |
Out[3]= | ![]() |
Dyck words are counted by the Catalan numbers:
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
Define the helper function:
In[6]:= | ![]() |
A Dyck path of length 2n units starts at the origin, goes NE or SE one unit and finishes on the x-axis:
In[7]:= | ![]() |
Out[7]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License