There's a line in Neal Stephenson's Cryptonomicon where one of
the main characters, a mathematician and programmer, is asked if he is
good with numbers. "I'm good with math," he replies.
"Mathematicians stay away from actual, specific numbers as much as
possible. We like to talk about numbers without actually exposing
ourselves to them."
To most people, math and numbers are the same thing, which is
unfortunate. Certain personality types respond well to numbers--one of
my ex-girlfriends, a CPA, derived a kind of warm satisfaction from
seeing columns upon columns of financial figures--but for the rest of us
they are at best an eye-crossing source of confusion, and at worst a
harbinger of bad news: taxes, checkbook balances, bills, etc.
Perhaps I'm an outlier (Cue cries of "freak!"), but I'm finding that
while I personally don't care for numbers, I really enjoy math.
I've learned (or re-learned) more math in the last two months of coding
than I picked up through all of college (granted, I majored in the
softer bits of Communication, and had taken all of the math courses
available at my high school). This late education has actually been a
lot of fun.
Here are a few math functions that I've either picked up, picked up
again, or had to explain to coworkers who have forgotten even
more of their algebra classes than I had:
- Modulo: You already know what modulo is, although you may
not know that you know. Everybody learns it in elementary school. The
modulo is better known as the remainder, or the amount left over after
performing division. Apparently, it gets its new name from modular
arithmetic, a system developed by Carl Gauss in the early 1800s, where
numbers loop back around to zero when they pass a certain value. Which,
if you think about it, is basically what the remainder does: it resets
to zero each time division results in a whole number. Since programmers
tend to care more about referencing 19th century research papers than
being accessible, we're stuck calling it "modulo" instead of
"remainder." I remember hating remainders in elementary school, because
a remainder meant you weren't done with the problem--we had to keep
dividing them into smaller and smaller decimal places. But remainders
are actually really useful in their own right, because they let you
cycle through a set of numbers using only addition and subtraction.
- Absolute values: I was really surprised when one of our
graphic artists didn't remember absolute value--the distance of any
given number from zero. Obviously, for positive numbers, the value and
the absolute value are the same. But for negative numbers, the absolute
value removes the sign. This is surprisingly handy. I've been using it
to test whether or not a given arithmetic operation changes the sign
between the input and output, for a hobby project.
- Sigma notation: Man, this is a scary one. I avoided
learning about sigma notation for years, but it's actually not that
frightening in reality. Sigma notation is just a shorthand for adding an
arbitrary number of equations over a range of values. The value below
the "broken E" is where your variable starts. The value above is when
you stop. And the equation to the right is what you do over and over
again, adding each result to all the previous results, until you hit the
stop condition. I'm mostly excited about it because I can finally
express my multiple-monitor-productivity equation: I figure that I'm 1/n
times more productive for each additional monitor. So my second monitor
makes me 50% more productive (1/1 + 1/2), while a third takes me up to
183% of normal productivity (1/1 + 1/2 + 1/3). Finally, I can adequately
express this for n number of monitors! ("Freak!")
- Sine and cosine: These are, I think, always explained very
badly in geometry classes, at least for the applications in which I've
used them 99% of the time. Sine and cosine are just the y and x values
of a point on a circle for x number of radians. Getting into the proof
and the explanation of how they work requires a lot of triangles, but
you don't actually need to know that part to use them. So basically,
yeah: y and x values on a circle. Can't draw a circle--or in my case,
animate pictures going around in a circle--without these guys.
I know, this all sounds really dorky. But what I'm enjoying about all
this math is that it's almost like a puzzle to solve: I've got x input,
and need to end up with y output. How do I get one to become the other?
All the different mathematical principles and operations are like boxes
that I can hook together, like the modulation matrix of a synthesizer,
until they spit out what I want. By focusing more on the operation and
less on the numbers, I'm having a lot more fun than I thought I would.