Module: sage.combinat.dyck_word
Dyck Words
Module-level Functions
| [dw=None], [noncrossing_partition=None]) |
Returns a Dyck word object
sage: dw = DyckWord([1, 0, 1, 0]); dw [1, 0, 1, 0] sage: print dw ()() sage: print dw.height() 1 sage: dw.to_noncrossing_partition() [[1], [2]]
sage: DyckWord('()()')
[1, 0, 1, 0]
sage: DyckWord(noncrossing_partition=[[1],[2]]) [1, 0, 1, 0]
| [k1=None], [k2=None]) |
Returns the combinatorial class of Dyck words.
If neither k1 nor k2 are specified, then it returns the combinatorial class of all Dyck words.
sage: DW = DyckWords(); DW Dyck words sage: [] in DW True sage: [1, 0, 1, 0] in DW True sage: [1, 1, 0] in DW False
If just k1 is specified, then it returns the combinatorial class of Dyck words with k1 opening parentheses and k1 closing parentheses.
sage: DW2 = DyckWords(2); DW2 Dyck words with 2 opening parentheses and 2 closing parentheses sage: DW2.first() [1, 1, 0, 0] sage: DW2.last() [1, 0, 1, 0] sage: DW2.count() 2
If k2 is specified in addition to k1, then it returns the combinatorial class of Dyck words with k1 opening parentheses and k2 closing parentheses.
sage: DW32 = DyckWords(3,2); DW32 Dyck words with 3 opening parentheses and 2 closing parentheses sage: DW32.list() [[1, 1, 1, 0, 0], [1, 1, 0, 1, 0], [1, 1, 0, 0, 1], [1, 0, 1, 1, 0], [1, 0, 1, 0, 1]]
| ncp) |
TESTS:
sage: DyckWord(noncrossing_partition=[[1,2]]) # indirect doctest [1, 1, 0, 0] sage: DyckWord(noncrossing_partition=[[1],[2]]) [1, 0, 1, 0]
sage: dws = DyckWords(5).list() sage: ncps = map( lambda x: x.to_noncrossing_partition(), dws) sage: dws2 = map( lambda x: DyckWord(noncrossing_partition=x), ncps) sage: dws == dws2 True
| tree) |
TESTS:
sage: sage.combinat.dyck_word.from_ordered_tree(1) Traceback (most recent call last): ... NotImplementedError: TODO
| obj, [k1=None], [k2=None]) |
If k1 is specificied, then the object must have exactly k1 open symbols. If k2 is also specified, then obj must have exactly k2 close symbols.
sage: from sage.combinat.dyck_word import is_a sage: is_a([1,1,0,0]) True sage: is_a([1,0,1,0]) True sage: is_a([1,1,0,0],2) True sage: is_a([1,1,0,0],3) False
| obj, [k1=None], [k2=None]) |
If k1 is specificied, then the object must have exactly k1 open symbols. If k2 is also specified, then obj must have exactly k2 close symbols.
sage: from sage.combinat.dyck_word import is_a_prefix sage: is_a_prefix([1,1,0]) True sage: is_a_prefix([0,1,0]) False sage: is_a_prefix([1,1,0],2,1) True sage: is_a_prefix([1,1,0],1,1) False
| x) |
sage: from sage.combinat.dyck_word import replace_parens
sage: replace_parens('(')
1
sage: replace_parens(')')
0
sage: replace_parens(1)
Traceback (most recent call last):
...
ValueError
| x) |
sage: from sage.combinat.dyck_word import replace_symbols
sage: replace_symbols(1)
'('
sage: replace_symbols(0)
')'
sage: replace_symbols(3)
Traceback (most recent call last):
...
ValueError
Class: DyckWord_class
Functions: a_statistic,
associated_parenthesis,
b_statistic,
height,
peaks,
size,
to_noncrossing_partition,
to_ordered_tree,
to_tableau,
to_triangulation
| self) |
Returns the a-statistic for the Dyck word. When viewed as a lattice path, the Dyck word's a-statistic is the number of boxes above the main diagonal.
sage: dw = DyckWord([1,1,1,0,1,1,1,0,0,0,1,1,0,0,1,0,0,0]) sage: dw.a_statistic() 19
sage: DyckWord([1,1,1,1,0,0,0,0]).a_statistic() 6 sage: DyckWord([1,1,1,0,1,0,0,0]).a_statistic() 5 sage: DyckWord([1,1,1,0,0,1,0,0]).a_statistic() 4 sage: DyckWord([1,1,1,0,0,0,1,0]).a_statistic() 3 sage: DyckWord([1,0,1,1,0,1,0,0]).a_statistic() 2 sage: DyckWord([1,1,0,1,1,0,0,0]).a_statistic() 4 sage: DyckWord([1,1,0,0,1,1,0,0]).a_statistic() 2 sage: DyckWord([1,0,1,1,1,0,0,0]).a_statistic() 3 sage: DyckWord([1,0,1,1,0,0,1,0]).a_statistic() 1 sage: DyckWord([1,0,1,0,1,1,0,0]).a_statistic() 1 sage: DyckWord([1,1,0,0,1,0,1,0]).a_statistic() 1 sage: DyckWord([1,1,0,1,0,0,1,0]).a_statistic() 2 sage: DyckWord([1,1,0,1,0,1,0,0]).a_statistic() 3 sage: DyckWord([1,0,1,0,1,0,1,0]).a_statistic() 0
| self, pos) |
sage: DyckWord([1, 0]).associated_parenthesis(0) 1 sage: DyckWord([1, 0, 1, 0]).associated_parenthesis(0) 1 sage: DyckWord([1, 0, 1, 0]).associated_parenthesis(1) 0 sage: DyckWord([1, 0, 1, 0]).associated_parenthesis(2) 3 sage: DyckWord([1, 0, 1, 0]).associated_parenthesis(3) 2 sage: DyckWord([1, 1, 0]).associated_parenthesis(1) 2 sage: DyckWord([1, 1]).associated_parenthesis(0)
| self) |
Returns the b-statistic for the Dyck word.
sage: dw = DyckWord([1,1,1,0,1,1,1,0,0,0,1,1,0,0,1,0,0,0]) sage: dw.b_statistic() 7
sage: DyckWord([1,1,1,1,0,0,0,0]).b_statistic() 0 sage: DyckWord([1,1,1,0,1,0,0,0]).b_statistic() 1 sage: DyckWord([1,1,1,0,0,1,0,0]).b_statistic() 2 sage: DyckWord([1,1,1,0,0,0,1,0]).b_statistic() 3 sage: DyckWord([1,0,1,1,0,1,0,0]).b_statistic() 3 sage: DyckWord([1,1,0,1,1,0,0,0]).b_statistic() 1 sage: DyckWord([1,1,0,0,1,1,0,0]).b_statistic() 2 sage: DyckWord([1,0,1,1,1,0,0,0]).b_statistic() 1 sage: DyckWord([1,0,1,1,0,0,1,0]).b_statistic() 4 sage: DyckWord([1,0,1,0,1,1,0,0]).b_statistic() 3 sage: DyckWord([1,1,0,0,1,0,1,0]).b_statistic() 5 sage: DyckWord([1,1,0,1,0,0,1,0]).b_statistic() 4 sage: DyckWord([1,1,0,1,0,1,0,0]).b_statistic() 2 sage: DyckWord([1,0,1,0,1,0,1,0]).b_statistic() 6
| self) |
Returns the height of the Dyck word.
sage: DyckWord([]).height() 0 sage: DyckWord([1,0]).height() 1 sage: DyckWord([1, 1, 0, 0]).height() 2 sage: DyckWord([1, 1, 0, 1, 0]).height() 2 sage: DyckWord([1, 1, 0, 0, 1, 0]).height() 2 sage: DyckWord([1, 0, 1, 0]).height() 1 sage: DyckWord([1, 1, 0, 0, 1, 1, 1, 0, 0, 0]).height() 3
| self) |
sage: DyckWord([1, 0, 1, 0]).peaks() [0, 2] sage: DyckWord([1, 1, 0, 0]).peaks() [1]
| self) |
Returns the size of the Dyck word, which is the number of opening parentheses in the Dyck word.
sage: DyckWord([1, 0, 1, 0]).size() 2 sage: DyckWord([1, 0, 1, 1, 0]).size() 3
| self) |
Bijection of Biane from Dyck words to non crossing partitions Thanks to Mathieu Dutour for describing the bijection.
sage: DyckWord([1, 0]).to_noncrossing_partition() [[1]] sage: DyckWord([1, 1, 0, 0]).to_noncrossing_partition() [[1, 2]] sage: DyckWord([1, 1, 1, 0, 0, 0]).to_noncrossing_partition() [[1, 2, 3]] sage: DyckWord([1, 0, 1, 0, 1, 0]).to_noncrossing_partition() [[1], [2], [3]] sage: DyckWord([1, 1, 0, 1, 0, 0]).to_noncrossing_partition() [[2], [1, 3]]
| self) |
TESTS:
sage: DyckWord([1, 1, 0, 0]).to_ordered_tree() Traceback (most recent call last): ... NotImplementedError: TODO
| self) |
sage: DyckWord([]).to_tableau() [] sage: DyckWord([1, 0]).to_tableau() [[2], [1]] sage: DyckWord([1, 1, 0, 0]).to_tableau() [[3, 4], [1, 2]] sage: DyckWord([1, 0, 1, 0]).to_tableau() [[2, 4], [1, 3]] sage: DyckWord([1]).to_tableau() [[1]] sage: DyckWord([1, 0, 1]).to_tableau() [[2], [1, 3]]
| self) |
TESTS:
sage: DyckWord([1, 1, 0, 0]).to_triangulation() Traceback (most recent call last): ... NotImplementedError: TODO
Special Functions: __str__
| self) |
Returns a string consisting of matched parenteses corresponding to the Dyck word.
sage: print DyckWord([1, 0, 1, 0]) ()() sage: print DyckWord([1, 1, 0, 0]) (())
Class: DyckWords_all
| self) |
TESTS:
sage: DW = DyckWords() sage: DW == loads(dumps(DW)) True
Functions: list
| self) |
TESTS:
sage: DyckWords().list() Traceback (most recent call last): ... NotImplementedError
Special Functions: __contains__,
__init__,
__repr__
| self, x) |
TESTS:
sage: [] in DyckWords() True sage: [1] in DyckWords() False sage: [0] in DyckWords() False sage: [1, 0] in DyckWords() True
| self) |
TESTS:
sage: repr(DyckWords()) 'Dyck words'
Class: DyckWords_size
| self, k1, [k2=None]) |
TESTS:
sage: DW4 = DyckWords(4) sage: DW4 == loads(dumps(DW4)) True sage: DW42 = DyckWords(4,2) sage: DW42 == loads(dumps(DW42)) True
Functions: count,
list
| self) |
Returns the number of Dyck words of size n, i.e. the n-th Catalan number.
sage: DyckWords(4).count() 14 sage: ns = range(9) sage: dws = [DyckWords(n) for n in ns] sage: all([ dw.count() == len(dw.list()) for dw in dws]) True
| self) |
Returns a list of all the Dyck words of size n.
sage: DyckWords(0).list() [[]] sage: DyckWords(1).list() [[1, 0]] sage: DyckWords(2).list() [[1, 1, 0, 0], [1, 0, 1, 0]]
Special Functions: __contains__,
__init__,
__repr__
| self, x) |
sage: [1, 0] in DyckWords(1) True sage: [1, 0] in DyckWords(2) False sage: [1, 1, 0, 0] in DyckWords(2) True sage: [1, 0, 0, 1] in DyckWords(2) False sage: [1, 0, 0, 1] in DyckWords(2,2) False sage: [1, 0, 1, 0] in DyckWords(2,2) True sage: [1, 0, 1, 0, 1] in DyckWords(3,2) True sage: [1, 0, 1, 1, 0] in DyckWords(3,2) True sage: [1, 0, 1, 1] in DyckWords(3,1) True
| self) |
TESTS:
sage: repr(DyckWords(4)) 'Dyck words with 4 opening parentheses and 4 closing parentheses'