### Generalized continued fractions and equal temperament

(In which we get mathematical about strange divisions of the octave)

The question of which equal divisions of the octave give good approximations to perfect fifths is a classic application of continued fractions.

That is, if we divide the octave into n equal steps (i.e., equal frequency ratios), we want to know for which values of n will there be an m such that m steps will be a good approximation to a perfect fifth: m/n is to be a close approximation to log(3/2)/log(2) = 0.584962501. As a continued fraction, 0.584962501 = 1/(1+1/(1+1/(2+1/(2+1/(3+…))))) The convergents are

0 / 1 = 0.000000
1 / 1 = 1.000000
1 / 2 = 0.500000
3 / 5 = 0.600000
7 / 12 = 0.583333
24 / 41 = 0.585366
31 / 53 = 0.584906
179 / 306 = 0.584967

The first division of the octave giving a fairly good fifth is 12, with 7 steps making a fifth. This is the equal temperament that has been the near universal basis of tuning in western music for the past couple hundred years. You can get better approximations to a fifth if you divide the octave into larger numbers of steps, though it may be surprising how few divisions give better fifths than 12-equal. If you examine all the possibilities, a few good ones do not turn up in the convergents of the continued fraction — 17/29 = 0.586207, for instance — but not many, and nothing better than 53-equal until you go to 200-equal. From a practical point of view, at least for non electronic instruments, 12-equal is the only division that makes any sense if the only interval of interest is the fifth.

That was the case in medieval music, where fifths were considered the height of avant-garde harmony (though that was before the need for equal temperament came along in the west), but then we started making chords with both fifths and thirds. So now the question becomes, which equal divisions of the octaves give both good perfect fifths and good major thirds? (A minor third is just the difference between a perfect fifth and a major third, so if the latter two are good, the minor third should be pretty good too.) That is, we want an n such that there are integers l and m for which l/n and m/n are simultaneously good approximations to log(5/4)/log(2) and log(3/2)/log(2).

Continued fractions don’t help here, because they deal with only a single ratio at a time.  In a 1948 article called “Music and Continued Fractions” (American Mathematical Monthly, Vol. 55, p. 545), J. M. Barbour discussed the use of ternary continued fractions to address this problem.  Ternary continued fractions are pretty much what they sound like, a generalization of continued fractions whose convergents are three integers whose ratios approximate two real numbers. Then in 1950, J. B. Rosser responded with “Generalized Ternary Continued Fractions” (American Mathematical Monthly, Vol. 57, p. 528). The title is something of a misnomer because the generalization Rosser describes is to p+1 integers — not just 3 — whose ratios approximate p real numbers. Rosser boasts of calculating the first 28 sets of convergents in only three hours. Ah, the pre-computer days. Nowadays you can have a computer generate those same convergents in seconds… after you spend three hours writing the Perl script to do it.

My script’s results don’t match Rosser’s exactly, because he seems to be inconsistent about choosing alternatives in cases of equality, but the convergents are the same:

1    0    0 |   0.000000 ( -1.000000)   0.000000 ( -1.000000)
0    1    0 |
0    0    1 |
1    1    0 |   1.000000 (  2.106284)   0.000000 ( -1.000000)
1    1    1 |   1.000000 (  2.106284)   1.000000 (  0.709511)
1    0    1 |   0.000000 ( -1.000000)   1.000000 (  0.709511)
2    1    1 |   0.500000 (  0.553142)   0.500000 ( -0.145244)
3    1    2 |   0.333333 (  0.035428)   0.666667 (  0.139674)
4    1    2 |   0.250000 ( -0.223429)   0.500000 ( -0.145244)
6    2    3 |   0.333333 (  0.035428)   0.500000 ( -0.145244)
9    3    5 |   0.333333 (  0.035428)   0.555556 ( -0.050272)
7    2    4 |   0.285714 ( -0.112490)   0.571429 ( -0.023136)
12    4    7 |   0.333333 (  0.035428)   0.583333 ( -0.002785)
19    6   11 |   0.315789 ( -0.019068)   0.578947 ( -0.010283)
22    7   13 |   0.318182 ( -0.011637)   0.590909 (  0.010166)
34   11   20 |   0.323529 (  0.004974)   0.588235 (  0.005595)
31   10   18 |   0.322581 (  0.002027)   0.580645 ( -0.007381)
53   17   31 |   0.320755 ( -0.003645)   0.584906 ( -0.000097)
65   21   38 |   0.323077 (  0.003569)   0.584615 ( -0.000593)
87   28   51 |   0.321839 ( -0.000277)   0.586207 (  0.002127)
152   49   89 |   0.322368 (  0.001368)   0.585526 (  0.000964)
118   38   69 |   0.322034 (  0.000329)   0.584746 ( -0.000371)
205   66  120 |   0.321951 (  0.000072)   0.585366 (  0.000690)

and so on. The convergents are on the left, with the number corresponding to the octave listed first, and on the right are the ratios of the second and third numbers to the first along with the differences between these and log(5/4)/log(2) = 0.321928 and log(3/2)/log(2) = 0.584963.This gives, for example, the familiar 12-equal scale with 4 and 7 steps making major thirds and perfect fifths, respectively, and the 53-equal scale turns up here again, with 17 and 31 steps for the major third and perfect fifth, but note that there are several divisions in between where the fifths are not quite as good but the thirds make the division worth thinking about. Indeed, the 19-equal division of the octave, in which the major third and perfect fifth are 6 and 11 steps, is almost exactly 1/3 comma meantone temperament, and the 16th century theorists Guillaume Costeley and Francisco de Salinas advocated use of 19 notes to the octave in this temperament. It’s almost practical for keyboard instruments, though a 19-tone clarinet would be a scary thing to contemplate.

One thing to notice is that, unlike the convergents of ordinary continued fractions, these do not always increase.  34-equal turns up before 31-equal, for instance.

Of course, once you have the Perl script, you can turn it loose on other problems. For instance: we said if you take care of the fifths and major thirds, the minor thirds should more or less take care of themselves. Is that true? Suppose we demand both?

1    0    0    0 |   0.000000 ( -1.000000)   0.000000 ( -1.000000)   0.000000 ( -1.000000)
0    1    0    0 |
0    0    1    0 |
0    0    0    1 |
1    1    0    0 |   1.000000 (  2.801784)   0.000000 ( -1.000000)   0.000000 ( -1.000000)
1    1    1    0 |   1.000000 (  2.801784)   1.000000 (  2.106284)   0.000000 ( -1.000000)
1    1    1    1 |   1.000000 (  2.801784)   1.000000 (  2.106284)   1.000000 (  0.709511)
1    0    1    0 |   0.000000 ( -1.000000)   1.000000 (  2.106284)   0.000000 ( -1.000000)
1    0    1    1 |   0.000000 ( -1.000000)   1.000000 (  2.106284)   1.000000 (  0.709511)
1    0    0    1 |   0.000000 ( -1.000000)   0.000000 ( -1.000000)   1.000000 (  0.709511)
2    1    1    2 |   0.500000 (  0.900892)   0.500000 (  0.553142)   1.000000 (  0.709511)
3    1    1    2 |   0.333333 (  0.267261)   0.333333 (  0.035428)   0.666667 (  0.139674)
2    0    1    1 |   0.000000 ( -1.000000)   0.500000 (  0.553142)   0.500000 ( -0.145244)
4    1    1    2 |   0.250000 ( -0.049554)   0.250000 ( -0.223429)   0.500000 ( -0.145244)
3    0    1    2 |   0.000000 ( -1.000000)   0.333333 (  0.035428)   0.666667 (  0.139674)
7    1    2    4 |   0.142857 ( -0.456888)   0.285714 ( -0.112490)   0.571429 ( -0.023136)
5    1    2    3 |   0.200000 ( -0.239643)   0.400000 (  0.242513)   0.600000 (  0.025707)
10    2    3    6 |   0.200000 ( -0.239643)   0.300000 ( -0.068115)   0.600000 (  0.025707)
9    2    3    5 |   0.222222 ( -0.155159)   0.333333 (  0.035428)   0.555556 ( -0.050272)
14    3    4    8 |   0.214286 ( -0.185332)   0.285714 ( -0.112490)   0.571429 ( -0.023136)
17    4    5   10 |   0.235294 ( -0.105463)   0.294118 ( -0.086387)   0.588235 (  0.005595)
12    3    4    7 |   0.250000 ( -0.049554)   0.333333 (  0.035428)   0.583333 ( -0.002785)
29    7    9   17 |   0.241379 ( -0.082328)   0.310345 ( -0.035981)   0.586207 (  0.002127)
7    2    2    4 |   0.285714 (  0.086224)   0.285714 ( -0.112490)   0.571429 ( -0.023136)

The ordering here becomes pretty wacky. In fact, let’s sort on the first column instead of looking at the convergents in the order they’re generated. Of course we’ll miss some that are generated later. The other thing is that it takes a while to get to going, so we have to look at, say, 50 convergents to get all the ones less than 100:

1    0    0    0 |   0.000000 ( -1.000000)   0.000000 ( -1.000000)   0.000000 ( -1.000000)
1    0    0    1 |   0.000000 ( -1.000000)   0.000000 ( -1.000000)   1.000000 (  0.709511)
1    0    1    0 |   0.000000 ( -1.000000)   1.000000 (  2.106284)   0.000000 ( -1.000000)
1    0    1    1 |   0.000000 ( -1.000000)   1.000000 (  2.106284)   1.000000 (  0.709511)
1    1    0    0 |   1.000000 (  2.801784)   0.000000 ( -1.000000)   0.000000 ( -1.000000)
1    1    1    0 |   1.000000 (  2.801784)   1.000000 (  2.106284)   0.000000 ( -1.000000)
1    1    1    1 |   1.000000 (  2.801784)   1.000000 (  2.106284)   1.000000 (  0.709511)
2    0    1    1 |   0.000000 ( -1.000000)   0.500000 (  0.553142)   0.500000 ( -0.145244)
2    1    1    2 |   0.500000 (  0.900892)   0.500000 (  0.553142)   1.000000 (  0.709511)
3    0    1    2 |   0.000000 ( -1.000000)   0.333333 (  0.035428)   0.666667 (  0.139674)
3    1    1    2 |   0.333333 (  0.267261)   0.333333 (  0.035428)   0.666667 (  0.139674)
4    1    1    2 |   0.250000 ( -0.049554)   0.250000 ( -0.223429)   0.500000 ( -0.145244)
5    1    2    3 |   0.200000 ( -0.239643)   0.400000 (  0.242513)   0.600000 (  0.025707)
7    1    2    4 |   0.142857 ( -0.456888)   0.285714 ( -0.112490)   0.571429 ( -0.023136)
7    2    2    4 |   0.285714 (  0.086224)   0.285714 ( -0.112490)   0.571429 ( -0.023136)
9    2    3    5 |   0.222222 ( -0.155159)   0.333333 (  0.035428)   0.555556 ( -0.050272)
10    2    3    6 |   0.200000 ( -0.239643)   0.300000 ( -0.068115)   0.600000 (  0.025707)
12    3    4    7 |   0.250000 ( -0.049554)   0.333333 (  0.035428)   0.583333 ( -0.002785)
14    3    4    8 |   0.214286 ( -0.185332)   0.285714 ( -0.112490)   0.571429 ( -0.023136)
15    4    5    9 |   0.266667 (  0.013809)   0.333333 (  0.035428)   0.600000 (  0.025707)
17    4    5   10 |   0.235294 ( -0.105463)   0.294118 ( -0.086387)   0.588235 (  0.005595)
19    5    6   11 |   0.263158 (  0.000469)   0.315789 ( -0.019068)   0.578947 ( -0.010283)
29    7    9   17 |   0.241379 ( -0.082328)   0.310345 ( -0.035981)   0.586207 (  0.002127)
31    8   10   18 |   0.258065 ( -0.018894)   0.322581 (  0.002027)   0.580645 ( -0.007381)
32    8   10   19 |   0.250000 ( -0.049554)   0.312500 ( -0.029286)   0.593750 (  0.015022)
34    9   11   20 |   0.264706 (  0.006355)   0.323529 (  0.004974)   0.588235 (  0.005595)
35    9   11   21 |   0.257143 ( -0.022398)   0.314286 ( -0.023739)   0.600000 (  0.025707)
53   14   17   31 |   0.264151 (  0.004245)   0.320755 ( -0.003645)   0.584906 ( -0.000097)
54   14   17   32 |   0.259259 ( -0.014352)   0.314815 ( -0.022096)   0.592593 (  0.013044)
65   17   21   38 |   0.261538 ( -0.005687)   0.323077 (  0.003569)   0.584615 ( -0.000593)
66   17   21   39 |   0.257576 ( -0.020753)   0.318182 ( -0.011637)   0.590909 (  0.010166)
81   21   26   48 |   0.259259 ( -0.014352)   0.320988 ( -0.002921)   0.592593 (  0.013044)
100   26   32   59 |   0.260000 ( -0.011536)   0.320000 ( -0.005989)   0.590000 (  0.008612)
112   29   36   66 |   0.258929 ( -0.015609)   0.321429 ( -0.001552)   0.589286 (  0.007391)
131   34   42   77 |   0.259542 ( -0.013277)   0.320611 ( -0.004092)   0.587786 (  0.004827)
162   42   52   95 |   0.259259 ( -0.014352)   0.320988 ( -0.002921)   0.586420 (  0.002491)
181   47   58  106 |   0.259669 ( -0.012796)   0.320442 ( -0.004616)   0.585635 (  0.001150)
215   56   69  126 |   0.260465 ( -0.009768)   0.320930 ( -0.003100)   0.586047 (  0.001853)
234   61   75  137 |   0.260684 ( -0.008937)   0.320513 ( -0.004396)   0.585470 (  0.000868)
299   78   96  175 |   0.260870 ( -0.008230)   0.321070 ( -0.002665)   0.585284 (  0.000550)
333   87  107  195 |   0.261261 ( -0.006741)   0.321321 ( -0.001885)   0.585586 (  0.001065)
352   92  113  206 |   0.261364 ( -0.006352)   0.321023 ( -0.002812)   0.585227 (  0.000453)
386  101  124  226 |   0.261658 ( -0.005233)   0.321244 ( -0.002126)   0.585492 (  0.000906)
420  110  135  246 |   0.261905 ( -0.004295)   0.321429 ( -0.001552)   0.585714 (  0.001285)
454  119  146  266 |   0.262115 ( -0.003497)   0.321586 ( -0.001063)   0.585903 (  0.001608)
519  136  167  304 |   0.262042 ( -0.003771)   0.321773 ( -0.000483)   0.585742 (  0.001332)
572  150  184  335 |   0.262238 ( -0.003029)   0.321678 ( -0.000776)   0.585664 (  0.001200)
606  159  195  355 |   0.262376 ( -0.002502)   0.321782 ( -0.000453)   0.585809 (  0.001446)

There are a lot of poorer approximations here, but pretty much the same good ones as before.

Now suppose we want to add 7-limit intervals to the story. We’ll use 4 real numbers: log(2), log(5/4), log(3/2), and log(7/4). The first 40 convergents, sorted, are

1    0    0    0 |   0.000000 ( -1.000000)   0.000000 ( -1.000000)   0.000000 ( -1.000000)
1    0    0    1 |   0.000000 ( -1.000000)   0.000000 ( -1.000000)   1.000000 (  0.238613)
1    0    1    0 |   0.000000 ( -1.000000)   1.000000 (  0.709511)   0.000000 ( -1.000000)
1    0    1    1 |   0.000000 ( -1.000000)   1.000000 (  0.709511)   1.000000 (  0.238613)
1    1    0    0 |   1.000000 (  2.106284)   0.000000 ( -1.000000)   0.000000 ( -1.000000)
1    1    1    0 |   1.000000 (  2.106284)   1.000000 (  0.709511)   0.000000 ( -1.000000)
1    1    1    1 |   1.000000 (  2.106284)   1.000000 (  0.709511)   1.000000 (  0.238613)
2    1    1    1 |   0.500000 (  0.553142)   0.500000 ( -0.145244)   0.500000 ( -0.380694)
2    1    1    2 |   0.500000 (  0.553142)   0.500000 ( -0.145244)   1.000000 (  0.238613)
3    1    1    2 |   0.333333 (  0.035428)   0.333333 ( -0.430163)   0.666667 ( -0.174258)
3    1    2    2 |   0.333333 (  0.035428)   0.666667 (  0.139674)   0.666667 ( -0.174258)
3    1    2    3 |   0.333333 (  0.035428)   0.666667 (  0.139674)   1.000000 (  0.238613)
4    1    2    3 |   0.250000 ( -0.223429)   0.500000 ( -0.145244)   0.750000 ( -0.071041)
5    2    3    4 |   0.400000 (  0.242513)   0.600000 (  0.025707)   0.800000 ( -0.009110)
6    2    4    5 |   0.333333 (  0.035428)   0.666667 (  0.139674)   0.833333 (  0.032177)
7    2    4    6 |   0.285714 ( -0.112490)   0.571429 ( -0.023136)   0.857143 (  0.061668)
9    3    5    7 |   0.333333 (  0.035428)   0.555556 ( -0.050272)   0.777778 ( -0.036635)
10    3    6    8 |   0.300000 ( -0.068115)   0.600000 (  0.025707)   0.800000 ( -0.009110)
12    4    7   10 |   0.333333 (  0.035428)   0.583333 ( -0.002785)   0.833333 (  0.032177)
15    5    9   12 |   0.333333 (  0.035428)   0.600000 (  0.025707)   0.800000 ( -0.009110)
19    6   11   15 |   0.315789 ( -0.019068)   0.578947 ( -0.010283)   0.789474 ( -0.022148)
22    7   13   18 |   0.318182 ( -0.011637)   0.590909 (  0.010166)   0.818182 (  0.013410)
31   10   18   25 |   0.322581 (  0.002027)   0.580645 ( -0.007381)   0.806452 ( -0.001119)
37   12   22   30 |   0.324324 (  0.007443)   0.594595 (  0.016466)   0.810811 (  0.004281)
41   13   24   33 |   0.317073 ( -0.015081)   0.585366 (  0.000690)   0.804878 ( -0.003068)
53   17   31   43 |   0.320755 ( -0.003645)   0.584906 ( -0.000097)   0.811321 (  0.004912)
68   22   40   55 |   0.323529 (  0.004974)   0.588235 (  0.005595)   0.808824 (  0.001819)
99   32   58   80 |   0.323232 (  0.004051)   0.585859 (  0.001532)   0.808081 (  0.000899)
109   35   64   88 |   0.321101 ( -0.002569)   0.587156 (  0.003750)   0.807339 ( -0.000019)
140   45   82  113 |   0.321429 ( -0.001552)   0.585714 (  0.001285)   0.807143 ( -0.000263)
162   52   95  131 |   0.320988 ( -0.002921)   0.586420 (  0.002491)   0.808642 (  0.001594)
171   55  100  138 |   0.321637 ( -0.000903)   0.584795 ( -0.000286)   0.807018 ( -0.000418)
230   74  135  186 |   0.321739 ( -0.000587)   0.586957 (  0.003409)   0.808696 (  0.001661)
261   84  153  211 |   0.321839 ( -0.000277)   0.586207 (  0.002127)   0.808429 (  0.001331)
270   87  158  218 |   0.322222 (  0.000914)   0.585185 (  0.000381)   0.807407 (  0.000065)
292   94  171  236 |   0.321918 ( -0.000032)   0.585616 (  0.001118)   0.808219 (  0.001070)
323  104  189  261 |   0.321981 (  0.000166)   0.585139 (  0.000302)   0.808050 (  0.000860)
354  114  207  286 |   0.322034 (  0.000329)   0.584746 ( -0.000371)   0.807910 (  0.000687)

One of the first good possibilities here is 22-equal, which is for example used by Ehrlich as a basis for his decatonic 7-limit scales.

And now suppose instead of equal divisions of the octave giving good approximations to frequency ratios of 5/4 and 3/2, what if you want equal divisions of the “tritave” (frequency ratio 3/1) with good approximations to 7/3 and 5/3? Those frequency ratios underlie Bohlen-Pierce scales, and with Rosser’s algorithm we get (after several uninteresting rows, and here I haven’t sorted):

9    4    7 |   0.444444 ( -0.044151)   0.777778 (  0.008472)
15    7   12 |   0.466667 (  0.003641)   0.800000 (  0.037286)
19    9   15 |   0.473684 (  0.018734)   0.789474 (  0.023637)
13    6   10 |   0.461538 ( -0.007388)   0.769231 ( -0.002610)
23   11   18 |   0.478261 (  0.028577)   0.782609 (  0.014736)
36   17   28 |   0.472222 (  0.015589)   0.777778 (  0.008472)
40   19   31 |   0.475000 (  0.021564)   0.775000 (  0.004870)
53   25   41 |   0.471698 (  0.014462)   0.773585 (  0.003036)
49   23   38 |   0.469388 (  0.009494)   0.775510 (  0.005532)

You can see the 13-equal division is quite good, and this is the division most often used for Bohlen-Pierce. Interestingly, 53-equal division comes up again as a good one — but 53-equal division of the tritave this time, remember. Nothing between 13 and 53 is really any better than 13 from this point of view.

Here’s another question: suppose you want a division of the octave giving both perfect fifths and neutral thirds. The latter is something midway between a major and a minor third, and 11/9 is a good representation of it. So the ratios of interest are log(11/9)/log(2) and log(3/2)/log(2), and some convergents (again unsorted) are:

8    2    5 |   0.250000 ( -0.136462)   0.625000 (  0.068445)
15    4    9 |   0.266667 ( -0.078893)   0.600000 (  0.025707)
18    5   11 |   0.277778 ( -0.040513)   0.611111 (  0.044701)
10    3    6 |   0.300000 (  0.036246)   0.600000 (  0.025707)
25    7   15 |   0.280000 ( -0.032837)   0.600000 (  0.025707)
32    9   19 |   0.281250 ( -0.028520)   0.593750 (  0.015022)
42   12   25 |   0.285714 ( -0.013099)   0.595238 (  0.017566)
49   14   29 |   0.285714 ( -0.013099)   0.591837 (  0.011752)
17    5   10 |   0.294118 (  0.015927)   0.588235 (  0.005595)
66   19   39 |   0.287879 ( -0.005623)   0.590909 (  0.010166)
73   21   43 |   0.287671 ( -0.006340)   0.589041 (  0.006972)
80   23   47 |   0.287500 ( -0.006931)   0.587500 (  0.004338)
97   28   57 |   0.288660 ( -0.002925)   0.587629 (  0.004558)
104   30   61 |   0.288462 ( -0.003610)   0.586538 (  0.002694)
111   32   65 |   0.288288 ( -0.004208)   0.585586 (  0.001065)
24    7   14 |   0.291667 (  0.007461)   0.583333 ( -0.002785)
128   37   75 |   0.289062 ( -0.001534)   0.585938 (  0.001667)
135   39   79 |   0.288889 ( -0.002134)   0.585185 (  0.000381)

It’s not surprising, really, that 24-equal is a good candidate (since 12-equal has good fifths, and major and minor thirds a step apart) though it is surprising how late it turns up. Arguably there is nothing better before 111-equal.