Thursday, April 25, 2019

How many EVMs should the EC check?

How many EVMs should be manually checked (i.e., VVPAT count compared with that of the machine) to have sufficiently high (>99%) confidence in EVMs?
Let's take an assembly election, say in Karnataka, which has around 5crore voters and 224 seats. This means that each constituency has ~2 lakh votes and given the EC recommendation of ~1400 people per booth (urban), around 130 booths per constituency.
Clearly, if we check all the EVMs in a constituency, we'll have 100% confidence in the outcome. But what is the minimum number of EVMs you need to check to be >99% confident?
Is it 50%, as CBN told Rajdeep Sardesai? Is it 90%? Or is it 99%? Well, the answer may surprise you.
But first, let's see how many EVMs need to be tampered in a close election. Let's assume two parties, and a vote split of 51-49. [Typical margins are way higher than this.] So, in our model constituency, this is a difference of 4000 votes. If the tampering party needs to overcome this margin without raising suspicion, the margin must be split across many polling booths. Given that each booth has 1500 votes and that voting percentages are typically around 60%, there are around 900 votes per booth. Let's say that to avoid raising suspicions, the number of tampered votes per booth won't exceed 10-20% of the overall vote (i.e., 100-150 votes). The tampering party therefore needs to tamper at least 4000 / 150 = ~ 27 booths. Which means, out of the 130 EVMs in the constituency, they have to tamper at least 27. So, we have ~80% good EVMs and ~20% bad ones per constituency.
OK, so let's say that we pick 5 machines (as per the SC order) for verification. Even if we find one bad EVM amongst the five, we can countermand the election in the constituency. Therefore, if all the five machines we select turn out to be good, we would have failed to detect the bad EVMs and the tamperers go scot-free. [Remember, there are 20% bad EVMs in the constituency]. What is the probability of this happening? Well, we have five selections to perform. In the first selection, the probability of selecting a good EVM = 0.8. On the second try, because we have removed this EVM, the probability = 0.79, and so on until the probability is 0.76 on the
5th selection. But what is the probability that all our selections are good? It is : 0.8 X 0.79 X 0.78 X 0.77 X 0.76 = ~0.288. So we have a 29% chance that our test will fail and a 71% chance that we'll detect a tampered EVM in a single constituency.
But remember, these tests are being done across the state! Even a single tampered EVM across the state will put the entire election into question. For simplicity let's assume that EVMs were tampered in 10 seats. So, what is the probability that our test will fail? It is 0.29^10, which is 0000042, which means our test will work 99.9995% of the time. And like the opposition if you assume that EVMs have been tampered in each constituency, the probability of our test failing is 0.29^224; a number that is closer to zero than even the mass of some elementary particles! [Of course, I'm making some simplifying assumptions, like the percentage of tampered machines being the same across constituencies.]
So one can see that manually verifying only 5 machines per constituency can give a near 100% confidence in our voting system. This even if we ignore the logistical difficulties and systemic safeguards that would make such large scale tampering near-impossible in the first place! Too bad simple mathematics does not find place in our national media narrative. 

Sunday, August 14, 2016


The news media is full of stories by liberal activists and journalists about a 'political solution' for Kashmir. But what are the contours of such a solution? No one bothers to explain, but everyone hints darkly at some form of freedom for Kashmir and Kashmiris. I'm fortunate enough to know some folks of such leaning, and one of them even lamented that India's presence in Kashmir is as untenable as Britain's in India! Really? Well, let's examine some facts:

- Historically, India was never part of Britain. She was accessed by force and guile. Kashmir on the other hand, is a part of India that fell into dispute because of the act of partition and the naivety of Indian leaders. In fact, the name Kashmir comes from Kashyapa Mira loosely translated as Kashyapa's mountain!

- Britain treated India like a colony. The imperial government killed our industry, our agriculture, and even our people. On the other hand, Kashmir is the most pampered state in the Indian union. Even if we ignore Article 370 (which is actually the reason for Kashmiri youth's despondence), an average Kashmiri gets eight times per-capita greater grants than any other citizen. Unlike every other state which gets 70% of central assistance as debt and 30% as grant, Kashmir gets 90% as grant, and 10% as debt. And unlike Britain, which drained India's resources, the rest of India has actually drained its resources to finance the profligacies of Kashmiri politicians and separatists.

Sane people can now agree that India's presence in Kashmir is nothing like that of Britain's occupation of India. Let's now try to see if there a political solution that works.

It should be clear as daylight to anyone that no prime minister will stand up in Parliament and present the "Independence of Kashmir act". It will not happen even if Prashant Bhushan becomes the prime minister. So, Independence is ruled out. Pakistan will not withdraw from PoK, so plebiscite is ruled out. (For those who came in recently, the 1948 UN resolution on Kashmir dictates three measures to be taken: First, Pakistan withdraws from PoK, second, the two governments restore peace and order in all of J&K and third, India conducts the plebiscite in question, and the three measures are to be taken in sequence.) The only option the Kashmiris have therefore, is to live in peace within the Indian constitution and partake in India's development.

There are three measures Kashmiris can take to get over their plight. First, disavow violence. The Indian government has never known to be gentle or kind towards its citizens, particularly the ones who take up armed revolt against it. Remember how a frail Anna was arrested in the heart of Delhi for his peaceful protest? Then why would we expect the government to take kindly to stone-pelters and saboteurs? I'm not for a minute condoning the government's handling of either protest. But fixing the government is a long-drawn process. And it won't be accomplished by arson. In the meantime, generations of young Kashmiris are forfeiting their right to a better life in chasing the chimera of Independence.

The second measure is to voluntarily abolish Article 370. One thing that is clear from India's development story is that the most open cities and states have created the most job opportunities for the country. Be it Bangalore, NCR, or Mumbai, the successes of these cities (and of course, the accompanying urban decay) is because anyone can stay in these cities, setup businesses and own property. Denying these opportunities to non-Kashmiris only perpetuates the rule of the zamindari class in Kashmir. The people of Kashmir must ask a simple question: Who benefits by the continuance of Article 370? Is it the zamindars, the politicians and the separatists, or is it the common people who have no job opportunities?

Finally, the youth must take a hard look at the supposed leaders of this movement. For all the encouragement the Hurriyat leaders give to the stone-pelters, they have ensured that their own kin are in safe havens pursuing non-separatist occupations! See this report in the Indian Express. The political leaders are no better. In Kannada, there is a saying which roughly translates into boiling your beans in someone else's pyre. The Abdullahs joined hands with Rajiv Gandhi to light the pyre in the 1980s and the Muftis have happily boiled their beans in it. And the separatists have stoked the pyre and added meat to the broth.

A solution to the Kashmir problem is not hard to seek, provided everyone involved realizes what realistic options they have.

Tuesday, April 15, 2014

Why I won't vote for Narendra Modi and the BJP

I'm a fairly political person and follow Indian politics with some vigour. For a while now, I was sure I'm going to vote for Narendra Modi and the BJP. At the same time however, I believe in Bayesian Inference and the need to update beliefs based on new evidence. And boy, has there been new evidence!? So many of my friends on facebook, particularly those who have no clue about India have become Indian political commentators. Then you have the patriotic, secular TV channels which have been blaring threats that face the nation. Add to it sundry activists and the India loving foreign media that implored Indians to make the right choice. Faced with such overwhelming odds, my Bayesian Inference engine had no choice but to reverse my original belief. And in the interests of Indian polity, I decided to share this evidence with you all, so that you too might make an informed decision on April 17th (or the day your elections are going to be conducted). So, here goes:

  • He personally massacred Muslims in Gujarat:

  • He failed the skull cap test of secularism, not realizing that all true Muslims wear the skull cap:

  • He wasn't born in a royal family; so ruling India isn't his birth right

  • Potholes on Gujarat's roads rival lunar craters while Karnataka roads are like Hemamalini's cheeks: 

  • Gujarat farmers are committing suicides in droves

  • The Narmada river being diverted has made Gujarat a desert

  • His brother-in-law did not make millions in dubious land deals 

  • He is anti-women, as evidenced by his fake marriage(s)

  • and by his comments on rape:

  • He is a tyrant and will become India's Hitler

  • He has lowered the level of the political discourse:

  • He made India a police state by attacking unarmed protesters 

    • He slept while his cabinet ministers looted the country 

    I hope this convinces you why I intend to vote against Modi. Please add any additional reasons why I shouldn't vote for the BJP and Narendra Modi.

    Saturday, March 22, 2014

    Religious offerings and binary relations

    Most of you, my dear readers, are familiar with binary relations. For those who are unaware, a binary relation, as the name suggests, is a relation between two entities. Think for example, “square-of-a-number” – this defines a relation between a number and its square. Relations have properties: for instance, a relation is symmetric if it applies both between a and b and between b and a.

    Recently, my wife mentioned a custom in Hinduism where devotees poured small cans of milk into a large container that was then offered to the deity by the priests in their name. That struck me – religious offerings are transitive! And it begged the question: So what other properties of binary relations do religious offerings satisfy?

    Surely, the offerings are irreflexive and antisymmetric – no one makes offerings to himself, and devotees make offerings to the deities, never the other way around. (One could however make a case that when prayers are answered, it is an offering made by the deity to the devotee thereby satisfying the symmetric property.)

    Religious offerings are surjective (i.e. onto)  (find me a deity who doesn’t have a devotee!), but they are not bijective – one devotee typically worships many gods (at least in the Hindu faith).

    Any other properties I’ve missed? Add them as comments :)

    Thursday, October 24, 2013

    Is city the new caste?

    Do we humans have an innate need to categorize and distinguish between groups people? You know the usual ones – race, caste, skin color, sex, language, religion, state and even how one wears a tilak on their forehead. And only recently, we found that even when everything else was the same, people are ready to divide a state based on whether a Nizam ruled them or not.

    Correspondingly you have racists, casteists, sexists, linguists(!), communalists, and now, nizamists.

    I think I’ve found a new one – cityists. These are people who divide based on which city you are from. Folks in the US are aware of this: New yorkers looking down on New Jersey, San Fransicans looking down on NY, and the southern Republicans looking down on all big cities.

    Of course, most of these are in jest, or out of a sense of (sometimes misplaced) pride, and in the case of the Republicans, sheer ignorance.

    Cityism, it seems, has now spread to India. Not that it wasn’t there earlier, but there was more of a regional (linguistic?) tinge to the hatred Bangaloreans expressed for Chennai weather, or contempt Chennaites showed for the Bangalorean classical music scene. Rarely did the city spirit cross the boundaries of state, or language. Rarely did the city you came from define who you are, and almost never more than your religion or caste (or language/region). Slowly however, belonging to a city is becoming as important as belonging to a caste, religion or language. I’m sure Tamil and Marathi speaking Mumbaikars identify with themselves more than their Tamilian or Maharashtrian kin. I know for a fact that I identify myself with my north Indian colleagues than with, say, Kannada authors. I’m also reminded of my friend, a Telugu-ite who once told me that he couldn’t stand Andhra telugus (only in jest, of course). And of Amitabh, who defended Mumbai from his state-mates from UP.

    These are of course, simply anecdotes. Do they point to a more secular trend of cityism, and will it change India for the better?

    Tuesday, September 10, 2013

    “New Rules” for library developers

    I love Bill Maher’s show, “Real time” on HBO, and in particular, am a big fan of the section “New Rules” where Bill Maher sets what are typically a new (and unusual) set of rules for his favourite targets. (This is one of my favourites, and there are more here.)

    Of late, I’ve been thinking about announcing a set of “New rules” myself – but for library developers. Here are a few I can think of right away:

    1. You will NOT accept a base class type as parameter to a function unless you mean it.

    This is one of the sad legacies of Java. You have a class that you think might have multiple implementations, and so you create a class hierarchy. You then want to use this class in some function, and in conformance to traditional OO principles, you accept a base class (or interface) object as parameter. But you know that there are multiple incompatible implementations of the interface, so in your code, you specialize by adding a runtime check on the type of the object passed. Days go by, and an intrepid developer looks at your interface, and develops a class that implements it, and a third developer comes in and invokes your function using this object as parameter. The interface allows it, the compiler allows it, but voila, he runs the program and everything crashes!

    Think this is a fairy tale? A classic .NET example of this is LINQ, which in theory takes a DbConnection parameter, but is really expecting a SqlConnection object (that establishes  SQL Server connections). So, it does a runtime check on the type of the class, which I’m quite sure is something like:

    if ( connection.GetType() != typeof(SqlConnection) )

    Enter the Microsoft Enterprise Library, and its class: ReliableSqlConnection, which establishes a reliable connection to a SQL Azure database. Create a connection of this class, and pass it to LINQ, and LINQ immediately throws an exception, even though this is a SQL Server connection, and LINQ supports SQL Azure databases!

    2. You will not have hidden dependencies between your types

    A class should be a single, cohesive unit of abstraction. Everything a class method needs should either be created in the constructor or in a static constructor, or must be taken as a parameter.

    Consider the RetryManager and RetryPolicy classes in the Enterprise library. You use a RetryPolicy to specify how many times an operation should be retried. However, what is unknown is that the RetryPolicy class expects the RetryManager class to be initialized earlier. Now, my question is, if that is the case, why not do it in the static constructor of RetryPolicy? Or why not have the RetryManager create instances of RetryPolicy?

    3. You will NOT generate user documentation exclusively from code comments.

    This is another tragic consequence of Java’s influence on the programming world. When introduced, Javadocs were a boon to programmers – you wrote all your documentation as comments and there was a tool that automatically generated formatted HTML documentation, freeing developers from mucking around with Word and repeating everything one wrote in their code comments.

    An unfortunate consequence of this is what I call “instant documentation”. Normally, when developers document functions, they are focused on documenting the behaviour of the function, and not the big picture or the 10,000m view. Extrapolate this to all functions and classes in the code and the entire documentation becomes about the trees in the forest, while excluding the forest itself. Users of the API are now unaware of why a certain structure/behavior exists, they are unaware of the interdependencies between the API components (except when bitten badly by them) and are unaware of the thought process behind the behavior, all of which are lost in the minds of the creators.

    Sadly, there is now no incentive to write classic documentation like that of early versions of MFC, or like that in the *-nix man pages. No engineer gets to the Principal level by writing good documentation. What is worse is that even books are now being written this way, essentially printing copies of generated documentation. Which is a shame because this reduces developers to search-engine users rather than system-aware engineers. It prevents transfer of useful insights from those who build these APIs to those who use them.

    4. Your test cases shall be your sample code

    I have been frustrated time and again, by the sparseness and triviality of the sample code that accompany libraries. Why not supply test code written to test the API as samples? At least in theory, test code should cover corner cases, combinations of functions, and other conditions that would interest  users of the function/class.

    5. You will make simple things easy, complex things possible

    This is probably the golden rule of API development. The API must be easy to use for the most common scenarios. Most things must be accomplished with one or a few function calls. At the same time, users who have complex requirement should be able to meet them, maybe by writing complex code.

    6. You will NOT write incomplete APIs

    Completeness of an API is of course, a relative measure. It is easy, in the name of completeness, to fall down the slope of adding too much functionality. For instance, adding an encrpyt() method to a String class! On the other hand, today’s agile API writers fall into the YAGNI trap, by not adding necessary functionality – like a cache that does not have a clear() method!  APIs must have the full set of methods that a typical user might consider necessary.

    7. You will avoid the “Kingdom of nouns”

    APIs are no different from books. Have too many characters in your book, and the resulting mental overload will turn off most readers (with honourable exceptions of George R R Martin and Tom Clancy). So, think about every word you use for your class and function names. Class names are concepts – use as few of them as necessary. Use standard verb-ese for function names – like store/retrieve instead of AddToStore and GetFromStore – the simpler names have the full meaning of the longer ones with none of the conceptual overload. And never, never overload the meaning of a common verb to do something other than what its common usage suggests.

    8. Your code shall be idempotent

    Idempotency is probably the most important property in today’s multi-threaded, distributed environments. If your API depends on state, it is inherently unsuitable for a world where computations fail and are retried!

    Before I conclude, apologies for the lack of examples, the poor organization and the length of the post. I’ve been away from writing for too long now Sad smile .

    Needless to say, even though I present examples from the Microsoft world, these problems are not exclusive to it.

    Wednesday, March 13, 2013

    Missing dad

    In the Mahabharata, Yudhishtira was asked by the Yaksha of the lake what the greatest wonder in the world was. Yudhishtira replies promptly: “Day after day countless creatures are going to the abode of Yama, yet those that remain behind live their lives as though they’ll live forever. What can be more wondrous than this?”

    I was in a similar state, until last Tuesday when my father passed away after a hard-fought battle with pneumonia.

    Nothing is more final than death. Nothing is more gut-wrenching than doctors and nurses referring to your loved one as “the body”. Nothing is more shocking than seeing the body of your loved ones burn and their bones get handed down to you in a pot. 

    Over the past year and a half, my father was diagnosed with multiple health problems. He had a blocked Right Coronary Artery, his kidneys were failing, and in April last year, he had a fall that led to a hemorrhage in his brain. Still, he and his doctors fought hard, which led to a partial recovery from all the ailments, sufficient enough for him to lead a near-normal life. However, from January this year, he was forced onto dialysis, and his health kept deteriorating until the final blow came in the form of pneumonia that proved to be untreatable.

    I miss him.

    While my dad had many accomplishments to his credit, the one that mattered to me the most was that he was an intense dad. The intensity with which he approached his role as a father (or grandfather) had to be seen to be believed. Be it carrying a sick 8 year old (me) for over six kilometers to get treatment, or waiting hours in front of my school to pick me up after my exams, or waiting in queues so that I didn’t have to - my dad always put my needs, desires, and even wishes before himself. He was always there for me and my brother – even for my nephews, when we needed him. He set the dad bar very high for my family.

    Today, I feel orphaned – even though it was I (and my brother/wife/sister-in-law and mother) who was taking care of him! I realize now how many things my father had insulated us from; how many responsibilities, duties and dirty tasks he had taken on his shoulders so that we wouldn’t feel the burden. Suddenly, I feel like a teenager who woke up one morning to find himself a middle-aged man.

    However, life must go on, lessons must be learnt, and we must look ahead. Therefore, let me conclude with some bit of advice from this experience:

    * Get regular medical checkups: True, it is a hassle, it takes at least 1/2 a day, and it is tremendously annoying. But it detects many potentially deadly disorders in advance. So, if you are over 30, get a checkup done at least once in two years. If you are over 40, get a checkup done at least once a year. We came to know about my dad’s kidney failure only when it was too late to remedy it.

    * Get health insurance: While it was heart rending to see my father take ill and be in pain, we were spared financial pain, thanks to a superb health insurance policy offered by Microsoft and my dad’s CGHS facility. If your company offers health insurance, ensure that you have at least a 5 lakh cover, and that your parents, spouse and kids are covered.

    * Don’t take antibiotics at random: One of the most difficult aspects of my dad’s illness was seeing that a curable disease like pneumonia became incurable because of resistance to antibiotics. Apparently, this is because of indiscriminate use of antibiotics in the general population, both with and without doctor prescriptions, leading to the evolution of more and more resistant strains of bacteria and virii.

    * Do talk to the people you love regularly: My father was in the ICU for nearly 4 weeks, during which he couldn’t utter a word. Day after day, we would go in only to see him either unconscious or unable to speak. He probably wanted to tell us something, but couldn’t. Neither could we convey to him any words of strength. Do not postpone words of love, encouragement or strength.

    If there is a soul, I hope his finds peace. If not, there are our memories where he’ll be cherished as long as we live. Thanks dad, for all you did for me. And If I ever have kids of my own, I hope I can be half as good a dad to them as you were to me.