Module: sage.combinat.subword
Subwords
Module-level Functions
w, [k=None]) |
Returns the combinatorial class of subwords of w.
If k is specified, then it returns the combinatorial class of subwords of w of length k.
sage: S = Subwords(['a','b','c']); S Subwords of ['a', 'b', 'c'] sage: S.first() [] sage: S.last() ['a', 'b', 'c'] sage: S.list() [[], ['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']]
sage: S = Subwords(['a','b','c'], 2); S Subwords of ['a', 'b', 'c'] of length 2 sage: S.list() [['a', 'b'], ['a', 'c'], ['b', 'c']]
word, subword, [pos=0]) |
Returns the smallest positions for which subword apppears as a subword of word. If pos is specified, then it returns the positions of the first appearance of subword starting at pos.
If subword is not found in word, then it returns False
sage: sage.combinat.subword.smallest_positions([1,2,3,4], [2,4]) [1, 3] sage: sage.combinat.subword.smallest_positions([1,2,3,4,4], [2,4]) [1, 3] sage: sage.combinat.subword.smallest_positions([1,2,3,3,4,4], [3,4]) [2, 4] sage: sage.combinat.subword.smallest_positions([1,2,3,3,4,4], [3,4],2) [2, 4] sage: sage.combinat.subword.smallest_positions([1,2,3,3,4,4], [3,4],3) [3, 4] sage: sage.combinat.subword.smallest_positions([1,2,3,4], [2,3]) [1, 2] sage: sage.combinat.subword.smallest_positions([1,2,3,4], [5,5]) False
Class: Subwords_w
self, w) |
TESTS:
sage: S = Subwords([1,2,3]) sage: S == loads(dumps(S)) True
Functions: count,
first,
iterator,
last
self) |
sage: Subwords([1,2,3]).count() 8
self) |
sage: Subwords([1,2,3]).first() []
self) |
sage: [sw for sw in Subwords([1,2,3])] [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
self) |
sage: Subwords([1,2,3]).last() [1, 2, 3]
Special Functions: __init__,
__repr__
self) |
TESTS:
sage: repr(Subwords([1,2,3])) 'Subwords of [1, 2, 3]'
Class: Subwords_wk
self, w, k) |
TESTS:
sage: S = Subwords([1,2,3],2) sage: S == loads(dumps(S)) True
Functions: count,
first,
iterator,
last
self) |
Returns the number of subwords of w of length k.
sage: Subwords([1,2,3], 2).count() 3
self) |
sage: Subwords([1,2,3],2).first() [1, 2] sage: Subwords([1,2,3],0).first() []
self) |
sage: [sw for sw in Subwords([1,2,3],2)] [[1, 2], [1, 3], [2, 3]] sage: [sw for sw in Subwords([1,2,3],0)] [[]]
self) |
sage: Subwords([1,2,3],2).last() [2, 3]
Special Functions: __init__,
__repr__
self) |
TESTS:
sage: repr(Subwords([1,2,3],2)) 'Subwords of [1, 2, 3] of length 2'