Pattern

class datastructuretools.Pattern(indices=None, inverted=None, operator=None, patterns=None, payload=None, period=None)

Pattern.

>>> import abjad
>>> from abjad.tools import rhythmmakertools

Matches three indices out of every eight:

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

Matches three indices out of every sixteen:

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

Works with improper indices:

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

Sieve from opening of Xenakis’s Psappha:

>>> sieve_1a = abjad.index_every([0, 1, 7], period=8)
>>> sieve_1b = abjad.index_every([1, 3], period=5)
>>> sieve_1 = sieve_1a & sieve_1b
>>> sieve_2a = abjad.index_every([0, 1, 2], period=8)
>>> sieve_2b = abjad.index_every([0], period=5)
>>> sieve_2 = sieve_2a & sieve_2b
>>> sieve_3 = abjad.index_every([3], period=8)
>>> sieve_4 = abjad.index_every([4], period=8)
>>> sieve_5a = abjad.index_every([5, 6], period=8)
>>> sieve_5b = abjad.index_every([2, 3, 4], period=5)
>>> sieve_5 = sieve_5a & sieve_5b
>>> sieve_6a = abjad.index_every([1], period=8)
>>> sieve_6b = abjad.index_every([2], period=5)
>>> sieve_6 = sieve_6a & sieve_6b
>>> sieve_7a = abjad.index_every([6], period=8)
>>> sieve_7b = abjad.index_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.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_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.Pattern.Pattern" [color=black, fontcolor=white, group=2, label=<<B>Pattern</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.datastructuretools.Pattern.Pattern"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

from_vector(vector) Makes pattern from boolean vector.
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([indices, inverted]) Makes pattern that matches indices.
index_all([inverted]) Makes pattern that matches all indices.
index_every(indices[, period, inverted]) Makes pattern that matches indices at period.
index_first([n, inverted]) Makes pattern that matches the first n indices.
index_last([n, inverted]) Makes pattern that matches the last n indices.
indices Gets indices of pattern.
inverted Is true when pattern is inverted.
matches_index(index, total_length[, rotation]) Is true when pattern matches index taken under total_length.
operator Gets operator of pattern.
patterns Gets paterns of pattern.
payload Gets payload of pattern.
period Gets period of pattern.
reverse() Reverses pattern.
rotate([n]) Rotates pattern by index n.
weight Gets weight of pattern.
__and__(pattern) Logical AND of two patterns.
__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.
__invert__() Inverts pattern.
__len__() Gets length of pattern.
__ne__(argument) Is true when Abjad object does not equal argument.
__or__(pattern) Logical OR of two patterns.
__repr__() Gets interpreter representation of Abjad object.
__xor__(pattern) Logical XOR of two patterns.

Read-only properties

Pattern.indices

Gets indices of pattern.

Matches three indices out of every eight:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
...     )
>>> pattern.indices
[0, 1, 7]

Matches three indices out of every sixteen:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=16,
...     )
>>> pattern.indices
[0, 1, 7]

Defaults to none.

Set to integers or none.

Returns integers or none.

Pattern.inverted

Is true when pattern is inverted. Otherwise false.

Matches three indices out of every eight:

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

Pattern that rejects three indices from every eight; equivalently, pattern matches 8-3=5 indices out of every eight:

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

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

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_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 = abjad.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.

Pattern.operator

Gets operator of pattern.

Set to string.

Returns string.

Pattern.patterns

Gets paterns of pattern.

Set to patterns or none.

Returns tuple of patterns or none.

Pattern.payload

Gets payload of pattern.

Pattern with rhythm-maker payload assigned to three of every eight indices:

>>> maker = rhythmmakertools.NoteRhythmMaker()
>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     payload=maker,
...     period=8,
...     )
>>> total_length = 10
>>> for index in range(10):
...     match = pattern.matches_index(index, total_length)
...     if match:
...         payload = pattern.payload
...     else:
...         payload = ''
...     print(index, payload)
... 
0 NoteRhythmMaker()
1 NoteRhythmMaker()
2 
3 
4 
5 
6 
7 NoteRhythmMaker()
8 NoteRhythmMaker()
9 NoteRhythmMaker()

Defaults to none.

Set to any object.

Returns arbitrary object.

Pattern.period

Gets period of pattern.

Pattern with a period of eight:

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

Same pattern with a period of sixteen:

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

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

>>> pattern_1 = abjad.Pattern([0], period=4)
>>> pattern_2 = abjad.Pattern([0], period=5)
>>> pattern = pattern_1 | pattern_2
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0],
            period=4,
            ),
        abjad.Pattern(
            indices=[0],
            period=5,
            ),
        ),
    period=20,
    )
>>> pattern.period
20

Returns none when pattern contains acyclic parts:

>>> pattern_1 = abjad.Pattern([0], period=4)
>>> pattern_2 = abjad.Pattern([0])
>>> pattern = pattern_1 | pattern_2
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0],
            period=4,
            ),
        abjad.Pattern(
            indices=[0],
            ),
        ),
    )
>>> pattern.period is None
True

Defaults to none.

Set to positive integer or none.

Returns positive integer or none.

Pattern.weight

Gets weight of pattern.

Gets weight of cyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
...     )
>>> pattern.weight
3

Gets weight of acyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 2, 3],
...     )
>>> pattern.weight
3

Weight defined equal to number of indices in pattern.

Returns nonnegative integer.

Methods

Pattern.get_boolean_vector(total_length=None)

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

Gets boolean vector of acyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
...     )
>>> pattern.get_boolean_vector(4)
[0, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[0, 0, 0, 0, 1, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]

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

>>> pattern.get_boolean_vector()
[0, 0, 0, 0, 1, 1, 1, 1]

Gets vector of cyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
...     period=20,
...     )
>>> pattern.get_boolean_vector(4)
[0, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[0, 0, 0, 0, 1, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]

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

>>> pattern.get_boolean_vector()
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Gets vector of inverted pattern:

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
...     period=20,
...     )
>>> pattern.get_boolean_vector(4)
[0, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[0, 0, 0, 0, 1, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]

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

>>> pattern.get_boolean_vector()
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Two-part pattern with logical OR:

>>> pattern = abjad.Pattern(
...     operator='or',
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     )
>>> 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 = abjad.Pattern(
...     operator='and',
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     )
>>> 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 indexes every fourth and fifth item:

>>> pattern_1 = abjad.Pattern([0], period=4)
>>> pattern_2 = abjad.Pattern([0], period=5)
>>> pattern = pattern_1 | pattern_2
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0],
            period=4,
            ),
        abjad.Pattern(
            indices=[0],
            period=5,
            ),
        ),
    period=20,
    )
>>> 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.

Pattern.get_matching_items(sequence)

Gets maching items from sequence.

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
...     )
>>> pattern.get_matching_items('abcdefghijklmnopqrstuvwxyz')
Sequence(['e', 'f', 'g', 'h'])
>>> pattern = abjad.Pattern(
...     indices=[8, 9],
...     period=10,
...     )
>>> pattern.get_matching_items('abcdefghijklmnopqrstuvwxyz')
Sequence(['i', 'j', 's', 't'])
>>> pattern = abjad.index_first(1) | abjad.index_last(2)
>>> pattern.get_matching_items('abcdefghijklmnopqrstuvwxyz')
Sequence(['a', 'y', 'z'])

Returns new sequence.

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

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

Matches three indices out of every eight:

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

Matches three indices out of every eight, offset 1 to the left:

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

Matches three indices out of every eight, offset ``2`` to the
left:
>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
...     )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(
...         index,
...         total_length,
...         rotation=2,
...         )
...     match = match or ''
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 True
6 True
7 True
8 
9 
10 
11 
12 
13 True
14 True
15 True

Matches three indices out of every sixteen:

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

Matches three indices out of every sixteen, offset 1 to the left:

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

Matches three indices out of every sixteen, offset 2 to the left:

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

Empty pattern:

>>> pattern = abjad.Pattern()

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 = abjad.Pattern(
...     operator='or',
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     )
>>> 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 = abjad.Pattern(
...     operator='and',
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     )
>>> 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 = abjad.Pattern(
...     operator='xor',
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     )
>>> 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 = abjad.Pattern(
...     operator='or',
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     )

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 = abjad.Pattern(
...     operator='and',
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     )

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 = abjad.Pattern(
...     operator='xor',
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             ),
...         ],
...     )

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 = abjad.Pattern(
...     operator='and',
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     )

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 = abjad.Pattern(
...     operator='and',
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...             ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...             ),
...         ],
...     )
>>> pattern = abjad.Pattern(
...     operator='or',
...     patterns=[
...         pattern,
...         abjad.Pattern(
...             indices=[0, 1, 2],
...             ),
...         ],
...     )
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            operator='and',
            patterns=(
                abjad.Pattern(
                    indices=[0],
                    period=2,
                    ),
                abjad.Pattern(
                    indices=[-3, -2, -1],
                    inverted=True,
                    ),
                ),
            ),
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        ),
    )

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.

Pattern.reverse()

Reverses pattern.

Matches three indices out of every eight:

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

Reverses pattern:

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

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

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

Reverses pattern:

>>> pattern = pattern.reverse()
>>> f(pattern)
abjad.Pattern(
    operator='and',
    patterns=(
        abjad.Pattern(
            indices=[-1],
            period=2,
            ),
        abjad.Pattern(
            indices=[2, 1, 0],
            inverted=True,
            ),
        ),
    )

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

Returns new pattern.

Pattern.rotate(n=0)

Rotates pattern by index n.

Matches three indices out of every eight:

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

Rotates pattern two elements to the right:

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

Matches three indices out of every eight with negative indices:

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

Rotates pattern two elements to the right:

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

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

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

Rotates pattern two elements to the right:

>>> pattern = pattern.rotate(n=2)
>>> f(pattern)
abjad.Pattern(
    operator='and',
    patterns=(
        abjad.Pattern(
            indices=[2],
            period=2,
            ),
        abjad.Pattern(
            indices=[-1, 0, 1],
            inverted=True,
            ),
        ),
    )

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

Returns new pattern.

Class & static methods

classmethod Pattern.from_vector(vector)

Makes pattern from boolean vector.

Matches three indices out of every five:

>>> pattern = [1, 0, 0, 1, 1]
>>> pattern = abjad.Pattern.from_vector(pattern)
>>> f(pattern)
abjad.Pattern(
    indices=[0, 3, 4],
    period=5,
    )
>>> total_length = 10
>>> for index in range(10):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
... 
0 True
1 
2 
3 True
4 True
5 True
6 
7 
8 True
9 True

Matches three indices out of every six:

>>> pattern = [1, 0, 0, 1, 1, 0]
>>> pattern = abjad.Pattern.from_vector(pattern)
>>> f(pattern)
abjad.Pattern(
    indices=[0, 3, 4],
    period=6,
    )
>>> total_length = 12
>>> for index in range(12):
...     match = pattern.matches_index(index, total_length)
...     match = match or ''
...     print(index, match)
... 
0 True
1 
2 
3 True
4 True
5 
6 True
7 
8 
9 True
10 True
11 

Returns pattern.

static Pattern.index(indices=None, inverted=None)

Makes pattern that matches indices.

Indexes item 2:

>>> pattern = abjad.index([2])
>>> f(pattern)
abjad.Pattern(
    indices=[2],
    )

Indexes items 2, 3 and 5:

>>> pattern = abjad.index([2, 3, 5])
>>> f(pattern)
abjad.Pattern(
    indices=[2, 3, 5],
    )

Returns pattern.

static Pattern.index_all(inverted=None)

Makes pattern that matches all indices.

Indexes all divisions for tie creation:

>>> pattern = abjad.index_all()
>>> f(pattern)
abjad.Pattern(
    indices=[0],
    period=1,
    )
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     tie_specifier=rhythmmakertools.TieSpecifier(
...         tie_across_divisions=pattern,
...         use_messiaen_style_ties=True,
...         ),
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

Returns pattern.

static Pattern.index_every(indices, period=None, inverted=None)

Makes pattern that matches indices at period.

Indexes every second division:

>>> mask = abjad.index_every(indices=[1], period=2)
>>> print(format(mask))
abjad.Pattern(
    indices=[1],
    period=2,
    )
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     division_masks=[mask],
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

Indexes every second and third division:

>>> mask = abjad.index_every(indices=[1, 2], period=3)
>>> print(format(mask))
abjad.Pattern(
    indices=[1, 2],
    period=3,
    )
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     division_masks=[mask],
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

Returns pattern.

static Pattern.index_first(n=1, inverted=None)

Makes pattern that matches the first n indices.

Indexes first division for tie creation:

>>> pattern = abjad.index_first()
>>> f(pattern)
abjad.Pattern(
    indices=[0],
    )
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     tie_specifier=rhythmmakertools.TieSpecifier(
...         tie_across_divisions=pattern,
...         use_messiaen_style_ties=True,
...         ),
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

Selects first two divisions for tie creation:

>>> pattern = abjad.index_first(n=2)
>>> f(pattern)
abjad.Pattern(
    indices=[0, 1],
    )
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     tie_specifier=rhythmmakertools.TieSpecifier(
...         tie_across_divisions=pattern,
...         use_messiaen_style_ties=True,
...         ),
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

Selects no divisions for tie creation:

>>> pattern = abjad.index_first(n=0)
>>> f(pattern)
abjad.Pattern()
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     tie_specifier=rhythmmakertools.TieSpecifier(
...         tie_across_divisions=pattern,
...         use_messiaen_style_ties=True,
...         ),
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

Returns pattern.

static Pattern.index_last(n=1, inverted=None)

Makes pattern that matches the last n indices.

Indexes last two divisions for tie creation:

>>> pattern = abjad.index_last(n=2)
>>> f(pattern)
abjad.Pattern(
    indices=[-2, -1],
    )
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     tie_specifier=rhythmmakertools.TieSpecifier(
...         tie_across_divisions=pattern,
...         use_messiaen_style_ties=True,
...         ),
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

(Tie creation happens between adjacent divisions. Selecting only the last division creates no ties.)

Selects no divisions for tie creation:

>>> pattern = abjad.index_last(n=0)
>>> f(pattern)
abjad.Pattern()
>>> maker = rhythmmakertools.NoteRhythmMaker(
...     tie_specifier=rhythmmakertools.TieSpecifier(
...         tie_across_divisions=pattern,
...         use_messiaen_style_ties=True,
...         ),
...     )
>>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)]
>>> music = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     music,
...     divisions,
...     )
>>> show(lilypond_file) 

Returns pattern.

Special methods

Pattern.__and__(pattern)

Logical AND of two patterns.

Flat grouping of two patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 & pattern_2
>>> f(pattern)
abjad.Pattern(
    operator='and',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )

Flat grouping of three patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index_every([0], period=2)
>>> pattern = pattern_1 & pattern_2 & pattern_3
>>> f(pattern)
abjad.Pattern(
    operator='and',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        abjad.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    )
>>> 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 of three patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index_every([0], period=2)
>>> pattern = pattern_1 & pattern_2 | pattern_3
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            operator='and',
            patterns=(
                abjad.Pattern(
                    indices=[0, 1, 2],
                    ),
                abjad.Pattern(
                    indices=[-3, -2, -1],
                    ),
                ),
            ),
        abjad.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]

In-place AND is allowed:

>>> pattern = abjad.index_first(3)
>>> pattern &= abjad.index_last(3)
>>> f(pattern)
abjad.Pattern(
    operator='and',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )

Returns new pattern.

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

Pattern.__invert__()

Inverts pattern.

>>> pattern = abjad.index_first(3)
>>> f(pattern)
abjad.Pattern(
    indices=[0, 1, 2],
    )
>>> pattern = ~pattern
>>> f(pattern)
abjad.Pattern(
    indices=[0, 1, 2],
    inverted=True,
    )
>>> pattern = ~pattern
>>> f(pattern)
abjad.Pattern(
    indices=[0, 1, 2],
    inverted=False,
    )

Negation defined equal to inversion.

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

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 | pattern_2
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )
>>> 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
>>> f(pattern)
abjad.Pattern(
    inverted=True,
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )
>>> 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 pattern.

Pattern.__len__()

Gets length of pattern.

Gets length of cyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
...     )
>>> len(pattern)
8

Length of cyclic pattern defined equal to period of the pattern.

Gets length of acyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 2, 3],
...     )
>>> len(pattern)
4

Length of acyclic pattern defined equal to greatest index in pattern, plus 1.

Gets length of pattern with negative indices:

>>> pattern = abjad.Pattern(
...     indices=[-3],
...     )
>>> len(pattern)
3

Length of pattern with negative indices defined equal to absolute value of least index.

Returns nonnegative integer.

(AbjadObject).__ne__(argument)

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

Returns true or false.

Pattern.__or__(pattern)

Logical OR of two patterns.

Flat grouping of two patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 | pattern_2
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )

Flat grouping:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index_every([0], period=2)
>>> pattern = pattern_1 | pattern_2 | pattern_3
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        abjad.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    )
>>> 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 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index_every([0], period=2)
>>> pattern = pattern_1 | pattern_2 & pattern_3
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            operator='and',
            patterns=(
                abjad.Pattern(
                    indices=[-3, -2, -1],
                    ),
                abjad.Pattern(
                    indices=[0],
                    period=2,
                    ),
                ),
            ),
        ),
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]

In-place OR is allowed:

>>> pattern = abjad.index_first(3)
>>> pattern |= abjad.index_last(3)
>>> f(pattern)
abjad.Pattern(
    operator='or',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )

Returns new pattern.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

Pattern.__xor__(pattern)

Logical XOR of two patterns.

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 ^ pattern_2
>>> f(pattern)
abjad.Pattern(
    operator='xor',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )

Flat grouping:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index_every([0], period=2)
>>> pattern = pattern_1 ^ pattern_2 ^ pattern_3
>>> f(pattern)
abjad.Pattern(
    operator='xor',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        abjad.Pattern(
            indices=[0],
            period=2,
            ),
        ),
    )
>>> 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 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index_every([0], period=2)
>>> pattern = pattern_1 ^ pattern_2 & pattern_3
>>> f(pattern)
abjad.Pattern(
    operator='xor',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            operator='and',
            patterns=(
                abjad.Pattern(
                    indices=[-3, -2, -1],
                    ),
                abjad.Pattern(
                    indices=[0],
                    period=2,
                    ),
                ),
            ),
        ),
    )
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]

In-place XOR is allowed:

>>> pattern = abjad.index_first(3)
>>> pattern ^= abjad.index_last(3)
>>> f(pattern)
abjad.Pattern(
    operator='xor',
    patterns=(
        abjad.Pattern(
            indices=[0, 1, 2],
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        ),
    )

Returns new pattern.