A plea for notational common sense

October 13th, 2009 — Mark Przepiora

Tradition can often be a retarding force in mathematics. Advancements in logic were held back by centuries due to a collective belief that Aristotle had it all figured out and there was nothing left to discover. Non-Euclidean geometry wasn’t seriously studied until the 1800s because no one could think of the parallel postulate being false.

We nowadays tend to recognize the dangers of blindly following tradition, yet in virtually all areas of mathematics we continue to adhere to notational lunacy, and pass it on to future generations starting as early as in junior high school.

This lunacy is so deeply ingrained in our minds that we see nothing wrong with the following expression:

\sin(f(x)^2)

Let’s decipher the above. We start with a number x, apply f, square the result, and finally apply sin. Yet how do we recover this order of operations from the symbols above? Starting at x in the middle we move left to f, right to the \bullet^2 , and far left to the sin.

Although we read and write left-to-right, and so naturally imagine time evolving in this direction, the notation f(x) (due to Euler) means the opposite: start with x, then apply f. Even worse is when we have an expression like f(g(h(x))). The very first operation is written on the very right, and the final operation is written on the very left, in complete contrast to how we normally think.

Worse still is that we do read some operations left-to-right, like raising to a power, and so we end up mentally zig-zagging across mathematical writing to even decipher mathematical expressions.

But worst of all is the following: when we write a function f:A\to B, A denotes the input domain, and B denotes the output domain: input on the left, output on the right. As we’d expect in a sane world. If we also have a function g:B\to C, this left-to-right notation suggests we should be able to follow the arrows (A to B to C) to compose f and g. Yet, of course, the composite is called gf rather than fg. When reading gf we are meant to mentally reverse the direction of the arrows, so that g:C\gets B and f:B\gets A, although we never write this way!

This is psychotic behaviour, and we should put a stop to it. I suggest we forget tradition, and instead succumb to notational common sense to write expressions like x.f.g rather than g(f(x)).

This may seem bizarre at first, but at least one group of scientists adopted this notation years ago. In object-oriented programming languages a mental shift is required, where one stops thinking that functions have certain inputs, and instead starts to see that inputs have certain functions. In doing so, the left-to-right notation becomes completely natural, and we would write deck.sort.pop to sort a deck of cards and remove the last one, rather than pop(sort(deck)) as we’d expect in the mathematicians’ ridiculous notation.

I believe that a notational shift would make all of our lives easier in the long run, but of course it will likely never happen. Just as negative charge will always correspond to an excess of electrons, Euler’s notation is an unfortunate convention that is simply known by too many people. As a result, already-difficult subjects like category theory are made even more maddening for silly reasons, and high school students have far more difficulty learning precalculus than they should.

Help us, Barack Obama, we need Change.

,

Substance abuse for thrifty individuals

September 19th, 2009 — Mark Przepiora

I bought a coffee maker a year ago in an effort to avoid spending money at coffee shops. Instead, since I consume the majority of my coffee at school and work, it’s been sitting in my cupboard ever since. But now being the poor grad student that I am, I decided to unpack it and take it to my office at the University to save gobs of money.

Downstairs in the ICT building, Ploughboy refills my (16 oz) coffee mug for the price of a small coffee—$1.54—a price of 77 cents per cup. This is by far the cheapest way to buy coffee on campus.

How much does it cost to instead make a cup of coffee myself? The local Superstore sells coffee beans for $1.79 per 100 grams, and I use 3 tablespoons of ground beans to make 4 cups of coffee. But how many grams are in a tablespoon? According to the International Coffee Organization, finely-ground coffee has a density of 25 lb per cubic foot. Using the magic of Google, I calculated that each cup of coffee costs me less than 8 cents to make.

The least expensive coffee on campus is nearly ten times more expensive than making my own. If I ever forget my mug and need to pay the full price for a paper cup then the cheapest alternative is The Coffee Company in MacEwan Hall which sells 16 oz coffees for $2.00, and the difference becomes closer to 13-fold.

Are there any other trivial-to-make foods or drinks that cost an order of magnitude more to buy out than make yourself? This sounds like an interesting project.

,

Twenty questions, in the degenerate case when 20 = lg(n)

August 3rd, 2009 — Mark Przepiora

A new post at Computational Complexity asks the following question:

(Problem 1.) You are trying to determine a secret integer x between 1 and n inclusive, using only queries of the form “is x = a (mod b)?” for integers a and b of your choosing. How many queries are required to determine x in the worst case?

And more restrictively,

(Problem 2.) Same as above but you are only allowed to make queries where b is prime.

The comments section seems to reveal at least a partial solution, but these are fun problems, so at least give them a shot before reading the solution there (or here.) If you’d like the solution spoiled anyway, read on! Read more…

, ,

Not so fundamental anymore, now are ya?

July 31st, 2009 — Mark Przepiora

So apparently the electron is not indivisible after all. Except, this is actually old news? What exactly is going on here?

Who says computer scientists don’t know how to have fun?

July 30th, 2009 — Mark Przepiora

Who says computer scientists don’t know how to have fun? As a counterexample, consider a new post over at Gödel’s Lost Letter that was obviously the result of some Wednesday-night festivities and intoxication.

I think, in a sense, we are the accelerators. As we smash ideas together sometimes we discover the further structure of our fundamental particles—our complexity classes.

Duuuuude.

, ,

The Fresnel integral

July 29th, 2009 — Mark Przepiora

Here’s a deceptively simple-looking integral:

\int_0^{\infty} sin(x^2)dx.

At first glance, it’s not even obvious whether the above converges.

On the other hand, it is easy to see that \int_0^{\infty} sin(x)dx does not exist (at least not in in the traditional sense) and is analogous to the alternating sequence { 1, -1, 1, -1, … }. But what of squaring the x? The function sin(x^2) alternates between positive and negative as well, so one might be tempted to say that its integral also diverges.

But before jumping to conclusions, let’s take a look at its graph:

sin(x^2)

Read more…

Circles covering squares and points

June 12th, 2009 — Mark Przepiora

The following question appeared in an issue of π in the Sky:

Show that given any 201 points inside a 10-by-10 square, there is a unit circle containing at least 3 of those points.

It is natural to ask, for what other number of points n does the above hold? And what is the smallest such n? Read more…

President Obama continues not to be Jesus

June 6th, 2009 — Mark Przepiora

From MESH, Walter Laqueur’s pithy response to worries that Obama’s speech to “the Muslim world” offered style over substance:

What of the impact of the speech? An unfair question: soft power, however desirable, has its limits. Pericles’ funeral oration did not lead to the resurrection of the dead and there is still much sin in the world despite the Sermon on the Mount.

,

This physically pains me

May 21st, 2009 — Mark Przepiora

Here’s a real excerpt (slightly modified to protect the stupid, and now fixed) from a web app I inherited. GRAAAAAAAARGH!

def encrypt_password
  ...
  self.salt = md5("#{Time.now.to_s}-#{login}")
  ...
end
 
def generate_confirm_hash
  ...
  self.confirm_hash = md5("#{Time.now.to_s}-#{email}")
  ..
end

Pro-tip for hiring managers: ask candidates to identify problems in the above code, and smack any who fail to do so.

, , ,

Pop quiz

May 4th, 2009 — Mark Przepiora

All right, class. Who can tell me what the following program will output? Bear with me, I promise this gets interesting.

1
2
3
4
5
6
int main ()
{
  int x = 0, y = 0;
  y = ++x + 10;
  printf("%d, %d\n", x, y);
}

That’s easy, it’s exactly what you expect: “1, 11″.

What about if you replace line 4 with the following?

y = x++ + 10;

Again, easy! This time, the expression x++ evaluates to the value of x before it is incremented, so the answer is “1, 10″.

Now, what about this?

1
2
3
4
5
6
int main ()
{
  int x = 0;
  x = ++x + 10;
  printf("%d\n", x);
}

This is no different than the first example, except that we’ve chucked the variable y, so the answer is “11″.

Last question: (and I’m sure you can see where this is going) what if you replace line 4 with the following?

x = x++ + 10;

 

I’m obviously trying to trick you, so you must realize that the answer is surprisingly also “11″, but can anyone tell me why it is so?

 

Extra credit: explain what happens if you replace line 4 with this seemingly-equivalent statement:

*(&x) = (x++) + 10;

,