4
$\begingroup$

A set partition is noncrossing if whenever four elements $a<b<c<d$ are such that $a,c$ are in the same block and $b,d$ are in the same block then $a,b,c,d$ are all in the same block.

Can I get a list of noncrossing set partitions.

With "Combinatorica" I can get ALL the set partitions (say of {1,2,3,4}) with the command SetPartitions[4].

What I want is this list without the element {{1,3},{2,4}} which is not noncrossing.

$\endgroup$
5
$\begingroup$
Needs["Combinatorica`"]

ClearAll[nonCrossingSetPartitions]
nonCrossingSetPartitions = 
    DeleteCases[{___, {___, a_, ___, c_, ___}, ___, {___, b_, ___, d_, ___}, ___} /;
       a < b < c < d] @* SetPartitions;

nonCrossingSetPartitions @ 4 // Column

enter image description here

nonCrossingSetPartitions @ 5 // Length

42

| improve this answer | |
$\endgroup$
  • $\begingroup$ There should be 42 noncrossing partitions of [5]. $\endgroup$ – geoffrey Sep 22 at 20:05
  • $\begingroup$ thank you @geoffrey. Updated with a fix. $\endgroup$ – kglr Sep 22 at 21:07
6
$\begingroup$

I have a Mathematica package for generating Catalan objects on GitHub, so I have some recursive algorithm which generates what you want. Moreover, it has a nice graphical representation of these, and some operations on these, such as rotation.

Just download the package, and do

Needs["CatalanObjects`"]
Last /@ NonCrossingPartitions[4]

to get

{{{1, 2, 3, 4}}, {{3}, {1, 2, 4}}, {{2}, {1, 3, 4}}, {{1, 4}, {2, 
   3}}, {{2}, {3}, {1, 4}}, {{1}, {2, 3, 4}}, {{1}, {3}, {2, 4}}, {{1,
    2}, {3, 4}}, {{1}, {2}, {3, 4}}, {{4}, {1, 2, 3}}, {{2}, {4}, {1, 
   3}}, {{1}, {4}, {2, 3}}, {{3}, {4}, {1, 2}}, {{1}, {2}, {3}, {4}}}

If you do not want everything in the package, it should be easy to extract the method.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.