Enumerator

class mathtools.Enumerator(sequence=None)

Enumerator.

Collects combinatorial enumerator methods.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" [color=1, group=0, label=AbjadValueObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.AbjadValueObject.AbjadValueObject"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_mathtools { graph [label=mathtools]; "abjad.tools.mathtools.Enumerator.Enumerator" [color=black, fontcolor=white, group=2, label=<<B>Enumerator</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" -> "abjad.tools.mathtools.Enumerator.Enumerator"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

sequence Gets sequence of enumerator.
yield_combinations([minimum_length, …]) Yields combinations of sequence items.
yield_outer_product() Yields outer product of sequences in sequence.
yield_pairs() Yields pairs sequence items.
yield_partitions() Yields partitions of sequence.
yield_permutations() Yields permutations of sequence.
yield_set_partitions() Yields set partitions of sequence.
yield_subsequences([minimum_length, …]) Yields subsequences of sequence.
__copy__(*arguments) Copies Abjad value object.
__eq__(argument) Is true when all initialization values of Abjad value object equal the initialization values of argument.
__format__([format_specification]) Formats Abjad object.
__hash__() Hashes Abjad value object.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.

Read-only properties

Enumerator.sequence

Gets sequence of enumerator.

Defaults to none.

Set to sequence or none.

Returns sequence or none.

Methods

Enumerator.yield_combinations(minimum_length=None, maximum_length=None)

Yields combinations of sequence items.

>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations():
...     combination
Sequence([])
Sequence([1])
Sequence([2])
Sequence([1, 2])
Sequence([3])
Sequence([1, 3])
Sequence([2, 3])
Sequence([1, 2, 3])
Sequence([4])
Sequence([1, 4])
Sequence([2, 4])
Sequence([1, 2, 4])
Sequence([3, 4])
Sequence([1, 3, 4])
Sequence([2, 3, 4])
Sequence([1, 2, 3, 4])
>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations(
...     minimum_length=3,
...     ):
...     combination
Sequence([1, 2, 3])
Sequence([1, 2, 4])
Sequence([1, 3, 4])
Sequence([2, 3, 4])
Sequence([1, 2, 3, 4])
>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations(
...     maximum_length=2,
...     ):
...     combination
Sequence([])
Sequence([1])
Sequence([2])
Sequence([1, 2])
Sequence([3])
Sequence([1, 3])
Sequence([2, 3])
Sequence([4])
Sequence([1, 4])
Sequence([2, 4])
Sequence([3, 4])
>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations(
...     minimum_length=2,
...     maximum_length=2,
...     ):
...     combination
Sequence([1, 2])
Sequence([1, 3])
Sequence([2, 3])
Sequence([1, 4])
Sequence([2, 4])
Sequence([3, 4])
>>> enumerator = abjad.Enumerator('text')
>>> for combination in enumerator.yield_combinations():
...     ''.join([str(_) for _ in combination])
''
't'
'e'
'te'
'x'
'tx'
'ex'
'tex'
't'
'tt'
'et'
'tet'
'xt'
'txt'
'ext'
'text'

Yields combinations in binary string order.

Returns sequence generator.

Enumerator.yield_outer_product()

Yields outer product of sequences in sequence.

>>> sequences = [[1, 2, 3], ['a', 'b']]
>>> enumerator = abjad.Enumerator(sequences)
>>> for sequence_ in enumerator.yield_outer_product():
...     sequence_
...
Sequence([1, 'a'])
Sequence([1, 'b'])
Sequence([2, 'a'])
Sequence([2, 'b'])
Sequence([3, 'a'])
Sequence([3, 'b'])
>>> sequences = [[1, 2, 3], ['a', 'b'], ['X', 'Y']]
>>> enumerator = abjad.Enumerator(sequences)
>>> for sequence_ in enumerator.yield_outer_product():
...     sequence_
...
Sequence([1, 'a', 'X'])
Sequence([1, 'a', 'Y'])
Sequence([1, 'b', 'X'])
Sequence([1, 'b', 'Y'])
Sequence([2, 'a', 'X'])
Sequence([2, 'a', 'Y'])
Sequence([2, 'b', 'X'])
Sequence([2, 'b', 'Y'])
Sequence([3, 'a', 'X'])
Sequence([3, 'a', 'Y'])
Sequence([3, 'b', 'X'])
Sequence([3, 'b', 'Y'])
>>> sequences = [[1, 2, 3], [4, 5], [6, 7, 8]]
>>> enumerator = abjad.Enumerator(sequences)
>>> for sequence_ in enumerator.yield_outer_product():
...     sequence_
...
Sequence([1, 4, 6])
Sequence([1, 4, 7])
Sequence([1, 4, 8])
Sequence([1, 5, 6])
Sequence([1, 5, 7])
Sequence([1, 5, 8])
Sequence([2, 4, 6])
Sequence([2, 4, 7])
Sequence([2, 4, 8])
Sequence([2, 5, 6])
Sequence([2, 5, 7])
Sequence([2, 5, 8])
Sequence([3, 4, 6])
Sequence([3, 4, 7])
Sequence([3, 4, 8])
Sequence([3, 5, 6])
Sequence([3, 5, 7])
Sequence([3, 5, 8])

Returns sequence generator.

Enumerator.yield_pairs()

Yields pairs sequence items.

Without duplicate items:

>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for pair in enumerator.yield_pairs():
...     pair
...
Sequence([1, 2])
Sequence([1, 3])
Sequence([1, 4])
Sequence([2, 3])
Sequence([2, 4])
Sequence([3, 4])

With duplicate items:

>>> enumerator = abjad.Enumerator([1, 1, 1])
>>> for pair in enumerator.yield_pairs():
...     pair
...
Sequence([1, 1])
Sequence([1, 1])
Sequence([1, 1])

Length-1 sequence:

>>> enumerator = abjad.Enumerator([1])
>>> for pair in enumerator.yield_pairs():
...     pair
...

Empty sequence:

>>> enumerator = abjad.Enumerator([])
>>> for pair in enumerator.yield_pairs():
...     pair
...

Returns generator of length-2 sequences.

Enumerator.yield_partitions()

Yields partitions of sequence.

>>> enumerator = abjad.Enumerator([0, 1, 2])
>>> for partition in enumerator.yield_partitions():
...     partition
...
Sequence([Sequence([0, 1, 2])])
Sequence([Sequence([0, 1]), Sequence([2])])
Sequence([Sequence([0]), Sequence([1, 2])])
Sequence([Sequence([0]), Sequence([1]), Sequence([2])])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3])
>>> for partition in enumerator.yield_partitions():
...     partition
...
Sequence([Sequence([0, 1, 2, 3])])
Sequence([Sequence([0, 1, 2]), Sequence([3])])
Sequence([Sequence([0, 1]), Sequence([2, 3])])
Sequence([Sequence([0, 1]), Sequence([2]), Sequence([3])])
Sequence([Sequence([0]), Sequence([1, 2, 3])])
Sequence([Sequence([0]), Sequence([1, 2]), Sequence([3])])
Sequence([Sequence([0]), Sequence([1]), Sequence([2, 3])])
Sequence([Sequence([0]), Sequence([1]), Sequence([2]), Sequence([3])])

Returns generator of nested sequences.

Enumerator.yield_permutations()

Yields permutations of sequence.

>>> enumerator = abjad.Enumerator([1, 2, 3])
>>> for permutation in enumerator.yield_permutations():
...     permutation
...
Sequence([1, 2, 3])
Sequence([1, 3, 2])
Sequence([2, 1, 3])
Sequence([2, 3, 1])
Sequence([3, 1, 2])
Sequence([3, 2, 1])

Returns sequence generator.

Enumerator.yield_set_partitions()

Yields set partitions of sequence.

>>> enumerator = abjad.Enumerator([21, 22, 23, 24])
>>> for set_partition in enumerator.yield_set_partitions():
...     set_partition
...
Sequence([Sequence([21, 22, 23, 24])])
Sequence([Sequence([21, 22, 23]), Sequence([24])])
Sequence([Sequence([21, 22, 24]), Sequence([23])])
Sequence([Sequence([21, 22]), Sequence([23, 24])])
Sequence([Sequence([21, 22]), Sequence([23]), Sequence([24])])
Sequence([Sequence([21, 23, 24]), Sequence([22])])
Sequence([Sequence([21, 23]), Sequence([22, 24])])
Sequence([Sequence([21, 23]), Sequence([22]), Sequence([24])])
Sequence([Sequence([21, 24]), Sequence([22, 23])])
Sequence([Sequence([21]), Sequence([22, 23, 24])])
Sequence([Sequence([21]), Sequence([22, 23]), Sequence([24])])
Sequence([Sequence([21, 24]), Sequence([22]), Sequence([23])])
Sequence([Sequence([21]), Sequence([22, 24]), Sequence([23])])
Sequence([Sequence([21]), Sequence([22]), Sequence([23, 24])])
Sequence([Sequence([21]), Sequence([22]), Sequence([23]), Sequence([24])])

Returns set partitions in order of restricted growth function.

Returns generator of list of lists.

Enumerator.yield_subsequences(minimum_length=0, maximum_length=None)

Yields subsequences of sequence.

>>> enumerator = abjad.Enumerator([0, 1, 2])
>>> for subsequence in enumerator.yield_subsequences():
...     subsequence
...
Sequence([])
Sequence([0])
Sequence([0, 1])
Sequence([0, 1, 2])
Sequence([1])
Sequence([1, 2])
Sequence([2])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3, 4])
>>> for subsequence in enumerator.yield_subsequences(
...     minimum_length=3,
...     ):
...     subsequence
...
Sequence([0, 1, 2])
Sequence([0, 1, 2, 3])
Sequence([0, 1, 2, 3, 4])
Sequence([1, 2, 3])
Sequence([1, 2, 3, 4])
Sequence([2, 3, 4])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3, 4])
>>> for subsequence in enumerator.yield_subsequences(
...     maximum_length=3,
...     ):
...     subsequence
...
Sequence([])
Sequence([0])
Sequence([0, 1])
Sequence([0, 1, 2])
Sequence([1])
Sequence([1, 2])
Sequence([1, 2, 3])
Sequence([2])
Sequence([2, 3])
Sequence([2, 3, 4])
Sequence([3])
Sequence([3, 4])
Sequence([4])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3, 4])
>>> for subsequence in enumerator.yield_subsequences(
...     minimum_length=3,
...     maximum_length=3,
...     ):
...     subsequence
...
Sequence([0, 1, 2])
Sequence([1, 2, 3])
Sequence([2, 3, 4])

Returns sequence generator.

Special methods

(AbjadValueObject).__copy__(*arguments)

Copies Abjad value object.

Returns new Abjad value object.

(AbjadValueObject).__eq__(argument)

Is true when all initialization values of Abjad value object equal the initialization values of argument.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(AbjadValueObject).__hash__()

Hashes Abjad value object.

Returns integer.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.