I often have to do calculations that pertain to musical intervals, i.e. the ratios between two pitches. E.g., the interval that commonly we call a "major third" (c-e, d-f# etc.) can be expressed as a 5/4 ratio (in so-called "just intonation").
Now consider such a ratio, such as 5/4.
Assume that, for our purposes, every ratio that, as a whole, is half as big, (or a quarter, or two times, four times...) is "as good as" that ratio. In other words, we consider 5/2, 5/8, 5/16 etc. equivalent to 5/4. Musically speaking, all those ratios express the same "pitch class". So if 1/1 were our c and 5/4 our e, then those "new" ratios we would call ,e, e' e'' etc., but they're all es.
Now assume that whenever I'm working with a ratio, I always want to stay within one octave, i.e. between 1/1 and 2/1. Every ratio that is generated in the process needs to be (and here's where, as mathematical layman, I run into terminological problems) "folded back" into one octave, i.e. be constrained between 1/1 and 2/1.
Say I wanted to calculate the pitch that we arrive at after stacking a few such major thirds on top of each other:
5/4 * 5/4 * 5/4 * 5/4 ...which, to most people, would be 625/256. But to me, as described above, it's 625/512.
Doing my maths with pen, paper and my head most of the time, none of this is a problem. I simply halve, double, etc. the nominator or denominator, and that's it (here: double the denominator).
But how would we solve such a problem in an automated way? I admit to using Excel once in a while to work on my music theory stuff (besides a dedicated application called "Scala" which is of little help in this specific problem). Suppose you only had Excel available as a tool, how would you go about it? How would you constrain the result of a division between two poles? Any advice is appreciated!
At each step of the multiplication, if you get a result larger than or equal to $2$, divide the result by $2$. (It's easier to do this at each step than to figure out how many times to divide by $2$ after all the multiplications. The Excel formula to divide a number (say in cell
B2) by $2$ if it is at least $2$, but leave it alone otherwise, is=IF(B2>=2,B2/2,B2).Here is a screenshot of a bit of Excel sheet that used a variation on this formula. [Corrected from original posting.] Hope it helps. (In case you're wondering, the formatting for the fractions is a custom format string,
#######/#######.You could also do this using the frequencies, instead of just the ratios, if you divide by $2$ when the result is twice the original base frequency or greater.