# Generator size manipulation

A canonical mapping form is an important standard to have as community for uniquely identifying temperaments, but it is not the only mapping form one should ever need, because one may wish to use differently-sized generators. Several such forms with different generator sizes have been presented, such as positive generator form, equave-reduced generator form, and minimal-generator form.

For our purposes here we will be using the defactored Hermite form as the canonical form. If two mappings are equivalent, i.e. they have the same canonical form and therefore represent the same temperament, then their corresponding generators are equivalent too. That doesn't mean their generators are the same sizes; it only means that in combination with each other, their generators reach the same set of pitches.

For example, the canonical form of 5-limit meantone is [1 1 0] 0 1 4], and form has generators with sizes of approximately an octave and a perfect fifth, respectively. But any pitch system constructed using an octave and a perfect fifth could also have been constructed using an octave and a perfect fourth, because the perfect fourth is the octave complement of the perfect fifth. Specifically, any pitch we reached previously with a perfect fifth could be instead reached by going up an octave and down a perfect fourth. So in situations where we're approaching 5-limit meantone as a pitch system constructed by an octave and a perfect fourth, we might prefer to have the mapping in that form, which looks like [1 2 4] 0 -1 -4].

As a further example, we might prefer only to use generators that are approximations of primes, so we'd like meantone's mapping in the form where the generators are an octave and a perfect twelfth, or tritave (3/1). This works for a similar reason: anything we could have reached with a perfect fifth we could also reach by moving up a tritave and down an octave, and that form looks like [1 0 -4] 0 1 4].

[⟨octave] ⟨fifth]⟩ [⟨1 1 0] ⟨0 1 4]⟩ [⟨1 2 4] ⟨0 -1 -4]⟩ [⟨1 0 -4] ⟨0 1 4]⟩

Now clearly all three of these mapping forms look related, and they are indeed, but the exact relationships between them may not be immediately apparent, or how those relationships correspond to the relationships between their generator sizes. The purpose of this article is to demonstrate tricks for transforming from one matrix form to another so that we can make the generators the sizes we want, and along the way we'll look at how the tricks work in order to explain these relationships.

## Generator size manipulation tricks

### First trick: change one generator by the size of another generator

The most basic trick is this: for a rank $r$ temperament whose mapping has rows $\textbf{r}_1, \textbf{r}_2 ... \textbf{r}_r$, and corresponding generators with cents $g_1, g_2 ... g_r$, if we want to increase $g_a$ by $g_b$, then replace $\textbf{r}_b$ with $\textbf{r}_b' = \textbf{r}_b - \textbf{r}_a$.

Let's demonstrate this trick on the most recent example we looked at: meantone as generated by an octave and a tritave. If we begin with meantone in canonical form, [1 1 0] 0 1 4], where the generators are an octave and a perfect fifth, then we know we need to increase the second generator by the size of the first generator, because a tritave is equal to a perfect fifth plus an octave. So in terms of our variables, we must change $g_2$ so that it's $g_2 + g_1$. According to our trick, then, we must replace $\textbf{r}_1$ with $\textbf{r}_1' = \textbf{r}_1 - \textbf{r}_2$. And so $\textbf{r}_1'$ is found like this:

$\begin{array} {r} \textbf{r}_1 \\ -\textbf{r}_2 \\ \hline \textbf{r}_1' \end{array} → \begin{array} {r} & \langle & 1 & 1 & 0 & ] \\ - & \langle & 0 & 1 & 4 & ] \\ \hline & \langle & 1 & 0 & -4 & ] \end{array}$

And then simply replace $\textbf{r}_1$ = 1 1 0] with $\textbf{r}_1'$ = 1 0 -4] in the mapping, changing [1 1 0] 0 1 4] to [1 0 -4] 0 1 4].

It may be counterintuitive at first that in order to change the size of a generator we must make a change to a mapping row other than the one which corresponds to that generator (in this example, we changed the size of of the second generator by changing the first row). But there is a way to train our intuition on this effect. Think of it like transferring jobs. Remember that in order to know the size in cents of a generator, we cannot look exclusively at that generator's mapping row out of context; we need to know the entire mapping, because the mapping rows all work together to determine how the temperament works. So we can think of every mapping row like a workforce that outsources some of its work to the other rows; they're an interconnected system of workforces. And so when we subtract one row from another, we're in effect saying that the row being subtracted from is going to do less of the work of the row being subtracted. So when we subtract $\textbf{r}_2$ from $\textbf{r}_1$, what we're saying is that whatever work the first generator was doing for the second generator, it will no longer do that work anymore, so the second generator will need to take care of that work itself; and that's why $g_2$ becomes the size of $g_2$ plus $g_1$.

Conversely, if we want to decrease $g_a$ by $g_b$, then we replace $\textbf{r}_b$ with $\textbf{r}_b' = \textbf{r}_b$ plus $\textbf{r}_a$.

### Second trick: negating a generator

Now let's demonstrate a slightly more complicated example: transforming the 5-limit meantone mapping from its canonical form which uses a perfect fifth to the form which uses a perfect fourth. Again, we know this is possible because the perfect fourth is the octave complement of the perfect fifth.

This generator complementing principle is not exclusive to the octave; it is fully generalizable, which is to say that we may replace any generator with its complement with any other generator, and we'll still be describing the same pitch system. Again, this is because any pitch we could have reached previously we can still reach, by moving by a combination of the new generator and the other generator we just changed its size by[1].

We could describe replacing a generator with its complement with another generator like this: first negate the generator, and then add the other generator.

Therefore, our first step is to negate our meantone generator so that it no longer represents a perfect fifth upward, but rather a perfect fifth downward.

We can't accomplish this using the one trick we've already learned. How could we? That first trick relies on the interactions of two different generators, whereas negating a generator only involves one generator: itself. So here's where our second generator size manipulation trick comes in: negating a generator.

Fortunately this second trick is very easy. All we need to do in order to negate $g_a$ (the generator size, e.g. in cents) is to negate each of the terms of the mapping row $\textbf{r}_a$. So, we would simply change $\textbf{r}_2$ = 0 1 4] to $\textbf{r}_2'$ = 0 -1 -4], thereby changing the mapping from [1 1 0] 0 1 4] to [1 1 0] 0 -1 -4][2].

So at this point, the generators are an octave and a negative perfect fifth. It's time for our second step.

The second step of achieving a generator with the size of a perfect fourth should be familiar: we need to increase our negative perfect fifth to a perfect fourth, and so we need to add one octave, and therefore we need to change $\textbf{r}_1$ to be $\textbf{r}_1 - v_2$, so we end up with:

$\begin{array} {r} \textbf{r}_1 \\ -\textbf{r}_2 \\ \hline \textbf{r}_1' \end{array} → \begin{array} {r} & \langle & 1 & 1 & 0 & ] \\ - & \langle & 0 & -1 & -4 & ] \\ \hline & \langle & 1 & 2 & 4 & ] \end{array}$

And we're done, having found the mapping [1 2 4] 0 -1 -4].

### Beyond rank-2

A demonstration of how one might transform the size of a generator of a rank-3 temperament.

These two tricks should enable us to attain any valid generator sizes we may wish for a given temperament. And these tricks work for any rank[3], not only rank 2 like we've looked at thus far with 5-limit meantone examples. To be clear, for a rank $r$ temperament, adding or subtracting $\textbf{r}_a$ from another generator will only affect the size of $g_a$.

For example, 7-limit marvel's canonical form is [1 0 0 -5] 0 1 0 2] 0 0 1 2], with generators of an octave, tritave, and pentave (5/1), in that order. We can change that second generator from a tritave to a perfect fifth by decreasing $g_2$ by $g_1$, which we know by the first trick means we add $\textbf{r}_2$ to $\textbf{r}_1$, producing [1 1 0 -3] 0 1 0 2] 0 0 1 2]. Helpfully, this trick has no effect on any other generators that were not involved, which in this case is just the size of the pentave, which was the one remaining generator out of the three in this temperament.

The fact that these tricks have isolated effects on the generator sizes like this makes it straightforward to compose sequences of them, applied one after the other, to attain an incredible variety of valid generator sizes, as you can see in the diagram to the right.

### Avoiding enfactoring

Using these two tricks, you do not have to worry about enfactoring the mapping, i.e. introducing a common factor in one of the rows. This is because neither of these tricks ever involve replacing a row with a multiple of that row; we always replace a row with a combination of at least one each of two different rows, as in trick 1, or with the row negated, as in trick 2.

## Tuning strategy

In order to define the size of the generators, you need to specify a tuning strategy. Though if you have two generators that are close enough that their size ranking depends on the tuning, then you probably have other problems. In any case, the tuning strategy that we'll be using here is T2, because it's decent enough and easy to compute.

## Easy instructions table to achieve mingen form for rank-2 mapping

The following table shows how to obtain minimal-generator form from various starting positions, by synthesizing the two generator size manipulation tricks explained in the previous section. In this table, the period $p$ is the first mapping row $r_1$ in cents and the generator $g$ is the second mapping row $r_2$ in cents. It uses the simple example of 5-limit meantone.

mapping manipulations
mapping $p$ (¢) $g$ (¢) current $p$ vs. $g$ desired new $g$ required $\textbf{r}_1$ change required $\textbf{r}_2$ change repeat?
[1 0 -4] 0 -1 -4] 1201.4 −1898.4 g < −p g + p \textbf{r}₁ − 2\textbf{r}₂ yes
[1 1 0] 0 -1 -4] 1201.4 −697.049 −p <= g < −p/2 p + g \textbf{r}₁ − \textbf{r}₂ no, you're done
[1 2 4] 0 1 4] 1201.4 −504.348 −p/2 <= g < 0 −g −\textbf{r}₂ no, you're done
[1 2 4] 0 -1 -4] 1201.4 504.4 0 <= g <= p/2 g no, you're done
[1 1 0] 0 1 4] 1201.4 697.049 p/2 < g <= p p - g \textbf{r}₁ + \textbf{r}₂ −\textbf{r}₂ no, you're done
[1 0 -4] 0 1 4] 1201.4 1898.4 p < g g - p \textbf{r}₁ + 2\textbf{r}₂ −\textbf{r}₂ yes

### Wolfram Language implementation of mingen form instructions above

The below code essentially works through the input matrix M two rows at a time, beginning with the first two rows. Each pair of rows is "fixed" so that the second row is less than half of the first row. The same set of changes and potential recursions as described in the table in the previous section is used for each pair of rows. When the sizes of the generators is computed, T2 tuning is used for its computational frugality and reasonableness.

jip[d_] := Map[Log2, Map[Prime,Range[d]]]
tenneyWeights[m_] := DiagonalMatrix[1/jip[Last[Dimensions[m]]]]
unweightedG[m_] := PseudoInverse[m]
weightedG[m_] := tenneyWeights[m].PseudoInverse[m.tenneyWeights[m]] // N
octaves[vOrVList_]:= N[jip[Length[vOrVList]].vOrVList, 10]
cents[vOrVList_] := N[1200.octaves[vOrVList], 10]

gens[m_] := cents[weightedG[m]]

fixM[m_, i_] := Module[{localM, rp, rg, mGens, p, g, fixedRpRg, fixedM},
localM = m;
rp = m[[i]];
rg = m[[i+1]];

mGens = gens[m];
p = mGens[[i]];
g = mGens[[i+1]];

fixedRpRg = Which[
g < -p, {rp-2*rg, rg},
-p <= g < -p/2, {rp-rg, rg},
-p/2 <= g < 0, {rp, -rg},
0 <= g <= p/2, {rp, rg},
p/2 < g <=p, {rp+rg, -rg},
p < g, {rp+2*rg, -rg}
];

fixedM = Take[localM, i-1] ~ Join ~ fixedRpRg ~ Join ~ Drop[localM, i+1];

If[
g < -p || p < g,
fixM[fixedM, i],
fixedM
]
]

mingen[m_] := Module[{localM, rp, rg, fixedM},
localM = m;

For[i = 1, i < Length[localM], i++,
localM = fixM[localM, i];
];

localM
]

(* examples *)

tester[m_] := Module[{ming},
ming = mingen[m];
"in: " <> ToString@m <> " w/ gens: " <> ToString@gens[m] <> "\nout: " <> ToString@ming <> " w/ gens: " <> ToString@gens[ming]
]

tester[{{1, 0, -4}, {0, -1, -4}}]
tester[{{1, 1, 0}, {0, -1, -4}}]
tester[{{1, 2, 4}, {0, 1, 4}}]
tester[{{1, 2, 4}, {0, -1, -4}}]
tester[{{1, 1, 0}, {0, 1, 4}}]
tester[{{1, 0, -4}, {0, 1, 4}}]

tester[{{12, 19, 28}}]
tester[{{1, 2, 3}, {0, 3, 5}}]
tester[{{1, 0, -4, -13}, {0, 1, 4, 10}}]
tester[{{5, 8, 0}, {0, 0, 1}}]
tester[{{2, 0, 11, 12}, {0, 1, -2, -2}}]
tester[{{1, 0, 0, -5}, {0, 1, 0, 2}, {0, 0, 1, 2}}]
tester[{{1, 0, 0, -5, 12}, {0, 1, 0, 2, -1}, {0, 0, 1, 2, -3}}]
tester[{{1, 8, 0}, {0, 11, -4}}]

dimensionality = RandomInteger[{3, 6}];
rank = RandomInteger[{2, dimensionality}];
randomM = RandomInteger[{-10, 10}, {rank, dimensionality}]
tester[randomM]



# Footnotes

1. And, of course, we can't reach any new pitches we couldn't already reach previously, either.
2. To extend the workplace analogy (if we really like, though I doubt it's helpful here), we could say that we changed $\textbf{r}_2$'s jobs so that they now do the exact opposite of what they used to do, so if we want them to accomplish the same thing as they used to, we have to have them undo their work.
3. past 1, anyway; of course, rank 1 temperaments are somewhat inflexible in their single generator's size.