Archive for November, 2008

Chuck: properly farsical

November 15th, 2008

A lot of really bad "comedy" movies have been made to portray the despair of suburbia. People whose lives revolve around work in a big supermarket or other chain, empty most of the time, so they try to find something, anything, to distract themselves from the daily routine.

The premise for Chuck is the same. He's a geek, he has a pity-friend geekier than him. He works at a big electronics chain. And he has a "normal" sister who wants him to be "normal".

Then it happens. His old college buddy, a CIA agent gone rogue, sends him a message containing every government secret he's stolen in his "rogueness". Chuck somehow absorbs the whole thing, the computer breaks, and now he's the only one with the secrets. Except he's still the geeky suburbia guy, so two agents from competing agencies show up to make sure nothing "happens" to him. Needless to say, he cannot divulge anything to his sister or his friend, so he has to pretend like nothing has changed. The agents, in turn, get jobs near him and have to fit into the suburban landscape.

You're probably thinking "with a premise like that it could so easily suck". And I'm with you. But it doesn't. Chuck is pretty good in his role, and the whole spying thing is sufficiently farsical to be funny, but not so overdone that it's stupid.

what's in a fixed point?

November 9th, 2008

The fixed point is a very intuitive idea that we know from daily life. It's the notion that if something is a certain way, and you do something to change it, it will change. Some things you can go on changing forever by repeating the same action, but other things reach a limit beyond which repeating the action has no effect. Suppose you are going 50km/h in your car and you step on the brake. The car slows down. You step on the brake again, the car slows down again. But eventually the car will have come to a complete stop and stepping on the brake doesn't do anything anymore. The point at which the action has no effect anymore has a scary math name: a fixed point.

It's easy enough to write a function that finds the fixed point of another function f. You apply f to the argument and you get a value, you apply f to that and you get a value, you apply f to that and you get a value etc. And every time you check if the new value is different from the old. (Or even if it's just sufficiently similar, Newton-Raphson says hello.) Here is how it goes:

fixfinder :: (Eq a) => (a -> a) -> a -> a
fixfinder f arg =
    let val = f arg
    in if val == arg
        then arg
        else (fixfinder f val)

{-
*Main> fixfinder sqrt 68
1.0
-}

We can try it on a function whose fixed point we know, like the square root. Back in school, did you ever hit the square root key on your calculator repeatedly out of shear boredom? Eventually you'd get 1. (You can also take the square root of 0 and get 0, the second fixed point, but that's not particularly exciting.)

So far so good, now comes the mysterious part. The fixed point idea exists in programming, but in a different guise. In Data.Function there is a function called fix. It makes a very odd promise: to find the fixed point of a function without using a value. Que? How can you return the fixed point value (leaving aside for the moment the question of how you can even calculate it) if you don't have a single value to begin with? Heck, without an input value you don't even know what type the output is, if f is a polymorphic function.

fix :: (a -> a) -> a
fix f = f (fix f)

{-
*Main> fix sqrt
*** Exception: stack overflow
-}

The function doesn't look promising at all. It applies f, but there is no termination condition. Once you reach the fixed point (if there is one), how do you stop? It obviously can't figure out the square root function.

It turns out that fix is a trick used to perform recursion in languages that don't have a recursion primitive (ie. the compiler reaches an expression containing the name of the function in its own body and doesn't know what to do). The trick is that you write a function expecting among other things, a function argument (fix). Then, at the point in your function where you need to recurse, you call fix. Fix then calls the function back, so it's a sort of mutual recursion. In pure lambda calculus fix is called the y-combinator. The formula is so ridiculously cryptic that some have taken to tattoo it on their arms, obviously given up on remembering.

So what do you get out of it? Solely the fact that you get around calling the function within itself, from what I can see. And clearly that's all it does too. How do you prevent the seemingly inevitable infinite loop? You put the termination condition in your semantic function. So you write your recursive function exactly the same, but you give it an extra argument, fix. Then, at the point of recursion, instead of calling the function, you call fix. It's so bizarre that I've written out the evaluation sequence to shed some light on it.

Daredevil that I am, I'm using the factorial function. What's happening here, supposedly, is that fix is computing the fixed point of fac. We can then take that result and apply it to a number, it finds the factorial, it doesn't diverge.

What's happening here? It looks like a sort of loop unrolling, which can clearly proceed ad infinitum, were it not for Haskell's lazy nature. And, one can speculate, it's unrolling the recursion exactly the number of times it needs to be expanded (but then again, evaluation with a value already does that), but how could you possibly know that before you have a value to calculate with? It's not actually computing anything, is it? How is this any different from any old recursive function?

What fac really does is take one step toward the factorial. Multiply one factor, then call fix, which calls fac again. Eventually, the termination condition within fac kicks in. But that doesn't mean we've found the fixed point of fac, which is fac(1) = 1 and fac(2) = 2.  In fact, it seems to me we're walking right past these two fixed points, and calling fac one last time with n=0, because how else can fac terminate?

There is a lot more to fixed points, there's even something called a fixed point datatype that my small brain completely fails to comprehend. The most sane description on fix that I found is in the Haskell Book if you want to take a look. I wish you luck.

the cleaning eye

November 6th, 2008

I'm often amazed at our natural ability to handle information. I know that we make a big deal out of google's ability to find things (and it is a bit deal). But our natural ability to contextualize, and just as crucially to hide information, is unlike anything man has built so far. Just imagine what would happen if your brain showed you all the information it has, spread across the living room floor. You would not only completely forget what you were doing, you'd also never be able to find anything ever again.

We have tried to emulate this contextual ability through what we like to call modes, or profiles, or presets. Fancy cars have the ability to tune the ride either for speed, or for comfort. Digital watches have modes of operation, so when you want use the stopwatch all the other displays vanish and you're in stopwatch mode. The idea is that you change one setting, the mode, and that triggers a whole range of sensible contextual settings appropriate to that mode.

There is definitely a lot of modal functionality in our visual perception. For instance, we can't perceive a very wide spectrum of luminosity, so when you go into a dark you room your eyes need to adjust. And in that mode, if you look at something very bright, it will blind you. You won't be able to see anything else. Another example is the way we see patterns. Most of the time, when you have your eyes open, you see the same level of detail all the time. It might be interesting to ask whether your eyes might be seeing more than your brain decides to "show" you. Again, hiding unnecessary information is valuable. But if you really look closely at something, even from the same distance, you begin to notice things that your "regular" vision doesn't see. Little details appear, details that are not generally "important" to the way you look at it, but since you've switched to detail mode, you now see them. Patterns in the material, shadows on an uneven surface, spots where the material is scratched.

I like to call this mode the cleaning eye. Have you ever noticed that when you start cleaning everything looks different? The cleaning eye is one particular mode that has to do with analyzing the surface and spotting things on the surface that are not part of the surface. We are not very sophisticated at this, there is one way to make a determination. It's called the cleaning test. Try to clean it, and if it comes loose, it's dirt. If it's dirt, then you know that everything else on this surface that looks like that is also dirt. This test can give misleading results. (Have you ever used a cleaning liquid that was too potent, and you ended up damaging the surface you were supposed to be cleaning?)

What's interesting to me about the cleaning eye is the emotional responses that go with it. There are two opposing forces. On the one hand, you want to spot dirt, because that's the only way to justify what you're doing. Why am I cleaning this, there's nothing to clean here, what a waste of time. But once you switch to cleaning mode, it doesn't take long before you find dirt, no matter how clean the thing is. So you start cleaning, and once you exhaust the supply of dirt, you move on to another area.

Now comes phase two. Your eyes have been focused on finding dirt for so long that you start noticing that in this new area there are spots of fine dirt that you didn't notice before. You think to yourself huh, that's weird, I didn't see this in the first area I was cleaning. So you go back, and suddenly, there it is. You got the big, obvious specs of dirt, but you missed these smaller ones. Now you have to make a decision. Do I ignore this, and hope that noone else will notice it either, and I'll be in the clear? Or do I do a thorough job and clean as much as I can?

Let's say you choose the latter option. So you're cleaning and it's really getting boring, cause there is so much more fine dirt than there is obvious, big dirt. Emotionally, there is no satisfaction from cleaning, because the more you clean the more details your eyes find that you didn't see before. Once you get rid of the really fine dirt and move on, you invariable notice you missed something over here. And over there. And everywhere.

In theory, the process of cleaning proceeds until there's no more dirt visible. But you'll never get there, because there's always more dirt, smaller dirt, or dirt that won't come off easily. You could clean your bathroom until it's completely pristine, and spend the whole weekend doing that, but would that really make you happy? In a week there will be dirt again, and in a month the dirt will be visible on a regular basis. All this time and effort you spent one weekend, and for what?

The truth, of course, is that it's impossible to get anything completely clean. You would have to actually remove all the molecules that don't belong.

So at some point you reach your limit. That's enough, I'm sick of cleaning. You stop cleaning, you sit back and relax for a minute. You're not feeling happy, because you know there is still more dirt over there. But how long can you go on cleaning? Alright, forget it. Your mind drifts off to something else you'd rather be thinking about. Cleaning starts to fade in your mind. Fifteen minutes later your mind is completely occupied with something else.

Now something interesting happens. Someone goes into the bathroom. Wow, it is really clean in here! Woh, what? You go in yourself. Hey, look at that, I don't remember the last time it was this clean. Interestingly, the pay off comes not from cleaning "until it's clean", but from giving up on it. You switch from cleaning mode and stop using your cleaning eye. Now the image before you is contrasted with the way you remember the bathroom, and you see the difference. Hey, it looks clean.

conquer your file associations in kde!

November 4th, 2008

So everyone knows KDE is a mammoth. And that it's very configurable. The problem is when you have to configure something for which there isn't a gui. For all I know, KDE's system of config files is completely sane and reasonable, but as a user I've never known how to understand it or where to read the explanation.

One thing that has always annoyed me across operating systems is mime types/file associations. You need some kind of mapping between file types and associated applications, and it always ends up being a kind of registry that's a pain to maintain. KDE is like that too.

Here's what I've found out. The application entries that appear in that gui are defined in .desktop files that live in /usr/share/applications. So to get your app in there, you clone an existing .desktop file and edit. In my case, I like to play all video media in mplayer, the non-gui version. Because it's non-gui, it's usually not set up through the package. Instead gmplayer, which I don't want, is. So I've made my own mplayer-nogui.desktop file.

[syntax,mplayer-nogui.desktop,bash]

Now, to make your app appear under the file types you want, you just put this in the .desktop file. Once you've done that, you have a reusable mplayer-nogui.desktop that you can push into /usr/share/applications on any distro that fails to set up mplayer without a gui.

The next step is to make MPlayer nogui the preferred app for every file type that it's associated with. This is stored in ~/.kde/share/config/profilerc. The file is easy to figure out, and ideally I'd want an easy way to just select all and then override with MPlayer nogui. But to do that I'd have to write a parser, and it's frankly not worth the effort. So I just go through the list of video filetypes and manually move MPlayer nogui to the top. It would be nice to automate this.

In terms of maintenance, linux is not the jungle that Windows is, which means apps you install later won't generally try to steal the preferred status. But they might. So again, it would be nice to automate reseting that (or maybe locking down the preferences somehow).

It would be nice if the KDE guys came out with a gui that made it possible to set up your file associations in 30 seconds, but until then this is the best I got.

The missionary position

November 3rd, 2008

It is classic Hitchens to examine the unexamined. He says of his endeavor to investigate the life of Mother Teresa that he would rather judge her reputation by her words and actions than to judge the words and actions by her reputation.

It would seem culturally counter intuitive to so much as suggest that Mother Teresa, a Nobel Peace Prize winner for starters, isn't entirely equal to the admiration she received in her lifetime and continues to receive posthumously. Hitchens has an explanation for this. He argues wealthy people living comfortable lives in rich countries want to believe that somewhere out there there is someone who is doing something for the poor.

Mother Teresa was self proclaimed for this role, of course. Hitchens paints a picture of a person so consumed by the conviction that for the poor there is glory in suffering that her whole organization is dedicated to enforcing it. Her clinic in Calcutta is void of appropriate medical equipment, despite the fact that through the numerous donations to her cause she would have amassed the funds to upgrade it.

Essentially, Hitchens says that Mother Teresa is using the poor and the suffering to power her operation, a sort of "poverty in practice". Her aim is not to empower the poor to propel them out of poverty, or even to end their suffering, but rather for them to endure their poverty and suffering, for such is the will of god. All the while preaching the strictest of Catholic doctrine. We know that Jesus devoted his end to suffering, although whether he was a real person or merely a philosophical character is not established. Mother Teresa, then, was dedicated to a reenactment of sorts through the poor in her clinic, who had no power to refuse.

It is a rather different view on the world renowned character, for which Christopher Hitchens unsurprisingly received much criticism. Is it because he is twisting the facts or because we in this world are so unwilling to blemish the image of someone who was supposed to be through and through noble?