# Fifty Shades of J/Chapter 47

Musical J-ers

### Principal Topics

\: (grade down) ~ (passive) \ (infix) tonic, dominant, octave, intervals, clock arithmetic, circle of fifths, celestial harmonies, 12 note chromatic scale, diatonic scale, Pythagorean tuning, just intonation, mean tone temperament, equal temperament, cents, Pythagorean comma, Wolf fifth. syntonic comma, frequencies.

Every now and then when struggling with some abstruse aspects of a technical subject, I get the feeling that it would have been so helpful if the experts and specialists had told me about it in J. One such area is that of temperament in music, and what follows is my attempt to make that case for using J to enlighten things in this field.

To start at the beginning, Pythagoras, he of the hypotenuse, also had strong ideas about music. He realised that a vibrating string when suddenly stopped at its middle point produces a note melodically identical to the original, only, in modern terminology, an octave higher. Call the melodic value of both these notes the tonic, so that advancing an octave allows us to βlistenβ to the fraction 1/2. If the string is now stopped its 2/3 point the result is another note called the dominant which, when sounded at the same time as the tonic, produces a pleasant sound combination.

### Simple fractions sound nice

From this starting point two separate experiments proceed. In the first the string is stopped at other fractional points with small integer numerators and denominators. Since the octave represents a full melodic circle which is repeated at 1/4 then 1/8 and so on, there is little point in considering stops other than those which lie between 1/2 and 1. The next βinterestingβ stop is thus at 3/4, followed by others at 3/5, 4/5 and 5/6. At this point all fractions with components of 6 or less have been exhausted, and in all cases pleasing sound combinations with the tonic are obtained. This experiment has incidentally provided a means of βhearingβ the following range of fractions : 1/2 2/3 3/4 4/5 5/6 which are defined by the hook

```    (%>:)1 2 3 4 5    NB. octave, 5th, 4th, 3rd, minor 3rd
0.5 0.667 0.75 0.8 0.833```

annotated above with intervals names which describe distances from the tonic. It is important to distinguish between notes and intervals, which is akin to observing the gaps in the fence rather than the fence posts. The piano tuner tweaks strings and the organ tuner adjusts pipes to produce notes, but what the listener hears is primarily intervals.

Advancing to higher integers in the above sequence, any fraction involving a 7, that is 4/7, 5/7, 6/7 and 7/8 produces distinctly unpleasant sound combinations. As for 8s, there is just one ratio which has not been investigated, namely 5/8 which also sounds nice and corresponds to the interval called a minor third. All of the intervals 1/2 2/3 3/4 3/5 4/5 5/6 5/8 are "pure" in the sense that they can be related to pleasant sounds which arise from the physical properties embodied in a bowed string, or resonating pipe.

### Calculating a circle of fifths

The second experiment involves intervals rather than notes, and consists of finding where the stop should be for the dominant of the dominant. The βobviousβ answer is 2/3 of 2/3 = 4/9, but this is outside the range 1/2 to 1. However, the first experiment showed that doubling the fraction lowers the note by an octave but makes no difference to its melodic quality of the note, so make the second stop position at 8/9. Then repeat the experiment to find the dominant of the dominant of the dominant at 2/3 of 8/9 = 16/27 which does not need doubling since it is already in the range 1/2. To continue this process use J to develop a compound verb "multiply-by-2/3-and-double-if-outside-1/2-to-1". This situation is reminiscent of clock arithmetic as practised in the early stages of primary school. For example in arithmetic modulo 5 adding 4 and 2 makes 1, multiplying 4 and 2 makes 3, notions which are captured in J by

```   cadd=.5&|@+         NB. clock add
1
cmult=.5&|@*        NB. clock multiply
4 cmult 2
3```

The whole infinite gamut of integers is thereby compressed into the set {0,1,2,3,4}. Another example of compressing an infinite into a finite one is the expression of numbers in scientific notation. Using logarithms, the fine detail of a real number is compressed into the range 1 (inclusive) to 10 (non-inclusive), while the exponent defines the wider territory within which the number lies. Again J can explain how to do this. If a number is expressed as v e x then

```   x=.<.@(10&^.)       NB. exponent
x 2675
3
v=.%10&^@x          NB. value
v 2675
2.675```

In pictorial terms v compresses numbers into the space

```     ββββββββββββββββ
10β°            10ΒΉ```

Now return to the musical experiment with its βspecialβ multiplication in which e.g. (2/3)2 = 8/9, so that the result always remains in the range 1/2 to 1. This compression region can be drawn as

```     ββββββββββββββββ
2β»ΒΉ            2β°```

β call the process "musical arithmetic"β which helps write the analogous verbs

```   x2=.<.@>:@(2&^.)
x2 1r8 2r3 4r9        NB. 2-exponent
_2 0 _1
v2=.%2&^@x2        NB. value
v2 1r8 2r3 4r9
0.5 0.666667 0.888889```

In musical arithmetic the "nice" sounds as defined above, (or as Pythagoras would have more grandiosely called them "celestial harmonies") are inverses according to the following plan :

2/3 : fifth 1/(2/3) = 3/4 fourth
4/5 : major third 1/(4/5) = 5/8 minor sixth
3/5 : major sixth 1/(3/5) = 5/6 minor third

So applying the power conjunction to the βmusical multiplicationβ verb to extend the Pythagorean progression of fifths :

```   v2 2r3^>:i.12        NB. successive fifths
0.667 0.889 0.593 0.79 0.527 0.702
0.936 0.624 0.832 0.555 0.74 0.987```

After twelve applications, a value 0.987, is obtained which is not too far from 1 representing the tonic. Given that the numerators are powers of 2 and the denominators are powers of 3, there can never be any question of solving (2/3)k = 1/2 exactly, and so it is reasonably satisfying to get as close as 0.987/2 in twelve steps. Musically this means that jumping by intervals of a fifth twelve times take us through a cycle of sounds which then repeats itself after an adjustment to make the octave pure. The natural place to make this adjustment is at the final step, but it could be made at any intermediate step or indeed spread across several steps. The above series is related to the familiar notes on a piano keyboard as follows

```   v2 2r3^>:i.12    NB. progression of fifths
0.667 0.889 0.593 0.79 0.527 0.702 0.936 0.624 0.832 0.555 0.74 0.987
G     D     A     E    B     F#    C#    G#    D#    A#    F    C```

The experiment is not over yet because the next question is what would happen if the above exercise was repeated for 3/4 rather than 2/3. The primary interval in this case is called a fourth, and the result is

```   v2 3r4^>:i.12    NB. progression of fourths
0.75 0.563 0.844 0.633 0.949 0.712 0.534 0.801 0.601 0.901 0.676 0.507
F    Bb    Eb    Ab    Db    F#    B     E     A     D     G     C```

that is, the same notes only in reverse order, and finishing on the low octave, value 1/2, rather than the high octave at 1.

The twelve notes thus identified comprise the 12-note chromatic scale which has underpinned most Western music since around 1600. However, the first of the above lists shows that if the stop positions on the string are obtained by successive fifths (a scheme which is called Pythagorean tuning, although Pythagoras himself would only have recognised the first few steps), then by the time F comes round its value will be slightly different from the βpureβ value of 3/4. Likewise the second list shows that tuning by successive fourths G will also be a shade impure. Similar considerations apply to the other notes, which in turn means that the intervals will differ from the intervals identified in the first experiment. More importantly, the adjustment noted above which is needed to make the octave pure at the twelfth and final step is called a comma, or more specifically a Pythagorean comma, and sometimes again the comma of Didymus.

### The Problem of D

So far six of the eight notes of the diatonic scale (that is the white notes on the piano in the scale of C) have been given places in the scheme of things, the two remaining being D and B. Since these are symmetrically placed at either end of the octave, a discussion of one is automatically a discussion of the other, so focus on D. D is not consonant with C, so there is no physical βrightβ fraction for it, rather there are two candidates. The first comes from considering the fact that D is one whole tone removed from C, and there is already a whole tone represented, namely F β G, whose ratio is (2/3) / (3/4) = 8/9. The second candidate arises from the fact that in order to make D β A a pure fifth D must be set at (3/5) / (2/3) = 9/10. (A harpsichord with two such D keys was in fact built in Holland in 1639, but did not prove particularly popular for obvious reasons!) The diagram below shows D set to 8/9, and 9/16 as the symmetrical consistent choice for B which makes high C equal to 8/9th of B.

```   1/2  9/16   3/5   5/8    2/3   3/4   4/5   5/6   (8/9)  1
0.5  0.567  0.6  0.675  0.667  0.75  0.8  0.833 (0.889) 1
C    B      A     G#     G     F     E     Eb    (D)   C```

### The Note in the middle

A full octave in the chromatic scale (that is including two tonics) has 13 notes, and thus 12 intervals, and a middle note, namely F#. Where does it appear in the above table? The answer is that it doesn't because βhalf-wayβ on a multiplicative scale means the position 1/β2, so playing the interval C β F# on the piano is a way of hearing the square root of 2! Moreover a glance at the progression series above shows that under musical multiplication both (2/3)6 and (3/4)6 are approximations to 1/β2, one being about 0.005 above and the other the same amount below. On either side of the middle, interval of a fifth, C β G, consists of seven semi-tones, whereas a fourth, C β F, consists of five semitones in which respect fifths and fourths are mirror images of each other, explaining incidentally why each of the two progression series is the reverse of the other.

The following is another copy of the 1/2 to 1 region in which the fractions are labelled with interval names rather than notes (dim stands for "diminished")

```  1/2  9/16  3/5    5/8    2/3   3/4  4/5    5/6    8/9  1
C    B     A     G#      G     F    E     Eb      D   C
oct  7th   6th  dim 6th  5th  4th   3rd  dim 3rd  2nd```

Under this scheme the whole tones D β E and G β A have values (4/5) / (8/9) and (3/5) / (2/3), both of which are equal to 9/10, which was the alternative candidate for D. This means that there are two types of whole tone in this scale, so that, for example, the first three notes of βThree Blind Miceβ become a melodic progression of unequal steps. Also the ratios for the main consonant intervals, obtained by dividing the value of the second note by that of the first, are

```      perfect fifths       major sixths    major third
F-C  G-D   D-A   A-E      F-D   G-E         F-A
2/3  2/3  27/40  2/3     16/27  3/5         4/5```

The values of 2/3, 4/5 and 3/5 are consistent with those for the tonic C, but clearly compromises must be made on account of the introduction of D which would need to be 9/10 to make D - A a pure fifth. Similarly in the key of G# the major third is G# β C, ratio 1/(5/8) = 4/5 and the fifth is G# β Eb = (5/6) / (5/8) = 2/3 both of which are pure. However, in the key of E the major third E β G# has the ratio (5/8)/(4/5) = 25/32 or 0.781 which is just a touch impure. And so one could go on. Once a set of strings is tuned for pure concordances in key C, compromises must be made, not just for melodies and harmonies in the key of C, but also for melodies played in other keys. How best to make such compromises has engaged the minds of musicians since medieval times, and is the subject of a fascinating little book called "Temperament - the idea that solved Music's Greatest Riddle" by Stuart Isacoff. (The word "temperament" was first used in this context round about 1500, and means, according to Chambers "a system of compromise in tuning".) The history of the debates on temperament is complex; but broadly, the D problem gave rise to two solution streams, one called just intonation which tolerated differences in whole tone values as a price worth paying for purity of major thirds, the other called mean tone temperament which is based on making whole tones uniform. βJustβ should be thought of as being derived from βadjustmentβ, of which there has already been hints in the preceding section. The notion of making adjustments to organ pipes or strings on keyboards may well date as early as the late 14th century, and it is important to bear in mind that Renaissance instruments were much less full-blooded than their modern counterparts, so that both players and listeners would have been more sensitive to variations in tuning than audiences are today.

### Equal Temperament

In the mid 16th century the concept of the equal-tempered scale emerged in which each of the twelve semi-tone intervals are equal on a multiplicative scale. This has the merit that music can be freely transposed into other keys, but at a cost of losing the βpurityβ of the Pythagorean ratios in any key. On the other hand tuning for Pythagorean perfection in, say, the key of C, means that transposing outwards to remote keys on the circle of fifths results in increasingly unpleasant harmonies. Equal temperament tuning first found favour among lute players for whom other forms of tuning necessitated the undesirable feature of having frets at unequal distances for different strings. Again, J can clarify and quantify what musicians and musical historians mean when they talk about this topic. In an equal-tempered system (and also a well-tempered system which is a subtly different but more sophisticated variation of it), the common ratio of the series of semi-tone values must be the twelfth root of 2, and so the stop ratios going up the scale are given by

```   ]r=.2^-%12    NB. r is 1/12th root of 2
0.944
r^i.13
1 0.944 0.891 0.841 0.794
0.749 0.707 0.667 0.63 0.595 0.561 0.53 0.5```

The following series is the corresponding ordered version of the ratios for Pythagorean tuning :

```   \:~1, v2 2r3^i.12    NB. equal-tempered stop positions
1 0.936 0.889 0.832 0.79 0.74 0.702 0.667 0.624 0.593 0.555 0.527 0.5```

For the purposes of comparing tuning systems it is useful to convert from a multiplicative scale ranging from 1 to 1/2 going up the scale to a.n additive one from 0 to 1200 in which each semitone interval is represented by 100 in an equal-temperament system. Pictorially this conversion is

```    ββββββββββββββββββββββββββββββ
2-1     2-(1/2)   2-(1/12)    20
to:
ββββββββββββββββββββββββββββββ
1200      600      100       0
```

Musicians call the unit which divides an octave into 1200 parts a cent, and J readily provides the means of conversion

```   cent=.1200&*@(2&^.)@%      NB. convert stop positions to cents
cent %12 4 3 2 1.5%:2      NB. equal tempered C# Eb F F# G#
100 300 400 600 800
cent r^i.13                NB. 12-tone equal-tempered scale
0 100 200 300 400 500 600 700 800 900 1000 1100 1200```

It is informative to see how Pythagorean tuning measures up on a cent scale. First observe the cent values of pure fifths, thirds and sixths which are respectively :

```   rnd=.<.@(0.5&+)              NB. round to nearest integer
rnd cent v2 2r3 4r5 3r5         NB. 5ths, maj 3rds. 6ths.
702 386 884```

The values of the three complementary intervals in the diatonic scale (fourths, minor sixths and minor thirds) are just 1200 minus these values, as confirmed by

```   rnd cent v2 3r4 5r8 5r6         NB. 4ths, min 3rds. 6ths.
498 814 316```

Next establish the cent values of all twelve points on the Pythagorean chromatic scale

```   rnd cent \:~v2 2r3^i.13     NB. Pyth tuning to cents
23 114 204 318 408 522 612 702 816 906 1020 1110 1200
C  C#  D   Eb  E   F   F#  G   G#  A   Bb    B    C```

The initial value of 23 represents the comma, that is the extent to which tuning by repeated fifths βmisses"β the octave whose purity in any tuning system is sacrosanct. Since an octave is also the sum of three major thirds and of four minor thirds, there are also discrepancies in these of 1200 β (3x386.6) = 41 below and (4x316) - 1200 = 63 above respectively, which are also commas of a sort, although the unqualified use of βcommaβ means the measure of around 23 cents. This comma is incidentally also the interval by which the fourth C - F is impure within a well-tempered system.

The sequence of fifths in the row above, that is C, G, D, A, E etc., shows a progressive overshoot of 2 cents at each step cumulating into the comma which, if corrected at the final step, requires this step to be curtailed to 702-23 = 679 cents. Two notes at this interval produce a discordant sound known since mediaeval times as the wolf fifth, presumably because of its supposed likeness to the braying of a wolf.

Another way of looking at the last row of figures above is to calculate their differences :

```    2-~/\0 114 204 318 408 522 612 702 816 906 1020 1110 1200
114 90 114 90 114 90 90 114 90 114 90 90
C      D      E   F     G      A      B  C```

This shows that every semitone is worth one of two values, namely 90 cents or 114 cents. If now the two semi-tones in the diatonic scale (that is the C scale without any black notes) are equalised at 90 by interchanging the 114 and 90 between E and F#, then the five whole tones in the diatonic scale are also equalised at 204 cents. (5x204) + (2x90) = 1200, which confirms the purity of the octave. The difference of 12 cents between some semitones and others is perceptible only to the most highly trained ears.

As an aside, it might be supposed that since fourths are the mirror images of fifths that tuning by successive fourths would be broadly similar. Try it on the computer, but not on your piano !

```   rnd cent \:~v2 3r4^i.13
90 180 294 384 498 588 678 792 882 996 1086 1177 1200```

### Just Intonation

Just intonation systems are based on the notion that the major third is somehow a more "beautiful" consonance than the "fifth" (think of songs in which soprano and alto voices proceed in a blend in parallel thirds). Some form of this may have been in the mind of Ptolemy in the second century A.D., hence the occasional use of the term Ptolemaic tuning as a synonym. The starting point is that the Pythagorean system has a major disadvantage in that the major thirds (C - E, F - A and G - B) all have values of 408 cents whereas purity requires that they should have a value of

```   cent v2 4r5    NB. size of equal-tempered major third
386.3```

One way around this is to accept D as 204 cents as above, corresponding to a harmonic value of 8/9, but make the next tone D - E equal to 386 - 204 = 182 cents, a reduction of a comma. Reducing the interval G - A by the same amount simultaneously adjusts both the F β A and G β B thirds to the pure value of 386. This leaves the two diatonic semitones to take up the slack of 44 so each becomes 90 + 22 = 112. Now consider the chromatic notes. D β F# is currently 182 + 112 + 114 = 408, in excess by a comma. Switching the semi-tone values between F and G, and changing them slightly from 114/90 to 112/92 makes D β F# pure, as are also F# - A and G# - B. This little bit of ingenuity leads to the scheme

```   ]just=.92 112;90 92;112;92 112;92 90;112 92;112
ββββββββ¬ββββββ¬ββββ¬βββββββ¬ββββββ¬βββββββ¬ββββ
β92 112β90 92β112β92 112β92 90β112 92β112β
ββββββββ΄ββββββ΄ββββ΄βββββββ΄ββββββ΄βββββββ΄ββββ
D     E   F      G     A      B   C```

It is now possible to use J to observe the effects of this particular just tuning on all the principal intervals based on different starting notes :

```   2+/\13\$;just    NB. tones
204 202 182 204 204 204 204 182 202 204 204 204
C   C#  D   Eb  E   F   F#  G   G#  A   Bb    B
7+/\18\$;just    NB. fifths
702 702 680 702 702 702 702 702 700 702 702 702
4+/\15\$;just    NB. major thirds
386 406 386 408 408 386 406 386 406 408 408 406
9+/\20\$;just    NB. sixths
884 904 884 906 906 906 904 884 904 906 906 906```

Other theorists had different ways of getting around the problem of D, and because of the ad hoc nature of such systems just systems are also referred to as irregular temperaments. It is doubtful whether they were much applied in practice to harmonised music.

Two other systems have a place in the history of temperament, both of which In his time only the diatonic scale in which there are just three thirds (C β E , F β A and G β B). The F β A ratio in the Pythagorean scheme is (3/5) / (3/4) = 4/5 which is pure, and purity for G β B would suggest a value of (2/3)x(4/5) = 8/15 (0.533) for B which also establishes the purity of the fifth E β B. It has already been observed that there is flexibility when D is introduced. The major third involves the 1/β2 note F#, and to make the minor third D - F pure means choosing a value of 9/10 rather than 8/9 should be chosen for D. Preserving the G - D fifth then requires adjusting G to 27/40 rather than 2/3 and to preserve the purity of the major third G - B, B should be set to 27/40 = 0.54 compared with the value reached at the fifth step in the fifths progression which is (2/3)5 = 128/243 = 0.527 Thus in this system the purity of the thirds is therefore preserved at the expense of impurity in the fifths.

### Mean-tone Temperaments

Mean-tone systems were specifically designed for keyboard instruments. In Pythagorean terms the note E required for the interval of a third is encountered after four steps (C β G β D β A β E), which, assuming that the progression is consistently upwards in pitch, represents an interval of four fifths, or equivalently two octaves and a major third. If the latter interval is to be tuned perfectly the component fifths must be tuned as the fourth power of 5 in the same way as semi-tones were obtained as powers of 12 in the well-tempered system. As already noted the pure third measures 386.3 cents, so that the two tones which comprise it have a mean value of 193.15 cents (cf. 204 in the just system). This mean is the size of all the whole tones in this system, hence the name "mean-tone temperament". Carrying out the sort of accountancy in the previous paragraph means that the values of the semi-tones intervals must be half of 1200 - (5x193.15) = 117 cents. This in turn means that those semi-tones which are not part of the diatonic scale must have the value 193 - 177 = 76 (cf. 92 under the just tuning described above) leading to a cent scale

``` 76 117 117 76 117 76 117 76 117 117 76 117
D      E   F      G      A      B   C```

(An astute observer will spot that the above list of numbers totals 1199 highlighting a small rounding effect).

Mean-tone systems can be thought of as βsplitting the commaβ, and the scheme above is not the only way of doing so.

### Comparison of systems described

The following table summarises in cents the values of the notes of the chromatic scale of C in the four systems of tuning considered in detail :

```         C  C#  D   Eb  E   F   F#  G   G#  A   Bb    B    C
eq-temp: 0 100 200 300 400 500 600 700 800 900 1000 1100 1200
Pyth :   0 114 204 318 408 522 612 702 816 906 1020 1110 1200
just :   0  92 204 294 386 498 590 702 794 884  996 1088 1200
mean :   0  76 193 310 386 503 579 696 772 889 1006 1082 1200```

### Frequencies

In terms of frequencies, life is even simpler since for Pythagorean tuning the relative frequencies of notes in the scale are now compressed into

```     ββββββββββββββββ
2β°             2ΒΉ```
```   fx=.<.@(2&^.)     NB. exponent
fv=.%2&^@x        NB. value```

Using the verb fv of course requires some correction due to the comma effect and the practical requirement that successive octaves should have values 1 and 2

```   /:~fv 1.5^i.13
1 1.014  1.068   1.125  1.201   1.266  1.352  1.424   1.5   1.602  1.688  1.802  1.898
C   C'    C#       D      Eb      E      F     F#      G      G#     A      Bb     B
octave  dim 2nd   2nd  dim 3rd   3rd    4th  dim 5th  5th  dim 6th  6th  dim 7th  7th```

Under equal temperament the corresponding frequencies are

```1        1.059   1.122  1.189   1.26  1.335  1.414  1.498   1.587   1.682  1.782   1.888
octave  dim 2nd   2nd  dim 3rd  3rd    4th  dim 5th  5th   dim 6th   6th  dim 7th   7th```

The above frequencies are relative; in terms of absolute frequencies, concert pitch is generally taken to be 440hz for the A above middle C, so using values from the above table as divisors the frequency of middle C is somewhere in the range 260-262hz depending on which tuning system is used, and similarly for other notes.

There is nothing in the above which cannot be found in, say, Encyclopedia Britannica, or Groveβs Dictionary of Music and Musicians. However the accounts there are not particularly easy to understand, and exposition in J would have helped me greatly. Incidentally I consider that a few figures in Groveβs tables under βMean-tine Temperamentβ are in error β had the description been in J it would be immediately clear who was right! Perhaps like Ken I am just temperamentally inclined towards J!

### Code Summary

```x=: <.@(10&^.)            NB. exponent
v=: %10&^@x               NB. value
x2=: <.@>:@(2&^.)         NB. 2-exponent
v2=: %2&^@x2              NB. value
rnd=: <.@(0.5&+)          NB. round
cent=: 1200&*@(2&^.)@%    NB. convert stop positions to cents
rnd=: <.@(0.5&+)          NB. round to nearest integer
fx=: <.@(2&^.)            NB. exponent
fv=: %2&^@x               NB. value```