# Sieve Theory

## Contents

# Sieve Theory#

The usage of sieves is first mentioned in [Xen92] in the chapter *Towards a Metmusic* and this technique is used to construct scales.

The chapter starts with a definition for a *tempered chromatic scale* much similiar to the Peano axioms in mathematics which serves as axioms on the natural numbers.
This scale is not limited to pitch but can also account for parameters such as denisity or intensity.

## Congruency#

Another definition which is important for the contsruction of sieves is *congruence*.

Definition

Two integers \(x\) and \(n\) are said to be congruent modulo \(m\) when \(m\) is a factor of \(x-n\). We write this down as \(x \equiv n \mod m\).

Some examples are

```
19.mod(5)
```

```
-> 4
```

```
13.mod(8)
```

```
-> 5
```

```
14.mod(7)
```

```
-> 0
```

For \(m, n, \in \mathbb{N}\) every \(n\) is mapped to a \(i \in \mathbb{N}\) which fulfills \(i \mod m\) where \(i \in R = \lbrace 0, 1, \dots, m-1 \rbrace\).
We define the set \(R\) as the set of *residual classes* and \(m_i = \lbrace n | n \equiv i \mod m \rbrace\).
We note that the cardinality of \(R\) must not be equal to \(m\), e.g. for \(x \in \mathbb{N}\) the residual class for \(x^2 \mod 6\) is \(R = \lbrace 0, 1, 3, 4 \rbrace\).

```
(0..12).collect({|i| i.mod(3)})
```

```
-> [ 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0 ]
```

```
(0..30).collect({|i| i.pow(2).asInteger.mod(6)})
```

```
-> [ 0, 1, 4, 3, 4, 1, 0, 1, 4, 3, 4, 1, 0, 1, 4, 3, 4, 1, 0, 1, 4, 3, 4, 1, 0, 1, 4, 3, 4, 1, 0 ]
```

## Scales#

Xenakis uses a residual class \(m_i\) where \(m\) is the starting point in the chromatic scale and \(i\) is the residual class (or step size). For now lets assume the 12 ET chromatic scale starting from \(\text{C}\) and inspect the example from the book

Note that \(4_4 = 4_0\) as this will repeat the same residuals.

```
(0..3).collect({|i|
(0..11).select({|j|
j.mod(4)==i
});
});
```

```
-> [ [ 0, 4, 8 ], [ 1, 5, 9 ], [ 2, 6, 10 ], [ 3, 7, 11 ] ]
```

### Scales and set theory#

By using set theory we can combine these residual classes to construct a variety of scales.
Most important are the terms *union*, *intersection* and *complement* which we will define as follows:

Definition

Let \(A\) and \(B\) be sets.

The

*union*of the sets \(A\) and \(B\) (written as \(A \cup B\), Xenakis uses \(A \lor B\)) contains all elements from \(A\) and \(B\), so

The

*intersection*of the sets \(A\) and \(B\) (written as \(A \cap B\), Xenakis uses \(A \land B\)) contains all elements that are both in \(A\) and \(B\), so

The

*complement*of a set \(A\) (written as \(A^c\) or \(\overline{A}\)) contains all elements that are not in \(A\), so

A Venn diagram helps to understand these basic set operations.

Lets construct 2 scales via residual classes

which both are the possible both tone scales in 12ET.

The union \(2_0 \cup 2_1 = \lbrace \text{C, C#, D, D#, E, F, F#, G, G#, A, A#, B} \rbrace\) is simply the 12ET we started with.

The intersection \(2_0, \cap 2_1 = \emptyset\) is the empty set as both scales do not share any notes.

\(\overline{2_0} = 2_1 = \lbrace \text{C#, D#, F, G, A, B} \rbrace\) as both scales are complementary.

```
a = (0..11).select({|i| i.mod(2)==0}).asSet;
b = (0..11).select({|i| i.mod(2)==1}).asSet;
"Set A: % \t Set B: %".format(a, b).postln;
```

```
Set A: Set[ 8, 4, 0, 2, 6, 10 ] Set B: Set[ 1, 3, 5, 9, 7, 11 ]
-> Set A: Set[ 8, 4, 0, 2, 6, 10 ] Set B: Set[ 1, 3, 5, 9, 7, 11 ]
```

```
a.union(b).asArray.sort
```

```
-> [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
```

```
a.sect(b).asArray.sort
```

```
-> [ ]
```

On page 196 Xenakis constructs the major scale via

which we also want to implement in SC. Instead of repeating the aproach from above and repeating the same steps over and over again we will write a function which we will call to generate the appropiate set.

```
f = {|i, j, unity=true|
// we go through all 12 tones of our ET chromatic scale
(0..11).select({|k|
// if unity is false we will return the complementary
if(unity, {
k.mod(i)==j;
}, {
k.mod(i)!=j;
});
}).asSet;
}
```

```
-> a Function
```

Now we can simply use the `sect (&)`

and `union (|)`

methods of the `Set`

class to construct the major scale.

```
x = (f.(3, 2, false) & f.(4, 0)) | (f.(3, 1, false) & f.(4, 1)) | (f.(3, 2) & f.(4, 2)) | (f.(3, 0, false) & f.(4, 3))
```

```
-> Set[ 5, 0, 9, 7, 4, 2, 11 ]
```

After we boot the server we can use a `Pdef`

to play back the scale to us.

```
s.boot;
```

```
-> localhost
```

```
Ndef(\scale, Pbind(
\dur, 0.5,
\note, Pseq(x.asArray.sort, 2)
)).play;
```

```
-> Ndef('scale')
```

And indeed it is the major scale.

As we now know how to construct scales via sieves we can try out some scales which are not based on the congruence classes of \(4\) and \(3\) (which are taken for symmetry reasons which allow for transposing the scales easily as discussed in the book) or permuting scales.

```
Tdef(\scalePlayer, {
(0..4).do({|i|
// modify the scale construction
var scale = f.(4, i) | f.(5, 4-i);
scale = scale.asArray.sort;
["scale", i, scale].postln;
scale.do({|note|
(note: note, dur: 0.125).play;
0.125.wait;
});
0.25.wait;
})
}).play;
```

```
-> Tdef('scalePlayer')
```

Note that for the exsiting examples we limited ourselves to the 12 ET chromatic scale but the usage of sieves is not limited to this scale. We can construct sieves with any kind of scale that can be expressed as well ordered set of Ordinals.