Acknowledgements
My thanks go to Herman Miller (http://www.io.com/~hmiller) for prompting me to formulate this general method, by informing me of his discovery of the usefulness of distributing the 126/125 small septimal comma (septimal semicomma?) (13.8c), and in particular the usefulness of tempering the octave in this case. I had previously only used the method to distribute the 225/224 septimal kleisma (7.7c) in the case of Lumma's tuning. (See lumma.scl in the Scala archive, http://www.xs4all.nl/~huygensf/scala/).
Introduction
The art and science of tuning musical scales can be seen as an eternal struggle between the conflicting requirements of maximising the number of available harmonies (and minimising their errors) while minimising the number of pitches. To a first approximation, a harmony is a pair of notes whose frequencies are in a simple wholenumber ratio, e.g. 1:2,1:3, 2:3, 3:4, 3:5. (See A note on mathematical notation for musical intervals). For the purpose of this paper I adopt a fairly generous definition of "simple wholenumber ratio". It will mean that, when the ratio is in lowest terms, no side is greater than 11, the two sides sum to no more than 20, and the interval spans no more than two octaves. In fact, we are rarely interested in the accuracy of ratios where any side is greater than 9, or that sum to more than 14, or that span more than a ninth.
Here is a table of all those intervals, listed in order of increasing
width, with the most important ones marked with an asterisk. The words
in parenthesis are optional. If you are interested in the system used to
name these and other intervals, please see A
note on the naming of musical intervals.







unison 

*  augmented fourth 

*  (major) ninth 

*  
classic major second 

diminished fifth 

subminor tenth 


Pythagorean major second 

(perfect) fifth 

*  major tenth 


supermajor second 

subminor sixth 

(perfect) eleventh 


subminor third 

*  minor sixth 

*  super eleventh 


minor third 

*  major sixth 

*  (perfect) twelfth 


neutral third 

subminor seventh 

*  major thirteenth 


major third 

*  (classic) minor seventh 

*  subminor fourteenth 


supermajor third 

neutral seventh 

neutral fourteenth 


(perfect) fourth 

*  octave 

*  two octaves 


super fourth 

neutral ninth 

What's a comma?
When we start stacking intervals that are tuned in precise frequency ratios (justly intoned), we sometimes find situations where two different stacks result in pitches which are almost the same. For example, meantone tunings are based on the fact that a stack of four fifths (2:3) is only slightly wider than two octaves (1:2) and a major third (4:5). We can work out that the difference between them is
(3/2 * 3/2 * 3/2 * 3/2) / (2/1 * 2/1 * 5/4) = 81/80To convert a ratio to cents we take its logarithm to the base 2 and multiply by 1200.
ln(81/80) / ln(2) * 1200 = 21.51 cA comma is any small interval that arises in a similar manner, in the range of about 2 to 65 cents. This particular one is called the syntonic comma. Some of these intervals may have other names such as various kinds of kleisma or diesis, but here I use comma as a generic term for all of them.
Why would we want to distribute a comma?
Rather than have two pitches which differ by such a small amount, we would prefer to have a single pitch which is somewhere between the two. But rather than change only the final pitch in the stack, we can obtain a much better result by distributing the error through the stack. In the above example, by narrowing each fifth by 1/4 of a syntonic comma (5.4 c) we obtain the well known 1/4comma meantone tuning system.
What do we mean by "optimal distribution"?
The particular kind of optimisation I'm referring to here is the one where we want to minimise the maximum of the absolute values of the errors of all the intervals that we care about; assuming they relate to the comma under consideration. It also seems that the method might be modified to minimise the maximum beat rate in a given chord. The RMS (or sum of squares) error cannot be minimised by this method but since it is a continuous function its minima may be found by equating its partial derivatives to zero and solving.
How do we do it?
First we'll consider a simple case where the intervals, whose errors we care about, have at most a single prime factor on each side of their ratio (in lowest terms) e.g. 1:2, 2:3, 2:5, 3:5, 2:7, 3:7, 5:7, or if we decide not to temper the octave, we can include those intervals with at most a single odd prime factor on each side, e.g. we can add 3:4, 4:5, 5:8, 5:6, 4:7, 6:7 (but not 4:9, 5:9, 7:9) to the list above. So in general, this simple case will allow for at most one tempered prime factor on each side of the ratio, and some other cases that we won't go into at this stage.
The syntonic comma 80:81
We'll use the syntonic comma for our first example.
First we prime factorise the comma's ratio.
81 3 * 3 * 3 * 3  =  80 2 * 2 * 2 * 2 * 5If you're not willing or able to temper the octaves then eliminate all factors of two. (We'll eliminate them for this first example.)
3 * 3 * 3 * 3  5Now see which line has the most factors and count the number of prime factors it has.
The top line is the longest, with 4 factors.The optimum distribution will occur when the comma is equally distributed over all those factors in the longest line, with zero errors for those in the shortest line. If it's the top line, each factor must be given a negative error (narrowed), if it's the bottom line, they must be given positive errors (widened).
So the errors in the top primes of our example (only "3" in this case) will be 1/4 of the comma, and the errors in the bottom primes (5) will be zero.
Now to obtain the error in any interval just prime factorise the interval's ratio and sum the errors for each prime on the top line and subtract the errors for each prime on the bottom line.
5 e.g. 4:5 =  so its error in the major third will be 2 * 2 (0)  (0 + 0) = 0 The error in the fifth (2:3) will be (1/4)  (0) = 1/4 comma All the relevant errors in this case are therefore: 1:2 2:3 4:5 5:6 ratio 0.0 5.4 0.0 5.4 error in cents 3:4 5:8 3:5 ratio +5.4 0.0 +5.4 error in centsThe syntonic comma  temper the octave?
Now lets look at what happens if we are willing to temper the octave.
81 3 * 3 * 3 * 3  =  80 2 * 2 * 2 * 2 * 5With the 2's left in, the longest line is the bottom one, with 5 factors.
So the rule says the optimum is to widen the 2 and the 5 by 1/5comma (4.3 c) and have a just 3. But remember I said that this is a simplified version of the procedure that doesn't work for ratios with more than one tempered prime factor on either side. So we shouldn't expect it to work for 4:5, 3:4 or 5:8. Lets look at the errors.
1:2 2:3 4:5 5:6 ratio +4.3 4.3 4.3 0.0 error in cents 3:4 5:8 3:5 ratio +8.6 +8.6 +4.3 error in centsOK. It didn't work for the 3:4 or 5:8 but it did work for the 4:5. Why? Because some errors cancelled out between the two sides of the ratio. This is one of the other cases I didn't go into above. So the real proviso is, it works for ratios where the counts, of tempered prime factors on each side of the ratio, differ by at most one.
So what do we do to make it work when they differ by more than one? We "weight" the count for the offending prime so they don't differ by more than 1 for any of the intervals under consideration. In this case, if we weight the count of 2's by 1/2 then 3:4 = 3:(2 * 2) will have one tempered prime on top and none on the bottom, 5:8 (= 5:(2 * 2 * 2)) will have 1.5 tempered primes on the top and 1 on the bottom.
The syntonic comma  refining the method
So now we go back to the syntonic comma ratio and count prime factors top and bottom using this weighting.
81 3 * 3 * 3 * 3  =  = 21.51 c 80 2 * 2 * 2 * 2 * 5We now count 4 on top and 3 on the bottom (the number of 2's is multiplied by 0.5), so even if we are willing to temper the octaves, we find that 1/4comma meantone (with only the 3's tempered) is still the best. So there's no point in tempering the octaves for meantone if we are only concerned about the seven ratios whose errors are listed above.
The syntonic comma  including 4:9 and 5:9
What if we decide we care about 4:9 and 5:9. To ensure that these ratios have no more than a difference of one in the numbers of tempered factors top and bottom, we must weight the 3's count by 1/2 as well. Then we look at our factorised comma and find we have weighted counts of: 2 on top and 3 on the bottom. So the bottom line wins this time and we find that the optimum distribution is to widen the 5 by 1/3 of a comma (+7.2 c) and the 2's by 1/6 of a comma each (+3.6 c).
We'll calculate the error in the minor third (5:6) as an example.
6 2 * 3  =  so the error is 5 5 (+1/6 + 0)  (+1/3) = 1/6Here are the other errors.
1:2 2:3 4:5 5:6 4:9 5:9 ratio +3.6 3.6 0.0 3.6 7.2 7.2 error in cents 3:4 5:8 3:5 ratio +7.2 +3.6 +7.2 error in centsSo a tuning with 1/6comma narrow fifths, just major thirds and 1/6 comma wide octaves is the optimum when ninths and classic minor sevenths are included (classic = 5limit).
Incidentally, the 12 note subset of meantone that has the maximum number of complete 7limit tetrads, 4:5:6:7 or 1/(7:6:5:4), looks like this on a chain of fifths. It has six tetrads, three otonal, three utonal.
Db Ab . . F C G D A E B F# . . D# A#A summary of the method
You've pretty much seen it all now. Here's the recipe:
1. First catch your comma.
2. Factorise until prime.
3. List the interval ratios you care about.
4. Prime factorise your interval ratios and eliminate any having a prime factor that does not occur amongst the comma's factors.
5. Decide whether you're willing or able to temper the octave. If not, you should ignore in what follows, all factors of 2 in your comma and your intervals.
6. Determine which primes need to have their counts weighted
so that no interval ratio has a difference of more than one between the
weighted count of tempered factors on the top and the weighted count
of tempered factors on the bottom. This must be satisfied under
either of the two possibilities regarding which factors are to be tempered;
either those on the top of the comma ratio or those on the bottom. The
most common cases are:
3:4 when 2's and 3's are on opposite sides of the comma ratio (requires
a weight of 1/2 or less on the 2's count).
4:5 when 2's and 5's are on opposite sides of the comma ratio (requires
a weight of 1/2 or less on the 2's count).
5:6 when 2's and 3's are on the same side of the comma ratio opposite
to 5 (requires that the weights for 2's and 3's sum to 1 or less).
5:8 when 2's and 5's are on the same side of the comma ratio (requires
a weight of 2/3 or less on the 2's count).
5:8 when 2's and 5's are on opposite sides of the comma ratio (requires
a weight of 1/3 or less on the 2's count).
4:9 when 2's and 3's are on opposite sides of the comma ratio (requires
a weight of 1/2 or less on the 2's count and the 3's count).
5:9 when 3's and 5's are on opposite sides of the comma ratio (requires
a weight of 1/2 or less on the 3's count).
Use the maximum weights that achieve this result for all interval ratios.
7. To determine which primes to temper, compare the weighted count of the factors on the top side of the comma ratio with the weighted count of those on the bottom side. The side with the greatest count (call it the winner) contains the primes that must be tempered to achieve the optimum error distribution. If they have equal counts you can take your pick or distribute the errors partly to both sides.
8. The amount by which to temper each of these primes is the prime's weight divided by the total weighted count of its side (i.e. the winning side). If they are on the large side (top) of the comma ratio they must be narrowed (negative errors). If they are on the small side (bottom) of the comma ratio they must be widened (positive errors).
9. Work out the error in each of the interval ratios by considering their prime factorisations. Sum the errors of the factors on the large side (top) of the interval ratio and subtract the errors of those on the small side (bottom).
The septimal kleisma 224:225
Let's look at something more exotic than the syntonic comma. The 224:225 septimal kleisma is what gets distributed in Lumma's scale (mentioned in the introduction).
225 3 * 3 * 5 * 5  =  = 7.71 c 224 2 * 2 * 2 * 2 * 2 * 7Let's say we care about the 7limit intervals 1:2, 2:3, 3:4, 4:5, 5:6, 6:7, 7:8, 3:5, 5:7, 4:7, 5:8. We are willing to temper the octave.
We must weight the 2's by 1/3 because of the 5:8. The top then has 4 factors and the bottom has 2+2/3. The top wins so we must narrow the 3's and 5's by 1/4 septimal kleisma (1.9 c). Thus the errors in the optimal case are:
1:2 2:3 4:5 5:6 4:7 5:7 6:7 0.0 1.9 1.9 0.0 0.0 +1.9 +1.9 3:4 5:8 3:5 7:8 +1.9 +1.9 0.0 0.0Since 1/4comma meantone is sometimes called quasijust with 5.4 c errors, I coined the term wafsojust (within a fly excrement of) for anything like this with errors less than about half that. I have since decided that microtempered is a more acceptable term
Here's a 7limit lattice for Lumma's scale, the 12 note subset of this tuning that has the maximum number of complete 7limit tetrads (6).
D#A# F / \ C / / \ / AEBF# / \ / \ Db/ \ Ab/ / D#\ / A#\ / \ / FCGD / \ / / B \ / F# DbAbAn exercise for the reader
Find the optimum distribution of the septimal kleisma in the 9limit case, i.e. when we care about all the ratios in the chord 4:5:6:7:9 and any inversions of them where no side of the ratio is greater than 11. We are willing to temper the octave.
If you're not sure of your answer, email me.
The small septimal comma 125:126
At last let's look at Herman Miller's small septimal comma (125:126).
126 2 * 3 * 3 * 7  =  = 13.79 c 125 5 * 5 * 5Look at the case where we're not willing or able to temper the octaves, and assume we don't need any ratios of 9. Now we find top and bottom are the same length, with 3 factors each.
When the two lines are of equal length we have an infinite number of possibilities, all having the same maximum absolute error. In this example we can have (a) 3's and 7's narrowed by 1/3 comma (4.6 c), or (b) 5's widened by 1/3 comma, or (c) 3's and 7's narrowed by 1/6 comma while 5's are widened by 1/6 comma, and all the cases in between. If one line contains a factor of 2 (and we are willing to temper the octave) we might decide to treat the other line as if it were the longest and avoid tempering the octave since it gives no benefit. We might generalise this to treat the line with the smallest prime as if it were the short line. Or you might decide that you would prefer some particular interval(s) to have zero error.
Another possibility is to use this freedom to simultaneously optimise the distribution of some other comma, such as the 384:385 small undecimal comma (4.5 c).
385 5 * 7 * 11 5^1 * 7^1 * 11^1  =  =  384 2 * 2 * 2 * 2 * 2 * 2 * 2 * 3 2^7 * 3^1But we won't consider that here.
Here are the errors for the case of distributing the 125:126 where we only widen the 5's. This gives us ratios of 9 as well (weight 3's by 1/2 and bottom line wins).
1:2 2:3 4:5 5:6 4:7 5:7 6:7 0.0 0.0 +4.6 4.6 0.0 4.6 0.0 3:4 5:8 3:5 7:8* 7:10* 7:12* * of doubtful interest 0.0 4.6 +4.6 0.0 +4.6 0.0If we are allowed to temper the octave and we don't need ratios of 9, then we must weight the 2's by 1/3 (for the 5:8) and we get that we should narrow the octave by 1/10 of a comma (1.38 c) and narrow the 3's and 7's by 3/10 of a comma (4.14 c). Max absolute error 4.14 c, slightly better than 1/4 comma meantone. So the fifths are 2/10 narrow (2.76 c), major thirds are 2/10 wide (+2.76 c) augmented sixths are 1/10 narrow (1.38 c). You can work out the others.
If we want ratios of 9, it is no longer useful to temper the octave for this comma and we are back to the case above, where we widen the 5's by 1/3 (small septimal) comma.
Here are 7limit lattices showing the two 12 note subsets of this tuning that have the maximum number of complete 7limit tetrads (5). The first is likely to be preferred since it has more otonal tetrads. However, these subsets do not support all of the scales described by Herman Miller in http://www.io.com/~hmiller/music/marrgarrel.html.
D#A# F / \ C / G / \ / BF# Db \ Ab/ \ \ / \ DAE \ / \ / \ \ / D#\ / A#\ FCG / \ / / B \ / F# DbAb D#A# F / \ C / / \ / EBF# \ Db/ \ Ab/ \ \ / \ / \ GDA \ / \ \ / D#\ A# FC / \ / E / B \ / F# DbAbI hope this has been useful.
Incidentally, all of the 12tone subsets mentioned in this document are local optima on a continuum between one particular subset of 31tET (the division of the octave into 31 equal steps) and several 7limit just scales including Fokker's 12 of 7limit. Or putting it another way, all these just and tempered scales, when mapped to the nearest steps of 31tET, result in the same subset. They are all simply different ways of trading off the number of consonances against their accuracy. In my opinion, nothing is gained in strictlyjust tunings by failing to distribute at least the 224:225 septimal kleisma. The errors introduced are less than 2 cents, which is less than the typical tuning accuracy of most nonelectronic instruments, and are a positive benefit in preventing cancellation of partials or apparent merging of individual voices (with harmonic timbres), and of course one also gains in the number of available harmonies.
Appendix
Here's step 6 in more detail:
6.1 Initialise all prime weights to 1.
6.2 First assume that the primes on the top side of the comma will be tempered.
6.2.1 Make a first pass thru the intervals, ignoring any with
more than one tempered prime on the same side (like 5:6 if 2's and 3's
are to be tempered) since they have too much freedom in assigning weights.
For each such interval:
Calculate the absolute value of the difference between the weighted
count of prime factors top and bottom.
If the difference is greater than 1, reduce the weight of the
prime with the greater weighted count just enough to make the difference
1. i.e. if Pg is the power (unweighted count) of the prime with the greater
weighted count and Wg is its current weight, and Pl and Wl similarly relate
to the one with the lesser weighted count (P1 will often be zero and Wl
undefined), then Wg := (Wl * Pl + 1)/Pg.
6.2.2 Make a second pass, this time processing the intervals
omitted in the first pass. If any of them still fail the test, make some
arbitrary decision about which prime to decrease the weight of. e.g. the
lowest prime.
6.3 Now assume that the primes on the bottom side of the comma
will be tempered.
6.3.1 (as for 6.2.1)
6.3.2 (as for 6.2.2)
Errata
Herman Miller has found a counterexample to this algorithm (in particular step 6). In the case of distributing the syntonic comma, when the only intervals of interest are 1:2, 2:3, 4:5, and we are willing to temper the octave, the optimum consists in widening the octaves by 1/7comma and narrowing the fifths by 1/7comma, which results in major thirds which are 1/7 comma wide. The above algorithm does not find this solution. The factors of 2 would need to be weighted by 1/3 to obtain this solution. I don't yet know how to fix step 6 to achieve this.