Grandfather Rice
Musings from a bit character


The complexities of simple math and the power of cat drawings.
Previous Entry :: Next Entry

Read/Post Comments (8)
Share on Facebook

As some of you (assuming someday that people will read this) may already know, I'm a software engineer by trade. This means that I write programs (Or more often parts of programs) that are used to torment presumably innocent people. We'll have to get into discussions on the need and practical use of torment on the undeserving some other time (This is a literary tool called "Foreshadowing" which means "I'm much too lazy to talk about this right now so I'm going to pretend I'll be less lazy later. (Parenthesis are another literary device I refer to as an "Annotation". Whether other people refer to it this way is questionable, but they should. It would be one step closer to making them more understandable (Nested Parenthesis are a nasty habit Software Engineers get into too.))).

A good way of thinking about programming is to take fairly complex tasks, reduce them to a rediculously small level of detail and then feed them into a device that's so hideously single-minded and anal it makes Rain Man look like Albert Einstein (And I don't just mean by making his hair grow out and turn white. (See, here are those pesky parentheses again. If they bother you inordinately, just don't read them. As with all good "Annotations", the text should be perfectly readable if you skip over anything between parentheses. More boring, certainly, but perfectly readable)). A good example of this behavior is with basic mathematics.

The stuff I've been working on recently has to do with writing musical notation. Music is handy because most of the time it's very attached to the number two. If you know anything of music, the very names of the notes are all into the number two. Half notes (1/2), Quarter notes (1/4 or 1/(2x2)), Eighth notes (1/8 or 1/(2x2x2)), etc. Even time signatures tend towards powers of two. Most everything can be happily halved or doubled and still make sense.

This is great for computers, because computers have an infatuation with the number 2. Computers run off a numerical system called "binary" which essentially means they only have two fingers to count everything on. As such, they seriously seriously dig things divisible by two. Since fully half the numbers are divisible by two, this is a fairly useful thing.

Let's do some basic music-notation to decimal (10 finger counting) conversion. I know that's a little odd, but bear with me.

  • 1(Whole note) = 1
  • 1/2(Half note) = .5
  • 1/4(Quarter note) = .25
  • 1/8(Eighth note) = .125
  • 1/16(Sixteenth note) = .0625
  • 1.32(ThirtySecond note) = .03125

Mathematically, these are pretty well-behaved decimals. They're fairly short (even .03125 you could memorize without a lot of effort) and they're nicely related. You could even call them "polite". This is a fact that I've been luxuriating in for quite some time now on this project. Until yesterday.

Yesterday, you see, I needed to make "triplets" work. A triplet, in music, is a grouping of three notes that happen in the same period of time as 2 other notes. 3 Triplet eighth notes, for example, take the same amount of time to play as 2 quarter notes. Besides being somewhat smarmy (Personal opinion), this plays merry hell with the math, because we're callously introducing the number three into a system that works incredibly well with the number two. Let's see what happens.

Let's say that we're working with triplet eighths. You need to fit three of these bad boys in the same time as two quarter notes.

So, two quarter notes = (1/4 + 1/4 = 2/4 reduced to 1/2). In decimal this would be .5

We need to fit three things in the same space so we divide by three (1/2 * 1/3 = 1/6). Fairly simple so far (If you missed a couple of turns in that last step, ignore and move on. Trust your Grandfather. Thousands of Chinese can't be wrong, unless they are.).

So computers don't like fractions. They're entirely too abstract. So they try to keep numbers as decimals. so what is 1/6 in decimal? .166666666666666666666666... and you can keep writing sixes until your arm gets tired or your soda gets flat or something altogether more interesting distracts you. You'll notice that this number is not nearly as polite as the ones we were looking at earlier. It's a selfish, greedy decimal that takes all the space you have and scoffs that you don't have more.

Further examples:

  • 1/12 = .083333333333333333....
  • 1/24 = .041666666666666666....

So computers have to store this nastiness somehow, and they only have so much space to do so. So what do they do? They keep figuring 3s or 6s to only so long, and then they round to keep every thing a fixed length (This is a simplification. (This was another annotation. Isn't learning fun!)). Well that's just ducky. But if you're trying to keep track of how far you've gotten, it just screws up your nice clean math. Say that you want to put a measure line when you have a total of a half notes worth of space. We need 3 triple-eighths to do the job (Again, trust me.). So we do some adding. Try this with a calculator. You can simplify the example by using the number .166. Just put in .166 and multiply by 3. Go Ahead. I'll wait.

What did you get? Well, my calculator says .498. In reality, since we're dealing with many more sixes, it's really something more like .49999999999(lots more nines)99998. So here comes the ass-chapping part. Is 4.999999etcetc = 5? Nope, never and twice never on Thursdays. It's close, really really really close, but no fig tree. The Idiot Savant computer will never say "Close enough for practical purposes". So now, as a programmer, I have to complicate all my calculations to handle this, just because some smarmy renaissance composer thought he'd be all rebellious and rule-breaking and inject triplets in an otherwise number-2-loving system. He probably wore his tricorn hat backwards and his shoes on the wrong feet and ran with a violent crowd of teenage gutter-composers defacing public property ('Mozard fo lif3') in the streets of venice (Although he wouldn't run very fast because his shoes were on the wrong feet and you don't run very fast on water. (See what comedy you would miss if you didn't read the annotations?)). Anyway, some prehistoric gang-banger is making my life difficult. I have no realistic path of retribution. So I shake my fist towards Italy and write about it in a blog. Way to go, me.



In other news, my son Av asked me to draw him a picture of our cat on his toddler magnetic etch-a-sketch thingy this morning. This is utterly and completely fantastic for two reasons:

  1. I understood what he was asking (Minor miracle, that).
  2. It was something I could and was willing to do (No, we can't smoosh crackers into the carpet. No, we shouldn't wake mommy, she's tired. Come back here!)

I rendered something mediocre which he was delighted with. He proceeded to take the picture and shove it two inches from the face of our cat and repeatedly tell the cat that it was a picture of him.

I smiled. It was awfully cute.

What is grit if not a bunch of fine detail?



Read/Post Comments (8)

Previous Entry :: Next Entry

Back to Top

Powered by JournalScape © 2001-2010 JournalScape.com. All rights reserved.
All content rights reserved by the author.
custsupport@journalscape.com