Sunday, March 17, 2013

Chitragupta's Algorithm

Body Master Chitragupta

Startled by the clamor around, I woke up to find myself in what looked like a court from Medieval times.  Well built mustached men with cold steely eyes moved around with immaculate precision.  From unseen dungeons below, I heard voices screaming for mercy.

As I walked through the halls of this presumed royal palace, first in awe, then in total curiosity, I bumped into a giant of man with a peculiar head gear and what looked like a large accountant's ledger in his hand.   He whirled around and let out a weak smile.

"Chitragupta, I presume?", I inquired, in a moment of inspired guess work.

"Indeed", he responded in a deep voice bordering on growling.  "I am the Body Master, keeping track of Karma for all souls.  The one and only trusted lieutenant of Lord Yama, the God of Death".

"Nothing to worry.", he added.  "Your time has not come yet.  I just need your assistance on an important matter".


Chitragupta's strange request

"I am tired of keeping track of Karma for all humans", Chitragupta began.  "While I am perfectly capable of handling the job", Chitragupta continued, feeling the edges of the large ledger book in his hand fondly, "my skills are better employed in more pressing matters".

Such as watching Apsaras dance in Lord Indra's court, I thought.

Ignoring my thoughts, Chitragupta continued.  "I have seen how you humans automate repetitious tasks on Earth.  I was looking for a good Programmer to help me with these chores.  So I had you invited here."

More like kidnapped, I muttered to myself.  Eyeing greedily around the sumptuous hall, I thought the assignment may be worth my time after all.

"You will be compensated handsomely based on your performance", Chitragupta nodded agreeably.

Jesus, it is hard to negotiate with a client who can read my mind.

"We don't allow people to use Gods from other religions here", prompt came the warning.

"Is your boss, Lord Yama on board with this arrangement?  I do not want my contract cancelled in the middle of the project.", I cautiously inquired.

Chitragupta's rubicund face fell.  Staring blankly at a distant palace, "I am going to demand more budget at my annual review.  I deserve a break, don't I?"


Chitragupta explains Karma

As a good Programmer, I then started gathering the client requirements in a series of interviews with Mr. Gupta over the next few days.

"Can you walk me through your current Karma algorithm?", I requested Chitragupta, when he had some spare time from scribbling his book.

"Okey dokey.  I just assign points to each action a person performs.  Positive points for good deeds; negative for demerits."

"Some use cases?"

"Sure.  +2 for telling the truth; -2 for each lie; +5 for lending a helping hand; -10 for cheating; +150 for rendering hymns to Lord Yama."

"You must be a busy God monitoring every act", I mused.

"Don't get me started", Chitragupta growled.  "All day long I just jot down these damn points.  And I have only two hands at that.  Some of the other Gods around here have 4 arms or more, but do nothing more than pose for pictures.  This is where you come in.", he looked at me hopefully.

"How do you handle abnormal terminations in your Karma algorithm?"

"You mean suicides?  It is a total sin.  It is we Gods who decide termination criteria for each soul.  If humans decide to terminate their lives at own will, what happens to our job security?"

Then Chitragupta added as an after thought: "But if a lady commits suicide when her husband dies, she is granted bonus merit points. These days Government bans such actions however", he added wistfully.

"What happens to a person who spent a corrupt life on Earth, enjoying his time in spite of the Scriptures?"

"After a brief stay here", pointing out to an invisible dungeon below, "we send him packing back to Earth.  We give him another chance to pray to us Gods."

"And to one who led a pious life, eschewing the bountiful luxuries that Earth has to offer, taking no pleasure in life, always spending his time stoically thinking of The Almighty?"

"We liberate him.  No more pleasures for him. We just kill his soul, taking it out of the game."  He clapped his hands gleefully.

"Let me get this right.  If a person has any positive points, he needs to return to Earth to enjoy life again? Not bad, if you ask me.  Does the algorithm provide a way out of this though?"

"The person can sacrifice all his merits to Lord Vishnu.  He kindly accepts such give-away.  How do you think He and his wife Goddess Lakshmi are so rich?", Chitragupta rolled his eyes.

"Now, can the person assign his negative points to Lord Vishnu as well?"

"No.  He does not accept it.  The person simply needs to suffer to burn off the negative points."


Decision Algorithm

Me: How do you decide whether a person's act is good or bad?
C. Gupta: It is obvious, no?  For example, harming your teacher is bad.  Very bad, indeed.
Me: Arjuna attacked his Guru Drona with weapons, per Mahabharatam.  But Lord Krishna applauded this was totally cool.
C. Gupta:  Don't worry about the edge cases.  Just ensure your solution works for at least 80% of the applicable scenarios.


Karma for animals

Me: Do animals incur Karma due to their act?
C. Gupta: Animals? Ha, no!  As it is, I have my hands full, keeping track of Karma for humans.
Me: So when a soul gets transformed to an animal, it can do whatever it damn well pleases?
C. Gupta: Yeah.  It gets a freebie life.
Me: Looks like being an animal is not bad, after all.


Idiosyncrasies of Big Gods

Me: When a person dies, his accumulated Karma gets carried over to the next cycle, right?
C. Gupta: Pretty much.
Me: Well, there are exceptions?
C. Gupta: Usually I do not cut a slack.  But Lords Vishnu and Shiva have demanded that if a person utters their names at the last breath, I cancel his Karma and liberate his soul.  And mind you, Lord Vishnu alone has over 1000 official names.
Me: So you hang around and pay close attention to what a person mutters at the end of product cycle?
C. Gupta:  Yes. All these journeys to be around each person passing away pretty much exceeds the travel miles the rest of Gods put around here. And I don't even have an official vehicle!  Our department has one  vehicle, the black buffalo.  My boss, Lord Yama, monopolizes its use, strutting around for cameo appearances in movies.
C. Gupta:  There are occasions where I don't even know if the guy said Rama or Llama.  I just give him the benefit of doubt.
Me: Any other exceptions that my algorithm should respect?
C. Gupta: Oh, yes.  If the person dies in the city of Varanasi, at least within the city's official boundary recorded in the State Government's survey books, he gets liberated.  Thus Lord Shiva has decreed.
Me: I am sure Lord Vishnu has competing requirements.
C. Gupta: You bet.  Lord Vishnu has decreed that any one passing away on His favorite day,Vaikunta Ekadasi, gets a free pass as well.
Me: Any other Gods with such special requirements?
C. Gupta: (sighs)  Only last month, Lord Ganesha was demanding liberation to people trampled to death by elephants.  When I protested in the Councils of Big Gods that at this rate, we can simply abolish Karma for all, Lord Ganesha backed off.


Thus spoke Chitragupta

Thus I spent several more sessions of requirements gathering with Chitragupta.  The more he explained Karma, the less I seemed to understand it.

Sensing my troubled face, Chitragupta helpfully offered, "Other than that, the algorithm is pretty intuitive.  It is not as complicated as your IRS tax laws."

"Why was Stalin, who murdered so many people, still led a wonderful life till the end?"

"Our jurisdiction does not extend beyond the Bharatavarsha continent."

"Well.  What about Gandhi then?  He was the apostle of non-violence, harming no one within 100 feet.  Yet, he met a brutal end."

"That is because of his past lives."

Pointing to a politician in newspaper I exclaimed, "No one is admittedly more terrible than him.  Why is his life getting better and better?"

"He will pay for his sins in his future lives."

"Why not settle the account fair and square within one's life? At least we humans can understand the logic better."

"If we keep things so simple, why would you need us Gods, then?  We need job security too.", Chitragupta looked at me contemptuously.


Escape from Chitragupta

By now, I was pretty convinced this was a doomed project.

"Body Master, Chitragupta!", I addressed.  "If there is some logic to Karma, I can automate it.  But this is a bunch of ever-changing rules and exceptions.  No one can help you, I am afraid."

"That is unacceptable.  Breach of contract is a culpable offense here."

I could see a bunch of thugs approaching me from behind.  I grabbed a pot of boiling oil, swung around, poured it on their heads, and started running.

Behind me, Chitragupta screamed, "Get him back. Ring the bell.  Ring the bell."

As I groped around, I found the alarm clock buzzing me for another day of hard programming, this time for a more reasonable client.




Friday, May 29, 2009

What can Aurangazeb teach MBA students?

Aurangzeb was the last Great Mughal Emperor, dying at the ripe age of 89 in 1707 AD.  Although the Mughal line would continue till 1858 AD with 11 more 'Emperors', none would ever rise to prominence.  Aurangzeb extended the Mughal domain to its greatest boundary, from Kabul till Assam, and reaching Kaveri basin in South India.   He was a brave warrior, fighting till his death many a battle, mostly successfully.

But historians generally consider Aurangzeb a failed emperor, as someone lacking a vision for the  future, who would damn the Mughal line forever.  There are many lessons from his life that can be applied to modern management practices.

At his core, Aurangzeb was a failed leader, although he won many short-term goals all his life.

Trust your partners
Aurangzeb was notoriously paranoid, not trusting his brothers, sons, ministers or even his own father.  At various stages, he imprisoned them, executed them or banished them, always viewing each as a rival power center.  This forced him to run all his campaigns as a solo champion.  From Akbar on, while no Mughal emperor had a cordial succession to power, Aurangzeb made things worse.

Lesson: Individual achievement will not lead to long-lasting organizational success, unless the leader shows trust in his deputies and takes effort to nurture each to his full potential.

Delegate and empower
Aurangzeb would not strengthen the forces even when is own son, Prince Muazzam, asked for reinforcement during the Deccan campaign, fearing his son would turn into a rebel against himself.   Not willing to delegate the responsibility, Aurangzeb would personally lead his Deccan campaign for 26 years, never again returning to North India.  He was reluctant to groom any successor even when he grew old.  When Aurangzeb passed away, there was no one with power to rule his domain effectively.

Lesson: The hallmark of a leader is his ability to create more leaders, perhaps someone who can even excel oneself.   Keeping the powers too centralized would distract the leader from working effectively.  Like his predecessors, had Aurangzeb delegated his Deccan campaign, he might have had time to consolidate his empire, saving it for his successors.  

Know when rules of the game has changed
Aurangzeb's lasting failure was against the Marathas, whom he would never subdue in spite of his dogged pursuits.  While Marathas initially had a charismatic center, Chatrapathi Shivaji, they quickly disintegrated into multiple factions, when Shivaji passed away in 1680 and his son Shambhuji was brutally tortured to death by Aurganzeb in 1689.  Marathas then took to plundering, moving in small teams for hit-and-run campaign against Mughals, with no central authority governing them.  Against these roving bands, Aurangzeb deployed his Imperial army, trying his old game plan on capturing forts on battlefield.  Even after decades of war, Aurangzeb failed to see that his Imperial Army was ineffective against the gorilla war of Marathas.  He was not a robust general to change his strategy in a fluid theater.  He never understood why he failed in his wretched Deccan campaign, dying a disillusioned old man.

Lesson: When the old and trusted strategy fails to work even after multiple attempts, it behooves the leader to dissect the situation to understand its root cause.  A leader should be agile and open-minded to think out-of-the-box, after first acknowledging the failure of his past efforts.  Not everything is a nail, simply because you have a hammer.

The perils of growing too fast
While Aurangzeb was a master empire-builder, he was a meek administrator.  His official writs were regularly ignored by his remote provincial governors.  Surprisingly, given his notoriety among historians, Aurangzeb was mild in dealing with Imperial officers for their disregard of his orders.  While Aurangzeb understood the importance of keeping his empire safe from external threats, he neglected to improve it.  Towards the end of his rule, only Bengal province under the governorship of Shayista Khan produced revenue for his central government.  Corruption and inefficiency was rampant in his administration, to his utter dismay.

Lesson:  Growth at any cost is a dangerous strategy.  Without a strong organic support to sustain the organization, expanding the organization for its own sake is bound to fail.

Address the Agency Problem

Aurangzeb's adversaries were regularly able to corrupt his forces, sometimes even his own sons,  to collude against his objectives.   In several instances, Mughal commanders simply bribed their Maratha counterparts to surrender the fort temporarily to get credit for victory - they even indulged in a bidding war among themselves.  In a particularly galling sham, Zulfiqar Khan, the Mughal commander sent to capture Rajaram in Gingee fort, simply chose to camp outside the fort to increase his importance in the Mughal court.  With his large force, Khan could have captured Gingee on the day of arrival, but he managed to drag the campaign out for 8 years, till he stormed the fort in 1698, even letting Rajaram escape.

Lesson:  As a project leader, ensure that all stake holders have a strong incentive for an orderly completion of the project.  Address the conflict of interest effectively before it manages to cripple the project.

Enjoy your work
Aurangzeb considered his role as an Emperor a sombre duty, to be executed meticulously without joy.  His self-control and simplicity in life were legendary.   His life stands in stark contrast with that of his forefathers, who regularly mixed business with pleasure.  Some of this drudgery was driven by his religious beliefs.   Aurangzeb's life became frustrating and dull and this affected his judgment towards the later part of his rule.

Lesson: Any task loses its luster, if executed mechanically.  A leader should be able to inspire his deputies to take pleasure in their work.  Quality of work suffers when the agent disconnects his heart from the work at hand.

Sunday, May 10, 2009

Holding the Programmer accountable

Currently the software industry takes great liberty in shipping buggy code to customers.  Even when the buggy software causes economic harm to the end-user, the liability of the programmer responsible for the bug is limited.  In the worst case, the programmer may lose his job, but more likely he suffers just a reprimand. The software vendor that shipped the defective product may sustain a slightly higher liability, such as a loss of the contract, or intangibles like loss of its reputation or damaged brand-name.

When a medical professional causes damage to his clients, he can be held legally liable for the suffering caused.  When a building collapses because of poor construction, we can go after the builder for reparation.   When your defective toaster causes fire, the manufacturer can be held liable.  When the car seat-belt fails to function, its maker can be hauled to the court of law.

When quality failures bankrupt other companies regularly, what makes the software vendor get away with it?  To add insult to injury, software industry routinely ships product with known bugs.  It is acceptable for a programmer to sign off her work with known defects.  The defect identified just gets added to a growing list of bugs to be fixed in the next project cycle.

Why not expose the programmer to legal liability for the damages he caused?  Will this accountability result in improved software products?  

In [CACM April 2009 - A direct path to dependable Software], Daniel Jackson gives a brief survey of software related incidents covering hospitals to medical instruments, and talks about software companies actively suppressing even basic data on the number and severity of bugs in their products.  Can a civilized society accept such practices in any industry, leave alone one as crucial as software development? 

There are some moves now to hold the software industry more accountable.

Let us look at some arguments both in favor of and against holding the programmer legally liable for delivering defective product.

Point 1: It is impossible to deliver a defect-free software product of reasonable complexity ("Halting Problem").  Also, Quality Control testing cannot catch all possibilities.  As Dijkstra famously observed, software tests can only prove the presence of bugs, not their absence.

Counterpoint 1: Liability depends on what could be reasonably expected of the programmer.   If the programmer did not follow the prevailing industry standards and make all efforts to deliver correct code, he should be held liable.

Point 2: Bugs are acceptable trade-offs in software delivery.  Quality can be traded-off against cost or time.  If the bugs identified are deemed non-lethal, the software product can be shipped out.  Some bugs may not be even experienced under regular use, rendering them harmless.  Delaying the product to fix all arcane bugs will result in competitive disadvantage.

Counterpoint 2: While not all bugs need to be fixed before delivery, those that break any reasonable user expectation should be fixed.  Any bug that violates the letter and spirit of user requirements is deemed harmful.  Minimally the user should be made aware of any shortfall in writing and his consent obtained before releasing the product with the defect.  The developer should be confident that his decision to release the product with known defects will stand scrutiny in a court of law.

Point 3: Defects may not be foreseeable.  Software behaviour is heavily influenced by the run time environment.  It may be impossible to account for all variations.  The combinatorial explosion that would result in certifying the product with other vendor products is insurmountable.

Counterpoint 3: Software products should be driven by clearly defined specifications that identify the typical run time environment.  If an user is known to use a set of third-party software products, its acceptable interaction if any should be documented in user requirements.  As long as the programmer did not do due diligence in ensuring his product would work under expected use cases, she should be held liable.

Point 4: Penalizing the programmer is counterproductive.  No professional deliberately sabotages her own product.  This scheme will incentivize the programmer to search for legal loopholes to avoid liability, instead of coding to the best of her abilities.

Counterpoint 4: A programmer aware of her legal liability will be doubly vigilant in her work.   Under the current situation where the programmer is treated with kid gloves, code quality is likely to take a back-seat to other priorities.  

Point 5: A programmer is naturally oblivious to defects in his own code.  It is easy to miss bugs in one's own code, lacking a different frame of mind to inspect it critically.

Counterpoint 5: There is a plethora of tools at the programmer's disposal to help him track and fix the bugs: user sign off on specs, design review, following coding standards, documentation, code review, various test approaches (unit, regression, system, automated, user-acceptance).  Following systematic approach is known to result in improved quality.  Again, the programmer's legal liability will account for what could be reasonably expected of him, under the existing state of industry.

Point 6:  In an industry notorious for a shortage of highly skilled labor, such a burden will drive away prospective employees.   As it is, students do not sign up for computer science courses.  

Counterpoint 6:  In classical Economics, a reduced supply and increased demand results in higher price equilibrium, which will force more participants to enter the supply side.  Such supply side concerns should be addressed independently, such as government subsidies to students, and should not be used as an excuse for delivering shoddy work.   

Point 7: Market-driven conditions already ensure good software quality.    Forcing the programmer to buy insurance for his work will result in that cost being passed on to the customer.

Counterpoint 7: Studies show that the threat of legal liability for shoddy work results in the actors paying attention to defects.  A software product should be viewed as a contractual obligation to its end users, and as such be subject to contract law.  Markets determine what is an acceptable cost increase for better quality.

Point 8: Software is mostly a collective enterprise.  Rarely industry strength products are developed by a lone programmer.  It is difficult to identify the programmer responsible for the bug.

Counterpoint 8: As a starting point, the software vendor should be held liable.  As all the programmers have a vested interest in their firm avoiding legal liability, this will have the result in delivering better software product.  

Point 9: Open-source software is a labor of love, developed by enthusiasts without a financial motive.  Legal penalties will shutter this movement down.

Counterpoint 9: Legal liabilities should be ascertained only on commercial software products.  This will result in commercial firms underwriting the legal liability of strong open source products.  For instance, IBM already offers to cover legal liabilities of Linux from patent infringement suits.  This is a win-win situation: open-source is left alone, commercial firms fill the vacuum to provide legal cover and legal liability results in improved software products.

Point 10: Legal liability will result in stifling creativity.  Software industry thrives on innovation.  Fear of suits will freeze the developer's flow, resulting in contrived products.  Many products are conceived without an end-user specification, created by the vision of few creative minds.  

Counterpoint 10: All commercial products should satisfy certain reasonable requirements, unlike artworks which are deemed expressions of freedom.  In particular, software products that result in harming the society should be held liable.

Point 11: All first generation software products are bound to have bugs, no matter how much effort is spent to avoid it.  Products regularly improve on repeated iterations, from real-world experience.  Legal penalty for bugs will ensure nothing new ever comes out.

Counterpoint 11: This does not seem to be true from experience in other industries.  Car companies regularly introduce new models.  Medical instrument makers constantly invest in innovation.   Builders try new construction material all the time.  In all these cases, they are successfully operating under the threat of legal action for defective products.  It is difficult to imagine software industry would be an exception.


Summary: Holding developers legally liable for defective products is definitely on its way.   Software industry can ignore this at its own peril.








Saturday, May 9, 2009

Honor killing or murder?

There are regular reports from the Middle East countries where a hapless victim, typically an unwed lady caught in an amorous episode, get stoned to death in public by a family member, in the name of Honor killing.   Sometimes these are justified invoking Sharia law, on religious grounds.  Many times, these killings are sanctioned by the law of land, after a court-trial.

These are similar to the medieval practices in India, where Rajputs regularly killed their women and children, when defeat was certain in their battles against the Muslim rulers.  Their women folks were regularly degraded by their Muslim conquerors, and their children rendered Eunuchs.  The proud Rajput warriors chose to kill their family members to protect their perceived clan honor. 

The idea of honor was pushed to extremes at times.  Previously in India, the Hindu widows were perceived to lose their place in the society and forced to terminate their lives on the funeral pyre of their deceased husbands. 

Historically, there has always been a trade-off: upholding one's social standing, even at the cost of self-injury, or accepting potential humiliation to live another day.  Sadly for most of the victims, this decision was made by their community.

From a selfish gene point of view, it is hard to justify such deaths.  All living beings have an innate sense of survival and rarely give up their rights to live.  To overcome this resistance to death, society sometimes dangles such carrots as going straight to heaven on death for the religiously inclined, or honor and pension for the victim's survivors, for the modern day soldiers.

Laws of all civilized nations permit killing only under the most extreme circumstances, where the victim's death overwhelmingly benefits the society at large.  No life is deemed so despondent to justify terminating it.   It is crucial not to romanticize those who killed their dependents under the guise of family honor, patriotism, love or religion. 

A woman who loses her honor may redeem it some day.  One who loses her life loses it forever.

Monday, April 27, 2009

The First Jihad against the Hindus

When cornered, a creative and determined man would skillfully convert his adversity into virtue.   Babur’s stunning victory against Rana Sanga of Mewar in the Battle of Khanua, 1527 AD, under the banner of Jihad (Holy War) was one such example.  Religion would be used as a means to advance personal ambitions, not for the last time in history.

While there were countless battles between the Hindus and the Muslims before, they were fought over India’s legendary riches.   Religion was never deemed a prime reason to wage a war in “Hindustan”, as the land was then called.

While Babur termed the very first Mughal battle against the Hindus as Holy War, such a label was more reflective of Babur's shrewd military prowess than his religious zeal.   Earlier, Babur had no qualms in accepting Rana Sangha’s help, who promised (but never delivered) diversionary attacks on Ibrahim Lodi in the First Battle of Panipat, 1526.

Rana Sanga, a ferocious Rajput warrior, was an worthy adversary of Babur, a battle-tested veteran and a descendant of Timur and Chingiz Khan.  Rana had lost an eye, an arm, had broken his limb and sported eighty wounds from sword or lance on his body – all the result of his previous military engagements.   

Rana dreamt of erecting a Hindu Raj, following Ibrahim Lodi’s defeat at Babur's hands, expecting Babur to quickly retreat to Kabul.   When Babur decided to stay in Hindustan, with his capital as Agra, Rana decided to take on Babur.  

Babur’s soldiers wanted to retire to Kabul with their loot after defeating Lodi Some of his allies in India began deserting him.  Babur estimated the strength of Rajputs at 200,000, far more than Lodi’s army that he had vanquished earlier.  Babur’s army numbered less than 12,000 men, but sported a modern army with muskets and cannons.

When confronted by a far superior enemy, Babur found a way to conveniently raise the morale of his troops, under the guise of Islam.

To win moral authority for his encounter with the Hindus, Babur turned to Islam - giving up wine and swearing not to trim his beard thereafter.  He declared the war as a Jihad, and addressed his troops that they will either become martyrs if defeated, or avengers of His sacred cause, if victorious.

Babur recounted the Battle of Khanua, 1527, in his autobiography, Baburnama.   The Mughals, with their blood ignited by Babur’s apparent religious zeal, overcame the Rajputs with their firepower.   Babur assumed the title of Ghazi, Holy Warrior, at this victory.

But Babur had no further interest in the Hindu army.  He did not pursue the Rajputs.  He even let Rana Sanga escape, who would later succumb to his wounds.  Content at securing his power, Babur returned to Agra Later, he would even return to drinking, breaking his vow at the Battle of Khanua.  Babur had little results by way of religion to show, having proclaimed the first Jihad against the Hindus.

Khanua was a watershed event in Indian history, with the Hindus losing forever their chance to establish a Hindu Raj all over their beloved Hindustan.   But the animosity of the Hindus towards the Mughal Empire would soon subside.

(Reference: The Mughal  Throne, Abraham Eraly, Phoenix, 2004)

Thursday, April 23, 2009

Morning Star ("Vidi Velli") - A poem in Tamil


This is a poem I composed on 9th May 1992.   Morning Star is traditionally associated with hope.  I chose this title in stark contrast to the dark mood elicited by this poem.