Monday, September 18, 2017

Lesson 2-3: If-then Statements in Computer Programs (Day 23)

This is what Theoni Pappas writes on page 261 of her Magic of Mathematics:

"The work of Frank Lloyd Wright has a definite style, yet his structures are so diverse that the style does not lie in the similarities of his buildings, but rather in the philosophy that the structure projects."

This is the first page of a new section, "The Destruction of the Box: The Architecture of Frank Lloyd Wright & the Liberation of Space." I mentioned the famous American architect a few weeks ago during Michael Serra's Chapter 0, and now he shows up again in Pappas.

Pappas tells us that Wright's buildings aren't like ordinary structures. She writes:

"He designed buildings so that the outside came inside."

What exactly does Pappas mean by this? We'll find out on the next page tomorrow -- but she does give us a hint in the caption of the lone photo on this page:

"Wright's Marin County Civic Center was one of his final designs. Marin County, California."

Here is a link to the website. Apparently they give Frank Lloyd Wright tours twice a week at the Northern California historical landmark:

https://www.marincounty.org/depts/cu/tours

Chapter 3 of Stanley Ogilvy's Excursions in Number Theory is "Prime Numbers as Building Blocks":

"The Fundamental Theorem of Arithmetic states that a number can be factored into its prime factors in essentially one way."

This chapter is fairly heavy. There are proofs of several number theoretic theorems in this chapter -- beginning, of course, with the aforementioned Fundamental Theorem of Arithmetic. We begin with two lemmas -- and Ogilvy jokingly defines "lemma" as "the hard part of the proof."

Oh, and the author gives one more definition. If two numbers have only the factor 1 in common, they are said to be relatively prime. That is, the GCF of two relatively prime numbers is 1. Ogilvy actually uses the abbreviation GCD instead of GCF, for "greatest common divisor." (On the other hand, I called it GCF in my sixth grade class last year.)

Lemma 1: If several numbers are all relatively prime to a number A, then their product is relatively prime to A. This follows from the definition; for no new factors were introduced in the product, and there were none in common with A to begin with. QED Lemma 1.

Lemma 2: If a product of several numbers is divisible by a prime p, then at least one of them is divisible by p. For to say that none is divisible by p is to say that each is relatively prime to p, and then the product would be relatively prime to p by Lemma 1. QED Lemma 2.

Main Proof:
Suppose there are two factorizations:

N = p_1 * p_2 ... p_m = q_1 * q_2 ... q_n.

Now q_1 divides some one of the p_1 ... p_m, by Lemma 2. But all of the p_i are primes; hence the only way q_1 can divide a p is that q_1 = that p, say p_1. Now divide p_1 = q_1 out from both sides. We are left with:

p_2 * p_3 ... p_m = q_2 * q_3 ... q_n.

Repeat the process until all the q_i are gone. Then there is no p_i remaining either; for the product of all the original q's was assumed to be = N, and therefore the whole value of N has been divided out of the p product. Thus we have identified each q exactly with a p, which is what we set out to do. QED

Ogilvy's next example is the Euclidean GCD algorithm. As its name implies, this algorithm goes all the back to the same ancient Greek sage who formulated Geometry.

In his first example, we are to find the GCD of 30 and 108. In each step, we divide the smaller number into the larger. The old divisor becomes the new dividend, and the old remainder becomes the new divisor. We stop as soon as the remainder is 0 -- the last divisor is the GCD:

Step 1. 108/30 = 3, remainder 18
Step 2. 30/18 = 1, remainder 12
Step 3. 18/12 = 1, remainder 6
Step 4. 12/6 = 2, remainder 0, STOP.

Then the GCD of 30 and 108 is 6. Ogilvy gives an informal proof of why this works:

"How do we know that 6 is the greatest common divisor just because it is the first divisor that yields a remainder of zero? Because the existence of any non-zero remainder means that the whole divisor is itself not a factor of the dividend. We know that our common factors are factors of both; the greatest factor of any divisor is certainly the divisor itself; and we stop as soon as we come to one that evenly divides the dividend. Had there been a larger one, it would have appeared sooner."

In this next example, Ogilvy finds the GCD of 14 ad 45:

Step 1: 45/14 = 3, remainder 3
Step 2: 14/3 = 4, remainder 2
Step 3: 3/2 = 1, remainder 1
Step 4: 2/1 = 2, remainder 0, STOP. GCD 1.

Even though 14 and 45 are both composite, they are relatively prime because their GCD is 1.

In the next section, Ogilvy asks the following question:

"What is the probability that two numbers selected at random are relatively prime?"

First, Ogilvy explains how probability works. Most readers will likely already know, but I'll repeat it here anyway. Probability is a seventh grade topic under the Common Core, but my seventh grade class never reached the Stats and Probability strand before my departure from the class.

First, Ogilvy tells us that if p is the probability of success and q the probability of failure, we have:

p + q = successes/total number + failures/total number
         = (successes + failures)/total number = 1.

That is,

p + q = 1, or q = 1 - p.

Next, the author tells us something about "the joint probability of independent events." Suppose that the probability of getting a head on a fair coin flip is 1/2. We want to find the probability of getting two heads on two coin flips. So he lists all the possibilities:

TT, (HT, TH), HH.

So there are four possibilities, only one of which is two heads. Thus the desired probability is 1/4, which of course is 1/2 * 1/2. Likewise, if we want the probability of three successive heads:

TTT, (TTH, THT, HTT), (HHT, HTH, THH), HHH

Now there are eight possibilities, only one of which is three heads. Thus the desired probability is 1/8, which of course is 1/2 * 1/2 * 1/2. To find the joint probability of independent events, we just multiply the probabilities.

At this point, Ogilvy pulls out "the biggest gun in our arsenal," the following equation:

(1 + 1/2^2 + 1/3^2 + 1/4^2 + 1/5^2 + ...)(1 - 1/2^2)(1 - 1/3^2)(1 - 1/5^2)(1 - 1/7^2)(1 - 1/11^2)... = 1

He tells us that the first term is a convergent series. An AP Calculus BC student can determine that it converges, but not to which value it converges to. The author reveals its value as pi^2/6, and tells us that a Fourier Series (a college-level topic) is needed to find this value. The important thing to show is that multiplying this series by all the (1 - 1/p^2) terms (p prime) gives 1 -- and he performs this basically using FOIL (the distributive property):

Here is the first multiplication, by 1 - 1/2^2:

  (1 + 1/2^2 + 1/3^2 + 1/4^2 + 1/5^2 + 1/6^2 + ...)(1 - 1/2^2)
= 1 + 1/2^2 + 1/3^2 + 1/4^2 + 1/5^2 + 1/6^2 ...
        - 1/2^2               - 1/4^2               - 1/6^2 ...
   1               + 1/3^2              + 1/5^2              ...

(I admit that this looks much better in the book than in ASCII.) Now that there are only odd terms left in the series, we perform the second multiplication, by 1 - 1/3^2:

  (1 + 1/3^2 + 1/5^2 + 1/7^2 + 1/9^2 + ...)(1 - 1/3^2)
= 1 + 1/3^2 + 1/5^2 + 1/7^2 + 1/9^2 + ...
        - 1/3^2                            - 1/9^2 + ...
   1               + 1/5^2 + 1/7^2                 ...

And now all the multiples of three are gone. Since there are no multiples of four, we next need to get rid of all the multiples of the next prime, 5. That's why we multiply by 1 - 1/p^2 for p prime only -- it's just like the Sieve of Eratosthenes. Eventually we sieve out all the primes, leaving just 1. What this tells us is that since the original series has value pi^2/6, we have:

(1 - 1/2^2)(1 - 1/3^2)(1 - 1/5^2)... = 1/(pi^2/6) = 6/pi^2.

Now here Ogilvy's main calculation for the original problem -- the probability that two natural numbers are relatively prime. Let m and n be the natural numbers, and we want to find the probability that a prime p doesn't divide both m and n. Well, the probability that p divides m is 1/p, and the probability that p divides n is 1/p, so the probability that p divides both is 1/p^2. Thus the probability that p doesn't divide both is 1 - 1/p^2.

But we want m and n to be relatively prime -- that is, we don't need just one prime p to fail to divide them both, but every prime must fail. So we multiply 1 - 1/p^2 for every prime p:

P = (1 - 1/2^2)(1 - 1/3^2)(1 - 1/5^2)... = 6/pi^2.
    = approximately .61, if anyone is interested in a decimal value.

The author tells us that we actually used something called the Riemann Zeta-function -- the series that converged to pi^2/6 is actually zeta(2).

Ogilvy tells us that this calculation contains a hidden assumption -- the infinitude of primes. A famous proof of this goes back to Euclid. But Ogilvy doesn't use the usual proof where all the primes are multiplied together -- instead he uses factorials. He defines:

N! = N(N - 1)(N - 2)(N - 3)...3 * 2 * 1

Then he points out that Q = N! + 1 must be divisible by a prime greater than N. In his example, he lets N = 5, and 5! + 1 is divisible by 11, so 5 isn't the largest prime. This completes a proof by contradiction (an indirect proof) that there is no largest prime.

But N! + 1 isn't itself always prime. In the final section, Ogilvy seeks out a formula that produces nothing but prime numbers. One such attempt was made by the French mathematician Fermat:

F_n = 2^2^n + 1

Let's try it:

F_0 = 2^2^0 + 1 = 3
F_1 = 2^2^1 + 1 = 5
F_2 = 2^2^2 + 1 = 17
F_3 = 2^2^3 + 1 = 257
F_4 = 2^2^4 + 1 = 65537
F_5 = 2^2^5 + 1 = 4294967297

The first five terms, from F_0 to F_4, are all prime (called Fermat primes), but F_5 is composite, and indeed Fermat himself found its factors as 641 and 6700417. At the time Ogilvy wrote his book, no more Fermat primes had been found -- and that's still true today. The smallest Fermat number whose primality is unknown is F_33.

Ogilvy now switches to polynomials that produce only primes. One attempt is:

y = x^2 - x + 41

It is prime for x = 1 all the way up to x = 40, but then if x = 41, then y = 41^2, a composite. Another example is:

y = x^2 - 79x + 1601

It is prime for x = 1 all the way up to x = 79, but then if x = 80, then y = 41^2, a composite. In fact, the final proof in this chapter is that there is no non-constant polynomial that produces primes for all values of x.

Once again, we use an indirect proof. Assume that such a polynomial exists:

y(x) = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n.

Let b be any integer Since y(x) is always prime, of course y(b) is prime, so we call it p. At this point we find the value y(b + mp) for any integer m:

y(b + mp) = a_0 + a_1(b + mp) + a_2(b + mp) + ... + a_n(b + mp).
y(b + mp) = [a_0 + a_1 b + a_2 b^2 + ... + a_n b^n] + [many other terms containing p as a factor]
y(b + mp) = y(b) + [many other terms containing p as a factor]
y(b + mp) = p + [another polynomial containing p as a factor]

So for every natural number m, y(b + mp) equals p plus something multiplied by p -- in other words, it's a multiple of p. But y(b + mp) is always prime -- and the only multiple of p that's prime is, of course, p itself. So the "other polynomial containing p as a factor" must equal zero -- and this must be true for every integer m. But keeping b and p constant, it's just a polynomial in m -- and the only polynomial equal to zero for infinitely many values of m is the zero polynomial. (Here Ogilvy goes full circle by implying another Fundamental Theorem -- of Algebra this time.) This is a contradiction, since this implies that y(x) is the constant polynomial equal to the prime p for all x. We conclude:

"Hence no such prime-producing polynomial exists."

Let's get to our lesson. Today is Day 23 of the school year. It marks the midpoint of the first quarter, and hence it's the start of the second quaver -- named for a British eighth note, since we have reached the one-eighth mark of the year. This is why I really wanted to get that Chapter 1 Test in last week, before the end of the first quaver.

Lesson 2-3 of the U of Chicago text is called "If-then Statements in Computer Programs." It does not appear in the modern Third Edition of the U of Chicago text, and we can see why when we look a little at what I wrote three years ago on the subject:

Lesson 2-3 of the U of Chicago text discusses computer programs written in BASIC. We must remind ourselves that this book was written over 20 years ago, back when BASIC was a popular language. But now, BASIC has been derided as "spaghetti code" and isn't as widely used anymore.

And so the Third Edition avoids this issue by leaving out this lesson entirely. Two years ago, I changed the lesson to use TI-BASIC, the language of the TI graphing calculator, instead. But today I have do access to something that runs BASIC programs -- the emulator of my old 1980's computer:

http://www.haplessgenius.com/mocha/

So for today, I'll post the old TI-BASIC worksheets from last year. But I'm actually going to write about BASIC itself using the emulator.

Let's start by writing the four BASIC programs used in the U of Chicago text. All four of these programs run on the emulator:

Program #1: Number of Diagonals in Polygon

10 PRINT "COMPUTE NUMBER OF DIAGONALS IN POLYGON"
20 PRINT "ENTER THE NUMBER OF SIDES"
30 INPUT N
40 IF N>=3 THEN PRINT "THE NUMBER OF DIAGONALS IS "; N*(N-3)/2
50 END

Program #2: Inventory of Electro-Robots

10 PRINT "INVENTORY OF ELECTRO-ROBOTS"
15 PRINT "ENTER THE NUMBER OF ELECTRO-ROBOTS"
20 INPUT N
25 PRINT "PROFIT EQUALS";5*N-1500
30 IF N<300 THEN PRINT "ORDER MORE ELECTRO-ROBOTS."
35 END

Program #3: Area of Circle

10 INPUT R
20 LET A=3.14159*R*R
30 IF R>0 THEN PRINT R,A
40 END

Program #4: Diagonals in Many Polygons

10 PRINT "NUMBER OF DIAGONALS IN POLYGONS"
20 FOR N=3 TO 20
30 PRINT "THE NUMBER OF SIDES IS";N
40 PRINT "THE NUMBER OF DIAGONALS IS";N*(N-3)/2
50 NEXT N
60 END

All of these programs work on the emulator. Actually, my computer doesn't require the last line of the program to be END -- we could omit each of those final lines. Also, my computer doesn't require line 20 of Program #3 to begin with LET -- just 20 A=3.14159*R*R is sufficient. Don't forget to type in NEW to erase the old program before entering the new one.

Now let's write some programs of our own. Earlier when we were reading Ogilvy, there was mention of a GCD algorithm. Let's try to write it in BASIC.

The main problem here is that BASIC doesn't do long division with quotient and remainder -- instead it only does decimal division (or "floating-point division"). Remainders, as we see above, are critical to the algorithm. But it's possible -- though not easy -- to use floating-point division for remainders.

Let's go back to the example above -- the GCD of 30 and 108. We need the remainder of 108/30, but if we ask BASIC to find 108/30, it calculates it as 3.6. We need to convert 3.6 into a remainder.

The key function is the INT function. INT represents the ceiling function in mathematics (as in the greatest-integer function). So INT(3.6)=3. Well, this gives us the quotient, but we need the remainder.

Hmmm, the part that relates to the remainder is the fraction part. We can find this by subtracting the integer part from the original number: 3.6-INT(3.6)=.6. This fractional part is 18/30, so we must multiply it back by 30 to obtain the remainder -- 18.

Theoretically, this should work. The problem is that all this division produces rounding errors -- and such rounding can lead to incorrect answers. For example, let's go back to Program #3 that calculates the area of a circle. If we try entering a radius of 4 or 5, there is a rounding error that becomes obvious after trying a radius of 1, 2, or 3 first:

r     Area (as given by emulator)
1    3.14159
2    12.56636
3    28.27431
4    50.2654401
5    78.5397501

That "01" at the end of the areas for 4 and 5 stick out like a sore thumb. And no, the "01" has nothing to do with using pi to more accuracy, since it would be 50.2654825 instead (and besides, we never gave the program those extra digits of pi).

The reason for the inaccuracy is that computers work in binary, not decimal. The decimal 3.14159 actually means 3+14159/100000, but fractions with a denominator of 100000 (or anything other than a power of two) can't be expressed exactly in binary. The difference between 3.14159 and whatever binary fraction the computer uses is small enough not to appear when multiplying by 4 or 9, but when we multiply by 16 or 25 it appears. This problem never occurs if we only use binary fractions such as .5, .125, and so on.

And this is just multiplication -- in division, we're even more likely to have rounding errors. We know that fractions like 1/3 trip us up in both decimal and binary. Here, we must multiply .6 by 30 to obtain our remainder 18, but .6 isn't a binary fraction. Therefore, we'll obtain something like 17.9999999 or 18.0000001 instead of 18 as the remainder. This will trip up the algorithm -- it's supposed to stop when the remainder is zero, but it'll never reach zero if we have 17.9999999 or 18.0000001.

Using INT will work if we have 18.0000001, but INT(17.9999999)=17 instead of the desired 18. To solve this problem, we implement 4/5 rounding by adding .5 to the number before taking INT. This works, since both INT(18.4999999) and INT(18.5000001) are equal to 18.

Here is our GCD program, written in BASIC:

10 PRINT "INPUT TWO NUMBERS"
20 INPUT A,B
30 IF B=0 THEN PRINT "THE GCD IS";A: END
40 Q=A/B
50 R=INT((Q-INT(Q))*B+.5)
60 A=B
70 B=R
80 GOTO 30

You may notice a few things about how this program is written:

-- The program doesn't end with END. In fact, END appears at the end of line 30, because we really want the program to end after printing the GCF rather than proceed to line 40.
-- LET is omitted, as my computer allows.
-- INPUT A,B allows us to enter both numbers using a comma.
-- The strange part is that the IF statement (which is the subject of Lesson 2-3) appears near the start of the program. Actually, most GCD programs are written this way, in order to safeguard against the user entering 0 as one of the numbers. The program ends before reaching line 40 and thus avoids division by zero.
-- After the division, if the remainder R=0, then the final answer is in B. But the values in B and R have moved to A and B before we reach the GOTO and IF statements. Therefore B is the value that we test for zero, and A contains the final answer.

Notice that in TI-BASIC, we have a fPart function that gives us the fractional part directly without needing int. To avoid rounding error, we use the round function -- 0 here means no decimal places (nearest integer):

PROGRAM:GCD
:Disp "2 NUMBERS"
:Input A
:Input B
:While B
:round(fPart(A/B)B,0)->R
:B->A
:R->B
:End
:A

In this program, both Goto and If are avoided because we used a While loop instead. The While loop does the testing -- the loop is executed while B is true (nonzero) and stops when it is false (0). Here the word End ends the While loop, not the program.

In other languages, such as C++, there is a % operator that gives us remainder directly. Here is how we'd write the gcd function:

int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}

Here we replaced "if" with the ternary operator ?: -- it means "If b is true (nonzero), then recursively call gcd on b and a%b (the remainder), else the answer is a."

OK, let's get back to BASIC. It's a shame that I didn't stumble onto the emulator back when I was writing about music over the summer on the Pappas music pages. Now that I have the emulator, I can't help but try to play microtonal music using the SOUND command in BASIC.

In an earlier post, we discovered that the most important number when making music using SOUND on the computer is 261. As it turns out, SOUND is based on EDL, or equal divisions of length, where the length of the string is the number of steps it takes to get to 261, the "bridge." For example, Sound 61 is 200 steps away from the bridge, while Sound 161 is 100 steps away from the bridge. Thus the interval between Sounds 61 and 161 is 200/100 or 2/1, which is an octave. (To make it easier to understand, the word "Sound" refers to the actual number used in the SOUND command, while "Degree" refers to the number of steps from away from Bridge 261.)

Oh, and incidentally, today is the 261st day of the year. So there is a connection between today's date and computer music, so there!

Notice that EDL's are not the same as EDO's, in which microtonal music is often written. But it's possible to approximate some simple EDO's using the EDL's on the computer. Here is an interesting BASIC program that uses trial-and-error to determine the best EDL approximation to a given EDO:

10 INPUT "EDO";N
20 DIM R(N), D(N)
30 FOR S=0 TO N
40 R(S)=2^(S/N)
50 NEXT S
60 M=N
70 FOR L=12 TO 260 STEP 2
80 PRINT "TESTING EDL";L
90 E=0
100 FOR S=0 TO N
110 D=L/R(S)
120 E=E+ABS(D-INT(D+.5))
130 NEXT S
140 IF E>=M THEN 190
150 FOR S=0 TO N
160 D(S)=INT(L/R(S)+.5)
170 NEXT S
180 M=E
190 NEXT L
200 CLS
210 PRINT "PLAYING SCALE"
220 FOR S=0 TO N
230 PRINT "DEGREE";D(S);"SOUND";261-D(S)
240 SOUND 261-D(S),4
250 NEXT S
261 END

(Note: Line 40 requires an up-arrow where you see the ^ caret.)

Here's how the program works -- the user inputs the desired EDO in line 10. Lines 30-50 set up the correct ratios for your EDO -- so if you choose 12EDO, then the ratios are 2^(0/12), 2^(1/12), 2^(2/12), all the way up to 2^(12/12).

Lines 70-190 set up a loop to test every EDL, from the shortest (12EDL) to the longest (260EDL). It calculates the error E between the correct ratio and closest possible degree available (notice how INT(D+.5) is used to round D to the nearest degree). The IF statement in line 140 is used to see whether E is less than the minimum error M encountered so far. If E>=M, then we skip to line 190 and check the next EDL. If E<M, then we have a new "best EDL so far," and lines 150-170 set up a loop to replace the list of "degrees of the best EDL so far" with the new list.

Afterwards, the final loop from lines 220-250 actually play the best scale on the computer. (Don't forget to click the "Sound" box in order to hear the sound!) I decided to make the length 4 because just as the magic number for pitch is 261, the magic number for duration is 32 (whole note). As today's the start of the second quaver, let's make it play quavers, so 32/8 = 4. The final END line isn't needed, but I include it just as an excuse to honor Bridge 261 with a line 261.

Here are the best possible scales the computer found for some EDO's:

5EDO: use 256EDL (Degrees 256, 223, 194, 169, 147, 128 -- Sounds 5, 38, 67, 92, 114, 133)
7EDO: use 156EDL (Degrees 156, 141, 128, 116, 105, 95, 86, 78)
10EDO: use 256EDL (add Degrees 239, 208, 181, 158, 137 in between 5EDO)
12EDO: use 232EDL (Degrees 232, 219, 207, 195, 184, 174, 164, 155, 146, 138, 130, 123, 116)
16EDO: use 214EDL (Degrees 214, 205, 196, 188, 180, 172, 165, 158, 151, 145, 139, 133, 127, 122, 117, 112, 107)

I actually recommend not going past 12EDO, since the error E rises sharply. If you must try a higher EDO, then use 16EDO as it has the least error. Other multiples of 4 (20EDO, 24EDO, 28EDO) have lower errors for their size, while 22EDO and 31EDO (mentioned in earlier posts) also have lower errors for their size. Beyond 31EDO, all scales are about equally bad (with the odd EDO's marginally better than the even EDO's).

It's interesting that 232EDL is the best for 12EDO, since the EDL link I mentioned in an earlier post recommended 120EDL and 196EDL (among others) to make a 12EDO scale.

But to me, making EDO scales is such a waste. The computer uses EDL's, which are based on exact divisions of length, so we should be playing sounds in just intonation, not EDL's.

Before we try to play some scales, keep in mind that an EDL scale is what we call "utonal." This means that if we think of intervals as being played above a bass note (as opposed to Pappas, who gave the ratios for the notes below C to form a major scale), then we must find a common numerator, then vary the denominators throughout the scale. We must keep this in mind as we try to play the various scales.

3-limit scales (Pythagorean):

Pythagorean scales as based on powers of 2 and 3. We notice that 261, the bridge, is very close to 256, which is 2^8. So we can create a scale based on Degree 256 (Sound 5).

Notice that we can't play perfect fifths (3/2) above Degree 256 since the numerator, 3, doesn't divide the degree (256) evenly. We can, however, play perfect fourths (4/3, which are utonal). If 256 is the bass note, than a fourth above it is 192, then another fourth above that is 144, and another fourth above that is 108, and another fourth above it is 81.

Now if the bass note were C, then proceeding by fourths gets us into flat notes quickly -- the first fourth is F, but then we have Bb (B-flat), Eb, and Ab. But fortunately, comparing Degree 256 (Sound 5) to my keyboard reveals that this note is the E below middle C. This is convenient, since the fourths proceeding from E require no flat signs -- A, D, G, and C (one octave above middle C).

Here are all the Pythagorean notes playable on the computer:

Degree     Sound     Note
256           5             E
243           18           F
216           45           G
192           69           A
162           99           C
144           117         D
128           133         E
108           153         G
96             165         A
81             180         C
72             189         D
64             197         E
54             207         G
48             213         A
36             225         D
32             229         E
27             234         G
24             237         A
18             243         D
16             245         E
12             249         A
9               252         D
8               254         E
6               255         A

The column marked "Degree" lists all of the 3-smooth numbers from 6 to 260. (Yes, primes -- just as Ogilvy tells us -- are the building blocks of music. Notice that the note B isn't playable, since we can't play a perfect fifth above E. Also, some notes aren't available in the higher octaves -- if a note falls on an odd degree (such as C on Degree 81), then we can't cut it in half to raise it an octave.

5-limit scales:

The usual major scale is 5-limit because it depends on the major third (5/4). If C, D, E, F, G, A, B, C is a Pythagorean major scale, we must convert it to the just major scale by lowering the note E, A, and B by a syntonic comma, 81/80. This produces the scale C (1/1), D (9/8), E (5/4), F (4/3), G (3/2), A(5/3), B (15/8), C (2/1). (Pappas lists the ratios counting down from the high C, rather than up from the bass C.)

It's impossible to play a major third above any of the Pythagorean notes, since 5 doesn't divide any of the Pythagorean degrees. Instead, we must go down a third from a Pythagorean note. We found out that 180 is the common numerator of all the ratios in the major scale, and so we can use 180EDL to make a just major scale. Degree 180 is a major third below Degree 144, which is labeled as D, and so the base of the scale must be labeled as Bb+, a syntonic comma above (Pythagorean) Bb. Earlier, I thought that the base note of the major scale was B, but it is properly labeled Bb+:

Bb+ (Degree 180), C+ (160), D (144), Eb+ (135), F+ (120), G (108), A (96), Bb+ (90)

Even though we can't play a major scale on D, we can play a minor scale -- exactly because minor intervals are utonal. Here is the just D minor scale (natural minor, not harmonic):

D (Degree 144), E (128), F+ (120), G (108), A (96), Bb+ (90), C+ (80), D (72)

7-limit scales:

I haven't explored these fully yet. We see that a harmonic seventh chord is in ratios 4-5-6-7 (that is, 1/1, 5/4, 3/2, 7/4), and the common numerator is 105. I prefer 210 so we can add an octave (2/1) above this note as well. The base note is called G+7 (G plus syntonic plus septimal comma), which is a long name, but notice it reflects the fact that 210 has both 5 and 7 as factors:

G+7 (Degree 210), B7 (168), D+7 (140), F+ (120), G+7 (105)

I remember when I first learned about the PLAY command on my old computer, the instruction manual joked "One further note...No, we're not going to spring a new note, like H or J, on you...."

Actually, there really is a scale that contains an H and a J. It's called the Bohlen-Pierce scale, named for its two creators. The extra notes are needed because the distance from C to C isn't an octave (2/1), but a wider interval called a "tritave" (3/1).

Even though a true Bohlen-Pierce scale isn't playable on the computer (since changing 2's, 3's, and 5's to 3's, 5's, and 7's make the numerators grow well past 260), I ran the above program using tritaves to find its best approximation. Believe it or not, the best approximation was 63EDL:

C (Degree 63), Db (58), D (53), E (49), F (45), Gb (41), G (38), H (35), Jb (32), J (29), A (27), Bb (25), B (23), C (21)

The notes C, E, G, H, A, Bb, and C are justly tuned in accordance with the specifications as given by Bohlen and Pierce. Since 63 is small enough, we can multiply all of these notes by three in order to play another tritave.

We can go on and on with 11- and 13-limit scales, but this post is getting long enough.



No comments:

Post a Comment