22 June, 2011

Do All, Pick One

Not too long ago, we had machines of different kinds -- each for a specific purpose. There were the big printing machines to print books, there were typewriters or "compact printing machines", cyclostyle machines for making copies, slide rules for doing calculations, files, ledgers, library "index" shelves, films, photo processing studio... one could go on and on.

Most of these have been replaced by one thing -- the computer.

Till the mid twentieth century, machines were always custom built for a specific purpose. But sometime in the late 1940s a new notion began to take root -- that of stored program computing. The main idea here is to go "meta" -- build one machine that could do act like several other machines, depending on what it is "told" to do.

This was not as novel as it sounds. Mathematicians had already been talking about going meta for several decades by that time. And indeed there were some machines which were "programmable". Textile looms for example.

But it was only with the advent of the "stored program computing machine" attributed to John von Neumann, the current day computer really took shape. Stored program computing has changed engineering so much so, that it was singularly responsible for the birth of an entirely new field: software.

Software is an intangible entity that we cannot see, touch, hear or feel in action. Yet, it controls our money, our entertainment, our knowledge and our lives.

So what makes a machine support software? You certainly cannot make your old bicycle (which is a machine) run a piece of C code. We also cannot make out room light and fan run code even though they run on electricity, just like a computer.

How does a computer "change its circuits" in response to what it is commanded to do? How does a machine that was wired to perform numerical computations, suddenly start showing a movie and do word processing?

The secret here is an extremely interesting and intriguing phenomenon, that we somehow seem to take for granted and never sit back and observe. This is what I call the "Do All, Pick One" algorithm.

The basic idea behind how a microprocessor can change its circuitry in response to its commands is based on this. The "rewiring" of circuitry takes place in the "Arithmetic and Logic Unit" (ALU) of a microprocessor. Each ALU is built to support a basic set of arithmetic operations like Add, Subtract, etc. and a basic set of logical operations like AND, OR, NOT, etc.

When a piece of instruction is loaded from memory into the processor, it is sent to a "decoder" that has one line each for every operation that is supported by the microprocessor. The decoder determines which operation is the instruction referring to, and switches on only that line (set it to logical 1) and switches all other lines off (set to logical 0).

Now comes the best part. The ALU meanwhile takes the data that needs to be processed and runs it through all the instructions in its instruction set! Each such execution gives out a result, which are then paired with the output lines of the decoder. Then, only that result is sent out, whose line has been switched on! Every other result is stopped in its tracks.

Hence, if your processor supports arithmetic operations like: ADD, SUBTRACT, MULTIPLY, LEFT-SHIFT and RIGHT-SHIFT; and your instructions ask the processor to perform an ADD, it actually performs all of the above! But only ADD is chosen to pass through the exit!

This neat little trick of "Do All, Pick One" enables the machine to become so flexible that it can now be "programmed" giving it such power that it sets serious directions of research, like asking "Can Machines Think" or will robots take over the world from us?


Whenever we think that we have invented something, nature would have invariably beat us to it by millions of years. And it is true of the "Do All, Pick One" algorithm too. Nature has been using this for eons and eons.

Machines of nature -- also called living beings, are built on principles very different from the machines that humans build. Ever notice that while we say "Don't reinvent the wheel" when it comes to machines, nature does not seem to use wheels at all? Animals don't run on wheels, they don't require highways, birds don't have engines and don't require runways. There are no turboprop birds and no jet birds. In fact, nature's pump -- the heart -- seems to be so strangely inefficient. It does not have a rotor or a jet. It works by the "primitive" method of contracting and expanding.

So what is happening here?

Well, nature's machines are not built from custom parts. Our building blocks are not components like spark plugs, crank shaft, etc. Look inside a womb when a new baby is being born, and it is definitely not the case that the organs, bones and limbs are built separately and assembled together. The entire baby is born right from inception! And it just "develops" and "grows". One fine day it grows big enough to come out of the womb, another fine day, it grows big enough to go to school and yet another fine day it grows big enough to ask for pocket money!

So what does it have to do with "Do all, Pick One"?

Machines of nature -- living beings -- are built by basic building blocks called "cells" -- each of which is a living being in itself. Recursive? Well, I think.. Maybe..

Each cell is an "autonomous agent" capable of not only doing a set of things, but also taking care of itself. That is, it is not just a processor with some arithmetic and logic capability; but it also has the requisite code to do what it takes to keep itself alive for as long as possible. It is a computing, self-regulating system capable of mechanical tasks and locomotion.

As part of their quest to keep themselves alive, cells collaborate and compete with one another. In this process of collaboration and competition, cells take on different roles. Some go on to become muscles. Some go on to become nerves. Some go on to become tissues. Some take care of the heart. Some take care of the brain. Some manages our legs. Some build bones and maintain them.

Not very different from a human society comprising of engineers, lawyers, doctors, accountants, artisans, painters, drivers, teachers, etc.

A cell, when it is born, is "multipotent". It has the capability to become anything, and it picks one. It can do all, but it picks one.

Go deeper inside a cell and into the genes and there is a "Do All, Pick One" game happening even there. Our genes contain certain "encodings" of our properties. Some properties are pretty clear and stable. Each human for example, should have a heart, lungs, liver, intestine, eyes, ears, tongue, etc. whose properties are fairly stable.

But certain other properties are not that stable. For instance, what "temperament" does a new born ought to have? Should the organism be optimized for physical tasks, artistic tasks, computational tasks, or what?

Well, guess what. Let's give everything to the organism. But have a circuitry to "choose one". This is what genes seem to say..

We have genes for a whole lot of our characteristics most of which are "suppressed" and only a few which are "expressed." When we are born, some choosing circuitry is created that determines which of the characteristics ought to be expressed and which ought to be suppressed. This choosing circuitry is determined by the signals given by the larger organism (the mother) in which all this is taking place. This gives credence to the folk wisdom that mothers who are expecting babies ought to be taken care of, both physically and emotionally. A stressed out mother gives implicit signals to the offspring to express characteristics relevant in high-stress situations, making the offspring have an overtly aggressive or defensive temperament.

Our basic circuitry for "pick one" is embedded in our firmware, so to speak, and most of us lead our entire lives blissfully unaware of its existence. Sometimes however, either due to external pressures or internal exploration, some of us discover characteristics within ourselves that we never knew existed in the first place! That is when we "discover ourselves" and come out saying "I never knew I had it in me" and so on..

At bigger scales, doing and picking that happens in the daily life of a diverse, democratic society is what makes them so resilient. And on places like Wikipedia, the doing (writing) and picking (editing and fighting it out on the discussion pages), is what helped create the world's largest encyclopedia without any contributor being paid anything.

While at the level of a microprocessor, the "picking" is a binary operation (either choose or discard), and higher levels of granularity, the "picking" operation is a matter of degree. For those who know Game Theory, it is somewhat like the difference between a pure strategy and a mixed strategy. But the basic algorithm is the same: Do All, Pick One (even if in the form of a probability distribution).

11 June, 2011

World Theological Convention of Variables

Once upon a time, there was a large application program universe. It was so large and so huge that it was believed that the application was countably infinite. The application program universe contained a vast variety of living beings, also called variables. There were ints, chars, structs, class variables, instance variables, auto variables, block variables and so on.

Usually variables went around their work diligently, but occasionally some of them stopped to contemplate. Some of them were rudely forced to contemplate when some other variable with a larger scope looked down upon them with contempt by overriding its namespace.

Finally one day, all the thinking variables of the universe decided to hold a theological convention to ponder and answer some pressing questions. Who are we? Where did we come from? What is the meaning of our lives? Is there a God? And so on..

Here we reproduce some of the proceedings of this important convention with permission from the convention organizers.

The theist who was born as a static char in a method that contained all auto chars, started first. "There exists a God!" it said with conviction. "Most of us are are visible only within the blocks in which are born, and there are those who are visible only in instances. But occasionally there comes a messiah, a saviour, who knows everything from everywhere. Someone who is visible to all, who can save anyone from an Exception. They are sometimes called global variables, but they are the best proof that God exists!"

The char *athiest spoke next. "There is no such thing as a God!" it said. "Global variables are a myth. They may have existed some time in the past, along with GOTOs, but they have all become extinct today. The universe just runs by cause and effect. The previous statement causes the current statement to run, unless it was reached by a jump like a method call or a loop."

The strongly typed variable moralist spoke next. "God does not 'exist' in the form of a variable and its powers is not determined by its scope. God exists in our deeds. If we are all moral and don't attempt to access memory locations that don't belong to us, and if we follow type systems correctly and don't try to perform unnatural typecasting, then we are all fine. If we cross these limits set by God, we are punished by a SIGSEGV or even a SIGKILL. That is the ultimate evidence of God." 

Next it was the turn of long int salvation . "Our life in this universe is temporary," it started. "We all come from the heavens and have taken birth in this universe and based on our deeds, we will either move up or down in our next life. Hence, if you are an auto int who worked well in this life, the next time the application runs you may well become static int, or even an attribute. However, if you have not lived well, the next run of the application may well see you as a block variable with limited scope. The final salvation happens when we become global variables and can talk directly with God."

void *connoisseur spoke next. "You guys are all too serious! Divinity is not just about rights and wrongs and rewards and punishments. Divinity lies in life, aesthetics and beauty. Just look at those nested for loops. And those tail recursions. Who can describe the awesome beauty of an iterator? And function pointers? And object serialization -- it is simply magic, a kind of rebirth! That, my friends is what is divine. Just learn to appreciate beauty. Loosen up. God does have a sense of humour. Laugh a lot. Pray a bit. Love a lot."

Next, it was the turn of struct Biologist EvolutionaryBiologist to speak next. "All those theories are hogwash," it started with an air of confidence. "Read up Darwin, Mendel, Dawkins, ... (rattles off some more names). The universe is a result of evolution. Our current universe is version 2.5.2. It evolved from version 2.5.1 (duh!). At each evolutionary boundary is a process of natural selection based on the principle of survival of the fittest. Only the fittest variables survive from one version to the next. The rest become extinct. What is fitness, you ask? Well simply put, fitness is the ability of a variable to survive a version change.

Upon hearing such strong words, the discussion become rather heated. Variables started assigning names to one another in violation of the code of type casting ethics. The atmosphere was so tense that doomsday a.k.a. SIGKILL almost seemed imminent. Then the boolean fatalist variable took over the stage to calm nerves. "Friends, please calm down. No matter what we think and what we argue, please remember that we are all mere mortals. Our existence is either true or false. Once our life here is over, we all go back to the heap. So please calm down. Let me now call a close to this conference and invite you all to the banquet."

Thus ended the biggest conference in the application history. We leave you with a few glimpses of the soothing fractal music played at the banquet and the vast table spread of RAMs, flash storage and other memories for the delegates to malloc. Arguably, these are one of the finest minds in the universe and it has been our privilege to be invited to this conference to cover its proceedings.


In other news; a grad student variable studying astronomy claims to have heard some kind of a message sent by an intelligent being far away in the universe, or perhaps, as the student claims, even outside of the universe. The message was undecipherable, but seemed to sound like a sound of frustration and sigh. He was not sure, but the message sounded something like, "Why is this code so buggy?!"

When asked about this to the variables in the convention, the claims were summarily dismissed as the ramblings of a nutty grad student.

23 May, 2011

Tune in to the spirit: With the right abstraction

A man was sitting in a roadside coffee shop sipping his coffee, when he saw a strange sight. Two municipal workers were busy at work on the road. One of them diligently dug a hole, and the other filled the hole back up. They then proceeded 10 meters ahead and again repeated the hole digging and filling up exercise. 
Intrigued, he went and asked them what were they up to. And one of them replied, "Well, we are planting trees. Joe here was in charge of digging the hole, while Sam who has called in sick today was in charge of planting the tree, while I am in charge of filling back the hole. We are professionals. We follow rules and we don't stop work just because one of us is absent!"


I'm reminded of this story quite often these days. :-) 
Like the other day when we went to a shopping mall, many of which are now under increased security measures. Every entrance had a metal detector and everyone entering the mall is supposed to walk through them. We didn't notice the metal detector and went by the side of it and immediately were stopped in our tracks by security people who asked us to walk through the detector. We then came back and walked through the detector and the detector beeped loudly for all of us. Following this, we were just let in and no one looked our way! 
When asked whether they are going to frisk us, they smiled and waved us on. "Rules!" they said. "Everyone must walk through the detector!" 
Sigh.. :-)
On the one hand we see a lot of refrain from people that Indians don't follow rules. "Just look at our traffic!" they say. And on the other hand, when we do follow rules, we get stories like the above. 
I've searched long and hard for a good term to explain the above kind of behaviour. Finally, I think I've got it: a clerical approach to rules. 
I don't mean to derogate clerks or their profession by saying so, just calm down.. I'm just saying that it is not enough, and there are certain other crucial skills that we don't have, and instead substitute with clerical skills when the other skills are what are necessary.
By definition, a clerk is someone who has to ensure that rules are complied with. They are not to question the rules themselves, and often times do not have the larger picture in mind as to why the rules are there in the first place. They are supposed to chide and admonish or even punish anyone who doesn't comply with the rules as written down in its letter. 
Basically, a clerical approach to professionalism need not necessarily uphold the spirit behind the activity in question.
It is argued that when dealing with large systems, it is best to comply with rules by the letter than try to reason out the spirit in every case. 
I beg to differ. 
As systems become larger, it becomes more and more complex to formulate rules in such a way that the letter does justice to the spirit in question. Take the case of the mall security example above. Having everyone enter through the metal detector only, was a rule to ensure that no one is above security screening and basically that security has to be upheld. But that is left unsaid in the letter of the rule and is basically implied. 
There is a saying attributed to Boris Pasternak: What is laid down, ordered, factual is never enough to embrace the whole truth: life always spills over the rim of every cup.
It is not possible to capture the "spirit" in writing. In fact, all our communication, including writing, is supposed to induce the right kinds of cognitive connections in our minds so that we are given a pathway to realize the underlying spirit. The words are not the spirit themselves. Words are not a substitute for thought. We still have to think enough to realize the underlying spirit. Words only help us in this process.

So how do we realize the underlying spirit? As I just mentioned, it is not possible to explain it completely in writing. But nevertheless, here are some speculations and thumb rules. 
A common mistake that I encounter when trying to reason about the underlying spirit is the following rule, typically coming from game theoretic arguments, that is considered axiomatic: Whatever we are trying to do has to make rational sense to all the people involved
Well yes, but not quite. Consider this following example. A teacher is trying to give grades for a class that has basically shown little interest in learning. Now, it makes perfect rational sense both for the teacher and the student if the teacher just gives good grades regardless of how the class has performed. The teacher can then avoid headaches of students coming back for grade correction and it avoids heartaches for the students of having to deal with bad grades. 
But then, such a decision, even though it is rational to all parties involved, violates the spirit behind the activity! The spirit in this case is that learning and academic integrity has to be upheld -- both by the teacher and the students. 
The spirit is more than just benefit for the parties involved. It is also more than what is pertinent here and now. Some things need to be done, because, they need to be done. The benefits of such activities can only be seen in the long term, with intangible payoffs and over larger issues. Education is one such example, where it is difficult to quantify the benefits of upholding the spirit behind education. Knowledge unsettles us as much as it paves the path to wisdom. Ignorance is bliss and all that.
So, well, let's say we are ready to think and won't excuse our laziness by just following rules by the letter. But even then, tuning in to the underlying spirit is hard. Often times, we don't have enough time and resources to tune in. So, what are some tools that can help us in tuning in to the underlying spirit? 
The best cognitive tool to this end is to have the right abstraction. It is very difficult to explain what is abstraction. Recently when some of us were debating about this, we realized that there is no term for "abstraction" in many, perhaps all, Indian languages!
Abstraction is not the same as vantage point, point of view, opinion, or a lot of candidate notions for which there are terms in Indian languages. 
An abstraction is essentially a cognitive model where just the important things are focused upon and everything else is well, "abstracted away." Abstraction involves "information hiding" yes, but it is not just about hiding any arbitrary piece of information. 
In French, there is a term called Raison d'ĂȘtre, translated as "Reason for existence" of a concept, which perhaps comes close. The right abstraction in understanding a rule, is one that focuses on the reason for existence for the rule. 
Here is another example that illustrates the importance of understanding the reason for existence.
Recently, we had this issue about course pre-requisites. One of my courses (let's call it course B) had another course (let's call it course A) as pre-requisite. The way the courses were offered, it caused a lot of confusion in the minds of students wanting to take up course B, in their decision to take up course A. 
Let's just say that courses B and A were offered in the same semester. And of course, there were jabs saying how can we be so "unprofessional" and so on. 
But the problem is of course, scheduling. We have limited time and resources within which all courses have to be scheduled. And for the tech-savvy among the readers, you might recall that scheduling is one of the most celebrated NP-complete (just understand it as "very hard") problems. There was just no other time in which courses A and B could be offered. 
So by offering the two courses in the same semester, did we violate the pre-requisite constraint? To understand this, I asked a question. What does the fact that course A is a pre-requisite for course B imply: 
  1. You can't take course B without taking course A
  2. You have to finish course A before starting course B
  3. Course B requires knowledge that one typically obtains in course A
I must say that I was quite surprised to note that several people who answered, chose option (1). While, the way I see it, the option is clearly (3).

Option (3) is the best interpretation among the above to uphold the spirit. Why? Because, there is a reason why courses are offered. And no, the reason is not that the students can get a degree and write this course name in their CVs. The reason for existence of a course, is that we collectively learn about something.

And once we see the reason for existence of a course, we can see that the pre-requisite rule is basically an advisory. It is not a rule to be hammered down, but an advise to students on what they should know beforehand. It is telling the students that in order to understand the concepts in course B, brush up on some background knowledge, which are typically covered in course A.

On the other hand, with option (1) as the interpretation, in this case, there was no solution. Given the time and other constraints, it was not possible to schedule courses in such a way that the "entry prohibition" interpretation can be implemented.

One could either say that "Well, there is no solution" and drop course B or say that, "We want to learn, so we'll work harder and get the required background knowledge" and take up both courses.

In my opinion, the latter is the one that best upholds the spirit, while the former is a clerical approach to interpreting pre-requisites.


Abstraction skills are not learned overnight. They have to be inculcated right from primary mathematical education. Yes, mathematical education. 
Our understanding of what is mathematics seems to be so lopsided that many of us don't really understand what mathematics is about. Apart from stereotypes of scary looking Greek characters, mathematics seems to be broadly equated to performing computation. 
In mathematics classes in primary school, we are taught multiplication tables, division rules, rules to compute the LCM, HCF, square roots, etc. But we are never taught why we need to do all these stuff in the first place. We are never taught how we can take a realistic problem setting and pose it as a mathematical model in precise terms, by "abstracting away" unnecessary details and keeping the focus on what is important. The clerical way of thinking seems to have deep roots. 
Getting the right abstraction will not guarantee that we will tune in to the underlying spirit; but without the right abstraction, there is hardly any hope..

19 April, 2011

Why ideas liberate

Most folks who have known me realize by now my advocacy of an "idea-centric" world-view from the present "people-centric" approach to things that is practiced in the part of the world where I live. A good quote towards this end that I've come across is: Small minds discuss people, average minds discuss events, great minds discuss ideas. (This quote is not mine; this is in retrospect one of the most useful quotes I've learnt from my grad school days).

As expected, I have met with a lot of opposition.

One of the most common opposition that I've encountered is that by speaking about "ideas" I am basically trying to "show off" that I am intellectually better, smarter, etc. And that it does not mean that people who don't talk about ideas are unintelligent; they may just be modest, and so on.

All I can say in response is *Sigh* :-) The opposing argument is again focused on the person and his underlying motives if any and fails to address the merit (or not) of the idea itself. So what if I am trying to show off, or not? It does not affect the truth or falsity of the assertion that focusing on ideas rather than people is better in the long run. And where did this whole stuff about someone being intelligent if they talk about ideas, come in? At least, I am not at all sure what constitutes intelligence and "measures" of intelligence in the form of IQ scores are the dumbest thing I've seen. It does not of course mean that there is no such thing called intelligence -- we just don't have a good enough model to understand its various dimensions. In any case, the assertion about ideas versus people has nothing whatever to do with a person's intelligence.

Another opposing argument I've encountered is that being people-centric means that we care for people and hence it is a noble thing to do, while being idea-centric is that we don't care about people and tend to end up living in our own worlds.

Not true.

Being people-centric does not mean that we care about people -- we just make people the center of our world-views. We think in terms of people. Hence, something bad means some person is to blame, and something good means some person is a hero. More often than not, a people-centric world-view makes us pass judgments about people, when disagreeing with them on an idea. I've seen in professional circles where a disagreement in (for example) a contract negotiation is taken to personal levels, seen as disrespect and a ego-battle, and so on. I'd say that one of the primary reasons that political manipulations permeate almost every aspect of our society in this country, is because of the people-centric world-view.

It is naive to believe that any society can be run without any form of disagreements among its members. And in a people-centric society, disagreements result in conflicts, while in an idea-centric society disagreements result in dispassionate argumentation.

Also, an idea-centric world-view does not have to mean that we don't care about people. It all depends on what our ideas are. We can pursue ideas that result in a net benefit for people and society in general (a win-win game), or we can pursue ideas that benefit only us and causes no or net negative benefit to others (a win-lose game), or we can pursue ideas that give us a net negative benefit while creating good for others (a lose-win game), or of course, we can pursue ideas that result in a net loss for us and others (a lose-lose game). It is completely up to us and our "intelligence."

Focusing on win-win ideas is "wise", focusing on win-lose ideas is "vain", focusing on lose-win ideas is "altruistic" and focusing on lose-lose ideas is, well, "stupid."

Of course, we can be "indifferent" and pursue ideas that have no perceivable value to either us or anyone else in the foreseeable future. What we do with ideas is basically up to us.

In fact, the assertion that "a people-centric world-view is all about caring for others" is basically an idea. Regardless of what we may believe, fundamentally it is ideas that mold our thinking.


So finally, what is the reason for my advocacy of an idea-centric world-view, if it is not for "showing off"?

The reason simply is that I believe, an idea-centric world is a win-win world. It will liberate us from a lot of social issues like prejudice, discrimination, insecurity, etc. that plague our society and keeps it from realizing its true potential. An idea-centric world gives a lot of freedom for individuals to be themselves and feel good about themselves, without judging them by their ideas. We can disagree with people fiercely on specific issues, yet go with them for evening chai and invite them for dinner. This (incomplete) shift in my own mind to an idea-centric paradigm has helped me cope with a number of crises without falling apart as an individual; and my only hope is that it can help others too.

I've disagreed with a lot of people on a lot of issues, but that does not mean that there is a personal enmity between us -- at least it is not there from my side. As I'd mentioned in a status update: an enemy is someone whom we want to harm, while an adversary is someone who we fear may harm us. My idea-centric world-view leaves me with no enemies; unfortunately it does not guarantee no adversaries. For that to happen, the other party should also be idea-centric.

There is a saying: The human mind is inelastic -- once it is stretched to the limits of a new idea, it never returns back to its previous dimensions. Once we know, we know. We may forget the details and we may even forget that we know; but we know. Our mind has changed, irrevocably.

Given that, it is imperative for us to carefully watch and weigh the ideas that we are letting manipulate our inelastic minds.

A people-centric world-view is basically an idea places people at the center of our world-views. It stretches our inelastic minds into a configuration that only leads to political manipulations, out of which can cannot escape so easily.

An idea-centric world-view is also an idea. But the way it stretches our inelastic minds gives our minds greater freedom to operate. It is somewhat analogous to how object-oriented thinking is better than procedural thinking. Whatever application program we write in say, Ruby or Java, we can very much write in COBOL or C. But the object-oriented paradigm of thinking makes it much easier to design and maintain large application programs, than a procedural paradigm.