CompoundPattern

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

Compound pattern.

Example 1. 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',
    )

Example 2. 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',
    )

Example 3. 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) Changes item to item.
get_boolean_vector([total_length]) Gets boolean vector of pattern applied to input sequence with total_length.
index(item) Changes item to item.
inverted Is true when compound pattern is inverted.
item_class Item class to coerce items into.
items Gets collection items.
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.
__add__(expr) Adds typed tuple to expr.
__and__(pattern) Logical AND of two patterns.
__contains__(item) Change item to item and return true if item exists in collection.
__eq__(expr) Is true when expr is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Formats Abjad object.
__getitem__(i) Gets i from type tuple.
__getslice__(start, stop) Gets slice from start to stop in typed tuple.
__hash__() Hashes typed tuple.
__invert__() Inverts pattern.
__iter__() Iterates typed collection.
__len__() Length of typed collection.
__mul__(expr) Multiplies typed tuple by expr.
__ne__(expr) Is true when expr is not a typed collection with items equal to this typed collection.
__or__(pattern) Logical OR of two patterns.
__radd__(expr) Right-adds expr to typed tuple.
__repr__() Gets interpreter representation of Abjad object.
__rmul__(expr) Multiplies expr by typed tuple.
__xor__(pattern) Logical XOR of two patterns.

Read-only properties

CompoundPattern.inverted

Is true when compound pattern is inverted. Otherwise false.

Example 1. 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]

Example 2. 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

Item class to coerce items into.

(TypedCollection).items

Gets collection items.

CompoundPattern.operator

Gets operator of compounnd pattern.

Set to string.

Returns string.

CompoundPattern.period

Gets period of compound pattern.

Example 1. 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

Example 2. 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)

Changes item to item.

Returns count in collection.

CompoundPattern.get_boolean_vector(total_length=None)

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

Example 1. 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).

Example 2. 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).

Example 3. 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.

(TypedTuple).index(item)

Changes item to item.

Returns index in collection.

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

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

Example 1. 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.

Example 2. 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.

Example 3. 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).

Example 4. 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).

Example 5. 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).

Example 6. 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).

Example 7. 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.

Example 1. 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.

Example 1. 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__(expr)

Adds typed tuple to expr.

Returns new typed tuple.

CompoundPattern.__and__(pattern)

Logical AND of two patterns.

Example 1. 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]

Example 2. 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)

Change item to item and return true if item exists in collection.

Returns none.

(TypedCollection).__eq__(expr)

Is true when expr 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__(i)

Gets i from type tuple.

Returns item.

(TypedTuple).__getslice__(start, stop)

Gets slice from start to stop in typed tuple.

Returns new typed tuple.

(TypedTuple).__hash__()

Hashes typed tuple.

Returns integer.

CompoundPattern.__invert__()

Inverts pattern.

Example 1. 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]

Example 2. 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__()

Length of typed collection.

Returns nonnegative integer.

(TypedTuple).__mul__(expr)

Multiplies typed tuple by expr.

Returns new typed tuple.

(TypedCollection).__ne__(expr)

Is true when expr 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.

Example 1. 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]

Example 2. 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__(expr)

Right-adds expr to typed tuple.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(TypedTuple).__rmul__(expr)

Multiplies expr by typed tuple.

Returns new typed tuple.

CompoundPattern.__xor__(pattern)

Logical XOR of two patterns.

Example 1. 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]

Example 2. 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.