Datatypes for words defined by iterators and callables

class sage.combinat.words.word_infinite_datatypes.WordDatatype_callable(parent, callable, length=None)

Bases: sage.combinat.words.word_datatypes.WordDatatype

Datatype for a word defined by a callable.

class sage.combinat.words.word_infinite_datatypes.WordDatatype_callable_with_caching(parent, callable, length=None)

Bases: sage.combinat.words.word_infinite_datatypes.WordDatatype_callable

Datatype for a word defined by a callable.

flush()

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
{}
class sage.combinat.words.word_infinite_datatypes.WordDatatype_iter(parent, iter, length=None)

Bases: sage.combinat.words.word_datatypes.WordDatatype

INPUT:

  • parent - a parent
  • iter - an iterator
  • length - (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
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
class sage.combinat.words.word_infinite_datatypes.WordDatatype_iter_with_caching(parent, iter, length=None)

Bases: sage.combinat.words.word_infinite_datatypes.WordDatatype_iter

INPUT:

  • parent - a parent
  • iter - an iterator
  • length - (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
flush()

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, [])