combinat::dyckWords – Dyck words

The library combinat::dyckWords provides functions for counting, generating, and manipulating Dyck words.

→ Examples

Superdomain

Dom::BaseDomain

Categories

Cat::DecomposableClass

Axioms

Ax::systemRep

Related Domains:

combinat::binaryTrees, combinat::nonCrossingPartitions

Details:

Entries

"domtype"

The MuPAD domain of Dyck words: DOM_LIST

"typePrefix"

The MuPAD type of prefix Dyck words.

isA – test if an object is a Dyck word

combinat::dyckWords::isA(any type dw, <nonnegative integer n1, nonnegative integer n2>)

Returns whether the object dw is a Dyck word.

If the optional argument is present, returns whether dw is a a Dyck word of length 2n1.

If the two optional arguments are present, returns whether dw is a (prefix) Dyck word of n1 opening parenthesis and n2 closing parenthesis.

isAPrefix – test if an object is a prefix Dyck word

combinat::dyckWords::isAPrefix(any type dw, <nonnegative integer n1, nonnegative integer math>)

Returns whether the object dw is a prefix Dyck word.

If the optional arguments are present, returns whether dw is a prefix Dyck word of n1 opening parenthesis and n2 closing parenthesis.

count – number of Dyck words

combinat::dyckWords::count(nonnegative integer n)

Returns the number of Dyck words of size n, i.e. the math-th Catalan number.

generator – generator for Dyck words

combinat::dyckWords::generator(nonnegative integer n)

Returns a generator for Dyck words of size n.

list – list of Dyck words

combinat::dyckWords::list(nonnegative integer n)

combinat::dyckWords::list(nonnegative integer n1, nonnegative integer n2)

Returns the list of Dyck words of size n.

Returns the list of prefix Dyck words, with n1 ones and n2 zeroes.

toString – conversion to string of well balanced parenthesis

combinat::dyckWords::toString(Dyck word w)

Returns the string of well balanced parenthesis corresponding to the Dyck word w, replacing "1" with "(" and "0" with ")". Note that the function works even if the word is not well balanced.

See also the function combinat::dyckWords::fromString

fromString – conversion from string of well balanced parenthesis

combinat::dyckWords::fromString(string s)

Returns the Dyck word corresponding to the string of well balanced parenthesis s, replacing "(" with "1" and ")" with "0". Note that the function does not check if the string is indeed well balanced.

See also combinat::dyckWords::toString

printPretty – print a Dyck word as a Dyck path

combinat::dyckWords::printPretty(Dyck word w)

Returns a output::asciiArt which prints out as a Dyck path. A Dyck path is a path in the integer quarter of plane starting from math using only north-est and south-east step and ending on the math axis. The conversion is done as follows: the "1"s correspond to north-est step whereas the "0"s corresponds to south-east step.

toNonCrossingPartition – Biane bijection to non crossing set partitions

combinat::dyckWords::toNonCrossingPartition(Dyck word w)

Returns the non-crossing set partition corresponding to the Dyck word w by the Biane bijection.

See also combinat::nonCrossingPartitions and combinat::dyckWords::fromNonCrossingPartition

Reference: Philippe Biane, Permutations suivant le type d'excédances et le nombre d'inversions et interprétation combinatoire d'une fraction continue de Heine, Europ. J. Comb., 14(4): 277-284, 1993

fromNonCrossingPartition – Biane bijection from non-crossing set partitions

combinat::dyckWords::fromNonCrossingPartition(non crossing set partition p)

Returns the Dyck word corresponding to the non crossing set partition p by the Biane bijection.

See also combinat::dyckWords::toNonCrossingPartition

fromOrderedTree – canonical bijection from ordered trees to Dyck words

combinat::dyckWords::fromOrderedTree(ordered tree t)

Returns the Dyck word corresponding to the ordered tree t.

This implements the canonical bijection from ordered trees with math nodes to Dyck words of size math such that if a tree math has math as childs then math.

See also combinat::trees and combinat::dyckWords::toOrderedTree.

toOrderedTree – canonical bijection from Dyck words to ordered trees

combinat::dyckWords::toOrderedTree(Dyck word w)

Returns the ordered tree corresponding to the Dyck word w.

See also combinat::dyckWords::fromOrderedTree.

toBinaryTree – bijection from Dyck words to binary trees

combinat::dyckWords::toBinaryTree(Dyck word w)

Returns the binary tree corresponding to the Dyck word w.

See also combinat::binaryTrees and combinat::dyckWords::fromBinaryTree

We use the standard bijection associated to the factorization math where math and math are Dyck words : math and math corresponds to the left and right subtrees.

fromBinaryTree – bijection from binary trees to Dyck words

combinat::dyckWords::fromBinaryTree(binary trees t)

Returns the Dyck word corresponding to the binary trees t.

See also combinat::dyckWords::toBinaryTree

Example 1:

There are math Dyck words of size math:

combinat::dyckWords::count(3)

math

Here is the list:

combinat::dyckWords::list(3)

math

They correspond to the math strings of well-balanced parenthesis of length math:

map(combinat::dyckWords::list(3), combinat::dyckWords::toString)

math

On the other hand, neither [1,0,0,1,1,0] nor [1,1,1,1,0,0] are Dyck words:

combinat::dyckWords::toString([1,0,0,1,1,0]);

combinat::dyckWords::toString([1,1,1,1,0,0])

math

math

Example 2:

In this example we check the type of some Dyck words.

combinat::dyckWords::isA([1, 1, 1, 0, 0, 0]);

combinat::dyckWords::isA([1, 1, 1, 0, 0, 0], 3);

combinat::dyckWords::isA([1, 1, 1, 0, 0, 0], 2);

math

math

math

The list [1,0,0,1,1,0] is not a Dyck word:

combinat::dyckWords::isA([1, 0, 0, 1, 1, 0]);

combinat::dyckWords::isA([1, 0, 0, 1, 1, 0], 3);

math

math

The list [1,1,1,1,0,0] is not a Dyck word, but a prefix Dyck word:

combinat::dyckWords::isA([1, 1, 1, 1, 0, 0]);

combinat::dyckWords::isA([1, 1, 1, 1, 0, 0], 4, 2);

combinat::dyckWords::isAPrefix([1, 1, 1, 1, 0, 0]);

combinat::dyckWords::isAPrefix([1, 1, 1, 1, 0, 0], 4, 2);

math

math

math

math

Example 3:

One can convert a Dyck word to a string of well-balanced parenthesis:

combinat::dyckWords::toString([1,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,0,0,1,0]);

math

And convert it back:

combinat::dyckWords::fromString("((()(()))())((()))()");

math

Example 4:

One can print a Dyck word as a Dyck path:

combinat::dyckWords::printPretty([1,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,0,0,1,0]);

     /\

  /\/  \      /\

/      \/\  /  \

/          \/    \/\

 

The return value is a MuPAD object which belongs to the domain output::asciiArt

domtype(combinat::dyckWords::printPretty([1,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,0,0,1,0]));

math

Example 5:

Dyck words of size math are in bijection with non-crossing set partitions of math. Here is the the image of [1,0,1,0,1,0] by the Biane bijection:

combinat::dyckWords::toNonCrossingPartition([1,0,1,1,0,0,1,0])

math

We can reconstruct the original Dyck word:

combinat::dyckWords::fromNonCrossingPartition({[1], [4], [2, 3]})

math

Here is the list of all non-crossing set partitions of math:

map(combinat::dyckWords::list(3),

    combinat::dyckWords::toNonCrossingPartition)

math

Example 6:

Dyck words of size math are in bijection with binary trees. Here is the the image of [1,0,1,0,1,0]:

t := combinat::dyckWords::toBinaryTree([1, 0, 1, 1, 0, 0, 1, 0])

o

\

/\

 

We can reconstruct the original Dyck word:

combinat::dyckWords::fromBinaryTree(t)

math

Here is the list of all binary trees of size math:

map(combinat::dyckWords::list(4),

    combinat::dyckWords::toBinaryTree)

--    o,   o,   o,   o ,  o,  o,  o ,  o ,  o  , o , o , o  , o  , o    --

|    /    /    /    / \  /   /   / \  / \  / \    \   \   \    \    \    |

|   /    /    /\   /     \   \   \      /     \   /   /   /\    \    \   |

-- /     \               /    \                  /    \         /     \ --

 

Note that the order is not the same as the order chosen on binary trees, which is more symmetric.

combinat::binaryTrees::list(4)

-- o   , o  , o  , o , o ,  o  ,  o ,  o ,   o ,  o,  o,   o,   o,    o --

|   \     \    \    \   \  / \   / \  / \   / \  /   /    /    /     /   |

|    \     \   /\   /   /     \    /  \    /     \   \   /\   /     /    |

--    \    /        \  /                          \  /        \    /    --

 

Background:

Dyck words are naturally ordered lexicographically.