Ask Your Question

Revision history [back]

As you can see, d is a kind of discrete primitive of w. So you can compute it as follows:

sage: def primitive(w):
....:     height = 0
....:     d = [height]
....:     for i in w:
....:         if i == 1:
....:             height += 1
....:             d.append(height)
....:         else:
....:             height -= 1
....:             d.append(height)
....:     return d

sage: w=[1,1,1,0,0,1,0,0]    
sage: primitive(w)
[0, 1, 2, 3, 2, 1, 2, 1, 0]

You can get its height as follows:

sage: max(primitive(w))
3

As you can see, d is a kind of discrete primitive of w. So you can compute it as follows:

sage: def primitive(w):
....:     height = 0
....:     d = [height]
....:     for i in w:
....:         if i == 1:
....:             height += 1
....:             d.append(height)
....:         else:
....:             height -= 1
....:             d.append(height)
....:     return d

sage: w=[1,1,1,0,0,1,0,0]    
sage: primitive(w)
[0, 1, 2, 3, 2, 1, 2, 1, 0]

You can get its height as follows:

sage: max(primitive(w))
3

You can get all primitives of all Dyck words of a given length as follows:

sage: [primitive(w) for w in DyckWords(4)] [[0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 2, 1, 0], [0, 1, 0, 1, 2, 1, 0, 1, 0], [0, 1, 0, 1, 2, 1, 2, 1, 0], [0, 1, 0, 1, 2, 3, 2, 1, 0], [0, 1, 2, 1, 0, 1, 0, 1, 0], [0, 1, 2, 1, 0, 1, 2, 1, 0], [0, 1, 2, 1, 2, 1, 0, 1, 0], [0, 1, 2, 1, 2, 1, 2, 1, 0], [0, 1, 2, 1, 2, 3, 2, 1, 0], [0, 1, 2, 3, 2, 1, 0, 1, 0], [0, 1, 2, 3, 2, 1, 2, 1, 0], [0, 1, 2, 3, 2, 3, 2, 1, 0], [0, 1, 2, 3, 4, 3, 2, 1, 0]]

Hence you can get the set of heights as follows:

sage: {max(primitive(w)) for w in DyckWords(4)}
{1, 2, 3, 4}

As you can see, d is a kind of discrete primitive of w. So you can compute it as follows:

sage: def primitive(w):
....:     height = 0
....:     d = [height]
....:     for i in w:
....:         if i == 1:
....:             height += 1
....:             d.append(height)
....:         else:
....:             height -= 1
....:             d.append(height)
....:     return d

sage: w=[1,1,1,0,0,1,0,0]    
sage: primitive(w)
[0, 1, 2, 3, 2, 1, 2, 1, 0]

You can get its height as follows:

sage: max(primitive(w))
3

You can get all primitives of all Dyck words of a given length as follows:

sage: [primitive(w) for w in DyckWords(4)]
[[0, 1, 0, 1, 0, 1, 0, 1, 0],
 [0, 1, 0, 1, 0, 1, 2, 1, 0],
 [0, 1, 0, 1, 2, 1, 0, 1, 0],
 [0, 1, 0, 1, 2, 1, 2, 1, 0],
 [0, 1, 0, 1, 2, 3, 2, 1, 0],
 [0, 1, 2, 1, 0, 1, 0, 1, 0],
 [0, 1, 2, 1, 0, 1, 2, 1, 0],
 [0, 1, 2, 1, 2, 1, 0, 1, 0],
 [0, 1, 2, 1, 2, 1, 2, 1, 0],
 [0, 1, 2, 1, 2, 3, 2, 1, 0],
 [0, 1, 2, 3, 2, 1, 0, 1, 0],
 [0, 1, 2, 3, 2, 1, 2, 1, 0],
 [0, 1, 2, 3, 2, 3, 2, 1, 0],
 [0, 1, 2, 3, 4, 3, 2, 1, 0]]

0]]

Hence you can get the set of heights as follows:

sage: {max(primitive(w)) for w in DyckWords(4)}
{1, 2, 3, 4}