CompoundPattern

class patterntools.CompoundPattern(items=None, inverted=None, operator='or')

Compound pattern.

>>> import abjad

Matches every index that is (one of the first three indices) OR (one of the last three indices):

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     )
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    operator='or',
    )

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices):

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     operator='and',
...     )
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0],
            period=2,
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            inverted=True,
            ),
        ),
    operator='and',
    )

Sieve from opening of Xenakis’s Psappha:

>>> sieve_1a = patterntools.select_every([0, 1, 7], period=8)
>>> sieve_1b = patterntools.select_every([1, 3], period=5)
>>> sieve_1 = sieve_1a & sieve_1b
>>> sieve_2a = patterntools.select_every([0, 1, 2], period=8)
>>> sieve_2b = patterntools.select_every([0], period=5)
>>> sieve_2 = sieve_2a & sieve_2b
>>> sieve_3 = patterntools.select_every([3], period=8)
>>> sieve_4 = patterntools.select_every([4], period=8)
>>> sieve_5a = patterntools.select_every([5, 6], period=8)
>>> sieve_5b = patterntools.select_every([2, 3, 4], period=5)
>>> sieve_5 = sieve_5a & sieve_5b
>>> sieve_6a = patterntools.select_every([1], period=8)
>>> sieve_6b = patterntools.select_every([2], period=5)
>>> sieve_6 = sieve_6a & sieve_6b
>>> sieve_7a = patterntools.select_every([6], period=8)
>>> sieve_7b = patterntools.select_every([1], period=5)
>>> sieve_7 = sieve_7a & sieve_7b
>>> sieve = sieve_1 | sieve_2 | sieve_3 | sieve_4 | sieve_5 | sieve_6 | sieve_7
>>> sieve.get_boolean_vector(total_length=40)
[1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1,
1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0]

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.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" [color=3, group=2, label=TypedCollection, shape=oval, style=bold]; "abjad.tools.datastructuretools.TypedTuple.TypedTuple" [color=3, group=2, label=TypedTuple, shape=box]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" -> "abjad.tools.datastructuretools.TypedTuple.TypedTuple"; } subgraph cluster_patterntools { graph [label=patterntools]; "abjad.tools.patterntools.CompoundPattern.CompoundPattern" [color=black, fontcolor=white, group=3, label=<<B>CompoundPattern</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.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.TypedCollection.TypedCollection"; "abjad.tools.datastructuretools.TypedTuple.TypedTuple" -> "abjad.tools.patterntools.CompoundPattern.CompoundPattern"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

count(item) Counts item in collection.
get_boolean_vector([total_length]) Gets boolean vector of pattern applied to input sequence with total_length.
get_matching_items(sequence) Gets maching items from sequence.
index(item) Gets index of item in collection.
inverted Is true when compound pattern is inverted.
item_class Gets item class of collection.
items Gets items in collection.
matches_index(index, total_length[, rotation]) Is true when compound pattern matches index under total_length.
operator Gets operator of compounnd pattern.
period Gets period of compound pattern.
reverse() Reverses compound pattern.
rotate([n]) Rotates compound pattern by index n.
__add__(argument) Adds typed tuple to argument.
__and__(pattern) Logical AND of two patterns.
__contains__(item) Is true if typed tuple contains item.
__eq__(argument) Is true when argument is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Formats Abjad object.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes typed tuple.
__invert__() Inverts pattern.
__iter__() Iterates typed collection.
__len__() Gets length of typed collection.
__mul__(argument) Multiplies typed tuple by argument.
__ne__(argument) Is true when argument is not a typed collection with items equal to this typed collection.
__or__(pattern) Logical OR of two patterns.
__radd__(argument) Right-adds argument to typed tuple.
__repr__() Gets interpreter representation of Abjad object.
__rmul__(argument) Multiplies argument by typed tuple.
__xor__(pattern) Logical XOR of two patterns.

Read-only properties

CompoundPattern.inverted

Is true when compound pattern is inverted. Otherwise false.

Matches every index that is (one of the first three indices) OR (one of the last three indices):

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern = pattern_1 | pattern_2
>>> pattern.inverted is None
True
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Matches every index that is NOT (one of the first three indices) OR (one of the last three indices):

>>> pattern = new(pattern, inverted=True)
>>> pattern.inverted
True
>>> pattern.get_boolean_vector(total_length=16)
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]

Defaults to none.

Set to true, false or none.

Returns true, false or none.

(TypedCollection).item_class

Gets item class of collection.

Collection coerces items according to item_class.

Returns class.

(TypedCollection).items

Gets items in collection.

Returns list.

CompoundPattern.operator

Gets operator of compounnd pattern.

Set to string.

Returns string.

CompoundPattern.period

Gets period of compound pattern.

Gets period of pattern that selects every fourth and fifth element:

>>> pattern_1 = patterntools.Pattern([0], period=4)
>>> pattern_2 = patterntools.Pattern([0], period=5)
>>> pattern = pattern_1 | pattern_2
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0],
            period=4,
            ),
        patterntools.Pattern(
            indices=[0],
            period=5,
            ),
        ),
    operator='or',
    )
>>> pattern.period
20

Returns none when pattern contains acyclic parts:

>>> pattern_1 = patterntools.Pattern([0], period=4)
>>> pattern_2 = patterntools.Pattern([0])
>>> pattern = pattern_1 | pattern_2
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0],
            period=4,
            ),
        patterntools.Pattern(
            indices=[0],
            ),
        ),
    operator='or',
    )
>>> pattern.period is None
True

Returns positive integer.

Methods

(TypedTuple).count(item)

Counts item in collection.

Coerces item.

Returns nonnegative integer.

CompoundPattern.get_boolean_vector(total_length=None)

Gets boolean vector of pattern applied to input sequence with total_length.

Two-part pattern with logical OR:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     operator='or',
...     )
>>> pattern.get_boolean_vector(4)
[1, 1, 1, 1]
>>> pattern.get_boolean_vector(8)
[1, 1, 1, 0, 0, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Matches every index that is (one of the first three indices) OR (one of the last three indices).

Two-part pattern with mixed periodic and inverted parts:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     operator='and',
...     )
>>> pattern.get_boolean_vector(4)
[1, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[1, 0, 1, 0, 1, 0, 0, 0]
>>> pattern.get_boolean_vector(16)
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0]

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices).

Cyclic pattern that selects every fourth and fifth item:

>>> pattern_1 = patterntools.Pattern([0], period=4)
>>> pattern_2 = patterntools.Pattern([0], period=5)
>>> pattern = pattern_1 | pattern_2
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0],
            period=4,
            ),
        patterntools.Pattern(
            indices=[0],
            period=5,
            ),
        ),
    operator='or',
    )
>>> pattern.get_boolean_vector(4)
[1, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[1, 0, 0, 0, 1, 1, 0, 0]
>>> pattern.get_boolean_vector(16)
[1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1]

Sets total length to period of pattern when total_length is none:

>>> pattern.period
20
>>> pattern.get_boolean_vector()
[1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0]
>>> pattern.period == len(pattern.get_boolean_vector())
True

Returns list of ones and zeroes.

CompoundPattern.get_matching_items(sequence)

Gets maching items from sequence.

>>> pattern = abjad.select_first(1) | abjad.select_last(2)
>>> pattern.get_matching_items('abcdefghijklmnopqrstuvwxyz')
Sequence(['a', 'y', 'z'])

Returns new sequence.

(TypedTuple).index(item)

Gets index of item in collection.

Coerces item.

Returns nonnegative integer.

CompoundPattern.matches_index(index, total_length, rotation=None)

Is true when compound pattern matches index under total_length. Otherwise false.

Empty pattern:

>>> pattern = patterntools.CompoundPattern()

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0
1
2
3
4
5
6
7

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0
1
2
3

Matches nothing.

Simple pattern:

Logical OR:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     operator='or',
...     )
>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4
5
6
7
8
9
10
11
12
13
14
15

Logical AND:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     operator='and',
...     )
>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4
5
6
7
8
9
10
11
12
13
14
15

Logical XOR:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     operator='xor',
...     )
>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4
5
6
7
8
9
10
11
12
13
14
15

Matches every index that is (one of the first three indices).

Ignores operator.

Two-part pattern with logical OR:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     operator='or',
...     )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4
5
6
7
8
9
10
11
12
13 True
14 True
15 True

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4
5 True
6 True
7 True

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3 True

Matches every index that is (one of the first three indices) OR (one of the last three indices).

Two-part pattern with logical AND:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     operator='and',
...     )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0
1
2
3
4
5
6
7

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0
1 True
2 True
3

Matches every index that is (one of the first three indices) AND (one of the last three indices).

Two-part pattern with logical XOR:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     operator='xor',
...     )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4
5
6
7
8
9
10
11
12
13 True
14 True
15 True

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4
5 True
6 True
7 True

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1
2
3 True

Matches every index that is (one of the first three indices) XOR (one of the last three indices).

Two-part pattern with mixed periodic and inverted parts:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     operator='and',
...     )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1
2 True
3
4 True
5
6 True
7
8 True
9
10 True
11
12 True
13
14
15

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1
2 True
3
4 True
5
6
7

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1
2
3

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices).

Complex pattern with compound and simple parts:

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     operator='and',
...     )
>>> pattern = patterntools.CompoundPattern(
...     [
...         pattern,
...         patterntools.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     operator='or',
...     )
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.CompoundPattern(
            (
                patterntools.Pattern(
                    indices=[0],
                    period=2,
                    ),
                patterntools.Pattern(
                    indices=[-3, -2, -1],
                    inverted=True,
                    ),
                ),
            operator='and',
            ),
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        ),
    operator='or',
    )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4 True
5
6 True
7
8 True
9
10 True
11
12 True
13
14
15

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3
4 True
5
6
7

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
0 True
1 True
2 True
3

Matches every index that is ((equal to 0 % 2) AND (not one of the last three indices)) OR is (one of the first three indices).

Returns true or false.

CompoundPattern.reverse()

Reverses compound pattern.

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices):

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     operator='and',
...     )
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0],
            period=2,
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            inverted=True,
            ),
        ),
    operator='and',
    )

Reverses pattern:

>>> pattern = pattern.reverse()
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[-1],
            period=2,
            ),
        patterntools.Pattern(
            indices=[2, 1, 0],
            inverted=True,
            ),
        ),
    operator='and',
    )

New pattern matches every index that is (equal to -1 % 2) AND (not one of the first three indices).

Returns new compound pattern.

CompoundPattern.rotate(n=0)

Rotates compound pattern by index n.

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices):

>>> pattern = patterntools.CompoundPattern(
...     [
...         patterntools.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         patterntools.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     operator='and',
...     )
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0],
            period=2,
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            inverted=True,
            ),
        ),
    operator='and',
    )

Rotates pattern two elements to the right:

>>> pattern = pattern.rotate(n=2)
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[2],
            period=2,
            ),
        patterntools.Pattern(
            indices=[-1, 0, 1],
            inverted=True,
            ),
        ),
    operator='and',
    )

New pattern matches every index that is (equal to 2 % 2) AND (not the first, second or last index in the pattern).

Returns new compound pattern.

Special methods

(TypedTuple).__add__(argument)

Adds typed tuple to argument.

Returns new typed tuple.

CompoundPattern.__and__(pattern)

Logical AND of two patterns.

Flat grouping:

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern_3 = patterntools.select_every([0], period=2)
>>> pattern = pattern_1 & pattern_2 & pattern_3
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            ),
        patterntools.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    operator='and',
    )
>>> pattern.get_boolean_vector(total_length=16)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Nested grouping:

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern_3 = patterntools.select_every([0], period=2)
>>> pattern = pattern_1 & pattern_2 | pattern_3
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.CompoundPattern(
            (
                patterntools.Pattern(
                    indices=[0, 1, 2],
                    ),
                patterntools.Pattern(
                    indices=[-3, -2, -1],
                    ),
                ),
            operator='and',
            ),
        patterntools.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    operator='or',
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]

Returns new compound pattern.

(TypedTuple).__contains__(item)

Is true if typed tuple contains item.

Coerces item.

Returns none.

(TypedCollection).__eq__(argument)

Is true when argument is a typed collection with items that compare equal to those of this typed collection. Otherwise false.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

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

Returns string.

(TypedTuple).__getitem__(argument)

Gets item or slice identified by argument.

Returns item or new typed tuple.

(TypedTuple).__hash__()

Hashes typed tuple.

Returns integer.

CompoundPattern.__invert__()

Inverts pattern.

Matches every index that is (one of the first three indices) or (one of the last three indices):

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern = pattern_1 | pattern_2
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    operator='or',
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Matches every index that is NOT (one of the first three indices) or (one of the last three indices):

>>> pattern = ~pattern
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    inverted=True,
    operator='or',
    )
>>> pattern.get_boolean_vector(total_length=16)
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]

Returns new compound pattern.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

(TypedTuple).__mul__(argument)

Multiplies typed tuple by argument.

Returns new typed tuple.

(TypedCollection).__ne__(argument)

Is true when argument is not a typed collection with items equal to this typed collection. Otherwise false.

Returns true or false.

CompoundPattern.__or__(pattern)

Logical OR of two patterns.

Flat grouping:

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern_3 = patterntools.select_every([0], period=2)
>>> pattern = pattern_1 | pattern_2 | pattern_3
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            ),
        patterntools.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    operator='or',
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1]

Nested grouping:

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern_3 = patterntools.select_every([0], period=2)
>>> pattern = pattern_1 | pattern_2 & pattern_3
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.CompoundPattern(
            (
                patterntools.Pattern(
                    indices=[-3, -2, -1],
                    ),
                patterntools.Pattern(
                    indices=[0],
                    period=2,
                    ),
                ),
            operator='and',
            ),
        ),
    operator='or',
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]

Returns new compound pattern.

(TypedTuple).__radd__(argument)

Right-adds argument to typed tuple.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(TypedTuple).__rmul__(argument)

Multiplies argument by typed tuple.

Returns new typed tuple.

CompoundPattern.__xor__(pattern)

Logical XOR of two patterns.

Flat grouping:

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern_3 = patterntools.select_every([0], period=2)
>>> pattern = pattern_1 ^ pattern_2 ^ pattern_3
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.Pattern(
            indices=[-3, -2, -1],
            ),
        patterntools.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    operator='xor',
    )
>>> pattern.get_boolean_vector(total_length=16)
[0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1]

Nested grouping:

>>> pattern_1 = patterntools.select_first(3)
>>> pattern_2 = patterntools.select_last(3)
>>> pattern_3 = patterntools.select_every([0], period=2)
>>> pattern = pattern_1 ^ pattern_2 & pattern_3
>>> print(format(pattern))
patterntools.CompoundPattern(
    (
        patterntools.Pattern(
            indices=[0, 1, 2],
            ),
        patterntools.CompoundPattern(
            (
                patterntools.Pattern(
                    indices=[-3, -2, -1],
                    ),
                patterntools.Pattern(
                    indices=[0],
                    period=2,
                    ),
                ),
            operator='and',
            ),
        ),
    operator='xor',
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]

Returns new compound pattern.