Sunday, May 19, 2013

Get Aeolian

I've been listening to Major Lazer's song Get Free a lot recently. If you haven't heard it before, here's the music video:

After playing the song a dozen or so times in a couple days, I figured it might be worth learning how to actually play it. I've only just started trying to play along to it by ear, but it's already becoming pretty clear that there's some interesting stuff going on.

For one thing, this song has one of the simplest chord progressions imaginable: G-A-Bm-G. That's three chords for the whole song (and they're easy enough chords that I could actually play them on a guitar, if I had a guitar).

So if there are only three chords, what makes the song interesting? As with a lot of electronic music, the timbre of sounds is important: the echoing, bouncy, electronic part contrasts with the vocal cries. It's also strong lyrically (at least I think so, "feeling like a battery hen" is a great simile). However, I think that even when you only consider the pitch of notes in the song it's still interesting, so the question is: how does that work?

It turns out that "Get Free" is a textbook example of the Aeolian mode (on B) [I started writing this post because I initially thought it was in Dorian, which would have been neat, because I don't know any popular Dorian mode songs; Aeolian is a bit less exciting, but oh well]. That means it's melody is formed from the notes B, C#, D, E, F#, G, and A. This mode is also known as the natural minor scale, since it's a minor scale without the raised sixth or seventh you'd get in the harmonic and melodic minor scales.

Because the natural minor scale is the exact same as the harmonic and melodic minor scales when the sixth and seventh are avoided, the melody simply sounds minor as long as these notes are avoided. However, the chord progression begins and ends on a G major chord and G is the sixth. The second chord in the progression is an A major chord and A is the seventh. Three quarters of the chords in the song are thus major, but they always lead up to the B minor chord before falling back to the G major. Note that in the G-A-Bm-G progression, the root of the chord rises by a whole tone between each of the first three chords which conveys a feeling of growing excitement or momentum, but that momentum is stopped by the minor third chord and we return to the familiar G chord which is repeated once before the chords rise again (and again, for the entire song). The result is sort of an optimistic sound that has been infused with melancholy. The chord progression is constantly rising; constantly retreating.

While the chords progress by rising a tone at a time and falling back, the melody consists primarily of downward runs. At one level, this provides a contrary motion to the bass line since the bass follows the rise of the chord progression. The rise and fall of a melody line also shapes the emotion conveyed by the line; although this isn't as straightforward as up=happy/down=sad. Loosely speaking, the downward parts deflate tension, while the upward ones increase it. My interpretation of the effect this has on the song is that the downward runs convey the sensation of lowering expectations or accepting circumstances, while the upward movements ramp up tension and express a desire to fight back.

Getting back to the use of the Aeolian mode in the song, the seventh (the A) is particularly important for the melody. Normally, you'd expect the melody to resolve to the tonic (B) after hitting the seventh (A), but that usually doesn't happen here. There are quite a few lines that end on an A at the same time as the G major chord is being played ...and that too is unusual. The G major chord contains a G and B: since the A falls between these two notes, the result is highly dissonant and strongly suggests that the melody should resolve to the B. This is often what's happening when the vocal part does its howling thing (for example, when the word "friend" is said in "how long, how long 'til we have a friend"). Not all of the "howls" use this technique ("dreams" in "what will I do without my dreams" is actually sung on a B, but the layered vocals add surrounding notes to create the same dissonance).

The upshot of all this is that it is technically a very simple song, but the techniques it does use are used brilliantly. The simpler a song can be while still remaining distinctive and evocative, the more likely it is to be memorable.

PS. Yes, this is the same Major Lazer that created "Pon de Floor", which is known for its absurd music video featuring daggering. Before you go Googling that, note that Wikipedia quotes some guy as saying "'Pon de Floor' seems equally as offensive as watching porn on hallucinogenic substances" so it might not be the sort of thing to watch at work or around your grandparents.

Saturday, March 2, 2013


If you ever find yourself wondering what the smallest positive integer value is that you cannot represent exactly in a single precision floating point number (using a standard binary32 representation as defined in IEEE 754-2008), the answer is the title of this post.

This little bit of trivia is something I discovered while playing with the tutorial I wrote for the data structures class I'm TA'ing (that tutorial again, in case you missed the plug in my previous post, is available here). The reason it happens is that the exponent of 16777216 is 24, but only 23 bits are used to represent the mantissa (non-exponent part) of the number.

For a double-precision floating-point number, 52 bits are used to represent the mantissa, so the integers from -9007199254740992 to 9007199254740992 can be exactly represented. This is more integers than you can represent with an integer! At least, it's more bits than you can represent with a normal 32-bit integer, which in retrospect is kind of obvious since the number 32 is smaller than 52.

Here's another equally nerdy bit of trivia: you can toggle between lowercase and capital letters that are represented as ASCII characters by toggling the 5th least-significant bit of the character. This works because the value of each lowercase letter is exactly 32 plus the value of the uppercase letter. Since the alphabet contains 26 letters, I assume that this spacing was designed deliberately to make case transformations easier. It's hard to imagine a situation in which switching the case of a letter would be so important that it would require this level of optimization, but the ASCII table was defined a long time ago and perhaps it was necessary for Ye Olde Computers.

In summary, I now know far more about data types than I've ever found necessary before. This is what happens when I try to teach stuff.

PS. If you're about to say "the exponent of 16777216 isn't 24, it's 7, dummy" that's because you are thinking in base ten:
16777216 = 1.6777216  * 10^7
when it's actually calculated in base two:
16777216 = 1.0000000 * 2^24

PPS. If you're thinking "52 bits can't represent the integers from -9007199254740992 to 9007199254740992" then you're right. The sign bit isn't counted in the mantissa and the number zero is represented when all 64 bits in the double are off (aside from the sign bit, which can be either on or off). Zero is a special case; we're basically rounding two values that are really close to zero to exactly zero. These notes go into more detail.

PPPS. For anyone who writes code in JavaScript, one of its quirks is that it stores all numbers as doubles. This means that JavaScript has full coverage of integers in the range -9007199254740992 to 9007199254740992. There are larger and smaller integers that can be exactly represented in JavaScript, but you need to start counting in twos (and once you hit 2^54, you'll need to count in fours, and so on).

Friday, February 22, 2013

Data and websites

I really need to redesign this website at some point.

In the meantime, if anyone wants a rudimentary C tutorial, check this out:

It's been a really long time since I've done any website development. It's not quite as painful as I remember it being (although that's mostly because I only bothered with compatibility for the most recent generation of web browsers).

Thursday, July 14, 2011

Energy Consumption

Apparently US data centers consumed 61 billion kWh in 2006 (according to this EPA report (PDF)). That sounds like a big number, but I like to judge these things by my favourite Big Energy metric: how much mass would you have to completely annihilate to get that much energy?

Well, assuming I crunched the numbers correctly (ie, assuming I can blindly trust Google's calculator), that amount of energy can be expressed as 2.196*(10^17) joules, which, when divided by the speed of light squared yields: 2.44 kilograms.

Given that the same EPA report claims that this energy usage statistic accounts for 1.5 percent of the total US electricity consumption, that means that to power all of the US for a year, you would need to annihilate 2.44 divided by 0.015 = 163 kg of matter.

That strikes me as a remarkably high number. It means that if I were to encounter my antimatter twin (and both of us weighed somewhere around 68 kg), even if we did fully annihilate each other and even if all the energy from this event were captured (and stored perfectly until needed), this would only power the US for somewhere around 300 days.

This saddens me, because it means that my human-antihuman power supply will require a disturbingly large number of sacrifices to keep running.

Wednesday, June 29, 2011

Quality Wasted Time

When I first started this blog, its mandate was to talk about engineering-lifestyle things, like freaking out about midterms and being jealous of MIT. I've strayed a bit from that ideal over the years, but I'd like to get back to it now with a discussion about the quintessential student pastime of wasting time on the internet.

Now, since you're reading my blog, I'm going to take it for granted that you already appreciate the benefits of spending time on online activities that are not, strictly speaking, useful. With that in mind, we can skip the moral questioning and get straight to the fun stuff: did you know you can download parts of Wikipedia as books?

It's true. I'm not referring to WikiBooks either, which are notoriously incomplete and haphazardly edited, but actual PDFs/ODT files/ZIM files/physical books made from the content of Wikipedia itself.

This might not sound like that much of a time waster, because navigating Wikipedia the conventional way is probably even more of a time waster due to all the link-hopping. Reading a book of encyclopedia articles could also be considered a constructive use of time. To both of these objections I present: this six hundred page book of chess variants. Clearly this is a waste of time and something I would never have wasted time on before it became possible to load onto an e-reader.

So you now have a couple thousand new books to read (starting, perhaps, with Philosophy of Science, Neuroscience, LGBT themes in science fiction, fantasy and horror, Consciousness, Complex Dynamics, or University Genetics). Interestingly, Creationism and Intelligent Design is one of the larger books, probably because the arguments, lawsuits, and politics involved are distressingly entertaining.

Moving along, I've also taken to wasting a fair amount of time on the Khan Academy site. Again, studying mathematics through a tutoring site (an incredibly good tutoring site with video tutorials from one instructor spanning topics from basic addition to vector calculus) might seem like a benign time waster, but I assure you it is quite possible to spend far too long there.

For one thing, the Khan Academy has discovered that the future is games and uses a gaming-inspired reward system to motivate students to study more. This only affects people who log into the site (with a Google or Facebook account) but should you be so unwise as to do so, you'll suddenly have the option to gain lots of points by watching video lectures and answering simple interactive math tests. Since the tests are aimed more at the elementary level than the university level, it is quite possible to gain ludicrous amounts of utterly meaningless points in the span of a few hours if you're willing to answer lots of arithmetic questions. I don't personally recommend doing this but, having done it, I have a renewed appreciation for not having to manually multiply dozens of three-digit number pairs together for homework anymore.

Seriously though, Khan Academy has a lot of good stuff for anyone who wants to learn stuff (mostly math, but there's a couple biology, chemistry, and history videos available for good measure). It's a similar type of time waster as watching lots of TED talks and you can even combine the two by watching a TED talk about Khan Academy.

In other news, I have a free unlimited internet connection and am really good at arithmetic again for no apparent reason.

In actual other news: brains, concepts, plasticity, self-organizing, going to CogSci 2011 woohoo, Shad BrainLab, iGEM, software, interfaces, coding Saturday, going to be awesome, can't say much about any of these things, but they're all awesome.

Wednesday, April 6, 2011

Best day... ever?

I was hoping to write a proper post about this, but I am somewhat too tired to do so, so I'll resort to posting a schedule of the day.

9:00 AM: Brain Day starts, introductions to talks by...

9:15 AM: Sebastian Seung (MIT) [I am my connectome TED Talk, on Youtube].

10:45 AM: Peter Strick (Pittsburgh): Motor control and basal ganglia / cerebellum topography.

1:30 PM: Jonathan Cohen (Princeton): Adaptive cognitive control.

3:00 PM: Ned Block (NYU, Philosophy) [On Consciousness Youtube clip].

[End of Brain Day]

7:00 PM: Perimeter Institute lecture by Roger Penrose [Discover Magazine article]

10:00 PM: Read web comics. There was a good crop today!

EDIT: Apparently Ryan North of Dinosaur Comics was also at the Perimeter Institure lecture. I'm kinda disappointed I spent too much time listening to the lecture to notice this.

Thursday, March 17, 2011

Dryers, Animals, and Other Housing Failures

Call it confirmation bias if you will, but I seem to have unusually bad luck with drying machines and animal infestations.

A couple terms ago, I made the (rather glaring, in retrospect) mistake of moving into a house where the washing machine and dryer would be "replaced soon" by the landlord (they weren't there when we moved in). The appliances did eventually get put in, but it would be a stretch to say they were new. In fact, the dryer was missing its exhaust vent, which is a rather important thing to have. Now, exhaust vents aren't that hard to get or install and eventually we did install one ourselves, but the process of doing this was all sorts of awful (most of them involving abuses of duct tape) since the pipe the landlord had supplied didn't fit the mangled attachment points.

The next term, in a different house, we had a bat somehow get into the house. I was fairly apathetic about this but one of the other guys in the house (a veteran from the dryer disaster) went mildly insane and plastered black garbage bags over every doorway in the house to prevent the bat from attacking us in our sleep and giving us rabies, or histoplasmosis, or something. The next day saw a bathunt with a bunch of twenty-year-old guys armed with broomsticks and an almost comical fear of giant leathery bugs. We never did find the bat.

Today, I was working on plotting out an essay for my philosophy class (topic: what is it like to be a bat?), when I heard a persistent fumbling sound coming from the laundry room. At first, I assumed one of my roommates was doing some incredibly clumsy laundry, but after half an hour or so, this hypothesis seemed increasingly and distressingly unlikely. No, there was clearly something stuck inside the dryer vent; something alive and possibly terrified.

After considering all the ways I could ignore the problem and hope for a resolution that did not require my intervention, I came to the sad realizations that (a) there was no way the thing was getting out on its own, (b) furry animals and exhaust vents are probably a fire hazard and animal cruelty, (c) anyone attempting to do laundry would be a very bad thing, and (d) people sometimes do laundry from which we can conclude that (e) having clean clothing is overrated and (f) I would have to talk the other residents of my house out of doing laundry for a while.

A dramatized reconstruction of this talk follows:
Me: So... have you ever thought about what it would be like to be a squirrel?
Guy: ...
Me: Say you were a squirrel stuck in a dryer exhaust.
Guy: Seriously?
Me: Um, yeah.

To shorten a lengthy tale into a slightly more condensed form of a lengthy tale, the Laundry Avoidance strategy didn't seem to adequately address the long-term implications of the Animal Stuck In Appliance scenario. What we decided to do was take apart the exhaust vent; sure, we'd have to get some duct tape and fix the damn thing later, but at least we could get on with life.

At this point, I was the only one who had heard the squirrel/bat/chipmunk thing inside the vent. If the bat and dryer experiences had taught me anything it was that wild animals can be bloody difficult to find and dryer vents aren't fun. Nonetheless, we did what we had to do: we unwrapped the duct tape holding the vent in place and we waited for stuff to come out.


We took out the other side: still nothing. There was nothing in the vent. At this point, you probably think that this blog post is about how I let my prior experiences impede my judgement. You might think that I'm slightly insane. You'd probably be right on both counts.


As I went back to planning my essay (maybe "problems with sense perception" would be a better topic than that bat nonsense), there was another fumbling sound from the laundry room. The laundry room that did not contain a squirrel stuck in a dryer vent. The laundry room that we had just conclusively proven (causing some amount of material damage in the process) did not contain a squirrel stuck in a laundry vent. The laundry room that had just as many squirrels in laundry vents as Area 51 had aliens facing human molestation charges and... the fumbling continued. I grabbed a video camera.

I shot a minute long video of an indistinct shape scrambling up a plastic dryer vent, trying to leap up a long vertical stretch of metal tubing, and failing miserably. Armed with this evidence, I set out to convince my earlier accomplice that I was still sane.

The resulting conversation was sufficiently awkward that I feel no need to immortalize it here, but to his credit my partner-in-dryer-destruction returned to the scene of the crime for a second look. Once again, the dryer vent was quiet when we arrived.

Pulling out my video camera, I played back the video I had taken. I had been so excited by the feeling of actually-having-proof-this-time that I had forgotten that most of the video consisted of silence.

"It gets better," I said.

And suddenly it did: a faint scampering could be heard from the video and almost simultaneously the real exhaust vent started shaking up again.

"There," I said, prodding at the screen, "you can kind of hear it there! Here, I'll rewind..."

It turns out that the live performance next to me was more convincing than my recording, so rewinding was unnecessary. We got our animal trapping gear back in place and I triumphantly removed the bottom of the vent and placed it into our designated cardboard box. I'm not even going to bother building this up, because obviously it didn't work. It couldn't work. There was nothing in the freaking vent!

"Huh," we said.


Can you figure out the case of the ghost squirrel?

PS: my philosophy essay is not about any of the topics listed here. I would say what it's actually about, but I don't want TurnItIn to think I plagiarized myself.

EDIT: The true conclusion to this shocking story of paranormal activity is here.