Datatypes for words defined by iterators and callables#
- class sage.combinat.words.word_infinite_datatypes.WordDatatype_callable(parent, callable, length=None)[source]#
Bases:
WordDatatype
Datatype for a word defined by a callable.
- class sage.combinat.words.word_infinite_datatypes.WordDatatype_callable_with_caching(parent, callable, length=None)[source]#
Bases:
WordDatatype_callable
Datatype for a word defined by a callable.
- flush()[source]#
Empty the associated cache of letters.
EXAMPLES:
The first 40 (by default) values are always cached:
sage: w = words.ThueMorseWord() sage: w._letter_cache {0: 0, 1: 1, 2: 1, 3: 0, 4: 1, 5: 0, 6: 0, 7: 1, 8: 1, 9: 0, 10: 0, 11: 1, 12: 0, 13: 1, 14: 1, 15: 0, 16: 1, 17: 0, 18: 0, 19: 1, 20: 0, 21: 1, 22: 1, 23: 0, 24: 0, 25: 1, 26: 1, 27: 0, 28: 1, 29: 0, 30: 0, 31: 1, 32: 1, 33: 0, 34: 0, 35: 1, 36: 0, 37: 1, 38: 1, 39: 0} sage: w[100] 1 sage: w._letter_cache {0: 0, 1: 1, 2: 1, 3: 0, 4: 1, 5: 0, 6: 0, 7: 1, 8: 1, 9: 0, 10: 0, 11: 1, 12: 0, 13: 1, 14: 1, 15: 0, 16: 1, 17: 0, 18: 0, 19: 1, 20: 0, 21: 1, 22: 1, 23: 0, 24: 0, 25: 1, 26: 1, 27: 0, 28: 1, 29: 0, 30: 0, 31: 1, 32: 1, 33: 0, 34: 0, 35: 1, 36: 0, 37: 1, 38: 1, 39: 0, 100: 1} sage: w.flush() sage: w._letter_cache {}
>>> from sage.all import * >>> w = words.ThueMorseWord() >>> w._letter_cache {0: 0, 1: 1, 2: 1, 3: 0, 4: 1, 5: 0, 6: 0, 7: 1, 8: 1, 9: 0, 10: 0, 11: 1, 12: 0, 13: 1, 14: 1, 15: 0, 16: 1, 17: 0, 18: 0, 19: 1, 20: 0, 21: 1, 22: 1, 23: 0, 24: 0, 25: 1, 26: 1, 27: 0, 28: 1, 29: 0, 30: 0, 31: 1, 32: 1, 33: 0, 34: 0, 35: 1, 36: 0, 37: 1, 38: 1, 39: 0} >>> w[Integer(100)] 1 >>> w._letter_cache {0: 0, 1: 1, 2: 1, 3: 0, 4: 1, 5: 0, 6: 0, 7: 1, 8: 1, 9: 0, 10: 0, 11: 1, 12: 0, 13: 1, 14: 1, 15: 0, 16: 1, 17: 0, 18: 0, 19: 1, 20: 0, 21: 1, 22: 1, 23: 0, 24: 0, 25: 1, 26: 1, 27: 0, 28: 1, 29: 0, 30: 0, 31: 1, 32: 1, 33: 0, 34: 0, 35: 1, 36: 0, 37: 1, 38: 1, 39: 0, 100: 1} >>> w.flush() >>> w._letter_cache {}
- class sage.combinat.words.word_infinite_datatypes.WordDatatype_iter(parent, iter, length=None)[source]#
Bases:
WordDatatype
INPUT:
parent
– a parentiter
– an iteratorlength
– (default:None
) the length of the word
EXAMPLES:
sage: w = Word(iter("abbabaab"), length="unknown", caching=False); w word: abbabaab sage: isinstance(w, sage.combinat.words.word_infinite_datatypes.WordDatatype_iter) True sage: w.length() is None False sage: w.length() 8 sage: s = "abbabaabbaababbabaababbaabbabaabbaababbaabbabaabab" sage: w = Word(iter(s), length="unknown", caching=False); w word: abbabaabbaababbabaababbaabbabaabbaababba... sage: w.length() is None True
>>> from sage.all import * >>> w = Word(iter("abbabaab"), length="unknown", caching=False); w word: abbabaab >>> isinstance(w, sage.combinat.words.word_infinite_datatypes.WordDatatype_iter) True >>> w.length() is None False >>> w.length() 8 >>> s = "abbabaabbaababbabaababbaabbabaabbaababbaabbabaabab" >>> w = Word(iter(s), length="unknown", caching=False); w word: abbabaabbaababbabaababbaabbabaabbaababba... >>> w.length() is None True
sage: w = Word(iter("abbabaab"), length="finite", caching=False); w word: abbabaab sage: isinstance(w, sage.combinat.words.word_infinite_datatypes.WordDatatype_iter) True sage: w.length() 8 sage: w = Word(iter("abbabaab"), length=8, caching=False); w word: abbabaab sage: isinstance(w, sage.combinat.words.word_infinite_datatypes.WordDatatype_iter) True sage: w.length() 8
>>> from sage.all import * >>> w = Word(iter("abbabaab"), length="finite", caching=False); w word: abbabaab >>> isinstance(w, sage.combinat.words.word_infinite_datatypes.WordDatatype_iter) True >>> w.length() 8 >>> w = Word(iter("abbabaab"), length=Integer(8), caching=False); w word: abbabaab >>> isinstance(w, sage.combinat.words.word_infinite_datatypes.WordDatatype_iter) True >>> w.length() 8
- class sage.combinat.words.word_infinite_datatypes.WordDatatype_iter_with_caching(parent, iter, length=None)[source]#
Bases:
WordDatatype_iter
INPUT:
parent
– a parentiter
– an iteratorlength
– (default:None
) the length of the word
EXAMPLES:
sage: import itertools sage: Word(itertools.cycle("abbabaab")) word: abbabaababbabaababbabaababbabaababbabaab... sage: w = Word(iter("abbabaab"), length="finite"); w word: abbabaab sage: w.length() 8 sage: w = Word(iter("abbabaab"), length="unknown"); w word: abbabaab sage: w.length() 8 sage: list(w) ['a', 'b', 'b', 'a', 'b', 'a', 'a', 'b'] sage: w.length() 8 sage: w = Word(iter("abbabaab"), length=8) sage: w._len 8
>>> from sage.all import * >>> import itertools >>> Word(itertools.cycle("abbabaab")) word: abbabaababbabaababbabaababbabaababbabaab... >>> w = Word(iter("abbabaab"), length="finite"); w word: abbabaab >>> w.length() 8 >>> w = Word(iter("abbabaab"), length="unknown"); w word: abbabaab >>> w.length() 8 >>> list(w) ['a', 'b', 'b', 'a', 'b', 'a', 'a', 'b'] >>> w.length() 8 >>> w = Word(iter("abbabaab"), length=Integer(8)) >>> w._len 8
- flush()[source]#
Delete the cached values.
EXAMPLES:
sage: from itertools import count sage: w = Word(count()) sage: w._last_index, len(w._list) (39, 40) sage: w[43] 43 sage: w._last_index, len(w._list) (43, 44) sage: w.flush() sage: w._last_index, w._list (-1, [])
>>> from sage.all import * >>> from itertools import count >>> w = Word(count()) >>> w._last_index, len(w._list) (39, 40) >>> w[Integer(43)] 43 >>> w._last_index, len(w._list) (43, 44) >>> w.flush() >>> w._last_index, w._list (-1, [])